whyclxw
2025-06-14 2f6c4f91e2cace4973770819e58651c1a643e0db
产品验收管理上传和查询
2个文件已修改
197 ■■■■ 已修改文件
src/main/java/com/whyc/controller/BomAcceptanceController.java 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/BomAcceptanceService.java 178 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/BomAcceptanceController.java
@@ -29,10 +29,10 @@
    @PostMapping("uploadBomAcceptance")
    public Response uploadBomAcceptance(@RequestParam(required = false) MultipartFile fileLeft,@RequestParam(required = false) MultipartFile fileRight
            ,@RequestParam(required = false) MultipartFile fileFront,@RequestParam(required = false) MultipartFile fileBack
            ,@RequestParam(required = false) MultipartFile Agreement
            ,@RequestParam(required = false) MultipartFile agreement
            ,@RequestPart(required = false) List<MultipartFile> multipartFileList, @RequestParam String feedbackJson) throws IOException {
        BomAcceptance bomAcceptance = ActionUtil.getGson().fromJson(feedbackJson, BomAcceptance.class);
        return service.uploadBomAcceptance(fileLeft,fileRight,fileFront,fileBack,Agreement,multipartFileList,bomAcceptance);
        return service.uploadBomAcceptance(fileLeft,fileRight,fileFront,fileBack,agreement,multipartFileList,bomAcceptance);
    }
    @ApiOperation("查询产品验收信息")
@@ -40,4 +40,19 @@
    public Response getBomAcceptance(@RequestBody BomAcceptance bomAcceptance,@RequestParam int pageNum,@RequestParam int pageSize){
        return service.getBomAcceptance(bomAcceptance,pageNum,pageSize);
    }
    @ApiOperation("删除产品验收信息")
    @GetMapping("delBomAcceptance")
    public Response delBomAcceptance(@RequestParam int num){
        return service.delBomAcceptance(num);
    }
    @ApiOperation(value = "编辑产品验收信息")
    @PostMapping("updateBomAcceptance")
    public Response updateBomAcceptance(@RequestParam(required = false) MultipartFile fileLeft,@RequestParam(required = false) MultipartFile fileRight
            ,@RequestParam(required = false) MultipartFile fileFront,@RequestParam(required = false) MultipartFile fileBack
            ,@RequestParam(required = false) MultipartFile Agreement
            ,@RequestPart(required = false) List<MultipartFile> multipartFileList, @RequestParam String feedbackJson) throws IOException {
        BomAcceptance bomAcceptance = ActionUtil.getGson().fromJson(feedbackJson, BomAcceptance.class);
        return service.updateBomAcceptance(fileLeft,fileRight,fileFront,fileBack,Agreement,multipartFileList,bomAcceptance);
    }
}
src/main/java/com/whyc/service/BomAcceptanceService.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.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
@@ -28,7 +29,138 @@
    //上传产品验收信息
    public Response uploadBomAcceptance(MultipartFile fileLeft, MultipartFile fileRight, MultipartFile fileFront, MultipartFile fileBack
            ,MultipartFile Agreement, List<MultipartFile> multipartFileList, BomAcceptance bomAcceptance) throws IOException {
            ,MultipartFile agreement, List<MultipartFile> multipartFileList, BomAcceptance bomAcceptance) throws IOException {
        Date date = new Date();
        bomAcceptance.setCreateTime(date);
        long time = date.getTime();
        String rootFile = CommonUtil.getRootFile();
        //配件存储
        if(multipartFileList!=null && multipartFileList.size()!=0){
            String spareDirSuffix = "acceptance_bom" + File.separator + time + File.separator+ "spare" + File.separator;
            String spareDir = rootFile + spareDirSuffix;
            File fileDir = new File(spareDir);
            if (!fileDir.exists()) {
                fileDir.mkdirs();
            }
            for (int i = 0; i < multipartFileList.size(); i++) {
                MultipartFile multipartFile = multipartFileList.get(i);
                //存储文件
                String originalFilename = multipartFile.getOriginalFilename();
                String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
                String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
                String sparePath = spareDir + fileName + suffix;
                File file = new File(sparePath);
                multipartFile.transferTo(file);
            }
            bomAcceptance.setSparePicpart(spareDirSuffix);
        }
        String devDirSuffix = "acceptance_bom" + File.separator + time + File.separator+ "dev" + File.separator;
        String devDir = rootFile + devDirSuffix;
        //左视图
        if(fileLeft!=null){
            //存储文件
            String originalFilename = fileLeft.getOriginalFilename();
            String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
            String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
            String path = devDir + fileName + suffix;
            createFilefolderIFNotExist(path);
            fileLeft.transferTo(new File(path));
            bomAcceptance.setDevPicleft("doc_file" + File.separator + devDirSuffix+originalFilename);
        }
        //右视图
        if(fileRight!=null){
            //存储文件
            String originalFilename = fileRight.getOriginalFilename();
            String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
            String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
            String path = devDir + fileName + suffix;
            createFilefolderIFNotExist(path);
            fileRight.transferTo(new File(path));
            bomAcceptance.setDevPicright("doc_file" + File.separator + devDirSuffix+originalFilename);
        }
        //正面图
        if(fileFront!=null){
            //存储文件
            String originalFilename = fileFront.getOriginalFilename();
            String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
            String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
            String path = devDir + fileName + suffix;
            createFilefolderIFNotExist(path);
            fileFront.transferTo(new File(path));
            bomAcceptance.setDevPicfront("doc_file" + File.separator + devDirSuffix+originalFilename);
        }
        //后面图
        if(fileBack!=null){
            //存储文件
            String originalFilename = fileBack.getOriginalFilename();
            String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
            String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
            String path = devDir + fileName + suffix;
            createFilefolderIFNotExist(path);
            fileBack.transferTo(new File(path));
            bomAcceptance.setDevPicback("doc_file" + File.separator + devDirSuffix+originalFilename);
        }
        String agreeDirSuffix = "acceptance_bom" + File.separator + time + File.separator+ "agree" + File.separator;
        String agreeDir = rootFile + agreeDirSuffix;
        //协议
        if(agreement!=null){
            //存储文件
            String originalFilename = agreement.getOriginalFilename();
            String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
            String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
            String path = agreeDir + fileName + suffix;
            createFilefolderIFNotExist(path);
            agreement.transferTo(new File(path));
            bomAcceptance.setBomAgreement("doc_file" + File.separator + agreeDirSuffix+originalFilename);
        }
        mapper.insert(bomAcceptance);
        return new Response().set(1,true,"上传成功");
    }
    //查询产品验收信息
    public Response getBomAcceptance(BomAcceptance bomAcceptance, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper wrapper=new QueryWrapper();
        if(bomAcceptance.getDirectName()!=null){
            wrapper.like("direct_name",bomAcceptance.getDirectName());
        }
        if(bomAcceptance.getBomSeries()!=null){
            wrapper.like("bom_series",bomAcceptance.getBomSeries());
        }
        if(bomAcceptance.getBomModel()!=null){
            wrapper.like("bom_model",bomAcceptance.getBomModel());
        }
        if(bomAcceptance.getBomVersion()!=null){
            wrapper.like("bom_version",bomAcceptance.getBomVersion());
        }
        if(bomAcceptance.getCreateTime()!=null){
            wrapper.ge("create_time",bomAcceptance.getCreateTime());
        }
        if(bomAcceptance.getCreateTime1()!=null){
            wrapper.le("create_time",bomAcceptance.getCreateTime1());
        }
        List<BomAcceptance> list = mapper.selectList(wrapper);
        String rootFile = CommonUtil.getRootFile();//主路径
        if(list!=null&&list.size()>0){
            for (BomAcceptance acceptance:list) {
                String filePath=rootFile+acceptance.getSparePicpart();
                acceptance.setSparePicpart("doc_file"+File.separator+acceptance.getSparePicpart());
                //获取文件夹下所有的图片名
                acceptance.setNameList(FileUtil.getFileNameWithOutDirectory(filePath));
            }
        }
        PageInfo  pageInfo=new PageInfo(list);
        return new Response().setII(1,list.size()>0,pageInfo,"查询产品验收信息");
    }
    //删除产品验收信息
    public Response delBomAcceptance(int num) {
        UpdateWrapper wrapper=new UpdateWrapper();
        wrapper.eq("num",num);
        int bl=mapper.delete(wrapper);
        return new Response().setII(1,bl>0,bl,"删除产品验收信息");
    }
   //编辑产品验收信息
    public Response updateBomAcceptance(MultipartFile fileLeft, MultipartFile fileRight, MultipartFile fileFront, MultipartFile fileBack
            , MultipartFile agreement, List<MultipartFile> multipartFileList, BomAcceptance bomAcceptance) throws IOException {
        Date date = new Date();
        long time = date.getTime();
        String rootFile = CommonUtil.getRootFile();
@@ -101,49 +233,19 @@
        String agreeDirSuffix = "acceptance_bom" + File.separator + time + File.separator+ "agree" + File.separator;
        String agreeDir = rootFile + agreeDirSuffix;
        //协议
        if(Agreement!=null){
        if(agreement!=null){
            //存储文件
            String originalFilename = Agreement.getOriginalFilename();
            String originalFilename = agreement.getOriginalFilename();
            String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
            String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));
            String path = agreeDir + fileName + suffix;
            createFilefolderIFNotExist(path);
            Agreement.transferTo(new File(path));
            agreement.transferTo(new File(path));
            bomAcceptance.setBomAgreement("doc_file" + File.separator + agreeDirSuffix+originalFilename);
        }
        mapper.insert(bomAcceptance);
        return new Response().set(1,true,"上传成功");
    }
    //查询产品验收信息
    public Response getBomAcceptance(BomAcceptance bomAcceptance, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper wrapper=new QueryWrapper();
        if(bomAcceptance.getDirectName()!=null){
            wrapper.like("direct_name",bomAcceptance.getDirectName());
        }
        if(bomAcceptance.getBomSeries()!=null){
            wrapper.like("bom_series",bomAcceptance.getBomSeries());
        }
        if(bomAcceptance.getBomModel()!=null){
            wrapper.like("bom_model",bomAcceptance.getBomModel());
        }
        if(bomAcceptance.getCreateTime()!=null){
            wrapper.ge("create_time",bomAcceptance.getCreateTime());
        }
        if(bomAcceptance.getCreateTime1()!=null){
            wrapper.le("create_time",bomAcceptance.getCreateTime1());
        }
        List<BomAcceptance> list = mapper.selectList(wrapper);
        String rootFile = CommonUtil.getRootFile();//主路径
        if(list!=null&&list.size()>0){
            for (BomAcceptance acceptance:list) {
                String filePath=rootFile+acceptance.getSparePicpart();
                acceptance.setSparePicpart("doc_file"+File.separator+acceptance.getSparePicpart());
                //获取文件夹下所有的图片名
                acceptance.setNameList(FileUtil.getFileNameWithOutDirectory(filePath));
            }
        }
        PageInfo  pageInfo=new PageInfo(list);
        return new Response().setII(1,list.size()>0,pageInfo,"查询产品验收信息");
        UpdateWrapper wrapper=new UpdateWrapper();
        wrapper.eq("num",bomAcceptance.getNum());
        mapper.update(bomAcceptance,wrapper);
        return new Response().set(1,true,"编辑成功");
    }
}