|
|
@ -4,6 +4,7 @@ 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.mybatisflex.core.update.UpdateWrapper; |
|
|
import com.thing.common.orm.service.impl.BaseServiceImpl; |
|
|
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.AdjustGroupDto; |
|
|
import com.thing.visual.group.dto.GroupSortInfo; |
|
|
import com.thing.visual.group.dto.GroupSortInfo; |
|
|
import com.thing.visual.group.dto.IotVisualGroupDTO; |
|
|
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.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.lang3.ObjectUtils; |
|
|
import org.apache.commons.lang3.ObjectUtils; |
|
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
@ -32,50 +36,100 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl<IotVisualGroupMap |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public QueryWrapper getWrapper(Map<String, Object> params){ |
|
|
public QueryWrapper getWrapper(Map<String, Object> params){ |
|
|
|
|
|
Long tenantCode = UserContext.getTenantCode(); |
|
|
QueryWrapper wrapper = new QueryWrapper(); |
|
|
QueryWrapper wrapper = new QueryWrapper(); |
|
|
|
|
|
String name = MapUtils.getString(params,"name"); |
|
|
|
|
|
String names = MapUtils.getString(params,"names"); |
|
|
|
|
|
List<String> 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; |
|
|
return wrapper; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@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()); |
|
|
|
|
|
} |
|
|
|
|
|
dto.setSort(groupSortInfo.getSort()); |
|
|
|
|
|
dto.setBsSort(groupSortInfo.getBsSort()); |
|
|
|
|
|
this.saveDto(dto); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void updateIotVisualGroupDTO(IotVisualGroupDTO dto) { |
|
|
public void updateIotVisualGroupDTO(IotVisualGroupDTO dto) { |
|
|
|
|
|
|
|
|
|
|
|
List<NameSort> 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 |
|
|
@Override |
|
|
public GroupSortInfo groupSortInfo(String name) { |
|
|
|
|
|
|
|
|
public GroupSortInfo groupSortInfo(String name,String type) { |
|
|
|
|
|
Long tenantCode = UserContext.getTenantCode(); |
|
|
QueryWrapper wrapper = new QueryWrapper(); |
|
|
QueryWrapper wrapper = new QueryWrapper(); |
|
|
wrapper.select(max(IOT_VISUAL_GROUP_ENTITY.SORT).as("sort"), max(IOT_VISUAL_GROUP_ENTITY.BS_SORT).as("bs_sort")) |
|
|
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)){ |
|
|
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(1L); |
|
|
|
|
|
sortInfo.setSort(1L); |
|
|
|
|
|
|
|
|
sortInfo.setBsSort(1); |
|
|
|
|
|
sortInfo.setSort(1); |
|
|
return sortInfo; |
|
|
return sortInfo; |
|
|
} |
|
|
} |
|
|
if(ObjectUtils.isNotEmpty(name)){ |
|
|
if(ObjectUtils.isNotEmpty(name)){ |
|
|
sortInfo.setSort(sortInfo.getSort()==null?1L:sortInfo.getSort()); |
|
|
|
|
|
|
|
|
sortInfo.setSort(sortInfo.getSort()==null?1:sortInfo.getSort()); |
|
|
}else { |
|
|
}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 ; |
|
|
return sortInfo ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public String adjustGroupSort(AdjustGroupDto dto) { |
|
|
public String adjustGroupSort(AdjustGroupDto dto) { |
|
|
List<NameSort> sortInfo = this.getNameSort(dto.getName()); |
|
|
|
|
|
|
|
|
List<NameSort> 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字段 |
|
|
//重置sort字段 |
|
|
updateSortValues(sortInfo); |
|
|
updateSortValues(sortInfo); |
|
|
|
|
|
|
|
|
@ -99,24 +153,62 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl<IotVisualGroupMap |
|
|
return "ok"; |
|
|
return "ok"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void updateGroup(IotVisualGroupDTO dto) { |
|
|
|
|
|
//修改一级得组,名称or排序 |
|
|
|
|
|
List<NameSort> 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<NameSort> 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 |
|
|
* @param name |
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
private List<NameSort> getNameSort(String name){ |
|
|
|
|
|
|
|
|
private List<NameSort> getNameSort(String name,String type){ |
|
|
|
|
|
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.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); |
|
|
wrapper.eq(IotVisualGroupEntity::getName,name).groupBy(IOT_VISUAL_GROUP_ENTITY.NAME).orderBy(IOT_VISUAL_GROUP_ENTITY.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); |
|
|
|
|
|
|
|
|
.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);; |
|
|
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); |
|
|
@ -129,11 +221,14 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl<IotVisualGroupMap |
|
|
* @param fromIndex |
|
|
* @param fromIndex |
|
|
* @param toIndex |
|
|
* @param toIndex |
|
|
*/ |
|
|
*/ |
|
|
private static void moveItem(List<NameSort> list, int fromIndex, int 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() || toIndex < 0 || toIndex >= list.size()) { |
|
|
throw new IndexOutOfBoundsException("Invalid index"); |
|
|
throw new IndexOutOfBoundsException("Invalid index"); |
|
|
} |
|
|
} |
|
|
NameSort item = list.remove(fromIndex); |
|
|
NameSort item = list.remove(fromIndex); |
|
|
|
|
|
if(ObjectUtils.isNotEmpty(name)){ |
|
|
|
|
|
item.setName(name); |
|
|
|
|
|
} |
|
|
list.add(toIndex, item); |
|
|
list.add(toIndex, item); |
|
|
updateSortValues(list); |
|
|
updateSortValues(list); |
|
|
} |
|
|
} |
|
|
@ -143,7 +238,7 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl<IotVisualGroupMap |
|
|
* @param list |
|
|
* @param list |
|
|
*/ |
|
|
*/ |
|
|
private static void updateSortValues(List<NameSort> list) { |
|
|
private static void updateSortValues(List<NameSort> list) { |
|
|
long sortValue = 1L; |
|
|
|
|
|
|
|
|
Integer sortValue = 1; |
|
|
for (NameSort item : list) { |
|
|
for (NameSort item : list) { |
|
|
item.setSort(sortValue++); |
|
|
item.setSort(sortValue++); |
|
|
} |
|
|
} |
|
|
|