whycxzp
2022-08-13 fde67238dfcd493876d45d6916d3f7bdd2bb7120
src/main/java/com/whyc/service/WorksheetMainService.java
@@ -11,6 +11,7 @@
import com.whyc.mapper.WorksheetLinkMapper;
import com.whyc.mapper.WorksheetMainMapper;
import com.whyc.pojo.*;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@@ -48,6 +49,12 @@
    @Autowired
    private ComponentService cService;
    @Autowired
    private ProductBomService pbService;
    @Autowired
    private ComponentProductHistoryService cphService;
    @Transactional
    public boolean submit(WorksheetMain main, DocUser user) {
@@ -213,48 +220,78 @@
    public Response componentSubmit(WorksheetMain main, DocUser user) {
        Response<Object> response = new Response<>();
        List<ComponentApproving> cApprovingList = main.getCApprovingList();
        //查询是否有 已生效或者已提交审批的 相同的散装件
        List<Component> existComponentList = new LinkedList<>();
        List<ComponentApproving> existCAList = new LinkedList<>();
        //判断是新增还是删除
        boolean isAdded = cApprovingList.get(0).getSubName()!=null;
        if(isAdded) { //新增
            //查询是否有 已生效或者已提交审批的 相同的散装件
            List<Component> existComponentList = new LinkedList<>();
            List<ComponentApproving> existCAList = new LinkedList<>();
        List<Component> componentList = cService.getList();
        List<ComponentApproving> cAList = cApprovingService.getListByStatus(1);
        for (int i = 0; i < cApprovingList.size(); i++) {
            ComponentApproving componentApproving = cApprovingList.get(i);
            for (int j = 0; j < componentList.size(); j++) {
                if(componentApproving.getSubCode().equals(componentList.get(j).getSubCode())
                    && componentApproving.getSubName().equals(componentList.get(j).getSubName())
                    && componentApproving.getSubModel().equals(componentList.get(j).getSubModel())
                ){
                    existComponentList.add(componentList.get(j));
            List<Component> componentList = cService.getList();
            List<ComponentApproving> cAList = cApprovingService.getListByStatus(1);
            for (int i = 0; i < cApprovingList.size(); i++) {
                ComponentApproving componentApproving = cApprovingList.get(i);
                for (int j = 0; j < componentList.size(); j++) {
                    if (componentApproving.getSubCode().equals(componentList.get(j).getSubCode())
                            && componentApproving.getSubName().equals(componentList.get(j).getSubName())
                            && componentApproving.getSubModel().equals(componentList.get(j).getSubModel())
                    ) {
                        existComponentList.add(componentList.get(j));
                    }
                }
                for (int j = 0; j < cAList.size(); j++) {
                    if (componentApproving.getSubCode().equals(cAList.get(j).getSubCode())
                            && componentApproving.getSubName().equals(cAList.get(j).getSubName())
                            && componentApproving.getSubModel().equals(cAList.get(j).getSubModel())
                    ) {
                        existCAList.add(cAList.get(j));
                    }
                }
            }
            for (int j = 0; j < cAList.size(); j++) {
                if(componentApproving.getSubCode().equals(cAList.get(j).getSubCode())
                        && componentApproving.getSubName().equals(cAList.get(j).getSubName())
                        && componentApproving.getSubModel().equals(cAList.get(j).getSubModel())
                ){
                    existCAList.add(cAList.get(j));
            int existCASize = existCAList.size();
            int existComponentSize = existComponentList.size();
            if (existCASize != 0) {
                if (existComponentSize != 0) {
                    response.setII(21, existCAList, existComponentList, "重复提交:现有散装件及正在进行审批的散装件中,存在当前提交上传的散装件");
                } else {
                    response.set(22, existCAList, "重复提交:正在进行审批的散装件中,存在当前提交上传的散装件");
                }
                return response;
            } else {
                if (existComponentSize != 0) {
                    return response.setII(23, null, existComponentList, "重复提交:现有散装件中,存在当前提交上传的散装件");
                }
            }
        }
        }else{ //删除
            //判断是否在散装件审批删除中,是否存在产品关联及关联审批
            ComponentApproving deleteApproving = new ComponentApproving();
            List<ComponentProductHistory> existComponentProducts = new LinkedList<>();
            List<ComponentProductApproving> existComponentProductApprovingList = new LinkedList<>();
            deleteApproving = cApprovingService.getListByComponentId(cApprovingList.get(0).getComponentId());
        int existCASize = existCAList.size();
        int existComponentSize = existComponentList.size();
        if(existCASize!=0){
            if(existComponentSize!=0){
                response.setII(21,existCAList,existComponentList,"重复提交:现有散装件及正在进行审批的散装件中,存在当前提交上传的散装件");
            //查看产品关联
            List<ComponentProductHistory> cphLatestExistList =  cphService.getLatestExistListByComponentId(cApprovingList.get(0).getComponentId());
            //查看产品关联审批
            List<ComponentProductApproving> cpaLatestExistList = cpApprovingService.getLatestExistListByComponentId(cApprovingList.get(0).getComponentId());
            if(deleteApproving!=null){
                return response.set(31,deleteApproving,"拒绝本次删除申请,当前散装件正在进行删除审批");
            }
            if(cphLatestExistList!=null && cphLatestExistList.size()!=0){
                if(cpaLatestExistList!=null && cpaLatestExistList.size()!=0){
                    return response.setII(32,cpaLatestExistList,cphLatestExistList,"拒绝本次删除申请,当前散装已经关联产品及在产品关联审批");
                }else{
                    return response.setII(33,null,cphLatestExistList,"拒绝本次删除申请,当前散装件在产品关联审批");
                }
            }else{
                response.set(22,existCAList,"重复提交:正在进行审批的散装件中,存在当前提交上传的散装件");
                if(cpaLatestExistList!=null && cpaLatestExistList.size()!=0){
                    return response.set(34,cpaLatestExistList,"拒绝本次删除申请,当前散装件已经关联产品");
                }
            }
            return response;
        }else{
            if(existComponentSize!=0){
                return response.setII(23,null,existComponentList,"重复提交:现有散装件中,存在当前提交上传的散装件");
            }
        }
        }
        main.setType(EnumWorksheetType.Component.getType());
        //提交主表
        main.setCreateUserId(user.getId());