whycxzp
2022-08-10 d8ca9ccd14fe70e83bd586468cbc3db569f91de2
src/main/java/com/whyc/service/WorksheetMainService.java
@@ -4,15 +4,13 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.config.EnumWorksheetType;
import com.whyc.dto.Response;
import com.whyc.dto.WorksheetMainDTO;
import com.whyc.mapper.DocUserMapper;
import com.whyc.mapper.WorksheetLinkMapper;
import com.whyc.mapper.WorksheetMainMapper;
import com.whyc.pojo.DocUser;
import com.whyc.pojo.ProductBomApproving;
import com.whyc.pojo.WorksheetLink;
import com.whyc.pojo.WorksheetMain;
import io.swagger.models.auth.In;
import com.whyc.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@@ -42,8 +40,12 @@
    @Lazy
    private ProductBomApprovingService approvingService;
    @Autowired
    private ComponentProductApprovingService cpApprovingService;
    @Transactional
    public boolean submit(WorksheetMain main, DocUser user) {
        main.setType(1);
        List<ProductBomApproving> bomList = main.getApprovingBomList();
        int rejectVersion=-1;
        //提交主表
@@ -121,6 +123,84 @@
            }
        });
        approvingService.insert(bomList);
        return true;
    }
    public boolean componentProductSubmit(WorksheetMainDTO mainDTO, DocUser user) {
        List<ComponentProductApproving> approvingList = new LinkedList<>();
        WorksheetMain main = mainDTO.getMain();
        List<ComponentProductApproving> addedList = mainDTO.getAddedList();
        List<ComponentProductApproving> replacedList = mainDTO.getReplacedList();
        List<ComponentProductApproving> removedList = mainDTO.getRemovedList();
        main.setType(EnumWorksheetType.ComponentProduct.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 false;
        }
        //散装件-产品审批提交
        if(addedList!=null && addedList.size()!=0){
            addedList.forEach(item->{
                item.setMainId(main.getId());
                item.setLinkType(1);
            });
            approvingList.addAll(addedList);
        }
        if(replacedList!=null && replacedList.size()!=0){
            replacedList.forEach(item->{
                item.setMainId(main.getId());
                item.setLinkType(2);
            });
            approvingList.addAll(replacedList);
        }
        if(removedList!=null && removedList.size()!=0){
            removedList.forEach(item->{
                item.setMainId(main.getId());
                item.setLinkType(-1);
            });
            approvingList.addAll(removedList);
        }
        cpApprovingService.insert(approvingList);
        return true;
    }
@@ -343,4 +423,5 @@
        return new Response<PageInfo<WorksheetMain>>().set(1,pageInfo);
    }
}