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

120 lines
4.4 KiB

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
10 months ago
11 months ago
11 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
11 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
11 months ago
10 months ago
11 months ago
11 months ago
11 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
10 months ago
11 months ago
  1. package com.example.demo.serviceImpl;
  2. import com.example.demo.domain.entity.Detail;
  3. import com.example.demo.mapper.RefundMapper;
  4. import com.example.demo.sevice.RefundService;
  5. import com.github.pagehelper.PageHelper;
  6. import com.github.pagehelper.PageInfo;
  7. import lombok.RequiredArgsConstructor;
  8. import org.springframework.cache.annotation.CacheConfig;
  9. import org.springframework.cache.annotation.CacheEvict;
  10. import org.springframework.cache.annotation.Cacheable;
  11. import org.springframework.stereotype.Service;
  12. import org.springframework.transaction.annotation.Transactional;
  13. import java.util.List;
  14. import java.util.UUID;
  15. @RequiredArgsConstructor
  16. @Transactional
  17. @Service
  18. @CacheConfig(cacheNames = "refund")
  19. public class RefundServiceImpl implements RefundService {
  20. private final RefundMapper refundMapper;
  21. @CacheEvict(value = {"refund", "recharge"}, allEntries = true)
  22. @Override
  23. public int add(Detail detail) {
  24. // 生成UUID作为订单编号
  25. String uuid = UUID.randomUUID().toString().replaceAll("-", ""); // 去掉UUID中的'-'
  26. detail.setOrderCode(uuid);
  27. return refundMapper.insert(detail);
  28. }
  29. @CacheEvict(value = {"refund", "recharge"}, allEntries = true) @Override
  30. public int addAudit(Detail detail) {
  31. return refundMapper.insertAudit(detail);
  32. }
  33. //自动软删除数据加更新数据
  34. @CacheEvict(value = {"refund", "recharge"}, allEntries = true) @Override
  35. public void edit(Detail newDetail) {
  36. // 获取旧的明细记录
  37. Detail oldDetail = refundMapper.selectByDetailId(newDetail.getDetailId());
  38. if (oldDetail == null || oldDetail.getDetailFlag() ==0) {
  39. throw new IllegalArgumentException("该记录不存在或已被隐藏!");
  40. }
  41. // 软删除旧记录
  42. refundMapper.update(oldDetail.getDetailId());
  43. // 将新的字段值复制到旧记录中,未修改的字段保持旧值
  44. if (newDetail.getJwcode() == null) newDetail.setJwcode(oldDetail.getJwcode());
  45. if (newDetail.getRefundType() == null) newDetail.setRefundType(oldDetail.getRefundType());
  46. if (newDetail.getRefundGoods() == null) newDetail.setRefundGoods(oldDetail.getRefundGoods());
  47. if (newDetail.getRechargeCoin() == null) newDetail.setRechargeCoin(oldDetail.getRechargeCoin());
  48. if (newDetail.getFreeCoin() == null) newDetail.setFreeCoin(oldDetail.getFreeCoin());
  49. if (newDetail.getTaskCoin() == null) newDetail.setTaskCoin(oldDetail.getTaskCoin());
  50. if (newDetail.getRemark() == null) newDetail.setRemark(oldDetail.getRemark());
  51. if (newDetail.getAdminId() == null) newDetail.setAdminId(oldDetail.getAdminId());
  52. // 插入新记录
  53. newDetail.setDetailId(null); // 清空 ID,让其自动生成
  54. newDetail.setDetailFlag(1); // 确保新记录未被删除
  55. refundMapper.insert(newDetail);
  56. }
  57. @Override
  58. @CacheEvict(value = {"refund", "recharge"}, allEntries = true) public int update(Integer contactId) {
  59. return refundMapper.updateOrderCode(contactId);
  60. }
  61. @Cacheable(key="#root.method.name")
  62. @Override
  63. public boolean existsByContactId(Integer contactId) {
  64. return refundMapper.existsByContactId(contactId);
  65. }
  66. @CacheEvict(value = {"refund", "recharge"}, allEntries = true)
  67. @Override
  68. public int softDelete(Integer detailId) {
  69. return refundMapper.update(detailId);
  70. }
  71. @Cacheable(key="#root.method.name")
  72. @Override
  73. public Detail selectByOrderCode(String orderCode) {
  74. return refundMapper.selectByOrderCode(orderCode);
  75. }
  76. @Cacheable(key="#root.method.name")
  77. @Override
  78. public Detail selectByJWCODE(String jwcode) {
  79. return refundMapper.selectByJWCODE(jwcode);
  80. }
  81. @Cacheable(key="#root.method.name")
  82. @Override
  83. public Detail selectByDetailId(Integer detailId) {
  84. return refundMapper.selectByDetailId(detailId);
  85. }
  86. @Cacheable(key="#root.method.name")
  87. @Override
  88. public List<Detail> search(Detail detail) {
  89. return refundMapper.select(detail);
  90. }
  91. @Cacheable(key="#root.method.name + ':'+ #pageNum + '-' + #pageSize + '-' + #detail.auditStatus ")
  92. @Override
  93. public PageInfo<Detail> searchForPage(Integer pageNum, Integer pageSize, Detail detail) {
  94. PageHelper.startPage(pageNum, pageSize);
  95. List<Detail> list = refundMapper.select(detail);
  96. return new PageInfo<>(list);
  97. }
  98. }