|
|
|
@ -1,16 +1,20 @@ |
|
|
|
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.orm.service.impl.BaseServiceImpl; |
|
|
|
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.visual.group.mapper.IotVisualGroupMapper; |
|
|
|
import com.thing.visual.group.entity.IotVisualGroupEntity; |
|
|
|
import com.thing.visual.group.service.IotVisualGroupService; |
|
|
|
import org.apache.commons.lang3.ObjectUtils; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import static com.mybatisflex.core.query.QueryMethods.max; |
|
|
|
@ -69,6 +73,80 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl<IotVisualGroupMap |
|
|
|
|
|
|
|
@Override |
|
|
|
public String adjustGroupSort(AdjustGroupDto dto) { |
|
|
|
return null; |
|
|
|
List<NameSort> sortInfo = this.getNameSort(dto.getName()); |
|
|
|
//修改排序 |
|
|
|
moveItem(sortInfo,dto.getCurrentSort()-1,dto.getUpSort()-1); |
|
|
|
//重置sort字段 |
|
|
|
updateSortValues(sortInfo); |
|
|
|
|
|
|
|
if(ObjectUtils.isNotEmpty(dto.getName())){ |
|
|
|
//组内排序 |
|
|
|
sortInfo.forEach(temp->{ |
|
|
|
UpdateChain.of(IotVisualGroupEntity.class) |
|
|
|
.set(IotVisualGroupEntity::getSort, temp.getSort()) |
|
|
|
.where(IotVisualGroupEntity::getName).eq(dto.getName()).eq(IotVisualGroupEntity::getBusinessName,temp.getName()) |
|
|
|
.update(); |
|
|
|
}); |
|
|
|
}else { |
|
|
|
//组排序 |
|
|
|
sortInfo.forEach(temp->{ |
|
|
|
UpdateChain.of(IotVisualGroupEntity.class) |
|
|
|
.set(IotVisualGroupEntity::getSort, temp.getSort()) |
|
|
|
.where(IotVisualGroupEntity::getName).eq(temp.getName()) |
|
|
|
.update(); |
|
|
|
}); |
|
|
|
} |
|
|
|
return "ok"; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 获取所有信息,看没有没有穿name,传name了,就是组内排序,没传name就是组排序 |
|
|
|
* @param name |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private List<NameSort> getNameSort(String name){ |
|
|
|
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")) |
|
|
|
.from(IOT_VISUAL_GROUP_ENTITY); |
|
|
|
wrapper.eq(IotVisualGroupEntity::getName,name).groupBy(IOT_VISUAL_GROUP_ENTITY.NAME).orderBy(IOT_VISUAL_GROUP_ENTITY.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); |
|
|
|
wrapper.groupBy(IOT_VISUAL_GROUP_ENTITY.NAME).orderBy(IOT_VISUAL_GROUP_ENTITY.SORT,true);; |
|
|
|
} |
|
|
|
return this.mapper.selectListByQueryAs(wrapper,NameSort.class); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 删除原坐标,在新的坐标插入我的对象 |
|
|
|
* @param list |
|
|
|
* @param fromIndex |
|
|
|
* @param toIndex |
|
|
|
*/ |
|
|
|
private static void moveItem(List<NameSort> list, int fromIndex, int toIndex) { |
|
|
|
if (fromIndex < 0 || fromIndex >= list.size() || toIndex < 0 || toIndex >= list.size()) { |
|
|
|
throw new IndexOutOfBoundsException("Invalid index"); |
|
|
|
} |
|
|
|
NameSort item = list.remove(fromIndex); |
|
|
|
list.add(toIndex, item); |
|
|
|
updateSortValues(list); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 重新修改 name中对应的sort信息 |
|
|
|
* @param list |
|
|
|
*/ |
|
|
|
private static void updateSortValues(List<NameSort> list) { |
|
|
|
long sortValue = 1L; |
|
|
|
for (NameSort item : list) { |
|
|
|
item.setSort(sortValue++); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |