From 54a89ef6be90fffbe27743f2bf4840060ffaf9c7 Mon Sep 17 00:00:00 2001 From: starrysky <838252223@qq.com> Date: Mon, 7 Oct 2019 14:00:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=80=97=E6=9D=90=E9=87=87?= =?UTF-8?q?=E8=B4=AD=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...umablesPurchaseOrderProductRepository.java | 17 +++++ .../ConsumablesPurchaseOrderRepository.java | 9 +++ ...onsumablesPurchaseOrderProductRequest.java | 71 +++++++++++++++++++ .../ConsumablesPurchaseOrderController.java | 5 +- .../rest/ProductPurchaseOrderController.java | 7 ++ .../ConsumablesPurchaseOrderService.java | 5 +- .../ConsumablesPurchaseOrderServiceImpl.java | 65 +++++++++++++++-- .../impl/ProductPurchaseOrderServiceImpl.java | 15 +++- 8 files changed, 181 insertions(+), 13 deletions(-) create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/request/ConsumablesPurchaseOrderProductRequest.java diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/repository/ConsumablesPurchaseOrderProductRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/repository/ConsumablesPurchaseOrderProductRepository.java index ddc07495..8f75d57b 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/repository/ConsumablesPurchaseOrderProductRepository.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/repository/ConsumablesPurchaseOrderProductRepository.java @@ -1,12 +1,29 @@ package me.zhengjie.modules.wms.purchase.repository; import me.zhengjie.modules.wms.purchase.domain.ConsumablesPurchaseOrderProduct; +import me.zhengjie.modules.wms.purchase.domain.ProductPurchaseOrderProduct; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; + +import java.util.List; /** * @author jie * @date 2019-10-06 */ public interface ConsumablesPurchaseOrderProductRepository extends JpaRepository, JpaSpecificationExecutor { + + /** + * 查询指定产品采购单下所有的产品信息(状态为true) + * @param consumablesPurchaseOrderId + * @return + */ + @Query(value ="select * from consumables_purchase_order_product where consumables_purchase_order_id = ?1 and status =1", nativeQuery = true) + List queryByConsumablesPurchaseOrderIdAndStatusTrue(Long consumablesPurchaseOrderId); + + @Modifying + @Query(value = "delete product_purchase_order_product where consumables_code = ?1 and consumables_purchase_order_id = ?2", nativeQuery = true) + void deleteByProductCodeAndConsumablesPurchaseOrderId(String consumablesCode, Long consumablesPurchaseOrderId); } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/repository/ConsumablesPurchaseOrderRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/repository/ConsumablesPurchaseOrderRepository.java index 3413f70f..730d4f3d 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/repository/ConsumablesPurchaseOrderRepository.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/repository/ConsumablesPurchaseOrderRepository.java @@ -1,12 +1,21 @@ package me.zhengjie.modules.wms.purchase.repository; import me.zhengjie.modules.wms.purchase.domain.ConsumablesPurchaseOrder; +import me.zhengjie.modules.wms.purchase.domain.ProductPurchaseOrder; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; /** * @author jie * @date 2019-10-06 */ public interface ConsumablesPurchaseOrderRepository extends JpaRepository, JpaSpecificationExecutor { + /** + * 根据耗材采购单单据编号查询耗材采购单单信息 + * @param consumablesPurchaseOrderCode + * @return + */ + @Query(value ="select * from consumables_purchase_order where consumables_purchase_order_code = ?1 and status = 1", nativeQuery = true) + ConsumablesPurchaseOrder findByConsumablesPurchaseOrderCode(String consumablesPurchaseOrderCode); } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/request/ConsumablesPurchaseOrderProductRequest.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/request/ConsumablesPurchaseOrderProductRequest.java new file mode 100644 index 00000000..34989239 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/request/ConsumablesPurchaseOrderProductRequest.java @@ -0,0 +1,71 @@ +package me.zhengjie.modules.wms.purchase.request; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.bean.copier.CopyOptions; +import lombok.Data; + +import javax.persistence.*; +import java.io.Serializable; +import java.sql.Timestamp; + +/** +* @author jie +* @date 2019-10-06 +*/ +@Entity +@Data +@Table(name="consumables_purchase_order_product") +public class ConsumablesPurchaseOrderProductRequest implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private Long id; + + // 所属耗材采购单 + @Column(name = "consumables_purchase_order_id") + private Long consumablesPurchaseOrderId; + + // 耗材主键 + @Column(name = "consumables_id") + private Long consumablesId; + + // 耗材名称 + @Column(name = "consumables_name") + private String consumablesName; + + // 产品单价 + @Column(name = "unit_price") + private Long unitPrice; + + // 产品总价 + @Column(name = "total_price") + private Long totalPrice; + + // 产品数量 + @Column(name = "consumables_number") + private Long consumablesNumber; + + // 备注 + @Column(name = "remark") + private String remark; + + // 创建时间 + @Column(name = "create_time") + private Timestamp createTime; + + // 更新时间 + @Column(name = "update_time") + private Timestamp updateTime; + + @Column(name = "status") + private Boolean status; + + // 耗材编号 + @Column(name = "consumables_code") + private String consumablesCode; + + public void copy(ConsumablesPurchaseOrderProductRequest source){ + BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/rest/ConsumablesPurchaseOrderController.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/rest/ConsumablesPurchaseOrderController.java index 4f79d078..6c621bdd 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/rest/ConsumablesPurchaseOrderController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/rest/ConsumablesPurchaseOrderController.java @@ -4,6 +4,7 @@ import me.zhengjie.aop.log.Log; import me.zhengjie.modules.wms.purchase.domain.ConsumablesPurchaseOrder; import me.zhengjie.modules.wms.purchase.request.AuditConsumablesPurchaseOrderRequest; import me.zhengjie.modules.wms.purchase.request.AuditProductPurchaseOrderRequest; +import me.zhengjie.modules.wms.purchase.request.CreateConsumablesPurchaseOrderRequest; import me.zhengjie.modules.wms.purchase.service.ConsumablesPurchaseOrderService; import me.zhengjie.modules.wms.purchase.service.dto.ConsumablesPurchaseOrderQueryCriteria; import org.springframework.beans.factory.annotation.Autowired; @@ -51,8 +52,8 @@ public class ConsumablesPurchaseOrderController { @ApiOperation(value = "新增耗材采购单") @PostMapping(value = "/consumablesPurchaseOrder") @PreAuthorize("hasAnyRole('ADMIN','CONSUMABLESPURCHASEORDER_ALL','CONSUMABLESPURCHASEORDER_CREATE')") - public ResponseEntity create(@Validated @RequestBody ConsumablesPurchaseOrder resources){ - return new ResponseEntity(consumablesPurchaseOrderService.create(resources),HttpStatus.CREATED); + public ResponseEntity create(@Validated @RequestBody CreateConsumablesPurchaseOrderRequest createConsumablesPurchaseOrderRequest){ + return new ResponseEntity(consumablesPurchaseOrderService.create(createConsumablesPurchaseOrderRequest),HttpStatus.CREATED); } @Log("修改耗材采购单") diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/rest/ProductPurchaseOrderController.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/rest/ProductPurchaseOrderController.java index b94056bb..ba01522d 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/rest/ProductPurchaseOrderController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/rest/ProductPurchaseOrderController.java @@ -82,4 +82,11 @@ public class ProductPurchaseOrderController { String supplierCode = "PP"+ LocalDateTime.now().format(fmt); return new ResponseEntity(supplierCode,HttpStatus.OK); } + + @Log("查看产品采购详情") + @ApiOperation(value = "查看产品采购详情") + @GetMapping(value = "/productPurchaseOrder/{id}") + public ResponseEntity getOutSourceInspectionCertificate(@PathVariable Long id){ + return new ResponseEntity(productPurchaseOrderService.findById(id), HttpStatus.OK); + } } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/service/ConsumablesPurchaseOrderService.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/service/ConsumablesPurchaseOrderService.java index ea54cb31..302069f8 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/service/ConsumablesPurchaseOrderService.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/service/ConsumablesPurchaseOrderService.java @@ -2,6 +2,7 @@ package me.zhengjie.modules.wms.purchase.service; import me.zhengjie.modules.wms.purchase.domain.ConsumablesPurchaseOrder; import me.zhengjie.modules.wms.purchase.request.AuditConsumablesPurchaseOrderRequest; +import me.zhengjie.modules.wms.purchase.request.CreateConsumablesPurchaseOrderRequest; import me.zhengjie.modules.wms.purchase.service.dto.ConsumablesPurchaseOrderDTO; import me.zhengjie.modules.wms.purchase.service.dto.ConsumablesPurchaseOrderQueryCriteria; //import org.springframework.cache.annotation.CacheConfig; @@ -43,11 +44,11 @@ public interface ConsumablesPurchaseOrderService { /** * create - * @param resources + * @param createConsumablesPurchaseOrderRequest * @return */ //@CacheEvict(allEntries = true) - ConsumablesPurchaseOrderDTO create(ConsumablesPurchaseOrder resources); + ConsumablesPurchaseOrderDTO create(CreateConsumablesPurchaseOrderRequest createConsumablesPurchaseOrderRequest); /** * update diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/service/impl/ConsumablesPurchaseOrderServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/service/impl/ConsumablesPurchaseOrderServiceImpl.java index c43fb278..a208eac3 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/service/impl/ConsumablesPurchaseOrderServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/service/impl/ConsumablesPurchaseOrderServiceImpl.java @@ -1,15 +1,19 @@ package me.zhengjie.modules.wms.purchase.service.impl; +import me.zhengjie.exception.BadRequestException; import me.zhengjie.modules.wms.purchase.domain.ConsumablesPurchaseOrder; +import me.zhengjie.modules.wms.purchase.domain.ConsumablesPurchaseOrderProduct; import me.zhengjie.modules.wms.purchase.domain.ProductPurchaseOrder; -import me.zhengjie.modules.wms.purchase.request.AuditConsumablesPurchaseOrderRequest; -import me.zhengjie.modules.wms.purchase.request.AuditProductPurchaseOrderRequest; +import me.zhengjie.modules.wms.purchase.domain.ProductPurchaseOrderProduct; +import me.zhengjie.modules.wms.purchase.repository.ConsumablesPurchaseOrderProductRepository; +import me.zhengjie.modules.wms.purchase.request.*; +import me.zhengjie.modules.wms.purchase.service.dto.*; +import me.zhengjie.modules.wms.purchase.service.mapper.ConsumablesPurchaseOrderProductMapper; import me.zhengjie.utils.ValidationUtil; import me.zhengjie.modules.wms.purchase.repository.ConsumablesPurchaseOrderRepository; import me.zhengjie.modules.wms.purchase.service.ConsumablesPurchaseOrderService; -import me.zhengjie.modules.wms.purchase.service.dto.ConsumablesPurchaseOrderDTO; -import me.zhengjie.modules.wms.purchase.service.dto.ConsumablesPurchaseOrderQueryCriteria; import me.zhengjie.modules.wms.purchase.service.mapper.ConsumablesPurchaseOrderMapper; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; @@ -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; @@ -46,6 +51,12 @@ public class ConsumablesPurchaseOrderServiceImpl implements ConsumablesPurchaseO @Autowired private ConsumablesPurchaseOrderMapper consumablesPurchaseOrderMapper; + @Autowired + private ConsumablesPurchaseOrderProductRepository consumablesPurchaseOrderProductRepository; + + @Autowired + private ConsumablesPurchaseOrderProductMapper consumablesPurchaseOrderProductMapper; + @Override public Object queryAll(ConsumablesPurchaseOrderQueryCriteria criteria, Pageable pageable){ Specification specification = new Specification() { @@ -103,8 +114,50 @@ public class ConsumablesPurchaseOrderServiceImpl implements ConsumablesPurchaseO @Override @Transactional(rollbackFor = Exception.class) - public ConsumablesPurchaseOrderDTO create(ConsumablesPurchaseOrder resources) { - return consumablesPurchaseOrderMapper.toDto(consumablesPurchaseOrderRepository.save(resources)); + public ConsumablesPurchaseOrderDTO create(CreateConsumablesPurchaseOrderRequest createConsumablesPurchaseOrderRequest) { + ConsumablesPurchaseOrder consumablesPurchaseOrder = new ConsumablesPurchaseOrder(); + BeanUtils.copyProperties(createConsumablesPurchaseOrderRequest, consumablesPurchaseOrder); + + String consumablesPurchaseOrderCode = consumablesPurchaseOrder.getConsumablesPurchaseOrderCode(); + if(!StringUtils.hasLength(consumablesPurchaseOrderCode)){ + throw new BadRequestException("耗材采购单单据编号不能为空!"); + } + + consumablesPurchaseOrder.setStatus(true); + // 新增耗材采购单 + consumablesPurchaseOrderRepository.save(consumablesPurchaseOrder); + + consumablesPurchaseOrder = consumablesPurchaseOrderRepository.findByConsumablesPurchaseOrderCode(consumablesPurchaseOrder.getConsumablesPurchaseOrderCode()); + + // 新增产品采购单产品信息 + List consumablesPurchaseOrderProductRequestList = createConsumablesPurchaseOrderRequest.getConsumablesPurchaseOrderProductList(); + if(CollectionUtils.isEmpty(consumablesPurchaseOrderProductRequestList)){ + throw new BadRequestException("耗材采购单产品信息不能为空!"); + } + + for(ConsumablesPurchaseOrderProductRequest consumablesPurchaseOrderProductRequest : consumablesPurchaseOrderProductRequestList){ + ConsumablesPurchaseOrderProduct consumablesPurchaseOrderProduct = new ConsumablesPurchaseOrderProduct(); + BeanUtils.copyProperties(consumablesPurchaseOrderProductRequest, consumablesPurchaseOrderProduct); + consumablesPurchaseOrderProduct.setStatus(true); + consumablesPurchaseOrderProduct.setConsumablesPurchaseOrderId(consumablesPurchaseOrder.getId()); + consumablesPurchaseOrderProductRepository.save(consumablesPurchaseOrderProduct); + } + + + ConsumablesPurchaseOrderDTO consumablesPurchaseOrderDTO = consumablesPurchaseOrderMapper.toDto(consumablesPurchaseOrder); + + List consumablesPurchaseOrderProductList = consumablesPurchaseOrderProductRepository.queryByConsumablesPurchaseOrderIdAndStatusTrue(consumablesPurchaseOrder.getId()); + if(!CollectionUtils.isEmpty(consumablesPurchaseOrderProductList)){ + List consumablesPurchaseOrderProductDTOList = new ArrayList<>(); + for(ConsumablesPurchaseOrderProduct consumablesPurchaseOrderProduct : consumablesPurchaseOrderProductList){ + ConsumablesPurchaseOrderProductDTO consumablesPurchaseOrderProductDTO = new ConsumablesPurchaseOrderProductDTO(); + BeanUtils.copyProperties(consumablesPurchaseOrderProduct, consumablesPurchaseOrderProductDTO); + consumablesPurchaseOrderProductDTOList.add(consumablesPurchaseOrderProductDTO); + } + consumablesPurchaseOrderDTO.setConsumablesPurchaseOrderProductList(consumablesPurchaseOrderProductDTOList); + } + + return consumablesPurchaseOrderDTO; } @Override diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/service/impl/ProductPurchaseOrderServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/service/impl/ProductPurchaseOrderServiceImpl.java index 86ee50c4..cbe1e806 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/service/impl/ProductPurchaseOrderServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/wms/purchase/service/impl/ProductPurchaseOrderServiceImpl.java @@ -114,9 +114,18 @@ public class ProductPurchaseOrderServiceImpl implements ProductPurchaseOrderServ @Override public ProductPurchaseOrderDTO findById(Long id) { - Optional productPurchaseOrder = productPurchaseOrderRepository.findById(id); - ValidationUtil.isNull(productPurchaseOrder,"ProductPurchaseOrder","id",id); - return productPurchaseOrderMapper.toDto(productPurchaseOrder.get()); + + Optional invoiceOptional = productPurchaseOrderRepository.findById(id); + ProductPurchaseOrder productPurchaseOrder = invoiceOptional.get(); + ProductPurchaseOrderDTO productPurchaseOrderDTO = productPurchaseOrderMapper.toDto(productPurchaseOrder); + + + List productPurchaseOrderProductList = productPurchaseOrderProductRepository.queryByProductPurchaseOrderIdAndStatusTrue(id); + if(!CollectionUtils.isEmpty(productPurchaseOrderProductList)){ + List productPurchaseOrderProductDTOList = productPurchaseOrderProductMapper.toDto(productPurchaseOrderProductList); + productPurchaseOrderDTO.setProductPurchaseOrderProductList(productPurchaseOrderProductDTOList); + } + return productPurchaseOrderDTO; } @Override