Authored by qinchao

Merge branch 'dev_qc_6.8.4_menu' into test6.8.4

package com.yoho.ufo.dal;
import com.yoho.ufo.model.salecategory.SaleCategory;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 品类mapper
*
* @author kun.wang
* @date 2018/9/12
* @date 2018/12/17
*/
public interface SaleCategoryMapper {
int insert(SaleCategory saleCategory);
int updateSaleCategoryById(@Param("saleCategory") SaleCategory saleCategory);
int updateStatusById(@Param("id") Integer id,@Param("status") Integer status,@Param("updateTime") Integer updateTime);
SaleCategory selectById(Integer id);
List<SaleCategory> selectByNameAndParentId(@Param("categoryName") String categoryName, @Param("parentId") Integer parentId);
List<SaleCategory> selectAll();
... ...
... ... @@ -20,6 +20,47 @@
id, category_name, status, level, parent_id, order_by,create_time,update_time,link_type,link_detail,image_url
</sql>
<insert id="insert" parameterType="com.yoho.ufo.model.salecategory.SaleCategory">
insert into sale_category(category_name, status, level, parent_id, order_by,create_time,update_time
, link_type,link_detail,image_url)
values (#{categoryName}, #{status}, #{level}, #{parentId}, #{orderBy}, #{createTime}, #{updateTime}
, #{linkType}, #{linkDetail}, #{imageUrl})
</insert>
<update id="updateStatusById">
update sale_category
<set>
status = #{status},
update_time = #{updateTime}
</set>
where id = #{id}
</update>
<update id="updateSaleCategoryById">
update sale_category
<set>
<if test="saleCategory.categoryName != null">
category_name = #{saleCategory.categoryName},
</if>
<if test="saleCategory.orderBy != null">
order_by = #{saleCategory.orderBy},
</if>
update_time = #{saleCategory.updateTime}
</set>
where id = #{saleCategory.id}
</update>
<select id="selectById" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from sale_category where id = #{id}
</select>
<select id="selectByNameAndParentId" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from sale_category where parent_id = #{parentId} and category_name = #{categoryName}
</select>
<select id="selectAll" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
... ...
... ... @@ -2,7 +2,9 @@ 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.SaleCategoryResponseBo;
import com.yohobuy.ufo.model.response.salecategory.SaleCategoryTreeViewResponseBo;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -32,4 +34,37 @@ public class SaleCategoryController {
LOGGER.info("SaleCategoryController getSaleCategoryList param = {}");
return new ApiResponse<>(saleCategoryService.getSaleCategoryList());
}
@RequestMapping(value = "/getSaleCategoryById", method = RequestMethod.POST)
public ApiResponse<SaleCategoryResponseBo> getSaleCategoryById(Integer id) {
LOGGER.info("getSaleCategoryById param = {}", id);
return new ApiResponse<>(saleCategoryService.getSaleCategoryById(id));
}
@RequestMapping(value = "/saveOrUpdateSaleCategory", method = RequestMethod.POST)
public ApiResponse<Object> saveOrUpdateSaleCategory(SaleCategoryResponseBo saleCategoryResponseBo) {
LOGGER.info("saveOrUpdateSaleCategory param = {}", saleCategoryResponseBo);
if(StringUtils.isBlank(saleCategoryResponseBo.getCategoryName())){
new ApiResponse<>(201,"参数错误:名称不能为空!", null);
}
if(saleCategoryResponseBo.getOrderBy()==null||saleCategoryResponseBo.getOrderBy()<0){
new ApiResponse<>(201,"参数错误:排序值必须为正整数!", null);
}
saleCategoryService.saveOrUpdateSaleCategory(saleCategoryResponseBo);
return new ApiResponse<>();
}
@RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
public ApiResponse<Object> updateStatus(SaleCategoryResponseBo saleCategoryResponseBo) {
LOGGER.info("updateStatus param = {}", saleCategoryResponseBo);
if(saleCategoryResponseBo.getId()==null){
new ApiResponse<>(201,"参数错误:id不能为空!", null);
}
if(saleCategoryResponseBo.getStatus()==null){
new ApiResponse<>(201,"参数错误:状态值不能为空!", null);
}
saleCategoryService.updateStatus(saleCategoryResponseBo);
return new ApiResponse<>();
}
}
... ...
package com.yoho.ufo.service;
import com.yohobuy.ufo.model.response.salecategory.SaleCategoryResponseBo;
import com.yohobuy.ufo.model.response.salecategory.SaleCategoryTreeViewResponseBo;
import java.util.List;
public interface ISaleCategoryService {
void updateStatus(SaleCategoryResponseBo saleCategoryResponseBo);
void saveOrUpdateSaleCategory(SaleCategoryResponseBo saleCategoryResponseBo);
SaleCategoryResponseBo getSaleCategoryById(Integer id);
List<SaleCategoryTreeViewResponseBo> getSaleCategoryList();
}
... ...
package com.yoho.ufo.service.impl;
import com.yoho.core.common.utils.DateUtil;
import com.yoho.ufo.dal.SaleCategoryMapper;
import com.yoho.ufo.exception.CommonException;
import com.yoho.ufo.model.salecategory.SaleCategory;
import com.yoho.ufo.service.ISaleCategoryService;
import com.yoho.ufo.util.OrikaUtils;
import com.yohobuy.ufo.model.response.salecategory.SaleCategoryResponseBo;
import com.yohobuy.ufo.model.response.salecategory.SaleCategoryTreeViewResponseBo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
... ... @@ -14,6 +17,7 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@Service
... ... @@ -30,22 +34,101 @@ public class SaleCategoryServiceImpl implements ISaleCategoryService {
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;
@Override
public void updateStatus(SaleCategoryResponseBo saleCategoryResponseBo){
log.info("updateStatus param = {}", saleCategoryResponseBo);
SaleCategory db_saleCategory = saleCategoryMapper.selectById(saleCategoryResponseBo.getId());
if(db_saleCategory==null){
throw new CommonException(201, "找不到销售类目!");
}
Integer newStatus = saleCategoryResponseBo.getStatus();
if(db_saleCategory.getStatus().equals(newStatus)){
return ;
}
@Autowired
private SaleCategoryMapper saleCategoryMapper;
//关闭就直接关闭,开启需要检查上一级是否开启,如果上一级没开启就提示,需要先开启上一级
if(newStatus==0){
//检查上一级
if(db_saleCategory.getLevel()>PRODUCT_SORT_LEVEL_1){
SaleCategory parent_saleCategory = saleCategoryMapper.selectById(saleCategoryResponseBo.getParentId());
if(parent_saleCategory!=null&&!parent_saleCategory.getStatus().equals(0)){
throw new CommonException(201, "请先开启上级类目!");
}
}
}else{
newStatus = 1;
}
saleCategoryMapper.updateStatusById(saleCategoryResponseBo.getId(),newStatus,DateUtil.currentTimeSeconds());
}
@Override
public void saveOrUpdateSaleCategory(SaleCategoryResponseBo saleCategoryResponseBo){
log.info("saveOrUpdateSaleCategory param = {}", saleCategoryResponseBo);
SaleCategory saleCategory = OrikaUtils.map(saleCategoryResponseBo, SaleCategory.class);
if (saleCategory.getId() == null || saleCategory.getId() == 0) {
// 新增
if (saleCategory.getParentId() == null || saleCategory.getParentId() == 0) {
// 一级层级
saleCategory.setLevel(PRODUCT_SORT_LEVEL_1);
saleCategory.setParentId(TOP_PARENT_ID);
} else {
//查看上一级的level
SaleCategory saleCategoryParent = saleCategoryMapper.selectById(saleCategory.getParentId());
if(saleCategoryParent==null){
throw new CommonException(201, "父类销售类目找不到!");
}
saleCategory.setLevel(saleCategoryParent.getLevel()+1);
}
saleCategory.setStatus(0);
saleCategory.setCreateTime(DateUtil.currentTimeSeconds());
saleCategory.setUpdateTime(saleCategory.getCreateTime());
List<SaleCategory> sameNameList = saleCategoryMapper.selectByNameAndParentId(saleCategory.getCategoryName(),saleCategory.getParentId());
if(CollectionUtils.isNotEmpty(sameNameList)){
throw new CommonException(201, "销售类目名称已被占用!");
}
saleCategoryMapper.insert(saleCategory);
} else {
// 更新
SaleCategory db_saleCategory = saleCategoryMapper.selectById(saleCategory.getId());
if(db_saleCategory==null){
throw new CommonException(201, "找不到销售类目!");
}
db_saleCategory.setCategoryName(saleCategoryResponseBo.getCategoryName());
db_saleCategory.setOrderBy(saleCategoryResponseBo.getOrderBy());
db_saleCategory.setUpdateTime(DateUtil.currentTimeSeconds());
List<SaleCategory> sameNameList = saleCategoryMapper.selectByNameAndParentId(saleCategory.getCategoryName(),saleCategory.getParentId());
if(CollectionUtils.isNotEmpty(sameNameList)){
//过滤掉自己
sameNameList = sameNameList.stream().filter(a -> !a.getId().equals(saleCategory.getId())) .collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(sameNameList)){
throw new CommonException(201, "销售类目名称已被占用!");
}
}
saleCategoryMapper.updateSaleCategoryById(db_saleCategory);
}
}
@Override
public SaleCategoryResponseBo getSaleCategoryById(Integer id){
log.info("enter getSaleCategoryById param = {}",id);
SaleCategory saleCategory = saleCategoryMapper.selectById(id);
if(saleCategory!=null){
return OrikaUtils.map(saleCategory, SaleCategoryResponseBo.class);
}
return null;
}
@Override
public List<SaleCategoryTreeViewResponseBo> getSaleCategoryList() {
log.info("enter getSaleCategoryList param = {}");
List<SaleCategory> productSorts = saleCategoryMapper.selectAll();
... ...
<!DOCTYPE html>
<div id="tt" class="easyui-layout" fit="true" style="overflow-y: scroll">
<form name="categoryEditForm" id="categoryEditForm" method="post" enctype="multipart/form-data">
<input type="hidden" name="id" />
<input type="hidden" name="parentId" id="parentId"/>
<div style="margin-top: 20px;margin-left: 30px">
<table border="0" style="width:95%;margin-top:5px;line-height:30px;" id="tab">
<tr style="height: 60px">
<td width="20%"><span style="color:red">*</span><label>名称</label></td>
<td>
<div style="width:200px;">
<input class="easyui-textbox" id="categoryName" name="categoryName" data-options="validType:'length[1,30]'" />
</div>
</td>
</tr>
<tr style="height: 60px">
<td width="20%"><span style="color:red">*</span><label>排序值</label></td>
<td>
<input class="easyui-numberbox" id="orderBy" name="orderBy" data-options="validType:'length[1,10]'" />
</td>
</tr>
</table>
</div>
</form>
</div>
<script>
$(function () {
$("#categoryEditForm #categoryName").textbox({
required: true,
missingMessage: "销售类目名称不能为空",
prompt: "请输入",
width: "200px"
});
$("#categoryEditForm #orderBy").numberbox({
required: true,
precision:0,
min:1,
missingMessage: "排序值不能为空",
prompt: "请输入",
width:"200px"
});
$("#categoryEditForm #parentId").val(saleCategoryParentId);
if (saleCategoryId > 0) {
$.post(contextPath + "/saleCategory/getSaleCategoryById", {
id: saleCategoryId
}, function (data) {
$("#categoryEditForm").form("load", data.data);
});
}
});
</script>
\ No newline at end of file
... ...
... ... @@ -25,7 +25,7 @@
}
</style>
<div style="margin-left: 30px;" class="div_search">
<a id="addSaleCategory" class="easyui-linkbutton btn-success">添加销售类目</a>
<a id="addSaleCategory" class="easyui-linkbutton btn-success">添加一级销售类目</a>
</div>
</div>
<div region="center">
... ... @@ -35,13 +35,13 @@
</div>
<script type="text/javascript">
var productSortId;
var saleCategoryId;
var saleCategoryParentId;
$(function () {
$('#addSaleCategory').linkbutton({
iconCls: "icon-edit",
onClick: function () {
editRow(0);
editRow(0,0);
}
});
... ... @@ -94,12 +94,12 @@
}, {
title: "排序",
field: "orderBy",
width: 80,
width: 30,
align: "center"
}, {
title: "状态",
field: "status",
width: 80,
width: 30,
align: "center",
formatter: function (value) {
if (value == 0) {
... ... @@ -110,19 +110,33 @@
}, {
title: "操作",
field: "operations",
width: 80,
width: 200,
align: "center",
formatter: function (value, rowData) {
var str = "<a role='edit' dataId='" + rowData.id + "' style='margin-left:10px;background-color: #5bc0de'>编辑</a>";
var str = "";
if(1== rowData.level||2==rowData.level) {
str += "<a role='edit' dataId='" + rowData.id + "' dataParentId='"+rowData.parentId+"' style='margin-left:10px;background-color: #5bc0de'>编辑</a>"
}else{
str += "<a role='addOrEditThirdLevel' dataId='" + rowData.id + "' dataParentId='"+rowData.parentId+"' style='margin-left:10px;background-color: #5bc0de'>编辑</a>"
}
if(1== rowData.level||2==rowData.level) {
str = "<a role='edit' dataId='" + rowData.id + "' dataParentId='"+rowData.parentId+"' style='margin-left:10px;background-color: #5bc0de'>编辑</a>";
if(1==rowData.level){
str += "<a role='addSecondLevel' dataId='" + rowData.id + "' style='margin-left:10px;background-color: #5bc0de;color:white;'>添加子类</a>";
}else {
str += "<a role='addOrEditThirdLevel' dataId='" + rowData.id + "' style='margin-left:10px;background-color: #5bc0de;color:white;'>添加子类</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;
}
}]],
... ... @@ -140,9 +154,29 @@
iconCls: "icon-edit",
onClick: function () {
var id = $(this).attr("dataId");
editRow(id);
var pid = $(this).attr("dataParentId");
editRow(id,pid);
}
});
$(this).myDatagrid("getPanel").find("a[role='addOrEditThirdLevel']").linkbutton({
iconCls: "icon-edit",
onClick: function () {
//添加子类,当前类的id作为pid
var id = $(this).attr("dataId");
alert("开发中"+id);
}
});
$(this).myDatagrid("getPanel").find("a[role='addSecondLevel']").linkbutton({
iconCls: "icon-edit",
onClick: function () {
//添加子类,当前类的id作为pid
var id = $(this).attr("dataId");
editRow(0,id);
}
});
// 关闭
$(this).myDatagrid("getPanel").find("a[role='closeCategoryName']").linkbutton({
iconCls: "icon-more",
... ... @@ -163,11 +197,108 @@
});
function editRow(id) {
function editRow(id,pid) {
saleCategoryId = id;
saleCategoryParentId = pid;
var div = $("<div>").appendTo($(document.body));
var title = "编辑品类";
var message = "确认修改销售类目信息吗?";
if (id == 0) {
title = "添加品类";
message = "确认添加销售类目信息吗?";
}
$(div).myDialog({
width: "850px",
height: "450px",
title: title,
href: contextPath + "/html/saleCategory/addOrEdit.html",
queryParams: {
saleCategoryParentId:saleCategoryParentId,
id: id
},
modal: true,
collapsible: true,
cache: false,
buttons: [{
id: "saveBtn",
text: "保存",
handler: function () {
$.messager.confirm("确认", message, function (flag) {
if(flag) {
$("#categoryEditForm").form("submit", {
url: contextPath + "/saleCategory/saveOrUpdateSaleCategory",
onSubmit: function () {
if (!$("#categoryEditForm").form("validate")) {
return false;
}
$.messager.progress({
title: "正在执行",
msg: "正在执行,请稍后..."
});
return true;
},
success: function (data) {
$.messager.progress("close");
data = JSON.parse(data);
if (data.code == 200) {
$(div).dialog("close");
$("#saleCategoryTable").treegrid("reload");
$.messager.show({
title: "提示",
msg: title + "成功!",
height: 120
});
} else {
$.messager.alert("失败", data.message, "error");
}
}
});
}
});
}
}, {
text: "关闭",
iconCls: "icon-cancel",
handler: function () {
$(div).dialog("close");
}
}]
});
}
function updateBrandStatus(id, status, parentId) {
var message = "";
var msg = "";
if (status == 0) {
message = "确认要开启销售类目吗?";
msg = "开启销售类目成功!";
} else {
message = "确认要关闭销售类目吗?";
msg = "关闭销售类目成功!";
}
window.top.$.messager.confirm("确认", message, function (flag) {
if (flag) {
window.top.$.messager.progress({
title: "正在执行",
msg: "正在执行,请稍后...",
interval: 500,
text: ""
});
$.post(contextPath + "/saleCategory/updateStatus",{"id":id, "status":status, "parentId": parentId}, function (data) {
window.top.$.messager.progress("close");
if (data.code == 200) {
$("#saleCategoryTable").treegrid("reload");
window.top.$.messager.show({
title: "提示",
msg: msg,
height: 120
});
} else {
window.top.$.messager.alert("失败", data.message, "error");
}
}, "json");
}
});
}
</script>
... ...