diff --git a/modules/visual-design/src/main/java/com/thing/visual/component/controller/IotVisualComponentController.java b/modules/visual-design/src/main/java/com/thing/visual/component/controller/IotVisualComponentController.java index ac1fe86..3dd9bce 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/component/controller/IotVisualComponentController.java +++ b/modules/visual-design/src/main/java/com/thing/visual/component/controller/IotVisualComponentController.java @@ -9,6 +9,8 @@ import com.thing.common.core.validator.group.DefaultGroup; import com.thing.common.core.validator.group.UpdateGroup; import com.thing.common.core.web.response.PageData; import com.thing.common.core.web.response.Result; +import com.thing.visual.component.dto.AdjustSortInfo; +import com.thing.visual.component.dto.GroupInfo; import com.thing.visual.component.dto.IotVisualComponentDTO; import com.thing.visual.component.service.IotVisualComponentService; @@ -19,6 +21,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; /** @@ -41,17 +44,19 @@ public class IotVisualComponentController { @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 = "groupIds", description = "组id,多个组id以英文逗号分隔"), + @Parameter(name = "name", description = "部件名称") }) public Result> page(@Parameter(hidden = true) @RequestParam Map params){ - PageData page = iotVisualComponentService.getPageData(params, IotVisualComponentDTO.class); + PageData page = iotVisualComponentService.getPageDataInfo(params); return new Result>().ok(page); } @GetMapping("{id}") @Operation(summary="信息") public Result get(@PathVariable("id") Long id){ - IotVisualComponentDTO data = iotVisualComponentService.getByIdAs(id, IotVisualComponentDTO.class); + IotVisualComponentDTO data = iotVisualComponentService.getByIdDto(id); return new Result().ok(data); } @@ -71,7 +76,7 @@ public class IotVisualComponentController { public Result update(@RequestBody IotVisualComponentDTO dto){ //效验数据 ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); - iotVisualComponentService.updateDto(dto); + iotVisualComponentService.updateIotVisualComponentDTO(dto); return new Result<>(); } @@ -86,4 +91,25 @@ public class IotVisualComponentController { } + @GetMapping("sort") + @Operation(summary="当前组的最大序号") + public Result getSort(@RequestParam("groupId") Long groupId){ + Integer sort = iotVisualComponentService.getSort(groupId); + return new Result().ok(sort); + } + + @GetMapping("businessList") + @Operation(summary="定制接口,获取 远程组件 类型列表,新增组件的时候使用") + public Result> businessList(){ + List businessList = iotVisualComponentService.businessList(); + return new Result>().ok(businessList); + } + + @GetMapping("adjustSort") + @Operation(summary="拖动修改排序") + public Result adjustSort(AdjustSortInfo sortInfo){ + String data = iotVisualComponentService.adjustSort(sortInfo); + return new Result().ok(data); + } + } \ No newline at end of file diff --git a/modules/visual-design/src/main/java/com/thing/visual/component/dto/AdjustSortInfo.java b/modules/visual-design/src/main/java/com/thing/visual/component/dto/AdjustSortInfo.java new file mode 100644 index 0000000..4ff0630 --- /dev/null +++ b/modules/visual-design/src/main/java/com/thing/visual/component/dto/AdjustSortInfo.java @@ -0,0 +1,20 @@ +package com.thing.visual.component.dto; + + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +@Schema(description = "部件拖动排序入参") +public class AdjustSortInfo { + + @Schema(description = "部件id") + private Long id; + @Schema(description = "部件组类型id") + private Long groupId; + @Schema(description = "原始序号") + private Integer currentSort; + @Schema(description = "被移动的序号") + private Integer upSort; + +} diff --git a/modules/visual-design/src/main/java/com/thing/visual/component/dto/ComponentSortInfo.java b/modules/visual-design/src/main/java/com/thing/visual/component/dto/ComponentSortInfo.java new file mode 100644 index 0000000..be1a025 --- /dev/null +++ b/modules/visual-design/src/main/java/com/thing/visual/component/dto/ComponentSortInfo.java @@ -0,0 +1,30 @@ +package com.thing.visual.component.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +/** +* 部件设计信息 +* +* @author xc +* @since 3.0 2024-08-21 +*/ +@Data +@Schema(description = "部件设计信息") +public class ComponentSortInfo implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + + @Schema(description = "部件id") + private Long id; + @Schema(description = "部件名称") + private String name; + @Schema(description = "部件组id") + private Integer groupId; + @Schema(description = "部件排序序号") + private Integer sort; + +} \ No newline at end of file diff --git a/modules/visual-design/src/main/java/com/thing/visual/component/dto/GroupInfo.java b/modules/visual-design/src/main/java/com/thing/visual/component/dto/GroupInfo.java new file mode 100644 index 0000000..5aeb3f8 --- /dev/null +++ b/modules/visual-design/src/main/java/com/thing/visual/component/dto/GroupInfo.java @@ -0,0 +1,18 @@ +package com.thing.visual.component.dto; + + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +@Schema(name = "组类型信息") +public class GroupInfo { + + + @Schema(name = "id") + private Long id; + @Schema(name = "组类型名称") + private String businessName; + + +} diff --git a/modules/visual-design/src/main/java/com/thing/visual/component/dto/IotVisualComponentDTO.java b/modules/visual-design/src/main/java/com/thing/visual/component/dto/IotVisualComponentDTO.java index cb63093..a2f4d42 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/component/dto/IotVisualComponentDTO.java +++ b/modules/visual-design/src/main/java/com/thing/visual/component/dto/IotVisualComponentDTO.java @@ -24,7 +24,13 @@ public class IotVisualComponentDTO implements Serializable { @Schema(description = "部件名称") private String name; @Schema(description = "部件组id") - private Integer groupId; + private Long groupId; + + @Schema(description = "部件组名称") + private String groupName; + @Schema(description = "部件组类型名称") + private String groupBusinessName; + @Schema(description = "部件类型") private String type; @Schema(description = "部件备注描述") @@ -56,4 +62,8 @@ public class IotVisualComponentDTO implements Serializable { @Schema(description = "部件排序序号") private Integer sort; + private Integer oldSort; + + + } \ No newline at end of file diff --git a/modules/visual-design/src/main/java/com/thing/visual/component/entity/IotVisualComponentEntity.java b/modules/visual-design/src/main/java/com/thing/visual/component/entity/IotVisualComponentEntity.java index a6f8435..7476051 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/component/entity/IotVisualComponentEntity.java +++ b/modules/visual-design/src/main/java/com/thing/visual/component/entity/IotVisualComponentEntity.java @@ -31,7 +31,7 @@ public class IotVisualComponentEntity extends BaseInfoEntity implements Serializ /** * 部件组id */ - private Integer groupId; + private Long groupId; /** * 部件类型 */ diff --git a/modules/visual-design/src/main/java/com/thing/visual/component/service/IotVisualComponentService.java b/modules/visual-design/src/main/java/com/thing/visual/component/service/IotVisualComponentService.java index 96fa55b..648938e 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/component/service/IotVisualComponentService.java +++ b/modules/visual-design/src/main/java/com/thing/visual/component/service/IotVisualComponentService.java @@ -1,9 +1,14 @@ package com.thing.visual.component.service; +import com.thing.common.core.web.response.PageData; import com.thing.common.orm.service.IBaseService; +import com.thing.visual.component.dto.AdjustSortInfo; +import com.thing.visual.component.dto.GroupInfo; +import com.thing.visual.component.dto.IotVisualComponentDTO; import com.thing.visual.component.entity.IotVisualComponentEntity; import java.util.List; +import java.util.Map; /** * 部件设计信息 @@ -14,4 +19,15 @@ import java.util.List; public interface IotVisualComponentService extends IBaseService { List getInfoByGroupIds(List groupIds); + + Integer getSort(Long groupId); + + List businessList(); + + String adjustSort(AdjustSortInfo sortInfo); + void updateIotVisualComponentDTO(IotVisualComponentDTO dto); + + PageData getPageDataInfo(Map params); + + IotVisualComponentDTO getByIdDto(Long id); } \ No newline at end of file diff --git a/modules/visual-design/src/main/java/com/thing/visual/component/service/impl/IotVisualComponentServiceImpl.java b/modules/visual-design/src/main/java/com/thing/visual/component/service/impl/IotVisualComponentServiceImpl.java index 7eb2ea8..99d951f 100644 --- a/modules/visual-design/src/main/java/com/thing/visual/component/service/impl/IotVisualComponentServiceImpl.java +++ b/modules/visual-design/src/main/java/com/thing/visual/component/service/impl/IotVisualComponentServiceImpl.java @@ -1,14 +1,32 @@ package com.thing.visual.component.service.impl; import com.mybatisflex.core.query.QueryWrapper; +import com.mybatisflex.core.update.UpdateChain; +import com.thing.common.core.web.response.PageData; import com.thing.common.orm.service.impl.BaseServiceImpl; +import com.thing.sys.security.context.UserContext; +import com.thing.visual.component.dto.AdjustSortInfo; +import com.thing.visual.component.dto.ComponentSortInfo; +import com.thing.visual.component.dto.GroupInfo; +import com.thing.visual.component.dto.IotVisualComponentDTO; import com.thing.visual.component.entity.IotVisualComponentEntity; import com.thing.visual.component.mapper.IotVisualComponentMapper; import com.thing.visual.component.service.IotVisualComponentService; +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.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; + +import static com.mybatisflex.core.query.QueryMethods.max; +import static com.thing.visual.component.entity.table.IotVisualComponentEntityTableDef.IOT_VISUAL_COMPONENT_ENTITY; /** * 部件设计信息 @@ -19,9 +37,26 @@ import java.util.Map; @Service public class IotVisualComponentServiceImpl extends BaseServiceImpl implements IotVisualComponentService { + + @Autowired + private IotVisualGroupService iotVisualGroupService; + + + @Override public QueryWrapper getWrapper(Map params){ QueryWrapper wrapper = new QueryWrapper(); + String name = MapUtils.getString(params,"name"); + String groupIds = MapUtils.getString(params,"names"); + List groupIdList = null; + if(StringUtils.isNotEmpty(groupIds)){ + groupIdList = Arrays.stream(groupIds.split(",")) + .map(String::trim) // 去掉可能的空格 + .map(Long::parseLong) // 将每个字符串转换为 Long + .collect(Collectors.toList()); + } + wrapper.in(IotVisualComponentEntity::getGroupId,groupIdList,ObjectUtils.isNotEmpty(groupIdList)); + wrapper.like(IotVisualComponentEntity::getName,name,StringUtils.isNotEmpty(name)); return wrapper; } @@ -32,4 +67,143 @@ public class IotVisualComponentServiceImpl extends BaseServiceImpl businessList() { + QueryWrapper wrapper = new QueryWrapper(); + wrapper.eq("name","远程组件"); + wrapper.orderBy("bs_sort",true); + return iotVisualGroupService.listAs(wrapper,GroupInfo.class); + } + + + + @Override + public String adjustSort(AdjustSortInfo sortInfo) { + List sortInfos = this.getComponentSortInfo(sortInfo.getGroupId()); + moveItem(sortInfos,sortInfo.getCurrentSort()-1,sortInfo.getUpSort()-1,null); + updateSortValues(sortInfos); + sortInfos.forEach(temp->{ + UpdateChain.of(IotVisualGroupEntity.class) + .set(IotVisualGroupEntity::getSort, temp.getSort()) + .where(IotVisualGroupEntity::getId).eq(temp.getId()) + .update(); + }); + return "排序成功!"; + } + + @Override + public PageData getPageDataInfo(Map params) { + + PageData dtoPageData = this.getPageData(params,IotVisualComponentDTO.class); + + dtoPageData.getList().forEach(temp->{ + IotVisualGroupEntity group = iotVisualGroupService.getById(temp.getGroupId()); + temp.setGroupName(group.getName()); + temp.setGroupBusinessName(group.getBusinessName()); + }); + return dtoPageData; + } + + @Override + public IotVisualComponentDTO getByIdDto(Long id) { + IotVisualComponentDTO data = this.getByIdAs(id,IotVisualComponentDTO.class); + + IotVisualGroupEntity group = iotVisualGroupService.getById(data.getGroupId()); + data.setGroupName(group.getName()); + data.setGroupBusinessName(group.getBusinessName()); + + return data; + } + + + @Override + public void updateIotVisualComponentDTO(IotVisualComponentDTO dto) { + if(ObjectUtils.isNotEmpty(dto.getOldSort())){ + List sortInfos = this.getComponentSortInfo(dto.getGroupId()); + + moveItem(sortInfos,dto.getOldSort()-1,dto.getSort()-1,dto.getName()); + //重置sort字段 + updateSortValues(sortInfos); + sortInfos.forEach(temp->{ + UpdateChain.of(IotVisualComponentEntity.class) + .set(IotVisualComponentEntity::getSort, temp.getSort()) + .set(IotVisualComponentEntity::getName,dto.getName()) + .set(IotVisualComponentEntity::getThumbnailUrl,dto.getThumbnailUrl()) + .set(IotVisualComponentEntity::getRemarks,dto.getRemarks()) + .set(IotVisualComponentEntity::getDesc,dto.getDesc()) + .set(IotVisualComponentEntity::getHash,dto.getHash()) + .set(IotVisualComponentEntity::getPreviewOptions,dto.getPreviewOptions()) + .set(IotVisualComponentEntity::getIsDefault,dto.getIsDefault()) + .where(IotVisualComponentEntity::getId).eq(temp.getId()) + .update(); + }); + }else { + this.updateDto(dto); + } + } + + + + + + + + private List getComponentSortInfo(Long groupId){ + QueryWrapper wrapper = new QueryWrapper(); + wrapper.eq("group_id",groupId); + wrapper.orderBy("sort",true); + return this.listAs(wrapper,ComponentSortInfo.class); + } + + + /** + * 删除原坐标,在新的坐标插入我的对象 + * @param list + * @param fromIndex + * @param toIndex + */ + private static void moveItem(List list, int fromIndex, int toIndex, String name) { + if (fromIndex < 0 || fromIndex >= list.size()) { + throw new IndexOutOfBoundsException("Invalid index"); + } + if(toIndex < 0 ){ + toIndex=0; + } + if(toIndex >= list.size()){ + toIndex= list.size()-1; + } + + ComponentSortInfo item = list.remove(fromIndex); + if(ObjectUtils.isNotEmpty(name)){ + item.setName(name); + } + list.add(toIndex, item); + updateSortValues(list); + } + + /** + * 重新修改 name中对应的sort信息 + * @param list + */ + private static void updateSortValues(List list) { + Integer sortValue = 1; + for (ComponentSortInfo item : list) { + item.setSort(sortValue++); + } + } } \ 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 9d80ad2..a4afe8f 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 @@ -148,7 +148,7 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl{ UpdateChain.of(IotVisualGroupEntity.class) - .set(IotVisualGroupEntity::getSort, temp.getSort()) + .set(IotVisualGroupEntity::getBsSort, temp.getSort()) .where(IotVisualGroupEntity::getName).eq(dto.getName()).eq(IotVisualGroupEntity::getBusinessName,temp.getName()) .update(); });