New file |
| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.BomAcceptanceMapper; |
| | | import com.whyc.pojo.BOMFeedback; |
| | | import com.whyc.pojo.BomAcceptance; |
| | | import com.whyc.pojo.DefectiveProducts; |
| | | import com.whyc.util.CommonUtil; |
| | | import com.whyc.util.FileUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import static com.whyc.util.ActionUtil.createFilefolderIFNotExist; |
| | | |
| | | @Service |
| | | public class BomAcceptanceService { |
| | | @Autowired(required = false) |
| | | private BomAcceptanceMapper mapper; |
| | | |
| | | //上传产品验收信息 |
| | | public Response uploadBomAcceptance(MultipartFile fileLeft, MultipartFile fileRight, MultipartFile fileFront, MultipartFile fileBack, List<MultipartFile> multipartFileList, BomAcceptance bomAcceptance) throws IOException { |
| | | Date date = new 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); |
| | | } |
| | | 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) { |
| | | acceptance.setSparePicpart("doc_file"+File.separator+acceptance.getSparePicpart()); |
| | | String filePath=rootFile+acceptance.getSparePicpart(); |
| | | //获取文件夹下所有的图片名 |
| | | acceptance.setNameList(FileUtil.getFileNameWithOutDirectory(filePath)); |
| | | } |
| | | } |
| | | PageInfo pageInfo=new PageInfo(list); |
| | | return new Response().setII(1,list.size()>0,pageInfo,"查询产品验收信息"); |
| | | } |
| | | } |