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.

755 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
3 months ago
5 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
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(cashRecordRefund.getJwcode()+languageTranslationUtil.translate("用户的客服退款申请待审核,前往处理", lang));
  187. message.setTitle(languageTranslationUtil.translate("现金退款--新增退款", lang));
  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(languageTranslationUtil.translate(marketName, lang));
  193. rabbitTemplate.convertAndSend(RabbitMQConfig.CASH_REFUND_EXCHANGE, "cash.refund.save", message);
  194. return Result.success("提交成功").getCode();
  195. }
  196. @Override
  197. public int update(CashRecordDone cashRecordDone, @RequestHeader(defaultValue = "zh_CN") String lang) throws Exception {
  198. if (cashRecordDone.getJwcode()== null) {
  199. throw new RuntimeException("未输入精网号");
  200. }
  201. if (cashRecordDone.getPaymentAmount()== null) {
  202. throw new RuntimeException("未输入付款金额");
  203. }
  204. if (cashRecordDone.getPaymentCurrency()== null){
  205. throw new RuntimeException("未输入付款币种");
  206. }
  207. if (cashRecordDone.getRefundModel()== null) {
  208. throw new RuntimeException("请填写退款类型");
  209. }
  210. if (cashRecordDone.getRefundReason()== null) {
  211. throw new RuntimeException("请填写退款理由");
  212. }
  213. if(cashRecordDone.getNewRefundGold()== null){
  214. cashRecordDone.setNewRefundGold(BigDecimal.valueOf(0));
  215. }
  216. if(cashRecordDone.getNewRefundFree()== null){
  217. cashRecordDone.setNewRefundFree(BigDecimal.valueOf(0));
  218. }
  219. int result = cashRefundMapper.update(cashRecordDone);
  220. CashRecordDTO cashRecordDTO = cashRefundMapper.selectById(cashRecordDone.getId());
  221. if (result > 0) {
  222. // 发送审核消息
  223. Messages message = new Messages();
  224. message.setJwcode(cashRecordDTO.getJwcode());
  225. message.setName(cashRecordDTO.getName());
  226. message.setStatus(cashRecordDTO.getStatus());
  227. message.setDesc(cashRecordDTO.getJwcode() + languageTranslationUtil.translate("用户的退款申请待审核,前往处理", lang));
  228. message.setTitle(languageTranslationUtil.translate("现金退款--当地退款审核(编辑后提交)", lang));
  229. message.setType(1);
  230. message.setTypeId(cashRecordDTO.getId());
  231. message.setMarket(cashRecordDTO.getMarket());
  232. String marketName = marketMapper.getMarketNameById(String.valueOf(message.getMarket()));
  233. message.setMarketName(languageTranslationUtil.translate(marketName, lang));
  234. rabbitTemplate.convertAndSend(RabbitMQConfig.CASH_REFUND_EXCHANGE, "cash.refund.save", message);
  235. }
  236. return (result > 0 ? Result.success("提交成功") : Result.error("提交失败")).getCode();
  237. }
  238. @Override
  239. public int withdraw(CashRecordDone cashRecordDone) {
  240. return cashRefundMapper.withdraw(cashRecordDone.getId());
  241. }
  242. @Override
  243. public int review(CashRecordDone cashRecordDone, @RequestHeader(defaultValue = "zh_CN") String lang) throws Exception {
  244. if(cashRecordDone.getStatus()== 12|| cashRecordDone.getStatus()== 22){
  245. if(cashRecordDone.getOrderCode()== null){
  246. throw new RuntimeException("未输入订单号");
  247. }
  248. CashRecordDone cashRecordDone1 = new CashRecordDone();
  249. cashRecordDone1.setId(cashRecordDone.getRelatedId());
  250. cashRecordDone1.setOrderCode(cashRecordDone.getOrderCode().substring(2));
  251. cashRecordDone1.setStatus(4);
  252. if (cashRecordDone1.getId()!=null||cashRecordDone1.getOrderCode()!= null){
  253. cashRefundMapper.updateStatus(cashRecordDone1);
  254. }}
  255. cashRefundMapper.updateAudit(cashRecordDone);
  256. int result = cashRefundMapper.review(cashRecordDone);
  257. CashRecordDTO cashRecordDTO = cashRefundMapper.selectById(cashRecordDone.getId());
  258. if (result > 0) {
  259. // 发送审核消息
  260. Messages message = new Messages();
  261. message.setJwcode(cashRecordDTO.getJwcode());
  262. message.setName(cashRecordDTO.getName());
  263. message.setStatus(cashRecordDTO.getStatus());
  264. message.setDesc(cashRecordDTO.getJwcode()+cashRecordDTO.getStatus()!=12|| cashRecordDTO.getStatus()!=22?languageTranslationUtil.translate("用户的退款申请待审核,前往处理", lang):languageTranslationUtil.translate("用户的现金退款申请已被驳回,前往查看详情", lang));
  265. message.setTitle(languageTranslationUtil.translate("现金退款--当地退款审核", lang));
  266. message.setType(1);
  267. message.setTypeId(cashRecordDTO.getId());
  268. message.setMarket(cashRecordDTO.getMarket());
  269. String marketName = marketMapper.getMarketNameById(String.valueOf(message.getMarket()));
  270. message.setMarketName(languageTranslationUtil.translate(marketName, lang));
  271. rabbitTemplate.convertAndSend(RabbitMQConfig.CASH_REFUND_EXCHANGE, "cash.refund.save", message);
  272. }
  273. return (result > 0 ? Result.success("提交成功") : Result.error("提交失败")).getCode();
  274. }
  275. @Override
  276. public int executor(CashRecordDone cashRecordDone) throws Exception {
  277. if(cashRecordDone.getRefundVoucher()== null){
  278. throw new RuntimeException("未输入退款凭证");
  279. }
  280. if(cashRecordDone.getRefundTime()== null){
  281. throw new RuntimeException("未输入退款时间");
  282. }
  283. if(cashRecordDone.getRefundRemark()== null){
  284. throw new RuntimeException("未输入退款备注");
  285. }
  286. if(cashRecordDone.getRefundChannels()== null){
  287. throw new RuntimeException("未输入退款途径");
  288. }
  289. if(cashRecordDone.getRefundCurrency()== null){
  290. throw new RuntimeException("未输入退款币种");
  291. }
  292. if(cashRecordDone.getRefundAmount()== null){
  293. throw new RuntimeException("未输入退款金额");
  294. }
  295. int result = cashRefundMapper.executor(cashRecordDone);
  296. return (result > 0 ? Result.success("提交成功") : Result.error("提交失败")).getCode();
  297. }
  298. @Override
  299. public int updateStatus(CashRecordDone cashRecordDone) {
  300. return cashRefundMapper.updateStatus(cashRecordDone);
  301. }
  302. @Override
  303. public int finalreview(CashRecordDone cashRecordDone, @RequestHeader(defaultValue = "zh_CN") String lang) {
  304. if(cashRecordDone.getPermanentGold()== null){
  305. cashRecordDone.setPermanentGold(0);
  306. }
  307. if(cashRecordDone.getFreeGold()== null){
  308. cashRecordDone.setFreeGold(0);
  309. }
  310. if(cashRecordDone.getStatus()== 32){
  311. CashRecordDone cashRecordDone1 = new CashRecordDone();
  312. cashRecordDone1.setOrderCode(cashRecordDone.getOrderCode().substring(2));
  313. cashRecordDone1.setStatus(4);
  314. if (cashRecordDone1.getId()!=null||cashRecordDone1.getOrderCode()!= null){
  315. cashRefundMapper.updateStatus(cashRecordDone1);
  316. }}
  317. if (cashRecordDone.getGoodsName() != null &&cashRecordDone.getStatus() ==40 &&
  318. (cashRecordDone.getGoodsName().equals(languageTranslationUtil.translate("金币充值", lang))||
  319. cashRecordDone.getGoodsName().contains(languageTranslationUtil.translate("金币充值", lang)))) {
  320. UserGoldRecord userGoldRecord = new UserGoldRecord();
  321. userGoldRecord.setOrderCode(cashRecordDone.getOrderCode());
  322. userGoldRecord.setType((byte) 2);
  323. userGoldRecord.setIsRefund((byte) 1);
  324. userGoldRecord.setRefundType("金币退款");
  325. if (cashRecordDone.getRefundModel() == 1){
  326. userGoldRecord.setRefundModel(Byte.valueOf("1"));
  327. }
  328. else if (cashRecordDone.getRefundModel() == 0){
  329. userGoldRecord.setRefundModel(Byte.valueOf("0"));
  330. }
  331. userGoldRecord.setJwcode(cashRecordDone.getJwcode());
  332. userGoldRecord.setSumGold(cashRecordDone.getPermanentGold()+cashRecordDone.getFreeGold());
  333. userGoldRecord.setPermanentGold(cashRecordDone.getPermanentGold());
  334. int currentMonth = LocalDate.now().getMonthValue();
  335. if (currentMonth >= 1 && currentMonth <= 6) {
  336. // 1-6月:设置12月额度,6月保持默认值
  337. userGoldRecord.setFreeJune(0);
  338. userGoldRecord.setFreeDecember(cashRecordDone.getFreeGold());
  339. } else {
  340. // 7-12月:设置6月额度,12月保持默认值
  341. userGoldRecord.setFreeJune(cashRecordDone.getFreeGold());
  342. userGoldRecord.setFreeDecember(0);
  343. }
  344. userGoldRecord.setGoodsName(cashRecordDone.getGoodsName());
  345. userGoldRecord.setPayPlatform("金币系统");
  346. userGoldRecord.setRemark(cashRecordDone.getRemark());
  347. userGoldRecord.setAdminId(cashRecordDone.getAdminId());
  348. userGoldRecord.setAuditStatus(1);
  349. userGoldRecord.setTaskGold(0);
  350. userGoldRecord.setCreateTime(new Date());
  351. userGoldRecord.setUpdateTime(new Date());
  352. String auditName = auditMapper.getName(cashRecordDone.getAuditId());
  353. refundMapper.add(userGoldRecord);
  354. User user = new User();
  355. user.setJwcode(userGoldRecord.getJwcode());
  356. user.setCurrentPermanentGold(BigDecimal.valueOf(-userGoldRecord.getPermanentGold())); //当前永久金币
  357. user.setCurrentFreeJune(BigDecimal.valueOf(-userGoldRecord.getFreeJune())); //当前六月免费金币
  358. user.setCurrentFreeDecember(BigDecimal.valueOf(-userGoldRecord.getFreeDecember())); //当前十二月免费金币
  359. auditMapper.updateUserGold(user);
  360. GoldTistV2.addCoinNew(userGoldRecord.getJwcode().toString(), 58, //退款免费+永久金币-充值
  361. (double) (userGoldRecord.getFreeDecember()+userGoldRecord.getFreeJune()+userGoldRecord.getPermanentGold() ) /100, SimpleIdGenerator.generateId(),
  362. userGoldRecord.getRemark(),(double) userGoldRecord.getPermanentGold() / 100, auditName, "退款金币充值");}
  363. cashRefundMapper.updateAudit(cashRecordDone);
  364. int result = cashRefundMapper.review(cashRecordDone);
  365. CashRecordDTO cashRecordDTO = cashRefundMapper.selectById(cashRecordDone.getId());
  366. if (result > 0) {
  367. // 发送审核消息
  368. Messages message = new Messages();
  369. message.setJwcode(cashRecordDTO.getJwcode());
  370. message.setName(cashRecordDTO.getName());
  371. message.setStatus(cashRecordDTO.getStatus());
  372. message.setDesc(cashRecordDTO.getJwcode()+cashRecordDTO.getStatus()!=32?languageTranslationUtil.translate("用户的退款申请待审核,前往处理", lang):languageTranslationUtil.translate("用户的现金退款申请已被驳回,前往查看详情", lang));
  373. message.setTitle(languageTranslationUtil.translate("现金退款--执行人退款提交", lang));
  374. message.setType(1);
  375. message.setTypeId(cashRecordDTO.getId());
  376. message.setMarket(cashRecordDTO.getMarket());
  377. String marketName = marketMapper.getMarketNameById(String.valueOf(message.getMarket()));
  378. message.setMarketName(languageTranslationUtil.translate(marketName, "zh_CN"));
  379. }
  380. return (result > 0 ? Result.success("提交成功") : Result.error("提交失败")).getCode();
  381. }
  382. @Override
  383. public PageInfo<CashRecordDTO> financeSelect(Integer pageNum, Integer pageSize, CashRecordDTO cashRecordDTO) {
  384. PageHelper.startPage(pageNum, pageSize); //必须要直接跟mapper
  385. // System.out.println(goldDetail.getMarkets());
  386. List<CashRecordDTO> list = cashRefundMapper.financeSelect(cashRecordDTO);
  387. if (list.isEmpty()) {
  388. return new PageInfo<>(list);
  389. }
  390. // 批量收集ID
  391. Set<Integer> relatedIds = new HashSet<>();
  392. Set<Integer> marketIds = new HashSet<>();
  393. Set<Integer> submitterIds = new HashSet<>();
  394. Set<Integer> auditIds = new HashSet<>();
  395. Set<Integer> executorIds = new HashSet<>();
  396. list.forEach(item -> {
  397. if (item.getRelatedId() != null) relatedIds.add(item.getRelatedId());
  398. if (item.getMarket() != null) marketIds.add(item.getMarket());
  399. if (item.getSubmitterId() != null) submitterIds.add(item.getSubmitterId());
  400. if (item.getAuditId() != null) auditIds.add(item.getAuditId());
  401. if (item.getExecutor() != null) executorIds.add(item.getExecutor());
  402. });
  403. // 批量查询
  404. Map<Integer, CashCollection> cashCollectionMap = cashCollectionMapper.selectBatchIds(relatedIds)
  405. .stream().collect(Collectors.toMap(CashCollection::getId, Function.identity()));
  406. Map<Integer, String> marketNameMap = marketMapper.getMarketByIds(marketIds)
  407. .stream().collect(Collectors.toMap(Market::getId, Market::getName));
  408. Map<Integer, String> submitterNameMap = auditMapper.getNamesByIds(submitterIds)
  409. .stream().collect(Collectors.toMap(Admin::getId, Admin::getAdminName));
  410. Map<Integer, LhlAudit> auditMap = cashRefundMapper.getAuditBatch(auditIds)
  411. .stream().collect(Collectors.toMap(LhlAudit::getId, Function.identity()));
  412. Map<String, String> executorNameMap = auditMapper.getNamesByJwcodes(executorIds)
  413. .stream().collect(Collectors.toMap(Admin::getAccount, Admin::getAdminName));
  414. // 处理数据
  415. list.forEach(item -> {
  416. CashCollection cashCollection = cashCollectionMap.get(item.getRelatedId());
  417. if (cashCollection != null) {
  418. processCashCollection(item, cashCollection);
  419. }
  420. String marketName = marketNameMap.get(item.getMarket());
  421. String submitter = submitterNameMap.get(item.getSubmitterId());
  422. LhlAudit lhlAudit = auditMap.get(item.getAuditId());
  423. String executorName = executorNameMap.get(String.valueOf(item.getExecutor()));
  424. item.setMarketName(marketName != null ? marketName : "");
  425. item.setSubmitter(submitter != null ? submitter : "");
  426. item.setExecutorName(executorName != null ? executorName : "");
  427. if (lhlAudit != null) {
  428. item.setAreaServise(lhlAudit.getAreaServise());
  429. item.setAreaFinance(lhlAudit.getAreaFinance());
  430. item.setAreaCharge(lhlAudit.getAreaCharge());
  431. item.setHeadFinance(lhlAudit.getHeadFinance());
  432. }
  433. });
  434. return new PageInfo<>(list);
  435. }
  436. @Override
  437. public PageInfo<CashRecordDTO> financeSelect2(Integer pageNum, Integer pageSize, CashRecordDTO cashRecordDTO) {
  438. PageHelper.startPage(pageNum, pageSize); //必须要直接跟mapper
  439. // System.out.println(goldDetail.getMarkets());
  440. List<CashRecordDTO> list = cashRefundMapper.financeSelect(cashRecordDTO);
  441. if (list.isEmpty()) {
  442. return new PageInfo<>(list);
  443. }
  444. // 批量收集ID
  445. Set<Integer> relatedIds = new HashSet<>();
  446. Set<Integer> marketIds = new HashSet<>();
  447. Set<Integer> submitterIds = new HashSet<>();
  448. Set<Integer> auditIds = new HashSet<>();
  449. Set<Integer> executorIds = new HashSet<>();
  450. list.forEach(item -> {
  451. if (item.getRelatedId() != null) relatedIds.add(item.getRelatedId());
  452. if (item.getMarket() != null) marketIds.add(item.getMarket());
  453. if (item.getSubmitterId() != null) submitterIds.add(item.getSubmitterId());
  454. if (item.getAuditId() != null) auditIds.add(item.getAuditId());
  455. if (item.getExecutor() != null) executorIds.add(item.getExecutor());
  456. });
  457. // 批量查询
  458. Map<Integer, CashCollection> cashCollectionMap = cashCollectionMapper.selectBatchIds(relatedIds)
  459. .stream().collect(Collectors.toMap(CashCollection::getId, Function.identity()));
  460. Map<Integer, String> marketNameMap = marketMapper.getMarketByIds(marketIds)
  461. .stream().collect(Collectors.toMap(Market::getId, Market::getName));
  462. Map<Integer, String> submitterNameMap = auditMapper.getNamesByIds(submitterIds)
  463. .stream().collect(Collectors.toMap(Admin::getId, Admin::getAdminName));
  464. Map<Integer, LhlAudit> auditMap = cashRefundMapper.getAuditBatch(auditIds)
  465. .stream().collect(Collectors.toMap(LhlAudit::getId, Function.identity()));
  466. Map<String, String> executorNameMap = auditMapper.getNamesByJwcodes(executorIds)
  467. .stream().collect(Collectors.toMap(Admin::getAccount, Admin::getAdminName));
  468. // 处理数据
  469. list.forEach(item -> {
  470. CashCollection cashCollection = cashCollectionMap.get(item.getRelatedId());
  471. if (cashCollection != null) {
  472. processCashCollection(item, cashCollection);
  473. }
  474. String marketName = marketNameMap.get(item.getMarket());
  475. String submitter = submitterNameMap.get(item.getSubmitterId());
  476. LhlAudit lhlAudit = auditMap.get(item.getAuditId());
  477. String executorName = executorNameMap.get(String.valueOf(item.getExecutor()));
  478. item.setMarketName(marketName != null ? marketName : "");
  479. item.setSubmitter(submitter != null ? submitter : "");
  480. item.setExecutorName(executorName != null ? executorName : "");
  481. if (lhlAudit != null) {
  482. item.setAreaServise(lhlAudit.getAreaServise());
  483. item.setAreaFinance(lhlAudit.getAreaFinance());
  484. item.setAreaCharge(lhlAudit.getAreaCharge());
  485. item.setHeadFinance(lhlAudit.getHeadFinance());
  486. }
  487. });
  488. return new PageInfo<>(list);
  489. }
  490. @Override
  491. public PageInfo<CashRecordDTO> exSelect(Integer pageNum, Integer pageSize, CashRecordDTO cashRecordDTO) {
  492. PageHelper.startPage(pageNum, pageSize); //必须要直接跟mapper
  493. // System.out.println(goldDetail.getMarkets());
  494. List<CashRecordDTO> list = cashRefundMapper.exSelect(cashRecordDTO);
  495. System.out.println( list);
  496. if (list.isEmpty()) {
  497. return new PageInfo<>(list);
  498. }
  499. // 批量收集ID
  500. Set<Integer> relatedIds = new HashSet<>();
  501. Set<Integer> marketIds = new HashSet<>();
  502. Set<Integer> submitterIds = new HashSet<>();
  503. Set<Integer> auditIds = new HashSet<>();
  504. Set<Integer> executorIds = new HashSet<>();
  505. list.forEach(item -> {
  506. if (item.getRelatedId() != null) relatedIds.add(item.getRelatedId());
  507. if (item.getMarket() != null) marketIds.add(item.getMarket());
  508. if (item.getSubmitterId() != null) submitterIds.add(item.getSubmitterId());
  509. if (item.getAuditId() != null) auditIds.add(item.getAuditId());
  510. if (item.getExecutor() != null) executorIds.add(item.getExecutor());
  511. });
  512. // 批量查询
  513. Map<Integer, CashCollection> cashCollectionMap = cashCollectionMapper.selectBatchIds(relatedIds)
  514. .stream().collect(Collectors.toMap(CashCollection::getId, Function.identity()));
  515. Map<Integer, String> marketNameMap = marketMapper.getMarketByIds(marketIds)
  516. .stream().collect(Collectors.toMap(Market::getId, Market::getName));
  517. Map<Integer, String> submitterNameMap = auditMapper.getNamesByIds(submitterIds)
  518. .stream().collect(Collectors.toMap(Admin::getId, Admin::getAdminName));
  519. Map<Integer, LhlAudit> auditMap = cashRefundMapper.getAuditBatch(auditIds)
  520. .stream().collect(Collectors.toMap(LhlAudit::getId, Function.identity()));
  521. Map<String, String> executorNameMap = auditMapper.getNamesByJwcodes(executorIds)
  522. .stream().collect(Collectors.toMap(Admin::getAccount, Admin::getAdminName));
  523. // 处理数据
  524. list.forEach(item -> {
  525. CashCollection cashCollection = cashCollectionMap.get(item.getRelatedId());
  526. if (cashCollection != null) {
  527. processCashCollection(item, cashCollection);
  528. }
  529. String marketName = marketNameMap.get(item.getMarket());
  530. String submitter = submitterNameMap.get(item.getSubmitterId());
  531. LhlAudit lhlAudit = auditMap.get(item.getAuditId());
  532. String executorName = executorNameMap.get(String.valueOf(item.getExecutor()));
  533. item.setMarketName(marketName != null ? marketName : "");
  534. item.setSubmitter(submitter != null ? submitter : "");
  535. item.setExecutorName(executorName != null ? executorName : "");
  536. if (lhlAudit != null) {
  537. item.setAreaServise(lhlAudit.getAreaServise());
  538. item.setAreaFinance(lhlAudit.getAreaFinance());
  539. item.setAreaCharge(lhlAudit.getAreaCharge());
  540. item.setHeadFinance(lhlAudit.getHeadFinance());
  541. }
  542. });
  543. return new PageInfo<>(list);
  544. }
  545. @Override
  546. public void addOnline(CashRecordRefund cashRecordRefund) {
  547. if(cashRecordRefund.getJwcode()==null){
  548. throw new BusinessException("未输入精网号") ;
  549. }
  550. if(cashRecordRefund.getRefundModel()== null){
  551. throw new BusinessException("请填充退款类型") ;
  552. }
  553. if(cashRecordRefund.getRefundReason()== null){
  554. throw new BusinessException("请填写退款理由") ;
  555. }
  556. CashRecordDone cashRecordDonetwo = new CashRecordDone();
  557. cashRecordDonetwo.setAreaServise(cashRecordRefund.getAreaServise());
  558. cashRefundMapper.addAudit(cashRecordDonetwo);
  559. cashRecordRefund.setAuditId(cashRecordDonetwo.getId());
  560. cashRecordRefund.setStatus(20);
  561. //生成订单号后半部分
  562. String orderNumber = cashRecordRefund.getOrderCode();
  563. //构建订单信息
  564. cashRecordRefund.setOrderCode("TK" + orderNumber); //订单号
  565. cashRecordRefund.setMarket(String.valueOf(Integer.valueOf(marketMapper.getMarketId(cashRecordRefund.getMarket()))));
  566. cashRefundMapper.insert(cashRecordRefund);
  567. CashRecordDone cashRecordDone1 = new CashRecordDone();
  568. cashRecordDone1.setId(cashRecordRefund.getId());
  569. cashRecordDone1.setStatus(6);
  570. if (cashRecordDone1.getId()!=null||cashRecordDone1.getOrderCode()!= null)
  571. cashRefundMapper.updateStatus(cashRecordDone1);
  572. else throw new SystemException("提交失败") ;
  573. }
  574. @Override
  575. public PageInfo<FundsDTO> funds(Integer pageNum, Integer pageSize, FundsDTO fundsDTO) {
  576. // 1. 分页查询主数据
  577. PageHelper.startPage(pageNum, pageSize);
  578. if (fundsDTO.getStatuses() == null || fundsDTO.getStatuses().isEmpty()) {
  579. fundsDTO.setStatuses(Arrays.asList(4, 6));
  580. }
  581. List<FundsDTO> list = cashRefundMapper.selectfunds(fundsDTO);
  582. // 2. 收集 status == 6 的记录 ID
  583. List<Integer> needQueryIds = new ArrayList<>();
  584. for (FundsDTO dto : list) {
  585. if (dto.getStatus() != null && dto.getStatus() == 6) {
  586. needQueryIds.add(dto.getId());
  587. }
  588. }
  589. // 3. 批量查询 refundDetail 信息(用于负数处理)
  590. if (!needQueryIds.isEmpty()) {
  591. List<FundsDTO> detailList = cashRefundMapper.selectRefundCount(needQueryIds);
  592. Map<Integer, FundsDTO> detailMap = new HashMap<>();
  593. for (FundsDTO detail : detailList) {
  594. // 假设 detail.getRelatedId() 对应主表的 id
  595. detailMap.put(detail.getRelatedId(), detail);
  596. }
  597. // 回填 refundAmount(取负)和 refundCurrency
  598. for (FundsDTO dto : list) {
  599. if (dto.getStatus() != null && dto.getStatus() == 6) {
  600. FundsDTO detail = detailMap.get(dto.getId());
  601. if (detail != null) {
  602. BigDecimal amount = detail.getRefundAmount();
  603. if (amount != null) {
  604. dto.setRefundAmount(amount.negate()); // 转为负数
  605. } else {
  606. dto.setRefundAmount(null); // 或设为 BigDecimal.ZERO
  607. }
  608. dto.setRefundCurrency(detail.getRefundCurrency());
  609. }
  610. }
  611. }
  612. }
  613. // 4. 收集所有需要转换的 regionId 和 currencyId
  614. Set<Integer> regionIds = new HashSet<>();
  615. Set<Integer> currencyIds = new HashSet<>();
  616. Set<Integer> reCurrencyIds = new HashSet<>();
  617. for (FundsDTO dto : list) {
  618. if (dto.getMarket() != null) {
  619. regionIds.add(dto.getMarket());
  620. }
  621. if (dto.getPaymentCurrency() != null) {
  622. currencyIds.add(dto.getPaymentCurrency());
  623. }
  624. if (dto.getReceivedCurrency() != null) {
  625. reCurrencyIds.add(dto.getReceivedCurrency());
  626. }
  627. }
  628. // 5. 批量查询地区字典
  629. Map<Integer, String> regionMap = new HashMap<>();
  630. if (!regionIds.isEmpty()) {
  631. List<Region> regions = refundMapper.selectByIds(new ArrayList<>(regionIds));
  632. for (Region region : regions) {
  633. regionMap.put(region.getId(), region.getName());
  634. }
  635. }
  636. // 6. 批量查询币种字典
  637. Map<Integer, String> currencyMap = new HashMap<>();
  638. if (!currencyIds.isEmpty()) {
  639. List<Currency> currencies = refundMapper.selectByCIds(new ArrayList<>(currencyIds));
  640. for (Currency currency : currencies) {
  641. currencyMap.put(currency.getId(), currency.getName()); // 或 getCode(),按需调整
  642. }
  643. }
  644. Map<Integer, String> reCurrencyMap = new HashMap<>();
  645. if (!reCurrencyIds.isEmpty()) {
  646. List<Currency> reCurrencies = refundMapper.selectByCIds(new ArrayList<>(reCurrencyIds));
  647. for (Currency reCurrency : reCurrencies) {
  648. reCurrencyMap.put(reCurrency.getId(), reCurrency.getName()); // 或 getCode(),按需调整
  649. }
  650. }
  651. // 7. 回填地区名称和币种名称到 DTO
  652. for (FundsDTO dto : list) {
  653. dto.setMarketName(regionMap.get(dto.getMarket()));
  654. dto.setPaymentCurrencyName(currencyMap.get(dto.getPaymentCurrency()));
  655. dto.setReceivedCurrencyName(reCurrencyMap.get(dto.getReceivedCurrency()));
  656. }
  657. // 8. 返回分页结果
  658. return new PageInfo<>(list);
  659. }
  660. }