whycxzp
2022-09-13 ace8bf9c348341ef13fed03370e9cc194ecff01e
更新软件适用机型
2个文件已修改
22 ■■■■■ 已修改文件
src/main/java/com/whyc/controller/SoftwareController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/SoftwareService.java 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/SoftwareController.java
@@ -49,7 +49,7 @@
    @ApiOperation("更新软件版本对应的适用机型")
    @PutMapping("applyModel")
    public Response updateApplyModel(@RequestParam MultipartFile multipartFile,@RequestParam String softwareStr){
    public Response updateApplyModel(@RequestParam MultipartFile multipartFile,@RequestParam String softwareStr) throws IOException {
        List<Software> softwareList = ActionUtil.getGson().fromJson(softwareStr,new TypeToken<List<Software>>(){}.getType());
        return service.updateApplyModel(multipartFile,softwareList);
    }
src/main/java/com/whyc/service/SoftwareService.java
@@ -202,23 +202,31 @@
    }
    @Transactional
    public Response updateApplyModel(MultipartFile multipartFile, List<Software> softwareList) {
    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",softwareList.get(0).getFileName()).last(" limit 1");
        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(software -> {
                software.setFileUrl(softwareDB.getFileUrl());
                software.setExcelUrl(softwareDB.getExcelUrl());
                software.setCreateTime(new Date());
            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,"更新完成");
        }
    }