whycxzp
2022-09-03 f40f45162d69d751628a8fa0c6784abb237d4eaa
src/main/java/com/whyc/service/WorksheetMainService.java
@@ -12,9 +12,9 @@
import com.whyc.mapper.WorksheetLinkMapper;
import com.whyc.mapper.WorksheetMainMapper;
import com.whyc.pojo.*;
import com.whyc.util.ActionUtil;
import com.whyc.util.CommonUtil;
import com.whyc.util.Zip4jUtil;
import org.aspectj.util.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@@ -49,28 +49,40 @@
    private ProductBomApprovingService approvingService;
    @Autowired
    private ComponentProductApprovingService cpApprovingService;
    private ProductApprovingService paService;
    @Autowired
    private ComponentApprovingService cApprovingService;
    private MaterialProductApprovingService cpApprovingService;
    @Autowired
    private ComponentService cService;
    private MaterialApprovingService mApprovingService;
    @Autowired
    private MaterialService mService;
    @Autowired
    private ProductBomService pbService;
    @Autowired
    private ComponentProductHistoryService cphService;
    private MaterialProductHistoryService cphService;
    @Autowired
    private ProductSoftwareApprovingService psaService;
    @Autowired
    private ProductSoftwareService productSoftwareService;
    @Autowired
    private ProductService productService;
    @Autowired
    private ProductHistoryService productHistoryService;
    @Transactional
    public boolean submit(WorksheetMain main, DocUser user) {
    public boolean submit(WorksheetMain main, DocUser user) throws IOException {
        main.setType(1);
        List<ProductBomApproving> bomList = main.getApprovingBomList();
        int rejectVersion=-1;
        ProductApproving productApproving = main.getProductApproving();
        List<ProductBomApproving> bomList = productApproving.getBomApprovingList();
        //提交主表
        main.setCreateUserId(user.getId());
        //提交人角色来判断工作流层级
@@ -79,8 +91,6 @@
                main.setLevel(2);
                main.setStatus(1);
                mainMapper.insert(main);
            }else {
                rejectVersion = approvingService.getRejectVersion(main.getId());
            }
            //提交子表
            WorksheetLink link =new WorksheetLink();
@@ -91,7 +101,6 @@
            link.setDealDesc(main.getDealDesc());
            link.setLinkStatus(0);
            link.setEnableArchive(0);
            link.setRejectVersion(rejectVersion+1);
            linkMapper.insert(link);
        }
        else if(user.getRoleId().equals("1002")){
@@ -99,8 +108,6 @@
                main.setLevel(1);
                main.setStatus(2);
                mainMapper.insert(main);
            }else {
                rejectVersion = approvingService.getRejectVersion(main.getId());
            }
            //提交子表
            WorksheetLink link =new WorksheetLink();
@@ -111,7 +118,6 @@
            link.setDealDesc(main.getDealDesc());
            link.setLinkStatus(0);
            link.setEnableArchive(1);
            link.setRejectVersion(rejectVersion+1);
            linkMapper.insert(link);
        }
        else if(user.getRoleId().equals("1003")){
@@ -122,12 +128,49 @@
            return false;
        }
        //产品bom/图纸图片提交
        //查询当前驳回版本
        int nextRejectVersion = rejectVersion+1;
        if(productApproving.getCustomCode()!=null && bomList.get(0).getId()!=null) { //与前端约定 定制表单号关联产品,则关联的产品id写入id
            Product product = productService.getById(bomList.get(0).getId());
            List<ProductBom> productBomList = pbService.getBomByProductId(bomList.get(0).getId());
            //product下的图纸复制到新的审批路径
            String rootFile = CommonUtil.getRootFile();
            String dateFormat = new SimpleDateFormat("YYYY-MM").format(new Date());
            long timeStamp = System.currentTimeMillis();
            String filePath = rootFile + "product_approving" + File.separator + user.getName() + File.separator + dateFormat+ File.separator + timeStamp;
            String inFilePath = rootFile + "product" + File.separator + product.getParentModel() + File.separator + "standard"+ File.separator + product.getVersion();
            File parentFile = new File(filePath);
            //FileCopyUtils.copy(new File(inFilePath),parentFile);
            FileUtil.copyDir(new File(inFilePath),parentFile);
            productApproving.setFileUrl(filePath);
            bomList.clear();
            productBomList.forEach(bom->{
                ProductBomApproving approving = new ProductBomApproving();
                approving.setCategory(bom.getCategory());
                approving.setSubCode(bom.getSubCode());
                approving.setSubName(bom.getSubName());
                approving.setSubModel(bom.getSubModel());
                approving.setUnit(bom.getUnit());
                approving.setQuantity(bom.getQuantity());
                approving.setProducer(bom.getProducer());
                approving.setMaterial(bom.getMaterial());
                approving.setThickness(bom.getThickness());
                approving.setSurfaceDetail(bom.getSurfaceDetail());
                approving.setNotes(bom.getNotes());
                bomList.add(approving);
            });
        }
        //冻结(不启用)已存在的产品编码+定制保单号
        productService.deleteByParentCodeAndCustomCode(productApproving.getParentCode(),productApproving.getCustomCode());
        productHistoryService.updateEnabledStatus(productApproving.getParentCode(),productApproving.getCustomCode(),0);
        productApproving.setMainId(main.getId());
        productApproving.setCreateTime(new Date());
        paService.insert(productApproving);
        bomList.forEach(bom->{
            bom.setMainId(main.getId());
            //bom.setMainId(main.getId());
            bom.setProductApprovingId(productApproving.getId());
            bom.setUpUserId(user.getId());
            bom.setRejectVersion(nextRejectVersion);
            bom.setCreateDate(new Date());
            if(bom.getDwgUrl()==null){
                bom.setDwgUrl("");
@@ -149,14 +192,14 @@
        return true;
    }
    public boolean componentProductSubmit(WorksheetMainDTO mainDTO, DocUser user) {
        List<ComponentProductApproving> approvingList = new LinkedList<>();
    public boolean MaterialProductSubmit(WorksheetMainDTO mainDTO, DocUser user) {
        List<MaterialProductApproving> approvingList = new LinkedList<>();
        WorksheetMain main = mainDTO.getMain();
        List<ComponentProductApproving> addedList = mainDTO.getAddedList();
        List<ComponentProductApproving> replacedList = mainDTO.getReplacedList();
        List<ComponentProductApproving> removedList = mainDTO.getRemovedList();
        List<MaterialProductApproving> addedList = mainDTO.getAddedList();
        //List<MaterialProductApproving> replacedList = mainDTO.getReplacedList();
        List<MaterialProductApproving> removedList = mainDTO.getRemovedList();
        main.setType(EnumWorksheetType.ComponentProduct.getType());
        main.setType(EnumWorksheetType.MaterialProduct.getType());
        //提交主表
        main.setCreateUserId(user.getId());
        //提交人角色来判断工作流层级
@@ -201,7 +244,7 @@
        }else{
            return false;
        }
        //散装件-产品审批提交
        //物料-产品审批提交
        if(addedList!=null && addedList.size()!=0){
            addedList.forEach(item->{
                item.setMainId(main.getId());
@@ -209,13 +252,13 @@
            });
            approvingList.addAll(addedList);
        }
        if(replacedList!=null && replacedList.size()!=0){
        /*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());
@@ -227,33 +270,33 @@
        return true;
    }
    public Response componentSubmit(WorksheetMain main, DocUser user) {
    public Response materialSubmit(WorksheetMain main, DocUser user) {
        Response<Object> response = new Response<>();
        List<ComponentApproving> cApprovingList = main.getCApprovingList();
        List<MaterialApproving> mApprovingList = main.getMApprovingList();
        //判断是新增还是删除
        boolean isAdded = cApprovingList.get(0).getSubName()!=null;
        boolean isAdded = mApprovingList.get(0).getSubName()!=null;
        if(isAdded) { //新增
            //查询是否有 已生效或者已提交审批的 相同的散装件
            List<Component> existComponentList = new LinkedList<>();
            List<ComponentApproving> existCAList = new LinkedList<>();
            //查询是否有 已生效或者已提交审批的 相同的物料
            List<Material> existMaterialList = new LinkedList<>();
            List<MaterialApproving> 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())
            List<Material> materialList = mService.getList();
            List<MaterialApproving> cAList = mApprovingService.getListByStatus(1);
            for (int i = 0; i < mApprovingList.size(); i++) {
                MaterialApproving materialApproving = mApprovingList.get(i);
                for (int j = 0; j < materialList.size(); j++) {
                    if (materialApproving.getSubCode().equals(materialList.get(j).getSubCode())
                            && materialApproving.getSubName().equals(materialList.get(j).getSubName())
                            && materialApproving.getSubModel().equals(materialList.get(j).getSubModel())
                    ) {
                        existComponentList.add(componentList.get(j));
                        existMaterialList.add(materialList.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())
                    if (materialApproving.getSubCode().equals(cAList.get(j).getSubCode())
                            && materialApproving.getSubName().equals(cAList.get(j).getSubName())
                            && materialApproving.getSubModel().equals(cAList.get(j).getSubModel())
                    ) {
                        existCAList.add(cAList.get(j));
                    }
@@ -261,48 +304,47 @@
            }
            int existCASize = existCAList.size();
            int existComponentSize = existComponentList.size();
            int existMaterialSize = existMaterialList.size();
            if (existCASize != 0) {
                if (existComponentSize != 0) {
                    response.setII(21, existCAList, existComponentList, "重复提交:现有散装件及正在进行审批的散装件中,存在当前提交上传的散装件");
                if (existMaterialSize != 0) {
                    response.setII(21, existCAList, existMaterialList, "重复提交:现有物料及正在进行审批的物料中,存在当前提交上传的物料");
                } else {
                    response.set(22, existCAList, "重复提交:正在进行审批的散装件中,存在当前提交上传的散装件");
                    response.set(22, existCAList, "重复提交:正在进行审批的物料中,存在当前提交上传的物料");
                }
                return response;
            } else {
                if (existComponentSize != 0) {
                    return response.setII(23, null, existComponentList, "重复提交:现有散装件中,存在当前提交上传的散装件");
                if (existMaterialSize != 0) {
                    return response.setII(23, null, existMaterialList, "重复提交:现有物料中,存在当前提交上传的物料");
                }
            }
        }else{ //删除
            //判断是否在散装件审批删除中,是否存在产品关联及关联审批
            ComponentApproving deleteApproving = new ComponentApproving();
            List<ComponentProductHistory> existComponentProducts = new LinkedList<>();
            List<ComponentProductApproving> existComponentProductApprovingList = new LinkedList<>();
            deleteApproving = cApprovingService.getListByComponentId(cApprovingList.get(0).getComponentId());
            //判断是否在物料审批删除中,是否存在产品关联及关联审批
            MaterialApproving deleteApproving = new MaterialApproving();
            List<MaterialProductHistory> existMaterialProducts = new LinkedList<>();
            List<MaterialProductApproving> existMaterialProductApprovingList = new LinkedList<>();
            deleteApproving = mApprovingService.getListByMaterialId(mApprovingList.get(0).getMaterialId());
            //查看产品关联
            List<ComponentProductHistory> cphLatestExistList =  cphService.getLatestExistListByComponentId(cApprovingList.get(0).getComponentId());
            List<MaterialProductHistory> cphLatestExistList =  cphService.getLatestExistListByMaterialId(mApprovingList.get(0).getMaterialId());
            //查看产品关联审批
            List<ComponentProductApproving> cpaLatestExistList = cpApprovingService.getLatestExistListByComponentId(cApprovingList.get(0).getComponentId());
            List<MaterialProductApproving> cpaLatestExistList = cpApprovingService.getLatestExistListByMaterialId(mApprovingList.get(0).getMaterialId());
            if(deleteApproving!=null){
                return response.set(31,deleteApproving,"拒绝本次删除申请,当前散装件正在进行删除审批");
                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,"拒绝本次删除申请,当前散装件在产品关联审批");
                    return response.setII(33,null,cphLatestExistList,"拒绝本次删除申请,当前物料在产品关联审批");
                }
            }else{
                if(cpaLatestExistList!=null && cpaLatestExistList.size()!=0){
                    return response.set(34,cpaLatestExistList,"拒绝本次删除申请,当前散装件已经关联产品");
                    return response.set(34,cpaLatestExistList,"拒绝本次删除申请,当前物料已经关联产品");
                }
            }
        }
        main.setType(EnumWorksheetType.Component.getType());
        main.setType(EnumWorksheetType.Material.getType());
        //提交主表
        main.setCreateUserId(user.getId());
        //提交人角色来判断工作流层级
@@ -347,23 +389,38 @@
        }else{
            return response.set(3);
        }
        //散装件-审批提交
        cApprovingList.forEach(cApproving->{
        //物料-审批提交
        mApprovingList.forEach(cApproving->{
            cApproving.setCreateDate(new Date());
            cApproving.setMainId(main.getId());
            cApproving.setStatus(1);
        });
        cApprovingService.insert(cApprovingList);
        mApprovingService.insert(mApprovingList);
        return response.set(1);
    }
    public Response productSoftwareSubmit(WorksheetMainDTO2 mainDTO, DocUser user) throws IOException {
    public Response productSoftwareSubmit(MultipartFile file, WorksheetMainDTO2 mainDTO, DocUser user) throws IOException {
        Response response = new Response();
        WorksheetMain main = mainDTO.getMain();
        ProductSoftwareApproving approving = mainDTO.getApproving();
        MultipartFile file = mainDTO.getFile();
        //首先校验文件名是否已存在
        String filename = file.getOriginalFilename();
        List<ProductSoftwareApproving> softwareApprovingList = psaService.getAll();
        List<ProductSoftware> softwareList = productSoftwareService.getAll();
        List<String> existApprovingList = softwareApprovingList.stream().map(ProductSoftwareApproving::getSoftwareName).collect(Collectors.toList());
        List<String> existList = softwareList.stream().map(ProductSoftware::getSoftwareName).collect(Collectors.toList());
        for (String existFilename:existList){
            if(filename.equals(existFilename)){
                return response.set(1,false,"软件文件名已存在");
            }
        }
        for (String existFilename:existApprovingList){
            if(filename.equals(existFilename)){
                return response.set(1,false,"软件文件名在审批列表中已存在");
            }
        }
        main.setType(1);
        //提交主表
@@ -429,6 +486,7 @@
        }
        file.transferTo(zipFile);
        approving.setSoftwareUrl("doc_file"+productSoftwarePath+File.separator+ originalFilename);
        approving.setSoftwareName(originalFilename);
        approving.setCreateTime(new Date());
        approving.setMainId(main.getId());
        //产品软件提交
@@ -588,11 +646,14 @@
         //判断是哪种类型的审批,返回不同的类型 具体数据
        Integer type = getInfoById(id).getType();
        if(type.intValue() == EnumWorksheetType.ProductBom.getType()) {
            return mainMapper.getLinkList(id);
        }else if(type.intValue() == EnumWorksheetType.Component.getType()){
            return mainMapper.getLinkListWithComponents(id);
        }else{ //散装件-产品
            return mainMapper.getLinkListWithComponentProducts(id);
            WorksheetMain main = mainMapper.getLinkList(id);
            List<ProductBomApproving> pbaList = approvingService.getList(main.getProductApproving().getId());
            main.getProductApproving().setBomApprovingList(pbaList);
            return main;
        }else if(type.intValue() == EnumWorksheetType.Material.getType()){
            return mainMapper.getLinkListWithMaterials(id);
        }else{ //物料-产品
            return mainMapper.getLinkListWithMaterialProducts(id);
        }
    }