|
|
@@ -0,0 +1,144 @@
|
|
|
+package org.dromara.business.service.impl;
|
|
|
+
|
|
|
+import org.dromara.business.domain.CategoryTag;
|
|
|
+import org.dromara.business.domain.bo.CategoryTagBo;
|
|
|
+import org.dromara.business.domain.vo.CategoryTagVo;
|
|
|
+import org.dromara.business.mapper.CategoryTagMapper;
|
|
|
+import org.dromara.business.service.ICategoryTagService;
|
|
|
+import org.dromara.common.core.exception.ServiceException;
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
+import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Collection;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 类目与标签合并Service业务层处理
|
|
|
+ *
|
|
|
+ * @author Lion Li
|
|
|
+ * @date 2025-12-12
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Service
|
|
|
+public class CategoryTagServiceImpl implements ICategoryTagService {
|
|
|
+
|
|
|
+ private final CategoryTagMapper baseMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询类目与标签合并
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @return 类目与标签合并
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public CategoryTagVo queryById(Long id){
|
|
|
+ return baseMapper.selectCategoryTagById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询类目与标签合并列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @param pageQuery 分页参数
|
|
|
+ * @return 类目与标签合并分页列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<CategoryTagVo> queryPageList(CategoryTagBo bo, PageQuery pageQuery) {
|
|
|
+ LambdaQueryWrapper<CategoryTag> lqw = buildQueryWrapper(bo);
|
|
|
+ Page<CategoryTagVo> result = baseMapper.selectCategoryTagPage(pageQuery.build(), lqw);
|
|
|
+ return TableDataInfo.build(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询符合条件的类目与标签合并列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @return 类目与标签合并列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<CategoryTagVo> queryList(CategoryTagBo bo) {
|
|
|
+ LambdaQueryWrapper<CategoryTag> lqw = buildQueryWrapper(bo);
|
|
|
+ return baseMapper.selectVoList(lqw);
|
|
|
+ }
|
|
|
+
|
|
|
+ private LambdaQueryWrapper<CategoryTag> buildQueryWrapper(CategoryTagBo bo) {
|
|
|
+ Map<String, Object> params = bo.getParams();
|
|
|
+ LambdaQueryWrapper<CategoryTag> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.orderByAsc(CategoryTag::getId);
|
|
|
+ lqw.like(StringUtils.isNotBlank(bo.getName()), CategoryTag::getName, bo.getName());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getType()), CategoryTag::getType, bo.getType());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getIconUrl()), CategoryTag::getIconUrl, bo.getIconUrl());
|
|
|
+ lqw.eq(bo.getSortWeight() != null, CategoryTag::getSortWeight, bo.getSortWeight());
|
|
|
+ lqw.eq(bo.getStatus() != null, CategoryTag::getStatus, bo.getStatus());
|
|
|
+ lqw.eq(bo.getDeletedAt() != null, CategoryTag::getDeletedAt, bo.getDeletedAt());
|
|
|
+ return lqw;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增类目与标签合并
|
|
|
+ *
|
|
|
+ * @param bo 类目与标签合并
|
|
|
+ * @return 是否新增成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean insertByBo(CategoryTagBo bo) {
|
|
|
+ CategoryTag add = MapstructUtils.convert(bo, CategoryTag.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ boolean flag = baseMapper.insertCategoryTag(add) > 0;
|
|
|
+ if (flag) {
|
|
|
+ bo.setId(add.getId());
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改类目与标签合并
|
|
|
+ *
|
|
|
+ * @param bo 类目与标签合并
|
|
|
+ * @return 是否修改成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean updateByBo(CategoryTagBo bo) {
|
|
|
+ CategoryTag update = MapstructUtils.convert(bo, CategoryTag.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ return baseMapper.updateCategoryTagById(update) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(CategoryTag entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+
|
|
|
+ CategoryTagVo categoryTagVo = baseMapper.selectCategoryTagExit(entity.getId(), entity.getName(), entity.getType());
|
|
|
+ if (categoryTagVo != null && !categoryTagVo.getId().equals(entity.getId())) {
|
|
|
+ throw new ServiceException("该名称重复");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验并批量删除类目与标签合并信息
|
|
|
+ *
|
|
|
+ * @param ids 待删除的主键集合
|
|
|
+ * @param isValid 是否进行有效性校验
|
|
|
+ * @return 是否删除成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return baseMapper.deleteCategoryTagById(ids) > 0;
|
|
|
+ }
|
|
|
+}
|