| | |
| | | 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; |
| | |
| | | import com.whyc.pojo.BOMFeedback; |
| | | import com.whyc.pojo.BomAcceptance; |
| | | import com.whyc.pojo.DefectiveProducts; |
| | | import com.whyc.pojo.ProductHistory; |
| | | import com.whyc.util.ActionUtil; |
| | | import com.whyc.util.CommonUtil; |
| | | import com.whyc.util.FileUtil; |
| | | import org.apache.poi.hssf.usermodel.*; |
| | | import org.apache.poi.ss.usermodel.IndexedColors; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.Date; |
| | |
| | | private BomAcceptanceMapper mapper; |
| | | |
| | | //上传产品验收信息 |
| | | public Response uploadBomAcceptance(MultipartFile fileLeft, MultipartFile fileRight, MultipartFile fileFront, MultipartFile fileBack, List<MultipartFile> multipartFileList, BomAcceptance bomAcceptance) throws IOException { |
| | | public Response uploadBomAcceptance(MultipartFile fileLeft, MultipartFile fileRight, MultipartFile fileFront, MultipartFile fileBack |
| | | ,MultipartFile agreement, List<MultipartFile> multipartFileList, BomAcceptance bomAcceptance) throws IOException { |
| | | Date date = new Date(); |
| | | bomAcceptance.setCreateTime(date); |
| | | long time = date.getTime(); |
| | | String rootFile = CommonUtil.getRootFile(); |
| | | //配件存储 |
| | |
| | | fileFront.transferTo(new File(path)); |
| | | bomAcceptance.setDevPicfront("doc_file" + File.separator + devDirSuffix+originalFilename); |
| | | } |
| | | //左视图 |
| | | //后面图 |
| | | if(fileBack!=null){ |
| | | //存储文件 |
| | | String originalFilename = fileBack.getOriginalFilename(); |
| | |
| | | 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,"上传成功"); |
| | |
| | | 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(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(BomAcceptance bomAcceptance) { |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.eq("num",bomAcceptance.getNum()); |
| | | if(bomAcceptance.getDirectName()!=null){ |
| | | wrapper.set("direct_name",bomAcceptance.getDirectName()); |
| | | } |
| | | if(bomAcceptance.getBomSeries()!=null){ |
| | | wrapper.set("bom_series",bomAcceptance.getBomSeries()); |
| | | } |
| | | if(bomAcceptance.getBomModel()!=null){ |
| | | wrapper.set("bom_model",bomAcceptance.getBomModel()); |
| | | } |
| | | if(bomAcceptance.getDevParam()!=null){ |
| | | wrapper.set("dev_param",bomAcceptance.getDevParam()); |
| | | } |
| | | if(bomAcceptance.getStandParam()!=null){ |
| | | wrapper.set("stand_param",bomAcceptance.getStandParam()); |
| | | } |
| | | if(bomAcceptance.getBomSize()!=null){ |
| | | wrapper.set("bom_size",bomAcceptance.getBomSize()); |
| | | } |
| | | if(bomAcceptance.getDevWeight()!=null){ |
| | | wrapper.set("dev_weight",bomAcceptance.getDevWeight()); |
| | | } |
| | | if(bomAcceptance.getDevWeightAll()!=null){ |
| | | wrapper.set("dev_weight_all",bomAcceptance.getDevWeightAll()); |
| | | } |
| | | if(bomAcceptance.getSparePartmodel()!=null){ |
| | | wrapper.set("spare_partmodel",bomAcceptance.getSparePartmodel()); |
| | | } |
| | | if(bomAcceptance.getBomVersion()!=null){ |
| | | wrapper.set("bom_version",bomAcceptance.getBomVersion()); |
| | | } |
| | | |
| | | mapper.update(null,wrapper); |
| | | return new Response().set(1,true,"编辑成功"); |
| | | } |
| | | //删除图 |
| | | public void delPic(int num, int picNum,String picUrl,String newPicUrl) { |
| | | String rootFile = CommonUtil.getRootFile();//主路径 |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.eq("num",num); |
| | | if(picNum==1){ |
| | | wrapper.set("dev_picleft",newPicUrl); |
| | | } |
| | | if(picNum==2){ |
| | | wrapper.set("dev_picright",newPicUrl); |
| | | } |
| | | if(picNum==3){ |
| | | wrapper.set("dev_picfront",newPicUrl); |
| | | } |
| | | if(picNum==4){ |
| | | wrapper.set("dev_picback",newPicUrl); |
| | | } |
| | | if(picNum==5){ |
| | | wrapper.set("spare_picpart",newPicUrl); |
| | | } |
| | | if(picNum==6){ |
| | | wrapper.set("bom_agreement",newPicUrl); |
| | | } |
| | | int flag=mapper.update(null,wrapper); |
| | | if(flag>0){ |
| | | rootFile=rootFile.replace("doc_file",""); |
| | | //删除图片 |
| | | FileUtil.deleteFile(new File(rootFile+picUrl)); |
| | | } |
| | | } |
| | | //编辑单个图片上传 |
| | | public Response updateDevPic(MultipartFile filePic, int num,int picNum,String picUrl) throws IOException { |
| | | Date date = new Date(); |
| | | long time = date.getTime(); |
| | | String rootFile = CommonUtil.getRootFile(); |
| | | String devDirSuffix = "acceptance_bom" + File.separator + time + File.separator+ "dev" + File.separator; |
| | | String devDir = rootFile + devDirSuffix; |
| | | //后面图 |
| | | if(filePic!=null){ |
| | | //存储文件 |
| | | String originalFilename = filePic.getOriginalFilename(); |
| | | String fileName = originalFilename.substring(0, originalFilename.lastIndexOf(".")); |
| | | String suffix = originalFilename.substring(originalFilename.lastIndexOf(".")); |
| | | String path = devDir + fileName + suffix; |
| | | createFilefolderIFNotExist(path); |
| | | filePic.transferTo(new File(path)); |
| | | String devFile="doc_file" + File.separator + devDirSuffix+originalFilename; |
| | | //删除旧的 |
| | | delPic(num,picNum,picUrl,devFile); |
| | | return new Response().set(1,true,"上传新图片成功"); |
| | | }else{ |
| | | return new Response().set(1,false,"图片不存在"); |
| | | } |
| | | } |
| | | //编辑多个图片上传 |
| | | public Response updatePartPic(List<MultipartFile> multipartFileList, String picUrl) throws IOException { |
| | | String rootFile = CommonUtil.getRootFile(); |
| | | rootFile=rootFile.replace("doc_file",""); |
| | | //配件存储 |
| | | if(multipartFileList!=null && multipartFileList.size()!=0){ |
| | | 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 = rootFile+picUrl + fileName + suffix; |
| | | File file = new File(sparePath); |
| | | multipartFile.transferTo(file); |
| | | } |
| | | return new Response().set(1,true,"上传成功"); |
| | | }else{ |
| | | return new Response().set(1,false,"图片不存在"); |
| | | } |
| | | } |
| | | //导出产品验收信息 |
| | | public void downloadBomAcceptance(HttpServletRequest req, HttpServletResponse resp, int num) { |
| | | //读取产品信息 |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("num",num); |
| | | wrapper.last("limit 1"); |
| | | BomAcceptance bomAcceptance=mapper.selectOne(wrapper); |
| | | //生成excel |
| | | creatBomAcceptanceExcel(req,resp,bomAcceptance); |
| | | } |
| | | //生成excel |
| | | private void creatBomAcceptanceExcel(HttpServletRequest req, HttpServletResponse resp, BomAcceptance bomAcceptance) { |
| | | //创建单个sheet |
| | | HSSFWorkbook wb = new HSSFWorkbook(); |
| | | //字体格式-加粗 |
| | | HSSFCellStyle cellStyle = wb.createCellStyle(); |
| | | cellStyle.setFillForegroundColor(IndexedColors.GOLD.getIndex());//添加前景色,内容看的清楚 |
| | | cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); |
| | | HSSFFont font = wb.createFont(); |
| | | font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); |
| | | cellStyle.setFont(font); |
| | | HSSFSheet sheet = wb.createSheet("产品验收信息记录"); |
| | | sheet.setColumnWidth(1,10000); |
| | | sheet.setDefaultRowHeight((short)(1000)); |
| | | //图片元素 |
| | | HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); |
| | | HSSFRow row=sheet.createRow(1); |
| | | HSSFCell cell=row.createCell(0); |
| | | cell=row.createCell(0); |
| | | cell.setCellValue("产品验收信息记录"); |
| | | cell.setCellStyle(cellStyle); |
| | | } |
| | | |
| | | } |