领取
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package com.czg.service.market.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.czg.market.entity.MkShopCouponRecord;
|
||||
|
||||
/**
|
||||
* 优惠券发放记录表 映射层。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-09-13
|
||||
*/
|
||||
public interface MkShopCouponRecordMapper extends BaseMapper<MkShopCouponRecord> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.czg.service.market.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.czg.account.entity.UserInfo;
|
||||
import com.czg.account.service.UserInfoService;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.market.dto.MkShopCouponRecordDTO;
|
||||
import com.czg.market.entity.MkShopCouponRecord;
|
||||
import com.czg.market.service.MkShopCouponRecordService;
|
||||
import com.czg.service.market.mapper.MkShopCouponRecordMapper;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 优惠券发放记录表 服务层实现。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-09-13
|
||||
*/
|
||||
@Service
|
||||
public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecordMapper, MkShopCouponRecord> implements MkShopCouponRecordService {
|
||||
|
||||
|
||||
@DubboReference
|
||||
private UserInfoService userInfoService;
|
||||
|
||||
@Override
|
||||
public Page<MkShopCouponRecordDTO> getRecord(String search, MkShopCouponRecordDTO mkShopCouponRecordDTO) {
|
||||
Map<Long, UserInfo> userInfoMap = new HashMap<>();
|
||||
if (StrUtil.isNotBlank(search)) {
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
queryWrapper.and(q -> {
|
||||
q.like(UserInfo::getId, search).or(r -> {
|
||||
r.like(UserInfo::getNickName, search);
|
||||
}).or(s -> {
|
||||
s.like(UserInfo::getPhone, search);
|
||||
});
|
||||
});
|
||||
List<UserInfo> userInfos = userInfoService.list(queryWrapper);
|
||||
if (CollUtil.isNotEmpty(userInfos)) {
|
||||
userInfoMap = userInfos.stream().collect(Collectors.toMap(UserInfo::getId, userInfo -> userInfo));
|
||||
} else {
|
||||
return new Page<>();
|
||||
}
|
||||
}
|
||||
QueryWrapper recordQueryWrapper = new QueryWrapper();
|
||||
recordQueryWrapper.eq(MkShopCouponRecord::getShopId, mkShopCouponRecordDTO.getShopId())
|
||||
.eq(MkShopCouponRecord::getCouponId, mkShopCouponRecordDTO.getCouponId())
|
||||
.eq(MkShopCouponRecord::getIsDel, 0)
|
||||
.eq(MkShopCouponRecord::getStatus, mkShopCouponRecordDTO.getStatus())
|
||||
.orderBy(MkShopCouponRecord::getCreateTime).desc();
|
||||
if (CollUtil.isNotEmpty(userInfoMap)) {
|
||||
recordQueryWrapper.in(MkShopCouponRecord::getUserId, userInfoMap.keySet());
|
||||
} else {
|
||||
recordQueryWrapper.eq(MkShopCouponRecord::getUserId, mkShopCouponRecordDTO.getUserId());
|
||||
}
|
||||
Page<MkShopCouponRecordDTO> recordPage = pageAs(PageUtil.buildPage(), recordQueryWrapper, MkShopCouponRecordDTO.class);
|
||||
if (CollUtil.isNotEmpty(userInfoMap)) {
|
||||
for (MkShopCouponRecordDTO record : recordPage.getRecords()) {
|
||||
UserInfo userInfo = userInfoMap.get(record.getUserId());
|
||||
record.setHeadImg(userInfo.getHeadImg());
|
||||
record.setNickName(userInfo.getNickName());
|
||||
}
|
||||
}
|
||||
return recordPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveCoupon(MkShopCouponRecordDTO mkShopCouponRecordDTO, Integer number) {
|
||||
if (number == null || number <= 0) {
|
||||
throw new CzgException("发放数量不能小于0");
|
||||
}
|
||||
MkShopCouponRecord bean = BeanUtil.toBean(mkShopCouponRecordDTO, MkShopCouponRecord.class);
|
||||
if (bean.getType() == 1) {
|
||||
if (bean.getFullAmount() == null) {
|
||||
throw new CzgException("满减券,满减金额不能为空");
|
||||
}
|
||||
if (bean.getDiscountAmount() == null) {
|
||||
throw new CzgException("满减券,折扣金额不能为空");
|
||||
}
|
||||
} else if (bean.getType() == 2) {
|
||||
// 类型2:fullAmount不能为空
|
||||
if (bean.getFullAmount() == null) {
|
||||
throw new CzgException("商品兑换券,门槛金额不能为空");
|
||||
}
|
||||
} else if (bean.getType() == 3) {
|
||||
// 类型3:discountRate不能为空
|
||||
if (bean.getDiscountRate() == null) {
|
||||
throw new CzgException("折扣券,折扣率不能为空");
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < number; i++) {
|
||||
bean.setId(null);
|
||||
save(bean);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteRecord(Long id) {
|
||||
updateById(new MkShopCouponRecord().setId(id).setIsDel(1), true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.czg.service.market.mapper.MkShopCouponRecordMapper">
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user