1
This commit is contained in:
@@ -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 获取模板
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user