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.

634 lines
31 KiB

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