Authored by qinchao

add 销售类目管理

package com.yoho.ufo.dal;
import com.yoho.ufo.model.salecategory.SaleCategory;
import java.util.List;
/**
* 品类mapper
*
* @author kun.wang
* @date 2018/9/12
*/
public interface SaleCategoryMapper {
List<SaleCategory> selectAll();
}
... ...
package com.yoho.ufo.model.salecategory;
import lombok.Data;
import lombok.ToString;
/**
* 销售类目
*/
@Data
@ToString
public class SaleCategory {
/**
* id 主键
*/
private Integer id;
/**
* 名称
*/
private String categoryName;
/**
* 层级
*/
private Integer level;
/**
* 状态
* 0:开启
* 1:关闭
*/
private Integer status;
/**
* 父级id
*/
private Integer parentId;
/**
* 创建时间
*/
private Integer createTime;
/**
* 更新时间
*/
private Integer updateTime;
/**
* 排序值
*/
private Integer orderBy;
//
private String linkType;
private String linkDetail;
}
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yoho.ufo.dal.SaleCategoryMapper">
<resultMap id="BaseResultMap" type="com.yoho.ufo.model.salecategory.SaleCategory">
<id property="id" column="id"/>
<result property="categoryName" column="category_name"/>
<result property="status" column="status"/>
<result property="level" column="level"/>
<result property="parentId" column="parent_id"/>
<result property="orderBy" column="order_by"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<result property="linkType" column="link_type"/>
<result property="linkDetail" column="link_detail"/>
</resultMap>
<sql id="Base_Column_List">
id, category_name, status, level, parent_id, order_by,create_time,update_time,link_type,link_detail
</sql>
<select id="selectAll" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from sale_category where 1=1
order by level,order_by
</select>
</mapper>
\ No newline at end of file
... ...
package com.yoho.ufo.controller.saleCategory;
import com.yoho.ufo.service.ISaleCategoryService;
import com.yohobuy.ufo.model.common.ApiResponse;
import com.yohobuy.ufo.model.response.salecategory.SaleCategoryTreeViewResponseBo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 销售类目controller
*
* @author craig.qin
*/
@RequestMapping(value = "/saleCategory")
@RestController
public class SaleCategoryController {
private static final Logger LOGGER = LoggerFactory.getLogger(SaleCategoryController.class);
@Autowired
private ISaleCategoryService saleCategoryService;
@RequestMapping(value = "/getSaleCategoryList", method = RequestMethod.POST)
public ApiResponse<List<SaleCategoryTreeViewResponseBo>> getSaleCategoryList() {
LOGGER.info("SaleCategoryController getSaleCategoryList param = {}");
return new ApiResponse<>(saleCategoryService.getSaleCategoryList());
}
}
... ...
package com.yoho.ufo.service;
import com.yohobuy.ufo.model.response.salecategory.SaleCategoryTreeViewResponseBo;
import java.util.List;
public interface ISaleCategoryService {
List<SaleCategoryTreeViewResponseBo> getSaleCategoryList();
}
... ...
package com.yoho.ufo.service.impl;
import com.google.common.collect.Lists;
import com.yoho.ufo.dal.SaleCategoryMapper;
import com.yoho.ufo.model.commoditybasicrole.category.ProductSort;
import com.yoho.ufo.model.salecategory.SaleCategory;
import com.yoho.ufo.service.ISaleCategoryService;
import com.yoho.ufo.util.CollectionUtil;
import com.yoho.ufo.util.OrikaUtils;
import com.yohobuy.ufo.model.request.productsort.ProductSortRequestBo;
import com.yohobuy.ufo.model.response.productsort.ProductSortTreeViewResponseBo;
import com.yohobuy.ufo.model.response.salecategory.SaleCategoryTreeViewResponseBo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@Slf4j
@Service
public class SaleCategoryServiceImpl implements ISaleCategoryService {
/**
* 顶级id
*/
private static final Integer TOP_PARENT_ID = 0;
/**
* 一级层级
*/
private static final Integer PRODUCT_SORT_LEVEL_1 = 1;
/**
* 二级层级
*/
private static final Integer PRODUCT_SORT_LEVEL_2 = 2;
/**
* 二级层级
*/
private static final Integer PRODUCT_SORT_LEVEL_3 = 3;
@Autowired
private SaleCategoryMapper saleCategoryMapper;
public List<SaleCategoryTreeViewResponseBo> getSaleCategoryList() {
log.info("enter getSaleCategoryList param = {}");
List<SaleCategory> productSorts = saleCategoryMapper.selectAll();
List<SaleCategoryTreeViewResponseBo> responseBos = new ArrayList<>();
processResult(productSorts, responseBos);
return responseBos;
}
private void processResult(List<SaleCategory> categoryList, List<SaleCategoryTreeViewResponseBo> responseBos) {
if(CollectionUtils.isEmpty(categoryList)){
return ;
}
Iterator<SaleCategory> iterator = categoryList.iterator();
// 挑选出一级分类
while (iterator.hasNext()) {
SaleCategory saleCategory1 = iterator.next();
if (PRODUCT_SORT_LEVEL_1.equals(saleCategory1.getLevel()) && TOP_PARENT_ID.equals(saleCategory1.getParentId())) {
responseBos.add(OrikaUtils.map(saleCategory1, SaleCategoryTreeViewResponseBo.class));
iterator.remove();
}
}
// 找出该一级分类下的二级分类
for (SaleCategoryTreeViewResponseBo treeViewResponseBo : responseBos) {
iterator = categoryList.iterator();
while (iterator.hasNext()) {
SaleCategory category2 = iterator.next();
if (treeViewResponseBo.getId().equals(category2.getParentId())) {
List<SaleCategoryTreeViewResponseBo> children = treeViewResponseBo.getChildren();
if (children == null) {
children = new ArrayList<>();
}
SaleCategoryTreeViewResponseBo treeViewResponseBo1 = OrikaUtils.map(category2, SaleCategoryTreeViewResponseBo.class);
//treeViewResponseBo1.setState(StringUtils.EMPTY);
children.add(treeViewResponseBo1);
treeViewResponseBo.setChildren(children);
iterator.remove();
}
}
}
// 找出三级分类
for (SaleCategoryTreeViewResponseBo treeViewResponseBoTmp : responseBos) {
if (CollectionUtils.isEmpty(treeViewResponseBoTmp.getChildren())) {
continue;
}
for(SaleCategoryTreeViewResponseBo snd: treeViewResponseBoTmp.getChildren()){
iterator = categoryList.iterator();
while (iterator.hasNext()) {
SaleCategory category3 = iterator.next();
if (snd.getId().equals(category3.getParentId())) {
List<SaleCategoryTreeViewResponseBo> children = snd.getChildren();
if (children == null) {
children = new ArrayList<>();
}
SaleCategoryTreeViewResponseBo treeViewResponseBo1 = OrikaUtils.map(category3, SaleCategoryTreeViewResponseBo.class);
treeViewResponseBo1.setState(StringUtils.EMPTY);
children.add(treeViewResponseBo1);
snd.setChildren(children);
iterator.remove();
}
}
}
}
// 处理一下一级分类下没有二级分类的state,把state值改为空字符串
for (SaleCategoryTreeViewResponseBo treeViewResponseBo : responseBos) {
if (CollectionUtils.isEmpty(treeViewResponseBo.getChildren())) {
treeViewResponseBo.setState(StringUtils.EMPTY);
}else{
//处理二级
for(SaleCategoryTreeViewResponseBo snd: treeViewResponseBo.getChildren()){
if (CollectionUtils.isEmpty(snd.getChildren())) {
snd.setState(StringUtils.EMPTY);
}
}
}
}
}
}
... ...
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Yoho!Buy运营平台</title>
<script src="/ufoPlatform/js/include.js"></script>
<script src="/ufoPlatform/js/ajaxfileupload.js"></script>
</head>
<body class="easyui-layout" fit="true">
<div region="north" style="height: 230px">
<script>
document.write(addHead('商品管理/销售类目管理', ''));
</script>
<style>
.div_search input {
margin-top: 20px;
}
.div_search .textbox {
margin-top: 20px;
}
.div_search .easyui-linkbutton {
margin-top: 20px;
}
</style>
<div style="margin-left: 30px;" class="div_search">
<a id="addSaleCategory" class="easyui-linkbutton btn-success">添加销售类目</a>
</div>
</div>
<div region="center">
<div style="margin-left: 30px;margin-top: 20px;height: 660px">
<table id="saleCategoryTable"></table>
</div>
</div>
<script type="text/javascript">
var productSortId;
$(function () {
$('#addSaleCategory').linkbutton({
iconCls: "icon-edit",
onClick: function () {
editRow(0);
}
});
$("#saleCategoryTable").treegrid({
fit: true,
fitColumns: true,
nowrap: false,
url: contextPath + "/saleCategory/getSaleCategoryList",
method: 'POST',
/*queryParams: {
'sortName':''
},*/
loadFilter: function (data) {
var temp = defaultLoadFilter(data);
temp.rows = temp.list;
return temp;
},
columns: [[{
title: "",
field: "treeField",
width: 40,
align: "center",
formatter:function () {
return '';
}
}, {
title: "类目ID",
field: "id",
width: 40,
align: "center"
}, {
title: "名称",
field: "categoryName",
width: 80,
align: "center"
}, {
title: "所属分类",
field: "level",
width: 80,
align: "center",
formatter: function (vaule) {
if (vaule == 1) {
return "1级分类";
} else if (vaule == 2) {
return "2级分类";
} else{
return "3级分类";
}
}
}, {
title: "排序",
field: "orderBy",
width: 80,
align: "center"
}, {
title: "状态",
field: "status",
width: 80,
align: "center",
formatter: function (value) {
if (value == 0) {
return '开启';
}
return '关闭';
}
}, {
title: "操作",
field: "operations",
width: 80,
align: "center",
formatter: function (value, rowData) {
var str = "<a role='edit' dataId='" + rowData.id + "' style='margin-left:10px;background-color: #5bc0de'>编辑</a>";
if (0 == rowData.status) {
str += "<a role='closeCategoryName' dataId='" + rowData.id + "' style='margin-left:10px;background-color: red' parentId = '" + rowData.parentId + "'>关闭</a>";
} else {
str += "<a role='openCategoryName' dataId='" + rowData.id + "' style='margin-left:10px; background-color: orange' parentId = '" + rowData.parentId + "'>开启</a>";
}
if(1== rowData.level||2==rowData.level){
str += "添加子类";
}
return str;
}
}]],
cache: false,
//pagination: true,
//pageSize: 100,
//pageList: [100, 200, 300],
idField: "id",
treeField:'treeField',
singleSelect: false,
checkOnSelect: false,
onLoadSuccess: function () {
// 编辑
$(this).myDatagrid("getPanel").find("a[role='edit']").linkbutton({
iconCls: "icon-edit",
onClick: function () {
var id = $(this).attr("dataId");
editRow(id);
}
});
// 关闭
$(this).myDatagrid("getPanel").find("a[role='closeCategoryName']").linkbutton({
iconCls: "icon-more",
onClick: function () {
updateBrandStatus($(this).attr("dataId"), 1, $(this).attr("parentId"));
}
});
// 开启
$(this).myDatagrid("getPanel").find("a[role='openCategoryName']").linkbutton({
iconCls: "icon-more",
onClick: function () {
updateBrandStatus($(this).attr("dataId"), 0, $(this).attr("parentId"));
}
});
}
});
});
function editRow(id) {
}
function updateBrandStatus(id, status, parentId) {
}
</script>
</body>
</html>
\ No newline at end of file
... ...