From a2299a6d4a6f99e9c11132138f5d3e9ec68f03ea Mon Sep 17 00:00:00 2001 From: jiangping <jp@doumee.com> Date: 星期五, 06 六月 2025 19:19:34 +0800 Subject: [PATCH] 开发更新 --- server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwStocktakingServiceImpl.java | 515 ++++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 415 insertions(+), 100 deletions(-) diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwStocktakingServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwStocktakingServiceImpl.java index 4901208..3ca923e 100644 --- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwStocktakingServiceImpl.java +++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwStocktakingServiceImpl.java @@ -1,20 +1,40 @@ package com.doumee.service.business.impl; +import com.alibaba.fastjson.JSONObject; +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.core.utils.redis.RedisUtil; +import com.doumee.dao.business.YwStockMapper; import com.doumee.dao.business.YwStocktakingMapper; -import com.doumee.dao.business.model.YwStocktaking; +import com.doumee.dao.business.YwStocktakingRecordMapper; +import com.doumee.dao.business.YwWarehouseMapper; +import com.doumee.dao.business.model.*; +import com.doumee.dao.system.SystemUserMapper; +import com.doumee.dao.system.join.NoticesJoinMapper; +import com.doumee.dao.system.model.Notices; +import com.doumee.dao.system.model.SystemUser; import com.doumee.service.business.YwStocktakingService; 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.lang.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; /** * 杩愮淮鐩樼偣淇℃伅琛⊿ervice瀹炵幇 @@ -27,15 +47,282 @@ @Autowired private YwStocktakingMapper ywStocktakingMapper; + @Autowired + private YwStockMapper ywStockMapper; + + + @Autowired + private YwStocktakingRecordMapper ywStocktakingRecordMapper; + + @Autowired + private YwWarehouseMapper ywWarehouseMapper; + + @Autowired + private NoticesJoinMapper noticesJoinMapper; + + @Autowired + private SystemUserMapper systemUserMapper; + + @Autowired + private RedisTemplate<String, Object> redisTemplate; + @Override + @Transactional(rollbackFor = {Exception.class,BusinessException.class}) public Integer create(YwStocktaking ywStocktaking) { + if(Objects.isNull(ywStocktaking) + || StringUtils.isBlank(ywStocktaking.getName()) + || Objects.isNull(ywStocktaking.getPlanDate()) + || Objects.isNull(ywStocktaking.getWarehouseId()) + || Objects.isNull(ywStocktaking.getUserId()) + ){ + throw new BusinessException(ResponseStatus.BAD_REQUEST); + } + YwWarehouse ywWarehouse = ywWarehouseMapper.selectById(ywStocktaking.getWarehouseId()); + if(Objects.isNull(ywWarehouse)){ + throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌浠撳簱鏁版嵁"); + } + //鍒ゆ柇褰撳墠浠撳簱褰撳墠鏃ユ湡鏄惁瀛樺湪鐩樼偣鍗� + if(ywStocktakingMapper.selectCount(new QueryWrapper<YwStocktaking>().lambda() + .eq(YwStocktaking::getIsdeleted,Constants.ZERO) + .in(YwStocktaking::getStatus,Constants.ZERO,Constants.ONE) + .eq(YwStocktaking::getWarehouseId,ywStocktaking.getWarehouseId()) + .apply(" DATE(PLAN_DATE) = '" + DateUtil.formatDate(ywStocktaking.getPlanDate(),"yyyy-MM-dd") +"'" ))>0){ + throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"["+DateUtil.formatDate(ywStocktaking.getPlanDate(),"yyyy-MM-dd")+"]["+ywWarehouse.getName()+"]宸叉湁鐩樼偣鍗曪紝涓嶅彲閲嶅鍙戣捣鐩樼偣"); + } + SystemUser systemUser = systemUserMapper.selectById(ywStocktaking.getUserId()); + if(Objects.isNull(systemUser)){ + throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌鐩樼偣浜轰俊鎭�"); + } + LoginUserInfo loginUserInfo = ywStocktaking.getLoginUserInfo(); + ywStocktaking.setCreator(loginUserInfo.getId()); + ywStocktaking.setCreateDate(new Date()); + ywStocktaking.setIsdeleted(Constants.ZERO); + ywStocktaking.setStatus(Constants.ZERO); + ywStocktaking.setCode(getNextCode()); ywStocktakingMapper.insert(ywStocktaking); + //娣诲姞寰呭姙淇℃伅 + Notices notices = new Notices(); + notices.setCreateDate(new Date()); + notices.setCreator(ywStocktaking.getCreator()); + notices.setIsdeleted(Constants.ZERO); + notices.setParam1(DateUtil.formatDate(ywStocktaking.getPlanDate(),"yyyy-MM-dd")); + notices.setTitle("鐩樼偣寰呭姙"); + notices.setContent("["+ywStocktaking.getName()+"]灏嗗湪["+notices.getParam1()+"]杩涜鐩樼偣锛岃鎸夋椂鎵ц"); + notices.setObjId(ywStocktaking.getId()); + notices.setObjType(Constants.ZERO); + notices.setType(notices.getObjType()); + notices.setUserId(ywStocktaking.getUserId()); + notices.setStatus(Constants.ZERO); + //鏁寸悊json鏁版嵁 + Map<String,Object> jsonMap = new HashMap<>(); + jsonMap.put("key1","鐩樼偣鍗�"+ywStocktaking.getCode()); + jsonMap.put("key2", DateUtil.getFomartDate(ywStocktaking.getPlanDate(),"yyyy-MM-dd")); + jsonMap.put("key3", ywWarehouse.getName()); + jsonMap.put("key4", systemUser.getRealname()); + notices.setParam2(JSONObject.toJSONString(jsonMap)); + notices.setParam3(Constants.ZERO+""); + noticesJoinMapper.insert(notices); return ywStocktaking.getId(); } @Override - public void deleteById(Integer id) { - ywStocktakingMapper.deleteById(id); + @Transactional(rollbackFor = {Exception.class,BusinessException.class}) + public void deleteById(Integer id, LoginUserInfo loginUserInfo) { + YwStocktaking model = ywStocktakingMapper.selectById(id); + if(Objects.isNull(model)){ + throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌鐩樼偣鍗曟暟鎹�"); + } + if(Constants.equalsInteger(model.getStatus(),Constants.ZERO)||Constants.equalsInteger(model.getStatus(),Constants.THREE)){ + ywStocktakingMapper.update(new UpdateWrapper<YwStocktaking>().lambda() + .set(YwStocktaking::getIsdeleted,Constants.ONE) + .set(YwStocktaking::getEditDate,DateUtil.getCurrDateTime()) + .set(YwStocktaking::getEditor,loginUserInfo.getId()) + .eq(YwStocktaking::getId,id) + ); + //鏍囪寰呭姙鍒犻櫎 + noticesJoinMapper.update(null,new UpdateWrapper<Notices>().lambda() + .set(Notices::getIsdeleted,Constants.ONE) + .eq(Notices::getIsdeleted,Constants.ZERO) + .eq(Notices::getObjType,Constants.ZERO) + .eq(Notices::getObjId,id) + ); + }else{ + throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鐩樼偣鍗曠姸鎬佸凡娴佽浆锛屾棤娉曡繘琛岃鎿嶄綔"); + } + } + + @Override + @Transactional(rollbackFor = {Exception.class,BusinessException.class}) + public void cancelById(Integer id, LoginUserInfo loginUserInfo) { + YwStocktaking model = ywStocktakingMapper.selectById(id); + if(Objects.isNull(model)){ + throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌鐩樼偣鍗曟暟鎹�"); + } + if(Constants.equalsInteger(model.getStatus(),Constants.ZERO)||Constants.equalsInteger(model.getStatus(),Constants.ONE)){ + ywStocktakingMapper.update(new UpdateWrapper<YwStocktaking>().lambda() + .set(YwStocktaking::getEditDate,DateUtil.getCurrDateTime()) + .set(YwStocktaking::getCancelDate,DateUtil.getCurrDateTime()) + .set(YwStocktaking::getCancelUserId,loginUserInfo.getId()) + .set(YwStocktaking::getEditor,loginUserInfo.getId()) + .set(YwStocktaking::getStatus,Constants.THREE).eq(YwStocktaking::getId,id)); + //鏍囪寰呭姙鍒犻櫎 + noticesJoinMapper.update(null,new UpdateWrapper<Notices>().lambda() + .set(Notices::getIsdeleted,Constants.ONE) + .eq(Notices::getIsdeleted,Constants.ZERO) + .eq(Notices::getObjType,Constants.ZERO) + .eq(Notices::getObjId,id) + ); + }else{ + throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鐩樼偣鍗曠姸鎬佸凡娴佽浆锛屾棤娉曡繘琛岃鎿嶄綔"); + } + } + + @Override + @Transactional(rollbackFor = {Exception.class,BusinessException.class}) + public void beginById(Integer id, LoginUserInfo loginUserInfo) { + YwStocktaking model = ywStocktakingMapper.selectById(id); + if(Objects.isNull(model)){ + throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌鐩樼偣鍗曟暟鎹�"); + } + if(model.getPlanDate().getTime()>System.currentTimeMillis()){ + throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鏈埌寮�濮嬫椂闂达紝鏃犳硶杩涜璇ユ搷浣�"); + } + if(Constants.equalsInteger(model.getStatus(),Constants.ZERO)&&Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){ + ywStocktakingMapper.update(new UpdateWrapper<YwStocktaking>().lambda() + .set(YwStocktaking::getEditDate,DateUtil.getCurrDateTime()) + .set(YwStocktaking::getDealDate,DateUtil.getCurrDateTime()) + .set(YwStocktaking::getDealUserId,loginUserInfo.getId()) + .set(YwStocktaking::getEditor,loginUserInfo.getId()) + .set(YwStocktaking::getStatus,Constants.ONE) + .eq(YwStocktaking::getId,model.getId())); + + //鏍囪寰呭姙宸插鐞� + noticesJoinMapper.update(null,new UpdateWrapper<Notices>().lambda() + .set(Notices::getParam3,Constants.ONE) + .eq(Notices::getStatus,Constants.ZERO) + .eq(Notices::getIsdeleted,Constants.ZERO) + .eq(Notices::getObjType,Constants.ZERO) + .eq(Notices::getObjId,id) + ); + + //鐢熸垚褰撳墠浠撳簱涓嬫墍鏈夌殑璧勪骇淇℃伅 + List<YwStock> stockList = ywStockMapper.selectList(new QueryWrapper<YwStock>().lambda().eq(YwStock::getIsdeleted,Constants.ZERO).eq(YwStock::getWarehouseId,model.getWarehouseId())); + if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(stockList)){ + List<YwStocktakingRecord> ywStocktakingRecordList = new ArrayList<>(); + for (YwStock ywStock:stockList) { + YwStocktakingRecord ywStocktakingRecord = new YwStocktakingRecord(); + ywStocktakingRecord.setCreator(loginUserInfo.getId()); + ywStocktakingRecord.setCreateDate(new Date()); + ywStocktakingRecord.setIsdeleted(Constants.ZERO); + ywStocktakingRecord.setStatus(Constants.ZERO); + ywStocktakingRecord.setMaterialId(ywStock.getMaterialId()); + ywStocktakingRecord.setUserId(model.getUserId()+""); + ywStocktakingRecord.setStock(ywStock.getStock()); + ywStocktakingRecord.setStocktakingId(model.getId()); + ywStocktakingRecordList.add(ywStocktakingRecord); + } + ywStocktakingRecordMapper.insert(ywStocktakingRecordList); + } + }else{ + throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鐩樼偣鍗曠姸鎬佸凡娴佽浆锛屾棤娉曡繘琛岃鎿嶄綔"); + } + } + + + @Override + @Transactional(rollbackFor = {Exception.class,BusinessException.class}) + public void finishById(Integer id, YwOutinboundServiceImpl ywOutinboundService, LoginUserInfo loginUserInfo) { + YwStocktaking model = ywStocktakingMapper.selectById(id); + if(Objects.isNull(model)){ + throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌鐩樼偣鍗曟暟鎹�"); + } + if(!Constants.equalsInteger(model.getStatus(),Constants.ONE)){ + throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鐩樼偣鍗曠姸鎬佸凡娴佽浆锛屾棤娉曡繘琛岃鎿嶄綔锛�"); + } + if(!Constants.equalsInteger(loginUserInfo.getId(),model.getUserId())){ + throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"闈炴偍鐨勭洏鐐瑰崟鏃犳硶杩涜鎿嶄綔"); + } + List<YwStocktakingRecord> recordList = ywStocktakingRecordMapper.selectList(new QueryWrapper<YwStocktakingRecord>().lambda() + .eq(YwStocktakingRecord::getStocktakingId,id).eq(YwStocktakingRecord::getIsdeleted,Constants.ZERO)); + //鐩樼泩鏁版嵁鍒楄〃 + List<YwOutinboundRecord> inBoundRecordList = new ArrayList<>(); + //鐩樹簭鏁版嵁鍒楄〃 + List<YwOutinboundRecord> outBoundRecordList = new ArrayList<>(); + for (YwStocktakingRecord ywStocktakingRecord:recordList) { + //鎻愪氦鏃� 鏈繘琛岀洏鐐圭殑鏄庣粏鏁版嵁 + if(Constants.equalsInteger(ywStocktakingRecord.getStatus(),Constants.ZERO)){ + ywStocktakingRecordMapper.update(new UpdateWrapper<YwStocktakingRecord>().lambda() + .set(YwStocktakingRecord::getStatus,Constants.TWO) + .set(YwStocktakingRecord::getUserId,loginUserInfo.getId()) + .eq(YwStocktakingRecord::getId,ywStocktakingRecord.getId()) + ); + continue; + } + //鏌ヨ搴撳瓨淇℃伅 杩涜搴撳瓨鏇存柊 + YwStock ywStock = ywStockMapper.selectOne(new QueryWrapper<YwStock>().lambda().eq(YwStock::getMaterialId,ywStocktakingRecord.getMaterialId()) + .eq(YwStock::getWarehouseId,model.getWarehouseId()).eq(YwStock::getStock,ywStocktakingRecord.getStock())); + if(ywStock.getStock().compareTo(ywStocktakingRecord.getActStock())<Constants.ZERO ){ + YwOutinboundRecord ywOutinboundRecord = new YwOutinboundRecord(); + ywOutinboundRecord.setMaterialId(ywStock.getMaterialId()); + ywOutinboundRecord.setStock(ywStocktakingRecord.getActStock().subtract(ywStock.getStock())); + inBoundRecordList.add(ywOutinboundRecord); + }else if(ywStock.getStock().compareTo(ywStocktakingRecord.getActStock())>Constants.ZERO ){ + YwOutinboundRecord ywOutinboundRecord = new YwOutinboundRecord(); + ywOutinboundRecord.setMaterialId(ywStock.getMaterialId()); + ywOutinboundRecord.setStock(ywStock.getStock().subtract(ywStocktakingRecord.getActStock())); + outBoundRecordList.add(ywOutinboundRecord); + } +// if(Objects.isNull(ywStock)){ +// throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"搴撳瓨淇℃伅寮傚父锛岃鑱旂郴绠$悊鍛�"); +// } +// if(ywStocktakingRecord.getActStock().compareTo(BigDecimal.ZERO)==Constants.ZERO){ +// ywStockMapper.deleteById(ywStock.getId()); +// }else { +// ywStockMapper.update(new UpdateWrapper<YwStock>().lambda().set(YwStock::getStock,ywStocktakingRecord.getActStock()).eq(YwStock::getId,ywStock.getId())); +// } + } + ywStocktakingMapper.update(new UpdateWrapper<YwStocktaking>().lambda() + .set(YwStocktaking::getEditDate,DateUtil.getCurrDateTime()) + .set(YwStocktaking::getDoneDate,DateUtil.getCurrDateTime()) + .set(YwStocktaking::getDoneUserId,loginUserInfo.getId()) + .set(YwStocktaking::getEditor,loginUserInfo.getId()) + .set(YwStocktaking::getStatus,Constants.TWO) + .eq(YwStocktaking::getId,model.getId())); + //鐢熶骇鐩樼泩鐨勫叆搴撳崟 + if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(inBoundRecordList)){ + YwOutinbound ywOutinbound = new YwOutinbound(); + ywOutinbound.setDoneDate(new Date()); + ywOutinbound.setWarehouseId(model.getWarehouseId()); + ywOutinbound.setType(4); + ywOutinbound.setOrigin(1); + ywOutinbound.setContent("鐩樼偣鍗曘��"+model.getCode() +"銆戝鐞嗙敓鎴愮洏鐩堟暟鎹�"); + ywOutinbound.setStatus(Constants.ZERO); + ywOutinbound.setRecordList(inBoundRecordList); + ywOutinbound.setLoginUserInfo(loginUserInfo); + ywOutinboundService.create(ywOutinbound); + } + if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(outBoundRecordList)){ + YwOutinbound ywOutinbound = new YwOutinbound(); + ywOutinbound.setDoneDate(new Date()); + ywOutinbound.setWarehouseId(model.getWarehouseId()); + ywOutinbound.setType(10); + ywOutinbound.setOrigin(1); + ywOutinbound.setContent("鐩樼偣鍗曘��"+model.getCode() +"銆戝鐞嗙敓鎴愮洏浜忔暟鎹�"); + ywOutinbound.setStatus(Constants.ZERO); + ywOutinbound.setRecordList(outBoundRecordList); + ywOutinbound.setLoginUserInfo(loginUserInfo); + ywOutinboundService.create(ywOutinbound); + } + + //鏍囪寰呭姙宸插畬鎴� + noticesJoinMapper.update(null,new UpdateWrapper<Notices>().lambda() + .set(Notices::getStatus,Constants.ONE) + .set(Notices::getParam3,Constants.TWO) + .eq(Notices::getIsdeleted,Constants.ZERO) + .eq(Notices::getObjType,Constants.ZERO) + .eq(Notices::getObjId,id) + ); + } @Override @@ -54,7 +341,73 @@ @Override public void updateById(YwStocktaking ywStocktaking) { + if(Objects.isNull(ywStocktaking) + || StringUtils.isBlank(ywStocktaking.getName()) + || Objects.isNull(ywStocktaking.getId()) + || Objects.isNull(ywStocktaking.getPlanDate()) + || Objects.isNull(ywStocktaking.getWarehouseId()) + || Objects.isNull(ywStocktaking.getUserId()) + ){ + throw new BusinessException(ResponseStatus.BAD_REQUEST); + } + YwStocktaking model = ywStocktakingMapper.selectById(ywStocktaking.getId()); + if(Objects.isNull(model)){ + throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌鐩樼偣鍗曟暟鎹�"); + } + + SystemUser systemUser = systemUserMapper.selectById(ywStocktaking.getUserId()); + if(Objects.isNull(systemUser)){ + throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌鐩樼偣浜轰俊鎭�"); + } + + YwWarehouse ywWarehouse = ywWarehouseMapper.selectById(ywStocktaking.getWarehouseId()); + if(Objects.isNull(ywWarehouse)){ + throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌浠撳簱鏁版嵁"); + } + //鍒ゆ柇褰撳墠浠撳簱褰撳墠鏃ユ湡鏄惁瀛樺湪鐩樼偣鍗� + if(ywStocktakingMapper.selectCount(new QueryWrapper<YwStocktaking>().lambda().ne(YwStocktaking::getId,ywStocktaking.getId()).eq(YwStocktaking::getIsdeleted,Constants.ZERO).eq(YwStocktaking::getStatus,Constants.ZERO) + .eq(YwStocktaking::getWarehouseId,ywStocktaking.getWarehouseId()).apply(" DATE(PLAN_DATE) = '" + DateUtil.formatDate(ywStocktaking.getPlanDate(),"yyyy-MM-dd") +"'" ))>0){ + throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"["+DateUtil.formatDate(ywStocktaking.getPlanDate(),"yyyy-MM-dd")+"]["+ywWarehouse.getName()+"]宸叉湁鐩樼偣鍗曪紝涓嶅彲閲嶅鍙戣捣鐩樼偣"); + } + LoginUserInfo loginUserInfo = ywStocktaking.getLoginUserInfo(); + ywStocktaking.setEditor(loginUserInfo.getId()); + ywStocktaking.setEditDate(new Date()); + ywStocktaking.setCode(null); ywStocktakingMapper.updateById(ywStocktaking); + + + //鏍囪寰呭姙宸插鐞� + noticesJoinMapper.update(null,new UpdateWrapper<Notices>().lambda() + .set(Notices::getStatus,Constants.ONE) + .eq(Notices::getIsdeleted,Constants.ONE) + .eq(Notices::getObjType,Constants.ZERO) + .eq(Notices::getObjId,ywStocktaking.getId()) + ); + + //娣诲姞寰呭姙淇℃伅 + Notices notices = new Notices(); + notices.setCreateDate(new Date()); + notices.setCreator(ywStocktaking.getCreator()); + notices.setIsdeleted(Constants.ZERO); + notices.setParam1(DateUtil.formatDate(ywStocktaking.getPlanDate(),"yyyy-MM-dd")); + notices.setTitle("鐩樼偣寰呭姙"); + notices.setContent("["+ywStocktaking.getName()+"]灏嗗湪["+notices.getParam1()+"]杩涜鐩樼偣锛岃鎸夋椂鎵ц"); + notices.setObjId(ywStocktaking.getId()); + notices.setObjType(Constants.ZERO); + notices.setType(notices.getObjType()); + notices.setUserId(ywStocktaking.getUserId()); + notices.setStatus(Constants.ZERO); + //鏁寸悊json鏁版嵁 + Map<String,Object> jsonMap = new HashMap<>(); + jsonMap.put("key1","鐩樼偣鍗�"+ywStocktaking.getCode()); + jsonMap.put("key2", DateUtil.getFomartDate(ywStocktaking.getPlanDate(),"yyyy-MM-dd")); + jsonMap.put("key3", ywWarehouse.getName()); + jsonMap.put("key4", systemUser.getRealname()); + notices.setParam2(JSONObject.toJSONString(jsonMap)); + notices.setParam3(Constants.ZERO+""); + noticesJoinMapper.insert(notices); + + } @Override @@ -73,6 +426,31 @@ } @Override + public YwStocktaking getDetail(Integer id) { + MPJLambdaWrapper<YwStocktaking> queryWrapper = new MPJLambdaWrapper<>(); + queryWrapper.selectAll(YwStocktaking.class) + .select(" s.realname ", YwStocktaking::getUserName) + .select(" s1.realname ",YwStocktaking::getCreateName) + .selectAs(YwWarehouse::getName,YwStocktaking::getWarehouseName) + .leftJoin(YwWarehouse.class,YwWarehouse::getId,YwStocktaking::getWarehouseId) + .leftJoin("system_user s on t.user_id = s.id") + .leftJoin("system_user s1 on t.creator = s1.id") + .eq(YwStocktaking::getId,id) + .last("limit 1"); + YwStocktaking ywStocktaking = ywStocktakingMapper.selectOne(queryWrapper); + List<YwStocktakingRecord> recordList = ywStocktakingRecordMapper.selectList(new QueryWrapper<YwStocktakingRecord>().lambda().eq(YwStocktakingRecord::getStocktakingId,id).eq(YwStocktakingRecord::getIsdeleted,Constants.ZERO)); + if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(recordList)){ + //鍚堣鐩樼偣鏁版嵁 + ywStocktaking.setFinishAmount(recordList.stream().filter(i->Constants.equalsInteger(i.getStatus(),Constants.ONE)).collect(Collectors.toList()).size()); + ywStocktaking.setUnFinishAmount(recordList.stream().filter(i->Constants.equalsInteger(i.getStatus(),Constants.TWO)).collect(Collectors.toList()).size()); + ywStocktaking.setEqualAmount(recordList.stream().filter(i->Constants.equalsInteger(i.getStatus(),Constants.ONE)&&Constants.equalsInteger(i.getType(),Constants.ZERO)).collect(Collectors.toList()).size()); + ywStocktaking.setLossAmount(recordList.stream().filter(i->Constants.equalsInteger(i.getStatus(),Constants.ONE)&&Constants.equalsInteger(i.getType(),Constants.ONE)).collect(Collectors.toList()).size()); + ywStocktaking.setProfitAmount(recordList.stream().filter(i->Constants.equalsInteger(i.getStatus(),Constants.ONE)&&Constants.equalsInteger(i.getType(),Constants.TWO)).collect(Collectors.toList()).size()); + } + return ywStocktaking; + } + + @Override public YwStocktaking findOne(YwStocktaking ywStocktaking) { QueryWrapper<YwStocktaking> wrapper = new QueryWrapper<>(ywStocktaking); return ywStocktakingMapper.selectOne(wrapper); @@ -87,103 +465,25 @@ @Override public PageData<YwStocktaking> findPage(PageWrap<YwStocktaking> pageWrap) { IPage<YwStocktaking> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); - QueryWrapper<YwStocktaking> queryWrapper = new QueryWrapper<>(); + MPJLambdaWrapper<YwStocktaking> queryWrapper = new MPJLambdaWrapper<>(); Utils.MP.blankToNull(pageWrap.getModel()); - if (pageWrap.getModel().getId() != null) { - queryWrapper.lambda().eq(YwStocktaking::getId, pageWrap.getModel().getId()); - } - if (pageWrap.getModel().getCreator() != null) { - queryWrapper.lambda().eq(YwStocktaking::getCreator, pageWrap.getModel().getCreator()); - } - if (pageWrap.getModel().getCreateDate() != null) { - queryWrapper.lambda().ge(YwStocktaking::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate())); - queryWrapper.lambda().le(YwStocktaking::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate())); - } - if (pageWrap.getModel().getEditor() != null) { - queryWrapper.lambda().eq(YwStocktaking::getEditor, pageWrap.getModel().getEditor()); - } - if (pageWrap.getModel().getEditDate() != null) { - queryWrapper.lambda().ge(YwStocktaking::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate())); - queryWrapper.lambda().le(YwStocktaking::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate())); - } - if (pageWrap.getModel().getIsdeleted() != null) { - queryWrapper.lambda().eq(YwStocktaking::getIsdeleted, pageWrap.getModel().getIsdeleted()); - } - if (pageWrap.getModel().getPosition() != null) { - queryWrapper.lambda().eq(YwStocktaking::getPosition, pageWrap.getModel().getPosition()); - } - if (pageWrap.getModel().getRemark() != null) { - queryWrapper.lambda().eq(YwStocktaking::getRemark, pageWrap.getModel().getRemark()); - } - if (pageWrap.getModel().getStatus() != null) { - queryWrapper.lambda().eq(YwStocktaking::getStatus, pageWrap.getModel().getStatus()); - } - if (pageWrap.getModel().getUserId() != null) { - queryWrapper.lambda().eq(YwStocktaking::getUserId, pageWrap.getModel().getUserId()); - } - if (pageWrap.getModel().getPlanDate() != null) { - queryWrapper.lambda().ge(YwStocktaking::getPlanDate, Utils.Date.getStart(pageWrap.getModel().getPlanDate())); - queryWrapper.lambda().le(YwStocktaking::getPlanDate, Utils.Date.getEnd(pageWrap.getModel().getPlanDate())); - } - if (pageWrap.getModel().getCode() != null) { - queryWrapper.lambda().eq(YwStocktaking::getCode, pageWrap.getModel().getCode()); - } - if (pageWrap.getModel().getDealUserId() != null) { - queryWrapper.lambda().eq(YwStocktaking::getDealUserId, pageWrap.getModel().getDealUserId()); - } - if (pageWrap.getModel().getDealDate() != null) { - queryWrapper.lambda().ge(YwStocktaking::getDealDate, Utils.Date.getStart(pageWrap.getModel().getDealDate())); - queryWrapper.lambda().le(YwStocktaking::getDealDate, Utils.Date.getEnd(pageWrap.getModel().getDealDate())); - } - if (pageWrap.getModel().getDealInfo() != null) { - queryWrapper.lambda().eq(YwStocktaking::getDealInfo, pageWrap.getModel().getDealInfo()); - } - if (pageWrap.getModel().getDoneNum() != null) { - queryWrapper.lambda().eq(YwStocktaking::getDoneNum, pageWrap.getModel().getDoneNum()); - } - if (pageWrap.getModel().getWaitNum() != null) { - queryWrapper.lambda().eq(YwStocktaking::getWaitNum, pageWrap.getModel().getWaitNum()); - } - if (pageWrap.getModel().getTotalNum() != null) { - queryWrapper.lambda().eq(YwStocktaking::getTotalNum, pageWrap.getModel().getTotalNum()); - } - if (pageWrap.getModel().getProfitNum() != null) { - queryWrapper.lambda().eq(YwStocktaking::getProfitNum, pageWrap.getModel().getProfitNum()); - } - if (pageWrap.getModel().getLossNum() != null) { - queryWrapper.lambda().eq(YwStocktaking::getLossNum, pageWrap.getModel().getLossNum()); - } - if (pageWrap.getModel().getEqualNum() != null) { - queryWrapper.lambda().eq(YwStocktaking::getEqualNum, pageWrap.getModel().getEqualNum()); - } - if (pageWrap.getModel().getDoneUserId() != null) { - queryWrapper.lambda().eq(YwStocktaking::getDoneUserId, pageWrap.getModel().getDoneUserId()); - } - if (pageWrap.getModel().getDoneDate() != null) { - queryWrapper.lambda().ge(YwStocktaking::getDoneDate, Utils.Date.getStart(pageWrap.getModel().getDoneDate())); - queryWrapper.lambda().le(YwStocktaking::getDoneDate, Utils.Date.getEnd(pageWrap.getModel().getDoneDate())); - } - if (pageWrap.getModel().getDoneInfo() != null) { - queryWrapper.lambda().eq(YwStocktaking::getDoneInfo, pageWrap.getModel().getDoneInfo()); - } - if (pageWrap.getModel().getCancelUserId() != null) { - queryWrapper.lambda().eq(YwStocktaking::getCancelUserId, pageWrap.getModel().getCancelUserId()); - } - if (pageWrap.getModel().getCancelDate() != null) { - queryWrapper.lambda().ge(YwStocktaking::getCancelDate, Utils.Date.getStart(pageWrap.getModel().getCancelDate())); - queryWrapper.lambda().le(YwStocktaking::getCancelDate, Utils.Date.getEnd(pageWrap.getModel().getCancelDate())); - } - if (pageWrap.getModel().getCancelInfo() != null) { - queryWrapper.lambda().eq(YwStocktaking::getCancelInfo, pageWrap.getModel().getCancelInfo()); - } - for(PageWrap.SortData sortData: pageWrap.getSorts()) { - if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { - queryWrapper.orderByDesc(sortData.getProperty()); - } else { - queryWrapper.orderByAsc(sortData.getProperty()); - } - } - return PageData.from(ywStocktakingMapper.selectPage(page, queryWrapper)); + YwStocktaking model = pageWrap.getModel(); + queryWrapper.selectAll(YwStocktaking.class) + .select(" s.realname ", YwStocktaking::getUserName) + .select(" s1.realname ",YwStocktaking::getCreateName) + .selectAs(YwWarehouse::getName,YwStocktaking::getWarehouseName) + .leftJoin(YwWarehouse.class,YwWarehouse::getId,YwStocktaking::getWarehouseId) + .leftJoin("system_user s on t.user_id = s.id") + .leftJoin("system_user s1 on t.creator = s1.id") + .eq(YwStocktaking::getIsdeleted,Constants.ZERO) + .like(StringUtils.isNotBlank(model.getName()),YwStocktaking::getName,model.getName()) + .eq(Objects.nonNull(model.getStatus()),YwStocktaking::getStatus,model.getStatus()) + .eq(Objects.nonNull(model.getUserId()),YwStocktaking::getUserId,model.getUserId()) + .orderByAsc(YwStocktaking::getStatus) + .orderByDesc(YwStocktaking::getPlanDate) + ; + IPage iPage = ywStocktakingMapper.selectJoinPage(page, YwStocktaking.class,queryWrapper); + return PageData.from(iPage); } @Override @@ -191,4 +491,19 @@ QueryWrapper<YwStocktaking> wrapper = new QueryWrapper<>(ywStocktaking); return ywStocktakingMapper.selectCount(wrapper); } + + + public synchronized String getNextCode(){ + String prefix = "PD-" + DateUtil.getDate(new Date(),"yyyyMMdd") +"-"; + Integer countNum = RedisUtil.getObject(redisTemplate, + Constants.RedisKeys.COM_OUTBOUND_TAKING_KEY, + Integer.class); + countNum = Constants.formatIntegerNum(countNum)+1; + //鏇存柊缂撳瓨 + RedisUtil.addObject(redisTemplate, Constants.RedisKeys.COM_OUTBOUND_TAKING_KEY,countNum); + String nextIndex =Integer.toString( countNum ); + return prefix + org.apache.commons.lang3.StringUtils.leftPad(nextIndex,4,"0"); + } + + } -- Gitblit v1.9.3