|
|
@@ -0,0 +1,202 @@
|
|
|
+package com.gree.mall.manager.logic.supply.funds;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.gree.mall.manager.bean.admin.AdminUserCom;
|
|
|
+import com.gree.mall.manager.bean.supply.funds.ReceiptVO;
|
|
|
+import com.gree.mall.manager.commonmapper.CommonMapper;
|
|
|
+import com.gree.mall.manager.enums.ExamineStatusEnum;
|
|
|
+import com.gree.mall.manager.enums.base.BaseEnum;
|
|
|
+import com.gree.mall.manager.enums.supply.ReceiptBillTypeEnum;
|
|
|
+import com.gree.mall.manager.exception.RemoteServiceException;
|
|
|
+import com.gree.mall.manager.logic.common.CommonLogic;
|
|
|
+import com.gree.mall.manager.plus.entity.AdminCompanyWallet;
|
|
|
+import com.gree.mall.manager.plus.entity.AdminCompanyWechat;
|
|
|
+import com.gree.mall.manager.plus.entity.Receipt;
|
|
|
+import com.gree.mall.manager.plus.entity.Wallet;
|
|
|
+import com.gree.mall.manager.plus.service.AdminCompanyWalletService;
|
|
|
+import com.gree.mall.manager.plus.service.AdminCompanyWechatService;
|
|
|
+import com.gree.mall.manager.plus.service.ReceiptService;
|
|
|
+import com.gree.mall.manager.plus.service.WalletService;
|
|
|
+import com.gree.mall.manager.zfire.bean.ZfireParamBean;
|
|
|
+import com.gree.mall.manager.zfire.util.FieldUtils;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+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.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class ReceiptLogic {
|
|
|
+
|
|
|
+ private final CommonLogic commonLogic;
|
|
|
+ private final CommonMapper commonMapper;
|
|
|
+ private final AdminCompanyWechatService adminCompanyWechatService;
|
|
|
+ private final AdminCompanyWalletService adminCompanyWechatWalletService;
|
|
|
+ private final WalletService walletService;
|
|
|
+ private final ReceiptService receiptService;
|
|
|
+ private final CompanyWalletLogic companyWalletLogic;
|
|
|
+
|
|
|
+ public IPage<ReceiptVO> list(ZfireParamBean zfireParamBean) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ FieldUtils.supplyParam(zfireParamBean, ReceiptVO.class, adminUser);
|
|
|
+
|
|
|
+ return commonMapper.receiptList(new Page(zfireParamBean.getPageNum(), zfireParamBean.getPageSize()), zfireParamBean);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public int importData(List<Object> objects) {
|
|
|
+ //所有商户
|
|
|
+ List<AdminCompanyWechat> adminCompanyWechatList = adminCompanyWechatService.list();
|
|
|
+ Map<String, AdminCompanyWechat> companyWechatMap = adminCompanyWechatList.stream().collect(Collectors.toMap(AdminCompanyWechat::getCorpId, v -> v));
|
|
|
+
|
|
|
+ //查询所有现金钱包
|
|
|
+ List<Wallet> wallets = walletService.list();
|
|
|
+ Map<String, Wallet> walletMap = wallets.stream().collect(Collectors.toMap(Wallet::getCode, v -> v));
|
|
|
+
|
|
|
+ //查询所有商户现金钱包
|
|
|
+ List<AdminCompanyWallet> companyWechatWalletList = adminCompanyWechatWalletService.list();
|
|
|
+ Map<String, AdminCompanyWallet> companyWechatWalletMap = companyWechatWalletList.stream().collect(Collectors.toMap(v -> v.getCompanyWechatId() + v.getWalletId(), v -> v));
|
|
|
+
|
|
|
+ List<Receipt> receiptList = new ArrayList<>();
|
|
|
+
|
|
|
+ int index = 2;
|
|
|
+ for(Object o : objects) {
|
|
|
+ List<Object> row = (List<Object>) o;
|
|
|
+ String billNo = (String) row.get(0);
|
|
|
+ String billType = (String) row.get(1);
|
|
|
+ String companyCode = (String) row.get(2);
|
|
|
+ String walletCode = (String) row.get(3);
|
|
|
+ String amountStr = (String) row.get(4);
|
|
|
+ String realAmountStr = (String) row.get(5);
|
|
|
+ String theTimeStr = (String) row.get(6);
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(billNo) || StringUtils.isEmpty(billType)
|
|
|
+ || StringUtils.isEmpty(companyCode) || StringUtils.isEmpty(walletCode)
|
|
|
+ || StringUtils.isEmpty(amountStr) || StringUtils.isEmpty(realAmountStr)) {
|
|
|
+ throw new RemoteServiceException("第" + index + "行, 检测到单据编号/单据类型/商户编码/钱包编码/应收金额/实收金额 有为空的情况");
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean exists = BaseEnum.keyToEnumOpt(ReceiptBillTypeEnum.class, billType).isPresent(); // false
|
|
|
+
|
|
|
+ if (!exists) {
|
|
|
+ throw new RemoteServiceException("第" + index + "行, 单据类型不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!companyWechatMap.containsKey(companyCode)) {
|
|
|
+ throw new RemoteServiceException("第" + index + "行, 商户编码不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!walletMap.containsKey(walletCode)) {
|
|
|
+ throw new RemoteServiceException("第" + index + "行, 钱包编码不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ final AdminCompanyWechat companyWechat = companyWechatMap.get(companyCode);
|
|
|
+ final Wallet wallet = walletMap.get(walletCode);
|
|
|
+
|
|
|
+ if (!companyWechatWalletMap.containsKey(companyWechat.getCompanyWechatId() + wallet.getId())) {
|
|
|
+ throw new RemoteServiceException("第" + index + "行, 商户与钱包关系不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal amount;
|
|
|
+ try {
|
|
|
+ amount = new BigDecimal(amountStr);
|
|
|
+ if (amount.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ throw new RemoteServiceException("第" + index + "行, 应收金额不能少于0");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RemoteServiceException("第" + index + "行, 应收金额异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal realAmount;
|
|
|
+ try {
|
|
|
+ realAmount = new BigDecimal(realAmountStr);
|
|
|
+ if (realAmount.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ throw new RemoteServiceException("第" + index + "行, 实收金额不能少于等于0");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RemoteServiceException("第" + index + "行, 实收金额异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ Date theTime = null;
|
|
|
+ if (StringUtils.isNotBlank(theTimeStr)) {
|
|
|
+ try {
|
|
|
+ theTime = DateUtil.parseDate(theTimeStr);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RemoteServiceException("第" + index + "行, 业务日期格式不正确, 要求:yyyy-MM-dd");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ final AdminCompanyWallet companyWallet = companyWechatWalletMap.get(companyWechat.getCompanyWechatId() + wallet.getId());
|
|
|
+
|
|
|
+ Receipt receipt = new Receipt();
|
|
|
+ receipt.setBillNo(billNo);
|
|
|
+ receipt.setBillType(billType);
|
|
|
+ receipt.setCompanyWechatId(companyWallet.getCompanyWechatId());
|
|
|
+ receipt.setCompanyName(companyWechat.getCompanyName());
|
|
|
+ receipt.setWalletId(companyWallet.getWalletId());
|
|
|
+ receipt.setAmount(amount);
|
|
|
+ receipt.setRealAmount(realAmount);
|
|
|
+ receipt.setStatus(ExamineStatusEnum.WAIT.getKey());
|
|
|
+ receipt.setTheTime(theTime);
|
|
|
+
|
|
|
+ receiptList.add(receipt);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CollectionUtil.isNotEmpty(receiptList)) {
|
|
|
+ receiptService.saveBatch(receiptList);
|
|
|
+ }
|
|
|
+
|
|
|
+ return receiptList.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void batchExamine(List<String> ids) {
|
|
|
+ final List<Receipt> receiptList = receiptService.lambdaQuery()
|
|
|
+ .eq(Receipt::getStatus, ExamineStatusEnum.WAIT.getKey())
|
|
|
+ .in(Receipt::getId, ids)
|
|
|
+ .list();
|
|
|
+
|
|
|
+ if (CollectionUtil.isEmpty(receiptList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+
|
|
|
+ // 商户分组
|
|
|
+ Map<String, List<Receipt>> companyGroupMap = receiptList.stream()
|
|
|
+ .collect(Collectors.groupingBy(Receipt::getCompanyWechatId));
|
|
|
+
|
|
|
+ for (Map.Entry<String, List<Receipt>> entry : companyGroupMap.entrySet()) {
|
|
|
+ // 开始处理钱包逻辑
|
|
|
+ companyWalletLogic.handleReceiptCompanyWallet(entry.getValue(), adminUser);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void batchFail(List<String> ids) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+ // 批量驳回
|
|
|
+ receiptService.lambdaUpdate()
|
|
|
+ .set(Receipt::getUpdateBy, adminUser.getNickName())
|
|
|
+ .set(Receipt::getUpdateTime, DateUtil.date())
|
|
|
+ .set(Receipt::getStatus, ExamineStatusEnum.FAIL.getKey())
|
|
|
+ .eq(Receipt::getStatus, ExamineStatusEnum.WAIT.getKey())
|
|
|
+ .in(Receipt::getId, ids)
|
|
|
+ .update();
|
|
|
+ }
|
|
|
+}
|