From e0b7b9effa5b69fbcc71362abd9cf500b2b99f45 Mon Sep 17 00:00:00 2001 From: renkang <8417338+k94314517@user.noreply.gitee.com> Date: 星期一, 06 一月 2025 18:39:38 +0800 Subject: [PATCH] 客户资料 巡检任务业务 --- server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwOutinboundServiceImpl.java | 347 +++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 294 insertions(+), 53 deletions(-) diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwOutinboundServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwOutinboundServiceImpl.java index 9e5724f..37a7c72 100644 --- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwOutinboundServiceImpl.java +++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwOutinboundServiceImpl.java @@ -1,20 +1,34 @@ package com.doumee.service.business.impl; +import com.alibaba.druid.sql.visitor.functions.Concat; +import com.doumee.core.constants.ResponseStatus; +import com.doumee.core.exception.BusinessException; +import com.doumee.core.model.LoginUserInfo; import com.doumee.core.model.PageData; import com.doumee.core.model.PageWrap; +import com.doumee.core.utils.Constants; +import com.doumee.core.utils.DateUtil; import com.doumee.core.utils.Utils; -import com.doumee.dao.business.YwOutinboundMapper; -import com.doumee.dao.business.model.YwOutinbound; +import com.doumee.core.utils.redis.RedisUtil; +import com.doumee.dao.business.*; +import com.doumee.dao.business.model.*; +import com.doumee.dao.system.model.SystemUser; import com.doumee.service.business.YwOutinboundService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.github.yulichang.wrapper.MPJLambdaWrapper; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; -import java.util.List; +import java.math.BigDecimal; +import java.util.*; +import java.util.stream.Collectors; /** * 杩愮淮鍑哄叆搴撲俊鎭〃Service瀹炵幇 @@ -27,11 +41,136 @@ @Autowired private YwOutinboundMapper ywOutinboundMapper; + @Autowired + private YwMaterialMapper ywMaterialMapper; + + @Autowired + private YwOutinboundRecordMapper ywOutinboundRecordMapper; + + @Autowired + private YwStockMapper ywStockMapper; + + @Autowired + private YwWarehouseMapper ywWarehouseMapper; + + @Autowired + private YwStocktakingMapper ywStocktakingMapper; + + @Autowired + private RedisTemplate<String, Object> redisTemplate; + @Override + @Transactional(rollbackFor = {Exception.class, BusinessException.class}) public Integer create(YwOutinbound ywOutinbound) { + List<YwOutinboundRecord> recordList = this.verifyData(ywOutinbound); + YwWarehouse ywWarehouse = ywWarehouseMapper.selectById(ywOutinbound.getWarehouseId()); + if(Objects.isNull(ywWarehouse)){ + throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌浠撳簱淇℃伅"); + } + LoginUserInfo loginUserInfo = ywOutinbound.getLoginUserInfo(); + //鏍规嵁鎿嶄綔绫诲瀷杩涜鍒ゆ柇鏄叆搴�/鍑哄簱 + Constants.ywOutInType ywOutInType = Constants.ywOutInType.getYwOutInType(ywOutinbound.getType()); + if(Objects.isNull(ywOutInType)){ + throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈尮閰嶅埌鍑哄叆搴撶被鍨�"); + } + //鐢熸垚鍑哄叆搴撳崟鎹紪鍙� + ywOutinbound.setCode(getNextInOutCode(ywOutInType.getInOut())); + ywOutinbound.setCreator(loginUserInfo.getId()); + ywOutinbound.setCreateDate(new Date()); + ywOutinbound.setOrigin(Constants.ZERO); ywOutinboundMapper.insert(ywOutinbound); + for (YwOutinboundRecord ywOutinboundRecord:recordList) { + ywOutinboundRecord.setCreator(loginUserInfo.getId()); + ywOutinboundRecord.setCreateDate(new Date()); + ywOutinboundRecord.setIsdeleted(Constants.ZERO); + } + ywOutinboundRecordMapper.insert(recordList); + //鏇存柊搴撳瓨淇℃伅 + this.dealStockData(ywOutinbound,recordList,ywOutInType.getInOut()); return ywOutinbound.getId(); } + + + public List<YwOutinboundRecord> verifyData(YwOutinbound ywOutinbound){ + if(Objects.isNull(ywOutinbound) + || Objects.isNull(ywOutinbound.getType()) + || (Objects.nonNull(ywOutinbound.getType()) && (!(ywOutinbound.getType() == Constants.ZERO || ywOutinbound.getType() == Constants.ONE))) + || Objects.isNull(ywOutinbound.getWarehouseId()) + || Objects.isNull(ywOutinbound.getDoneDate()) + || com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(ywOutinbound.getRecordList()) + ){ + throw new BusinessException(ResponseStatus.BAD_REQUEST); + } + List<YwOutinboundRecord> recordList = ywOutinbound.getRecordList(); + for (YwOutinboundRecord ywOutinboundRecord:recordList) { + if(Objects.isNull(ywOutinboundRecord) + ||Objects.isNull(ywOutinboundRecord.getMaterialId()) + ||Objects.isNull(ywOutinboundRecord.getStock()) + ||ywOutinboundRecord.getStock().compareTo(BigDecimal.ZERO)<=Constants.ZERO + ){ + throw new BusinessException(ResponseStatus.BAD_REQUEST); + } + } + //鍒ゆ柇褰撳墠鏄惁瀛樺湪杩涜涓殑鐩樼偣鍗� + if(ywStocktakingMapper.selectCount(new QueryWrapper<YwStocktaking>().lambda().eq(YwStocktaking::getIsdeleted,Constants.ZERO) + .eq(YwStocktaking::getWarehouseId,ywOutinbound.getWarehouseId()) + .eq(YwStocktaking::getStatus,Constants.ONE))>Constants.ZERO){ + throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀛樺湪杩涜涓殑鐩樼偣鍗曪紝鏃犳硶杩涜鍑哄叆搴撴搷浣�"); + }; + //鍒ゆ柇鏄惁瀛樺湪鐩稿悓鏁版嵁 + Set<Integer> materialIds = new HashSet<Integer>(recordList.stream().map(i->i.getMaterialId()).collect(Collectors.toList())); + if(materialIds.size() != recordList.size()){ + throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀛樺湪鐩稿悓璧勪骇淇℃伅锛岃妫�鏌ユ暟鎹紒"); + } + if(ywMaterialMapper.selectCount(new QueryWrapper<YwMaterial>().lambda().in(YwMaterial::getId,materialIds))!=recordList.size()){ + throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"璧勪骇淇℃伅瀛樺湪寮傚父锛岃妫�鏌ユ暟鎹紒"); + } + return recordList; + + + } + + public void dealStockData(YwOutinbound ywOutinbound,List<YwOutinboundRecord> recordList,Integer inOut){ + for (YwOutinboundRecord ywOutinboundRecord:recordList) { + YwStock ywStock = ywStockMapper.selectOne(new QueryWrapper<YwStock>().lambda().eq(YwStock::getIsdeleted,Constants.ZERO).eq(YwStock::getWarehouseId,ywOutinbound.getWarehouseId()).eq(YwStock::getMaterialId,ywOutinboundRecord.getMaterialId())); + if(Constants.equalsInteger(inOut,Constants.ZERO)){ + //鍏ュ簱 + if(Objects.isNull(ywStock)){ + ywStock.setStock(ywOutinboundRecord.getStock()); + ywStock.setWarehouseId(ywOutinbound.getWarehouseId()); + ywStock.setMaterialId(ywOutinboundRecord.getMaterialId()); + ywStock.setCreateDate(new Date()); + ywStock.setCreator(ywOutinbound.getCreator()); + ywStockMapper.insert(ywStock); + }else{ + ywStockMapper.update(new UpdateWrapper<YwStock>().lambda() + .set(YwStock::getStock," ( stock + " + ywStock.getStock() + " )") + .set(YwStock::getEditDate, DateUtil.getCurrDateTime()) + .set(YwStock::getEditor, ywOutinbound.getCreator()) + .eq(YwStock::getId,ywStock.getId()) + ); + } + }else{ + YwMaterial ywMaterial = ywMaterialMapper.selectById(ywOutinboundRecord.getMaterialId()); + //鍑哄簱 + if(Objects.isNull(ywStock) || ywStock.getStock().compareTo(ywOutinboundRecord.getStock()) < Constants.ZERO){ + throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), ywMaterial.getName() + "搴撳瓨涓嶈冻锛岃鍒锋柊閲嶈瘯"); + }else if(ywStock.getStock().compareTo(ywOutinboundRecord.getStock()) == Constants.ZERO){ + ywStockMapper.deleteById(ywStock.getId()); + }else{ + ywStockMapper.update(new UpdateWrapper<YwStock>().lambda() + .set(YwStock::getStock," ( stock - " + ywStock.getStock() + " )") + .set(YwStock::getEditDate, DateUtil.getCurrDateTime()) + .set(YwStock::getEditor, ywOutinbound.getCreator()) + .eq(YwStock::getId,ywStock.getId()) + ); + } + } + } + } + + + @Override public void deleteById(Integer id) { @@ -83,60 +222,45 @@ QueryWrapper<YwOutinbound> wrapper = new QueryWrapper<>(ywOutinbound); return ywOutinboundMapper.selectList(wrapper); } - + + @Override + public YwOutinbound getDetail(Integer id) { + MPJLambdaWrapper<YwOutinbound> queryWrapper = new MPJLambdaWrapper<YwOutinbound>(); + queryWrapper.selectAll(YwOutinbound.class) + .selectAs(SystemUser::getRealname,YwOutinbound::getCreateUserName) + .selectAs(YwWarehouse::getName,YwOutinbound::getWarehouseName) + .leftJoin(SystemUser.class,SystemUser::getId,YwOutinbound::getCreator) + .leftJoin(YwWarehouse.class,YwWarehouse::getId,YwOutinbound::getWarehouseId) + .eq(YwOutinbound::getId,id) + .last(" limit 1"); + YwOutinbound ywOutinbound = ywOutinboundMapper.selectJoinOne(YwOutinbound.class,queryWrapper); + List<Integer> idList = new ArrayList<>(); + idList.add(id); + ywOutinbound.setRecordList(this.getRecordDetailData(idList)); + return ywOutinbound; + } + + @Override public PageData<YwOutinbound> findPage(PageWrap<YwOutinbound> pageWrap) { IPage<YwOutinbound> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); - QueryWrapper<YwOutinbound> queryWrapper = new QueryWrapper<>(); + MPJLambdaWrapper<YwOutinbound> queryWrapper = new MPJLambdaWrapper<YwOutinbound>(); Utils.MP.blankToNull(pageWrap.getModel()); - if (pageWrap.getModel().getId() != null) { - queryWrapper.lambda().eq(YwOutinbound::getId, pageWrap.getModel().getId()); + YwOutinbound model = pageWrap.getModel(); + if(Objects.isNull(model)||Objects.isNull(model.getInOut())){ + throw new BusinessException(ResponseStatus.BAD_REQUEST); } - if (pageWrap.getModel().getCreator() != null) { - queryWrapper.lambda().eq(YwOutinbound::getCreator, pageWrap.getModel().getCreator()); - } - if (pageWrap.getModel().getCreateDate() != null) { - queryWrapper.lambda().ge(YwOutinbound::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate())); - queryWrapper.lambda().le(YwOutinbound::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate())); - } - if (pageWrap.getModel().getEditor() != null) { - queryWrapper.lambda().eq(YwOutinbound::getEditor, pageWrap.getModel().getEditor()); - } - if (pageWrap.getModel().getEditDate() != null) { - queryWrapper.lambda().ge(YwOutinbound::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate())); - queryWrapper.lambda().le(YwOutinbound::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate())); - } - if (pageWrap.getModel().getIsdeleted() != null) { - queryWrapper.lambda().eq(YwOutinbound::getIsdeleted, pageWrap.getModel().getIsdeleted()); - } - if (pageWrap.getModel().getRemark() != null) { - queryWrapper.lambda().eq(YwOutinbound::getRemark, pageWrap.getModel().getRemark()); - } - if (pageWrap.getModel().getWarehouseId() != null) { - queryWrapper.lambda().eq(YwOutinbound::getWarehouseId, pageWrap.getModel().getWarehouseId()); - } - if (pageWrap.getModel().getMaterialId() != null) { - queryWrapper.lambda().eq(YwOutinbound::getMaterialId, pageWrap.getModel().getMaterialId()); - } - if (pageWrap.getModel().getStock() != null) { - queryWrapper.lambda().eq(YwOutinbound::getStock, pageWrap.getModel().getStock()); - } - if (pageWrap.getModel().getType() != null) { - queryWrapper.lambda().eq(YwOutinbound::getType, pageWrap.getModel().getType()); - } - if (pageWrap.getModel().getOrigin() != null) { - queryWrapper.lambda().eq(YwOutinbound::getOrigin, pageWrap.getModel().getOrigin()); - } - if (pageWrap.getModel().getContent() != null) { - queryWrapper.lambda().eq(YwOutinbound::getContent, pageWrap.getModel().getContent()); - } - if (pageWrap.getModel().getDoneDate() != null) { - queryWrapper.lambda().ge(YwOutinbound::getDoneDate, Utils.Date.getStart(pageWrap.getModel().getDoneDate())); - queryWrapper.lambda().le(YwOutinbound::getDoneDate, Utils.Date.getEnd(pageWrap.getModel().getDoneDate())); - } - if (pageWrap.getModel().getStatus() != null) { - queryWrapper.lambda().eq(YwOutinbound::getStatus, pageWrap.getModel().getStatus()); - } + List<Integer> typeList = Constants.ywOutInType.getAllTypeKey(model.getInOut()); + queryWrapper.selectAll(YwOutinbound.class) + .selectAs(SystemUser::getRealname,YwOutinbound::getCreateUserName) + .selectAs(YwWarehouse::getName,YwOutinbound::getWarehouseName) + .leftJoin(SystemUser.class,SystemUser::getId,YwOutinbound::getCreator) + .leftJoin(YwWarehouse.class,YwWarehouse::getId,YwOutinbound::getWarehouseId) + .like(StringUtils.isNotBlank(model.getCode()),YwOutinbound::getCode,model.getCode()) + .eq(Objects.nonNull(model.getType()),YwOutinbound::getType,model.getType()) + .eq(Objects.nonNull(model.getWarehouseId()),YwOutinbound::getWarehouseId,model.getWarehouseId()) + .in(Objects.nonNull(model.getInOut()),YwOutinbound::getType,typeList) + ; for(PageWrap.SortData sortData: pageWrap.getSorts()) { if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { queryWrapper.orderByDesc(sortData.getProperty()); @@ -144,12 +268,129 @@ queryWrapper.orderByAsc(sortData.getProperty()); } } - return PageData.from(ywOutinboundMapper.selectPage(page, queryWrapper)); + IPage iPage = ywOutinboundMapper.selectJoinPage(page,YwOutinbound.class,queryWrapper); + if(Objects.nonNull(iPage.getRecords())){ + iPage.setRecords(this.getDetailData(iPage.getRecords())); + } + return PageData.from(iPage); } + + public List<YwOutinbound> getDetailData(List<YwOutinbound> ywOutinboundList){ + List<Integer> idList = ywOutinboundList.stream().map(i->i.getId()).collect(Collectors.toList()); + if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(idList)){ + List<YwOutinboundRecord> ywOutinboundRecordList = this.getRecordDetailData(idList); + if(CollectionUtils.isEmpty(ywOutinboundRecordList)){ + return ywOutinboundList; + } + for (YwOutinbound ywOutinbound:ywOutinboundList) { + ywOutinbound.setRecordList( + ywOutinboundRecordList.stream().filter(i->Constants.equalsInteger(i.getOutInBoundId(),ywOutinbound.getId())).collect(Collectors.toList()) + ); + } + } + return ywOutinboundList; + } + + + public List<YwOutinboundRecord> getRecordDetailData(List<Integer> outinBoundIdList){ + List<YwOutinboundRecord> ywOutinboundRecordList = ywOutinboundRecordMapper.selectJoinList(YwOutinboundRecord.class, + new MPJLambdaWrapper<YwOutinboundRecord>() + .selectAll(YwOutinboundRecord.class) + .selectAs(YwMaterial::getCode,YwOutinboundRecord::getMaterialCode) + .selectAs(YwMaterial::getName,YwOutinboundRecord::getMaterialName) + .selectAs(YwMaterial::getQrcode,YwOutinboundRecord::getMaterialQrcode) + .selectAs(YwMaterial::getBrand,YwOutinboundRecord::getMaterialBrand) + .selectAs(YwMaterial::getUnitName,YwOutinboundRecord::getMaterialUnitName) + .leftJoin(YwMaterial.class,YwMaterial::getId,YwOutinboundRecord::getMaterialId) + .eq(YwOutinboundRecord::getIsdeleted,Constants.ZERO) + .in(YwOutinboundRecord::getOutInBoundId,outinBoundIdList) + ); + return ywOutinboundRecordList; + } + + +// @Override +// public PageData<YwOutinbound> findPage(PageWrap<YwOutinbound> pageWrap) { +// IPage<YwOutinbound> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); +// +// QueryWrapper<YwOutinbound> queryWrapper = new QueryWrapper<>(); +// Utils.MP.blankToNull(pageWrap.getModel()); +// if (pageWrap.getModel().getId() != null) { +// queryWrapper.lambda().eq(YwOutinbound::getId, pageWrap.getModel().getId()); +// } +// if (pageWrap.getModel().getCreator() != null) { +// queryWrapper.lambda().eq(YwOutinbound::getCreator, pageWrap.getModel().getCreator()); +// } +// if (pageWrap.getModel().getCreateDate() != null) { +// queryWrapper.lambda().ge(YwOutinbound::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate())); +// queryWrapper.lambda().le(YwOutinbound::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate())); +// } +// if (pageWrap.getModel().getEditor() != null) { +// queryWrapper.lambda().eq(YwOutinbound::getEditor, pageWrap.getModel().getEditor()); +// } +// if (pageWrap.getModel().getEditDate() != null) { +// queryWrapper.lambda().ge(YwOutinbound::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate())); +// queryWrapper.lambda().le(YwOutinbound::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate())); +// } +// if (pageWrap.getModel().getIsdeleted() != null) { +// queryWrapper.lambda().eq(YwOutinbound::getIsdeleted, pageWrap.getModel().getIsdeleted()); +// } +// if (pageWrap.getModel().getRemark() != null) { +// queryWrapper.lambda().eq(YwOutinbound::getRemark, pageWrap.getModel().getRemark()); +// } +// if (pageWrap.getModel().getWarehouseId() != null) { +// queryWrapper.lambda().eq(YwOutinbound::getWarehouseId, pageWrap.getModel().getWarehouseId()); +// } +// if (pageWrap.getModel().getMaterialId() != null) { +// queryWrapper.lambda().eq(YwOutinbound::getMaterialId, pageWrap.getModel().getMaterialId()); +// } +// if (pageWrap.getModel().getStock() != null) { +// queryWrapper.lambda().eq(YwOutinbound::getStock, pageWrap.getModel().getStock()); +// } +// if (pageWrap.getModel().getType() != null) { +// queryWrapper.lambda().eq(YwOutinbound::getType, pageWrap.getModel().getType()); +// } +// if (pageWrap.getModel().getOrigin() != null) { +// queryWrapper.lambda().eq(YwOutinbound::getOrigin, pageWrap.getModel().getOrigin()); +// } +// if (pageWrap.getModel().getContent() != null) { +// queryWrapper.lambda().eq(YwOutinbound::getContent, pageWrap.getModel().getContent()); +// } +// if (pageWrap.getModel().getDoneDate() != null) { +// queryWrapper.lambda().ge(YwOutinbound::getDoneDate, Utils.Date.getStart(pageWrap.getModel().getDoneDate())); +// queryWrapper.lambda().le(YwOutinbound::getDoneDate, Utils.Date.getEnd(pageWrap.getModel().getDoneDate())); +// } +// if (pageWrap.getModel().getStatus() != null) { +// queryWrapper.lambda().eq(YwOutinbound::getStatus, pageWrap.getModel().getStatus()); +// } +// for(PageWrap.SortData sortData: pageWrap.getSorts()) { +// if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { +// queryWrapper.orderByDesc(sortData.getProperty()); +// } else { +// queryWrapper.orderByAsc(sortData.getProperty()); +// } +// } +// return PageData.from(ywOutinboundMapper.selectPage(page, queryWrapper)); +// } @Override public long count(YwOutinbound ywOutinbound) { QueryWrapper<YwOutinbound> wrapper = new QueryWrapper<>(ywOutinbound); return ywOutinboundMapper.selectCount(wrapper); } + + + public synchronized String getNextInOutCode(Integer inOut){ + String prefix = Constants.equalsInteger(inOut,0)?"RK-":"CK-" + DateUtil.getDate(new Date(),"yyyyMMdd") +"-"; + Integer countNum = RedisUtil.getObject(redisTemplate, + Constants.equalsInteger(inOut,0)?Constants.RedisKeys.COM_OUTBOUND_OUT_KEY:Constants.RedisKeys.COM_OUTBOUND_IN_KEY, + Integer.class); + countNum = Constants.formatIntegerNum(countNum)+1; + //鏇存柊缂撳瓨 + RedisUtil.addObject(redisTemplate,Constants.equalsInteger(inOut,0)?Constants.RedisKeys.COM_OUTBOUND_OUT_KEY:Constants.RedisKeys.COM_OUTBOUND_IN_KEY,countNum); + String nextIndex =Integer.toString( countNum ); + return prefix + StringUtils.leftPad(nextIndex,4,"0"); + } + + } -- Gitblit v1.9.3