| | |
| | | package cc.mrbird.febs.ai.service.impl; |
| | | |
| | | import cc.mrbird.febs.ai.entity.AiMemberRole; |
| | | import cc.mrbird.febs.ai.entity.AiProductCategory; |
| | | import cc.mrbird.febs.ai.mapper.AiProductCategoryMapper; |
| | | import cc.mrbird.febs.ai.service.AiProductCategoryService; |
| | | import cc.mrbird.febs.ai.util.UUID; |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.entity.QueryRequest; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * AI产品类别 Service实现类 |
| | |
| | | |
| | | @Override |
| | | public AiProductCategory getById(String id) { |
| | | return this.getById(id); |
| | | return aiProductCategoryMapper.selectById(id); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductCategory> getByCompanyId(String companyId) { |
| | | LambdaQueryWrapper<AiProductCategory> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductCategory::getCompanyId, companyId); |
| | | queryWrapper.orderByAsc(AiProductCategory::getSort); |
| | | queryWrapper.orderByDesc(AiProductCategory::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | public List<AiProductCategory> getList() { |
| | | LambdaQueryWrapper<AiProductCategory> query = Wrappers.lambdaQuery(AiProductCategory.class); |
| | | query.ne(AiProductCategory::getState, 2); |
| | | query.orderByDesc(AiProductCategory::getHotState); |
| | | query.orderByAsc(AiProductCategory::getSort); |
| | | List<AiProductCategory> aiProductCategories = aiProductCategoryMapper.selectList(query); |
| | | return aiProductCategories; |
| | | } |
| | | |
| | | @Override |
| | | public AiProductCategory getByCode(String code) { |
| | | LambdaQueryWrapper<AiProductCategory> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductCategory::getCode, code); |
| | | return this.getOne(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductCategory> getByName(String name) { |
| | | LambdaQueryWrapper<AiProductCategory> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.like(AiProductCategory::getName, name); |
| | | queryWrapper.orderByAsc(AiProductCategory::getSort); |
| | | queryWrapper.orderByDesc(AiProductCategory::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductCategory> getByState(Integer state) { |
| | | LambdaQueryWrapper<AiProductCategory> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductCategory::getState, state); |
| | | queryWrapper.orderByAsc(AiProductCategory::getSort); |
| | | queryWrapper.orderByDesc(AiProductCategory::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductCategory> getByHotState(Integer hotState) { |
| | | LambdaQueryWrapper<AiProductCategory> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductCategory::getHotState, hotState); |
| | | queryWrapper.orderByAsc(AiProductCategory::getSort); |
| | | queryWrapper.orderByDesc(AiProductCategory::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductCategory> getByCompanyIdAndState(String companyId, Integer state) { |
| | | LambdaQueryWrapper<AiProductCategory> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductCategory::getCompanyId, companyId); |
| | | queryWrapper.eq(AiProductCategory::getState, state); |
| | | queryWrapper.orderByAsc(AiProductCategory::getSort); |
| | | queryWrapper.orderByDesc(AiProductCategory::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductCategory> getByCompanyIdAndHotState(String companyId, Integer hotState) { |
| | | LambdaQueryWrapper<AiProductCategory> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductCategory::getCompanyId, companyId); |
| | | queryWrapper.eq(AiProductCategory::getHotState, hotState); |
| | | queryWrapper.orderByAsc(AiProductCategory::getSort); |
| | | queryWrapper.orderByDesc(AiProductCategory::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductCategory> getEnabledCategories() { |
| | | LambdaQueryWrapper<AiProductCategory> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductCategory::getState, 1); // 1-启用 |
| | | queryWrapper.orderByAsc(AiProductCategory::getSort); |
| | | queryWrapper.orderByDesc(AiProductCategory::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean saveProductCategory(AiProductCategory aiProductCategory) { |
| | | try { |
| | | return this.save(aiProductCategory); |
| | | } catch (Exception e) { |
| | | log.error("保存AI产品类别失败: ", e); |
| | | return false; |
| | | public Map<String, AiProductCategory> selectMapByIds(Set<String> collect) { |
| | | Map<String,AiProductCategory> map = new HashMap<>(); |
| | | if(CollUtil.isNotEmpty( collect)){ |
| | | List<AiProductCategory> aiProductCategories = aiProductCategoryMapper.selectList( |
| | | Wrappers.lambdaQuery(AiProductCategory.class) |
| | | .in(AiProductCategory::getId,collect) |
| | | ); |
| | | if(CollUtil.isNotEmpty(aiProductCategories)){ |
| | | aiProductCategories.forEach(aiProductCategory -> map.put(aiProductCategory.getId(),aiProductCategory)); |
| | | } |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean saveBatchProductCategories(List<AiProductCategory> productCategories) { |
| | | try { |
| | | return this.saveBatch(productCategories); |
| | | } catch (Exception e) { |
| | | log.error("批量保存AI产品类别失败: ", e); |
| | | return false; |
| | | } |
| | | public IPage<AiProductCategory> listInPage(AiProductCategory dto, QueryRequest request) { |
| | | |
| | | |
| | | Page<AiProductCategory> page = new Page<>(request.getPageNum(), request.getPageSize()); |
| | | LambdaQueryWrapper<AiProductCategory> query = Wrappers.lambdaQuery(AiProductCategory.class); |
| | | query.ne(AiProductCategory::getState, 2); |
| | | query.orderByDesc(AiProductCategory::getHotState); |
| | | query.orderByAsc(AiProductCategory::getSort); |
| | | Page<AiProductCategory> pages = aiProductCategoryMapper.selectPage(page, query); |
| | | return pages; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean updateProductCategory(AiProductCategory aiProductCategory) { |
| | | try { |
| | | return this.updateById(aiProductCategory); |
| | | } catch (Exception e) { |
| | | log.error("更新AI产品类别失败: ", e); |
| | | return false; |
| | | public FebsResponse changeState(String id, Integer type, Integer state) { |
| | | AiProductCategory entity = this.getById(id); |
| | | if(ObjectUtil.isNotNull(entity)){ |
| | | if(1 == type){ |
| | | aiProductCategoryMapper.update(null, |
| | | Wrappers.lambdaUpdate(AiProductCategory.class) |
| | | .set(AiProductCategory::getState, state) |
| | | .eq(AiProductCategory::getId, id) |
| | | ); |
| | | } |
| | | if(2 == type){ |
| | | aiProductCategoryMapper.update(null, |
| | | Wrappers.lambdaUpdate(AiProductCategory.class) |
| | | .set(AiProductCategory::getHotState, state) |
| | | .eq(AiProductCategory::getId, id) |
| | | ); |
| | | } |
| | | } |
| | | return new FebsResponse().success().message("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean deleteById(String id) { |
| | | try { |
| | | return this.removeById(id); |
| | | } catch (Exception e) { |
| | | log.error("删除AI产品类别失败: ", e); |
| | | return false; |
| | | } |
| | | public FebsResponse add(AiProductCategory dto) { |
| | | AiProductCategory entity = new AiProductCategory(); |
| | | entity.setId(UUID.getSimpleUUIDString()); |
| | | entity.setCompanyId(dto.getCompanyId()); |
| | | entity.setCode(dto.getCode()); |
| | | entity.setName(dto.getName()); |
| | | entity.setBackImg(dto.getBackImg()); |
| | | entity.setIconImg(dto.getIconImg()); |
| | | entity.setSort(dto.getSort()); |
| | | entity.setCreatedTime(new Date()); |
| | | this.save(entity); |
| | | return new FebsResponse().success().message("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean deleteByCompanyId(String companyId) { |
| | | try { |
| | | LambdaQueryWrapper<AiProductCategory> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProductCategory::getCompanyId, companyId); |
| | | return this.remove(queryWrapper); |
| | | } catch (Exception e) { |
| | | log.error("根据公司ID删除AI产品类别失败: ", e); |
| | | return false; |
| | | public FebsResponse update(AiProductCategory dto) { |
| | | String id = dto.getId(); |
| | | AiProductCategory entity = this.getById(id); |
| | | if (ObjectUtil.isNotNull( entity)){ |
| | | this.update(null, |
| | | Wrappers.lambdaUpdate(AiProductCategory.class) |
| | | .set(AiProductCategory::getCode, dto.getCode()) |
| | | .set(AiProductCategory::getName, dto.getName()) |
| | | .set(AiProductCategory::getBackImg, dto.getBackImg()) |
| | | .set(AiProductCategory::getIconImg, dto.getIconImg()) |
| | | .set(AiProductCategory::getSort, dto.getSort()) |
| | | .set(AiProductCategory::getUpdatedTime, new Date()) |
| | | .eq(AiProductCategory::getId, id) |
| | | ); |
| | | } |
| | | return new FebsResponse().success().message("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | public FebsResponse delete(String id) { |
| | | |
| | | AiProductCategory entity = this.getById(id); |
| | | if(ObjectUtil.isNotNull( entity)){ |
| | | this.update(null, |
| | | Wrappers.lambdaUpdate(AiProductCategory.class) |
| | | .set(AiProductCategory::getState, 2) |
| | | .set(AiProductCategory::getUpdatedTime, new Date()) |
| | | .eq(AiProductCategory::getId, id)); |
| | | |
| | | } |
| | | return new FebsResponse().success().message("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProductCategory> categoryTree() { |
| | | return this.getList() ; |
| | | } |
| | | } |