whycxzp
6 天以前 4262e1fb86b1bd9f3e38430cdf02696c10d5a801
src/main/java/com/whyc/service/WorkflowLinkService.java
@@ -6,9 +6,9 @@
import com.whyc.dto.Response;
import com.whyc.mapper.*;
import com.whyc.pojo.db_user.User;
import com.whyc.pojo.web_site.WorkflowLink;
import com.whyc.pojo.web_site.WorkflowMain;
import com.whyc.pojo.web_site.*;
import com.whyc.util.CommonUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@@ -28,6 +28,14 @@
    @Lazy
    private WorkflowMainService mainService;
    @Autowired
    private WorkflowDeviceService deviceService;
    @Autowired
    private DeviceSpareService deviceSpareService;
    @Autowired
    private DeviceScrapService deviceScrapService;
    public void addBatch(List<WorkflowLink> links) {
        mapper.insertBatchSomeColumn(links);
@@ -46,24 +54,127 @@
        User user = CommonUtil.getUser();
        Date now = new Date();
        //根据id.查询关联的主表
        WorkflowMain main = mainService.getById(linkInDB.getMainId());
        WorkflowMain mainInDB = mainService.getById(linkInDB.getMainId());
        //查看申请流程类型
        switch (main.getType()) {
        switch (mainInDB.getType()) {
            case 1: { //设备维修申请
                //查看主表的状态
                if(main.getStatus() == WorkflowEnum.MAIN_STATUS_DEALING.getValue().intValue()){ //待处理,下一步是审批通过,待处理 或者驳回
                    if(link.getStatus() == WorkflowEnum.LINK_STATUS_PASS.getValue().intValue()){
                        main.setStatus(WorkflowEnum.MAIN_STATUS_WAIT_FOR_DEALING.getValue());
                        mainService.updateStatus(main);
                    }else if(link.getStatus() == WorkflowEnum.LINK_STATUS_REJECT.getValue().intValue()){
                        main.setStatus(WorkflowEnum.MAIN_STATUS_END_REJECT.getValue());
                        main.setEndReason(link.getDealRejectReason());
                        main.setEndTime(now);
                        mainService.updateStatus(main);
                        link.setDealAndClose(1);
                    }
                //因为是单个链路节点,所以不需要判断是不是待处理,肯定只有1个节点. 审批通过或者驳回
                //if(main.getStatus() == WorkflowEnum.MAIN_STATUS_DEALING.getValue().intValue()){ //待处理,下一步是审批通过,待处理 或者驳回
                if(link.getStatus() == WorkflowEnum.LINK_STATUS_PASS.getValue().intValue()){
                    mainInDB.setStatus(WorkflowEnum.MAIN_STATUS_WAIT_FOR_DEALING.getValue());
                    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);
                    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_END_PASS.getValue());
                    mainInDB.setEndTime(now);
                    mainInDB.setEndReason(link.getDealReason());
                    mainService.updateById(mainInDB);
                    List<WorkflowDevice> deviceListInDB = deviceService.getByMainId(mainInDB.getId());
                    //入库
                    if(mainInDB.getType() == 2){
                        List<DeviceSpare> spareList = new ArrayList<>();
                        deviceListInDB.forEach(device -> {
                            DeviceSpare spare = new DeviceSpare();
                            /*spare.setName(device.getName());
                            spare.setModel(device.getModel());
                            spare.setVersion(device.getVersion());
                            spare.setQuantity(device.getQuantity());
                            spare.setBrand(device.getBrand());
                            spare.setType(device.getType());
                            spare.setSupplier(device.getSupplier());*/
                            BeanUtils.copyProperties(device,spare);
                            spareList.add(spare);
                        });
                        deviceSpareService.addOrUpdate(spareList);
                    }else{ //进入报废库
                        List<DeviceScrap> scrapList = new ArrayList<>();
                        deviceListInDB.forEach(device -> {
                            DeviceScrap deviceScrap = new DeviceScrap();
                            BeanUtils.copyProperties(device,deviceScrap);
                            deviceScrap.setApplyUserId(mainInDB.getCreateUserId());
                            deviceScrap.setApplyUserName(mainInDB.getCreateUserName());
                            deviceScrap.setCreateTime(now);
                            deviceScrap.setMainId(mainInDB.getId());
                            scrapList.add(deviceScrap);
                        });
                        deviceScrapService.add(scrapList);
                    }
                }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);
                        //关联工单的设备附属表未处理数量也要回退,等于主表设备数量
                        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:{ // 出库申请
                if(link.getStatus() == WorkflowEnum.LINK_STATUS_PASS.getValue().intValue()){
                    mainInDB.setStatus(WorkflowEnum.MAIN_STATUS_END_PASS.getValue());
                    mainInDB.setEndTime(now);
                    mainInDB.setEndReason(link.getDealReason());
                    mainService.updateById(mainInDB);
                    //获取出库申请单设备
                    List<WorkflowDevice> deviceListInDB = deviceService.getByMainId(mainInDB.getId());
                    List<DeviceSpare> spareList = new ArrayList<>();
                    deviceListInDB.forEach(device -> {
                        DeviceSpare spare = new DeviceSpare();
                        BeanUtils.copyProperties(device,spare);
                        spareList.add(spare);
                    });
                    //更新库存
                    deviceSpareService.outBound(spareList);
                }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);
                    mainService.updateById(mainInDB);
                    link.setDealAndClose(1);
                }
            }break;
            default:
                break;
        }