| | |
| | | import com.walker.db.page.GenericPager; |
| | | import com.walker.infrastructure.utils.StringUtils; |
| | | import com.walker.web.ResponseValue; |
| | | import io.swagger.annotations.Api; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | /** |
| | |
| | | * @Author 卢庆阳 |
| | | * @Date 2023/10/23 |
| | | */ |
| | | @Api(value = "物品分类", tags = "物品分类") |
| | | // @Api(value = "物品分类", tags = "物品分类") |
| | | @RestController |
| | | @RequestMapping("/pc/base/category") |
| | | public class BaseCategoryController extends BaseController { |
| | |
| | | if (category != null) { |
| | | return ResponseValue.error("分类名称已存在"); |
| | | } |
| | | |
| | | // 判断添加的父级不能是3 |
| | | if (param2.getFatherCategoryId() != null) { |
| | | BaseCategory baseCategory = new BaseCategory(); |
| | | baseCategory.setId(param2.getFatherCategoryId()); |
| | | BaseCategory baseCategory1 = this.baseCategoryService.get(baseCategory); |
| | | if (baseCategory1 != null && baseCategory1.getLevels() >= 3) { |
| | | return ResponseValue.error("分类最多支持三级"); |
| | | } |
| | | } |
| | | int result = this.baseCategoryService.add(param, this.getCurrentUser()); |
| | | if (result > 0) { |
| | | return ResponseValue.success(1); |
| | |
| | | if (currentUser == null) { |
| | | return ResponseValue.error("登录用户信息不存在"); |
| | | } |
| | | List<BaseCategory> list = this.baseGoodsTemplateService.getByCategoryId(baseCategory.getId()); |
| | | if (!CollectionUtils.isEmpty(list) && param2.getStates() != 1) { |
| | | return ResponseValue.error("分类下有商品在用,不允许禁用"); |
| | | } |
| | | // 查询分类下是否有子级分类 |
| | | BaseCategory baseCategory1 = new BaseCategory(); |
| | | baseCategory1.setFatherCategoryId(param2.getId()); |
| | | List<BaseCategory> select = this.baseCategoryService.select(baseCategory1); |
| | | if (!CollectionUtils.isEmpty(select) && param2.getStates() != 1) { |
| | | return ResponseValue.error("分类下有子级分类在用,不允许禁用"); |
| | | } |
| | | int num = this.baseCategoryService.updateBaseCategory(baseCategory); |
| | | return num > 0 ? ResponseValue.success(1) : ResponseValue.error("编辑失败!"); |
| | | } |
| | |
| | | } |
| | | // 根据分类id和状态查询物品模版 |
| | | List<BaseCategory> list = this.baseGoodsTemplateService.getByCategoryId(baseCategory.getId()); |
| | | if (baseCategory.getStates() == 2 && !CollectionUtils.isEmpty(list)) { |
| | | return ResponseValue.error("分类下有正常状态的物品,不允许禁用"); |
| | | if (!CollectionUtils.isEmpty(list)) { |
| | | return ResponseValue.error("分类下有商品在用,不允许禁用"); |
| | | } |
| | | |
| | | // 查询分类下是否有子级分类 |
| | | BaseCategory baseCategory1 = new BaseCategory(); |
| | | baseCategory1.setFatherCategoryId(param2.getId()); |
| | | List<BaseCategory> select = this.baseCategoryService.select(baseCategory1); |
| | | if (!CollectionUtils.isEmpty(select)) { |
| | | return ResponseValue.error("分类下有子级分类在用,不允许禁用"); |
| | | } |
| | | int num = this.baseCategoryService.updateStatus(baseCategory); |
| | | return num > 0 ? ResponseValue.success(1) : ResponseValue.error("修改失败!"); |
| | | } |
| | |
| | | BaseCategory param2 = new BaseCategory(); |
| | | CommonUtil.copyProperties(baseCategory, param2); |
| | | baseCategory = param2; |
| | | |
| | | if (baseCategory.getId() == null) { |
| | | return ResponseValue.error("分类id为空"); |
| | | } |
| | | // 判断分类是否有商品在用 |
| | | List<BaseCategory> byCategoryId = this.baseGoodsTemplateService.getByCategoryId(baseCategory.getId()); |
| | | if (!CollectionUtils.isEmpty(byCategoryId)) { |
| | | return ResponseValue.error("分类下有商品在用,不允许删除"); |
| | | } |
| | | // 查询分类下是否有子级分类 |
| | | List<BaseCategory> select = this.baseCategoryService.selectByFatherId(param2.getId()); |
| | | if (!CollectionUtils.isEmpty(select)) { |
| | | return ResponseValue.error("分类下有子级分类在用,不允许删除"); |
| | | } |
| | | int num = this.baseCategoryService.updateById(baseCategory, this.getCurrentUser()); |
| | | |
| | |
| | | if (currentUser == null) { |
| | | return ResponseValue.error("登录用户信息不存在"); |
| | | } |
| | | |
| | | List<BaseCategory> baseCategories = this.baseCategoryService.queryForLv3Tree(); |
| | | return ResponseValue.success(baseCategories); |
| | | } |