whycxzp
2023-02-21 6b81463956244414475df449d3f3a773a3839d44
ecr更新
3个文件已修改
76 ■■■■ 已修改文件
src/main/java/com/whyc/controller/ECRController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/ECR.java 38 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/ECRService.java 36 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/ECRController.java
@@ -32,7 +32,7 @@
        if(!name.substring(name.length()-4).equals(".xls") && !name.substring(name.length()-5).equals(".xlsx")){
            response.set(1,false,"文件解析错误:上传格式非excel格式");
        }else{
            response =  service.ecrImportByExcel(multipartFile.getInputStream());
            response =  service.ecrImportByExcel(multipartFile);
        }
        return response;
    }
src/main/java/com/whyc/pojo/ECR.java
@@ -14,10 +14,12 @@
    private Date proposeDate;
    private String proposer;
    private String changeDescription;
    private String code;
    private String model;
    private String subCode;
    private String subModel;
    private String parentModel;
    private String solution;
    private Date createTime;
    private String excelFile;
    public Integer getId() {
        return id;
@@ -59,20 +61,28 @@
        this.changeDescription = changeDescription;
    }
    public String getCode() {
        return code;
    public String getSubCode() {
        return subCode;
    }
    public void setCode(String code) {
        this.code = code;
    public void setSubCode(String subCode) {
        this.subCode = subCode;
    }
    public String getModel() {
        return model;
    public String getSubModel() {
        return subModel;
    }
    public void setModel(String model) {
        this.model = model;
    public void setSubModel(String subModel) {
        this.subModel = subModel;
    }
    public String getParentModel() {
        return parentModel;
    }
    public void setParentModel(String parentModel) {
        this.parentModel = parentModel;
    }
    public String getSolution() {
@@ -90,4 +100,12 @@
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public String getExcelFile() {
        return excelFile;
    }
    public void setExcelFile(String excelFile) {
        this.excelFile = excelFile;
    }
}
src/main/java/com/whyc/service/ECRService.java
@@ -11,8 +11,11 @@
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
@@ -26,7 +29,26 @@
    @Resource
    private ECRMapper mapper;
    public Response ecrImportByExcel(InputStream inputStream) throws IOException, InvalidFormatException, ParseException {
    @Transactional
    public Response ecrImportByExcel(MultipartFile multipartFile) throws IOException, InvalidFormatException, ParseException {
        InputStream inputStream = multipartFile.getInputStream();
        //存储excel
        String originalFilename = multipartFile.getOriginalFilename();
        Date date = new Date();
        String dateUnion = DateUtil.YYYY_MM_DD_HH_MM_SS_UNION.format(date);
        //存储路径
        String rootFile = CommonUtil.getRootFile();
        String excelDir = rootFile + "ecr";
        File excelDirFile = new File(excelDir);
        if(!excelDirFile.exists()){
            excelDirFile.mkdirs();
        }
        String excelFilePath = excelDir + File.separator + originalFilename.substring(0,originalFilename.lastIndexOf(".")) + "_" + dateUnion +originalFilename.substring(originalFilename.lastIndexOf("."));
        String excelHttpUrl = excelFilePath.substring(excelDir.lastIndexOf("doc_file"+ File.separator + "ecr"));
        multipartFile.transferTo(new File(excelFilePath));
        int a = 0;
        int b = 3/a;
        Workbook workbook = null;
        workbook = WorkbookFactory.create(inputStream);
        inputStream.close();
@@ -65,6 +87,8 @@
        String proposerCellValue = sheet.getRow(2).getCell(22).getStringCellValue();
        //申请人:xxx
        String proposer = proposerCellValue.substring(4).trim();
        String parentModel = sheet.getRow(3).getCell(0).getStringCellValue().substring(10).trim();
        String changeDescriptionCellValue = sheet.getRow(4).getCell(0).getStringCellValue();
@@ -127,7 +151,7 @@
            }
        }
        String changeType = changeTypeBuilder.toString();
        String changeDescription = changeDescriptionCellValue + "\n"+changeType;
        String changeDescription = changeDescriptionCellValue + "\n变更原因类别:"+changeType;
        //处理方式,处理方式:
        //□1.报废.  □2. 用完为止  □3. 重工(变)
@@ -146,13 +170,15 @@
        ecr.setProposer(proposer);
        ecr.setChangeDescription(changeDescription);
        ecr.setSolution(solution);
        ecr.setCreateTime(new Date());
        ecr.setCreateTime(date);
        ecr.setExcelFile(excelHttpUrl);
        ecr.setParentModel(parentModel);
        //赋值给具体对象
        for (int i = 0; i < codeSplit.length; i++) {
            ECR ecrTemp = new ECR();
            BeanUtils.copyProperties(ecr,ecrTemp);
            ecrTemp.setCode(CommonUtil.codeAutoFill(codeSplit[i]));
            ecrTemp.setModel(modelSplit[i]);
            ecrTemp.setSubCode(CommonUtil.codeAutoFill(codeSplit[i]));
            ecrTemp.setSubModel(modelSplit[i]);
            ecrList.add(ecrTemp);
        }
        mapper.insertBatchSomeColumn(ecrList);