You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

777 lines
36 KiB

5 months ago
3 months ago
3 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
5 months ago
5 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
3 months ago
3 months ago
3 months ago
5 months ago
3 months ago
3 months ago
3 months ago
5 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
5 months ago
  1. package com.example.demo.serviceImpl.cash;
  2. import com.example.demo.Util.LanguageTranslationUtil;
  3. import com.example.demo.Util.SimpleIdGenerator;
  4. import com.example.demo.domain.entity.Admin;
  5. import com.example.demo.Util.BusinessException;
  6. import com.example.demo.Util.GoldTistV2;
  7. import com.example.demo.config.RabbitMQConfig;
  8. import com.example.demo.domain.entity.Market;
  9. import com.example.demo.domain.entity.User;
  10. import com.example.demo.domain.entity.UserGoldRecord;
  11. import com.example.demo.domain.vo.bean.Region;
  12. import com.example.demo.domain.vo.cash.*;
  13. import com.example.demo.domain.vo.coin.Messages;
  14. import com.example.demo.domain.vo.coin.Result;
  15. import com.example.demo.exception.SystemException;
  16. import com.example.demo.mapper.cash.CashCollectionMapper;
  17. import com.example.demo.mapper.cash.CashRefundMapper;
  18. import com.example.demo.mapper.coin.AuditMapper;
  19. import com.example.demo.mapper.coin.MarketMapper;
  20. import com.example.demo.mapper.coin.OperationLogMapper;
  21. import com.example.demo.mapper.coin.RefundMapper;
  22. import com.example.demo.service.cash.RefundService;
  23. import com.github.pagehelper.PageHelper;
  24. import com.github.pagehelper.PageInfo;
  25. import org.springframework.amqp.rabbit.core.RabbitTemplate;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Service;
  28. import org.springframework.web.bind.annotation.RequestHeader;
  29. import com.example.demo.domain.DTO.Currency;
  30. import java.math.BigDecimal;
  31. import java.math.RoundingMode;
  32. import java.time.LocalDate;
  33. import java.util.*;
  34. import java.util.function.Function;
  35. import java.util.stream.Collectors;
  36. import static org.apache.commons.lang3.StringUtils.substring;
  37. /**
  38. * @program: GOLD
  39. * @ClassName CashRefundServiceImpl
  40. * @description:
  41. * @author: huangqizhen
  42. * @create: 202509-28 15:02
  43. * @Version 1.0
  44. **/
  45. @Service
  46. public class CashRefundServiceImpl implements RefundService {
  47. @Autowired
  48. private CashRefundMapper cashRefundMapper;
  49. @Autowired
  50. private RefundMapper refundMapper;
  51. @Autowired
  52. private AuditMapper auditMapper;
  53. @Autowired
  54. private MarketMapper marketMapper;
  55. @Autowired
  56. private RabbitTemplate rabbitTemplate;
  57. @Autowired
  58. private OperationLogMapper operationLogMapper;
  59. @Autowired
  60. private CashCollectionMapper cashCollectionMapper;
  61. @Autowired
  62. private LanguageTranslationUtil languageTranslationUtil;
  63. @Override
  64. public PageInfo<CashRecordDTO> select(Integer pageNum, Integer pageSize, CashRecordDTO cashRecordDTO) {
  65. PageHelper.startPage(pageNum, pageSize); //必须要直接跟mapper
  66. List<CashRecordDTO> list = cashRefundMapper.select(cashRecordDTO);
  67. if (list.isEmpty()) {
  68. return new PageInfo<>(list);
  69. }
  70. // 批量收集ID
  71. Set<Integer> relatedIds = new HashSet<>();
  72. Set<Integer> marketIds = new HashSet<>();
  73. Set<Integer> submitterIds = new HashSet<>();
  74. Set<Integer> auditIds = new HashSet<>();
  75. Set<Integer> executorIds = new HashSet<>();
  76. list.forEach(item -> {
  77. if (item.getRelatedId() != null) relatedIds.add(item.getRelatedId());
  78. if (item.getMarket() != null) marketIds.add(item.getMarket());
  79. if (item.getSubmitterId() != null) submitterIds.add(item.getSubmitterId());
  80. if (item.getAuditId() != null) auditIds.add(item.getAuditId());
  81. if (item.getExecutor() != null) executorIds.add(item.getExecutor());
  82. });
  83. // 批量查询
  84. Map<Integer, CashCollection> cashCollectionMap = cashCollectionMapper.selectBatchIds(relatedIds)
  85. .stream().collect(Collectors.toMap(CashCollection::getId, Function.identity()));
  86. Map<Integer, String> marketNameMap = marketMapper.getMarketByIds(marketIds)
  87. .stream().collect(Collectors.toMap(Market::getId, Market::getName));
  88. Map<Integer, String> submitterNameMap = auditMapper.getNamesByIds(submitterIds)
  89. .stream().collect(Collectors.toMap(Admin::getId, Admin::getAdminName));
  90. Map<Integer, LhlAudit> auditMap = cashRefundMapper.getAuditBatch(auditIds)
  91. .stream().collect(Collectors.toMap(LhlAudit::getId, Function.identity()));
  92. Map<String, String> executorNameMap = auditMapper.getNamesByJwcodes(executorIds)
  93. .stream().collect(Collectors.toMap(Admin::getAccount, Admin::getAdminName));
  94. // 处理数据
  95. list.forEach(item -> {
  96. CashCollection cashCollection = cashCollectionMap.get(item.getRelatedId());
  97. if (cashCollection != null) {
  98. processCashCollection(item, cashCollection);
  99. }
  100. String marketName = marketNameMap.get(item.getMarket());
  101. String submitter = submitterNameMap.get(item.getSubmitterId());
  102. LhlAudit lhlAudit = auditMap.get(item.getAuditId());
  103. String executorName = executorNameMap.get(String.valueOf(item.getExecutor()));
  104. item.setMarketName(marketName != null ? marketName : "");
  105. item.setSubmitter(submitter != null ? submitter : "");
  106. item.setExecutorName(executorName != null ? executorName : "");
  107. if (lhlAudit != null) {
  108. item.setAreaServise(lhlAudit.getAreaServise());
  109. item.setAreaFinance(lhlAudit.getAreaFinance());
  110. item.setAreaCharge(lhlAudit.getAreaCharge());
  111. item.setHeadFinance(lhlAudit.getHeadFinance());
  112. }
  113. });
  114. return new PageInfo<>(list);
  115. }
  116. private void processCashCollection(CashRecordDTO item, CashCollection cashCollection) {
  117. // 设置默认值
  118. Integer freeGold = cashCollection.getFreeGold() != null ? cashCollection.getFreeGold() : 0;
  119. Integer permanentGold = cashCollection.getPermanentGold() != null ? cashCollection.getPermanentGold() : 0;
  120. BigDecimal free = new BigDecimal(freeGold).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
  121. BigDecimal permanent = new BigDecimal(permanentGold).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
  122. item.setGold(permanent);
  123. item.setFree(free);
  124. item.setActivity(cashCollection.getActivity());
  125. item.setPaymentCurrency(cashCollection.getPaymentCurrency());
  126. if (cashCollection.getPaymentCurrency() != null) {
  127. item.setPaymentAmount(cashCollection.getPaymentAmount().divide(new BigDecimal(100), 2, RoundingMode.HALF_UP));
  128. } else item.setPaymentAmount(cashCollection.getPaymentAmount());
  129. item.setReceivedCurrency(cashCollection.getReceivedCurrency());
  130. if (cashCollection.getReceivedCurrency() != null) {
  131. item.setReceivedAmount(cashCollection.getReceivedAmount().divide(new BigDecimal(100), 2, RoundingMode.HALF_UP));
  132. } else item.setReceivedAmount(cashCollection.getReceivedAmount());
  133. item.setPayType(cashCollection.getPayType());
  134. item.setPayTime(cashCollection.getPayTime());
  135. item.setPayBankCode(cashCollection.getBankCode());
  136. item.setPaySubmitter(cashCollection.getSubmitterName());
  137. item.setAudit(cashCollection.getAuditName());
  138. item.setReceivedTime(cashCollection.getReceivedTime());
  139. item.setPayVoucher(cashCollection.getVoucher());
  140. item.setPayRemark(cashCollection.getRemark());
  141. item.setHandlingCharge(cashCollection.getHandlingCharge().divide(new BigDecimal(100), 2, RoundingMode.HALF_UP));
  142. // 处理金币金额
  143. if (item.getPermanentGold() != null) {
  144. item.setPermanentGold(item.getPermanentGold().divide(new BigDecimal(100), 2, RoundingMode.HALF_UP));
  145. }
  146. if (item.getFreeGold() != null) {
  147. item.setFreeGold(item.getFreeGold().divide(new BigDecimal(100), 2, RoundingMode.HALF_UP));
  148. }
  149. }
  150. @Override
  151. public int add(CashRecordRefund cashRecordRefund, @RequestHeader(defaultValue = "zh_CN") String lang) throws Exception {
  152. if (cashRecordRefund.getJwcode() == null) {
  153. throw new Exception("未输入精网号");
  154. }
  155. if (cashRecordRefund.getRefundModel() == null) {
  156. throw new Exception("请填充退款类型");
  157. }
  158. if (cashRecordRefund.getRefundReason() == null) {
  159. throw new Exception("请填写退款理由");
  160. }
  161. if (cashRecordRefund.getHandlingCharge() == null) {
  162. throw new Exception("请先填写手续费");
  163. }
  164. CashRecordDone cashRecordDonetwo = new CashRecordDone();
  165. cashRecordDonetwo.setAreaServise(cashRecordRefund.getAreaServise());
  166. cashRefundMapper.addAudit(cashRecordDonetwo);
  167. cashRecordRefund.setAuditId(cashRecordDonetwo.getId());
  168. cashRecordRefund.setStatus(10);
  169. //生成订单号后半部分
  170. String orderNumber = cashRecordRefund.getOrderCode();
  171. //构建订单信息
  172. cashRecordRefund.setOrderCode("TK" + orderNumber); //订单号
  173. cashRecordRefund.setMarket(String.valueOf(Integer.valueOf(marketMapper.getMarketId(cashRecordRefund.getMarket()))));
  174. cashRefundMapper.insert(cashRecordRefund);
  175. CashRecordDone cashRecordDone1 = new CashRecordDone();
  176. cashRecordDone1.setId(cashRecordRefund.getOriginalOrderId());
  177. cashRecordDone1.setStatus(6);
  178. if (cashRecordDone1.getId() != null || cashRecordDone1.getOrderCode() != null)
  179. cashRefundMapper.updateStatus(cashRecordDone1);
  180. else return Result.error("提交失败").getCode();
  181. // 发送退款创建消息
  182. Messages message = new Messages();
  183. message.setJwcode(cashRecordRefund.getJwcode());
  184. message.setName(cashRecordRefund.getName());
  185. message.setStatus(cashRecordRefund.getStatus());
  186. message.setDesc("的客服退款申请待审核,前往处理");
  187. message.setTitle("现金退款--新增退款");
  188. message.setType(0);
  189. message.setTypeId(cashRecordRefund.getId());
  190. message.setMarket(Integer.valueOf(cashRecordRefund.getMarket()));
  191. String marketName = marketMapper.getMarketNameById(String.valueOf(message.getMarket()));
  192. message.setMarketName(marketName);
  193. message.setQueryId(103);
  194. rabbitTemplate.convertAndSend(RabbitMQConfig.CASH_REFUND_EXCHANGE, "cash.refund.save", message);
  195. return Result.success("提交成功").getCode();
  196. }
  197. @Override
  198. public int update(CashRecordDone cashRecordDone, @RequestHeader(defaultValue = "zh_CN") String lang) throws Exception {
  199. if (cashRecordDone.getJwcode() == null) {
  200. throw new RuntimeException("未输入精网号");
  201. }
  202. if (cashRecordDone.getPaymentAmount() == null) {
  203. throw new RuntimeException("未输入付款金额");
  204. }
  205. if (cashRecordDone.getPaymentCurrency() == null) {
  206. throw new RuntimeException("未输入付款币种");
  207. }
  208. if (cashRecordDone.getRefundModel() == null) {
  209. throw new RuntimeException("请填写退款类型");
  210. }
  211. if (cashRecordDone.getRefundReason() == null) {
  212. throw new RuntimeException("请填写退款理由");
  213. }
  214. if (cashRecordDone.getNewRefundGold() == null) {
  215. cashRecordDone.setNewRefundGold(BigDecimal.valueOf(0));
  216. }
  217. if (cashRecordDone.getNewRefundFree() == null) {
  218. cashRecordDone.setNewRefundFree(BigDecimal.valueOf(0));
  219. }
  220. int result = cashRefundMapper.update(cashRecordDone);
  221. CashRecordDTO cashRecordDTO = cashRefundMapper.selectById(cashRecordDone.getId());
  222. if (result > 0) {
  223. // 发送审核消息
  224. Messages message = new Messages();
  225. message.setJwcode(cashRecordDTO.getJwcode());
  226. message.setName(cashRecordDTO.getName());
  227. message.setStatus(cashRecordDTO.getStatus());
  228. message.setDesc("的退款申请待审核,前往处理");
  229. message.setTitle("现金管理--退款审批");
  230. message.setType(1);
  231. message.setTypeId(cashRecordDTO.getId());
  232. message.setMarket(cashRecordDTO.getMarket());
  233. String marketName = marketMapper.getMarketNameById(String.valueOf(message.getMarket()));
  234. message.setMarketName(marketName);
  235. message.setQueryId(103);
  236. rabbitTemplate.convertAndSend(RabbitMQConfig.CASH_REFUND_EXCHANGE, "cash.refund.save", message);
  237. }
  238. return (result > 0 ? Result.success("提交成功") : Result.error("提交失败")).getCode();
  239. }
  240. @Override
  241. public int withdraw(CashRecordDone cashRecordDone) {
  242. return cashRefundMapper.withdraw(cashRecordDone.getId());
  243. }
  244. @Override
  245. public int review(CashRecordDone cashRecordDone, @RequestHeader(defaultValue = "zh_CN") String lang) throws Exception {
  246. if (cashRecordDone.getStatus() == 12 || cashRecordDone.getStatus() == 22) {
  247. if (cashRecordDone.getOrderCode() == null) {
  248. throw new RuntimeException("未输入订单号");
  249. }
  250. CashRecordDone cashRecordDone1 = new CashRecordDone();
  251. cashRecordDone1.setId(cashRecordDone.getRelatedId());
  252. cashRecordDone1.setOrderCode(cashRecordDone.getOrderCode().substring(2));
  253. cashRecordDone1.setStatus(4);
  254. if (cashRecordDone1.getId() != null || cashRecordDone1.getOrderCode() != null) {
  255. cashRefundMapper.updateStatus(cashRecordDone1);
  256. }
  257. }
  258. cashRefundMapper.updateAudit(cashRecordDone);
  259. int result = cashRefundMapper.review(cashRecordDone);
  260. CashRecordDTO cashRecordDTO = cashRefundMapper.selectById(cashRecordDone.getId());
  261. if (result > 0) {
  262. // 发送审核消息
  263. Messages message = new Messages();
  264. message.setJwcode(cashRecordDTO.getJwcode());
  265. message.setName(cashRecordDTO.getName());
  266. message.setStatus(cashRecordDTO.getStatus());
  267. if (cashRecordDTO.getStatus()==20) {
  268. message.setDesc("的线下退款申请待审批,前往处理");
  269. message.setTitle("现金管理--退款审批(负责人)");
  270. message.setQueryId(107);
  271. } else if (cashRecordDTO.getStatus()==30) {
  272. message.setDesc("的线下退款申请待审核,前往处理");
  273. message.setTitle("现金管理--退款审批(总部财务)");
  274. message.setQueryId(111);
  275. } else {
  276. message.setDesc("的现金退款申请已被驳回,前往查看详情");
  277. message.setTitle("现金管理--退款提交");
  278. message.setQueryId(99);
  279. }
  280. message.setType(1);
  281. message.setTypeId(cashRecordDTO.getId());
  282. message.setMarket(cashRecordDTO.getMarket());
  283. String marketName = marketMapper.getMarketNameById(String.valueOf(message.getMarket()));
  284. message.setMarketName(marketName);
  285. rabbitTemplate.convertAndSend(RabbitMQConfig.CASH_REFUND_EXCHANGE, "cash.refund.save", message);
  286. }
  287. return (result > 0 ? Result.success("提交成功") : Result.error("提交失败")).getCode();
  288. }
  289. @Override
  290. public int executor(CashRecordDone cashRecordDone) throws Exception {
  291. if (cashRecordDone.getRefundVoucher() == null) {
  292. throw new RuntimeException("未输入退款凭证");
  293. }
  294. if (cashRecordDone.getRefundTime() == null) {
  295. throw new RuntimeException("未输入退款时间");
  296. }
  297. if (cashRecordDone.getRefundRemark() == null) {
  298. throw new RuntimeException("未输入退款备注");
  299. }
  300. if (cashRecordDone.getRefundChannels() == null) {
  301. throw new RuntimeException("未输入退款途径");
  302. }
  303. if (cashRecordDone.getRefundCurrency() == null) {
  304. throw new RuntimeException("未输入退款币种");
  305. }
  306. if (cashRecordDone.getRefundAmount() == null) {
  307. throw new RuntimeException("未输入退款金额");
  308. }
  309. int result = cashRefundMapper.executor(cashRecordDone);
  310. return (result > 0 ? Result.success("提交成功") : Result.error("提交失败")).getCode();
  311. }
  312. @Override
  313. public int updateStatus(CashRecordDone cashRecordDone) {
  314. return cashRefundMapper.updateStatus(cashRecordDone);
  315. }
  316. @Override
  317. public int finalreview(CashRecordDone cashRecordDone, @RequestHeader(defaultValue = "zh_CN") String lang) {
  318. if (cashRecordDone.getPermanentGold() == null) {
  319. cashRecordDone.setPermanentGold(0);
  320. }
  321. if (cashRecordDone.getFreeGold() == null) {
  322. cashRecordDone.setFreeGold(0);
  323. }
  324. if (cashRecordDone.getStatus() == 32) {
  325. CashRecordDone cashRecordDone1 = new CashRecordDone();
  326. cashRecordDone1.setOrderCode(cashRecordDone.getOrderCode().substring(2));
  327. cashRecordDone1.setStatus(4);
  328. if (cashRecordDone1.getId() != null || cashRecordDone1.getOrderCode() != null) {
  329. cashRefundMapper.updateStatus(cashRecordDone1);
  330. }
  331. }
  332. if (cashRecordDone.getGoodsName() != null && cashRecordDone.getStatus() == 40 &&
  333. (cashRecordDone.getGoodsName().equals(languageTranslationUtil.translate("金币充值", lang)) ||
  334. cashRecordDone.getGoodsName().contains(languageTranslationUtil.translate("金币充值", lang)))) {
  335. UserGoldRecord userGoldRecord = new UserGoldRecord();
  336. userGoldRecord.setOrderCode(cashRecordDone.getOrderCode());
  337. String orderCode = cashRecordDone.getOrderCode();
  338. if (orderCode != null && orderCode.length() > 4 && orderCode.startsWith("TKXJ")) {
  339. orderCode = "XJCZ" + orderCode.substring(4);
  340. }
  341. userGoldRecord.setType((byte) 2);
  342. userGoldRecord.setIsRefund((byte) 1);
  343. userGoldRecord.setRefundType("金币退款");
  344. if (cashRecordDone.getRefundModel() == 1) {
  345. userGoldRecord.setRefundModel(Byte.valueOf("1"));
  346. } else if (cashRecordDone.getRefundModel() == 0) {
  347. userGoldRecord.setRefundModel(Byte.valueOf("0"));
  348. }
  349. userGoldRecord.setJwcode(cashRecordDone.getJwcode());
  350. userGoldRecord.setSumGold(cashRecordDone.getPermanentGold() + cashRecordDone.getFreeGold());
  351. userGoldRecord.setPermanentGold(cashRecordDone.getPermanentGold());
  352. int currentMonth = LocalDate.now().getMonthValue();
  353. if (currentMonth >= 1 && currentMonth <= 6) {
  354. // 1-6月:设置12月额度,6月保持默认值
  355. userGoldRecord.setFreeJune(0);
  356. userGoldRecord.setFreeDecember(cashRecordDone.getFreeGold());
  357. } else {
  358. // 7-12月:设置6月额度,12月保持默认值
  359. userGoldRecord.setFreeJune(cashRecordDone.getFreeGold());
  360. userGoldRecord.setFreeDecember(0);
  361. }
  362. userGoldRecord.setGoodsName("金币充值");
  363. userGoldRecord.setPayPlatform("金币系统");
  364. userGoldRecord.setRemark(cashRecordDone.getRemark());
  365. userGoldRecord.setAdminId(cashRecordDone.getAdminId());
  366. userGoldRecord.setAuditStatus(1);
  367. userGoldRecord.setTaskGold(0);
  368. userGoldRecord.setCreateTime(new Date());
  369. userGoldRecord.setUpdateTime(new Date());
  370. String auditName = auditMapper.getName(cashRecordDone.getAuditId());
  371. refundMapper.add(userGoldRecord);
  372. cashRefundMapper.updategold(orderCode);
  373. User user = new User();
  374. user.setJwcode(userGoldRecord.getJwcode());
  375. user.setCurrentPermanentGold(BigDecimal.valueOf(-userGoldRecord.getPermanentGold())); //当前永久金币
  376. user.setCurrentFreeJune(BigDecimal.valueOf(-userGoldRecord.getFreeJune())); //当前六月免费金币
  377. user.setCurrentFreeDecember(BigDecimal.valueOf(-userGoldRecord.getFreeDecember())); //当前十二月免费金币
  378. auditMapper.updateUserGold(user);
  379. GoldTistV2.addCoinNew(userGoldRecord.getJwcode().toString(), 58, //退款免费+永久金币-充值
  380. (double) (userGoldRecord.getFreeDecember() + userGoldRecord.getFreeJune() + userGoldRecord.getPermanentGold()) / 100, SimpleIdGenerator.generateId(),
  381. userGoldRecord.getRemark(), (double) userGoldRecord.getPermanentGold() / 100, auditName, "退款金币充值");
  382. }
  383. cashRefundMapper.updateAudit(cashRecordDone);
  384. int result = cashRefundMapper.review(cashRecordDone);
  385. CashRecordDTO cashRecordDTO = cashRefundMapper.selectById(cashRecordDone.getId());
  386. if (result > 0) {
  387. // 发送审核消息
  388. Messages message = new Messages();
  389. message.setJwcode(cashRecordDTO.getJwcode());
  390. message.setName(cashRecordDTO.getName());
  391. message.setStatus(cashRecordDTO.getStatus());
  392. message.setDesc(cashRecordDTO.getStatus() != 32 ? "的退款记录需填写执行明细,前往查看处理" : "的现金退款申请已被驳回,前往查看详情");
  393. message.setTitle(cashRecordDTO.getStatus() != 32 ? "现金管理--执行明细填写":"现金管理--退款提交");
  394. message.setType(1);
  395. message.setTypeId(cashRecordDTO.getId());
  396. message.setMarket(cashRecordDTO.getMarket());
  397. String marketName = marketMapper.getMarketNameById(String.valueOf(message.getMarket()));
  398. message.setMarketName(marketName);
  399. message.setQueryId(cashRecordDTO.getStatus() != 32 ? 115:99);
  400. rabbitTemplate.convertAndSend(RabbitMQConfig.CASH_REFUND_EXCHANGE, "cash.refund.save", message);
  401. }
  402. return (result > 0 ? Result.success("提交成功") : Result.error("提交失败")).getCode();
  403. }
  404. @Override
  405. public PageInfo<CashRecordDTO> financeSelect(Integer pageNum, Integer pageSize, CashRecordDTO cashRecordDTO) {
  406. PageHelper.startPage(pageNum, pageSize); //必须要直接跟mapper
  407. // System.out.println(goldDetail.getMarkets());
  408. List<CashRecordDTO> list = cashRefundMapper.financeSelect(cashRecordDTO);
  409. if (list.isEmpty()) {
  410. return new PageInfo<>(list);
  411. }
  412. // 批量收集ID
  413. Set<Integer> relatedIds = new HashSet<>();
  414. Set<Integer> marketIds = new HashSet<>();
  415. Set<Integer> submitterIds = new HashSet<>();
  416. Set<Integer> auditIds = new HashSet<>();
  417. Set<Integer> executorIds = new HashSet<>();
  418. list.forEach(item -> {
  419. if (item.getRelatedId() != null) relatedIds.add(item.getRelatedId());
  420. if (item.getMarket() != null) marketIds.add(item.getMarket());
  421. if (item.getSubmitterId() != null) submitterIds.add(item.getSubmitterId());
  422. if (item.getAuditId() != null) auditIds.add(item.getAuditId());
  423. if (item.getExecutor() != null) executorIds.add(item.getExecutor());
  424. });
  425. // 批量查询
  426. Map<Integer, CashCollection> cashCollectionMap = cashCollectionMapper.selectBatchIds(relatedIds)
  427. .stream().collect(Collectors.toMap(CashCollection::getId, Function.identity()));
  428. Map<Integer, String> marketNameMap = marketMapper.getMarketByIds(marketIds)
  429. .stream().collect(Collectors.toMap(Market::getId, Market::getName));
  430. Map<Integer, String> submitterNameMap = auditMapper.getNamesByIds(submitterIds)
  431. .stream().collect(Collectors.toMap(Admin::getId, Admin::getAdminName));
  432. Map<Integer, LhlAudit> auditMap = cashRefundMapper.getAuditBatch(auditIds)
  433. .stream().collect(Collectors.toMap(LhlAudit::getId, Function.identity()));
  434. Map<String, String> executorNameMap = auditMapper.getNamesByJwcodes(executorIds)
  435. .stream().collect(Collectors.toMap(Admin::getAccount, Admin::getAdminName));
  436. // 处理数据
  437. list.forEach(item -> {
  438. CashCollection cashCollection = cashCollectionMap.get(item.getRelatedId());
  439. if (cashCollection != null) {
  440. processCashCollection(item, cashCollection);
  441. }
  442. String marketName = marketNameMap.get(item.getMarket());
  443. String submitter = submitterNameMap.get(item.getSubmitterId());
  444. LhlAudit lhlAudit = auditMap.get(item.getAuditId());
  445. String executorName = executorNameMap.get(String.valueOf(item.getExecutor()));
  446. item.setMarketName(marketName != null ? marketName : "");
  447. item.setSubmitter(submitter != null ? submitter : "");
  448. item.setExecutorName(executorName != null ? executorName : "");
  449. if (lhlAudit != null) {
  450. item.setAreaServise(lhlAudit.getAreaServise());
  451. item.setAreaFinance(lhlAudit.getAreaFinance());
  452. item.setAreaCharge(lhlAudit.getAreaCharge());
  453. item.setHeadFinance(lhlAudit.getHeadFinance());
  454. }
  455. });
  456. return new PageInfo<>(list);
  457. }
  458. @Override
  459. public PageInfo<CashRecordDTO> financeSelect2(Integer pageNum, Integer pageSize, CashRecordDTO cashRecordDTO) {
  460. PageHelper.startPage(pageNum, pageSize); //必须要直接跟mapper
  461. // System.out.println(goldDetail.getMarkets());
  462. List<CashRecordDTO> list = cashRefundMapper.financeSelect(cashRecordDTO);
  463. if (list.isEmpty()) {
  464. return new PageInfo<>(list);
  465. }
  466. // 批量收集ID
  467. Set<Integer> relatedIds = new HashSet<>();
  468. Set<Integer> marketIds = new HashSet<>();
  469. Set<Integer> submitterIds = new HashSet<>();
  470. Set<Integer> auditIds = new HashSet<>();
  471. Set<Integer> executorIds = new HashSet<>();
  472. list.forEach(item -> {
  473. if (item.getRelatedId() != null) relatedIds.add(item.getRelatedId());
  474. if (item.getMarket() != null) marketIds.add(item.getMarket());
  475. if (item.getSubmitterId() != null) submitterIds.add(item.getSubmitterId());
  476. if (item.getAuditId() != null) auditIds.add(item.getAuditId());
  477. if (item.getExecutor() != null) executorIds.add(item.getExecutor());
  478. });
  479. // 批量查询
  480. Map<Integer, CashCollection> cashCollectionMap = cashCollectionMapper.selectBatchIds(relatedIds)
  481. .stream().collect(Collectors.toMap(CashCollection::getId, Function.identity()));
  482. Map<Integer, String> marketNameMap = marketMapper.getMarketByIds(marketIds)
  483. .stream().collect(Collectors.toMap(Market::getId, Market::getName));
  484. Map<Integer, String> submitterNameMap = auditMapper.getNamesByIds(submitterIds)
  485. .stream().collect(Collectors.toMap(Admin::getId, Admin::getAdminName));
  486. Map<Integer, LhlAudit> auditMap = cashRefundMapper.getAuditBatch(auditIds)
  487. .stream().collect(Collectors.toMap(LhlAudit::getId, Function.identity()));
  488. Map<String, String> executorNameMap = auditMapper.getNamesByJwcodes(executorIds)
  489. .stream().collect(Collectors.toMap(Admin::getAccount, Admin::getAdminName));
  490. // 处理数据
  491. list.forEach(item -> {
  492. CashCollection cashCollection = cashCollectionMap.get(item.getRelatedId());
  493. if (cashCollection != null) {
  494. processCashCollection(item, cashCollection);
  495. }
  496. String marketName = marketNameMap.get(item.getMarket());
  497. String submitter = submitterNameMap.get(item.getSubmitterId());
  498. LhlAudit lhlAudit = auditMap.get(item.getAuditId());
  499. String executorName = executorNameMap.get(String.valueOf(item.getExecutor()));
  500. item.setMarketName(marketName != null ? marketName : "");
  501. item.setSubmitter(submitter != null ? submitter : "");
  502. item.setExecutorName(executorName != null ? executorName : "");
  503. if (lhlAudit != null) {
  504. item.setAreaServise(lhlAudit.getAreaServise());
  505. item.setAreaFinance(lhlAudit.getAreaFinance());
  506. item.setAreaCharge(lhlAudit.getAreaCharge());
  507. item.setHeadFinance(lhlAudit.getHeadFinance());
  508. }
  509. });
  510. return new PageInfo<>(list);
  511. }
  512. @Override
  513. public PageInfo<CashRecordDTO> exSelect(Integer pageNum, Integer pageSize, CashRecordDTO cashRecordDTO) {
  514. PageHelper.startPage(pageNum, pageSize); //必须要直接跟mapper
  515. // System.out.println(goldDetail.getMarkets());
  516. List<CashRecordDTO> list = cashRefundMapper.exSelect(cashRecordDTO);
  517. System.out.println(list);
  518. if (list.isEmpty()) {
  519. return new PageInfo<>(list);
  520. }
  521. // 批量收集ID
  522. Set<Integer> relatedIds = new HashSet<>();
  523. Set<Integer> marketIds = new HashSet<>();
  524. Set<Integer> submitterIds = new HashSet<>();
  525. Set<Integer> auditIds = new HashSet<>();
  526. Set<Integer> executorIds = new HashSet<>();
  527. list.forEach(item -> {
  528. if (item.getRelatedId() != null) relatedIds.add(item.getRelatedId());
  529. if (item.getMarket() != null) marketIds.add(item.getMarket());
  530. if (item.getSubmitterId() != null) submitterIds.add(item.getSubmitterId());
  531. if (item.getAuditId() != null) auditIds.add(item.getAuditId());
  532. if (item.getExecutor() != null) executorIds.add(item.getExecutor());
  533. });
  534. // 批量查询
  535. Map<Integer, CashCollection> cashCollectionMap = cashCollectionMapper.selectBatchIds(relatedIds)
  536. .stream().collect(Collectors.toMap(CashCollection::getId, Function.identity()));
  537. Map<Integer, String> marketNameMap = marketMapper.getMarketByIds(marketIds)
  538. .stream().collect(Collectors.toMap(Market::getId, Market::getName));
  539. Map<Integer, String> submitterNameMap = auditMapper.getNamesByIds(submitterIds)
  540. .stream().collect(Collectors.toMap(Admin::getId, Admin::getAdminName));
  541. Map<Integer, LhlAudit> auditMap = cashRefundMapper.getAuditBatch(auditIds)
  542. .stream().collect(Collectors.toMap(LhlAudit::getId, Function.identity()));
  543. Map<String, String> executorNameMap = auditMapper.getNamesByJwcodes(executorIds)
  544. .stream().collect(Collectors.toMap(Admin::getAccount, Admin::getAdminName));
  545. // 处理数据
  546. list.forEach(item -> {
  547. CashCollection cashCollection = cashCollectionMap.get(item.getRelatedId());
  548. if (cashCollection != null) {
  549. processCashCollection(item, cashCollection);
  550. }
  551. String marketName = marketNameMap.get(item.getMarket());
  552. String submitter = submitterNameMap.get(item.getSubmitterId());
  553. LhlAudit lhlAudit = auditMap.get(item.getAuditId());
  554. String executorName = executorNameMap.get(String.valueOf(item.getExecutor()));
  555. item.setMarketName(marketName != null ? marketName : "");
  556. item.setSubmitter(submitter != null ? submitter : "");
  557. item.setExecutorName(executorName != null ? executorName : "");
  558. if (lhlAudit != null) {
  559. item.setAreaServise(lhlAudit.getAreaServise());
  560. item.setAreaFinance(lhlAudit.getAreaFinance());
  561. item.setAreaCharge(lhlAudit.getAreaCharge());
  562. item.setHeadFinance(lhlAudit.getHeadFinance());
  563. }
  564. });
  565. return new PageInfo<>(list);
  566. }
  567. @Override
  568. public void addOnline(CashRecordRefund cashRecordRefund) {
  569. if (cashRecordRefund.getJwcode() == null) {
  570. throw new BusinessException("未输入精网号");
  571. }
  572. if (cashRecordRefund.getRefundModel() == null) {
  573. throw new BusinessException("请填充退款类型");
  574. }
  575. if (cashRecordRefund.getRefundReason() == null) {
  576. throw new BusinessException("请填写退款理由");
  577. }
  578. CashRecordDone cashRecordDonetwo = new CashRecordDone();
  579. cashRecordDonetwo.setAreaServise(cashRecordRefund.getAreaServise());
  580. cashRefundMapper.addAudit(cashRecordDonetwo);
  581. cashRecordRefund.setAuditId(cashRecordDonetwo.getId());
  582. cashRecordRefund.setStatus(20);
  583. //生成订单号后半部分
  584. String orderNumber = cashRecordRefund.getOrderCode();
  585. //构建订单信息
  586. cashRecordRefund.setOrderCode("TK" + orderNumber); //订单号
  587. cashRecordRefund.setMarket(String.valueOf(Integer.valueOf(marketMapper.getMarketId(cashRecordRefund.getMarket()))));
  588. cashRefundMapper.insert(cashRecordRefund);
  589. CashRecordDone cashRecordDone1 = new CashRecordDone();
  590. cashRecordDone1.setId(cashRecordRefund.getId());
  591. cashRecordDone1.setStatus(6);
  592. if (cashRecordDone1.getId() != null || cashRecordDone1.getOrderCode() != null)
  593. cashRefundMapper.updateStatus(cashRecordDone1);
  594. else throw new SystemException("提交失败");
  595. }
  596. @Override
  597. public PageInfo<FundsDTO> funds(Integer pageNum, Integer pageSize, FundsDTO fundsDTO) {
  598. // 1. 分页查询主数据
  599. PageHelper.startPage(pageNum, pageSize);
  600. if (fundsDTO.getStatuses() == null || fundsDTO.getStatuses().isEmpty()) {
  601. fundsDTO.setStatuses(Arrays.asList(4, 6));
  602. }
  603. List<FundsDTO> list = cashRefundMapper.selectfunds(fundsDTO);
  604. // 2. 收集 status == 6 的记录 ID
  605. List<Integer> needQueryIds = new ArrayList<>();
  606. for (FundsDTO dto : list) {
  607. if (dto.getStatus() != null && dto.getStatus() == 6) {
  608. needQueryIds.add(dto.getId());
  609. }
  610. }
  611. // 3. 批量查询 refundDetail 信息(用于负数处理)
  612. if (!needQueryIds.isEmpty()) {
  613. List<FundsDTO> detailList = cashRefundMapper.selectRefundCount(needQueryIds);
  614. Map<Integer, FundsDTO> detailMap = new HashMap<>();
  615. for (FundsDTO detail : detailList) {
  616. // 假设 detail.getRelatedId() 对应主表的 id
  617. detailMap.put(detail.getRelatedId(), detail);
  618. }
  619. // 回填 refundAmount(取负)和 refundCurrency
  620. for (FundsDTO dto : list) {
  621. if (dto.getStatus() != null && dto.getStatus() == 6) {
  622. FundsDTO detail = detailMap.get(dto.getId());
  623. if (detail != null) {
  624. BigDecimal amount = detail.getRefundAmount();
  625. if (amount != null) {
  626. dto.setRefundAmount(amount.negate()); // 转为负数
  627. } else {
  628. dto.setRefundAmount(null); // 或设为 BigDecimal.ZERO
  629. }
  630. dto.setRefundCurrency(detail.getRefundCurrency());
  631. }
  632. }
  633. }
  634. }
  635. // 4. 收集所有需要转换的 regionId 和 currencyId
  636. Set<Integer> regionIds = new HashSet<>();
  637. Set<Integer> currencyIds = new HashSet<>();
  638. Set<Integer> reCurrencyIds = new HashSet<>();
  639. for (FundsDTO dto : list) {
  640. if (dto.getMarket() != null) {
  641. regionIds.add(dto.getMarket());
  642. }
  643. if (dto.getPaymentCurrency() != null) {
  644. currencyIds.add(dto.getPaymentCurrency());
  645. }
  646. if (dto.getReceivedCurrency() != null) {
  647. reCurrencyIds.add(dto.getReceivedCurrency());
  648. }
  649. }
  650. // 5. 批量查询地区字典
  651. Map<Integer, String> regionMap = new HashMap<>();
  652. if (!regionIds.isEmpty()) {
  653. List<Region> regions = refundMapper.selectByIds(new ArrayList<>(regionIds));
  654. for (Region region : regions) {
  655. regionMap.put(region.getId(), region.getName());
  656. }
  657. }
  658. // 6. 批量查询币种字典
  659. Map<Integer, String> currencyMap = new HashMap<>();
  660. if (!currencyIds.isEmpty()) {
  661. List<Currency> currencies = refundMapper.selectByCIds(new ArrayList<>(currencyIds));
  662. for (Currency currency : currencies) {
  663. currencyMap.put(currency.getId(), currency.getName()); // 或 getCode(),按需调整
  664. }
  665. }
  666. Map<Integer, String> reCurrencyMap = new HashMap<>();
  667. if (!reCurrencyIds.isEmpty()) {
  668. List<Currency> reCurrencies = refundMapper.selectByCIds(new ArrayList<>(reCurrencyIds));
  669. for (Currency reCurrency : reCurrencies) {
  670. reCurrencyMap.put(reCurrency.getId(), reCurrency.getName()); // 或 getCode(),按需调整
  671. }
  672. }
  673. // 7. 回填地区名称和币种名称到 DTO
  674. for (FundsDTO dto : list) {
  675. dto.setMarketName(regionMap.get(dto.getMarket()));
  676. dto.setPaymentCurrencyName(currencyMap.get(dto.getPaymentCurrency()));
  677. dto.setReceivedCurrencyName(reCurrencyMap.get(dto.getReceivedCurrency()));
  678. }
  679. // 8. 返回分页结果
  680. return new PageInfo<>(list);
  681. }
  682. }