抢单历史记录
This commit is contained in:
@@ -0,0 +1,270 @@
|
||||
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.LbBuyAccountHistory;
|
||||
import com.rj.mapper.LbBuyAccountHistoryMapper;
|
||||
import com.rj.service.ILbBuyAccountHistoryService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class LbBuyAccountHistoryServiceImpl
|
||||
extends ServiceImpl<LbBuyAccountHistoryMapper, LbBuyAccountHistory>
|
||||
implements ILbBuyAccountHistoryService {
|
||||
|
||||
private static final DateTimeFormatter DATE_TIME_FORMATTER =
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@Override
|
||||
public Map<String, Object> add(LbBuyAccountHistory entity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
Map<String, Object> validation = validateRequiredForAdd(entity);
|
||||
if (validation != null) {
|
||||
return validation;
|
||||
}
|
||||
trimStringFields(entity);
|
||||
defaultIntegerFields(entity);
|
||||
|
||||
if (entity.getId() == null || entity.getId().trim().isEmpty()) {
|
||||
entity.setId(UUID.randomUUID().toString());
|
||||
}
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
if (entity.getCreateTime() == null) {
|
||||
entity.setCreateTime(now);
|
||||
}
|
||||
entity.setUpdateTime(now);
|
||||
|
||||
boolean ok = this.save(entity);
|
||||
result.put("success", ok);
|
||||
result.put("message", ok ? "新增成功" : "新增失败");
|
||||
if (ok) {
|
||||
result.put("data", entity);
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("抢单历史新增异常", e);
|
||||
result.put("success", false);
|
||||
result.put("message", "新增异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> update(LbBuyAccountHistory entity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (entity.getId() == null || entity.getId().trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "id不能为空");
|
||||
return result;
|
||||
}
|
||||
trimStringFields(entity);
|
||||
entity.setUpdateTime(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) {
|
||||
log.error("抢单历史编辑异常", e);
|
||||
result.put("success", false);
|
||||
result.put("message", "编辑异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> deleteById(String id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (id == null || id.trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "id不能为空");
|
||||
return result;
|
||||
}
|
||||
boolean ok = this.removeById(id.trim());
|
||||
result.put("success", ok);
|
||||
result.put("message", ok ? "删除成功" : "删除失败");
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("抢单历史删除异常", e);
|
||||
result.put("success", false);
|
||||
result.put("message", "删除异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> pageQuery(Integer current,
|
||||
Integer size,
|
||||
String tenantId,
|
||||
String tenantName,
|
||||
String loginAccount,
|
||||
String nickname,
|
||||
String createTimeStart,
|
||||
String createTimeEnd,
|
||||
String lastRushBuyTimeStart,
|
||||
String lastRushBuyTimeEnd) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (current == null || current < 1) {
|
||||
current = 1;
|
||||
}
|
||||
if (size == null || size < 1) {
|
||||
size = 10;
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<LbBuyAccountHistory> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (tenantId != null && !tenantId.trim().isEmpty()) {
|
||||
queryWrapper.eq(LbBuyAccountHistory::getTenantId, tenantId.trim());
|
||||
}
|
||||
if (tenantName != null && !tenantName.trim().isEmpty()) {
|
||||
queryWrapper.like(LbBuyAccountHistory::getTenantName, tenantName.trim());
|
||||
}
|
||||
if (loginAccount != null && !loginAccount.trim().isEmpty()) {
|
||||
queryWrapper.like(LbBuyAccountHistory::getLoginAccount, loginAccount.trim());
|
||||
}
|
||||
if (nickname != null && !nickname.trim().isEmpty()) {
|
||||
queryWrapper.like(LbBuyAccountHistory::getNickname, nickname.trim());
|
||||
}
|
||||
|
||||
LocalDateTime createStart = parseDateTime(createTimeStart);
|
||||
if (createTimeStart != null && !createTimeStart.trim().isEmpty() && createStart == null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "createTimeStart 格式错误,请使用 yyyy-MM-dd HH:mm:ss");
|
||||
return result;
|
||||
}
|
||||
LocalDateTime createEnd = parseDateTime(createTimeEnd);
|
||||
if (createTimeEnd != null && !createTimeEnd.trim().isEmpty() && createEnd == null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "createTimeEnd 格式错误,请使用 yyyy-MM-dd HH:mm:ss");
|
||||
return result;
|
||||
}
|
||||
if (createStart != null) {
|
||||
queryWrapper.ge(LbBuyAccountHistory::getCreateTime, createStart);
|
||||
}
|
||||
if (createEnd != null) {
|
||||
queryWrapper.le(LbBuyAccountHistory::getCreateTime, createEnd);
|
||||
}
|
||||
|
||||
LocalDateTime rushStart = parseDateTime(lastRushBuyTimeStart);
|
||||
if (lastRushBuyTimeStart != null && !lastRushBuyTimeStart.trim().isEmpty() && rushStart == null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "lastRushBuyTimeStart 格式错误,请使用 yyyy-MM-dd HH:mm:ss");
|
||||
return result;
|
||||
}
|
||||
LocalDateTime rushEnd = parseDateTime(lastRushBuyTimeEnd);
|
||||
if (lastRushBuyTimeEnd != null && !lastRushBuyTimeEnd.trim().isEmpty() && rushEnd == null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "lastRushBuyTimeEnd 格式错误,请使用 yyyy-MM-dd HH:mm:ss");
|
||||
return result;
|
||||
}
|
||||
if (rushStart != null) {
|
||||
queryWrapper.ge(LbBuyAccountHistory::getLastRushBuyTime, rushStart);
|
||||
}
|
||||
if (rushEnd != null) {
|
||||
queryWrapper.le(LbBuyAccountHistory::getLastRushBuyTime, rushEnd);
|
||||
}
|
||||
|
||||
queryWrapper.orderByDesc(LbBuyAccountHistory::getLastRushBuyTime)
|
||||
.orderByDesc(LbBuyAccountHistory::getUpdateTime)
|
||||
.orderByDesc(LbBuyAccountHistory::getCreateTime);
|
||||
|
||||
Page<LbBuyAccountHistory> page = this.page(new Page<>(current, size), queryWrapper);
|
||||
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) {
|
||||
log.error("抢单历史查询异常", e);
|
||||
result.put("success", false);
|
||||
result.put("message", "查询异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> validateRequiredForAdd(LbBuyAccountHistory entity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
if (entity.getTenantId() == null || entity.getTenantId().trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "tenantId不能为空");
|
||||
return result;
|
||||
}
|
||||
if (entity.getTenantName() == null || entity.getTenantName().trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "tenantName不能为空");
|
||||
return result;
|
||||
}
|
||||
if (entity.getLoginAccount() == null || entity.getLoginAccount().trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "loginAccount不能为空");
|
||||
return result;
|
||||
}
|
||||
if (entity.getLoginPassword() == null || entity.getLoginPassword().trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "loginPassword不能为空");
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void trimStringFields(LbBuyAccountHistory entity) {
|
||||
if (entity.getTenantId() != null) {
|
||||
entity.setTenantId(entity.getTenantId().trim());
|
||||
}
|
||||
if (entity.getTenantName() != null) {
|
||||
entity.setTenantName(entity.getTenantName().trim());
|
||||
}
|
||||
if (entity.getLoginAccount() != null) {
|
||||
entity.setLoginAccount(entity.getLoginAccount().trim());
|
||||
}
|
||||
if (entity.getLoginPassword() != null) {
|
||||
entity.setLoginPassword(entity.getLoginPassword().trim());
|
||||
}
|
||||
if (entity.getNickname() != null) {
|
||||
entity.setNickname(entity.getNickname().trim());
|
||||
}
|
||||
if (entity.getRushBuyResult() != null) {
|
||||
entity.setRushBuyResult(entity.getRushBuyResult().trim());
|
||||
}
|
||||
}
|
||||
|
||||
private static void defaultIntegerFields(LbBuyAccountHistory entity) {
|
||||
if (entity.getMaxGrabAmount() == null) {
|
||||
entity.setMaxGrabAmount(0);
|
||||
}
|
||||
if (entity.getMaxGrabCount() == null) {
|
||||
entity.setMaxGrabCount(0);
|
||||
}
|
||||
if (entity.getRushBuyFailCount() == null) {
|
||||
entity.setRushBuyFailCount(0);
|
||||
}
|
||||
}
|
||||
|
||||
private static LocalDateTime parseDateTime(String text) {
|
||||
if (text == null || text.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return LocalDateTime.parse(text.trim(), DATE_TIME_FORMATTER);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,12 @@ public class LbOrderRowServiceImpl extends ServiceImpl<LbOrderRowMapper, LbOrder
|
||||
|
||||
private static final long SUM_PLACEHOLDER_USER_ID = 10000L;
|
||||
|
||||
/** seller_id 缺失时的占位默认值 */
|
||||
private static final long DEFAULT_SELLER_ID = 20000L;
|
||||
|
||||
/** merchandise_id 统计行占位默认值 */
|
||||
private static final long DEFAULT_MERCHANDISE_ID = 30000L;
|
||||
|
||||
private static final String SUM_ORDER_SN = "order_sn_10000";
|
||||
|
||||
private static final DateTimeFormatter DAY_TIME_FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
@@ -87,9 +93,7 @@ public class LbOrderRowServiceImpl extends ServiceImpl<LbOrderRowMapper, LbOrder
|
||||
return result;
|
||||
}
|
||||
if (entity.getSellerId() == null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "sellerId不能为空");
|
||||
return result;
|
||||
entity.setSellerId(DEFAULT_SELLER_ID);
|
||||
}
|
||||
if (entity.getBuyerId() == null) {
|
||||
result.put("success", false);
|
||||
@@ -657,7 +661,7 @@ public class LbOrderRowServiceImpl extends ServiceImpl<LbOrderRowMapper, LbOrder
|
||||
sum.setTodayUnresellCount(unresellCount);
|
||||
sum.setTodayOrderCount(orderCount);
|
||||
sum.setAvgAmt(avgAmt);
|
||||
sum.setSellerId(SUM_PLACEHOLDER_USER_ID);
|
||||
sum.setSellerId(DEFAULT_SELLER_ID);
|
||||
sum.setBuyerId(SUM_PLACEHOLDER_USER_ID);
|
||||
sum.setOrderSn(SUM_ORDER_SN);
|
||||
sum.setPhone("18808852688");
|
||||
@@ -668,7 +672,7 @@ public class LbOrderRowServiceImpl extends ServiceImpl<LbOrderRowMapper, LbOrder
|
||||
sum.setIsShow(1);
|
||||
sum.setPayTime(payTime);
|
||||
sum.setBuyTime(payTime);
|
||||
sum.setMerchandiseId(0L);
|
||||
sum.setMerchandiseId(DEFAULT_MERCHANDISE_ID);
|
||||
sum.setCreatedAt(nowStr);
|
||||
sum.setUpdatedAt(nowStr);
|
||||
return sum;
|
||||
@@ -701,9 +705,11 @@ public class LbOrderRowServiceImpl extends ServiceImpl<LbOrderRowMapper, LbOrder
|
||||
stat.setId(id);
|
||||
stat.setTenantId(tenantId);
|
||||
stat.setDataType(BUYER_DAY_STAT_DATA_TYPE);
|
||||
stat.setSellerId(DEFAULT_SELLER_ID);
|
||||
stat.setBuyerPhone(buyerPhone);
|
||||
stat.setBuyerId(sample.getBuyerId());
|
||||
stat.setBuyerName(sample.getBuyerName());
|
||||
stat.setConsignee(resolveConsigneeFromRows(buyerDayRows));
|
||||
stat.setPhone(buyerPhone);
|
||||
stat.setTodayTotalMoneySum(moneySum);
|
||||
stat.setTodayOrderCount(orderCount);
|
||||
@@ -712,13 +718,35 @@ public class LbOrderRowServiceImpl extends ServiceImpl<LbOrderRowMapper, LbOrder
|
||||
stat.setOrderSn("day_stat_" + buyerPhone + "_" + day.format(DAY_FMT));
|
||||
stat.setPayTime(payTime);
|
||||
stat.setBuyTime(payTime);
|
||||
stat.setIsResell(1);
|
||||
stat.setStatus(1);
|
||||
stat.setIsShow(1);
|
||||
stat.setMerchandiseId(DEFAULT_MERCHANDISE_ID);
|
||||
stat.setCreatedAt(nowStr);
|
||||
stat.setUpdatedAt(nowStr);
|
||||
return stat;
|
||||
}
|
||||
|
||||
/** 从明细中取收货人姓名,优先 consignee,其次 buyer_name */
|
||||
private static String resolveConsigneeFromRows(List<LbOrderRow> rows) {
|
||||
if (rows == null || rows.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
for (LbOrderRow row : rows) {
|
||||
String consignee = trimToNull(row.getConsignee());
|
||||
if (consignee != null) {
|
||||
return consignee;
|
||||
}
|
||||
}
|
||||
for (LbOrderRow row : rows) {
|
||||
String buyerName = trimToNull(row.getBuyerName());
|
||||
if (buyerName != null) {
|
||||
return buyerName;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** 同一天、同一租户、同一 buyer_phone 已存在 day_stat 则复用其 id,否则生成占位 id */
|
||||
private Long resolveBuyerDayStatRowId(String tenantId, String buyerPhone, String payTime) {
|
||||
LambdaQueryWrapper<LbOrderRow> w = new LambdaQueryWrapper<>();
|
||||
@@ -807,6 +835,7 @@ public class LbOrderRowServiceImpl extends ServiceImpl<LbOrderRowMapper, LbOrder
|
||||
continue;
|
||||
}
|
||||
entity.setTenantId(tenantId);
|
||||
ensureSellerId(entity);
|
||||
deduped.put(compositeKey(tenantId, entity.getId()), entity);
|
||||
}
|
||||
if (deduped.isEmpty()) {
|
||||
@@ -964,6 +993,12 @@ public class LbOrderRowServiceImpl extends ServiceImpl<LbOrderRowMapper, LbOrder
|
||||
return trimToNull(tenantIdFromParam);
|
||||
}
|
||||
|
||||
private static void ensureSellerId(LbOrderRow entity) {
|
||||
if (entity.getSellerId() == null) {
|
||||
entity.setSellerId(DEFAULT_SELLER_ID);
|
||||
}
|
||||
}
|
||||
|
||||
private static String compositeKey(String tenantId, Long id) {
|
||||
return tenantId + ":" + id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user