Authored by qinchao

add 销售类目功能

package com.yoho.ufo.dal;
import com.yoho.ufo.model.salecategory.SaleCategory;
import org.apache.ibatis.annotations.Param;
import java.util.List;
... ... @@ -12,6 +13,14 @@ import java.util.List;
*/
public interface SaleCategoryMapper {
int insert(SaleCategory saleCategory);
int updateSaleCategoryById(@Param("saleCategory") SaleCategory saleCategory);
SaleCategory selectById(Integer id);
List<SaleCategory> selectByNameAndParentId(@Param("categoryName") String categoryName, @Param("parentId") Integer parentId);
List<SaleCategory> selectAll();
... ...
... ... @@ -20,6 +20,36 @@
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="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" />
... ...
package com.yoho.ufo.controller.saleCategory;
import com.yoho.ufo.exception.CommonException;
import com.yoho.ufo.exception.PlatformException;
import com.yoho.ufo.service.ISaleCategoryService;
import com.yoho.ufo.util.OvalValidationUtils;
import com.yohobuy.ufo.model.common.ApiResponse;
import com.yohobuy.ufo.model.request.productsort.ProductSortRequestBo;
import com.yohobuy.ufo.model.response.productsort.ProductSortResponseBo;
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 +39,24 @@ 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<>();
}
}
... ...
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 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.commoditybasicrole.category.ProductSort;
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 +18,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,21 +35,66 @@ 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;
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, "销售类目名称已被占用!");
}
@Autowired
private SaleCategoryMapper saleCategoryMapper;
saleCategoryMapper.insert(saleCategory);
} else {
// 更新
SaleCategory db_saleCategory = saleCategoryMapper.selectById(saleCategory.getId());
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);
}
}
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;
}
public List<SaleCategoryTreeViewResponseBo> getSaleCategoryList() {
log.info("enter getSaleCategoryList param = {}");
... ...
<!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" />
<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"
});
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,9 +35,8 @@
</div>
<script type="text/javascript">
var productSortId;
var saleCategoryId;
$(function () {
$('#addSaleCategory').linkbutton({
iconCls: "icon-edit",
onClick: function () {
... ... @@ -164,7 +163,70 @@
});
function editRow(id) {
saleCategoryId = id;
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: {
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) {
... ...