发货单

pull/451/head
starrysky 2019-08-29 16:34:13 +08:00
parent bc9e4fecf5
commit 3b78ebb4c5
19 changed files with 198 additions and 91 deletions

View File

@ -30,7 +30,7 @@ public class CustomerOrderProduct implements Serializable {
// 产品名称
@Column(name = "product_name")
private Long productName;
private String productName;
// 规格
@Column(name = "specifications")

View File

@ -27,6 +27,6 @@ public interface CustomerOrderRepository extends JpaRepository<CustomerOrder, Lo
* @param customerOrderCode
* @return
*/
@Query(value = "select * from s_customer_order where customerOrderCode = ?1 and status = 1", nativeQuery = true)
@Query(value = "select * from s_customer_order where customer_order_code = ?1 and status = 1", nativeQuery = true)
CustomerOrder findByCustomerOrderCodeAndStatusTrue(String customerOrderCode);
}

View File

@ -16,7 +16,7 @@ public class CustomerOrderProductRequest implements Serializable {
private Long productId;
// 产品名称
private Long productName;
private String productName;
// 规格
private String specifications;

View File

@ -21,7 +21,7 @@ public class CustomerOrderProductDTO {
private Long productId;
// 产品名称
private Long productName;
private String productName;
// 规格
private String specifications;

View File

@ -1,6 +1,9 @@
package me.zhengjie.modules.wms.customerOrder.service.impl;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.wms.bd.domain.CustomerInfo;
import me.zhengjie.modules.wms.bd.repository.CustomerInfoRepository;
import me.zhengjie.modules.wms.bd.service.mapper.CustomerInfoMapper;
import me.zhengjie.modules.wms.customerOrder.domain.CustomerOrderProduct;
import me.zhengjie.modules.wms.customerOrder.repository.CustomerOrderRepository;
import me.zhengjie.modules.wms.customerOrder.request.UpdateCustomerOrderRequest;
@ -54,6 +57,12 @@ public class CustomerOrderServiceImpl implements CustomerOrderService {
@Autowired
private CustomerOrderProductMapper customerOrderProductMapper;
@Autowired
private CustomerInfoMapper customerInfoMapper;
@Autowired
private CustomerInfoRepository customerInfoRepository;
@Override
public Object queryAll(CustomerOrderQueryCriteria criteria, Pageable pageable){
Page<CustomerOrder> page = customerOrderRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
@ -84,19 +93,34 @@ public class CustomerOrderServiceImpl implements CustomerOrderService {
@Override
@Transactional(rollbackFor = Exception.class)
public CustomerOrderDTO create(CreateCustomerOrderRequest createCustomerOrderRequest) {
CustomerOrder customerOrder = new CustomerOrder();
BeanUtils.copyProperties(createCustomerOrderRequest, customerOrder);
customerOrder.setStatus(true);
//插入客户订单
customerOrderRepository.save(customerOrder);
customerOrder= customerOrderRepository.findByCustomerOrderCodeAndStatusTrue(createCustomerOrderRequest.getCustomerOrderCode());
//插入客户订单对应的产品信息
List<CustomerOrderProductRequest> customerOrderProductRequestList = createCustomerOrderRequest.getCustomerOrderProductList();
if(CollectionUtils.isEmpty(customerOrderProductRequestList)){
throw new BadRequestException("订单产品不能为空!");
}
CustomerOrder customerOrder = new CustomerOrder();
BeanUtils.copyProperties(createCustomerOrderRequest, customerOrder);
customerOrder.setStatus(true);
Long customerId = createCustomerOrderRequest.getCustomerId();
if(null == customerId){
throw new BadRequestException("客户不能为空!");
}
Optional<CustomerInfo> customerInfoOptional = customerInfoRepository.findById(customerId);
if(null == customerInfoOptional || null == customerInfoOptional.get()){
throw new BadRequestException("客户不存在!");
}
CustomerInfo customerInfo = customerInfoOptional.get();
customerOrder.setCustomerName(customerInfo.getCustomerName());
//插入客户订单
customerOrderRepository.save(customerOrder);
customerOrder= customerOrderRepository.findByCustomerOrderCodeAndStatusTrue(createCustomerOrderRequest.getCustomerOrderCode());
List<CustomerOrderProduct> customerOrderProductList = new ArrayList<>();
for(CustomerOrderProductRequest customerOrderProductRequest : customerOrderProductRequestList){
CustomerOrderProduct customerOrderProduct = new CustomerOrderProduct();

View File

@ -57,7 +57,7 @@ public class Invoice implements Serializable {
// 状态
@Column(name = "status")
private Integer status;
private Boolean status;
// 备注
@Column(name = "remark")

View File

@ -31,7 +31,7 @@ public class InvoiceProduct implements Serializable {
// 状态
@Column(name = "status")
private Integer status;
private Boolean status;
// 产品主键
@Column(name = "product_id",nullable = false)

View File

@ -3,6 +3,8 @@ package me.zhengjie.modules.wms.invoice.repository;
import me.zhengjie.modules.wms.invoice.domain.InvoiceProduct;
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;
@ -13,4 +15,18 @@ import java.util.List;
public interface InvoiceProductRepository extends JpaRepository<InvoiceProduct, Long>, JpaSpecificationExecutor {
List<InvoiceProduct> findByInvoiceIdAndStatusTrue(Long invoiceId);
@Modifying
@Query(value = "update s_invoice_product set status = 0 where invoice_id = ?1", nativeQuery = true)
void deleteInvoiceProduct(long invoiceId);
/**
* codeid
* @param productCode
* @param invoiceId
*/
@Modifying
@Query(value = "delete s_invoice_product where product_code = ?1 and invoice_id = ?2", nativeQuery = true)
void deleteByProductCodeAndInvoiceId(String productCode, Long invoiceId);
}

View File

@ -3,6 +3,8 @@ package me.zhengjie.modules.wms.invoice.repository;
import me.zhengjie.modules.wms.invoice.domain.Invoice;
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;
/**
* @author jie
@ -11,4 +13,8 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
public interface InvoiceRepository extends JpaRepository<Invoice, Long>, JpaSpecificationExecutor {
Invoice findBySaleInvoiceCode(String saleInvoiceCode);
@Modifying
@Query(value = "update s_invoice set status = 0 where id = ?1", nativeQuery = true)
void deleteInvoice(long invoiceId);
}

View File

@ -0,0 +1,54 @@
package me.zhengjie.modules.wms.invoice.request;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import lombok.Data;
import me.zhengjie.modules.wms.invoice.domain.Invoice;
import me.zhengjie.modules.wms.invoice.domain.InvoiceProduct;
import me.zhengjie.modules.wms.invoice.service.dto.InvoiceProductDTO;
import java.io.Serializable;
import java.util.List;
/**
* @author
* @date 2019-08-27
*/
@Data
public class UpdateInvoiceRequest implements Serializable {
// 主键
private Long id;
// 客户订单编号
private String customerOrderCode;
// 收货地址
private String deliveryAddress;
// 收货人
private String consignee;
// 联系方式
private String contactWay;
// 发票号
private String invoiceNumber;
// 物流公司
private String logisticsCompany;
// 销售发货单号
private String saleInvoiceCode;
// 备注
private String remark;
// 客户ID
private Long customerId;
private List<InvoiceProductDTO> invoiceProductList;
public void copy(Invoice source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}

View File

@ -3,6 +3,7 @@ package me.zhengjie.modules.wms.invoice.rest;
import me.zhengjie.aop.log.Log;
import me.zhengjie.modules.wms.invoice.domain.Invoice;
import me.zhengjie.modules.wms.invoice.request.CreateInvoiceRequest;
import me.zhengjie.modules.wms.invoice.request.UpdateInvoiceRequest;
import me.zhengjie.modules.wms.invoice.service.InvoiceService;
import me.zhengjie.modules.wms.invoice.service.dto.InvoiceQueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
@ -14,6 +15,9 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* @author jie
* @date 2019-08-27
@ -55,8 +59,8 @@ public class InvoiceController {
@ApiOperation(value = "修改销售发货单")
@PutMapping(value = "/invoice")
@PreAuthorize("hasAnyRole('ADMIN','SINVOICE_ALL','SINVOICE_EDIT')")
public ResponseEntity update(@Validated @RequestBody Invoice resources){
invoiceService.update(resources);
public ResponseEntity update(@RequestBody UpdateInvoiceRequest updateInvoiceRequest){
invoiceService.update(updateInvoiceRequest);
return new ResponseEntity(HttpStatus.NO_CONTENT);
}
@ -68,4 +72,12 @@ public class InvoiceController {
invoiceService.delete(id);
return new ResponseEntity(HttpStatus.OK);
}
@Log("初始化发货单编号")
@GetMapping(value = "/initInvoiceCode")
public ResponseEntity initInvoiceCode(){
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");//设置日期格式
String supplierCode = "INVOICE"+ LocalDateTime.now().format(fmt);
return new ResponseEntity(supplierCode,HttpStatus.OK);
}
}

View File

@ -1,61 +0,0 @@
package me.zhengjie.modules.wms.invoice.rest;
import me.zhengjie.aop.log.Log;
import me.zhengjie.modules.wms.invoice.domain.InvoiceProduct;
import me.zhengjie.modules.wms.invoice.service.InvoiceProductService;
import me.zhengjie.modules.wms.invoice.service.dto.InvoiceProductQueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
/**
* @author jie
* @date 2019-08-27
*/
@Api(tags = "SInvoiceProduct管理")
@RestController
@RequestMapping("api")
public class InvoiceProductController {
@Autowired
private InvoiceProductService invoiceProductService;
@Log("查询SInvoiceProduct")
@ApiOperation(value = "查询SInvoiceProduct")
@GetMapping(value = "/sInvoiceProduct")
@PreAuthorize("hasAnyRole('ADMIN','SINVOICEPRODUCT_ALL','SINVOICEPRODUCT_SELECT')")
public ResponseEntity getSInvoiceProducts(InvoiceProductQueryCriteria criteria, Pageable pageable){
return new ResponseEntity(invoiceProductService.queryAll(criteria,pageable),HttpStatus.OK);
}
@Log("新增SInvoiceProduct")
@ApiOperation(value = "新增SInvoiceProduct")
@PostMapping(value = "/sInvoiceProduct")
@PreAuthorize("hasAnyRole('ADMIN','SINVOICEPRODUCT_ALL','SINVOICEPRODUCT_CREATE')")
public ResponseEntity create(@Validated @RequestBody InvoiceProduct resources){
return new ResponseEntity(invoiceProductService.create(resources),HttpStatus.CREATED);
}
@Log("修改SInvoiceProduct")
@ApiOperation(value = "修改SInvoiceProduct")
@PutMapping(value = "/sInvoiceProduct")
@PreAuthorize("hasAnyRole('ADMIN','SINVOICEPRODUCT_ALL','SINVOICEPRODUCT_EDIT')")
public ResponseEntity update(@Validated @RequestBody InvoiceProduct resources){
invoiceProductService.update(resources);
return new ResponseEntity(HttpStatus.NO_CONTENT);
}
@Log("删除SInvoiceProduct")
@ApiOperation(value = "删除SInvoiceProduct")
@DeleteMapping(value = "/sInvoiceProduct/{id}")
@PreAuthorize("hasAnyRole('ADMIN','SINVOICEPRODUCT_ALL','SINVOICEPRODUCT_DELETE')")
public ResponseEntity delete(@PathVariable Long id){
invoiceProductService.delete(id);
return new ResponseEntity(HttpStatus.OK);
}
}

View File

@ -2,6 +2,7 @@ package me.zhengjie.modules.wms.invoice.service;
import me.zhengjie.modules.wms.invoice.domain.Invoice;
import me.zhengjie.modules.wms.invoice.request.CreateInvoiceRequest;
import me.zhengjie.modules.wms.invoice.request.UpdateInvoiceRequest;
import me.zhengjie.modules.wms.invoice.service.dto.InvoiceDTO;
import me.zhengjie.modules.wms.invoice.service.dto.InvoiceDetailDTO;
import me.zhengjie.modules.wms.invoice.service.dto.InvoiceQueryCriteria;
@ -52,10 +53,10 @@ public interface InvoiceService {
/**
* update
* @param resources
* @param updateInvoiceRequest
*/
//@CacheEvict(allEntries = true)
void update(Invoice resources);
void update(UpdateInvoiceRequest updateInvoiceRequest);
/**
* delete

View File

@ -39,7 +39,7 @@ public class InvoiceDTO implements Serializable {
private String saleInvoiceCode;
// 状态
private Integer status;
private Boolean status;
// 备注
private String remark;

View File

@ -21,7 +21,7 @@ public class InvoiceProductDTO implements Serializable {
private Timestamp updateStatus;
// 状态
private Integer status;
private Boolean status;
// 产品主键
private Long productId;

View File

@ -3,10 +3,14 @@ package me.zhengjie.modules.wms.invoice.service.impl;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.wms.bd.domain.CustomerInfo;
import me.zhengjie.modules.wms.bd.repository.CustomerInfoRepository;
import me.zhengjie.modules.wms.customerOrder.domain.CustomerOrder;
import me.zhengjie.modules.wms.customerOrder.domain.CustomerOrderProduct;
import me.zhengjie.modules.wms.customerOrder.service.dto.CustomerOrderProductDTO;
import me.zhengjie.modules.wms.invoice.domain.Invoice;
import me.zhengjie.modules.wms.invoice.domain.InvoiceProduct;
import me.zhengjie.modules.wms.invoice.repository.InvoiceProductRepository;
import me.zhengjie.modules.wms.invoice.request.CreateInvoiceRequest;
import me.zhengjie.modules.wms.invoice.request.UpdateInvoiceRequest;
import me.zhengjie.modules.wms.invoice.service.dto.InvoiceDetailDTO;
import me.zhengjie.modules.wms.invoice.service.dto.InvoiceProductDTO;
import me.zhengjie.modules.wms.invoice.service.mapper.InvoiceProductMapper;
@ -22,8 +26,13 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import me.zhengjie.utils.PageUtil;
@ -141,17 +150,63 @@ public class InvoiceServiceImpl implements InvoiceService {
@Override
@Transactional(rollbackFor = Exception.class)
public void update(Invoice resources) {
Optional<Invoice> optionalSInvoice = invoiceRepository.findById(resources.getId());
ValidationUtil.isNull( optionalSInvoice,"SInvoice","id",resources.getId());
Invoice invoice = optionalSInvoice.get();
invoice.copy(resources);
public void update(UpdateInvoiceRequest updateInvoiceRequest) {
Invoice invoice = new Invoice();
BeanUtils.copyProperties(updateInvoiceRequest, invoice);
// 修改发货单概要信息
invoiceRepository.save(invoice);
// 修改产品信息之前查询该订单中原来的产品信息key为产品code
List<InvoiceProduct> invoiceProductListBeforeUpdate = invoiceProductRepository.findByInvoiceIdAndStatusTrue(invoice.getId());
Map<String, InvoiceProduct> invoiceProductMapBefore = invoiceProductListBeforeUpdate.stream().collect(Collectors.toMap(InvoiceProduct::getProductCode, Function.identity()));
List<InvoiceProductDTO> invoiceProductRequestList = updateInvoiceRequest.getInvoiceProductList();
if(CollectionUtils.isEmpty(invoiceProductRequestList)){
throw new BadRequestException("发货单产品不能为空!");
}
Map<String, InvoiceProductDTO> invoiceProductMapAfter = invoiceProductRequestList.stream().collect(Collectors.toMap(InvoiceProductDTO::getProductCode, Function.identity()));
//需要将订单中原来订单对应的产品删除了的数据
List<String> deleteTargetList = new ArrayList<>();
//比较量个map中key不一样的数据
for(Map.Entry<String, InvoiceProduct> entry:invoiceProductMapBefore.entrySet()){
String productCode = entry.getKey();
//修改后的map记录对应的key在原来中是否存在
InvoiceProductDTO invoiceProductDTOTemp = invoiceProductMapAfter.get(productCode);
if(null == invoiceProductDTOTemp){
deleteTargetList.add(entry.getKey());
}
}
List<InvoiceProduct> invoiceProductList = new ArrayList<>();
for(InvoiceProductDTO invoiceProductDTO : invoiceProductRequestList){
InvoiceProduct invoiceProduct = new InvoiceProduct();
BeanUtils.copyProperties(invoiceProductDTO, invoiceProduct);
invoiceProduct.setInvoiceId(invoice.getId());
invoiceProduct.setStatus(true);
}
invoiceProductRepository.saveAll(invoiceProductList);
/**
* :
* 1. a b c
* 2. a c
* 3.
*/
if(!CollectionUtils.isEmpty(deleteTargetList)){
for(String prductCode : deleteTargetList){
invoiceProductRepository.deleteByProductCodeAndInvoiceId(prductCode, invoice.getId());
}
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(Long id) {
invoiceRepository.deleteById(id);
invoiceRepository.deleteInvoice(id);
invoiceProductRepository.deleteInvoiceProduct(id);
}
}

View File

@ -4,8 +4,8 @@ spring:
druid:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
url: jdbc:log4jdbc:mysql://rm-2ze4a3l502a15dg50qo.mysql.rds.aliyuncs.com:3306/eladmin?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
username: tenjeu
url: jdbc:log4jdbc:mysql://47.103.159.227:3306/eladmin?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
username: root
password: starrysky622209Qwe!

View File

@ -4,8 +4,8 @@ spring:
druid:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
url: jdbc:log4jdbc:mysql://rm-2ze4a3l502a15dg50qo.mysql.rds.aliyuncs.com:3306/eladmin?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
username: tenjeu
url: jdbc:log4jdbc:mysql://47.103.159.227:3306/eladmin?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
username: root
password: starrysky622209Qwe!
# 初始化配置

View File

@ -3,7 +3,7 @@ server:
spring:
profiles:
active: dev
active: prod
jackson:
time-zone: GMT+8
data: