From ba46dc4ac737b65a29221f02f5acf51112fc4de7 Mon Sep 17 00:00:00 2001 From: xiachao Date: Tue, 27 Aug 2024 15:56:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B4=A0=E6=9D=90=E9=83=A8=E4=BB=B6=E7=BB=84?= =?UTF-8?q?=E7=AE=A1=E7=90=86=EF=BC=8C=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IotNewSourceMaterialController.java | 2 +- .../service/IotNewSourceMaterialService.java | 2 + .../impl/IotNewSourceMaterialServiceImpl.java | 9 +- modules/visual-design/pom.xml | 7 + .../service/IotVisualComponentService.java | 3 + .../impl/IotVisualComponentServiceImpl.java | 7 + .../controller/IotVisualGroupController.java | 29 ++- .../visual/group/dto/GroupInfoFormatDTO.java | 32 ++++ .../group/service/IotVisualGroupService.java | 10 +- .../impl/IotVisualGroupServiceImpl.java | 168 +++++++++++++----- 10 files changed, 215 insertions(+), 54 deletions(-) create mode 100644 modules/visual-design/src/main/java/com/thing/visual/group/dto/GroupInfoFormatDTO.java diff --git a/modules/configuration/src/main/java/com/thing/configuration/newmaterial/controller/IotNewSourceMaterialController.java b/modules/configuration/src/main/java/com/thing/configuration/newmaterial/controller/IotNewSourceMaterialController.java index 73d3aa9..3ba96d7 100644 --- a/modules/configuration/src/main/java/com/thing/configuration/newmaterial/controller/IotNewSourceMaterialController.java +++ b/modules/configuration/src/main/java/com/thing/configuration/newmaterial/controller/IotNewSourceMaterialController.java @@ -127,7 +127,7 @@ public class IotNewSourceMaterialController { @PostMapping("export") @Operation(summary="导出") @Parameters({ - @Parameter(name ="groupIds",description ="部件组id 多个以英文逗号分割"), + @Parameter(name ="groupIds",description ="素材组id 多个以英文逗号分割"), @Parameter(name ="name",description ="素材名称"), @Parameter(name ="type",description ="文件类型"), @Parameter(name ="ids",description ="id数组"), diff --git a/modules/configuration/src/main/java/com/thing/configuration/newmaterial/service/IotNewSourceMaterialService.java b/modules/configuration/src/main/java/com/thing/configuration/newmaterial/service/IotNewSourceMaterialService.java index c8a8a74..6ec232d 100644 --- a/modules/configuration/src/main/java/com/thing/configuration/newmaterial/service/IotNewSourceMaterialService.java +++ b/modules/configuration/src/main/java/com/thing/configuration/newmaterial/service/IotNewSourceMaterialService.java @@ -32,4 +32,6 @@ public interface IotNewSourceMaterialService extends IBaseService getInfoByGroupIds(List groupIds); } \ No newline at end of file diff --git a/modules/configuration/src/main/java/com/thing/configuration/newmaterial/service/impl/IotNewSourceMaterialServiceImpl.java b/modules/configuration/src/main/java/com/thing/configuration/newmaterial/service/impl/IotNewSourceMaterialServiceImpl.java index 40e94ae..dc5d52c 100644 --- a/modules/configuration/src/main/java/com/thing/configuration/newmaterial/service/impl/IotNewSourceMaterialServiceImpl.java +++ b/modules/configuration/src/main/java/com/thing/configuration/newmaterial/service/impl/IotNewSourceMaterialServiceImpl.java @@ -24,7 +24,6 @@ import com.thing.configuration.newmaterial.mapper.IotNewSourceMaterialMapper; import com.thing.configuration.newmaterial.service.IotNewSourceMaterialService; import com.thing.sys.biz.dto.SysUserDTO; import com.thing.sys.biz.service.SysUserService; -import com.thing.sys.oss.cloud.AbstractCloudStorageService; import com.thing.sys.oss.cloud.OSSFactory; import com.thing.sys.security.context.TenantContext; import com.thing.sys.security.context.UserContext; @@ -240,4 +239,12 @@ public class IotNewSourceMaterialServiceImpl extends BaseServiceImpl getInfoByGroupIds(List groupIds) { + + QueryWrapper wrapper = new QueryWrapper(); + wrapper.eq( "group_id", groupIds); + return this.mapper.selectListByQuery(wrapper); + } } \ No newline at end of file diff --git a/modules/visual-design/pom.xml b/modules/visual-design/pom.xml index dbccc95..3e084a5 100644 --- a/modules/visual-design/pom.xml +++ b/modules/visual-design/pom.xml @@ -27,5 +27,12 @@ com.thing.modules thing + + + com.thing.modules + configuration + + + 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 7d9aff9..96fa55b 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 @@ -3,6 +3,8 @@ package com.thing.visual.component.service; import com.thing.common.orm.service.IBaseService; import com.thing.visual.component.entity.IotVisualComponentEntity; +import java.util.List; + /** * 部件设计信息 * @@ -11,4 +13,5 @@ import com.thing.visual.component.entity.IotVisualComponentEntity; */ public interface IotVisualComponentService extends IBaseService { + List getInfoByGroupIds(List groupIds); } \ 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 eb9ab1b..7eb2ea8 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 @@ -7,6 +7,7 @@ import com.thing.visual.component.mapper.IotVisualComponentMapper; import com.thing.visual.component.service.IotVisualComponentService; import org.springframework.stereotype.Service; +import java.util.List; import java.util.Map; /** @@ -25,4 +26,10 @@ public class IotVisualComponentServiceImpl extends BaseServiceImpl getInfoByGroupIds(List groupIds) { + QueryWrapper wrapper = new QueryWrapper(); + wrapper.eq( "group_id", groupIds); + return this.mapper.selectListByQuery(wrapper); + } } \ No newline at end of file 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 a9ffbe5..141d4f0 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 @@ -4,10 +4,8 @@ import com.thing.common.core.constants.Constant; import com.thing.common.core.validator.AssertUtils; import com.thing.common.core.web.response.PageData; 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.thing.group.dto.IotGroupInfoFormatDTO; +import com.thing.visual.group.dto.*; import com.thing.visual.group.service.IotVisualGroupService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -40,6 +38,7 @@ public class IotVisualGroupController { @Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true) , @Parameter(name = Constant.ORDER_FIELD, description = "排序字段") , @Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)"), + @Parameter(name = "type", description = "类型,1素材,2部件 必传"), @Parameter(name = "name", description = "组名称"), @Parameter(name = "businessName", description = "组类型名称"), @Parameter(name = "names", description = "组名称集合,多个组名称,以英文逗号分割") @@ -81,7 +80,7 @@ public class IotVisualGroupController { } @DeleteMapping - @Operation(summary="删除") + @Operation(summary="删除 这个接口删除二级右侧列表里面的数据,传入数据id") public Result delete(@RequestBody Long[] ids){ //效验数据 AssertUtils.isArrayEmpty(ids, "id"); @@ -89,6 +88,13 @@ public class IotVisualGroupController { return new Result<>(); } + @DeleteMapping("group") + @Operation(summary="删除 这个接口删除一级左侧列表里面的数据,传入组名称") + public Result deleteGroup(@RequestParam(required = false) String name, @RequestParam(required = true) String type){ + return new Result().ok(iotVisualGroupService.deleteGroup(name,type)); + } + + @GetMapping("groupInfo") @Operation(summary="左侧组列表,可按名称模糊查询") @@ -111,4 +117,17 @@ public class IotVisualGroupController { String data = iotVisualGroupService.adjustGroupSort(dto); return new Result().ok(data); } + + @GetMapping("listTree") + @Operation(summary="返回所有可见组的树结构,部件素材侧边栏使用(组级别是虚拟的,没有id生成的虚拟id)") + @Parameters({ + @Parameter(name ="type",description ="1素材,2部件"), + @Parameter(name ="name",description ="组名称") + }) + public Result> listTree(String type, String name){ + return iotVisualGroupService.listTree(type,name); + } + + + } \ No newline at end of file diff --git a/modules/visual-design/src/main/java/com/thing/visual/group/dto/GroupInfoFormatDTO.java b/modules/visual-design/src/main/java/com/thing/visual/group/dto/GroupInfoFormatDTO.java new file mode 100644 index 0000000..e39b800 --- /dev/null +++ b/modules/visual-design/src/main/java/com/thing/visual/group/dto/GroupInfoFormatDTO.java @@ -0,0 +1,32 @@ +package com.thing.visual.group.dto; + +import com.thing.thing.group.dto.IotGroupInfoFormatDTO; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.List; + + +@Data +public class GroupInfoFormatDTO { + + @Schema(description = "id") + private Long id; + + @Schema(description = "组名称") + private String name; + + @Schema(description = "组类型名称") + private String businessName; + + @Schema(description = "缩略图url") + private String thumbnailUrl; + + private Integer sort; + + private Integer bsSort; + + @Schema(description = "组类型列表") + private List typeList; + +} 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 2a23545..a85d3c5 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 @@ -1,10 +1,9 @@ package com.thing.visual.group.service; +import com.thing.common.core.web.response.Result; 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.thing.group.dto.IotGroupInfoFormatDTO; +import com.thing.visual.group.dto.*; import com.thing.visual.group.entity.IotVisualGroupEntity; import java.util.List; @@ -28,4 +27,7 @@ public interface IotVisualGroupService extends IBaseService groupInfo(String name, String type); + String deleteGroup(String name, String type); + + Result> listTree(String type, String name); } \ 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 2bd5ce1..9d80ad2 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 @@ -2,24 +2,28 @@ package com.thing.visual.group.service.impl; import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.update.UpdateChain; -import com.mybatisflex.core.update.UpdateWrapper; +import com.thing.common.core.utils.ConvertUtils; +import com.thing.common.core.web.response.Result; import com.thing.common.orm.service.impl.BaseServiceImpl; +import com.thing.configuration.newmaterial.entity.IotNewSourceMaterialEntity; +import com.thing.configuration.newmaterial.service.IotNewSourceMaterialService; 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; -import com.thing.visual.group.dto.NameSort; +import com.thing.thing.group.dto.IotGroupInfoDTO; +import com.thing.thing.group.dto.IotGroupInfoFormatDTO; +import com.thing.visual.component.entity.IotVisualComponentEntity; +import com.thing.visual.component.service.IotVisualComponentService; +import com.thing.visual.group.dto.*; 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.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; import static com.mybatisflex.core.query.QueryMethods.max; import static com.mybatisflex.core.query.QueryMethods.max; @@ -28,20 +32,34 @@ import static com.thing.visual.group.entity.table.IotVisualGroupEntityTableDef.I /** * 素材部件组管理 * - * @author xc + * @author xc * @since 3.0 2024-08-21 */ @Service public class IotVisualGroupServiceImpl extends BaseServiceImpl implements IotVisualGroupService { + + + @Autowired + private IotNewSourceMaterialService iotNewSourceMaterialService; + @Autowired + private IotVisualComponentService iotVisualComponentService; + + + + @Override public QueryWrapper getWrapper(Map 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(",")); + List nameList = null; + if(StringUtils.isNotEmpty(names)){ + nameList = Arrays.asList(names.split(",")); + } String businessName = MapUtils.getString(params,"businessName"); + wrapper.eq(IotVisualGroupEntity::getType,MapUtils.getString(params,"type")); 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)); @@ -54,16 +72,7 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl 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()); - } + GroupSortInfo groupSortInfo = this.groupSortInfo(dto.getName(),dto.getType()); dto.setSort(groupSortInfo.getSort()); dto.setBsSort(groupSortInfo.getBsSort()); this.saveDto(dto); @@ -82,17 +91,17 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl{ - if(dto.getOldBusinessName().equals(temp.getName())){ + if(dto.getBusinessName().equals(temp.getName())){ UpdateChain.of(IotVisualGroupEntity.class) - .set(IotVisualGroupEntity::getSort, temp.getSort()) + .set(IotVisualGroupEntity::getBsSort, 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(); }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()) + .set(IotVisualGroupEntity::getBsSort, temp.getSort()) .where(IotVisualGroupEntity::getName).eq(dto.getName()).eq(IotVisualGroupEntity::getBusinessName,temp.getName()) .update(); } @@ -107,20 +116,22 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl{ - UpdateChain.of(IotVisualGroupEntity.class) - .set(IotVisualGroupEntity::getSort, temp.getSort()) - .where(IotVisualGroupEntity::getName).eq(temp.getName()) - .update(); + if(temp.getName().equals(dto.getName())){ + UpdateChain.of(IotVisualGroupEntity.class) + .set(IotVisualGroupEntity::getSort, temp.getSort()) + .set(IotVisualGroupEntity::getName, temp.getName()) + .where(IotVisualGroupEntity::getName).eq(dto.getOldName()).and("type = '"+dto.getType()+"'") + .update(); + }else { + UpdateChain.of(IotVisualGroupEntity.class) + .set(IotVisualGroupEntity::getSort, temp.getSort()) + .where(IotVisualGroupEntity::getName).eq(temp.getName()).and("type = '"+dto.getType()+"'") + .update(); + } }); } @@ -182,14 +201,70 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl entities = this.list(wrapper); + + List groupIds = entities.stream() + .map(IotVisualGroupEntity::getId) + .toList(); + //素材or部件 有被引用,则不允许删除 + List materialList = iotNewSourceMaterialService.getInfoByGroupIds(groupIds); + if(ObjectUtils.isNotEmpty(materialList)){ + return "当前组下有类型被引用,不允许删除!"; + } + List componentEntityList = iotVisualComponentService.getInfoByGroupIds(groupIds); + if(ObjectUtils.isNotEmpty(componentEntityList)){ + return "当前组下有类型被引用,不允许删除!"; + } + //删除组 + QueryWrapper queryWrapper = QueryWrapper.create(); + queryWrapper.eq(IotVisualGroupEntity::getName,name); + queryWrapper.eq(IotVisualGroupEntity::getType,type); + this.mapper.deleteByQuery(queryWrapper); + return "删除成功!"; + + } + + @Override + public Result> listTree(String type, String name) { + List resultList = new ArrayList<>(); + QueryWrapper queryWrapper = QueryWrapper.create(); + queryWrapper.eq(IotVisualGroupEntity::getType,type); + queryWrapper.like(IotVisualGroupEntity::getName,name); + List infos = listAs(queryWrapper, IotVisualGroupDTO.class); + + Map> map = infos.stream().collect(Collectors.groupingBy(IotVisualGroupDTO::getName)); + + for (String temp : map.keySet()) { + GroupInfoFormatDTO dto = new GroupInfoFormatDTO(); + dto.setName(temp); + dto.setBusinessName(temp); + dto.setId((new Random().nextInt()*-1- 19900000000L)); + List infoDTOS = map.get(temp).parallelStream().sorted(Comparator.comparingLong(IotVisualGroupDTO::getBsSort)).collect(Collectors.toList()); + dto.setThumbnailUrl(infoDTOS.get(0).getThumbnailUrl()); + map.get(temp).forEach(info->{ + info.setName(info.getBusinessName()); + }); + dto.setSort(infoDTOS.get(0).getSort()); + dto.setTypeList(ConvertUtils.sourceToTarget(infoDTOS,GroupInfoFormatDTO.class)); + resultList.add(dto); + } + return new Result>().ok(resultList.parallelStream().sorted(Comparator.comparingLong(GroupInfoFormatDTO::getSort)).collect(Collectors.toList())); + } + /** * 获取所有排序信息,看没有没有穿name,传name了,就是组内排序,没传name就是组排序 @@ -197,14 +272,14 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl getNameSort(String name,String type){ - Long tenantCode = UserContext.getTenantCode(); + 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")) + wrapper.select(max(IOT_VISUAL_GROUP_ENTITY.BS_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); + wrapper.eq(IotVisualGroupEntity::getName,name).groupBy(IOT_VISUAL_GROUP_ENTITY.BUSINESS_NAME).orderBy("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).eq(IotVisualGroupEntity::getType,type); @@ -222,9 +297,16 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl list, int fromIndex, int toIndex,String name) { - if (fromIndex < 0 || fromIndex >= list.size() || toIndex < 0 || toIndex >= list.size()) { + if (fromIndex < 0 || fromIndex >= list.size()) { throw new IndexOutOfBoundsException("Invalid index"); } + if(toIndex < 0 ){ + toIndex=0; + } + if(toIndex >= list.size()){ + toIndex= list.size()-1; + } + NameSort item = list.remove(fromIndex); if(ObjectUtils.isNotEmpty(name)){ item.setName(name);