Merge branch 'develop' of http://139.196.179.195:3000/chenxudong/electromagnetic-data-new into develop
This commit is contained in:
commit
feb6fa89da
|
|
@ -17,22 +17,31 @@ public class EdMetaObjectHandler implements MetaObjectHandler {
|
||||||
if (metaObject.hasGetter("createdAt")) {
|
if (metaObject.hasGetter("createdAt")) {
|
||||||
this.strictInsertFill(metaObject, "createdAt", Date.class, new Date());
|
this.strictInsertFill(metaObject, "createdAt", Date.class, new Date());
|
||||||
}
|
}
|
||||||
if (metaObject.hasSetter("gmtModified")) {
|
if (metaObject.hasGetter("createdTime")) {
|
||||||
this.strictUpdateFill(metaObject, "gmtModified", Date.class, new Date());
|
this.strictInsertFill(metaObject, "createdTime", Date.class, new Date());
|
||||||
|
}
|
||||||
|
if (metaObject.hasGetter("gmtModified")) {
|
||||||
|
this.strictInsertFill(metaObject, "gmtModified", Date.class, new Date());
|
||||||
}
|
}
|
||||||
if (metaObject.hasGetter("updatedAt")) {
|
if (metaObject.hasGetter("updatedAt")) {
|
||||||
this.strictUpdateFill(metaObject, "updatedAt", Date.class, new Date());
|
this.strictInsertFill(metaObject, "updatedAt", Date.class, new Date());
|
||||||
|
}
|
||||||
|
if (metaObject.hasGetter("updatedTime")) {
|
||||||
|
this.strictInsertFill(metaObject, "updatedTime", Date.class, new Date());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateFill(MetaObject metaObject) {
|
public void updateFill(MetaObject metaObject) {
|
||||||
if (metaObject.hasSetter("gmtModified")) {
|
if (metaObject.hasGetter("gmtModified")) {
|
||||||
this.strictUpdateFill(metaObject, "gmtModified", Date.class, new Date());
|
this.strictUpdateFill(metaObject, "gmtModified", Date.class, new Date());
|
||||||
}
|
}
|
||||||
if (metaObject.hasGetter("updatedAt")) {
|
if (metaObject.hasGetter("updatedAt")) {
|
||||||
this.strictUpdateFill(metaObject, "updatedAt", Date.class, new Date());
|
this.strictUpdateFill(metaObject, "updatedAt", Date.class, new Date());
|
||||||
}
|
}
|
||||||
|
if (metaObject.hasGetter("updatedTime")) {
|
||||||
|
this.strictUpdateFill(metaObject, "updatedTime", Date.class, new Date());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.electromagnetic.industry.software.manage.controller;
|
package com.electromagnetic.industry.software.manage.controller;
|
||||||
|
|
||||||
|
import com.electromagnetic.industry.software.common.annotations.UserOperation;
|
||||||
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;
|
||||||
|
|
@ -17,6 +18,7 @@ public class EdTagLibraryController {
|
||||||
|
|
||||||
// 新建标签组
|
// 新建标签组
|
||||||
@PostMapping("/createGroup")
|
@PostMapping("/createGroup")
|
||||||
|
@UserOperation(value="创建了标签组")
|
||||||
public ElectromagneticResult<?> createTagGroup(@RequestParam String tagName) {
|
public ElectromagneticResult<?> createTagGroup(@RequestParam String tagName) {
|
||||||
String createdBy = UserThreadLocal.getUserId();
|
String createdBy = UserThreadLocal.getUserId();
|
||||||
return ElectromagneticResultUtil.success(edTagLibraryService.createTagGroup(tagName, createdBy));
|
return ElectromagneticResultUtil.success(edTagLibraryService.createTagGroup(tagName, createdBy));
|
||||||
|
|
@ -24,25 +26,30 @@ public class EdTagLibraryController {
|
||||||
|
|
||||||
// 在标签组下新建标签
|
// 在标签组下新建标签
|
||||||
@PostMapping("/createTag")
|
@PostMapping("/createTag")
|
||||||
|
@UserOperation(value="创建了标签")
|
||||||
public ElectromagneticResult<?> createTag(@RequestParam String parentId, @RequestParam String tagName) {
|
public ElectromagneticResult<?> createTag(@RequestParam String parentId, @RequestParam String tagName) {
|
||||||
String createdBy = UserThreadLocal.getUserId();
|
String createdBy = UserThreadLocal.getUserId();
|
||||||
return ElectromagneticResultUtil.success(edTagLibraryService.createTag(parentId, tagName, createdBy));
|
return ElectromagneticResultUtil.success(edTagLibraryService.createTag(parentId, tagName, createdBy));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拖拽修改排序
|
// 拖拽修改排序/分组
|
||||||
@PostMapping("/updateOrder")
|
@PostMapping("/updateOrder")
|
||||||
public ElectromagneticResult<?> updateTagOrder(@RequestParam String tagId, @RequestParam Integer orderBy) {
|
@UserOperation("修改了标签顺序")
|
||||||
return ElectromagneticResultUtil.success(edTagLibraryService.updateTagOrder(tagId, orderBy));
|
public ElectromagneticResult<?> updateTagOrder(@RequestParam String tagId, @RequestParam String newParentId, @RequestParam Integer newOrderBy) {
|
||||||
|
String updatedBy = UserThreadLocal.getUserId();
|
||||||
|
return ElectromagneticResultUtil.success(edTagLibraryService.updateTagOrder(tagId, newParentId, newOrderBy,updatedBy));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发布标签
|
// 发布标签
|
||||||
@PostMapping("/batchPublish")
|
@PostMapping("/batchPublish")
|
||||||
|
@UserOperation(value="发布了标签组")
|
||||||
public ElectromagneticResult<?> publishTag(@RequestParam List<String> tagIds) {
|
public ElectromagneticResult<?> publishTag(@RequestParam List<String> tagIds) {
|
||||||
return ElectromagneticResultUtil.success(edTagLibraryService.batchPublishTagGroups(tagIds));
|
return ElectromagneticResultUtil.success(edTagLibraryService.batchPublishTagGroups(tagIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 废除标签
|
// 废除标签
|
||||||
@GetMapping("/delete")
|
@GetMapping("/delete")
|
||||||
|
@UserOperation(value="废除了标签组/标签")
|
||||||
public ElectromagneticResult<?> deleteTag(@RequestParam String tagId) {
|
public ElectromagneticResult<?> deleteTag(@RequestParam String tagId) {
|
||||||
return ElectromagneticResultUtil.success(edTagLibraryService.deleteTagOrGroup(tagId));
|
return ElectromagneticResultUtil.success(edTagLibraryService.deleteTagOrGroup(tagId));
|
||||||
}
|
}
|
||||||
|
|
@ -52,5 +59,13 @@ public class EdTagLibraryController {
|
||||||
public ElectromagneticResult<?> listTags() {
|
public ElectromagneticResult<?> listTags() {
|
||||||
return ElectromagneticResultUtil.success(edTagLibraryService.listTagsWithGroups());
|
return ElectromagneticResultUtil.success(edTagLibraryService.listTagsWithGroups());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 修改标签组/标签
|
||||||
|
@PostMapping ("/updateTag")
|
||||||
|
@UserOperation("修改了标签名称")
|
||||||
|
public ElectromagneticResult<?> updateTag(@RequestParam String tagId, @RequestParam String tagName) {
|
||||||
|
String updatedBy = UserThreadLocal.getUserId();
|
||||||
|
return ElectromagneticResultUtil.success(edTagLibraryService.updateTagInfo(tagId, tagName, updatedBy));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package com.electromagnetic.industry.software.manage.pojo.models;
|
package com.electromagnetic.industry.software.manage.pojo.models;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
@ -8,7 +10,7 @@ import java.util.Date;
|
||||||
@Data
|
@Data
|
||||||
@TableName("ed_tag_library")
|
@TableName("ed_tag_library")
|
||||||
public class EdTagLibrary {
|
public class EdTagLibrary {
|
||||||
@TableId
|
|
||||||
private String tagId; // 主键 ID
|
private String tagId; // 主键 ID
|
||||||
private String parentId; // 父 ID,"" 代表是标签组
|
private String parentId; // 父 ID,"" 代表是标签组
|
||||||
private Integer type; // 0: 标签组, 1: 标签
|
private Integer type; // 0: 标签组, 1: 标签
|
||||||
|
|
@ -16,8 +18,13 @@ public class EdTagLibrary {
|
||||||
private Integer orderBy; // 排序字段
|
private Integer orderBy; // 排序字段
|
||||||
private Integer isPublished; // 是否已发布(0: 未发布, 1: 已发布)
|
private Integer isPublished; // 是否已发布(0: 未发布, 1: 已发布)
|
||||||
private String createdBy; // 创建人
|
private String createdBy; // 创建人
|
||||||
|
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
private Date createdTime; // 创建时间
|
private Date createdTime; // 创建时间
|
||||||
|
|
||||||
private String updatedBy; // 更新人
|
private String updatedBy; // 更新人
|
||||||
|
|
||||||
|
@TableField(fill = FieldFill.UPDATE)
|
||||||
private Date updatedTime; // 更新时间
|
private Date updatedTime; // 更新时间
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,9 @@ public interface EdTagLibraryService extends IService<EdTagLibrary> {
|
||||||
/**
|
/**
|
||||||
* 拖拽标签顺序
|
* 拖拽标签顺序
|
||||||
* @param tagId
|
* @param tagId
|
||||||
* @param orderBy
|
* @param newOrderBy
|
||||||
*/
|
*/
|
||||||
Boolean updateTagOrder(String tagId, Integer orderBy);
|
Boolean updateTagOrder(String tagId, String newParentId, Integer newOrderBy, String updatedBy);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发布标签
|
* 发布标签
|
||||||
|
|
@ -48,4 +48,12 @@ public interface EdTagLibraryService extends IService<EdTagLibrary> {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<TagListVO> listTagsWithGroups();
|
List<TagListVO> listTagsWithGroups();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新标签信息
|
||||||
|
* @param tagId
|
||||||
|
* @param tagName
|
||||||
|
* @return 更新结果
|
||||||
|
*/
|
||||||
|
Boolean updateTagInfo(String tagId, String tagName, String updatedBy);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.electromagnetic.industry.software.common.enums.PublishEnum;
|
import com.electromagnetic.industry.software.common.enums.PublishEnum;
|
||||||
import com.electromagnetic.industry.software.common.enums.TagTypeEnum;
|
import com.electromagnetic.industry.software.common.enums.TagTypeEnum;
|
||||||
|
|
@ -32,20 +33,19 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
||||||
|
|
||||||
// 查询当前最大排序值
|
// 查询当前最大排序值
|
||||||
Integer maxOrder = this.getBaseMapper()
|
Integer maxOrder = this.getBaseMapper()
|
||||||
.selectMaxOrder(TagTypeEnum.GROUP.getCode(), "");
|
.selectMaxOrder(TagTypeEnum.GROUP.getCode(), "0");
|
||||||
if (maxOrder == null) {
|
if (maxOrder == null) {
|
||||||
maxOrder = 0;
|
maxOrder = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
EdTagLibrary tagGroup = new EdTagLibrary();
|
EdTagLibrary tagGroup = new EdTagLibrary();
|
||||||
tagGroup.setTagId(IdWorker.getSnowFlakeIdString());
|
tagGroup.setTagId(IdWorker.getSnowFlakeIdString());
|
||||||
tagGroup.setParentId(""); // 标签组父节点为""
|
tagGroup.setParentId("0"); // 标签组父节点为"0"
|
||||||
tagGroup.setType(TagTypeEnum.GROUP.getCode());
|
tagGroup.setType(TagTypeEnum.GROUP.getCode());
|
||||||
tagGroup.setTagName(tagName);
|
tagGroup.setTagName(tagName);
|
||||||
tagGroup.setOrderBy(maxOrder+1); // 排在最后
|
tagGroup.setOrderBy(maxOrder+1); // 排在最后
|
||||||
tagGroup.setIsPublished(PublishEnum.UNPUBLISHED.getCode());
|
tagGroup.setIsPublished(PublishEnum.UNPUBLISHED.getCode());
|
||||||
tagGroup.setCreatedBy(createdBy);
|
tagGroup.setCreatedBy(createdBy);
|
||||||
tagGroup.setCreatedTime(new Date());
|
|
||||||
return this.save(tagGroup);
|
return this.save(tagGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,7 +60,7 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
||||||
|
|
||||||
// 查询当前组内最大排序值
|
// 查询当前组内最大排序值
|
||||||
Integer maxOrder = this.getBaseMapper()
|
Integer maxOrder = this.getBaseMapper()
|
||||||
.selectMaxOrder(TagTypeEnum.GROUP.getCode(), parentId);
|
.selectMaxOrder(TagTypeEnum.TAG.getCode(), parentId);
|
||||||
if (maxOrder == null) {
|
if (maxOrder == null) {
|
||||||
maxOrder = 0;
|
maxOrder = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -73,20 +73,54 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
||||||
tag.setOrderBy(maxOrder+1); // 默认排序
|
tag.setOrderBy(maxOrder+1); // 默认排序
|
||||||
tag.setIsPublished(PublishEnum.UNPUBLISHED.getCode()); // 默认未发布
|
tag.setIsPublished(PublishEnum.UNPUBLISHED.getCode()); // 默认未发布
|
||||||
tag.setCreatedBy(createdBy);
|
tag.setCreatedBy(createdBy);
|
||||||
tag.setCreatedTime(new Date());
|
|
||||||
return this.save(tag);
|
return this.save(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新标签顺序
|
* 更新标签顺序
|
||||||
* @param tagId
|
* @param tagId
|
||||||
* @param orderBy
|
* @param newOrderBy
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Boolean updateTagOrder(String tagId, Integer orderBy) {
|
@Transactional
|
||||||
|
public Boolean updateTagOrder(String tagId, String newParentId, Integer newOrderBy, String updatedBy) {
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(newParentId) || newOrderBy == null) {
|
||||||
|
throw new IllegalArgumentException("缺少参数");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询该标签
|
||||||
|
EdTagLibrary tag = this.getOne(new LambdaQueryWrapper<EdTagLibrary>()
|
||||||
|
.eq(EdTagLibrary::getTagId, tagId));
|
||||||
|
|
||||||
|
if (tag == null) {
|
||||||
|
throw new IllegalArgumentException("标签不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
String oldParentId = tag.getParentId();
|
||||||
|
Integer oldOrderBy = tag.getOrderBy();
|
||||||
|
// 是否更换了标签组
|
||||||
|
boolean isMoveToNewGroup = !oldParentId.equals(newParentId);
|
||||||
|
|
||||||
|
if (isMoveToNewGroup) {
|
||||||
|
// 旧组重新排序
|
||||||
|
int max = this.baseMapper.selectMaxOrder(tag.getType(),oldParentId)+1;
|
||||||
|
reorderTagGroup(oldParentId, oldOrderBy, max);
|
||||||
|
|
||||||
|
// 新组重新排序
|
||||||
|
max = this.baseMapper.selectMaxOrder(tag.getType(), newParentId)+1;
|
||||||
|
reorderTagGroup(newParentId, max, newOrderBy);
|
||||||
|
} else {
|
||||||
|
// 仅更新同组内的排序
|
||||||
|
reorderTagGroup(oldParentId, oldOrderBy, newOrderBy);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新当前标签的新排序值
|
||||||
return this.update(new LambdaUpdateWrapper<EdTagLibrary>()
|
return this.update(new LambdaUpdateWrapper<EdTagLibrary>()
|
||||||
.eq(EdTagLibrary::getTagId, tagId)
|
.eq(EdTagLibrary::getTagId, tagId)
|
||||||
.set(EdTagLibrary::getOrderBy, orderBy));
|
.set(EdTagLibrary::getParentId, newParentId)
|
||||||
|
.set(EdTagLibrary::getOrderBy, newOrderBy)
|
||||||
|
.set(EdTagLibrary::getUpdatedBy, updatedBy));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -104,7 +138,7 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
||||||
boolean groupUpdated = this.update(new LambdaUpdateWrapper<EdTagLibrary>()
|
boolean groupUpdated = this.update(new LambdaUpdateWrapper<EdTagLibrary>()
|
||||||
.in(EdTagLibrary::getTagId, tagGroupIds)
|
.in(EdTagLibrary::getTagId, tagGroupIds)
|
||||||
.eq(EdTagLibrary::getType, TagTypeEnum.GROUP.getCode()) // 只更新标签组
|
.eq(EdTagLibrary::getType, TagTypeEnum.GROUP.getCode()) // 只更新标签组
|
||||||
.set(EdTagLibrary::getIsPublished, PublishEnum.UNPUBLISHED.getCode()));
|
.set(EdTagLibrary::getIsPublished, PublishEnum.PUBLISHED.getCode()));
|
||||||
|
|
||||||
if (!groupUpdated) {
|
if (!groupUpdated) {
|
||||||
throw new BizException("发布标签组失败");
|
throw new BizException("发布标签组失败");
|
||||||
|
|
@ -176,5 +210,43 @@ public class EdTagLibraryServiceImpl extends ServiceImpl<EdTagLibraryMapper, EdT
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新标签信息
|
||||||
|
* @param tagId
|
||||||
|
* @param tagName
|
||||||
|
* @param updatedBy
|
||||||
|
* @return 更新结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Boolean updateTagInfo(String tagId, String tagName, String updatedBy) {
|
||||||
|
LambdaUpdateWrapper<EdTagLibrary> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
updateWrapper.eq(EdTagLibrary::getTagId, tagId)
|
||||||
|
.set(EdTagLibrary::getTagName, tagName)
|
||||||
|
.set(EdTagLibrary::getUpdatedBy, updatedBy);
|
||||||
|
return this.update(updateWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重排标签组
|
||||||
|
*/
|
||||||
|
private void reorderTagGroup(String parentId, Integer oldOrderBy, Integer newOrderBy) {
|
||||||
|
|
||||||
|
boolean isMoveDown = newOrderBy > oldOrderBy;
|
||||||
|
|
||||||
|
LambdaUpdateWrapper<EdTagLibrary> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
updateWrapper.eq(EdTagLibrary::getParentId, parentId);
|
||||||
|
|
||||||
|
if (isMoveDown) {
|
||||||
|
updateWrapper.setSql("order_by = order_by - 1")
|
||||||
|
.gt(EdTagLibrary::getOrderBy, oldOrderBy)
|
||||||
|
.le(EdTagLibrary::getOrderBy, newOrderBy);
|
||||||
|
} else {
|
||||||
|
updateWrapper.setSql("order_by = order_by + 1")
|
||||||
|
.ge(EdTagLibrary::getOrderBy, newOrderBy)
|
||||||
|
.lt(EdTagLibrary::getOrderBy, oldOrderBy);
|
||||||
|
}
|
||||||
|
this.update(updateWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue