lb用户同步的代码结构

This commit is contained in:
2026-05-19 07:29:43 +08:00
parent 8ddab219b7
commit 7c9ee9101e
10 changed files with 673 additions and 16 deletions

View File

@@ -48,7 +48,7 @@ public class LbOrderRowServiceImpl extends ServiceImpl<LbOrderRowMapper, LbOrder
private static final int DINGTALK_SELLER_CONFIRM_BATCH_SIZE = 15;
private static final String DINGTALK_SELLER_CONFIRM_PREFIX =
"买家已支付,不要影响 对方寄卖, 请如下卖家确认:";
"提醒,请如下卖家确认,不要耽误 买方寄卖";
private static final long SUM_PLACEHOLDER_USER_ID = 10000L;
@@ -458,16 +458,18 @@ public class LbOrderRowServiceImpl extends ServiceImpl<LbOrderRowMapper, LbOrder
return result;
}
List<String> sellerNames =
details.stream()
.map(this::resolveSellerDisplayName)
.distinct()
.limit(DINGTALK_SELLER_CONFIRM_BATCH_SIZE)
.collect(Collectors.toList());
int messageCount = 0;
for (int i = 0; i < details.size(); i += DINGTALK_SELLER_CONFIRM_BATCH_SIZE) {
int end = Math.min(i + DINGTALK_SELLER_CONFIRM_BATCH_SIZE, details.size());
List<LbOrderRow> batch = details.subList(i, end);
String sellerNames =
batch.stream()
.map(this::resolveSellerDisplayName)
.collect(Collectors.joining(","));
dingTalkRobotService.sendText(DINGTALK_SELLER_CONFIRM_PREFIX + sellerNames);
messageCount++;
if (!sellerNames.isEmpty()) {
dingTalkRobotService.sendText(
DINGTALK_SELLER_CONFIRM_PREFIX + String.join(",", sellerNames));
messageCount = 1;
}
result.put("success", true);

View File

@@ -0,0 +1,279 @@
package com.rj.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rj.entity.LbUser;
import com.rj.mapper.LbUserMapper;
import com.rj.service.ILbUserService;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.HashMap;
import java.util.Map;
@Service
public class LbUserServiceImpl extends ServiceImpl<LbUserMapper, LbUser> implements ILbUserService {
private static final DateTimeFormatter DATETIME_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@Override
public Map<String, Object> add(LbUser entity) {
Map<String, Object> result = new HashMap<>();
try {
if (entity.getId() == null) {
result.put("success", false);
result.put("message", "id不能为空");
return result;
}
if (this.getById(entity.getId()) != null) {
result.put("success", false);
result.put("message", "该用户 id 已存在");
return result;
}
applyDefaults(entity);
LocalDateTime now = LocalDateTime.now();
if (entity.getCreatedAt() == null) {
entity.setCreatedAt(now);
}
if (entity.getUpdatedAt() == null) {
entity.setUpdatedAt(now);
}
boolean ok = this.save(entity);
result.put("success", ok);
result.put("message", ok ? "新增成功" : "新增失败");
if (ok) {
result.put("data", this.getById(entity.getId()));
}
return result;
} catch (Exception e) {
result.put("success", false);
result.put("message", "新增异常:" + e.getMessage());
return result;
}
}
@Override
public Map<String, Object> update(LbUser entity) {
Map<String, Object> result = new HashMap<>();
try {
if (entity.getId() == null) {
result.put("success", false);
result.put("message", "id不能为空");
return result;
}
if (this.getById(entity.getId()) == null) {
result.put("success", false);
result.put("message", "记录不存在");
return result;
}
entity.setUpdatedAt(LocalDateTime.now());
boolean ok = this.updateById(entity);
result.put("success", ok);
result.put("message", ok ? "编辑成功" : "编辑失败");
if (ok) {
result.put("data", this.getById(entity.getId()));
}
return result;
} catch (Exception e) {
result.put("success", false);
result.put("message", "编辑异常:" + e.getMessage());
return result;
}
}
@Override
public Map<String, Object> deleteById(Long id) {
Map<String, Object> result = new HashMap<>();
try {
boolean ok = this.removeById(id);
result.put("success", ok);
result.put("message", ok ? "删除成功" : "删除失败");
return result;
} catch (Exception e) {
result.put("success", false);
result.put("message", "删除异常:" + e.getMessage());
return result;
}
}
@Override
public Map<String, Object> pageQuery(
Integer current,
Integer size,
Long pid,
String username,
String nickname,
String mobile,
String invite,
Integer status,
Integer isVip,
Integer isResell,
Integer level,
String pname,
String joinTimeStart,
String joinTimeEnd,
String updatedAtStart,
String updatedAtEnd) {
Map<String, Object> result = new HashMap<>();
try {
if (current == null || current < 1) {
current = 1;
}
if (size == null || size < 1) {
size = 10;
}
LambdaQueryWrapper<LbUser> w = new LambdaQueryWrapper<>();
if (pid != null) {
w.eq(LbUser::getPid, pid);
}
if (username != null && !username.trim().isEmpty()) {
w.like(LbUser::getUsername, username.trim());
}
if (nickname != null && !nickname.trim().isEmpty()) {
w.like(LbUser::getNickname, nickname.trim());
}
if (mobile != null && !mobile.trim().isEmpty()) {
w.like(LbUser::getMobile, mobile.trim());
}
if (invite != null && !invite.trim().isEmpty()) {
w.eq(LbUser::getInvite, invite.trim());
}
if (status != null) {
w.eq(LbUser::getStatus, status);
}
if (isVip != null) {
w.eq(LbUser::getIsVip, isVip);
}
if (isResell != null) {
w.eq(LbUser::getIsResell, isResell);
}
if (level != null) {
w.eq(LbUser::getLevel, level);
}
if (pname != null && !pname.trim().isEmpty()) {
w.like(LbUser::getPname, pname.trim());
}
LocalDateTime joinStart = parseDateTime(joinTimeStart);
if (joinTimeStart != null && !joinTimeStart.trim().isEmpty() && joinStart == null) {
result.put("success", false);
result.put("message", "joinTimeStart 格式错误,请使用 yyyy-MM-dd HH:mm:ss");
return result;
}
LocalDateTime joinEnd = parseDateTime(joinTimeEnd);
if (joinTimeEnd != null && !joinTimeEnd.trim().isEmpty() && joinEnd == null) {
result.put("success", false);
result.put("message", "joinTimeEnd 格式错误,请使用 yyyy-MM-dd HH:mm:ss");
return result;
}
if (joinStart != null) {
w.ge(LbUser::getJoinTime, joinStart);
}
if (joinEnd != null) {
w.le(LbUser::getJoinTime, joinEnd);
}
LocalDateTime updatedStart = parseDateTime(updatedAtStart);
if (updatedAtStart != null && !updatedAtStart.trim().isEmpty() && updatedStart == null) {
result.put("success", false);
result.put("message", "updatedAtStart 格式错误,请使用 yyyy-MM-dd HH:mm:ss");
return result;
}
LocalDateTime updatedEnd = parseDateTime(updatedAtEnd);
if (updatedAtEnd != null && !updatedAtEnd.trim().isEmpty() && updatedEnd == null) {
result.put("success", false);
result.put("message", "updatedAtEnd 格式错误,请使用 yyyy-MM-dd HH:mm:ss");
return result;
}
if (updatedStart != null) {
w.ge(LbUser::getUpdatedAt, updatedStart);
}
if (updatedEnd != null) {
w.le(LbUser::getUpdatedAt, updatedEnd);
}
w.orderByDesc(LbUser::getUpdatedAt).orderByDesc(LbUser::getId);
Page<LbUser> page = this.page(new Page<>(current, size), w);
result.put("success", true);
result.put("message", "查询成功");
result.put("data", page.getRecords());
result.put("total", page.getTotal());
result.put("current", page.getCurrent());
result.put("size", page.getSize());
result.put("pages", page.getPages());
return result;
} catch (Exception e) {
result.put("success", false);
result.put("message", "查询异常:" + e.getMessage());
return result;
}
}
private static void applyDefaults(LbUser entity) {
if (entity.getLevel() == null) {
entity.setLevel(0);
}
if (entity.getMoney() == null) {
entity.setMoney(BigDecimal.ZERO);
}
if (entity.getCoupon() == null) {
entity.setCoupon(BigDecimal.ZERO);
}
if (entity.getSelfBonus() == null) {
entity.setSelfBonus(BigDecimal.ZERO);
}
if (entity.getShareBonus() == null) {
entity.setShareBonus(BigDecimal.ZERO);
}
if (entity.getScore() == null) {
entity.setScore(0);
}
if (entity.getStatus() == null) {
entity.setStatus(1);
}
if (entity.getIsVip() == null) {
entity.setIsVip(0);
}
if (entity.getMaxOrder() == null) {
entity.setMaxOrder(0);
}
if (entity.getIsResell() == null) {
entity.setIsResell(0);
}
if (entity.getYesterdaySellCount() == null) {
entity.setYesterdaySellCount(0);
}
if (entity.getTodayBuyCount() == null) {
entity.setTodayBuyCount(0);
}
if (entity.getTodayBuyTotal() == null) {
entity.setTodayBuyTotal(BigDecimal.ZERO);
}
if (entity.getTodaySellTotal() == null) {
entity.setTodaySellTotal(BigDecimal.ZERO);
}
if (entity.getPoor() == null) {
entity.setPoor(0);
}
}
private static LocalDateTime parseDateTime(String text) {
if (text == null || text.trim().isEmpty()) {
return null;
}
try {
return LocalDateTime.parse(text.trim(), DATETIME_FMT);
} catch (DateTimeParseException e) {
return null;
}
}
}