Merge remote-tracking branch 'origin/0.8.X' into 0.8.X

This commit is contained in:
2025-07-26 11:33:22 +08:00
11 changed files with 305 additions and 111 deletions

View File

@@ -9,6 +9,15 @@ export function listProductSalesScript(query) {
})
}
// 查询产品销售话术,只要标题和内容有一个配置就会被返回
export function searchProductSalesScript(keyword) {
return request({
url: '/klp/productSalesScript/list',
method: 'get',
params: { keyword }
})
}
// 查询产品销售话术详细
export function getProductSalesScript(scriptId) {
return request({

View File

@@ -0,0 +1,44 @@
<template>
<div ref="preview" class="markdown-preview" style="min-height: 192px;"></div>
</template>
<script>
import Vditor from 'vditor'
export default {
name: 'MarkdownPreview',
props: {
value: {
type: String,
default: ''
}
},
mounted() {
this.renderMarkdown();
},
watch: {
value() {
this.renderMarkdown();
}
},
methods: {
renderMarkdown() {
Vditor.preview(this.$refs.preview, this.value || '', {
anchor: 1,
hl: true,
math: { inlineDigit: true },
mermaid: true,
});
}
}
}
</script>
<style scoped>
.markdown-preview {
border: 1px solid #e4e7ed;
border-radius: 4px;
padding: 8px;
background: #fff;
}
</style>

View File

@@ -12,6 +12,10 @@ export default {
value: {
type: String,
default: ''
},
readonly: {
type: Boolean,
default: false
}
},
data() {
@@ -20,27 +24,40 @@ export default {
}
},
mounted() {
this.vditor = new Vditor('vditor', {
const config = {
value: this.value,
height: 360,
toolbarConfig: {
pin: true,
},
cache: {
enable: false,
},
cache: { enable: false },
after: () => {
this.vditor.setValue(this.value || '')
},
input: (val) => {
this.$emit('input', val)
}
})
};
if (this.readonly) {
config.toolbar = []; // 不显示工具栏
config.editable = false;
} else {
config.toolbarConfig = { pin: true };
config.editable = true;
}
this.vditor = new Vditor('vditor', config);
if (this.readonly) {
console.log(this.vditor)
this.vditor.vditor.disabled()
}
},
watch: {
value(val) {
if (this.vditor && val !== this.vditor.getValue()) {
this.vditor.setValue(val || '')
// 只读模式下内容变化时重新渲染mermaid
if (this.readonly && window.VditorPreview && typeof window.VditorPreview.mermaidRender === 'function') {
this.$nextTick(() => {
window.VditorPreview.mermaidRender(document);
});
}
}
}
}

View File

@@ -0,0 +1,116 @@
<template>
<div class="app-container">
<el-row :gutter="10" style="margin-bottom: 16px;">
<el-col :span="16">
<el-select
v-model="selectedId"
filterable
remote
clearable
placeholder="搜索并选择文章"
:remote-method="remoteSearch"
:loading="loading"
style="width: 100%;"
@change="fetchDetail"
>
<el-option
v-for="item in articleList"
:key="item.scriptId"
:label="item.scriptTitle"
:value="item.scriptId"
>
<div>
<span v-html="highlight(item.scriptTitle)"></span>
<span style="color:#999; font-size:12px; margin-left:8px;">{{ item.featurePoint }}</span>
</div>
</el-option>
</el-select>
</el-col>
</el-row>
<el-card v-if="detail" shadow="hover">
<div class="card-header" style="display: flex; justify-content: space-between; align-items: center;">
<div>
<strong>{{ detail.scriptTitle }}</strong>
<span style="margin-left: 8px; color: #999;">({{ detail.featurePoint }})</span>
</div>
<div>
<el-tag v-if="detail.isEnabled == 1 || detail.isEnabled === '1'" type="success">启用</el-tag>
<el-tag v-else type="info">禁用</el-tag>
</div>
</div>
<div style="margin: 8px 0;" v-loading="articleLoading">
<MarkdownPreview :value="detail.scriptContent" />
</div>
<div style="font-size: 13px; color: #888;">备注: {{ detail.remark }}</div>
</el-card>
<div v-else style="text-align:center; color:#999; margin-top:40px;">暂无数据</div>
</div>
</template>
<script>
import { getProductSalesScript, searchProductSalesScript } from "@/api/wms/productSalesScript";
import MarkdownPreview from '@/components/MarkdownPreview.vue';
export default {
name: "ProductSalesScriptDetail",
components: { MarkdownPreview },
data() {
return {
searchKeyword: "",
articleList: [],
selectedId: undefined,
detail: null,
loading: false,
articleLoading: false,
};
},
created() {
// 获取路由参数scriptId只查详情
const scriptId = this.$route?.params?.scriptId;
if (scriptId) {
this.fetchDetail(scriptId);
}
},
methods: {
// 初始化时带id只查详情不查列表
fetchList(keyword = "") {
this.loading = true;
searchProductSalesScript(keyword).then(res => {
const rows = res.rows || res.data || [];
this.articleList = rows;
}).finally(() => {
this.loading = false;
});
},
remoteSearch(query) {
this.searchKeyword = query;
this.fetchList(query);
},
highlight(text) {
if (!this.searchKeyword || !text) return text;
const reg = new RegExp(this.searchKeyword.replace(/[.*+?^${}()|[\]\\]/g, '\$&'), 'gi');
return text.replace(reg, match => `<span style='background:yellow;color:#d0021b;'>${match}</span>`);
},
fetchDetail(id) {
this.articleLoading = true;
getProductSalesScript(id).then(res => {
this.detail = res.data || null;
}).finally(() => {
this.articleLoading = false;
});
},
}
};
</script>
<style scoped>
.app-container {
max-width: 900px;
margin: 0 auto;
}
.card-header {
font-size: 20px;
margin-bottom: 8px;
}
</style>

View File

@@ -43,8 +43,8 @@
</el-row>
<div class="waterfall-list">
<div v-for="item in productSalesScriptList" :key="item.scriptId" class="waterfall-item">
<el-card shadow="hover">
<div v-for="item in productSalesScriptList" @click="goToDetail(item.scriptId)" :key="item.scriptId" class="waterfall-item">
<el-card shadow="hover" style="cursor:pointer;">
<div class="card-header" style="display: flex; justify-content: space-between; align-items: center;">
<div>
<strong>{{ item.scriptTitle }}</strong>
@@ -59,8 +59,8 @@
<div style="font-size: 13px; color: #888;">产品ID: {{ item.productName }} ({{ item.productCode }})</div>
<div style="font-size: 13px; color: #888;">备注: {{ item.remark }}</div>
<div style="margin-top: 12px; text-align: right;">
<el-button size="mini" type="primary" icon="el-icon-edit" @click="handleUpdate(item)">修改</el-button>
<el-button size="mini" type="danger" icon="el-icon-delete" @click="handleDelete(item)">删除</el-button>
<el-button size="mini" type="primary" icon="el-icon-edit" @click.stop="handleUpdate(item)">修改</el-button>
<el-button size="mini" type="danger" icon="el-icon-delete" @click.stop="handleDelete(item)">删除</el-button>
</div>
</el-card>
</div>
@@ -314,6 +314,10 @@ export default {
this.download('system/productSalesScript/export', {
...this.queryParams
}, `productSalesScript_${new Date().getTime()}.xlsx`)
},
// 跳转详情页
goToDetail(scriptId) {
this.$router.push({ path: `/shop/rich/${scriptId}` });
}
}
}

View File

@@ -6,7 +6,7 @@ import java.util.Arrays;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.klp.common.annotation.RepeatSubmit;
@@ -24,7 +24,7 @@ import com.klp.service.IWmsProductSalesScriptService;
import com.klp.common.core.page.TableDataInfo;
import com.klp.common.utils.redis.RedisUtils;
import java.time.Duration;
import com.klp.domain.vo.HotProductVO;
import com.klp.domain.vo.ProductRankingVo;
/**
* 产品销售话术
@@ -66,7 +66,14 @@ public class WmsProductSalesScriptController extends BaseController {
@GetMapping("/{scriptId}")
public R<WmsProductSalesScriptVo> getInfo(@NotNull(message = "主键不能为空")
@PathVariable Long scriptId) {
return R.ok(iWmsProductSalesScriptService.queryById(scriptId));
WmsProductSalesScriptVo vo = iWmsProductSalesScriptService.queryById(scriptId);
// 记录产品访问次数到Redis
if (vo != null && vo.getProductId() != null) {
iWmsProductSalesScriptService.recordProductViewCount(vo.getProductId());
}
return R.ok(vo);
}
/**
@@ -102,27 +109,11 @@ public class WmsProductSalesScriptController extends BaseController {
}
/**
* 记录话术访问频率
*
* @param productId 产品ID
* 获取产品咨询热度排行
*/
@PostMapping("/recordVisit/{productId}")
public R<Void> recordVisit(@NotNull(message = "产品ID不能为空") @PathVariable Long productId) {
String key = "product:visit:frequency:" + productId;
// 原子递增访问次数设置7天过期时间
long count = RedisUtils.incrAtomicValue(key);
if (count == 1) {
// 第一次访问时设置过期时间
RedisUtils.expire(key, Duration.ofDays(7));
}
return R.ok();
}
/**
* 获取热门产品排行(基于访问频率)
*/
@GetMapping("/hotProducts")
public R<List<HotProductVO>> getHotProducts(@RequestParam(defaultValue = "10") Integer limit) {
return R.ok(iWmsProductSalesScriptService.getHotProducts(limit));
@GetMapping("/dashboard/ranking")
public R<List<ProductRankingVo>> getProductRanking() {
List<ProductRankingVo> ranking = iWmsProductSalesScriptService.getProductRanking();
return R.ok(ranking);
}
}

View File

@@ -11,34 +11,29 @@ import java.util.List;
*/
@Data
public class DashboardOverviewVO {
/**
* 订单汇总
*/
private OrderSummaryVO orderSummary;
/**
* 销售经理饼图
*/
private List<SalesManagerPieVO> salesManagerPie;
/**
* 产品销量排行
*/
private List<ProductRankVO> productRank;
/**
* 订单物料分析
*/
private List<OrderMaterialVO> orderMaterial;
/**
* 客户分布
*/
private List<CustomerRegionVO> customerRegion;
/**
* 热门产品排行(基于访问频率)
*/
private List<HotProductVO> hotProducts;
}

View File

@@ -3,36 +3,36 @@ package com.klp.domain.vo;
import lombok.Data;
/**
* 热门产品视图对象
* 产品咨询热度排行视图对象
*
* @author klp
* @date 2025-01-27
* @date 2025-07-24
*/
@Data
public class HotProductVO {
public class ProductRankingVo {
/**
* 产品ID
*/
private Long productId;
/**
* 产品名称
*/
private String productName;
/**
* 产品编号
*/
private String productCode;
/**
* 产品名称
*/
private String productName;
/**
* 访问次数
*/
private Long visitCount;
private Long viewCount;
/**
* 排名
*/
private Integer rank;
private Integer ranking;
}

View File

@@ -1,11 +1,10 @@
package com.klp.service;
import com.klp.domain.WmsProductSalesScript;
import com.klp.domain.vo.WmsProductSalesScriptVo;
import com.klp.domain.bo.WmsProductSalesScriptBo;
import com.klp.common.core.page.TableDataInfo;
import com.klp.common.core.domain.PageQuery;
import com.klp.domain.vo.HotProductVO;
import com.klp.domain.vo.ProductRankingVo;
import java.util.Collection;
import java.util.List;
@@ -49,7 +48,12 @@ public interface IWmsProductSalesScriptService {
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
/**
* 获取热门产品排行(基于访问频率)
* 记录产品访问次数
*/
List<HotProductVO> getHotProducts(Integer limit);
void recordProductViewCount(Long productId);
/**
* 获取产品咨询热度排行
*/
List<ProductRankingVo> getProductRanking();
}

View File

@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.klp.common.utils.StringUtils;
import com.klp.domain.WmsProduct;
import com.klp.mapper.WmsProductMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.klp.domain.bo.WmsProductSalesScriptBo;
@@ -14,16 +16,16 @@ import com.klp.domain.vo.WmsProductSalesScriptVo;
import com.klp.domain.WmsProductSalesScript;
import com.klp.mapper.WmsProductSalesScriptMapper;
import com.klp.service.IWmsProductSalesScriptService;
import com.klp.domain.vo.HotProductVO;
import com.klp.domain.vo.ProductRankingVo;
import com.klp.common.utils.redis.RedisUtils;
import java.util.stream.Collectors;
import java.util.Comparator;
import com.klp.domain.WmsProduct;
import com.klp.mapper.WmsProductMapper;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Collection;
import org.redisson.api.RScoredSortedSet;
import javax.annotation.Resource;
/**
* 产品销售话术Service业务层处理
@@ -36,7 +38,9 @@ import java.util.Collection;
public class WmsProductSalesScriptServiceImpl implements IWmsProductSalesScriptService {
private final WmsProductSalesScriptMapper baseMapper;
private final WmsProductMapper wmsProductMapper;
@Resource
private WmsProductMapper wmsProductMapper;
/**
* 查询产品销售话术
@@ -125,43 +129,58 @@ public class WmsProductSalesScriptServiceImpl implements IWmsProductSalesScriptS
return baseMapper.deleteBatchIds(ids) > 0;
}
/**
* 获取热门产品排行(基于访问频率)
*/
@Override
public List<HotProductVO> getHotProducts(Integer limit) {
// 获取所有产品访问频率的key
Collection<String> keys = RedisUtils.keys("product:visit:frequency:*");
List<HotProductVO> hotProducts = keys.stream()
.map(key -> {
String productIdStr = key.replace("product:visit:frequency:", "");
Long productId = Long.valueOf(productIdStr);
Long visitCount = RedisUtils.getAtomicValue(key);
// 查询产品信息
WmsProduct product = wmsProductMapper.selectById(productId);
if (product == null) {
return null;
}
HotProductVO vo = new HotProductVO();
vo.setProductId(productId);
vo.setProductName(product.getProductName());
vo.setProductCode(product.getProductCode());
vo.setVisitCount(visitCount);
return vo;
})
.filter(vo -> vo != null)
.sorted(Comparator.comparing(HotProductVO::getVisitCount).reversed())
.limit(limit)
.collect(Collectors.toList());
// 设置排名
for (int i = 0; i < hotProducts.size(); i++) {
hotProducts.get(i).setRank(i + 1);
public void recordProductViewCount(Long productId) {
String countKey = "product:view:count:" + productId;
String rankingKey = "product:view:ranking";
// 计数器+1使用原子操作
RedisUtils.incrAtomicValue(countKey);
// 设置计数器过期时间为1天
RedisUtils.expire(countKey, 24 * 60 * 60);
// 更新排行榜使用ZSet操作
RScoredSortedSet<String> zSet = RedisUtils.getClient().getScoredSortedSet(rankingKey);
zSet.addScore(productId.toString(), 1);
// 设置排行榜过期时间为1天
RedisUtils.expire(rankingKey, 24 * 60 * 60);
}
@Override
public List<ProductRankingVo> getProductRanking() {
String rankingKey = "product:view:ranking";
// 获取排行榜前10名按访问次数降序
RScoredSortedSet<String> zSet = RedisUtils.getClient().getScoredSortedSet(rankingKey);
List<ProductRankingVo> rankingList = new ArrayList<>();
int rank = 1;
// 获取前10名的产品ID和分数
Collection<String> topProducts = zSet.valueRangeReversed(0, 9);
for (String productIdStr : topProducts) {
Long productId = Long.valueOf(productIdStr);
Double score = zSet.getScore(productIdStr);
Long viewCount = score != null ? score.longValue() : 0L;
ProductRankingVo vo = new ProductRankingVo();
vo.setProductId(productId);
vo.setViewCount(viewCount);
vo.setRanking(rank++);
//补充产品基础信息这里需要注入ProductMapper
WmsProduct product = wmsProductMapper.selectById(productId);
if (product != null) {
vo.setProductCode(product.getProductCode());
vo.setProductName(product.getProductName());
}
rankingList.add(vo);
}
return hotProducts;
return rankingList;
}
}

View File

@@ -16,8 +16,6 @@ import com.klp.domain.WmsProduct;
import com.klp.mapper.WmsProductMapper;
import com.klp.service.IWmsProductService;
import com.klp.domain.vo.OrderSummaryVO;
import com.klp.domain.vo.HotProductVO;
import com.klp.service.IWmsProductSalesScriptService;
import java.util.List;
import java.util.Map;
@@ -34,7 +32,6 @@ import java.util.Collection;
public class WmsProductServiceImpl implements IWmsProductService {
private final WmsProductMapper baseMapper;
private final IWmsProductSalesScriptService iWmsProductSalesScriptService;
/**
* 查询产品
@@ -152,8 +149,6 @@ public class WmsProductServiceImpl implements IWmsProductService {
vo.setProductRank(baseMapper.selectProductRank());
vo.setOrderMaterial(baseMapper.selectOrderMaterial());
vo.setCustomerRegion(baseMapper.selectCustomerRegion());
// 添加热门产品数据
vo.setHotProducts(iWmsProductSalesScriptService.getHotProducts(10));
return vo;
}
}