22
22
import com .wansenai .dto .receipt .retail .QueryShipmentsDTO ;
23
23
import com .wansenai .dto .receipt .retail .RetailRefundDTO ;
24
24
import com .wansenai .dto .receipt .retail .RetailShipmentsDTO ;
25
- import com .wansenai .entities .financial .FinancialAccount ;
26
25
import com .wansenai .entities .product .ProductStock ;
27
26
import com .wansenai .entities .product .ProductStockKeepUnit ;
28
27
import com .wansenai .entities .receipt .ReceiptRetailMain ;
44
43
import com .wansenai .utils .constants .ReceiptConstants ;
45
44
import com .wansenai .utils .enums .BaseCodeEnum ;
46
45
import com .wansenai .utils .enums .RetailCodeEnum ;
46
+ import com .wansenai .utils .excel .ExcelUtils ;
47
47
import com .wansenai .utils .response .Response ;
48
48
import com .wansenai .vo .receipt .ReceiptRetailDetailVO ;
49
49
import com .wansenai .vo .receipt .retail .*;
50
+ import jakarta .servlet .http .HttpServletResponse ;
50
51
import lombok .extern .slf4j .Slf4j ;
51
52
import org .springframework .stereotype .Service ;
52
53
import org .springframework .transaction .annotation .Transactional ;
53
54
import org .springframework .util .StringUtils ;
54
55
56
+ import java .io .File ;
57
+ import java .io .IOException ;
55
58
import java .math .BigDecimal ;
56
59
import java .time .LocalDateTime ;
57
60
import java .util .ArrayList ;
@@ -69,8 +72,6 @@ public class ReceiptRetailServiceImpl extends ServiceImpl<ReceiptRetailMainMappe
69
72
70
73
private final ReceiptRetailSubService receiptRetailSubService ;
71
74
72
- private final MemberService memberService ;
73
-
74
75
private final IFinancialAccountService accountService ;
75
76
76
77
private final ISysUserService userService ;
@@ -86,10 +87,9 @@ public class ReceiptRetailServiceImpl extends ServiceImpl<ReceiptRetailMainMappe
86
87
private final CommonService commonService ;
87
88
88
89
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 ) {
90
91
this .receiptRetailMainMapper = receiptRetailMainMapper ;
91
92
this .receiptRetailSubService = receiptRetailSubService ;
92
- this .memberService = memberService ;
93
93
this .accountService = accountService ;
94
94
this .userService = userService ;
95
95
this .fileMapper = fileMapper ;
@@ -596,6 +596,49 @@ public Response<Page<RetailRefundVO>> getRetailRefund(QueryRetailRefundDTO refun
596
596
return Response .responseData (result );
597
597
}
598
598
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
+
599
642
@ Override
600
643
@ Transactional
601
644
public Response <String > addOrUpdateRetailRefund (RetailRefundDTO refundDTO ) {
@@ -841,4 +884,16 @@ public Response<String> updateRetailRefundStatus(List<Long> ids, Integer status)
841
884
return updateRetailStatus (ids , status , RetailCodeEnum .UPDATE_RETAIL_REFUND_SUCCESS , RetailCodeEnum .UPDATE_RETAIL_REFUND_ERROR );
842
885
}
843
886
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
+
844
899
}
0 commit comments