| | |
| | | import com.whyc.dto.FileDirPath; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.ZipUtils; |
| | | import com.whyc.mapper.ComponentMapper; |
| | | import com.whyc.mapper.MaterialMapper; |
| | | import com.whyc.mapper.ProductBomHistoryMapper; |
| | | import com.whyc.pojo.DocUser; |
| | | import com.whyc.pojo.ProductBom; |
| | | import com.whyc.pojo.ProductBomHistory; |
| | | import com.whyc.mapper.ProductHistoryMapper; |
| | | import com.whyc.pojo.*; |
| | | import com.whyc.util.ActionUtil; |
| | | import org.apache.poi.hssf.usermodel.*; |
| | | import org.apache.poi.ss.usermodel.ClientAnchor; |
| | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.*; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | |
| | | public class ProductBomHistoryService { |
| | | @Autowired(required = false) |
| | | private ProductBomHistoryMapper mapper; |
| | | |
| | | @Autowired(required = false) |
| | | private ComponentMapper cponentMapper; |
| | | private ProductHistoryMapper pHistoryMapper; |
| | | |
| | | @Autowired(required = false) |
| | | private MaterialMapper cponentMapper; |
| | | |
| | | @Autowired |
| | | private DocLogService logService; |
| | |
| | | public void updateVersionBatch(List<ProductBomHistory> newVersionCurrentHistoryList) { |
| | | mapper.updateVersionBatch(newVersionCurrentHistoryList); |
| | | } |
| | | //查询具体某一版本产品信息 |
| | | /* //查询具体某一版本产品信息 |
| | | public Response getBoomByVersion(String parentModel, int version) { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("parent_model",parentModel); |
| | |
| | | wrapper.ge("e_version",version); |
| | | List<ProductBomHistory> list=mapper.selectList(wrapper); |
| | | //查询出存在替换关系得散装件 |
| | | List<ProductBomHistory> replaceBomHis=cponentMapper.getReplaceHisComponent(parentModel,version); |
| | | List<ProductBomHistory> replaceBomHis=cponentMapper.getReplaceHisMaterial(parentModel,version); |
| | | //两个集合合并才是最终的BOM |
| | | if(list!=null&&list.size()>0){ |
| | | if(replaceBomHis!=null&&replaceBomHis.size()>0){ |
| | |
| | | } |
| | | } |
| | | return new Response().setII(1,list.size()>0?true:false,list,""); |
| | | } |
| | | //下载指定版本的产品 |
| | | public void downloaByVersion(HttpServletRequest req, HttpServletResponse resp, String parentModel, int version) { |
| | | }*/ |
| | | //历史产品信息查看(根据历史产品产品id和版本查询子件及其关联的物料信息) |
| | | public Response getBomHistoryAndMaterial(int productId, int version) { |
| | | List<ProductBomHistory> list=mapper.getBomHistoryAndMaterial(productId,version); |
| | | //查询产品的软件 |
| | | List<ProductSoftware> listsoft=mapper.selectSoftware(productId); |
| | | //将没有管理BOM的dwg文件 |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("id",productId); |
| | | wrapper.eq("version",version); |
| | | wrapper.last("limit 1"); |
| | | ProductHistory pHistory=pHistoryMapper.selectOne(wrapper); |
| | | String withOutDwg="doc_file/product"+File.separator+pHistory.getParentModel(); |
| | | if(pHistory.getCustomCode()!=null&&!pHistory.getCustomCode().isEmpty()){ |
| | | withOutDwg+=File.separator+pHistory.getCustomCode()+File.separator+version; |
| | | }else{ |
| | | withOutDwg+=File.separator+"standard"+File.separator+version; |
| | | } |
| | | String fileDirName = FileDirPath.getFileDirName(); |
| | | //将没有管理BOM的dwg文件拷贝下载 |
| | | fileDirName=fileDirName+File.separator+withOutDwg; |
| | | File start = new File(fileDirName); |
| | | String[] files =new String[]{}; |
| | | if(start.exists()) { |
| | | files= start.list();//获取该文件夹下的所有文件名字 |
| | | if(files.length>=0){ |
| | | for(int i=0;i<files.length;i++) { |
| | | files[i]=withOutDwg+File.separator+files[i]; |
| | | } |
| | | } |
| | | } |
| | | return new Response().setIIII(1,list.size()>0?true:false,list,listsoft,files,"返回物料信息及关联物料"); |
| | | } |
| | | //历史产品下载(产品id和版本<下载的版本>) |
| | | public void downloadProductHistory(HttpServletRequest req, HttpServletResponse resp, int productId, int version) { |
| | | //读取产品信息 |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("parent_model",parentModel); |
| | | wrapper.le("s_version",version); |
| | | wrapper.ge("e_version",version); |
| | | List<ProductBomHistory> list=mapper.selectList(wrapper); |
| | | //查询出存在替换关系得散装件 |
| | | List<ProductBomHistory> replaceBomHis=cponentMapper.getReplaceHisComponent(parentModel,version); |
| | | //两个集合合并才是最终的BOM |
| | | if(list!=null&&list.size()>0){ |
| | | if(replaceBomHis!=null&&replaceBomHis.size()>0){ |
| | | replaceBomHis.stream().forEach(replaceBom->{ |
| | | list.add(replaceBom); |
| | | }); |
| | | wrapper.eq("id",productId); |
| | | wrapper.eq("version",version); |
| | | wrapper.last("limit 1"); |
| | | ProductHistory pHistory=pHistoryMapper.selectOne(wrapper); |
| | | //读取指定版本产品的子件和关联的物料信息 |
| | | List<ProductBomHistory> list=mapper.getBomHistoryAndMaterial(productId,version); |
| | | //处理存在关联关系的物料 |
| | | List<ProductBomHistory> endList=new ArrayList<>(); |
| | | list.stream().forEach(bomHistory -> { |
| | | endList.add(bomHistory); |
| | | if(bomHistory.getMaterials()!=null&&bomHistory.getMaterials().size()>0){ |
| | | for (Material m:bomHistory.getMaterials()) { |
| | | //将物料存放为一个bom为下载做准备 |
| | | ProductBomHistory copyBomHis=copyMaterialToBomHis(m); |
| | | endList.add(copyBomHis); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | HSSFWorkbook wb = new HSSFWorkbook(); |
| | | //字体格式-加粗 |
| | | HSSFCellStyle cellStyle = wb.createCellStyle(); |
| | | HSSFFont font = wb.createFont(); |
| | | font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); |
| | | cellStyle.setFont(font); |
| | | String withOutDwg="doc_file/product"+File.separator+pHistory.getParentModel(); |
| | | if(pHistory.getCustomCode()!=null&&!pHistory.getCustomCode().isEmpty()){ |
| | | withOutDwg+=File.separator+pHistory.getCustomCode()+File.separator+version; |
| | | }else{ |
| | | withOutDwg+=File.separator+"standard"+File.separator+version; |
| | | } |
| | | //生成excel并将dwg文件放在同一报下压缩 |
| | | creatBomHsitoryExcel(req,resp,list,wb,version); |
| | | creatBomHsitoryExcel(req,resp,pHistory,endList,wb,withOutDwg); |
| | | //记录日志 |
| | | DocUser docUser= ActionUtil.getUser(); |
| | | String operationDetail="具体产品母料型号为:"+parentModel; |
| | | String opreationMsg="执行了最新版产品下载操作"; |
| | | String operationDetail="具体产品为:"+pHistory.toString(); |
| | | String opreationMsg="执行了"+pHistory.getVersion()+"版本产品的下载操作"; |
| | | String terminalIp=req.getRemoteAddr(); |
| | | logService.recordOperationLog(docUser.getId(),docUser.getName(), UserOperation.TYPE_DOWNLOAD.getType(),new Date(),terminalIp,opreationMsg,operationDetail); |
| | | } |
| | | //根据产品信息创建excel表格并存放在指定目录 |
| | | public void creatBomHsitoryExcel(HttpServletRequest req, HttpServletResponse resp,List<ProductBomHistory> list, HSSFWorkbook wb,int version){ |
| | | public void creatBomHsitoryExcel(HttpServletRequest req, HttpServletResponse resp,ProductHistory pHistory,List<ProductBomHistory> list, HSSFWorkbook wb,String withOutDwg){ |
| | | String fileDirName = FileDirPath.getFileDirName(); |
| | | String rootFace=""; |
| | | String excelName=""; |
| | | //创建单个sheet |
| | | HSSFSheet sheet = wb.createSheet("bom_"+version+"信息"); |
| | | HSSFSheet sheet = wb.createSheet("bom_"+pHistory.getVersion()+"信息"); |
| | | sheet.setColumnWidth(1,5000); |
| | | sheet.setColumnWidth(2,5000); |
| | | sheet.setColumnWidth(3,5000); |
| | |
| | | sheet.getRow(rownum).createCell(14).setCellValue("表面处理/物料详情"); |
| | | sheet.getRow(rownum).createCell(15).setCellValue("备注"); |
| | | sheet.getRow(rownum).createCell(16).setCellValue("图片"); |
| | | |
| | | excelName=pHistory.getParentCode()+"_"+pHistory.getParentModel()+"_"+pHistory.getVersion(); |
| | | rootFace=fileDirName+ File.separator+excelName; |
| | | File destfile = new File(rootFace); |
| | | if(!destfile.exists()) { |
| | | destfile.mkdir(); |
| | | } |
| | | //将没有管理BOM的dwg文件拷贝下载 |
| | | withOutDwg=fileDirName+File.separator+withOutDwg; |
| | | bomService.copyDir(withOutDwg,rootFace); |
| | | //将选中的文件存入指定目录下打包下载 |
| | | if(list!=null&&list.size()>0){ |
| | | for (int i=0;i<list.size();i++) { |
| | | ProductBomHistory bomHistory= (ProductBomHistory) list.get(i); |
| | | String dwgUrl=bomHistory.getDwgUrl(); |
| | | if(i==0){ |
| | | excelName=bomHistory.getParentCode()+"_"+bomHistory.getParentModel()+"_"+version; |
| | | rootFace=fileDirName+ File.separator+excelName; |
| | | File destfile = new File(rootFace); |
| | | if(!destfile.exists()) { |
| | | destfile.mkdir(); |
| | | } |
| | | } |
| | | |
| | | if((dwgUrl!=null)&&(!dwgUrl.isEmpty())){ |
| | | File sourceFile=new File(fileDirName+ File.separator+dwgUrl); |
| | | bomService.copyFile(sourceFile,rootFace); |
| | |
| | | Row row=sheet.createRow(rownum+i+1); |
| | | //row.setHeight((short)(1500)); |
| | | sheet.getRow(rownum+i+1).createCell(1).setCellValue(i+1); |
| | | sheet.getRow(rownum+i+1).createCell(2).setCellValue(bomHistory.getParentCode()); |
| | | sheet.getRow(rownum+i+1).createCell(3).setCellValue(bomHistory.getParentName()); |
| | | sheet.getRow(rownum+i+1).createCell(4).setCellValue(bomHistory.getParentModel()); |
| | | sheet.getRow(rownum+i+1).createCell(2).setCellValue(pHistory.getParentCode()); |
| | | sheet.getRow(rownum+i+1).createCell(3).setCellValue(pHistory.getParentName()); |
| | | sheet.getRow(rownum+i+1).createCell(4).setCellValue(pHistory.getParentModel()); |
| | | sheet.getRow(rownum+i+1).createCell(5).setCellValue(bomHistory.getCategory()); |
| | | sheet.getRow(rownum+i+1).createCell(6).setCellValue(bomHistory.getSubCode()); |
| | | if(bomHistory.getOldSubName()!=null&&!bomHistory.getOldSubName().isEmpty()){ |
| | | sheet.getRow(rownum+i+1).createCell(7).setCellValue(bomHistory.getSubName()+"("+bomHistory.getOldSubName()+")"); |
| | | }else{ |
| | | sheet.getRow(rownum+i+1).createCell(7).setCellValue(bomHistory.getSubName()); |
| | | } |
| | | sheet.getRow(rownum+i+1).createCell(7).setCellValue(bomHistory.getSubName()); |
| | | sheet.getRow(rownum+i+1).createCell(8).setCellValue(bomHistory.getSubModel()); |
| | | sheet.getRow(rownum+i+1).createCell(9).setCellValue(bomHistory.getUnit()==null?"":bomHistory.getUnit()); |
| | | sheet.getRow(rownum+i+1).createCell(10).setCellValue(bomHistory.getQuantity()); |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | //将物料存放为一个bomHistory为下载做准备 |
| | | private ProductBomHistory copyMaterialToBomHis(Material m) { |
| | | ProductBomHistory bomHis=new ProductBomHistory(); |
| | | bomHis.setType(m.getType()); |
| | | bomHis.setCategory(m.getCategory()); |
| | | bomHis.setSubCode(m.getSubCode()); |
| | | bomHis.setSubName(m.getSubName()); |
| | | bomHis.setSubModel(m.getSubModel()); |
| | | bomHis.setUnit(m.getUnit()); |
| | | bomHis.setQuantity(m.getQuantity()); |
| | | bomHis.setProducer(m.getProducer()); |
| | | bomHis.setMaterial(m.getMaterial()); |
| | | bomHis.setThickness(m.getThickness()); |
| | | bomHis.setSurfaceDetail(m.getSurfaceDetail()); |
| | | bomHis.setNotes(m.getNotes()); |
| | | bomHis.setPictureUrl(m.getPictureUrl()); |
| | | bomHis.setDwgUrl(m.getDwgUrl()); |
| | | bomHis.setFileUrl(m.getFileUrl()); |
| | | bomHis.setCreateDate(m.getCreateDate()); |
| | | return bomHis; |
| | | } |
| | | |
| | | public void insertBatch(List<ProductBomHistory> bomHistoryList) { |
| | | mapper.insertBatchSomeColumn(bomHistoryList); |
| | | } |
| | | } |