|
|
@ -1,14 +1,32 @@ |
|
|
package com.thing.visual.component.service.impl; |
|
|
package com.thing.visual.component.service.impl; |
|
|
|
|
|
|
|
|
import com.mybatisflex.core.query.QueryWrapper; |
|
|
import com.mybatisflex.core.query.QueryWrapper; |
|
|
|
|
|
import com.mybatisflex.core.update.UpdateChain; |
|
|
|
|
|
import com.thing.common.core.web.response.PageData; |
|
|
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.component.dto.AdjustSortInfo; |
|
|
|
|
|
import com.thing.visual.component.dto.ComponentSortInfo; |
|
|
|
|
|
import com.thing.visual.component.dto.GroupInfo; |
|
|
|
|
|
import com.thing.visual.component.dto.IotVisualComponentDTO; |
|
|
import com.thing.visual.component.entity.IotVisualComponentEntity; |
|
|
import com.thing.visual.component.entity.IotVisualComponentEntity; |
|
|
import com.thing.visual.component.mapper.IotVisualComponentMapper; |
|
|
import com.thing.visual.component.mapper.IotVisualComponentMapper; |
|
|
import com.thing.visual.component.service.IotVisualComponentService; |
|
|
import com.thing.visual.component.service.IotVisualComponentService; |
|
|
|
|
|
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 org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
import static com.mybatisflex.core.query.QueryMethods.max; |
|
|
|
|
|
import static com.thing.visual.component.entity.table.IotVisualComponentEntityTableDef.IOT_VISUAL_COMPONENT_ENTITY; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 部件设计信息 |
|
|
* 部件设计信息 |
|
|
@ -19,9 +37,26 @@ import java.util.Map; |
|
|
@Service |
|
|
@Service |
|
|
public class IotVisualComponentServiceImpl extends BaseServiceImpl<IotVisualComponentMapper, IotVisualComponentEntity> implements IotVisualComponentService { |
|
|
public class IotVisualComponentServiceImpl extends BaseServiceImpl<IotVisualComponentMapper, IotVisualComponentEntity> implements IotVisualComponentService { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private IotVisualGroupService iotVisualGroupService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public QueryWrapper getWrapper(Map<String, Object> params){ |
|
|
public QueryWrapper getWrapper(Map<String, Object> params){ |
|
|
QueryWrapper wrapper = new QueryWrapper(); |
|
|
QueryWrapper wrapper = new QueryWrapper(); |
|
|
|
|
|
String name = MapUtils.getString(params,"name"); |
|
|
|
|
|
String groupIds = MapUtils.getString(params,"names"); |
|
|
|
|
|
List<Long> groupIdList = null; |
|
|
|
|
|
if(StringUtils.isNotEmpty(groupIds)){ |
|
|
|
|
|
groupIdList = Arrays.stream(groupIds.split(",")) |
|
|
|
|
|
.map(String::trim) // 去掉可能的空格 |
|
|
|
|
|
.map(Long::parseLong) // 将每个字符串转换为 Long |
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
} |
|
|
|
|
|
wrapper.in(IotVisualComponentEntity::getGroupId,groupIdList,ObjectUtils.isNotEmpty(groupIdList)); |
|
|
|
|
|
wrapper.like(IotVisualComponentEntity::getName,name,StringUtils.isNotEmpty(name)); |
|
|
return wrapper; |
|
|
return wrapper; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -32,4 +67,143 @@ public class IotVisualComponentServiceImpl extends BaseServiceImpl<IotVisualComp |
|
|
wrapper.eq( "group_id", groupIds); |
|
|
wrapper.eq( "group_id", groupIds); |
|
|
return this.mapper.selectListByQuery(wrapper); |
|
|
return this.mapper.selectListByQuery(wrapper); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public Integer getSort(Long groupId) { |
|
|
|
|
|
Long tenantCode = UserContext.getTenantCode(); |
|
|
|
|
|
QueryWrapper wrapper = new QueryWrapper(); |
|
|
|
|
|
wrapper.select(max(IOT_VISUAL_COMPONENT_ENTITY.SORT).as("sort")) |
|
|
|
|
|
.from(IOT_VISUAL_COMPONENT_ENTITY).eq(IotVisualComponentEntity::getGroupId,groupId); |
|
|
|
|
|
wrapper.and(IOT_VISUAL_COMPONENT_ENTITY.TENANT_CODE.eq(tenantCode).or(IOT_VISUAL_COMPONENT_ENTITY.IS_DEFAULT.eq("1"))); |
|
|
|
|
|
Integer number = this.mapper.selectOneByQueryAs(wrapper,Integer.class); |
|
|
|
|
|
if(ObjectUtils.isEmpty(number)){ |
|
|
|
|
|
return 1; |
|
|
|
|
|
} |
|
|
|
|
|
return number; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public List<GroupInfo> businessList() { |
|
|
|
|
|
QueryWrapper wrapper = new QueryWrapper(); |
|
|
|
|
|
wrapper.eq("name","远程组件"); |
|
|
|
|
|
wrapper.orderBy("bs_sort",true); |
|
|
|
|
|
return iotVisualGroupService.listAs(wrapper,GroupInfo.class); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public String adjustSort(AdjustSortInfo sortInfo) { |
|
|
|
|
|
List<ComponentSortInfo> sortInfos = this.getComponentSortInfo(sortInfo.getGroupId()); |
|
|
|
|
|
moveItem(sortInfos,sortInfo.getCurrentSort()-1,sortInfo.getUpSort()-1,null); |
|
|
|
|
|
updateSortValues(sortInfos); |
|
|
|
|
|
sortInfos.forEach(temp->{ |
|
|
|
|
|
UpdateChain.of(IotVisualGroupEntity.class) |
|
|
|
|
|
.set(IotVisualGroupEntity::getSort, temp.getSort()) |
|
|
|
|
|
.where(IotVisualGroupEntity::getId).eq(temp.getId()) |
|
|
|
|
|
.update(); |
|
|
|
|
|
}); |
|
|
|
|
|
return "排序成功!"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public PageData<IotVisualComponentDTO> getPageDataInfo(Map<String, Object> params) { |
|
|
|
|
|
|
|
|
|
|
|
PageData<IotVisualComponentDTO> dtoPageData = this.getPageData(params,IotVisualComponentDTO.class); |
|
|
|
|
|
|
|
|
|
|
|
dtoPageData.getList().forEach(temp->{ |
|
|
|
|
|
IotVisualGroupEntity group = iotVisualGroupService.getById(temp.getGroupId()); |
|
|
|
|
|
temp.setGroupName(group.getName()); |
|
|
|
|
|
temp.setGroupBusinessName(group.getBusinessName()); |
|
|
|
|
|
}); |
|
|
|
|
|
return dtoPageData; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public IotVisualComponentDTO getByIdDto(Long id) { |
|
|
|
|
|
IotVisualComponentDTO data = this.getByIdAs(id,IotVisualComponentDTO.class); |
|
|
|
|
|
|
|
|
|
|
|
IotVisualGroupEntity group = iotVisualGroupService.getById(data.getGroupId()); |
|
|
|
|
|
data.setGroupName(group.getName()); |
|
|
|
|
|
data.setGroupBusinessName(group.getBusinessName()); |
|
|
|
|
|
|
|
|
|
|
|
return data; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void updateIotVisualComponentDTO(IotVisualComponentDTO dto) { |
|
|
|
|
|
if(ObjectUtils.isNotEmpty(dto.getOldSort())){ |
|
|
|
|
|
List<ComponentSortInfo> sortInfos = this.getComponentSortInfo(dto.getGroupId()); |
|
|
|
|
|
|
|
|
|
|
|
moveItem(sortInfos,dto.getOldSort()-1,dto.getSort()-1,dto.getName()); |
|
|
|
|
|
//重置sort字段 |
|
|
|
|
|
updateSortValues(sortInfos); |
|
|
|
|
|
sortInfos.forEach(temp->{ |
|
|
|
|
|
UpdateChain.of(IotVisualComponentEntity.class) |
|
|
|
|
|
.set(IotVisualComponentEntity::getSort, temp.getSort()) |
|
|
|
|
|
.set(IotVisualComponentEntity::getName,dto.getName()) |
|
|
|
|
|
.set(IotVisualComponentEntity::getThumbnailUrl,dto.getThumbnailUrl()) |
|
|
|
|
|
.set(IotVisualComponentEntity::getRemarks,dto.getRemarks()) |
|
|
|
|
|
.set(IotVisualComponentEntity::getDesc,dto.getDesc()) |
|
|
|
|
|
.set(IotVisualComponentEntity::getHash,dto.getHash()) |
|
|
|
|
|
.set(IotVisualComponentEntity::getPreviewOptions,dto.getPreviewOptions()) |
|
|
|
|
|
.set(IotVisualComponentEntity::getIsDefault,dto.getIsDefault()) |
|
|
|
|
|
.where(IotVisualComponentEntity::getId).eq(temp.getId()) |
|
|
|
|
|
.update(); |
|
|
|
|
|
}); |
|
|
|
|
|
}else { |
|
|
|
|
|
this.updateDto(dto); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<ComponentSortInfo> getComponentSortInfo(Long groupId){ |
|
|
|
|
|
QueryWrapper wrapper = new QueryWrapper(); |
|
|
|
|
|
wrapper.eq("group_id",groupId); |
|
|
|
|
|
wrapper.orderBy("sort",true); |
|
|
|
|
|
return this.listAs(wrapper,ComponentSortInfo.class); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 删除原坐标,在新的坐标插入我的对象 |
|
|
|
|
|
* @param list |
|
|
|
|
|
* @param fromIndex |
|
|
|
|
|
* @param toIndex |
|
|
|
|
|
*/ |
|
|
|
|
|
private static void moveItem(List<ComponentSortInfo> list, int fromIndex, int toIndex, String name) { |
|
|
|
|
|
if (fromIndex < 0 || fromIndex >= list.size()) { |
|
|
|
|
|
throw new IndexOutOfBoundsException("Invalid index"); |
|
|
|
|
|
} |
|
|
|
|
|
if(toIndex < 0 ){ |
|
|
|
|
|
toIndex=0; |
|
|
|
|
|
} |
|
|
|
|
|
if(toIndex >= list.size()){ |
|
|
|
|
|
toIndex= list.size()-1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ComponentSortInfo item = list.remove(fromIndex); |
|
|
|
|
|
if(ObjectUtils.isNotEmpty(name)){ |
|
|
|
|
|
item.setName(name); |
|
|
|
|
|
} |
|
|
|
|
|
list.add(toIndex, item); |
|
|
|
|
|
updateSortValues(list); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 重新修改 name中对应的sort信息 |
|
|
|
|
|
* @param list |
|
|
|
|
|
*/ |
|
|
|
|
|
private static void updateSortValues(List<ComponentSortInfo> list) { |
|
|
|
|
|
Integer sortValue = 1; |
|
|
|
|
|
for (ComponentSortInfo item : list) { |
|
|
|
|
|
item.setSort(sortValue++); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |