对接3方系统,开通新人特权

This commit is contained in:
2026-05-16 15:40:04 +08:00
parent d66daf375c
commit 3e753ba8b2
5 changed files with 191 additions and 21 deletions

View File

@@ -31,4 +31,40 @@ public class HxrAdminProperties {
* 仅 PHPSID 会话值(不含 {@code PHPSID=} 前缀);在 {@link #cookie} 为空时使用。 * 仅 PHPSID 会话值(不含 {@code PHPSID=} 前缀);在 {@link #cookie} 为空时使用。
*/ */
private String phpsid = ""; private String phpsid = "";
/**
* 用户列表接口 URL可含默认查询串实际请求会覆盖 {@code mobile} 等参数。
*/
private String userSelectUrl =
"https://hxrdhoutai.hxrdsm.cn/app/admin/user/select?page=1&limit=20";
/**
* 用户更新接口 URL。
*/
private String userUpdateUrl = "https://hxrdhoutai.hxrdsm.cn/app/admin/user/update";
/**
* 组装 Cookie 请求头:优先 {@link #cookie},否则 {@code PHPSID=}{@link #phpsid}。
*
* @return 非空 Cookie 值,或无法组装时的空串
*/
public String resolveCookieHeader() {
String c = firstNonBlank(cookie);
if (c != null) {
return c;
}
String id = firstNonBlank(phpsid);
if (id != null) {
return "PHPSID=" + id;
}
return "";
}
private static String firstNonBlank(String s) {
if (s == null) {
return null;
}
String t = s.trim();
return t.isEmpty() ? null : t;
}
} }

View File

@@ -106,6 +106,30 @@ public class LbPurchaseApplyController {
return ResponseEntity.internalServerError().body(result); return ResponseEntity.internalServerError().body(result);
} }
@GetMapping("/syncHxrAdminUserVip")
@Operation(summary = "按申请日期与租户同步 hxrd 用户 VIP 字段",
description = "根据 lb_purchase_apply 的申请日期区间与 tenant_id 逐条处理记录,"
+ "以每条记录的 apply_date 为起算日计算 viptime周末先对齐到下一工作日再顺延 2 个工作日),"
+ "再 GET /app/admin/user/select、POST /app/admin/user/updatemax_order、is_vip=1 等)。"
+ "需配置 hxr.admin.cookie 或 hxr.admin.phpsid。")
public ResponseEntity<Map<String, Object>> syncHxrAdminUserVip(
@Parameter(description = "申请开始日期(yyyy-MM-dd)", required = true)
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate applyDateStart,
@Parameter(description = "申请结束日期(yyyy-MM-dd)", required = true)
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate applyDateEnd,
@Parameter(description = "租户ID", required = true)
@RequestParam String tenantId,
@Parameter(description = "最大订单数 max_order", required = true)
@RequestParam("max_order") Integer maxOrder) {
Map<String, Object> result = lbPurchaseApplyService.syncHxrAdminUserVipByApplyDateRange(
applyDateStart, applyDateEnd, tenantId, maxOrder);
Boolean success = (Boolean) result.get("success");
if (success != null && success) {
return ResponseEntity.ok(result);
}
return ResponseEntity.badRequest().body(result);
}
@GetMapping("/needPrivilegeRecommenders") @GetMapping("/needPrivilegeRecommenders")
@Operation(summary = "按日期范围查询需要添加特权的推荐人") @Operation(summary = "按日期范围查询需要添加特权的推荐人")
public ResponseEntity<Map<String, Object>> needPrivilegeRecommenders( public ResponseEntity<Map<String, Object>> needPrivilegeRecommenders(

View File

@@ -53,7 +53,7 @@ public class HxrAdminOrderSelectService {
} }
private Optional<HxrOrderSelectResponse> fetchOrderSelectInternal(String requestUri) throws Exception { private Optional<HxrOrderSelectResponse> fetchOrderSelectInternal(String requestUri) throws Exception {
String cookieHeader = resolveCookieHeader(); String cookieHeader = properties.resolveCookieHeader();
if (cookieHeader == null || cookieHeader.isBlank()) { if (cookieHeader == null || cookieHeader.isBlank()) {
log.warn("hxr.admin 未配置 cookie 或 phpsid跳过拉取"); log.warn("hxr.admin 未配置 cookie 或 phpsid跳过拉取");
return Optional.empty(); return Optional.empty();
@@ -119,26 +119,6 @@ public class HxrAdminOrderSelectService {
} }
} }
private String resolveCookieHeader() {
String c = firstNonBlank(properties.getCookie());
if (c != null) {
return c;
}
String id = firstNonBlank(properties.getPhpsid());
if (id != null) {
return "PHPSID=" + id;
}
return "";
}
private static String firstNonBlank(String s) {
if (s == null) {
return null;
}
String t = s.trim();
return t.isEmpty() ? null : t;
}
private static String abbreviate(String s, int maxLen) { private static String abbreviate(String s, int maxLen) {
if (s == null) { if (s == null) {
return ""; return "";

View File

@@ -26,6 +26,13 @@ public interface ILbPurchaseApplyService extends IService<LbPurchaseApply> {
Map<String, Object> listNeedPrivilegeRecommenders(LocalDate startDate, LocalDate endDate); Map<String, Object> listNeedPrivilegeRecommenders(LocalDate startDate, LocalDate endDate);
/**
* 按申请日期区间与租户筛选进货申请,对不重复的 {@code apply_phone} 调用 hxrd 用户查询与更新接口,
* 写入 {@code max_order}、VIP/转卖/状态 及 {@code viptime}(当前时间 +2 天,若落在周末则顺延至下周一)。
*/
Map<String, Object> syncHxrAdminUserVipByApplyDateRange(
LocalDate applyDateStart, LocalDate applyDateEnd, String tenantId, Integer maxOrder);
/** /**
* 根据订货自然语言描述调用大模型解析为 {@link LbPurchaseApply}(不落库)。 * 根据订货自然语言描述调用大模型解析为 {@link LbPurchaseApply}(不落库)。
* *

View File

@@ -11,11 +11,13 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.rj.dto.hxr.HxrUserRow;
import com.rj.entity.LbDailyUserTradeReport; import com.rj.entity.LbDailyUserTradeReport;
import com.rj.entity.LbPurchaseApply; import com.rj.entity.LbPurchaseApply;
import com.rj.util.IsoWorkdayUtils; import com.rj.util.IsoWorkdayUtils;
import com.rj.mapper.LbDailyUserTradeReportMapper; import com.rj.mapper.LbDailyUserTradeReportMapper;
import com.rj.mapper.LbPurchaseApplyMapper; import com.rj.mapper.LbPurchaseApplyMapper;
import com.rj.service.HxrAdminUserService;
import com.rj.service.ILbPurchaseApplyService; import com.rj.service.ILbPurchaseApplyService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -31,6 +33,7 @@ import java.time.format.DateTimeFormatter;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.Set; import java.util.Set;
@Slf4j @Slf4j
@@ -42,6 +45,9 @@ public class LbPurchaseApplyServiceImpl
@Autowired @Autowired
private LbDailyUserTradeReportMapper lbDailyUserTradeReportMapper; private LbDailyUserTradeReportMapper lbDailyUserTradeReportMapper;
@Autowired
private HxrAdminUserService hxrAdminUserService;
@Autowired @Autowired
private ObjectMapper objectMapper; private ObjectMapper objectMapper;
@@ -502,4 +508,121 @@ public class LbPurchaseApplyServiceImpl
return result; return result;
} }
} }
@Override
public Map<String, Object> syncHxrAdminUserVipByApplyDateRange(
LocalDate applyDateStart, LocalDate applyDateEnd, String tenantId, Integer maxOrder) {
Map<String, Object> result = new HashMap<>();
try {
if (applyDateStart == null || applyDateEnd == null) {
result.put("success", false);
result.put("message", "申请开始日期与结束日期不能为空");
return result;
}
if (applyDateEnd.isBefore(applyDateStart)) {
result.put("success", false);
result.put("message", "结束日期不能早于开始日期");
return result;
}
if (tenantId == null || tenantId.trim().isEmpty()) {
result.put("success", false);
result.put("message", "租户id不能为空");
return result;
}
if (maxOrder == null) {
result.put("success", false);
result.put("message", "max_order不能为空");
return result;
}
LambdaQueryWrapper<LbPurchaseApply> q = new LambdaQueryWrapper<>();
q.eq(LbPurchaseApply::getTenantId, tenantId.trim())
.ge(LbPurchaseApply::getApplyDate, applyDateStart)
.le(LbPurchaseApply::getApplyDate, applyDateEnd);
List<LbPurchaseApply> rows = this.list(q);
if (rows == null || rows.isEmpty()) {
result.put("success", true);
result.put("message", "该条件下无申请记录,未调用第三方");
result.put("totalRecords", 0);
result.put("details", List.of());
result.put("applyDateStart", applyDateStart);
result.put("applyDateEnd", applyDateEnd);
result.put("tenantId", tenantId.trim());
return result;
}
List<Map<String, Object>> details = new ArrayList<>();
int ok = 0;
int fail = 0;
for (LbPurchaseApply row : rows) {
Map<String, Object> one = new HashMap<>();
one.put("applyId", row.getId());
one.put("applyDate", row.getApplyDate());
String phone = row.getApplyPhone() != null ? row.getApplyPhone().trim() : "";
one.put("applyPhone", phone);
if (phone.isEmpty()) {
one.put("success", false);
one.put("message", "apply_phone 为空,跳过");
fail++;
details.add(one);
continue;
}
if (row.getApplyDate() == null) {
one.put("success", false);
one.put("message", "applyDate 为空,跳过");
fail++;
details.add(one);
continue;
}
try {
LocalDateTime vipTime = HxrAdminUserService.computeVipExpireTime(row.getApplyDate());
String vipTimeStr = HxrAdminUserService.formatVipTime(vipTime);
one.put("viptime", vipTimeStr);
Optional<HxrUserRow> userOpt = hxrAdminUserService.fetchFirstUserByMobile(phone);
if (userOpt.isEmpty()) {
one.put("success", false);
one.put("message", "user/select 无用户或接口失败");
fail++;
details.add(one);
continue;
}
long hxrUserId = userOpt.get().id();
one.put("hxrUserId", hxrUserId);
boolean updated =
hxrAdminUserService.updateUserVipFields(hxrUserId, maxOrder, vipTimeStr);
if (updated) {
one.put("success", true);
one.put("message", "user/update 成功");
ok++;
} else {
one.put("success", false);
one.put("message", "user/update 失败");
fail++;
}
} catch (Exception ex) {
one.put("success", false);
one.put("message", "调用异常:" + ex.getMessage());
fail++;
}
details.add(one);
}
result.put("success", fail == 0);
result.put("message", fail == 0 ? "全部处理成功" : "部分或全部失败,见 details");
result.put("totalRecords", rows.size());
result.put("successCount", ok);
result.put("failCount", fail);
result.put("maxOrder", maxOrder);
result.put("details", details);
result.put("applyDateStart", applyDateStart);
result.put("applyDateEnd", applyDateEnd);
result.put("tenantId", tenantId.trim());
return result;
} catch (Exception e) {
result.put("success", false);
result.put("message", "处理异常:" + e.getMessage());
return result;
}
}
} }