| | |
| | | //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.getQuantityUnprocessed()) { |
| | | 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.setStatus(mainStatus); |
| | | main.setProcessStage(process.getStage()); |
| | | if(main.getType() == WorkflowTypeEnum.DEVICE_REPAIR.getType().intValue()){ //维修申请单,需填入 |
| | | main.setQuantityUnprocessed(main.getQuantity()); |
| | | for (int i = 0; i < deviceList.size(); i++) { |
| | | deviceList.get(i).setQuantityUnprocessed(deviceList.get(i).getQuantity()); |
| | | } |
| | | } |
| | | add(main); |
| | | //主表关联的物料插入 |
| | | List<WorkflowDevice> deviceList = main.getDeviceList(); |
| | | for (WorkflowDevice device : deviceList) { |
| | | device.setMainId(main.getId()); |
| | | } |
| | |
| | | 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.getQuantityUnprocessed()){ //说明需要自动生成入库或者报废单据 |
| | | //申请的数量<关联单据的未处理数量,则说明有剩余. 需要自动生成对立工单 |
| | | 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.getQuantityUnprocessed()- 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("用户提交维修申请后的报废申请,维修流程结束"); |
| | | } |
| | | relatedMain.setQuantityUnprocessed(0); |
| | | updateById(relatedMain); |
| | | //更新关联单据的设备剩余未处理数量为0 |
| | | deviceService.setQuantityUnprocessedZero(main.getRelatedId()); |
| | | } |
| | | } |
| | | |
| | |
| | | mapper.update((WorkflowMain) ActionUtil.objeNull,update); |
| | | } |
| | | |
| | | public void resetRepairStatus(Integer relatedId, Integer quantity) { |
| | | 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) |
| | | .set("quantity_unprocessed",quantity) |
| | | .eq("id",relatedId); |
| | | mapper.update((WorkflowMain) ActionUtil.objeNull,update); |
| | | } |