From 5e75ef24e5dd45ae934dc7f03f6c7736ca73c9ff Mon Sep 17 00:00:00 2001 From: Fancy <Fancy.fx@outlook.com> Date: 星期二, 27 八月 2024 15:01:32 +0800 Subject: [PATCH] fix order search --- pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/AssemblySv.java | 125 +++++++++++++++++++++++------------------ 1 files changed, 70 insertions(+), 55 deletions(-) diff --git a/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/AssemblySv.java b/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/AssemblySv.java index ca1a2ac..0d8501b 100644 --- a/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/AssemblySv.java +++ b/pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/AssemblySv.java @@ -15,6 +15,7 @@ import com.dy.pmsGlobal.pojoPr.PrBatchNumber; import com.dy.pmsGlobal.pojoPr.PrDevice; import com.dy.pmsGlobal.pojoPr.PrProductionProcess; +import com.dy.pmsGlobal.util.QrCodeConstant; import com.dy.pmsGlobal.util.QrCodeUtil; import com.dy.pmsGlobal.util.UserUtil; import lombok.extern.slf4j.Slf4j; @@ -35,11 +36,10 @@ private static final int BATCH_SIZE = 100; // 鎵归噺澶勭悊澶у皬 private static final String CODE_FORMAT = "%03d"; private static final String CODE_FORMAT_7 = "%07d"; - private static final String TYPE_CODE_EQUIP = "110"; private PrAssemblyPlanMapper assemblyDao; private UserUtil userUtil; private PrBatchNumberMapper batchDao; - private PrDeviceMapper equipDao; + private PrDeviceMapper deviceDao; private PltProductMapper productDao; private PrProductionProcessMapper processDao; @Autowired @@ -55,8 +55,8 @@ this.userUtil = userUtil; } @Autowired - public void setEquipDao(PrDeviceMapper equipDao) { - this.equipDao = equipDao; + public void setDeviceDao(PrDeviceMapper deviceDao) { + this.deviceDao = deviceDao; } @Autowired public void setProductDao(PltProductMapper productDao) { @@ -74,10 +74,7 @@ if(assemblyDao.exists(plan.name,plan.id)){ throw new RuntimeException("璁″垝鍚嶇О涓嶈兘閲嶅"); } - PrProductionProcess process = processDao.selectByPrimaryKey(plan.processId); - if(process == null || !process.proId.equals(plan.proId)){ - throw new RuntimeException("浜у搧涓庣敓浜ф祦绋嬩笉鍖归厤"); - } + extractedCheck(plan); PrBatchNumber batch = new PrBatchNumber(); batch.batchNumber = getNextCode(); batch.proId = plan.proId; @@ -88,7 +85,7 @@ plan.creator = loginUser.id; } batchDao.insertSelective(batch); - insertEquip(plan.proId,batch.id,batch.batchNumber,plan.number,1); + insertDevice(plan.proId,batch.id,batch.batchNumber,plan.number,1); plan.batchId = batch.id; plan.status =PlanStatusEnum.NORMAL.getCode(); @@ -102,9 +99,37 @@ if(assemblyDao.exists(plan.name,plan.id)){ throw new RuntimeException("璁″垝鍚嶇О涓嶈兘閲嶅"); } + PrAssemblyPlan origPlan = assemblyDao.selectByPrimaryKey(plan.id); + PrBatchNumber batch = batchDao.selectByPrimaryKey(origPlan.batchId); + //濡傛灉鏈夋姇鍏�,浜у搧鍜屾祦绋嬩笉鑳藉彉鏇� + if(origPlan.getInputNumber() > 0){ + if(!origPlan.proId.equals(plan.proId) || !origPlan.processId.equals(plan.processId)){ + throw new RuntimeException("璁″垝宸叉姇鍏�,浜у搧涓庣敓浜ф祦绋嬩笉鑳藉彉鏇�"); + } + } + extractedCheck(plan); + //浜у搧鏀瑰彉鍒欐洿鏂板叏閮ㄥ凡鐢熸垚璁惧鍙� + if(origPlan.proId != plan.proId){ + batch.proId = plan.proId; + batchDao.updateByPrimaryKeySelective(batch); + + deviceDao.deleteByBatchId(origPlan.batchId); + insertDevice(plan.proId,origPlan.batchId,batch.batchNumber,plan.number,1); + }else if(origPlan.number < plan.number){ + //鏁伴噺澧炲姞鍒欐柊澧炶澶囧彿 + insertDevice(plan.proId,origPlan.batchId,batch.batchNumber,plan.number,origPlan.number+1); + } + return assemblyDao.updateByPrimaryKeySelective(plan); + } + + private void extractedCheck(PrAssemblyPlan plan) { PrProductionProcess process = processDao.selectByPrimaryKey(plan.processId); if(process == null || !process.proId.equals(plan.proId)){ throw new RuntimeException("浜у搧涓庣敓浜ф祦绋嬩笉鍖归厤"); + } + //寮�濮嬫棩鏈熻灏忎簬缁撴潫鏃ユ湡 + if(plan.startDate.compareTo(plan.endDate) > 0){ + throw new RuntimeException("寮�濮嬫棩鏈熶笉鑳藉ぇ浜庣粨鏉熸棩鏈�"); } //Fancy add 2024/07/09 濡傛灉鐘舵�佷负鎵ц ,鍒欑粨鏉熸棩鏈熷繀椤诲ぇ浜庣瓑浜庡綋鍓嶆棩鏈� if(plan.status == PlanStatusEnum.NORMAL.getCode()){ @@ -113,31 +138,16 @@ LocalDate nextDay = endDate.plusDays(1); LocalDate today = LocalDate.now(); // 鑾峰彇褰撳墠鏃ユ湡 if (nextDay.isBefore(today)) { - throw new RuntimeException("鎵ц鐘舵�佺粨鏉熸棩鏈熷繀椤诲ぇ浜庣瓑浜庡綋鍓嶆棩鏈�"); + throw new RuntimeException("鎵ц鐘舵�佺粨鏉熸棩鏈熷繀椤诲ぇ浜庣瓑浜庡綋鍓嶆棩鏈�,璇蜂慨鏀圭粨鏉熸棩鏈�"); } } - PrAssemblyPlan origPlan = assemblyDao.selectByPrimaryKey(plan.id); - PrBatchNumber batch = batchDao.selectByPrimaryKey(origPlan.batchId); - //浜у搧鏀瑰彉鍒欐洿鏂板叏閮ㄥ凡鐢熸垚璁惧鍙� - if(origPlan.proId != plan.proId){ - batch.proId = plan.proId; - batchDao.updateByPrimaryKeySelective(batch); - - equipDao.deleteByBatchId(origPlan.batchId); - insertEquip(plan.proId,origPlan.batchId,batch.batchNumber,plan.number,1); - }else if(origPlan.number < plan.number){ - //鏁伴噺澧炲姞鍒欐柊澧炶澶囧彿 - insertEquip(plan.proId,origPlan.batchId,batch.batchNumber,plan.number,origPlan.number+1); - } - return assemblyDao.updateByPrimaryKeySelective(plan); } - @Transactional - public int addEquip(Long planId,int num){ + public int addDevice(Long planId,int num){ PrAssemblyPlan plan = assemblyDao.selectByPrimaryKey(planId); PrBatchNumber batch = batchDao.selectByPrimaryKey(plan.batchId); - int count =insertEquip(plan.proId,plan.batchId,batch.batchNumber,num + plan.number,plan.number+1); + int count =insertDevice(plan.proId,plan.batchId,batch.batchNumber,num + plan.number,plan.number+1); // plan.number = plan.number + num; // assemblyDao.updateByPrimaryKeySelective (plan); return count; @@ -152,27 +162,27 @@ * @param number 鏁伴噺 * @return 鎻掑叆鏁伴噺 */ - private int insertEquip(Long proId,Long batchId,String batchCode,Integer number,int startIndex){ + private int insertDevice(Long proId,Long batchId,String batchCode,Integer number,int startIndex){ log.info("鎵归噺鎻掑叆璁惧"); PltProduct product = productDao.selectByPrimaryKey(proId); List<PrDevice> list = new java.util.ArrayList<>(); for(int i= startIndex ;i<= number;i++){ - PrDevice equip = new PrDevice(); - equip.proId = proId; - equip.batchId = batchId; - equip.deviceNo = getEquipNo(product.code,batchCode,i); - equip.status = 0; - list.add(equip); + PrDevice device = new PrDevice(); + device.proId = proId; + device.batchId = batchId; + device.deviceNo = getDeviceNo(product.code,batchCode,i); + device.status = 0; + list.add(device); } - return insertBatchEquip(list); + return insertBatchDevice(list); } - private int insertBatchEquip(List<PrDevice> list) { + private int insertBatchDevice(List<PrDevice> list) { int count = 0; for (int i = 0; i < list.size(); i += BATCH_SIZE) { List<PrDevice> subList = list.subList(i, Math.min(i + BATCH_SIZE, list.size())); // 璋冪敤MyBatis鎻掑叆杩欐壒鏁版嵁 - count += equipDao.insertBatch(subList); + count += deviceDao.insertBatch(subList); } return count; } @@ -192,26 +202,26 @@ return currentDay + String.format(CODE_FORMAT, nextCode); } } - private static String getEquipNo(String proCode,String batchCode,int index){ - String equipNo = TYPE_CODE_EQUIP + proCode + batchCode + + private static String getDeviceNo(String proCode,String batchCode,int index){ + String deviceNo = QrCodeConstant.TypeProduct + proCode + batchCode + String.format(CODE_FORMAT_7, index); - return equipNo; + return deviceNo; } public static void main(String[] args) { List<PrDevice> list = new java.util.ArrayList<>(); for(int i= 1 ;i<= 10000;i++){ - PrDevice equip = new PrDevice(); - equip.proId = 2024052310512000003l; - equip.batchId = 2024053017154400004l; - equip.deviceNo = getEquipNo("002","2024001",i); - equip.status = 0; + PrDevice device = new PrDevice(); + device.proId = 2024052310512000003l; + device.batchId = 2024053017154400004l; + device.deviceNo = getDeviceNo("002","2024001",i); + device.status = 0; - list.add(equip); + list.add(device); } - list.forEach(equip->{ - System.out.println(equip.deviceNo); + list.forEach(device->{ + System.out.println(device.deviceNo); }); } @@ -239,23 +249,23 @@ return rsVo ; } - public QueryResultVo<List<PrDevice>> selectSomeEquip(QueryVo queryVo) { + public QueryResultVo<List<PrDevice>> selectSomeDevice(QueryVo queryVo) { Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); //鏌ヨ绗﹀悎鏉′欢鐨勮褰曟�绘暟 - Long itemTotal = equipDao.selectSomeCount(params); + Long itemTotal = deviceDao.selectSomeCount(params); QueryResultVo<List<PrDevice>> rsVo = new QueryResultVo<>(queryVo.pageSize, queryVo.pageCurr) ; //璁$畻鍒嗛〉绛変俊鎭� rsVo.calculateAndSet(itemTotal, params); //鏌ヨ绗﹀悎鏉′欢鐨勮褰� - rsVo.obj = equipDao.selectSome(params); - rsVo.obj.forEach(equip->{ - equip.qrCode = QrCodeUtil.genQrCodeString(equip.deviceNo); + rsVo.obj = deviceDao.selectSome(params); + rsVo.obj.forEach(device->{ + device.qrCode = QrCodeUtil.genQrCodeString(device.deviceNo); }); return rsVo ; } - public List<PrDevice> selectEquipByBatchId(Long batchId) { - return equipDao.selectByBatchId(batchId); + public List<PrDevice> selectDeviceByBatchId(Long batchId) { + return deviceDao.selectByBatchId(batchId); } /** @@ -265,6 +275,11 @@ */ @Transactional public int updateStatus(PrAssemblyPlan plan) { + if(plan.status == PlanStatusEnum.NORMAL.getCode()){ + PrAssemblyPlan assemblyPlan = assemblyDao.selectByPrimaryKey(plan.id); + assemblyPlan.status = plan.status; + extractedCheck(assemblyPlan); + } PrAssemblyPlan param = new PrAssemblyPlan(); param.id =plan.id; param.status = plan.status; -- Gitblit v1.8.0