das接口修改

This commit is contained in:
chenhaojie 2024-08-02 16:24:09 +08:00
parent a98a7d94db
commit 648169ac57
14 changed files with 203 additions and 51 deletions

View File

@ -21,4 +21,8 @@ public interface SysIotModelMapper extends BaseMapper<SysIotModel> {
List<SysIotModelVo> getSysIotModelByType(Integer objectType);
String getIotModelFieldCode(Integer objectType);
String getIotModelServiceCode(Integer objectType);
}

View File

@ -2,10 +2,13 @@ package com.das.modules.node.command;
import com.das.common.utils.AdminRedisTemplate;
import com.das.common.utils.StringUtils;
import com.das.modules.node.constant.NodeConstant;
import com.das.modules.node.domain.bo.TerminalMessage;
import com.fasterxml.jackson.databind.JsonNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service(value = NodeConstant.HEARTBEAT)
public class HeartbeatCommand implements BaseCommand{
@Autowired

View File

@ -7,4 +7,6 @@ public interface NodeConstant {
String REMOTE_IP = "remoteIp";
String LAST_PONG_TIME = "LastPongTime";
String HEARTBEAT = "heartbeat";
}

View File

@ -9,12 +9,18 @@ import com.das.common.utils.PageDataInfo;
import com.das.modules.node.domain.dto.*;
import com.das.modules.node.domain.vo.*;
import com.das.modules.node.service.SysNodeService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@ -152,10 +158,10 @@ public class SysNodeController {
public R<?> getMappingList(@RequestBody SysImptabmappingDto sysImptabmappingDto) {
//判断是否有权限
boolean hasPermission = StpUtil.hasPermission(SysAuthorityIds.SYS_AUTHORITY_ID_DEVICE_MGR.toString());
if(!hasPermission){
return R.fail("没有节点管理权限");
}
// boolean hasPermission = StpUtil.hasPermission(SysAuthorityIds.SYS_AUTHORITY_ID_DEVICE_MGR.toString());
// if(!hasPermission){
// return R.fail("没有节点管理权限");
// }
if (sysImptabmappingDto.getLinkId() == null) {
throw new ServiceException("参数缺失");
}
@ -204,5 +210,24 @@ public class SysNodeController {
sysNodeService.saveMappingList(impList);
return R.success();
}
/** 导出测点信息成json文件 */
@PostMapping("/link/exportMappingList")
public void exportMappingList(HttpServletRequest request, HttpServletResponse response, @RequestBody SysImptabmappingDto sysImptabmappingDto) throws IOException {
sysNodeService.exportMappingList(sysImptabmappingDto,request,response);
}
/** 导入测点信息json文件 */
@PostMapping("/link/importMappingList")
public R<?> importMappingList(String id, @RequestParam("file") MultipartFile file) {
boolean result = sysNodeService.importMappingList(id, file);
if (result) {
return R.success("导入成功");
}
return R.success("导入失败");
}
}

View File

@ -15,7 +15,10 @@ public class ImptabmappingDto implements Serializable {
@JsonSerialize(using = ToStringSerializer.class)
private Long equipmentId;
@JsonSerialize(using = ToStringSerializer.class)
private Long id;
private Integer type;
private Object params;
private String params;
}

View File

@ -3,6 +3,7 @@ package com.das.modules.node.domain.vo;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import org.springframework.boot.configurationprocessor.json.JSONObject;
/**
@ -18,7 +19,11 @@ public class ImptabmappingVo {
@JsonSerialize(using = ToStringSerializer.class)
private Long equipmentId;
@JsonSerialize(using = ToStringSerializer.class)
private Long id;
private String equipmentName;
private Integer porder;
private String params;

View File

@ -34,5 +34,7 @@ public class SysImptabmappingVo {
private String params;
private String IotAddr;
private Integer revision;
}

View File

@ -18,9 +18,9 @@ import java.util.List;
@Mapper
public interface SysImptabmappingMapper extends BaseMapperPlus<SysImptabmapping, SysImptabmapping> {
List<ImptabmappingVo> getMappingList(Long linkId, Integer type);
List<ImptabmappingVo> getMappingList(Long linkId, String code);
List<ImptabmappingVo> getMappingControlList(Long linkId, Integer type);
List<ImptabmappingVo> getMappingControlList(Long linkId, String code);
List<SysImptabmappingVo> getBindDevice(Long linkId);
@ -37,4 +37,6 @@ public interface SysImptabmappingMapper extends BaseMapperPlus<SysImptabmapping,
String getAttributeCode(Long equipmentId, Integer type);
String getServiceCode(Long equipmentId, Integer type);
List<SysImptabmappingVo> getMappingInfoList(Long linkId);
}

View File

@ -1,12 +1,18 @@
package com.das.modules.node.service;
import com.das.common.utils.PageDataInfo;
import com.das.modules.equipment.domain.dto.SysEquipmentDto;
import com.das.modules.node.domain.dto.*;
import com.das.modules.node.domain.vo.ImptabmappingVo;
import com.das.modules.node.domain.vo.SysCommunicationLinkVo;
import com.das.modules.node.domain.vo.SysImptabmappingVo;
import com.das.modules.node.domain.vo.SysNodeVo;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;
public interface SysNodeService {
@ -32,4 +38,8 @@ public interface SysNodeService {
void bindDeviceMeas(List<BindEquipmentInfoDto> equipmentId, Long linkId);
void saveMappingList(List<ImptabmappingDto> impList);
void exportMappingList(SysImptabmappingDto sysImptabmappingDto,HttpServletRequest request, HttpServletResponse response);
boolean importMappingList(String linkId, MultipartFile file);
}

View File

@ -115,7 +115,7 @@ public class DataServiceImpl implements DataService {
List<IotModelVo> iotModelFieldList = sysImptabmappingMapper.getIotModelFieldByEquipmentId(equipmentId);
if (!CollectionUtils.isEmpty(iotModelFieldList)) {
for (IotModelVo info : iotModelFieldList) {
if(info.getParams() != null){
if(info.getParams() == null){
// info.setParams();
}
newIotModelFieldList.add(info);
@ -124,9 +124,9 @@ public class DataServiceImpl implements DataService {
List<IotModelVo> iotModelServiceList = sysImptabmappingMapper.getIotModelServiceByEquipmentId(equipmentId);
if (!CollectionUtils.isEmpty(iotModelServiceList)) {
for (IotModelVo info : iotModelServiceList) {
// if(!StringUtils.hasText(info.getParams())){
// info.setParams("{}");
// }
if(info.getParams() == null){
// info.setParams();
}
newIotModelServiceList.add(info);
}
}

View File

@ -1,6 +1,7 @@
package com.das.modules.node.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.io.IoUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.das.common.config.SessionUtil;
import com.das.common.utils.BeanCopyUtils;
@ -11,6 +12,7 @@ import com.das.modules.auth.domain.vo.SysUserVo;
import com.das.modules.auth.entity.SysOrg;
import com.das.modules.auth.mapper.SysOrgMapper;
import com.das.modules.equipment.mapper.SysEquipmentMapper;
import com.das.modules.equipment.mapper.SysIotModelMapper;
import com.das.modules.node.domain.dto.*;
import com.das.modules.node.domain.vo.ImptabmappingVo;
import com.das.modules.node.domain.vo.SysCommunicationLinkVo;
@ -23,17 +25,30 @@ import com.das.modules.node.mapper.SysCommunicationLinkMapper;
import com.das.modules.node.mapper.SysImptabmappingMapper;
import com.das.modules.node.mapper.SysNodeMapper;
import com.das.modules.node.service.SysNodeService;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Transactional(rollbackFor = Exception.class)
@Service
@Slf4j
public class SysNodeServiceImpl implements SysNodeService {
@Autowired
@ -52,6 +67,9 @@ public class SysNodeServiceImpl implements SysNodeService {
@Autowired
private SysEquipmentMapper sysEquipmentMapper;
@Autowired
private SysIotModelMapper sysIotModelMapper;
@Override
public List<SysNodeVo> querySysNodeList() {
List<SysNodeVo> sysNodeVoList = sysNodeMapper.querySysNodeList();
@ -61,7 +79,7 @@ public class SysNodeServiceImpl implements SysNodeService {
@Override
public SysNodeVo createSysNode(SysNodeDto sysNodeDto) {
SysNode sysNode = new SysNode();
BeanCopyUtils.copy(sysNodeDto,sysNode);
BeanCopyUtils.copy(sysNodeDto, sysNode);
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
sysNode.setId(SequenceUtils.generateId());
@ -74,7 +92,7 @@ public class SysNodeServiceImpl implements SysNodeService {
SysNodeVo sysNodeVo = new SysNodeVo();
// 根据org_id查询组织名称
SysOrg sysorg = sysOrgMapper.selectById(sysNode.getOrgId());
BeanCopyUtils.copy(sysNode,sysNodeVo);
BeanCopyUtils.copy(sysNode, sysNodeVo);
sysNodeVo.setOrgName(sysorg.getName());
return sysNodeVo;
}
@ -82,7 +100,7 @@ public class SysNodeServiceImpl implements SysNodeService {
@Override
public SysNodeVo updateSysNode(SysNodeDto sysNodeDto) {
SysNode sysNode = new SysNode();
BeanCopyUtils.copy(sysNodeDto,sysNode);
BeanCopyUtils.copy(sysNodeDto, sysNode);
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
sysNode.setUpdatedTime(new Date());
// sysNode.setUpdatedBy("测试");
@ -91,7 +109,7 @@ public class SysNodeServiceImpl implements SysNodeService {
SysNodeVo sysNodeVo = new SysNodeVo();
// 根据org_id查询组织名称
SysOrg sysorg = sysOrgMapper.selectById(sysNode.getOrgId());
BeanCopyUtils.copy(sysNode,sysNodeVo);
BeanCopyUtils.copy(sysNode, sysNodeVo);
sysNodeVo.setOrgName(sysorg.getName());
return sysNodeVo;
}
@ -117,7 +135,7 @@ public class SysNodeServiceImpl implements SysNodeService {
@Override
public SysCommunicationLinkVo createSysCommunicationLink(SysCommunicationLinkDto sysCommunicationLinkDto) {
SysCommunicationLink sysCommunicationLink = new SysCommunicationLink();
BeanCopyUtils.copy(sysCommunicationLinkDto,sysCommunicationLink);
BeanCopyUtils.copy(sysCommunicationLinkDto, sysCommunicationLink);
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
sysCommunicationLink.setId(SequenceUtils.generateId());
@ -130,7 +148,7 @@ public class SysNodeServiceImpl implements SysNodeService {
SysCommunicationLinkVo sysCommunicationLinkVo = new SysCommunicationLinkVo();
// 根据org_id查询组织名称
SysNode sysNode = sysNodeMapper.selectById(sysCommunicationLinkDto.getNodeId());
BeanCopyUtils.copy(sysCommunicationLink,sysCommunicationLinkVo);
BeanCopyUtils.copy(sysCommunicationLink, sysCommunicationLinkVo);
sysCommunicationLinkVo.setNodeName(sysNode.getNodeName());
return sysCommunicationLinkVo;
}
@ -139,7 +157,7 @@ public class SysNodeServiceImpl implements SysNodeService {
public SysCommunicationLinkVo updateSysCommunicationLink(SysCommunicationLinkDto sysCommunicationLinkDto) {
SysCommunicationLink sysCommunicationLink = new SysCommunicationLink();
BeanCopyUtils.copy(sysCommunicationLinkDto,sysCommunicationLink);
BeanCopyUtils.copy(sysCommunicationLinkDto, sysCommunicationLink);
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
sysCommunicationLink.setUpdatedTime(new Date());
@ -149,7 +167,7 @@ public class SysNodeServiceImpl implements SysNodeService {
SysCommunicationLinkVo sysCommunicationLinkVo = new SysCommunicationLinkVo();
// 根据org_id查询组织名称
SysNode sysNode = sysNodeMapper.selectById(sysCommunicationLinkDto.getNodeId());
BeanCopyUtils.copy(sysCommunicationLink,sysCommunicationLinkVo);
BeanCopyUtils.copy(sysCommunicationLink, sysCommunicationLinkVo);
sysCommunicationLinkVo.setNodeName(sysNode.getNodeName());
return sysCommunicationLinkVo;
}
@ -165,10 +183,14 @@ public class SysNodeServiceImpl implements SysNodeService {
// 138模拟量 139累积量 140离散量 146遥调 147遥控
Integer type = sysImptabmappingDto.getType();
List<ImptabmappingVo> list = new ArrayList<>();
// 根据类型获取物模型属性或者动作编码
String code = "";
if (type == 138 || type == 139 || type == 140) {
list = sysImptabmappingMapper.getMappingList(sysImptabmappingDto.getLinkId(), type);
}else if (type == 146 || type == 147) {
list = sysImptabmappingMapper.getMappingControlList(sysImptabmappingDto.getLinkId(), type);
code = sysIotModelMapper.getIotModelFieldCode(type);
list = sysImptabmappingMapper.getMappingList(sysImptabmappingDto.getLinkId(), code);
} else if (type == 146 || type == 147) {
code = sysIotModelMapper.getIotModelServiceCode(type);
list = sysImptabmappingMapper.getMappingControlList(sysImptabmappingDto.getLinkId(), code);
}
return list;
@ -203,38 +225,101 @@ public class SysNodeServiceImpl implements SysNodeService {
public void saveMappingList(List<ImptabmappingDto> impList) {
if (!CollectionUtils.isEmpty(impList)) {
List<SysImptabmapping> list = new ArrayList<>();
int index = 0;
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
for (ImptabmappingDto imp : impList) {
SysImptabmapping sysImptabmapping = new SysImptabmapping();
// 更新记录
sysImptabmapping.setId(imp.getId());
if (imp.getType() == 138 || imp.getType() == 139 || imp.getType() == 140) {
// 获取属性编码
String code = sysImptabmappingMapper.getAttributeCode(imp.getEquipmentId(), imp.getType());
sysImptabmapping.setEquipmentAttribute(code);
}else if (imp.getType() == 146 || imp.getType() == 147) {
} else if (imp.getType() == 146 || imp.getType() == 147) {
// 获取动作编码
String code = sysImptabmappingMapper.getServiceCode(imp.getEquipmentId(), imp.getType());
sysImptabmapping.setEquipmentService(code);
}
index++;
sysImptabmapping.setCreatedTime(new Date());
sysImptabmapping.setUpdatedTime(new Date());
sysImptabmapping.setCreatedBy(sysUserVo.getAccount());
sysImptabmapping.setUpdatedBy(sysUserVo.getAccount());
sysImptabmapping.setLinkId(imp.getLinkId());
sysImptabmapping.setEquipmentId(imp.getEquipmentId());
sysImptabmapping.setId(SequenceUtils.generateId());
sysImptabmapping.setPorder(index);
sysImptabmapping.setParams(String.valueOf(imp.getParams()));
sysImptabmapping.setRevision(1);
list.add(sysImptabmapping);
}
if (!CollectionUtils.isEmpty(list)){
sysImptabmappingMapper.insertBatch(list);
if (!CollectionUtils.isEmpty(list)) {
sysImptabmappingMapper.updateBatchById(list);
}
}
}
@Override
public void exportMappingList(SysImptabmappingDto sysImptabmappingDto, HttpServletRequest request, HttpServletResponse response) {
// 根据链路Id获取映射表信息并导出成json文件
List<SysImptabmappingVo> list = sysImptabmappingMapper.getMappingInfoList(sysImptabmappingDto.getLinkId());
ObjectMapper mapper = new ObjectMapper();
try {
String jsonContent = mapper.writeValueAsString(list);
OutputStream os = null;
if (response != null) {
response.reset();
response.setHeader("Content-Disposition", String.format("attachment; filename=%s", "imptabmapping.json"));
response.setContentType(String.format("application/json; charset=%s", "UTF-8"));
if (os == null) {
os = response.getOutputStream();
os.write(jsonContent.getBytes(StandardCharsets.UTF_8));
}
}
IoUtil.close(os);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public boolean importMappingList(String linkId, MultipartFile file) {
boolean flag = false;
try {
// SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
List<SysImptabmapping> addList = new ArrayList<>();
String content = new BufferedReader(new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8))
.lines()
.reduce("", (accumulator, _item) -> accumulator + _item);
ObjectMapper objectMapper = new ObjectMapper();
List<SysImptabmappingVo> list = objectMapper.readValue(content, objectMapper.getTypeFactory().constructCollectionType(List.class, SysImptabmappingVo.class));
for (SysImptabmappingVo info : list) {
SysImptabmapping newInfo = new SysImptabmapping();
newInfo.setId(SequenceUtils.generateId());
newInfo.setLinkId(Long.valueOf(linkId));
newInfo.setEquipmentAttribute(info.getEquipmentAttribute());
newInfo.setEquipmentId(info.getEquipmentId());
newInfo.setEquipmentService(info.getEquipmentService());
newInfo.setParams(info.getParams());
newInfo.setPorder(info.getPorder());
newInfo.setRevision(1);
newInfo.setCreatedTime(new Date());
newInfo.setUpdatedTime(new Date());
// newInfo.setCreatedBy(sysUserVo.getAccount());
// newInfo.setUpdatedBy(sysUserVo.getAccount());
newInfo.setCreatedBy("ceshi");
newInfo.setUpdatedBy("ceshi");
addList.add(newInfo);
}
if (!CollectionUtils.isEmpty(addList)) {
sysImptabmappingMapper.insertBatch(addList);
flag = true;
}
flag = true;
} catch (IOException e) {
log.error("导入映射表失败 ", e);
flag = false;
}
return flag;
}
private void addSysImptabmapping(List<BindEquipmentInfoDto> equipmentId, Long linkId, SysUserVo sysUserVo, List<SysImptabmapping> addList) {
int index = 0;
for (BindEquipmentInfoDto info : equipmentId) {

View File

@ -11,41 +11,35 @@
<result property="equipmentAttribute" column="equipment_attribute" jdbcType="VARCHAR"/>
<result property="equipmentService" column="equipment_service" jdbcType="VARCHAR"/>
<result property="params" column="params" jdbcType="VARCHAR"/>
<result property="iotAddr" column="iot_addr" jdbcType="VARCHAR"/>
<result property="porder" column="porder" jdbcType="INTEGER"/>
<result property="revision" column="revision" jdbcType="INTEGER"/>
</resultMap>
<resultMap type="com.das.modules.node.domain.vo.ImptabmappingVo" id="ImptabmappingMap">
<result property="equipmentName" column="equipmentName" jdbcType="VARCHAR"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="equipmentId" column="equipment_id" jdbcType="BIGINT"/>
<result property="params" column="params" jdbcType="VARCHAR"/>
</resultMap>
<resultMap type="com.das.modules.node.domain.vo.IotModelVo" id="IotModelMap">
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="type" column="type" jdbcType="VARCHAR"/>
<result property="params" column="params" jdbcType="VARCHAR"/>
</resultMap>
<select id="getMappingList" resultMap="ImptabmappingMap">
select se."name" as equipmentName, simf.attribute_name as name,si.params,se.id as equipment_id from sys_imptabmapping si
<select id="getMappingList" resultType="com.das.modules.node.domain.vo.ImptabmappingVo">
select si.id, se."name" as equipmentName, simf.attribute_name as name,si.params,se.id as equipmentId from sys_imptabmapping si
left join sys_equipment se on si.equipment_id = se.id
left join sys_iot_model_field simf on se.iot_model_id = simf.iot_model_id
where si.link_id = #{linkId} and simf.attribute_type = #{type}
where si.link_id = #{linkId} and si.equipment_attribute = #{code}
order by si.porder
</select>
<select id="getMappingControlList" resultMap="ImptabmappingMap">
select se."name" as equipmentName, sims.service_name as name,si.params,se.id as equipment_id from sys_imptabmapping si
<select id="getMappingControlList" resultType="com.das.modules.node.domain.vo.ImptabmappingVo">
select si.id, se."name" as equipmentName, sims.service_name as name,si.params,se.id as equipmentId from sys_imptabmapping si
left join sys_equipment se on si.equipment_id = se.id
left join sys_iot_model_service sims on se.iot_model_id = sims.iot_model_id
where si.link_id = #{linkId} and sims.service_type = #{type}
where si.link_id = #{linkId} and si.equipment_service = #{code}
order by si.porder
</select>
<select id="getBindDevice" resultMap="SysImptabmappingMap">
select se.id as equipment_id,se."name" as equipmentName, si.porder from sys_imptabmapping si
select se.id as equipment_id,se."name" as equipmentName, si.porder, se.iot_addr from sys_imptabmapping si
left join sys_equipment se on se.id = si.equipment_id
where si.link_id = #{linkId} order by si.porder
</select>
@ -93,4 +87,10 @@
where se.id = #{equipmentId} and sims.service_type = #{type}
</select>
<select id="getMappingInfoList" resultMap="SysImptabmappingMap">
select si.*,se.iot_addr from sys_imptabmapping si
left join sys_equipment se on si.equipment_id = se.id
where si.link_id = #{linkId}
</select>
</mapper>

View File

@ -44,4 +44,15 @@
select * from sys_iot_model where object_type = #{objectType}
</select>
<select id="getIotModelFieldCode" resultType="java.lang.String">
select distinct attribute_code from sys_iot_model_field where attribute_type = #{objectType}
</select>
<select id="getIotModelServiceCode" resultType="java.lang.String">
select distinct service_code from sys_iot_model_service where service_type = #{objectType}
</select>
</mapper>

View File

@ -402,7 +402,7 @@ POST 请求接口
请求参数
```json
{
"linkId": "73556002258550784"
"id": "73556002258550784"
}
```