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.
204 lines
7.4 KiB
204 lines
7.4 KiB
package com.example.demo.serviceImpl;
|
|
|
|
import com.example.demo.domain.entity.Audit;
|
|
import com.example.demo.domain.entity.Detail;
|
|
import com.example.demo.domain.entity.Recharge;
|
|
import com.example.demo.domain.entity.User;
|
|
import com.example.demo.domain.vo.RechargeVo;
|
|
import com.example.demo.domain.vo.Result;
|
|
import com.example.demo.mapper.AuditMapper;
|
|
import com.example.demo.mapper.DetailMapper;
|
|
import com.example.demo.mapper.RechargeMapper;
|
|
import com.example.demo.mapper.UserMapper;
|
|
import com.example.demo.sevice.RechargeService;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageInfo;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.cache.annotation.CacheConfig;
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
import org.springframework.cache.annotation.CachePut;
|
|
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;
|
|
import java.util.UUID;
|
|
|
|
@Transactional
|
|
@Service
|
|
@RequiredArgsConstructor
|
|
@CacheConfig(cacheNames = "recharge")
|
|
public class RechargeServiceImpl implements RechargeService {
|
|
@Autowired
|
|
private RechargeMapper rechargeMapper;
|
|
@Autowired
|
|
private AuditMapper auditMapper;
|
|
@Autowired
|
|
private DetailMapper detailMapper;
|
|
@Autowired
|
|
private UserMapper userMapper;
|
|
@Override
|
|
@Transactional
|
|
|
|
@CacheEvict(value = "recharge",allEntries = true)
|
|
public int add(Recharge recharge) throws Exception {
|
|
// return rechargeMapper.insert(recharge);
|
|
|
|
String uuid = UUID.randomUUID().toString().replace("-", ""); // 去掉UUID中的'-'
|
|
recharge.setOrderCode(uuid);
|
|
int result = rechargeMapper.insert(recharge);
|
|
if (result != 1) {
|
|
throw new Exception("Failed to insert recharge data");
|
|
}
|
|
System.out.println(recharge);
|
|
|
|
// 检查充值金额是否在有效范围内
|
|
BigDecimal RechargeGold = recharge.getRechargeGold();
|
|
BigDecimal PaidGold = recharge.getPaidGold();
|
|
BigDecimal FreeGold = recharge.getFreeGold();
|
|
|
|
if (RechargeGold.compareTo(BigDecimal.ZERO) < 0 || RechargeGold.compareTo(new BigDecimal("999999")) > 0 ||
|
|
PaidGold.compareTo(BigDecimal.ZERO) < 0 || PaidGold.compareTo(new BigDecimal("999999")) > 0 ||
|
|
FreeGold.compareTo(BigDecimal.ZERO) < 0 || FreeGold.compareTo(new BigDecimal("999999")) > 0) {
|
|
throw new Exception("充值金额有误,金额必须在0到999999之间!");
|
|
}
|
|
|
|
int rechargeId = recharge.getRechargeId();
|
|
String jwCode= recharge.getJwcode();
|
|
String JwCode = recharge.getJwcode();
|
|
int activityId = recharge.getActivityId();
|
|
BigDecimal paidGold =recharge.getPaidGold();
|
|
BigDecimal freeGold =recharge.getFreeGold();
|
|
BigDecimal rechargeGold =recharge.getRechargeGold();
|
|
String rechargeWay =recharge.getRechargeWay();
|
|
String remark =recharge.getRemark();
|
|
int adminId =recharge.getAdminId();
|
|
|
|
|
|
Detail detail = new Detail();
|
|
|
|
//根据jwcode和充值类型判断detail有没有,有首充标识设为0,否者设为1
|
|
String jwcode= recharge.getJwcode();
|
|
|
|
Integer count=rechargeMapper.getAllByjwAndup(jwcode);
|
|
System.out.println("count:-----"+count);
|
|
if(count==0){
|
|
detail.setFirstRecharge(1);
|
|
}else{
|
|
detail.setFirstRecharge(0);
|
|
}
|
|
detail.setJwcode(JwCode);
|
|
detail.setActivityId(activityId);
|
|
detail.setRechargeCoin(rechargeGold);
|
|
detail.setFreeCoin(freeGold);
|
|
detail.setRechargeWay(rechargeWay);
|
|
detail.setRemark(remark);
|
|
detail.setUpdateType(0);
|
|
detail.setAdminId(adminId);
|
|
detail.setConsumePlatform("金币系统");
|
|
|
|
|
|
System.out.println(uuid+"/*/*/*-/-*/-/*-/-*/-/*-/*-/-*");
|
|
detail.setOrderCode(uuid);
|
|
System.out.println(detail);
|
|
result = detailMapper.add(detail);
|
|
if (result != 1) {
|
|
throw new Exception("Failed to insert another entity");
|
|
}
|
|
|
|
// BigDecimal paidGold1 =recharge.getPaidGold();
|
|
// BigDecimal freeGold1 =recharge.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 isAfterJune = currentMonth.getValue() > Month.JUNE.getValue();
|
|
//
|
|
//// 根据月份更新 free6 或 free12
|
|
// if (isBeforeJune) {
|
|
// // 如果是六月前,更新 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 another entity");
|
|
}
|
|
|
|
int detailId = detail.getDetailId();
|
|
|
|
System.out.println(detailId);
|
|
Audit audit = new Audit();
|
|
audit.setRechargeId(rechargeId);
|
|
audit.setJwcode(jwCode);
|
|
audit.setDetailId(detailId);
|
|
System.out.println(audit+"---------------------------------------");
|
|
result = auditMapper.insert(audit);
|
|
if (result != 1) {
|
|
throw new Exception("Failed to insert another entity");
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
}
|
|
@CacheEvict(value = "recharge",allEntries = true)
|
|
@Override
|
|
public int edit(Recharge recharge) throws Exception {
|
|
recharge.setFlag(0);
|
|
return rechargeMapper.update(recharge);
|
|
}
|
|
@Override
|
|
public Recharge findById(int id) throws Exception {
|
|
return null;
|
|
}
|
|
@Cacheable(key="#root.method.name")
|
|
@Override
|
|
public List<RechargeVo> search(RechargeVo rechargeVo) {
|
|
return rechargeMapper.select(rechargeVo);
|
|
}
|
|
@Cacheable(key="#root.method.name + ':'+ #pageNum + '-' + #pageSize + '-' + #rechargeVo.hashCode() ")
|
|
@Override
|
|
public PageInfo<RechargeVo> searchForPage(Integer pageNum, Integer pageSize, RechargeVo rechargeVo) {
|
|
PageHelper.startPage(pageNum, pageSize);
|
|
List<RechargeVo> list= rechargeMapper.select(rechargeVo);
|
|
return new PageInfo<>(list);
|
|
}
|
|
|
|
@Cacheable(key="#root.method.name")
|
|
@Override
|
|
public int getAllByjwAndup(String jwcode) {
|
|
return rechargeMapper.getAllByjwAndup(jwcode);
|
|
}
|
|
@CacheEvict(value = "recharge",allEntries = true)
|
|
@Override
|
|
public Result addRecharges(List<Recharge> recharges) {
|
|
try {
|
|
for (Recharge recharge : recharges) {
|
|
add(recharge); // 调用add方法处理每个Recharge对象
|
|
}
|
|
return Result.success("批量添加成功");
|
|
} catch (Exception e) {
|
|
return Result.error("批量添加失败: " + e.getMessage());
|
|
}
|
|
}
|
|
}
|
|
|