whycxzp
2022-09-15 788f57c0f36ce4e625b068b5891c35ed8f8da2c7
src/main/java/com/whyc/service/SoftwareService.java
@@ -1,12 +1,15 @@
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.constant.UserOperation;
import com.whyc.dto.FileDirPath;
import com.whyc.dto.Response;
import com.whyc.mapper.SoftwareMapper;
import com.whyc.pojo.AttachLock;
import com.whyc.pojo.DocUser;
import com.whyc.pojo.Software;
import com.whyc.util.ActionUtil;
@@ -20,6 +23,7 @@
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
@@ -77,7 +81,15 @@
        common.setBasedVersion(sheet.getRow(5).getCell(4).getStringCellValue());
        common.setOwner(sheet.getRow(6).getCell(2).getStringCellValue());
        common.setFilingDate(sheet.getRow(6).getCell(4).getStringCellValue());
        Cell cellFilingDate = sheet.getRow(6).getCell(4);
        if(cellFilingDate.getCellType() == Cell.CELL_TYPE_NUMERIC){
            Date dateCellValue = cellFilingDate.getDateCellValue();
            common.setFilingDate(DateUtil.YYYY_MM_DD.format(dateCellValue));
            System.out.println(dateCellValue);
        }else {
            cellFilingDate.setCellType(Cell.CELL_TYPE_STRING);
            common.setFilingDate(cellFilingDate.getStringCellValue());
        }
        //最后一行,取发布说明
        common.setReleaseNotes(sheet.getRow(lastRowNum).getCell(2).getStringCellValue());
@@ -101,9 +113,9 @@
    }
    //查询软件列表的信息
    public Response getAllSoftware(String fileName,String applyMaterialCode,String applyModel,String owner, int pageCurr, int pageSize) {
    public Response getAllSoftware(String fileName,String applyMaterialCode,String applyModel,String owner, String boardNumber,int pageCurr, int pageSize) {
        PageHelper.startPage(pageCurr,pageSize);
        List list=mapper.getFileUrl(fileName,applyMaterialCode,applyModel,owner);
        List list=mapper.getFileUrl(fileName,applyMaterialCode,applyModel,owner,boardNumber);
        PageInfo pageInfo=new PageInfo(list);
        return new Response().setII(1,list.size()>0,pageInfo,"软件信息返回");
    }
@@ -158,14 +170,18 @@
        if(!software.getFileName().equals(file1Name.substring(0,file1Name.lastIndexOf(".")))){
            return new Response().set(1,false,"附件的文件名与软件发布记录excel内的文件名称不一致");
        }
        Software softExists = getByFilename(software.getFileName());
        if(softExists != null){ //文件名:规格型号_软件版本,已存在,不能重复上传;这种情况属于追加机型,别处更新
            return new Response().set(1,false,"文件名称("+softExists.getFileName()+")已存在,不能重复上传");
        }
        Date date = new Date();
        String dateUnion = DateUtil.YYYY_MM_DD_HH_MM_SS_UNION.format(date);
        //文件重命名
        file1Name = file1Name.substring(0,file1Name.lastIndexOf(".")) + "_" + dateUnion +file1Name.substring(file1Name.lastIndexOf("."));
        file2Name = file2Name.substring(0,file2Name.lastIndexOf(".")) + "_" + dateUnion +file2Name.substring(file2Name.lastIndexOf("."));
        //文件重命名(暂不需要,严格遵守名称规则的情况下不会重名)
        //file1Name = file1Name.substring(0,file1Name.lastIndexOf(".")) + "_" + dateUnion +file1Name.substring(file1Name.lastIndexOf("."));
        //file2Name = file2Name.substring(0,file2Name.lastIndexOf(".")) + "_" + dateUnion +file2Name.substring(file2Name.lastIndexOf("."));
        //存储路径
        String rootFile = CommonUtil.getRootFile();
        String softwareDir = rootFile + "software" + File.separator + software.getOwner();
        String softwareDir = rootFile + "software" + File.separator + software.getOwner()+ File.separator + software.getFileName();
        String softwareHttpUrl = softwareDir.substring(softwareDir.lastIndexOf("doc_file"+ File.separator + "software"));
        File softwareDirFile = new File(softwareDir);
        if(!softwareDirFile.exists()){
@@ -184,7 +200,52 @@
        return new Response().set(1,true,"上传完成");
    }
    private Software getByFilename(String fileName) {
        QueryWrapper<Software> query = Wrappers.query();
        query.eq("file_name",fileName).last(" limit 1");
        return mapper.selectOne(query);
    }
    private void insertBatch(List<Software> softwareList){
        mapper.insertBatchSomeColumn(softwareList);
    }
    @Transactional
    public Response updateApplyModel(MultipartFile multipartFile, List<Software> softwareList) throws IOException {
        String originalFilename = multipartFile.getOriginalFilename();
        Software software = softwareList.get(0);
        QueryWrapper<Software> query = Wrappers.query();
        query.eq("file_name", software.getFileName()).last(" limit 1");
        Software softwareDB = mapper.selectOne(query);
        if(softwareDB == null){
            return new Response().set(1,false,"对应的软件并未上传过,无法更新适用机型");
        }else{
            //写入新增的软件发布记录excel
            String rootFile = CommonUtil.getRootFile();
            String softwareDir = rootFile + "software" + File.separator + software.getOwner()+ File.separator + software.getFileName();
            String softwareHttpUrl = softwareDir.substring(softwareDir.lastIndexOf("doc_file"+ File.separator + "software"));
            multipartFile.transferTo(new File(softwareDir + File.separator + originalFilename));
            //先删除对应的适用机型,再新增适用机型记录
            UpdateWrapper<Software> update = Wrappers.update();
            update.eq("file_name",softwareDB.getFileName());
            mapper.delete(update);
            softwareList.forEach(software2 -> {
                software2.setFileUrl(softwareDB.getFileUrl());
                software2.setExcelUrl(softwareHttpUrl + File.separator + originalFilename);
                software2.setCreateTime(new Date());
            });
            mapper.insertBatchSomeColumn(softwareList);
            return new Response().set(1,true,"更新完成");
        }
    }
    //根据软件id修改软件锁定状态
    public Response updateSoftwareLock(String fileUrl,int lockFlag,String localReason) {
        UpdateWrapper uwrapper=new UpdateWrapper();
        uwrapper.set("lock_flag",lockFlag);
        uwrapper.set("local_reason",localReason);
        uwrapper.eq("file_url",fileUrl);
        int flag=mapper.update(null,uwrapper);
        return new Response().set(1,flag>0,"锁定/解锁成功");
    }
}