|
|
|
@ -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<IotVisualGroupMapper, IotVisualGroupEntity> implements IotVisualGroupService { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private IotNewSourceMaterialService iotNewSourceMaterialService; |
|
|
|
@Autowired |
|
|
|
private IotVisualComponentService iotVisualComponentService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public QueryWrapper getWrapper(Map<String, Object> params){ |
|
|
|
Long tenantCode = UserContext.getTenantCode(); |
|
|
|
QueryWrapper wrapper = new QueryWrapper(); |
|
|
|
String name = MapUtils.getString(params,"name"); |
|
|
|
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"); |
|
|
|
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<IotVisualGroupMap |
|
|
|
|
|
|
|
@Override |
|
|
|
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.setBsSort(groupSortInfo.getBsSort()); |
|
|
|
this.saveDto(dto); |
|
|
|
@ -82,17 +91,17 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl<IotVisualGroupMap |
|
|
|
updateSortValues(sortInfo); |
|
|
|
} |
|
|
|
sortInfo.forEach(temp->{ |
|
|
|
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<IotVisualGroupMap |
|
|
|
.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); |
|
|
|
wrapper.eq(IotVisualGroupEntity::getName,name); |
|
|
|
} |
|
|
|
GroupSortInfo sortInfo = this.mapper.selectOneByQueryAs(wrapper,GroupSortInfo.class); |
|
|
|
if(ObjectUtils.isEmpty(sortInfo)){ |
|
|
|
sortInfo = new GroupSortInfo(); |
|
|
|
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; |
|
|
|
} |
|
|
|
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); |
|
|
|
return sortInfo ; |
|
|
|
} |
|
|
|
@ -170,10 +181,18 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl<IotVisualGroupMap |
|
|
|
} |
|
|
|
//组排序 |
|
|
|
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(); |
|
|
|
|
|
|
|
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); |
|
|
|
//本企业得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,StringUtils.isNotEmpty(name)); |
|
|
|
wrapper.groupBy(IOT_VISUAL_GROUP_ENTITY.NAME).orderBy(IOT_VISUAL_GROUP_ENTITY.SORT,true); |
|
|
|
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就是组排序 |
|
|
|
@ -197,14 +272,14 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl<IotVisualGroupMap |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private List<NameSort> 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<IotVisualGroupMap |
|
|
|
* @param toIndex |
|
|
|
*/ |
|
|
|
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"); |
|
|
|
} |
|
|
|
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); |
|
|
|
|