mirror of https://github.com/elunez/eladmin
新增产品资料
parent
b27df38006
commit
32b2700a9f
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<ProductInventoryWarning> productInventoryWarningList;
|
||||
|
||||
// 产品期初设置
|
||||
private List<ProductInitialSetup> productInitialSetupList;
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package me.zhengjie.modules.wms.bd.request;
|
||||
|
||||
/**
|
||||
* @author 黄星星
|
||||
* @date 2019-08-21
|
||||
*/
|
||||
public class ProductInventoryWarning {
|
||||
}
|
|
@ -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("分页查询产品类别")
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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<ProductInventoryWarning> productInventoryWarningList;
|
||||
|
||||
private List<ProductInitialSetup> productInitialSetupList;
|
||||
|
||||
}
|
|
@ -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<ProductInfo> specification = new Specification<ProductInfo>() {
|
||||
|
@ -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<MeasureUnit> 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<ProductCategory> 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<ProductInventoryWarning> productInventoryWarningList = createProductInfoRequest.getProductInventoryWarningList();
|
||||
if(!CollectionUtils.isEmpty(productInventoryWarningList)){
|
||||
String productInventoryWarningStr = new Gson().toJson(productInventoryWarningList);
|
||||
productInfo.setProductInventoryWarning(productInventoryWarningStr);
|
||||
productInfoDetailDTO.setProductInventoryWarningList(productInventoryWarningList);
|
||||
}
|
||||
List<ProductInitialSetup> 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) {
|
||||
|
|
Loading…
Reference in New Issue