| | |
| | | package cc.mrbird.febs.ai.service.impl; |
| | | |
| | | import cc.mrbird.febs.ai.entity.AiProduct; |
| | | import cc.mrbird.febs.ai.entity.AiProductPoint; |
| | | import cc.mrbird.febs.ai.mapper.AiProductMapper; |
| | | import cc.mrbird.febs.ai.service.AiProductService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import cc.mrbird.febs.ai.req.product.ApiProductInfoDto; |
| | | import cc.mrbird.febs.ai.req.product.ApiProductPageDto; |
| | | import cc.mrbird.febs.ai.res.product.ApiProductInfoVo; |
| | | import cc.mrbird.febs.ai.res.product.ApiProductVo; |
| | | import cc.mrbird.febs.ai.res.productPoint.ApiProductPointVo; |
| | | import cc.mrbird.febs.ai.service.*; |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cn.hutool.core.util.StrUtil; |
| | | 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; |
| | | |
| | |
| | | public class AiProductServiceImpl extends ServiceImpl<AiProductMapper, AiProduct> implements AiProductService { |
| | | |
| | | private final AiProductMapper aiProductMapper; |
| | | private final AiMemberRoleService aiMemberRoleService; |
| | | private final AiProductCategoryService aiProductCategoryService; |
| | | private final AiProductPointService aiProductPointService; |
| | | |
| | | |
| | | @Override |
| | | public AiProduct getById(String id) { |
| | | return this.getById(id); |
| | | return aiProductMapper.selectById( id); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProduct> getByCompanyId(String companyId) { |
| | | LambdaQueryWrapper<AiProduct> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProduct::getCompanyId, companyId); |
| | | queryWrapper.orderByDesc(AiProduct::getSort); |
| | | queryWrapper.orderByDesc(AiProduct::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | public Page<ApiProductVo> getPageListByQuery(Page<ApiProductVo> page, ApiProductPageDto dto) { |
| | | return aiProductMapper.selectPageListByQuery(page, dto); |
| | | } |
| | | |
| | | @Override |
| | | public AiProduct getByCode(String code) { |
| | | LambdaQueryWrapper<AiProduct> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProduct::getCode, code); |
| | | return this.getOne(queryWrapper); |
| | | } |
| | | public FebsResponse productList(ApiProductPageDto dto) { |
| | | |
| | | @Override |
| | | public List<AiProduct> getByName(String name) { |
| | | LambdaQueryWrapper<AiProduct> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.like(AiProduct::getName, name); |
| | | queryWrapper.orderByDesc(AiProduct::getSort); |
| | | queryWrapper.orderByDesc(AiProduct::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProduct> getByProductCategoryId(String productCategoryId) { |
| | | LambdaQueryWrapper<AiProduct> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProduct::getProductCategoryId, productCategoryId); |
| | | queryWrapper.orderByDesc(AiProduct::getSort); |
| | | queryWrapper.orderByDesc(AiProduct::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProduct> getByState(Integer state) { |
| | | LambdaQueryWrapper<AiProduct> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProduct::getState, state); |
| | | queryWrapper.orderByDesc(AiProduct::getSort); |
| | | queryWrapper.orderByDesc(AiProduct::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProduct> getByHotState(Integer hotState) { |
| | | LambdaQueryWrapper<AiProduct> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProduct::getHotState, hotState); |
| | | queryWrapper.orderByDesc(AiProduct::getSort); |
| | | queryWrapper.orderByDesc(AiProduct::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProduct> getByCompanyIdAndState(String companyId, Integer state) { |
| | | LambdaQueryWrapper<AiProduct> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProduct::getCompanyId, companyId); |
| | | queryWrapper.eq(AiProduct::getState, state); |
| | | queryWrapper.orderByDesc(AiProduct::getSort); |
| | | queryWrapper.orderByDesc(AiProduct::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<AiProduct> getByCompanyIdAndHotState(String companyId, Integer hotState) { |
| | | LambdaQueryWrapper<AiProduct> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProduct::getCompanyId, companyId); |
| | | queryWrapper.eq(AiProduct::getHotState, hotState); |
| | | queryWrapper.orderByDesc(AiProduct::getSort); |
| | | queryWrapper.orderByDesc(AiProduct::getCreatedTime); |
| | | return this.list(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean saveProduct(AiProduct aiProduct) { |
| | | try { |
| | | return this.save(aiProduct); |
| | | } catch (Exception e) { |
| | | log.error("保存AI产品失败: ", e); |
| | | return false; |
| | | if(StrUtil.isEmpty(dto.getMemberRoleId())){ |
| | | String memberRoleId = aiMemberRoleService.getDefaultMemberRoleId(); |
| | | dto.setMemberRoleId(memberRoleId); |
| | | } |
| | | |
| | | if(StrUtil.isEmpty(dto.getCategoryId())){ |
| | | String categoryId = aiProductCategoryService.getDefaultProductCategoryId(); |
| | | dto.setCategoryId(categoryId); |
| | | } |
| | | // 创建分页对象,传入当前页和每页大小 |
| | | Page<ApiProductVo> page = new Page<>(dto.getPageNow(), dto.getPageSize()); |
| | | Page<ApiProductVo> pageListByQuery = this.getPageListByQuery(page, dto); |
| | | return new FebsResponse().success().data(pageListByQuery); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean saveBatchProducts(List<AiProduct> products) { |
| | | try { |
| | | return this.saveBatch(products); |
| | | } catch (Exception e) { |
| | | log.error("批量保存AI产品失败: ", e); |
| | | return false; |
| | | } |
| | | public FebsResponse productInfo(ApiProductInfoDto dto) { |
| | | |
| | | String id = dto.getId(); |
| | | AiProduct entity = this.getById(id); |
| | | ApiProductInfoVo vo = new ApiProductInfoVo(); |
| | | vo.setId(entity.getId()); |
| | | vo.setProductCategoryId(entity.getProductCategoryId()); |
| | | vo.setName(entity.getName()); |
| | | vo.setScene(entity.getScene()); |
| | | vo.setTarget(entity.getTarget()); |
| | | vo.setBackImg(entity.getBackImg()); |
| | | vo.setIconImg(entity.getIconImg()); |
| | | vo.setDescription(entity.getDescription()); |
| | | vo.setQuestionCount(entity.getQuestionCount()); |
| | | |
| | | vo.setProductPointList(aiProductPointService.listByProductId(id)); |
| | | return new FebsResponse().success().data(vo); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean updateProduct(AiProduct aiProduct) { |
| | | try { |
| | | return this.updateById(aiProduct); |
| | | } catch (Exception e) { |
| | | log.error("更新AI产品失败: ", e); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean deleteById(String id) { |
| | | try { |
| | | return this.removeById(id); |
| | | } catch (Exception e) { |
| | | log.error("删除AI产品失败: ", e); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean deleteByCompanyId(String companyId) { |
| | | try { |
| | | LambdaQueryWrapper<AiProduct> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(AiProduct::getCompanyId, companyId); |
| | | return this.remove(queryWrapper); |
| | | } catch (Exception e) { |
| | | log.error("根据公司ID删除AI产品失败: ", e); |
| | | return false; |
| | | } |
| | | public FebsResponse pointInfoList(ApiProductInfoDto dto) { |
| | | String id = dto.getId(); |
| | | AiProduct entity = this.getById(id); |
| | | List<ApiProductPointVo> apiProductPointVos = aiProductPointService.listByProductId(id); |
| | | return new FebsResponse().success().data(apiProductPointVos); |
| | | } |
| | | } |