| | |
| | | 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()); |
| | |
| | | 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->{ |
| | |
| | | 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()); |
| | |
| | | |
| | | productBomList.add(bom); |
| | | }); |
| | | pbService.insertBatch(productBomList); |
| | | pbService.insertBatch(productBomList);*/ |
| | | // -> product_bom_history |
| | | List<ProductBomHistory> bomHistoryList = new LinkedList<>(); |
| | | bomMaterialList.forEach(bomMaterial -> { |
| | |
| | | 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"); |