| | |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.function.Function; |
| | | import java.util.function.Predicate; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | |
| | | int lastRowNum = sheet.getLastRowNum(); |
| | | //取第三行,并以第三行开始 |
| | | Row row2 = sheet.getRow(1); |
| | | //现在规定为17列 |
| | | short lastCellNum = row2.getLastCellNum(); |
| | | if(lastCellNum !=18){ |
| | | return response.set(1, false, "上传文件的bom清单列数不对"); |
| | | } |
| | | for (int k = 2; k < lastRowNum + 1; k++) { |
| | | if(k==2){ |
| | | product.setParentCode(sheet.getRow(2).getCell(1).getStringCellValue()); |
| | | product.setParentName(sheet.getRow(2).getCell(2).getStringCellValue()); |
| | | product.setParentModel(sheet.getRow(2).getCell(3).getStringCellValue()); |
| | | String parentModel = sheet.getRow(2).getCell(3).getStringCellValue(); |
| | | parentModel = parentModel.trim(); |
| | | String regexStr = "[\\/*?\"|:<>\t]"; |
| | | boolean matches = Pattern.compile(regexStr).matcher(parentModel).find(); |
| | | if(!matches) { |
| | | product.setParentModel(parentModel); |
| | | }else{ |
| | | return response.set(1,false,"母料型号包含非法字符:\\/*?\"|:<>或前置空格"); |
| | | } |
| | | } |
| | | ProductBom bom = new ProductBom(); |
| | | for (int j = 0; j < lastCellNum; j++) { |
| | |
| | | Cell cell = row.getCell(j); |
| | | String cellValue = null; |
| | | Double cellValueInt = 0d; |
| | | if (j == 9 || j == 0) { |
| | | if (j == 9 || j == 0) { //1和10列为数值 |
| | | cellValueInt = cell.getNumericCellValue(); |
| | | } else if (j != 15) { |
| | | } else if (j != 16) { //16列为图片 |
| | | cellValue = cell.getStringCellValue(); |
| | | } |
| | | if(cellValue!=null) { |
| | |
| | | } |
| | | break; |
| | | case 11: { |
| | | bom.setMaterial(cellValue); |
| | | bom.setProducerSpecification(cellValue); |
| | | } |
| | | break; |
| | | case 12: { |
| | | bom.setThickness(cellValue); |
| | | bom.setMaterial(cellValue); |
| | | } |
| | | break; |
| | | case 13: { |
| | | bom.setSurfaceDetail(cellValue); |
| | | bom.setThickness(cellValue); |
| | | } |
| | | break; |
| | | case 14: { |
| | | bom.setNotes(cellValue); |
| | | bom.setSurfaceDetail(cellValue); |
| | | } |
| | | break; |
| | | case 15: { |
| | | bom.setNotes(cellValue); |
| | | } |
| | | break; |
| | | case 16: { |
| | | /* 弃用,不适用于 图片不按顺序摆放情况 |
| | | //图片,从0开始,到图片size为止 |
| | | int m = k - 2; |
| | |
| | | fileOutputStream.write(data); |
| | | |
| | | bom.setPictureUrl(picturePathFront); |
| | | } |
| | | } |
| | | break; |
| | | case 17: { |
| | | if(cellValue!=null && !cellValue.trim().equals("")) { |
| | | if(cellValue.contains(",") || cellValue.contains(",")){ |
| | | bom.setRelatedMaterialCodes(cellValue); |
| | | }else{ |
| | | return response.set(1, false, "上传文件的bom清单内替料格式不对"); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | |
| | | * @return |
| | | * @throws IOException |
| | | */ |
| | | @Transactional |
| | | @Transactional(rollbackFor = {RuntimeException.class,Exception.class}) |
| | | public Response add(Product product) throws IOException { |
| | | String parentCode = product.getParentCode(); |
| | | String customCode = product.getCustomCode(); |
| | |
| | | Date date = new Date(); |
| | | boolean isCopyCustom = false; |
| | | Product relatedProduct = null; |
| | | //校验凡是有定制表单号的产品,不能使用已上传过的标准产品编码 |
| | | if(customCode!=null && !customCode.trim().equals("")){ |
| | | ProductHistory standard = phService.getStandard(parentCode); |
| | | if(standard !=null){ |
| | | return new Response().set(1,false,"系统存在此次母物料编码的标准产品,拒绝提交"); |
| | | } |
| | | } |
| | | //判断是否为依据产品复制定制的产品 |
| | | if(bomList == null){ |
| | | bomList = pbService.getBomByProductId(product.getId()); |
| | |
| | | } |
| | | } |
| | | |
| | | //查询是否bomList中有替料 |
| | | // 有的话,检查关联表中是否已存在或本版本已生效 |
| | | List<MaterialProductHistory> newAddedList = new LinkedList<>(); |
| | | List<MaterialProductHistory> versionUpdateList = new LinkedList<>(); |
| | | |
| | | List<MaterialProductHistory> mpListInDB = mphService.getListByParentCodeAndCustomCodeAndSubMaterialIdAndVersion(parentCode,customCode,bomList,currentVersion); |
| | | List<String> subMaterialListInDB = mpListInDB.stream().map(mp->mp.getSubMaterial().getSubCode()+"_"+mp.getSubMaterial().getSubModel()).collect(Collectors.toList()); |
| | | bomList.forEach(bom->{ |
| | | if(bom.getRelatedMaterialCodes()!=null) { |
| | | String relatedMaterialCodes = bom.getRelatedMaterialCodes().trim(); |
| | | if (!relatedMaterialCodes.equals("")) { |
| | | if (subMaterialListInDB.contains(bom.getSubCode()+"_"+bom.getSubModel())) { //当前物料有替代料 |
| | | String[] relatedList; |
| | | if (relatedMaterialCodes.contains(",")) { |
| | | relatedList = relatedMaterialCodes.split(","); |
| | | } else { |
| | | relatedList = relatedMaterialCodes.split(","); |
| | | } |
| | | for (String related : relatedList) { |
| | | bom.setRelatedMaterialCodes(related); |
| | | boolean exists = false; |
| | | for (MaterialProductHistory mp : mpListInDB) { |
| | | //物料相同,替代料相同 |
| | | if ((mp.getSubMaterial().getSubCode()+"_"+mp.getSubMaterial().getSubModel()).equals(bom.getSubCode()+"_"+bom.getSubModel()) |
| | | && mp.getRelatedSubMaterial().getSubCode().equals(related)) { |
| | | //只可能存在0 和 1 的情况,因为查询的是 >=上个版本 |
| | | if (nextVersion - mp.getEVersion() == 0) { //已存在,无需添加 |
| | | //break; |
| | | } else if (nextVersion - mp.getEVersion() == 1) { //更新到当前版本 |
| | | mp.setEVersion(nextVersion); |
| | | versionUpdateList.add(mp); |
| | | } |
| | | exists = true; |
| | | } |
| | | } |
| | | if(!exists) { //不存在相邻及相同的记录版本,新增 |
| | | MaterialProductHistory newTemp = new MaterialProductHistory(); |
| | | newTemp.setParentCode(parentCode); |
| | | newTemp.setCustomCode(customCode); |
| | | newTemp.setSubCode(bom.getSubCode()); |
| | | Material material = mService.getByCodeAndModel(bom.getSubCode(), bom.getSubModel()); |
| | | newTemp.setSubMaterialId(material.getId()); |
| | | newTemp.setSVersion(nextVersion); |
| | | newTemp.setEVersion(nextVersion); |
| | | newTemp.setQuantity(bom.getQuantity()); |
| | | //2323-09-08 与杨红兰微信确认<就按照我上传清单的时间,系统里最新的是啥型号,就取什么型号> |
| | | Material relatedMaterial = mService.getLastByCode(related); |
| | | if(relatedMaterial == null){ |
| | | throw new RuntimeException("当前替料"+related+",编码在平台中不存在,无法关联替代"); |
| | | } |
| | | newTemp.setMaterialId(relatedMaterial.getId()); |
| | | newTemp.setCreateTime(date); |
| | | newAddedList.add(newTemp); |
| | | } |
| | | } |
| | | } |
| | | else{ |
| | | String[] relatedList; |
| | | if (relatedMaterialCodes.contains(",")) { |
| | | relatedList = relatedMaterialCodes.split(","); |
| | | } else { |
| | | relatedList = relatedMaterialCodes.split(","); |
| | | } |
| | | for (String related : relatedList) { |
| | | MaterialProductHistory newTemp = new MaterialProductHistory(); |
| | | newTemp.setParentCode(parentCode); |
| | | newTemp.setCustomCode(customCode); |
| | | newTemp.setSubCode(bom.getSubCode()); |
| | | Material material = mService.getByCodeAndModel(bom.getSubCode(), bom.getSubModel()); |
| | | newTemp.setSubMaterialId(material.getId()); |
| | | newTemp.setSVersion(nextVersion); |
| | | newTemp.setEVersion(nextVersion); |
| | | newTemp.setQuantity(bom.getQuantity()); |
| | | //2323-09-08 与杨红兰微信确认<就按照我上传清单的时间,系统里最新的是啥型号,就取什么型号> |
| | | Material relatedMaterial = mService.getLastByCode(related); |
| | | if(relatedMaterial == null){ |
| | | throw new RuntimeException("当前替料"+related+",编码在平台中不存在,无法关联替代"); |
| | | } |
| | | newTemp.setMaterialId(relatedMaterial.getId()); |
| | | newTemp.setCreateTime(date); |
| | | newAddedList.add(newTemp); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | //执行更新 |
| | | if(newAddedList.size()!=0) { |
| | | mphService.insertBatch(newAddedList); |
| | | } |
| | | if(versionUpdateList.size()!=0) { |
| | | mphService.updateVersionBatch(versionUpdateList); |
| | | } |
| | | |
| | | |
| | | //将产品文件复制至正式路径 |
| | | //文件转移,未跟子件挂钩的所有图纸图片转移到产品版本下:doc_file/product/{产品型号}/standard或者{customCode}}/{version}/ |
| | | //跟子件挂钩的转移到子件图纸下:doc_file/material/ |
| | |
| | | his.setVersionTime(product.getVersionTime()); |
| | | his.setVersion(1); |
| | | his.setSubVersionMax(1); |
| | | his.setEnabled(1); |
| | | //上传后的最初始使能状态为-1 |
| | | //第一次解锁后,后续的锁定和解锁在0和1之间切换 |
| | | his.setEnabled(-1); |
| | | phService.insertAndUpdateEnabled(his); |
| | | //phService.insert(his); |
| | | // -> product |
| | | // -> product 现有产品和产品bom不需要插入,但是要做删除原来的旧版本 |
| | | product.setId(his.getId()); |
| | | product.setCreateTime(date); |
| | | product.setVersion(1); |
| | | //insert(product); |
| | | deleteAndInsert(product); |
| | | //deleteAndInsert(product); |
| | | delete(product); |
| | | // -> bom |
| | | bomList.forEach(bom-> { |
| | | /*bomList.forEach(bom-> { |
| | | bom.setProductId(product.getId()); |
| | | bom.setSubVersion(1); |
| | | }); |
| | | pbService.insertBatch(bomList); |
| | | pbService.insertBatch(bomList);*/ |
| | | // -> bom_his |
| | | List<ProductBomHistory> bomHistoryList = new LinkedList<>(); |
| | | bomList.forEach(bom->{ |
| | |
| | | bomHistory.setMaterial(bom.getMaterial()); |
| | | bomHistory.setNotes(bom.getNotes()); |
| | | bomHistory.setProducer(bom.getProducer()); |
| | | bomHistory.setProducerSpecification(bom.getProducerSpecification()); |
| | | bomHistory.setSurfaceDetail(bom.getSurfaceDetail()); |
| | | bomHistory.setThickness(bom.getThickness()); |
| | | bomHistory.setSubSVersion(1); |
| | |
| | | productHistory.setVersion(nextVersion); |
| | | //版本新增,初始bom子件版本为1 |
| | | productHistory.setSubVersionMax(1); |
| | | productHistory.setEnabled(1); |
| | | |
| | | productHistory.setEnabled(-1); |
| | | phService.insertAndUpdateEnabled(productHistory); |
| | | // -> product |
| | | // -> product 现有产品和产品bom不需要插入,但是要做删除原来的旧版本 |
| | | product.setId(productHistory.getId()); |
| | | product.setCreateTime(date); |
| | | product.setVersion(nextVersion); |
| | | deleteAndInsert(product); |
| | | //deleteAndInsert(product); |
| | | delete(product); |
| | | // -> product_bom |
| | | List<ProductBom> productBomList = new LinkedList<>(); |
| | | /*List<ProductBom> productBomList = new LinkedList<>(); |
| | | bomMaterialList.forEach(bomMaterial -> { |
| | | ProductBom bom = new ProductBom(); |
| | | bom.setProductId(product.getId()); |
| | |
| | | bom.setMaterial(bomMaterial.getMaterial()); |
| | | bom.setNotes(bomMaterial.getNotes()); |
| | | bom.setProducer(bomMaterial.getProducer()); |
| | | bom.setProducerSpecification(bomMaterial.getProducerSpecification()); |
| | | bom.setSurfaceDetail(bomMaterial.getSurfaceDetail()); |
| | | bom.setThickness(bomMaterial.getThickness()); |
| | | bom.setSubVersion(1); |
| | |
| | | |
| | | productBomList.add(bom); |
| | | }); |
| | | pbService.insertBatch(productBomList); |
| | | pbService.insertBatch(productBomList);*/ |
| | | // -> product_bom_history |
| | | List<ProductBomHistory> bomHistoryList = new LinkedList<>(); |
| | | bomMaterialList.forEach(bomMaterial -> { |
| | |
| | | bomHistory.setMaterial(bomMaterial.getMaterial()); |
| | | bomHistory.setNotes(bomMaterial.getNotes()); |
| | | bomHistory.setProducer(bomMaterial.getProducer()); |
| | | bomHistory.setProducerSpecification(bomMaterial.getProducerSpecification()); |
| | | bomHistory.setSurfaceDetail(bomMaterial.getSurfaceDetail()); |
| | | bomHistory.setThickness(bomMaterial.getThickness()); |
| | | bomHistory.setSubSVersion(1); |
| | |
| | | mapper.insert(product); |
| | | } |
| | | |
| | | private void delete(Product product) { |
| | | Product productDB = getByProductCodeAndCustomCode(product.getParentCode(), product.getCustomCode()); |
| | | if(productDB!=null) { |
| | | mapper.deleteById(productDB.getId()); |
| | | pbService.deleteByProductId(productDB.getId()); |
| | | } |
| | | } |
| | | |
| | | private Product getByProductCodeAndCustomCode(String parentCode, String customCode) { |
| | | QueryWrapper<Product> query = Wrappers.query(); |
| | | query.eq("parent_code",parentCode).eq("custom_code",customCode).last(" limit 1"); |