|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import cc.mrbird.febs.common.entity.FebsResponse; | 
|---|
|  |  |  | import cc.mrbird.febs.common.entity.QueryRequest; | 
|---|
|  |  |  | import cc.mrbird.febs.common.utils.AppContants; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.MallGoods; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.entity.MallGoodsCategory; | 
|---|
|  |  |  | import cc.mrbird.febs.mall.mapper.MallGoodsCategoryMapper; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public FebsResponse addAppCategory(MallGoodsCategory mallGoodsCategory) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String name = mallGoodsCategory.getName(); | 
|---|
|  |  |  | if(StrUtil.isEmpty(name)){ | 
|---|
|  |  |  | return new FebsResponse().fail().message("分类名称不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<MallGoodsCategory> categorys = mallGoodsCategoryMapper.selectCategoryByName(name); | 
|---|
|  |  |  | if(CollUtil.isNotEmpty(categorys)){ | 
|---|
|  |  |  | return new FebsResponse().fail().message("分类名称不能重复"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //        Long parentIdParam = mallGoodsCategory.getParentId() == null ? 0L:mallGoodsCategory.getParentId(); | 
|---|
|  |  |  | //        Integer isRecommendParam = mallGoodsCategory.getIsRecommend(); | 
|---|
|  |  |  | //        if(parentIdParam > 0 && isRecommendParam == 1){ | 
|---|
|  |  |  | //            return new FebsResponse().fail().message("子分类不能选择【是否推荐】为【是】"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | MallGoodsCategory goodsCategory = new MallGoodsCategory(); | 
|---|
|  |  |  | goodsCategory.setName(name); | 
|---|
|  |  |  | goodsCategory.setIsApp(AppContants.IS_APP_CATEGORY); | 
|---|
|  |  |  | goodsCategory.setImage(mallGoodsCategory.getImage()); | 
|---|
|  |  |  | goodsCategory.setIndexNum(mallGoodsCategory.getIndexNum()); | 
|---|
|  |  |  | //        if(ObjectUtil.isNotEmpty(mallGoodsCategory.getParentId())){ | 
|---|
|  |  |  | //            Long parentId = mallGoodsCategory.getParentId(); | 
|---|
|  |  |  | //            MallGoodsCategory mallGoodsCategoryParent = mallGoodsCategoryMapper.selectById(parentId); | 
|---|
|  |  |  | //            goodsCategory.setParentId(mallGoodsCategory.getParentId()); | 
|---|
|  |  |  | //            if(StrUtil.isNotEmpty(mallGoodsCategoryParent.getParentIds())){ | 
|---|
|  |  |  | //                goodsCategory.setParentIds(mallGoodsCategoryParent.getParentIds()+","+mallGoodsCategory.getParentId()+","); | 
|---|
|  |  |  | //            }else{ | 
|---|
|  |  |  | //                goodsCategory.setParentIds(mallGoodsCategory.getParentId()+","); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //            goodsCategory.setIsRecommend(0); | 
|---|
|  |  |  | //        }else{ | 
|---|
|  |  |  | //            goodsCategory.setParentId(0L); | 
|---|
|  |  |  | //            goodsCategory.setIsRecommend(mallGoodsCategory.getIsRecommend()); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | mallGoodsCategoryMapper.insert(goodsCategory); | 
|---|
|  |  |  | return new FebsResponse().success(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<MallGoodsCategory> getCategorys(MallGoodsCategory mallGoodsCategory) { | 
|---|
|  |  |  | List<MallGoodsCategory> mallGoodsCategorys = mallGoodsCategoryMapper.getCategorys(); | 
|---|
|  |  |  | return mallGoodsCategorys; | 
|---|
|  |  |  | 
|---|
|  |  |  | MallGoodsCategory mallGoodsCategory = mallGoodsCategoryMapper.selectById(id); | 
|---|
|  |  |  | mallGoodsCategory.setName(mallGoodsCategoryParam.getName()); | 
|---|
|  |  |  | mallGoodsCategory.setImage(mallGoodsCategoryParam.getImage()); | 
|---|
|  |  |  | mallGoodsCategory.setIndexNum(mallGoodsCategoryParam.getIndexNum()); | 
|---|
|  |  |  | if(ObjectUtil.isNotEmpty(mallGoodsCategoryParam.getParentId())){ | 
|---|
|  |  |  | Long parentId = mallGoodsCategoryParam.getParentId(); | 
|---|
|  |  |  | MallGoodsCategory mallGoodsCategoryParent = mallGoodsCategoryMapper.selectById(parentId); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public FebsResponse updateAppCategory(MallGoodsCategory mallGoodsCategoryParam) { | 
|---|
|  |  |  | String name = mallGoodsCategoryParam.getName(); | 
|---|
|  |  |  | if(StrUtil.isEmpty(name)){ | 
|---|
|  |  |  | return new FebsResponse().fail().message("名称不能为空"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //        Long parentIdParam = mallGoodsCategoryParam.getParentId() == null ? 0L:mallGoodsCategoryParam.getParentId(); | 
|---|
|  |  |  | //        Integer isRecommendParam = mallGoodsCategoryParam.getIsRecommend(); | 
|---|
|  |  |  | //        if(parentIdParam > 0 && isRecommendParam == 1){ | 
|---|
|  |  |  | //            return new FebsResponse().fail().message("子分类不能选择【是否推荐】为【是】"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Long id = mallGoodsCategoryParam.getId(); | 
|---|
|  |  |  | MallGoodsCategory mallGoodsCategory = mallGoodsCategoryMapper.selectById(id); | 
|---|
|  |  |  | mallGoodsCategory.setName(mallGoodsCategoryParam.getName()); | 
|---|
|  |  |  | mallGoodsCategory.setImage(mallGoodsCategoryParam.getImage()); | 
|---|
|  |  |  | mallGoodsCategory.setIndexNum(mallGoodsCategoryParam.getIndexNum()); | 
|---|
|  |  |  | //        if(ObjectUtil.isNotEmpty(mallGoodsCategoryParam.getParentId())){ | 
|---|
|  |  |  | //            Long parentId = mallGoodsCategoryParam.getParentId(); | 
|---|
|  |  |  | //            MallGoodsCategory mallGoodsCategoryParent = mallGoodsCategoryMapper.selectById(parentId); | 
|---|
|  |  |  | //            mallGoodsCategory.setParentId(mallGoodsCategoryParam.getParentId()); | 
|---|
|  |  |  | //            if(StrUtil.isNotEmpty(mallGoodsCategoryParent.getParentIds())){ | 
|---|
|  |  |  | //                mallGoodsCategory.setParentIds(mallGoodsCategoryParent.getParentIds()+","+mallGoodsCategory.getParentId()+","); | 
|---|
|  |  |  | //            }else{ | 
|---|
|  |  |  | //                mallGoodsCategory.setParentIds(mallGoodsCategory.getParentId()+","); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //            mallGoodsCategory.setIsRecommend(0); | 
|---|
|  |  |  | //        }else{ | 
|---|
|  |  |  | //            mallGoodsCategory.setParentId(0L); | 
|---|
|  |  |  | //            mallGoodsCategory.setIsRecommend(mallGoodsCategoryParam.getIsRecommend()); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | mallGoodsCategoryMapper.updateById(mallGoodsCategory); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return new FebsResponse().success(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public FebsResponse delCategary(Long id) { | 
|---|
|  |  |  | MallGoodsCategory mallGoodsCategory = mallGoodsCategoryMapper.selectById(id); | 
|---|
|  |  |  | if(ObjectUtil.isEmpty(mallGoodsCategory)){ | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public FebsResponse delAppCategary(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(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<AdminMallGoodsCategoryTreeVo> getAllCategorys() { | 
|---|
|  |  |  | List<AdminMallGoodsCategoryTreeVo> adminMallGoodsCategoryTreeVos = mallGoodsCategoryMapper.getAllCategorys(); | 
|---|
|  |  |  | return adminMallGoodsCategoryTreeVos; | 
|---|