whycxzp
2022-09-15 788f57c0f36ce4e625b068b5891c35ed8f8da2c7
src/main/java/com/whyc/service/SoftwareService.java
@@ -1,6 +1,7 @@
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;
@@ -8,6 +9,7 @@
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;
@@ -21,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;
@@ -78,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());
@@ -102,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,"软件信息返回");
    }
@@ -198,4 +209,43 @@
    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,"锁定/解锁成功");
    }
}