|
|
@@ -0,0 +1,159 @@
|
|
|
+package com.ruoyi.business.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.ruoyi.business.domain.BusinessCategoryRelation;
|
|
|
+import com.ruoyi.business.domain.bo.BusinessCategoryRelationBo;
|
|
|
+import com.ruoyi.business.domain.vo.BusinessCategoryRelationVo;
|
|
|
+import com.ruoyi.business.exception.BusinessCategoryRelationExceptionEnum;
|
|
|
+import com.ruoyi.business.mapper.BusinessCategoryRelationMapper;
|
|
|
+import com.ruoyi.business.service.IBusinessCategoryRelationService;
|
|
|
+import com.ruoyi.common.core.domain.PageQuery;
|
|
|
+import com.ruoyi.common.core.page.TableDataInfo;
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
+import com.ruoyi.common.utils.BeanCopyUtils;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 商家分类关联Service业务层处理
|
|
|
+ *
|
|
|
+ * @author ruoyi
|
|
|
+ * @date 2026-04-08
|
|
|
+ */
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Service
|
|
|
+public class BusinessCategoryRelationServiceImpl implements IBusinessCategoryRelationService {
|
|
|
+
|
|
|
+ private final BusinessCategoryRelationMapper baseMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询商家分类关联分页
|
|
|
+ *
|
|
|
+ * @param bo 商家分类关联
|
|
|
+ * @return 商家分类关联
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<BusinessCategoryRelationVo> queryPageList(BusinessCategoryRelationBo bo, PageQuery pageQuery) {
|
|
|
+ LambdaQueryWrapper<BusinessCategoryRelation> lqw = buildQueryWrapper(bo);
|
|
|
+ Page<BusinessCategoryRelationVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
+ return TableDataInfo.build(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询商家分类关联列表
|
|
|
+ *
|
|
|
+ * @param bo 商家分类关联
|
|
|
+ * @return 商家分类关联
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<BusinessCategoryRelationVo> queryList(BusinessCategoryRelationBo bo) {
|
|
|
+ LambdaQueryWrapper<BusinessCategoryRelation> lqw = buildQueryWrapper(bo);
|
|
|
+ return baseMapper.selectVoList(lqw);
|
|
|
+ }
|
|
|
+
|
|
|
+ private LambdaQueryWrapper<BusinessCategoryRelation> buildQueryWrapper(BusinessCategoryRelationBo bo) {
|
|
|
+ Map<String, Object> params = bo.getParams();
|
|
|
+ LambdaQueryWrapper<BusinessCategoryRelation> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.eq(bo.getBusinessId() != null, BusinessCategoryRelation::getBusinessId, bo.getBusinessId());
|
|
|
+ lqw.eq(bo.getCategoryId() != null, BusinessCategoryRelation::getCategoryId, bo.getCategoryId());
|
|
|
+ return lqw;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询商家分类关联
|
|
|
+ *
|
|
|
+ * @param relationId 商家分类关联主键
|
|
|
+ * @return 商家分类关联
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public BusinessCategoryRelationVo queryById(Long relationId){
|
|
|
+ return baseMapper.selectVoById(relationId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 详情商家分类关联
|
|
|
+ *
|
|
|
+ * @param relationId 商家分类关联主键
|
|
|
+ * @return 商家分类关联
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public BusinessCategoryRelation loadById(Long relationId, Boolean tw){
|
|
|
+ BusinessCategoryRelation info = this.baseMapper.selectById(relationId);
|
|
|
+ if(ObjectUtil.isEmpty(info) && tw){
|
|
|
+ throw new ServiceException(BusinessCategoryRelationExceptionEnum.BusinessCategoryRelation_IS_NOT_EXISTS);
|
|
|
+ }
|
|
|
+ return info;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增商家分类关联
|
|
|
+ *
|
|
|
+ * @param bos 商家分类关联
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public Boolean insertByBo(List<BusinessCategoryRelationBo> bos) {
|
|
|
+ //判断是不是同一个商家
|
|
|
+ Set<Long> businessIds = bos.stream()
|
|
|
+ .map(BusinessCategoryRelationBo::getBusinessId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ if (businessIds.size() > 1) {
|
|
|
+ throw new ServiceException("批量操作仅支持同一商家的分类关联");
|
|
|
+ }
|
|
|
+ Long businessId = businessIds.iterator().next();
|
|
|
+ //先删除
|
|
|
+ baseMapper.delete(new LambdaQueryWrapper<BusinessCategoryRelation>().eq(BusinessCategoryRelation::getBusinessId, businessId));
|
|
|
+ //在添加
|
|
|
+ return baseMapper.insertBatch(BeanCopyUtils.copyList(bos, BusinessCategoryRelation.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改商家分类关联
|
|
|
+ *
|
|
|
+ * @param bo 商家分类关联
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean updateByBo(BusinessCategoryRelationBo bo) {
|
|
|
+ BusinessCategoryRelation businessCategoryRelation = baseMapper.selectById(bo.getRelationId());
|
|
|
+ BusinessCategoryRelation update = BeanCopyUtils.copy(bo, businessCategoryRelation);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ return baseMapper.updateById(update) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ *
|
|
|
+ * @param entity 实体类数据
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(BusinessCategoryRelation entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量删除商家分类关联
|
|
|
+ *
|
|
|
+ * @param ids 需要删除的商家分类关联主键
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return baseMapper.deleteBatchIds(ids) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|