Browse Source

组态设计,部件设计代码提交

thing_master
xiachao 1 year ago
parent
commit
5a5fea2881
  1. 34
      modules/visual-design/src/main/java/com/thing/visual/component/controller/IotVisualComponentController.java
  2. 20
      modules/visual-design/src/main/java/com/thing/visual/component/dto/AdjustSortInfo.java
  3. 30
      modules/visual-design/src/main/java/com/thing/visual/component/dto/ComponentSortInfo.java
  4. 18
      modules/visual-design/src/main/java/com/thing/visual/component/dto/GroupInfo.java
  5. 12
      modules/visual-design/src/main/java/com/thing/visual/component/dto/IotVisualComponentDTO.java
  6. 2
      modules/visual-design/src/main/java/com/thing/visual/component/entity/IotVisualComponentEntity.java
  7. 16
      modules/visual-design/src/main/java/com/thing/visual/component/service/IotVisualComponentService.java
  8. 174
      modules/visual-design/src/main/java/com/thing/visual/component/service/impl/IotVisualComponentServiceImpl.java
  9. 2
      modules/visual-design/src/main/java/com/thing/visual/group/service/impl/IotVisualGroupServiceImpl.java

34
modules/visual-design/src/main/java/com/thing/visual/component/controller/IotVisualComponentController.java

@ -9,6 +9,8 @@ import com.thing.common.core.validator.group.DefaultGroup;
import com.thing.common.core.validator.group.UpdateGroup;
import com.thing.common.core.web.response.PageData;
import com.thing.common.core.web.response.Result;
import com.thing.visual.component.dto.AdjustSortInfo;
import com.thing.visual.component.dto.GroupInfo;
import com.thing.visual.component.dto.IotVisualComponentDTO;
import com.thing.visual.component.service.IotVisualComponentService;
@ -19,6 +21,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
@ -41,17 +44,19 @@ public class IotVisualComponentController {
@Parameter(name = Constant.PAGE, description = "当前页码,从1开始", required = true) ,
@Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true) ,
@Parameter(name = Constant.ORDER_FIELD, description = "排序字段") ,
@Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)")
@Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)"),
@Parameter(name = "groupIds", description = "组id,多个组id以英文逗号分隔"),
@Parameter(name = "name", description = "部件名称")
})
public Result<PageData<IotVisualComponentDTO>> page(@Parameter(hidden = true) @RequestParam Map<String, Object> params){
PageData<IotVisualComponentDTO> page = iotVisualComponentService.getPageData(params, IotVisualComponentDTO.class);
PageData<IotVisualComponentDTO> page = iotVisualComponentService.getPageDataInfo(params);
return new Result<PageData<IotVisualComponentDTO>>().ok(page);
}
@GetMapping("{id}")
@Operation(summary="信息")
public Result<IotVisualComponentDTO> get(@PathVariable("id") Long id){
IotVisualComponentDTO data = iotVisualComponentService.getByIdAs(id, IotVisualComponentDTO.class);
IotVisualComponentDTO data = iotVisualComponentService.getByIdDto(id);
return new Result<IotVisualComponentDTO>().ok(data);
}
@ -71,7 +76,7 @@ public class IotVisualComponentController {
public Result<Void> update(@RequestBody IotVisualComponentDTO dto){
//效验数据
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
iotVisualComponentService.updateDto(dto);
iotVisualComponentService.updateIotVisualComponentDTO(dto);
return new Result<>();
}
@ -86,4 +91,25 @@ public class IotVisualComponentController {
}
@GetMapping("sort")
@Operation(summary="当前组的最大序号")
public Result<Integer> getSort(@RequestParam("groupId") Long groupId){
Integer sort = iotVisualComponentService.getSort(groupId);
return new Result<Integer>().ok(sort);
}
@GetMapping("businessList")
@Operation(summary="定制接口,获取 远程组件 类型列表,新增组件的时候使用")
public Result<List<GroupInfo>> businessList(){
List<GroupInfo> businessList = iotVisualComponentService.businessList();
return new Result<List<GroupInfo>>().ok(businessList);
}
@GetMapping("adjustSort")
@Operation(summary="拖动修改排序")
public Result<String> adjustSort(AdjustSortInfo sortInfo){
String data = iotVisualComponentService.adjustSort(sortInfo);
return new Result<String>().ok(data);
}
}

20
modules/visual-design/src/main/java/com/thing/visual/component/dto/AdjustSortInfo.java

@ -0,0 +1,20 @@
package com.thing.visual.component.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
@Schema(description = "部件拖动排序入参")
public class AdjustSortInfo {
@Schema(description = "部件id")
private Long id;
@Schema(description = "部件组类型id")
private Long groupId;
@Schema(description = "原始序号")
private Integer currentSort;
@Schema(description = "被移动的序号")
private Integer upSort;
}

30
modules/visual-design/src/main/java/com/thing/visual/component/dto/ComponentSortInfo.java

@ -0,0 +1,30 @@
package com.thing.visual.component.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* 部件设计信息
*
* @author xc
* @since 3.0 2024-08-21
*/
@Data
@Schema(description = "部件设计信息")
public class ComponentSortInfo implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "部件id")
private Long id;
@Schema(description = "部件名称")
private String name;
@Schema(description = "部件组id")
private Integer groupId;
@Schema(description = "部件排序序号")
private Integer sort;
}

18
modules/visual-design/src/main/java/com/thing/visual/component/dto/GroupInfo.java

@ -0,0 +1,18 @@
package com.thing.visual.component.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
@Schema(name = "组类型信息")
public class GroupInfo {
@Schema(name = "id")
private Long id;
@Schema(name = "组类型名称")
private String businessName;
}

12
modules/visual-design/src/main/java/com/thing/visual/component/dto/IotVisualComponentDTO.java

@ -24,7 +24,13 @@ public class IotVisualComponentDTO implements Serializable {
@Schema(description = "部件名称")
private String name;
@Schema(description = "部件组id")
private Integer groupId;
private Long groupId;
@Schema(description = "部件组名称")
private String groupName;
@Schema(description = "部件组类型名称")
private String groupBusinessName;
@Schema(description = "部件类型")
private String type;
@Schema(description = "部件备注描述")
@ -56,4 +62,8 @@ public class IotVisualComponentDTO implements Serializable {
@Schema(description = "部件排序序号")
private Integer sort;
private Integer oldSort;
}

2
modules/visual-design/src/main/java/com/thing/visual/component/entity/IotVisualComponentEntity.java

@ -31,7 +31,7 @@ public class IotVisualComponentEntity extends BaseInfoEntity implements Serializ
/**
* 部件组id
*/
private Integer groupId;
private Long groupId;
/**
* 部件类型
*/

16
modules/visual-design/src/main/java/com/thing/visual/component/service/IotVisualComponentService.java

@ -1,9 +1,14 @@
package com.thing.visual.component.service;
import com.thing.common.core.web.response.PageData;
import com.thing.common.orm.service.IBaseService;
import com.thing.visual.component.dto.AdjustSortInfo;
import com.thing.visual.component.dto.GroupInfo;
import com.thing.visual.component.dto.IotVisualComponentDTO;
import com.thing.visual.component.entity.IotVisualComponentEntity;
import java.util.List;
import java.util.Map;
/**
* 部件设计信息
@ -14,4 +19,15 @@ import java.util.List;
public interface IotVisualComponentService extends IBaseService<IotVisualComponentEntity> {
List<IotVisualComponentEntity> getInfoByGroupIds(List<Long> groupIds);
Integer getSort(Long groupId);
List<GroupInfo> businessList();
String adjustSort(AdjustSortInfo sortInfo);
void updateIotVisualComponentDTO(IotVisualComponentDTO dto);
PageData<IotVisualComponentDTO> getPageDataInfo(Map<String, Object> params);
IotVisualComponentDTO getByIdDto(Long id);
}

174
modules/visual-design/src/main/java/com/thing/visual/component/service/impl/IotVisualComponentServiceImpl.java

@ -1,14 +1,32 @@
package com.thing.visual.component.service.impl;
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.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.mapper.IotVisualComponentMapper;
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 java.util.Arrays;
import java.util.List;
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
public class IotVisualComponentServiceImpl extends BaseServiceImpl<IotVisualComponentMapper, IotVisualComponentEntity> implements IotVisualComponentService {
@Autowired
private IotVisualGroupService iotVisualGroupService;
@Override
public QueryWrapper getWrapper(Map<String, Object> params){
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;
}
@ -32,4 +67,143 @@ public class IotVisualComponentServiceImpl extends BaseServiceImpl<IotVisualComp
wrapper.eq( "group_id", groupIds);
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++);
}
}
}

2
modules/visual-design/src/main/java/com/thing/visual/group/service/impl/IotVisualGroupServiceImpl.java

@ -148,7 +148,7 @@ public class IotVisualGroupServiceImpl extends BaseServiceImpl<IotVisualGroupMap
//组内排序
sortInfo.forEach(temp->{
UpdateChain.of(IotVisualGroupEntity.class)
.set(IotVisualGroupEntity::getSort, temp.getSort())
.set(IotVisualGroupEntity::getBsSort, temp.getSort())
.where(IotVisualGroupEntity::getName).eq(dto.getName()).eq(IotVisualGroupEntity::getBusinessName,temp.getName())
.update();
});

Loading…
Cancel
Save