Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
张松
2025-12-05 13:36:12 +08:00
4 changed files with 137 additions and 5 deletions

View File

@@ -0,0 +1,113 @@
package com.czg.market.entity;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import java.io.Serializable;
import java.math.BigInteger;
import java.time.LocalDateTime;
import java.io.Serial;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
/**
* 聊天消息表 实体类。
*
* @author ww
* @since 2025-12-04
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table("chat_message")
@Accessors(chain = true)
public class ChatMessage implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 消息ID
*/
@Id(keyType = KeyType.Auto)
private BigInteger id;
/**
* 发送者ID
*/
private String fromId;
/**
* 接收者ID单聊=对方ID群聊=群ID
*/
private String toId;
/**
* 群ID
*/
private String groupId;
/**
* 聊天类型1=单聊2=群聊
*/
private Integer chatType;
/**
* 消息类型1=文本/常用语/表情2=图片3=订单, 4 优惠券 5视频
*/
private Integer msgType;
/**
* 文本/表情代码/常用语ID仅msg_type=1
*/
private String content;
/**
* 图片URL仅msg_type=2
*/
private String imageUrl;
/**
* 订单ID仅msg_type=3
*/
private String orderId;
/**
* 优惠券信息 仅msg_type=4
*/
private String coupon;
/**
* 是否已读0=未读1=已读
*/
private Integer isRead;
/**
* 发送时间
*/
private LocalDateTime sendTime;
/**
* 会话ID单聊=min(from,to)_max(from,to),群聊=group_群ID
*/
private String sessionId;
private Long shopId;
/**
* chat_coupon的 id
*/
private Long chatCouponId;
/**
* 1 领取
*/
private Integer couponClaim;
}

View File

@@ -66,10 +66,13 @@ public interface MkShopCouponRecordService extends IService<MkShopCouponRecord>
Boolean grant(Long shopId, MkRewardCouponDTO rewardCouponDTO, String source); Boolean grant(Long shopId, MkRewardCouponDTO rewardCouponDTO, String source);
/**
* 组装 群聊活动优惠券
*/
MkShopCouponRecord assembleRecord(Long chatCouponId, ShopCoupon coupon); MkShopCouponRecord assembleRecord(Long chatCouponId, ShopCoupon coupon);
/** /**
* 优惠券发放 * 群聊活动优惠券发放
*/ */
void grantChatCoupon(MkShopCouponRecord record, Integer number); void grantChatCoupon(MkShopCouponRecord record, Integer number);

View File

@@ -3,6 +3,7 @@ package com.czg.service.market.service.impl;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.czg.exception.CzgException; import com.czg.exception.CzgException;
import com.czg.market.dto.ChatCouponDTO; import com.czg.market.dto.ChatCouponDTO;
import com.czg.market.dto.MkShopCouponGiftDTO;
import com.czg.market.entity.MkShopCouponRecord; import com.czg.market.entity.MkShopCouponRecord;
import com.czg.market.entity.ShopCoupon; import com.czg.market.entity.ShopCoupon;
import com.czg.market.service.MkShopCouponRecordService; import com.czg.market.service.MkShopCouponRecordService;
@@ -128,7 +129,14 @@ public class ChatCouponServiceImpl extends ServiceImpl<ChatCouponMapper, ChatCou
MkShopCouponRecord record = JSONObject.parseObject(coupon.getCouponJson(), MkShopCouponRecord.class); MkShopCouponRecord record = JSONObject.parseObject(coupon.getCouponJson(), MkShopCouponRecord.class);
record.setShopUserId(shopUserId); record.setShopUserId(shopUserId);
record.setUserId(userId); record.setUserId(userId);
recordService.grantChatCoupon(record, coupon.getGetLimit()); // recordService.grantChatCoupon(record, coupon.getGetLimit());
MkShopCouponGiftDTO giftDTO = new MkShopCouponGiftDTO()
.setCouponId(coupon.getCouponId())
.setShopId(coupon.getShopId())
.setSourceId(coupon.getId())
.setShopUserId(shopUserId)
.setSource("群聊发放");
recordService.receiveCoupon(giftDTO, coupon.getGetLimit(), false);
} }
@Override @Override

View File

@@ -37,6 +37,7 @@ import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
@@ -308,6 +309,7 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
} }
@Override @Override
@Transactional
public void receiveCoupon(MkShopCouponGiftDTO giftDTO, Integer number, boolean isLimit) { public void receiveCoupon(MkShopCouponGiftDTO giftDTO, Integer number, boolean isLimit) {
if (number == null || number <= 0) { if (number == null || number <= 0) {
throw new CzgException("发放数量不能小于0"); throw new CzgException("发放数量不能小于0");
@@ -357,6 +359,7 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
start = coupon.getValidStartTime(); start = coupon.getValidStartTime();
end = coupon.getValidEndTime(); end = coupon.getValidEndTime();
} }
List<MkShopCouponRecord> recordList = new ArrayList<>();
for (int i = 0; i < number; i++) { for (int i = 0; i < number; i++) {
MkShopCouponRecord record = new MkShopCouponRecord(); MkShopCouponRecord record = new MkShopCouponRecord();
record.setShopId(giftDTO.getShopId()); record.setShopId(giftDTO.getShopId());
@@ -380,8 +383,9 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
record.setUseStartTime(start); record.setUseStartTime(start);
record.setUseEndTime(end); record.setUseEndTime(end);
save(record); // save(record);
} }
mapper.insertBatchSelective(recordList, 10);
QueryWrapper queryWrapper = new QueryWrapper(); QueryWrapper queryWrapper = new QueryWrapper();
ShopCoupon newCoupon = new ShopCoupon(); ShopCoupon newCoupon = new ShopCoupon();
newCoupon.setLeftNum(coupon.getLeftNum()); newCoupon.setLeftNum(coupon.getLeftNum());
@@ -500,6 +504,7 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
} }
@Override @Override
@Transactional
public Boolean grant(Long shopId, MkRewardCouponDTO rewardCouponDTO, String source) { public Boolean grant(Long shopId, MkRewardCouponDTO rewardCouponDTO, String source) {
Long mainIdByShopId = shopInfoService.getMainIdByShopId(shopId); Long mainIdByShopId = shopInfoService.getMainIdByShopId(shopId);
ShopUser shopUser = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getMainShopId, mainIdByShopId).eq(ShopUser::getUserId, rewardCouponDTO.getUserId())); ShopUser shopUser = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getMainShopId, mainIdByShopId).eq(ShopUser::getUserId, rewardCouponDTO.getUserId()));
@@ -520,6 +525,7 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
MkShopCouponRecord record = new MkShopCouponRecord(); MkShopCouponRecord record = new MkShopCouponRecord();
record.setShopId(coupon.getShopId()); record.setShopId(coupon.getShopId());
record.setCouponName(coupon.getTitle()); record.setCouponName(coupon.getTitle());
record.setName(coupon.getTitle());
record.setCouponId(coupon.getId()); record.setCouponId(coupon.getId());
record.setCouponSyncId(coupon.getSyncId()); record.setCouponSyncId(coupon.getSyncId());
record.setSourceId(chatCouponId); record.setSourceId(chatCouponId);
@@ -532,6 +538,7 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
record.setMaxDiscountAmount(coupon.getMaxDiscountAmount()); record.setMaxDiscountAmount(coupon.getMaxDiscountAmount());
record.setCreateTime(LocalDateTime.now()); record.setCreateTime(LocalDateTime.now());
record.setIsDel(0); record.setIsDel(0);
record.setValidType(coupon.getValidType());
if ("fixed".equals(coupon.getValidType())) { if ("fixed".equals(coupon.getValidType())) {
record.setDaysToTakeEffect(coupon.getDaysToTakeEffect()); record.setDaysToTakeEffect(coupon.getDaysToTakeEffect());
record.setValidDays(coupon.getValidDays()); record.setValidDays(coupon.getValidDays());
@@ -543,6 +550,7 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
} }
@Override @Override
@Transactional
public void grantChatCoupon(MkShopCouponRecord record, Integer number) { public void grantChatCoupon(MkShopCouponRecord record, Integer number) {
ShopCoupon coupon = couponService.selectOneById(record.getCouponId()); ShopCoupon coupon = couponService.selectOneById(record.getCouponId());
AssertUtil.isNull(coupon, "优惠券不存在"); AssertUtil.isNull(coupon, "优惠券不存在");
@@ -556,7 +564,7 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
if (coupon.getStatus() != 1) { if (coupon.getStatus() != 1) {
return; return;
} }
coupon.setGiftNum(coupon.getGiftNum() + number); //组装 发放优惠券
if ("fixed".equals(record.getValidType())) { if ("fixed".equals(record.getValidType())) {
LocalDateTime start = LocalDateTime.now().with(LocalTime.MIN); LocalDateTime start = LocalDateTime.now().with(LocalTime.MIN);
//固定时间 //固定时间
@@ -574,7 +582,7 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
QueryWrapper queryWrapper = new QueryWrapper(); QueryWrapper queryWrapper = new QueryWrapper();
ShopCoupon newCoupon = new ShopCoupon(); ShopCoupon newCoupon = new ShopCoupon();
newCoupon.setGiftNum(coupon.getGiftNum()); newCoupon.setGiftNum(coupon.getGiftNum() + number);
if (coupon.getSyncId() != null) { if (coupon.getSyncId() != null) {
queryWrapper.and(q -> { queryWrapper.and(q -> {
q.eq(ShopCoupon::getId, coupon.getSyncId()).or(q1 -> { q.eq(ShopCoupon::getId, coupon.getSyncId()).or(q1 -> {