From 585e878b169bdeb2bc8cc452b9d2e640d00caa6d Mon Sep 17 00:00:00 2001 From: YYC <1833023622@qq.com> Date: 星期二, 04 七月 2023 09:00:35 +0800 Subject: [PATCH] 质检报告 --- igds-inout/src/main/java/com/ld/igds/inout/service/impl/InoutServiceImpl.java | 443 ++++++++++++++++++++++++++++-------------------------- 1 files changed, 230 insertions(+), 213 deletions(-) diff --git a/igds-inout/src/main/java/com/ld/igds/inout/service/impl/InoutServiceImpl.java b/igds-inout/src/main/java/com/ld/igds/inout/service/impl/InoutServiceImpl.java index 4df6212..e56e76a 100644 --- a/igds-inout/src/main/java/com/ld/igds/inout/service/impl/InoutServiceImpl.java +++ b/igds-inout/src/main/java/com/ld/igds/inout/service/impl/InoutServiceImpl.java @@ -1,7 +1,6 @@ package com.ld.igds.inout.service.impl; import com.bstek.dorado.data.entity.EntityUtils; -import com.ld.igds.check.dto.CheckItemData; import com.ld.igds.common.CoreCommonService; import com.ld.igds.constant.BizType; import com.ld.igds.constant.Constant; @@ -9,16 +8,17 @@ import com.ld.igds.data.CommonData; import com.ld.igds.data.Page; import com.ld.igds.inout.InoutConstant; +import com.ld.igds.inout.dto.InoutCheckData; +import com.ld.igds.inout.dto.InoutCheckParam; import com.ld.igds.inout.dto.InoutData; import com.ld.igds.inout.dto.InoutParam; +import com.ld.igds.inout.mapper.InoutCheckMapper; import com.ld.igds.inout.mapper.InoutRecordMapper; import com.ld.igds.inout.service.InoutService; -import com.ld.igds.io.constant.OrderRespEnum; -import com.ld.igds.models.Depot; +import com.ld.igds.models.InoutPrice; import com.ld.igds.util.ContextUtil; import com.ld.igds.util.DateUtil; import com.ld.igds.util.RedisUtil; -import com.ld.igds.websocket.WebSocketPacket; import com.ld.igds.websocket.WebSocketServer; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -39,6 +39,8 @@ @Resource private InoutRecordMapper inoutMapper; @Resource + private InoutCheckMapper inoutCheckMapper; + @Resource private RedisUtil redisUtil; @Resource private CoreCommonService commonService; @@ -48,6 +50,7 @@ if (StringUtils.isEmpty(param.getCompanyId())) { param.setCompanyId(ContextUtil.getCompanyId()); } + // 棣栧厛浠庣紦瀛樹腑鑾峰彇锛屽鏋滄病鏈夊垯浠庢暟鎹簱鑾峰彇 InoutData result = this.getFromInoutCache(param); if (null != result) { @@ -92,24 +95,26 @@ return "娌℃湁鑾峰彇鍒拌鍒犻櫎鏁版嵁鐨処D锛屾棤娉曞垹闄わ紒"; } - // 缂撳瓨涓垹闄� - this.delInoutFromCache(param.getDeptId(), param.getType(), param.getId(), false); - inoutMapper.deleteData(param); + + delFromCache(param.getDeptId(), param.getType(), param.getId()); return null; } @Override - public String inoutStop(InoutParam param) { + public String inoutStop(InoutParam param) throws Exception { if (StringUtils.isEmpty(param.getCompanyId())) { - param.setCompanyId(ContextUtil.getCompanyId()); + param.setCompanyId(ContextUtil.getDefaultCompanyId()); } - // 缂撳瓨涓垹闄� - this.delInoutFromCache(param.getDeptId(), param.getType(), param.getId(), false); + param.setProgress(InoutConstant.PROGRESS_RECORD); - param.setRecordStatus(InoutConstant.RECORD_STATUS_ERROR); + param.setRecordStatus(InoutConstant.RECORD_STATUS_DEL); + + + // 缂撳瓨涓垹闄� + delFromCache(param.getDeptId(), param.getType(), param.getId()); inoutMapper.inoutStop(param); @@ -118,65 +123,61 @@ @Override public String insertData(InoutData data) { + try { + data.setUpdateTime(new Date()); - if (StringUtils.isEmpty(data.getCompanyId())) { - data.setCompanyId(ContextUtil.getCompanyId()); - } + if (null == data.getDeptId()) { + data.setDeptId(ContextUtil.subDeptId(null)); + } - // 鑾峰彇褰撳墠浠撳簱鐨勫疄闄呭簱瀛� - if (StringUtils.isNotEmpty(data.getDepotId())) { - if (null == data.getFoodYear() || null == data.getFoodType()) { - Depot depot = commonService.getCacheDepot(data.getCompanyId(), data.getDepotId()); - if (null == data.getFoodYear()) { - data.setFoodYear(depot.getFoodYear()); - } - if (null == data.getFoodType()) { - data.setFoodType(depot.getFoodType()); + String id = this.createId(data.getRegisterTime(), data.getCompanyId()); + if (StringUtils.isEmpty(data.getId())) { + if (InoutConstant.TYPE_IN.equals(data.getType())) { + data.setId("R_" + id); + } else if (InoutConstant.TYPE_OUT.equals(data.getType())) { + data.setId("C_" + id); + } else if (Constant.LOSS_OVER_OVER.equals(data.getType())) { + data.setId("R_" + id); + } else if (Constant.LOSS_OVER_LOSS.equals(data.getType())) { + data.setId("C_" + id); + } else { + data.setId("M_" + id); } } - } - - if (null == data.getRegisterTime()) { - data.setRegisterTime(new Date()); - } - - String id = this.createId(data.getRegisterTime(), data.getCompanyId()); - - if (StringUtils.isEmpty(data.getId())) { - if (InoutConstant.TYPE_IN.equals(data.getType())) { - data.setId("R_" + id); - } else if (InoutConstant.TYPE_OUT.equals(data.getType())) { - data.setId("C_" + id); - } else if (Constant.LOSS_OVER_OVER.equals(data.getType())) { - data.setId("R_" + id); - } else if (Constant.LOSS_OVER_LOSS.equals(data.getType())) { - data.setId("C_" + id); - } else { - data.setId("M_" + id); + if (StringUtils.isEmpty(data.getCheckId())) { + data.setCheckId(id); } - } - if (StringUtils.isEmpty(data.getCheckId())) { - data.setCheckId(id); - } - if (null == data.getDeptId()) { - data.setDeptId(ContextUtil.subDeptId(null)); - } - if (null == data.getUserName()) { - data.setUserName(""); + + if (null == data.getUserName()) { + data.setUserName(""); + } + + InoutData newData; + if (EntityUtils.isEntity(data)) { + newData = new InoutData(); + BeanUtils.copyProperties(data, newData, new String[]{"checkItems", "files"}); + }else{ + newData = data; + } + + inoutMapper.insertData(newData); + + + updateInoutCache(newData); + + } catch (Exception e) { + log.error("------------鍑哄叆搴撴墽琛屼繚瀛樺嚭閿�---{}", e); + return "鍚庡彴寮傚父锛�" + e.getMessage(); } - inoutMapper.insertData(data); - - // 濡傛灉涓嶆槸鎵嬪姩琛ュ綍鐨勬暟鎹紝娣诲姞鍒扮紦瀛樹腑 - if (!InoutConstant.RECORD_STATUS_ADD.equals(data.getRecordStatus())) { - this.addInoutCache(data); - } return null; } @Override public String updateData(InoutData data) throws Exception { + + data.setUpdateTime(new Date()); if (StringUtils.isEmpty(data.getCompanyId())) { data.setCompanyId(ContextUtil.getCompanyId()); } @@ -190,17 +191,31 @@ inoutMapper.updateData(newData); - //濡傛灉鏄畬鎴愮姸鎬佷笉鍦ㄨ繘琛屽悗鏈熷鐞嗭紝鍗曠嫭璧癱omplete鏂规硶 - if (InoutConstant.PROGRESS_RECORD.equals(newData.getProgress())) { - return null; + //鏇存柊缂撳瓨 + updateInoutCache(newData); + + return null; + } + + @Override + public String updateDataByHandle(InoutData data) { + data.setUpdateTime(new Date()); + + if (StringUtils.isEmpty(data.getCompanyId())) { + data.setCompanyId(ContextUtil.getCompanyId()); + } + InoutData newData; + if (EntityUtils.isEntity(data)) { + newData = new InoutData(); + BeanUtils.copyProperties(data, newData, new String[]{"checkItems", "files"}); + } else { + newData = data; } - // 鏇存柊绶╁瓨 - if (InoutConstant.PROGRESS_RECORD.equals(newData.getProgress())) { - this.delInoutFromCache(newData.getDeptId(), newData.getType(), newData.getId(), true); - } else { - this.updateInoutCache(newData); - } + inoutMapper.updateDataByHandle(newData); + + //鏇存柊缂撳瓨 + updateInoutCache(newData); return null; } @@ -232,11 +247,15 @@ param.setUserId("%" + param.getUserId() + "%"); } + if (null != param.getRecordStatus() && InoutConstant.RECORD_STATUS_NORMAL.equals(param.getRecordStatus())) { + param.setRecordStatus(null); + } + List<InoutData> records = inoutMapper.pageRecordData(page, param); //鍒ゆ柇鍏ュ簱閲嶉噺鏄惁涓虹┖锛屼负绌哄垯璧嬪�肩粨绠楅噸閲� - if(records != null){ + if (records != null) { for (InoutData record : records) { - if(record.getRecordWeight() == null || record.getRecordWeight() == 0.0){ + if (record.getRecordWeight() == null || record.getRecordWeight() == 0.0) { record.setRecordWeight(record.getSettleWeight()); } } @@ -256,16 +275,6 @@ return records; } -// @Override -// public InoutData getLastRecord(InoutParam param) { -// return inoutMapper.getLastRecord(param); -// } - -// @Override -// public int updateCuStorage(InoutParam param) { -// return inoutMapper.updateCuStorage(param); -// } - @Override public String validate(String intelCard, String plateNum) { InoutParam param = new InoutParam(); @@ -284,27 +293,25 @@ @Override public String toComplete(InoutParam param) throws Exception { - if (null == param.getCompanyId()) { - param.setCompanyId(ContextUtil.getCompanyId()); - } + param.setUpdateTime(new Date()); - if (null == param.getFoodType()) { - // 鏍规嵁浠撳簱淇℃伅鑾峰彇缂撳瓨 - Depot depot = commonService.getCacheDepot(param.getCompanyId(), param.getDepotId()); - param.setFoodType(depot.getFoodType()); + if (null == param.getCompanyId()) { + param.setCompanyId(ContextUtil.getDefaultCompanyId()); } // 娓呴櫎缂撳瓨 - this.delInoutFromCache(param.getDeptId(), param.getType(), param.getId(), true); + this.delFromCache(param.getDeptId(), param.getType(), param.getId()); + inoutMapper.toComplete(param); + return null; } @Override public String quickComplete(InoutData data) throws Exception { if (null == data.getCompanyId()) { - data.setCompanyId(ContextUtil.getCompanyId()); + data.setCompanyId(ContextUtil.getDefaultCompanyId()); } if (null == data.getCompleteTime()) { data.setCompleteTime(new Date()); @@ -315,7 +322,6 @@ if (null == data.getEmptyWeightTime()) { data.setEmptyWeightTime(new Date()); } - //璋冩暣鏃堕棿宸� if (InoutConstant.TYPE_IN.equals(data.getType())) { @@ -344,50 +350,34 @@ // 璁剧疆娴佺▼缁撴潫 data.setProgress(InoutConstant.PROGRESS_RECORD); - - if (null == data.getFoodType()) { - // 鏍规嵁浠撳簱淇℃伅鑾峰彇缂撳瓨 - Depot depot = commonService.getCacheDepot(data.getCompanyId(), data.getDepotId()); - data.setFoodType(depot.getFoodType()); - } - - // 娓呴櫎缂撳瓨 - this.delInoutFromCache(data.getDeptId(), data.getType(), data.getId(), false); - + //鎵ц鏇存柊 inoutMapper.updateData(data); + + //鏇存柊缂撳瓨 + updateInoutCache(data); return null; } @Override - public void addInoutCache(InoutData data) { - data.setFiles(null); - data.setCheckItems(null); - - this.setInoutCache(data.getDeptId(), data); - - // 鎺ㄩ�佸埌澶у睆 - List<InoutData> list = this.getListInoutCache(data.getDeptId()); - - this.notifyToScreen(data.getDeptId(), list, null); - } - - @Override public void updateInoutCache(InoutData data) { + data.setFiles(null); data.setCheckItems(null); - this.setInoutCache(data.getDeptId(), data); + if (InoutConstant.PROGRESS_RECORD.equals(data.getProgress())) { - // 鎺ㄩ�佸埌澶у睆 - List<InoutData> list = this.getListInoutCache(data.getDeptId()); - List<InoutData> completeList = this.getCompleteListInoutCache(data.getDeptId()); + delFromCache(data.getDeptId(), data.getType(), data.getId()); - this.notifyToScreen(data.getCompanyId(), list, completeList); + setCompleteInoutCache(data.getDeptId(), data); + + } else { + setInoutCache(data.getDeptId(), data); + } } - @Override - public void delInoutFromCache(String deptId, String type, String id, boolean addToComplete) { + + public void delFromCache(String deptId, String type, String id) { if (StringUtils.isEmpty(deptId)) { return; } @@ -397,44 +387,14 @@ if (StringUtils.isEmpty(id)) { return; } - //鍒犻櫎鏈畬鎴愭祦绋嬬殑缂撳瓨 + //浠庢湭瀹屾垚鍒楄〃涓垹闄� String key = this.buildInoutKey(deptId, InoutConstant.KEY_INOUT_LIST, type, id); - InoutData inoutData = (InoutData) redisUtil.get(key); redisUtil.del(key); - List<InoutData> list = this.getListInoutCache(deptId); - - //鍒犻櫎宸插畬鎴愭祦绋嬬殑缂撳瓨 - key = this.buildInoutKey(deptId, InoutConstant.KEY_INOUT_COMPLETE_LIST, type, id); - redisUtil.del(key); - List<InoutData> completeList = this.getCompleteListInoutCache(deptId); - - if (addToComplete) { - addInoutCompleteCache(inoutData); - completeList = this.getCompleteListInoutCache(deptId); - } - - // 閫氱煡鍒板ぇ灞� - notifyToScreen(deptId, list, completeList); - } - - /** - * 娣诲姞鍒板凡缁忓畬鎴愮殑闃熷垪涓� - * - * @param data - */ - public void addInoutCompleteCache(InoutData data) { - - if (null == data.getCompleteTime()) { - data.setCompleteTime(new Date()); - } - if (!InoutConstant.PROGRESS_RECORD.equals(data.getProgress())) { - data.setProgress(InoutConstant.PROGRESS_RECORD); - } - this.setCompleteInoutCache(data.getDeptId(), data); } @Override public List<InoutData> getListInoutCache(String deptId) { + String pattern = RedisConst.buildKey(deptId, InoutConstant.KEY_INOUT_LIST); Set<String> keys = redisUtil.keys(pattern); if (null == keys || keys.isEmpty()) { @@ -467,6 +427,7 @@ if (StringUtils.isEmpty(param.getDeptId())) { param.setDeptId(ContextUtil.subDeptId(null)); } + List<InoutData> list = getListInoutCache(param.getDeptId()); if (null == list || list.isEmpty()) return null; @@ -490,35 +451,6 @@ } } return null; - } - - @Override - public void initInoutScreen(String deptId) { - if (null == deptId) { - deptId = ContextUtil.subDeptId(null); - } - - List<InoutData> curList = this.getListInoutCache(deptId); - List<InoutData> complateList = this.getCompleteListInoutCache(deptId); - - notifyToScreen(deptId, curList, complateList); - - } - - @Override - public void notifyWeb(InoutData result) { - // 濡傛灉褰撳墠涓烘弧杞︾О閲嶆墽琛屾帹閫� - if (result.getType().equals(InoutConstant.TYPE_IN) && result.getProgress().equals(InoutConstant.PROGRESS_WEIGHT_FULL)) { - WebSocketPacket packet = new WebSocketPacket(); - packet.setBizType(BizType.SCREEN_CHECK.getCode()); - packet.setCompanyId(result.getCompanyId()); - packet.setOrderResp(OrderRespEnum.MSG_SUCCESS.getCode()); - packet.setData(result); - packet.setBizTag(InoutConstant.PROGRESS_WEIGHT_FULL); - log.debug("----鍚戝寲楠屽ぇ灞忔帹閫佹弧杞︾О閲嶄俊鎭� ----{}", result.getPlateNum()); - WebSocketServer.sendByBizTag(packet); - } - } @Override @@ -554,10 +486,7 @@ } @Override - public InoutData getLastRecord(String companyId, String depotId) { - InoutParam param = new InoutParam(); - param.setCompanyId(companyId); - param.setDepotId(depotId); + public InoutData getLastRecord(InoutParam param) { return inoutMapper.getLastRecord(param); } @@ -565,16 +494,16 @@ public String addInoutDataByLossOver(InoutData data) { // 鑾峰彇涓婁竴杞︾殑娴佹按鏁版嵁 - InoutData inoutData = this.getLastRecord(data.getCompanyId(), data.getDepotId()); + // InoutData inoutData = this.getLastRecord(data.getCompanyId(), data.getDepotId()); - // 璁剧疆娴佹按鐨勫簱瀛� - if (InoutConstant.TYPE_IN.equals(inoutData.getType())) { - data.setCurStorage(inoutData.getCurStorage() - + inoutData.getSettleWeight()); - } else if (InoutConstant.TYPE_OUT.equals(inoutData.getType())) { - data.setCurStorage(inoutData.getCurStorage() - - inoutData.getSettleWeight()); - } +// // 璁剧疆娴佹按鐨勫簱瀛� +// if (InoutConstant.TYPE_IN.equals(inoutData.getType())) { +// data.setCurStorage(inoutData.getCurStorage() +// + inoutData.getSettleWeight()); +// } else if (InoutConstant.TYPE_OUT.equals(inoutData.getType())) { +// data.setCurStorage(inoutData.getCurStorage() +// - inoutData.getSettleWeight()); +// } // 娣诲姞琛ュ崟鏁版嵁 this.insertData(data); @@ -596,12 +525,6 @@ redisUtil.set(cacheKey, data.getCheckItems(), 60 * 60 * 24 * 3); } - @SuppressWarnings("unchecked") - @Override - public List<CheckItemData> getCheckCache(String companyId, String checkId) { - String cacheKey = RedisConst.buildKey(companyId, checkId); - return (List<CheckItemData>) redisUtil.get(cacheKey); - } /** * 鍑哄叆搴撴祦绋婭D鍒涘缓 202001030001 202001030001 @@ -677,6 +600,11 @@ return result.getNumValue1(); } + @Override + public int checkExist(InoutParam param) { + return inoutMapper.checkExist(param); + } + /** * 鏈畬鎴愭祦绋嬪瓨鍏ョ紦瀛� * @@ -684,9 +612,7 @@ * @param data */ private void setInoutCache(String deptId, InoutData data) { - String key = this.buildInoutKey(deptId, - InoutConstant.KEY_INOUT_LIST, data.getType(), data.getId()); - + String key = this.buildInoutKey(deptId, InoutConstant.KEY_INOUT_LIST, data.getType(), data.getId()); redisUtil.set(key, data, InoutConstant.KEY_INOUT_LIST_TIME); } @@ -698,7 +624,6 @@ */ private void setCompleteInoutCache(String deptId, InoutData data) { String key = this.buildInoutKey(deptId, InoutConstant.KEY_INOUT_COMPLETE_LIST, data.getType(), data.getId()); - //璁剧疆缂撳瓨鍒扮浜屽ぉ鍑屾櫒(璁$畻褰撳墠鏃堕棿鍒扮浜屽ぉ鍑屾櫒鐨勬椂闂村樊绉掓暟) redisUtil.set(key, data, DateUtil.getNowToNextDaySeconds()); } @@ -706,12 +631,17 @@ /** * 鎺ㄩ�佸埌澶у睆锛屽垽鏂彧鏈夊綋澶у睆鍦ㄧ嚎鏃跺�欐墠澶勭悊褰撳墠閫昏緫锛岄伩鍏嶉〉闈㈠崱椤匡紝璋冪敤瀛愪换鍔″畬鎴愭帹閫� * - * @param deptId - * @param curList 鏈畬鎴愭祦绋嬩釜鏁� - * @param completeList 宸茬粡瀹屾垚娴佺▼涓暟 + * @param companyId 缁勭粐缂栧彿 + * @param deptId 鍒嗗簱缂栧彿 + * @param progress 娴佽浆鑺傜偣 */ - private void notifyToScreen(String deptId, List<InoutData> curList, - List<InoutData> completeList) { + public void notifyToScreen(String companyId, String deptId, String progress) { + + // 鎺ㄩ�佸埌澶у睆 + List<InoutData> curList = this.getListInoutCache(deptId); + + List<InoutData> completeList = this.getCompleteListInoutCache(deptId); + if (null == WebSocketServer.contextOnLineMap.get(BizType.SCREEN .getCode())) { @@ -735,13 +665,10 @@ || WebSocketServer.contextOnLineMap.get(BizType.SCREEN_CHECK .getCode())) { - if (null == completeList) { - completeList = this.getCompleteListInoutCache(deptId); - } // 鍒涘缓涓�涓瓙浠诲姟杩涜鎺ㄩ�佷俊鎭� - FutureTask<String> futureTask = new FutureTask<>( - new NotifyScreenTask(curList, completeList, deptId)); + FutureTask<String> futureTask = new FutureTask<>(new NotifyScreenTask(curList, completeList, deptId)); + ExecutorService executorService = Executors.newCachedThreadPool(); executorService.submit(futureTask); executorService.shutdown(); @@ -760,4 +687,94 @@ public String buildInoutKey(String deptId, String key, String type, String bizId) { return Constant.APP_NAME + ":" + deptId + ":" + key + ":" + type + ":" + bizId; } + + @Override + public Page<InoutCheckData> pageSampleData(InoutCheckParam param) { + + //璁剧疆璧峰鍜屾埅姝㈡椂闂� + if (null != param.getStart()) { + param.setStart(DateUtil.getCurZero(param.getStart())); + } + if (null != param.getEnd()) { + param.setEnd(DateUtil.getNextZero(param.getEnd())); + } + + // 璁剧疆杞︾墝鍜屾楠屽崟鎹殑妯$硦鏌ヨ + if (StringUtils.isNotEmpty(param.getPlateNum())) { + param.setPlateNum("%" + param.getPlateNum() + "%"); + } + if (StringUtils.isNotEmpty(param.getCheckId())) { + param.setCheckId("%" + param.getCheckId() + "%"); + } + + Page<InoutCheckData> page = new Page<>(param.getPage(), param.getLimit()); + page.setSearchCount(true); + + List<InoutCheckData> records = inoutCheckMapper.pageSampleData(page, param); + page.setRecords(records); + + return page; + } + + @Override + public String updateSampleData(InoutCheckData data) { + if (StringUtils.isEmpty(data.getCompanyId())) { + data.setCompanyId(ContextUtil.getCompanyId()); + } + if (StringUtils.isEmpty(data.getDeptId())) { + data.setCompanyId(ContextUtil.subDeptId(null)); + } + + inoutCheckMapper.updateSampleData(data); + + return null; + } + + @Override + public Page<InoutCheckData> pageCheckData(InoutCheckParam param) { + + //璁剧疆璧峰鍜屾埅姝㈡椂闂� + if (null != param.getStart()) { + param.setStart(DateUtil.getCurZero(param.getStart())); + } + if (null != param.getEnd()) { + param.setEnd(DateUtil.getNextZero(param.getEnd())); + } + + // 璁剧疆妫�楠屽崟鎹殑妯$硦鏌ヨ + if (StringUtils.isNotEmpty(param.getCheckId())) { + param.setCheckId("%" + param.getCheckId() + "%"); + } + + Page<InoutCheckData> page = new Page<>(param.getPage(), param.getLimit()); + page.setSearchCount(true); + + List<InoutCheckData> records = inoutCheckMapper.pageCheckData(page, param); + page.setRecords(records); + + return page; + } + + @Override + public String updateCheckData(InoutData data) { + data.setUpdateTime(new Date()); + + inoutCheckMapper.updateCheckData(data); + + //鏇存柊缂撳瓨 + updateInoutCache(data); + + return null; + } + + @Override + public List<InoutPrice> getPrice(InoutCheckParam param) { + if (null == param.getStart()) { + param.setStart(new Date()); + } + if (null == param.getEnd()) { + param.setEnd(new Date()); + } + return inoutCheckMapper.getPrice(param); + } } -- Gitblit v1.9.3