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.

618 lines
30 KiB

6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
3 months ago
  1. package com.example.demo.serviceImpl.cash;
  2. import com.example.demo.Util.JWTUtil;
  3. import com.example.demo.Util.LanguageTranslationUtil;
  4. import com.example.demo.config.RabbitMQConfig;
  5. import com.example.demo.domain.DTO.PerformanceDTO;
  6. import com.example.demo.domain.entity.*;
  7. import com.example.demo.domain.vo.cash.*;
  8. import com.example.demo.domain.vo.coin.GoldUser;
  9. import com.example.demo.domain.vo.coin.Messages;
  10. import com.example.demo.domain.vo.coin.Result;
  11. import com.example.demo.mapper.cash.CashCollectionMapper;
  12. import com.example.demo.mapper.coin.MarketMapper;
  13. import com.example.demo.mapper.coin.UserMapper;
  14. import com.example.demo.service.cash.CashCollectionService;
  15. import com.github.pagehelper.PageHelper;
  16. import com.github.pagehelper.PageInfo;
  17. import jakarta.servlet.http.HttpServletRequest;
  18. import lombok.extern.slf4j.Slf4j;
  19. import org.springframework.amqp.rabbit.core.RabbitTemplate;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.stereotype.Service;
  22. import org.springframework.transaction.annotation.Transactional;
  23. import org.springframework.util.CollectionUtils;
  24. import org.springframework.web.bind.annotation.RequestHeader;
  25. import org.springframework.web.context.request.RequestContextHolder;
  26. import org.springframework.web.context.request.ServletRequestAttributes;
  27. import java.math.BigDecimal;
  28. import java.time.LocalDateTime;
  29. import java.time.ZoneOffset;
  30. import java.util.Arrays;
  31. import java.util.List;
  32. import java.util.Objects;
  33. import java.util.UUID;
  34. import java.util.stream.Collectors;
  35. /**
  36. * @program: gold-java
  37. * @ClassName cashCollectionServiceImpl
  38. * @description: 处理收款相关业务逻辑
  39. * @author: Ethan
  40. * @create: 202509-26 11:23
  41. * @Version 1.0
  42. **/
  43. @Service
  44. @Slf4j
  45. public class CashCollectionServiceImpl implements CashCollectionService {
  46. @Autowired
  47. private CashCollectionMapper cashCollectionMapper;
  48. @Autowired
  49. private UserMapper userMapper;
  50. @Autowired
  51. private MarketMapper marketMapper;
  52. @Autowired
  53. private RabbitTemplate rabbitTemplate;
  54. @Autowired
  55. private LanguageTranslationUtil languageTranslationUtil;
  56. //新增收款订单
  57. @Override
  58. public String add(CashCollection cashCollection,@RequestHeader(defaultValue = "zh_CN") String lang) {
  59. if (cashCollection.getJwcode() == null) {
  60. throw new IllegalArgumentException("精网号不能为空");
  61. }
  62. if (cashCollection.getJwcode() < 10000000 || cashCollection.getJwcode() > 99999999) {
  63. throw new IllegalArgumentException("精网号必须为8位");
  64. }
  65. if (cashCollection.getName() == null || cashCollection.getName().isEmpty()){
  66. throw new IllegalArgumentException("客户姓名不能为空");
  67. }
  68. if (cashCollection.getActivity() == null || cashCollection.getActivity().isEmpty()) {
  69. throw new IllegalArgumentException("活动不能为空");
  70. }
  71. if (cashCollection.getGoodsName() == null|| cashCollection.getGoodsName().isEmpty()) {
  72. throw new IllegalArgumentException("产品名称不能为空");
  73. }
  74. if (cashCollection.getGoodsName().equals("金币充值")) {
  75. if (cashCollection.getPermanentGold() == 0 && cashCollection.getFreeGold() == 0) {
  76. throw new IllegalArgumentException("金币数量不能为空");
  77. }
  78. if (cashCollection.getWalletId() == null || cashCollection.getWalletId() < 0 || cashCollection.getWalletId() > 10) {
  79. throw new IllegalArgumentException("钱包ID不能为空");
  80. }
  81. }
  82. if (!cashCollection.getGoodsName().equals("金币充值")) {
  83. if (cashCollection.getGoodNum() == 0) {
  84. throw new IllegalArgumentException("产品数量不能为空");
  85. }
  86. if (cashCollection.getNumUnit() == null|| cashCollection.getNumUnit().isEmpty()) {
  87. throw new IllegalArgumentException("数量单位不能为空");
  88. }
  89. }
  90. if (cashCollection.getPaymentCurrency() == null || cashCollection.getPaymentCurrency().isEmpty()) {
  91. throw new IllegalArgumentException("支付币种不能为空");
  92. }
  93. if (cashCollection.getPaymentAmount() == null || cashCollection.getPaymentAmount().compareTo(BigDecimal.ZERO) == 0) {
  94. throw new IllegalArgumentException("支付金额不能为空");
  95. }
  96. if (cashCollection.getPayType() == null|| cashCollection.getPayType().isEmpty()) {
  97. throw new IllegalArgumentException("支付方式不能为空");
  98. }
  99. if (cashCollection.getReceivedMarket() == null||cashCollection.getReceivedMarket().isEmpty()) {
  100. throw new IllegalArgumentException("到账地区不能为空");
  101. }
  102. if (cashCollection.getPayTime() == null) {
  103. throw new IllegalArgumentException("付款时间不能为空");
  104. }
  105. //生成订单号后半部分
  106. String orderNumber = UUID.randomUUID().toString().replaceAll("-", "");
  107. CashRecord cashRecord = new CashRecord();
  108. //构建订单信息
  109. cashRecord.setOrderCode("XJ_" + orderNumber); //订单号
  110. cashRecord.setJwcode(cashCollection.getJwcode()); //精网号
  111. cashRecord.setName(cashCollection.getName()); //客户姓名
  112. cashRecord.setActivity(cashCollection.getActivity()); // 活动
  113. cashRecord.setGoodsName(cashCollection.getGoodsName()); //商品名称
  114. cashRecord.setGoodNum(cashCollection.getGoodNum()); //商品数量
  115. cashRecord.setNumUnit(cashCollection.getNumUnit()); //数量单位
  116. cashRecord.setPermanentGold(cashCollection.getPermanentGold()); //永久金币
  117. cashRecord.setFreeGold(cashCollection.getFreeGold()); //免费金币
  118. cashRecord.setWalletId(cashCollection.getWalletId()); // 钱包 ID
  119. cashRecord.setPaymentCurrency(cashCollection.getPaymentCurrency()); //付款币种
  120. cashRecord.setPaymentAmount(cashCollection.getPaymentAmount()); //付款金额
  121. cashRecord.setReceivedMarket(cashCollection.getReceivedMarket()); //到账地区
  122. cashRecord.setPayType(cashCollection.getPayType()); //支付方式
  123. cashRecord.setPayTime(cashCollection.getPayTime()); //付款时间
  124. cashRecord.setVoucher(cashCollection.getVoucher()); //转账凭证
  125. cashRecord.setRemark(cashCollection.getRemark()); //备注
  126. cashRecord.setStatus(0); //订单状态:付款线下财务待审核
  127. cashRecord.setSubmitterId(cashCollection.getSubmitterId()); //提交人 ID
  128. cashRecord.setSubmitterMarket(cashCollection.getSubmitterMarket());
  129. cashRecord.setOrderType(1); //订单类型:1-收款
  130. cashRecord.setMarket(cashCollection.getMarket());
  131. //地区,根据jwcode插入
  132. //cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(cashRecord.getJwcode()));
  133. //插入新收款订单
  134. cashCollectionMapper.add(cashRecord);
  135. // 发送收款创建消息
  136. Messages message = new Messages();
  137. message.setJwcode(cashRecord.getJwcode());
  138. message.setName(cashRecord.getName());
  139. message.setStatus(cashRecord.getStatus());
  140. message.setDesc("的现金收款申请待审核,前往审核");
  141. message.setTitle("现金管理--收款处理");
  142. message.setType(0);
  143. message.setTypeId(cashRecord.getId());
  144. message.setMarket(Integer.valueOf(cashRecord.getMarket()));
  145. String marketName = marketMapper.getMarketNameById(String.valueOf(message.getMarket()));
  146. message.setMarketName(marketName);
  147. message.setQueryId(67);
  148. rabbitTemplate.convertAndSend(RabbitMQConfig.CASH_COLLECTION_EXCHANGE, "cash.collection.save", message);
  149. return "添加成功";
  150. }
  151. @Override
  152. public String addFreeCoin(CashCollection cashCollection,@RequestHeader(defaultValue = "zh_CN") String lang) {
  153. if (cashCollection.getJwcode() == null) {
  154. throw new IllegalArgumentException("精网号不能为空");
  155. }
  156. if (cashCollection.getJwcode() < 10000000 || cashCollection.getJwcode() > 99999999) {
  157. throw new IllegalArgumentException("精网号必须为8位");
  158. }
  159. if (cashCollection.getName() == null || cashCollection.getName().isEmpty()){
  160. throw new IllegalArgumentException("客户姓名不能为空");
  161. }
  162. if (cashCollection.getActivity() == null || cashCollection.getActivity().isEmpty()) {
  163. throw new IllegalArgumentException("活动不能为空");
  164. }
  165. if (cashCollection.getFreeGold() == 0) {
  166. throw new IllegalArgumentException("免费金币数量不能为空");
  167. }
  168. //生成订单号后半部分
  169. String orderNumber = UUID.randomUUID().toString().replaceAll("-", "");
  170. CashRecord cashRecord = new CashRecord();
  171. //构建订单信息
  172. cashRecord.setOrderCode("XJ_" + orderNumber); //订单号
  173. cashRecord.setJwcode(cashCollection.getJwcode()); //精网号
  174. cashRecord.setName(cashCollection.getName()); //客户姓名
  175. cashRecord.setActivity(cashCollection.getActivity()); // 活动
  176. cashRecord.setGoodsName("免费金币赠送"); //商品名称
  177. cashRecord.setFreeGold(cashCollection.getFreeGold()); //免费金币
  178. cashRecord.setRemark(cashCollection.getRemark()); //备注
  179. cashRecord.setStatus(0); //订单状态:付款线下财务待审核
  180. cashRecord.setSubmitterId(cashCollection.getSubmitterId()); //提交人ID
  181. cashRecord.setSubmitterMarket(cashCollection.getSubmitterMarket());
  182. cashRecord.setOrderType(1); //订单类型:1-收款
  183. cashRecord.setMarket(cashCollection.getMarket());
  184. //地区,根据jwcode插入
  185. //cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(cashRecord.getJwcode()));
  186. //插入新收款订单
  187. cashCollectionMapper.add(cashRecord);
  188. // 发送收款创建消息
  189. Messages message = new Messages();
  190. message.setJwcode(cashRecord.getJwcode());
  191. message.setName(cashRecord.getName());
  192. message.setStatus(cashRecord.getStatus());
  193. message.setDesc("的现金收款申请待审核,请前往审核");
  194. message.setTitle("现金收款--现金收款");
  195. message.setType(1);
  196. message.setTypeId(cashRecord.getId());
  197. message.setMarket(Integer.valueOf(cashRecord.getMarket()));
  198. String marketName = marketMapper.getMarketNameById(String.valueOf(message.getMarket()));
  199. message.setMarketName(marketName);
  200. message.setQueryId(67);
  201. rabbitTemplate.convertAndSend(RabbitMQConfig.CASH_COLLECTION_EXCHANGE, "cash.collection.save", message);
  202. return "添加成功";
  203. }
  204. //撤回未审核的订单
  205. @Override
  206. public String cancel(String orderCode) {
  207. // 查询订单是否存在
  208. CashRecord cashRecord = cashCollectionMapper.selectByOrderCode(orderCode);
  209. if (cashRecord == null) {
  210. throw new IllegalArgumentException("订单不存在");
  211. }
  212. if (cashRecord.getStatus() != 0) {
  213. throw new IllegalArgumentException("订单状态不符合条件");
  214. }
  215. // 更新订单状态为撤回状态(5)
  216. int rows = cashCollectionMapper.updateStatus(orderCode, 5);
  217. // 更新与该订单关联的消息记录的 flag 字段为 1
  218. try {
  219. // 根据订单ID查找关联的消息记录
  220. Messages message = new Messages();
  221. message.setTypeId(cashRecord.getId()); // 订单ID作为消息的 typeId
  222. message.setType(0); // 消息类型为收款
  223. // 更新消息的 flag 字段为 1
  224. int messageRows = cashCollectionMapper.updateMessageFlagByTypeIdAndType(
  225. message.getTypeId(), message.getType(), 1);
  226. if (messageRows <= 0) {
  227. log.warn("未找到与订单 {} 关联的消息记录", orderCode);
  228. }
  229. } catch (Exception e) {
  230. log.error("更新消息状态失败,订单号:{}", orderCode, e);
  231. // 可选择抛出异常或记录日志后继续执行
  232. }
  233. return rows > 0 ? "撤回成功" : "撤回失败";
  234. }
  235. //编辑并重新提交收款订单
  236. @Override
  237. public String reSubmit(CashRecord cashRecord,@RequestHeader(defaultValue = "zh_CN") String lang) {
  238. if (cashRecord.getJwcode() == null) {
  239. throw new IllegalArgumentException("精网号不能为空");
  240. }
  241. if (cashRecord.getJwcode() < 10000000 || cashRecord.getJwcode() > 99999999) {
  242. throw new IllegalArgumentException("精网号必须为8位");
  243. }
  244. if (cashRecord.getName() == null) {
  245. throw new IllegalArgumentException("客户姓名不能为空");
  246. }
  247. if (cashRecord.getActivity() == null) {
  248. throw new IllegalArgumentException("活动不能为空");
  249. }
  250. if (cashRecord.getGoodsName() == null) {
  251. throw new IllegalArgumentException("商品名不能为空");
  252. }
  253. if (cashRecord.getGoodsName().equals("金币充值")) {
  254. if (cashRecord.getPermanentGold() == 0 && cashRecord.getFreeGold() == 0) {
  255. throw new IllegalArgumentException("金币数量不能为空");
  256. }if (cashRecord.getPermanentGold() == 0){
  257. throw new IllegalArgumentException("永久金币数量不能为空");
  258. }
  259. if (cashRecord.getWalletId() == null) {
  260. throw new IllegalArgumentException("钱包ID不能为空");
  261. }
  262. }
  263. if (!cashRecord.getGoodsName().equals("金币充值")) {
  264. if (cashRecord.getGoodNum() == 0) {
  265. throw new IllegalArgumentException("产品数量不能为空");
  266. }
  267. if (cashRecord.getNumUnit() == null) {
  268. throw new IllegalArgumentException("数量单位不能为空");
  269. }
  270. }
  271. if (cashRecord.getPaymentCurrency() == null) {
  272. throw new IllegalArgumentException("支付币种不能为空");
  273. }
  274. if (cashRecord.getPaymentAmount() == null || cashRecord.getPaymentAmount().compareTo(BigDecimal.ZERO) == 0) {
  275. throw new IllegalArgumentException("支付金额不能为空");
  276. }
  277. if (cashRecord.getPayType() == null) {
  278. throw new IllegalArgumentException("支付方式不能为空");
  279. }
  280. if (cashRecord.getReceivedMarket() == null) {
  281. throw new IllegalArgumentException("到账地区不能为空");
  282. }
  283. if (cashRecord.getPayTime() == null) {
  284. throw new IllegalArgumentException("付款时间不能为空");
  285. }
  286. CashRecord status = cashCollectionMapper.selectByOrderCode(cashRecord.getOrderCode());
  287. if (!status.getStatus().equals(5)) {
  288. throw new IllegalArgumentException("只允许编辑已撤回订单");
  289. }
  290. //地区,根据jwcode插入(弃用,插入前调用接口获取地区和姓名,之后前端传入)
  291. //cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(cashRecord.getJwcode()));
  292. int rows = cashCollectionMapper.updateByOrderCode(cashRecord);
  293. if (rows > 0) {
  294. // 发送收款创建消息
  295. Messages message = new Messages();
  296. message.setJwcode(cashRecord.getJwcode());
  297. message.setName(cashRecord.getName());
  298. message.setStatus(cashRecord.getStatus());
  299. message.setDesc("的现金收款申请待审核,前往审核");
  300. message.setTitle("现金管理--收款处理");
  301. message.setType(0);
  302. message.setTypeId(cashRecord.getId());
  303. message.setMarket(Integer.valueOf(cashRecord.getMarket()));
  304. String marketName = marketMapper.getMarketNameById(String.valueOf(message.getMarket()));
  305. message.setMarketName(marketName);
  306. message.setQueryId(67);
  307. rabbitTemplate.convertAndSend(RabbitMQConfig.CASH_COLLECTION_EXCHANGE, "cash.collection.save", message);
  308. }
  309. return rows > 0 ? "重新提交成功" : "重新提交失败";
  310. }
  311. //多条件查询收款订单列表
  312. @Override
  313. public PageInfo<CashCollection> selectCollection(Integer pageNum, Integer pageSize, CashCollection cashCollection) {
  314. /* //将操作人的地区列表改为id
  315. List<String> markets = marketMapper.getMarketIds(cashCollection.getMarkets());
  316. if (markets.contains("9") || markets.contains("9999")) {
  317. markets = null;
  318. }*/
  319. // cashCollection.setReceivedMarket(marketMapper.getMarketId(cashCollection.getReceivedMarket()));
  320. if (cashCollection.getCashRoleId() == 2) {
  321. //角色是总部时,若不特地传状态,传1346,sql处理为(1,3,4,6)筛选,
  322. if (cashCollection.getStatus() == null) {
  323. cashCollection.setStatus(1346);
  324. }
  325. cashCollection.setSubmitterId(null);
  326. cashCollection.setReceivedMarket(null);
  327. cashCollection.setSubmitterMarket(null);
  328. }
  329. if (cashCollection.getCashRoleId() == 1) {
  330. //角色是地方财务,提交人置空不设筛选条件,仅按收款地区、提交人地区筛选()
  331. if (cashCollection.getStatus() == null) {
  332. cashCollection.setStatus(123460);
  333. }
  334. //状态为待审核和已驳回时按照提交人地区筛选
  335. if (cashCollection.getStatus() == 0 || cashCollection.getStatus() == 2) {
  336. cashCollection.setReceivedMarket(null);
  337. }
  338. //状态为已通过和Link通过时,满足收款地区或提交人地区即可
  339. /* if (cashCollection.getStatus() == 13) {
  340. cashCollection.setSubmitterId(null);
  341. }*/
  342. //状态为13 或46,已通过或已完成和已退款,满足收款地区或提交人地区即可,
  343. cashCollection.setSubmitterId(null);
  344. }
  345. if (cashCollection.getCashRoleId() == 0) {
  346. //角色是地方财务,提交人置空不设筛选条件---仅当角色是0 地方客服时,按提交人筛选
  347. if (cashCollection.getStatus() == null) {
  348. cashCollection.setStatus(1234560);
  349. }
  350. cashCollection.setSubmitterId(cashCollection.getSubmitterId());
  351. cashCollection.setReceivedMarket(null);
  352. }
  353. // cashCollection.setMarkets(markets);
  354. PageHelper.startPage(pageNum, pageSize); //必须要直接跟mapper
  355. List<CashCollection> cashCollections = cashCollectionMapper.selectCollection1(pageNum, pageSize, cashCollection);
  356. return new PageInfo<>(cashCollections);
  357. }
  358. //补全手续费等内容
  359. @Override
  360. @Transactional(rollbackFor = Exception.class)
  361. public String complete(CashRecord cashRecord) {
  362. if (!Objects.equals(cashRecord.getPaymentCurrency(), cashRecord.getReceivedCurrency())
  363. && ("Stripe".equals(cashRecord.getPayType()) || "Paypal".equals(cashRecord.getPayType()))) {
  364. return "支付币种与收款币种不一致";
  365. }
  366. int rows = cashCollectionMapper.complete(cashRecord);
  367. String goodsName = cashCollectionMapper.selectGoodsNameByCode(cashRecord.getOrderCode());
  368. if (goodsName != null && goodsName.equals("金币充值")) {
  369. cashRecord.setOrderCode(cashRecord.getOrderCode().replace("XJ_", "XJCZ_"));
  370. //修改金币订单
  371. cashCollectionMapper.updateGoldOrder(cashRecord);
  372. }
  373. return rows > 0 ? "编辑成功" : "编辑失败";
  374. }
  375. //根据精网号查询姓名和地区
  376. @Override
  377. public Result getNameAndMarket(Integer jwcode,@RequestHeader(defaultValue = "zh_CN") String lang) {
  378. try {
  379. HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
  380. String token = request.getHeader("token");
  381. Admin admin = (Admin) JWTUtil.getUserDetailsList(String.valueOf(token), Admin.class);
  382. if (admin != null) {
  383. List<String> list = Arrays.asList(admin.getMarkets().split(","));
  384. List<String> markets = marketMapper.getMarketIds(list);
  385. // 检查用户是否存在
  386. int userCount = cashCollectionMapper.checkUserExists(jwcode);
  387. if (userCount == 0) {
  388. String message = languageTranslationUtil.translate("精网号有误!请检查", lang);
  389. return Result.error(message);
  390. }
  391. if (markets.contains("9") || markets.contains("9999")) {
  392. // 有特殊权限,可访问所有用户
  393. User user = new User();
  394. user.setMarket(cashCollectionMapper.getMarketByJwcode(jwcode));
  395. user.setName(cashCollectionMapper.getNameByJwcode(jwcode));
  396. user.setMarketName(cashCollectionMapper.getMarketNameByJwcode(jwcode));
  397. return Result.success(user);
  398. } else {
  399. // 检查用户所在市场是否在管理员权限范围内
  400. String userMarket = cashCollectionMapper.getMarketByJwcode(jwcode);
  401. if (userMarket != null && markets.contains(userMarket)) {
  402. // 有权限访问,返回用户信息
  403. User user = new User();
  404. user.setMarket(userMarket);
  405. user.setName(cashCollectionMapper.getNameByJwcode(jwcode));
  406. user.setMarketName(cashCollectionMapper.getMarketNameByJwcode(jwcode));
  407. return Result.success(user);
  408. } else {
  409. // 无权限,返回用户所属地区
  410. String userMarketName = cashCollectionMapper.getMarketNameByJwcode(jwcode);
  411. String translatedMarketName = languageTranslationUtil.translate(userMarketName, lang);
  412. String message = languageTranslationUtil.translate("无权限访问", lang);
  413. return Result.errorWithData(message, java.util.Map.of("market", translatedMarketName));
  414. }
  415. }
  416. } else {
  417. // admin 为 null,即权限验证失败
  418. String userMarketName = cashCollectionMapper.getMarketNameByJwcode(jwcode);
  419. String translatedMarketName = languageTranslationUtil.translate(userMarketName, lang);
  420. String message = languageTranslationUtil.translate("无权限访问", lang);
  421. return Result.errorWithData(message, java.util.Map.of("market", translatedMarketName));
  422. }
  423. } catch (Exception e) {
  424. e.printStackTrace();
  425. String errorMessage = languageTranslationUtil.translate("精网号有误!请检查", lang);
  426. return Result.error(errorMessage);
  427. }
  428. }
  429. //获取收款活动列表
  430. @Override
  431. public List<RechargeActivity> getActivityList() {
  432. LocalDateTime now = LocalDateTime.now();
  433. return cashCollectionMapper.getActivityList(now);
  434. }
  435. //同步g_order订单到cash_record表
  436. @Override
  437. public Object syncToCashRecord() {
  438. int total = 0;
  439. while (true) {
  440. List<GOrder> gOrders = cashCollectionMapper.getUnSync(50);
  441. if (CollectionUtils.isEmpty(gOrders)) {
  442. break;
  443. }
  444. try {
  445. // 每批独立事务
  446. processBatch(gOrders);
  447. total += gOrders.size();
  448. log.info("✅ 同步完成一批,数量: {}, 累计: {}", gOrders.size(), total);
  449. } catch (Exception e) {
  450. List<Integer> failedIds = gOrders.stream().map(GOrder::getId).collect(Collectors.toList());
  451. log.error("失败订单ID: {}", failedIds);
  452. // 可存入 error_log 表,供人工处理
  453. // 这里选择继续下一批(容忍部分失败)
  454. }
  455. if (gOrders.size() < 50) {
  456. break; // 最后一批
  457. }
  458. }
  459. return "同步完毕,成功处理 " + total + " 条";
  460. }
  461. @Override
  462. @Transactional(rollbackFor = Exception.class)
  463. public void processBatch(List<GOrder> gOrders) {
  464. for (GOrder gOrder : gOrders) {
  465. CashRecord cashRecord = new CashRecord();
  466. //构建基础信息
  467. cashRecord.setOrderType(1);
  468. cashRecord.setJwcode(gOrder.getJwcode());
  469. String name=cashCollectionMapper.getNameByJwcode(gOrder.getJwcode());
  470. if (name!=null){
  471. cashRecord.setName(name);
  472. }else cashRecord.setName("未知");
  473. cashRecord.setMarket(cashCollectionMapper.getMarketByJwcode(gOrder.getJwcode()));
  474. if (gOrder.getType().equals("gold")){ //充金豆
  475. cashRecord.setActivity("99");
  476. cashRecord.setGoodsName("Link充值金豆");
  477. cashRecord.setRemark("Link充值金豆");
  478. cashRecord.setNumUnit("个");
  479. cashRecord.setPermanentGold(0);
  480. cashRecord.setGoodNum(gOrder.getCount());
  481. }
  482. if (gOrder.getType().equals("gold_coin")){//充金币
  483. cashRecord.setActivity("98");
  484. cashRecord.setGoodsName("Link充值金币");
  485. cashRecord.setRemark("Link充值金币");
  486. cashRecord.setPermanentGold(gOrder.getCount()*100);
  487. cashRecord.setGoodNum(0);
  488. }
  489. cashRecord.setOrderCode(gOrder.getOrderNo());
  490. if (gOrder != null) {
  491. switch (gOrder.getPayStyle()) {
  492. case 3:
  493. cashRecord.setPayType("IOS内购");
  494. cashRecord.setBankCode(gOrder.getIosTransactionId());
  495. cashRecord.setReceivedMarket("4");
  496. cashRecord.setPayload("IOS");
  497. break;
  498. case 5:
  499. cashRecord.setPayType("Stripe");
  500. cashRecord.setReceivedMarket("13");
  501. cashRecord.setPayload("Stripe");
  502. break;
  503. case 6:
  504. cashRecord.setPayType("PaymentAsia");
  505. cashRecord.setReceivedMarket("13");
  506. cashRecord.setPayload("PaymentAsia");
  507. break;
  508. case 7:
  509. cashRecord.setPayType("Ipay88");
  510. cashRecord.setReceivedMarket("5");
  511. cashRecord.setPayload("Ipay88");
  512. break;
  513. case 9:
  514. cashRecord.setPayType("FirstData");
  515. cashRecord.setReceivedMarket("4");
  516. cashRecord.setBankCode(gOrder.getFirstdataIpgTransactionId());
  517. cashRecord.setPayload("FirstData");
  518. break;
  519. case 10:
  520. cashRecord.setPayType("PaySolutions");
  521. cashRecord.setReceivedMarket("24018");
  522. cashRecord.setPayload("PaySolutions");
  523. break;
  524. case 15:
  525. cashRecord.setPayType("Stripe2");
  526. cashRecord.setReceivedMarket("4");
  527. cashRecord.setPayload("Stripe2");
  528. default:
  529. break;
  530. }
  531. }
  532. cashRecord.setFreeGold(0);
  533. cashRecord.setPaymentCurrency("");
  534. cashRecord.setPaymentAmount(BigDecimal.valueOf(0));
  535. //转换时间戳,加上时区偏移
  536. cashRecord.setPayTime(LocalDateTime.ofEpochSecond(gOrder.getSuccessTime(), 0, ZoneOffset.of("+08:00")));
  537. cashRecord.setAuditTime(LocalDateTime.ofEpochSecond(gOrder.getSuccessTime(), 0, ZoneOffset.of("+08:00")));
  538. cashRecord.setStatus(3);
  539. cashRecord.setSubmitterId(99999);
  540. //存入现金库
  541. cashCollectionMapper.add(cashRecord);
  542. cashCollectionMapper.markSynced(gOrder.getId());
  543. }
  544. }
  545. @Override
  546. public CashCollection selectById(CashCollection cashCollection) {
  547. return cashCollectionMapper.selectById(cashCollection.getId());
  548. }
  549. //根据goldcoin订单号查询收款订单
  550. @Override
  551. public CashCollection selectByGoldCoinOrderCode(String orderNo) {
  552. return cashCollectionMapper.selectByGoldCoinOrderCode(orderNo);
  553. }
  554. //多条件查询收款订单列表
  555. @Override
  556. public PageInfo<PerformanceVO> performanceSelect(Integer pageNum, Integer pageSize, PerformanceDTO performanceDTO) {
  557. PageHelper.startPage(pageNum, pageSize); //必须要直接跟mapper
  558. List<PerformanceVO> performanceVOs = cashCollectionMapper.performanceSelect(performanceDTO);
  559. return new PageInfo<>(performanceVOs);
  560. }
  561. // 根据精网号和钱包 ID 查询用户钱包明细列表(分页)
  562. @Override
  563. public PageInfo<UserWalletRecordVO> selectWalletRecordsByJwcodeAndWalletId(
  564. Integer pageNum, Integer pageSize, Integer jwcode, Integer walletId) {
  565. PageHelper.startPage(pageNum, pageSize);
  566. List<UserWalletRecordVO> records = cashCollectionMapper.selectWalletRecordsByJwcodeAndWalletId(jwcode, walletId);
  567. return new PageInfo<>(records);
  568. }
  569. // 根据精网号和地区查询用户的所有钱包 ID 和金币数量(包含用户名和地区)(分页)
  570. @Override
  571. public PageInfo<UserWalletVO> selectUserWallets(Integer jwcode, String market, Integer pageNum, Integer pageSize) {
  572. PageHelper.startPage(pageNum, pageSize);
  573. List<UserWalletVO> wallets = cashCollectionMapper.selectUserWallets(jwcode, market);
  574. return new PageInfo<>(wallets);
  575. }
  576. }