whycxzp
2022-08-11 250eb9393c3356cc68d1c4c0664b80fd36ae7334
src/main/java/com/whyc/service/WorksheetMainService.java
@@ -43,6 +43,12 @@
    @Autowired
    private ComponentProductApprovingService cpApprovingService;
    @Autowired
    private ComponentApprovingService cApprovingService;
    @Autowired
    private ComponentService cService;
    @Transactional
    public boolean submit(WorksheetMain main, DocUser user) {
        main.setType(1);
@@ -204,6 +210,107 @@
        return true;
    }
    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<>();
        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));
                }
            }
        }
        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,"重复提交:现有散装件中,存在当前提交上传的散装件");
            }
        }
        main.setType(EnumWorksheetType.Component.getType());
        //提交主表
        main.setCreateUserId(user.getId());
        //提交人角色来判断工作流层级
        if(user.getRoleId().equals("1001")){
            if(main.getId()==null) {
                main.setLevel(2);
                main.setStatus(1);
                mainMapper.insert(main);
            }
            //提交子表
            WorksheetLink link =new WorksheetLink();
            link.setMainId(main.getId());
            link.setParentId(0);
            link.setDealUserId(main.getNextUser());
            link.setDealType(1);
            link.setDealDesc(main.getDealDesc());
            link.setLinkStatus(0);
            link.setEnableArchive(0);
            linkMapper.insert(link);
        }
        else if(user.getRoleId().equals("1002")){
            if(main.getId()==null) {
                main.setLevel(1);
                main.setStatus(2);
                mainMapper.insert(main);
            }
            //提交子表
            WorksheetLink link =new WorksheetLink();
            link.setMainId(main.getId());
            link.setParentId(0);
            link.setDealUserId(main.getNextUser());
            link.setDealType(2);
            link.setDealDesc(main.getDealDesc());
            link.setLinkStatus(0);
            link.setEnableArchive(1);
            linkMapper.insert(link);
        }
        else if(user.getRoleId().equals("1003")){
            main.setLevel(0);
            main.setStatus(5);
            mainMapper.insert(main);
        }else{
            return response.set(3);
        }
        //散装件-审批提交
        cApprovingList.forEach(cApproving->{
            cApproving.setCreateDate(new Date());
            cApproving.setMainId(main.getId());
            cApproving.setStatus(1);
        });
        cApprovingService.insert(cApprovingList);
        return response.set(1);
    }
    public WorksheetMain getInfoById(Integer id) {
        return mainMapper.selectById(id);
    }