From 7dc3d76ececcb3ddcb79256a048cd9ba4fa6cd51 Mon Sep 17 00:00:00 2001 From: starrysky <838252223@qq.com> Date: Thu, 22 Aug 2019 10:21:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A7=E5=93=81=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bd/request/UpdateProductInfoRequest.java | 48 ++++++++ .../wms/bd/rest/ProductInfoController.java | 5 +- .../wms/bd/service/ProductInfoService.java | 10 +- .../service/impl/ProductInfoServiceImpl.java | 103 ++++++++++++++++-- 4 files changed, 150 insertions(+), 16 deletions(-) create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/request/UpdateProductInfoRequest.java diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/request/UpdateProductInfoRequest.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/request/UpdateProductInfoRequest.java new file mode 100644 index 00000000..93830afc --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/bd/request/UpdateProductInfoRequest.java @@ -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 productInventoryWarningList; + + // 产品期初设置 + private List productInitialSetupList; + +} 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 b41a3d6b..5271b669 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 @@ -3,6 +3,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.request.UpdateProductInfoRequest; import me.zhengjie.modules.wms.bd.service.ProductInfoService; import me.zhengjie.modules.wms.bd.service.dto.ProductInfoQueryCriteria; import org.springframework.beans.factory.annotation.Autowired; @@ -69,8 +70,8 @@ public class ProductInfoController { @ApiOperation(value = "修改产品资料") @PutMapping(value = "/productInfo") @PreAuthorize("hasAnyRole('ADMIN','BDPRODUCTINFO_ALL','BDPRODUCTINFO_EDIT')") - public ResponseEntity update(@Validated @RequestBody ProductInfo resources){ - productInfoService.update(resources); + public ResponseEntity update(@RequestBody UpdateProductInfoRequest updateProductInfoRequest){ + productInfoService.update(updateProductInfoRequest); return new ResponseEntity(HttpStatus.NO_CONTENT); } 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 6668786b..96529137 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 @@ -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.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.ProductInfoDetailDTO; import me.zhengjie.modules.wms.bd.service.dto.ProductInfoQueryCriteria; //import org.springframework.cache.annotation.CacheConfig; //import org.springframework.cache.annotation.CacheEvict; @@ -39,7 +41,7 @@ public interface ProductInfoService { * @return */ //@Cacheable(key = "#p0") - ProductInfoDTO findById(Long id); + ProductInfoDetailDTO findById(Long id); /** * create @@ -47,14 +49,14 @@ public interface ProductInfoService { * @return */ //@CacheEvict(allEntries = true) - ProductInfoDTO create(CreateProductInfoRequest createProductInfoRequest); + ProductInfoDetailDTO create(CreateProductInfoRequest createProductInfoRequest); /** * update - * @param resources + * @param updateProductInfoRequest */ //@CacheEvict(allEntries = true) - void update(ProductInfo resources); + void update(UpdateProductInfoRequest updateProductInfoRequest); /** * delete 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 a4e5e84d..96e46d99 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,6 +1,7 @@ package me.zhengjie.modules.wms.bd.service.impl; import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import me.zhengjie.exception.BadRequestException; import me.zhengjie.modules.wms.bd.domain.*; 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.Transactional; +import java.sql.Timestamp; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Optional; 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.QueryHelp; import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; @@ -98,15 +103,33 @@ public class ProductInfoServiceImpl implements ProductInfoService { } @Override - public ProductInfoDTO findById(Long id) { - Optional bdProductInfo = productInfoRepository.findById(id); - ValidationUtil.isNull(bdProductInfo,"BdProductInfo","id",id); - return productInfoMapper.toDto(bdProductInfo.get()); + public ProductInfoDetailDTO findById(Long id) { + ProductInfoDetailDTO productInfoDetailDTO = new ProductInfoDetailDTO(); + + Optional 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 productInventoryWarningList = new Gson().fromJson(productInventoryWarningStr,new TypeToken>() {}.getType()); + productInfoDetailDTO.setProductInventoryWarningList(productInventoryWarningList); + } + + + String productInitialSetupStr = productInfo.getProductInitialSetup(); + if(StringUtils.hasLength(productInitialSetupStr)){ + List productInitialSetupList = new Gson().fromJson(productInitialSetupStr,new TypeToken>() {}.getType()); + productInfoDetailDTO.setProductInitialSetupList(productInitialSetupList); + } + } + return productInfoDetailDTO; } @Override @Transactional(rollbackFor = Exception.class) - public ProductInfoDTO create(CreateProductInfoRequest createProductInfoRequest) { + public ProductInfoDetailDTO create(CreateProductInfoRequest createProductInfoRequest) { Long measureUnitId = createProductInfoRequest.getMeasureUnitId(); if(null == measureUnitId){ throw new BadRequestException("计量单位不能为空!"); @@ -159,11 +182,71 @@ public class ProductInfoServiceImpl implements ProductInfoService { @Override @Transactional(rollbackFor = Exception.class) - public void update(ProductInfo resources) { - Optional optionalBdProductInfo = productInfoRepository.findById(resources.getId()); - ValidationUtil.isNull( optionalBdProductInfo,"productInfo","id",resources.getId()); - ProductInfo productInfo = optionalBdProductInfo.get(); - productInfo.copy(resources); + public void update(UpdateProductInfoRequest updateProductInfoRequest) { + Long productInfoId = updateProductInfoRequest.getId(); + if(null == productInfoId){ + throw new BadRequestException("产品信息主键不能为空!"); + } + + Long measureUnitId = updateProductInfoRequest.getMeasureUnitId(); + if(null == measureUnitId){ + throw new BadRequestException("计量单位不能为空!"); + } + Optional 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 productCategoryOptional = productCategoryRepository.findById(productCategoryId); + ProductCategory productCategory = productCategoryOptional.get(); + if(null == productCategory){ + throw new BadRequestException("产品类别不存在!"); + } + + + + // 产品资料-仓库预警修改目标 + List productInventoryWarningListTarget = updateProductInfoRequest.getProductInventoryWarningList(); + // 产品资料-期初设置修改目标 + List 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); }