Authored by qinchao

add 销售类目功能

... ... @@ -6,10 +6,8 @@ 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 {
... ... @@ -17,6 +15,8 @@ public interface SaleCategoryMapper {
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);
... ...
... ... @@ -27,6 +27,17 @@
, #{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>
... ...
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;
... ... @@ -59,4 +54,17 @@ public class SaleCategoryController {
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<>();
}
}
... ...
... ... @@ -7,6 +7,8 @@ import java.util.List;
public interface ISaleCategoryService {
void updateStatus(SaleCategoryResponseBo saleCategoryResponseBo);
void saveOrUpdateSaleCategory(SaleCategoryResponseBo saleCategoryResponseBo);
SaleCategoryResponseBo getSaleCategoryById(Integer id);
... ...
... ... @@ -3,7 +3,6 @@ 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;
... ... @@ -40,6 +39,35 @@ public class SaleCategoryServiceImpl implements ISaleCategoryService {
@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 ;
}
//关闭就直接关闭,开启需要检查上一级是否开启,如果上一级没开启就提示,需要先开启上一级
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);
... ... @@ -70,6 +98,9 @@ public class SaleCategoryServiceImpl implements ISaleCategoryService {
} 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());
... ... @@ -87,6 +118,7 @@ public class SaleCategoryServiceImpl implements ISaleCategoryService {
}
@Override
public SaleCategoryResponseBo getSaleCategoryById(Integer id){
log.info("enter getSaleCategoryById param = {}",id);
SaleCategory saleCategory = saleCategoryMapper.selectById(id);
... ... @@ -96,6 +128,7 @@ public class SaleCategoryServiceImpl implements ISaleCategoryService {
return null;
}
@Override
public List<SaleCategoryTreeViewResponseBo> getSaleCategoryList() {
log.info("enter getSaleCategoryList param = {}");
List<SaleCategory> productSorts = saleCategoryMapper.selectAll();
... ...
... ... @@ -267,6 +267,38 @@
}
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>
... ...