From b848451e8889fea12ce40b7818c1b8d84b50ea02 Mon Sep 17 00:00:00 2001 From: lxw <810412026@qq.com> Date: 星期四, 01 九月 2022 13:41:07 +0800 Subject: [PATCH] 权限管理组合操作 --- src/main/java/com/whyc/service/ProductBomService.java | 296 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 216 insertions(+), 80 deletions(-) diff --git a/src/main/java/com/whyc/service/ProductBomService.java b/src/main/java/com/whyc/service/ProductBomService.java index 786578f..1c48b4e 100644 --- a/src/main/java/com/whyc/service/ProductBomService.java +++ b/src/main/java/com/whyc/service/ProductBomService.java @@ -9,14 +9,12 @@ import com.whyc.dto.FileDirPath; import com.whyc.dto.Response; import com.whyc.dto.ZipUtils; +import com.whyc.mapper.MaterialMapper; import com.whyc.mapper.ProductBomMapper; -import com.whyc.pojo.DocUser; -import com.whyc.pojo.ProductBom; -import com.whyc.pojo.ProductBomApproving; -import com.whyc.pojo.ProductBomHistory; +import com.whyc.mapper.ProductMapper; +import com.whyc.pojo.*; import com.whyc.util.ActionUtil; import org.apache.poi.hssf.usermodel.*; -import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.ClientAnchor; import org.apache.poi.ss.usermodel.Row; import org.springframework.beans.factory.annotation.Autowired; @@ -28,7 +26,6 @@ import javax.servlet.http.HttpServletResponse; import java.awt.image.BufferedImage; import java.io.*; -import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; import java.util.LinkedList; @@ -37,8 +34,15 @@ @Service public class ProductBomService { + @Autowired(required = false) private ProductBomMapper mapper; + + @Autowired(required = false) + private MaterialMapper cponentMapper; + + @Autowired(required = false) + private ProductMapper productMapper; @Autowired private DocLogService logService; @@ -49,52 +53,24 @@ PageInfo pageInfo=new PageInfo(list); return new Response().setII(1,list.size()>0?true:false,pageInfo,"鏁版嵁杩斿洖"); } - //鍥剧焊鏂囦欢涓嬭浇 - public void downloadCadDrawer(HttpServletRequest req, HttpServletResponse resp, ArrayList<String> pictureUrls) { - String fileDirName = FileDirPath.getFileDirName(); - String rootFace=fileDirName+ File.separator+"downLoad"; - String pictureName=""; - //灏嗛�変腑鐨勬枃浠跺瓨鍏ユ寚瀹氱洰褰曚笅鎵撳寘涓嬭浇 - if(pictureUrls!=null&&pictureUrls.size()>0){ - for (String picUrl:pictureUrls) { - pictureName+=picUrl.substring(picUrl.lastIndexOf("\\")+1)+","; - File sourceFile=new File(fileDirName+ File.separator+picUrl); - copyFile(sourceFile,rootFace); - } - } - String timeStr= ActionUtil.sdfwithFTP.format(new Date()); - try { - File file=new File(rootFace+".zip"); - FileOutputStream forootFace = new FileOutputStream(file); - ZipUtils.toZip(rootFace, forootFace,true); - // 杞爜闃叉涔辩爜 - resp.addHeader("Content-Disposition", "attachment;filename=" - + new String(timeStr.getBytes("UTF-8"), "ISO8859-1") - + ".zip"); - OutputStream out = resp.getOutputStream(); - FileInputStream in = new FileInputStream(rootFace+".zip"); - int len=0; - byte[] buffer =new byte[1024]; - //7. 灏嗙紦鍐插尯涓殑鏁版嵁杈撳嚭 - while ((len=in.read(buffer))>0){ - out.write(buffer,0,len); - } - in.close(); - out.close(); - file.delete(); - } catch (FileNotFoundException | UnsupportedEncodingException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } + /* //鍥剧焊鏂囦欢涓嬭浇 + public void downloadCadDrawer(HttpServletRequest req, HttpServletResponse resp, List<ProductBom> boms) { + HSSFWorkbook wb = new HSSFWorkbook(); + //瀛椾綋鏍煎紡-鍔犵矖 + HSSFCellStyle cellStyle = wb.createCellStyle(); + HSSFFont font = wb.createFont(); + font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); + cellStyle.setFont(font); + //鐢熸垚excel骞跺皢dwg鏂囦欢鏀惧湪鍚屼竴鎶ヤ笅鍘嬬缉 + creatBomExcel(req,resp,boms,wb,"pic"); //璁板綍鏃ュ織 DocUser docUser= ActionUtil.getUser(); - String operationDetail="鍏蜂綋鍥剧焊涓�:"+pictureName.substring(0,pictureName.lastIndexOf(",")); + String operationDetail="鍏蜂綋鍥剧焊涓烘暟閲�:"+boms.size(); String opreationMsg="鎵ц浜嗘枃浠舵墦鍖呬笅杞芥搷浣�"; String terminalIp=req.getRemoteAddr(); logService.recordOperationLog(docUser.getId(),docUser.getName(), UserOperation.TYPE_DOWNLOAD.getType(),new Date(),terminalIp,opreationMsg,operationDetail); - } + }*/ //鏍规嵁瀛愪欢code鑾峰彇鏈�缁堢殑淇℃伅 public Response getBomBySubcode(String scode) { QueryWrapper wrapper=new QueryWrapper(); @@ -115,7 +91,8 @@ @Transactional public void updateNewBom(List<ProductBomHistory> newBomHistoryList) { UpdateWrapper<ProductBom> update = Wrappers.update(); - update.eq("parent_model",newBomHistoryList.get(0).getParentModel()); + //lxw娉ㄩ噴 + //update.eq("parent_model",newBomHistoryList.get(0).getParentModel()); mapper.delete(update); List<ProductBom> newBomList = new LinkedList<>(); @@ -127,10 +104,10 @@ newBom.setFileUrl(newBomHis.getFileUrl()); newBom.setMaterial(newBomHis.getMaterial()); newBom.setNotes(newBomHis.getNotes()); - newBom.setParentCode(newBomHis.getParentCode()); - newBom.setParentModel(newBomHis.getParentModel()); - newBom.setParentName(newBomHis.getParentName()); - newBom.setParentVersion(newBomHis.getParentVersion()); + //newBom.setParentCode(newBomHis.getParentCode()); + //newBom.setParentModel(newBomHis.getParentModel()); + //newBom.setParentName(newBomHis.getParentName()); + //newBom.setParentVersion(newBomHis.getParentVersion()); newBom.setPictureUrl(newBomHis.getPictureUrl()); newBom.setProducer(newBomHis.getProducer()); newBom.setQuantity(newBomHis.getQuantity()); @@ -142,7 +119,7 @@ newBom.setType(newBomHis.getType()); newBom.setUnit(newBomHis.getUnit()); newBom.setUpUserId(newBomHis.getUpUserId()); - newBom.setVersion(newBomHis.getEVersion()); + //newBom.setVersion(newBomHis.getEVersion()); newBomList.add(newBom); }); @@ -155,7 +132,11 @@ File destfile = new File(dest); if(!destfile.exists()) { destfile.mkdir(); - } + }/*else{ + if(i==0){ + ZipUtils.delDir(dest); + } + }*/ //source鏄枃浠讹紝鍒欑敤瀛楄妭杈撳叆杈撳嚭娴佸鍒舵枃浠� try { if(source.isFile()){ @@ -184,42 +165,113 @@ e.printStackTrace(); } } + //鏂囦欢澶圭殑鎷疯礉 + public void copyDir(String sourcePathDir, String newPathDir) { + File start = new File(sourcePathDir); + File end = new File(newPathDir); + if(!start.exists()) { + return; + } + String[] filePath = start.list();//鑾峰彇璇ユ枃浠跺す涓嬬殑鎵�鏈夋枃浠朵互鍙婄洰褰曠殑鍚嶅瓧 + if(!end.exists()) { + end.mkdir(); + } + if(filePath.length>=0){ + for(String temp : filePath) { + //娣诲姞婊¤冻鎯呭喌鐨勬潯浠� + if(new File(sourcePathDir + File.separator + temp ).isFile()) { + //涓烘枃浠跺垯杩涜鎷疯礉 + copyFile(new File(sourcePathDir + File.separator + temp ), newPathDir ); + } + } + } + } public void updateUrl(List<ProductBomApproving> fileBomApprovingList) { mapper.updateUrl(fileBomApprovingList); } /** * 鑾峰彇鎵�鏈変骇鍝佷俊鎭�*/ - public Response getAllBom() { + /*public Response getAllBom(String parentCode,String parentName,String parentModel, int pageCurr,int pageSize) { + PageHelper.startPage(pageCurr,pageSize); QueryWrapper wrapper=new QueryWrapper(); wrapper.select("distinct parent_code","parent_name","parent_model","version").orderByAsc("id"); + if(parentCode!=null&&!parentCode.isEmpty()){ + wrapper.like("parent_code",parentCode); + } + if(parentName!=null&&!parentName.isEmpty()){ + wrapper.like("parent_name",parentName); + } + if(parentModel!=null&&!parentModel.isEmpty()){ + wrapper.like("parent_model",parentModel); + } List list=mapper.selectList(wrapper); - return new Response().setII(1,list!=null?true:false,list,"杩斿洖鏁版嵁"); - } - //浜у搧鎵撳寘涓嬭浇 - public Response downloadBom(HttpServletRequest req, HttpServletResponse resp, String parentModel) { + PageInfo pageInfo=new PageInfo(list); + return new Response().setII(1,list!=null?true:false,pageInfo,"杩斿洖鏁版嵁"); + }*/ + //浜у搧涓嬭浇(浜у搧id鍜岀増鏈�) + public void downloadProduct(HttpServletRequest req, HttpServletResponse resp, int productId , int version) { HSSFWorkbook wb = new HSSFWorkbook(); + //璇诲彇浜у搧淇℃伅 + QueryWrapper wrapper=new QueryWrapper(); + wrapper.eq("id",productId); + wrapper.eq("version",version); + wrapper.last("limit 1"); + Product product=productMapper.selectOne(wrapper); + //璇诲彇浜у搧鐨勫瓙浠跺拰鍏宠仈鐨勭墿鏂欎俊鎭� + List<ProductBom> list=mapper.getBomAndMaterial(productId,version); + //澶勭悊瀛樺湪鍏宠仈鍏崇郴鐨勭墿鏂� + List<ProductBom> endList=new ArrayList<>(); + list.stream().forEach(bom -> { + endList.add(bom); + if(bom.getMaterials()!=null&&bom.getMaterials().size()>0){ + for (Material m:bom.getMaterials()) { + //灏嗙墿鏂欏瓨鏀句负涓�涓猙om涓轰笅杞藉仛鍑嗗 + ProductBom copyBom=copyMaterialToBom(m); + endList.add(copyBom); + } + } + }); + //灏嗘病鏈夌鐞咮OM鐨刣wg鏂囦欢鎷疯礉涓嬭浇 + String withOutDwg="doc_file/product"+File.separator+product.getParentModel(); + if(product.getCustomCode()!=null&&!product.getCustomCode().isEmpty()){ + withOutDwg+=File.separator+product.getCustomCode()+File.separator+version; + }else{ + withOutDwg+=File.separator+"standard"+File.separator+version; + } + //鐢熸垚excel骞跺皢dwg鏂囦欢鏀惧湪鍚屼竴鎶ヤ笅鍘嬬缉 + creatBomExcel(req,resp,product,endList,wb,"bom",withOutDwg); + //璁板綍鏃ュ織 + DocUser docUser= ActionUtil.getUser(); + String operationDetail="鍏蜂綋浜у搧淇℃伅涓�:"+product.toString(); + String opreationMsg="鎵ц浜嗘渶鏂扮増浜у搧涓嬭浇鎿嶄綔"; + String terminalIp=req.getRemoteAddr(); + logService.recordOperationLog(docUser.getId(),docUser.getName(), UserOperation.TYPE_DOWNLOAD.getType(),new Date(),terminalIp,opreationMsg,operationDetail); + } + + + //鏍规嵁浜у搧淇℃伅鍒涘缓excel琛ㄦ牸骞跺瓨鏀惧湪鎸囧畾鐩綍 + private void creatBomExcel(HttpServletRequest req, HttpServletResponse resp,Product product,List list, HSSFWorkbook wb,String type,String withOutDwg){ + String fileDirName = FileDirPath.getFileDirName(); + String rootFace=""; + String excelName=""; //瀛椾綋鏍煎紡-鍔犵矖 HSSFCellStyle cellStyle = wb.createCellStyle(); HSSFFont font = wb.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); + font.setColor(HSSFFont.COLOR_RED); cellStyle.setFont(font); - QueryWrapper wrapper=new QueryWrapper(); - wrapper.eq("parent_model",parentModel); - List<ProductBom> list=mapper.selectList(wrapper); - //鐢熸垚excel骞跺皢dwg鏂囦欢鏀惧湪鍚屼竴鎶ヤ笅鍘嬬缉 - creatBomExcel(req,resp,list,wb); - return new Response().setII(1,true,"",""); - } - //鏍规嵁浜у搧淇℃伅鍒涘缓excel琛ㄦ牸骞跺瓨鏀惧湪鎸囧畾鐩綍 - public void creatBomExcel(HttpServletRequest req, HttpServletResponse resp,List<ProductBom> list, HSSFWorkbook wb){ - String fileDirName = FileDirPath.getFileDirName(); - String rootFace=fileDirName+ File.separator+"downLoad"; - String pictureName=""; - String excelName=""; //鍒涘缓鍗曚釜sheet - HSSFSheet sheet = wb.createSheet("bom淇℃伅"); + HSSFSheet sheet = wb.createSheet("浜у搧淇℃伅"); + sheet.setColumnWidth(1,5000); + sheet.setColumnWidth(2,5000); + sheet.setColumnWidth(3,5000); + sheet.setColumnWidth(4,5000); + sheet.setColumnWidth(6,5000); + sheet.setColumnWidth(7,5000); + sheet.setColumnWidth(8,5000); sheet.setColumnWidth(16,6000); + sheet.setDefaultRowHeight((short)(1000)); //鍥剧墖鍏冪礌 HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); int rownum = 1; @@ -240,23 +292,35 @@ sheet.getRow(rownum).createCell(14).setCellValue("琛ㄩ潰澶勭悊/鐗╂枡璇︽儏"); sheet.getRow(rownum).createCell(15).setCellValue("澶囨敞"); sheet.getRow(rownum).createCell(16).setCellValue("鍥剧墖"); + //鏋勫缓excel鍚嶇О鍜屽垱寤烘枃浠跺す + excelName=product.getParentCode()+"_"+product.getParentModel(); + String timeStr= ActionUtil.sdfwithFTP.format(new Date()); + if(type.equals("pic")){ + excelName=timeStr; + } + rootFace=fileDirName+File.separator+excelName; + File destfile = new File(rootFace); + if(!destfile.exists()) { + destfile.mkdir(); + } + //灏嗘病鏈夌鐞咮OM鐨刣wg鏂囦欢鎷疯礉涓嬭浇 + withOutDwg=fileDirName+File.separator+withOutDwg; + copyDir(withOutDwg,rootFace); //灏嗛�変腑鐨勬枃浠跺瓨鍏ユ寚瀹氱洰褰曚笅鎵撳寘涓嬭浇 if(list!=null&&list.size()>0){ for (int i=0;i<list.size();i++) { - ProductBom bom=list.get(i); + ProductBom bom= (ProductBom) list.get(i); String dwgUrl=bom.getDwgUrl(); - excelName=bom.getParentCode(); if((dwgUrl!=null)&&(!dwgUrl.isEmpty())){ - pictureName+=dwgUrl.substring(dwgUrl.lastIndexOf("\\")+1)+","; File sourceFile=new File(fileDirName+ File.separator+dwgUrl); copyFile(sourceFile,rootFace); } Row row=sheet.createRow(rownum+i+1); - row.setHeight((short)(1500)); + row.setRowStyle(cellStyle); sheet.getRow(rownum+i+1).createCell(1).setCellValue(i+1); - sheet.getRow(rownum+i+1).createCell(2).setCellValue(bom.getParentCode()); - sheet.getRow(rownum+i+1).createCell(3).setCellValue(bom.getParentName()); - sheet.getRow(rownum+i+1).createCell(4).setCellValue(bom.getParentModel()); + sheet.getRow(rownum+i+1).createCell(2).setCellValue(product.getParentCode()); + sheet.getRow(rownum+i+1).createCell(3).setCellValue(product.getParentName()); + sheet.getRow(rownum+i+1).createCell(4).setCellValue(product.getParentModel()); sheet.getRow(rownum+i+1).createCell(5).setCellValue(bom.getCategory()); sheet.getRow(rownum+i+1).createCell(6).setCellValue(bom.getSubCode()); sheet.getRow(rownum+i+1).createCell(7).setCellValue(bom.getSubName()); @@ -309,10 +373,11 @@ } } } - try { + try { File file=new File(rootFace+".zip"); FileOutputStream forootFace = new FileOutputStream(file); ZipUtils.toZip(rootFace, forootFace,true); + // 杞爜闃叉涔辩爜 resp.addHeader("Content-Disposition", "attachment;filename=" + new String(excelName.getBytes("UTF-8"), "ISO8859-1") @@ -328,11 +393,82 @@ in.close(); out.close(); file.delete(); + ZipUtils.delDir(rootFace); } catch (FileNotFoundException | UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } + //鏌ヨ鎵�鏈変骇鍝佷腑娌℃湁涓庢寚瀹氭暎瑁呬欢鍏宠仈鐨勫瓙浠� + public Response getAllSubWithOutMaterial(int materialId) { + List<ProductBom> list=mapper.getAllSubWithOutMaterial(materialId); + return new Response().setII(1,list.size()>0?true:false,list,"杩斿洖鏁版嵁"); + } + //鏍规嵁姣嶆枡鍨嬪彿鏌ヨ瀛愪欢淇℃伅鍙婃湁鏈�鏂扮増鏈叧鑱旂殑鏁h浠朵俊鎭� + /*public Response getSubByMaterialProduct(String parentModel) { + List<ProductBom> list=mapper.getSubByMaterialProduct(parentModel); + //鏌ヨ鍑哄瓨鍦ㄦ浛鎹㈠叧绯诲緱鏁h浠� + List<ProductBom> replaceBoms=cponentMapper.getReplaceMaterial(parentModel); + if(replaceBoms!=null&&replaceBoms.size()>0){ + replaceBoms.stream().forEach(replaceBom->{ + //濡傛灉瀛樺湪鏇挎崲鍏崇郴锛屾煡璇㈠嚭鍘熷瓙浠剁殑鍏宠仈鍏崇郴(灏嗗師瀛愪欢鍚嶇О鏀惧湪oldSubName涓�) + if(replaceBom!=null&&!replaceBom.getSubName().isEmpty()) { + //replaceBom琛ㄧず涓烘浛鎹欢 + replaceBom.setReplaceStatus(1); + if (replaceBom.getOldSubName() != null && !replaceBom.getOldSubName().isEmpty()) { + //鏌ヨ鍑哄瓨鍦ㄧ殑鏃х殑鍏宠仈瀛愪欢,杩樿涓庡師BOM鐗堟湰涓�鑷� + List<Material> oldCponent = mapper.getOldMaterial(replaceBom.getOldSubName()); + replaceBom.setMaterials(oldCponent); + } + } + list.add(replaceBom); + } + ); + } + return new Response().setII(1,list.size()>0?true:false,list,"杩斿洖鏁版嵁"); + }*/ + //鏍规嵁浜у搧id鏌ヨ瀛愪欢鍙婂叾鍏宠仈鐨勭墿鏂欎俊鎭� + public Response getBomAndMaterial(int productId,int version) { + List<ProductBom> list=mapper.getBomAndMaterial(productId,version); + return new Response().setII(1,list.size()>0?true:false,list,"杩斿洖鐗╂枡淇℃伅鍙婂叧鑱旂墿鏂�"); + } + //灏嗙墿鏂欏瓨鏀句负涓�涓猙om涓轰笅杞藉仛鍑嗗 + private ProductBom copyMaterialToBom(Material m) { + ProductBom bom=new ProductBom(); + bom.setType(m.getType()); + bom.setCategory(m.getCategory()); + bom.setSubCode(m.getSubCode()); + bom.setSubName(m.getSubName()); + bom.setSubModel(m.getSubModel()); + bom.setUnit(m.getUnit()); + bom.setQuantity(m.getQuantity()); + bom.setProducer(m.getProducer()); + bom.setMaterial(m.getMaterial()); + bom.setThickness(m.getThickness()); + bom.setSurfaceDetail(m.getSurfaceDetail()); + bom.setNotes(m.getNotes()); + bom.setPictureUrl(m.getPictureUrl()); + bom.setDwgUrl(m.getDwgUrl()); + bom.setFileUrl(m.getFileUrl()); + bom.setCreateDate(m.getCreateDate()); + return bom; + } + + public void insertBatch(List<ProductBom> productBomList) { + mapper.insertBatchSomeColumn(productBomList); + } + + public List<ProductBom> getBomByProductId(Integer productId) { + QueryWrapper<ProductBom> query = Wrappers.query(); + query.eq("product_id",productId); + return mapper.selectList(query); + } + + public void deleteByProductId(Integer productId) { + UpdateWrapper<ProductBom> update = Wrappers.update(); + update.eq("product_id",productId); + mapper.delete(update); + } } -- Gitblit v1.9.1