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

122 lines
4.5 KiB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
  1. package com.example.demo.serviceImpl;
  2. import com.example.demo.domain.entity.Audit;
  3. import com.example.demo.domain.entity.User;
  4. import com.example.demo.domain.vo.ConsumeDetail;
  5. import com.example.demo.mapper.AuditMapper;
  6. import com.example.demo.mapper.RechargeMapper;
  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.List;
  21. @Transactional
  22. @Service
  23. @RequiredArgsConstructor
  24. @CacheConfig(cacheNames = "audit")
  25. public class AuditServiceImpl implements AuditService {
  26. private final UserMapper userMapper;
  27. private final AuditMapper auditMapper;
  28. @CacheEvict(value = {"audit", "recharge"}, allEntries = true)
  29. @Override
  30. public int add(Audit audit) {
  31. return auditMapper.insert(audit);
  32. }
  33. @CacheEvict(value = {"audit", "recharge","refund"}, allEntries = true)
  34. @Override
  35. public int edit(Audit audit) {
  36. return auditMapper.update(audit);
  37. }
  38. @CacheEvict(value = {"audit", "recharge","refund"}, allEntries = true)
  39. @Override
  40. public int goldedit(Audit audit) throws Exception {
  41. int result = auditMapper.update(audit);
  42. if (result != 1) {
  43. throw new Exception("Failed to insert recharge data");
  44. }
  45. Integer status = audit.getStatus();
  46. if(status == 1){
  47. String jwcode=audit.getJwcode();
  48. BigDecimal paidGold1 =audit.getPaidGold();
  49. BigDecimal freeGold1 =audit.getFreeGold();
  50. User user = userMapper.select(jwcode);
  51. BigDecimal buyJb =user.getBuyJb();
  52. buyJb = buyJb.add(paidGold1);
  53. // 设置更新后的Sumgold回到user对象
  54. user.setBuyJb(buyJb);
  55. LocalDate now = LocalDate.now();
  56. // 判断当前日期是在六月之前还是之后
  57. Month currentMonth = now.getMonth();
  58. boolean isBeforeJune = currentMonth.getValue() < Month.JUNE.getValue();
  59. boolean isJune = currentMonth.getValue() == Month.JUNE.getValue();
  60. boolean isAfterJune = currentMonth.getValue() > Month.JUNE.getValue();
  61. // 根据月份更新 free6 或 free12
  62. if (isBeforeJune||isJune) {
  63. // 如果是六月前,更新 free6
  64. BigDecimal free6 = user.getFree6().add(freeGold1);
  65. user.setFree6(free6);
  66. } else if (isAfterJune) {
  67. // 如果是六月后,更新 free12
  68. BigDecimal free12 = user.getFree12().add(freeGold1);
  69. user.setFree12(free12);
  70. }
  71. System.out.println(user+"----------------------------------------------------------");
  72. result = userMapper.update(user);
  73. if (result != 1) {
  74. throw new Exception("Failed to insert recharge data");
  75. }
  76. }
  77. return auditMapper.update(audit);
  78. }
  79. @Override
  80. public List<Audit> search(Audit audit) {
  81. return auditMapper.select(audit);
  82. }
  83. @Cacheable(key="#root.method.name + ':'+ #pageNum + '-' + #pageSize + '-' + #audit.hashCode() ")
  84. @Override
  85. public PageInfo<Audit> searchForPage(Integer pageNum, Integer pageSize, Audit audit) {
  86. PageHelper.startPage(pageNum,pageSize);
  87. List<Audit> list= auditMapper.select(audit);
  88. return new PageInfo<>(list);
  89. }
  90. @Cacheable(key="#root.method.name")
  91. @Override
  92. public List<ConsumeDetail> searchForDetail(ConsumeDetail consumeDetail) {
  93. return auditMapper.selectCon(consumeDetail);
  94. }
  95. //问题:每次更新完数据后,redis依然是老数据,无法实时更新
  96. //解决方案:除了查询操作之外,所有的操纵都要执行删除缓存
  97. @Cacheable(key="#root.method.name + ':'+ #pageNum + '-' + #pageSize + '-' + #consumeDetail.hashCode() ")
  98. @Override
  99. public PageInfo<ConsumeDetail> searchForConsumeDetail(Integer pageNum, Integer pageSize, ConsumeDetail consumeDetail) {
  100. PageHelper.startPage(pageNum,pageSize);
  101. List<ConsumeDetail> list= auditMapper.selectCon(consumeDetail);
  102. return new PageInfo<>(list);
  103. }
  104. }