Compare commits
9
Commits
54c0e420bf
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f13538ba23 | ||
|
|
76fe4f1651 | ||
|
|
43c9a71150 | ||
|
|
630be449fd | ||
|
|
51461b2834 | ||
|
|
38e988077c | ||
|
|
ddb49ab073 | ||
|
|
b42bcc0335 | ||
|
|
954da9da60 |
@@ -141,6 +141,31 @@ public class CommentController extends BaseController {
|
|||||||
return success(map);
|
return success(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存型号与商品ID映射(京东:型号→京东商品ID;淘宝:京东商品ID→淘宝商品ID)
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('jarvis:comment:edit')")
|
||||||
|
@Log(title = "评论商品ID", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping("/redis/map")
|
||||||
|
public AjaxResult saveProductTypeMap(@RequestBody ProductTypeMapBody body) {
|
||||||
|
if (body == null) {
|
||||||
|
return error("参数不能为空");
|
||||||
|
}
|
||||||
|
commentService.saveProductTypeMap(body.getSource(), body.getKey(), body.getValue(), body.getOldKey());
|
||||||
|
return success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除型号与商品ID映射
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('jarvis:comment:edit')")
|
||||||
|
@Log(title = "评论商品ID", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/redis/map")
|
||||||
|
public AjaxResult deleteProductTypeMap(@RequestParam("source") String source, @RequestParam("key") String key) {
|
||||||
|
commentService.deleteProductTypeMap(source, key);
|
||||||
|
return success();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取评论(后端转发到外部服务,避免前端跨域)
|
* 获取评论(后端转发到外部服务,避免前端跨域)
|
||||||
* 请求转发至:GET {fetch-comments.base-url}/fetch_comments?product_id=xxx
|
* 请求转发至:GET {fetch-comments.base-url}/fetch_comments?product_id=xxx
|
||||||
@@ -161,5 +186,51 @@ public class CommentController extends BaseController {
|
|||||||
return error("调用获取评论接口失败: " + e.getMessage());
|
return error("调用获取评论接口失败: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品ID映射保存参数
|
||||||
|
*/
|
||||||
|
public static class ProductTypeMapBody {
|
||||||
|
/** jd 或 tb */
|
||||||
|
private String source;
|
||||||
|
/** 京东为型号名称,淘宝为京东商品ID */
|
||||||
|
private String key;
|
||||||
|
/** 京东为京东商品ID,淘宝为淘宝商品ID */
|
||||||
|
private String value;
|
||||||
|
/** 编辑前的 key,新增时为空 */
|
||||||
|
private String oldKey;
|
||||||
|
|
||||||
|
public String getSource() {
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSource(String source) {
|
||||||
|
this.source = source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKey(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOldKey() {
|
||||||
|
return oldKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOldKey(String oldKey) {
|
||||||
|
this.oldKey = oldKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+28
@@ -42,6 +42,20 @@ public class OrderProfitAnalysisController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出连续若干个月的利润和单量纯文本。不调用大模型。
|
||||||
|
*/
|
||||||
|
@GetMapping("/export-text")
|
||||||
|
public AjaxResult exportText(@RequestParam(value = "months", required = false) Integer months,
|
||||||
|
@RequestParam(value = "date", required = false) String date) {
|
||||||
|
try {
|
||||||
|
return AjaxResult.success(orderProfitAnalysisService.exportMonthsText(months, date));
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("导出利润文本失败", e);
|
||||||
|
return AjaxResult.error("导出失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 套固定提示词调用已配置大模型;push=true 时推企微。
|
* 套固定提示词调用已配置大模型;push=true 时推企微。
|
||||||
*/
|
*/
|
||||||
@@ -82,6 +96,20 @@ public class OrderProfitAnalysisController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 大模型调用记录(新的在前):开始时间、耗时、返回正文。
|
||||||
|
*/
|
||||||
|
@GetMapping("/call-logs")
|
||||||
|
public AjaxResult callLogs(@RequestParam(value = "limit", required = false) Integer limit) {
|
||||||
|
try {
|
||||||
|
int n = limit == null ? 30 : limit;
|
||||||
|
return AjaxResult.success(orderProfitAnalysisService.listCallLogs(n));
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("读取利润分析调用记录失败", e);
|
||||||
|
return AjaxResult.error("读取失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送记录(新的在前)。
|
* 发送记录(新的在前)。
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -156,6 +156,50 @@ public class SocialMediaController extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 闲鱼品类模板:发货说明、六个品类装箱清单、型号覆盖清单
|
||||||
|
*/
|
||||||
|
@GetMapping("/xianyu-template")
|
||||||
|
public AjaxResult listXianyuCopyTemplates()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return socialMediaService.listXianyuCopyTemplates();
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("获取闲鱼品类模板失败", e);
|
||||||
|
return AjaxResult.error("获取失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存闲鱼品类模板
|
||||||
|
*/
|
||||||
|
@Log(title = "保存闲鱼品类模板", businessType = BusinessType.UPDATE)
|
||||||
|
@PostMapping("/xianyu-template/save")
|
||||||
|
public AjaxResult saveXianyuCopyTemplate(@RequestBody Map<String, Object> request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return socialMediaService.saveXianyuCopyTemplate(request);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("保存闲鱼品类模板失败", e);
|
||||||
|
return AjaxResult.error("保存失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除闲鱼品类模板
|
||||||
|
*/
|
||||||
|
@Log(title = "删除闲鱼品类模板", businessType = BusinessType.DELETE)
|
||||||
|
@PostMapping("/xianyu-template/delete")
|
||||||
|
public AjaxResult deleteXianyuCopyTemplate(@RequestBody Map<String, Object> request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return socialMediaService.deleteXianyuCopyTemplate(request);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("删除闲鱼品类模板失败", e);
|
||||||
|
return AjaxResult.error("删除失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列出多套大模型接入配置及当前激活 id
|
* 列出多套大模型接入配置及当前激活 id
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# 闲鱼代下单装箱清单。在 ruoyi 使用的 Redis 里执行:redis-cli < xianyu_packlist_import.redis
|
||||||
|
# 型号特例另设,命中后覆盖品类清单,不与下面的内容拼接:
|
||||||
|
# SET "xianyu:sku_note:型号" "含厨改加装套件"
|
||||||
|
# 发货说明可选:SET "xianyu:ship_note" "当天付款当天排单,物流到达前电话联系预约安装。"
|
||||||
|
|
||||||
|
SET "xianyu:packlist:油烟机" "主机1台、装饰罩1套、止逆阀1个、排烟管1根、安装配件1包"
|
||||||
|
SET "xianyu:packlist:洗碗机" "主机1台、碗篮1套、进水管1根、排水管1根、安装配件1包"
|
||||||
|
SET "xianyu:packlist:消毒柜" "主机1台、层架1套、安装配件1包"
|
||||||
|
SET "xianyu:packlist:洗衣机" "主机1台、进水管1根、排水管1根、运输螺栓扳手1把"
|
||||||
|
SET "xianyu:packlist:洗烘套餐" "洗衣机1台、干衣机1台、叠放支架1套、进水管1根、排水管1根"
|
||||||
|
SET "xianyu:packlist:灶具" "灶具1台、锅支架2个、电池1节、进气管1根"
|
||||||
@@ -77,5 +77,16 @@ public interface ICommentService {
|
|||||||
* 获取Redis产品类型映射(淘宝)
|
* 获取Redis产品类型映射(淘宝)
|
||||||
*/
|
*/
|
||||||
Map<String, String> getTbProductTypeMap();
|
Map<String, String> getTbProductTypeMap();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存型号与商品ID映射。source 为 jd 或 tb。
|
||||||
|
* oldKey 为空表示新增;与 key 不同表示重命名。
|
||||||
|
*/
|
||||||
|
void saveProductTypeMap(String source, String key, String value, String oldKey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除型号与商品ID映射
|
||||||
|
*/
|
||||||
|
void deleteProductTypeMap(String source, String key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+14
-1
@@ -16,12 +16,25 @@ public interface IOrderProfitAnalysisService {
|
|||||||
Map<String, Object> buildStats(String periodType, String date);
|
Map<String, Object> buildStats(String periodType, String date);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统计 + AI 分析;push=true 时推送到企微。
|
* 导出连续若干个自然月的利润和单量纯文本,给本地助手看。不调用大模型,不含文案提示词。
|
||||||
|
*
|
||||||
|
* @param months 月数,1-24,空则 6
|
||||||
|
* @param date 结束月锚点 yyyy-MM-dd,空则本月
|
||||||
|
*/
|
||||||
|
Map<String, Object> exportMonthsText(Integer months, String date);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交一次 AI 分析后立即返回。模型调用在后台进行,结果写入调用记录。
|
||||||
*
|
*
|
||||||
* @param trigger scheduled / manual / test,写入发送记录
|
* @param trigger scheduled / manual / test,写入发送记录
|
||||||
*/
|
*/
|
||||||
Map<String, Object> analyze(String periodType, String date, boolean push, String profileId, String trigger);
|
Map<String, Object> analyze(String periodType, String date, boolean push, String profileId, String trigger);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 大模型调用记录,新的在前。含开始时间、耗时和返回正文。
|
||||||
|
*/
|
||||||
|
java.util.List<Map<String, Object>> listCallLogs(int limit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 读取最近一次分析结果(Redis)。
|
* 读取最近一次分析结果(Redis)。
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -64,6 +64,21 @@ public interface ISocialMediaService
|
|||||||
*/
|
*/
|
||||||
com.ruoyi.common.core.domain.AjaxResult deletePromptTemplate(String key);
|
com.ruoyi.common.core.domain.AjaxResult deletePromptTemplate(String key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 闲鱼代下单品类模板:发货说明、品类装箱清单、型号覆盖清单。
|
||||||
|
*/
|
||||||
|
com.ruoyi.common.core.domain.AjaxResult listXianyuCopyTemplates();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存一条闲鱼品类模板。type=ship|packlist|sku。
|
||||||
|
*/
|
||||||
|
com.ruoyi.common.core.domain.AjaxResult saveXianyuCopyTemplate(Map<String, Object> request);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除一条闲鱼品类模板。发货说明和品类清单删除后走内置默认或省略。
|
||||||
|
*/
|
||||||
|
com.ruoyi.common.core.domain.AjaxResult deleteXianyuCopyTemplate(Map<String, Object> request);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成闲鱼文案(代下单、教你下单),并可选生成种草文案。
|
* 生成闲鱼文案(代下单、教你下单),并可选生成种草文案。
|
||||||
*
|
*
|
||||||
|
|||||||
+49
-6
@@ -543,8 +543,12 @@ public class GoofishOrderPipeline {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ShipAddressParts addr = resolveShippingAddressParts(row);
|
ShipAddressParts addr = resolveShippingAddressParts(row);
|
||||||
if (StringUtils.isEmpty(addr.shipName) || StringUtils.isEmpty(addr.shipMobile)
|
String shipMobile = normalizeShipMobile(addr.shipMobile);
|
||||||
|| StringUtils.isEmpty(addr.shipAddress)) {
|
// 虚拟号(11位主号-分机、带空格、700 开头 15 位)过不了开放平台 ^1[3-9]\\d{9}$。
|
||||||
|
// 抽不出合法 11 位时不传寄件方,走闲管家后台默认发货地址。
|
||||||
|
boolean omitSender = shipMobile == null && StringUtils.isNotEmpty(addr.shipMobile);
|
||||||
|
if (!omitSender && (StringUtils.isEmpty(addr.shipName) || StringUtils.isEmpty(shipMobile)
|
||||||
|
|| StringUtils.isEmpty(addr.shipAddress))) {
|
||||||
patchShipError(row, "缺少收货人/手机/地址:详情无字段时请关联京东单并维护地址,或等平台返回收货字段");
|
patchShipError(row, "缺少收货人/手机/地址:详情无字段时请关联京东单并维护地址,或等平台返回收货字段");
|
||||||
if (goofishOrderChangeLogger != null) {
|
if (goofishOrderChangeLogger != null) {
|
||||||
goofishOrderChangeLogger.append(row.getId(), row.getAppKey(), row.getOrderNo(),
|
goofishOrderChangeLogger.append(row.getId(), row.getAppKey(), row.getOrderNo(),
|
||||||
@@ -557,8 +561,11 @@ public class GoofishOrderPipeline {
|
|||||||
IERPAccount cred = erpAccountResolver.resolve(row.getAppKey());
|
IERPAccount cred = erpAccountResolver.resolve(row.getAppKey());
|
||||||
OrderShipRequest ship = new OrderShipRequest(cred);
|
OrderShipRequest ship = new OrderShipRequest(cred);
|
||||||
ship.setOrderNo(row.getOrderNo());
|
ship.setOrderNo(row.getOrderNo());
|
||||||
|
if (omitSender) {
|
||||||
|
log.info("闲管家发货:号码不是合法手机号,不传寄件方,改用闲管家默认发货地址 orderNo={}", row.getOrderNo());
|
||||||
|
} else {
|
||||||
ship.setShipName(addr.shipName);
|
ship.setShipName(addr.shipName);
|
||||||
ship.setShipMobile(addr.shipMobile);
|
ship.setShipMobile(shipMobile);
|
||||||
ship.setShipAddress(addr.shipAddress);
|
ship.setShipAddress(addr.shipAddress);
|
||||||
if (addr.shipDistrictId != null) {
|
if (addr.shipDistrictId != null) {
|
||||||
ship.setShipDistrictId(addr.shipDistrictId);
|
ship.setShipDistrictId(addr.shipDistrictId);
|
||||||
@@ -572,6 +579,7 @@ public class GoofishOrderPipeline {
|
|||||||
if (StringUtils.isNotEmpty(addr.shipAreaName)) {
|
if (StringUtils.isNotEmpty(addr.shipAreaName)) {
|
||||||
ship.setShipAreaName(addr.shipAreaName);
|
ship.setShipAreaName(addr.shipAreaName);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ship.setWaybillNo(waybill.trim());
|
ship.setWaybillNo(waybill.trim());
|
||||||
ship.setExpressCode(expressCode);
|
ship.setExpressCode(expressCode);
|
||||||
ship.setExpressName(expressName);
|
ship.setExpressName(expressName);
|
||||||
@@ -816,6 +824,27 @@ public class GoofishOrderPipeline {
|
|||||||
row.setShipError(m);
|
row.setShipError(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开放平台 ship_mobile 只接受 {@code ^1[3-9]\\d{9}$}。
|
||||||
|
* 虚拟号里的空格、{@code -分机}、{@code 转}、前缀 86 先去掉,只留 11 位主号;700 开头的 15 位号返回 null。
|
||||||
|
*/
|
||||||
|
static String normalizeShipMobile(String raw) {
|
||||||
|
if (StringUtils.isEmpty(raw)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String digits = raw.replaceAll("\\D", "");
|
||||||
|
if (digits.startsWith("86") && digits.length() >= 13) {
|
||||||
|
String rest = digits.substring(2);
|
||||||
|
if (rest.length() >= 11 && rest.substring(0, 11).matches("1[3-9]\\d{9}")) {
|
||||||
|
return rest.substring(0, 11);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (digits.length() >= 11 && digits.substring(0, 11).matches("1[3-9]\\d{9}")) {
|
||||||
|
return digits.substring(0, 11);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private static class ShipAddressParts {
|
private static class ShipAddressParts {
|
||||||
String shipName;
|
String shipName;
|
||||||
String shipMobile;
|
String shipMobile;
|
||||||
@@ -983,9 +1012,11 @@ public class GoofishOrderPipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ShipAddressParts ship = resolveShippingAddressParts(row);
|
ShipAddressParts ship = resolveShippingAddressParts(row);
|
||||||
vo.setShipReceiverName(ship.shipName);
|
String normalizedMobile = normalizeShipMobile(ship.shipMobile);
|
||||||
vo.setShipReceiverMobile(ship.shipMobile);
|
boolean omitSender = normalizedMobile == null && StringUtils.isNotEmpty(ship.shipMobile);
|
||||||
vo.setShipFullAddress(StringUtils.isNotEmpty(ship.shipAddress) ? ship.shipAddress.trim() : "");
|
vo.setShipReceiverName(omitSender ? null : ship.shipName);
|
||||||
|
vo.setShipReceiverMobile(omitSender ? null : normalizedMobile);
|
||||||
|
vo.setShipFullAddress(omitSender || StringUtils.isEmpty(ship.shipAddress) ? "" : ship.shipAddress.trim());
|
||||||
|
|
||||||
String nGoofishAddr = normalizeAddrComparable(vo.getGoofishOrderFullAddress());
|
String nGoofishAddr = normalizeAddrComparable(vo.getGoofishOrderFullAddress());
|
||||||
String nShipAddr = normalizeAddrComparable(vo.getShipFullAddress());
|
String nShipAddr = normalizeAddrComparable(vo.getShipFullAddress());
|
||||||
@@ -1017,6 +1048,18 @@ public class GoofishOrderPipeline {
|
|||||||
}
|
}
|
||||||
hint.append("与闲鱼订单收件串不完全一致(可能已用京东补全或未刷新详情)");
|
hint.append("与闲鱼订单收件串不完全一致(可能已用京东补全或未刷新详情)");
|
||||||
}
|
}
|
||||||
|
if (omitSender) {
|
||||||
|
if (hint.length() > 0) {
|
||||||
|
hint.append(';');
|
||||||
|
}
|
||||||
|
hint.append("收件号码是虚拟号,整理不成 11 位手机号,本次不传寄件方,使用闲管家默认发货地址");
|
||||||
|
} else if (StringUtils.isNotEmpty(ship.shipMobile) && !ship.shipMobile.replaceAll("\\D", "").equals(normalizedMobile)
|
||||||
|
&& StringUtils.isNotEmpty(normalizedMobile)) {
|
||||||
|
if (hint.length() > 0) {
|
||||||
|
hint.append(';');
|
||||||
|
}
|
||||||
|
hint.append("虚拟号已取前 11 位主号作为寄件手机");
|
||||||
|
}
|
||||||
if (hint.length() == 0) {
|
if (hint.length() == 0) {
|
||||||
hint.append(goofishHasContact || goofishHasAddr ? "可对照下方两项文本核对收件信息" : "暂无闲鱼收件信息,请先刷新详情或关联京东单");
|
hint.append(goofishHasContact || goofishHasAddr ? "可对照下方两项文本核对收件信息" : "暂无闲鱼收件信息,请先刷新详情或关联京东单");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.ruoyi.jarvis.service.impl;
|
package com.ruoyi.jarvis.service.impl;
|
||||||
|
|
||||||
|
import com.ruoyi.common.exception.ServiceException;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.jarvis.domain.Comment;
|
import com.ruoyi.jarvis.domain.Comment;
|
||||||
import com.ruoyi.jarvis.domain.dto.CommentApiStatistics;
|
import com.ruoyi.jarvis.domain.dto.CommentApiStatistics;
|
||||||
import com.ruoyi.jarvis.domain.dto.CommentStatistics;
|
import com.ruoyi.jarvis.domain.dto.CommentStatistics;
|
||||||
@@ -287,6 +289,57 @@ public class CommentServiceImpl implements ICommentService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveProductTypeMap(String source, String key, String value, String oldKey) {
|
||||||
|
String redisKey = productTypeRedisKey(source);
|
||||||
|
String field = StringUtils.trim(key);
|
||||||
|
String mappedId = StringUtils.trim(value);
|
||||||
|
if (StringUtils.isBlank(field) || StringUtils.isBlank(mappedId)) {
|
||||||
|
throw new ServiceException(mapFieldLabel(source) + "和" + mapValueLabel(source) + "不能为空");
|
||||||
|
}
|
||||||
|
String previous = StringUtils.trim(oldKey);
|
||||||
|
boolean creating = StringUtils.isBlank(previous);
|
||||||
|
boolean renaming = !creating && !field.equals(previous);
|
||||||
|
if ((creating || renaming) && Boolean.TRUE.equals(stringRedisTemplate.opsForHash().hasKey(redisKey, field))) {
|
||||||
|
throw new ServiceException(mapFieldLabel(source) + "已存在");
|
||||||
|
}
|
||||||
|
stringRedisTemplate.opsForHash().put(redisKey, field, mappedId);
|
||||||
|
if (renaming) {
|
||||||
|
stringRedisTemplate.opsForHash().delete(redisKey, previous);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteProductTypeMap(String source, String key) {
|
||||||
|
String redisKey = productTypeRedisKey(source);
|
||||||
|
String field = StringUtils.trim(key);
|
||||||
|
if (StringUtils.isBlank(field)) {
|
||||||
|
throw new ServiceException(mapFieldLabel(source) + "不能为空");
|
||||||
|
}
|
||||||
|
stringRedisTemplate.opsForHash().delete(redisKey, field);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String productTypeRedisKey(String source) {
|
||||||
|
if (stringRedisTemplate == null) {
|
||||||
|
throw new ServiceException("Redis未配置,无法维护商品ID");
|
||||||
|
}
|
||||||
|
if ("jd".equals(source)) {
|
||||||
|
return PRODUCT_TYPE_MAP_PREFIX;
|
||||||
|
}
|
||||||
|
if ("tb".equals(source)) {
|
||||||
|
return PRODUCT_TYPE_MAP_PREFIX_TB;
|
||||||
|
}
|
||||||
|
throw new ServiceException("来源只能是京东或淘宝");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String mapFieldLabel(String source) {
|
||||||
|
return "tb".equals(source) ? "京东商品ID" : "型号名称";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String mapValueLabel(String source) {
|
||||||
|
return "tb".equals(source) ? "淘宝商品ID" : "京东商品ID";
|
||||||
|
}
|
||||||
|
|
||||||
private String getTodayDate() {
|
private String getTodayDate() {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
return sdf.format(new Date());
|
return sdf.format(new Date());
|
||||||
|
|||||||
+38
-7
@@ -78,7 +78,7 @@ public class InstructionServiceImpl implements IInstructionService {
|
|||||||
private static final int EXTERNAL_LOGISTICS_LIST_LIMIT = 35;
|
private static final int EXTERNAL_LOGISTICS_LIST_LIMIT = 35;
|
||||||
|
|
||||||
// 录单模板(与 jd/JDUtil 中 WENAN_D 保持一致)
|
// 录单模板(与 jd/JDUtil 中 WENAN_D 保持一致)
|
||||||
private static final String WENAN_D = "单:\n" + "{单号} \n" + "分销标记:{分销标记}\n" + "第三方单号:{第三方单号}\n" + "—————————\n" + "下单链接(必须用这个):\n" + "{链接}\n" + "下单地址(注意带分机):\n" + "{地址}\n" + "—————————\n" + "型号:{型号}\n" + "\n" + "下单人(需填):\n" + "\n" + "下单付款(注意核对):\n" + "\n" + "后返金额(注意核对):\n" + "\n" + "订单号(需填):\n" + "\n" + "物流链接(需填):\n" + "\n" + "物流单号(无链接时填):\n" + "\n" + "备注(下单号码有变动/没法带分机号的写这里):\n" + "{单的备注}\n" + "—————————\n" + "京粉实际价格:不用填";
|
private static final String WENAN_D = "单:\n" + "{单号} \n" + "分销标记:{分销标记}\n" + "第三方单号:{第三方单号}\n" + "—————————\n" + "下单链接(必须用这个):\n" + "{链接}\n" + "下单地址(注意带分机):\n" + "{地址}\n" + "—————————\n" + "型号:{型号}\n" + "\n" + "下单人(需填):\n" + "\n" + "下单付款(注意核对):\n" + "\n" + "后返金额(注意核对):\n" + "\n" + "成本价(注意核对):\n" + "\n" + "订单号(需填):\n" + "\n" + "物流链接(需填):\n" + "\n" + "物流单号(无链接时填):\n" + "\n" + "备注(下单号码有变动/没法带分机号的写这里):\n" + "{单的备注}\n" + "—————————\n" + "京粉实际价格:不用填";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> execute(String command) {
|
public List<String> execute(String command) {
|
||||||
@@ -1801,6 +1801,16 @@ public class InstructionServiceImpl implements IInstructionService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 成本价 = 下单付款 − 后返金额。付款为空时不写。 */
|
||||||
|
private static String formatCostPrice(Double payment, Double rebate) {
|
||||||
|
if (payment == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
java.math.BigDecimal pay = java.math.BigDecimal.valueOf(payment);
|
||||||
|
java.math.BigDecimal reb = rebate != null ? java.math.BigDecimal.valueOf(rebate) : java.math.BigDecimal.ZERO;
|
||||||
|
return pay.subtract(reb).setScale(2, java.math.RoundingMode.HALF_UP).toPlainString();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 格式化订单为新模板格式
|
* 格式化订单为新模板格式
|
||||||
*/
|
*/
|
||||||
@@ -1828,6 +1838,8 @@ public class InstructionServiceImpl implements IInstructionService {
|
|||||||
sb.append(order.getPaymentAmount() != null ? order.getPaymentAmount().toString() : "").append("\n");
|
sb.append(order.getPaymentAmount() != null ? order.getPaymentAmount().toString() : "").append("\n");
|
||||||
sb.append("后返金额(注意核对):\n");
|
sb.append("后返金额(注意核对):\n");
|
||||||
sb.append(order.getRebateAmount() != null ? order.getRebateAmount().toString() : "").append("\n");
|
sb.append(order.getRebateAmount() != null ? order.getRebateAmount().toString() : "").append("\n");
|
||||||
|
sb.append("成本价(注意核对):\n");
|
||||||
|
sb.append(formatCostPrice(order.getPaymentAmount(), order.getRebateAmount())).append("\n");
|
||||||
sb.append("订单号(需填):\n");
|
sb.append("订单号(需填):\n");
|
||||||
sb.append(order.getOrderId() != null ? order.getOrderId() : "").append("\n");
|
sb.append(order.getOrderId() != null ? order.getOrderId() : "").append("\n");
|
||||||
sb.append("物流链接(需填):\n");
|
sb.append("物流链接(需填):\n");
|
||||||
@@ -2024,19 +2036,33 @@ public class InstructionServiceImpl implements IInstructionService {
|
|||||||
}
|
}
|
||||||
System.out.println("下单付款: " + order.getPaymentAmount());
|
System.out.println("下单付款: " + order.getPaymentAmount());
|
||||||
|
|
||||||
// 后返金额(新格式)或后返金额(旧格式)
|
// 后返金额(新格式)或后返金额(旧格式)。显式填写的 0 要落库;字段缺失时不把默认 0 当成已填。
|
||||||
String rebateStr = fields.getOrDefault("后返金额(注意核对)", null);
|
String rebateStr = fields.get("后返金额(注意核对)");
|
||||||
if (rebateStr == null) {
|
if (rebateStr == null) {
|
||||||
rebateStr = fields.getOrDefault("后返金额", "0");
|
rebateStr = fields.get("后返金额");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
rebateStr = rebateStr.trim();
|
if (rebateStr != null && !rebateStr.trim().isEmpty()) {
|
||||||
if (!rebateStr.isEmpty() && !rebateStr.equals("0")) {
|
order.setRebateAmount(Double.parseDouble(rebateStr.trim()));
|
||||||
order.setRebateAmount(Double.parseDouble(rebateStr));
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("解析后返金额失败: " + rebateStr + ", error: " + e.getMessage());
|
System.out.println("解析后返金额失败: " + rebateStr + ", error: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
if (order.getRebateAmount() == null && order.getPaymentAmount() != null) {
|
||||||
|
String costStr = fields.get("成本价(注意核对)");
|
||||||
|
if (costStr == null) {
|
||||||
|
costStr = fields.get("成本价");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (costStr != null && !costStr.trim().isEmpty()) {
|
||||||
|
java.math.BigDecimal pay = java.math.BigDecimal.valueOf(order.getPaymentAmount());
|
||||||
|
java.math.BigDecimal cost = new java.math.BigDecimal(costStr.trim());
|
||||||
|
order.setRebateAmount(pay.subtract(cost).setScale(2, java.math.RoundingMode.HALF_UP).doubleValue());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("解析成本价失败: " + costStr + ", error: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
System.out.println("后返金额: " + order.getRebateAmount());
|
System.out.println("后返金额: " + order.getRebateAmount());
|
||||||
|
|
||||||
// 下单地址(新格式)或地址(旧格式)
|
// 下单地址(新格式)或地址(旧格式)
|
||||||
@@ -2119,7 +2145,12 @@ public class InstructionServiceImpl implements IInstructionService {
|
|||||||
extractFieldWithSeparator(input, fields, "型号:", "下单人(需填):");
|
extractFieldWithSeparator(input, fields, "型号:", "下单人(需填):");
|
||||||
extractFieldWithSeparator(input, fields, "下单人(需填):", "下单付款(注意核对):");
|
extractFieldWithSeparator(input, fields, "下单人(需填):", "下单付款(注意核对):");
|
||||||
extractFieldWithSeparator(input, fields, "下单付款(注意核对):", "后返金额(注意核对):");
|
extractFieldWithSeparator(input, fields, "下单付款(注意核对):", "后返金额(注意核对):");
|
||||||
|
if (input.contains("成本价(注意核对):")) {
|
||||||
|
extractFieldWithSeparator(input, fields, "后返金额(注意核对):", "成本价(注意核对):");
|
||||||
|
extractFieldWithSeparator(input, fields, "成本价(注意核对):", "订单号(需填):");
|
||||||
|
} else {
|
||||||
extractFieldWithSeparator(input, fields, "后返金额(注意核对):", "订单号(需填):");
|
extractFieldWithSeparator(input, fields, "后返金额(注意核对):", "订单号(需填):");
|
||||||
|
}
|
||||||
extractFieldWithSeparator(input, fields, "订单号(需填):", "物流链接(需填):");
|
extractFieldWithSeparator(input, fields, "订单号(需填):", "物流链接(需填):");
|
||||||
if (input.contains("物流单号(无链接时填):") || input.contains("物流单号:")) {
|
if (input.contains("物流单号(无链接时填):") || input.contains("物流单号:")) {
|
||||||
String waybillLabel = input.contains("物流单号(无链接时填):") ? "物流单号(无链接时填):" : "物流单号:";
|
String waybillLabel = input.contains("物流单号(无链接时填):") ? "物流单号(无链接时填):" : "物流单号:";
|
||||||
|
|||||||
+467
-15
@@ -14,6 +14,8 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
@@ -34,6 +36,10 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@@ -50,7 +56,12 @@ public class OrderProfitAnalysisServiceImpl implements IOrderProfitAnalysisServi
|
|||||||
private static final String REDIS_PROMPT_PREFIX = "social_media:prompt:";
|
private static final String REDIS_PROMPT_PREFIX = "social_media:prompt:";
|
||||||
private static final String REDIS_LATEST_PREFIX = "order_profit_analysis:latest:";
|
private static final String REDIS_LATEST_PREFIX = "order_profit_analysis:latest:";
|
||||||
private static final String REDIS_SEND_LOG = "order_profit_analysis:send_log";
|
private static final String REDIS_SEND_LOG = "order_profit_analysis:send_log";
|
||||||
|
private static final String REDIS_CALL_PREFIX = "order_profit_analysis:call:";
|
||||||
|
private static final String REDIS_CALL_IDS = "order_profit_analysis:call_ids";
|
||||||
private static final int SEND_LOG_MAX = 80;
|
private static final int SEND_LOG_MAX = 80;
|
||||||
|
private static final int CALL_LOG_MAX = 80;
|
||||||
|
/** 超过该时间仍是进行中,列表里记为失败,避免页面一直轮询 */
|
||||||
|
private static final long CALL_STALE_MS = 8L * 60L * 1000L;
|
||||||
private static final Pattern THINK_BLOCK = Pattern.compile(
|
private static final Pattern THINK_BLOCK = Pattern.compile(
|
||||||
"(?is)<think\\b[^>]*>.*?</think>");
|
"(?is)<think\\b[^>]*>.*?</think>");
|
||||||
private static final Pattern THINK_TAG = Pattern.compile("(?i)</?think\\b[^>]*>");
|
private static final Pattern THINK_TAG = Pattern.compile("(?i)</?think\\b[^>]*>");
|
||||||
@@ -133,6 +144,19 @@ public class OrderProfitAnalysisServiceImpl implements IOrderProfitAnalysisServi
|
|||||||
@Value("${jarvis.wecom.goofish-notify-touser:}")
|
@Value("${jarvis.wecom.goofish-notify-touser:}")
|
||||||
private String fallbackTouser;
|
private String fallbackTouser;
|
||||||
|
|
||||||
|
private final ExecutorService analyzeExecutor = Executors.newFixedThreadPool(2, r -> {
|
||||||
|
Thread t = new Thread(r, "order-profit-analyze");
|
||||||
|
t.setDaemon(true);
|
||||||
|
return t;
|
||||||
|
});
|
||||||
|
private final ConcurrentHashMap<String, String> localCallJson = new ConcurrentHashMap<>();
|
||||||
|
private final ConcurrentLinkedDeque<String> localCallIds = new ConcurrentLinkedDeque<>();
|
||||||
|
|
||||||
|
@PreDestroy
|
||||||
|
public void shutdownAnalyzeExecutor() {
|
||||||
|
analyzeExecutor.shutdownNow();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> buildStats(String periodType, String date) {
|
public Map<String, Object> buildStats(String periodType, String date) {
|
||||||
PeriodRange current = resolvePeriod(periodType, date, false);
|
PeriodRange current = resolvePeriod(periodType, date, false);
|
||||||
@@ -141,10 +165,245 @@ public class OrderProfitAnalysisServiceImpl implements IOrderProfitAnalysisServi
|
|||||||
return stats;
|
return stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> exportMonthsText(Integer months, String date) {
|
||||||
|
int n = months == null ? 6 : months;
|
||||||
|
if (n < 1) {
|
||||||
|
n = 1;
|
||||||
|
} else if (n > 24) {
|
||||||
|
n = 24;
|
||||||
|
}
|
||||||
|
LocalDate anchor = parseDate(date);
|
||||||
|
if (anchor == null) {
|
||||||
|
anchor = LocalDate.now(ZONE);
|
||||||
|
}
|
||||||
|
LocalDate endMonth = anchor.with(TemporalAdjusters.firstDayOfMonth());
|
||||||
|
LocalDate startMonth = endMonth.minusMonths(n - 1L);
|
||||||
|
LocalDate rangeEnd = endMonth.with(TemporalAdjusters.lastDayOfMonth());
|
||||||
|
|
||||||
|
List<MonthAcc> series = new ArrayList<>();
|
||||||
|
Map<String, MonthAcc> index = new LinkedHashMap<>();
|
||||||
|
DateTimeFormatter ym = DateTimeFormatter.ofPattern("yyyy-MM");
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
LocalDate m = startMonth.plusMonths(i);
|
||||||
|
MonthAcc acc = new MonthAcc();
|
||||||
|
acc.key = m.format(ym);
|
||||||
|
acc.label = m.getYear() + "年" + m.getMonthValue() + "月";
|
||||||
|
series.add(acc);
|
||||||
|
index.put(acc.key, acc);
|
||||||
|
}
|
||||||
|
|
||||||
|
JDOrder query = new JDOrder();
|
||||||
|
query.getParams().put("beginTime", startMonth.format(DAY));
|
||||||
|
query.getParams().put("endTime", rangeEnd.format(DAY));
|
||||||
|
List<JDOrder> rows = jdOrderService.selectJDOrderList(query);
|
||||||
|
if (rows == null) {
|
||||||
|
rows = Collections.emptyList();
|
||||||
|
}
|
||||||
|
int used = 0;
|
||||||
|
for (JDOrder o : rows) {
|
||||||
|
if (!isCountEnabled(o) || o.getOrderTime() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String key = o.getOrderTime().toInstant().atZone(ZONE).format(ym);
|
||||||
|
MonthAcc acc = index.get(key);
|
||||||
|
if (acc == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
used++;
|
||||||
|
acc.orderCount++;
|
||||||
|
String kind = markKind(blankTo(o.getDistributionMark(), "未标记"));
|
||||||
|
KindAcc ka = acc.byKind.computeIfAbsent(kind, k -> new KindAcc());
|
||||||
|
ka.orderCount++;
|
||||||
|
boolean refunded = o.getIsRefunded() != null && o.getIsRefunded() == 1;
|
||||||
|
if (refunded) {
|
||||||
|
acc.refundCount++;
|
||||||
|
ka.refundCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BigDecimal pay = money(o.getPaymentAmount());
|
||||||
|
BigDecimal reb = money(o.getRebateAmount());
|
||||||
|
acc.payment = acc.payment.add(pay);
|
||||||
|
acc.rebate = acc.rebate.add(reb);
|
||||||
|
ka.payment = ka.payment.add(pay);
|
||||||
|
ka.rebate = ka.rebate.add(reb);
|
||||||
|
if (o.getProfit() == null) {
|
||||||
|
acc.missingProfit++;
|
||||||
|
ka.missingProfit++;
|
||||||
|
} else {
|
||||||
|
BigDecimal pft = money(o.getProfit());
|
||||||
|
acc.profit = acc.profit.add(pft);
|
||||||
|
ka.profit = ka.profit.add(pft);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String text = renderMonthsText(series, LocalDate.now(ZONE));
|
||||||
|
log.info("导出利润文本 months={} rows={} used={} chars={}", n, rows.size(), used, text.length());
|
||||||
|
Map<String, Object> out = new LinkedHashMap<>();
|
||||||
|
out.put("text", text);
|
||||||
|
out.put("chars", text.length());
|
||||||
|
out.put("months", n);
|
||||||
|
out.put("begin", series.get(0).label);
|
||||||
|
out.put("end", series.get(series.size() - 1).label);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String renderMonthsText(List<MonthAcc> series, LocalDate today) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
MonthAcc first = series.get(0);
|
||||||
|
MonthAcc last = series.get(series.size() - 1);
|
||||||
|
String thisMonth = today.format(DateTimeFormatter.ofPattern("yyyy-MM"));
|
||||||
|
sb.append("慢单月度利润、单量与垫资\n");
|
||||||
|
sb.append("区间:").append(first.label).append(" 至 ").append(last.label);
|
||||||
|
if (thisMonth.equals(last.key)) {
|
||||||
|
sb.append("(").append(last.label).append("截至 ").append(today.format(DAY)).append(")");
|
||||||
|
}
|
||||||
|
sb.append("\n");
|
||||||
|
sb.append("口径:只含参与统计的单。退款计入总单量,不计入垫资、后返、利润。金额单位元。\n");
|
||||||
|
sb.append("垫资=有效单付款(垫给京东的钱)。后返=垫资里稍后收回的部分,不是收入。净垫资=垫资-后返。利润是订单上已经算好的 profit。\n");
|
||||||
|
sb.append("类型:自有单=F开头且除去F-W、F-H;代下单=仅F-W、F-H;代下单单=其余前缀。三类分开,不要合并。\n\n");
|
||||||
|
|
||||||
|
int sumOrder = 0;
|
||||||
|
int sumRefund = 0;
|
||||||
|
int sumMissing = 0;
|
||||||
|
BigDecimal sumPayment = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
BigDecimal sumRebate = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
BigDecimal sumProfit = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
Map<String, KindAcc> sumKind = new LinkedHashMap<>();
|
||||||
|
MonthAcc prev = null;
|
||||||
|
for (MonthAcc m : series) {
|
||||||
|
int valid = m.orderCount - m.refundCount;
|
||||||
|
sb.append(m.label).append('\n');
|
||||||
|
sb.append("总单 ").append(m.orderCount)
|
||||||
|
.append(" 退款 ").append(m.refundCount)
|
||||||
|
.append(" 有效 ").append(valid)
|
||||||
|
.append(" 缺利润 ").append(m.missingProfit)
|
||||||
|
.append('\n');
|
||||||
|
appendMoneyLine(sb, "合计", m.payment, m.rebate, m.profit, valid);
|
||||||
|
appendKindLine(sb, "自有单", m.byKind.get("自有单"));
|
||||||
|
appendKindLine(sb, "代下单", m.byKind.get("代下单"));
|
||||||
|
appendKindLine(sb, "代下单单", m.byKind.get("代下单单"));
|
||||||
|
KindAcc unmarked = m.byKind.get("未标记");
|
||||||
|
if (unmarked != null && unmarked.orderCount > 0) {
|
||||||
|
appendKindLine(sb, "未标记", unmarked);
|
||||||
|
}
|
||||||
|
if (prev == null) {
|
||||||
|
sb.append("较上月 —\n");
|
||||||
|
} else {
|
||||||
|
int prevValid = prev.orderCount - prev.refundCount;
|
||||||
|
sb.append("较上月 有效 ").append(signedInt(valid - prevValid))
|
||||||
|
.append(" 垫资 ").append(signedMoney(m.payment.subtract(prev.payment)))
|
||||||
|
.append(" 后返 ").append(signedMoney(m.rebate.subtract(prev.rebate)))
|
||||||
|
.append(" 净垫资 ").append(signedMoney(netAdvance(m).subtract(netAdvance(prev))))
|
||||||
|
.append(" 利润 ").append(signedMoney(m.profit.subtract(prev.profit)))
|
||||||
|
.append('\n');
|
||||||
|
}
|
||||||
|
sb.append('\n');
|
||||||
|
sumOrder += m.orderCount;
|
||||||
|
sumRefund += m.refundCount;
|
||||||
|
sumMissing += m.missingProfit;
|
||||||
|
sumPayment = sumPayment.add(m.payment);
|
||||||
|
sumRebate = sumRebate.add(m.rebate);
|
||||||
|
sumProfit = sumProfit.add(m.profit);
|
||||||
|
mergeKind(sumKind, m.byKind);
|
||||||
|
prev = m;
|
||||||
|
}
|
||||||
|
int sumValid = sumOrder - sumRefund;
|
||||||
|
sb.append("合计\n");
|
||||||
|
sb.append("总单 ").append(sumOrder)
|
||||||
|
.append(" 退款 ").append(sumRefund)
|
||||||
|
.append(" 有效 ").append(sumValid)
|
||||||
|
.append(" 缺利润 ").append(sumMissing)
|
||||||
|
.append('\n');
|
||||||
|
appendMoneyLine(sb, "合计", sumPayment, sumRebate, sumProfit, sumValid);
|
||||||
|
appendKindLine(sb, "自有单", sumKind.get("自有单"));
|
||||||
|
appendKindLine(sb, "代下单", sumKind.get("代下单"));
|
||||||
|
appendKindLine(sb, "代下单单", sumKind.get("代下单单"));
|
||||||
|
KindAcc unmarkedSum = sumKind.get("未标记");
|
||||||
|
if (unmarkedSum != null && unmarkedSum.orderCount > 0) {
|
||||||
|
appendKindLine(sb, "未标记", unmarkedSum);
|
||||||
|
}
|
||||||
|
sb.append('\n');
|
||||||
|
sb.append("请根据以上各月垫资规模、后返、净垫资、利润和单量分析收入与资金占用:趋势、三类各自占了多少垫资、后返和利润。后返不是收入。不要编造上面没有的数字。\n");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void appendKindLine(StringBuilder sb, String name, KindAcc src) {
|
||||||
|
KindAcc a = src == null ? new KindAcc() : src;
|
||||||
|
int valid = a.orderCount - a.refundCount;
|
||||||
|
sb.append(name).append(" 有效 ").append(valid).append(' ');
|
||||||
|
appendMoneyLine(sb, null, a.payment, a.rebate, a.profit, valid);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void appendMoneyLine(StringBuilder sb, String prefix, BigDecimal payment, BigDecimal rebate,
|
||||||
|
BigDecimal profit, int valid) {
|
||||||
|
if (prefix != null) {
|
||||||
|
sb.append(prefix).append(' ');
|
||||||
|
}
|
||||||
|
BigDecimal pay = payment == null ? BigDecimal.ZERO : payment;
|
||||||
|
BigDecimal reb = rebate == null ? BigDecimal.ZERO : rebate;
|
||||||
|
sb.append("垫资 ").append(plain(pay))
|
||||||
|
.append(" 后返 ").append(plain(reb))
|
||||||
|
.append(" 净垫资 ").append(plain(pay.subtract(reb)))
|
||||||
|
.append(" 利润 ").append(plain(profit))
|
||||||
|
.append(" 单均 ").append(plain(avgOf(profit, valid)))
|
||||||
|
.append('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BigDecimal netAdvance(MonthAcc m) {
|
||||||
|
BigDecimal pay = m.payment == null ? BigDecimal.ZERO : m.payment;
|
||||||
|
BigDecimal reb = m.rebate == null ? BigDecimal.ZERO : m.rebate;
|
||||||
|
return pay.subtract(reb);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void mergeKind(Map<String, KindAcc> sum, Map<String, KindAcc> part) {
|
||||||
|
for (Map.Entry<String, KindAcc> e : part.entrySet()) {
|
||||||
|
KindAcc dst = sum.computeIfAbsent(e.getKey(), k -> new KindAcc());
|
||||||
|
KindAcc src = e.getValue();
|
||||||
|
dst.orderCount += src.orderCount;
|
||||||
|
dst.refundCount += src.refundCount;
|
||||||
|
dst.missingProfit += src.missingProfit;
|
||||||
|
dst.payment = dst.payment.add(src.payment);
|
||||||
|
dst.rebate = dst.rebate.add(src.rebate);
|
||||||
|
dst.profit = dst.profit.add(src.profit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BigDecimal avgOf(BigDecimal profit, int valid) {
|
||||||
|
if (valid <= 0) {
|
||||||
|
return BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
return profit.divide(BigDecimal.valueOf(valid), 2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String plain(BigDecimal v) {
|
||||||
|
if (v == null) {
|
||||||
|
return "0.00";
|
||||||
|
}
|
||||||
|
return v.setScale(2, RoundingMode.HALF_UP).toPlainString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String signedInt(int n) {
|
||||||
|
return n > 0 ? "+" + n : String.valueOf(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String signedMoney(BigDecimal v) {
|
||||||
|
BigDecimal n = v == null ? BigDecimal.ZERO : v.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
if (n.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
|
return "+" + n.toPlainString();
|
||||||
|
}
|
||||||
|
return n.toPlainString();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> analyze(String periodType, String date, boolean push, String profileId, String trigger) {
|
public Map<String, Object> analyze(String periodType, String date, boolean push, String profileId, String trigger) {
|
||||||
PeriodRange current = resolvePeriod(periodType, date, false);
|
PeriodRange current = resolvePeriod(periodType, date, false);
|
||||||
return doAnalyze(periodType, current, push, profileId, trigger);
|
Map<String, Object> rec = newRunningRecord(current, push, trigger);
|
||||||
|
persistCall(rec, true);
|
||||||
|
Map<String, Object> snapshot = new LinkedHashMap<>(rec);
|
||||||
|
final String profile = profileId;
|
||||||
|
final String trig = normalizeTrigger(trigger);
|
||||||
|
analyzeExecutor.execute(() -> runRecorded(current, push, profile, trig, rec));
|
||||||
|
return snapshot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -191,14 +450,28 @@ public class OrderProfitAnalysisServiceImpl implements IOrderProfitAnalysisServi
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PeriodRange current = resolvePeriod(periodType, null, true);
|
PeriodRange current = resolvePeriod(periodType, null, true);
|
||||||
try {
|
Map<String, Object> rec = newRunningRecord(current, true, "scheduled");
|
||||||
Map<String, Object> result = doAnalyze(periodType, current, true, null, "scheduled");
|
persistCall(rec, true);
|
||||||
log.info("慢单利润分析定时完成 period={} pushed={} reportLen={}",
|
runRecorded(current, true, null, "scheduled", rec);
|
||||||
current.label, result.get("pushed"),
|
|
||||||
result.get("report") == null ? 0 : String.valueOf(result.get("report")).length());
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("慢单利润分析定时失败 periodType={} range={}", periodType, current.label, e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Map<String, Object>> listCallLogs(int limit) {
|
||||||
|
int n = limit <= 0 ? 30 : Math.min(limit, CALL_LOG_MAX);
|
||||||
|
List<Map<String, Object>> out = new ArrayList<>();
|
||||||
|
for (String id : readCallIds(n)) {
|
||||||
|
String json = readCallJson(id);
|
||||||
|
if (StringUtils.isEmpty(json)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
JSONObject jo = JSON.parseObject(json);
|
||||||
|
if (jo == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
markStaleCall(jo);
|
||||||
|
out.add(new LinkedHashMap<>(jo));
|
||||||
|
}
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Object> doAnalyze(String periodType, PeriodRange current, boolean push, String profileId,
|
private Map<String, Object> doAnalyze(String periodType, PeriodRange current, boolean push, String profileId,
|
||||||
@@ -211,18 +484,26 @@ public class OrderProfitAnalysisServiceImpl implements IOrderProfitAnalysisServi
|
|||||||
|
|
||||||
String report;
|
String report;
|
||||||
String aiError = null;
|
String aiError = null;
|
||||||
|
String rawReply = null;
|
||||||
|
long llmStart = System.currentTimeMillis();
|
||||||
|
long llmDurationMs = 0;
|
||||||
try {
|
try {
|
||||||
report = callJarvisLlm(prompt, profileId);
|
LlmReply llm = callJarvisLlm(prompt, profileId);
|
||||||
if (StringUtils.isEmpty(report)) {
|
llmDurationMs = llm.elapsedMs > 0 ? llm.elapsedMs : (System.currentTimeMillis() - llmStart);
|
||||||
|
rawReply = llm.text;
|
||||||
|
if (StringUtils.isEmpty(rawReply)) {
|
||||||
throw new RuntimeException("大模型返回为空");
|
throw new RuntimeException("大模型返回为空");
|
||||||
}
|
}
|
||||||
report = stripThinkTags(report);
|
report = stripThinkTags(rawReply);
|
||||||
if (StringUtils.isEmpty(report)) {
|
if (StringUtils.isEmpty(report)) {
|
||||||
throw new RuntimeException("大模型仅返回思考过程,无正文");
|
throw new RuntimeException("大模型仅返回思考过程,无正文");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
if (llmDurationMs <= 0) {
|
||||||
|
llmDurationMs = System.currentTimeMillis() - llmStart;
|
||||||
|
}
|
||||||
aiError = e.getMessage();
|
aiError = e.getMessage();
|
||||||
log.warn("慢单利润 AI 分析失败,改用数字摘要: {}", aiError);
|
log.warn("慢单利润 AI 分析失败,改用数字摘要,耗时 {} ms: {}", llmDurationMs, aiError);
|
||||||
report = buildFallbackReport(stats, aiError);
|
report = buildFallbackReport(stats, aiError);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,6 +537,9 @@ public class OrderProfitAnalysisServiceImpl implements IOrderProfitAnalysisServi
|
|||||||
result.put("llmJsonChars", statsJson.length());
|
result.put("llmJsonChars", statsJson.length());
|
||||||
result.put("report", report);
|
result.put("report", report);
|
||||||
result.put("aiError", aiError);
|
result.put("aiError", aiError);
|
||||||
|
result.put("llmDurationMs", llmDurationMs);
|
||||||
|
result.put("promptChars", prompt.length());
|
||||||
|
result.put("replyChars", rawReply == null ? 0 : rawReply.length());
|
||||||
result.put("pushed", pushed);
|
result.put("pushed", pushed);
|
||||||
result.put("pushError", pushError);
|
result.put("pushError", pushError);
|
||||||
result.put("toUser", toUser);
|
result.put("toUser", toUser);
|
||||||
@@ -651,7 +935,146 @@ public class OrderProfitAnalysisServiceImpl implements IOrderProfitAnalysisServi
|
|||||||
return DEFAULT_PROMPT;
|
return DEFAULT_PROMPT;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String callJarvisLlm(String message, String profileId) throws Exception {
|
private void runRecorded(PeriodRange current, boolean push, String profileId, String trigger,
|
||||||
|
Map<String, Object> rec) {
|
||||||
|
long started = longValue(rec.get("startedAtMs"));
|
||||||
|
try {
|
||||||
|
Map<String, Object> result = doAnalyze(current.type, current, push, profileId, trigger);
|
||||||
|
String aiError = result.get("aiError") == null ? "" : String.valueOf(result.get("aiError"));
|
||||||
|
rec.put("status", StringUtils.isEmpty(aiError) ? "success" : "failed");
|
||||||
|
rec.put("report", result.get("report"));
|
||||||
|
rec.put("aiError", StringUtils.isEmpty(aiError) ? null : aiError);
|
||||||
|
rec.put("pushed", result.get("pushed"));
|
||||||
|
rec.put("pushError", result.get("pushError"));
|
||||||
|
rec.put("llmDurationMs", result.get("llmDurationMs"));
|
||||||
|
rec.put("promptChars", result.get("promptChars"));
|
||||||
|
rec.put("replyChars", result.get("replyChars"));
|
||||||
|
rec.put("toUser", result.get("toUser"));
|
||||||
|
if (result.get("periodLabel") != null) {
|
||||||
|
rec.put("periodLabel", result.get("periodLabel"));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("慢单利润调用失败 id={}", rec.get("id"), e);
|
||||||
|
rec.put("status", "failed");
|
||||||
|
rec.put("aiError", e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage());
|
||||||
|
}
|
||||||
|
rec.put("finishedAt", java.time.LocalDateTime.now(ZONE).format(TS));
|
||||||
|
if (started > 0) {
|
||||||
|
rec.put("durationMs", System.currentTimeMillis() - started);
|
||||||
|
}
|
||||||
|
persistCall(rec, false);
|
||||||
|
log.info("慢单利润调用记录 id={} status={} durationMs={} llmMs={} replyChars={} error={}",
|
||||||
|
rec.get("id"), rec.get("status"), rec.get("durationMs"), rec.get("llmDurationMs"),
|
||||||
|
rec.get("replyChars"), rec.get("aiError"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> newRunningRecord(PeriodRange current, boolean push, String trigger) {
|
||||||
|
Map<String, Object> rec = new LinkedHashMap<>();
|
||||||
|
rec.put("id", UUID.randomUUID().toString().replace("-", ""));
|
||||||
|
rec.put("status", "running");
|
||||||
|
rec.put("startedAt", java.time.LocalDateTime.now(ZONE).format(TS));
|
||||||
|
rec.put("startedAtMs", System.currentTimeMillis());
|
||||||
|
rec.put("periodType", current.type);
|
||||||
|
rec.put("periodLabel", current.label);
|
||||||
|
rec.put("trigger", normalizeTrigger(trigger));
|
||||||
|
rec.put("push", push);
|
||||||
|
return rec;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void persistCall(Map<String, Object> rec, boolean create) {
|
||||||
|
String id = String.valueOf(rec.get("id"));
|
||||||
|
String json = JSON.toJSONString(rec);
|
||||||
|
localCallJson.put(id, json);
|
||||||
|
if (create) {
|
||||||
|
localCallIds.addFirst(id);
|
||||||
|
while (localCallIds.size() > CALL_LOG_MAX) {
|
||||||
|
String old = localCallIds.pollLast();
|
||||||
|
if (old != null) {
|
||||||
|
localCallJson.remove(old);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (redisTemplate == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
redisTemplate.opsForValue().set(REDIS_CALL_PREFIX + id, json, 40, TimeUnit.DAYS);
|
||||||
|
if (create) {
|
||||||
|
redisTemplate.opsForList().leftPush(REDIS_CALL_IDS, id);
|
||||||
|
redisTemplate.opsForList().trim(REDIS_CALL_IDS, 0, CALL_LOG_MAX - 1);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("写入利润分析调用记录失败: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> readCallIds(int n) {
|
||||||
|
if (redisTemplate != null) {
|
||||||
|
try {
|
||||||
|
List<String> ids = redisTemplate.opsForList().range(REDIS_CALL_IDS, 0, n - 1);
|
||||||
|
if (ids != null && !ids.isEmpty()) {
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("读取调用记录索引失败: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<String> ids = new ArrayList<>();
|
||||||
|
for (String id : localCallIds) {
|
||||||
|
ids.add(id);
|
||||||
|
if (ids.size() >= n) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String readCallJson(String id) {
|
||||||
|
if (redisTemplate != null) {
|
||||||
|
try {
|
||||||
|
String raw = redisTemplate.opsForValue().get(REDIS_CALL_PREFIX + id);
|
||||||
|
if (StringUtils.isNotEmpty(raw)) {
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("读取调用记录失败: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return localCallJson.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void markStaleCall(JSONObject jo) {
|
||||||
|
if (!"running".equals(jo.getString("status"))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
long started = jo.getLongValue("startedAtMs");
|
||||||
|
if (started <= 0 || System.currentTimeMillis() - started < CALL_STALE_MS) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
jo.put("status", "failed");
|
||||||
|
jo.put("finishedAt", java.time.LocalDateTime.now(ZONE).format(TS));
|
||||||
|
jo.put("durationMs", System.currentTimeMillis() - started);
|
||||||
|
if (StringUtils.isEmpty(jo.getString("aiError"))) {
|
||||||
|
jo.put("aiError", "调用未在时限内写回结果");
|
||||||
|
}
|
||||||
|
persistCall(new LinkedHashMap<>(jo), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static long longValue(Object value) {
|
||||||
|
if (value instanceof Number) {
|
||||||
|
return ((Number) value).longValue();
|
||||||
|
}
|
||||||
|
if (value == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return Long.parseLong(String.valueOf(value));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private LlmReply callJarvisLlm(String message, String profileId) throws Exception {
|
||||||
String base = jarvisBaseUrl == null ? "" : jarvisBaseUrl.trim();
|
String base = jarvisBaseUrl == null ? "" : jarvisBaseUrl.trim();
|
||||||
if (base.endsWith("/")) {
|
if (base.endsWith("/")) {
|
||||||
base = base.substring(0, base.length() - 1);
|
base = base.substring(0, base.length() - 1);
|
||||||
@@ -662,7 +1085,10 @@ public class OrderProfitAnalysisServiceImpl implements IOrderProfitAnalysisServi
|
|||||||
if (StringUtils.isNotEmpty(profileId)) {
|
if (StringUtils.isNotEmpty(profileId)) {
|
||||||
body.put("profileId", profileId.trim());
|
body.put("profileId", profileId.trim());
|
||||||
}
|
}
|
||||||
String resp = postJson(url, body.toJSONString(), 15000, 180000);
|
// 须长于 Jarvis 调模型的读超时(360 秒),否则外层会先断开
|
||||||
|
long httpStart = System.currentTimeMillis();
|
||||||
|
String resp = postJson(url, body.toJSONString(), 15000, 420000);
|
||||||
|
long httpMs = System.currentTimeMillis() - httpStart;
|
||||||
if (StringUtils.isEmpty(resp)) {
|
if (StringUtils.isEmpty(resp)) {
|
||||||
throw new RuntimeException("Jarvis 返回为空,请检查服务可达性");
|
throw new RuntimeException("Jarvis 返回为空,请检查服务可达性");
|
||||||
}
|
}
|
||||||
@@ -682,7 +1108,21 @@ public class OrderProfitAnalysisServiceImpl implements IOrderProfitAnalysisServi
|
|||||||
if (!Boolean.TRUE.equals(data.getBoolean("success"))) {
|
if (!Boolean.TRUE.equals(data.getBoolean("success"))) {
|
||||||
throw new RuntimeException(StringUtils.isEmpty(data.getString("error")) ? "大模型调用失败" : data.getString("error"));
|
throw new RuntimeException(StringUtils.isEmpty(data.getString("error")) ? "大模型调用失败" : data.getString("error"));
|
||||||
}
|
}
|
||||||
return data.getString("reply");
|
long elapsed = data.getLongValue("elapsedMs");
|
||||||
|
if (elapsed <= 0) {
|
||||||
|
elapsed = httpMs;
|
||||||
|
}
|
||||||
|
return new LlmReply(data.getString("reply"), elapsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class LlmReply {
|
||||||
|
final String text;
|
||||||
|
final long elapsedMs;
|
||||||
|
|
||||||
|
LlmReply(String text, long elapsedMs) {
|
||||||
|
this.text = text;
|
||||||
|
this.elapsedMs = elapsedMs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> buildPushChunks(String title, String report) {
|
private List<String> buildPushChunks(String title, String report) {
|
||||||
@@ -1268,6 +1708,18 @@ public class OrderProfitAnalysisServiceImpl implements IOrderProfitAnalysisServi
|
|||||||
BigDecimal profit = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
|
BigDecimal profit = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final class MonthAcc {
|
||||||
|
String key;
|
||||||
|
String label;
|
||||||
|
int orderCount;
|
||||||
|
int refundCount;
|
||||||
|
int missingProfit;
|
||||||
|
BigDecimal payment = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
BigDecimal rebate = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
BigDecimal profit = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
Map<String, KindAcc> byKind = new LinkedHashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
private static final class KindAcc {
|
private static final class KindAcc {
|
||||||
int orderCount;
|
int orderCount;
|
||||||
int refundCount;
|
int refundCount;
|
||||||
|
|||||||
+287
-12
@@ -25,6 +25,7 @@ import java.util.Comparator;
|
|||||||
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.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.regex.PatternSyntaxException;
|
import java.util.regex.PatternSyntaxException;
|
||||||
@@ -56,6 +57,7 @@ public class SocialMediaServiceImpl implements ISocialMediaService
|
|||||||
"content:douyin",
|
"content:douyin",
|
||||||
"content:both",
|
"content:both",
|
||||||
"xianyu:wenan_base",
|
"xianyu:wenan_base",
|
||||||
|
"xianyu:wenan_extra",
|
||||||
"xianyu:jiaonixiadan_extra",
|
"xianyu:jiaonixiadan_extra",
|
||||||
"xianyu:title_clean_regex",
|
"xianyu:title_clean_regex",
|
||||||
"xianyu:seed_note_prompt",
|
"xianyu:seed_note_prompt",
|
||||||
@@ -68,7 +70,8 @@ public class SocialMediaServiceImpl implements ISocialMediaService
|
|||||||
put("content:xhs", "小红书文案生成提示词模板\n占位符:%s - 商品名称,%s - 价格信息,%s - 关键词信息");
|
put("content:xhs", "小红书文案生成提示词模板\n占位符:%s - 商品名称,%s - 价格信息,%s - 关键词信息");
|
||||||
put("content:douyin", "抖音文案生成提示词模板\n占位符:%s - 商品名称,%s - 价格信息,%s - 关键词信息");
|
put("content:douyin", "抖音文案生成提示词模板\n占位符:%s - 商品名称,%s - 价格信息,%s - 关键词信息");
|
||||||
put("content:both", "通用文案生成提示词模板\n占位符:%s - 商品名称,%s - 价格信息,%s - 关键词信息");
|
put("content:both", "通用文案生成提示词模板\n占位符:%s - 商品名称,%s - 价格信息,%s - 关键词信息");
|
||||||
put("xianyu:wenan_base", "闲鱼文案·正文基础说明\n用于「一键代下」与「教你下单」两版文案中,紧接在标题/型号行之后(纯文本,无占位符)");
|
put("xianyu:wenan_base", "闲鱼文案·代下单正文基础说明\n只用于「代下单」,紧接在标题/型号行之后(纯文本,无占位符)");
|
||||||
|
put("xianyu:wenan_extra", "闲鱼文案·代下单品类补充说明\n接在正文基础说明之后,独立成段;留空则整段省略,不额外空行(纯文本,无占位符)");
|
||||||
put("xianyu:jiaonixiadan_extra", "闲鱼文案·教你下单版尾部附加说明\n接在「更新日期:yyyy-MM-dd」之后(纯文本)");
|
put("xianyu:jiaonixiadan_extra", "闲鱼文案·教你下单版尾部附加说明\n接在「更新日期:yyyy-MM-dd」之后(纯文本)");
|
||||||
put("xianyu:title_clean_regex", "闲鱼文案·标题/型号清洗正则\n从标题与型号备注中移除营销敏感片段;须为 Java 正则,匹配到的内容会被删除");
|
put("xianyu:title_clean_regex", "闲鱼文案·标题/型号清洗正则\n从标题与型号备注中移除营销敏感片段;须为 Java 正则,匹配到的内容会被删除");
|
||||||
put("xianyu:seed_note_prompt", "闲鱼文案·种草文案提示词模板\n占位符:{{goods_title}} {{goods_model}} {{goods_type}} {{goods_brand}} {{channel_source}} {{official_price}} {{sell_price}} {{warranty}} {{delivery_install}}");
|
put("xianyu:seed_note_prompt", "闲鱼文案·种草文案提示词模板\n占位符:{{goods_title}} {{goods_model}} {{goods_type}} {{goods_brand}} {{channel_source}} {{official_price}} {{sell_price}} {{warranty}} {{delivery_install}}");
|
||||||
@@ -86,11 +89,28 @@ public class SocialMediaServiceImpl implements ISocialMediaService
|
|||||||
private static final String LLM_MODE_OLLAMA = "ollama";
|
private static final String LLM_MODE_OLLAMA = "ollama";
|
||||||
private static final String LLM_MODE_OPENAI = "openai";
|
private static final String LLM_MODE_OPENAI = "openai";
|
||||||
|
|
||||||
/** 闲鱼文案-通用基础说明(Redis 未配置时使用) */
|
/** 闲鱼文案-代下单基础说明(Redis 未配置时使用) */
|
||||||
private static final String DEFAULT_XIANYU_WENAN_BASE =
|
private static final String DEFAULT_XIANYU_WENAN_BASE =
|
||||||
"全新未拆封正品,包邮包安装,支持查验后再签收。\n"
|
"全新未拆封,整机配件齐全,全国联保。\n"
|
||||||
+ "运损可免费换新。\n"
|
+ "包邮包安装,支持查验后再签收。\n"
|
||||||
+ "售后全部支持全国联保。";
|
+ "运损可免费换新。";
|
||||||
|
/** 闲鱼文案-代下单品类补充(Redis 未配置时为空,生成时整段省略) */
|
||||||
|
private static final String DEFAULT_XIANYU_WENAN_EXTRA = "";
|
||||||
|
/** 闲鱼文案-发货说明(Redis 键 xianyu:ship_note 未配置时使用) */
|
||||||
|
private static final String DEFAULT_XIANYU_SHIP_NOTE = "当天付款当天排单,物流到达前电话联系预约安装。";
|
||||||
|
/** 品类维护页和标题骨架共用的固定顺序 */
|
||||||
|
private static final String[] XIANYU_CATEGORIES = {
|
||||||
|
"油烟机", "洗碗机", "消毒柜", "洗衣机", "洗烘套餐", "灶具"
|
||||||
|
};
|
||||||
|
/** 代下单标题里的品类骨架。不在表内的品类骨架为空,装箱清单仍按原值查 Redis */
|
||||||
|
private static final Map<String, String> CATEGORY_TITLE_SKELETON = new HashMap<String, String>() {{
|
||||||
|
put("油烟机", "侧吸式油烟机");
|
||||||
|
put("洗碗机", "嵌入式洗碗机");
|
||||||
|
put("消毒柜", "嵌入式消毒柜");
|
||||||
|
put("洗衣机", "滚筒洗衣机");
|
||||||
|
put("洗烘套餐", "洗烘套装");
|
||||||
|
put("灶具", "嵌入式燃气灶");
|
||||||
|
}};
|
||||||
/** 闲鱼文案-教你下单附加说明(不含更新日期) */
|
/** 闲鱼文案-教你下单附加说明(不含更新日期) */
|
||||||
private static final String DEFAULT_XIANYU_JIAONIXIADAN_EXTRA =
|
private static final String DEFAULT_XIANYU_JIAONIXIADAN_EXTRA =
|
||||||
"\n无偿提供下单方案,包价格成立:\n"
|
"\n无偿提供下单方案,包价格成立:\n"
|
||||||
@@ -98,7 +118,8 @@ public class SocialMediaServiceImpl implements ISocialMediaService
|
|||||||
+ "我会根据你所在地区和需求,\n"
|
+ "我会根据你所在地区和需求,\n"
|
||||||
+ "优先回复你合适的下单渠道和详细步骤,让你安全省钱地完成下单。";
|
+ "优先回复你合适的下单渠道和详细步骤,让你安全省钱地完成下单。";
|
||||||
/** 标题/型号清洗:去掉营销敏感词 */
|
/** 标题/型号清洗:去掉营销敏感词 */
|
||||||
private static final String DEFAULT_XIANYU_TITLE_CLEAN_REGEX = "以旧|政府|换新|领取|国家|补贴|15%|20%|国补|立减|【|】";
|
private static final String DEFAULT_XIANYU_TITLE_CLEAN_REGEX =
|
||||||
|
"以旧|政府|换新|领取|国家级|国家|补贴|15%|20%|国补|立减|【|】|客服|咨询|惊喜|618|价保|最好|最佳|最便宜|绝对|唯一|全网最低|假一赔|包退无忧|旗舰店";
|
||||||
/** 闲鱼种草文案提示词模板(Redis 未配置时使用) */
|
/** 闲鱼种草文案提示词模板(Redis 未配置时使用) */
|
||||||
private static final String DEFAULT_XIANYU_SEED_NOTE_PROMPT =
|
private static final String DEFAULT_XIANYU_SEED_NOTE_PROMPT =
|
||||||
"# 角色设定\n"
|
"# 角色设定\n"
|
||||||
@@ -192,6 +213,7 @@ public class SocialMediaServiceImpl implements ISocialMediaService
|
|||||||
+ "%s"
|
+ "%s"
|
||||||
+ "\n请直接生成文案内容,不要添加其他说明:");
|
+ "\n请直接生成文案内容,不要添加其他说明:");
|
||||||
put("xianyu:wenan_base", DEFAULT_XIANYU_WENAN_BASE);
|
put("xianyu:wenan_base", DEFAULT_XIANYU_WENAN_BASE);
|
||||||
|
put("xianyu:wenan_extra", DEFAULT_XIANYU_WENAN_EXTRA);
|
||||||
put("xianyu:jiaonixiadan_extra", DEFAULT_XIANYU_JIAONIXIADAN_EXTRA);
|
put("xianyu:jiaonixiadan_extra", DEFAULT_XIANYU_JIAONIXIADAN_EXTRA);
|
||||||
put("xianyu:title_clean_regex", DEFAULT_XIANYU_TITLE_CLEAN_REGEX);
|
put("xianyu:title_clean_regex", DEFAULT_XIANYU_TITLE_CLEAN_REGEX);
|
||||||
put("xianyu:seed_note_prompt", DEFAULT_XIANYU_SEED_NOTE_PROMPT);
|
put("xianyu:seed_note_prompt", DEFAULT_XIANYU_SEED_NOTE_PROMPT);
|
||||||
@@ -521,6 +543,188 @@ public class SocialMediaServiceImpl implements ISocialMediaService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AjaxResult listXianyuCopyTemplates() {
|
||||||
|
Map<String, Object> data = new HashMap<>();
|
||||||
|
boolean redisOk = redisTemplate != null;
|
||||||
|
data.put("redisAvailable", redisOk);
|
||||||
|
|
||||||
|
String ship = readXianyuRedis("xianyu:ship_note");
|
||||||
|
boolean shipDefault = StringUtils.isEmpty(ship);
|
||||||
|
Map<String, Object> shipNote = new HashMap<>();
|
||||||
|
shipNote.put("value", shipDefault ? DEFAULT_XIANYU_SHIP_NOTE : ship);
|
||||||
|
shipNote.put("isDefault", shipDefault);
|
||||||
|
data.put("shipNote", shipNote);
|
||||||
|
|
||||||
|
List<Map<String, Object>> categories = new ArrayList<>();
|
||||||
|
for (String category : XIANYU_CATEGORIES) {
|
||||||
|
Map<String, Object> row = new HashMap<>();
|
||||||
|
row.put("category", category);
|
||||||
|
row.put("skeleton", CATEGORY_TITLE_SKELETON.getOrDefault(category, ""));
|
||||||
|
row.put("packList", readXianyuRedis("xianyu:packlist:" + category));
|
||||||
|
categories.add(row);
|
||||||
|
}
|
||||||
|
data.put("categories", categories);
|
||||||
|
data.put("skuNotes", listSkuNotes());
|
||||||
|
return AjaxResult.success(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AjaxResult saveXianyuCopyTemplate(Map<String, Object> request) {
|
||||||
|
if (request == null) {
|
||||||
|
return AjaxResult.error("请求不能为空");
|
||||||
|
}
|
||||||
|
if (redisTemplate == null) {
|
||||||
|
return AjaxResult.error("Redis未配置,无法保存");
|
||||||
|
}
|
||||||
|
String type = trimToEmpty(asString(request.get("type")));
|
||||||
|
String value = request.get("value") == null ? "" : String.valueOf(request.get("value")).trim();
|
||||||
|
try {
|
||||||
|
if ("ship".equals(type)) {
|
||||||
|
if (StringUtils.isEmpty(value)) {
|
||||||
|
redisTemplate.delete("xianyu:ship_note");
|
||||||
|
return AjaxResult.success("已恢复默认发货说明");
|
||||||
|
}
|
||||||
|
redisTemplate.opsForValue().set("xianyu:ship_note", value);
|
||||||
|
return AjaxResult.success("保存成功");
|
||||||
|
}
|
||||||
|
if ("packlist".equals(type)) {
|
||||||
|
String category = trimToEmpty(asString(request.get("name")));
|
||||||
|
if (!isXianyuCategory(category)) {
|
||||||
|
return AjaxResult.error("品类不在可选范围内");
|
||||||
|
}
|
||||||
|
String key = "xianyu:packlist:" + category;
|
||||||
|
if (StringUtils.isEmpty(value)) {
|
||||||
|
redisTemplate.delete(key);
|
||||||
|
return AjaxResult.success("已清空,生成时将省略该品类装箱清单");
|
||||||
|
}
|
||||||
|
redisTemplate.opsForValue().set(key, value);
|
||||||
|
return AjaxResult.success("保存成功");
|
||||||
|
}
|
||||||
|
if ("sku".equals(type)) {
|
||||||
|
String model = normalizeSkuModel(asString(request.get("name")));
|
||||||
|
if (StringUtils.isEmpty(model)) {
|
||||||
|
return AjaxResult.error("型号清洗后为空,无法作为匹配键");
|
||||||
|
}
|
||||||
|
if (model.length() > 80) {
|
||||||
|
return AjaxResult.error("型号过长");
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(value)) {
|
||||||
|
return AjaxResult.error("型号清单不能为空,删除请点删除");
|
||||||
|
}
|
||||||
|
String oldName = trimToEmpty(asString(request.get("oldName")));
|
||||||
|
if (StringUtils.isNotEmpty(oldName) && !oldName.equals(model)) {
|
||||||
|
if (!isSafeSkuKeySuffix(oldName)) {
|
||||||
|
return AjaxResult.error("原型号无效");
|
||||||
|
}
|
||||||
|
redisTemplate.delete("xianyu:sku_note:" + oldName);
|
||||||
|
}
|
||||||
|
redisTemplate.opsForValue().set("xianyu:sku_note:" + model, value);
|
||||||
|
Map<String, Object> saved = new HashMap<>();
|
||||||
|
saved.put("model", model);
|
||||||
|
return AjaxResult.success("保存成功", saved);
|
||||||
|
}
|
||||||
|
return AjaxResult.error("未知的模板类型");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("保存闲鱼品类模板失败", e);
|
||||||
|
return AjaxResult.error("保存失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AjaxResult deleteXianyuCopyTemplate(Map<String, Object> request) {
|
||||||
|
if (request == null) {
|
||||||
|
return AjaxResult.error("请求不能为空");
|
||||||
|
}
|
||||||
|
if (redisTemplate == null) {
|
||||||
|
return AjaxResult.error("Redis未配置,无法删除");
|
||||||
|
}
|
||||||
|
String type = trimToEmpty(asString(request.get("type")));
|
||||||
|
try {
|
||||||
|
if ("ship".equals(type)) {
|
||||||
|
redisTemplate.delete("xianyu:ship_note");
|
||||||
|
return AjaxResult.success("已恢复默认发货说明");
|
||||||
|
}
|
||||||
|
if ("packlist".equals(type)) {
|
||||||
|
String category = trimToEmpty(asString(request.get("name")));
|
||||||
|
if (!isXianyuCategory(category)) {
|
||||||
|
return AjaxResult.error("品类不在可选范围内");
|
||||||
|
}
|
||||||
|
redisTemplate.delete("xianyu:packlist:" + category);
|
||||||
|
return AjaxResult.success("已清空,生成时将省略该品类装箱清单");
|
||||||
|
}
|
||||||
|
if ("sku".equals(type)) {
|
||||||
|
String model = trimToEmpty(asString(request.get("name")));
|
||||||
|
if (!isSafeSkuKeySuffix(model)) {
|
||||||
|
return AjaxResult.error("型号无效");
|
||||||
|
}
|
||||||
|
redisTemplate.delete("xianyu:sku_note:" + model);
|
||||||
|
return AjaxResult.success("已删除");
|
||||||
|
}
|
||||||
|
return AjaxResult.error("未知的模板类型");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("删除闲鱼品类模板失败", e);
|
||||||
|
return AjaxResult.error("删除失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Map<String, Object>> listSkuNotes() {
|
||||||
|
List<Map<String, Object>> skuNotes = new ArrayList<>();
|
||||||
|
if (redisTemplate == null) {
|
||||||
|
return skuNotes;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Set<String> keys = redisTemplate.keys("xianyu:sku_note:*");
|
||||||
|
if (keys == null || keys.isEmpty()) {
|
||||||
|
return skuNotes;
|
||||||
|
}
|
||||||
|
List<String> sorted = new ArrayList<>(keys);
|
||||||
|
sorted.sort(String::compareTo);
|
||||||
|
String prefix = "xianyu:sku_note:";
|
||||||
|
for (String key : sorted) {
|
||||||
|
if (key == null || !key.startsWith(prefix) || key.length() <= prefix.length()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Map<String, Object> row = new HashMap<>();
|
||||||
|
row.put("model", key.substring(prefix.length()));
|
||||||
|
row.put("packList", readXianyuRedis(key));
|
||||||
|
skuNotes.add(row);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("列举型号装箱清单失败", e);
|
||||||
|
}
|
||||||
|
return skuNotes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isXianyuCategory(String category) {
|
||||||
|
if (StringUtils.isEmpty(category)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (String item : XIANYU_CATEGORIES) {
|
||||||
|
if (item.equals(category)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 与代下单生成使用同一套清洗,保证页面上保存的型号能被命中。 */
|
||||||
|
private String normalizeSkuModel(String raw) {
|
||||||
|
String model = cleanTitleOrRemark(trimToEmpty(raw));
|
||||||
|
model = model.replaceAll("\\s{2,}", " ").trim();
|
||||||
|
if (model.indexOf('\n') >= 0 || model.indexOf('\r') >= 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isSafeSkuKeySuffix(String model) {
|
||||||
|
if (StringUtils.isEmpty(model) || model.length() > 80) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return model.indexOf('\n') < 0 && model.indexOf('\r') < 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从 Redis 获取模板
|
* 从 Redis 获取模板
|
||||||
*/
|
*/
|
||||||
@@ -1033,17 +1237,23 @@ public class SocialMediaServiceImpl implements ISocialMediaService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String category = trimToEmpty(asString(req.get("category")));
|
||||||
|
String brand = asString(req.get("brand"));
|
||||||
String wenanBase = getPromptTemplateWithDefault("xianyu:wenan_base", DEFAULT_XIANYU_WENAN_BASE);
|
String wenanBase = getPromptTemplateWithDefault("xianyu:wenan_base", DEFAULT_XIANYU_WENAN_BASE);
|
||||||
|
String shipNote = readXianyuRedis("xianyu:ship_note");
|
||||||
|
if (StringUtils.isEmpty(shipNote)) {
|
||||||
|
shipNote = DEFAULT_XIANYU_SHIP_NOTE;
|
||||||
|
}
|
||||||
|
String packList = resolvePackList(cleanRemark, category);
|
||||||
String jiaonixiadanExtra = getPromptTemplateWithDefault("xianyu:jiaonixiadan_extra", DEFAULT_XIANYU_JIAONIXIADAN_EXTRA);
|
String jiaonixiadanExtra = getPromptTemplateWithDefault("xianyu:jiaonixiadan_extra", DEFAULT_XIANYU_JIAONIXIADAN_EXTRA);
|
||||||
|
|
||||||
// 标题行
|
|
||||||
StringBuilder daixiadanBuilder = new StringBuilder();
|
StringBuilder daixiadanBuilder = new StringBuilder();
|
||||||
daixiadanBuilder.append(cleanTitle).append("\n");
|
daixiadanBuilder.append(buildDaixiadanTitleLine(brand, category, cleanRemark)).append("\n\n");
|
||||||
// 型号行(可选)
|
daixiadanBuilder.append(trimBlock(wenanBase)).append("\n\n");
|
||||||
if (StringUtils.isNotEmpty(cleanRemark)) {
|
if (StringUtils.isNotEmpty(packList)) {
|
||||||
daixiadanBuilder.append("型号:").append(cleanRemark).append("\n");
|
daixiadanBuilder.append("装箱清单:").append(packList).append("\n\n");
|
||||||
}
|
}
|
||||||
daixiadanBuilder.append(wenanBase);
|
daixiadanBuilder.append(trimBlock(shipNote));
|
||||||
|
|
||||||
// 教你下单版
|
// 教你下单版
|
||||||
StringBuilder jiaonixiadanBuilder = new StringBuilder();
|
StringBuilder jiaonixiadanBuilder = new StringBuilder();
|
||||||
@@ -1171,6 +1381,71 @@ public class SocialMediaServiceImpl implements ISocialMediaService
|
|||||||
return StringUtils.trim(value.toString());
|
return StringUtils.trim(value.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String trimToEmpty(String value) {
|
||||||
|
return value == null ? "" : value.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代下单标题:{品牌} {品类骨架} {型号} 全新未拆封 支持验货 全国联保。
|
||||||
|
* 骨架或型号缺失时该段省略,再把连续空格收成一个。
|
||||||
|
*/
|
||||||
|
private String buildDaixiadanTitleLine(String brand, String category, String cleanRemark) {
|
||||||
|
String brandText = StringUtils.isEmpty(brand) ? "海尔" : brand.trim();
|
||||||
|
String skeleton = "";
|
||||||
|
if (StringUtils.isNotEmpty(category)) {
|
||||||
|
String mapped = CATEGORY_TITLE_SKELETON.get(category);
|
||||||
|
if (mapped != null) {
|
||||||
|
skeleton = mapped;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StringBuilder line = new StringBuilder();
|
||||||
|
line.append(brandText);
|
||||||
|
if (StringUtils.isNotEmpty(skeleton)) {
|
||||||
|
line.append(' ').append(skeleton);
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotEmpty(cleanRemark)) {
|
||||||
|
line.append(' ').append(cleanRemark);
|
||||||
|
}
|
||||||
|
line.append(" 全新未拆封 支持验货 全国联保");
|
||||||
|
return line.toString().replaceAll("\\s{2,}", " ").trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 装箱清单:清洗后的型号命中 sku_note 则覆盖;否则用品类 packlist。都没有则返回空串。
|
||||||
|
*/
|
||||||
|
private String resolvePackList(String cleanRemark, String category) {
|
||||||
|
if (StringUtils.isNotEmpty(cleanRemark)) {
|
||||||
|
String skuNote = readXianyuRedis("xianyu:sku_note:" + cleanRemark);
|
||||||
|
if (StringUtils.isNotEmpty(skuNote)) {
|
||||||
|
return skuNote;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(category)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return readXianyuRedis("xianyu:packlist:" + category);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读运营 Redis。未配置、空白、Redis 不可用都返回空串,不向外抛错。
|
||||||
|
*/
|
||||||
|
private String readXianyuRedis(String key) {
|
||||||
|
if (redisTemplate == null || StringUtils.isEmpty(key)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return trimToEmpty(redisTemplate.opsForValue().get(key));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("读取闲鱼文案 Redis 失败,按未配置处理: {}", key, e);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 去掉段落首尾空白,保留中间换行。 */
|
||||||
|
private static String trimBlock(String block) {
|
||||||
|
return block == null ? "" : block.trim();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清洗标题/型号中的敏感词(正则来自可配置模板 xianyu:title_clean_regex)
|
* 清洗标题/型号中的敏感词(正则来自可配置模板 xianyu:title_clean_regex)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
-- 闲鱼目录下增加「品类模板」。menu_id 若冲突请改大号后执行。
|
||||||
|
-- 超级管理员登录后重新进入系统即可看到;已授权「发品」的角色一并授权本菜单。
|
||||||
|
INSERT INTO sys_menu (
|
||||||
|
menu_id, menu_name, parent_id, order_num, path, component, query, route_name,
|
||||||
|
is_frame, is_cache, menu_type, visible, status, perms, icon,
|
||||||
|
create_by, create_time, update_by, update_time, remark
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
2130, '品类模板', 2097, 1, 'xianyu-template', 'system/social-media/xianyu-template', '', '',
|
||||||
|
1, 0, 'C', '0', '0', '', 'edit',
|
||||||
|
'admin', sysdate(), '', NULL, '维护闲鱼代下单的发货说明、品类装箱清单和型号覆盖'
|
||||||
|
FROM DUAL
|
||||||
|
WHERE NOT EXISTS (SELECT 1 FROM sys_menu WHERE menu_id = 2130 OR (parent_id = 2097 AND path = 'xianyu-template'));
|
||||||
|
|
||||||
|
INSERT INTO sys_role_menu (role_id, menu_id)
|
||||||
|
SELECT rm.role_id, 2130
|
||||||
|
FROM sys_role_menu rm
|
||||||
|
WHERE rm.menu_id = 2034
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1 FROM sys_role_menu x WHERE x.role_id = rm.role_id AND x.menu_id = 2130
|
||||||
|
);
|
||||||
Reference in New Issue
Block a user