From 3b30019d9177781f46bb6424df6b08fcec124d15 Mon Sep 17 00:00:00 2001 From: xiachao Date: Mon, 26 Aug 2024 14:41:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E7=9A=84=E7=B4=A0=E6=9D=90=E9=83=A8?= =?UTF-8?q?=E4=BB=B6=E7=BB=84=E7=AE=A1=E7=90=86=EF=BC=8C=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/IotVisualGroupController.java | 35 ++++- .../thing/visual/group/dto/GroupSortInfo.java | 4 +- .../visual/group/dto/IotVisualGroupDTO.java | 17 ++- .../com/thing/visual/group/dto/NameSort.java | 6 +- .../group/entity/IotVisualGroupEntity.java | 4 +- .../group/service/IotVisualGroupService.java | 9 +- .../impl/IotVisualGroupServiceImpl.java | 127 +++++++++++++++--- 7 files changed, 172 insertions(+), 30 deletions(-) diff --git a/modules/visual-design/src/main/java/com/thing/visual/group/controller/IotVisualGroupController.java b/modules/visual-design/src/main/java/com/thing/visual/group/controller/IotVisualGroupController.java index d09d801..a9ffbe5 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/group/controller/IotVisualGroupController.java +++ b/modules/visual-design/src/main/java/com/thing/visual/group/controller/IotVisualGroupController.java @@ -7,6 +7,7 @@ import com.thing.common.core.web.response.Result; import com.thing.visual.group.dto.AdjustGroupDto; import com.thing.visual.group.dto.GroupSortInfo; import com.thing.visual.group.dto.IotVisualGroupDTO; +import com.thing.visual.group.dto.NameSort; import com.thing.visual.group.service.IotVisualGroupService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -15,6 +16,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; +import java.util.List; import java.util.Map; /** @@ -37,13 +39,18 @@ public class IotVisualGroupController { @Parameter(name = Constant.PAGE, description = "当前页码,从1开始", required = true) , @Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true) , @Parameter(name = Constant.ORDER_FIELD, description = "排序字段") , - @Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)") + @Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)"), + @Parameter(name = "name", description = "组名称"), + @Parameter(name = "businessName", description = "组类型名称"), + @Parameter(name = "names", description = "组名称集合,多个组名称,以英文逗号分割") }) public Result> page(@Parameter(hidden = true) @RequestParam Map params){ PageData page = iotVisualGroupService.getPageData(params, IotVisualGroupDTO.class); return new Result>().ok(page); } + + @GetMapping("{id}") @Operation(summary="信息") public Result get(@PathVariable("id") Long id){ @@ -59,12 +66,20 @@ public class IotVisualGroupController { } @PutMapping - @Operation(summary="修改") + @Operation(summary="修改,这个接口,只能修改二级得组类型") public Result update(@RequestBody IotVisualGroupDTO dto){ iotVisualGroupService.updateIotVisualGroupDTO(dto); return new Result<>(); } + + @PutMapping("group") + @Operation(summary="修改,这个接口,只能修改一级得组") + public Result updateGroup(@RequestBody IotVisualGroupDTO dto){ + iotVisualGroupService.updateGroup(dto); + return new Result<>(); + } + @DeleteMapping @Operation(summary="删除") public Result delete(@RequestBody Long[] ids){ @@ -75,15 +90,23 @@ public class IotVisualGroupController { } + @GetMapping("groupInfo") + @Operation(summary="左侧组列表,可按名称模糊查询") + public Result> groupInfo(@RequestParam(required = false) String name, @RequestParam(required = true) String type){ + List data = iotVisualGroupService.groupInfo(name,type); + return new Result>().ok(data); + } + + @GetMapping("groupSortInfo") - @Operation(summary="获取排序信息,可以传入已存在的组名称") - public Result groupSortInfo(@RequestParam(required = false) String name){ - GroupSortInfo data = iotVisualGroupService.groupSortInfo(name); + @Operation(summary="获取排序信息,可以传入已存在的组名称,新增得时候使用") + public Result groupSortInfo(@RequestParam(required = false) String name,@RequestParam(required = true) String type){ + GroupSortInfo data = iotVisualGroupService.groupSortInfo(name,type); return new Result().ok(data); } @PostMapping("adjustGroupSort") - @Operation(summary="调整组排序") + @Operation(summary="调整组排序,拖动排序,如果传入name,就是组内排序") public Result adjustGroupSort(@RequestBody AdjustGroupDto dto){ String data = iotVisualGroupService.adjustGroupSort(dto); return new Result().ok(data); diff --git a/modules/visual-design/src/main/java/com/thing/visual/group/dto/GroupSortInfo.java b/modules/visual-design/src/main/java/com/thing/visual/group/dto/GroupSortInfo.java index aa3c9cd..b8a5e15 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/group/dto/GroupSortInfo.java +++ b/modules/visual-design/src/main/java/com/thing/visual/group/dto/GroupSortInfo.java @@ -7,8 +7,8 @@ import lombok.Data; @Schema(description = "组排序信息") public class GroupSortInfo { - private Long sort; + private Integer sort; - private Long bsSort; + private Integer bsSort; } diff --git a/modules/visual-design/src/main/java/com/thing/visual/group/dto/IotVisualGroupDTO.java b/modules/visual-design/src/main/java/com/thing/visual/group/dto/IotVisualGroupDTO.java index 4a0d7c9..4996174 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/group/dto/IotVisualGroupDTO.java +++ b/modules/visual-design/src/main/java/com/thing/visual/group/dto/IotVisualGroupDTO.java @@ -32,9 +32,9 @@ public class IotVisualGroupDTO implements Serializable { @Schema(description = "缩略图url/这里放text,也可以是svg或base64") private String thumbnailUrl; @Schema(description = "组排序") - private Long sort; + private Integer sort; @Schema(description = "二级业务排序") - private Long bsSort; + private Integer bsSort; @Schema(description = "备注说明") private String remark; @Schema(description = "所属企业(租户code)") @@ -52,4 +52,17 @@ public class IotVisualGroupDTO implements Serializable { @Schema(description = "更新时间") private Long updateDate; + @Schema(description = "素材/部件组修改之前得名称") + private String oldName; + + @Schema(description = "素材/部件组修改之前得排序") + private Integer oldSort; + + + @Schema(description = "素材/部件组修改之前得业务二级名称") + private String oldBusinessName; + + + @Schema(description = "修改之前得二级业务排序") + private Integer oldBsSort; } \ No newline at end of file diff --git a/modules/visual-design/src/main/java/com/thing/visual/group/dto/NameSort.java b/modules/visual-design/src/main/java/com/thing/visual/group/dto/NameSort.java index 9172a90..c834cb8 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/group/dto/NameSort.java +++ b/modules/visual-design/src/main/java/com/thing/visual/group/dto/NameSort.java @@ -1,13 +1,17 @@ package com.thing.visual.group.dto; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; @Data +@AllArgsConstructor +@NoArgsConstructor public class NameSort { private String name; - private Long sort; + private Integer sort; } diff --git a/modules/visual-design/src/main/java/com/thing/visual/group/entity/IotVisualGroupEntity.java b/modules/visual-design/src/main/java/com/thing/visual/group/entity/IotVisualGroupEntity.java index 7f1d211..a742150 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/group/entity/IotVisualGroupEntity.java +++ b/modules/visual-design/src/main/java/com/thing/visual/group/entity/IotVisualGroupEntity.java @@ -47,11 +47,11 @@ public class IotVisualGroupEntity extends BaseInfoEntity implements Serializable /** * 组排序 */ - private Long sort; + private Integer sort; /** * 二级业务排序 */ - private Long bsSort; + private Integer bsSort; /** * 备注说明 */ diff --git a/modules/visual-design/src/main/java/com/thing/visual/group/service/IotVisualGroupService.java b/modules/visual-design/src/main/java/com/thing/visual/group/service/IotVisualGroupService.java index 6c4e003..2a23545 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/group/service/IotVisualGroupService.java +++ b/modules/visual-design/src/main/java/com/thing/visual/group/service/IotVisualGroupService.java @@ -4,8 +4,11 @@ import com.thing.common.orm.service.IBaseService; import com.thing.visual.group.dto.AdjustGroupDto; import com.thing.visual.group.dto.GroupSortInfo; import com.thing.visual.group.dto.IotVisualGroupDTO; +import com.thing.visual.group.dto.NameSort; import com.thing.visual.group.entity.IotVisualGroupEntity; +import java.util.List; + /** * 素材部件组管理 * @@ -18,7 +21,11 @@ public interface IotVisualGroupService extends IBaseService groupInfo(String name, String type); } \ No newline at end of file diff --git a/modules/visual-design/src/main/java/com/thing/visual/group/service/impl/IotVisualGroupServiceImpl.java b/modules/visual-design/src/main/java/com/thing/visual/group/service/impl/IotVisualGroupServiceImpl.java index 85e64e6..2bd5ce1 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/group/service/impl/IotVisualGroupServiceImpl.java +++ b/modules/visual-design/src/main/java/com/thing/visual/group/service/impl/IotVisualGroupServiceImpl.java @@ -4,6 +4,7 @@ import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.update.UpdateChain; import com.mybatisflex.core.update.UpdateWrapper; import com.thing.common.orm.service.impl.BaseServiceImpl; +import com.thing.sys.security.context.UserContext; import com.thing.visual.group.dto.AdjustGroupDto; import com.thing.visual.group.dto.GroupSortInfo; import com.thing.visual.group.dto.IotVisualGroupDTO; @@ -11,9 +12,12 @@ import com.thing.visual.group.dto.NameSort; import com.thing.visual.group.mapper.IotVisualGroupMapper; import com.thing.visual.group.entity.IotVisualGroupEntity; import com.thing.visual.group.service.IotVisualGroupService; +import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -32,50 +36,100 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl params){ + Long tenantCode = UserContext.getTenantCode(); QueryWrapper wrapper = new QueryWrapper(); + String name = MapUtils.getString(params,"name"); + String names = MapUtils.getString(params,"names"); + List nameList = Arrays.asList(names.split(",")); + String businessName = MapUtils.getString(params,"businessName"); + wrapper.and(IOT_VISUAL_GROUP_ENTITY.TENANT_CODE.eq(tenantCode).or(IOT_VISUAL_GROUP_ENTITY.IS_DEFAULT.eq("1"))); + wrapper.like(IotVisualGroupEntity::getName,name, StringUtils.isNotEmpty(name)); + wrapper.like(IotVisualGroupEntity::getBusinessName,businessName, StringUtils.isNotEmpty(businessName)); + wrapper.in(IotVisualGroupEntity::getName,nameList,ObjectUtils.isNotEmpty(nameList)); + wrapper.orderBy(IotVisualGroupEntity::getSort,true); + wrapper.orderBy(IotVisualGroupEntity::getBsSort,true); return wrapper; } @Override public void saveIotVisualGroupDTO(IotVisualGroupDTO dto) { + List sortInfo = this.getNameSort(dto.getName(),dto.getType()); + GroupSortInfo groupSortInfo =null; + if(ObjectUtils.isEmpty(sortInfo)){ + //如果sortInfo 是空得话,那就是没有,组得排序给当前最大值+1,类型给默认值1 + groupSortInfo = this.groupSortInfo(null,dto.getType()); + }else { + //如果不是空,那就获取这个组得序号,组类型最大值+1 + groupSortInfo = this.groupSortInfo(dto.getName(),dto.getType()); + } + dto.setSort(groupSortInfo.getSort()); + dto.setBsSort(groupSortInfo.getBsSort()); + this.saveDto(dto); } @Override public void updateIotVisualGroupDTO(IotVisualGroupDTO dto) { - + List sortInfo = this.getNameSort(dto.getName(),dto.getType()); + if(dto.getOldBusinessName().equals(dto.getBusinessName())){ + moveItem(sortInfo,dto.getOldBsSort()-1,dto.getBsSort()-1,null); + //重置sort字段 + updateSortValues(sortInfo); + }else { + moveItem(sortInfo,dto.getOldBsSort()-1,dto.getBsSort()-1,dto.getBusinessName()); + //重置sort字段 + updateSortValues(sortInfo); + } + sortInfo.forEach(temp->{ + if(dto.getOldBusinessName().equals(temp.getName())){ + UpdateChain.of(IotVisualGroupEntity.class) + .set(IotVisualGroupEntity::getSort, temp.getSort()) + .where(IotVisualGroupEntity::getName).eq(dto.getName()).eq(IotVisualGroupEntity::getBusinessName,temp.getName()) + .update(); + }else { + UpdateChain.of(IotVisualGroupEntity.class) + .set(IotVisualGroupEntity::getSort, temp.getSort()) + .set(IotVisualGroupEntity::getThumbnailUrl,dto.getThumbnailUrl()) + .set(IotVisualGroupEntity::getBusinessName,dto.getBusinessName()) + .set(IotVisualGroupEntity::getRemark,dto.getRemark()) + .where(IotVisualGroupEntity::getName).eq(dto.getName()).eq(IotVisualGroupEntity::getBusinessName,temp.getName()) + .update(); + } + }); } @Override - public GroupSortInfo groupSortInfo(String name) { + public GroupSortInfo groupSortInfo(String name,String type) { + Long tenantCode = UserContext.getTenantCode(); QueryWrapper wrapper = new QueryWrapper(); wrapper.select(max(IOT_VISUAL_GROUP_ENTITY.SORT).as("sort"), max(IOT_VISUAL_GROUP_ENTITY.BS_SORT).as("bs_sort")) - .from(IOT_VISUAL_GROUP_ENTITY); + .from(IOT_VISUAL_GROUP_ENTITY).eq(IotVisualGroupEntity::getType,type); + wrapper.and(IOT_VISUAL_GROUP_ENTITY.TENANT_CODE.eq(tenantCode).or(IOT_VISUAL_GROUP_ENTITY.IS_DEFAULT.eq("1"))); if(ObjectUtils.isNotEmpty(name)){ wrapper.eq(IotVisualGroupEntity::getName,name); } GroupSortInfo sortInfo = this.mapper.selectOneByQueryAs(wrapper,GroupSortInfo.class); if(ObjectUtils.isEmpty(sortInfo)){ sortInfo = new GroupSortInfo(); - sortInfo.setBsSort(1L); - sortInfo.setSort(1L); + sortInfo.setBsSort(1); + sortInfo.setSort(1); return sortInfo; } if(ObjectUtils.isNotEmpty(name)){ - sortInfo.setSort(sortInfo.getSort()==null?1L:sortInfo.getSort()); + sortInfo.setSort(sortInfo.getSort()==null?1:sortInfo.getSort()); }else { - sortInfo.setSort(sortInfo.getSort()==null?1L:sortInfo.getSort()+1); + sortInfo.setSort(sortInfo.getSort()==null?1:sortInfo.getSort()+1); } - sortInfo.setBsSort(sortInfo.getBsSort()==null?1L:sortInfo.getBsSort()+1); + sortInfo.setBsSort(sortInfo.getBsSort()==null?1:sortInfo.getBsSort()+1); return sortInfo ; } @Override public String adjustGroupSort(AdjustGroupDto dto) { - List sortInfo = this.getNameSort(dto.getName()); + List sortInfo = this.getNameSort(dto.getName(),dto.getType()); //修改排序 - moveItem(sortInfo,dto.getCurrentSort()-1,dto.getUpSort()-1); + moveItem(sortInfo,dto.getCurrentSort()-1,dto.getUpSort()-1,null); //重置sort字段 updateSortValues(sortInfo); @@ -99,24 +153,62 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl sortInfo = this.getNameSort(null,dto.getType()); + if(dto.getOldName().equals(dto.getName())){ + //修改排序 + moveItem(sortInfo,dto.getOldSort()-1,dto.getSort()-1,null); + //重置sort字段 + updateSortValues(sortInfo); + }else { + //修改排序 + moveItem(sortInfo,dto.getOldSort()-1,dto.getSort()-1,dto.getName()); + //重置sort字段 + updateSortValues(sortInfo); + } + //组排序 + sortInfo.forEach(temp->{ + UpdateChain.of(IotVisualGroupEntity.class) + .set(IotVisualGroupEntity::getSort, temp.getSort()) + .where(IotVisualGroupEntity::getName).eq(temp.getName()) + .update(); + }); + } + @Override + public List groupInfo(String name, String type) { + Long tenantCode = UserContext.getTenantCode(); + QueryWrapper wrapper = new QueryWrapper(); + wrapper.select(max(IOT_VISUAL_GROUP_ENTITY.SORT).as("sort"), IOT_VISUAL_GROUP_ENTITY.BUSINESS_NAME.as("name")) + .from(IOT_VISUAL_GROUP_ENTITY).eq(IotVisualGroupEntity::getType,type); + //本企业得or 默认得 + wrapper.and(IOT_VISUAL_GROUP_ENTITY.TENANT_CODE.eq(tenantCode).or(IOT_VISUAL_GROUP_ENTITY.IS_DEFAULT.eq("1"))); + wrapper.eq(IotVisualGroupEntity::getName,name).groupBy(IOT_VISUAL_GROUP_ENTITY.NAME).orderBy(IOT_VISUAL_GROUP_ENTITY.SORT,true); + return this.mapper.selectListByQueryAs(wrapper,NameSort.class); + } /** - * 获取所有信息,看没有没有穿name,传name了,就是组内排序,没传name就是组排序 + * 获取所有排序信息,看没有没有穿name,传name了,就是组内排序,没传name就是组排序 * @param name * @return */ - private List getNameSort(String name){ + private List getNameSort(String name,String type){ + Long tenantCode = UserContext.getTenantCode(); QueryWrapper wrapper = new QueryWrapper(); if(ObjectUtils.isNotEmpty(name)){ wrapper.select(max(IOT_VISUAL_GROUP_ENTITY.SORT).as("sort"), IOT_VISUAL_GROUP_ENTITY.BUSINESS_NAME.as("name")) - .from(IOT_VISUAL_GROUP_ENTITY); + .from(IOT_VISUAL_GROUP_ENTITY).eq(IotVisualGroupEntity::getType,type); + //本企业得or 默认得 + wrapper.and(IOT_VISUAL_GROUP_ENTITY.TENANT_CODE.eq(tenantCode).or(IOT_VISUAL_GROUP_ENTITY.IS_DEFAULT.eq("1"))); wrapper.eq(IotVisualGroupEntity::getName,name).groupBy(IOT_VISUAL_GROUP_ENTITY.NAME).orderBy(IOT_VISUAL_GROUP_ENTITY.SORT,true); }else { wrapper.select(max(IOT_VISUAL_GROUP_ENTITY.SORT).as("sort"), IOT_VISUAL_GROUP_ENTITY.NAME.as("name")) - .from(IOT_VISUAL_GROUP_ENTITY); + .from(IOT_VISUAL_GROUP_ENTITY).eq(IotVisualGroupEntity::getType,type); + wrapper.and(IOT_VISUAL_GROUP_ENTITY.TENANT_CODE.eq(tenantCode).or(IOT_VISUAL_GROUP_ENTITY.IS_DEFAULT.eq("1"))); wrapper.groupBy(IOT_VISUAL_GROUP_ENTITY.NAME).orderBy(IOT_VISUAL_GROUP_ENTITY.SORT,true);; } return this.mapper.selectListByQueryAs(wrapper,NameSort.class); @@ -129,11 +221,14 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl list, int fromIndex, int toIndex) { + private static void moveItem(List list, int fromIndex, int toIndex,String name) { if (fromIndex < 0 || fromIndex >= list.size() || toIndex < 0 || toIndex >= list.size()) { throw new IndexOutOfBoundsException("Invalid index"); } NameSort item = list.remove(fromIndex); + if(ObjectUtils.isNotEmpty(name)){ + item.setName(name); + } list.add(toIndex, item); updateSortValues(list); } @@ -143,7 +238,7 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl list) { - long sortValue = 1L; + Integer sortValue = 1; for (NameSort item : list) { item.setSort(sortValue++); }