From 2205305e5be09c54dcaa3638f9412227cb3b9e7e Mon Sep 17 00:00:00 2001 From: whycxzp <glperry@163.com> Date: 星期四, 19 六月 2025 20:32:17 +0800 Subject: [PATCH] 维修调度-工单模块的设备信息关联处理 --- src/main/java/com/whyc/pojo/web_site/WorkflowMain.java | 5 - src/main/java/com/whyc/service/WorkflowLinkService.java | 44 +++++++++- src/main/java/com/whyc/service/WorkflowDeviceService.java | 26 ++++++ src/main/java/com/whyc/pojo/web_site/WorkflowDevice.java | 2 src/main/java/com/whyc/service/WorkflowMainService.java | 105 +++++++++++++++++++++++--- 5 files changed, 157 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/whyc/pojo/web_site/WorkflowDevice.java b/src/main/java/com/whyc/pojo/web_site/WorkflowDevice.java index 3a75062..c6796b9 100644 --- a/src/main/java/com/whyc/pojo/web_site/WorkflowDevice.java +++ b/src/main/java/com/whyc/pojo/web_site/WorkflowDevice.java @@ -21,6 +21,8 @@ private String version; @ApiModelProperty("鏁伴噺") private Integer quantity; + @ApiModelProperty("鏈鐞嗙殑鏁伴噺.缁翠慨鐢宠鏃堕渶濉叆") + private Integer quantityUnprocessed; @ApiModelProperty("鍝佺墝") private String brand; @ApiModelProperty("绫诲瀷") diff --git a/src/main/java/com/whyc/pojo/web_site/WorkflowMain.java b/src/main/java/com/whyc/pojo/web_site/WorkflowMain.java index 3c562bb..399d1be 100644 --- a/src/main/java/com/whyc/pojo/web_site/WorkflowMain.java +++ b/src/main/java/com/whyc/pojo/web_site/WorkflowMain.java @@ -54,11 +54,6 @@ @ApiModelProperty("褰掓。鏃堕棿") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai") private Date endTime; - - @ApiModelProperty("鐢宠鏁伴噺") - private Integer quantity; - @ApiModelProperty("鏈鐞嗙殑鏁伴噺.缁翠慨鐢宠鏃堕渶濉叆") - private Integer quantityUnprocessed; /**浠诲姟绛夌骇*/ @ApiModelProperty("浠诲姟绛夌骇") private Integer taskLevel; diff --git a/src/main/java/com/whyc/service/WorkflowDeviceService.java b/src/main/java/com/whyc/service/WorkflowDeviceService.java index 8bc2317..286cb2f 100644 --- a/src/main/java/com/whyc/service/WorkflowDeviceService.java +++ b/src/main/java/com/whyc/service/WorkflowDeviceService.java @@ -1,7 +1,11 @@ package com.whyc.service; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.whyc.mapper.WorkflowDeviceMapper; import com.whyc.pojo.web_site.WorkflowDevice; +import com.whyc.util.ActionUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -16,4 +20,26 @@ public void addBatch(List<WorkflowDevice> deviceList) { mapper.insertBatchSomeColumn(deviceList); } + + public List<WorkflowDevice> getByMainId(Integer relatedId) { + QueryWrapper<WorkflowDevice> query = Wrappers.query(); + query.eq("main_id",relatedId); + return mapper.selectList(query); + } + + public void setQuantityUnprocessedZero(Integer relatedId) { + UpdateWrapper<WorkflowDevice> update = Wrappers.update(); + update.set("quantity_unprocessed",0).eq("main_id",relatedId); + mapper.update((WorkflowDevice) ActionUtil.objeNull,update); + } + + public void updateQuantityUnprocessedBatch(List<WorkflowDevice> deviceRelatedListInDB) { + for (int i = 0; i < deviceRelatedListInDB.size(); i++) { + WorkflowDevice deviceRelatedInDB = deviceRelatedListInDB.get(i); + UpdateWrapper<WorkflowDevice> update = Wrappers.update(); + update.set("quantity_unprocessed",deviceRelatedInDB.getQuantityUnprocessed()) + .eq("id",deviceRelatedInDB.getId()); + mapper.update((WorkflowDevice) ActionUtil.objeNull,update); + } + } } diff --git a/src/main/java/com/whyc/service/WorkflowLinkService.java b/src/main/java/com/whyc/service/WorkflowLinkService.java index 5cde308..86b2328 100644 --- a/src/main/java/com/whyc/service/WorkflowLinkService.java +++ b/src/main/java/com/whyc/service/WorkflowLinkService.java @@ -6,6 +6,7 @@ import com.whyc.dto.Response; import com.whyc.mapper.*; 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.CommonUtil; @@ -27,6 +28,9 @@ @Autowired @Lazy private WorkflowMainService mainService; + + @Autowired + private WorkflowDeviceService deviceService; public void addBatch(List<WorkflowLink> links) { @@ -63,27 +67,51 @@ mainService.updateById(mainInDB); link.setDealAndClose(1); } - } + }break; //璁惧鍏ュ簱鐢宠 case 2: //璁惧鎶ュ簾鐢宠 case 3:{ if(link.getStatus() == WorkflowEnum.LINK_STATUS_PASS.getValue().intValue()){ - mainInDB.setStatus(WorkflowEnum.MAIN_STATUS_WAIT_FOR_DEALING.getValue()); + mainInDB.setStatus(WorkflowEnum.MAIN_STATUS_END_PASS.getValue()); + mainInDB.setEndTime(now); + mainInDB.setEndReason(link.getDealReason()); mainService.updateById(mainInDB); }else if(link.getStatus() == WorkflowEnum.LINK_STATUS_REJECT.getValue().intValue()){ mainInDB.setStatus(WorkflowEnum.MAIN_STATUS_END_REJECT.getValue()); mainInDB.setEndReason(link.getDealRejectReason()); mainInDB.setEndTime(now); - //妫�鏌ユ槸鍚︽湁鍏宠仈宸ュ崟.濡傛灉鏈夊叧鑱斿伐鍗�,鍏宠仈宸ュ崟鐘舵�侀噸缃负瀹岀粨寰呭鐞�,瀹屾垚鏃堕棿閲嶇疆涓虹┖ + //妫�鏌ユ槸鍚︽湁鍏宠仈宸ュ崟. + // 濡傛灉鏈夊叧鑱斿伐鍗�,鍏宠仈宸ュ崟鐘舵�侀噸缃负瀹岀粨寰呭鐞�,瀹屾垚鏃堕棿閲嶇疆涓虹┖ if(mainInDB.getRelatedId() != null){ Integer relatedId = mainInDB.getRelatedId(); - mainService.resetRepairStatus(relatedId,mainInDB.getQuantity()); + mainService.resetRepairStatus(relatedId); + //鍏宠仈宸ュ崟鐨勮澶囬檮灞炶〃鏈鐞嗘暟閲忎篃瑕佸洖閫�,绛変簬涓昏〃璁惧鏁伴噺 + List<WorkflowDevice> deviceRelatedListInDB = deviceService.getByMainId(mainInDB.getRelatedId()); + List<WorkflowDevice> deviceListInDB = deviceService.getByMainId(mainInDB.getId()); + for (int i = 0; i < deviceListInDB.size(); i++) { + WorkflowDevice deviceInDB = deviceListInDB.get(i); + for (int j = 0; j < deviceRelatedListInDB.size(); j++) { + WorkflowDevice deviceRelatedInDB = deviceRelatedListInDB.get(j); + if (deviceInDB.getName().equals(deviceRelatedInDB.getName()) + && deviceInDB.getModel().equals(deviceRelatedInDB.getModel()) + && deviceInDB.getVersion().equals(deviceRelatedInDB.getVersion()) + && deviceInDB.getBrand().equals(deviceRelatedInDB.getBrand()) + && deviceInDB.getType().equals(deviceRelatedInDB.getType()) + && deviceInDB.getSupplier().equals(deviceRelatedInDB.getSupplier()) + ) { + deviceRelatedInDB.setQuantityUnprocessed(deviceInDB.getQuantity()); + //鍏宠仈宸ュ崟褰撳墠璁惧闄勫睘鐨勬湭澶勭悊鏁伴噺鍥為��瀹屾垚,涓嬩竴涓� + break; + } + } + } + deviceService.updateQuantityUnprocessedBatch(deviceRelatedListInDB); } mainService.updateById(mainInDB); link.setDealAndClose(1); } - } + }break; case 4:{ //TODO 鍑哄簱鐢宠 if(link.getStatus() == WorkflowEnum.LINK_STATUS_PASS.getValue().intValue()){ mainInDB.setStatus(WorkflowEnum.MAIN_STATUS_WAIT_FOR_DEALING.getValue()); @@ -95,12 +123,14 @@ //妫�鏌ユ槸鍚︽湁鍏宠仈宸ュ崟.濡傛灉鏈夊叧鑱斿伐鍗�,鍏宠仈宸ュ崟鐘舵�侀噸缃负瀹岀粨寰呭鐞�,瀹屾垚鏃堕棿閲嶇疆涓虹┖ if(mainInDB.getRelatedId() != null){ Integer relatedId = mainInDB.getRelatedId(); - mainService.resetRepairStatus(relatedId,mainInDB.getQuantity()); + //mainService.resetRepairStatus(relatedId,mainInDB.getQuantity()); } mainService.updateById(mainInDB); link.setDealAndClose(1); } - } + }break; + default: + break; } diff --git a/src/main/java/com/whyc/service/WorkflowMainService.java b/src/main/java/com/whyc/service/WorkflowMainService.java index db7566a..8bce361 100644 --- a/src/main/java/com/whyc/service/WorkflowMainService.java +++ b/src/main/java/com/whyc/service/WorkflowMainService.java @@ -248,10 +248,30 @@ //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鍐呯殑瀵硅薄鐨剄uantity鍊煎ぇ浜� deviceListRelatedInDB鍐呭璞″垪琛ㄤ腑鐨勫璞℃墍鏈夊瓧娈电浉鍚岀殑璁板綍鐨剄uantityUnprocessed鍊�,鍒欒繑鍥為敊璇� + 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; + } + } + + } } } //涓昏〃鎻掑叆 @@ -274,11 +294,12 @@ 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()); } @@ -309,14 +330,25 @@ 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鍐卶uantity灞炴�у�肩殑鍜� + int sumQuantity = 0; + for (WorkflowDevice device : deviceList) { + sumQuantity += device.getQuantity(); + } + //璁$畻deviceListRelatedInDBn鍐卶uantityUnprocessed灞炴�у�肩殑鍜� + int sumQuantityUnprocessedInDB = 0; + for (WorkflowDevice device : deviceListRelatedInDB) { + sumQuantityUnprocessedInDB += device.getQuantityUnprocessed(); + } + if (sumQuantity < sumQuantityUnprocessedInDB){ //璇存槑闇�瑕佽嚜鍔ㄧ敓鎴愬叆搴撴垨鑰呮姤搴熷崟鎹� //闇�瑕佽嚜鍔ㄧ敓鎴愭姤搴熺殑鐢宠 WorkflowMain mainAuto = new WorkflowMain(); WorkflowTypeEnum typeEnumAuto; @@ -326,10 +358,52 @@ 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("鎻愪氦浜嗙淮淇悗鐨勫叆搴撶敵璇�,绯荤粺鑷姩鐢熸垚鍓╀綑鏁伴噺鐨勬姤搴熺敵璇�"); @@ -343,6 +417,11 @@ mainAuto.setTitle(titleAuto); mainAuto.setType(typeEnumAuto.getType()); add(mainAuto); + deviceListAuto.forEach(device -> { + device.setMainId(mainAuto.getId()); + }); + //鎻掑叆涓昏〃鐨勮澶囬檮琛� + deviceService.addBatch(deviceListAuto); //鑷姩鑺傜偣鐢熸垚 WorkflowLink linkAuto = new WorkflowLink(); @@ -368,8 +447,9 @@ }else{ relatedMain.setEndReason("鐢ㄦ埛鎻愪氦缁翠慨鐢宠鍚庣殑鎶ュ簾鐢宠,缁翠慨娴佺▼缁撴潫"); } - relatedMain.setQuantityUnprocessed(0); updateById(relatedMain); + //鏇存柊鍏宠仈鍗曟嵁鐨勮澶囧墿浣欐湭澶勭悊鏁伴噺涓�0 + deviceService.setQuantityUnprocessedZero(main.getRelatedId()); } } @@ -420,12 +500,11 @@ 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); } -- Gitblit v1.9.1