mirror of https://github.com/elunez/eladmin
新增耗材采购单
parent
a32eac2321
commit
54a89ef6be
|
@ -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<ConsumablesPurchaseOrderProduct, Long>, 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<ConsumablesPurchaseOrderProduct> 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);
|
||||
}
|
|
@ -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<ConsumablesPurchaseOrder, Long>, 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);
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -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("修改耗材采购单")
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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<ConsumablesPurchaseOrder> specification = new Specification<ConsumablesPurchaseOrder>() {
|
||||
|
@ -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<ConsumablesPurchaseOrderProductRequest> 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<ConsumablesPurchaseOrderProduct> consumablesPurchaseOrderProductList = consumablesPurchaseOrderProductRepository.queryByConsumablesPurchaseOrderIdAndStatusTrue(consumablesPurchaseOrder.getId());
|
||||
if(!CollectionUtils.isEmpty(consumablesPurchaseOrderProductList)){
|
||||
List<ConsumablesPurchaseOrderProductDTO> consumablesPurchaseOrderProductDTOList = new ArrayList<>();
|
||||
for(ConsumablesPurchaseOrderProduct consumablesPurchaseOrderProduct : consumablesPurchaseOrderProductList){
|
||||
ConsumablesPurchaseOrderProductDTO consumablesPurchaseOrderProductDTO = new ConsumablesPurchaseOrderProductDTO();
|
||||
BeanUtils.copyProperties(consumablesPurchaseOrderProduct, consumablesPurchaseOrderProductDTO);
|
||||
consumablesPurchaseOrderProductDTOList.add(consumablesPurchaseOrderProductDTO);
|
||||
}
|
||||
consumablesPurchaseOrderDTO.setConsumablesPurchaseOrderProductList(consumablesPurchaseOrderProductDTOList);
|
||||
}
|
||||
|
||||
return consumablesPurchaseOrderDTO;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -114,9 +114,18 @@ public class ProductPurchaseOrderServiceImpl implements ProductPurchaseOrderServ
|
|||
|
||||
@Override
|
||||
public ProductPurchaseOrderDTO findById(Long id) {
|
||||
Optional<ProductPurchaseOrder> productPurchaseOrder = productPurchaseOrderRepository.findById(id);
|
||||
ValidationUtil.isNull(productPurchaseOrder,"ProductPurchaseOrder","id",id);
|
||||
return productPurchaseOrderMapper.toDto(productPurchaseOrder.get());
|
||||
|
||||
Optional<ProductPurchaseOrder> invoiceOptional = productPurchaseOrderRepository.findById(id);
|
||||
ProductPurchaseOrder productPurchaseOrder = invoiceOptional.get();
|
||||
ProductPurchaseOrderDTO productPurchaseOrderDTO = productPurchaseOrderMapper.toDto(productPurchaseOrder);
|
||||
|
||||
|
||||
List<ProductPurchaseOrderProduct> productPurchaseOrderProductList = productPurchaseOrderProductRepository.queryByProductPurchaseOrderIdAndStatusTrue(id);
|
||||
if(!CollectionUtils.isEmpty(productPurchaseOrderProductList)){
|
||||
List<ProductPurchaseOrderProductDTO> productPurchaseOrderProductDTOList = productPurchaseOrderProductMapper.toDto(productPurchaseOrderProductList);
|
||||
productPurchaseOrderDTO.setProductPurchaseOrderProductList(productPurchaseOrderProductDTOList);
|
||||
}
|
||||
return productPurchaseOrderDTO;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue