Showing
7 changed files
with
467 additions
and
0 deletions
1 | +package com.yoho.ufo.dal; | ||
2 | + | ||
3 | +import com.yoho.ufo.model.salecategory.SaleCategory; | ||
4 | + | ||
5 | +import java.util.List; | ||
6 | + | ||
7 | +/** | ||
8 | + * 品类mapper | ||
9 | + * | ||
10 | + * @author kun.wang | ||
11 | + * @date 2018/9/12 | ||
12 | + */ | ||
13 | +public interface SaleCategoryMapper { | ||
14 | + | ||
15 | + List<SaleCategory> selectAll(); | ||
16 | + | ||
17 | + | ||
18 | +} |
1 | +package com.yoho.ufo.model.salecategory; | ||
2 | + | ||
3 | +import lombok.Data; | ||
4 | +import lombok.ToString; | ||
5 | + | ||
6 | +/** | ||
7 | + * 销售类目 | ||
8 | + */ | ||
9 | +@Data | ||
10 | +@ToString | ||
11 | +public class SaleCategory { | ||
12 | + | ||
13 | + | ||
14 | + /** | ||
15 | + * id 主键 | ||
16 | + */ | ||
17 | + private Integer id; | ||
18 | + | ||
19 | + /** | ||
20 | + * 名称 | ||
21 | + */ | ||
22 | + private String categoryName; | ||
23 | + | ||
24 | + /** | ||
25 | + * 层级 | ||
26 | + */ | ||
27 | + private Integer level; | ||
28 | + | ||
29 | + /** | ||
30 | + * 状态 | ||
31 | + * 0:开启 | ||
32 | + * 1:关闭 | ||
33 | + */ | ||
34 | + private Integer status; | ||
35 | + | ||
36 | + /** | ||
37 | + * 父级id | ||
38 | + */ | ||
39 | + private Integer parentId; | ||
40 | + | ||
41 | + | ||
42 | + /** | ||
43 | + * 创建时间 | ||
44 | + */ | ||
45 | + private Integer createTime; | ||
46 | + | ||
47 | + /** | ||
48 | + * 更新时间 | ||
49 | + */ | ||
50 | + private Integer updateTime; | ||
51 | + | ||
52 | + /** | ||
53 | + * 排序值 | ||
54 | + */ | ||
55 | + private Integer orderBy; | ||
56 | + | ||
57 | + // | ||
58 | + private String linkType; | ||
59 | + | ||
60 | + private String linkDetail; | ||
61 | + | ||
62 | +} |
1 | +<?xml version="1.0" encoding="UTF-8" ?> | ||
2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > | ||
3 | +<mapper namespace="com.yoho.ufo.dal.SaleCategoryMapper"> | ||
4 | + | ||
5 | + <resultMap id="BaseResultMap" type="com.yoho.ufo.model.salecategory.SaleCategory"> | ||
6 | + <id property="id" column="id"/> | ||
7 | + <result property="categoryName" column="category_name"/> | ||
8 | + <result property="status" column="status"/> | ||
9 | + <result property="level" column="level"/> | ||
10 | + <result property="parentId" column="parent_id"/> | ||
11 | + <result property="orderBy" column="order_by"/> | ||
12 | + <result property="createTime" column="create_time"/> | ||
13 | + <result property="updateTime" column="update_time"/> | ||
14 | + <result property="linkType" column="link_type"/> | ||
15 | + <result property="linkDetail" column="link_detail"/> | ||
16 | + </resultMap> | ||
17 | + | ||
18 | + <sql id="Base_Column_List"> | ||
19 | + id, category_name, status, level, parent_id, order_by,create_time,update_time,link_type,link_detail | ||
20 | + </sql> | ||
21 | + | ||
22 | + | ||
23 | + <select id="selectAll" resultMap="BaseResultMap"> | ||
24 | + select <include refid="Base_Column_List" /> | ||
25 | + from sale_category where 1=1 | ||
26 | + order by level,order_by | ||
27 | + </select> | ||
28 | + | ||
29 | +</mapper> |
1 | +package com.yoho.ufo.controller.saleCategory; | ||
2 | + | ||
3 | +import com.yoho.ufo.service.ISaleCategoryService; | ||
4 | +import com.yohobuy.ufo.model.common.ApiResponse; | ||
5 | +import com.yohobuy.ufo.model.response.salecategory.SaleCategoryTreeViewResponseBo; | ||
6 | +import org.slf4j.Logger; | ||
7 | +import org.slf4j.LoggerFactory; | ||
8 | +import org.springframework.beans.factory.annotation.Autowired; | ||
9 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
10 | +import org.springframework.web.bind.annotation.RequestMethod; | ||
11 | +import org.springframework.web.bind.annotation.RestController; | ||
12 | + | ||
13 | +import java.util.List; | ||
14 | + | ||
15 | +/** | ||
16 | + * 销售类目controller | ||
17 | + * | ||
18 | + * @author craig.qin | ||
19 | + */ | ||
20 | +@RequestMapping(value = "/saleCategory") | ||
21 | +@RestController | ||
22 | +public class SaleCategoryController { | ||
23 | + | ||
24 | + private static final Logger LOGGER = LoggerFactory.getLogger(SaleCategoryController.class); | ||
25 | + | ||
26 | + @Autowired | ||
27 | + private ISaleCategoryService saleCategoryService; | ||
28 | + | ||
29 | + | ||
30 | + @RequestMapping(value = "/getSaleCategoryList", method = RequestMethod.POST) | ||
31 | + public ApiResponse<List<SaleCategoryTreeViewResponseBo>> getSaleCategoryList() { | ||
32 | + LOGGER.info("SaleCategoryController getSaleCategoryList param = {}"); | ||
33 | + return new ApiResponse<>(saleCategoryService.getSaleCategoryList()); | ||
34 | + } | ||
35 | +} |
1 | +package com.yoho.ufo.service.impl; | ||
2 | + | ||
3 | +import com.google.common.collect.Lists; | ||
4 | +import com.yoho.ufo.dal.SaleCategoryMapper; | ||
5 | +import com.yoho.ufo.model.commoditybasicrole.category.ProductSort; | ||
6 | +import com.yoho.ufo.model.salecategory.SaleCategory; | ||
7 | +import com.yoho.ufo.service.ISaleCategoryService; | ||
8 | +import com.yoho.ufo.util.CollectionUtil; | ||
9 | +import com.yoho.ufo.util.OrikaUtils; | ||
10 | +import com.yohobuy.ufo.model.request.productsort.ProductSortRequestBo; | ||
11 | +import com.yohobuy.ufo.model.response.productsort.ProductSortTreeViewResponseBo; | ||
12 | +import com.yohobuy.ufo.model.response.salecategory.SaleCategoryTreeViewResponseBo; | ||
13 | +import lombok.extern.slf4j.Slf4j; | ||
14 | +import org.apache.commons.collections.CollectionUtils; | ||
15 | +import org.apache.commons.lang3.StringUtils; | ||
16 | +import org.springframework.beans.factory.annotation.Autowired; | ||
17 | +import org.springframework.stereotype.Service; | ||
18 | + | ||
19 | +import java.util.ArrayList; | ||
20 | +import java.util.Iterator; | ||
21 | +import java.util.List; | ||
22 | + | ||
23 | +@Slf4j | ||
24 | +@Service | ||
25 | +public class SaleCategoryServiceImpl implements ISaleCategoryService { | ||
26 | + | ||
27 | + /** | ||
28 | + * 顶级id | ||
29 | + */ | ||
30 | + private static final Integer TOP_PARENT_ID = 0; | ||
31 | + | ||
32 | + /** | ||
33 | + * 一级层级 | ||
34 | + */ | ||
35 | + private static final Integer PRODUCT_SORT_LEVEL_1 = 1; | ||
36 | + | ||
37 | + | ||
38 | + /** | ||
39 | + * 二级层级 | ||
40 | + */ | ||
41 | + private static final Integer PRODUCT_SORT_LEVEL_2 = 2; | ||
42 | + | ||
43 | + | ||
44 | + /** | ||
45 | + * 二级层级 | ||
46 | + */ | ||
47 | + private static final Integer PRODUCT_SORT_LEVEL_3 = 3; | ||
48 | + | ||
49 | + | ||
50 | + | ||
51 | + @Autowired | ||
52 | + private SaleCategoryMapper saleCategoryMapper; | ||
53 | + | ||
54 | + public List<SaleCategoryTreeViewResponseBo> getSaleCategoryList() { | ||
55 | + log.info("enter getSaleCategoryList param = {}"); | ||
56 | + List<SaleCategory> productSorts = saleCategoryMapper.selectAll(); | ||
57 | + List<SaleCategoryTreeViewResponseBo> responseBos = new ArrayList<>(); | ||
58 | + processResult(productSorts, responseBos); | ||
59 | + return responseBos; | ||
60 | + } | ||
61 | + | ||
62 | + | ||
63 | + private void processResult(List<SaleCategory> categoryList, List<SaleCategoryTreeViewResponseBo> responseBos) { | ||
64 | + if(CollectionUtils.isEmpty(categoryList)){ | ||
65 | + return ; | ||
66 | + } | ||
67 | + Iterator<SaleCategory> iterator = categoryList.iterator(); | ||
68 | + // 挑选出一级分类 | ||
69 | + while (iterator.hasNext()) { | ||
70 | + SaleCategory saleCategory1 = iterator.next(); | ||
71 | + if (PRODUCT_SORT_LEVEL_1.equals(saleCategory1.getLevel()) && TOP_PARENT_ID.equals(saleCategory1.getParentId())) { | ||
72 | + responseBos.add(OrikaUtils.map(saleCategory1, SaleCategoryTreeViewResponseBo.class)); | ||
73 | + iterator.remove(); | ||
74 | + } | ||
75 | + } | ||
76 | + | ||
77 | + // 找出该一级分类下的二级分类 | ||
78 | + for (SaleCategoryTreeViewResponseBo treeViewResponseBo : responseBos) { | ||
79 | + iterator = categoryList.iterator(); | ||
80 | + while (iterator.hasNext()) { | ||
81 | + SaleCategory category2 = iterator.next(); | ||
82 | + | ||
83 | + if (treeViewResponseBo.getId().equals(category2.getParentId())) { | ||
84 | + List<SaleCategoryTreeViewResponseBo> children = treeViewResponseBo.getChildren(); | ||
85 | + if (children == null) { | ||
86 | + children = new ArrayList<>(); | ||
87 | + } | ||
88 | + SaleCategoryTreeViewResponseBo treeViewResponseBo1 = OrikaUtils.map(category2, SaleCategoryTreeViewResponseBo.class); | ||
89 | + //treeViewResponseBo1.setState(StringUtils.EMPTY); | ||
90 | + children.add(treeViewResponseBo1); | ||
91 | + treeViewResponseBo.setChildren(children); | ||
92 | + iterator.remove(); | ||
93 | + } | ||
94 | + } | ||
95 | + } | ||
96 | + | ||
97 | + // 找出三级分类 | ||
98 | + for (SaleCategoryTreeViewResponseBo treeViewResponseBoTmp : responseBos) { | ||
99 | + if (CollectionUtils.isEmpty(treeViewResponseBoTmp.getChildren())) { | ||
100 | + continue; | ||
101 | + } | ||
102 | + for(SaleCategoryTreeViewResponseBo snd: treeViewResponseBoTmp.getChildren()){ | ||
103 | + iterator = categoryList.iterator(); | ||
104 | + while (iterator.hasNext()) { | ||
105 | + SaleCategory category3 = iterator.next(); | ||
106 | + | ||
107 | + if (snd.getId().equals(category3.getParentId())) { | ||
108 | + List<SaleCategoryTreeViewResponseBo> children = snd.getChildren(); | ||
109 | + if (children == null) { | ||
110 | + children = new ArrayList<>(); | ||
111 | + } | ||
112 | + SaleCategoryTreeViewResponseBo treeViewResponseBo1 = OrikaUtils.map(category3, SaleCategoryTreeViewResponseBo.class); | ||
113 | + treeViewResponseBo1.setState(StringUtils.EMPTY); | ||
114 | + children.add(treeViewResponseBo1); | ||
115 | + snd.setChildren(children); | ||
116 | + iterator.remove(); | ||
117 | + } | ||
118 | + } | ||
119 | + } | ||
120 | + } | ||
121 | + | ||
122 | + // 处理一下一级分类下没有二级分类的state,把state值改为空字符串 | ||
123 | + for (SaleCategoryTreeViewResponseBo treeViewResponseBo : responseBos) { | ||
124 | + if (CollectionUtils.isEmpty(treeViewResponseBo.getChildren())) { | ||
125 | + treeViewResponseBo.setState(StringUtils.EMPTY); | ||
126 | + }else{ | ||
127 | + //处理二级 | ||
128 | + for(SaleCategoryTreeViewResponseBo snd: treeViewResponseBo.getChildren()){ | ||
129 | + if (CollectionUtils.isEmpty(snd.getChildren())) { | ||
130 | + snd.setState(StringUtils.EMPTY); | ||
131 | + } | ||
132 | + } | ||
133 | + } | ||
134 | + } | ||
135 | + } | ||
136 | + | ||
137 | +} |
1 | +<!DOCTYPE html> | ||
2 | +<html> | ||
3 | +<head> | ||
4 | + <meta charset="UTF-8"/> | ||
5 | + <title>Yoho!Buy运营平台</title> | ||
6 | + <script src="/ufoPlatform/js/include.js"></script> | ||
7 | + <script src="/ufoPlatform/js/ajaxfileupload.js"></script> | ||
8 | +</head> | ||
9 | +<body class="easyui-layout" fit="true"> | ||
10 | +<div region="north" style="height: 230px"> | ||
11 | + <script> | ||
12 | + document.write(addHead('商品管理/销售类目管理', '')); | ||
13 | + </script> | ||
14 | + <style> | ||
15 | + .div_search input { | ||
16 | + margin-top: 20px; | ||
17 | + } | ||
18 | + | ||
19 | + .div_search .textbox { | ||
20 | + margin-top: 20px; | ||
21 | + } | ||
22 | + | ||
23 | + .div_search .easyui-linkbutton { | ||
24 | + margin-top: 20px; | ||
25 | + } | ||
26 | + </style> | ||
27 | + <div style="margin-left: 30px;" class="div_search"> | ||
28 | + <a id="addSaleCategory" class="easyui-linkbutton btn-success">添加销售类目</a> | ||
29 | + </div> | ||
30 | +</div> | ||
31 | +<div region="center"> | ||
32 | + <div style="margin-left: 30px;margin-top: 20px;height: 660px"> | ||
33 | + <table id="saleCategoryTable"></table> | ||
34 | + </div> | ||
35 | +</div> | ||
36 | + | ||
37 | +<script type="text/javascript"> | ||
38 | + var productSortId; | ||
39 | + $(function () { | ||
40 | + | ||
41 | + $('#addSaleCategory').linkbutton({ | ||
42 | + iconCls: "icon-edit", | ||
43 | + onClick: function () { | ||
44 | + editRow(0); | ||
45 | + } | ||
46 | + }); | ||
47 | + | ||
48 | + $("#saleCategoryTable").treegrid({ | ||
49 | + fit: true, | ||
50 | + fitColumns: true, | ||
51 | + nowrap: false, | ||
52 | + url: contextPath + "/saleCategory/getSaleCategoryList", | ||
53 | + method: 'POST', | ||
54 | + /*queryParams: { | ||
55 | + 'sortName':'' | ||
56 | + },*/ | ||
57 | + loadFilter: function (data) { | ||
58 | + var temp = defaultLoadFilter(data); | ||
59 | + temp.rows = temp.list; | ||
60 | + return temp; | ||
61 | + }, | ||
62 | + columns: [[{ | ||
63 | + title: "", | ||
64 | + field: "treeField", | ||
65 | + width: 40, | ||
66 | + align: "center", | ||
67 | + formatter:function () { | ||
68 | + return ''; | ||
69 | + } | ||
70 | + }, { | ||
71 | + title: "类目ID", | ||
72 | + field: "id", | ||
73 | + width: 40, | ||
74 | + align: "center" | ||
75 | + }, { | ||
76 | + title: "名称", | ||
77 | + field: "categoryName", | ||
78 | + width: 80, | ||
79 | + align: "center" | ||
80 | + }, { | ||
81 | + title: "所属分类", | ||
82 | + field: "level", | ||
83 | + width: 80, | ||
84 | + align: "center", | ||
85 | + formatter: function (vaule) { | ||
86 | + if (vaule == 1) { | ||
87 | + return "1级分类"; | ||
88 | + } else if (vaule == 2) { | ||
89 | + return "2级分类"; | ||
90 | + } else{ | ||
91 | + return "3级分类"; | ||
92 | + } | ||
93 | + } | ||
94 | + }, { | ||
95 | + title: "排序", | ||
96 | + field: "orderBy", | ||
97 | + width: 80, | ||
98 | + align: "center" | ||
99 | + }, { | ||
100 | + title: "状态", | ||
101 | + field: "status", | ||
102 | + width: 80, | ||
103 | + align: "center", | ||
104 | + formatter: function (value) { | ||
105 | + if (value == 0) { | ||
106 | + return '开启'; | ||
107 | + } | ||
108 | + return '关闭'; | ||
109 | + } | ||
110 | + }, { | ||
111 | + title: "操作", | ||
112 | + field: "operations", | ||
113 | + width: 80, | ||
114 | + align: "center", | ||
115 | + formatter: function (value, rowData) { | ||
116 | + var str = "<a role='edit' dataId='" + rowData.id + "' style='margin-left:10px;background-color: #5bc0de'>编辑</a>"; | ||
117 | + if (0 == rowData.status) { | ||
118 | + str += "<a role='closeCategoryName' dataId='" + rowData.id + "' style='margin-left:10px;background-color: red' parentId = '" + rowData.parentId + "'>关闭</a>"; | ||
119 | + } else { | ||
120 | + str += "<a role='openCategoryName' dataId='" + rowData.id + "' style='margin-left:10px; background-color: orange' parentId = '" + rowData.parentId + "'>开启</a>"; | ||
121 | + } | ||
122 | + | ||
123 | + if(1== rowData.level||2==rowData.level){ | ||
124 | + str += "添加子类"; | ||
125 | + } | ||
126 | + return str; | ||
127 | + } | ||
128 | + }]], | ||
129 | + cache: false, | ||
130 | + //pagination: true, | ||
131 | + //pageSize: 100, | ||
132 | + //pageList: [100, 200, 300], | ||
133 | + idField: "id", | ||
134 | + treeField:'treeField', | ||
135 | + singleSelect: false, | ||
136 | + checkOnSelect: false, | ||
137 | + onLoadSuccess: function () { | ||
138 | + // 编辑 | ||
139 | + $(this).myDatagrid("getPanel").find("a[role='edit']").linkbutton({ | ||
140 | + iconCls: "icon-edit", | ||
141 | + onClick: function () { | ||
142 | + var id = $(this).attr("dataId"); | ||
143 | + editRow(id); | ||
144 | + } | ||
145 | + }); | ||
146 | + // 关闭 | ||
147 | + $(this).myDatagrid("getPanel").find("a[role='closeCategoryName']").linkbutton({ | ||
148 | + iconCls: "icon-more", | ||
149 | + onClick: function () { | ||
150 | + updateBrandStatus($(this).attr("dataId"), 1, $(this).attr("parentId")); | ||
151 | + } | ||
152 | + }); | ||
153 | + | ||
154 | + // 开启 | ||
155 | + $(this).myDatagrid("getPanel").find("a[role='openCategoryName']").linkbutton({ | ||
156 | + iconCls: "icon-more", | ||
157 | + onClick: function () { | ||
158 | + updateBrandStatus($(this).attr("dataId"), 0, $(this).attr("parentId")); | ||
159 | + } | ||
160 | + }); | ||
161 | + } | ||
162 | + }); | ||
163 | + | ||
164 | + }); | ||
165 | + | ||
166 | + function editRow(id) { | ||
167 | + | ||
168 | + } | ||
169 | + | ||
170 | + function updateBrandStatus(id, status, parentId) { | ||
171 | + | ||
172 | + } | ||
173 | +</script> | ||
174 | + | ||
175 | +</body> | ||
176 | +</html> |
-
Please register or login to post a comment