whycxzp
2022-08-15 6eda8b2ff2b6748376670e84a14a8656cc1094c6
src/main/java/com/whyc/service/ComponentApprovingService.java
@@ -1,21 +1,25 @@
package com.whyc.service;
import com.whyc.dto.FileUrlDTO;
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.whyc.dto.Response;
import com.whyc.mapper.ComponentApprovingMapper;
import com.whyc.pojo.ComponentApproving;
import com.whyc.pojo.ComponentProductApproving;
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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -25,6 +29,9 @@
@Service
public class ComponentApprovingService {
    @Resource
    private ComponentApprovingMapper mapper;
    /**
     *
@@ -59,7 +66,7 @@
        //遍历解压后的文件夹路径,解析excel
        System.out.println(filePath);
        List<String> fileList = new ArrayList<>();
        fileList = FileUtil.getStaticFilePath(parentFile,fileList);
        for (int i = 0; i < fileList.size(); i++) {
            String fileTempUrl = fileList.get(i);
            //查询到xls数据
@@ -83,6 +90,11 @@
                Row row3 = sheet.getRow(3);
                String productVersion = row3.getCell(5).getStringCellValue();
                for (int l = 8; l < lastRowNum-1; l++) {
                    Cell cellTemp = sheet.getRow(l).getCell(1);
                    cellTemp.setCellType(Cell.CELL_TYPE_STRING);
                    if(cellTemp.getStringCellValue().equals("")){
                        break;
                    }
                    ComponentApproving approving = new ComponentApproving();
                    approving.setCreateDate(new Date());
@@ -93,9 +105,11 @@
                        int cellValueInt = 0;
                        Double cellValueDouble = null;
                        if(m == 3){
                            cellValueDouble = cell.getNumericCellValue();
                            DecimalFormat decimalFormat = new DecimalFormat("0");
                            cellValue = decimalFormat.format(cellValueDouble);
                            //cellValueDouble = cell.getNumericCellValue();
                            //DecimalFormat decimalFormat = new DecimalFormat("0");
                            //cellValue = decimalFormat.format(cellValueDouble);
                            cell.setCellType(Cell.CELL_TYPE_STRING);
                            cellValue = cell.getStringCellValue();
                        }
                        else if(m ==7){
                            cellValueDouble = cell.getNumericCellValue();
@@ -119,7 +133,40 @@
                }
            }
        }
        for (ComponentApproving componentApproving : list) {
            if(componentApproving.getSubName()==null ||componentApproving.getSubName().equals("")){
                return response.set(1,false,"拒绝解析,excel文件中记录包含名称为空的记录");
            }
        }
        String nextTitle = originalFilename.substring(0,originalFilename.lastIndexOf("."));
        return response.setIII(1,true,list,nextTitle,"解析完成");
    }
    public void insert(List<ComponentApproving> cApprovingList) {
        mapper.insertBatchSomeColumn(cApprovingList);
    }
    public List<ComponentApproving> getListByStatus(int status) {
        QueryWrapper<ComponentApproving> query = Wrappers.query();
        query.eq("status",status);
        return mapper.selectList(query);
    }
    public void endStatus(Integer mainId) {
        UpdateWrapper<ComponentApproving> update = Wrappers.update();
        update.set("status",2).eq("main_id",mainId);
        mapper.update(null,update);
    }
    public List<ComponentApproving> getListByMainId(Integer mainId) {
        QueryWrapper<ComponentApproving> query = Wrappers.query();
        query.eq("main_id",mainId);
        return mapper.selectList(query);
    }
    public ComponentApproving getListByComponentId(Integer componentId) {
        QueryWrapper<ComponentApproving> query = Wrappers.query();
        query.eq("component_id",componentId).last(" limit 1");
        return mapper.selectOne(query);
    }
}