whycxzp
2022-08-08 deb3fd075536721b3e59d9f25472f23395c2654a
散装件更新
6个文件已添加
3个文件已修改
490 ■■■■■ 已修改文件
src/main/java/com/whyc/controller/ComponentApprovingController.java 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/WorksheetMainController.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/dto/WorksheetMainDTO.java 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/ComponentProductApprovingMapper.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/ComponentProductApproving.java 70 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/ComponentProductHistory.java 45 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/ComponentApprovingService.java 168 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/ComponentProductApprovingService.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/WorksheetMainService.java 91 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/ComponentApprovingController.java
New file
@@ -0,0 +1,35 @@
package com.whyc.controller;
import com.whyc.dto.Response;
import com.whyc.pojo.ProductBomApproving;
import com.whyc.service.ComponentApprovingService;
import com.whyc.service.ProductBomApprovingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
/**
 * 散装件解析
 */
@RestController
@RequestMapping("componentApproving")
@Api(tags = "散装件审批解析")
public class ComponentApprovingController {
    @Autowired
    private ComponentApprovingService service;
    @PostMapping("zipParse")
    @ApiOperation("zip解析")
    public Response zipParse(@RequestParam("file") MultipartFile file) throws IOException, InvalidFormatException {
        return service.zipParse(file);
    }
}
src/main/java/com/whyc/controller/WorksheetMainController.java
@@ -2,6 +2,7 @@
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.dto.WorksheetMainDTO;
import com.whyc.pojo.DocUser;
import com.whyc.pojo.WorksheetMain;
import com.whyc.service.WorksheetMainService;
@@ -35,10 +36,10 @@
    }
    @PostMapping("componentRelatedSubmit")
    @ApiOperation(value="散装件-产品审批提交",notes = "type:1(关联),2(替换),3(删除),4(解除);散装件-产品的信息在approvingBomList,这个对象数组内,componentList为关联的散装件")
    public Response componentProductSubmit(@RequestParam int type,@RequestBody WorksheetMain main){
    @ApiOperation(value="散装件-产品审批提交")
    public Response componentProductSubmit(@RequestBody WorksheetMainDTO mainDTO){
        DocUser user = ActionUtil.getUser();
        boolean res = service.componentProductSubmit(type,main,user);
        boolean res = service.componentProductSubmit(mainDTO,user);
        if(res) {
            return new Response().set(1,true, "提交完成");
        }else{
src/main/java/com/whyc/dto/WorksheetMainDTO.java
New file
@@ -0,0 +1,49 @@
package com.whyc.dto;
import com.whyc.pojo.ComponentProductApproving;
import com.whyc.pojo.WorksheetMain;
import java.util.List;
/**
 * 工作流主表,关联散件产品
 */
public class WorksheetMainDTO {
    private WorksheetMain main;
    private List<ComponentProductApproving> addedList;
    private List<ComponentProductApproving> replacedList;
    private List<ComponentProductApproving> removedList;
    public WorksheetMain getMain() {
        return main;
    }
    public void setMain(WorksheetMain main) {
        this.main = main;
    }
    public List<ComponentProductApproving> getAddedList() {
        return addedList;
    }
    public void setAddedList(List<ComponentProductApproving> addedList) {
        this.addedList = addedList;
    }
    public List<ComponentProductApproving> getReplacedList() {
        return replacedList;
    }
    public void setReplacedList(List<ComponentProductApproving> replacedList) {
        this.replacedList = replacedList;
    }
    public List<ComponentProductApproving> getRemovedList() {
        return removedList;
    }
    public void setRemovedList(List<ComponentProductApproving> removedList) {
        this.removedList = removedList;
    }
}
src/main/java/com/whyc/mapper/ComponentProductApprovingMapper.java
New file
@@ -0,0 +1,6 @@
package com.whyc.mapper;
import com.whyc.pojo.ComponentProductApproving;
public interface ComponentProductApprovingMapper extends CustomMapper<ComponentProductApproving> {
}
src/main/java/com/whyc/pojo/ComponentProductApproving.java
New file
@@ -0,0 +1,70 @@
package com.whyc.pojo;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import org.apache.ibatis.type.Alias;
@TableName(schema = "db_doc",value = "tb_component_product_approving")
@Alias("ComponentProductApproving")
public class ComponentProductApproving {
    private Integer id;
    @ApiModelProperty("散装件id")
    private Integer componentId;
    @ApiModelProperty("母料型号")
    private String parentModel;
    @ApiModelProperty("子件名称")
    private String subName;
    @ApiModelProperty("关联类型:-1(移除),1(关联),2(替换)")
    private Integer linkType;
    @ApiModelProperty("主表id")
    private Integer mainId;
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public Integer getComponentId() {
        return componentId;
    }
    public void setComponentId(Integer componentId) {
        this.componentId = componentId;
    }
    public String getParentModel() {
        return parentModel;
    }
    public void setParentModel(String parentModel) {
        this.parentModel = parentModel;
    }
    public String getSubName() {
        return subName;
    }
    public void setSubName(String subName) {
        this.subName = subName;
    }
    public Integer getMainId() {
        return mainId;
    }
    public void setMainId(Integer mainId) {
        this.mainId = mainId;
    }
    public Integer getLinkType() {
        return linkType;
    }
    public void setLinkType(Integer linkType) {
        this.linkType = linkType;
    }
}
src/main/java/com/whyc/pojo/ComponentProductHistory.java
@@ -17,10 +17,11 @@
    private String parentModel;
    @ApiModelProperty("子件名称")
    private String subName;
    private Date createTime;
    @ApiModelProperty("关联类型:1(关联),2(替换)")
    private Integer linkType;
    private Integer sVersion;
    private Integer eVersion;
    private Date createTime;
    public Integer getId() {
        return id;
@@ -54,6 +55,38 @@
        this.subName = subName;
    }
    public Integer getSVersion() {
        return sVersion;
    }
    public void setSVersion(Integer sVersion) {
        this.sVersion = sVersion;
    }
    public Integer getEVersion() {
        return eVersion;
    }
    public void setEVersion(Integer eVersion) {
        this.eVersion = eVersion;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Integer getLinkType() {
        return linkType;
    }
    public void setLinkType(Integer linkType) {
        this.linkType = linkType;
    }
    public Integer getsVersion() {
        return sVersion;
    }
@@ -68,13 +101,5 @@
    public void seteVersion(Integer eVersion) {
        this.eVersion = eVersion;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
}
src/main/java/com/whyc/service/ComponentApprovingService.java
New file
@@ -0,0 +1,168 @@
package com.whyc.service;
import com.whyc.dto.FileUrlDTO;
import com.whyc.dto.Response;
import com.whyc.pojo.DocUser;
import com.whyc.pojo.ProductBomApproving;
import com.whyc.util.ActionUtil;
import com.whyc.util.CommonUtil;
import com.whyc.util.FileUtil;
import com.whyc.util.Zip4jUtil;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
@Service
public class ComponentApprovingService {
    /**
     *  TODO 后续修改调试
     * @param file
     * @return
     * @throws IOException
     * @throws InvalidFormatException
     */
    public Response zipParse(MultipartFile file) throws IOException, InvalidFormatException {
        List<ProductBomApproving> list = new LinkedList<>();
        List<ProductBomApproving> referenceList = new LinkedList<>();
        Response response = new Response();
        //检查是否为zip
        boolean isZip = Zip4jUtil.checkZipFileParam(file);
        if(!isZip){
            return response.set(1,false,"上传的文件格式不是zip");
        }
        //zip存储路径:doc_file/product_approving/${username}/{dateFormat}/${timeStamp}
        String rootFile = CommonUtil.getRootFile();
        DocUser user = ActionUtil.getUser();
        String dateFormat = new SimpleDateFormat("YYYY-MM").format(new Date());
        long timeStamp = System.currentTimeMillis();
        String filePath = rootFile + File.separator + "component_approving" + File.separator + user.getName() + File.separator + dateFormat+ File.separator + timeStamp;
        File parentFile = new File(filePath);
        String originalFilename = file.getOriginalFilename();
        File zipFile = new File(filePath+File.separator+ originalFilename);
        if(!zipFile.exists()){
            zipFile.mkdirs();
        }
        file.transferTo(zipFile);
        //解压文件夹
        Zip4jUtil.unPackZip(zipFile,null,filePath);
        //遍历解压后的文件夹路径,解析excel
        System.out.println(filePath);
        List<String> fileList = new ArrayList<>();
        for (int i = 0; i < fileList.size(); i++) {
            String fileTempUrl = fileList.get(i);
            //查询到xls数据
            if(fileTempUrl.contains(".xls")){
                File fileTemp = new File(fileTempUrl);
                Workbook workbook = null;
                workbook = WorkbookFactory.create(fileTemp);
                List<? extends PictureData> allPictures = workbook.getAllPictures();
                //取第一个sheet表
                Sheet sheet = workbook.getSheetAt(0);
                int lastRowNum = sheet.getLastRowNum();
                //取第三行,并以第三行开始
                Row rowTemp = sheet.getRow(1);
                short lastCellNum = rowTemp.getLastCellNum();
                //先单独获取产品型号和版本号/分类
                Row row = sheet.getRow(1);
                String type = row.getCell(1).getStringCellValue();
                Row row2 = sheet.getRow(2);
                String productModel = row2.getCell(5).getStringCellValue();
                Row row3 = sheet.getRow(3);
                String productVersion = row3.getCell(5).getStringCellValue();
                for (int l = 9; l < lastRowNum-1; l++) {
                    ProductBomApproving bomApproving = new ProductBomApproving();
                    bomApproving.setParentModel(productModel);
                    bomApproving.setParentVersion(productVersion);
                    bomApproving.setType(type);
                    bomApproving.setExcelName(fileTempUrl.substring(fileTempUrl.lastIndexOf(File.separator)+1));
                    for (int m = 2; m < lastCellNum; m++) {
                        row = sheet.getRow(l);
                        Cell cell = row.getCell(m);
                        String cellValue = null;
                        int cellValueInt = 0;
                        Double cellValueDouble = null;
                        if(m == 3){
                            cellValueDouble = cell.getNumericCellValue();
                            DecimalFormat decimalFormat = new DecimalFormat("0");
                            cellValue = decimalFormat.format(cellValueDouble);
                        }
                        else if(m ==7){
                            cellValueDouble = cell.getNumericCellValue();
                            if(cellValueDouble.equals(0d)){
                                cellValue = "";
                            }else{
                                cellValue = cellValueDouble.toString();
                            }
                        }
                        else if(m==8){
                            cellValueDouble = cell.getNumericCellValue();
                        }
                        else {
                            cellValue = cell.getStringCellValue();
                        }
                        switch (m){
                            case 2:{bomApproving.setCategory(cellValue);}break;
                            case 3:{bomApproving.setSubCode(cellValue);}break;
                            case 4:{bomApproving.setSubName(cellValue);}break;
                            case 5:{
                                /*bomApproving.setSubModel(cellValue);
                                //判断图纸查看是否存在
                                bomApproving.setDwgExist(0);
                                String dwgFileName = cellValue+".dwg";
                                for (int n = 0; n < dwgExistsList.size(); n++) {
                                    FileUrlDTO fileUrlDTO = dwgExistsList.get(n);
                                    if(dwgFileName.equals(fileUrlDTO.getFileName())){
                                        //存在
                                        bomApproving.setDwgExist(1);
                                        bomApproving.setDwgUrl(fileUrlDTO.getHttpFileUrl());
                                        break;
                                    }
                                }*/
                            }break;
                            case 6:{bomApproving.setMaterial(cellValue);}break;
                            case 7:{bomApproving.setThickness(cellValue);}break;
                            case 8:{bomApproving.setQuantity(cellValueDouble.intValue());}break;
                            case 9:{bomApproving.setSurfaceDetail(cellValue);}break;
                            case 10:{bomApproving.setNotes(cellValue);}break;
                            case 11:{
                                //图片,从0开始,到图片size为止
                                int k = l-9;
                                if(k<allPictures.size()-1){
                                    PictureData pictureData = allPictures.get(k+1);
                                    //图片存储 doc_file/product_approving/${username}/{dateFormat}/${timeStamp}
                                    String suffix = pictureData.suggestFileExtension();
                                    String picturePath = filePath + File.separator + bomApproving.getSubModel() + "." + suffix;
                                    String picturePathFront = "doc_file" + File.separator + "product_approving" + File.separator + user.getName() + File.separator + dateFormat + File.separator + timeStamp  + File.separator + bomApproving.getSubModel() + "." + suffix;
                                    byte[] data = pictureData.getData();
                                    FileOutputStream fileOutputStream = null;
                                    File pictureFile = new File(picturePath);
                                    fileOutputStream = new FileOutputStream(pictureFile);
                                    fileOutputStream.write(data);
                                    bomApproving.setPictureUrl(picturePathFront);
                                }
                            }break;
                        }
                    }
                    list.add(bomApproving);
                }
            }
        }
        String nextTitle = originalFilename.substring(0,originalFilename.lastIndexOf("."));
        return response.setIII(1,true,list,nextTitle,"解析完成");
    }
}
src/main/java/com/whyc/service/ComponentProductApprovingService.java
New file
@@ -0,0 +1,19 @@
package com.whyc.service;
import com.whyc.mapper.ComponentProductApprovingMapper;
import com.whyc.pojo.ComponentProductApproving;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class ComponentProductApprovingService {
    @Resource
    private ComponentProductApprovingMapper mapper;
    public void insert(List<ComponentProductApproving> approvingList) {
        mapper.insertBatchSomeColumn(approvingList);
    }
}
src/main/java/com/whyc/service/WorksheetMainService.java
@@ -5,14 +5,11 @@
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
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;
@@ -41,6 +38,9 @@
    @Autowired
    @Lazy
    private ProductBomApprovingService approvingService;
    @Autowired
    private ComponentProductApprovingService cpApprovingService;
    @Transactional
    public boolean submit(WorksheetMain main, DocUser user) {
@@ -121,6 +121,83 @@
            }
        });
        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.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;
    }
@@ -344,8 +421,4 @@
    }
    public boolean componentProductSubmit(int type, WorksheetMain main, DocUser user) {
         return false;
    }
}