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.
|
|
package com.example.demo.serviceImpl;
import com.example.demo.domain.entity.*; import com.example.demo.domain.vo.ConsumeDetail; import com.example.demo.mapper.*; import com.example.demo.sevice.AuditService; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import lombok.Data; 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.Date; import java.util.List;
@Transactional @Service @RequiredArgsConstructor @CacheConfig(cacheNames = "audit") public class AuditServiceImpl implements AuditService {
private final UserMapper userMapper; private final AuditMapper auditMapper; private final DetailYMapper detailYMapper; private final RefundMapper refundMapper;
@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 @Transactional 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(); System.out.println(jwcode); BigDecimal paidGold1 =audit.getPaidGold(); BigDecimal freeGold1 =audit.getFreeGold(); UserGold userGold = userMapper.selectGold(jwcode); BigDecimal buyJb =userGold.getBuyJb();
buyJb = buyJb.add(paidGold1);
// 设置更新后的Sumgold回到user对象
userGold.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 = userGold.getFree6().add(freeGold1); userGold.setFree6(free6); } else if (isAfterJune) { // 如果是六月后,更新 free12
BigDecimal free12 = userGold.getFree12().add(freeGold1); userGold.setFree12(free12); }
System.out.println(userGold+"----------------------------------------------------------"); result = userMapper.updateGold(userGold); if (result != 1) { throw new Exception("Failed to insert recharge data"); }
int rechargeId = audit.getRechargeId(); String jwCode= audit.getJwcode(); String JwCode = audit.getJwcode(); int activityId = audit.getActivityId(); BigDecimal paidGold =audit.getPaidGold(); BigDecimal freeGold =audit.getFreeGold(); BigDecimal rechargeGold =audit.getRechargeGold(); String remark =audit.getRemark(); String Way=audit.getRechargeWay(); String uuid = audit.getOrderCode(); int adminId =audit.getAdminId(); String activityName = audit.getActivityName(); String area = audit.getArea(); String username = audit.getUsername(); Integer status1=audit.getStatus(); String reson = audit.getReson(); String name = audit.getName(); System.out.println(name+"11111111111111111111111111111111111111111111111"); System.out.println(username); Integer flag = audit.getFlag(); Date createTime = audit.getCreateTime();
DetailY detailY = new DetailY(); detailY.setJwcode(JwCode); detailY.setActivityId(activityId); detailY.setRechargeCoin(paidGold); detailY.setRechargeWay(Way); detailY.setFreeCoin(freeGold); detailY.setRemark(remark); detailY.setUpdateType(0); detailY.setAdminId(adminId); detailY.setActivityName(activityName); detailY.setArea(area); detailY.setName(name); detailY.setUsername(username); detailY.setOrderCode(uuid); detailY.setStatus(status1); detailY.setReson(reson); detailY.setFlag(flag); detailY.setCreateTime(createTime); detailY.setConsumePlatform("金币系统");
System.out.println(uuid+"/*/*/*-/-*/-/*-/-*/-/*-/*-/-*"); detailY.setOrderCode(uuid); System.out.println(detailY); result = detailYMapper.add(detailY); if (result != 1) { throw new Exception("Failed to insert another entity"); } } 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<Detail> searchForDetail(Detail detail) { return refundMapper.select(detail); }
//问题:每次更新完数据后,redis依然是老数据,无法实时更新
//解决方案:除了查询操作之外,所有的操纵都要执行删除缓存
@Cacheable(key = "#root.method.name + ':' + #pageNum + '-' + #pageSize + '-' + T(java.util.Objects).hashCode(#detail)") @Override public PageInfo<Detail> searchForConsumeDetail(Integer pageNum, Integer pageSize, Detail detail) { PageHelper.startPage(pageNum,pageSize); List<Detail> list= refundMapper.select(detail); return new PageInfo<>(list); } }
|