whycxzp
2022-08-31 b03a9514b19665fcfbd4b3138d6d56899496f755
产品新增更新
3个文件已修改
57 ■■■■■ 已修改文件
src/main/java/com/whyc/controller/ProductController.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/Product.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/ProductService.java 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/ProductController.java
@@ -1,6 +1,7 @@
package com.whyc.controller;
import com.whyc.dto.Response;
import com.whyc.pojo.Product;
import com.whyc.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -81,4 +82,10 @@
    public Response zipParse(@RequestParam("file") MultipartFile file) throws IOException, InvalidFormatException {
        return service.zipParse(file);
    }
    @PostMapping
    @ApiOperation(value = "新增",notes = "解析时返回的绝对路径,需要回传到字段fileUrl")
    public Response add(@RequestBody Product product){
        return service.add(product);
    }
}
src/main/java/com/whyc/pojo/Product.java
@@ -50,6 +50,10 @@
    @TableField(exist = false)
    private List materialIds;
    @TableField(exist = false)
    private List<ProductBom> bomList;
    @TableField(exist = false)
    private String fileUrl;
}
src/main/java/com/whyc/service/ProductService.java
@@ -8,9 +8,7 @@
import com.whyc.dto.FileUrlDTO;
import com.whyc.dto.Response;
import com.whyc.mapper.ProductMapper;
import com.whyc.pojo.DocUser;
import com.whyc.pojo.Product;
import com.whyc.pojo.ProductBom;
import com.whyc.pojo.*;
import com.whyc.util.ActionUtil;
import com.whyc.util.CommonUtil;
import com.whyc.util.FileUtil;
@@ -32,6 +30,13 @@
public class ProductService {
    @Autowired(required = false)
    private ProductMapper mapper;
    @Autowired
    private ProductHistoryService phService;
    @Autowired
    private MaterialProductHistoryService mphService;
    //查询出所有的产品信息(分页加模糊查询<产品的编码,型号,名字,定制表编号>
    public Response getAllProduct(String parentCode, String parentName, String parentModel, String customCode, int pageCurr, int pageSize) {
@@ -263,4 +268,39 @@
        });
        return list;
    }
    public Response add(Product product) {
        String parentCode = product.getParentCode();
        String customCode = product.getCustomCode();
        //查询产品最新的版本号
        ProductHistory latestProduct = phService.getLatestVersion(parentCode, customCode);
        ProductHistory enabledProduct = phService.getEnabledByParentCodeAndCustomCode(parentCode, customCode);
        int currentVersion = 0;
        if (latestProduct != null) {
            currentVersion = latestProduct.getVersion();
        }
        Integer nextVersion = currentVersion + 1;
        //产品物料关系迁移
        //查询生效版本的关联关系
        if(latestProduct!=null &&enabledProduct!=null) {
            List<MaterialProductHistory> mpList = mphService.getListByParentCodeAndCustomCodeAndVersion(parentCode, customCode, enabledProduct.getVersion());
            if (latestProduct.getVersion().intValue() == enabledProduct.getVersion()) {
                //最新版本生效,关联关系版本连着的
                mphService.updateVersionBatch(mpList);
            } else {
                //旧版本生效,关联关系版本不连着
                mpList.forEach(mp -> {
                    mp.setSVersion(nextVersion);
                    mp.setEVersion(nextVersion);
                });
                mphService.insertBatch(mpList);
            }
        }
        //将产品文件复制至正式路径
        //物料表中不存在的,则添加到物料表中去(包含product这个物料)
        return null;
    }
}