Showing
7 changed files
with
252 additions
and
14 deletions
1 | package com.yoho.ufo.dal; | 1 | package com.yoho.ufo.dal; |
2 | 2 | ||
3 | import com.yoho.ufo.model.salecategory.SaleCategory; | 3 | import com.yoho.ufo.model.salecategory.SaleCategory; |
4 | +import org.apache.ibatis.annotations.Param; | ||
4 | 5 | ||
5 | import java.util.List; | 6 | import java.util.List; |
6 | 7 | ||
@@ -12,6 +13,14 @@ import java.util.List; | @@ -12,6 +13,14 @@ import java.util.List; | ||
12 | */ | 13 | */ |
13 | public interface SaleCategoryMapper { | 14 | public interface SaleCategoryMapper { |
14 | 15 | ||
16 | + int insert(SaleCategory saleCategory); | ||
17 | + | ||
18 | + int updateSaleCategoryById(@Param("saleCategory") SaleCategory saleCategory); | ||
19 | + | ||
20 | + SaleCategory selectById(Integer id); | ||
21 | + | ||
22 | + List<SaleCategory> selectByNameAndParentId(@Param("categoryName") String categoryName, @Param("parentId") Integer parentId); | ||
23 | + | ||
15 | List<SaleCategory> selectAll(); | 24 | List<SaleCategory> selectAll(); |
16 | 25 | ||
17 | 26 |
@@ -20,6 +20,36 @@ | @@ -20,6 +20,36 @@ | ||
20 | id, category_name, status, level, parent_id, order_by,create_time,update_time,link_type,link_detail,image_url | 20 | id, category_name, status, level, parent_id, order_by,create_time,update_time,link_type,link_detail,image_url |
21 | </sql> | 21 | </sql> |
22 | 22 | ||
23 | + <insert id="insert" parameterType="com.yoho.ufo.model.salecategory.SaleCategory"> | ||
24 | + insert into sale_category(category_name, status, level, parent_id, order_by,create_time,update_time | ||
25 | + , link_type,link_detail,image_url) | ||
26 | + values (#{categoryName}, #{status}, #{level}, #{parentId}, #{orderBy}, #{createTime}, #{updateTime} | ||
27 | + , #{linkType}, #{linkDetail}, #{imageUrl}) | ||
28 | + </insert> | ||
29 | + | ||
30 | + <update id="updateSaleCategoryById"> | ||
31 | + update sale_category | ||
32 | + <set> | ||
33 | + <if test="saleCategory.categoryName != null"> | ||
34 | + category_name = #{saleCategory.categoryName}, | ||
35 | + </if> | ||
36 | + <if test="saleCategory.orderBy != null"> | ||
37 | + order_by = #{saleCategory.orderBy}, | ||
38 | + </if> | ||
39 | + update_time = #{saleCategory.updateTime} | ||
40 | + </set> | ||
41 | + where id = #{saleCategory.id} | ||
42 | + </update> | ||
43 | + | ||
44 | + <select id="selectById" resultMap="BaseResultMap"> | ||
45 | + select <include refid="Base_Column_List" /> | ||
46 | + from sale_category where id = #{id} | ||
47 | + </select> | ||
48 | + | ||
49 | + <select id="selectByNameAndParentId" resultMap="BaseResultMap"> | ||
50 | + select <include refid="Base_Column_List" /> | ||
51 | + from sale_category where parent_id = #{parentId} and category_name = #{categoryName} | ||
52 | + </select> | ||
23 | 53 | ||
24 | <select id="selectAll" resultMap="BaseResultMap"> | 54 | <select id="selectAll" resultMap="BaseResultMap"> |
25 | select <include refid="Base_Column_List" /> | 55 | select <include refid="Base_Column_List" /> |
1 | package com.yoho.ufo.controller.saleCategory; | 1 | package com.yoho.ufo.controller.saleCategory; |
2 | 2 | ||
3 | +import com.yoho.ufo.exception.CommonException; | ||
4 | +import com.yoho.ufo.exception.PlatformException; | ||
3 | import com.yoho.ufo.service.ISaleCategoryService; | 5 | import com.yoho.ufo.service.ISaleCategoryService; |
6 | +import com.yoho.ufo.util.OvalValidationUtils; | ||
4 | import com.yohobuy.ufo.model.common.ApiResponse; | 7 | import com.yohobuy.ufo.model.common.ApiResponse; |
8 | +import com.yohobuy.ufo.model.request.productsort.ProductSortRequestBo; | ||
9 | +import com.yohobuy.ufo.model.response.productsort.ProductSortResponseBo; | ||
10 | +import com.yohobuy.ufo.model.response.salecategory.SaleCategoryResponseBo; | ||
5 | import com.yohobuy.ufo.model.response.salecategory.SaleCategoryTreeViewResponseBo; | 11 | import com.yohobuy.ufo.model.response.salecategory.SaleCategoryTreeViewResponseBo; |
12 | +import org.apache.commons.lang3.StringUtils; | ||
6 | import org.slf4j.Logger; | 13 | import org.slf4j.Logger; |
7 | import org.slf4j.LoggerFactory; | 14 | import org.slf4j.LoggerFactory; |
8 | import org.springframework.beans.factory.annotation.Autowired; | 15 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -32,4 +39,24 @@ public class SaleCategoryController { | @@ -32,4 +39,24 @@ public class SaleCategoryController { | ||
32 | LOGGER.info("SaleCategoryController getSaleCategoryList param = {}"); | 39 | LOGGER.info("SaleCategoryController getSaleCategoryList param = {}"); |
33 | return new ApiResponse<>(saleCategoryService.getSaleCategoryList()); | 40 | return new ApiResponse<>(saleCategoryService.getSaleCategoryList()); |
34 | } | 41 | } |
42 | + | ||
43 | + | ||
44 | + @RequestMapping(value = "/getSaleCategoryById", method = RequestMethod.POST) | ||
45 | + public ApiResponse<SaleCategoryResponseBo> getSaleCategoryById(Integer id) { | ||
46 | + LOGGER.info("getSaleCategoryById param = {}", id); | ||
47 | + return new ApiResponse<>(saleCategoryService.getSaleCategoryById(id)); | ||
48 | + } | ||
49 | + | ||
50 | + @RequestMapping(value = "/saveOrUpdateSaleCategory", method = RequestMethod.POST) | ||
51 | + public ApiResponse<Object> saveOrUpdateSaleCategory(SaleCategoryResponseBo saleCategoryResponseBo) { | ||
52 | + LOGGER.info("saveOrUpdateSaleCategory param = {}", saleCategoryResponseBo); | ||
53 | + if(StringUtils.isBlank(saleCategoryResponseBo.getCategoryName())){ | ||
54 | + new ApiResponse<>(201,"参数错误:名称不能为空!", null); | ||
55 | + } | ||
56 | + if(saleCategoryResponseBo.getOrderBy()==null||saleCategoryResponseBo.getOrderBy()<0){ | ||
57 | + new ApiResponse<>(201,"参数错误:排序值必须为正整数!", null); | ||
58 | + } | ||
59 | + saleCategoryService.saveOrUpdateSaleCategory(saleCategoryResponseBo); | ||
60 | + return new ApiResponse<>(); | ||
61 | + } | ||
35 | } | 62 | } |
1 | package com.yoho.ufo.service; | 1 | package com.yoho.ufo.service; |
2 | 2 | ||
3 | +import com.yohobuy.ufo.model.response.salecategory.SaleCategoryResponseBo; | ||
3 | import com.yohobuy.ufo.model.response.salecategory.SaleCategoryTreeViewResponseBo; | 4 | import com.yohobuy.ufo.model.response.salecategory.SaleCategoryTreeViewResponseBo; |
4 | 5 | ||
5 | import java.util.List; | 6 | import java.util.List; |
6 | 7 | ||
7 | public interface ISaleCategoryService { | 8 | public interface ISaleCategoryService { |
8 | 9 | ||
10 | + void saveOrUpdateSaleCategory(SaleCategoryResponseBo saleCategoryResponseBo); | ||
11 | + | ||
12 | + SaleCategoryResponseBo getSaleCategoryById(Integer id); | ||
13 | + | ||
9 | List<SaleCategoryTreeViewResponseBo> getSaleCategoryList(); | 14 | List<SaleCategoryTreeViewResponseBo> getSaleCategoryList(); |
15 | + | ||
10 | } | 16 | } |
1 | package com.yoho.ufo.service.impl; | 1 | package com.yoho.ufo.service.impl; |
2 | 2 | ||
3 | +import com.yoho.core.common.utils.DateUtil; | ||
3 | import com.yoho.ufo.dal.SaleCategoryMapper; | 4 | import com.yoho.ufo.dal.SaleCategoryMapper; |
5 | +import com.yoho.ufo.exception.CommonException; | ||
6 | +import com.yoho.ufo.model.commoditybasicrole.category.ProductSort; | ||
4 | import com.yoho.ufo.model.salecategory.SaleCategory; | 7 | import com.yoho.ufo.model.salecategory.SaleCategory; |
5 | import com.yoho.ufo.service.ISaleCategoryService; | 8 | import com.yoho.ufo.service.ISaleCategoryService; |
6 | import com.yoho.ufo.util.OrikaUtils; | 9 | import com.yoho.ufo.util.OrikaUtils; |
10 | +import com.yohobuy.ufo.model.response.salecategory.SaleCategoryResponseBo; | ||
7 | import com.yohobuy.ufo.model.response.salecategory.SaleCategoryTreeViewResponseBo; | 11 | import com.yohobuy.ufo.model.response.salecategory.SaleCategoryTreeViewResponseBo; |
8 | import lombok.extern.slf4j.Slf4j; | 12 | import lombok.extern.slf4j.Slf4j; |
9 | import org.apache.commons.collections.CollectionUtils; | 13 | import org.apache.commons.collections.CollectionUtils; |
@@ -14,6 +18,7 @@ import org.springframework.stereotype.Service; | @@ -14,6 +18,7 @@ import org.springframework.stereotype.Service; | ||
14 | import java.util.ArrayList; | 18 | import java.util.ArrayList; |
15 | import java.util.Iterator; | 19 | import java.util.Iterator; |
16 | import java.util.List; | 20 | import java.util.List; |
21 | +import java.util.stream.Collectors; | ||
17 | 22 | ||
18 | @Slf4j | 23 | @Slf4j |
19 | @Service | 24 | @Service |
@@ -30,21 +35,66 @@ public class SaleCategoryServiceImpl implements ISaleCategoryService { | @@ -30,21 +35,66 @@ public class SaleCategoryServiceImpl implements ISaleCategoryService { | ||
30 | private static final Integer PRODUCT_SORT_LEVEL_1 = 1; | 35 | private static final Integer PRODUCT_SORT_LEVEL_1 = 1; |
31 | 36 | ||
32 | 37 | ||
33 | - /** | ||
34 | - * 二级层级 | ||
35 | - */ | ||
36 | - private static final Integer PRODUCT_SORT_LEVEL_2 = 2; | ||
37 | 38 | ||
38 | 39 | ||
39 | - /** | ||
40 | - * 二级层级 | ||
41 | - */ | ||
42 | - private static final Integer PRODUCT_SORT_LEVEL_3 = 3; | 40 | + @Autowired |
41 | + private SaleCategoryMapper saleCategoryMapper; | ||
43 | 42 | ||
43 | + public void saveOrUpdateSaleCategory(SaleCategoryResponseBo saleCategoryResponseBo){ | ||
44 | + log.info("saveOrUpdateSaleCategory param = {}", saleCategoryResponseBo); | ||
45 | + SaleCategory saleCategory = OrikaUtils.map(saleCategoryResponseBo, SaleCategory.class); | ||
46 | + if (saleCategory.getId() == null || saleCategory.getId() == 0) { | ||
47 | + // 新增 | ||
48 | + if (saleCategory.getParentId() == null || saleCategory.getParentId() == 0) { | ||
49 | + // 一级层级 | ||
50 | + saleCategory.setLevel(PRODUCT_SORT_LEVEL_1); | ||
51 | + saleCategory.setParentId(TOP_PARENT_ID); | ||
52 | + } else { | ||
53 | + //查看上一级的level | ||
54 | + SaleCategory saleCategoryParent = saleCategoryMapper.selectById(saleCategory.getParentId()); | ||
55 | + if(saleCategoryParent==null){ | ||
56 | + throw new CommonException(201, "父类销售类目找不到!"); | ||
57 | + } | ||
58 | + saleCategory.setLevel(saleCategoryParent.getLevel()+1); | ||
59 | + } | ||
60 | + saleCategory.setStatus(0); | ||
61 | + saleCategory.setCreateTime(DateUtil.currentTimeSeconds()); | ||
62 | + saleCategory.setUpdateTime(saleCategory.getCreateTime()); | ||
44 | 63 | ||
64 | + List<SaleCategory> sameNameList = saleCategoryMapper.selectByNameAndParentId(saleCategory.getCategoryName(),saleCategory.getParentId()); | ||
65 | + if(CollectionUtils.isNotEmpty(sameNameList)){ | ||
66 | + throw new CommonException(201, "销售类目名称已被占用!"); | ||
67 | + } | ||
45 | 68 | ||
46 | - @Autowired | ||
47 | - private SaleCategoryMapper saleCategoryMapper; | 69 | + saleCategoryMapper.insert(saleCategory); |
70 | + } else { | ||
71 | + // 更新 | ||
72 | + SaleCategory db_saleCategory = saleCategoryMapper.selectById(saleCategory.getId()); | ||
73 | + db_saleCategory.setCategoryName(saleCategoryResponseBo.getCategoryName()); | ||
74 | + db_saleCategory.setOrderBy(saleCategoryResponseBo.getOrderBy()); | ||
75 | + db_saleCategory.setUpdateTime(DateUtil.currentTimeSeconds()); | ||
76 | + | ||
77 | + List<SaleCategory> sameNameList = saleCategoryMapper.selectByNameAndParentId(saleCategory.getCategoryName(),saleCategory.getParentId()); | ||
78 | + if(CollectionUtils.isNotEmpty(sameNameList)){ | ||
79 | + //过滤掉自己 | ||
80 | + sameNameList = sameNameList.stream().filter(a -> !a.getId().equals(saleCategory.getId())) .collect(Collectors.toList()); | ||
81 | + if(CollectionUtils.isNotEmpty(sameNameList)){ | ||
82 | + throw new CommonException(201, "销售类目名称已被占用!"); | ||
83 | + } | ||
84 | + } | ||
85 | + saleCategoryMapper.updateSaleCategoryById(db_saleCategory); | ||
86 | + } | ||
87 | + } | ||
88 | + | ||
89 | + | ||
90 | + public SaleCategoryResponseBo getSaleCategoryById(Integer id){ | ||
91 | + log.info("enter getSaleCategoryById param = {}",id); | ||
92 | + SaleCategory saleCategory = saleCategoryMapper.selectById(id); | ||
93 | + if(saleCategory!=null){ | ||
94 | + return OrikaUtils.map(saleCategory, SaleCategoryResponseBo.class); | ||
95 | + } | ||
96 | + return null; | ||
97 | + } | ||
48 | 98 | ||
49 | public List<SaleCategoryTreeViewResponseBo> getSaleCategoryList() { | 99 | public List<SaleCategoryTreeViewResponseBo> getSaleCategoryList() { |
50 | log.info("enter getSaleCategoryList param = {}"); | 100 | log.info("enter getSaleCategoryList param = {}"); |
1 | +<!DOCTYPE html> | ||
2 | +<div id="tt" class="easyui-layout" fit="true" style="overflow-y: scroll"> | ||
3 | + <form name="categoryEditForm" id="categoryEditForm" method="post" enctype="multipart/form-data"> | ||
4 | + <input type="hidden" name="id" /> | ||
5 | + <input type="hidden" name="parentId" /> | ||
6 | + <div style="margin-top: 20px;margin-left: 30px"> | ||
7 | + <table border="0" style="width:95%;margin-top:5px;line-height:30px;" id="tab"> | ||
8 | + <tr style="height: 60px"> | ||
9 | + <td width="20%"><span style="color:red">*</span><label>名称</label></td> | ||
10 | + <td> | ||
11 | + <div style="width:200px;"> | ||
12 | + <input class="easyui-textbox" id="categoryName" name="categoryName" data-options="validType:'length[1,30]'" /> | ||
13 | + </div> | ||
14 | + </td> | ||
15 | + </tr> | ||
16 | + <tr style="height: 60px"> | ||
17 | + <td width="20%"><span style="color:red">*</span><label>排序值</label></td> | ||
18 | + <td> | ||
19 | + <input class="easyui-numberbox" id="orderBy" name="orderBy" data-options="validType:'length[1,10]'" /> | ||
20 | + </td> | ||
21 | + </tr> | ||
22 | + </table> | ||
23 | + </div> | ||
24 | + </form> | ||
25 | +</div> | ||
26 | +<script> | ||
27 | + $(function () { | ||
28 | + $("#categoryEditForm #categoryName").textbox({ | ||
29 | + required: true, | ||
30 | + missingMessage: "销售类目名称不能为空", | ||
31 | + prompt: "请输入", | ||
32 | + width: "200px" | ||
33 | + }); | ||
34 | + | ||
35 | + $("#categoryEditForm #orderBy").numberbox({ | ||
36 | + required: true, | ||
37 | + precision:0, | ||
38 | + min:1, | ||
39 | + missingMessage: "排序值不能为空", | ||
40 | + prompt: "请输入", | ||
41 | + width:"200px" | ||
42 | + }); | ||
43 | + | ||
44 | + if (saleCategoryId > 0) { | ||
45 | + $.post(contextPath + "/saleCategory/getSaleCategoryById", { | ||
46 | + id: saleCategoryId | ||
47 | + }, function (data) { | ||
48 | + $("#categoryEditForm").form("load", data.data); | ||
49 | + | ||
50 | + }); | ||
51 | + } | ||
52 | + }); | ||
53 | + | ||
54 | +</script> |
@@ -25,7 +25,7 @@ | @@ -25,7 +25,7 @@ | ||
25 | } | 25 | } |
26 | </style> | 26 | </style> |
27 | <div style="margin-left: 30px;" class="div_search"> | 27 | <div style="margin-left: 30px;" class="div_search"> |
28 | - <a id="addSaleCategory" class="easyui-linkbutton btn-success">添加销售类目</a> | 28 | + <a id="addSaleCategory" class="easyui-linkbutton btn-success">添加一级销售类目</a> |
29 | </div> | 29 | </div> |
30 | </div> | 30 | </div> |
31 | <div region="center"> | 31 | <div region="center"> |
@@ -35,9 +35,8 @@ | @@ -35,9 +35,8 @@ | ||
35 | </div> | 35 | </div> |
36 | 36 | ||
37 | <script type="text/javascript"> | 37 | <script type="text/javascript"> |
38 | - var productSortId; | 38 | + var saleCategoryId; |
39 | $(function () { | 39 | $(function () { |
40 | - | ||
41 | $('#addSaleCategory').linkbutton({ | 40 | $('#addSaleCategory').linkbutton({ |
42 | iconCls: "icon-edit", | 41 | iconCls: "icon-edit", |
43 | onClick: function () { | 42 | onClick: function () { |
@@ -164,7 +163,70 @@ | @@ -164,7 +163,70 @@ | ||
164 | }); | 163 | }); |
165 | 164 | ||
166 | function editRow(id) { | 165 | function editRow(id) { |
167 | - | 166 | + saleCategoryId = id; |
167 | + var div = $("<div>").appendTo($(document.body)); | ||
168 | + var title = "编辑品类"; | ||
169 | + var message = "确认修改销售类目信息吗?"; | ||
170 | + if (id == 0) { | ||
171 | + title = "添加品类"; | ||
172 | + message = "确认添加销售类目信息吗?"; | ||
173 | + } | ||
174 | + $(div).myDialog({ | ||
175 | + width: "850px", | ||
176 | + height: "450px", | ||
177 | + title: title, | ||
178 | + href: contextPath + "/html/saleCategory/addOrEdit.html", | ||
179 | + queryParams: { | ||
180 | + id: id | ||
181 | + }, | ||
182 | + modal: true, | ||
183 | + collapsible: true, | ||
184 | + cache: false, | ||
185 | + buttons: [{ | ||
186 | + id: "saveBtn", | ||
187 | + text: "保存", | ||
188 | + handler: function () { | ||
189 | + $.messager.confirm("确认", message, function (flag) { | ||
190 | + if(flag) { | ||
191 | + $("#categoryEditForm").form("submit", { | ||
192 | + url: contextPath + "/saleCategory/saveOrUpdateSaleCategory", | ||
193 | + onSubmit: function () { | ||
194 | + if (!$("#categoryEditForm").form("validate")) { | ||
195 | + return false; | ||
196 | + } | ||
197 | + $.messager.progress({ | ||
198 | + title: "正在执行", | ||
199 | + msg: "正在执行,请稍后..." | ||
200 | + }); | ||
201 | + return true; | ||
202 | + }, | ||
203 | + success: function (data) { | ||
204 | + $.messager.progress("close"); | ||
205 | + data = JSON.parse(data); | ||
206 | + if (data.code == 200) { | ||
207 | + $(div).dialog("close"); | ||
208 | + $("#saleCategoryTable").treegrid("reload"); | ||
209 | + $.messager.show({ | ||
210 | + title: "提示", | ||
211 | + msg: title + "成功!", | ||
212 | + height: 120 | ||
213 | + }); | ||
214 | + } else { | ||
215 | + $.messager.alert("失败", data.message, "error"); | ||
216 | + } | ||
217 | + } | ||
218 | + }); | ||
219 | + } | ||
220 | + }); | ||
221 | + } | ||
222 | + }, { | ||
223 | + text: "关闭", | ||
224 | + iconCls: "icon-cancel", | ||
225 | + handler: function () { | ||
226 | + $(div).dialog("close"); | ||
227 | + } | ||
228 | + }] | ||
229 | + }); | ||
168 | } | 230 | } |
169 | 231 | ||
170 | function updateBrandStatus(id, status, parentId) { | 232 | function updateBrandStatus(id, status, parentId) { |
-
Please register or login to post a comment