| | |
| | | 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; |
| | |
| | | |
| | | //上传产品验收信息 |
| | | 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(); |
| | |
| | | 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,"编辑成功"); |
| | | } |
| | | } |