src/main/java/cc/mrbird/febs/mall/controller/AdminMallGoodsCategoryController.java
@@ -11,12 +11,10 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import javax.validation.constraints.NotNull; import java.util.List; import java.util.Map; @@ -72,4 +70,15 @@ public FebsResponse updateCategory(@Valid MallGoodsCategory mallGoodsCategory) { return goodsCategoryService.updateCategory(mallGoodsCategory); } /** * 商品分类-删除 */ @GetMapping("delCategary/{id}") @ControllerEndpoint(operation = " 商品分类-删除", exceptionMessage = "操作失败") public FebsResponse delCategary(@NotNull(message = "{required}") @PathVariable Long id) { return goodsCategoryService.delCategary(id); } } src/main/java/cc/mrbird/febs/mall/mapper/MallGoodsCategoryMapper.java
@@ -28,4 +28,6 @@ AdminMallGoodsCategoryVo getMallGoodsCategoryInfoById(@Param("id")long id); List<AdminMallGoodsCategoryTreeVo> getParentCategorys(); List<MallGoodsCategory> selectChildCategaryById(@Param("id")Long id); } src/main/java/cc/mrbird/febs/mall/mapper/MallGoodsMapper.java
@@ -11,6 +11,7 @@ import org.apache.ibatis.annotations.Param; import java.math.BigDecimal; import java.util.List; import java.util.Map; public interface MallGoodsMapper extends BaseMapper<MallGoods> { @@ -28,4 +29,6 @@ AdminMailGoodsDetailVo selectMallGoodsInfoById(@Param("id")long id); Map<String, BigDecimal> selectGoodsStockAndVolume(@Param("id") Long id); List<MallGoods> selectMallGoodsByCategaryId(@Param("categaryId")Long id); } src/main/java/cc/mrbird/febs/mall/service/IAdminMallGoodsCategoryService.java
@@ -24,4 +24,6 @@ List<AdminMallGoodsCategoryTreeVo> getParentCategorys(); FebsResponse updateCategory(MallGoodsCategory mallGoodsCategory); FebsResponse delCategary(Long id); } src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsCategoryService.java
@@ -2,8 +2,10 @@ import cc.mrbird.febs.common.entity.FebsResponse; import cc.mrbird.febs.common.entity.QueryRequest; import cc.mrbird.febs.mall.entity.MallGoods; import cc.mrbird.febs.mall.entity.MallGoodsCategory; import cc.mrbird.febs.mall.mapper.MallGoodsCategoryMapper; import cc.mrbird.febs.mall.mapper.MallGoodsMapper; import cc.mrbird.febs.mall.service.IAdminMallGoodsCategoryService; import cc.mrbird.febs.mall.vo.AdminMallGoodsCategoryTreeVo; import cc.mrbird.febs.mall.vo.AdminMallGoodsCategoryVo; @@ -25,6 +27,8 @@ public class AdminMallGoodsCategoryService extends ServiceImpl<MallGoodsCategoryMapper, MallGoodsCategory> implements IAdminMallGoodsCategoryService { private final MallGoodsCategoryMapper mallGoodsCategoryMapper; private final MallGoodsMapper mallGoodsMapper; @Override public IPage<MallGoodsCategory> getCategoryList(MallGoodsCategory mallGoodsCategory, QueryRequest request) { @@ -122,4 +126,33 @@ return new FebsResponse().success(); } @Override public FebsResponse delCategary(Long id) { MallGoodsCategory mallGoodsCategory = mallGoodsCategoryMapper.selectById(id); if(ObjectUtil.isEmpty(mallGoodsCategory)){ return new FebsResponse().fail().message("系统繁忙,请刷新页面重试"); } List<MallGoodsCategory> childCategarys = mallGoodsCategoryMapper.selectChildCategaryById(id); if(CollUtil.isNotEmpty(childCategarys)){ for(MallGoodsCategory childCategary : childCategarys){ Long childCategaryId = childCategary.getId(); List<MallGoods> mallChildGoods = mallGoodsMapper.selectMallGoodsByCategaryId(childCategaryId); if(CollUtil.isNotEmpty(mallChildGoods)){ return new FebsResponse().fail().message("该分类下的子类【"+childCategary.getName()+"】还有商品,请先删除商品或者修改商品分类"); } } } if(CollUtil.isNotEmpty(childCategarys)){ return new FebsResponse().fail().message("该分类下还有子类,请先删除子类"); } List<MallGoods> mallGoods = mallGoodsMapper.selectMallGoodsByCategaryId(id); if(CollUtil.isNotEmpty(mallGoods)){ return new FebsResponse().fail().message("该分类下还有商品,请先删除商品或者修改商品分类"); } mallGoodsCategoryMapper.deleteById(mallGoodsCategory); return new FebsResponse().success(); } } src/main/resources/mapper/modules/MallGoodsCategoryMapper.xml
@@ -66,4 +66,10 @@ <select id="getParentCategorys" resultType="cc.mrbird.febs.mall.vo.AdminMallGoodsCategoryTreeVo"> SELECT m.id parentId,m.name name FROM mall_goods_category m where m.parent_id = 0 </select> <select id="selectChildCategaryById" resultType="cc.mrbird.febs.mall.entity.MallGoodsCategory"> select * from mall_goods_category where parent_id = #{id} </select> </mapper> src/main/resources/mapper/modules/MallGoodsMapper.xml
@@ -152,4 +152,8 @@ from mall_goods_sku where goods_id=#{id} </select> <select id="selectMallGoodsByCategaryId" resultType="cc.mrbird.febs.mall.entity.MallGoods"> select * from mall_goods a where a.category_id = #{categaryId} </select> </mapper> src/main/resources/templates/febs/views/modules/product/categoryList.html
@@ -88,6 +88,11 @@ } }); } if (layEvent === 'delCategary') { febs.modal.confirm('删除', '确认删除?', function () { delCategary(data.id); }); } if (layEvent === 'seeImges') { var t = $view.find('#seeImges'+data.id+''); //页面层 @@ -105,6 +110,12 @@ } }); function delCategary(id) { febs.get(ctx + 'admin/goodsCategory/delCategary/' + id, null, function () { febs.alert.success('操作成功'); $query.click(); }); } // 查询按钮 $query.on('click', function () { @@ -146,6 +157,7 @@ {title: '操作', templet: function (d) { return '<button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="see" shiro:hasPermission="user:update">编辑</button>' +'<button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="delCategary" shiro:hasPermission="user:update">删除</button>' },minWidth: 300,align:'center'} ]] });