1
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -64,6 +64,21 @@ public interface ISocialMediaService
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* 生成闲鱼文案(代下单、教你下单),并可选生成种草文案。
|
||||
*
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
@@ -97,6 +98,10 @@ public class SocialMediaServiceImpl implements ISocialMediaService
|
||||
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("油烟机", "侧吸式油烟机");
|
||||
@@ -538,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 获取模板
|
||||
*/
|
||||
|
||||
@@ -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