From f2cd828d3719efd7796f5bd7692b3d9946b5b772 Mon Sep 17 00:00:00 2001 From: Fancy <Fancy.fx@outlook.com> Date: 星期四, 11 七月 2024 11:37:21 +0800 Subject: [PATCH] check process used can not change product --- pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/taskPlan/AssemblySv.java | 161 +++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 111 insertions(+), 50 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 6f2600d..885bebd 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 @@ -7,21 +7,25 @@ import com.dy.pmsGlobal.daoPlt.PltProductMapper; import com.dy.pmsGlobal.daoPr.PrAssemblyPlanMapper; import com.dy.pmsGlobal.daoPr.PrBatchNumberMapper; -import com.dy.pmsGlobal.daoPr.PrEquipMapper; +import com.dy.pmsGlobal.daoPr.PrDeviceMapper; +import com.dy.pmsGlobal.daoPr.PrProductionProcessMapper; import com.dy.pmsGlobal.pojoBa.BaUser; import com.dy.pmsGlobal.pojoPlt.PltProduct; import com.dy.pmsGlobal.pojoPr.PrAssemblyPlan; import com.dy.pmsGlobal.pojoPr.PrBatchNumber; -import com.dy.pmsGlobal.pojoPr.PrEquip; +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; import org.apache.dubbo.common.utils.PojoUtils; -import org.apache.ibatis.session.SqlSessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.List; import java.util.Map; @@ -32,13 +36,12 @@ 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 PrEquipMapper equipDao; + private PrDeviceMapper deviceDao; private PltProductMapper productDao; - private SqlSessionFactory sqlSessionFactory; + private PrProductionProcessMapper processDao; @Autowired public void setAssemblyDao(PrAssemblyPlanMapper assemblyDao) { this.assemblyDao = assemblyDao; @@ -52,8 +55,8 @@ this.userUtil = userUtil; } @Autowired - public void setEquipDao(PrEquipMapper equipDao) { - this.equipDao = equipDao; + public void setDeviceDao(PrDeviceMapper deviceDao) { + this.deviceDao = deviceDao; } @Autowired public void setProductDao(PltProductMapper productDao) { @@ -61,12 +64,20 @@ } @Autowired - public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) { - this.sqlSessionFactory = sqlSessionFactory; + public void setProcessDao(PrProductionProcessMapper processDao) { + this.processDao = processDao; } @Transactional public int save(PrAssemblyPlan plan){ + //璁″垝鍚嶇О涓嶈兘閲嶅 + 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("浜у搧涓庣敓浜ф祦绋嬩笉鍖归厤"); + } PrBatchNumber batch = new PrBatchNumber(); batch.batchNumber = getNextCode(); batch.proId = plan.proId; @@ -77,7 +88,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(); @@ -85,28 +96,60 @@ return assemblyDao.insertSelective(plan); } + @Transactional public int update(PrAssemblyPlan plan){ + //璁″垝鍚嶇О涓嶈兘閲嶅 + 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){ - equipDao.deleteByBatchId(origPlan.batchId); - insertEquip(plan.proId,origPlan.batchId,batch.batchNumber,plan.number,1); + 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){ //鏁伴噺澧炲姞鍒欐柊澧炶澶囧彿 - insertEquip(plan.proId,origPlan.batchId,batch.batchNumber,plan.number,origPlan.number+1); + 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("浜у搧涓庣敓浜ф祦绋嬩笉鍖归厤"); + } + //Fancy add 2024/07/09 濡傛灉鐘舵�佷负鎵ц ,鍒欑粨鏉熸棩鏈熷繀椤诲ぇ浜庣瓑浜庡綋鍓嶆棩鏈� + if(plan.status == PlanStatusEnum.NORMAL.getCode()){ + String endDateStr = plan.getEndDate(); + LocalDate endDate = LocalDate.parse(endDateStr, DateTimeFormatter.ISO_LOCAL_DATE); + LocalDate nextDay = endDate.plusDays(1); + LocalDate today = LocalDate.now(); // 鑾峰彇褰撳墠鏃ユ湡 + if (nextDay.isBefore(today)) { + throw new RuntimeException("鎵ц鐘舵�佺粨鏉熸棩鏈熷繀椤诲ぇ浜庣瓑浜庡綋鍓嶆棩鏈�,璇蜂慨鏀圭粨鏉熸棩鏈�"); + } + } + } - public int addEquip(Long planId,int num){ + @Transactional + 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); - plan.number = plan.number + num; - assemblyDao.updateByPrimaryKeySelective(plan); + 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; } @@ -119,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<PrEquip> list = new java.util.ArrayList<>(); + List<PrDevice> list = new java.util.ArrayList<>(); for(int i= startIndex ;i<= number;i++){ - PrEquip equip = new PrEquip(); - equip.proId = proId; - equip.batchId = batchId; - equip.equipNo = 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); } - public int insertBatchEquip(List<PrEquip> list) { + private int insertBatchDevice(List<PrDevice> list) { int count = 0; for (int i = 0; i < list.size(); i += BATCH_SIZE) { - List<PrEquip> subList = list.subList(i, Math.min(i + BATCH_SIZE, list.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; } @@ -159,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<PrEquip> list = new java.util.ArrayList<>(); + List<PrDevice> list = new java.util.ArrayList<>(); for(int i= 1 ;i<= 10000;i++){ - PrEquip equip = new PrEquip(); - equip.proId = 2024052310512000003l; - equip.batchId = 2024053017154400004l; - equip.equipNo = 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.equipNo); + list.forEach(device->{ + System.out.println(device.deviceNo); }); } @@ -206,22 +249,40 @@ return rsVo ; } - public QueryResultVo<List<PrEquip>> selectSomeEquip(QueryVo queryVo) { + public QueryResultVo<List<PrDevice>> selectSomeDevice(QueryVo queryVo) { Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo); //鏌ヨ绗﹀悎鏉′欢鐨勮褰曟�绘暟 - Long itemTotal = assemblyDao.selectSomeCount(params); - QueryResultVo<List<PrEquip>> rsVo = new QueryResultVo<>(queryVo.pageSize, queryVo.pageCurr) ; + 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.equipNo); + rsVo.obj = deviceDao.selectSome(params); + rsVo.obj.forEach(device->{ + device.qrCode = QrCodeUtil.genQrCodeString(device.deviceNo); }); return rsVo ; } - public List<PrEquip> selectEquipByBatchId(Long batchId) { - return equipDao.selectByBatchId(batchId); + public List<PrDevice> selectDeviceByBatchId(Long batchId) { + return deviceDao.selectByBatchId(batchId); + } + + /** + * 鍙洿鏂扮姸鎬�,涓嶆洿鏂板叾浠栧瓧娈� + * @param plan + * @return + */ + @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; + return assemblyDao.updateByPrimaryKeySelective(param); } } -- Gitblit v1.8.0