Merge branch 'develop' of http://139.196.179.195:3000/chenxudong/electromagnetic-data-new into develop
This commit is contained in:
commit
50e8af4a39
|
|
@ -1,6 +1,5 @@
|
||||||
package com.electromagnetic.industry.software.manage.controller;
|
package com.electromagnetic.industry.software.manage.controller;
|
||||||
|
|
||||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
|
||||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||||
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
||||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||||
|
|
@ -22,7 +21,7 @@ public class EdFileFavoriteController {
|
||||||
* @param id 文件id
|
* @param id 文件id
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@PostMapping("/add")
|
@GetMapping("/add")
|
||||||
public ElectromagneticResult<?> addFavorite(@RequestParam String id) {
|
public ElectromagneticResult<?> addFavorite(@RequestParam String id) {
|
||||||
String userId = UserThreadLocal.getUserId();
|
String userId = UserThreadLocal.getUserId();
|
||||||
return ElectromagneticResultUtil.success(edFileFavoriteService.addFavorite(userId, id));
|
return ElectromagneticResultUtil.success(edFileFavoriteService.addFavorite(userId, id));
|
||||||
|
|
@ -33,7 +32,7 @@ public class EdFileFavoriteController {
|
||||||
* @param id 文件id
|
* @param id 文件id
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@PostMapping("/remove")
|
@GetMapping("/remove")
|
||||||
public ElectromagneticResult<?> removeFavorite(@RequestParam String id) {
|
public ElectromagneticResult<?> removeFavorite(@RequestParam String id) {
|
||||||
String userId = UserThreadLocal.getUserId();
|
String userId = UserThreadLocal.getUserId();
|
||||||
return ElectromagneticResultUtil.success(edFileFavoriteService.removeFavorite(userId, id));
|
return ElectromagneticResultUtil.success(edFileFavoriteService.removeFavorite(userId, id));
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,56 @@
|
||||||
|
package com.electromagnetic.industry.software.manage.controller;
|
||||||
|
|
||||||
|
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||||
|
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
||||||
|
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||||
|
import com.electromagnetic.industry.software.manage.service.EdTagLibraryService;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/data/ed/tag")
|
||||||
|
public class EdTagLibraryController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private EdTagLibraryService edTagLibraryService;
|
||||||
|
|
||||||
|
// 新建标签组
|
||||||
|
@PostMapping("/createGroup")
|
||||||
|
public ElectromagneticResult<?> createTagGroup(@RequestParam String tagName) {
|
||||||
|
String createdBy = UserThreadLocal.getUserId();
|
||||||
|
return ElectromagneticResultUtil.success(edTagLibraryService.createTagGroup(tagName, createdBy));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 在标签组下新建标签
|
||||||
|
@PostMapping("/createTag")
|
||||||
|
public ElectromagneticResult<?> createTag(@RequestParam String parentId, @RequestParam String tagName) {
|
||||||
|
String createdBy = UserThreadLocal.getUserId();
|
||||||
|
return ElectromagneticResultUtil.success(edTagLibraryService.createTag(parentId, tagName, createdBy));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 拖拽修改排序
|
||||||
|
@PostMapping("/updateOrder")
|
||||||
|
public ElectromagneticResult<?> updateTagOrder(@RequestParam String tagId, @RequestParam Integer orderBy) {
|
||||||
|
return ElectromagneticResultUtil.success(edTagLibraryService.updateTagOrder(tagId, orderBy));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发布标签
|
||||||
|
@PostMapping("/batchPublish")
|
||||||
|
public ElectromagneticResult<?> publishTag(@RequestParam List<String> tagIds) {
|
||||||
|
return ElectromagneticResultUtil.success(edTagLibraryService.batchPublishTagGroups(tagIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 废除标签
|
||||||
|
@GetMapping("/delete")
|
||||||
|
public ElectromagneticResult<?> deleteTag(@RequestParam String tagId) {
|
||||||
|
return ElectromagneticResultUtil.success(edTagLibraryService.deleteTagOrGroup(tagId));
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取标签数据
|
||||||
|
@GetMapping("/list")
|
||||||
|
public ElectromagneticResult<?> listTags() {
|
||||||
|
return ElectromagneticResultUtil.success(edTagLibraryService.listTagsWithGroups());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.electromagnetic.industry.software.manage.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.electromagnetic.industry.software.common.enums.TagTypeEnum;
|
||||||
|
import com.electromagnetic.industry.software.manage.pojo.models.EdTagLibrary;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface EdTagLibraryMapper extends BaseMapper<EdTagLibrary> {
|
||||||
|
|
||||||
|
@Select("SELECT MAX(order_by) FROM ed_tag_library WHERE type = #{type} and parent_id = #{parentId}")
|
||||||
|
Integer selectMaxOrder(@Param("type") int type, @Param("parentId") String parentId);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.electromagnetic.industry.software.manage.pojo.models;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("ed_tag_library")
|
||||||
|
public class EdTagLibrary {
|
||||||
|
@TableId
|
||||||
|
private String tagId; // 主键 ID
|
||||||
|
private String parentId; // 父 ID,"" 代表是标签组
|
||||||
|
private Integer type; // 0: 标签组, 1: 标签
|
||||||
|
private String tagName; // 标签库或标签名称
|
||||||
|
private Integer orderBy; // 排序字段
|
||||||
|
private Integer isPublished; // 是否已发布(0: 未发布, 1: 已发布)
|
||||||
|
private String createdBy; // 创建人
|
||||||
|
private Date createdTime; // 创建时间
|
||||||
|
private String updatedBy; // 更新人
|
||||||
|
private Date updatedTime; // 更新时间
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.electromagnetic.industry.software.manage.pojo.resp;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.electromagnetic.industry.software.manage.pojo.models.EdTagLibrary;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class TagListVO {
|
||||||
|
|
||||||
|
private String tagId; // 主键 ID
|
||||||
|
private String parentId; // 父 ID,"" 代表是标签组
|
||||||
|
private Integer type; // 0: 标签组, 1: 标签
|
||||||
|
private String tagName; // 标签库或标签名称
|
||||||
|
private Integer orderBy; // 排序字段
|
||||||
|
private Integer isPublished; // 是否已发布(0: 未发布, 1: 已发布)
|
||||||
|
|
||||||
|
private List<EdTagLibrary> childList;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
package com.electromagnetic.industry.software.manage.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.electromagnetic.industry.software.manage.pojo.models.EdTagLibrary;
|
||||||
|
import com.electromagnetic.industry.software.manage.pojo.resp.TagListVO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface EdTagLibraryService extends IService<EdTagLibrary> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新建分组
|
||||||
|
* @param tagName
|
||||||
|
* @param createdBy
|
||||||
|
*/
|
||||||
|
Boolean createTagGroup(String tagName, String createdBy);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新建标签
|
||||||
|
* @param parentId
|
||||||
|
* @param tagName
|
||||||
|
* @param createdBy
|
||||||
|
*/
|
||||||
|
Boolean createTag(String parentId, String tagName, String createdBy);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拖拽标签顺序
|
||||||
|
* @param tagId
|
||||||
|
* @param orderBy
|
||||||
|
*/
|
||||||
|
Boolean updateTagOrder(String tagId, Integer orderBy);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发布标签
|
||||||
|
* @param tagGroupIds
|
||||||
|
*/
|
||||||
|
Boolean batchPublishTagGroups(List<String> tagGroupIds);
|
||||||
|
|
||||||
|
/** 废除标签
|
||||||
|
* @param tagId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Boolean deleteTagOrGroup(String tagId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签数据
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<TagListVO> listTagsWithGroups();
|
||||||
|
}
|
||||||
|
|
@ -18,6 +18,7 @@ import com.electromagnetic.industry.software.manage.service.EdFileInfoService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.thymeleaf.util.ListUtils;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -73,8 +74,15 @@ public class EdFileFavoriteServiceImpl extends ServiceImpl<EdFileFavoriteMapper,
|
||||||
|
|
||||||
LambdaQueryWrapper<EdFileInfo> queryWrapper2 = Wrappers.lambdaQuery(EdFileInfo.class)
|
LambdaQueryWrapper<EdFileInfo> queryWrapper2 = Wrappers.lambdaQuery(EdFileInfo.class)
|
||||||
.eq(EdFileInfo::getSaveStatus, EleDataSaveStatusEnum.SUCCESS.code)
|
.eq(EdFileInfo::getSaveStatus, EleDataSaveStatusEnum.SUCCESS.code)
|
||||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code);
|
||||||
.in(EdFileInfo::getFileId, fileIds);
|
|
||||||
|
// 只有 fileIds 不为空时才添加 in 条件,否则添加一个 false 条件
|
||||||
|
if (fileIds != null && !fileIds.isEmpty()) {
|
||||||
|
queryWrapper2.in(EdFileInfo::getFileId, fileIds);
|
||||||
|
} else {
|
||||||
|
queryWrapper2.apply("1 = 0"); // 保证 fileIds 为空时查询结果为空
|
||||||
|
}
|
||||||
|
|
||||||
return fileInfoServiceImpl.page(page, queryWrapper2);
|
return fileInfoServiceImpl.page(page, queryWrapper2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,180 @@
|
||||||
|
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.electromagnetic.industry.software.common.enums.PublishEnum;
|
||||||
|
import com.electromagnetic.industry.software.common.enums.TagTypeEnum;
|
||||||
|
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||||
|
import com.electromagnetic.industry.software.common.util.IdWorker;
|
||||||
|
import com.electromagnetic.industry.software.manage.mapper.EdTagLibraryMapper;
|
||||||
|
import com.electromagnetic.industry.software.manage.pojo.models.EdTagLibrary;
|
||||||
|
import com.electromagnetic.industry.software.manage.pojo.resp.TagListVO;
|
||||||
|
import com.electromagnetic.industry.software.manage.service.EdTagLibraryService;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdTagLibrary> implements EdTagLibraryService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新建标签组
|
||||||
|
* @param tagName
|
||||||
|
* @param createdBy
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean createTagGroup(String tagName, String createdBy) {
|
||||||
|
|
||||||
|
// 查询当前最大排序值
|
||||||
|
Integer maxOrder = this.getBaseMapper()
|
||||||
|
.selectMaxOrder(TagTypeEnum.GROUP.getCode(), "");
|
||||||
|
if (maxOrder == null) {
|
||||||
|
maxOrder = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
EdTagLibrary tagGroup = new EdTagLibrary();
|
||||||
|
tagGroup.setTagId(IdWorker.getSnowFlakeIdString());
|
||||||
|
tagGroup.setParentId(""); // 标签组父节点为""
|
||||||
|
tagGroup.setType(TagTypeEnum.GROUP.getCode());
|
||||||
|
tagGroup.setTagName(tagName);
|
||||||
|
tagGroup.setOrderBy(maxOrder+1); // 排在最后
|
||||||
|
tagGroup.setIsPublished(PublishEnum.UNPUBLISHED.getCode());
|
||||||
|
tagGroup.setCreatedBy(createdBy);
|
||||||
|
tagGroup.setCreatedTime(new Date());
|
||||||
|
return this.save(tagGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新建标签
|
||||||
|
* @param parentId
|
||||||
|
* @param tagName
|
||||||
|
* @param createdBy
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean createTag(String parentId, String tagName, String createdBy) {
|
||||||
|
|
||||||
|
// 查询当前组内最大排序值
|
||||||
|
Integer maxOrder = this.getBaseMapper()
|
||||||
|
.selectMaxOrder(TagTypeEnum.GROUP.getCode(), parentId);
|
||||||
|
if (maxOrder == null) {
|
||||||
|
maxOrder = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
EdTagLibrary tag = new EdTagLibrary();
|
||||||
|
tag.setTagId(IdWorker.getSnowFlakeIdString());
|
||||||
|
tag.setParentId(parentId);
|
||||||
|
tag.setType(TagTypeEnum.TAG.getCode()); // 标签
|
||||||
|
tag.setTagName(tagName);
|
||||||
|
tag.setOrderBy(maxOrder+1); // 默认排序
|
||||||
|
tag.setIsPublished(PublishEnum.UNPUBLISHED.getCode()); // 默认未发布
|
||||||
|
tag.setCreatedBy(createdBy);
|
||||||
|
tag.setCreatedTime(new Date());
|
||||||
|
return this.save(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新标签顺序
|
||||||
|
* @param tagId
|
||||||
|
* @param orderBy
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean updateTagOrder(String tagId, Integer orderBy) {
|
||||||
|
return this.update(new LambdaUpdateWrapper<EdTagLibrary>()
|
||||||
|
.eq(EdTagLibrary::getTagId, tagId)
|
||||||
|
.set(EdTagLibrary::getOrderBy, orderBy));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发布标签批量
|
||||||
|
* @param tagGroupIds
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public Boolean batchPublishTagGroups(List<String> tagGroupIds) {
|
||||||
|
|
||||||
|
if (tagGroupIds == null || tagGroupIds.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("参数 tagGroupIds 不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean groupUpdated = this.update(new LambdaUpdateWrapper<EdTagLibrary>()
|
||||||
|
.in(EdTagLibrary::getTagId, tagGroupIds)
|
||||||
|
.eq(EdTagLibrary::getType, TagTypeEnum.GROUP.getCode()) // 只更新标签组
|
||||||
|
.set(EdTagLibrary::getIsPublished, PublishEnum.UNPUBLISHED.getCode()));
|
||||||
|
|
||||||
|
if (!groupUpdated) {
|
||||||
|
throw new BizException("发布标签组失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean tagUpdated = this.update(new LambdaUpdateWrapper<EdTagLibrary>()
|
||||||
|
.in(EdTagLibrary::getParentId, tagGroupIds) // 父 ID 是传入的标签组
|
||||||
|
.eq(EdTagLibrary::getType, TagTypeEnum.TAG.getCode()) // 只更新标签
|
||||||
|
.set(EdTagLibrary::getIsPublished, PublishEnum.PUBLISHED.getCode()));
|
||||||
|
|
||||||
|
if (!tagUpdated) {
|
||||||
|
throw new RuntimeException("发布标签失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 废除标签
|
||||||
|
* @param tagId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public Boolean deleteTagOrGroup(String tagId) {
|
||||||
|
EdTagLibrary tag = this.getById(tagId);
|
||||||
|
|
||||||
|
if (tag == null) {
|
||||||
|
throw new BizException("此标签已被删除");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果是标签组,级联删除其下的所有标签
|
||||||
|
if (tag.getType() == 0) {
|
||||||
|
this.remove(new LambdaQueryWrapper<EdTagLibrary>().eq(EdTagLibrary::getParentId, tagId));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除本身
|
||||||
|
return this.removeById(tagId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签数据
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<TagListVO> listTagsWithGroups() {
|
||||||
|
|
||||||
|
// 查询所有标签组
|
||||||
|
List<EdTagLibrary> groups = this.list(new LambdaQueryWrapper<EdTagLibrary>()
|
||||||
|
.eq(EdTagLibrary::getType, TagTypeEnum.GROUP.getCode())
|
||||||
|
.orderByAsc(EdTagLibrary::getOrderBy));
|
||||||
|
|
||||||
|
// 查询所有标签
|
||||||
|
List<EdTagLibrary> tags = this.list(new LambdaQueryWrapper<EdTagLibrary>()
|
||||||
|
.eq(EdTagLibrary::getType, TagTypeEnum.TAG.getCode())
|
||||||
|
.orderByAsc(EdTagLibrary::getOrderBy));
|
||||||
|
|
||||||
|
// 构造分组数据
|
||||||
|
Map<String, List<EdTagLibrary>> tagsGrouped = tags.stream()
|
||||||
|
.collect(Collectors.groupingBy(EdTagLibrary::getParentId));
|
||||||
|
|
||||||
|
List<TagListVO> result = new ArrayList<>();
|
||||||
|
for (EdTagLibrary group : groups) {
|
||||||
|
TagListVO vo = new TagListVO();
|
||||||
|
BeanUtils.copyProperties(group, vo);
|
||||||
|
vo.setChildList(tagsGrouped.getOrDefault(group.getTagId(), new ArrayList<>()));
|
||||||
|
result.add(vo);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.electromagnetic.industry.software.common.enums;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public enum TagTypeEnum {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签组
|
||||||
|
*/
|
||||||
|
GROUP (0),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签
|
||||||
|
*/
|
||||||
|
TAG (1);
|
||||||
|
|
||||||
|
private final Integer code;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue