| | |
| | | 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.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; |
| | |
| | | private PrAssemblyPlanMapper assemblyDao; |
| | | private UserUtil userUtil; |
| | | private PrBatchNumberMapper batchDao; |
| | | private PrEquipMapper equipDao; |
| | | private PrDeviceMapper equipDao; |
| | | private PltProductMapper productDao; |
| | | private SqlSessionFactory sqlSessionFactory; |
| | | private PrProductionProcessMapper processDao; |
| | | @Autowired |
| | | public void setAssemblyDao(PrAssemblyPlanMapper assemblyDao) { |
| | | this.assemblyDao = assemblyDao; |
| | |
| | | this.userUtil = userUtil; |
| | | } |
| | | @Autowired |
| | | public void setEquipDao(PrEquipMapper equipDao) { |
| | | public void setEquipDao(PrDeviceMapper equipDao) { |
| | | this.equipDao = equipDao; |
| | | } |
| | | @Autowired |
| | |
| | | } |
| | | |
| | | @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; |
| | |
| | | |
| | | @Transactional |
| | | public int update(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("产品与生产流程不匹配"); |
| | | } |
| | | //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("执行状态结束日期必须大于等于当前日期"); |
| | | } |
| | | } |
| | | 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){ |
| | |
| | | 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); |
| | | // plan.number = plan.number + num; |
| | | // assemblyDao.updateByPrimaryKeySelective (plan); |
| | | return count; |
| | | } |
| | | |
| | |
| | | private int insertEquip(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(); |
| | | PrDevice equip = new PrDevice(); |
| | | equip.proId = proId; |
| | | equip.batchId = batchId; |
| | | equip.equipNo = getEquipNo(product.code,batchCode,i); |
| | | equip.deviceNo = getEquipNo(product.code,batchCode,i); |
| | | equip.status = 0; |
| | | list.add(equip); |
| | | } |
| | | return insertBatchEquip(list); |
| | | } |
| | | |
| | | private int insertBatchEquip(List<PrEquip> list) { |
| | | private int insertBatchEquip(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); |
| | | } |
| | |
| | | } |
| | | |
| | | 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(); |
| | | PrDevice equip = new PrDevice(); |
| | | equip.proId = 2024052310512000003l; |
| | | equip.batchId = 2024053017154400004l; |
| | | equip.equipNo = getEquipNo("002","2024001",i); |
| | | equip.deviceNo = getEquipNo("002","2024001",i); |
| | | equip.status = 0; |
| | | |
| | | list.add(equip); |
| | | } |
| | | list.forEach(equip->{ |
| | | System.out.println(equip.equipNo); |
| | | System.out.println(equip.deviceNo); |
| | | }); |
| | | } |
| | | |
| | |
| | | return rsVo ; |
| | | } |
| | | |
| | | public QueryResultVo<List<PrEquip>> selectSomeEquip(QueryVo queryVo) { |
| | | public QueryResultVo<List<PrDevice>> selectSomeEquip(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 = equipDao.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); |
| | | equip.qrCode = QrCodeUtil.genQrCodeString(equip.deviceNo); |
| | | }); |
| | | return rsVo ; |
| | | } |
| | | |
| | | public List<PrEquip> selectEquipByBatchId(Long batchId) { |
| | | public List<PrDevice> selectEquipByBatchId(Long batchId) { |
| | | return equipDao.selectByBatchId(batchId); |
| | | } |
| | | |
| | |
| | | PrAssemblyPlan param = new PrAssemblyPlan(); |
| | | param.id =plan.id; |
| | | param.status = plan.status; |
| | | return assemblyDao.updateByPrimaryKeySelective(plan); |
| | | return assemblyDao.updateByPrimaryKeySelective(param); |
| | | } |
| | | } |