whycxzp
2022-08-24 b7e7e5bc76ee661a71d1a89acc6ff3333b496cdf
产品bom审批更新
5个文件已修改
164 ■■■■■ 已修改文件
src/main/java/com/whyc/controller/MaterialController.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/MaterialMapper.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/MaterialService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/WorksheetLinkService.java 136 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/MaterialMapper.xml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/MaterialController.java
@@ -5,10 +5,9 @@
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Api(tags = "物料管理")
@RestController
@@ -39,4 +38,10 @@
        return service.getMaterialLimit(subCode,subName,subModel,pageCurr,pageSize);
    }
    @ApiOperation(value = "test")
    @PostMapping("test")
    public List test(@RequestBody List<String> codeList){
        return service.getListByCodeList(codeList);
    }
}
src/main/java/com/whyc/mapper/MaterialMapper.java
@@ -1,8 +1,6 @@
package com.whyc.mapper;
import com.whyc.pojo.Material;
import com.whyc.pojo.ProductBom;
import com.whyc.pojo.ProductBomHistory;
import java.util.List;
@@ -17,4 +15,7 @@
    List<ProductBomHistory> getReplaceHisMaterial(String parentModel,int version);*/
    //查询所有物料(分页,模糊查询)
    List<Material> getMaterialLimit(String subCode, String subName, String subModel);
    List<String> getListByCodeList(List<String> codeList);
}
src/main/java/com/whyc/service/MaterialService.java
@@ -67,4 +67,8 @@
        List<Material> list=mapper.selectList(wrapper);
        return new Response().setII(1,list.size()>0?true:false,list,"查询所有物料(不分页)");
    }
    public List<String> getListByCodeList(List<String> codeList) {
        return mapper.getListByCodeList(codeList);
    }
}
src/main/java/com/whyc/service/WorksheetLinkService.java
@@ -6,11 +6,16 @@
import com.whyc.mapper.ProductBomApprovingMapper;
import com.whyc.mapper.WorksheetLinkMapper;
import com.whyc.pojo.*;
import com.whyc.util.CommonUtil;
import com.whyc.util.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.FileCopyUtils;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
@@ -132,9 +137,11 @@
            //审批通过,更新主表状态
            mainService.updateEndStatusById(link.getMainId(), "完结", 5);
            if (type.intValue() == EnumWorksheetType.ProductBom.getType()) { //产品审批
                //将产品文件复制至正式路径 TODO
                ProductApproving  productApproving = paService.getByMainId(link.getMainId());
                List<ProductBomApproving> approvingList = pbaService.getList(productApproving.getId());
                //查询产品最新的版本号
                String parentModel = productApproving.getParentModel();
                String parentCode = productApproving.getParentCode();
                String customCode = productApproving.getCustomCode();
                Product product = productService.getVersion(parentCode, customCode);
@@ -143,12 +150,102 @@
                    currentVersion = product.getVersion();
                }
                Integer nextVersion = currentVersion + 1;
                //将产品文件复制至正式路径
                //文件转移,未跟子件挂钩的所有图纸图片转移到产品版本下:doc_file/product/{产品型号}/standard或者{customCode}}/{version}/
                //跟子件挂钩的转移到子件图纸下:doc_file/material/
                //存储本次审批文件夹绝对路径
                String fileUrl = productApproving.getFileUrl();
                File file = new File(fileUrl);
                List<String> fileUrlList = new LinkedList<>();
                List<String> dwgUrlList = null;
                List<String> picUrlList = null;
                //存于物料下,bom内有对应
                List<String> materialUrlList = new LinkedList<>();
                //存于产品下,bom内没对应
                List<String> productUrlList = new LinkedList<>();
                List<String> productUrlNameList = new LinkedList<>();
                List<String> materialUrlNameList = new LinkedList<>();
                List<String> picUrlNameList = new LinkedList<>();
                fileUrlList = FileUtil.getStaticFilePath(file,fileUrlList);
                //图纸dwg 子件/产品
                dwgUrlList = fileUrlList.stream().filter(url->url.contains(".dwg")).collect(Collectors.toList());
                picUrlList = fileUrlList.stream().filter(url->url.contains(".png") || url.contains(".jpeg")).collect(Collectors.toList());
                dwgUrlList.forEach(dwgUrl->{
                    boolean existFlag = false;
                    for (ProductBomApproving approving :approvingList){
                        String filename = dwgUrl.substring(dwgUrl.lastIndexOf(File.separator) + 1, dwgUrl.length() - 4);
                        if(approving.getSubModel().toUpperCase().equals(filename.toUpperCase())){
                            materialUrlList.add(dwgUrl);
                            existFlag = true;
                            break;
                        }
                    }
                    if(!existFlag) {
                        productUrlList.add(dwgUrl);
                    }
                });
                //一定是有对应物料的,从bom内剥离的
                picUrlList.forEach(picUrl->{
                    for (ProductBomApproving approving :approvingList){
                        String filename = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1, picUrl.length() - 4);
                        if(approving.getSubModel().toUpperCase().equals(filename.toUpperCase())){
                            picUrlNameList.add(picUrl);
                            break;
                        }
                    }
                });
                //转移路径
                String projectDir = CommonUtil.getProjectDir();
                //doc_file/product/{产品型号}/standard或者{customCode}}/{version}/
                //跟子件挂钩的转移到子件图纸下:doc_file/material/
                String customCodeString = null;
                if(customCode==null) {
                    customCodeString = "standard";
                }else{
                    customCodeString = customCode;
                }
                String productDir = projectDir + File.separator + "doc_file" + File.separator + "product" + File.separator + parentModel
                        + File.separator + customCodeString + File.separator +nextVersion;
                String materialDir = projectDir + File.separator + "doc_file" + File.separator + "material";
                File productDirFile = new File(productDir);
                File materialFile = new File(materialDir);
                if(!productDirFile.exists()){
                    productDirFile.mkdirs();
                }
                if(!materialFile.exists()){
                    materialFile.mkdirs();
                }
                productUrlList.forEach(productUrl->{
                    String dwgName = productUrl.substring(productUrl.lastIndexOf(File.separator) + 1, productUrl.length() - 4);
                    productUrlNameList.add(dwgName);
                    try {
                        FileCopyUtils.copy(new File(productUrl),new File(productDir+File.separator+dwgName+".dwg"));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                });
                materialUrlList.forEach(materialUrl->{
                    String dwgName = materialUrl.substring(materialUrl.lastIndexOf(File.separator) + 1, materialUrl.length() - 4);
                    materialUrlNameList.add(dwgName);
                    try {
                        FileCopyUtils.copy(new File(materialUrl),new File(materialDir+File.separator+dwgName+".dwg"));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                });
                //转移审批表数据到历史表/最新版本表 product_history/product_bom_history/product/product_bom
                List<ProductBomApproving> approvingList = pbaService.getList(productApproving.getId());
                ProductHistory productHistory = new ProductHistory();
                productHistory.setParentCode(parentCode);
                productHistory.setParentName(productApproving.getParentName());
                productApproving.setParentModel(productApproving.getParentModel());
                productApproving.setParentModel(parentModel);
                productHistory.setNotes(productApproving.getNotes());
                productHistory.setCustomCode(customCode);
                productHistory.setCreateTime(new Date());
@@ -210,10 +307,37 @@
                historyService.addBatch(productBomHistoryList);
                bomService.insertBatch(productBomList);
                //物料表中不存在的,则添加到物料表中去 TODO 考虑是否需要这么操作
                //物料表中不存在的,则添加到物料表中去
                List<String> codeList = approvingList.stream().map(ProductBomApproving::getSubCode).collect(Collectors.toList());
                List<String> existCodeList = mService.getListByCodeList(codeList);
                List<Material> materialList = new LinkedList<>();
                approvingList.forEach(approving->{
                    if(!existCodeList.contains(approving.getSubCode())){ //这个审批bom中的物料不在物料管理内
                        Material temp = new Material();
                        temp.setCategory(approving.getCategory());
                        temp.setCreateDate(new Date());
                        temp.setDwgUrl(approving.getDwgUrl());
                        temp.setFileUrl(approving.getFileUrl());
                        temp.setMaterial(approving.getMaterial());
                        temp.setNotes(approving.getNotes());
                        temp.setPictureUrl(approving.getPictureUrl());
                        temp.setProducer(approving.getProducer());
                        temp.setQuantity(approving.getQuantity());
                        temp.setStatus(1);
                        temp.setSubCode(approving.getSubCode());
                        temp.setSubModel(approving.getSubModel());
                        temp.setSubName(approving.getSubName());
                        temp.setSurfaceDetail(approving.getSurfaceDetail());
                        temp.setThickness(approving.getThickness());
                        temp.setType(approving.getType());
                        temp.setUnit(approving.getUnit());
                        materialList.add(temp);
                    }
                });
                mService.insertBatch(materialList);
                //文件转移,未跟子件挂钩的所有图纸图片转移到产品版本下:doc_file/product/{产品型号}/standard或者{customCode}}/{version}/
                //跟子件挂钩的转移到子件图纸下:doc_file/material/ TODO
                //将dwg图纸和pic图片,全部更新到对应的记录url中 TODO
                /*List<ProductBomApproving> fileBomApprovingList = approvingList.stream()
                        .filter(productBomApproving ->
                                productBomApproving.getPictureUrl() != null || productBomApproving.getDwgUrl() != null
src/main/resources/mapper/MaterialMapper.xml
@@ -188,4 +188,10 @@
          and tb_material.sub_code=tb_product_bom.sub_code
          and tb_material.sub_code=#{subCode}
    </select>
    <select id="getListByCodeList" resultType="java.lang.String">
        SELECT sub_code FROM db_doc.tb_material where sub_code in
        <foreach collection="list" item="code" separator="," open="(" close=")">
            ${code}
        </foreach>
    </select>
</mapper>