金币系统后端
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.

186 lines
7.1 KiB

6 months ago
6 months ago
4 months ago
  1. package com.example.demo.serviceImpl;
  2. import com.example.demo.Util.GoldTistV2;
  3. import com.example.demo.domain.entity.*;
  4. import com.example.demo.mapper.AuditMapper;
  5. import com.example.demo.mapper.DetailYMapper;
  6. import com.example.demo.mapper.RefundMapper;
  7. import com.example.demo.mapper.UserMapper;
  8. import com.example.demo.sevice.AuditService;
  9. import com.github.pagehelper.PageHelper;
  10. import com.github.pagehelper.PageInfo;
  11. import lombok.RequiredArgsConstructor;
  12. import org.springframework.cache.annotation.CacheConfig;
  13. import org.springframework.cache.annotation.CacheEvict;
  14. import org.springframework.cache.annotation.Cacheable;
  15. import org.springframework.stereotype.Service;
  16. import org.springframework.transaction.annotation.Transactional;
  17. import java.math.BigDecimal;
  18. import java.time.LocalDate;
  19. import java.time.Month;
  20. import java.util.Date;
  21. import java.util.List;
  22. @Transactional
  23. @Service
  24. @RequiredArgsConstructor
  25. @CacheConfig(cacheNames = "audit")
  26. public class AuditServiceImpl implements AuditService {
  27. private final UserMapper userMapper;
  28. private final AuditMapper auditMapper;
  29. private final DetailYMapper detailYMapper;
  30. private final RefundMapper refundMapper;
  31. @CacheEvict(value = {"audit", "recharge"}, allEntries = true)
  32. @Override
  33. public int add(Audit audit) {
  34. return auditMapper.insert(audit);
  35. }
  36. @CacheEvict(value = {"audit", "recharge","refund"}, allEntries = true)
  37. @Override
  38. public int edit(Audit audit) {
  39. return auditMapper.update(audit);
  40. }
  41. @CacheEvict(value = {"audit", "recharge","refund"}, allEntries = true)
  42. @Override
  43. @Transactional
  44. public int goldedit(Audit audit) throws Exception {
  45. int result = auditMapper.update(audit);
  46. if (result != 1) {
  47. throw new Exception("Failed to insert recharge data");
  48. }
  49. Integer status = audit.getStatus();
  50. if(status == 1){
  51. String jwcode=audit.getJwcode();
  52. System.out.println(jwcode);
  53. BigDecimal paidGold1 =audit.getPaidGold();
  54. BigDecimal freeGold1 =audit.getFreeGold();
  55. UserGold userGold = userMapper.selectGold(jwcode);
  56. BigDecimal buyJb =userGold.getBuyJb();
  57. buyJb = buyJb.add(paidGold1);
  58. // 设置更新后的Sumgold回到user对象
  59. userGold.setBuyJb(buyJb);
  60. LocalDate now = LocalDate.now();
  61. // 判断当前日期是在六月之前还是之后
  62. Month currentMonth = now.getMonth();
  63. boolean isBeforeJune = currentMonth.getValue() < Month.JUNE.getValue();
  64. boolean isJune = currentMonth.getValue() == Month.JUNE.getValue();
  65. boolean isAfterJune = currentMonth.getValue() > Month.JUNE.getValue();
  66. // 根据月份更新 free6 或 free12
  67. if (isBeforeJune||isJune) {
  68. // 如果是六月前,更新 free6
  69. BigDecimal free6 = userGold.getFree6().add(freeGold1);
  70. userGold.setFree6(free6);
  71. } else if (isAfterJune) {
  72. // 如果是六月后,更新 free12
  73. BigDecimal free12 = userGold.getFree12().add(freeGold1);
  74. userGold.setFree12(free12);
  75. }
  76. System.out.println(userGold+"----------------------------------------------------------");
  77. result = userMapper.updateGold(userGold);
  78. if (result != 1) {
  79. throw new Exception("Failed to insert recharge data");
  80. }
  81. int rechargeId = audit.getRechargeId();
  82. String jwCode= audit.getJwcode();
  83. String JwCode = audit.getJwcode();
  84. int activityId = audit.getActivityId();
  85. BigDecimal paidGold =audit.getPaidGold();
  86. BigDecimal freeGold =audit.getFreeGold();
  87. BigDecimal rechargeGold =audit.getRechargeGold();
  88. String remark =audit.getRemark();
  89. String Way=audit.getRechargeWay();
  90. String uuid = audit.getOrderCode();
  91. int adminId =audit.getAdminId();
  92. String activityName = audit.getActivityName();
  93. String area = audit.getArea();
  94. String username = audit.getUsername();
  95. Integer status1=audit.getStatus();
  96. String reson = audit.getReson();
  97. String name = audit.getName();
  98. System.out.println(name+"11111111111111111111111111111111111111111111111");
  99. System.out.println(username);
  100. Integer flag = audit.getFlag();
  101. Date createTime = audit.getCreateTime();
  102. DetailY detailY = new DetailY();
  103. detailY.setJwcode(JwCode);
  104. detailY.setActivityId(activityId);
  105. detailY.setRechargeCoin(paidGold);
  106. detailY.setRechargeWay(Way);
  107. detailY.setFreeCoin(freeGold);
  108. detailY.setRemark(remark);
  109. detailY.setUpdateType(0);
  110. detailY.setAdminId(adminId);
  111. detailY.setActivityName(activityName);
  112. detailY.setArea(area);
  113. detailY.setName(name);
  114. detailY.setUsername(username);
  115. detailY.setOrderCode(uuid);
  116. detailY.setStatus(status1);
  117. detailY.setReson(reson);
  118. detailY.setFlag(flag);
  119. detailY.setCreateTime(createTime);
  120. detailY.setConsumePlatform("金币系统");
  121. System.out.println(uuid+"/*/*/*-/-*/-/*-/-*/-/*-/*-/-*");
  122. detailY.setOrderCode(uuid);
  123. detailY.setFirstRecharge(0);
  124. System.out.println(detailY);
  125. // result = detailYMapper.add(detailY);
  126. if(paidGold != null && paidGold.compareTo(BigDecimal.ZERO) != 0) {
  127. GoldTistV2.addCoinNew(jwcode, 64, paidGold.doubleValue()/100, remark, 0, name, "金币充值");
  128. }
  129. if(freeGold != null && freeGold.compareTo(BigDecimal.ZERO) != 0) {
  130. GoldTistV2.addCoinNew(jwcode, 63, freeGold.doubleValue()/100, remark, 0, name, "金币充值");
  131. }
  132. }
  133. return auditMapper.update(audit);
  134. }
  135. @Override
  136. public List<Audit> search(Audit audit) {
  137. return auditMapper.select(audit);
  138. }
  139. @Cacheable(key="#root.method.name + ':'+ #pageNum + '-' + #pageSize + '-' + #audit.hashCode() ")
  140. @Override
  141. public PageInfo<Audit> searchForPage(Integer pageNum, Integer pageSize, Audit audit) {
  142. PageHelper.startPage(pageNum,pageSize);
  143. List<Audit> list= auditMapper.select(audit);
  144. return new PageInfo<>(list);
  145. }
  146. @Cacheable(key="#root.method.name")
  147. @Override
  148. public List<Detail> searchForDetail(Detail detail) {
  149. return refundMapper.select(detail);
  150. }
  151. //问题:每次更新完数据后,redis依然是老数据,无法实时更新
  152. //解决方案:除了查询操作之外,所有的操纵都要执行删除缓存
  153. @Cacheable(key = "#root.method.name + ':' + #pageNum + '-' + #pageSize + '-' + T(java.util.Objects).hashCode(#detail)")
  154. @Override
  155. public PageInfo<Detail> searchForConsumeDetail(Integer pageNum, Integer pageSize, Detail detail) {
  156. PageHelper.startPage(pageNum,pageSize);
  157. List<Detail> list= refundMapper.select(detail);
  158. return new PageInfo<>(list);
  159. }
  160. }