| | |
| | | import cc.mrbird.febs.ai.util.UUID; |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.entity.QueryRequest; |
| | | import cc.mrbird.febs.common.exception.FebsException; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductCategory> getList() { |
| | | public List<AiProductCategory> getList(String companyId) { |
| | | LambdaQueryWrapper<AiProductCategory> query = Wrappers.lambdaQuery(AiProductCategory.class); |
| | | if (StrUtil.isNotEmpty(companyId)){ |
| | | query.eq(AiProductCategory::getCompanyId, companyId); |
| | | } |
| | | query.ne(AiProductCategory::getState, 2); |
| | | query.eq(AiProductCategory::getLevel, ProductCategoryLevelEnum.LEVEL_ONE.getLevel()); |
| | | query.orderByDesc(AiProductCategory::getHotState); |
| | |
| | | |
| | | Page<AiProductCategory> page = new Page<>(request.getPageNum(), request.getPageSize()); |
| | | LambdaQueryWrapper<AiProductCategory> query = Wrappers.lambdaQuery(AiProductCategory.class); |
| | | if (StrUtil.isNotEmpty(dto.getCompanyId())){ |
| | | query.eq(AiProductCategory::getCompanyId, dto.getCompanyId()); |
| | | } |
| | | query.ne(AiProductCategory::getState, 2); |
| | | query.orderByDesc(AiProductCategory::getHotState); |
| | | query.orderByAsc(AiProductCategory::getSort); |
| | |
| | | public FebsResponse update(AiProductCategory dto) { |
| | | String id = dto.getId(); |
| | | AiProductCategory entity = this.getById(id); |
| | | dto.setLevel(ProductCategoryLevelEnum.LEVEL_ONE.getLevel()); |
| | | String parentId = dto.getParentId(); |
| | | if (parentId.equals( id)){ |
| | | throw new FebsException("父类不能选择自己"); |
| | | } |
| | | if (StrUtil.isNotEmpty(parentId)){ |
| | | AiProductCategory parent = this.getById(parentId); |
| | | if ( |
| | | ObjectUtil.isNotNull(parent) |
| | | && parent.getLevel() < ProductCategoryLevelEnum.LEVEL_TWO.getLevel() |
| | | ){ |
| | | dto.setLevel(parent.getLevel() +1); |
| | | dto.setParentId(parentId); |
| | | } |
| | | } |
| | | if (ObjectUtil.isNotNull( entity)){ |
| | | this.update(null, |
| | | Wrappers.lambdaUpdate(AiProductCategory.class) |
| | |
| | | .set(AiProductCategory::getIconImg, dto.getIconImg()) |
| | | .set(AiProductCategory::getSort, dto.getSort()) |
| | | .set(AiProductCategory::getUpdatedTime, new Date()) |
| | | .set(AiProductCategory::getParentId, dto.getParentId()) |
| | | .set(AiProductCategory::getLevel, dto.getLevel()) |
| | | .eq(AiProductCategory::getId, id) |
| | | ); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductCategory> categoryTree() { |
| | | return this.getList() ; |
| | | public List<AiProductCategory> categoryTree(String companyId) { |
| | | return this.getList(companyId) ; |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductCategory> parent() { |
| | | public List<AiProductCategory> parent(String companyId) { |
| | | LambdaQueryWrapper<AiProductCategory> query = Wrappers.lambdaQuery(AiProductCategory.class); |
| | | query.select(AiProductCategory::getId,AiProductCategory::getName); |
| | | if (StrUtil.isNotEmpty(companyId)){ |
| | | query.eq(AiProductCategory::getCompanyId, companyId); |
| | | } |
| | | query.eq(AiProductCategory::getLevel, 1); |
| | | query.ne(AiProductCategory::getState, 2); |
| | | return this.getBaseMapper().selectList(query); |