小程序商城段首页类目

This commit is contained in:
clunt 2022-05-10 16:02:27 +08:00
parent ad7357aea7
commit f05e7914b3
6 changed files with 105 additions and 6 deletions

View File

@ -1,9 +1,12 @@
package com.ghy.web.controller.goods;
import com.ghy.common.core.controller.BaseController;
import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.core.domain.Ztree;
import com.ghy.goods.domain.DeptGoodsCategory;
import com.ghy.goods.domain.GoodsCategory;
import com.ghy.goods.service.GoodsCategoryService;
import com.ghy.goods.service.GoodsDeptCategoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
@ -20,8 +23,9 @@ public class GoodsDeptCategoryController extends BaseController {
@Resource
GoodsCategoryService goodsCategoryService;
// @Resource
// GoodsDeptCategoryService goodsDeptCategoryService;
@Resource
GoodsDeptCategoryService goodsDeptCategoryService;
@RequiresPermissions("goods:deptcategory:view")
@GetMapping()
@ -54,4 +58,10 @@ public class GoodsDeptCategoryController extends BaseController {
return goodsCategoryService.selectCategoryTree(null);
}
@PostMapping("/app/list")
@ResponseBody
public AjaxResult appList(@RequestBody DeptGoodsCategory deptGoodsCategory){
return AjaxResult.success(goodsDeptCategoryService.appList(deptGoodsCategory.getDeptId()));
}
}

View File

@ -4,6 +4,8 @@ import com.ghy.common.annotation.Excel;
import com.ghy.common.core.domain.BaseEntity;
import lombok.Data;
import java.util.List;
/**
* @author clunt
* 分公司使用类目
@ -31,4 +33,11 @@ public class DeptGoodsCategory extends BaseEntity {
@Excel(name = "三级分销扣点比例", cellType = Excel.ColumnType.STRING)
private String threeRate;
private Long parentCategoryId;
private String goodsCategoryName;
private List<DeptGoodsCategory> child;
}

View File

@ -44,4 +44,7 @@ public interface DeptGoodsCategoryMapper {
*/
int deleteDeptGoodsCategoryByIds(Long[] goodsCategoryId);
List<DeptGoodsCategory> appList(DeptGoodsCategory deptGoodsCategory);
}

View File

@ -1,11 +1,18 @@
package com.ghy.goods.service;
import com.ghy.common.core.domain.Ztree;
import com.ghy.goods.domain.DeptGoodsCategory;
import java.util.List;
public interface GoodsDeptCategoryService {
List<Ztree> tree(Long parentId);
/**
* @param deptId 筛选条件
* @return 父子层级的list
*/
List<DeptGoodsCategory> appList(Long deptId);
}

View File

@ -1,17 +1,69 @@
package com.ghy.goods.service.impl;
import com.ghy.common.core.domain.Ztree;
import com.ghy.common.utils.StringUtils;
import com.ghy.goods.domain.DeptGoodsCategory;
import com.ghy.goods.mapper.DeptGoodsCategoryMapper;
import com.ghy.goods.service.DeptGoodsCategoryService;
import com.ghy.goods.service.GoodsDeptCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
* @author clunt
* 分公司使用类目
*/
@Slf4j
@Service
public class DeptGoodsCategoryServiceImpl implements DeptGoodsCategoryService {
public class DeptGoodsCategoryServiceImpl implements GoodsDeptCategoryService {
@Autowired
private DeptGoodsCategoryMapper goodsCategoryMapper;
@Override
public List<Ztree> tree(Long parentId) {
return null;
}
@Override
public List<DeptGoodsCategory> appList(Long deptId) {
DeptGoodsCategory deptGoodsCategory = new DeptGoodsCategory();
deptGoodsCategory.setDeptId(deptId);
// 第一层
List<DeptGoodsCategory> goodsCategoryList = goodsCategoryMapper.appList(deptGoodsCategory);
// 第二层
this.fillChild(goodsCategoryList);
// 第三层
for (DeptGoodsCategory category : goodsCategoryList){
if(StringUtils.isNotNull(category.getChild())){
this.fillChild(category.getChild());
}
}
// 第四层
for (DeptGoodsCategory category : goodsCategoryList){
if(StringUtils.isNotNull(category.getChild())){
for (DeptGoodsCategory result : category.getChild()){
if(StringUtils.isNotNull(result.getChild())){
this.fillChild(result.getChild());
}
}
}
}
return goodsCategoryList;
}
private void fillChild(List<DeptGoodsCategory> goodsCategoryList){
List<DeptGoodsCategory> childList;
for (DeptGoodsCategory deptGoodsCategory : goodsCategoryList){
childList = goodsCategoryMapper.appList(deptGoodsCategory);
if(childList.size()>0){
deptGoodsCategory.setChild(childList);
}
}
}
}

View File

@ -6,11 +6,12 @@
<result property="deptGoodsCategoryId" column="dept_goods_category_id"/>
<result property="deptId" column="dept_id"/>
<result property="goodsCategoryId" column="goods_category_id"/>
<result property="goodsCategoryName" column="goods_category_name"/>
<result property="parentCategoryId" column="parent_category_id" />
<result property="categorySort" column="category_sort"/>
<result property="oneRate" column="one_rate"/>
<result property="twoRate" column="two_rate"/>
<result property="threeRate" column="three_rate"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
@ -19,11 +20,28 @@
</resultMap>
<sql id="selectDeptGoodsCategory">
SELECT dept_goods_category_id, dept_id, dept_goods_category_id, category_sort,
SELECT dept_goods_category_id, dept_id, goods_category_id, category_sort,
one_rate, two_rate, three_rate, create_by, create_time, remark
FROM dept_goods_category
</sql>
<select id="appList" parameterType="com.ghy.goods.domain.DeptGoodsCategory" resultMap="DeptGoodsCategoryResult">
SELECT dgc.dept_goods_category_id, dgc.dept_id, dgc.goods_category_id, gc.goods_category_name, gc.parent_category_id, dgc.category_sort,
dgc.one_rate, dgc.two_rate, dgc.three_rate, dgc.create_by, dgc.create_time, dgc.remark
FROM dept_goods_category dgc
LEFT JOIN goods_category gc on gc.goods_category_id = dgc.goods_category_id
<where>
dgc.dept_id = #{deptId}
<if test="goodsCategoryId == null ">
and gc.parent_category_id is null
</if>
<if test="goodsCategoryId != null ">
and gc.parent_category_id = #{goodsCategoryId}
</if>
</where>
</select>
<update id="updateDeptGoodsCategory" parameterType="com.ghy.goods.domain.DeptGoodsCategory">
UPDATE dept_goods_category
<set>