mirror of https://github.com/elunez/eladmin
产品信息
parent
32b2700a9f
commit
7dc3d76ece
|
@ -0,0 +1,48 @@
|
||||||
|
package me.zhengjie.modules.wms.bd.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author 黄星星
|
||||||
|
* @date 2019-08-21
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UpdateProductInfoRequest implements Serializable {
|
||||||
|
// 产品信息主键
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
// 所属产品分类
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package me.zhengjie.modules.wms.bd.rest;
|
||||||
import me.zhengjie.aop.log.Log;
|
import me.zhengjie.aop.log.Log;
|
||||||
import me.zhengjie.modules.wms.bd.domain.ProductInfo;
|
import me.zhengjie.modules.wms.bd.domain.ProductInfo;
|
||||||
import me.zhengjie.modules.wms.bd.request.CreateProductInfoRequest;
|
import me.zhengjie.modules.wms.bd.request.CreateProductInfoRequest;
|
||||||
|
import me.zhengjie.modules.wms.bd.request.UpdateProductInfoRequest;
|
||||||
import me.zhengjie.modules.wms.bd.service.ProductInfoService;
|
import me.zhengjie.modules.wms.bd.service.ProductInfoService;
|
||||||
import me.zhengjie.modules.wms.bd.service.dto.ProductInfoQueryCriteria;
|
import me.zhengjie.modules.wms.bd.service.dto.ProductInfoQueryCriteria;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -69,8 +70,8 @@ public class ProductInfoController {
|
||||||
@ApiOperation(value = "修改产品资料")
|
@ApiOperation(value = "修改产品资料")
|
||||||
@PutMapping(value = "/productInfo")
|
@PutMapping(value = "/productInfo")
|
||||||
@PreAuthorize("hasAnyRole('ADMIN','BDPRODUCTINFO_ALL','BDPRODUCTINFO_EDIT')")
|
@PreAuthorize("hasAnyRole('ADMIN','BDPRODUCTINFO_ALL','BDPRODUCTINFO_EDIT')")
|
||||||
public ResponseEntity update(@Validated @RequestBody ProductInfo resources){
|
public ResponseEntity update(@RequestBody UpdateProductInfoRequest updateProductInfoRequest){
|
||||||
productInfoService.update(resources);
|
productInfoService.update(updateProductInfoRequest);
|
||||||
return new ResponseEntity(HttpStatus.NO_CONTENT);
|
return new ResponseEntity(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,9 @@ package me.zhengjie.modules.wms.bd.service;
|
||||||
|
|
||||||
import me.zhengjie.modules.wms.bd.domain.ProductInfo;
|
import me.zhengjie.modules.wms.bd.domain.ProductInfo;
|
||||||
import me.zhengjie.modules.wms.bd.request.CreateProductInfoRequest;
|
import me.zhengjie.modules.wms.bd.request.CreateProductInfoRequest;
|
||||||
|
import me.zhengjie.modules.wms.bd.request.UpdateProductInfoRequest;
|
||||||
import me.zhengjie.modules.wms.bd.service.dto.ProductInfoDTO;
|
import me.zhengjie.modules.wms.bd.service.dto.ProductInfoDTO;
|
||||||
|
import me.zhengjie.modules.wms.bd.service.dto.ProductInfoDetailDTO;
|
||||||
import me.zhengjie.modules.wms.bd.service.dto.ProductInfoQueryCriteria;
|
import me.zhengjie.modules.wms.bd.service.dto.ProductInfoQueryCriteria;
|
||||||
//import org.springframework.cache.annotation.CacheConfig;
|
//import org.springframework.cache.annotation.CacheConfig;
|
||||||
//import org.springframework.cache.annotation.CacheEvict;
|
//import org.springframework.cache.annotation.CacheEvict;
|
||||||
|
@ -39,7 +41,7 @@ public interface ProductInfoService {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
//@Cacheable(key = "#p0")
|
//@Cacheable(key = "#p0")
|
||||||
ProductInfoDTO findById(Long id);
|
ProductInfoDetailDTO findById(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create
|
* create
|
||||||
|
@ -47,14 +49,14 @@ public interface ProductInfoService {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
//@CacheEvict(allEntries = true)
|
//@CacheEvict(allEntries = true)
|
||||||
ProductInfoDTO create(CreateProductInfoRequest createProductInfoRequest);
|
ProductInfoDetailDTO create(CreateProductInfoRequest createProductInfoRequest);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update
|
* update
|
||||||
* @param resources
|
* @param updateProductInfoRequest
|
||||||
*/
|
*/
|
||||||
//@CacheEvict(allEntries = true)
|
//@CacheEvict(allEntries = true)
|
||||||
void update(ProductInfo resources);
|
void update(UpdateProductInfoRequest updateProductInfoRequest);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* delete
|
* delete
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package me.zhengjie.modules.wms.bd.service.impl;
|
package me.zhengjie.modules.wms.bd.service.impl;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
import me.zhengjie.exception.BadRequestException;
|
import me.zhengjie.exception.BadRequestException;
|
||||||
import me.zhengjie.modules.wms.bd.domain.*;
|
import me.zhengjie.modules.wms.bd.domain.*;
|
||||||
import me.zhengjie.modules.wms.bd.repository.MeasureUnitRepository;
|
import me.zhengjie.modules.wms.bd.repository.MeasureUnitRepository;
|
||||||
|
@ -18,7 +19,10 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
|
@ -26,6 +30,7 @@ import org.springframework.data.domain.Pageable;
|
||||||
import me.zhengjie.utils.PageUtil;
|
import me.zhengjie.utils.PageUtil;
|
||||||
import me.zhengjie.utils.QueryHelp;
|
import me.zhengjie.utils.QueryHelp;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
|
@ -98,15 +103,33 @@ public class ProductInfoServiceImpl implements ProductInfoService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProductInfoDTO findById(Long id) {
|
public ProductInfoDetailDTO findById(Long id) {
|
||||||
Optional<ProductInfo> bdProductInfo = productInfoRepository.findById(id);
|
ProductInfoDetailDTO productInfoDetailDTO = new ProductInfoDetailDTO();
|
||||||
ValidationUtil.isNull(bdProductInfo,"BdProductInfo","id",id);
|
|
||||||
return productInfoMapper.toDto(bdProductInfo.get());
|
Optional<ProductInfo> productInfoOptional = productInfoRepository.findById(id);
|
||||||
|
ProductInfo productInfo = productInfoOptional.get();
|
||||||
|
ProductInfoDTO productInfoDTO = productInfoMapper.toDto(productInfo);
|
||||||
|
if(null != productInfoDTO){
|
||||||
|
BeanUtils.copyProperties( productInfoDTO, productInfoDetailDTO);
|
||||||
|
String productInventoryWarningStr = productInfo.getProductInventoryWarning();
|
||||||
|
if(StringUtils.hasLength(productInventoryWarningStr)){
|
||||||
|
List<ProductInventoryWarning> productInventoryWarningList = new Gson().fromJson(productInventoryWarningStr,new TypeToken<ArrayList<ProductInventoryWarning>>() {}.getType());
|
||||||
|
productInfoDetailDTO.setProductInventoryWarningList(productInventoryWarningList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String productInitialSetupStr = productInfo.getProductInitialSetup();
|
||||||
|
if(StringUtils.hasLength(productInitialSetupStr)){
|
||||||
|
List<ProductInitialSetup> productInitialSetupList = new Gson().fromJson(productInitialSetupStr,new TypeToken<ArrayList<SupplierContact>>() {}.getType());
|
||||||
|
productInfoDetailDTO.setProductInitialSetupList(productInitialSetupList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return productInfoDetailDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public ProductInfoDTO create(CreateProductInfoRequest createProductInfoRequest) {
|
public ProductInfoDetailDTO create(CreateProductInfoRequest createProductInfoRequest) {
|
||||||
Long measureUnitId = createProductInfoRequest.getMeasureUnitId();
|
Long measureUnitId = createProductInfoRequest.getMeasureUnitId();
|
||||||
if(null == measureUnitId){
|
if(null == measureUnitId){
|
||||||
throw new BadRequestException("计量单位不能为空!");
|
throw new BadRequestException("计量单位不能为空!");
|
||||||
|
@ -159,11 +182,71 @@ public class ProductInfoServiceImpl implements ProductInfoService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void update(ProductInfo resources) {
|
public void update(UpdateProductInfoRequest updateProductInfoRequest) {
|
||||||
Optional<ProductInfo> optionalBdProductInfo = productInfoRepository.findById(resources.getId());
|
Long productInfoId = updateProductInfoRequest.getId();
|
||||||
ValidationUtil.isNull( optionalBdProductInfo,"productInfo","id",resources.getId());
|
if(null == productInfoId){
|
||||||
ProductInfo productInfo = optionalBdProductInfo.get();
|
throw new BadRequestException("产品信息主键不能为空!");
|
||||||
productInfo.copy(resources);
|
}
|
||||||
|
|
||||||
|
Long measureUnitId = updateProductInfoRequest.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 = updateProductInfoRequest.getProductCategoryId();
|
||||||
|
if(null == productCategoryId){
|
||||||
|
throw new BadRequestException("产品类别不能为空!");
|
||||||
|
}
|
||||||
|
Optional<ProductCategory> productCategoryOptional = productCategoryRepository.findById(productCategoryId);
|
||||||
|
ProductCategory productCategory = productCategoryOptional.get();
|
||||||
|
if(null == productCategory){
|
||||||
|
throw new BadRequestException("产品类别不存在!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 产品资料-仓库预警修改目标
|
||||||
|
List<ProductInventoryWarning> productInventoryWarningListTarget = updateProductInfoRequest.getProductInventoryWarningList();
|
||||||
|
// 产品资料-期初设置修改目标
|
||||||
|
List<ProductInitialSetup> productInitialSetupListTarget = updateProductInfoRequest.getProductInitialSetupList();
|
||||||
|
|
||||||
|
ProductInfo productInfo = productInfoRepository.findByIdAndStatusTrue(productInfoId);
|
||||||
|
|
||||||
|
if(null == productInfo){
|
||||||
|
throw new BadRequestException("产品信息不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
Timestamp createTime = productInfo.getCreateTime();
|
||||||
|
|
||||||
|
// 将需要修改的值复制到数据库对象中
|
||||||
|
BeanUtils.copyProperties(updateProductInfoRequest, productInfo);
|
||||||
|
|
||||||
|
// 判断提前获取的供应商联系地址和联系方式是否是空
|
||||||
|
if(CollectionUtils.isEmpty(productInventoryWarningListTarget)){
|
||||||
|
productInfo.setProductInventoryWarning(null);
|
||||||
|
}else{
|
||||||
|
String productInventoryWarningStr = new Gson().toJson(productInventoryWarningListTarget);
|
||||||
|
productInfo.setProductInventoryWarning(productInventoryWarningStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(CollectionUtils.isEmpty(productInitialSetupListTarget)){
|
||||||
|
productInfo.setProductInitialSetup(null);
|
||||||
|
}else{
|
||||||
|
String productInitialSetupStr = new Gson().toJson(productInitialSetupListTarget);
|
||||||
|
productInfo.setProductInitialSetup(productInitialSetupStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
productInfo.setCreateTime(createTime);
|
||||||
|
productInfo.setStatus(true);
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
productInfo.setUpdateTime(Timestamp.valueOf(sdf.format(new Date())));
|
||||||
|
productInfo.setProductCategoryName(productCategory.getName());
|
||||||
|
// 修改客户资料
|
||||||
productInfoRepository.save(productInfo);
|
productInfoRepository.save(productInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue