Browse Source

素材部件组管理,代码提交

thing_master
xiachao 1 year ago
parent
commit
ba46dc4ac7
  1. 2
      modules/configuration/src/main/java/com/thing/configuration/newmaterial/controller/IotNewSourceMaterialController.java
  2. 2
      modules/configuration/src/main/java/com/thing/configuration/newmaterial/service/IotNewSourceMaterialService.java
  3. 9
      modules/configuration/src/main/java/com/thing/configuration/newmaterial/service/impl/IotNewSourceMaterialServiceImpl.java
  4. 7
      modules/visual-design/pom.xml
  5. 3
      modules/visual-design/src/main/java/com/thing/visual/component/service/IotVisualComponentService.java
  6. 7
      modules/visual-design/src/main/java/com/thing/visual/component/service/impl/IotVisualComponentServiceImpl.java
  7. 29
      modules/visual-design/src/main/java/com/thing/visual/group/controller/IotVisualGroupController.java
  8. 32
      modules/visual-design/src/main/java/com/thing/visual/group/dto/GroupInfoFormatDTO.java
  9. 10
      modules/visual-design/src/main/java/com/thing/visual/group/service/IotVisualGroupService.java
  10. 168
      modules/visual-design/src/main/java/com/thing/visual/group/service/impl/IotVisualGroupServiceImpl.java

2
modules/configuration/src/main/java/com/thing/configuration/newmaterial/controller/IotNewSourceMaterialController.java

@ -127,7 +127,7 @@ public class IotNewSourceMaterialController {
@PostMapping("export") @PostMapping("export")
@Operation(summary="导出") @Operation(summary="导出")
@Parameters({ @Parameters({
@Parameter(name ="groupIds",description ="部件组id 多个以英文逗号分割"),
@Parameter(name ="groupIds",description ="素材组id 多个以英文逗号分割"),
@Parameter(name ="name",description ="素材名称"), @Parameter(name ="name",description ="素材名称"),
@Parameter(name ="type",description ="文件类型"), @Parameter(name ="type",description ="文件类型"),
@Parameter(name ="ids",description ="id数组"), @Parameter(name ="ids",description ="id数组"),

2
modules/configuration/src/main/java/com/thing/configuration/newmaterial/service/IotNewSourceMaterialService.java

@ -32,4 +32,6 @@ public interface IotNewSourceMaterialService extends IBaseService<IotNewSourceMa
void deleteIotNewSourceMaterialDTO(Long[] ids); void deleteIotNewSourceMaterialDTO(Long[] ids);
Result saveBatch(IotNewSourceMaterialDTO[] dtos); Result saveBatch(IotNewSourceMaterialDTO[] dtos);
List<IotNewSourceMaterialEntity> getInfoByGroupIds(List<Long> groupIds);
} }

9
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.configuration.newmaterial.service.IotNewSourceMaterialService;
import com.thing.sys.biz.dto.SysUserDTO; import com.thing.sys.biz.dto.SysUserDTO;
import com.thing.sys.biz.service.SysUserService; 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.oss.cloud.OSSFactory;
import com.thing.sys.security.context.TenantContext; import com.thing.sys.security.context.TenantContext;
import com.thing.sys.security.context.UserContext; import com.thing.sys.security.context.UserContext;
@ -240,4 +239,12 @@ public class IotNewSourceMaterialServiceImpl extends BaseServiceImpl<IotNewSourc
} }
return new Result().ok("批量新增成功"); return new Result().ok("批量新增成功");
} }
@Override
public List<IotNewSourceMaterialEntity> getInfoByGroupIds(List<Long> groupIds) {
QueryWrapper wrapper = new QueryWrapper();
wrapper.eq( "group_id", groupIds);
return this.mapper.selectListByQuery(wrapper);
}
} }

7
modules/visual-design/pom.xml

@ -27,5 +27,12 @@
<groupId>com.thing.modules</groupId> <groupId>com.thing.modules</groupId>
<artifactId>thing</artifactId> <artifactId>thing</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.thing.modules</groupId>
<artifactId>configuration</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

3
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.common.orm.service.IBaseService;
import com.thing.visual.component.entity.IotVisualComponentEntity; 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<IotVisualComponentEntity> { public interface IotVisualComponentService extends IBaseService<IotVisualComponentEntity> {
List<IotVisualComponentEntity> getInfoByGroupIds(List<Long> groupIds);
} }

7
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 com.thing.visual.component.service.IotVisualComponentService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -25,4 +26,10 @@ public class IotVisualComponentServiceImpl extends BaseServiceImpl<IotVisualComp
} }
@Override
public List<IotVisualComponentEntity> getInfoByGroupIds(List<Long> groupIds) {
QueryWrapper wrapper = new QueryWrapper();
wrapper.eq( "group_id", groupIds);
return this.mapper.selectListByQuery(wrapper);
}
} }

29
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.validator.AssertUtils;
import com.thing.common.core.web.response.PageData; import com.thing.common.core.web.response.PageData;
import com.thing.common.core.web.response.Result; 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 com.thing.visual.group.service.IotVisualGroupService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
@ -40,6 +38,7 @@ public class IotVisualGroupController {
@Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true) , @Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true) ,
@Parameter(name = Constant.ORDER_FIELD, description = "排序字段") , @Parameter(name = Constant.ORDER_FIELD, description = "排序字段") ,
@Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)"), @Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)"),
@Parameter(name = "type", description = "类型,1素材,2部件 必传"),
@Parameter(name = "name", description = "组名称"), @Parameter(name = "name", description = "组名称"),
@Parameter(name = "businessName", description = "组类型名称"), @Parameter(name = "businessName", description = "组类型名称"),
@Parameter(name = "names", description = "组名称集合,多个组名称,以英文逗号分割") @Parameter(name = "names", description = "组名称集合,多个组名称,以英文逗号分割")
@ -81,7 +80,7 @@ public class IotVisualGroupController {
} }
@DeleteMapping @DeleteMapping
@Operation(summary="删除")
@Operation(summary="删除 这个接口删除二级右侧列表里面的数据,传入数据id")
public Result<Void> delete(@RequestBody Long[] ids){ public Result<Void> delete(@RequestBody Long[] ids){
//效验数据 //效验数据
AssertUtils.isArrayEmpty(ids, "id"); AssertUtils.isArrayEmpty(ids, "id");
@ -89,6 +88,13 @@ public class IotVisualGroupController {
return new Result<>(); return new Result<>();
} }
@DeleteMapping("group")
@Operation(summary="删除 这个接口删除一级左侧列表里面的数据,传入组名称")
public Result<String> deleteGroup(@RequestParam(required = false) String name, @RequestParam(required = true) String type){
return new Result<String>().ok(iotVisualGroupService.deleteGroup(name,type));
}
@GetMapping("groupInfo") @GetMapping("groupInfo")
@Operation(summary="左侧组列表,可按名称模糊查询") @Operation(summary="左侧组列表,可按名称模糊查询")
@ -111,4 +117,17 @@ public class IotVisualGroupController {
String data = iotVisualGroupService.adjustGroupSort(dto); String data = iotVisualGroupService.adjustGroupSort(dto);
return new Result<String>().ok(data); return new Result<String>().ok(data);
} }
@GetMapping("listTree")
@Operation(summary="返回所有可见组的树结构,部件素材侧边栏使用(组级别是虚拟的,没有id生成的虚拟id)")
@Parameters({
@Parameter(name ="type",description ="1素材,2部件"),
@Parameter(name ="name",description ="组名称")
})
public Result<List<GroupInfoFormatDTO>> listTree(String type, String name){
return iotVisualGroupService.listTree(type,name);
}
} }

32
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<GroupInfoFormatDTO> typeList;
}

10
modules/visual-design/src/main/java/com/thing/visual/group/service/IotVisualGroupService.java

@ -1,10 +1,9 @@
package com.thing.visual.group.service; package com.thing.visual.group.service;
import com.thing.common.core.web.response.Result;
import com.thing.common.orm.service.IBaseService; 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 com.thing.visual.group.entity.IotVisualGroupEntity;
import java.util.List; import java.util.List;
@ -28,4 +27,7 @@ public interface IotVisualGroupService extends IBaseService<IotVisualGroupEntity
void updateGroup(IotVisualGroupDTO dto); void updateGroup(IotVisualGroupDTO dto);
List<NameSort> groupInfo(String name, String type); List<NameSort> groupInfo(String name, String type);
String deleteGroup(String name, String type);
Result<List<GroupInfoFormatDTO>> listTree(String type, String name);
} }

168
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.query.QueryWrapper;
import com.mybatisflex.core.update.UpdateChain; 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.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.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.mapper.IotVisualGroupMapper;
import com.thing.visual.group.entity.IotVisualGroupEntity; import com.thing.visual.group.entity.IotVisualGroupEntity;
import com.thing.visual.group.service.IotVisualGroupService; import com.thing.visual.group.service.IotVisualGroupService;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; 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;
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 * @since 3.0 2024-08-21
*/ */
@Service @Service
public class IotVisualGroupServiceImpl extends BaseServiceImpl<IotVisualGroupMapper, IotVisualGroupEntity> implements IotVisualGroupService { public class IotVisualGroupServiceImpl extends BaseServiceImpl<IotVisualGroupMapper, IotVisualGroupEntity> implements IotVisualGroupService {
@Autowired
private IotNewSourceMaterialService iotNewSourceMaterialService;
@Autowired
private IotVisualComponentService iotVisualComponentService;
@Override @Override
public QueryWrapper getWrapper(Map<String, Object> params){ public QueryWrapper getWrapper(Map<String, Object> params){
Long tenantCode = UserContext.getTenantCode(); Long tenantCode = UserContext.getTenantCode();
QueryWrapper wrapper = new QueryWrapper(); QueryWrapper wrapper = new QueryWrapper();
String name = MapUtils.getString(params,"name"); String name = MapUtils.getString(params,"name");
String names = MapUtils.getString(params,"names"); String names = MapUtils.getString(params,"names");
List<String> nameList = Arrays.asList(names.split(","));
List<String> nameList = null;
if(StringUtils.isNotEmpty(names)){
nameList = Arrays.asList(names.split(","));
}
String businessName = MapUtils.getString(params,"businessName"); 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.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::getName,name, StringUtils.isNotEmpty(name));
wrapper.like(IotVisualGroupEntity::getBusinessName,businessName, StringUtils.isNotEmpty(businessName)); wrapper.like(IotVisualGroupEntity::getBusinessName,businessName, StringUtils.isNotEmpty(businessName));
@ -54,16 +72,7 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl<IotVisualGroupMap
@Override @Override
public void saveIotVisualGroupDTO(IotVisualGroupDTO dto) { public void saveIotVisualGroupDTO(IotVisualGroupDTO dto) {
List<NameSort> 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.setSort(groupSortInfo.getSort());
dto.setBsSort(groupSortInfo.getBsSort()); dto.setBsSort(groupSortInfo.getBsSort());
this.saveDto(dto); this.saveDto(dto);
@ -82,17 +91,17 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl<IotVisualGroupMap
updateSortValues(sortInfo); updateSortValues(sortInfo);
} }
sortInfo.forEach(temp->{ sortInfo.forEach(temp->{
if(dto.getOldBusinessName().equals(temp.getName())){
if(dto.getBusinessName().equals(temp.getName())){
UpdateChain.of(IotVisualGroupEntity.class) 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()) .where(IotVisualGroupEntity::getName).eq(dto.getName()).eq(IotVisualGroupEntity::getBusinessName,temp.getName())
.update(); .update();
}else { }else {
UpdateChain.of(IotVisualGroupEntity.class) 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()) .where(IotVisualGroupEntity::getName).eq(dto.getName()).eq(IotVisualGroupEntity::getBusinessName,temp.getName())
.update(); .update();
} }
@ -107,20 +116,22 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl<IotVisualGroupMap
.from(IOT_VISUAL_GROUP_ENTITY).eq(IotVisualGroupEntity::getType,type); .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.and(IOT_VISUAL_GROUP_ENTITY.TENANT_CODE.eq(tenantCode).or(IOT_VISUAL_GROUP_ENTITY.IS_DEFAULT.eq("1")));
if(ObjectUtils.isNotEmpty(name)){ if(ObjectUtils.isNotEmpty(name)){
wrapper.eq(IotVisualGroupEntity::getName,name);
wrapper.eq(IotVisualGroupEntity::getName,name);
} }
GroupSortInfo sortInfo = this.mapper.selectOneByQueryAs(wrapper,GroupSortInfo.class); GroupSortInfo sortInfo = this.mapper.selectOneByQueryAs(wrapper,GroupSortInfo.class);
if(ObjectUtils.isEmpty(sortInfo)){ if(ObjectUtils.isEmpty(sortInfo)){
sortInfo = new GroupSortInfo(); sortInfo = new GroupSortInfo();
sortInfo.setBsSort(1); sortInfo.setBsSort(1);
sortInfo.setSort(1);
wrapper = new QueryWrapper();
//当前最大 sort 返回
wrapper.select(max(IOT_VISUAL_GROUP_ENTITY.SORT).as("sort"))
.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")));
GroupSortInfo maxSort = this.mapper.selectOneByQueryAs(wrapper,GroupSortInfo.class);
sortInfo.setSort(maxSort.getSort()+1);
return sortInfo; return sortInfo;
} }
if(ObjectUtils.isNotEmpty(name)){
sortInfo.setSort(sortInfo.getSort()==null?1:sortInfo.getSort());
}else {
sortInfo.setSort(sortInfo.getSort()==null?1:sortInfo.getSort()+1);
}
sortInfo.setBsSort(sortInfo.getBsSort()==null?1:sortInfo.getBsSort()+1); sortInfo.setBsSort(sortInfo.getBsSort()==null?1:sortInfo.getBsSort()+1);
return sortInfo ; return sortInfo ;
} }
@ -170,10 +181,18 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl<IotVisualGroupMap
} }
//组排序 //组排序
sortInfo.forEach(temp->{ sortInfo.forEach(temp->{
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<IotVisualGroupMap
Long tenantCode = UserContext.getTenantCode(); Long tenantCode = UserContext.getTenantCode();
QueryWrapper wrapper = new QueryWrapper(); QueryWrapper wrapper = new QueryWrapper();
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.SORT).as("sort"), IOT_VISUAL_GROUP_ENTITY.NAME.as("name"))
.from(IOT_VISUAL_GROUP_ENTITY).eq(IotVisualGroupEntity::getType,type); .from(IOT_VISUAL_GROUP_ENTITY).eq(IotVisualGroupEntity::getType,type);
//本企业得or 默认得 //本企业得or 默认得
wrapper.and(IOT_VISUAL_GROUP_ENTITY.TENANT_CODE.eq(tenantCode).or(IOT_VISUAL_GROUP_ENTITY.IS_DEFAULT.eq("1"))); 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,StringUtils.isNotEmpty(name));
wrapper.groupBy(IOT_VISUAL_GROUP_ENTITY.NAME).orderBy(IOT_VISUAL_GROUP_ENTITY.SORT,true);
return this.mapper.selectListByQueryAs(wrapper,NameSort.class); return this.mapper.selectListByQueryAs(wrapper,NameSort.class);
} }
@Override
public String deleteGroup(String name, String type) {
QueryWrapper wrapper = new QueryWrapper();
wrapper.eq(IotVisualGroupEntity::getName,name);
wrapper.eq(IotVisualGroupEntity::getType,type);
List<IotVisualGroupEntity> entities = this.list(wrapper);
List<Long> groupIds = entities.stream()
.map(IotVisualGroupEntity::getId)
.toList();
//素材or部件 有被引用则不允许删除
List<IotNewSourceMaterialEntity> materialList = iotNewSourceMaterialService.getInfoByGroupIds(groupIds);
if(ObjectUtils.isNotEmpty(materialList)){
return "当前组下有类型被引用,不允许删除!";
}
List<IotVisualComponentEntity> 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<List<GroupInfoFormatDTO>> listTree(String type, String name) {
List<GroupInfoFormatDTO> resultList = new ArrayList<>();
QueryWrapper queryWrapper = QueryWrapper.create();
queryWrapper.eq(IotVisualGroupEntity::getType,type);
queryWrapper.like(IotVisualGroupEntity::getName,name);
List<IotVisualGroupDTO> infos = listAs(queryWrapper, IotVisualGroupDTO.class);
Map<String, List<IotVisualGroupDTO>> 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<IotVisualGroupDTO> 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<List<GroupInfoFormatDTO>>().ok(resultList.parallelStream().sorted(Comparator.comparingLong(GroupInfoFormatDTO::getSort)).collect(Collectors.toList()));
}
/** /**
* 获取所有排序信息看没有没有穿name传name了就是组内排序没传name就是组排序 * 获取所有排序信息看没有没有穿name传name了就是组内排序没传name就是组排序
@ -197,14 +272,14 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl<IotVisualGroupMap
* @return * @return
*/ */
private List<NameSort> getNameSort(String name,String type){ private List<NameSort> getNameSort(String name,String type){
Long tenantCode = UserContext.getTenantCode();
Long tenantCode = UserContext.getTenantCode();
QueryWrapper wrapper = new QueryWrapper(); QueryWrapper wrapper = new QueryWrapper();
if(ObjectUtils.isNotEmpty(name)){ 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); .from(IOT_VISUAL_GROUP_ENTITY).eq(IotVisualGroupEntity::getType,type);
//本企业得or 默认得 //本企业得or 默认得
wrapper.and(IOT_VISUAL_GROUP_ENTITY.TENANT_CODE.eq(tenantCode).or(IOT_VISUAL_GROUP_ENTITY.IS_DEFAULT.eq("1"))); 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 { }else {
wrapper.select(max(IOT_VISUAL_GROUP_ENTITY.SORT).as("sort"), IOT_VISUAL_GROUP_ENTITY.NAME.as("name")) 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); .from(IOT_VISUAL_GROUP_ENTITY).eq(IotVisualGroupEntity::getType,type);
@ -222,9 +297,16 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl<IotVisualGroupMap
* @param toIndex * @param toIndex
*/ */
private static void moveItem(List<NameSort> list, int fromIndex, int toIndex,String name) { private static void moveItem(List<NameSort> 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"); throw new IndexOutOfBoundsException("Invalid index");
} }
if(toIndex < 0 ){
toIndex=0;
}
if(toIndex >= list.size()){
toIndex= list.size()-1;
}
NameSort item = list.remove(fromIndex); NameSort item = list.remove(fromIndex);
if(ObjectUtils.isNotEmpty(name)){ if(ObjectUtils.isNotEmpty(name)){
item.setName(name); item.setName(name);

Loading…
Cancel
Save