Merge remote-tracking branch 'origin/0.8.X' into 0.8.X
This commit is contained in:
@@ -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) {
|
export function getProductSalesScript(scriptId) {
|
||||||
return request({
|
return request({
|
||||||
|
|||||||
44
klp-ui/src/components/MarkdownPreview.vue
Normal file
44
klp-ui/src/components/MarkdownPreview.vue
Normal 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>
|
||||||
@@ -12,6 +12,10 @@ export default {
|
|||||||
value: {
|
value: {
|
||||||
type: String,
|
type: String,
|
||||||
default: ''
|
default: ''
|
||||||
|
},
|
||||||
|
readonly: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
@@ -20,27 +24,40 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.vditor = new Vditor('vditor', {
|
const config = {
|
||||||
value: this.value,
|
value: this.value,
|
||||||
height: 360,
|
height: 360,
|
||||||
toolbarConfig: {
|
cache: { enable: false },
|
||||||
pin: true,
|
|
||||||
},
|
|
||||||
cache: {
|
|
||||||
enable: false,
|
|
||||||
},
|
|
||||||
after: () => {
|
after: () => {
|
||||||
this.vditor.setValue(this.value || '')
|
this.vditor.setValue(this.value || '')
|
||||||
},
|
},
|
||||||
input: (val) => {
|
input: (val) => {
|
||||||
this.$emit('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: {
|
watch: {
|
||||||
value(val) {
|
value(val) {
|
||||||
if (this.vditor && val !== this.vditor.getValue()) {
|
if (this.vditor && val !== this.vditor.getValue()) {
|
||||||
this.vditor.setValue(val || '')
|
this.vditor.setValue(val || '')
|
||||||
|
// 只读模式下内容变化时重新渲染mermaid
|
||||||
|
if (this.readonly && window.VditorPreview && typeof window.VditorPreview.mermaidRender === 'function') {
|
||||||
|
this.$nextTick(() => {
|
||||||
|
window.VditorPreview.mermaidRender(document);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
116
klp-ui/src/views/wms/productSalesScript/detail.vue
Normal file
116
klp-ui/src/views/wms/productSalesScript/detail.vue
Normal 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>
|
||||||
@@ -43,8 +43,8 @@
|
|||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
<div class="waterfall-list">
|
<div class="waterfall-list">
|
||||||
<div v-for="item in productSalesScriptList" :key="item.scriptId" class="waterfall-item">
|
<div v-for="item in productSalesScriptList" @click="goToDetail(item.scriptId)" :key="item.scriptId" class="waterfall-item">
|
||||||
<el-card shadow="hover">
|
<el-card shadow="hover" style="cursor:pointer;">
|
||||||
<div class="card-header" style="display: flex; justify-content: space-between; align-items: center;">
|
<div class="card-header" style="display: flex; justify-content: space-between; align-items: center;">
|
||||||
<div>
|
<div>
|
||||||
<strong>{{ item.scriptTitle }}</strong>
|
<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;">产品ID: {{ item.productName }} ({{ item.productCode }})</div>
|
||||||
<div style="font-size: 13px; color: #888;">备注: {{ item.remark }}</div>
|
<div style="font-size: 13px; color: #888;">备注: {{ item.remark }}</div>
|
||||||
<div style="margin-top: 12px; text-align: right;">
|
<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="primary" icon="el-icon-edit" @click.stop="handleUpdate(item)">修改</el-button>
|
||||||
<el-button size="mini" type="danger" icon="el-icon-delete" @click="handleDelete(item)">删除</el-button>
|
<el-button size="mini" type="danger" icon="el-icon-delete" @click.stop="handleDelete(item)">删除</el-button>
|
||||||
</div>
|
</div>
|
||||||
</el-card>
|
</el-card>
|
||||||
</div>
|
</div>
|
||||||
@@ -314,6 +314,10 @@ export default {
|
|||||||
this.download('system/productSalesScript/export', {
|
this.download('system/productSalesScript/export', {
|
||||||
...this.queryParams
|
...this.queryParams
|
||||||
}, `productSalesScript_${new Date().getTime()}.xlsx`)
|
}, `productSalesScript_${new Date().getTime()}.xlsx`)
|
||||||
|
},
|
||||||
|
// 跳转详情页
|
||||||
|
goToDetail(scriptId) {
|
||||||
|
this.$router.push({ path: `/shop/rich/${scriptId}` });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import java.util.Arrays;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.validation.constraints.*;
|
import javax.validation.constraints.*;
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import com.klp.common.annotation.RepeatSubmit;
|
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.core.page.TableDataInfo;
|
||||||
import com.klp.common.utils.redis.RedisUtils;
|
import com.klp.common.utils.redis.RedisUtils;
|
||||||
import java.time.Duration;
|
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}")
|
@GetMapping("/{scriptId}")
|
||||||
public R<WmsProductSalesScriptVo> getInfo(@NotNull(message = "主键不能为空")
|
public R<WmsProductSalesScriptVo> getInfo(@NotNull(message = "主键不能为空")
|
||||||
@PathVariable Long scriptId) {
|
@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}")
|
@GetMapping("/dashboard/ranking")
|
||||||
public R<Void> recordVisit(@NotNull(message = "产品ID不能为空") @PathVariable Long productId) {
|
public R<List<ProductRankingVo>> getProductRanking() {
|
||||||
String key = "product:visit:frequency:" + productId;
|
List<ProductRankingVo> ranking = iWmsProductSalesScriptService.getProductRanking();
|
||||||
// 原子递增访问次数,设置7天过期时间
|
return R.ok(ranking);
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,9 +36,4 @@ public class DashboardOverviewVO {
|
|||||||
* 客户分布
|
* 客户分布
|
||||||
*/
|
*/
|
||||||
private List<CustomerRegionVO> customerRegion;
|
private List<CustomerRegionVO> customerRegion;
|
||||||
|
|
||||||
/**
|
|
||||||
* 热门产品排行(基于访问频率)
|
|
||||||
*/
|
|
||||||
private List<HotProductVO> hotProducts;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,36 +3,36 @@ package com.klp.domain.vo;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 热门产品视图对象
|
* 产品咨询热度排行视图对象
|
||||||
*
|
*
|
||||||
* @author klp
|
* @author klp
|
||||||
* @date 2025-01-27
|
* @date 2025-07-24
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class HotProductVO {
|
public class ProductRankingVo {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 产品ID
|
* 产品ID
|
||||||
*/
|
*/
|
||||||
private Long productId;
|
private Long productId;
|
||||||
|
|
||||||
/**
|
|
||||||
* 产品名称
|
|
||||||
*/
|
|
||||||
private String productName;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 产品编号
|
* 产品编号
|
||||||
*/
|
*/
|
||||||
private String productCode;
|
private String productCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品名称
|
||||||
|
*/
|
||||||
|
private String productName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 访问次数
|
* 访问次数
|
||||||
*/
|
*/
|
||||||
private Long visitCount;
|
private Long viewCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 排名
|
* 排名
|
||||||
*/
|
*/
|
||||||
private Integer rank;
|
private Integer ranking;
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
package com.klp.service;
|
package com.klp.service;
|
||||||
|
|
||||||
import com.klp.domain.WmsProductSalesScript;
|
|
||||||
import com.klp.domain.vo.WmsProductSalesScriptVo;
|
import com.klp.domain.vo.WmsProductSalesScriptVo;
|
||||||
import com.klp.domain.bo.WmsProductSalesScriptBo;
|
import com.klp.domain.bo.WmsProductSalesScriptBo;
|
||||||
import com.klp.common.core.page.TableDataInfo;
|
import com.klp.common.core.page.TableDataInfo;
|
||||||
import com.klp.common.core.domain.PageQuery;
|
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.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -49,7 +48,12 @@ public interface IWmsProductSalesScriptService {
|
|||||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取热门产品排行(基于访问频率)
|
* 记录产品访问次数
|
||||||
*/
|
*/
|
||||||
List<HotProductVO> getHotProducts(Integer limit);
|
void recordProductViewCount(Long productId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取产品咨询热度排行
|
||||||
|
*/
|
||||||
|
List<ProductRankingVo> getProductRanking();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.klp.common.utils.StringUtils;
|
import com.klp.common.utils.StringUtils;
|
||||||
|
import com.klp.domain.WmsProduct;
|
||||||
|
import com.klp.mapper.WmsProductMapper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.klp.domain.bo.WmsProductSalesScriptBo;
|
import com.klp.domain.bo.WmsProductSalesScriptBo;
|
||||||
@@ -14,16 +16,16 @@ import com.klp.domain.vo.WmsProductSalesScriptVo;
|
|||||||
import com.klp.domain.WmsProductSalesScript;
|
import com.klp.domain.WmsProductSalesScript;
|
||||||
import com.klp.mapper.WmsProductSalesScriptMapper;
|
import com.klp.mapper.WmsProductSalesScriptMapper;
|
||||||
import com.klp.service.IWmsProductSalesScriptService;
|
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 com.klp.common.utils.redis.RedisUtils;
|
||||||
import java.util.stream.Collectors;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
|
||||||
import com.klp.domain.WmsProduct;
|
|
||||||
import com.klp.mapper.WmsProductMapper;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import org.redisson.api.RScoredSortedSet;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 产品销售话术Service业务层处理
|
* 产品销售话术Service业务层处理
|
||||||
@@ -36,7 +38,9 @@ import java.util.Collection;
|
|||||||
public class WmsProductSalesScriptServiceImpl implements IWmsProductSalesScriptService {
|
public class WmsProductSalesScriptServiceImpl implements IWmsProductSalesScriptService {
|
||||||
|
|
||||||
private final WmsProductSalesScriptMapper baseMapper;
|
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;
|
return baseMapper.deleteBatchIds(ids) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取热门产品排行(基于访问频率)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public List<HotProductVO> getHotProducts(Integer limit) {
|
public void recordProductViewCount(Long productId) {
|
||||||
// 获取所有产品访问频率的key
|
String countKey = "product:view:count:" + productId;
|
||||||
Collection<String> keys = RedisUtils.keys("product:visit:frequency:*");
|
String rankingKey = "product:view:ranking";
|
||||||
|
|
||||||
List<HotProductVO> hotProducts = keys.stream()
|
// 计数器+1(使用原子操作)
|
||||||
.map(key -> {
|
RedisUtils.incrAtomicValue(countKey);
|
||||||
String productIdStr = key.replace("product:visit:frequency:", "");
|
|
||||||
|
// 设置计数器过期时间为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);
|
Long productId = Long.valueOf(productIdStr);
|
||||||
Long visitCount = RedisUtils.getAtomicValue(key);
|
Double score = zSet.getScore(productIdStr);
|
||||||
|
Long viewCount = score != null ? score.longValue() : 0L;
|
||||||
|
|
||||||
// 查询产品信息
|
ProductRankingVo vo = new ProductRankingVo();
|
||||||
WmsProduct product = wmsProductMapper.selectById(productId);
|
|
||||||
if (product == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
HotProductVO vo = new HotProductVO();
|
|
||||||
vo.setProductId(productId);
|
vo.setProductId(productId);
|
||||||
vo.setProductName(product.getProductName());
|
vo.setViewCount(viewCount);
|
||||||
vo.setProductCode(product.getProductCode());
|
vo.setRanking(rank++);
|
||||||
vo.setVisitCount(visitCount);
|
|
||||||
return vo;
|
|
||||||
})
|
|
||||||
.filter(vo -> vo != null)
|
|
||||||
.sorted(Comparator.comparing(HotProductVO::getVisitCount).reversed())
|
|
||||||
.limit(limit)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
// 设置排名
|
//补充产品基础信息(这里需要注入ProductMapper)
|
||||||
for (int i = 0; i < hotProducts.size(); i++) {
|
WmsProduct product = wmsProductMapper.selectById(productId);
|
||||||
hotProducts.get(i).setRank(i + 1);
|
if (product != null) {
|
||||||
|
vo.setProductCode(product.getProductCode());
|
||||||
|
vo.setProductName(product.getProductName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return hotProducts;
|
rankingList.add(vo);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rankingList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ import com.klp.domain.WmsProduct;
|
|||||||
import com.klp.mapper.WmsProductMapper;
|
import com.klp.mapper.WmsProductMapper;
|
||||||
import com.klp.service.IWmsProductService;
|
import com.klp.service.IWmsProductService;
|
||||||
import com.klp.domain.vo.OrderSummaryVO;
|
import com.klp.domain.vo.OrderSummaryVO;
|
||||||
import com.klp.domain.vo.HotProductVO;
|
|
||||||
import com.klp.service.IWmsProductSalesScriptService;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -34,7 +32,6 @@ import java.util.Collection;
|
|||||||
public class WmsProductServiceImpl implements IWmsProductService {
|
public class WmsProductServiceImpl implements IWmsProductService {
|
||||||
|
|
||||||
private final WmsProductMapper baseMapper;
|
private final WmsProductMapper baseMapper;
|
||||||
private final IWmsProductSalesScriptService iWmsProductSalesScriptService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询产品
|
* 查询产品
|
||||||
@@ -152,8 +149,6 @@ public class WmsProductServiceImpl implements IWmsProductService {
|
|||||||
vo.setProductRank(baseMapper.selectProductRank());
|
vo.setProductRank(baseMapper.selectProductRank());
|
||||||
vo.setOrderMaterial(baseMapper.selectOrderMaterial());
|
vo.setOrderMaterial(baseMapper.selectOrderMaterial());
|
||||||
vo.setCustomerRegion(baseMapper.selectCustomerRegion());
|
vo.setCustomerRegion(baseMapper.selectCustomerRegion());
|
||||||
// 添加热门产品数据
|
|
||||||
vo.setHotProducts(iWmsProductSalesScriptService.getHotProducts(10));
|
|
||||||
return vo;
|
return vo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user