122 lines
4.5 KiB
122 lines
4.5 KiB
package com.example.demo.serviceImpl;
|
|
|
|
|
|
|
|
|
|
import com.example.demo.domain.entity.Audit;
|
|
import com.example.demo.domain.entity.User;
|
|
import com.example.demo.domain.vo.ConsumeDetail;
|
|
import com.example.demo.mapper.AuditMapper;
|
|
import com.example.demo.mapper.RechargeMapper;
|
|
import com.example.demo.mapper.UserMapper;
|
|
import com.example.demo.sevice.AuditService;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageInfo;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.cache.annotation.CacheConfig;
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.time.LocalDate;
|
|
import java.time.Month;
|
|
import java.util.List;
|
|
@Transactional
|
|
@Service
|
|
@RequiredArgsConstructor
|
|
@CacheConfig(cacheNames = "audit")
|
|
public class AuditServiceImpl implements AuditService {
|
|
|
|
private final UserMapper userMapper;
|
|
private final AuditMapper auditMapper;
|
|
|
|
@CacheEvict(value = {"audit", "recharge"}, allEntries = true)
|
|
@Override
|
|
public int add(Audit audit) {
|
|
return auditMapper.insert(audit);
|
|
}
|
|
|
|
@CacheEvict(value = {"audit", "recharge","refund"}, allEntries = true)
|
|
@Override
|
|
public int edit(Audit audit) {
|
|
return auditMapper.update(audit);
|
|
}
|
|
|
|
@CacheEvict(value = {"audit", "recharge","refund"}, allEntries = true)
|
|
@Override
|
|
public int goldedit(Audit audit) throws Exception {
|
|
int result = auditMapper.update(audit);
|
|
if (result != 1) {
|
|
throw new Exception("Failed to insert recharge data");
|
|
}
|
|
Integer status = audit.getStatus();
|
|
if(status == 1){
|
|
String jwcode=audit.getJwcode();
|
|
BigDecimal paidGold1 =audit.getPaidGold();
|
|
BigDecimal freeGold1 =audit.getFreeGold();
|
|
User user = userMapper.select(jwcode);
|
|
BigDecimal buyJb =user.getBuyJb();
|
|
|
|
buyJb = buyJb.add(paidGold1);
|
|
|
|
// 设置更新后的Sumgold回到user对象
|
|
user.setBuyJb(buyJb);
|
|
LocalDate now = LocalDate.now();
|
|
|
|
// 判断当前日期是在六月之前还是之后
|
|
Month currentMonth = now.getMonth();
|
|
boolean isBeforeJune = currentMonth.getValue() < Month.JUNE.getValue();
|
|
boolean isJune = currentMonth.getValue() == Month.JUNE.getValue();
|
|
boolean isAfterJune = currentMonth.getValue() > Month.JUNE.getValue();
|
|
|
|
// 根据月份更新 free6 或 free12
|
|
if (isBeforeJune||isJune) {
|
|
// 如果是六月前,更新 free6
|
|
BigDecimal free6 = user.getFree6().add(freeGold1);
|
|
user.setFree6(free6);
|
|
} else if (isAfterJune) {
|
|
// 如果是六月后,更新 free12
|
|
BigDecimal free12 = user.getFree12().add(freeGold1);
|
|
user.setFree12(free12);
|
|
}
|
|
|
|
System.out.println(user+"----------------------------------------------------------");
|
|
result = userMapper.update(user);
|
|
if (result != 1) {
|
|
throw new Exception("Failed to insert recharge data");
|
|
}
|
|
}
|
|
return auditMapper.update(audit);
|
|
}
|
|
|
|
@Override
|
|
public List<Audit> search(Audit audit) {
|
|
return auditMapper.select(audit);
|
|
}
|
|
@Cacheable(key="#root.method.name + ':'+ #pageNum + '-' + #pageSize + '-' + #audit.hashCode() ")
|
|
@Override
|
|
public PageInfo<Audit> searchForPage(Integer pageNum, Integer pageSize, Audit audit) {
|
|
PageHelper.startPage(pageNum,pageSize);
|
|
List<Audit> list= auditMapper.select(audit);
|
|
return new PageInfo<>(list);
|
|
}
|
|
@Cacheable(key="#root.method.name")
|
|
@Override
|
|
public List<ConsumeDetail> searchForDetail(ConsumeDetail consumeDetail) {
|
|
return auditMapper.selectCon(consumeDetail);
|
|
}
|
|
|
|
//问题:每次更新完数据后,redis依然是老数据,无法实时更新
|
|
|
|
//解决方案:除了查询操作之外,所有的操纵都要执行删除缓存
|
|
|
|
@Cacheable(key="#root.method.name + ':'+ #pageNum + '-' + #pageSize + '-' + #consumeDetail.hashCode() ")
|
|
@Override
|
|
public PageInfo<ConsumeDetail> searchForConsumeDetail(Integer pageNum, Integer pageSize, ConsumeDetail consumeDetail) {
|
|
PageHelper.startPage(pageNum,pageSize);
|
|
List<ConsumeDetail> list= auditMapper.selectCon(consumeDetail);
|
|
return new PageInfo<>(list);
|
|
}
|
|
}
|