From 32b2700a9f9c5dc8f652d656468a6c33a53ac2ee Mon Sep 17 00:00:00 2001 From: starrysky <838252223@qq.com> Date: Thu, 22 Aug 2019 09:56:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BA=A7=E5=93=81=E8=B5=84?= =?UTF-8?q?=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/wms/bd/domain/ProductInfo.java | 2 +- .../bd/request/CreateProductInfoRequest.java | 50 ++++++++++++++ .../wms/bd/request/ProductInitialSetup.java | 23 +++++++ .../bd/request/ProductInventoryWarning.java | 8 +++ .../bd/rest/ProductCategoryController.java | 4 +- .../wms/bd/rest/ProductInfoController.java | 6 +- .../wms/bd/service/ProductInfoService.java | 5 +- .../wms/bd/service/dto/ProductInfoDTO.java | 10 --- .../bd/service/dto/ProductInfoDetailDTO.java | 24 +++++++ .../service/impl/ProductInfoServiceImpl.java | 69 +++++++++++++++++-- 10 files changed, 177 insertions(+), 24 deletions(-) create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/request/CreateProductInfoRequest.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/request/ProductInitialSetup.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/request/ProductInventoryWarning.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/dto/ProductInfoDetailDTO.java diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/domain/ProductInfo.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/domain/ProductInfo.java index b1fc2c97..f2d3d722 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/domain/ProductInfo.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/domain/ProductInfo.java @@ -55,7 +55,7 @@ public class ProductInfo implements Serializable { @Column(name = "unit_price") private Long unitPrice; - // 产品库存预警[{“sort”:1,”ware_house_code”:””,”ware_house_name”:””,”minimum_inventory”:””,”highest_inventory”:””}] + // 产品库存预警[{“sort”:1,”wareHouseCode”:””,”wareHouseName”:””,”minimumInventory”:””,”highestInventory”:””}] @Column(name = "product_inventory_warning") private String productInventoryWarning; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/request/CreateProductInfoRequest.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/request/CreateProductInfoRequest.java new file mode 100644 index 00000000..ce832554 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/request/CreateProductInfoRequest.java @@ -0,0 +1,50 @@ +package me.zhengjie.modules.wms.bd.request; + +import lombok.Data; + +import javax.persistence.Column; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import java.io.Serializable; +import java.util.List; + +/** + * @author 黄星星 + * @date 2019-08-21 + */ + +@Data +public class CreateProductInfoRequest implements Serializable { + + // 所属产品分类 + private long productCategoryId; + + // 产品分类名称 + private String productCategoryName; + + // 产品编号 + private String productCode; + + // 产品名称 + private String name; + + // 产品规格 + private String specifications; + + // 所属计量单位主键 + private long measureUnitId; + + // 所属计量单位名称 + private String measureUnitName; + + // 产品单价(保留两位小数) 单位:元 + private Long unitPrice; + + // 产品库存预警 + private List productInventoryWarningList; + + // 产品期初设置 + private List productInitialSetupList; + +} diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/request/ProductInitialSetup.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/request/ProductInitialSetup.java new file mode 100644 index 00000000..138200d9 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/request/ProductInitialSetup.java @@ -0,0 +1,23 @@ +package me.zhengjie.modules.wms.bd.request; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @author 黄星星 + * @date 2019-08-22 + */ +@Data +public class ProductInitialSetup implements Serializable { + + private Integer sort; + + private String wareHouseCode; + + private String wareHouseName; + + private String wareHouseTypeCode; + + private String wareHouseTypeName; +} diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/request/ProductInventoryWarning.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/request/ProductInventoryWarning.java new file mode 100644 index 00000000..1009a7df --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/request/ProductInventoryWarning.java @@ -0,0 +1,8 @@ +package me.zhengjie.modules.wms.bd.request; + +/** + * @author 黄星星 + * @date 2019-08-21 + */ +public class ProductInventoryWarning { +} diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/rest/ProductCategoryController.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/rest/ProductCategoryController.java index 324d5d21..d8ec9be0 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/rest/ProductCategoryController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/rest/ProductCategoryController.java @@ -50,8 +50,8 @@ public class ProductCategoryController { @Log("查询产品类别列表") @GetMapping(value = "/queryProductCategoryList") - public ResponseEntity queryProductCategoryList(ProductCategoryDTO resources, Pageable pageable){ - return new ResponseEntity(productCategoryService.queryAll(resources,pageable),HttpStatus.OK); + public ResponseEntity queryProductCategoryList(ProductCategoryDTO resources){ + return new ResponseEntity(productCategoryService.queryAll(resources),HttpStatus.OK); } @Log("分页查询产品类别") diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/rest/ProductInfoController.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/rest/ProductInfoController.java index fa6836d3..b41a3d6b 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/rest/ProductInfoController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/rest/ProductInfoController.java @@ -2,6 +2,7 @@ package me.zhengjie.modules.wms.bd.rest; import me.zhengjie.aop.log.Log; import me.zhengjie.modules.wms.bd.domain.ProductInfo; +import me.zhengjie.modules.wms.bd.request.CreateProductInfoRequest; import me.zhengjie.modules.wms.bd.service.ProductInfoService; import me.zhengjie.modules.wms.bd.service.dto.ProductInfoQueryCriteria; import org.springframework.beans.factory.annotation.Autowired; @@ -60,8 +61,8 @@ public class ProductInfoController { @ApiOperation(value = "新增产品资料") @PostMapping(value = "/productInfo") @PreAuthorize("hasAnyRole('ADMIN','BDPRODUCTINFO_ALL','BDPRODUCTINFO_CREATE')") - public ResponseEntity create(@Validated @RequestBody ProductInfo resources){ - return new ResponseEntity(productInfoService.create(resources),HttpStatus.CREATED); + public ResponseEntity create(@RequestBody CreateProductInfoRequest createProductInfoRequest){ + return new ResponseEntity(productInfoService.create(createProductInfoRequest),HttpStatus.CREATED); } @Log("修改产品资料") @@ -87,4 +88,5 @@ public class ProductInfoController { public ResponseEntity getMessureUnit(@PathVariable Long id){ return new ResponseEntity(productInfoService.findById(id), HttpStatus.OK); } + } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/ProductInfoService.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/ProductInfoService.java index 4fed9a69..6668786b 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/ProductInfoService.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/ProductInfoService.java @@ -1,6 +1,7 @@ package me.zhengjie.modules.wms.bd.service; import me.zhengjie.modules.wms.bd.domain.ProductInfo; +import me.zhengjie.modules.wms.bd.request.CreateProductInfoRequest; import me.zhengjie.modules.wms.bd.service.dto.ProductInfoDTO; import me.zhengjie.modules.wms.bd.service.dto.ProductInfoQueryCriteria; //import org.springframework.cache.annotation.CacheConfig; @@ -42,11 +43,11 @@ public interface ProductInfoService { /** * create - * @param resources + * @param createProductInfoRequest * @return */ //@CacheEvict(allEntries = true) - ProductInfoDTO create(ProductInfo resources); + ProductInfoDTO create(CreateProductInfoRequest createProductInfoRequest); /** * update diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/dto/ProductInfoDTO.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/dto/ProductInfoDTO.java index 2ce68fec..5ebca459 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/dto/ProductInfoDTO.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/dto/ProductInfoDTO.java @@ -39,16 +39,6 @@ public class ProductInfoDTO implements Serializable { // 产品单价(保留两位小数) 单位:元 private long unitPrice; - // 产品库存预警[{“sort”:1,”ware_house_code”:””,”ware_house_name”:””,”minimum_inventory”:””,”highest_inventory”:””}] - private String productInventoryWarning; - - // 产品期初设置 -// [{“sort”:””,”ware_house_code”:””,”ware_house_name”:””,”ware_house_type_code”:””,“ ware_house_type_name”:””, -// “material_code”:””,“material_name”:””,“specifications”:””,“unit_price”:””, -// “total_price”:””,”minimum_inventory”:””,”highest_inventory”:”” -// }] - private String productInitialSetup; - // 创建时间 private Timestamp createTime; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/dto/ProductInfoDetailDTO.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/dto/ProductInfoDetailDTO.java new file mode 100644 index 00000000..3907fd7a --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/dto/ProductInfoDetailDTO.java @@ -0,0 +1,24 @@ +package me.zhengjie.modules.wms.bd.service.dto; + +import lombok.Data; +import me.zhengjie.modules.wms.bd.request.ProductInitialSetup; +import me.zhengjie.modules.wms.bd.request.ProductInventoryWarning; +import me.zhengjie.modules.wms.bd.request.SupplierAddress; +import me.zhengjie.modules.wms.bd.request.SupplierContact; + +import java.io.Serializable; +import java.util.List; + + +/** +* @author jie +* @date 2019-08-03 +*/ +@Data +public class ProductInfoDetailDTO extends ProductInfoDTO implements Serializable { + + private List productInventoryWarningList; + + private List productInitialSetupList; + +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/impl/ProductInfoServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/impl/ProductInfoServiceImpl.java index e7f35b7a..a4e5e84d 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/impl/ProductInfoServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/service/impl/ProductInfoServiceImpl.java @@ -1,14 +1,17 @@ package me.zhengjie.modules.wms.bd.service.impl; +import com.google.gson.Gson; import me.zhengjie.exception.BadRequestException; -import me.zhengjie.modules.wms.bd.domain.MaterialInfo; -import me.zhengjie.modules.wms.bd.domain.ProductInfo; +import me.zhengjie.modules.wms.bd.domain.*; +import me.zhengjie.modules.wms.bd.repository.MeasureUnitRepository; +import me.zhengjie.modules.wms.bd.repository.ProductCategoryRepository; +import me.zhengjie.modules.wms.bd.request.*; +import me.zhengjie.modules.wms.bd.service.dto.*; import me.zhengjie.utils.ValidationUtil; import me.zhengjie.modules.wms.bd.repository.ProductInfoRepository; import me.zhengjie.modules.wms.bd.service.ProductInfoService; -import me.zhengjie.modules.wms.bd.service.dto.ProductInfoDTO; -import me.zhengjie.modules.wms.bd.service.dto.ProductInfoQueryCriteria; import me.zhengjie.modules.wms.bd.service.mapper.ProductInfoMapper; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; @@ -43,6 +46,12 @@ public class ProductInfoServiceImpl implements ProductInfoService { @Autowired private ProductInfoMapper productInfoMapper; + @Autowired + private MeasureUnitRepository measureUnitRepository; + + @Autowired + private ProductCategoryRepository productCategoryRepository; + @Override public Object queryAll(ProductInfoQueryCriteria criteria, Pageable pageable){ Specification specification = new Specification() { @@ -97,11 +106,57 @@ public class ProductInfoServiceImpl implements ProductInfoService { @Override @Transactional(rollbackFor = Exception.class) - public ProductInfoDTO create(ProductInfo resources) { - productInfoRepository.save(resources); - return productInfoMapper.toDto(productInfoRepository.save(resources)); + public ProductInfoDTO create(CreateProductInfoRequest createProductInfoRequest) { + Long measureUnitId = createProductInfoRequest.getMeasureUnitId(); + if(null == measureUnitId){ + throw new BadRequestException("计量单位不能为空!"); + } + Optional measureUnitOptional = measureUnitRepository.findById(measureUnitId); + MeasureUnit measureUnit = measureUnitOptional.get(); + if(null == measureUnit){ + throw new BadRequestException("计量单位不存在!"); + } + + Long productCategoryId = createProductInfoRequest.getProductCategoryId(); + if(null == productCategoryId){ + throw new BadRequestException("产品类别不能为空!"); + } + Optional productCategoryOptional = productCategoryRepository.findById(productCategoryId); + ProductCategory productCategory = productCategoryOptional.get(); + if(null == productCategory){ + throw new BadRequestException("产品类别不存在!"); + } + + + + ProductInfoDetailDTO productInfoDetailDTO = new ProductInfoDetailDTO(); + + ProductInfo productInfo = new ProductInfo(); + BeanUtils.copyProperties(createProductInfoRequest, productInfo); + productInfo.setStatus(true); + List productInventoryWarningList = createProductInfoRequest.getProductInventoryWarningList(); + if(!CollectionUtils.isEmpty(productInventoryWarningList)){ + String productInventoryWarningStr = new Gson().toJson(productInventoryWarningList); + productInfo.setProductInventoryWarning(productInventoryWarningStr); + productInfoDetailDTO.setProductInventoryWarningList(productInventoryWarningList); + } + List productInitialSetupList = createProductInfoRequest.getProductInitialSetupList(); + if(!CollectionUtils.isEmpty(productInitialSetupList)){ + String productInitialSetupStr = new Gson().toJson(productInitialSetupList); + productInfo.setProductInitialSetup(productInitialSetupStr); + productInfoDetailDTO.setProductInitialSetupList(productInitialSetupList); + } + + productInfo.setProductCategoryName(productCategory.getName()); + productInfo.setMeasureUnitName(measureUnit.getName()); + + productInfo = productInfoRepository.save(productInfo); + ProductInfoDTO productInfoDTO = productInfoMapper.toDto(productInfo); + BeanUtils.copyProperties(productInfoDTO, productInfoDetailDTO); + return productInfoDetailDTO; } + @Override @Transactional(rollbackFor = Exception.class) public void update(ProductInfo resources) {