whycxzp
2022-09-15 788f57c0f36ce4e625b068b5891c35ed8f8da2c7
src/main/java/com/whyc/service/ProductService.java
@@ -17,6 +17,7 @@
import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.multipart.MultipartFile;
@@ -46,8 +47,8 @@
    private MaterialService mService;
    //查询出所有的产品信息(分页加模糊查询<产品的编码,型号,名字,定制表编号>
    public Response getAllProduct(String parentCode, String parentName, String parentModel, String customCode, int pageCurr, int pageSize) {
        PageHelper.startPage(pageCurr,pageSize);
    public Response getAllProduct(String subCode,String parentCode, String parentName, String parentModel, String customCode, int pageCurr, int pageSize) {
        /*PageHelper.startPage(pageCurr,pageSize);
        QueryWrapper wrapper=new QueryWrapper();
        if(parentCode!=null){
            wrapper.like("parent_code",parentCode);
@@ -66,7 +67,8 @@
            }
        }
        wrapper.orderByAsc("id");
        List list=mapper.selectList(wrapper);
        List list=mapper.selectList(wrapper);*/
        List list=mapper.getAllProduct(subCode,parentCode,parentName,parentModel,customCode);
        PageInfo pageInfo=new PageInfo(list);
        return new Response().setII(1,list.size()>0,pageInfo,"返回产品信息");
    }
@@ -280,6 +282,7 @@
        return list;
    }
    @Transactional
    public Response add(Product product) throws IOException {
        String parentCode = product.getParentCode();
        String customCode = product.getCustomCode();
@@ -327,27 +330,44 @@
                || (relatedProduct.getParentCode().equals(product.getParentCode())
                && relatedProduct.getCustomCode().equals(product.getCustomCode())
                )
            ) { //属于是产品升级
                if (latestProduct != null && enabledProduct != null) {
                    List<MaterialProductHistory> mpList = mphService.getListByParentCodeAndCustomCodeAndVersion(parentCode, customCode, enabledProduct.getVersion());
                    if (mpList.size() != 0) { //存在关联关系
                        //当前的产品bom明细包含 继承的产品子件物料,继承关系保留
                        //设置mpList关联的物料详细信息
                        mpList = mphService.getListWithMaterialInfo(mpList);
                        List<String> newBomMaterialStrList = bomList.stream().map(bom -> bom.getSubCode() + "/" + bom.getSubModel()).collect(Collectors.toList());
                        mpList = mpList.stream().filter(mp -> newBomMaterialStrList.contains(mp.getSubMaterial().getSubCode() + "/" + mp.getSubMaterial().getSubModel())).collect(Collectors.toList());
                        if(mpList.size()!=0) {
                            if (latestProduct.getVersion().intValue() == enabledProduct.getVersion()) {
                                //最新版本生效,关联关系版本连着的
                                mphService.updateVersionBatch(mpList);
                            } else {
                                //旧版本生效,关联关系版本不连着
            ) { //属于是产品升级或基于标准产品定制
                List<MaterialProductHistory> mpList = new LinkedList<>();
                if (latestProduct != null && enabledProduct != null) { //产品升级
                    mpList = mphService.getListByParentCodeAndCustomCodeAndVersion(parentCode, customCode, enabledProduct.getVersion());
                }else{ //基于标准产品定制/新添加标准产品
                    Product version = getVersion(parentCode, "");
                    if(version!=null) { //新添加标准产品
                        int standardEnabledVersion = version.getVersion();
                        mpList = mphService.getListByParentCodeAndCustomCodeAndVersion(parentCode, "", standardEnabledVersion);
                    }
                }
                if (mpList.size() != 0) { //存在关联关系
                    //当前的产品bom明细包含 继承的产品子件物料,继承关系保留
                    //设置mpList关联的物料详细信息
                    mpList = mphService.getListWithMaterialInfo(mpList);
                    List<String> newBomMaterialStrList = bomList.stream().map(bom -> bom.getSubCode() + "/" + bom.getSubModel()).collect(Collectors.toList());
                    mpList = mpList.stream().filter(mp -> newBomMaterialStrList.contains(mp.getSubMaterial().getSubCode() + "/" + mp.getSubMaterial().getSubModel())).collect(Collectors.toList());
                    if(mpList.size()!=0) {
                        if ((latestProduct !=null && enabledProduct!=null) && latestProduct.getVersion().intValue() == enabledProduct.getVersion()) {
                            //最新版本生效,关联关系版本连着的
                            mphService.updateVersionBatch(mpList);
                        } else {
                            //关联关系版本不连着,生成新纪录:包含 升级和基于标准产品定制
                            if(customCode.equals("")) {
                                mpList.forEach(mp -> {
                                    mp.setSVersion(nextVersion);
                                    mp.setEVersion(nextVersion);
                                    mp.setCreateTime(date);
                                });
                                mphService.insertBatch(mpList);
                            }else{
                                mpList.forEach(mp -> {
                                    mp.setCustomCode(customCode);
                                    mp.setSVersion(nextVersion);
                                    mp.setEVersion(nextVersion);
                                    mp.setCreateTime(date);
                                });
                            }
                            mphService.insertBatch(mpList);
                        }
                    }
                }