package com.stylefeng.guns.modular.system.service.impl;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.plugins.Page;
|
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
|
import com.stylefeng.guns.core.shiro.ShiroKit;
|
import com.stylefeng.guns.core.shiro.ShiroUser;
|
import com.stylefeng.guns.core.util.SinataUtil;
|
import com.stylefeng.guns.modular.system.model.TCheckCarActivity;
|
import com.stylefeng.guns.modular.system.model.TCheckCarActivityRecord;
|
import com.stylefeng.guns.modular.system.dao.TCheckCarActivityMapper;
|
import com.stylefeng.guns.modular.system.service.ITCheckCarActivityService;
|
import com.stylefeng.guns.modular.system.service.ITCheckCarActivityRecordService;
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.StringUtils;
|
|
import java.math.BigDecimal;
|
import java.util.*;
|
|
/**
|
* <p>
|
* 代检车活动表 服务实现类
|
* </p>
|
*
|
* @author mitao
|
* @since 2025-08-02
|
*/
|
@Service
|
public class TCheckCarActivityServiceImpl extends ServiceImpl<TCheckCarActivityMapper, TCheckCarActivity> implements ITCheckCarActivityService {
|
|
@Autowired
|
private ITCheckCarActivityRecordService tCheckCarActivityRecordService;
|
|
@Override
|
public Page<TCheckCarActivity> getOrderList(String createTime, String branchOfficeName, String name, String activityAreaCode, Integer status) {
|
ShiroUser user = ShiroKit.getUser();
|
String beginTime = null;
|
String endTime = null;
|
if (SinataUtil.isNotEmpty(createTime)){
|
String[] timeArray = createTime.split(" - ");
|
beginTime = timeArray[0];
|
endTime = timeArray[1];
|
}
|
|
String provinceCode = null;
|
String cityCode = null;
|
String areaCode = null;
|
if(StringUtils.hasLength(activityAreaCode)){
|
String[] split = activityAreaCode.split("-");
|
provinceCode = split[0];
|
cityCode = split[1];
|
areaCode = split[2];
|
}
|
Page<TCheckCarActivity> page = new PageFactory<TCheckCarActivity>().defaultPage();
|
List<TCheckCarActivity> list = baseMapper.getOrderList(page, beginTime, endTime, branchOfficeName, user.getRoleType(), user.getObjectId(), name, provinceCode, cityCode, areaCode, status);
|
list.forEach(item -> {
|
if (item.getAuditStatus().equals(1)) {
|
//判断是否开始
|
Date now = new Date();
|
if (item.getStartTime() != null && item.getStartTime().after(now)) {
|
item.setActivityStatus(0); // 未开始
|
} else if (item.getEndTime() != null && item.getEndTime().before(now)) {
|
item.setActivityStatus(2); // 已结束
|
} else if (item.getPauseFlag() != null && item.getPauseFlag().equals(1) &&
|
item.getStartTime() != null && item.getStartTime().before(now) &&
|
item.getEndTime() != null && item.getEndTime().after(now)) {
|
item.setActivityStatus(3); // 已暂停
|
} else if (item.getStartTime() != null && item.getStartTime().before(now) &&
|
item.getEndTime() != null && item.getEndTime().after(now)) {
|
item.setActivityStatus(1); // 进行中
|
}else {
|
item.setActivityStatus(0); // 未开始
|
}
|
}
|
});
|
return page.setRecords(list);
|
}
|
|
@Override
|
public Map<String, Object> getActivityStatistics(Integer activityId) {
|
Map<String, Object> result = new HashMap<>();
|
|
// 获取活动基本信息
|
TCheckCarActivity activity = selectById(activityId);
|
if (activity == null) {
|
return result;
|
}
|
|
// 优惠券总计数量
|
Integer totalCoupons = activity.getCouponNum();
|
|
// 已领取优惠券数量
|
Integer receivedCoupons = activity.getReceivedNum() != null ? activity.getReceivedNum() : 0;
|
|
// 剩余优惠券数量
|
Integer remainingCoupons = totalCoupons - receivedCoupons;
|
|
// 优惠券总计金额
|
BigDecimal couponAmount = activity.getCouponAmount();
|
BigDecimal totalAmount = couponAmount.multiply(new BigDecimal(totalCoupons));
|
|
// 查询已使用和未使用的统计
|
List<TCheckCarActivityRecord> records = tCheckCarActivityRecordService.selectList(
|
new EntityWrapper<TCheckCarActivityRecord>().eq("checkCarActivityId", activityId)
|
);
|
|
long usedCount = records.stream().filter(record -> record.getStatus() != null && record.getStatus() == 1).count();
|
long unusedCount = records.stream().filter(record -> record.getStatus() != null && record.getStatus() == 0).count();
|
|
// 已使用金额
|
BigDecimal usedAmount = couponAmount.multiply(new BigDecimal(usedCount));
|
|
// 未使用金额
|
BigDecimal unusedAmount = couponAmount.multiply(new BigDecimal(unusedCount));
|
|
result.put("totalCoupons", totalCoupons);
|
result.put("receivedCoupons", receivedCoupons);
|
result.put("remainingCoupons", remainingCoupons);
|
result.put("totalAmount", totalAmount);
|
result.put("usedAmount", usedAmount);
|
result.put("unusedAmount", unusedAmount);
|
|
return result;
|
}
|
|
@Override
|
public Page<TCheckCarActivityRecord> getActivityRecords(Integer activityId, String userPhone) {
|
Page<TCheckCarActivityRecord> page = new PageFactory<TCheckCarActivityRecord>().defaultPage();
|
|
// 构建查询条件
|
EntityWrapper<TCheckCarActivityRecord> wrapper = new EntityWrapper<>();
|
wrapper.eq("checkCarActivityId", activityId);
|
|
// 如果提供了手机号搜索条件,添加模糊查询
|
if (StringUtils.hasText(userPhone)) {
|
wrapper.like("userPhone", userPhone);
|
}
|
|
// 按领取时间倒序排列
|
wrapper.orderBy("receiveTime", false);
|
|
// 分页查询记录
|
List<TCheckCarActivityRecord> records = tCheckCarActivityRecordService.selectPage(page, wrapper).getRecords();
|
return page.setRecords(records);
|
}
|
}
|