|
|
@@ -0,0 +1,136 @@
|
|
|
+package cn.com.yusys.yusp.service.impl;
|
|
|
+
|
|
|
+import cn.com.yusys.yusp.domain.dto.AitagTagCategoryCreateDTO;
|
|
|
+import cn.com.yusys.yusp.domain.dto.AitagTagCategoryUpdateDTO;
|
|
|
+import cn.com.yusys.yusp.domain.entity.AitagTagCategory;
|
|
|
+import cn.com.yusys.yusp.domain.vo.AitagTagCategoryVO;
|
|
|
+import cn.com.yusys.yusp.mapper.AitagTagCategoryMapper;
|
|
|
+import cn.com.yusys.yusp.service.AitagTagCategoryService;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class AitagTagCategoryServiceImpl implements AitagTagCategoryService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AitagTagCategoryMapper aiTagCategoryMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<AitagTagCategoryVO> listCategories(int page, int size) {
|
|
|
+ int offset = (page - 1) * size;
|
|
|
+ List<AitagTagCategory> records = aiTagCategoryMapper.selectPageCategories(offset, size);
|
|
|
+ long total = aiTagCategoryMapper.selectCountAll();
|
|
|
+
|
|
|
+ // 转换为 VO 并动态计算 tagNum
|
|
|
+ List<AitagTagCategoryVO> voList = records.stream().map(category -> {
|
|
|
+ AitagTagCategoryVO vo = new AitagTagCategoryVO();
|
|
|
+ vo.setId(category.getId());
|
|
|
+ vo.setCategoryCode(category.getCategoryCode());
|
|
|
+ vo.setCategoryNm(category.getCategoryNm());
|
|
|
+ vo.setCategoryDesc(category.getCategoryDesc());
|
|
|
+ vo.setVisibilityLevel(category.getVisibilityLevel());
|
|
|
+ vo.setState(category.getState());
|
|
|
+ vo.setIsDelete(category.getIsDelete());
|
|
|
+
|
|
|
+ // 动态计算 tagNum
|
|
|
+ int tagNum = aiTagCategoryMapper.countTagsByCategoryId(category.getId());
|
|
|
+ vo.setTagNum(tagNum);
|
|
|
+
|
|
|
+ return vo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ Page<AitagTagCategoryVO> pageObj = new Page<>(page, size, total);
|
|
|
+ pageObj.setRecords(voList);
|
|
|
+ return pageObj;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AitagTagCategory createCategory(AitagTagCategoryCreateDTO dto) {
|
|
|
+ // 校验唯一性
|
|
|
+ if (aiTagCategoryMapper.selectCountByNameAndNotDeleted(dto.getCategoryNm()) > 0) {
|
|
|
+ throw new RuntimeException("标签体系名称已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ AitagTagCategory category = new AitagTagCategory();
|
|
|
+ category.setId(UUID.randomUUID().toString());
|
|
|
+ category.setCategoryNm(dto.getCategoryNm());
|
|
|
+ category.setCategoryDesc(dto.getCategoryDesc());
|
|
|
+ category.setState(0); // 默认启用
|
|
|
+ category.setIsDelete(0); // 未删除
|
|
|
+
|
|
|
+ aiTagCategoryMapper.insertCategory(category);
|
|
|
+ return category;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AitagTagCategory updateCategory(AitagTagCategoryUpdateDTO dto) {
|
|
|
+ AitagTagCategory existing = aiTagCategoryMapper.selectById(dto.getId());
|
|
|
+ if (existing == null) {
|
|
|
+ throw new RuntimeException("标签体系不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验唯一性(排除自己)
|
|
|
+ if (!existing.getCategoryNm().equals(dto.getCategoryNm())) {
|
|
|
+ if (aiTagCategoryMapper.selectCountByNameAndNotDeleted(dto.getCategoryNm()) > 0) {
|
|
|
+ throw new RuntimeException("标签体系名称已存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ existing.setCategoryNm(dto.getCategoryNm());
|
|
|
+ existing.setCategoryDesc(dto.getCategoryDesc());
|
|
|
+
|
|
|
+ aiTagCategoryMapper.updateCategory(existing);
|
|
|
+ return existing;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<AitagTagCategory> searchByCategoryNm(String categoryNm) {
|
|
|
+ return aiTagCategoryMapper.selectByCategoryNmLike(categoryNm);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void enableCategory(String id) {
|
|
|
+ AitagTagCategory category = aiTagCategoryMapper.selectById(id);
|
|
|
+ if (category == null) {
|
|
|
+ throw new RuntimeException("标签体系不存在");
|
|
|
+ }
|
|
|
+ if (category.getState() == 0) {
|
|
|
+ throw new RuntimeException("标签体系已经是启用状态");
|
|
|
+ }
|
|
|
+ aiTagCategoryMapper.updateState(id, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void disableCategory(String id) {
|
|
|
+ AitagTagCategory category = aiTagCategoryMapper.selectById(id);
|
|
|
+ if (category == null) {
|
|
|
+ throw new RuntimeException("标签体系不存在");
|
|
|
+ }
|
|
|
+ if (category.getState() == 1) {
|
|
|
+ throw new RuntimeException("标签体系已经是停用状态");
|
|
|
+ }
|
|
|
+ aiTagCategoryMapper.updateState(id, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteCategory(String id) {
|
|
|
+ AitagTagCategory category = aiTagCategoryMapper.selectById(id);
|
|
|
+ if (category == null) {
|
|
|
+ throw new RuntimeException("标签体系不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 判断标签数量是否为0
|
|
|
+ int tagCount = aiTagCategoryMapper.countTagsByCategoryId(id);
|
|
|
+ if (tagCount > 0) {
|
|
|
+ throw new RuntimeException("该标签体系下仍有标签,无法删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ aiTagCategoryMapper.deleteCategory(id);
|
|
|
+ }
|
|
|
+}
|