whycxzp
2023-07-04 4e0147ac43533a4dc99f86d443618a4959c28162
src/main/java/com/whyc/service/MaterialService.java
@@ -1,11 +1,11 @@
package com.whyc.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.FileDirPath;
import com.whyc.dto.MaterialCheckDTO;
import com.whyc.dto.Response;
import com.whyc.mapper.MaterialMapper;
import com.whyc.pojo.DocUser;
@@ -25,10 +25,7 @@
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@@ -272,7 +269,7 @@
                        cellValue = cell.getStringCellValue();
                        switch (m){
                            case 2:{material.setCategory(cellValue);}break;
                            //case 2:{material.setCategory(cellValue);}break;
                            case 3:{material.setSubCode(cellValue);}break;
                            case 4:{material.setSubName(cellValue);}break;
                            case 5:{material.setSubModel(cellValue);}break;
@@ -306,6 +303,19 @@
                return response.set(1,false,"拒绝解析,excel文件中记录包含名称为空的记录");
            }
        }
        //追加物料规范校验 暂时去除校验
        /*List<MaterialCheckDTO> checkList = list.stream().map(material -> {
            MaterialCheckDTO dto = new MaterialCheckDTO();
            dto.setNum(material.getId());
            dto.setSubCode(material.getSubCode());
            dto.setSubName(material.getSubName());
            dto.setSubModel(material.getSubModel());
            return dto;
        }).collect(Collectors.toList());
        List<MaterialCheckDTO> irregularList = CommonUtil.checkFormat(checkList);
        if(irregularList.size()>0){
            return new Response().setII(1,false,irregularList,"名称或型号命名不规范");
        }*/
        return response.setII(1,true,list,filePath);
    }
    //根据物料id查询返回附件文件夹下所有的文件列表
@@ -523,28 +533,47 @@
        return mapper.getSameSubCodeAndModel(bomList);
    }
    public void updateFillCategory(String sign) {
        if(sign.equals("perryhsu")){ //允许操作
            //联查产品物料历史表,获取物料对应的类别
            List<Material> materialList = mapper.getCategory();
            List<Material> materialWithOneCategoryList = new LinkedList<>();
            Map<Integer, List<Material>> materialIdMap = materialList.stream().collect(Collectors.groupingBy(Material::getId));
            Set<Integer> materialIdSet = materialIdMap.keySet();
            for (Integer materialId : materialIdSet) {
                List<Material> temp = materialIdMap.get(materialId);
                if(temp.size()==1){
                    materialWithOneCategoryList.add(temp.get(0));
                }else{
                    System.err.println("物料id:"+materialId+"对应"+temp.size()+"个类别"+temp.get(0).getCategory()+"/"+temp.get(1).getCategory());
                }
            }
            //将类别回填到物料表
            for (int i = 0; i < materialWithOneCategoryList.size(); i++) {
                Material material = materialWithOneCategoryList.get(i);
                UpdateWrapper<Material> update = Wrappers.update();
                update.set("category",material.getCategory()).eq("id",material.getId());
                mapper.update(null,update);
            }
    public void checkNaming(InputStream inputStream, HttpServletResponse response) throws IOException, InvalidFormatException {
        List<MaterialCheckDTO> checkList = new LinkedList<>();
        Workbook workbook = null;
        workbook = WorkbookFactory.create(inputStream);
        inputStream.close();
        //取第一个sheet表
        Sheet sheet = workbook.getSheetAt(0);
        int lastRowNum = sheet.getLastRowNum();
        for (int i = 1; i <= lastRowNum; i++) {
            System.out.println(i);
            //从第二行开始
            Row row = sheet.getRow(i);
            Cell cell = row.getCell(0);
            cell.setCellType(CellType.STRING);
            String code = cell.getStringCellValue();
            String name = row.getCell(1).getStringCellValue();
            Cell cell2 = row.getCell(2);
            cell2.setCellType(CellType.STRING);
            String model = cell2.getStringCellValue();
            MaterialCheckDTO dto = new MaterialCheckDTO();
            dto.setNum(i);
            dto.setSubName(name);
            dto.setSubCode(code);
            dto.setSubModel(model);
            checkList.add(dto);
        }
        List<MaterialCheckDTO> materialCheckDTOS = CommonUtil.checkFormat(checkList);
        int size = materialCheckDTOS.size();
        //ECR编号,申请日期,申请人,变更描述,变更料号,变更型号,变更所属型号,处理方式,创建时间
        String[] title = new String[]{"序号","物料编码","物料名称","规格型号","不规范原因"};
        String[][] values = new String[size][]; //size行
        for (int i = 0; i < size; i++) {
            values[i] = new String[5];
            MaterialCheckDTO dto = materialCheckDTOS.get(i);
            values[i][0] = dto.getNum().toString();
            values[i][1] = dto.getSubCode();
            values[i][2] = dto.getSubName();
            values[i][3] = dto.getSubModel();
            values[i][4] = dto.getIrregularDesc();
        }
        ExcelUtil.exportExcel("清单","物料",title,values,null,response);
    }
}