| | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.WorkflowMainMapper; |
| | | import com.whyc.pojo.db_user.User; |
| | | import com.whyc.pojo.web_site.WorkflowDevice; |
| | | import com.whyc.pojo.web_site.WorkflowLink; |
| | | import com.whyc.pojo.web_site.WorkflowMain; |
| | | import com.whyc.util.ActionUtil; |
| | |
| | | |
| | | @Autowired(required = false) |
| | | private WorkflowLinkService linkService; |
| | | |
| | | @Autowired |
| | | private WorkflowDeviceService deviceService; |
| | | |
| | | |
| | | /** |
| | |
| | | return null; |
| | | } |
| | | |
| | | public void updateStatus(WorkflowMain main) { |
| | | public void updateById(WorkflowMain main) { |
| | | mapper.updateById(main); |
| | | } |
| | | |
| | |
| | | /** |
| | | * 通用提交方法,提交给角色-角色层 |
| | | * 如果related_id不为空,则需要特殊处理. 证明会影响到关联单据 |
| | | * |
| | | * 涉及到新的问题需要解决,现场故障后,设备维修申请 或 报废申请 是多个,并存入工单设备表中. 并不只是单纯的数量. TODO ?自动化处理怎么更新 |
| | | */ |
| | | |
| | | @Transactional |
| | |
| | | //1.提交到单据审批流程 |
| | | //如果存在关联单据id,首先校验提交的数量 |
| | | Date now = new Date(); |
| | | WorkflowMain mainRelated = getById(main.getRelatedId()); |
| | | List<WorkflowDevice> deviceListRelatedInDB = deviceService.getByMainId(main.getRelatedId()); |
| | | List<WorkflowDevice> deviceList = main.getDeviceList(); |
| | | if(main.getRelatedId() != null) { |
| | | if (main.getQuantity() > mainRelated.getQuantity()) { |
| | | return new Response().setII(1, "入库数量不能大于维修申请关联单据的数量"); |
| | | //遍历deviceList,如果deviceList内的对象的quantity值大于 deviceListRelatedInDB内对象列表中的对象所有字段相同的记录的quantityUnprocessed值,则返回错误 |
| | | for (int i = 0; i < deviceList.size(); i++) { |
| | | WorkflowDevice device = deviceList.get(i); |
| | | for (int j = 0; j < deviceListRelatedInDB.size(); j++) { |
| | | WorkflowDevice deviceInDB = deviceListRelatedInDB.get(j); |
| | | if (device.getName().equals(deviceInDB.getName()) |
| | | && device.getModel().equals(deviceInDB.getModel()) |
| | | && device.getVersion().equals(deviceInDB.getVersion()) |
| | | && device.getBrand().equals(deviceInDB.getBrand()) |
| | | && device.getType().equals(deviceInDB.getType()) |
| | | && device.getSupplier().equals(deviceInDB.getSupplier()) |
| | | ) { |
| | | if (device.getQuantity() > deviceInDB.getQuantityUnprocessed()) { |
| | | return new Response().setII(1, "入库数量不能大于维修申请关联单据的未处理数量"); |
| | | }else{ |
| | | //当前设备的校验结束,进入下一个设备校验 |
| | | break; |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | //主表插入 |
| | |
| | | main.setBeginTime(now); |
| | | main.setStatus(mainStatus); |
| | | main.setProcessStage(process.getStage()); |
| | | if(main.getType() == WorkflowTypeEnum.DEVICE_REPAIR.getType().intValue()){ //维修申请单,需填入 |
| | | for (int i = 0; i < deviceList.size(); i++) { |
| | | deviceList.get(i).setQuantityUnprocessed(deviceList.get(i).getQuantity()); |
| | | } |
| | | } |
| | | add(main); |
| | | //主表关联的物料插入 |
| | | for (WorkflowDevice device : deviceList) { |
| | | device.setMainId(main.getId()); |
| | | } |
| | | deviceService.addBatch(deviceList); |
| | | |
| | | //内存中去除已插入数据库的单号 |
| | | ServletContext application = ActionUtil.getApplication(); |
| | | List<String> orderIdList = (List<String>) application.getAttribute("orderIdList"); |
| | |
| | | linkService.add(link); |
| | | |
| | | //如果存在关联单据id,处理关联单据及自动生成新单据 |
| | | checkRelatedAndDone(main, now, mainRelated, user); |
| | | checkRelatedAndDone(main, now, deviceListRelatedInDB, user); |
| | | return new Response().setII(1,"提交完成"); |
| | | } |
| | | |
| | | private void checkRelatedAndDone(WorkflowMain main, Date now, WorkflowMain mainRelated, User user) { |
| | | private void checkRelatedAndDone(WorkflowMain main, Date now, List<WorkflowDevice> deviceListRelatedInDB, User user) { |
| | | if(main.getRelatedId() != null){ |
| | | //判断是申请的入库,还是报废. |
| | | if (main.getQuantity() < mainRelated.getQuantity()){ //说明需要自动生成入库或者报废单据 |
| | | //申请的数量<关联单据的未处理数量,则说明有剩余. 需要自动生成对立工单 |
| | | List<WorkflowDevice> deviceList = main.getDeviceList(); |
| | | //计算deviceListn内quantity属性值的和 |
| | | int sumQuantity = 0; |
| | | for (WorkflowDevice device : deviceList) { |
| | | sumQuantity += device.getQuantity(); |
| | | } |
| | | //计算deviceListRelatedInDBn内quantityUnprocessed属性值的和 |
| | | int sumQuantityUnprocessedInDB = 0; |
| | | for (WorkflowDevice device : deviceListRelatedInDB) { |
| | | sumQuantityUnprocessedInDB += device.getQuantityUnprocessed(); |
| | | } |
| | | if (sumQuantity < sumQuantityUnprocessedInDB){ //说明需要自动生成入库或者报废单据 |
| | | //需要自动生成报废的申请 |
| | | WorkflowMain mainAuto = new WorkflowMain(); |
| | | WorkflowTypeEnum typeEnumAuto; |
| | |
| | | mainAuto.setCreateUserId(user.getId()); |
| | | mainAuto.setCreateTime(now); |
| | | mainAuto.setBeginTime(now); |
| | | mainAuto.setQuantity(mainRelated.getQuantity()- main.getQuantity()); |
| | | mainAuto.setProcessStage(processAuto.getStage()); |
| | | mainAuto.setStatus(statusAuto); |
| | | mainAuto.setRelatedId(main.getRelatedId()); |
| | | //整理主表的设备附表 |
| | | List<WorkflowDevice> deviceListAuto = new ArrayList<>(); |
| | | //遍历deviceListRelatedInDB,减去deviceList中申请的数量 |
| | | for (WorkflowDevice deviceInDB : deviceListRelatedInDB) { |
| | | boolean deviceExists = false; |
| | | for (WorkflowDevice device : deviceList) { |
| | | if (device.getName().equals(deviceInDB.getName()) |
| | | && device.getModel().equals(deviceInDB.getModel()) |
| | | && device.getVersion().equals(deviceInDB.getVersion()) |
| | | && device.getBrand().equals(deviceInDB.getBrand()) |
| | | && device.getType().equals(deviceInDB.getType()) |
| | | && device.getSupplier().equals(deviceInDB.getSupplier()) |
| | | ){ |
| | | deviceExists = true; |
| | | if (deviceInDB.getQuantityUnprocessed()-device.getQuantity() > 0){ |
| | | WorkflowDevice deviceAuto = new WorkflowDevice(); |
| | | deviceAuto.setName(deviceInDB.getName()); |
| | | deviceAuto.setModel(deviceInDB.getModel()); |
| | | deviceAuto.setVersion(deviceInDB.getVersion()); |
| | | deviceAuto.setQuantity(deviceInDB.getQuantityUnprocessed()-device.getQuantity()); |
| | | deviceAuto.setBrand(deviceInDB.getBrand()); |
| | | deviceAuto.setType(deviceInDB.getType()); |
| | | deviceAuto.setSupplier(deviceInDB.getSupplier()); |
| | | |
| | | deviceListAuto.add(deviceAuto); |
| | | }else{ |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if (!deviceExists){ |
| | | WorkflowDevice deviceAuto = new WorkflowDevice(); |
| | | deviceAuto.setName(deviceInDB.getName()); |
| | | deviceAuto.setModel(deviceInDB.getModel()); |
| | | deviceAuto.setVersion(deviceInDB.getVersion()); |
| | | deviceAuto.setQuantity(deviceInDB.getQuantityUnprocessed()); |
| | | deviceAuto.setBrand(deviceInDB.getBrand()); |
| | | deviceAuto.setType(deviceInDB.getType()); |
| | | deviceAuto.setSupplier(deviceInDB.getSupplier()); |
| | | |
| | | deviceListAuto.add(deviceAuto); |
| | | } |
| | | } |
| | | |
| | | if(main.getType() == WorkflowTypeEnum.DEVICE_IN.getType().intValue()) { //申请的入库 |
| | | mainAuto.setTaskDesc("提交了维修后的入库申请,系统自动生成剩余数量的报废申请"); |
| | |
| | | mainAuto.setTitle(titleAuto); |
| | | mainAuto.setType(typeEnumAuto.getType()); |
| | | add(mainAuto); |
| | | deviceListAuto.forEach(device -> { |
| | | device.setMainId(mainAuto.getId()); |
| | | }); |
| | | //插入主表的设备附表 |
| | | deviceService.addBatch(deviceListAuto); |
| | | |
| | | //自动节点生成 |
| | | WorkflowLink linkAuto = new WorkflowLink(); |
| | |
| | | }else{ |
| | | relatedMain.setEndReason("用户提交维修申请后的报废申请,维修流程结束"); |
| | | } |
| | | updateStatus(relatedMain); |
| | | updateById(relatedMain); |
| | | //更新关联单据的设备剩余未处理数量为0 |
| | | deviceService.setQuantityUnprocessedZero(main.getRelatedId()); |
| | | } |
| | | } |
| | | |
| | |
| | | update.set("process_level",processLevel).eq("id",mainId); |
| | | mapper.update((WorkflowMain) ActionUtil.objeNull,update); |
| | | } |
| | | |
| | | public void resetRepairStatus(Integer relatedId) { |
| | | UpdateWrapper<WorkflowMain> update = Wrappers.update(); |
| | | update.set("status",WorkflowEnum.MAIN_STATUS_WAIT_FOR_DEALING.getValue()) |
| | | .set("end_time",null) |
| | | .set("end_reason",null) |
| | | .eq("id",relatedId); |
| | | mapper.update((WorkflowMain) ActionUtil.objeNull,update); |
| | | } |
| | | } |