whycxzp
2023-07-05 c66d31a27637ccbb783d0c97fd7c68a9cec67170
src/main/java/com/whyc/service/SOPService.java
@@ -1,5 +1,8 @@
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.PageInfo;
import com.whyc.dto.Response;
import com.whyc.dto.SopDto;
@@ -54,7 +57,7 @@
        Sheet sheet = workbook.getSheetAt(0);
        int lastRowNum = sheet.getLastRowNum();
        //文件名
        sop.setFileName(sheet.getRow(2).getCell(2).getStringCellValue());
        sop.setFileName(sheet.getRow(2).getCell(2).getStringCellValue().trim());
        //下面的row是动态的,因为文件类型的行数是动态拓展的
        //锚点:文件版本
        int fileVersionIndex = 0;
@@ -259,6 +262,7 @@
        sop.setReleaseNotes(releaseNotes);
        //第10行开始,倒数第2行截止
        int currentFlag=0;  //通用表示(0:非通用,1:通用)
        for (int i = fileSuitableProductIndex+1; i < lastRowNum; i++) {
            SOPProduct product = new SOPProduct();
            //取第3列,第5列
@@ -279,12 +283,12 @@
            }else{
                product.setModel(model);
            }
            if((code.equals("") && model.equals(""))){
                sop.setCurrentFlag(1);//通用
            if((!code.equals("") && !model.equals(""))){
                currentFlag+=1;
            }
            sopProductList.add(product);
        }
        sop.setCurrentFlag(currentFlag>0?0:1);//通用
        //存储excel文件,/sop_submit/xxx_202306250506.xlsx(改,不存粗excel了)
        /*String originalFilename = multipartFile.getOriginalFilename();
        String[] fileNameSplit = originalFilename.split("\\.");
@@ -302,6 +306,17 @@
    @Transactional
    public Response add(SOP sop,MultipartFile multipartFile) throws IOException {
        //是否存在旧版本,存在则把所有旧版本状态更新为0
        QueryWrapper<SOP> query = Wrappers.query();
        query.eq("file_name",sop.getFileName()).eq("status",1);
        List<SOP> sopListExists = mapper.selectList(query);
        if(sopListExists.size()>0){
            for (SOP sopExists : sopListExists) {
                sopExists.setStatus(0);
                mapper.updateById(sopExists);
            }
        }
        List<SOPProduct> sopProductList = sop.getSopProductList();
         String originalFilename = multipartFile.getOriginalFilename();
        String[] fileNameSplit = originalFilename.split("\\.");
@@ -311,6 +326,7 @@
        //String fileUrlTemp = sop.getFileUrl();
        //fileUrlTemp = fileUrlTemp.replace("sop_submit", "sop");
        sop.setFileUrl(fileUrlTemp);
        sop.setStatus(1);
        mapper.insert(sop);
        if(sopProductList.size()>0) {
            sopProductList.forEach(product -> product.setSopId(sop.getId()));
@@ -398,4 +414,11 @@
        }
        return new Response().setII(1,"更新sop说明完成");
    }
    public Response updateStatusById(int id, int status) {
        UpdateWrapper<SOP> update = Wrappers.update();
        update.set("status",status).eq("id",id);
        mapper.update(null,update);
        return new Response().setII(1,"设置完成");
    }
}