|
@@ -33,10 +33,9 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
@@ -51,6 +50,7 @@ public class NewRefundManageLogic {
|
|
|
private final MaterialGoodsStockLogic materialGoodsStockLogic;
|
|
|
private final WebsitPartsRefundRecordService websitPartsRefundRecordService;
|
|
|
private final StorageService storageService;
|
|
|
+ private final WebsitPartsWorkerCreditRecordService websitPartsWorkerCreditRecordService;
|
|
|
|
|
|
public IPage<NewRefundManageVO> list(ZfireParamBean zfireParamBean) {
|
|
|
AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
@@ -95,7 +95,7 @@ public class NewRefundManageLogic {
|
|
|
if (flag.equals(PartsOrderFlagEnum.AGREE.toString())) {
|
|
|
// 通过
|
|
|
// this.insertPartsMessageTip(partsNewRefundManage, curDate);
|
|
|
- }else if (flag.equals(PartsOrderFlagEnum.REJECT.toString())) {
|
|
|
+ } else if (flag.equals(PartsOrderFlagEnum.REJECT.toString())) {
|
|
|
// 驳回
|
|
|
List<WebsitPartsNewRefundManageItem> partsNewRefundManageItems = websitPartsNewRefundManageItemService.lambdaQuery()
|
|
|
.eq(WebsitPartsNewRefundManageItem::getApplyNo, partsNewRefundManage.getApplyNo())
|
|
@@ -141,13 +141,33 @@ public class NewRefundManageLogic {
|
|
|
List<WebsitStockDTO> shopStockDTOList = this.createWebsitStockDTO(partsNewRefundManage, partsNewRefundManageItems);
|
|
|
materialGoodsStockLogic.handleWebsitStock(shopStockDTOList);
|
|
|
|
|
|
- //TODO 插入退款记录
|
|
|
+ // 插入退款记录
|
|
|
List<WebsitPartsNewRefundManageRecord> partsNewRefundManageRecords = websitPartsNewRefundManageRecordService.lambdaQuery()
|
|
|
.eq(WebsitPartsNewRefundManageRecord::getApplyNo, partsNewRefundManage.getApplyNo())
|
|
|
.list();
|
|
|
List<WebsitPartsRefundRecord> partsRefundRecordList = this.createRefundRecord(partsNewRefundManage, partsNewRefundManageRecords);
|
|
|
- if(CollectionUtil.isNotEmpty(partsRefundRecordList))
|
|
|
+ if (CollectionUtil.isNotEmpty(partsRefundRecordList)) {
|
|
|
websitPartsRefundRecordService.saveBatch(partsRefundRecordList);
|
|
|
+
|
|
|
+ // 查询是否有记账记录
|
|
|
+ List<WebsitPartsWorkerCreditRecord> recordList = websitPartsWorkerCreditRecordService.lambdaQuery()
|
|
|
+ .eq(WebsitPartsWorkerCreditRecord::getCompanyWechatId, partsNewRefundManage.getCompanyWechatId())
|
|
|
+ .eq(WebsitPartsWorkerCreditRecord::getSalesId, partsNewRefundManage.getSalesId())
|
|
|
+ .in(WebsitPartsWorkerCreditRecord::getSalesItemId, partsNewRefundManageRecords.stream()
|
|
|
+ .map(WebsitPartsNewRefundManageRecord::getSalesItemId)
|
|
|
+ .collect(Collectors.toList()))
|
|
|
+ .list();
|
|
|
+ if (CollectionUtil.isNotEmpty(recordList)) {
|
|
|
+ Map<String, WebsitPartsNewRefundManageRecord> recordMap = partsNewRefundManageRecords.stream()
|
|
|
+ .collect(Collectors.toMap(WebsitPartsNewRefundManageRecord::getSalesItemId, Function.identity()));
|
|
|
+ for (WebsitPartsWorkerCreditRecord creditRecord : recordList) {
|
|
|
+ WebsitPartsNewRefundManageRecord record = recordMap.get(creditRecord.getSalesItemId());
|
|
|
+ creditRecord.setQty(creditRecord.getQty().subtract(record.getQty()));
|
|
|
+ creditRecord.setTotalAmount(creditRecord.getQty().multiply(creditRecord.getSalesPrice()));
|
|
|
+ }
|
|
|
+ websitPartsWorkerCreditRecordService.saveOrUpdateBatch(recordList);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private List<WebsitPartsRefundRecord> createRefundRecord(WebsitPartsNewRefundManage partsNewRefundManage, List<WebsitPartsNewRefundManageRecord> partsNewRefundManageRecords) {
|