This commit is contained in:
PQZ 2025-06-30 14:43:35 +08:00
parent 02b918182c
commit 74ee7e5eb9
12 changed files with 175 additions and 43 deletions

View File

@ -54,34 +54,39 @@ public class BusiCategoryController extends BaseController {
/** /**
* 获取网站栏目详细信息 * 获取网站栏目信息
*/ * @author PQZ
* @date 11:54 2025/6/30
* @param id id
* @return com.ruoyi.common.core.domain.AjaxResult
**/
@GetMapping(value = "/{id}") @GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") String id) { public AjaxResult getInfo(@PathVariable("id") String id) {
return success(busiCategoryService.getById(id)); return success(busiCategoryService.getById(id));
} }
/** /**
* 新增网站栏目 * 保存网站栏目
*/ * @author PQZ
* @date 11:54 2025/6/30
* @param busiCategory {@link BusiCategory}
* @return com.ruoyi.common.core.domain.AjaxResult
**/
@Log(title = "网站栏目", businessType = BusinessType.INSERT) @Log(title = "网站栏目", businessType = BusinessType.INSERT)
@PostMapping @PostMapping
public AjaxResult add(@RequestBody BusiCategory busiCategory) { public AjaxResult add(@RequestBody BusiCategory busiCategory) {
return toAjax(busiCategoryService.save(busiCategory)); return toAjax(busiCategoryService.saveOrUpdate(busiCategory));
} }
/**
* 修改网站栏目
*/
@Log(title = "网站栏目", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody BusiCategory busiCategory) {
return toAjax(busiCategoryService.updateById(busiCategory));
}
/** /**
* 删除网站栏目 * 删除网站栏目
*/ * @author PQZ
* @date 11:55 2025/6/30
* @param ids 删除id
* @return com.ruoyi.common.core.domain.AjaxResult
**/
@Log(title = "网站栏目", businessType = BusinessType.DELETE) @Log(title = "网站栏目", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}") @DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable String[] ids) { public AjaxResult remove(@PathVariable String[] ids) {

View File

@ -50,11 +50,11 @@ public class BusiCategory extends DlBaseEntity
/** 直接下级产品数 */ /** 直接下级产品数 */
@Excel(name = "直接下级产品数") @Excel(name = "直接下级产品数")
private Long prodsJunior; private Integer prodsJunior;
/** 递归产品数 */ /** 递归产品数 */
@Excel(name = "递归产品数") @Excel(name = "递归产品数")
private Long prodsAll; private Integer prodsAll;
/** 页面title */ /** 页面title */
@Excel(name = "页面title") @Excel(name = "页面title")

View File

@ -21,4 +21,12 @@ public interface BusiProdNewMapper extends BaseMapper<BusiProdNew>
IPage<ProdNewVO> queryListPage(@Param("entity") ProdNewVO entity, Page<BusiProdNew> page); IPage<ProdNewVO> queryListPage(@Param("entity") ProdNewVO entity, Page<BusiProdNew> page);
Long selectMaxSort(@Param("tenantId")String tenantId); Long selectMaxSort(@Param("tenantId")String tenantId);
/**
* 统计分类下产品数量
* @author PQZ
* @date 14:06 2025/6/30
* @return java.util.List<com.ruoyi.busi.vo.ProdNewVO>
**/
List<ProdNewVO> getCatgAmount();
} }

View File

@ -3,6 +3,7 @@ package com.ruoyi.busi.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.busi.domain.BusiCategory; import com.ruoyi.busi.domain.BusiCategory;
import com.ruoyi.busi.vo.BusiCategoryVO; import com.ruoyi.busi.vo.BusiCategoryVO;
import com.ruoyi.busi.vo.ProdNewVO;
import java.util.List; import java.util.List;
@ -24,4 +25,13 @@ public interface IBusiCategoryService extends IService<BusiCategory> {
**/ **/
List<BusiCategoryVO> treeCategory(BusiCategory category); List<BusiCategoryVO> treeCategory(BusiCategory category);
/**
* 设置直接产品数递归产品数
* @author PQZ
* @date 14:12 2025/6/30
**/
void setCategoryAmount(List<ProdNewVO> list,String tenantId);
} }

View File

@ -25,4 +25,13 @@ public interface IBusiProdNewService extends IService<BusiProdNew>
* @return java.lang.Long * @return java.lang.Long
**/ **/
Long getMaxSort(String tenantId); Long getMaxSort(String tenantId);
/**
* 为网站栏目中递归产品数和下级产品数赋值
* @author PQZ
* @date 14:03 2025/6/30
* @return void
**/
void setAmount(String tenantId);
} }

View File

@ -6,6 +6,7 @@ import com.ruoyi.busi.domain.BusiCategory;
import com.ruoyi.busi.mapper.BusiCategoryMapper; import com.ruoyi.busi.mapper.BusiCategoryMapper;
import com.ruoyi.busi.service.IBusiCategoryService; import com.ruoyi.busi.service.IBusiCategoryService;
import com.ruoyi.busi.vo.BusiCategoryVO; import com.ruoyi.busi.vo.BusiCategoryVO;
import com.ruoyi.busi.vo.ProdNewVO;
import com.ruoyi.common.core.domain.DlBaseEntity; import com.ruoyi.common.core.domain.DlBaseEntity;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
@ -51,6 +52,33 @@ public class BusiCategoryServiceImpl extends ServiceImpl<BusiCategoryMapper, Bus
return buildCategoryTree(list); return buildCategoryTree(list);
} }
/**
* 设置直接产品数递归产品数
*
* @author PQZ
* @date 14:12 2025/6/30
**/
@Override
public void setCategoryAmount(List<ProdNewVO> list,String tenantId) {
Map<String, Integer> idToProdsJunior = new HashMap<>();
list.forEach(item -> {
idToProdsJunior.put(item.getCatgId(),item.getAmount());
});
//查询全部栏目
LambdaQueryWrapper<BusiCategory> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(DlBaseEntity::getDelFlag,0)
.eq(BusiCategory::getTenantId,tenantId);
List<BusiCategory> categoryList = list(lambdaQueryWrapper);
//遍历赋值
categoryList.forEach(item->{
if (idToProdsJunior.containsKey(item.getId())) {
item.setProdsJunior(idToProdsJunior.get(item.getId()));
}
});
}
/** /**
* 生成树结构 * 生成树结构
@ -66,6 +94,8 @@ public class BusiCategoryServiceImpl extends ServiceImpl<BusiCategoryMapper, Bus
for (BusiCategory category : list) { for (BusiCategory category : list) {
BusiCategoryVO vo = new BusiCategoryVO(); BusiCategoryVO vo = new BusiCategoryVO();
BeanUtils.copyProperties(category,vo); BeanUtils.copyProperties(category,vo);
vo.setValue(category.getId());
vo.setLabel(category.getCatgName());
idToNodeMap.put(vo.getId(), vo); idToNodeMap.put(vo.getId(), vo);
} }
List<BusiCategoryVO> roots = new ArrayList<>(); List<BusiCategoryVO> roots = new ArrayList<>();

View File

@ -2,6 +2,7 @@ package com.ruoyi.busi.service.impl;
import java.util.List; import java.util.List;
import com.ruoyi.busi.service.IBusiCategoryService;
import com.ruoyi.busi.vo.ProdNewVO; import com.ruoyi.busi.vo.ProdNewVO;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
@ -24,6 +25,8 @@ public class BusiProdNewServiceImpl extends ServiceImpl<BusiProdNewMapper,BusiPr
{ {
@Autowired @Autowired
private BusiProdNewMapper busiProdNewMapper; private BusiProdNewMapper busiProdNewMapper;
@Autowired
private IBusiCategoryService categoryService;
@Override @Override
public IPage<ProdNewVO> queryListPage(ProdNewVO pageReqVO, Page<BusiProdNew> page) { public IPage<ProdNewVO> queryListPage(ProdNewVO pageReqVO, Page<BusiProdNew> page) {
@ -50,4 +53,19 @@ public class BusiProdNewServiceImpl extends ServiceImpl<BusiProdNewMapper,BusiPr
Long sort = busiProdNewMapper.selectMaxSort(tenantId); Long sort = busiProdNewMapper.selectMaxSort(tenantId);
return null==sort?1:sort+1; return null==sort?1:sort+1;
} }
/**
* 为网站栏目中递归产品数和下级产品数赋值
*
* @author PQZ
* @date 14:03 2025/6/30
**/
@Override
public void setAmount(String tenantId) {
//统计各分类产品数量
List<ProdNewVO> list = busiProdNewMapper.getCatgAmount();
if (!list.isEmpty()) {
categoryService.setCategoryAmount(list,tenantId);
}
}
} }

View File

@ -19,6 +19,9 @@ import java.util.List;
@Data @Data
public class BusiCategoryVO extends BusiCategory { public class BusiCategoryVO extends BusiCategory {
private String value;
private String label;
/** /**
* 子集 * 子集
*/ */

View File

@ -33,6 +33,9 @@ public class ProdNewVO extends BusiProdNew {
/** 随机产品数量 */ /** 随机产品数量 */
private Integer randomNum; private Integer randomNum;
/**同分类下产品数量*/
private Integer amount;
/** /**
* 批量传的图片 * 批量传的图片
**/ **/

View File

@ -112,4 +112,15 @@
del_flag = '0' del_flag = '0'
AND tenant_id = #{tenantId} AND tenant_id = #{tenantId}
</select> </select>
<select id="getCatgAmount" resultType="com.ruoyi.busi.vo.ProdNewVO">
SELECT
catg_id as catgId,
COUNT( id ) as amount
FROM
dl_busi_prod_new
WHERE
del_flag = 0
GROUP BY
catg_id
</select>
</mapper> </mapper>

View File

@ -11,7 +11,7 @@
</el-col> </el-col>
<el-col :span="8"> <el-col :span="8">
<el-form-item label="栏目类型" prop="catgType"> <el-form-item label="栏目类型" prop="catgType">
<el-select v-model="form.catgType" placeholder="请选择通告栏目类型" > <el-select :disabled="form.catgLevel > 1" v-model="form.catgType" placeholder="请选择通告栏目类型" >
<el-option <el-option
v-for="dict in dict.type.category_type" v-for="dict in dict.type.category_type"
:key="dict.value" :key="dict.value"
@ -28,18 +28,6 @@
</el-col> </el-col>
</el-row> </el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="产品上方内容html" prop="prodUp">
<el-input type="textarea" v-model="form.prodUp" placeholder="请输入产品上方内容html" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="产品下方内容html" prop="prodDown">
<el-input type="textarea" v-model="form.prodDown" placeholder="请输入产品下方内容html" />
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :span="12"> <el-col :span="12">
@ -59,8 +47,21 @@
</el-col> </el-col>
</el-row> </el-row>
<el-row v-if="form.catgType == 'cp'" :gutter="20">
<el-col :span="12">
<el-form-item label="产品上方内容html" prop="prodUp">
<el-input type="textarea" v-model="form.prodUp" placeholder="请输入产品上方内容html" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="产品下方内容html" prop="prodDown">
<el-input type="textarea" v-model="form.prodDown" placeholder="请输入产品下方内容html" />
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-row v-if="form.catgType == 'dym' || form.catgType == 'xp'">
<el-col> <el-col>
<el-form-item label="内容html" prop="content"> <el-form-item label="内容html" prop="content">
<editor v-model="form.content" :min-height="192"/> <editor v-model="form.content" :min-height="192"/>
@ -79,7 +80,7 @@
</template> </template>
<script> <script>
import {addCategory} from "@/api/busi/category"; import {addCategory,getCategory} from "@/api/busi/category";
export default { export default {
name: "categoryForm", name: "categoryForm",
dicts: ['category_type'], dicts: ['category_type'],
@ -99,8 +100,9 @@ export default {
prodDown:"", prodDown:"",
content:"" content:""
}, },
id:null,
// //
query:{}, isChild:false,
// //
rules:{ rules:{
code: [ code: [
@ -116,19 +118,18 @@ export default {
} }
}, },
created() { created() {
this.query = this.$route.query if (this.$route.query.id){
this.id = this.$route.query.id
this.initCategory(this.$route.query.id)
} else {
this.form = this.$route.query
}
}, },
methods:{ methods:{
/**确定按钮*/ /**确定按钮*/
submitForm(){ submitForm(){
if (this.query.catgLevel){
this.form.catgLevel = this.query.catgLevel
}
if (this.query.parentId){
this.form.parentId = this.query.parentId
}
addCategory(this.form).then((res) => { addCategory(this.form).then((res) => {
if (res.code == 200){ if (res.code == 200){
this.$modal.msgSuccess("保存成功"); this.$modal.msgSuccess("保存成功");
@ -137,6 +138,15 @@ export default {
}); });
}, },
/**获取网站栏目分类*/
initCategory(id){
getCategory(id).then((res)=>{
if (res.code == 200){
this.form = res.data
}
})
},
/**取消按钮*/ /**取消按钮*/
cancel(){ cancel(){
this.reset(); this.reset();
@ -148,7 +158,17 @@ export default {
/**表单重置*/ /**表单重置*/
reset(){ reset(){
this.form = {
catgName:"",
catgType:"",
sort:"",
title:"",
keyword:"",
description:"",
prodUp:"",
prodDown:"",
content:""
}
} }
} }

View File

@ -52,12 +52,21 @@
<el-table-column label="操作" align="center" class-name="small-padding fixed-width"> <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button <el-button
v-if="scope.row.catgType != 'dym' && scope.row.catgType != 'cp'"
size="mini" size="mini"
type="text" type="text"
icon="el-icon-edit" icon="el-icon-document-copy"
@click="handleChildAdd(scope.row)" @click="handleChildAdd(scope.row)"
v-hasPermi="['busi:category:edit']" v-hasPermi="['busi:category:edit']"
>添加子栏目</el-button> >添加子栏目</el-button>
<el-button
v-if="scope.row.catgType == 'cp'"
size="mini"
type="text"
icon="el-icon-document-copy"
@click="handleChildAdd(scope.row)"
v-hasPermi="['busi:category:edit']"
>添加产品分类</el-button>
<el-button <el-button
size="mini" size="mini"
type="text" type="text"
@ -135,12 +144,18 @@ export default {
/**添加子栏目*/ /**添加子栏目*/
handleChildAdd(row){ handleChildAdd(row){
this.$router.push({path:'/category/categoryForm',query:{catgLevel:row.catgLevel+1,parentId:row.id}}) this.$router.push({path:'/category/categoryForm',query:{
catgLevel:row.catgLevel+1,
parentId:row.id,
catgType:row.catgType
}})
}, },
/** 修改按钮操作 */ /** 修改按钮操作 */
handleUpdate(row) { handleUpdate(row) {
this.$router.push({path:'/category/categoryForm',query:{
id:row.id,
}})
}, },
/** 删除按钮操作 */ /** 删除按钮操作 */