赠送券活动 关联表
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.MkCouponGift;
|
||||
|
||||
/**
|
||||
* 券赠送关联表 映射层。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-09-12
|
||||
*/
|
||||
public interface MkCouponGiftMapper extends BaseMapper<MkCouponGift> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.czg.service.market.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.czg.market.dto.MkCouponGiftDTO;
|
||||
import com.czg.market.entity.MkCouponGift;
|
||||
import com.czg.market.entity.ShopCoupon;
|
||||
import com.czg.market.service.MkCouponGiftService;
|
||||
import com.czg.market.service.ShopCouponService;
|
||||
import com.czg.service.market.mapper.MkCouponGiftMapper;
|
||||
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 jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 券赠送关联表 服务层实现。
|
||||
*
|
||||
* @author ww
|
||||
* @since 2025-09-12
|
||||
*/
|
||||
@Service
|
||||
public class MkCouponGiftServiceImpl extends ServiceImpl<MkCouponGiftMapper, MkCouponGift> implements MkCouponGiftService {
|
||||
|
||||
@Resource
|
||||
private ShopCouponService shopCouponService;
|
||||
|
||||
@Override
|
||||
public Page<MkCouponGiftDTO> getCouponGiftPage(Long couponId) {
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
queryWrapper.eq(MkCouponGift::getCouponId, couponId)
|
||||
.orderBy(MkCouponGift::getId).desc();
|
||||
return pageAs(PageUtil.buildPage(), queryWrapper, MkCouponGiftDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MkCouponGiftDTO> getCouponGiftBySourceId(Long sourceId, Integer type) {
|
||||
return listAs(new QueryWrapper().eq(MkCouponGift::getSourceId, sourceId).eq(MkCouponGift::getType, type), MkCouponGiftDTO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCouponGift(Long sourceId, String sourceName, Integer type, List<MkCouponGiftDTO> couponGiftList) {
|
||||
if (CollUtil.isNotEmpty(couponGiftList)) {
|
||||
List newCoupons = new ArrayList<>();
|
||||
for (MkCouponGiftDTO giftDTO : couponGiftList) {
|
||||
ShopCoupon coupon = shopCouponService.queryChain().select(ShopCoupon::getTitle)
|
||||
.where(ShopCoupon::getId).eq(giftDTO.getCouponId())
|
||||
.one();
|
||||
if (coupon == null) {
|
||||
continue;
|
||||
}
|
||||
MkCouponGift couponGift = new MkCouponGift();
|
||||
couponGift.setSourceId(sourceId);
|
||||
couponGift.setSourceName(sourceName);
|
||||
couponGift.setType(type);
|
||||
couponGift.setCouponId(giftDTO.getCouponId());
|
||||
couponGift.setNum(giftDTO.getNum());
|
||||
newCoupons.add(couponGift);
|
||||
}
|
||||
saveBatch(newCoupons);
|
||||
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void upCouponGift(Long sourceId, String sourceName, Integer type, List<MkCouponGiftDTO> couponGiftList) {
|
||||
deleteJoinCouponGift(sourceId, type);
|
||||
addCouponGift(sourceId, sourceName, type, couponGiftList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteJoinCouponGift(Long sourceId, Integer type) {
|
||||
remove(new QueryWrapper().eq(MkCouponGift::getSourceId, sourceId).eq(MkCouponGift::getType, type));
|
||||
}
|
||||
}
|
||||
@@ -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.MkCouponGiftMapper">
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user