package com.ccl.tt.controller; import com.ccl.tt.dao.BasicDao; import com.ccl.tt.dao.FinalRollDao; import com.ccl.tt.data.PartData; import com.ccl.tt.entity.*; import com.ccl.tt.repository.*; import com.ccl.tt.service.MailSendService; import com.ccl.tt.service.PrepressService; import com.ccl.tt.utils.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.propertyeditors.CustomDateEditor; import org.springframework.core.io.FileSystemResource; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; import org.springframework.data.repository.query.Param; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.*; import javax.persistence.criteria.Predicate; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.*; import java.util.regex.Pattern; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @Controller @RequestMapping("/prepress") public class PrePressController { private static Logger logger = LoggerFactory.getLogger(PrePressController.class); @Autowired private FinalRollDao finalRollDao; @Autowired private ShipmentRepository shipRepo; @Autowired private ProjectCodeRepository pjcRepo; @Autowired private MailSendService mailSendService; @Value("${com.ftp.ftpHost}") private String ftpHost; @Value("${com.ftp.ftpPort}") private Integer ftpPort; @Value("${com.ftp.ftpUser}") private String ftpUser; @Value("${com.ftp.ftpPassword}") private String ftpPassword; @Value("${com.ftp.ftpDir}") private String ftpDir; @Autowired private PrepressService prepressService; @Value("${item.zipPath}") private String zipPath; @Autowired private BasicDao basicDao; @InitBinder public void initBinder(WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); } @GetMapping("/") public String prepressHome(){ return "sntracking/prepress"; } /** * 返工单页面 * @return */ @GetMapping("/rework") public String prepressReworkHome(){ return "sntracking/prepress_rework"; } @GetMapping("/query") public String prepressQuery(){ return "sntracking/prepress_query"; } /** * IFS入库数量核实 * @return */ @GetMapping("/receiveQty") public String receiveQty(){ return "sntracking/receiveQty"; } /** * * @Title: serialInfo * @Description: 查询信息页面 * @author lirui * @date 2018年4月20日 * @param @return 参数 * @return String 返回类型 * @throws */ @GetMapping("/serialInfo") public String serialInfo(){ return "/sntracking/serial_info"; } /** * 按SO的数量自动统计页面 * @return */ @GetMapping("/soOrderInfo") public String soOrderInfo(){ return "/sntracking/so_order_info"; } /** * * @Title: getSerialInfo * @Description: TODO(这里用一句话描述这个方法的作用) * @author lirui * @date 2018年4月20日 * @param @param serialNo * @param @return 参数 * @return Object 返回类型 * @throws */ @PostMapping("/serialInfo") @ResponseBody public Object getSerialInfo(String serialNo){ Map map = new HashMap<>(); List rows = finalRollDao.getSerialInfo(serialNo); map.put("total", rows.size()); map.put("rows", rows); return map; } @PostMapping("/missingReportData") @ResponseBody public Object missingReportData(String serialNo){ Map map = new HashMap<>(); List rows = finalRollDao.getSerialInfo(serialNo); map.put("total", rows.size()); map.put("rows", rows); return map; } @GetMapping("/downSerialInfo") @ResponseBody public Object downSerialInfo(@RequestParam("serilaNo") String serilaNo, HttpServletResponse response) throws Exception { String filename = "Serials Number"+serilaNo+""+DateUtils.getStringDate(new Date(), "yyyyMMddhhmmss")+".xlsx"; File files = new File(filename); List> serialInfo = finalRollDao.getSerialforExcel(serilaNo); if(serialInfo==null ||serialInfo.isEmpty()){ return null; } OutExcel.converterMapToExcel(serialInfo, files,"Serials Number"+serilaNo+"",20); byte[] buffer = new byte[1024]; FileInputStream fis = null; BufferedInputStream bis = null; response.setContentType("application/force-download;charset=UTF-8"); response.setHeader("Content-disposition", "attachment; filename=" + new String(filename.getBytes(), "iso8859-1")); try { fis = new FileInputStream(files); bis = new BufferedInputStream(fis); int i = bis.read(buffer); ServletOutputStream os = response.getOutputStream(); while (i != -1) { os.write(buffer, 0, i); i = bis.read(buffer); } } catch (Exception e) { logger.info("Exception handling:"+e.getMessage()); } //释放资源 finally { if (bis != null) { bis.close(); } if (fis != null) { fis.close(); } } return null; } /** * 按SO的数量自动统计功能 * @param orderNo * @return */ @PostMapping("/soOrderInfo") @ResponseBody public Object getSoOrderInfo(String orderNo){ Map map = new HashMap<>(); List rows = finalRollDao.getSoOutputStatistic(orderNo); map.put("total", rows.size()); map.put("rows", rows); return map; } @GetMapping("/downSoOrderInfo") @ResponseBody public Object downSoOrderInfo(@RequestParam("orderNoSearch") String orderNoSearch, HttpServletResponse response) throws Exception { String filename = "Serials Number"+orderNoSearch+""+DateUtils.getStringDate(new Date(), "yyyyMMddhhmmss")+".xlsx"; File files = new File(filename); List> soOrderInfo = finalRollDao.getSoOrderforExcel(orderNoSearch); if(soOrderInfo==null ||soOrderInfo.isEmpty()){ return null; } OutExcel.converterMapToExcel(soOrderInfo, files,"Serials Number"+orderNoSearch+"",20); byte[] buffer = new byte[1024]; FileInputStream fis = null; BufferedInputStream bis = null; response.setContentType("application/force-download;charset=UTF-8"); response.setHeader("Content-disposition", "attachment; filename=" + new String(filename.getBytes(), "iso8859-1")); try { fis = new FileInputStream(files); bis = new BufferedInputStream(fis); int i = bis.read(buffer); ServletOutputStream os = response.getOutputStream(); while (i != -1) { os.write(buffer, 0, i); i = bis.read(buffer); } } catch (Exception e) { logger.info("Exception handling:"+e.getMessage()); } //释放资源 finally { if (bis != null) { bis.close(); } if (fis != null) { fis.close(); } } return null; } @Autowired private SoInfoRepository soInfoRepo; @Autowired private SoRollRepository rollRepo; @GetMapping("/all") @ResponseBody public Map soInfoJson( @RequestParam(value = "orderNo", required = false) String orderNo, @RequestParam(value = "createdDateFrom", required = false) String createdDateFrom, @RequestParam(value = "createdDateTo", required = false) String createdDateTo, @RequestParam(value = "statement", required = false) String statement, @RequestParam(value = "page", required = false, defaultValue = "1") Integer currPage, @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows, @RequestParam(value = "sort", required = false, defaultValue = "id") String sortField, @RequestParam(value = "order", required = false, defaultValue = "desc") String orderDirection ){ SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Sort sort = new Sort("desc".equals(orderDirection)?Sort.Direction.DESC:Sort.Direction.ASC, sortField); PageRequest pageRequest = new PageRequest(currPage-1, rows, sort); Page page = soInfoRepo.findAll((root, query, cb) -> { List predicateList = new ArrayList<>(); predicateList.add(cb.like(root.get("isrework"), "N")); if(StringUtils.hasText(orderNo)){ predicateList.add(cb.like(root.get("orderNo"), "%"+orderNo)); } if(StringUtils.hasText(statement)){ predicateList.add(cb.equal(root.get("statement"), statement)); } if(StringUtils.hasText(createdDateFrom)){ try { predicateList.add(cb.greaterThanOrEqualTo(root.get("createdDate"), fmt.parse(createdDateFrom + " 00:00:00"))); } catch (Exception e) { e.printStackTrace(); } } if(StringUtils.hasText(createdDateTo)){ try { predicateList.add(cb.lessThan(root.get("createdDate"), fmt.parse(createdDateTo + " 23:59:59"))); } catch (Exception e) { e.printStackTrace(); } } query.where(predicateList.toArray(new Predicate[]{})); return null; }, pageRequest); Map map = new HashMap(); map.put("total", page.getTotalElements()); map.put("rows", page.getContent()); return map; } @GetMapping("/reworkAll") @ResponseBody public Map soInfoReworkJson( @RequestParam(value = "orderNo", required = false) String orderNo, @RequestParam(value = "createdDateFrom", required = false) String createdDateFrom, @RequestParam(value = "createdDateTo", required = false) String createdDateTo, @RequestParam(value = "statement", required = false) String statement, @RequestParam(value = "page", required = false, defaultValue = "1") Integer currPage, @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows, @RequestParam(value = "sort", required = false, defaultValue = "id") String sortField, @RequestParam(value = "order", required = false, defaultValue = "desc") String orderDirection ){ SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Sort sort = new Sort("desc".equals(orderDirection)?Sort.Direction.DESC:Sort.Direction.ASC, sortField); PageRequest pageRequest = new PageRequest(currPage-1, rows, sort); Page page = soInfoRepo.findAll((root, query, cb) -> { List predicateList = new ArrayList<>(); predicateList.add(cb.like(root.get("isrework"), "Y")); if(StringUtils.hasText(orderNo)){ predicateList.add(cb.like(root.get("orderNo"), "%"+orderNo)); } if(StringUtils.hasText(statement)){ predicateList.add(cb.equal(root.get("statement"), statement)); } if(StringUtils.hasText(createdDateFrom)){ try { predicateList.add(cb.greaterThanOrEqualTo(root.get("createdDate"), fmt.parse(createdDateFrom + " 00:00:00"))); } catch (Exception e) { e.printStackTrace(); } } if(StringUtils.hasText(createdDateTo)){ try { predicateList.add(cb.lessThan(root.get("createdDate"), fmt.parse(createdDateTo + " 23:59:59"))); } catch (Exception e) { e.printStackTrace(); } } query.where(predicateList.toArray(new Predicate[]{})); return null; }, pageRequest ); Map map = new HashMap(); map.put("total", page.getTotalElements()); map.put("rows", page.getContent()); return map; } @GetMapping("/orderrolls/{orderNo}") @ResponseBody public Map orderRolls( @PathVariable(value = "orderNo") String orderNo, @RequestParam(value = "page", required = false, defaultValue = "1") Integer currPage, @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows, @RequestParam(value = "sort", required = false, defaultValue = "id") String sortField, @RequestParam(value = "order", required = false, defaultValue = "asc") String orderDirection ){ Sort sort = new Sort("desc".equals(orderDirection)?Sort.Direction.DESC:Sort.Direction.ASC, sortField); PageRequest pageRequest = new PageRequest(currPage-1, rows, sort); Page page = rollRepo.findAll((root, query, cb) -> { List predicateList = new ArrayList<>(); if(StringUtils.hasText(orderNo)){ predicateList.add(cb.equal(root.get("orderNo"), orderNo)); } query.where(predicateList.toArray(new Predicate[]{})); return null; }, pageRequest ); Map map = new HashMap(); map.put("total", page.getTotalElements()); map.put("rows", page.getContent()); return map; } /** * 生产订单导入 * @param soInfo * @return */ @PostMapping("/soinfo/add") @ResponseBody public Map add(SoInfo soInfo){ Map ret = new HashMap(); //调用方法 进行工单的新增 Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); try{ soInfo.setCreatedBy(authentication.getName()); soInfo.setCreatedDate(new Timestamp(System.currentTimeMillis())); soInfo.setStatus(SoInfo.CREATED); soInfo.setIsrework("N"); // soInfo.setFirstRollTime(new Date()); soInfo.validate(); //查询是否经过热覆合 String projectCode = soInfo.getProject(); ProjectCode projectData = pjcRepo.findOneByProjectCode(projectCode); if(projectData==null){ throw new RuntimeException("项目号不存在请联系系统管理员!"); } //设置参数 soInfo.setLaminationFlag(projectData.getLaminationFlag()); //查询长度是否符合要求 String apn = soInfo.getApn(); if(apn.length() != 11) { throw new RuntimeException("Length of apn does not comply with the rules!"); } String revNo = soInfo.getRevNo(); if(revNo.length() != 1) { throw new RuntimeException("revNo长度不符规则!"); } //添加全的客户料号 Map ifsOrder = jdbcTemplate.queryForMap(ifsOrderSql, soInfo.getOrderNo()); //获取字符串内容 String customerPartNoAll = String.valueOf(ifsOrder.get("customer_part_no")); //设置参数 soInfo.setCustomerPartNoAll(customerPartNoAll); soInfoRepo.save(soInfo); ret.put("success", true); }catch(DataIntegrityViolationException e){ ret.put("errorMsg", "Order No 不能重复"); }catch(Exception e){ ret.put("errorMsg", e.getMessage()); } return ret; } /** * * @Title: addSoInfo * @Description: 工单新增信息 * @author: LR * @date 2024年6月19日 下午2:24:09 * @return: Object * @throws */ @PostMapping("/soinfo/addSoInfo") @ResponseBody public Object addSoInfo(SoInfo soInfo){ Map resultMap = new HashMap(); try{ //获取ifs的工单信息 prepressService.addSoInfo(soInfo); resultMap.put("msg", "Successfully!"); resultMap.put("success", true); resultMap.put("code", 200); }catch (Exception e){ resultMap.put("code", 400); resultMap.put("success", false); resultMap.put("msg", e.getMessage()); } return resultMap; } /** * 新增返工订单 * @param soInfo * @return */ @PostMapping("/soinfo/addrework") @ResponseBody public Map addrework(SoInfo soInfo){ Map ret = new HashMap(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); try{ soInfo.setCreatedBy(authentication.getName()); soInfo.setCreatedDate(new Timestamp(System.currentTimeMillis())); soInfo.setStatus(SoInfo.CREATED); soInfo.setIsrework("Y"); soInfo.setFirstRollTime(new Date()); soInfo.validate(); //查询是否经过热覆合 //设置参数 soInfo.setLaminationFlag("Y"); //添加全的客户料号 Map ifsOrder = jdbcTemplate.queryForMap(ifsOrderSql, soInfo.getOrderNo()); //获取字符串内容 String customerPartNoAll = String.valueOf(ifsOrder.get("customer_part_no")); //设置参数 soInfo.setCustomerPartNoAll(customerPartNoAll); soInfoRepo.save(soInfo); ret.put("success", true); }catch(DataIntegrityViolationException e){ ret.put("errorMsg", "Order No 不能重复"); }catch(Exception e){ ret.put("errorMsg", e.getMessage()); } return ret; } @PostMapping("/soinfo/{id}/update") @ResponseBody public Map add(@PathVariable("id") Integer id, SoInfo soInfo){ Map ret = new HashMap(); try{ SoInfo dbSoInfo = soInfoRepo.findOne(id); dbSoInfo.setOrderNo(soInfo.getOrderNo()); dbSoInfo.setPartNo(soInfo.getPartNo()); dbSoInfo.setPartDesc(soInfo.getPartDesc()); dbSoInfo.setLotSize(soInfo.getLotSize()); dbSoInfo.setInputLotSize(soInfo.getInputLotSize()); dbSoInfo.setNeedDate(soInfo.getNeedDate()); dbSoInfo.setNoOfCross(soInfo.getNoOfCross()); dbSoInfo.setSerialsDate(soInfo.getSerialsDate()); dbSoInfo.setApn(soInfo.getApn()); dbSoInfo.setRevNo(soInfo.getRevNo()); dbSoInfo.setCustomerPartNo(soInfo.getCustomerPartNo()); dbSoInfo.setProject(soInfo.getProject()); dbSoInfo.setStandardRollQty(soInfo.getStandardRollQty()); //查询是否经过热覆合 String projectCode = soInfo.getProject(); ProjectCode projectData = pjcRepo.findOneByProjectCode(projectCode); //设置参数 soInfo.setLaminationFlag(projectData.getLaminationFlag()); dbSoInfo.validate(); soInfoRepo.save(dbSoInfo); ret.put("success", true); }catch(DataIntegrityViolationException e){ ret.put("errorMsg", "Order No 不能重复"); }catch(Exception e){ ret.put("errorMsg", e.getMessage()); } return ret; } @PostMapping("/soinfo/{id}/delete") @ResponseBody public Map delete(@PathVariable Integer id){ Map ret = new HashMap(); try{ SoInfo dbSoInfo = soInfoRepo.findOne(id); if (dbSoInfo == null){ throw new RuntimeException("订单未找到"); } if (!SoInfo.CREATED.equals(dbSoInfo.getStatus())){ throw new RuntimeException("Order number not found"); } soInfoRepo.delete(id); ret.put("success", true); }catch(Exception e){ ret.put("errorMsg", e.getMessage()); } return ret; } @PostMapping("/soinfo/{id}/delsn") @ResponseBody @Transactional public Map deleteSn(@PathVariable Integer id,Authentication authentication){ Map ret = new HashMap(); try{ SoInfo dbSoInfo = soInfoRepo.findOne(id); if (dbSoInfo == null){ throw new RuntimeException("订单未找到"); } List list = rollRepo.findByOrderNo(dbSoInfo.getOrderNo()); if (list != null && list.size() > 0){ throw new RuntimeException("已经存在卷信息,不能删除"); } if (SoInfo.GENERATED.equals(dbSoInfo.getStatus())){ dbSoInfo.setStatus(SoInfo.CREATED); } dbSoInfo.setSerialsGenBy(null); dbSoInfo.setSerialsGenDate(null); soInfoRepo.save(dbSoInfo); finalRollDao.deleteSNTemplateCopy(dbSoInfo); ret.put("success", true); }catch(Exception e){ ret.put("errorMsg", e.getMessage()); } return ret; } @PostMapping("/soinfo/{id}/refreshSerials") @ResponseBody public Map refreshSerials(@PathVariable Integer id,Authentication authentication){ Map ret = new HashMap(); try{ SoInfo dbSoInfo = soInfoRepo.findOne(id); if (dbSoInfo == null){ throw new RuntimeException("订单未找到"); } dbSoInfo.setStatus(SoInfo.GENERATED); List copyList=finalRollDao.getSNTemplateCopy(dbSoInfo); if (copyList.size()==0){ throw new RuntimeException("没有码包数据"); } dbSoInfo.setSerialsGenBy(copyList.get(0).getSerialsGenBy()); dbSoInfo.setSerialsGenDate(copyList.get(0).getSerialsGenDate()); dbSoInfo.setSerialEnd(copyList.get(0).getSerialEnd()); dbSoInfo.setSerialStart(copyList.get(0).getSerialStart()); dbSoInfo.setSerialsTemplate(copyList.get(0).getSerialsTemplate()); soInfoRepo.save(dbSoInfo); ret.put("success", true); }catch(Exception e){ ret.put("errorMsg", e.getMessage()); } return ret; } @GetMapping("/download/{filename}") @ResponseBody public FileSystemResource downloadFile(@PathVariable("filename") String filename, HttpServletResponse response){ response.setContentType("application/csv"); response.setHeader("Content-Disposition", "attachment; filename=" + filename + ".csv"); File file = new File("snfiles"+File.separator + filename + ".csv"); return new FileSystemResource(file); } /** * * @Title: downloadFileZip * @Description: 下载已经生成好的文件 * @author: LR * @date 2024年7月29日 下午5:46:22 * @return: FileSystemResource * @throws */ @GetMapping("/downloadFileZip/{fileName}") @ResponseBody public FileSystemResource downloadFileZip(@PathVariable("fileName") String fileName, HttpServletResponse response){ response.setContentType("application/zip"); response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".zip"); File sourceFile = new File(zipPath); //判断是否存在不存在创建目录 if(!sourceFile.exists()) { sourceFile.mkdirs(); } File targetFile = new File(sourceFile, fileName + ".zip"); return new FileSystemResource(targetFile); } @GetMapping("/downloadFileZipMulit/{filename}") @ResponseBody public FileSystemResource downloadFileZipMulit(@PathVariable("filename") String filename, HttpServletResponse response){ SoInfo soInfo=soInfoRepo.findByOrderNo(filename); String filenameNew=soInfo.getOrderNo()+"-"+soInfo.getPartNo()+"-"+soInfo.getApn()+"-"+soInfo.getRevNo(); response.setContentType("application/zip"); response.setHeader("Content-Disposition", "attachment; filename=" + filenameNew + ".zip"); File file = new File("snfiles"+File.separator + filenameNew + ".zip"); return new FileSystemResource(file); } @PostMapping("/uploadFTP") @ResponseBody @Transactional public Map uploadFTP(@RequestParam("fileName[]") String[] fileName, @Param("shipNo") String shipNo, HttpServletResponse response){ response.setContentType("application/csv"); response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".zip"); Shipment shipment = shipRepo.findByShipNo(shipNo); Map ret = new HashMap(); String flag = shipment.getFtpUploadflag(); ret.put("msg", ""); if("Y".equals(flag)){ ret.put("errorMsg", true); ret.put("data", "已上传"); logger.info("已上传"); return ret; } // Shipment shipment = shipRepo.findByShipNo(shipNo); List list = new ArrayList(); if(shipment.getCustomerNo()!=null&&!"".equals(shipment.getCustomerNo())){ list = finalRollDao.findByNo(shipment.getCustomerNo()); }else{ ret.put("errorMsg", true); ret.put("data", "用户编号为空"); logger.info("用户编号为空"); return ret; } if(null == list || list.size() ==0){ ret.put("errorMsg", true); ret.put("data", "数据库数据为空"); logger.info("数据库数据为空"); return ret; }else if(list.get(0).getFtpPath() == null || "".equals(list.get(0).getFtpPath())){ ret.put("errorMsg", true); ret.put("data", "The data is null"); logger.info("The data is null"); return ret; } String path ="";//上传成功后的返回路径 String filePath = "";//上传成功后保存数据库路径 FTPManager mana = FTPManager.getInstance(); String host = ftpHost;//IP地址 Integer port = ftpPort;//端口号 String user = ftpUser; //用户名 String password = ftpPassword;//密码 String dir = ftpDir;//首路径 //设置 mana.setInfo(host, port, user, password, dir); String bpath = ""; List findByNo=finalRollDao.findByNo(shipment.getCustomerNo()); if(findByNo.size()==0){ throw new RuntimeException("客户信息customer_ftppath未维护,请联系系统管理员!"); } String ftpFlag=findByNo.get(0).getFtpFlag(); try { for(int i = 0;i1){ titleEnd+="-"+(i+1); } mailSendService.sendCustomerMail(list.get(0), bpath,titleEnd); } ret.put("msg", "邮件发送成功!"); } } return ret; } @Autowired private SequenceRepository seqRepo; private static Pattern apnRevPattern = Pattern.compile("Label,([0-9A-Za-z\\-]+)-(\\S{1}),"); //Matcher m = p.matcher("Label,826-02449-A,NA"); @PostMapping("/soinfo/{id}/gensn") @Transactional @ResponseBody public Map genSn(@PathVariable Integer id){ Map ret = new HashMap(); try{ SoInfo dbSoInfo = soInfoRepo.findOne(id); if (dbSoInfo == null){ ret.put("errorMsg", "Order not found."); return ret; } if (dbSoInfo.getSerialsGenDate() != null){ ret.put("errorMsg", "Already generated"); return ret; } String snTemplate = genSerialTemplate(dbSoInfo); if(snTemplate==null){ ret.put("errorMsg", "eeeecode not found"); return ret; } dbSoInfo.setSerialsTemplate(snTemplate); //find existing Sequence seq = seqRepo.findByTag(snTemplate); if (seq == null){ seq = new Sequence(); seq.setTag(snTemplate); seq.setSeq(0); } dbSoInfo.setSerialStart(seq.getSeq() + 1); dbSoInfo.setSerialEnd(dbSoInfo.getSerialStart() + dbSoInfo.getInputLotSize() - 1); //多排文件 generateSerialNumbers(dbSoInfo); //单排文件 generateSerialNumbers_old(dbSoInfo); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); dbSoInfo.setRolls(0); dbSoInfo.setStatus(SoInfo.GENERATED); dbSoInfo.setSerialsGenBy(authentication.getName()); dbSoInfo.setSerialsGenDate(new Timestamp(System.currentTimeMillis())); finalRollDao.deleteSNTemplateCopy(dbSoInfo); finalRollDao.saveSNTemplateCopy(dbSoInfo); soInfoRepo.save(dbSoInfo); seq.setSeq(dbSoInfo.getSerialEnd()); seqRepo.save(seq); ret.put("success", true); }catch(Exception e){ ret.put("errorMsg", e.getMessage()); } return ret; } /** * * @Title: genSerials * @Description: 产生工单得码包新的方法 * @author: LR * @date 2024年6月19日 下午2:46:03 * @return: Object * @throws */ @PostMapping("/soinfo/{id}/genSerials") @ResponseBody public Object genSerials(@PathVariable Integer id){ Map resultMap = new HashMap(); try{ //获取ifs的工单信息 prepressService.genSerials(id); resultMap.put("msg", "Successfully!"); resultMap.put("success", true); }catch (Exception e){ resultMap.put("msg", e.getMessage()); } return resultMap; } @Value("${eeeecode}") private String appleEeeeCode; private String genSerialTemplate(SoInfo soInfo) { List list = pjcRepo.findByProjectCode(soInfo.getProject()); if(list.size()==0){ return null; } //查询生码的类型 String partNo = soInfo.getPartNo(); //查询物料的信息 PartData partData = basicDao.getPartDataByPartNo(partNo); String codeType = partData.getCodeType(); Calendar cal = Calendar.getInstance(); cal.setTime(soInfo.getSerialsDate()); String platCode3 = "J4K"; String year1 = String.valueOf(cal.get(Calendar.YEAR) % 10); String week2 = org.apache.commons.lang3.StringUtils.leftPad(String.valueOf(cal.get(Calendar.WEEK_OF_YEAR)), 2, '0'); String day1 = String.valueOf(cal.get(Calendar.DAY_OF_WEEK)); String code4 = "____"; String appleEEEE4 = list.get(0).getEeeecode(); String rev1 = soInfo.getRevNo(); String delimiter1 = "+"; String apn = soInfo.getApn(); String checkSum1 = "_"; String snLeft7 = platCode3 + year1 + week2 + day1; String snMiddle5 = appleEEEE4 + rev1; String snRight = delimiter1 + apn; String snFormat = null; if ("2024".equals(codeType)) { snFormat = snLeft7 + code4 + snMiddle5 + checkSum1 + snRight; }else if("2025".equals(codeType)) { snFormat = snLeft7 + code4 + snMiddle5 + checkSum1; } return snFormat; } //20230427 阮琦修改 原版在下面 private void generateSerialNumbers(SoInfo soInfo) throws IOException { if (soInfo.getSerialEnd() > 1336335) { throw new RuntimeException("序列号["+soInfo.getSerialStart()+"-"+soInfo.getSerialEnd()+"], 数量超出最大值。"); } long start = System.currentTimeMillis(); String fileName = soInfo.getOrderNo()+"-"+soInfo.getPartNo()+"-"+soInfo.getApn()+"-"+soInfo.getRevNo(); //start generate FileOutputStream fos = new FileOutputStream( "snfiles" + File.separator + fileName + ".zip"); BufferedOutputStream bos = new BufferedOutputStream(fos); ZipOutputStream zos = new ZipOutputStream(bos); ZipEntry entry = new ZipEntry(fileName + ".csv"); zos.putNextEntry(entry); //查询当前物料的数据 获取编码的类型 String partNo = soInfo.getPartNo(); PartData part = basicDao.getPartDataByPartNo(partNo); String codeType = part.getCodeType(); //把所有序列号收集起来放进一个list List allSn=new ArrayList<>(); StringBuilder template2 = new StringBuilder(soInfo.getSerialsTemplate()); int j=1; for (int snIndex = soInfo.getSerialStart(); snIndex <= soInfo.getSerialEnd(); snIndex++) { String currentSn = SerialUtil.getSerialNo(template2, snIndex, codeType); SNData snData=new SNData(); snData.setSn(currentSn); snData.setNumber(j); allSn.add(snData); j++; } int batchSize = (int) Math.ceil((double)allSn.size() / 4.0); //分成四组 List> groups = new ArrayList<>(); int startNum = 0; while (startNum < allSn.size()) { int endNum = Math.min(startNum + batchSize, allSn.size()); List group=new ArrayList<>(allSn.subList(startNum, endNum)); //如果最后一列少几个序列号 空字符串补齐 一般不会出现 while (group.size() < batchSize) { group.add(new SNData()); } groups.add(group); startNum = endNum; } zos.write(( soInfo.getApn()+"-"+soInfo.getRevNo()+"-1").getBytes("UTF-8")); zos.write(( ",").getBytes("UTF-8")); zos.write(( "ID-1").getBytes("UTF-8")); zos.write(( ",").getBytes("UTF-8")); zos.write(( soInfo.getApn()+"-"+soInfo.getRevNo()+"-2").getBytes("UTF-8")); zos.write(( ",").getBytes("UTF-8")); zos.write(( "ID-2").getBytes("UTF-8")); zos.write(( ",").getBytes("UTF-8")); zos.write(( soInfo.getApn()+"-"+soInfo.getRevNo()+"-3").getBytes("UTF-8")); zos.write(( ",").getBytes("UTF-8")); zos.write(( "ID-3").getBytes("UTF-8")); zos.write(( ",").getBytes("UTF-8")); zos.write(( soInfo.getApn()+"-"+soInfo.getRevNo()+"-4").getBytes("UTF-8")); zos.write(( ",").getBytes("UTF-8")); zos.write(( "ID-4" + "\r\n").getBytes("UTF-8")); for (int i=0; i 1336335) { throw new RuntimeException("序列号["+soInfo.getSerialStart()+"-"+soInfo.getSerialEnd()+"], 数量超出最大值。"); } long start = System.currentTimeMillis(); String fileName = soInfo.getOrderNo(); //start generate FileOutputStream fos = new FileOutputStream( "snfiles" + File.separator + fileName + ".zip"); BufferedOutputStream bos = new BufferedOutputStream(fos); ZipOutputStream zos = new ZipOutputStream(bos); ZipEntry entry = new ZipEntry(fileName + ".csv"); zos.putNextEntry(entry); zos.write(( soInfo.getApn()).getBytes("UTF-8")); zos.write(( ",").getBytes("UTF-8")); zos.write(( "ID" + "\r\n").getBytes("UTF-8")); StringBuilder template = new StringBuilder(soInfo.getSerialsTemplate()); int i =0; //查询当前物料的数据 获取编码的类型 String partNo = soInfo.getPartNo(); PartData part = basicDao.getPartDataByPartNo(partNo); String codeType = part.getCodeType(); for (int snIndex = soInfo.getSerialStart(); snIndex <= soInfo.getSerialEnd(); snIndex++) { i = i+1; String currentSn = SerialUtil.getSerialNo(template, snIndex, codeType); zos.write(( currentSn).getBytes("UTF-8")); zos.write(( ",").getBytes("UTF-8")); zos.write(( i + "\r\n").getBytes("UTF-8")); } zos.flush(); zos.close(); bos.flush(); bos.close(); fos.flush(); fos.close(); long duration = System.currentTimeMillis() - start; logger.info("Generated SN for order [{}], template={}, size={}, duration={}.", soInfo.getOrderNo(), soInfo.getSerialsTemplate(), soInfo.getInputLotSize(), duration); } @Autowired SerialsTrackingService snTrackingService; @PostMapping("/downloadTrace") @ResponseBody public Map downloadTrace(@RequestParam("orderNo") String orderNo){ Map ret = new HashMap(); try{ snTrackingService.trace(orderNo); ret.put("fileName", "tracking"+orderNo); ret.put("success", true); }catch (Exception e){ ret.put("errorMsg", e.getMessage()); } return ret; } /** * * @Title: downloadSingleTrace * @Description: 按照单排下载 * @param orderNo * @return * @return: Map * @author LR * @date: 2021-7-28 10:09:34 * @throws */ @PostMapping("/downloadSingleTrace") @ResponseBody public Map downloadSingleTrace(@RequestParam("orderNo") String orderNo){ Map ret = new HashMap(); try{ snTrackingService.downloadSingleTrace(orderNo); ret.put("fileName", "tracking-single-"+orderNo); ret.put("success", true); }catch (Exception e){ ret.put("errorMsg", e.getMessage()); } return ret; } /** * 仅导出未扫描(Trace) * @param orderNo * @return */ @PostMapping("/notScanTrace") @ResponseBody public Map notScanTrace(@RequestParam("orderNo") String orderNo){ Map ret = new HashMap(); try{ snTrackingService.notScanTrace(orderNo); ret.put("fileName", "notScanTrace"+orderNo); ret.put("success", true); }catch (Exception e){ ret.put("errorMsg", e.getMessage()); } return ret; } /** * 仅导出未扫描(Trace) * @param orderNo * @return */ @PostMapping("/exportMissSn") @ResponseBody public Map exportMissSn(@RequestParam("startQty") Integer startQty,@RequestParam("endQty") Integer endQty ,@RequestParam("orderNo") String orderNo,@RequestParam("serialNo") String serialNo){ Map ret = new HashMap(); try{ snTrackingService.exportMissSn(startQty,endQty,orderNo,serialNo); ret.put("fileName", "missingReport"+orderNo); ret.put("success", true); }catch (Exception e){ ret.put("errorMsg", e.getMessage()); } return ret; } // @Autowired // IfsService ifsService; @Value("${ifs.datasource.sql.order}") String ifsOrderSql; @Autowired JdbcTemplate jdbcTemplate; @PostMapping("/ifsOrder") @ResponseBody public Map getIfsOrder(@RequestParam("orderNo") String orderNo){ Map resultMap = new HashMap(); try{ //获取ifs的工单信息 Map resultRow = prepressService.getIfsOrder(orderNo); resultMap.put("ifsOrder", resultRow); resultMap.put("msg", "Successfully!"); resultMap.put("success", true); }catch (Exception e){ resultMap.put("success", false); resultMap.put("msg", e.getMessage()); } return resultMap; } @GetMapping("/getReceiveQty") @ResponseBody public Object getReceiveQty(@RequestParam(value = "orderNo", required = false) String orderNo, String startTime, String endTime, @RequestParam(value = "page", required = false, defaultValue = "1") Integer currPage, @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows, @RequestParam(value = "sort", required = false, defaultValue = "id") String sortField, @RequestParam(value = "order", required = false, defaultValue = "asc") String orderDirection){ Map map = new HashMap<>(); List row = finalRollDao.getReceiveQty(orderNo, startTime, endTime); map.put("total", row.size()); map.put("rows", row); return map; } }