抢单账号配置
This commit is contained in:
@@ -634,9 +634,7 @@ public class LbAssessmentApplyServiceImpl
|
||||
if (meetingNumber != null && !meetingNumber.trim().isEmpty()) {
|
||||
queryWrapper.like(LbAssessmentApply::getMeetingNumber, meetingNumber.trim());
|
||||
}
|
||||
queryWrapper.orderByAsc(LbAssessmentApply::getSortedNum)
|
||||
.orderByDesc(LbAssessmentApply::getUpdatedAt)
|
||||
.orderByDesc(LbAssessmentApply::getCreatedAt);
|
||||
queryWrapper.orderByDesc(LbAssessmentApply::getUpdatedAt) ;
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,12 +6,17 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.rj.entity.LbBuyAccount;
|
||||
import com.rj.mapper.LbBuyAccountMapper;
|
||||
import com.rj.service.ILbBuyAccountService;
|
||||
import com.rj.service.ILbGoodsService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -21,9 +26,15 @@ public class LbBuyAccountServiceImpl
|
||||
extends ServiceImpl<LbBuyAccountMapper, LbBuyAccount>
|
||||
implements ILbBuyAccountService {
|
||||
|
||||
/** 与表字段 rush_buy_result(TEXT)长度上限一致 */
|
||||
private static final int RUSH_BUY_RESULT_MAX_LEN = 65535;
|
||||
|
||||
private static final DateTimeFormatter DATE_TIME_FORMATTER =
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@Autowired
|
||||
private ILbGoodsService lbGoodsService;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> add(LbBuyAccount entity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
@@ -185,6 +196,113 @@ public class LbBuyAccountServiceImpl
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> rushBuyByIds(List<String> ids) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "ids不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
List<String> normalizedIds = new ArrayList<>();
|
||||
for (String id : ids) {
|
||||
if (id != null && !id.trim().isEmpty()) {
|
||||
normalizedIds.add(id.trim());
|
||||
}
|
||||
}
|
||||
if (normalizedIds.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "ids不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
List<LbBuyAccount> accounts = this.listByIds(normalizedIds);
|
||||
Map<String, LbBuyAccount> accountMap = new LinkedHashMap<>();
|
||||
for (LbBuyAccount account : accounts) {
|
||||
if (account != null && account.getId() != null) {
|
||||
accountMap.put(account.getId(), account);
|
||||
}
|
||||
}
|
||||
|
||||
List<Map<String, Object>> accountResults = new ArrayList<>();
|
||||
int successAccounts = 0;
|
||||
int failAccounts = 0;
|
||||
|
||||
for (String id : normalizedIds) {
|
||||
Map<String, Object> item = new LinkedHashMap<>();
|
||||
item.put("accountId", id);
|
||||
|
||||
LbBuyAccount account = accountMap.get(id);
|
||||
if (account == null) {
|
||||
item.put("success", false);
|
||||
item.put("message", "抢单账号不存在");
|
||||
accountResults.add(item);
|
||||
failAccounts++;
|
||||
continue;
|
||||
}
|
||||
|
||||
item.put("loginAccount", account.getLoginAccount());
|
||||
item.put("tenantId", account.getTenantId());
|
||||
item.put("nickname", account.getNickname());
|
||||
|
||||
String resultMessage;
|
||||
Boolean rushSuccess = false;
|
||||
LocalDateTime rushBuyTime = LocalDateTime.now();
|
||||
|
||||
if (account.getEnabled() != null && account.getEnabled() == 0) {
|
||||
resultMessage = formatPreRushBuyFailure("账号未启用");
|
||||
} else if (account.getTenantId() == null || account.getTenantId().trim().isEmpty()) {
|
||||
resultMessage = formatPreRushBuyFailure("tenantId不能为空");
|
||||
} else if (account.getTokenFront() == null || account.getTokenFront().trim().isEmpty()) {
|
||||
resultMessage = formatPreRushBuyFailure("token_front不能为空");
|
||||
} else {
|
||||
Integer maxGrabCount = account.getMaxGrabCount();
|
||||
if (maxGrabCount == null || maxGrabCount <= 0) {
|
||||
resultMessage = formatPreRushBuyFailure("maxGrabCount必须大于0");
|
||||
} else {
|
||||
Map<String, Object> rushBuyResult = lbGoodsService.rushBuy(
|
||||
account.getTenantId().trim(),
|
||||
account.getTokenFront().trim(),
|
||||
maxGrabCount);
|
||||
item.put("rushBuyResult", rushBuyResult);
|
||||
rushSuccess = rushBuyResult.get("success") instanceof Boolean
|
||||
? (Boolean) rushBuyResult.get("success")
|
||||
: null;
|
||||
resultMessage = formatRushBuyResultMessage(rushBuyResult);
|
||||
}
|
||||
}
|
||||
|
||||
item.put("success", Boolean.TRUE.equals(rushSuccess));
|
||||
item.put("message", resultMessage);
|
||||
accountResults.add(item);
|
||||
persistRushBuyOutcome(account.getId(), resultMessage, rushBuyTime);
|
||||
|
||||
if (Boolean.TRUE.equals(rushSuccess)) {
|
||||
successAccounts++;
|
||||
} else {
|
||||
failAccounts++;
|
||||
}
|
||||
}
|
||||
|
||||
result.put("success", successAccounts > 0);
|
||||
result.put("message", successAccounts > 0
|
||||
? "批量抢购完成,成功账号 " + successAccounts + " 个,失败 " + failAccounts + " 个"
|
||||
: "批量抢购未成功");
|
||||
result.put("totalAccounts", normalizedIds.size());
|
||||
result.put("successAccounts", successAccounts);
|
||||
result.put("failAccounts", failAccounts);
|
||||
result.put("accountResults", accountResults);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("抢单账号批量抢购异常", e);
|
||||
result.put("success", false);
|
||||
result.put("message", "批量抢购异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> validateRequiredForAdd(LbBuyAccount entity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
if (entity.getTenantId() == null || entity.getTenantId().trim().isEmpty()) {
|
||||
@@ -235,6 +353,9 @@ public class LbBuyAccountServiceImpl
|
||||
if (entity.getLoginUrl() != null) {
|
||||
entity.setLoginUrl(entity.getLoginUrl().trim());
|
||||
}
|
||||
if (entity.getTokenFront() != null) {
|
||||
entity.setTokenFront(entity.getTokenFront().trim());
|
||||
}
|
||||
}
|
||||
|
||||
private static void defaultIntegerFields(LbBuyAccount entity) {
|
||||
@@ -253,6 +374,131 @@ public class LbBuyAccountServiceImpl
|
||||
if (entity.getTotalPoints() == null) {
|
||||
entity.setTotalPoints(0);
|
||||
}
|
||||
if (entity.getEnabled() == null) {
|
||||
entity.setEnabled(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将本次抢单结果与抢单时间写入 lb_buy_account(rush_buy_result、last_rush_buy_time)。
|
||||
*/
|
||||
private void persistRushBuyOutcome(String accountId, String resultMessage, LocalDateTime rushBuyTime) {
|
||||
if (accountId == null || accountId.trim().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String storedResult = truncateRushBuyResult(
|
||||
resultMessage != null && !resultMessage.isEmpty() ? resultMessage : "未知抢单结果");
|
||||
LocalDateTime time = rushBuyTime != null ? rushBuyTime : LocalDateTime.now();
|
||||
try {
|
||||
boolean ok = this.lambdaUpdate()
|
||||
.eq(LbBuyAccount::getId, accountId.trim())
|
||||
.set(LbBuyAccount::getRushBuyResult, storedResult)
|
||||
.set(LbBuyAccount::getLastRushBuyTime, time)
|
||||
.set(LbBuyAccount::getUpdateTime, LocalDateTime.now())
|
||||
.update();
|
||||
if (!ok) {
|
||||
log.warn("抢单结果落库未更新任何行,accountId={}", accountId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("抢单结果落库异常,accountId={}", accountId, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String formatPreRushBuyFailure(String reason) {
|
||||
return "【失败】原因:" + reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 rushBuy 返回结构生成落库文案:成功记录货品 ID 与金额;失败记录原因与接口返回信息。
|
||||
*/
|
||||
private static String formatRushBuyResultMessage(Map<String, Object> rushBuyResult) {
|
||||
if (rushBuyResult == null || rushBuyResult.isEmpty()) {
|
||||
return formatPreRushBuyFailure("抢购未返回结果");
|
||||
}
|
||||
|
||||
Object summaryMsg = rushBuyResult.get("message");
|
||||
Object detailsObj = rushBuyResult.get("details");
|
||||
if (!(detailsObj instanceof List<?> details) || details.isEmpty()) {
|
||||
return formatRushBuyWithoutDetails(rushBuyResult, summaryMsg);
|
||||
}
|
||||
|
||||
List<String> successLines = new ArrayList<>();
|
||||
List<String> failLines = new ArrayList<>();
|
||||
for (Object detailObj : details) {
|
||||
if (!(detailObj instanceof Map<?, ?> detail)) {
|
||||
continue;
|
||||
}
|
||||
Object successFlag = detail.get("success");
|
||||
boolean itemSuccess = Boolean.TRUE.equals(successFlag);
|
||||
if (itemSuccess) {
|
||||
successLines.add(formatRushBuySuccessDetail(detail));
|
||||
} else {
|
||||
failLines.add(formatRushBuyFailDetail(detail));
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (summaryMsg != null) {
|
||||
sb.append("汇总:").append(summaryMsg);
|
||||
}
|
||||
Object successCount = rushBuyResult.get("successCount");
|
||||
Object failCount = rushBuyResult.get("failCount");
|
||||
if (successCount != null || failCount != null) {
|
||||
sb.append("(成功").append(successCount).append("笔,失败").append(failCount).append("笔)");
|
||||
}
|
||||
|
||||
if (!successLines.isEmpty()) {
|
||||
sb.append(" | 【成功】").append(String.join("; ", successLines));
|
||||
}
|
||||
if (!failLines.isEmpty()) {
|
||||
sb.append(" | 【失败】").append(String.join("; ", failLines));
|
||||
}
|
||||
if (successLines.isEmpty() && failLines.isEmpty()) {
|
||||
sb.append(" | 【失败】原因:无有效抢购明细");
|
||||
if (summaryMsg != null) {
|
||||
sb.append(";返回信息:").append(summaryMsg);
|
||||
}
|
||||
}
|
||||
return truncateRushBuyResult(sb.toString());
|
||||
}
|
||||
|
||||
/** rushBuy 未产生逐笔明细(配置缺失、无可抢货品、异常等) */
|
||||
private static String formatRushBuyWithoutDetails(Map<String, Object> rushBuyResult, Object summaryMsg) {
|
||||
Boolean overallSuccess = rushBuyResult.get("success") instanceof Boolean
|
||||
? (Boolean) rushBuyResult.get("success")
|
||||
: null;
|
||||
String summary = summaryMsg != null ? summaryMsg.toString() : "无返回信息";
|
||||
if (Boolean.TRUE.equals(overallSuccess)) {
|
||||
return truncateRushBuyResult("【成功】返回信息:" + summary);
|
||||
}
|
||||
return truncateRushBuyResult("【失败】原因:" + summary + ";返回信息:" + summary);
|
||||
}
|
||||
|
||||
private static String formatRushBuySuccessDetail(Map<?, ?> detail) {
|
||||
return "货品ID=" + detail.get("id")
|
||||
+ ",金额=" + detail.get("totalMoney");
|
||||
}
|
||||
|
||||
private static String formatRushBuyFailDetail(Map<?, ?> detail) {
|
||||
Object apiCode = detail.get("apiCode");
|
||||
Object apiMsg = detail.get("message");
|
||||
String reason = apiCode != null
|
||||
? "接口返回码=" + apiCode + (apiMsg != null ? "," + apiMsg : "")
|
||||
: (apiMsg != null ? apiMsg.toString() : "未知原因");
|
||||
return "货品ID=" + detail.get("id")
|
||||
+ ",金额=" + detail.get("totalMoney")
|
||||
+ ",原因=" + reason
|
||||
+ ",返回信息=" + (apiMsg != null ? apiMsg : "无");
|
||||
}
|
||||
|
||||
private static String truncateRushBuyResult(String text) {
|
||||
if (text == null) {
|
||||
return null;
|
||||
}
|
||||
if (text.length() <= RUSH_BUY_RESULT_MAX_LEN) {
|
||||
return text;
|
||||
}
|
||||
return text.substring(0, RUSH_BUY_RESULT_MAX_LEN);
|
||||
}
|
||||
|
||||
private static LocalDateTime parseDateTime(String text) {
|
||||
|
||||
@@ -11,6 +11,7 @@ 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.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.rj.dto.hxr.HxrAdminUserApiContext;
|
||||
import com.rj.dto.hxr.HxrUserRow;
|
||||
import com.rj.entity.LbDailyUserTrade;
|
||||
import com.rj.entity.LbDailyUserTradeReport;
|
||||
@@ -25,6 +26,7 @@ import com.rj.mapper.LbPurchaseApplyMapper;
|
||||
import com.rj.mapper.LbUserMapper;
|
||||
import com.rj.service.HxrAdminUserService;
|
||||
import com.rj.service.ILbPurchaseApplyService;
|
||||
import com.rj.service.ILbThirdIntegrationConfigService;
|
||||
import jakarta.servlet.ServletOutputStream;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -71,6 +73,9 @@ public class LbPurchaseApplyServiceImpl
|
||||
@Autowired
|
||||
private HxrAdminUserService hxrAdminUserService;
|
||||
|
||||
@Autowired
|
||||
private ILbThirdIntegrationConfigService lbThirdIntegrationConfigService;
|
||||
|
||||
@Autowired
|
||||
private LbUserMapper lbUserMapper;
|
||||
|
||||
@@ -907,6 +912,22 @@ public class LbPurchaseApplyServiceImpl
|
||||
return result;
|
||||
}
|
||||
|
||||
String tid = tenantId.trim();
|
||||
Optional<HxrAdminUserApiContext> apiContextOpt =
|
||||
lbThirdIntegrationConfigService.resolveAdminUserApiContext(tid);
|
||||
if (apiContextOpt.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message",
|
||||
"未找到该租户的第三方集成配置,或配置未启用、URL/凭证不完整(请检查 lb_third_integration_config)");
|
||||
result.put("totalRecords", userIds.size());
|
||||
result.put("successCount", 0);
|
||||
result.put("failCount", userIds.size());
|
||||
result.put("details", List.of());
|
||||
result.put("tenantId", tid);
|
||||
return result;
|
||||
}
|
||||
HxrAdminUserApiContext apiContext = apiContextOpt.get();
|
||||
|
||||
List<Map<String, Object>> details = new ArrayList<>();
|
||||
int ok = 0;
|
||||
int fail = 0;
|
||||
@@ -926,7 +947,8 @@ public class LbPurchaseApplyServiceImpl
|
||||
try {
|
||||
Integer maxOrderForApi = maxOrder == 0 ? null : maxOrder;
|
||||
boolean updated =
|
||||
hxrAdminUserService.updateUserVipFields(userId, maxOrderForApi, vipTimeStr, isVip);
|
||||
hxrAdminUserService.updateUserVipFields(
|
||||
userId, maxOrderForApi, vipTimeStr, isVip, apiContext);
|
||||
if (updated) {
|
||||
one.put("success", true);
|
||||
one.put("message", "user/update 成功");
|
||||
@@ -985,6 +1007,24 @@ public class LbPurchaseApplyServiceImpl
|
||||
return result;
|
||||
}
|
||||
|
||||
String tid = tenantId.trim();
|
||||
Optional<HxrAdminUserApiContext> apiContextOpt =
|
||||
lbThirdIntegrationConfigService.resolveAdminUserApiContext(tid);
|
||||
if (apiContextOpt.isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message",
|
||||
"未找到该租户的第三方集成配置,或配置未启用、URL/凭证不完整(请检查 lb_third_integration_config)");
|
||||
result.put("totalRecords", rows.size());
|
||||
result.put("successCount", 0);
|
||||
result.put("failCount", rows.size());
|
||||
result.put("details", List.of());
|
||||
result.put("applyDateStart", applyDateStart);
|
||||
result.put("applyDateEnd", applyDateEnd);
|
||||
result.put("tenantId", tid);
|
||||
return result;
|
||||
}
|
||||
HxrAdminUserApiContext apiContext = apiContextOpt.get();
|
||||
|
||||
Set<String> tradeMatchedNicknames = ctx.tradeMatchedNicknames();
|
||||
List<Map<String, Object>> details = new ArrayList<>();
|
||||
int ok = 0;
|
||||
@@ -1010,7 +1050,7 @@ public class LbPurchaseApplyServiceImpl
|
||||
String vipTimeStr = HxrAdminUserService.formatVipTime(vipTime);
|
||||
one.put("viptime", vipTimeStr);
|
||||
|
||||
Optional<HxrUserRow> userOpt = hxrAdminUserService.fetchFirstUserByMobile(phone);
|
||||
Optional<HxrUserRow> userOpt = hxrAdminUserService.fetchFirstUserByMobile(phone, apiContext);
|
||||
if (userOpt.isEmpty()) {
|
||||
one.put("success", false);
|
||||
one.put("message", "user/select 无用户或接口失败");
|
||||
@@ -1031,7 +1071,7 @@ public class LbPurchaseApplyServiceImpl
|
||||
}
|
||||
one.put("maxOrder", maxOrder);
|
||||
boolean updated =
|
||||
hxrAdminUserService.updateUserVipFields(hxrUserId, maxOrder, vipTimeStr);
|
||||
hxrAdminUserService.updateUserVipFields(hxrUserId, maxOrder, vipTimeStr, 1, apiContext);
|
||||
if (updated) {
|
||||
one.put("success", true);
|
||||
one.put("message", "user/update 成功");
|
||||
|
||||
@@ -362,6 +362,7 @@ public class LbThirdIntegrationConfigServiceImpl
|
||||
try {
|
||||
return Optional.of(new HxrAdminUserApiContext(
|
||||
LbThirdIntegrationConfigUtil.resolveUserSelectBaseUrl(config),
|
||||
LbThirdIntegrationConfigUtil.resolveUserUpdateUrl(config),
|
||||
LbThirdIntegrationConfigUtil.resolveUserPageLimit(config),
|
||||
cookieHeader.trim(),
|
||||
LbThirdIntegrationConfigUtil.resolveUserReferer(config)));
|
||||
|
||||
Reference in New Issue
Block a user