商品分类提交~

This commit is contained in:
YunaiV
2019-03-04 19:35:07 +08:00
parent 13e9b5526b
commit 5192472ed5
14 changed files with 416 additions and 20 deletions

View File

@@ -0,0 +1,26 @@
package cn.iocoder.mall.product.config;
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.mall.product.api.constant.ProductErrorCodeEnum;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
@Configuration
public class ServiceExceptionConfiguration {
@EventListener(ApplicationReadyEvent.class) // 可参考 https://www.cnblogs.com/ssslinppp/p/7607509.html
public void initMessages() {
// 从 service_exception_message.properties 加载错误码的方案
// Properties properties;
// try {
// properties = PropertiesLoaderUtils.loadAllProperties("classpath:service_exception_message.properties");
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
for (ProductErrorCodeEnum item : ProductErrorCodeEnum.values()) {
ServiceExceptionUtil.put(item.getCode(), item.getMessage());
}
}
}

View File

@@ -7,6 +7,7 @@ import cn.iocoder.common.framework.dataobject.BaseDO;
*/
public class ProductCategoryDO extends BaseDO {
@Deprecated
public static final Integer STATUS_ENABLE = 1;
/**

View File

@@ -1,5 +1,6 @@
package cn.iocoder.mall.product.service;
import cn.iocoder.common.framework.constant.SysErrorCodeEnum;
import cn.iocoder.common.framework.dataobject.BaseDO;
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
import cn.iocoder.common.framework.vo.CommonResult;
@@ -32,15 +33,15 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
}
@Override
public List<ProductCategoryBO> getAll() {
public CommonResult<List<ProductCategoryBO>> getAll() {
List<ProductCategoryDO> categoryList = productCategoryMapper.selectList();
return ProductCategoryConvert.INSTANCE.convertToBO(categoryList);
return CommonResult.success(ProductCategoryConvert.INSTANCE.convertToBO(categoryList));
}
@Override
public CommonResult<ProductCategoryBO> addProductCategory(Integer adminId, ProductCategoryAddDTO productCategoryAddDTO) {
// 校验父分类是否存在
if (ProductCategoryConstants.PID_ROOT.equals(productCategoryAddDTO.getPid())
if (!ProductCategoryConstants.PID_ROOT.equals(productCategoryAddDTO.getPid())
&& productCategoryMapper.selectById(productCategoryAddDTO.getPid()) == null) {
return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_CATEGORY_PARENT_NOT_EXISTS.getCode());
}
@@ -65,7 +66,7 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_CATEGORY_PARENT_NOT_SELF.getCode());
}
// 校验父分类是否存在
if (ProductCategoryConstants.PID_ROOT.equals(productCategoryUpdateDTO.getPid())
if (!ProductCategoryConstants.PID_ROOT.equals(productCategoryUpdateDTO.getPid())
&& productCategoryMapper.selectById(productCategoryUpdateDTO.getPid()) == null) {
return ServiceExceptionUtil.error(ProductErrorCodeEnum.PRODUCT_CATEGORY_PARENT_NOT_EXISTS.getCode());
}
@@ -78,6 +79,10 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
@Override
public CommonResult<Boolean> updateProductCategoryStatus(Integer adminId, Integer productCategoryId, Integer status) {
// 校验参数
if (!isValidStatus(status)) {
return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "变更状态必须是开启1或关闭2"); // TODO 有点搓
}
// 校验分类是否存在
ProductCategoryDO productCategory = productCategoryMapper.selectById(productCategoryId);
if (productCategory == null) {
@@ -107,11 +112,16 @@ public class ProductCategoryServiceImpl implements ProductCategoryService {
}
// TODO 芋艿:考虑下,是否需要判断下该分类下是否有商品
// 标记删除商品分类
ProductCategoryDO updateProductCategory = new ProductCategoryDO();
ProductCategoryDO updateProductCategory = new ProductCategoryDO().setId(productCategoryId);
updateProductCategory.setDeleted(BaseDO.DELETED_YES);
productCategoryMapper.update(updateProductCategory);
// TODO 操作日志
return CommonResult.success(true);
}
private boolean isValidStatus(Integer status) {
return ProductCategoryConstants.STATUS_ENABLE.equals(status)
|| ProductCategoryConstants.STATUS_DISABLE.equals(status);
}
}

View File

@@ -3,7 +3,7 @@
<mapper namespace="cn.iocoder.mall.product.dao.ProductCategoryMapper">
<sql id="FIELDS">
id, pid, name, descrption, pic_url,
id, pid, name, description, pic_url,
sort, status, create_time
</sql>
@@ -43,7 +43,7 @@
</insert>
<update id="update" parameterType="ProductCategoryDO">
UPDATE resource
UPDATE product_category
<set>
<if test="pid != null">
pid = #{pid},