推荐人特权
This commit is contained in:
@@ -130,6 +130,29 @@ public class LbPurchaseApplyController {
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
|
||||
@GetMapping("/syncHxrAdminColleagueVip")
|
||||
@Operation(summary = "按申请日期与租户同步同事 hxrd 用户 VIP",
|
||||
description = "根据 lb_purchase_apply 的申请日期区间与 tenant_id 逐条处理,"
|
||||
+ "以 colleague_phone 查询 /app/admin/user/select,"
|
||||
+ "以每条记录的 apply_date 为起算日顺延 2 个自然日计算 viptime,"
|
||||
+ "再 POST /app/admin/user/update(max_order 使用 select 返回的 HxrUserRow.max_order)。"
|
||||
+ "需配置 hxr.admin.cookie 或 hxr.admin.phpsid。")
|
||||
public ResponseEntity<Map<String, Object>> syncHxrAdminColleagueVip(
|
||||
@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) {
|
||||
Map<String, Object> result = lbPurchaseApplyService.syncHxrAdminColleagueVipByApplyDateRange(
|
||||
applyDateStart, applyDateEnd, tenantId);
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success != null && success) {
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
|
||||
@GetMapping("/needPrivilegeRecommenders")
|
||||
@Operation(summary = "按日期范围查询需要添加特权的推荐人")
|
||||
public ResponseEntity<Map<String, Object>> needPrivilegeRecommenders(
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.rj.dto.hxr;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
* hxrd 后台 {@code /app/admin/user/select} 列表项(仅声明更新所需字段,其余字段忽略)。
|
||||
*/
|
||||
public record HxrUserRow(Long id) {}
|
||||
public record HxrUserRow(
|
||||
Long id,
|
||||
@JsonProperty("max_order") Integer maxOrder) {}
|
||||
|
||||
@@ -64,6 +64,20 @@ public class HxrAdminUserService {
|
||||
return LocalDateTime.of(d, now.toLocalTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* VIP 到期时间:以 {@code applyDate} 为起算日顺延 {@code calendarDays} 个自然日,时刻与当前时分秒一致。
|
||||
*/
|
||||
public static LocalDateTime computeVipExpireTimePlusCalendarDays(LocalDate applyDate, int calendarDays) {
|
||||
if (applyDate == null) {
|
||||
throw new IllegalArgumentException("applyDate不能为空");
|
||||
}
|
||||
if (calendarDays < 0) {
|
||||
throw new IllegalArgumentException("calendarDays不能为负");
|
||||
}
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
return LocalDateTime.of(applyDate.plusDays(calendarDays), now.toLocalTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用第三方接口
|
||||
* 按手机号查询用户列表,返回第一条。
|
||||
|
||||
@@ -33,6 +33,13 @@ public interface ILbPurchaseApplyService extends IService<LbPurchaseApply> {
|
||||
Map<String, Object> syncHxrAdminUserVipByApplyDateRange(
|
||||
LocalDate applyDateStart, LocalDate applyDateEnd, String tenantId, Integer maxOrder);
|
||||
|
||||
/**
|
||||
* 按申请日期区间与租户筛选进货申请,对每条记录的 {@code colleague_phone} 调用 hxrd 用户查询与更新,
|
||||
* 以 {@code apply_date} 为起算日顺延 2 个自然日写入 {@code viptime} 等 VIP 字段。
|
||||
*/
|
||||
Map<String, Object> syncHxrAdminColleagueVipByApplyDateRange(
|
||||
LocalDate applyDateStart, LocalDate applyDateEnd, String tenantId);
|
||||
|
||||
/**
|
||||
* 根据订货自然语言描述调用大模型解析为 {@link LbPurchaseApply}(不落库)。
|
||||
*
|
||||
|
||||
@@ -625,4 +625,127 @@ public class LbPurchaseApplyServiceImpl
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> syncHxrAdminColleagueVipByApplyDateRange(
|
||||
LocalDate applyDateStart, LocalDate applyDateEnd, String tenantId) {
|
||||
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;
|
||||
}
|
||||
|
||||
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());
|
||||
one.put("colleagueName", row.getColleagueName());
|
||||
String phone = row.getColleaguePhone() != null ? row.getColleaguePhone().trim() : "";
|
||||
one.put("colleaguePhone", phone);
|
||||
if (phone.isEmpty()) {
|
||||
one.put("success", false);
|
||||
one.put("message", "colleague_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.computeVipExpireTimePlusCalendarDays(row.getApplyDate(), 2);
|
||||
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;
|
||||
}
|
||||
HxrUserRow hxrUser = userOpt.get();
|
||||
long hxrUserId = hxrUser.id();
|
||||
one.put("hxrUserId", hxrUserId);
|
||||
Integer maxOrder = hxrUser.maxOrder();
|
||||
if (maxOrder == null) {
|
||||
one.put("success", false);
|
||||
one.put("message", "user/select 未返回 max_order,跳过");
|
||||
fail++;
|
||||
details.add(one);
|
||||
continue;
|
||||
}
|
||||
one.put("maxOrder", maxOrder);
|
||||
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("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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user