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

179 lines
6.6 KiB

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