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.
155 lines
5.4 KiB
155 lines
5.4 KiB
package com.example.demo.serviceImpl;
|
|
|
|
|
|
import com.example.demo.domain.entity.Detail;
|
|
import com.example.demo.domain.vo.RefundA;
|
|
import com.example.demo.mapper.RefundMapper;
|
|
import com.example.demo.sevice.RefundService;
|
|
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.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
|
|
|
|
@RequiredArgsConstructor
|
|
@Transactional
|
|
@Service
|
|
@CacheConfig(cacheNames = "refund")
|
|
public class RefundServiceImpl implements RefundService {
|
|
private final RefundMapper refundMapper;
|
|
|
|
@CacheEvict(value = {"refund", "audit"}, allEntries = true)
|
|
@Override
|
|
public int add(Detail detail) {
|
|
// 生成UUID作为订单编号
|
|
String uuid = UUID.randomUUID().toString().replaceAll("-", ""); // 去掉UUID中的'-'
|
|
detail.setOrderCode(uuid);
|
|
return refundMapper.insert(detail);
|
|
}
|
|
|
|
@CacheEvict(value = {"refund", "audit"}, allEntries = true)
|
|
@Override
|
|
public int addAudit(Detail detail) {
|
|
return refundMapper.insertAudit(detail);
|
|
}
|
|
|
|
//自动软删除数据加更新数据
|
|
@CacheEvict(value = {"refund", "audit"}, allEntries = true)
|
|
@Override
|
|
public void edit(Detail newDetail) {
|
|
// 获取旧的明细记录
|
|
Detail oldDetail = refundMapper.selectByDetailId(newDetail.getDetailId());
|
|
|
|
if (oldDetail == null || oldDetail.getDetailFlag() == 0) {
|
|
throw new IllegalArgumentException("该记录不存在或已被隐藏!");
|
|
}
|
|
|
|
// 软删除旧记录
|
|
refundMapper.update(oldDetail.getDetailId());
|
|
|
|
// 将新的字段值复制到旧记录中,未修改的字段保持旧值
|
|
if (newDetail.getJwcode() == null) newDetail.setJwcode(oldDetail.getJwcode());
|
|
if (newDetail.getRefundType() == null) newDetail.setRefundType(oldDetail.getRefundType());
|
|
if (newDetail.getRefundGoods() == null) newDetail.setRefundGoods(oldDetail.getRefundGoods());
|
|
if (newDetail.getRechargeCoin() == null) newDetail.setRechargeCoin(oldDetail.getRechargeCoin());
|
|
if (newDetail.getFreeCoin() == null) newDetail.setFreeCoin(oldDetail.getFreeCoin());
|
|
if (newDetail.getTaskCoin() == null) newDetail.setTaskCoin(oldDetail.getTaskCoin());
|
|
if (newDetail.getRemark() == null) newDetail.setRemark(oldDetail.getRemark());
|
|
if (newDetail.getAdminId() == null) newDetail.setAdminId(oldDetail.getAdminId());
|
|
|
|
// 插入新记录
|
|
newDetail.setDetailId(null); // 清空 ID,让其自动生成
|
|
newDetail.setDetailFlag(1); // 确保新记录未被删除
|
|
refundMapper.insert(newDetail);
|
|
}
|
|
|
|
@Override
|
|
@CacheEvict(value = {"refund", "recharge"}, allEntries = true)
|
|
public int update(Integer contactId) {
|
|
return refundMapper.updateOrderCode(contactId);
|
|
}
|
|
|
|
|
|
@Override
|
|
public boolean existsByContactId(Integer contactId) {
|
|
return refundMapper.existsByContactId(contactId);
|
|
}
|
|
|
|
@CacheEvict(value = {"refund", "recharge"}, allEntries = true)
|
|
@Override
|
|
public int softDelete(Integer detailId) {
|
|
return refundMapper.update(detailId);
|
|
}
|
|
|
|
|
|
@Override
|
|
public Detail selectByOrderCode(String orderCode) {
|
|
return refundMapper.selectByOrderCode(orderCode);
|
|
}
|
|
|
|
|
|
@Override
|
|
public Detail selectByJWCODE(String jwcode) {
|
|
return refundMapper.selectByJWCODE(jwcode);
|
|
}
|
|
|
|
|
|
@Override
|
|
public Detail selectByDetailId(Integer detailId) {
|
|
return refundMapper.selectByDetailId(detailId);
|
|
}
|
|
|
|
@Override
|
|
public List<Detail> search(Detail detail) {
|
|
return refundMapper.select(detail);
|
|
}
|
|
|
|
|
|
@Cacheable(key = "#root.method.name + ':' + #pageNum + '-' + #pageSize + '-' + T(java.util.Objects).hashCode(#detail)")
|
|
@Override
|
|
public PageInfo<Detail> searchForPage(Integer pageNum, Integer pageSize, Detail detail) {
|
|
PageHelper.startPage(pageNum, pageSize);
|
|
List<Detail> list = refundMapper.select(detail);
|
|
return new PageInfo<>(list);
|
|
}
|
|
|
|
// @Override
|
|
// public List<RefundA> getRefundA(RefundA refundA) {
|
|
// return refundMapper.getRefundA(refundA);
|
|
// }
|
|
|
|
@Override
|
|
public List<RefundA> getRefundA(RefundA refundA) {
|
|
// 执行原始查询,获取实际存在的分类及其汇总值
|
|
List<RefundA> result = refundMapper.getRefundA(refundA);
|
|
|
|
// 定义完整的分类列表
|
|
List<String> fullStatuses = Arrays.asList("待审核", "已通过", "已驳回");
|
|
|
|
// 遍历分类列表,检查哪些分类在查询结果中缺失,并为其补充默认值
|
|
for (String status : fullStatuses) {
|
|
boolean categoryExists = result.stream()
|
|
.anyMatch(refund -> status.equals(refund.getStatus()));
|
|
|
|
if (!categoryExists) {
|
|
// 如果分类缺失,补充默认值
|
|
RefundA defaultRefund = new RefundA();
|
|
defaultRefund.setStatus(status);
|
|
defaultRefund.setAmount(BigDecimal.ZERO); // 默认值为 0
|
|
result.add(defaultRefund);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|