Skip to content

Commit

Permalink
Merge pull request #247 from Jzow/master
Browse files Browse the repository at this point in the history
Add shipments and refund export table data api for retail module
  • Loading branch information
wansenai-bot authored Nov 30, 2023
2 parents 094f16e + 4c6586f commit e19ecd6
Show file tree
Hide file tree
Showing 13 changed files with 235 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
import com.wansenai.dto.receipt.retail.RetailRefundDTO;
import com.wansenai.dto.receipt.retail.RetailShipmentsDTO;
import com.wansenai.service.receipt.ReceiptRetailService;
import com.wansenai.utils.excel.ExcelUtils;
import com.wansenai.utils.response.Response;
import com.wansenai.vo.receipt.retail.RetailRefundDetailVO;
import com.wansenai.vo.receipt.retail.RetailRefundVO;
import com.wansenai.vo.receipt.retail.RetailShipmentsDetailVO;
import com.wansenai.vo.receipt.retail.RetailShipmentsVO;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand Down Expand Up @@ -101,4 +103,16 @@ public Response<String> refundDeleteByIds(@RequestParam("ids") List<Long> ids) {
public Response<String> refundUpdateStatus(@RequestParam("ids") List<Long> ids, @RequestParam("status") Integer status) {
return receiptRetailService.updateRetailRefundStatus(ids, status);
}

@GetMapping("/shipments/export")
public void exportShipmentsExcel(@ModelAttribute QueryShipmentsDTO queryShipmentsDTO, HttpServletResponse response) throws Exception {
var file = receiptRetailService.exportRetailShipmentsExcel(queryShipmentsDTO, response);
ExcelUtils.downloadExcel(file, "零售出库单", response);
}

@GetMapping("/refund/export")
public void exportRefundExcel(@ModelAttribute QueryRetailRefundDTO queryRetailRefundDTO, HttpServletResponse response) throws Exception {
var file = receiptRetailService.exportRetailRefundExcel(queryRetailRefundDTO, response);
ExcelUtils.downloadExcel(file, "零售退货单", response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.wansenai.bo.BigDecimalSerializerBO;
import com.wansenai.utils.excel.ExcelExport;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -32,27 +33,37 @@ public class RetailRefundVO {
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long id;

@ExcelExport(value = "会员名称")
private String memberName;

@ExcelExport(value = "单据编号")
private String receiptNumber;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ExcelExport(value = "单据日期")
private LocalDateTime receiptDate;

@ExcelExport(value = "商品信息")
private String productInfo;

@ExcelExport(value = "操作人")
private String operator;

@ExcelExport(value = "商品数量")
private Integer productNumber;

@JsonSerialize(using = BigDecimalSerializerBO.class)
@ExcelExport(value = "金额合计")
private BigDecimal totalPrice;

@JsonSerialize(using = BigDecimalSerializerBO.class)
@ExcelExport(value = "付款金额")
private BigDecimal paymentAmount;

@JsonSerialize(using = BigDecimalSerializerBO.class)
@ExcelExport(value = "找零金额")
private BigDecimal backAmount;

@ExcelExport(value = "状态", kv = "0-未审核;1-已审核")
private Integer status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.wansenai.bo.BigDecimalSerializerBO;
import com.wansenai.utils.excel.ExcelExport;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -20,27 +21,37 @@ public class RetailShipmentsVO {
@JsonFormat(shape = JsonFormat.Shape.STRING)
private Long id;

@ExcelExport(value = "会员名称")
private String memberName;

@ExcelExport(value = "单据编号")
private String receiptNumber;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ExcelExport(value = "单据日期")
private LocalDateTime receiptDate;

@ExcelExport(value = "商品信息")
private String productInfo;

@ExcelExport(value = "操作人")
private String operator;

@ExcelExport(value = "商品数量")
private Integer productNumber;

@JsonSerialize(using = BigDecimalSerializerBO.class)
@ExcelExport(value = "金额合计")
private BigDecimal totalPrice;

@JsonSerialize(using = BigDecimalSerializerBO.class)
@ExcelExport(value = "收款金额")
private BigDecimal collectionAmount;

@JsonSerialize(using = BigDecimalSerializerBO.class)
@ExcelExport(value = "找零金额")
private BigDecimal backAmount;

@ExcelExport(value = "状态", kv = "0-未审核;1-已审核")
private Integer status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wansenai.vo.receipt.ReceiptRetailDetailVO;
import com.wansenai.vo.receipt.retail.*;
import jakarta.servlet.http.HttpServletResponse;

import java.io.File;
import java.io.IOException;
import java.util.List;

public interface ReceiptRetailService extends IService<ReceiptRetailMain> {
Expand Down Expand Up @@ -185,4 +188,36 @@ public interface ReceiptRetailService extends IService<ReceiptRetailMain> {
* 返回修改结果
*/
Response<String> updateRetailRefundStatus(List<Long> ids, Integer status);

/**
* Query data through public query criteria and export retail shipments data files
* 根据公共查询条件查询数据并导出零售出库数据文件
*
* @param queryShipmentsDTO Query common conditions
* 查询公共条件
* @param response HttpServletResponse
*
* @return Returns the exported file
* 返回导出的文件
*
* @throws Exception Exception
* 异常
*/
File exportRetailShipmentsExcel(QueryShipmentsDTO queryShipmentsDTO, HttpServletResponse response) throws Exception;

/**
* Query data through public query criteria and export retail refund data files
* 根据公共查询条件查询数据并导出零售退货数据文件
*
* @param queryRetailRefundDTO Query common conditions
* 查询公共条件
* @param response HttpServletResponse
*
* @return Returns the exported file
* 返回导出的文件
*
* @throws Exception Exception
* 异常
*/
File exportRetailRefundExcel(QueryRetailRefundDTO queryRetailRefundDTO, HttpServletResponse response) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.wansenai.dto.receipt.retail.QueryShipmentsDTO;
import com.wansenai.dto.receipt.retail.RetailRefundDTO;
import com.wansenai.dto.receipt.retail.RetailShipmentsDTO;
import com.wansenai.entities.financial.FinancialAccount;
import com.wansenai.entities.product.ProductStock;
import com.wansenai.entities.product.ProductStockKeepUnit;
import com.wansenai.entities.receipt.ReceiptRetailMain;
Expand All @@ -44,14 +43,18 @@
import com.wansenai.utils.constants.ReceiptConstants;
import com.wansenai.utils.enums.BaseCodeEnum;
import com.wansenai.utils.enums.RetailCodeEnum;
import com.wansenai.utils.excel.ExcelUtils;
import com.wansenai.utils.response.Response;
import com.wansenai.vo.receipt.ReceiptRetailDetailVO;
import com.wansenai.vo.receipt.retail.*;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
Expand All @@ -69,8 +72,6 @@ public class ReceiptRetailServiceImpl extends ServiceImpl<ReceiptRetailMainMappe

private final ReceiptRetailSubService receiptRetailSubService;

private final MemberService memberService;

private final IFinancialAccountService accountService;

private final ISysUserService userService;
Expand All @@ -86,10 +87,9 @@ public class ReceiptRetailServiceImpl extends ServiceImpl<ReceiptRetailMainMappe
private final CommonService commonService;


public ReceiptRetailServiceImpl(ReceiptRetailMainMapper receiptRetailMainMapper, ReceiptRetailSubService receiptRetailSubService, MemberService memberService, IFinancialAccountService accountService, ISysUserService userService, SysFileMapper fileMapper, ProductStockMapper productStockMapper, ProductStockKeepUnitMapper productStockKeepUnitMapper, ProductService productService, CommonService commonService) {
public ReceiptRetailServiceImpl(ReceiptRetailMainMapper receiptRetailMainMapper, ReceiptRetailSubService receiptRetailSubService, IFinancialAccountService accountService, ISysUserService userService, SysFileMapper fileMapper, ProductStockMapper productStockMapper, ProductStockKeepUnitMapper productStockKeepUnitMapper, ProductService productService, CommonService commonService) {
this.receiptRetailMainMapper = receiptRetailMainMapper;
this.receiptRetailSubService = receiptRetailSubService;
this.memberService = memberService;
this.accountService = accountService;
this.userService = userService;
this.fileMapper = fileMapper;
Expand Down Expand Up @@ -596,6 +596,49 @@ public Response<Page<RetailRefundVO>> getRetailRefund(QueryRetailRefundDTO refun
return Response.responseData(result);
}

private Response<List<RetailRefundVO>> getRetailRefundList(QueryRetailRefundDTO refundDTO) {
List<RetailRefundVO> result = new ArrayList<>();
var retailRefundList = lambdaQuery()
.eq(ReceiptRetailMain::getType, ReceiptConstants.RECEIPT_TYPE_STORAGE)
.in(ReceiptRetailMain::getSubType, ReceiptConstants.RECEIPT_SUB_TYPE_RETAIL_REFUND)
.eq(StringUtils.hasText(refundDTO.getReceiptNumber()), ReceiptRetailMain::getReceiptNumber, refundDTO.getReceiptNumber())
.like(StringUtils.hasText(refundDTO.getRemark()), ReceiptRetailMain::getRemark, refundDTO.getRemark())
.eq(refundDTO.getMemberId() != null, ReceiptRetailMain::getMemberId, refundDTO.getMemberId())
.eq(refundDTO.getAccountId() != null, ReceiptRetailMain::getAccountId, refundDTO.getAccountId())
.eq(refundDTO.getOperatorId() != null, ReceiptRetailMain::getCreateBy, refundDTO.getOperatorId())
.eq(refundDTO.getStatus() != null, ReceiptRetailMain::getStatus, refundDTO.getStatus())
.eq(ReceiptRetailMain::getDeleteFlag, CommonConstants.NOT_DELETED)
.ge(StringUtils.hasText(refundDTO.getStartDate()), ReceiptRetailMain::getCreateTime, refundDTO.getStartDate())
.le(StringUtils.hasText(refundDTO.getEndDate()), ReceiptRetailMain::getCreateTime, refundDTO.getEndDate())
.list();

retailRefundList.forEach(item -> {
var receiptSubList = receiptRetailSubService.lambdaQuery()
.eq(ReceiptRetailSub::getReceiptMainId, item.getId())
.list();
var productNumber = calculateProductNumber(receiptSubList);
var memberName = commonService.getMemberName(item.getMemberId());
var crateBy = getUserName(item.getCreateBy());

var retailRefundVO = RetailRefundVO.builder()
.id(item.getId())
.memberName(memberName)
.receiptNumber(item.getReceiptNumber())
.receiptDate(item.getReceiptDate())
.productInfo(item.getRemark())
.operator(crateBy)
.productNumber(productNumber)
.totalPrice(item.getTotalAmount())
.paymentAmount(item.getChangeAmount())
.backAmount(item.getBackAmount())
.status(item.getStatus())
.build();
result.add(retailRefundVO);
});

return Response.responseData(result);
}

@Override
@Transactional
public Response<String> addOrUpdateRetailRefund(RetailRefundDTO refundDTO) {
Expand Down Expand Up @@ -841,4 +884,16 @@ public Response<String> updateRetailRefundStatus(List<Long> ids, Integer status)
return updateRetailStatus(ids, status, RetailCodeEnum.UPDATE_RETAIL_REFUND_SUCCESS, RetailCodeEnum.UPDATE_RETAIL_REFUND_ERROR);
}

@Override
public File exportRetailShipmentsExcel(QueryShipmentsDTO queryShipmentsDTO, HttpServletResponse response) throws Exception {
var data = getRetailShipmentsList(queryShipmentsDTO).getData();
return ExcelUtils.exportFile(ExcelUtils.DEFAULT_FILE_PATH, "销售出库单", data);
}

@Override
public File exportRetailRefundExcel(QueryRetailRefundDTO queryRetailRefundDTO, HttpServletResponse response) throws Exception {
var data = getRetailRefundList(queryRetailRefundDTO).getData();
return ExcelUtils.exportFile(ExcelUtils.DEFAULT_FILE_PATH, "销售退货单", data);
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
* Copyright 2023-2033 WanSen AI Team, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
* with the License. A copy of the License is located at
*
* http://opensource.wansenai.com/apache2.0/
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
* OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package com.wansenai.utils.excel;

import java.lang.annotation.ElementType;
Expand All @@ -7,7 +19,8 @@

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ExcelExport {
public @interface
ExcelExport {

/** 字段名称 */
String value();
Expand All @@ -21,4 +34,6 @@
/** 导出模板示例值(有值的话,直接取该值,不做映射) */
String example() default "";

// 引用自定义序列化器
Class<?> serializer() default Void.class;
}
Loading

0 comments on commit e19ecd6

Please sign in to comment.