Skip to content

Commit 787cda3

Browse files
committed
fetch: add shipments and refund export table data api for retail module eairps#245
1 parent 5a538ed commit 787cda3

File tree

5 files changed

+131
-5
lines changed

5 files changed

+131
-5
lines changed

core/api/src/main/java/com/wansenai/api/receipt/RetailController.java

+14
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
import com.wansenai.dto.receipt.retail.RetailRefundDTO;
1919
import com.wansenai.dto.receipt.retail.RetailShipmentsDTO;
2020
import com.wansenai.service.receipt.ReceiptRetailService;
21+
import com.wansenai.utils.excel.ExcelUtils;
2122
import com.wansenai.utils.response.Response;
2223
import com.wansenai.vo.receipt.retail.RetailRefundDetailVO;
2324
import com.wansenai.vo.receipt.retail.RetailRefundVO;
2425
import com.wansenai.vo.receipt.retail.RetailShipmentsDetailVO;
2526
import com.wansenai.vo.receipt.retail.RetailShipmentsVO;
27+
import jakarta.servlet.http.HttpServletResponse;
2628
import org.springframework.web.bind.annotation.*;
2729

2830
import java.util.List;
@@ -101,4 +103,16 @@ public Response<String> refundDeleteByIds(@RequestParam("ids") List<Long> ids) {
101103
public Response<String> refundUpdateStatus(@RequestParam("ids") List<Long> ids, @RequestParam("status") Integer status) {
102104
return receiptRetailService.updateRetailRefundStatus(ids, status);
103105
}
106+
107+
@GetMapping("/shipments/export")
108+
public void exportShipmentsExcel(@ModelAttribute QueryShipmentsDTO queryShipmentsDTO, HttpServletResponse response) throws Exception {
109+
var file = receiptRetailService.exportRetailShipmentsExcel(queryShipmentsDTO, response);
110+
ExcelUtils.downloadExcel(file, "零售出库单", response);
111+
}
112+
113+
@GetMapping("/refund/export")
114+
public void exportRefundExcel(@ModelAttribute QueryRetailRefundDTO queryRetailRefundDTO, HttpServletResponse response) throws Exception {
115+
var file = receiptRetailService.exportRetailRefundExcel(queryRetailRefundDTO, response);
116+
ExcelUtils.downloadExcel(file, "零售退货单", response);
117+
}
104118
}

core/domain/src/main/java/com/wansenai/vo/receipt/retail/RetailRefundVO.java

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.fasterxml.jackson.annotation.JsonFormat;
1616
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
1717
import com.wansenai.bo.BigDecimalSerializerBO;
18+
import com.wansenai.utils.excel.ExcelExport;
1819
import lombok.AllArgsConstructor;
1920
import lombok.Builder;
2021
import lombok.Data;
@@ -32,27 +33,37 @@ public class RetailRefundVO {
3233
@JsonFormat(shape = JsonFormat.Shape.STRING)
3334
private Long id;
3435

36+
@ExcelExport(value = "会员名称")
3537
private String memberName;
3638

39+
@ExcelExport(value = "单据编号")
3740
private String receiptNumber;
3841

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

46+
@ExcelExport(value = "商品信息")
4247
private String productInfo;
4348

49+
@ExcelExport(value = "操作人")
4450
private String operator;
4551

52+
@ExcelExport(value = "商品数量")
4653
private Integer productNumber;
4754

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

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

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

67+
@ExcelExport(value = "状态", kv = "0-未审核;1-已审核")
5768
private Integer status;
5869
}

core/domain/src/main/java/com/wansenai/vo/receipt/retail/RetailShipmentsVO.java

+11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.annotation.JsonFormat;
44
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
55
import com.wansenai.bo.BigDecimalSerializerBO;
6+
import com.wansenai.utils.excel.ExcelExport;
67
import lombok.AllArgsConstructor;
78
import lombok.Builder;
89
import lombok.Data;
@@ -20,27 +21,37 @@ public class RetailShipmentsVO {
2021
@JsonFormat(shape = JsonFormat.Shape.STRING)
2122
private Long id;
2223

24+
@ExcelExport(value = "会员名称")
2325
private String memberName;
2426

27+
@ExcelExport(value = "单据编号")
2528
private String receiptNumber;
2629

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

34+
@ExcelExport(value = "商品信息")
3035
private String productInfo;
3136

37+
@ExcelExport(value = "操作人")
3238
private String operator;
3339

40+
@ExcelExport(value = "商品数量")
3441
private Integer productNumber;
3542

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

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

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

55+
@ExcelExport(value = "状态", kv = "0-未审核;1-已审核")
4556
private Integer status;
4657
}

core/service/src/main/java/com/wansenai/service/receipt/ReceiptRetailService.java

+35
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
2323
import com.wansenai.vo.receipt.ReceiptRetailDetailVO;
2424
import com.wansenai.vo.receipt.retail.*;
25+
import jakarta.servlet.http.HttpServletResponse;
2526

27+
import java.io.File;
28+
import java.io.IOException;
2629
import java.util.List;
2730

2831
public interface ReceiptRetailService extends IService<ReceiptRetailMain> {
@@ -185,4 +188,36 @@ public interface ReceiptRetailService extends IService<ReceiptRetailMain> {
185188
* 返回修改结果
186189
*/
187190
Response<String> updateRetailRefundStatus(List<Long> ids, Integer status);
191+
192+
/**
193+
* Query data through public query criteria and export retail shipments data files
194+
* 根据公共查询条件查询数据并导出零售出库数据文件
195+
*
196+
* @param queryShipmentsDTO Query common conditions
197+
* 查询公共条件
198+
* @param response HttpServletResponse
199+
*
200+
* @return Returns the exported file
201+
* 返回导出的文件
202+
*
203+
* @throws Exception Exception
204+
* 异常
205+
*/
206+
File exportRetailShipmentsExcel(QueryShipmentsDTO queryShipmentsDTO, HttpServletResponse response) throws Exception;
207+
208+
/**
209+
* Query data through public query criteria and export retail refund data files
210+
* 根据公共查询条件查询数据并导出零售退货数据文件
211+
*
212+
* @param queryRetailRefundDTO Query common conditions
213+
* 查询公共条件
214+
* @param response HttpServletResponse
215+
*
216+
* @return Returns the exported file
217+
* 返回导出的文件
218+
*
219+
* @throws Exception Exception
220+
* 异常
221+
*/
222+
File exportRetailRefundExcel(QueryRetailRefundDTO queryRetailRefundDTO, HttpServletResponse response) throws Exception;
188223
}

core/service/src/main/java/com/wansenai/service/receipt/impl/ReceiptRetailServiceImpl.java

+60-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.wansenai.dto.receipt.retail.QueryShipmentsDTO;
2323
import com.wansenai.dto.receipt.retail.RetailRefundDTO;
2424
import com.wansenai.dto.receipt.retail.RetailShipmentsDTO;
25-
import com.wansenai.entities.financial.FinancialAccount;
2625
import com.wansenai.entities.product.ProductStock;
2726
import com.wansenai.entities.product.ProductStockKeepUnit;
2827
import com.wansenai.entities.receipt.ReceiptRetailMain;
@@ -44,14 +43,18 @@
4443
import com.wansenai.utils.constants.ReceiptConstants;
4544
import com.wansenai.utils.enums.BaseCodeEnum;
4645
import com.wansenai.utils.enums.RetailCodeEnum;
46+
import com.wansenai.utils.excel.ExcelUtils;
4747
import com.wansenai.utils.response.Response;
4848
import com.wansenai.vo.receipt.ReceiptRetailDetailVO;
4949
import com.wansenai.vo.receipt.retail.*;
50+
import jakarta.servlet.http.HttpServletResponse;
5051
import lombok.extern.slf4j.Slf4j;
5152
import org.springframework.stereotype.Service;
5253
import org.springframework.transaction.annotation.Transactional;
5354
import org.springframework.util.StringUtils;
5455

56+
import java.io.File;
57+
import java.io.IOException;
5558
import java.math.BigDecimal;
5659
import java.time.LocalDateTime;
5760
import java.util.ArrayList;
@@ -69,8 +72,6 @@ public class ReceiptRetailServiceImpl extends ServiceImpl<ReceiptRetailMainMappe
6972

7073
private final ReceiptRetailSubService receiptRetailSubService;
7174

72-
private final MemberService memberService;
73-
7475
private final IFinancialAccountService accountService;
7576

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

8889

89-
public ReceiptRetailServiceImpl(ReceiptRetailMainMapper receiptRetailMainMapper, ReceiptRetailSubService receiptRetailSubService, MemberService memberService, IFinancialAccountService accountService, ISysUserService userService, SysFileMapper fileMapper, ProductStockMapper productStockMapper, ProductStockKeepUnitMapper productStockKeepUnitMapper, ProductService productService, CommonService commonService) {
90+
public ReceiptRetailServiceImpl(ReceiptRetailMainMapper receiptRetailMainMapper, ReceiptRetailSubService receiptRetailSubService, IFinancialAccountService accountService, ISysUserService userService, SysFileMapper fileMapper, ProductStockMapper productStockMapper, ProductStockKeepUnitMapper productStockKeepUnitMapper, ProductService productService, CommonService commonService) {
9091
this.receiptRetailMainMapper = receiptRetailMainMapper;
9192
this.receiptRetailSubService = receiptRetailSubService;
92-
this.memberService = memberService;
9393
this.accountService = accountService;
9494
this.userService = userService;
9595
this.fileMapper = fileMapper;
@@ -596,6 +596,49 @@ public Response<Page<RetailRefundVO>> getRetailRefund(QueryRetailRefundDTO refun
596596
return Response.responseData(result);
597597
}
598598

599+
private Response<List<RetailRefundVO>> getRetailRefundList(QueryRetailRefundDTO refundDTO) {
600+
List<RetailRefundVO> result = new ArrayList<>();
601+
var retailRefundList = lambdaQuery()
602+
.eq(ReceiptRetailMain::getType, ReceiptConstants.RECEIPT_TYPE_STORAGE)
603+
.in(ReceiptRetailMain::getSubType, ReceiptConstants.RECEIPT_SUB_TYPE_RETAIL_REFUND)
604+
.eq(StringUtils.hasText(refundDTO.getReceiptNumber()), ReceiptRetailMain::getReceiptNumber, refundDTO.getReceiptNumber())
605+
.like(StringUtils.hasText(refundDTO.getRemark()), ReceiptRetailMain::getRemark, refundDTO.getRemark())
606+
.eq(refundDTO.getMemberId() != null, ReceiptRetailMain::getMemberId, refundDTO.getMemberId())
607+
.eq(refundDTO.getAccountId() != null, ReceiptRetailMain::getAccountId, refundDTO.getAccountId())
608+
.eq(refundDTO.getOperatorId() != null, ReceiptRetailMain::getCreateBy, refundDTO.getOperatorId())
609+
.eq(refundDTO.getStatus() != null, ReceiptRetailMain::getStatus, refundDTO.getStatus())
610+
.eq(ReceiptRetailMain::getDeleteFlag, CommonConstants.NOT_DELETED)
611+
.ge(StringUtils.hasText(refundDTO.getStartDate()), ReceiptRetailMain::getCreateTime, refundDTO.getStartDate())
612+
.le(StringUtils.hasText(refundDTO.getEndDate()), ReceiptRetailMain::getCreateTime, refundDTO.getEndDate())
613+
.list();
614+
615+
retailRefundList.forEach(item -> {
616+
var receiptSubList = receiptRetailSubService.lambdaQuery()
617+
.eq(ReceiptRetailSub::getReceiptMainId, item.getId())
618+
.list();
619+
var productNumber = calculateProductNumber(receiptSubList);
620+
var memberName = commonService.getMemberName(item.getMemberId());
621+
var crateBy = getUserName(item.getCreateBy());
622+
623+
var retailRefundVO = RetailRefundVO.builder()
624+
.id(item.getId())
625+
.memberName(memberName)
626+
.receiptNumber(item.getReceiptNumber())
627+
.receiptDate(item.getReceiptDate())
628+
.productInfo(item.getRemark())
629+
.operator(crateBy)
630+
.productNumber(productNumber)
631+
.totalPrice(item.getTotalAmount())
632+
.paymentAmount(item.getChangeAmount())
633+
.backAmount(item.getBackAmount())
634+
.status(item.getStatus())
635+
.build();
636+
result.add(retailRefundVO);
637+
});
638+
639+
return Response.responseData(result);
640+
}
641+
599642
@Override
600643
@Transactional
601644
public Response<String> addOrUpdateRetailRefund(RetailRefundDTO refundDTO) {
@@ -841,4 +884,16 @@ public Response<String> updateRetailRefundStatus(List<Long> ids, Integer status)
841884
return updateRetailStatus(ids, status, RetailCodeEnum.UPDATE_RETAIL_REFUND_SUCCESS, RetailCodeEnum.UPDATE_RETAIL_REFUND_ERROR);
842885
}
843886

887+
@Override
888+
public File exportRetailShipmentsExcel(QueryShipmentsDTO queryShipmentsDTO, HttpServletResponse response) throws Exception {
889+
var data = getRetailShipmentsList(queryShipmentsDTO).getData();
890+
return ExcelUtils.exportFile(ExcelUtils.DEFAULT_FILE_PATH, "销售出库单", data);
891+
}
892+
893+
@Override
894+
public File exportRetailRefundExcel(QueryRetailRefundDTO queryRetailRefundDTO, HttpServletResponse response) throws Exception {
895+
var data = getRetailRefundList(queryRetailRefundDTO).getData();
896+
return ExcelUtils.exportFile(ExcelUtils.DEFAULT_FILE_PATH, "销售退货单", data);
897+
}
898+
844899
}

0 commit comments

Comments
 (0)