Compare commits

...

5 Commits

Author SHA1 Message Date
maxw@mesnac.com 66dd765033 plc协议开发 2 weeks ago
maxw@mesnac.com 9bce8c0df2 历史记录 2 weeks ago
maxw@mesnac.com b817d4b51b plc协议开发 2 weeks ago
maxw@mesnac.com d08e7012ff plc协议前端开发 3 weeks ago
maxw@mesnac.com eb7844ffc0 plc协议后端开发 3 weeks ago

@ -20,4 +20,15 @@ public interface RemoteBusinessService {
*/
@GetMapping("/device/computeOnlineDevicecCount/{days}")
public R<?> computeOnlineDevicecCount(@PathVariable("days") int days, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
@GetMapping("/plcDevice/modbusDataProcess")
public R<?> modbusDataProcess(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
@GetMapping("/plcDevice/mcDataProcess")
public R<?> mcDataProcess(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
@GetMapping("/plcDevice/aeDataProcess")
public R<?> aeDataProcess(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
@GetMapping("/plcDevice/ehternetDataProcess")
public R<?> ehternetDataProcess(@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
}

@ -21,6 +21,26 @@ public class RemoteBusinessFallbackFactory implements FallbackFactory<RemoteBusi
public R<?> computeOnlineDevicecCount(int days, String source) {
return R.fail("获取租户信息失败:" + throwable.getMessage());
}
@Override
public R<?> modbusDataProcess(String source) {
return R.fail("获取租户信息失败:" + throwable.getMessage());
}
@Override
public R<?> mcDataProcess(String source) {
return R.fail("获取租户信息失败:" + throwable.getMessage());
}
@Override
public R<?> aeDataProcess(String source) {
return R.fail("获取租户信息失败:" + throwable.getMessage());
}
@Override
public R<?> ehternetDataProcess(String source) {
return R.fail("获取租户信息失败:" + throwable.getMessage());
}
};
}
}

@ -32,7 +32,9 @@ public class TdEngineConstants {
// public static final String DEFAULT_DB_NAME_PREFIX = "db_scene_";//数据库名称前缀
public static final String DEFAULT_SUPER_TABLE_NAME_PREFIX = "st_devicemode_";//超级表名称前缀
public static final String PLC_SUPER_TABLE_NAME_PREFIX = "plc_";//plc超级表名称前缀
public static final String DEFAULT_TABLE_NAME_PREFIX = "t_device_";//数据表名称前缀
public static final String PLC_TABLE_NAME_PREFIX = "plc_device_";//plc数据表名称前缀
public static final String DEFAULT_DEVICE_STATUS_SUPER_TABLE_NAME= "st_ds";//设备状态超级表名称
public static final String DEFAULT_DEVICE_STATUS_TABLE_NAME_PREFIX = "t_ds_";//设备状态数据表名称前缀
@ -43,6 +45,14 @@ public class TdEngineConstants {
public static final int ST_TAG_DEVICECODE_TYPE = 10;
public static final int ST_TAG_DEVICECODE_SIZE=50;
public static final String PLC_TAG_IP = "IP";
public static final int PLC_TAG_IP_TYPE = 10;
public static final int PLC_TAG_IP_SIZE=100;
public static final String PLC_TAG_LOCATION = "dlocation";
public static final int PLC_TAG_LOCATION_TYPE = 10;
public static final int PLC_TAG_LOCATION_SIZE=50;
public static final String ST_TAG_DEVICENAME = "devicename";
public static final String ST_TAG_DEVICETYPE = "devicetype";
@ -53,6 +63,9 @@ public class TdEngineConstants {
public static final String ST_TAG_DEVICEID = "deviceid";
public static final int ST_TAG_DEVICEID_TYPE = 2;
public static final String PLC_TAG_PORT = "PORT1";
public static final int PLC_TAG_PORT_TYPE = 2;
public static final String ST_TAG_DEVICEMODEID = "devicemodeid";
public static final int ST_TAG_DEVICEMODEID_TYPE = 2;

@ -83,6 +83,13 @@
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-common-datascope</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.plc4x/plc4j-protocol-ethernetip -->
<dependency>
<groupId>org.apache.plc4x</groupId>
<artifactId>plc4j-driver-ethernet-ip</artifactId>
<version>0.6.0</version>
</dependency>
<!-- RuoYi Common Log -->
<dependency>
@ -105,6 +112,11 @@
<groupId>com.ruoyi</groupId>
<artifactId>hw-api-tdengine</artifactId>
</dependency>
<dependency>
<groupId>com.github.dathlin</groupId>
<artifactId>HslCommunication</artifactId>
<version>3.3.1</version>
</dependency>
<!-- RuoYi Common International Language -->
<dependency>

@ -0,0 +1,149 @@
package com.ruoyi.business.controller;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.ruoyi.business.domain.HwDevice;
import com.ruoyi.business.domain.HwDeviceMode;
import com.ruoyi.business.domain.PlcDevice;
import com.ruoyi.business.domain.PlcDeviceMode;
import com.ruoyi.business.service.PlcDeviceService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ExecutionException;
/**
* plc(PlcDevice)
*
* @author makejava
* @since 2024-12-19 16:22:43
*/
@RestController
@RequestMapping("plcDevice")
public class PlcDeviceController extends BaseController {
/**
*
*/
@Resource
private PlcDeviceService plcDeviceService;
/**
*
*
* @param plcDevice
* @param pageRequest
* @return
*/
@GetMapping
public ResponseEntity<Page<PlcDevice>> queryByPage(PlcDevice plcDevice, PageRequest pageRequest) {
return ResponseEntity.ok(this.plcDeviceService.queryByPage(plcDevice, pageRequest));
}
/**
*
*
* @param id
* @return
*/
@GetMapping("{deviceId}")
public AjaxResult queryById(@PathVariable("deviceId") Long id) throws JsonProcessingException {
return AjaxResult.success(this.plcDeviceService.queryById(id));
}
/**
*
*
* @param plcDevice
* @return
*/
@PostMapping
public AjaxResult add(@RequestBody PlcDevice plcDevice) {
return toAjax(this.plcDeviceService.insert(plcDevice));
}
@PutMapping("/changeDeviceStatus")
public AjaxResult changeDeviceStatus(@RequestBody PlcDevice device) {
return toAjax(plcDeviceService.changeDeviceStatus(device));
}
/**
*
*
* @param plcDevice
* @return
*/
// @PutMapping
// public AjaxResult edit(PlcDevice plcDevice) {
// return AjaxResult.success(plcDeviceService.update(plcDevice));
// }
@GetMapping("getProtocols")
public AjaxResult getProtocols(){
HashMap<String, String> map = new HashMap<>();
map.put("protocolName","mc");
map.put("protocolValue","1");
HashMap<String, String> map1 = new HashMap<>();
map1.put("protocolName","modbus");
map1.put("protocolValue","2");
ArrayList<HashMap> objects = new ArrayList<>();
objects.add(map);
objects.add(map1);
return AjaxResult.success(objects);
}
/**
*
*
* @param id
* @return
*/
@DeleteMapping("{deviceId}")
public AjaxResult deleteById(@PathVariable("deviceId") Long deviceId) {
return AjaxResult.success(this.plcDeviceService.deleteById(deviceId));
}
@GetMapping("/modbusDataProcess")
public AjaxResult modbusDataProcess() throws JsonProcessingException {
return AjaxResult.success(plcDeviceService.modbusDataProcess());
}
@GetMapping("/mcDataProcess")
public AjaxResult mcDataProcess() throws JsonProcessingException {
return AjaxResult.success(plcDeviceService.mcDataProcess());
}
@GetMapping("/aeDataProcess")
public AjaxResult aeDataProcess() throws JsonProcessingException {
return AjaxResult.success(plcDeviceService.aeDataProcess());
}
@GetMapping("/ehternetDataProcess")
public AjaxResult ehternetDataProcess() throws JsonProcessingException{
return AjaxResult.success(plcDeviceService.ehternetDataProcess());
}
@GetMapping("/list")
public TableDataInfo list(PlcDevice hwDevice) {
startPage();
List<PlcDevice> list = plcDeviceService.selectHwDeviceJoinList(hwDevice);
return getDataTable(list);
}
@GetMapping(value = {"/getDeviceModes/", "/getDeviceModes/{sceneId}"})
public AjaxResult getDeviceModes(@PathVariable(value = "sceneId", required = false) Long sceneId) {
PlcDeviceMode queryDeviceMode = new PlcDeviceMode();
queryDeviceMode.setSceneId(sceneId);
return success(plcDeviceService.selectHwDeviceModeList(queryDeviceMode));
}
@PutMapping
public AjaxResult edit(@RequestBody PlcDevice hwDevice) {
hwDevice.setUpdateBy(SecurityUtils.getUsername());
return toAjax(plcDeviceService.updateDevice(hwDevice));
}
}

@ -0,0 +1,111 @@
package com.ruoyi.business.controller;
import com.ruoyi.business.domain.HwDeviceMode;
import com.ruoyi.business.domain.HwDeviceModeFunction;
import com.ruoyi.business.domain.PlcDeviceMode;
import com.ruoyi.business.domain.PlcDeviceModeFunction;
import com.ruoyi.business.service.PlcDeviceModeService;
import com.ruoyi.common.core.constant.HwDictConstants;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* plc(PlcDeviceMode)
*
* @author makejava
* @since 2024-12-19 16:23:27
*/
@RestController
@RequestMapping("plcDeviceMode")
public class PlcDeviceModeController extends BaseController {
/**
*
*/
@Resource
private PlcDeviceModeService plcDeviceModeService;
/**
*
*
* @param plcDeviceMode
* @param pageRequest
* @return
*/
@GetMapping
public ResponseEntity<Page<PlcDeviceMode>> queryByPage(PlcDeviceMode plcDeviceMode, PageRequest pageRequest) {
return ResponseEntity.ok(this.plcDeviceModeService.queryByPage(plcDeviceMode, pageRequest));
}
/**
*
*
* @param id
* @return
*/
@GetMapping("{deviceModeId}")
public AjaxResult queryById(@PathVariable("deviceModeId") Long deviceModeId) {
PlcDeviceMode hwDeviceMode = plcDeviceModeService.selectHwDeviceModeByDeviceModeId(deviceModeId);
List<PlcDeviceModeFunction> hwDeviceModeFunctions = plcDeviceModeService.selectFunctionList(deviceModeId);
hwDeviceMode.setFunctionList(null);
Map<String, Object> map = new HashMap<>();
map.put("deviceMode", hwDeviceMode);
map.put("deviceModeFunctionMap", hwDeviceModeFunctions);
return success(map);
}
/**
*
*
* @param plcDeviceMode
* @return
*/
@PostMapping
public AjaxResult add(@RequestBody PlcDeviceMode plcDeviceMode) {
return toAjax(this.plcDeviceModeService.insert(plcDeviceMode));
}
@RequiresPermissions("business:deviceMode:list")
@GetMapping("/list")
public TableDataInfo list(PlcDeviceMode hwDeviceMode) {
startPage();
hwDeviceMode.setDeviceModeStatus(HwDictConstants.DEVICE_MODE_STATUS_NORMAL);
List<PlcDeviceMode> list = plcDeviceModeService.selectList(hwDeviceMode);
return getDataTable(list);
}
/**
*
*
* @param plcDeviceMode
* @return
*/
@PutMapping
public AjaxResult edit(@RequestBody PlcDeviceMode plcDeviceMode) {
return toAjax(this.plcDeviceModeService.update(plcDeviceMode));
}
/**
*
*
* @param id
* @return
*/
@DeleteMapping("/{deviceModeIds}")
public ResponseEntity<Integer> deleteById(@PathVariable Long[] deviceModeIds) {
return ResponseEntity.ok(this.plcDeviceModeService.deleteHwDeviceModeByDeviceModeIds(deviceModeIds));
}
}

@ -0,0 +1,87 @@
package com.ruoyi.business.controller;
import com.ruoyi.business.domain.PlcDeviceModeFunction;
import com.ruoyi.business.service.PlcDeviceModeFunctionService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
* plc(PlcDeviceModeFunction)
*
* @author makejava
* @since 2024-12-19 16:23:52
*/
@RestController
@RequestMapping("plcDeviceModeFunction")
public class PlcDeviceModeFunctionController extends BaseController {
/**
*
*/
@Resource
private PlcDeviceModeFunctionService plcDeviceModeFunctionService;
/**
*
*
* @param plcDeviceModeFunction
* @param pageRequest
* @return
*/
@GetMapping
public ResponseEntity<Page<PlcDeviceModeFunction>> queryByPage(PlcDeviceModeFunction plcDeviceModeFunction, PageRequest pageRequest) {
return ResponseEntity.ok(this.plcDeviceModeFunctionService.queryByPage(plcDeviceModeFunction, pageRequest));
}
/**
*
*
* @param id
* @return
*/
@GetMapping("{id}")
public ResponseEntity<PlcDeviceModeFunction> queryById(@PathVariable("id") Long id) {
return ResponseEntity.ok(this.plcDeviceModeFunctionService.queryById(id));
}
/**
*
*
* @param plcDeviceModeFunction
* @return
*/
@PostMapping
public AjaxResult add(@RequestBody PlcDeviceModeFunction plcDeviceModeFunction) {
return toAjax(this.plcDeviceModeFunctionService.insert(plcDeviceModeFunction));
}
/**
*
*
* @param plcDeviceModeFunction
* @return
*/
@PutMapping
public AjaxResult edit(@RequestBody PlcDeviceModeFunction plcDeviceModeFunction) {
return toAjax(this.plcDeviceModeFunctionService.update(plcDeviceModeFunction));
}
/**
*
*
* @param id
* @return
*/
@DeleteMapping("/{modeFunctionId}")
public AjaxResult deleteById(@PathVariable("modeFunctionId") Long modeFunctionId) {
return toAjax(this.plcDeviceModeFunctionService.deleteById(modeFunctionId));
}
}

@ -0,0 +1,247 @@
package com.ruoyi.business.domain;
import com.ruoyi.common.core.annotation.Excel;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* plc(PlcDevice)
*
* @author makejava
* @since 2024-12-19 16:22:47
*/
@Data
public class PlcDevice implements Serializable {
private static final long serialVersionUID = -11771385039084146L;
/**
* ID
*/
private Long deviceId;
/**
*
*/
private String deviceCode;
/**
*
*/
private String deviceName;
/**
* IDhw_tenanttenant_id
*/
private Long tenantId;
/**
* hw_scenescene_id
*/
private Long sceneId;
/**
* ip
*/
private String ip;
/**
*
*/
private Integer port1;
/**
*
*/
private String location;
/**
* 1mc2modbus
*/
private Integer accessProtocol;
private Integer station;
/**
*
*/
private Integer length;
private String dataType;
private String tenantName;
private String sceneName;
private String deviceModeName;
/**
* hw_device_modedevice_mode_id
*/
@Excel(name = "设备模型")
private Long deviceModeId;
/**
* 019
*/
private String deviceStatus;
/**
*
*/
private String createBy;
/**
*
*/
private Date createTime;
private Date publishTime;
/**
*
*/
private String updateBy;
/**
*
*/
private Date updateTime;
public void setDeviceModeId(Long deviceModeId) {
this.deviceModeId = deviceModeId;
}
public Long getDeviceModeId() {
return deviceModeId;
}
public Long getDeviceId() {
return deviceId;
}
public void setDeviceId(Long deviceId) {
this.deviceId = deviceId;
}
public String getDeviceCode() {
return deviceCode;
}
public void setDeviceCode(String deviceCode) {
this.deviceCode = deviceCode;
}
public String getDataType() {
return dataType;
}
public void setDataType(String dataType) {
this.dataType = dataType;
}
public String getDeviceName() {
return deviceName;
}
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
// public String getdLocation() {
// return dLocation;
// }
//
// public void setdLocation(String dLocation) {
// this.dLocation = dLocation;
// }
public Long getTenantId() {
return tenantId;
}
public void setTenantId(Long tenantId) {
this.tenantId = tenantId;
}
public Long getSceneId() {
return sceneId;
}
public void setSceneId(Long sceneId) {
this.sceneId = sceneId;
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public Integer getPort1() {
return port1;
}
public void setPort1(Integer port1) {
this.port1 = port1;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public Integer getAccessProtocol() {
return accessProtocol;
}
public void setAccessProtocol(Integer accessProtocol) {
this.accessProtocol = accessProtocol;
}
public Integer getStation() {
return station;
}
public void setStation(Integer station) {
this.station = station;
}
public Integer getLength() {
return length;
}
public void setLength(Integer length) {
this.length = length;
}
public String getDeviceStatus() {
return deviceStatus;
}
public void setDeviceStatus(String deviceStatus) {
this.deviceStatus = deviceStatus;
}
public String getCreateBy() {
return createBy;
}
public void setCreateBy(String createBy) {
this.createBy = createBy;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getPublishTime() {
return publishTime;
}
public void setPublishTime(Date publishTime) {
this.publishTime = publishTime;
}
public String getUpdateBy() {
return updateBy;
}
public void setUpdateBy(String updateBy) {
this.updateBy = updateBy;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
}

@ -0,0 +1,147 @@
package com.ruoyi.business.domain;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* plc(PlcDeviceMode)
*
* @author makejava
* @since 2024-12-19 16:23:27
*/
@Data
public class PlcDeviceMode implements Serializable {
private static final long serialVersionUID = 441335518091339874L;
/**
* ID
*/
private Long deviceModeId;
/**
*
*/
private String deviceModeName;
/**
* IDhw_tenanttenant_id
*/
private Long tenantId;
/**
* hw_scenescene_id
*/
private Long sceneId;
/**
* 19
*/
private String deviceModeStatus;
/**
*
*/
private String createBy;
/**
*
*/
private Date createTime;
/**
*
*/
private String updateBy;
/**
*
*/
private Date updateTime;
private List<PlcDeviceModeFunction> functionList;
private String tenantName;
private String sceneName;
public Long getDeviceModeId() {
return deviceModeId;
}
public void setDeviceModeId(Long deviceModeId) {
this.deviceModeId = deviceModeId;
}
public String getDeviceModeName() {
return deviceModeName;
}
public void setDeviceModeName(String deviceModeName) {
this.deviceModeName = deviceModeName;
}
public String getTenantName() {
return tenantName;
}
public void setTenantName(String tenantName) {
this.tenantName = tenantName;
}
public String getSceneName() {
return sceneName;
}
public void setSceneName(String sceneName) {
this.sceneName = sceneName;
}
public Long getTenantId() {
return tenantId;
}
public void setTenantId(Long tenantId) {
this.tenantId = tenantId;
}
public Long getSceneId() {
return sceneId;
}
public void setSceneId(Long sceneId) {
this.sceneId = sceneId;
}
public String getDeviceModeStatus() {
return deviceModeStatus;
}
public void setDeviceModeStatus(String deviceModeStatus) {
this.deviceModeStatus = deviceModeStatus;
}
public String getCreateBy() {
return createBy;
}
public void setCreateBy(String createBy) {
this.createBy = createBy;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getUpdateBy() {
return updateBy;
}
public void setUpdateBy(String updateBy) {
this.updateBy = updateBy;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
}

@ -0,0 +1,134 @@
package com.ruoyi.business.domain;
import com.ruoyi.common.core.annotation.Excel;
import java.io.Serializable;
/**
* plc(PlcDeviceModeFunction)
*
* @author makejava
* @since 2024-12-19 16:23:52
*/
public class PlcDeviceModeFunction implements Serializable {
private static final long serialVersionUID = -19875863077506718L;
/**
* ID
*/
private Long modeFunctionId;
/**
* IDplc_device_modedevice_mode_id
*/
private Long deviceModeId;
/**
*
*/
private String functionName;
/**
* 线50
*/
private String functionIdentifier;
/**
* 2int4float5double6binary(image/base64),9bool10string
*/
private Integer dataType;
/**
* json
1{'minValue':1,'maxValue':100},
2
{'1':'','2','','3','}
3bool
{'0':'关','1','开'}
4Text
{'dataLength'1024}
5String
{'dateFormat':'StringUTC'}
*/
private String dataDefinition;
/**
*
*/
private String propertyUnit;
/**
*
*/
private String remark;
/** 功能模式1、属性2、服务3、事件 */
// @Excel(name = "功能模式", readConverterExp = "1=属性,2=服务,3=事件")
private String functionMode;
public void setFunctionMode(String functionMode)
{
this.functionMode = functionMode;
}
public String getFunctionMode()
{
return functionMode;
}
public Long getModeFunctionId() {
return modeFunctionId;
}
public void setModeFunctionId(Long modeFunctionId) {
this.modeFunctionId = modeFunctionId;
}
public Long getDeviceModeId() {
return deviceModeId;
}
public void setDeviceModeId(Long deviceModeId) {
this.deviceModeId = deviceModeId;
}
public String getFunctionName() {
return functionName;
}
public void setFunctionName(String functionName) {
this.functionName = functionName;
}
public String getFunctionIdentifier() {
return functionIdentifier;
}
public void setFunctionIdentifier(String functionIdentifier) {
this.functionIdentifier = functionIdentifier;
}
public Integer getDataType() {
return dataType;
}
public void setDataType(Integer dataType) {
this.dataType = dataType;
}
public String getDataDefinition() {
return dataDefinition;
}
public void setDataDefinition(String dataDefinition) {
this.dataDefinition = dataDefinition;
}
public String getPropertyUnit() {
return propertyUnit;
}
public void setPropertyUnit(String propertyUnit) {
this.propertyUnit = propertyUnit;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}

@ -0,0 +1,91 @@
package com.ruoyi.business.mapper;
import com.ruoyi.business.domain.PlcDevice;
import com.ruoyi.business.domain.PlcDeviceMode;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Pageable;
import java.util.List;
/**
* plc(PlcDevice)访
*
* @author makejava
* @since 2024-12-19 16:22:43
*/
public interface PlcDeviceDao {
/**
* ID
*
* @param deviceId
* @return
*/
List<PlcDevice> queryById();
List<PlcDevice> queryPlcDevices(@Param("accessProtocol") int accessProtocol);
/**
*
*
* @param plcDevice
* @param pageable
* @return
*/
List<PlcDevice> queryAllByLimit(PlcDevice plcDevice, @Param("pageable") Pageable pageable);
/**
*
*
* @param plcDevice
* @return
*/
long count(PlcDevice plcDevice);
/**
*
*
* @param plcDevice
* @return
*/
int insert(PlcDevice plcDevice);
/**
* MyBatisforeach
*
* @param entities List<PlcDevice>
* @return
*/
int insertBatch(@Param("entities") List<PlcDevice> entities);
/**
* MyBatisforeach
*
* @param entities List<PlcDevice>
* @return
* @throws org.springframework.jdbc.BadSqlGrammarException ListSQL
*/
int insertOrUpdateBatch(@Param("entities") List<PlcDevice> entities);
/**
*
*
* @param plcDevice
* @return
*/
int update(PlcDevice plcDevice);
/**
*
*
* @param deviceId
* @return
*/
int deleteById(Long deviceId);
List<PlcDevice> selectHwDeviceJoinList(PlcDevice hwDevice);
List<PlcDeviceMode> selectPlcDeviceMode(PlcDeviceMode queryDeviceMode);
PlcDevice selectHwDeviceByDeviceId(Long deviceId);
}

@ -0,0 +1,88 @@
package com.ruoyi.business.mapper;
import com.ruoyi.business.domain.HwDeviceMode;
import com.ruoyi.business.domain.PlcDeviceMode;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Pageable;
import java.util.List;
/**
* plc(PlcDeviceMode)访
*
* @author makejava
* @since 2024-12-19 16:23:27
*/
public interface PlcDeviceModeDao {
/**
* ID
*
* @param deviceModeId
* @return
*/
PlcDeviceMode queryById(Long deviceModeId);
/**
*
*
* @param plcDeviceMode
* @param pageable
* @return
*/
List<PlcDeviceMode> queryAllByLimit(PlcDeviceMode plcDeviceMode, @Param("pageable") Pageable pageable);
/**
*
*
* @param plcDeviceMode
* @return
*/
long count(PlcDeviceMode plcDeviceMode);
/**
*
*
* @param plcDeviceMode
* @return
*/
int insert(PlcDeviceMode plcDeviceMode);
/**
* MyBatisforeach
*
* @param entities List<PlcDeviceMode>
* @return
*/
int insertBatch(@Param("entities") List<PlcDeviceMode> entities);
/**
* MyBatisforeach
*
* @param entities List<PlcDeviceMode>
* @return
* @throws org.springframework.jdbc.BadSqlGrammarException ListSQL
*/
int insertOrUpdateBatch(@Param("entities") List<PlcDeviceMode> entities);
/**
*
*
* @param plcDeviceMode
* @return
*/
int update(PlcDeviceMode plcDeviceMode);
/**
*
*
* @param deviceModeId
* @return
*/
int deleteById(Long deviceModeId);
List<PlcDeviceMode> selectList(PlcDeviceMode hwDeviceMode);
int deleteHwDeviceModeByDeviceModeIds(Long[] deviceModeIds);
}

@ -0,0 +1,94 @@
package com.ruoyi.business.mapper;
import com.ruoyi.business.domain.HwDeviceModeFunction;
import com.ruoyi.business.domain.PlcDeviceModeFunction;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Pageable;
import java.util.List;
/**
* plc(PlcDeviceModeFunction)访
*
* @author makejava
* @since 2024-12-19 16:23:52
*/
public interface PlcDeviceModeFunctionDao {
/**
* ID
*
* @param modeFunctionId
* @return
*/
PlcDeviceModeFunction queryById(Long modeFunctionId);
/**
*
*
* @param plcDeviceModeFunction
* @param pageable
* @return
*/
List<PlcDeviceModeFunction> queryAllByLimit(PlcDeviceModeFunction plcDeviceModeFunction, @Param("pageable") Pageable pageable);
/**
*
*
* @param plcDeviceModeFunction
* @return
*/
long count(PlcDeviceModeFunction plcDeviceModeFunction);
/**
*
*
* @param plcDeviceModeFunction
* @return
*/
int insert(PlcDeviceModeFunction plcDeviceModeFunction);
/**
* MyBatisforeach
*
* @param entities List<PlcDeviceModeFunction>
* @return
*/
int insertBatch(@Param("entities") List<PlcDeviceModeFunction> entities);
/**
* MyBatisforeach
*
* @param entities List<PlcDeviceModeFunction>
* @return
* @throws org.springframework.jdbc.BadSqlGrammarException ListSQL
*/
int insertOrUpdateBatch(@Param("entities") List<PlcDeviceModeFunction> entities);
/**
*
*
* @param plcDeviceModeFunction
* @return
*/
int update(PlcDeviceModeFunction plcDeviceModeFunction);
/**
*
*
* @param modeFunctionId
* @return
*/
int deleteById(Long modeFunctionId);
List<PlcDeviceModeFunction> selectFunctions(Long deviceModeId);
List<PlcDeviceModeFunction> selectFunctionList(Long deviceModeId);
List<HwDeviceModeFunction> selectHwDeviceModeFunctionList(HwDeviceModeFunction queryDeviceModeFunction);
int deleteHwDeviceModeParameterByModeFunctionId(Long modeFunctionId);
int deleteHwDeviceModeFunctionByDeviceModeIds(Long[] deviceModeIds);
}

@ -0,0 +1,55 @@
package com.ruoyi.business.service;
import com.ruoyi.business.domain.PlcDeviceModeFunction;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
/**
* plc(PlcDeviceModeFunction)
*
* @author makejava
* @since 2024-12-19 16:23:52
*/
public interface PlcDeviceModeFunctionService {
/**
* ID
*
* @param modeFunctionId
* @return
*/
PlcDeviceModeFunction queryById(Long modeFunctionId);
/**
*
*
* @param plcDeviceModeFunction
* @param pageRequest
* @return
*/
Page<PlcDeviceModeFunction> queryByPage(PlcDeviceModeFunction plcDeviceModeFunction, PageRequest pageRequest);
/**
*
*
* @param plcDeviceModeFunction
* @return
*/
int insert(PlcDeviceModeFunction plcDeviceModeFunction);
/**
*
*
* @param plcDeviceModeFunction
* @return
*/
int update(PlcDeviceModeFunction plcDeviceModeFunction);
/**
*
*
* @param modeFunctionId
* @return
*/
int deleteById(Long modeFunctionId);
}

@ -0,0 +1,66 @@
package com.ruoyi.business.service;
import com.ruoyi.business.domain.HwDeviceMode;
import com.ruoyi.business.domain.PlcDeviceMode;
import com.ruoyi.business.domain.PlcDeviceModeFunction;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import java.util.List;
/**
* plc(PlcDeviceMode)
*
* @author makejava
* @since 2024-12-19 16:23:27
*/
public interface PlcDeviceModeService {
/**
* ID
*
* @param deviceModeId
* @return
*/
PlcDeviceMode queryById(Long deviceModeId);
/**
*
*
* @param plcDeviceMode
* @param pageRequest
* @return
*/
Page<PlcDeviceMode> queryByPage(PlcDeviceMode plcDeviceMode, PageRequest pageRequest);
/**
*
*
* @param plcDeviceMode
* @return
*/
int insert(PlcDeviceMode plcDeviceMode);
/**
*
*
* @param plcDeviceMode
* @return
*/
int update(PlcDeviceMode plcDeviceMode);
/**
*
*
* @param deviceModeId
* @return
*/
boolean deleteById(Long deviceModeId);
List<PlcDeviceMode> selectList(PlcDeviceMode hwDeviceMode);
PlcDeviceMode selectHwDeviceModeByDeviceModeId(Long deviceModeId);
List<PlcDeviceModeFunction> selectFunctionList(Long deviceModeId);
int deleteHwDeviceModeByDeviceModeIds(Long[] deviceModeIds);
}

@ -0,0 +1,79 @@
package com.ruoyi.business.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.ruoyi.business.domain.HwDeviceMode;
import com.ruoyi.business.domain.PlcDevice;
import com.ruoyi.business.domain.PlcDeviceMode;
import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import java.util.List;
import java.util.concurrent.ExecutionException;
/**
* plc(PlcDevice)
*
* @author makejava
* @since 2024-12-19 16:22:51
*/
public interface PlcDeviceService {
/**
* ID
*
* @param deviceId
* @return
*/
PlcDevice queryById(Long deviceId) throws JsonProcessingException;
/**
*
*
* @param plcDevice
* @param pageRequest
* @return
*/
Page<PlcDevice> queryByPage(PlcDevice plcDevice, PageRequest pageRequest);
/**
*
*
* @param plcDevice
* @return
*/
int insert(PlcDevice plcDevice);
/**
*
*
* @param plcDevice
* @return
*/
PlcDevice update(PlcDevice plcDevice) throws JsonProcessingException;
/**
*
*
* @param deviceId
* @return
*/
int deleteById(Long deviceId);
String modbusDataProcess() throws JsonProcessingException;
String mcDataProcess() throws JsonProcessingException;
List<PlcDevice> selectHwDeviceJoinList(PlcDevice hwDevice);
List<PlcDeviceMode> selectHwDeviceModeList(PlcDeviceMode queryDeviceMode);
int changeDeviceStatus(PlcDevice device);
int updateDevice(PlcDevice hwDevice);
String aeDataProcess() throws JsonProcessingException;
String ehternetDataProcess() throws JsonProcessingException;
}

@ -193,6 +193,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
if (deviceInfoJson.getString("deviceCode").equals(hwDevice.getDeviceCode())) {
deviceInfoJson.put("userName", modeAccount);
deviceInfoJson.put("password", modeKey);
// deviceInfoJsonArr.add(deviceInfoJson);
redisUpdated = true;
}
}
@ -838,7 +839,9 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
@Override
public JSONObject getOnlineDevicesCount(Long sceneId) {
JSONObject returnObj = new JSONObject();
int onlineDevicesCount = hwDeviceMapper.getOnlineDeviceNum(sceneId);
Long tenantId = SecurityUtils.getTenantId();
HwScene hwScene = hwSceneMapper.selectHwSceneByTenantId(tenantId);
int onlineDevicesCount = hwDeviceMapper.getOnlineDeviceNum(hwScene.getSceneId());
JSONObject sortedJsonObject = new JSONObject();
@ -1440,8 +1443,13 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
List<String> list2 = new ArrayList<String>();
list2.addAll(strings);
for (int i = 0; i < list2.size(); i++) {
String s = "";
if (list2.get(i).equals("value1")){
s = hwDeviceMapper.selectFunctionNameByFunctionIdentifier("value",modeId);
}else {
s = hwDeviceMapper.selectFunctionNameByFunctionIdentifier(list2.get(i),modeId);
}
//查询类型的字段名
String s = hwDeviceMapper.selectFunctionNameByFunctionIdentifier(list2.get(i),modeId);
mapName.put(list2.get(i),s);
}
list.add(mapName);

@ -0,0 +1,252 @@
package com.ruoyi.business.service.impl;
import com.ruoyi.business.domain.HwDevice;
import com.ruoyi.business.domain.HwDeviceModeFunction;
import com.ruoyi.business.domain.PlcDeviceModeFunction;
import com.ruoyi.business.mapper.PlcDeviceModeFunctionDao;
import com.ruoyi.business.service.PlcDeviceModeFunctionService;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.constant.HwDictConstants;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.constant.TdEngineConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.enums.DataTypeEnums;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.tdengine.api.RemoteTdEngineService;
import com.ruoyi.tdengine.api.domain.TdField;
import com.ruoyi.tdengine.api.domain.TdSuperTableVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
* plc(PlcDeviceModeFunction)
*
* @author makejava
* @since 2024-12-19 16:23:52
*/
@Service("plcDeviceModeFunctionService")
public class PlcDeviceModeFunctionServiceImpl implements PlcDeviceModeFunctionService {
@Resource
private PlcDeviceModeFunctionDao plcDeviceModeFunctionDao;
@Autowired
private RemoteTdEngineService remoteTdEngineService;
/**
* ID
*
* @param modeFunctionId
* @return
*/
@Override
public PlcDeviceModeFunction queryById(Long modeFunctionId) {
return this.plcDeviceModeFunctionDao.queryById(modeFunctionId);
}
/**
*
*
* @param plcDeviceModeFunction
* @param pageRequest
* @return
*/
@Override
public Page<PlcDeviceModeFunction> queryByPage(PlcDeviceModeFunction plcDeviceModeFunction, PageRequest pageRequest) {
long total = this.plcDeviceModeFunctionDao.count(plcDeviceModeFunction);
return new PageImpl<>(this.plcDeviceModeFunctionDao.queryAllByLimit(plcDeviceModeFunction, pageRequest), pageRequest, total);
}
/**
*
*
* @param plcDeviceModeFunction
* @return
*/
@Override
public int insert(PlcDeviceModeFunction plcDeviceModeFunction) {
checkDuplicateIdentifiers(plcDeviceModeFunction);
int functionId = this.plcDeviceModeFunctionDao.insert(plcDeviceModeFunction);
this.addTdSuperTableColumn(plcDeviceModeFunction);
return functionId;
}
private void addTdSuperTableColumn(PlcDeviceModeFunction hwDeviceModeFunction) {
String functionMode = hwDeviceModeFunction.getFunctionMode();
if (functionMode.equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) {
Long deviceModeId = hwDeviceModeFunction.getDeviceModeId();
String dbName = TdEngineConstants.getDatabaseName();
String superTableName = TdEngineConstants.PLC_SUPER_TABLE_NAME_PREFIX + deviceModeId;
TdSuperTableVo tdSuperTableVo = new TdSuperTableVo();
TdField schemaField = new TdField();
String functionIdentifierTransfer = TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(hwDeviceModeFunction.getFunctionIdentifier());
String functionIdentifier = functionIdentifierTransfer == null ? hwDeviceModeFunction.getFunctionIdentifier() : functionIdentifierTransfer;
schemaField.setFieldName(functionIdentifier);
Integer dataType = hwDeviceModeFunction.getDataType();
schemaField.setDataTypeCode(dataType);
//一个integer类型一个long类型需要转换为string类型比较
if (String.valueOf(dataType).equals(String.valueOf(DataTypeEnums.NCHAR.getDataCode()))) {
schemaField.setSize(Integer.valueOf(hwDeviceModeFunction.getDataDefinition()));
}
tdSuperTableVo.setDatabaseName(dbName);
tdSuperTableVo.setSuperTableName(superTableName);
tdSuperTableVo.setField(schemaField);
R<?> tdReturnMsg = this.remoteTdEngineService.addSuperTableColumn(tdSuperTableVo, SecurityConstants.INNER);
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg());
}
}
}
/**
*
*
* @param plcDeviceModeFunction
* @return
*/
@Override
public int update(PlcDeviceModeFunction plcDeviceModeFunction) {
//校验有没有重复标识符
checkDuplicateIdentifiers(plcDeviceModeFunction);
//与数据库中的数据判断标识符有没有修改如果修改则在tdengine超级表删除老的字段增加修改的字段
String functionMode = plcDeviceModeFunction.getFunctionMode();
if (functionMode.equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) {
PlcDeviceModeFunction dbHwDeviceModeFunction = plcDeviceModeFunctionDao
.queryById(plcDeviceModeFunction.getModeFunctionId());
String dbFunctionIdentifier = dbHwDeviceModeFunction.getFunctionIdentifier();
String functionIdentifier = plcDeviceModeFunction.getFunctionIdentifier();
Integer dbDataType = dbHwDeviceModeFunction.getDataType();
Integer dataType = plcDeviceModeFunction.getDataType();
//标识符或数据类型变化时需要先删除超级表column再增加新的column,删除的column数据将会清空(有事务问题,暂时不支持)
if (!dbFunctionIdentifier.equalsIgnoreCase(functionIdentifier)
|| !dbDataType.equals(dataType)) {
// this.dropTdSuperTableColumn(dbHwDeviceModeFunction);
// this.addTdSuperTableColumn(hwDeviceModeFunction);
throw new RuntimeException("标识符和数据类型不支持修改,可删除再新建");
} else {
if (String.valueOf(dataType).equals(String.valueOf(DataTypeEnums.NCHAR.getDataCode()))) {
int dbDataDefinition = Integer.parseInt(dbHwDeviceModeFunction.getDataDefinition());
int dataDefinition = Integer.parseInt(plcDeviceModeFunction.getDataDefinition());
if (dbDataDefinition > dataDefinition) {
throw new ServiceException("数据长度只能改大");
} else if (dbDataDefinition < dataDefinition) {
this.modifyTdSuperTableColumn(plcDeviceModeFunction);
}
}
}
} else {
plcDeviceModeFunctionDao.deleteById(plcDeviceModeFunction.getModeFunctionId());
List<PlcDeviceModeFunction> hwDeviceModeFunctions = new ArrayList<>();
hwDeviceModeFunctions.add(plcDeviceModeFunction);
// batchInsertHwDeviceModeParameters(hwDeviceModeFunctions);
}
return plcDeviceModeFunctionDao.update(plcDeviceModeFunction);
}
private void modifyTdSuperTableColumn(PlcDeviceModeFunction hwDeviceModeFunction) {
String functionMode = hwDeviceModeFunction.getFunctionMode();
if (functionMode.equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) {
Long deviceModeId = hwDeviceModeFunction.getDeviceModeId();
String dbName = TdEngineConstants.getDatabaseName();
String superTableName = TdEngineConstants.PLC_SUPER_TABLE_NAME_PREFIX + deviceModeId;
TdSuperTableVo tdSuperTableVo = new TdSuperTableVo();
TdField schemaField = new TdField();
String functionIdentifierTransfer = TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(hwDeviceModeFunction.getFunctionIdentifier());
String functionIdentifier = functionIdentifierTransfer == null ? hwDeviceModeFunction.getFunctionIdentifier() : functionIdentifierTransfer;
schemaField.setFieldName(functionIdentifier);
Integer dataType = hwDeviceModeFunction.getDataType();
schemaField.setDataTypeCode(dataType.intValue());
//一个integer类型一个long类型需要转换为string类型比较
if (String.valueOf(dataType).equals(String.valueOf(DataTypeEnums.NCHAR.getDataCode()))) {
schemaField.setSize(Integer.valueOf(hwDeviceModeFunction.getDataDefinition()));
}
tdSuperTableVo.setDatabaseName(dbName);
tdSuperTableVo.setSuperTableName(superTableName);
tdSuperTableVo.setField(schemaField);
R<?> tdReturnMsg = this.remoteTdEngineService.modifySuperTableColumn(tdSuperTableVo, SecurityConstants.INNER);
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg());
}
}
}
/**
* @param: hwDeviceModeFunction
* @description
* @author xins
* @date 2023-09-13 13:38
*/
private void checkDuplicateIdentifiers(PlcDeviceModeFunction hwDeviceModeFunction) {
String functionIdentifier = hwDeviceModeFunction.getFunctionIdentifier();
if (TdEngineConstants.ABNDON_FUNCTION_IDENTIFIERS.contains(functionIdentifier.toLowerCase())) {
throw new ServiceException("标识符不能等于:" + functionIdentifier);
}
// R<String> keyLongitudeR = remoteConfigService.getConfigKeyStr("hw.gps.longitude");
// R<String> keyLatitudeR = remoteConfigService.getConfigKeyStr("hw.gps.latitude");
// String keyLongitude = keyLongitudeR.getData();
// String keyLatitude = keyLatitudeR.getData();
// if (StringUtils.isEmpty(hwDeviceModeFunction.getCoordinate()) &&
// (hwDeviceModeFunction.getFunctionIdentifier().equalsIgnoreCase(keyLongitude)
// || hwDeviceModeFunction.getFunctionIdentifier().equalsIgnoreCase(keyLatitude))) {
// throw new ServiceException("非定位设备模型标识符不能等于:" + keyLongitude + "或" + keyLatitude);
// }
Long deviceModeId = hwDeviceModeFunction.getDeviceModeId();
HwDeviceModeFunction queryDeviceModeFunction = new HwDeviceModeFunction();
queryDeviceModeFunction.setDeviceModeId(deviceModeId);
List<PlcDeviceModeFunction> hwDeviceModeFunctions = plcDeviceModeFunctionDao.selectFunctionList(deviceModeId);
/**
*
*/
long duplicateCount = hwDeviceModeFunctions.stream().filter(dmf ->
((hwDeviceModeFunction.getModeFunctionId() == null) ||
(hwDeviceModeFunction.getModeFunctionId() != null && !hwDeviceModeFunction.getModeFunctionId().equals(dmf.getModeFunctionId())))
&& dmf.getFunctionIdentifier().equalsIgnoreCase(hwDeviceModeFunction.getFunctionIdentifier())).count();
if (duplicateCount > 0) {
throw new ServiceException("标识符重复");
}
}
/**
*
*
* @param modeFunctionId
* @return
*/
@Override
public int deleteById(Long modeFunctionId) {
PlcDeviceModeFunction hwDeviceModeFunction = plcDeviceModeFunctionDao.queryById(modeFunctionId);
//查询是否有已发布的设备关联此设备模型
int rows = plcDeviceModeFunctionDao.deleteById(modeFunctionId);
this.dropTdSuperTableColumn(hwDeviceModeFunction);
return rows;
}
private void dropTdSuperTableColumn(PlcDeviceModeFunction hwDeviceModeFunction) {
String functionMode = hwDeviceModeFunction.getFunctionMode();
if (functionMode.equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) {
Long deviceModeId = hwDeviceModeFunction.getDeviceModeId();
String dbName = TdEngineConstants.getDatabaseName();
String superTableName = TdEngineConstants.PLC_SUPER_TABLE_NAME_PREFIX + deviceModeId;
TdSuperTableVo tdSuperTableVo = new TdSuperTableVo();
TdField schemaField = new TdField();
schemaField.setFieldName(hwDeviceModeFunction.getFunctionIdentifier());
tdSuperTableVo.setDatabaseName(dbName);
tdSuperTableVo.setSuperTableName(superTableName);
tdSuperTableVo.setField(schemaField);
R<?> tdReturnMsg = this.remoteTdEngineService.dropColumnForSuperTable(tdSuperTableVo, SecurityConstants.INNER);
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg());
}
}
}
}

@ -0,0 +1,189 @@
package com.ruoyi.business.service.impl;
import com.ruoyi.business.domain.HwDeviceMode;
import com.ruoyi.business.domain.HwDeviceModeFunction;
import com.ruoyi.business.domain.PlcDeviceMode;
import com.ruoyi.business.domain.PlcDeviceModeFunction;
import com.ruoyi.business.mapper.PlcDeviceModeDao;
import com.ruoyi.business.mapper.PlcDeviceModeFunctionDao;
import com.ruoyi.business.service.PlcDeviceModeService;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.constant.HwDictConstants;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.constant.TdEngineConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.enums.DataTypeEnums;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.tdengine.api.RemoteTdEngineService;
import com.ruoyi.tdengine.api.domain.TdField;
import com.ruoyi.tdengine.api.domain.TdSuperTableVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
* plc(PlcDeviceMode)
*
* @author makejava
* @since 2024-12-19 16:23:27
*/
@Service("plcDeviceModeService")
public class PlcDeviceModeServiceImpl implements PlcDeviceModeService {
@Autowired
private PlcDeviceModeDao plcDeviceModeDao;
@Autowired
private PlcDeviceModeFunctionDao plcDeviceModeFunctionDao;
@Autowired
private RemoteTdEngineService remoteTdEngineService;
/**
* ID
*
* @param deviceModeId
* @return
*/
@Override
public PlcDeviceMode queryById(Long deviceModeId) {
return this.plcDeviceModeDao.queryById(deviceModeId);
}
/**
*
*
* @param plcDeviceMode
* @param pageRequest
* @return
*/
@Override
public Page<PlcDeviceMode> queryByPage(PlcDeviceMode plcDeviceMode, PageRequest pageRequest) {
long total = this.plcDeviceModeDao.count(plcDeviceMode);
return new PageImpl<>(this.plcDeviceModeDao.queryAllByLimit(plcDeviceMode, pageRequest), pageRequest, total);
}
/**
*
*
* @param plcDeviceMode
* @return
*/
@Override
public int insert(PlcDeviceMode plcDeviceMode) {
Long tenantId = SecurityUtils.getTenantId();
plcDeviceMode.setTenantId(tenantId);
plcDeviceMode.setDeviceModeStatus("1");
int rows = plcDeviceModeDao.insert(plcDeviceMode);
List<PlcDeviceModeFunction> functionList = plcDeviceMode.getFunctionList();
for (PlcDeviceModeFunction function : functionList) {
function.setDeviceModeId(plcDeviceMode.getDeviceModeId());
}
int i = plcDeviceModeFunctionDao.insertBatch(functionList);
this.createTdSuperTable(plcDeviceMode);
return rows;
}
private void createTdSuperTable(PlcDeviceMode plcDeviceMode) {
TdSuperTableVo tdSuperTableVo = new TdSuperTableVo();
String dbName = TdEngineConstants.getDatabaseName();
String superTableName = TdEngineConstants.PLC_SUPER_TABLE_NAME_PREFIX + plcDeviceMode.getDeviceModeId();
List<TdField> tagFields = new ArrayList<TdField>();
TdField tagField = new TdField();
tagField.setFieldName(TdEngineConstants.PLC_TAG_IP);
tagField.setDataTypeCode(TdEngineConstants.PLC_TAG_IP_TYPE);
tagField.setSize(TdEngineConstants.PLC_TAG_IP_SIZE);
tagFields.add(tagField);
tagField = new TdField();
tagField.setFieldName(TdEngineConstants.PLC_TAG_PORT);
tagField.setDataTypeCode(TdEngineConstants.PLC_TAG_PORT_TYPE);
// tagField.setSize(TdEngineConstants.ST_TAG_DEVICENAME_SIZE);
tagFields.add(tagField);
tagField = new TdField();
tagField.setFieldName(TdEngineConstants.PLC_TAG_LOCATION);
tagField.setDataTypeCode(TdEngineConstants.PLC_TAG_LOCATION_TYPE);
tagField.setSize(TdEngineConstants.PLC_TAG_LOCATION_SIZE);
tagFields.add(tagField);
List<TdField> schemaFields = new ArrayList<TdField>();
List<PlcDeviceModeFunction> hwDeviceModeFunctions = plcDeviceMode.getFunctionList();
TdField schemaField;
for (PlcDeviceModeFunction hwDeviceModeFunction : hwDeviceModeFunctions) {
String functionMode = hwDeviceModeFunction.getFunctionMode();
if (functionMode.equalsIgnoreCase(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) {
schemaField = new TdField();
// String functionIdentifierTransfer = TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(hwDeviceModeFunction.getFunctionIdentifier());
// String functionIdentifier = functionIdentifierTransfer == null ? hwDeviceModeFunction.getFunctionIdentifier() : functionIdentifierTransfer;
String functionIdentifier = hwDeviceModeFunction.getFunctionIdentifier();
schemaField.setFieldName(functionIdentifier);
Integer dataType = hwDeviceModeFunction.getDataType();
schemaField.setDataTypeCode(dataType);
if (String.valueOf(dataType).equals(String.valueOf(DataTypeEnums.NCHAR.getDataCode()))) {
schemaField.setSize(Integer.valueOf(hwDeviceModeFunction.getDataDefinition()));
}
schemaFields.add(schemaField);
}
}
tdSuperTableVo.setDatabaseName(dbName);
tdSuperTableVo.setSuperTableName(superTableName);
tdSuperTableVo.setFirstFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME);
tdSuperTableVo.setSchemaFields(schemaFields);
tdSuperTableVo.setTagsFields(tagFields);
R<?> tdReturnMsg = this.remoteTdEngineService.createSuperTable(tdSuperTableVo, SecurityConstants.INNER);
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg());
}
}
/**
*
*
* @param plcDeviceMode
* @return
*/
@Override
public int update(PlcDeviceMode plcDeviceMode) {
return this.plcDeviceModeDao.update(plcDeviceMode);
}
@Override
public int deleteHwDeviceModeByDeviceModeIds(Long[] deviceModeIds) {
plcDeviceModeFunctionDao.deleteHwDeviceModeFunctionByDeviceModeIds(deviceModeIds);
return plcDeviceModeDao.deleteHwDeviceModeByDeviceModeIds(deviceModeIds);
}
@Override
public List<PlcDeviceModeFunction> selectFunctionList(Long deviceModeId) {
return plcDeviceModeFunctionDao.selectFunctionList(deviceModeId);
}
@Override
public PlcDeviceMode selectHwDeviceModeByDeviceModeId(Long deviceModeId) {
return plcDeviceModeDao.queryById(deviceModeId);
}
@Override
public List<PlcDeviceMode> selectList(PlcDeviceMode hwDeviceMode) {
return plcDeviceModeDao.selectList(hwDeviceMode);
}
/**
*
*
* @param deviceModeId
* @return
*/
@Override
public boolean deleteById(Long deviceModeId) {
return this.plcDeviceModeDao.deleteById(deviceModeId) > 0;
}
}

@ -0,0 +1,571 @@
package com.ruoyi.business.service.impl;
import HslCommunication.Core.Transfer.DataFormat;
import HslCommunication.Core.Types.OperateResult;
import HslCommunication.Core.Types.OperateResultExOne;
import HslCommunication.ModBus.ModbusTcpNet;
import HslCommunication.Profinet.AllenBradley.AllenBradleyNet;
import HslCommunication.Profinet.Melsec.MelsecA1ENet;
import HslCommunication.Profinet.Melsec.MelsecFxSerialOverTcp;
import HslCommunication.Profinet.Melsec.MelsecHelper;
import HslCommunication.Profinet.Melsec.MelsecMcNet;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.business.domain.*;
import com.ruoyi.business.mapper.PlcDeviceDao;
import com.ruoyi.business.mapper.PlcDeviceModeFunctionDao;
import com.ruoyi.business.service.PlcDeviceService;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.constant.HwDictConstants;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.constant.TdEngineConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.enums.DataTypeEnums;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser;
import com.ruoyi.tdengine.api.RemoteTdEngineService;
import com.ruoyi.tdengine.api.domain.AlterTagVo;
import com.ruoyi.tdengine.api.domain.TdField;
import com.ruoyi.tdengine.api.domain.TdTableVo;
import org.apache.plc4x.java.PlcDriverManager;
import org.apache.plc4x.java.api.PlcConnection;
import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
import org.apache.plc4x.java.api.messages.PlcReadRequest;
import org.apache.plc4x.java.api.messages.PlcReadResponse;
import org.apache.plc4x.java.api.metadata.PlcConnectionMetadata;
import org.apache.plc4x.java.ethernetip.EtherNetIpPlcDriver;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
/**
* plc(PlcDevice)
*
* @author makejava
* @since 2024-12-19 16:22:51
*/
@Service("plcDeviceService")
public class PlcDeviceServiceImpl implements PlcDeviceService {
@Resource
private PlcDeviceDao plcDeviceDao;
@Autowired
private RemoteTdEngineService remoteTdEngineService;
@Autowired
private PlcDeviceModeFunctionDao plcDeviceModeFunctionDao;
/**
* ID
*
* @param deviceId
* @return
*/
@Override
public PlcDevice queryById(Long deviceId) throws JsonProcessingException {
// List<PlcDevice> plcDevices = this.plcDeviceDao.queryPlcDevices(1);
// for (PlcDevice plcDevice : plcDevices) {
// int station = plcDevice.getStation();
// byte a = (byte)station;
// int length = plcDevice.getLength();
// short b = (short)length;
// ModbusTcpNet tcpNet = new ModbusTcpNet(plcDevice.getIp(),plcDevice.getPort1(), a);
// tcpNet.getByteTransform().setDataFormat(DataFormat.CDAB);
// TdTableVo tdTableVo = new TdTableVo();
// List<TdField> schemaFields = new ArrayList<>();
// TdField firstTdField = new TdField();
// firstTdField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME);
// long currentTimeMillis = System.currentTimeMillis();
// firstTdField.setFieldValue(currentTimeMillis);
// String databaseName = TdEngineConstants.getDatabaseName();
// String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX + plcDevice.getDeviceId();
// // firstTdField.setFieldValue(ts);
// schemaFields.add(firstTdField);
// List<PlcDeviceModeFunction> list = plcDeviceModeFunctionDao.selectFunctions(plcDevice.getDeviceModeId());
// if (plcDevice.getDataType().equals("10")){
// OperateResultExOne<String> resultExOne = tcpNet.ReadString(plcDevice.getDLocation(),b, StandardCharsets.UTF_8);
// String content = resultExOne.Content;
// ObjectMapper objectMapper = new ObjectMapper();
// Map map = objectMapper.readValue(content, Map.class);
// for (PlcDeviceModeFunction function : list) {
// Object value = map.get(function.getFunctionIdentifier());
// TdField tdField = new TdField();
// tdField.setFieldName(function.getFunctionIdentifier());
// tdField.setFieldValue(value);
// schemaFields.add(tdField);
// }
// }else if (plcDevice.getDataType().equals("2")){
// OperateResultExOne<Integer> exOne = tcpNet.ReadInt32(plcDevice.getDLocation());
// TdField tdField = new TdField();
// tdField.setFieldName(list.get(0).getFunctionIdentifier());
// tdField.setFieldValue(exOne.Content);
// schemaFields.add(tdField);
// }else if (plcDevice.getDataType().equals("4")){
// OperateResultExOne<Float> floatOperateResultExOne = tcpNet.ReadFloat(plcDevice.getDLocation());
// TdField tdField = new TdField();
// tdField.setFieldName(list.get(0).getFunctionIdentifier());
// tdField.setFieldValue(floatOperateResultExOne.Content);
// schemaFields.add(tdField);
// }
// tdTableVo.setDatabaseName(databaseName);
// tdTableVo.setTableName(tableName);
// tdTableVo.setSchemaFields(schemaFields);
// final R<?> insertResult = this.remoteTdEngineService.insertTable(tdTableVo , SecurityConstants.INNER);
// }
// OperateResultExOne<Float> exOne = tcpNet.ReadFloat("100");
// System.out.println(exOne.Content);
return this.plcDeviceDao.selectHwDeviceByDeviceId(deviceId);
}
@Override
public int updateDevice(PlcDevice hwDevice) {
PlcDevice dbDevice = plcDeviceDao.selectHwDeviceByDeviceId(hwDevice.getDeviceId());
if (dbDevice.getDeviceStatus().equals(HwDictConstants.DEVICE_STATUS_PUBLISH)) {
throw new ServiceException("已发布状态不能修改");
}
hwDevice.setUpdateTime(DateUtils.getNowDate());
int rows = plcDeviceDao.update(hwDevice);
this.updateTdEngine(hwDevice, dbDevice);
return rows;
}
public void updateTdEngine(PlcDevice hwDevice, PlcDevice dbDevice) {
String databaseName = TdEngineConstants.getDatabaseName();
String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX + hwDevice.getDeviceId();
AlterTagVo alterTagVo = new AlterTagVo();
alterTagVo.setDatabaseName(databaseName);
alterTagVo.setTableName(tableName);
R<?> tdReturnMsg;
if (!hwDevice.getIp().equals(dbDevice.getIp())) {
alterTagVo.setTagName(TdEngineConstants.PLC_TAG_IP);
alterTagVo.setTagValue("'" + hwDevice.getIp() + "'");
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo, SecurityConstants.INNER);
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg());
}
}
if (!hwDevice.getPort1().equals(dbDevice.getPort1())) {
alterTagVo.setTagName(TdEngineConstants.PLC_TAG_PORT);
alterTagVo.setTagValue(hwDevice.getPort1());
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo, SecurityConstants.INNER);
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg());
}
}
if (!hwDevice.getLocation().equals(dbDevice.getLocation())) {
alterTagVo.setTagName(TdEngineConstants.PLC_TAG_LOCATION);
alterTagVo.setTagValue("'" + hwDevice.getLocation() + "'");
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo, SecurityConstants.INNER);
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg());
}
}
}
@Override
public int changeDeviceStatus(PlcDevice device) {
PlcDevice dbDevice = plcDeviceDao.selectHwDeviceByDeviceId(device.getDeviceId());
if (dbDevice.getDeviceStatus().equals(HwDictConstants.DEVICE_STATUS_PUBLISH) && !device.getDeviceStatus().equals("0")) {
throw new ServiceException("已发布状态不能修改");
}
device.setUpdateBy(SecurityUtils.getUsername());
Date currentDate = new Date();
device.setUpdateTime(currentDate);
device.setPublishTime(currentDate);
return plcDeviceDao.update(device);
}
@Override
public List<PlcDeviceMode> selectHwDeviceModeList(PlcDeviceMode queryDeviceMode) {
return plcDeviceDao.selectPlcDeviceMode(queryDeviceMode);
}
@Override
public List<PlcDevice> selectHwDeviceJoinList(PlcDevice hwDevice) {
LoginUser loginUser = SecurityUtils.getLoginUser();
SysUser sysUser = loginUser.getSysUser();
Long tenantId = sysUser.getTenantId();
hwDevice.setTenantId(tenantId);
return plcDeviceDao.selectHwDeviceJoinList(hwDevice);
}
// mc协议获取处理plc数据
@Override
public String mcDataProcess() throws JsonProcessingException {
List<PlcDevice> plcDevices = this.plcDeviceDao.queryPlcDevices(1);
for (PlcDevice plcDevice : plcDevices) {
int station = plcDevice.getStation();
byte a = (byte)station;
int length = plcDevice.getLength();
short b = (short)length;
MelsecMcNet melsecMcNet = new MelsecMcNet(plcDevice.getIp(),plcDevice.getPort1());
// ModbusTcpNet tcpNet = new ModbusTcpNet(plcDevice.getIp(),plcDevice.getPort1(), a);
// tcpNet.getByteTransform().setDataFormat(DataFormat.CDAB);
TdTableVo tdTableVo = new TdTableVo();
List<TdField> schemaFields = new ArrayList<>();
TdField firstTdField = new TdField();
firstTdField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME);
long currentTimeMillis = System.currentTimeMillis();
firstTdField.setFieldValue(currentTimeMillis);
String databaseName = TdEngineConstants.getDatabaseName();
String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX + plcDevice.getDeviceId();
// firstTdField.setFieldValue(ts);
schemaFields.add(firstTdField);
List<PlcDeviceModeFunction> list = plcDeviceModeFunctionDao.selectFunctions(plcDevice.getDeviceModeId());
if (plcDevice.getDataType().equals("10")){
OperateResultExOne<String> resultExOne = melsecMcNet.ReadString(plcDevice.getLocation(),b, StandardCharsets.UTF_8);
String content = resultExOne.Content;
ObjectMapper objectMapper = new ObjectMapper();
Map map = objectMapper.readValue(content, Map.class);
for (PlcDeviceModeFunction function : list) {
Object value = map.get(function.getFunctionIdentifier());
TdField tdField = new TdField();
tdField.setFieldName(function.getFunctionIdentifier());
tdField.setFieldValue(value);
schemaFields.add(tdField);
}
}else if (plcDevice.getDataType().equals("2")||plcDevice.getDataType().equals("9")){
OperateResultExOne<Integer> exOne = melsecMcNet.ReadInt32(plcDevice.getLocation());
TdField tdField = new TdField();
tdField.setFieldName(list.get(0).getFunctionIdentifier());
tdField.setFieldValue(exOne.Content);
schemaFields.add(tdField);
}else if (plcDevice.getDataType().equals("4")){
OperateResultExOne<Float> floatOperateResultExOne = melsecMcNet.ReadFloat(plcDevice.getLocation());
TdField tdField = new TdField();
tdField.setFieldName(list.get(0).getFunctionIdentifier());
tdField.setFieldValue(floatOperateResultExOne.Content);
schemaFields.add(tdField);
}else if (plcDevice.getDataType().equals("5")){
OperateResultExOne<Double> doubleOperateResultExOne = melsecMcNet.ReadDouble(plcDevice.getLocation());
TdField tdField = new TdField();
tdField.setFieldName(list.get(0).getFunctionIdentifier());
tdField.setFieldValue(doubleOperateResultExOne.Content);
schemaFields.add(tdField);
}
tdTableVo.setDatabaseName(databaseName);
tdTableVo.setTableName(tableName);
tdTableVo.setSchemaFields(schemaFields);
final R<?> insertResult = this.remoteTdEngineService.insertTable(tdTableVo , SecurityConstants.INNER);
}
return null;
}
// modbus协议获取处理plc数据
@Override
public String modbusDataProcess() throws JsonProcessingException {
List<PlcDevice> plcDevices = this.plcDeviceDao.queryPlcDevices(2);
for (PlcDevice plcDevice : plcDevices) {
int station = plcDevice.getStation();
byte a = (byte)station;
int length = plcDevice.getLength();
short b = (short)length;
ModbusTcpNet tcpNet = new ModbusTcpNet(plcDevice.getIp(),plcDevice.getPort1(), a);
tcpNet.getByteTransform().setDataFormat(DataFormat.CDAB);
TdTableVo tdTableVo = new TdTableVo();
List<TdField> schemaFields = new ArrayList<>();
TdField firstTdField = new TdField();
firstTdField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME);
long currentTimeMillis = System.currentTimeMillis();
firstTdField.setFieldValue(currentTimeMillis);
String databaseName = TdEngineConstants.getDatabaseName();
String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX + plcDevice.getDeviceId();
// firstTdField.setFieldValue(ts);
schemaFields.add(firstTdField);
List<PlcDeviceModeFunction> list = plcDeviceModeFunctionDao.selectFunctions(plcDevice.getDeviceModeId());
if (plcDevice.getDataType().equals("10")){
OperateResultExOne<String> resultExOne = tcpNet.ReadString(plcDevice.getLocation(),b, StandardCharsets.UTF_8);
String content = resultExOne.Content;
ObjectMapper objectMapper = new ObjectMapper();
Map map = objectMapper.readValue(content, Map.class);
for (PlcDeviceModeFunction function : list) {
Object value = map.get(function.getFunctionIdentifier());
TdField tdField = new TdField();
tdField.setFieldName(function.getFunctionIdentifier());
tdField.setFieldValue(value);
schemaFields.add(tdField);
}
}else if (plcDevice.getDataType().equals("2")||plcDevice.getDataType().equals("9")){
OperateResultExOne<Integer> exOne = tcpNet.ReadInt32(plcDevice.getLocation());
TdField tdField = new TdField();
tdField.setFieldName(list.get(0).getFunctionIdentifier());
tdField.setFieldValue(exOne.Content);
schemaFields.add(tdField);
}else if (plcDevice.getDataType().equals("4")){
OperateResultExOne<Float> floatOperateResultExOne = tcpNet.ReadFloat(plcDevice.getLocation());
TdField tdField = new TdField();
tdField.setFieldName(list.get(0).getFunctionIdentifier());
tdField.setFieldValue(floatOperateResultExOne.Content);
schemaFields.add(tdField);
}else if (plcDevice.getDataType().equals("5")){
OperateResultExOne<Double> doubleOperateResultExOne = tcpNet.ReadDouble(plcDevice.getLocation());
TdField tdField = new TdField();
tdField.setFieldName(list.get(0).getFunctionIdentifier());
tdField.setFieldValue(doubleOperateResultExOne.Content);
schemaFields.add(tdField);
}
tdTableVo.setDatabaseName(databaseName);
tdTableVo.setTableName(tableName);
tdTableVo.setSchemaFields(schemaFields);
final R<?> insertResult = this.remoteTdEngineService.insertTable(tdTableVo , SecurityConstants.INNER);
}
return null;
}
//EtherNet协议数据读取
@Override
public String ehternetDataProcess() throws JsonProcessingException {
// AllenBradleyNet plc = new AllenBradleyNet("127.0.0.1",44818);
// OperateResult operateResult = plc.ConnectServer();
// OperateResultExOne<String> f = plc.ReadString("F");
// String content = f.Content;
// return null;
List<PlcDevice> plcDevices = this.plcDeviceDao.queryPlcDevices(4);
for (PlcDevice plcDevice : plcDevices) {
int station = plcDevice.getStation();
byte a = (byte)station;
int length = plcDevice.getLength();
short b = (short)length;
// ModbusTcpNet tcpNet = new ModbusTcpNet(plcDevice.getIp(),plcDevice.getPort1(), a);
// tcpNet.getByteTransform().setDataFormat(DataFormat.CDAB);
AllenBradleyNet ethernet = new AllenBradleyNet(plcDevice.getIp(),plcDevice.getPort1());
TdTableVo tdTableVo = new TdTableVo();
List<TdField> schemaFields = new ArrayList<>();
TdField firstTdField = new TdField();
firstTdField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME);
long currentTimeMillis = System.currentTimeMillis();
firstTdField.setFieldValue(currentTimeMillis);
String databaseName = TdEngineConstants.getDatabaseName();
String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX + plcDevice.getDeviceId();
// firstTdField.setFieldValue(ts);
schemaFields.add(firstTdField);
List<PlcDeviceModeFunction> list = plcDeviceModeFunctionDao.selectFunctions(plcDevice.getDeviceModeId());
if (plcDevice.getDataType().equals("10")){
OperateResultExOne<String> resultExOne = ethernet.ReadString(plcDevice.getLocation(),b, StandardCharsets.UTF_8);
String content = resultExOne.Content;
ObjectMapper objectMapper = new ObjectMapper();
Map map = objectMapper.readValue(content, Map.class);
for (PlcDeviceModeFunction function : list) {
Object value = map.get(function.getFunctionIdentifier());
TdField tdField = new TdField();
tdField.setFieldName(function.getFunctionIdentifier());
tdField.setFieldValue(value);
schemaFields.add(tdField);
}
}else if (plcDevice.getDataType().equals("2")||plcDevice.getDataType().equals("9")){
OperateResultExOne<Integer> exOne = ethernet.ReadInt32(plcDevice.getLocation());
TdField tdField = new TdField();
tdField.setFieldName(list.get(0).getFunctionIdentifier());
tdField.setFieldValue(exOne.Content);
schemaFields.add(tdField);
}else if (plcDevice.getDataType().equals("4")){
OperateResultExOne<Float> floatOperateResultExOne = ethernet.ReadFloat(plcDevice.getLocation());
TdField tdField = new TdField();
tdField.setFieldName(list.get(0).getFunctionIdentifier());
tdField.setFieldValue(floatOperateResultExOne.Content);
schemaFields.add(tdField);
}else if (plcDevice.getDataType().equals("5")){
OperateResultExOne<Double> doubleOperateResultExOne = ethernet.ReadDouble(plcDevice.getLocation());
TdField tdField = new TdField();
tdField.setFieldName(list.get(0).getFunctionIdentifier());
tdField.setFieldValue(doubleOperateResultExOne.Content);
schemaFields.add(tdField);
}
tdTableVo.setDatabaseName(databaseName);
tdTableVo.setTableName(tableName);
tdTableVo.setSchemaFields(schemaFields);
final R<?> insertResult = this.remoteTdEngineService.insertTable(tdTableVo , SecurityConstants.INNER);
}
return null;
}
// A1E协议
public String aeDataProcess() throws JsonProcessingException {
List<PlcDevice> plcDevices = this.plcDeviceDao.queryPlcDevices(3);
for (PlcDevice plcDevice : plcDevices) {
int station = plcDevice.getStation();
byte a = (byte)station;
int length = plcDevice.getLength();
short b = (short)length;
// ModbusTcpNet tcpNet = new ModbusTcpNet(plcDevice.getIp(),plcDevice.getPort1(), a);
// tcpNet.getByteTransform().setDataFormat(DataFormat.CDAB);
MelsecA1ENet net = new MelsecA1ENet(plcDevice.getIp(),plcDevice.getPort1());
TdTableVo tdTableVo = new TdTableVo();
List<TdField> schemaFields = new ArrayList<>();
TdField firstTdField = new TdField();
firstTdField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME);
long currentTimeMillis = System.currentTimeMillis();
firstTdField.setFieldValue(currentTimeMillis);
String databaseName = TdEngineConstants.getDatabaseName();
String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX + plcDevice.getDeviceId();
// firstTdField.setFieldValue(ts);
schemaFields.add(firstTdField);
List<PlcDeviceModeFunction> list = plcDeviceModeFunctionDao.selectFunctions(plcDevice.getDeviceModeId());
if (plcDevice.getDataType().equals("10")){
OperateResultExOne<String> resultExOne = net.ReadString(plcDevice.getLocation(),b, StandardCharsets.UTF_8);
String content = resultExOne.Content;
ObjectMapper objectMapper = new ObjectMapper();
Map map = objectMapper.readValue(content, Map.class);
for (PlcDeviceModeFunction function : list) {
Object value = map.get(function.getFunctionIdentifier());
TdField tdField = new TdField();
tdField.setFieldName(function.getFunctionIdentifier());
tdField.setFieldValue(value);
schemaFields.add(tdField);
}
}else if (plcDevice.getDataType().equals("2")||plcDevice.getDataType().equals("9")){
OperateResultExOne<Integer> exOne = net.ReadInt32(plcDevice.getLocation());
TdField tdField = new TdField();
tdField.setFieldName(list.get(0).getFunctionIdentifier());
tdField.setFieldValue(exOne.Content);
schemaFields.add(tdField);
}else if (plcDevice.getDataType().equals("4")){
OperateResultExOne<Float> floatOperateResultExOne = net.ReadFloat(plcDevice.getLocation());
TdField tdField = new TdField();
tdField.setFieldName(list.get(0).getFunctionIdentifier());
tdField.setFieldValue(floatOperateResultExOne.Content);
schemaFields.add(tdField);
}else if (plcDevice.getDataType().equals("5")){
OperateResultExOne<Double> doubleOperateResultExOne = net.ReadDouble(plcDevice.getLocation());
TdField tdField = new TdField();
tdField.setFieldName(list.get(0).getFunctionIdentifier());
tdField.setFieldValue(doubleOperateResultExOne.Content);
schemaFields.add(tdField);
}
tdTableVo.setDatabaseName(databaseName);
tdTableVo.setTableName(tableName);
tdTableVo.setSchemaFields(schemaFields);
final R<?> insertResult = this.remoteTdEngineService.insertTable(tdTableVo , SecurityConstants.INNER);
}
return null;
}
/**
*
*
* @param plcDevice
* @param pageRequest
* @return
*/
@Override
public Page<PlcDevice> queryByPage(PlcDevice plcDevice, PageRequest pageRequest) {
long total = this.plcDeviceDao.count(plcDevice);
return new PageImpl<>(this.plcDeviceDao.queryAllByLimit(plcDevice, pageRequest), pageRequest, total);
}
/**
*
*
* @param plcDevice
* @return
*/
@Override
public int insert(PlcDevice plcDevice) {
String username = SecurityUtils.getUsername();
plcDevice.setCreateBy(username);
plcDevice.setCreateTime(new Date());
Long tenantId = SecurityUtils.getTenantId();
plcDevice.setTenantId(tenantId);
plcDevice.setDeviceStatus("0");
int deviceId = this.plcDeviceDao.insert(plcDevice);
this.createTdTable(plcDevice);
return deviceId;
}
// public void createTdDeviceStatusTable(HwDevice hwDevice) {
// TdTableVo tdTableVo = new TdTableVo();
// tdTableVo.setDatabaseName(TdEngineConstants.PLATFORM_DB_NAME);
// tdTableVo.setSuperTableName(TdEngineConstants.DEFAULT_DEVICE_STATUS_SUPER_TABLE_NAME);
// tdTableVo.setTableName(TdEngineConstants.getDeviceStatusTableName(hwDevice.getDeviceId()));
//
// List<TdField> tagsFields = getTdTagsFields(hwDevice);
//
// TdField sceneIdTag = new TdField();
// sceneIdTag.setFieldName(TdEngineConstants.ST_TAG_SCENEID);
// sceneIdTag.setFieldValue(hwDevice.getSceneId());
// tagsFields.add(sceneIdTag);
//
// tdTableVo.setTagsFieldValues(tagsFields);
//
// R<?> tdReturnMsg = this.remoteTdEngineService.createTable(tdTableVo, SecurityConstants.INNER);
// if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
// throw new RuntimeException(tdReturnMsg.getMsg());
// }
// }
public void createTdTable(PlcDevice hwDevice) {
TdTableVo tdTableVo = new TdTableVo();
String databaseName = TdEngineConstants.getDatabaseName();
String superTableName = TdEngineConstants.PLC_SUPER_TABLE_NAME_PREFIX+hwDevice.getDeviceModeId();
String tableName = TdEngineConstants.PLC_TABLE_NAME_PREFIX+hwDevice.getDeviceId();
List<TdField> tagsFields = getTdTagsFields(hwDevice);
tdTableVo.setDatabaseName(databaseName);
tdTableVo.setSuperTableName(superTableName);
tdTableVo.setTableName(tableName);
tdTableVo.setTagsFieldValues(tagsFields);
R<?> tdReturnMsg = this.remoteTdEngineService.createTable(tdTableVo, SecurityConstants.INNER);
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg());
}
}
private List<TdField> getTdTagsFields(PlcDevice hwDevice) {
List<TdField> tagFields = new ArrayList<TdField>();
TdField ipTag = new TdField();
ipTag.setFieldName(TdEngineConstants.PLC_TAG_IP);
ipTag.setFieldValue(hwDevice.getIp());
ipTag.setDataTypeCode(DataTypeEnums.NCHAR.getDataCode());
tagFields.add(ipTag);
TdField portTag = new TdField();
portTag.setFieldName(TdEngineConstants.PLC_TAG_PORT);
portTag.setFieldValue(hwDevice.getPort1());
tagFields.add(portTag);
TdField locationTag = new TdField();
locationTag.setFieldName(TdEngineConstants.PLC_TAG_LOCATION);
locationTag.setDataTypeCode(DataTypeEnums.NCHAR.getDataCode());
locationTag.setFieldValue(hwDevice.getLocation());
tagFields.add(locationTag);
return tagFields;
}
/**
*
*
* @param plcDevice
* @return
*/
@Override
public PlcDevice update(PlcDevice plcDevice) throws JsonProcessingException {
this.plcDeviceDao.update(plcDevice);
return this.queryById(plcDevice.getDeviceId());
}
/**
*
*
* @param deviceId
* @return
*/
@Override
public int deleteById(Long deviceId) {
return this.plcDeviceDao.deleteById(deviceId);
}
}

@ -0,0 +1,280 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.business.mapper.PlcDeviceDao">
<resultMap type="com.ruoyi.business.domain.PlcDevice" id="PlcDeviceMap">
<result property="deviceId" column="device_id" jdbcType="INTEGER"/>
<result property="deviceCode" column="device_code" jdbcType="VARCHAR"/>
<result property="deviceName" column="device_name" jdbcType="VARCHAR"/>
<result property="tenantId" column="tenant_id" jdbcType="INTEGER"/>
<result property="sceneId" column="scene_id" jdbcType="INTEGER"/>
<result property="ip" column="ip" jdbcType="VARCHAR"/>
<result property="port1" column="port1" jdbcType="INTEGER"/>
<result property="location" column="location" jdbcType="VARCHAR"/>
<result property="accessProtocol" column="access_protocol" jdbcType="INTEGER"/>
<result property="length" column="length" jdbcType="INTEGER"/>
<result property="deviceStatus" column="device_status" jdbcType="VARCHAR"/>
<result property="createBy" column="create_by" jdbcType="VARCHAR"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
</resultMap>
<!--查询单个-->
<select id="queryById" resultMap="PlcDeviceMap">
select
device_id, device_code, device_name, tenant_id, scene_id, ip, port1, location, access_protocol, length, device_status, create_by, create_time, update_by, update_time,data_type,station,device_mode_id,station
from plc_device
-- where device_id = #{deviceId}
</select>
<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="PlcDeviceMap">
select
device_id, device_code, device_name, tenant_id, scene_id, ip, port1, location, access_protocol, length, device_status, create_by, create_time, update_by, update_time
from plc_device
<where>
<if test="deviceId != null">
and device_id = #{deviceId}
</if>
<if test="deviceCode != null and deviceCode != ''">
and device_code = #{deviceCode}
</if>
<if test="deviceName != null and deviceName != ''">
and device_name = #{deviceName}
</if>
<if test="tenantId != null">
and tenant_id = #{tenantId}
</if>
<if test="sceneId != null">
and scene_id = #{sceneId}
</if>
<if test="ip != null and ip != ''">
and ip = #{ip}
</if>
<if test="port1 != null">
and port1 = #{port1}
</if>
<if test="location != null and location != ''">
and location = #{location}
</if>
<if test="accessProtocol != null">
and access_protocol = #{accessProtocol}
</if>
<if test="length != null">
and length = #{length}
</if>
<if test="deviceStatus != null and deviceStatus != ''">
and device_status = #{deviceStatus}
</if>
<if test="createBy != null and createBy != ''">
and create_by = #{createBy}
</if>
<if test="createTime != null">
and create_time = #{createTime}
</if>
<if test="updateBy != null and updateBy != ''">
and update_by = #{updateBy}
</if>
<if test="updateTime != null">
and update_time = #{updateTime}
</if>
</where>
limit #{pageable.offset}, #{pageable.pageSize}
</select>
<!--统计总行数-->
<select id="count" resultType="java.lang.Long">
select count(1)
from plc_device
<where>
<if test="deviceId != null">
and device_id = #{deviceId}
</if>
<if test="deviceCode != null and deviceCode != ''">
and device_code = #{deviceCode}
</if>
<if test="deviceName != null and deviceName != ''">
and device_name = #{deviceName}
</if>
<if test="tenantId != null">
and tenant_id = #{tenantId}
</if>
<if test="sceneId != null">
and scene_id = #{sceneId}
</if>
<if test="ip != null and ip != ''">
and ip = #{ip}
</if>
<if test="port1 != null">
and port1 = #{port1}
</if>
<if test="location != null and location != ''">
and location = #{location}
</if>
<if test="accessProtocol != null">
and access_protocol = #{accessProtocol}
</if>
<if test="length != null">
and length = #{length}
</if>
<if test="deviceStatus != null and deviceStatus != ''">
and device_status = #{deviceStatus}
</if>
<if test="createBy != null and createBy != ''">
and create_by = #{createBy}
</if>
<if test="createTime != null">
and create_time = #{createTime}
</if>
<if test="updateBy != null and updateBy != ''">
and update_by = #{updateBy}
</if>
<if test="updateTime != null">
and update_time = #{updateTime}
</if>
</where>
</select>
<select id="queryPlcDevices" resultType="com.ruoyi.business.domain.PlcDevice">
select
device_id, device_code, device_name, tenant_id, scene_id, ip, port1, location, access_protocol, length, device_status, create_by, create_time, update_by, update_time,data_type,station,device_mode_id,station
from plc_device where access_protocol = #{accessProtocol}
</select>
<select id="selectHwDeviceJoinList" resultType="com.ruoyi.business.domain.PlcDevice"
parameterType="com.ruoyi.business.domain.PlcDevice">
select hd.device_id,hd.device_name,
hd.tenant_id,hd.scene_id,hd.device_mode_id,hd.ip,hd.port1,hd.location,hd.data_type,hd.length,
hd.device_status,
hd.access_protocol,hd.station,
hs.scene_name,hdmf.device_mode_name,ht.tenant_name
from plc_device hd
left join hw_scene hs on hd.scene_id = hs.scene_id
left join plc_device_mode hdmf on hd.device_mode_id = hdmf.device_mode_id
left join hw_tenant ht on hd.tenant_id=ht.tenant_id
<where>
and hd.device_status != '9'
<if test="deviceCode != null and deviceCode != ''"> and hd.device_code like concat('%', #{deviceCode}, '%')</if>
<if test="deviceName != null and deviceName != ''"> and hd.device_name like concat('%', #{deviceName}, '%')</if>
<if test="sceneId != null "> and hd.scene_id = #{sceneId}</if>
<if test="deviceModeId != null "> and hd.device_mode_id = #{deviceModeId}</if>
<if test="deviceStatus != null and deviceStatus != ''"> and hd.device_status = #{deviceStatus}</if>
<if test="tenantId != null "> and hd.tenant_id = #{tenantId}</if>
</where>
order by hd.device_id desc
</select>
<select id="selectPlcDeviceMode" resultType="com.ruoyi.business.domain.PlcDeviceMode"
parameterType="com.ruoyi.business.domain.PlcDeviceMode">
select * from plc_device_mode
<where>
<if test="sceneId != null "> and scene_id = #{sceneId}</if>
</where>
order by device_mode_id desc
</select>
<select id="selectHwDeviceByDeviceId" resultType="com.ruoyi.business.domain.PlcDevice"
parameterType="java.lang.Long">
select
device_id, device_code, device_name, tenant_id, scene_id, ip, port1, location , access_protocol, length, device_status, create_by, create_time, update_by, update_time,data_type,station,device_mode_id,station
from plc_device
where device_id = #{deviceId}
</select>
<!--新增所有列-->
<insert id="insert" keyProperty="deviceId" useGeneratedKeys="true">
insert into plc_device(device_code, device_name, tenant_id, scene_id, ip, port1, location, access_protocol, length, device_status, create_by, create_time, update_by, update_time,station,data_type,device_mode_id)
values (#{deviceCode}, #{deviceName}, #{tenantId}, #{sceneId}, #{ip}, #{port1}, #{location}, #{accessProtocol}, #{length}, #{deviceStatus}, #{createBy}, #{createTime}, #{updateBy}, #{updateTime},#{station},#{dataType},#{deviceModeId})
</insert>
<insert id="insertBatch" keyProperty="deviceId" useGeneratedKeys="true">
insert into plc_device(device_code, device_name, tenant_id, scene_id, ip, port1, location, access_protocol, length, device_status, create_by, create_time, update_by, update_time)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.deviceCode}, #{entity.deviceName}, #{entity.tenantId}, #{entity.sceneId}, #{entity.ip}, #{entity.port1}, #{entity.location}, #{entity.accessProtocol}, #{entity.length}, #{entity.deviceStatus}, #{entity.createBy}, #{entity.createTime}, #{entity.updateBy}, #{entity.updateTime})
</foreach>
</insert>
<insert id="insertOrUpdateBatch" keyProperty="deviceId" useGeneratedKeys="true">
insert into plc_device(device_code, device_name, tenant_id, scene_id, ip, port1, location, access_protocol, length, device_status, create_by, create_time, update_by, update_time)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.deviceCode}, #{entity.deviceName}, #{entity.tenantId}, #{entity.sceneId}, #{entity.ip}, #{entity.port1}, #{entity.location}, #{entity.accessProtocol}, #{entity.length}, #{entity.deviceStatus}, #{entity.createBy}, #{entity.createTime}, #{entity.updateBy}, #{entity.updateTime})
</foreach>
on duplicate key update
device_code = values(device_code),
device_name = values(device_name),
tenant_id = values(tenant_id),
scene_id = values(scene_id),
ip = values(ip),
port1 = values(port1),
location = values(location),
access_protocol = values(access_protocol),
length = values(length),
device_status = values(device_status),
create_by = values(create_by),
create_time = values(create_time),
update_by = values(update_by),
update_time = values(update_time)
</insert>
<!--通过主键修改数据-->
<update id="update">
update plc_device
<set>
<if test="deviceCode != null and deviceCode != ''">
device_code = #{deviceCode},
</if>
<if test="deviceName != null and deviceName != ''">
device_name = #{deviceName},
</if>
<if test="tenantId != null">
tenant_id = #{tenantId},
</if>
<if test="sceneId != null">
scene_id = #{sceneId},
</if>
<if test="ip != null and ip != ''">
ip = #{ip},
</if>
<if test="port1 != null">
port1 = #{port1},
</if>
<if test="location != null and location != ''">
location = #{location},
</if>
<if test="accessProtocol != null">
access_protocol = #{accessProtocol},
</if>
<if test="length != null">
length = #{length},
</if>
<if test="deviceStatus != null and deviceStatus != ''">
device_status = #{deviceStatus},
</if>
<if test="createBy != null and createBy != ''">
create_by = #{createBy},
</if>
<if test="createTime != null">
create_time = #{createTime},
</if>
<if test="updateBy != null and updateBy != ''">
update_by = #{updateBy},
</if>
<if test="updateTime != null">
update_time = #{updateTime},
</if>
<if test="dataType != null">
data_type = #{dataType},
</if>
<if test="station != null">
station = #{station},
</if>
</set>
where device_id = #{deviceId}
</update>
<!--通过主键删除-->
<delete id="deleteById">
delete from plc_device where device_id = #{deviceId}
</delete>
</mapper>

@ -0,0 +1,206 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.business.mapper.PlcDeviceModeDao">
<resultMap type="com.ruoyi.business.domain.PlcDeviceMode" id="PlcDeviceModeMap">
<result property="deviceModeId" column="device_mode_id" jdbcType="INTEGER"/>
<result property="deviceModeName" column="device_mode_name" jdbcType="VARCHAR"/>
<result property="tenantId" column="tenant_id" jdbcType="INTEGER"/>
<result property="sceneId" column="scene_id" jdbcType="INTEGER"/>
<result property="deviceModeStatus" column="device_mode_status" jdbcType="VARCHAR"/>
<result property="createBy" column="create_by" jdbcType="VARCHAR"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
</resultMap>
<!--查询单个-->
<select id="queryById" resultMap="PlcDeviceModeMap">
select
device_mode_id, device_mode_name, tenant_id, scene_id, device_mode_status, create_by, create_time, update_by, update_time
from plc_device_mode
where device_mode_id = #{deviceModeId}
</select>
<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="PlcDeviceModeMap">
select
device_mode_id, device_mode_name, tenant_id, scene_id, device_mode_status, create_by, create_time, update_by, update_time
from plc_device_mode
<where>
<if test="deviceModeId != null">
and device_mode_id = #{deviceModeId}
</if>
<if test="deviceModeName != null and deviceModeName != ''">
and device_mode_name = #{deviceModeName}
</if>
<if test="tenantId != null">
and tenant_id = #{tenantId}
</if>
<if test="sceneId != null">
and scene_id = #{sceneId}
</if>
<if test="deviceModeStatus != null and deviceModeStatus != ''">
and device_mode_status = #{deviceModeStatus}
</if>
<if test="createBy != null and createBy != ''">
and create_by = #{createBy}
</if>
<if test="createTime != null">
and create_time = #{createTime}
</if>
<if test="updateBy != null and updateBy != ''">
and update_by = #{updateBy}
</if>
<if test="updateTime != null">
and update_time = #{updateTime}
</if>
</where>
limit #{pageable.offset}, #{pageable.pageSize}
</select>
<!--统计总行数-->
<select id="count" resultType="java.lang.Long">
select count(1)
from plc_device_mode
<where>
<if test="deviceModeId != null">
and device_mode_id = #{deviceModeId}
</if>
<if test="deviceModeName != null and deviceModeName != ''">
and device_mode_name = #{deviceModeName}
</if>
<if test="tenantId != null">
and tenant_id = #{tenantId}
</if>
<if test="sceneId != null">
and scene_id = #{sceneId}
</if>
<if test="deviceModeStatus != null and deviceModeStatus != ''">
and device_mode_status = #{deviceModeStatus}
</if>
<if test="createBy != null and createBy != ''">
and create_by = #{createBy}
</if>
<if test="createTime != null">
and create_time = #{createTime}
</if>
<if test="updateBy != null and updateBy != ''">
and update_by = #{updateBy}
</if>
<if test="updateTime != null">
and update_time = #{updateTime}
</if>
</where>
</select>
<select id="selectList" resultType="com.ruoyi.business.domain.PlcDeviceMode">
select a.*,ht.tenant_name,hs.scene_name
from plc_device_mode a left join hw_scene hs on a.scene_id = hs.scene_id
left join hw_tenant ht on a.tenant_id=ht.tenant_id
<where>
<if test="deviceModeId != null">
and a.device_mode_id = #{deviceModeId}
</if>
<if test="deviceModeName != null and deviceModeName != ''">
and a.device_mode_name like concat('%',#{deviceModeName},'%')
</if>
<if test="tenantId != null">
and a.tenant_id = #{tenantId}
</if>
<if test="sceneId != null">
and a.scene_id = #{sceneId}
</if>
<if test="deviceModeStatus != null and deviceModeStatus != ''">
and a.device_mode_status = #{deviceModeStatus}
</if>
<if test="createBy != null and createBy != ''">
and a.create_by = #{createBy}
</if>
<if test="createTime != null">
and a.create_time = #{createTime}
</if>
<if test="updateBy != null and updateBy != ''">
and a.update_by = #{updateBy}
</if>
<if test="updateTime != null">
and a.update_time = #{updateTime}
</if>
</where>
</select>
<!--新增所有列-->
<insert id="insert" keyProperty="deviceModeId" useGeneratedKeys="true">
insert into plc_device_mode(device_mode_name, tenant_id, scene_id, device_mode_status, create_by, create_time, update_by, update_time)
values (#{deviceModeName}, #{tenantId}, #{sceneId}, #{deviceModeStatus}, #{createBy}, #{createTime}, #{updateBy}, #{updateTime})
</insert>
<insert id="insertBatch" keyProperty="deviceModeId" useGeneratedKeys="true">
insert into plc_device_mode(device_mode_name, tenant_id, scene_id, device_mode_status, create_by, create_time, update_by, update_time)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.deviceModeName}, #{entity.tenantId}, #{entity.sceneId}, #{entity.deviceModeStatus}, #{entity.createBy}, #{entity.createTime}, #{entity.updateBy}, #{entity.updateTime})
</foreach>
</insert>
<insert id="insertOrUpdateBatch" keyProperty="deviceModeId" useGeneratedKeys="true">
insert into plc_device_mode(device_mode_name, tenant_id, scene_id, device_mode_status, create_by, create_time, update_by, update_time)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.deviceModeName}, #{entity.tenantId}, #{entity.sceneId}, #{entity.deviceModeStatus}, #{entity.createBy}, #{entity.createTime}, #{entity.updateBy}, #{entity.updateTime})
</foreach>
on duplicate key update
device_mode_name = values(device_mode_name),
tenant_id = values(tenant_id),
scene_id = values(scene_id),
device_mode_status = values(device_mode_status),
create_by = values(create_by),
create_time = values(create_time),
update_by = values(update_by),
update_time = values(update_time)
</insert>
<!--通过主键修改数据-->
<update id="update">
update plc_device_mode
<set>
<if test="deviceModeName != null and deviceModeName != ''">
device_mode_name = #{deviceModeName},
</if>
<if test="tenantId != null">
tenant_id = #{tenantId},
</if>
<if test="sceneId != null">
scene_id = #{sceneId},
</if>
<if test="deviceModeStatus != null and deviceModeStatus != ''">
device_mode_status = #{deviceModeStatus},
</if>
<if test="createBy != null and createBy != ''">
create_by = #{createBy},
</if>
<if test="createTime != null">
create_time = #{createTime},
</if>
<if test="updateBy != null and updateBy != ''">
update_by = #{updateBy},
</if>
<if test="updateTime != null">
update_time = #{updateTime},
</if>
</set>
where device_mode_id = #{deviceModeId}
</update>
<!--通过主键删除-->
<delete id="deleteById">
delete from plc_device_mode where device_mode_id = #{deviceModeId}
</delete>
<delete id="deleteHwDeviceModeByDeviceModeIds">
delete from plc_device_mode where device_mode_id in
<foreach item="deviceModeId" collection="array" open="(" separator="," close=")">
#{deviceModeId}
</foreach>
</delete>
</mapper>

@ -0,0 +1,182 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.business.mapper.PlcDeviceModeFunctionDao">
<resultMap type="com.ruoyi.business.domain.PlcDeviceModeFunction" id="PlcDeviceModeFunctionMap">
<result property="modeFunctionId" column="mode_function_id" jdbcType="INTEGER"/>
<result property="deviceModeId" column="device_mode_id" jdbcType="INTEGER"/>
<result property="functionName" column="function_name" jdbcType="VARCHAR"/>
<result property="functionIdentifier" column="function_identifier" jdbcType="VARCHAR"/>
<result property="dataType" column="data_type" jdbcType="INTEGER"/>
<result property="dataDefinition" column="data_definition" jdbcType="VARCHAR"/>
<result property="propertyUnit" column="property_unit" jdbcType="VARCHAR"/>
<result property="remark" column="remark" jdbcType="VARCHAR"/>
<result property="functionMode" column="function_mode" jdbcType="VARCHAR"/>
</resultMap>
<!--查询单个-->
<select id="queryById" resultMap="PlcDeviceModeFunctionMap">
select
mode_function_id, device_mode_id, function_name, function_identifier, data_type, data_definition, property_unit, remark,function_mode
from plc_device_mode_function
where mode_function_id = #{modeFunctionId}
</select>
<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="PlcDeviceModeFunctionMap">
select
mode_function_id, device_mode_id, function_name, function_identifier, data_type, data_definition, property_unit, remark
from plc_device_mode_function
<where>
<if test="modeFunctionId != null">
and mode_function_id = #{modeFunctionId}
</if>
<if test="deviceModeId != null">
and device_mode_id = #{deviceModeId}
</if>
<if test="functionName != null and functionName != ''">
and function_name = #{functionName}
</if>
<if test="functionIdentifier != null and functionIdentifier != ''">
and function_identifier = #{functionIdentifier}
</if>
<if test="dataType != null">
and data_type = #{dataType}
</if>
<if test="dataDefinition != null and dataDefinition != ''">
and data_definition = #{dataDefinition}
</if>
<if test="propertyUnit != null and propertyUnit != ''">
and property_unit = #{propertyUnit}
</if>
<if test="remark != null and remark != ''">
and remark = #{remark}
</if>
</where>
limit #{pageable.offset}, #{pageable.pageSize}
</select>
<!--统计总行数-->
<select id="count" resultType="java.lang.Long">
select count(1)
from plc_device_mode_function
<where>
<if test="modeFunctionId != null">
and mode_function_id = #{modeFunctionId}
</if>
<if test="deviceModeId != null">
and device_mode_id = #{deviceModeId}
</if>
<if test="functionName != null and functionName != ''">
and function_name = #{functionName}
</if>
<if test="functionIdentifier != null and functionIdentifier != ''">
and function_identifier = #{functionIdentifier}
</if>
<if test="dataType != null">
and data_type = #{dataType}
</if>
<if test="dataDefinition != null and dataDefinition != ''">
and data_definition = #{dataDefinition}
</if>
<if test="propertyUnit != null and propertyUnit != ''">
and property_unit = #{propertyUnit}
</if>
<if test="remark != null and remark != ''">
and remark = #{remark}
</if>
</where>
</select>
<select id="selectFunctions" resultType="com.ruoyi.business.domain.PlcDeviceModeFunction"
parameterType="java.lang.Long">
SELECT
x.*
FROM
`hwsaas-cloud`.plc_device_mode_function x
WHERE
x.device_mode_id = #{deviceModeId}
</select>
<select id="selectFunctionList" resultType="com.ruoyi.business.domain.PlcDeviceModeFunction"
parameterType="java.lang.Long">
select * from plc_device_mode_function where device_mode_id = #{deviceModeId}
</select>
<select id="selectHwDeviceModeFunctionList" resultType="com.ruoyi.business.domain.HwDeviceModeFunction"
parameterType="com.ruoyi.business.domain.HwDeviceModeFunction">
select * from plc_device_mode_function where device_mode_id = #{deviceModeId}
</select>
<!--新增所有列-->
<insert id="insert" keyProperty="modeFunctionId" useGeneratedKeys="true">
insert into plc_device_mode_function(device_mode_id, function_name, function_identifier, data_type, data_definition, property_unit, remark,function_mode)
values (#{deviceModeId}, #{functionName}, #{functionIdentifier}, #{dataType}, #{dataDefinition}, #{propertyUnit}, #{remark},#{functionMode})
</insert>
<insert id="insertBatch" keyProperty="modeFunctionId" useGeneratedKeys="true">
insert into plc_device_mode_function(device_mode_id, function_name, function_identifier, data_type, data_definition, property_unit, remark,function_mode)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.deviceModeId}, #{entity.functionName}, #{entity.functionIdentifier}, #{entity.dataType}, #{entity.dataDefinition}, #{entity.propertyUnit}, #{entity.remark},#{entity.functionMode})
</foreach>
</insert>
<insert id="insertOrUpdateBatch" keyProperty="modeFunctionId" useGeneratedKeys="true">
insert into plc_device_mode_function(device_mode_id, function_name, function_identifier, data_type, data_definition, property_unit, remark)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.deviceModeId}, #{entity.functionName}, #{entity.functionIdentifier}, #{entity.dataType}, #{entity.dataDefinition}, #{entity.propertyUnit}, #{entity.remark})
</foreach>
on duplicate key update
device_mode_id = values(device_mode_id),
function_name = values(function_name),
function_identifier = values(function_identifier),
data_type = values(data_type),
data_definition = values(data_definition),
property_unit = values(property_unit),
remark = values(remark)
</insert>
<!--通过主键修改数据-->
<update id="update">
update plc_device_mode_function
<set>
<if test="deviceModeId != null">
device_mode_id = #{deviceModeId},
</if>
<if test="functionName != null and functionName != ''">
function_name = #{functionName},
</if>
<if test="functionIdentifier != null and functionIdentifier != ''">
function_identifier = #{functionIdentifier},
</if>
<if test="dataType != null">
data_type = #{dataType},
</if>
<if test="dataDefinition != null and dataDefinition != ''">
data_definition = #{dataDefinition},
</if>
<if test="propertyUnit != null and propertyUnit != ''">
property_unit = #{propertyUnit},
</if>
<if test="remark != null and remark != ''">
remark = #{remark},
</if>
</set>
where mode_function_id = #{modeFunctionId}
</update>
<!--通过主键删除-->
<delete id="deleteById">
delete from plc_device_mode_function where mode_function_id = #{modeFunctionId}
</delete>
<delete id="deleteHwDeviceModeParameterByModeFunctionId" parameterType="java.lang.Long">
</delete>
<delete id="deleteHwDeviceModeFunctionByDeviceModeIds">
delete from plc_device_mode_function where device_mode_id in
<foreach item="deviceModeId" collection="array" open="(" separator="," close=")">
#{deviceModeId}
</foreach>
</delete>
</mapper>

@ -99,7 +99,8 @@ public class DataProcessServiceImpl extends CommanHandleService implements IData
@Override
public int processBusinessData(String jsonData, String imagePath,
String imagePatterns, String imageDomain, String imagePrefix, String topic) {
JSONObject json = JSON.parseObject(jsonData);
String data = jsonData.replaceAll(" ", "");
JSONObject json = JSON.parseObject(data);
Long ts = json.getLong(TdEngineConstants.PAYLOAD_TS);
String tsStr = String.valueOf(ts);
if (tsStr.length() == 10) {
@ -164,7 +165,7 @@ public class DataProcessServiceImpl extends CommanHandleService implements IData
}
if (value instanceof String) {
if (value instanceof String && key !="longitude" && key != "latitude") {
String valueStr = (String) value;
if (StringUtils.isNotBlank(valueStr)) {
/**
@ -198,22 +199,49 @@ public class DataProcessServiceImpl extends CommanHandleService implements IData
schemaFields.add(tdField);
}
} else {
TdField tdField = new TdField();
tdField.setFieldName(key);
tdField.setFieldValue(value);
schemaFields.add(tdField);
//经纬度判断
if (key.equalsIgnoreCase(HwDictConstants.DEFAULT_FUNCTION_LONGITUDE_IDENTIFIER)) {
longitude = value;
String value1 = value.toString();
String value2 = value1.substring(1,value1.length());
longitude = value2;
TdField tdField = new TdField();
tdField.setFieldName(key);
tdField.setFieldValue(value2);
schemaFields.add(tdField);
} else if (key.equalsIgnoreCase(HwDictConstants.DEFAULT_FUNCTION_LATITUDE_IDENTIFIER)) {
latitude = value;
} else {
String value1 = value.toString();
String value2 = value1.substring(1,value1.length());
latitude = value2;
TdField tdField = new TdField();
tdField.setFieldName(key);
tdField.setFieldValue(value2);
schemaFields.add(tdField);
}else {
TdField alarmTdField = new TdField();
alarmTdField.setFieldName(originalKey);
alarmTdField.setFieldValue(value);
alarmSchemaFields.add(alarmTdField);
TdField tdField = new TdField();
tdField.setFieldName(key);
tdField.setFieldValue(value);
schemaFields.add(tdField);
}
// //经纬度判断
// if (key.equalsIgnoreCase(HwDictConstants.DEFAULT_FUNCTION_LONGITUDE_IDENTIFIER)) {
// String value1 = value.toString();
// value2 = value1.substring(2);
// longitude = value2;
// } else if (key.equalsIgnoreCase(HwDictConstants.DEFAULT_FUNCTION_LATITUDE_IDENTIFIER)) {
// String value1 = value.toString();
// value2 = value1.substring(2);
// latitude = value2;
// } else {
// TdField alarmTdField = new TdField();
// alarmTdField.setFieldName(originalKey);
// alarmTdField.setFieldValue(value);
// alarmSchemaFields.add(alarmTdField);
// }
}
}

@ -31,6 +31,21 @@ public class RyTask {
public void computeOnlineDevicesCount(Integer days) {
System.out.println("开始了");
this.remoteBusinessService.computeOnlineDevicecCount(days, SecurityConstants.INNER);
}
public void mcDataProcess() {
remoteBusinessService.mcDataProcess(SecurityConstants.INNER);
}
public void modbusDataProcess() {
remoteBusinessService.modbusDataProcess(SecurityConstants.INNER);
}
public void aeDataProcess() {
remoteBusinessService.aeDataProcess(SecurityConstants.INNER);
}
public void ehternetDataProcess() {
remoteBusinessService.ehternetDataProcess(SecurityConstants.INNER);
}
}

@ -0,0 +1,129 @@
import request from '@/utils/request'
import {parseStrEmpty} from "@/utils/ruoyi";
// 查询设备信息列表
export function listDevice(query) {
return request({
url: '/business/plcDevice/list',
method: 'get',
params: query
})
}
// 查询设备信息详细
export function getDevice(deviceId) {
return request({
url: '/business/plcDevice/' + deviceId,
method: 'get'
})
}
// 新增设备信息
export function addDevice(data) {
return request({
url: '/business/plcDevice',
method: 'post',
data: data
})
}
// 修改设备信息
export function updateDevice(data) {
return request({
url: '/business/plcDevice',
method: 'put',
data: data
})
}
// 删除设备信息
export function delDevice(deviceId) {
return request({
url: '/business/plcDevice/' + deviceId,
method: 'delete'
})
}
// 查询场景信息列表供查询页面选择使用(例如下拉列表)
export function getScenes(query) {
return request({
url: '/business/device/getScenes',
method: 'get',
params: query
})
}
// 查询场景信息列表供编辑页面选择使用(例如下拉列表)
export function getEditedScenes(query) {
return request({
url: '/business/device/getEditedScenes',
method: 'get',
params: query
})
}
export function getProtocols() {
return request({
url: '/business/plcDevice/getProtocols',
method: 'get'
})
}
// 查询监控单元树
export function getMonitorTree(sceneId) {
return request({
url: '/business/device/monitorUnitTree/' + parseStrEmpty(sceneId),
method: 'get'
})
}
// 查询设备模型
export function getDeviceModes(sceneId) {
return request({
url: '/business/plcDevice/getDeviceModes/' + parseStrEmpty(sceneId),
method: 'get'
})
}
// 查询网关设备
export function getGatewayDevices(sceneId) {
return request({
url: '/business/device/getGatewayDevices/' + parseStrEmpty(sceneId),
method: 'get'
})
}
// 设备状态修改
export function changeDeviceStatus(deviceId, deviceStatus) {
const data = {
deviceId,
deviceStatus
}
return request({
url: '/business/plcDevice/changeDeviceStatus',
method: 'put',
data: data
})
}
export function publishControlCommand(deviceId, type) {
const data = {
deviceId,
type
}
return request({
url: '/business/device/publishControlCommand',
method: 'put',
data: data
})
}
// 重新生成tdengine所有表
export function rebuildTdTables() {
return request({
url: '/business/device/rebuildTdTables',
method: 'get'
})
}

@ -0,0 +1,89 @@
import request from '@/utils/request'
// 查询设备模型列表
export function listDeviceMode(query) {
return request({
url: '/business/plcDeviceMode/list',
method: 'get',
params: query
})
}
export function addDeviceModeFunction(data) {
return request({
url: '/business/plcDeviceModeFunction',
method: 'post',
data: data
})
}
export function updateDeviceModeFunction(data) {
return request({
url: '/business/plcDeviceModeFunction',
method: 'put',
data: data
})
}
export function delDeviceModeFunction(modeFunctionId) {
return request({
url: '/business/plcDeviceModeFunction/' + modeFunctionId,
method: 'delete'
})
}
// 查询设备模型详细
export function getDeviceMode(deviceModeId) {
return request({
url: '/business/plcDeviceMode/' + deviceModeId,
method: 'get'
})
}
// 新增设备模型
export function addDeviceMode(data) {
return request({
url: '/business/plcDeviceMode',
method: 'post',
data: data
})
}
// 修改设备模型
export function updateDeviceMode(data) {
return request({
url: '/business/plcDeviceMode',
method: 'put',
data: data
})
}
// 删除设备模型
export function delDeviceMode(deviceModeId) {
return request({
url: '/business/plcDeviceMode/' + deviceModeId,
method: 'delete'
})
}
// 查询场景信息列表供插叙页面选择使用(例如下拉列表)
export function getScenes(query) {
return request({
url: '/business/deviceMode/getScenes',
method: 'get',
params: query
})
}
// 查询场景信息列表供编辑页面选择使用(例如下拉列表)
export function getEditedScenes(query) {
return request({
url: '/business/deviceMode/getEditedScenes',
method: 'get',
params: query
})
}
// 重新生成tdengine所有超级表
export function rebuildTdSuperTables() {
return request({
url: '/business/deviceMode/rebuildTdSuperTables',
method: 'get'
})
}

@ -231,6 +231,20 @@ export const dynamicRoutes = [
}
]
},
{
path: '/plcDeviceMode/mode-add',
component: Layout,
hidden: true,
permissions: ['business:deviceMode:add'],
children: [
{
path: 'index',
component: () => import('@/views/plc/plcModel/editDeviceMode'),
name: 'ModeAdd',
meta: { title: '添加设备模型', activeMenu: '/plc/plcModel' }
}
]
},
{
path: '/deviceMode/mode-edit',
component: Layout,
@ -245,6 +259,20 @@ export const dynamicRoutes = [
}
]
},
{
path: '/plcDeviceMode/mode-edit',
component: Layout,
hidden: true,
permissions: ['business:deviceMode:edit'],
children: [
{
path: 'index/:deviceModeId(\\d+)',
component: () => import('@/views/plc/plcModel/editDeviceMode'),
name: 'ModeEdit',
meta: { title: '修改设备模型', activeMenu: '/plc/plcModel' }
}
]
},
{
path: '/electronicFence/fence-add',
component: Layout,

File diff suppressed because it is too large Load Diff

@ -0,0 +1,885 @@
<template>
<div class="app-container">
<el-form ref="basicInfoForm" :model="info" :rules="rules" label-width="150px">
<el-form-item label="通用标识" prop="commonFlag" v-if="false">
<el-input placeholder="请选择通用标识" v-model="info.commonFlag"/>
</el-form-item>
<el-row>
<el-col :span="12">
<el-form-item label="模型名称" prop="deviceModeName">
<el-input placeholder="请输入模型名称" v-model="info.deviceModeName"/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="所属场景" prop="sceneId">
<el-select v-model="info.sceneId" placeholder="请选择" :disabled="disabled">
<el-option
v-for="(scene, index) in scenes"
:key="index"
:label="scene.sceneName"
:value="scene.sceneId"
:disabled="scene.selectedDisable && scene.selectedDisable == 1"
></el-option>
</el-select>
</el-form-item>
</el-col>
<!-- <el-col :span="12">-->
<!-- <el-form-item label="定位标识" prop="gpsFlag">-->
<!-- <el-radio-group v-model="info.gpsFlag" @input="gpsFlagRadioChange" :disabled="disabled">-->
<!-- <el-radio-->
<!-- v-for="dict in dict.type.hw_device_mode_gps_flag"-->
<!-- :key="dict.value"-->
<!-- :label="dict.value"-->
<!-- v-model="gps_flag"-->
<!-- >{{ dict.label }}-->
<!-- </el-radio>-->
<!-- </el-radio-group>-->
<!-- </el-form-item>-->
<!-- </el-col>-->
<!-- <el-col :span="12">-->
<!-- <el-form-item label="模型分类" prop="modeClassfication">-->
<!-- <el-select v-model="info.modeClassfication" placeholder="请选择数据类型">-->
<!-- <el-option-->
<!-- v-for="dict in dict.type.hw_mode_function_mode_classfication"-->
<!-- :key="dict.value"-->
<!-- :label="dict.label"-->
<!-- :value="parseInt(dict.value)"-->
<!-- ></el-option>-->
<!-- </el-select>-->
<!-- </el-form-item>-->
<!-- </el-col>-->
<el-col :span="24">
<el-form-item label="语言" prop="language_code" v-if="false">
<el-select v-model="info.languageCode" placeholder="请选择">
<el-option
v-for="(language, index) in languages"
:key="index"
:label="language.languageName"
:value="language.languageCode"
></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="设备模型图片" prop="deviceModePic">
<el-upload
single
:action="uploadImgUrl"
list-type="picture-card"
:limit="limit"
:on-success="handleUploadSuccess"
:before-upload="handleBeforeUpload"
:on-error="handleUploadError"
:on-exceed="handleExceed"
ref="imageUpload"
:on-remove="handleDeletePicture"
:show-file-list="true"
:headers="headers"
:file-list="fileList"
:on-preview="handlePictureCardPreview"
:class="{hide: this.fileList.length >= 1}"
>
<i class="el-icon-plus"></i>
</el-upload>
<!-- 上传提示 -->
<div class="el-upload__tip" slot="tip" v-if="showTip">
请上传
<template v-if="fileSize"> <b style="color: #f56c6c">{{ fileSize }}MB</b></template>
<template v-if="fileType"> <b style="color: #f56c6c">{{ fileType.join("/") }}</b></template>
的文件
</div>
<el-dialog
:visible.sync="dialogVisible"
title="预览"
width="800"
append-to-body
>
<img
:src="dialogImageUrl"
style="display: block; max-width: 100%; margin: 0 auto"
/>
</el-dialog>
</el-form-item>
</el-col>
</el-row>
</el-form>
<el-card>
<el-tabs v-model="activeName">
<el-tab-pane label="属性" name="attributesInfo">
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleAdd"
>新增
</el-button>
</el-col>
</el-row>
<el-table ref="attributesTable" :data="attributesData" row-key="columnId">
<el-table-column label="序号" type="index" min-width="5%" class-name="allowDrag"/>
<!-- <el-table-column-->
<!-- label="功能模式"-->
<!-- prop="functionMode"-->
<!-- v-if="false"-->
<!-- />-->
<!-- <el-table-column-->
<!-- label="定位坐标标识"-->
<!-- prop="coordinate"-->
<!-- v-if="false"-->
<!-- />-->
<el-table-column
label="描述"
prop="remark"
v-if="false"
/>
<!-- <el-table-column-->
<!-- label="功能类型"-->
<!-- prop="functionType"-->
<!-- min-width="10%">-->
<!-- <template slot-scope="scope">-->
<!-- <dict-tag :options="dict.type.hw_mode_function_function_type" :value="scope.row.functionType"/>-->
<!-- </template>-->
<!-- </el-table-column>-->
<el-table-column
label="功能名称"
prop="functionName"
min-width="10%"
:show-overflow-tooltip="true"
/>
<el-table-column
label="标识符"
prop="functionIdentifier"
min-width="10%"
:show-overflow-tooltip="true"
/>
<el-table-column prop="dataType" label="数据类型" min-width="10%">
<template slot-scope="scope">
<dict-tag :options="dict.type.hw_mode_function_data_type" :value="scope.row.dataType"/>
</template>
</el-table-column>
<el-table-column
label="数据定义"
prop="dataDefinition"
min-width="10%"
:show-overflow-tooltip="true"
v-if="false"
/>
<el-table-column
label="单位"
prop="propertyUnit"
min-width="10%"
:show-overflow-tooltip="true"
/>
<!-- <el-table-column-->
<!-- label="读写权限"-->
<!-- prop="rwFlag"-->
<!-- min-width="10%"-->
<!-- :show-overflow-tooltip="true"-->
<!-- >-->
<!-- <template slot-scope="scope">-->
<!-- <dict-tag :options="dict.type.hw_mode_function_rw_flag" :value="scope.row.rwFlag"/>-->
<!-- </template>-->
<!-- </el-table-column>-->
<!-- <el-table-column-->
<!-- label="显示"-->
<!-- prop="displayFlag"-->
<!-- min-width="10%"-->
<!-- :show-overflow-tooltip="true"-->
<!-- >-->
<!-- <template slot-scope="scope">-->
<!-- <dict-tag :options="dict.type.hw_mode_function_display_flag" :value="scope.row.displayFlag"/>-->
<!-- </template>-->
<!-- </el-table-column>-->
<el-table-column label="操作" align="center" min-width="10%">
<template slot-scope="scope" v-if="scope.row.roleId !== 1">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
v-if="scope.row.coordinate==null"
@click="handleUpdateAttribute(scope.row)"
>修改
</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
v-if="scope.row.coordinate==null"
@click="handleDeleteAttribute(scope.row)"
>删除
</el-button>
</template>
</el-table-column>
</el-table>
<!-- 添加或修改设备模型功能对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="modeFunctionForm" :model="form" :rules="modeFunctionRules" label-width="80px">
<!-- <el-form-item label="功能模式" prop="functionMode" v-show="false">-->
<!-- <el-input v-model="form.functionMode" placeholder="请输入功能模式"/>-->
<!-- </el-form-item>-->
<!-- <el-form-item label="功能类型" prop="functionType">-->
<!-- <el-select v-model="form.functionType" placeholder="请选择功能类型">-->
<!-- <el-option-->
<!-- v-for="dict in dict.type.hw_mode_function_function_type"-->
<!-- :key="dict.value"-->
<!-- :label="dict.label"-->
<!-- :value="dict.value"-->
<!-- ></el-option>-->
<!-- </el-select>-->
<!-- </el-form-item>-->
<el-form-item label="功能名称" prop="functionName">
<el-input v-model="form.functionName" placeholder="请输入功能名称" maxlength="30"/>
</el-form-item>
<el-form-item label="标识符" prop="functionIdentifier">
<el-input v-model="form.functionIdentifier" placeholder="请输入标识符" maxlength="30"
:disabled="editDisable"/>
</el-form-item>
<el-form-item label="数据类型" prop="dataType">
<el-select v-model="form.dataType" placeholder="请选择数据类型" :disabled="editDisable">
<el-option
v-for="dict in dict.type.hw_mode_function_data_type"
:key="dict.value"
:label="dict.label"
:value="dict.value"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="取值范围" prop="dataDefinition" v-show="false">
<el-input v-model="form.minValue" placeholder="请输入最小值" style="width:150px;"/>
<el-input v-model="form.maxValue" placeholder="请输入最大值" style="width:150px;"/>
</el-form-item>
<el-form-item label="布尔值" prop="dataDefinition" v-show="form.dataType == '8'">
0
<el-input v-model="form.boolFalse" placeholder="请输入值" style="width:150px;"/>
</el-form-item>
<el-form-item label="" prop="dataDefinition" v-show="form.dataType == '8'">
1
<el-input v-model="form.boolTrue" placeholder="请输入值" style="width:150px;"/>
</el-form-item>
<el-form-item label="长度" prop="dataDefinition" v-show="form.dataType == '10'">
<el-input-number v-model="form.dataDefinition" placeholder="请输入最大长度" :min="10" :max="1000"
style="width:150px;"/>
</el-form-item>
<el-form-item label="单位" prop="propertyUnit">
<el-input v-model="form.propertyUnit" placeholder="请输入单位"/>
</el-form-item>
<!-- <el-form-item label="显示标识" prop="displayFlag">-->
<!-- <el-radio-group v-model="form.displayFlag">-->
<!-- <el-radio-->
<!-- v-for="dict in dict.type.hw_mode_function_display_flag"-->
<!-- :key="dict.value"-->
<!-- :label="dict.value"-->
<!-- >{{ dict.label }}-->
<!-- </el-radio>-->
<!-- </el-radio-group>-->
<!-- </el-form-item>-->
<!-- <el-form-item label="读写标识" prop="rwFlag">-->
<!-- <el-radio-group v-model="form.rwFlag">-->
<!-- <el-radio-->
<!-- v-for="dict in dict.type.hw_mode_function_rw_flag"-->
<!-- :key="dict.value"-->
<!-- :label="dict.value"-->
<!-- >{{ dict.label }}-->
<!-- </el-radio>-->
<!-- </el-radio-group>-->
<!-- </el-form-item>-->
<el-form-item label="描述" prop="remark">
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容"/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitDeviceModeFunctionForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</el-tab-pane>
<!-- <el-tab-pane label="服务" name="servicesInfo">-->
<!-- <device-mode-service ref="servicesTable" :servicesData="servicesData" :deviceModeId="deviceModeId"/>-->
<!-- </el-tab-pane>-->
<!-- <el-tab-pane label="事件" name="eventsInfo">-->
<!-- <device-mode-event ref="eventInfo" :eventsData="eventsData" :deviceModeId="deviceModeId"/>-->
<!-- </el-tab-pane>-->
</el-tabs>
<el-form label-width="100px">
<el-form-item style="text-align: center;margin-left:-100px;margin-top:10px;">
<el-button type="primary" @click="submitForm()"></el-button>
<el-button @click="close()"></el-button>
</el-form-item>
</el-form>
</el-card>
</div>
</template>
<script>
import {addDeviceMode, getDeviceMode, updateDeviceMode, getEditedScenes,addDeviceModeFunction,delDeviceModeFunction,
updateDeviceModeFunction} from "@/api/plc/plcDeviceMode";
import {getToken} from "@/utils/auth";
export default {
dicts: ['hw_device_mode_gps_flag', 'hw_mode_function_mode_classfication', 'hw_mode_function_function_type', 'hw_mode_function_function_type', 'hw_mode_function_data_type', 'hw_mode_function_display_flag', 'hw_mode_function_rw_flag'],
components: {
},
props: {
value: [String, Object, Array],
//
limit: {
type: Number,
default: 1,
},
// (MB)
fileSize: {
type: Number,
default: 5,
},
// , ['png', 'jpg', 'jpeg']
fileType: {
type: Array,
default: () => ["png", "jpg", "jpeg"],
},
//
isShowTip: {
type: Boolean,
default: true
}
},
data() {
return {
info: {},
//
title: "",
//
form: {},
editedForm: {},
gps_flag: '',
//
open: false,
disabled: true,
rules: {
deviceModeName: [{
required: true,
message: '请输入模型名称',
trigger: 'blur'
}],
sceneId: [
{required: true, message: "请选择场景", trigger: "change"}
],
gpsFlag: [
{required: true, message: "请选择定位标识", trigger: "change"}
],
},
modeFunctionRules: {
functionType: [
{required: true, message: "请选择功能类型", trigger: "blur"},
],
functionName: [
{required: true, message: "请输入功能名称", trigger: "blur"}
],
functionIdentifier: [
{required: true, message: "请输入标识符", trigger: "blur"},
{
pattern: /^[a-z][a-z0-9_]+$/,
message: "2-30个字符由小写字母、数字或下划线组成开头必须为小写字母",
trigger: "blur"
}
],
dataType: [
{required: true, message: "请选择数据类型", trigger: "change"}
],
displayFlag: [
{required: true, message: "请选择显示标识", trigger: "change"}
],
rwFlag: [
{required: true, message: "请选择读写标识", trigger: "change"}
],
},
// name
activeName: "attributesInfo",
//
scenes: [],
//
languages: [],
//
IDENTIFIER_LONGITUDE: 'longitude',
//
IDENTIFIER_LATITUDE: 'latitude',
editDisable: true,
//ID
deviceModeId: '',
//
attributesData: [],
attributeDataIndex: -1,//index
//
servicesData: [],
//
eventsData: [],
//
tableHeight: document.documentElement.scrollHeight - 245 + "px",
number: 0,
uploadList: [],
dialogImageUrl: "",
dialogVisible: false,
hideUpload: false,
uploadImgUrl: process.env.VUE_APP_BASE_API + "/file/upload", //
headers: {
Authorization: "Bearer " + getToken(),
},
fileList: [],
}
},
created() {
this.getConfigKey("hw.gps.longitude").then(response => {//
this.IDENTIFIER_LONGITUDE = response.msg;
});
this.getConfigKey("hw.gps.latitude").then(response => {//
this.IDENTIFIER_LATITUDE = response.msg;
});
// getLanguages().then(response => {
// this.languages = response.data;
// });
getEditedScenes().then(response => {
this.scenes = response.data;
});
this.eventsData = [];
this.servicesData = [];
this.attributesData = [];
const deviceModeId = this.$route.params && this.$route.params.deviceModeId;
if (deviceModeId) {
//
getDeviceMode(deviceModeId).then(res => {
console.log(deviceModeId)
this.info = res.data.deviceMode;
console.log(this.info)
this.attributesData = res.data.deviceModeFunctionMap;
const servicesData = (res.data.deviceModeFunctionMap)['2'];
const eventsData = (res.data.deviceModeFunctionMap)['3'];
if(servicesData != null && servicesData!==''){
this.servicesData =servicesData;
}
if(servicesData != null && eventsData!==''){
this.eventsData =eventsData;
}
this.deviceModeId = deviceModeId;
if (res.data.deviceMode.deviceModePic != null) {
let previewFile = {};
previewFile.url = res.data.deviceMode.deviceModePic
this.fileList.push(previewFile);
}
// this.columns = res.data.rows;
});
/** 查询字典下拉列表 */
// getDictOptionselect().then(response => {
// this.dictOptions = response.data;
// });
} else {
//
this.info = {
gpsFlag: "0",
commonFlag: "0"
};
this.gps_flag = "0"
this.disabled = false;
}
},
computed: {},
watch: {},
mounted() {
},
methods: {
//
gpsFlagRadioChange(value) {
if (parseInt(value) === 1) {//
let attributesData = this.attributesData;
if (attributesData.length > 0) {
this.$modal.confirm('修改定位标识会删除所有属性,确定修改定位标识么?').then(function () {
attributesData.splice(0, attributesData.length);
}).then(() => {
this.addGpsAttribute();
});
} else {
this.addGpsAttribute();
}
} else {
let attributesData = this.attributesData;
if (attributesData.length > 0) {
this.$modal.confirm('修改定位标识会删除所有属性,确定修改定位标识么?').then(function () {
attributesData.splice(0, attributesData.length);
});
}
}
},
addGpsAttribute() {
this.reset();
this.form.coordinate = "1"
this.form.functionIdentifier = this.IDENTIFIER_LONGITUDE;
this.form.functionName = "经度";
this.form.dataType = 5;
this.attributesData.push(this.form);
this.reset();
this.form.coordinate = "2"
this.form.functionIdentifier = this.IDENTIFIER_LATITUDE;
this.form.functionName = "纬度";
this.form.dataType = 5;
this.attributesData.push(this.form);
},
/** 新增属性按钮操作 */
handleAdd() {
this.reset();
this.editDisable = false;
this.open = true;
this.title = "添加设备模型属性";
},
//
reset() {
this.form = {
functionMode: '1',
modeFunctionId: null,
deviceModeId: null,
coordinate: null,
functionName: null,
functionIdentifier: null,
functionType: "1",//
dataType: "2",//int
dataDefinition: null,
functionFormula: null,
propertyUnit: null,
displayFlag: "1",//
rwFlag: "2",//
boolFalse: '',
boolTrue: '',
minValue: '',
maxValue: '',
invokeMethod: null,
eventType: null,
remark: null,
};
//this.resetForm("modeFunctionForm");
},
handleUpdateAttribute(row) {
// this.reset();
this.editDisable = true;
this.attributeDataIndex = this.attributesData.indexOf(row);
this.convertParameterDefinition(row);
this.form = JSON.parse(JSON.stringify(row));//
this.open = true;
this.title = "修改设备模型属性";
},
convertParameterDefinition(row) {
let dataType = row.dataType;
if (parseInt(dataType) === 8) {
let dataDefinitionJson = JSON.parse(row.dataDefinition)
row.boolFalse = dataDefinitionJson["0"];
row.boolTrue = dataDefinitionJson["1"];
}
row.dataType = dataType.toString();
},
handleDeleteAttribute(row) {
console.log(row.modeFunctionId)
if (row.modeFunctionId !== null) {
if (this.attributesData.length <= 1) {
this.$modal.msgWarning("最少一个属性");
return;
}
this.$modal.confirm('删除属性之前上报此属性的数据会清除,确认要删除么?').then(() => {
delDeviceModeFunction(row.modeFunctionId).then(res => {
this.$modal.msgSuccess(res.msg);
if (res.code === 200) {
this.attributesData.splice(this.attributesData.indexOf(row), 1);
}
});
})
} else {
console.log(row.modeFunctionId)
this.attributesData.splice(this.attributesData.indexOf(row), 1);
}
},
/** 关闭按钮 */
close() {
// alert(this.$route.query.pageNum);
const obj = {path: "/plc/model", query: {t: Date.now(), pageNum: this.$route.query.pageNum}};
this.$tab.closeOpenPage(obj);
},
submitDeviceModeFunctionForm() {
this.$refs['modeFunctionForm'].validate(valid => {
if (valid) {
/** 设备模型添加后在list中添加 */
//alert(this.minValue+"--"+this.maxValue)
if (this.form.dataType === "8") {
let boolFalse = this.form.boolFalse;
let boolTrue = this.form.boolTrue;
if (boolFalse === '' || boolTrue === '') {
this.$modal.msgError("请输入布尔值");
return;
} else {
this.form.dataDefinition = '{"0":"' + boolFalse + '","1":"' + boolTrue + '"}';
}
}
if (this.deviceModeId && this.deviceModeId !== '') {
let modeFunctionId = this.form.modeFunctionId;
this.form.deviceModeId = this.deviceModeId;
if (modeFunctionId !== undefined && modeFunctionId != null) {
let attributeDataIndex = this.attributeDataIndex;
let oldForm = this.attributesData[attributeDataIndex];
if (oldForm.functionIdentifier != this.form.functionIdentifier
|| oldForm.dataType != this.form.dataType) {
this.$modal.confirm('修改标识符或数据类型,之前上报数据会清除,确认要修改么?').then(() => {
return this.doUpdateDeviceModeFunction();
}
)
} else {
// console.log(res)
this.doUpdateDeviceModeFunction();
}
} else {
console.log(1)
addDeviceModeFunction(this.form).then(res => {
console.log(res)
this.$modal.msgSuccess(res.msg);
if (res.code === 200) {
this.open = false;
this.form.modeFunctionId = res.data;
this.pushData();
}
});
}
} else {
this.open = false;
this.pushData();
}
}
})
},
doUpdateDeviceModeFunction() {
updateDeviceModeFunction(this.form).then(res => {
this.$modal.msgSuccess(res.msg);
if (res.code === 200) {
this.open = false;
this.pushData();
}
});
},
pushData() {
let attributeDataIndex = this.attributeDataIndex;
if (attributeDataIndex > -1) {
this.attributeDataIndex = -1;
this.attributesData.splice(attributeDataIndex, 1, this.form);
} else {
this.attributesData.push(this.form)
}
},
//
cancel() {
this.open = false;
this.reset();
},
submitForm() {
this.$refs['basicInfoForm'].validate(valid => {
if (valid) {
if (this.info.deviceModeId != undefined) {
updateDeviceMode(this.info).then(res => {
this.$modal.msgSuccess(res.msg);
if (res.code === 200) {
this.close();
}
});
} else {
if (this.attributesData.length <= 0) {
this.$modal.msgError("请添加属性");
return;
}
let functionData = this.servicesData.concat(this.attributesData);
functionData = functionData.concat(this.eventsData)
console.log(functionData)
this.info.functionList = functionData;
addDeviceMode(this.info).then(res => {
this.$modal.msgSuccess(res.msg);
if (res.code === 200) {
this.close();
}
});
}
}
})
},
/**上传图片处理*/
// loading
handleBeforeUpload(file) {
let isImg = false;
if (this.fileType.length) {
let fileExtension = "";
if (file.name.lastIndexOf(".") > -1) {
fileExtension = file.name.slice(file.name.lastIndexOf(".") + 1);
}
isImg = this.fileType.some(type => {
if (file.type.indexOf(type) > -1) return true;
if (fileExtension && fileExtension.indexOf(type) > -1) return true;
return false;
});
} else {
isImg = file.type.indexOf("image") > -1;
}
if (!isImg) {
this.$modal.msgError(`文件格式不正确, 请上传${this.fileType.join("/")}图片格式文件!`);
return false;
}
if (this.fileSize) {
const isLt = file.size / 1024 / 1024 < this.fileSize;
if (!isLt) {
this.$modal.msgError(`上传头像图片大小不能超过 ${this.fileSize} MB!`);
return false;
}
}
this.$modal.loading("正在上传图片,请稍候...");
this.number++;
},
checkPicture(file) {
},
//
handleExceed() {
this.$modal.msgError(`上传文件数量不能超过 ${this.limit} !`);
},
//
handleUploadSuccess(res, file) {
if (res.code === 200) {
this.uploadList.push(res.data.url);
this.uploadedSuccessfully();
} else {
this.number--;
this.$modal.closeLoading();
this.$modal.msgError(res.msg);
this.$refs.imageUpload.handleRemove(file);
this.uploadedSuccessfully();
}
},
//
uploadedSuccessfully() {
if (this.number > 0 && this.uploadList.length === this.number) {
this.fileList = this.fileList.concat(this.uploadList);
this.uploadList = [];
this.number = 0;
this.info.deviceModePic = this.fileList[0];
// this.$emit("input", this.listToString(this.fileList));
this.$modal.closeLoading();
}
},
//
handleDeletePicture(file) {
const findex = this.fileList.map(f => f.name).indexOf(file.name);
if (findex > -1) {
this.fileList.splice(findex, 1);
// this.$emit("input", this.listToString(this.fileList));
}
this.info.deviceModePic = '';
},
//
handleUploadError() {
this.$modal.msgError("上传图片失败,请重试");
this.$modal.closeLoading();
},
//
handlePictureCardPreview(file) {
this.dialogImageUrl = file.url;
this.dialogVisible = true;
},
//
listToString(list, separator) {
let strs = "";
separator = separator || ",";
for (let i in list) {
if (list[i].url) {
strs += list[i].url.replace(this.baseUrl, "") + separator;
}
}
return strs != '' ? strs.substr(0, strs.length - 1) : '';
},
},
}
</script>

@ -0,0 +1,417 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="模型名称" prop="deviceModeName">
<el-input
v-model="queryParams.deviceModeName"
placeholder="请输入模型名称"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="所属场景" prop="sceneId">
<el-select v-model="queryParams.sceneId" placeholder="请选择所属场景">
<el-option
v-for="(scene, index) in scenes"
:key="index"
:label="scene.sceneName"
:value="scene.sceneId"
></el-option>
</el-select>
</el-form-item>
<!-- <el-form-item label="定位标识" prop="gpsFlag">-->
<!-- <el-select v-model="queryParams.gpsFlag" placeholder="请选择定位标识" clearable>-->
<!-- <el-option-->
<!-- v-for="dict in dict.type.hw_device_mode_gps_flag"-->
<!-- :key="dict.value"-->
<!-- :label="dict.label"-->
<!-- :value="dict.value"-->
<!-- ></el-option>-->
<!-- </el-select>-->
<!-- </el-form-item>-->
<!-- <el-form-item label="模型分类" prop="modeClassfication">-->
<!-- <el-select v-model="queryParams.modeClassfication" placeholder="请选择模型分类" clearable>-->
<!-- <el-option-->
<!-- v-for="dict in dict.type.hw_mode_function_mode_classfication"-->
<!-- :key="dict.value"-->
<!-- :label="dict.label"-->
<!-- :value="dict.value"-->
<!-- ></el-option>-->
<!-- </el-select>-->
<!-- </el-form-item>-->
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"></el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery"></el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['business:deviceMode:add']"
>新增
</el-button>
</el-col>
<!-- <el-col :span="1.5">-->
<!-- <el-button-->
<!-- type="success"-->
<!-- plain-->
<!-- icon="el-icon-edit"-->
<!-- size="mini"-->
<!-- :disabled="single"-->
<!-- @click="handleUpdate"-->
<!-- v-hasPermi="['business:deviceMode:edit']"-->
<!-- >修改-->
<!-- </el-button>-->
<!-- </el-col>-->
<!-- <el-col :span="1.5">-->
<!-- <el-button-->
<!-- type="warning"-->
<!-- plain-->
<!-- icon="el-icon-download"-->
<!-- size="mini"-->
<!-- @click="handleExport"-->
<!-- v-hasPermi="['business:deviceMode:export']"-->
<!-- >导出-->
<!-- </el-button>-->
<!-- </el-col>-->
<!-- <el-col :span="1.5">-->
<!-- <el-button-->
<!-- type="primary"-->
<!-- plain-->
<!-- icon="el-icon-plus"-->
<!-- size="mini"-->
<!-- @click="handleRebuildTdSuperTables"-->
<!-- v-hasPermi="['business:deviceMode:rebuild']"-->
<!-- >重建超级表-->
<!-- </el-button>-->
<!-- </el-col>-->
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="deviceModeList" @selection-change="handleSelectionChange">
<el-table-column label="模型ID" align="center" prop="deviceModeId"/>
<el-table-column label="模型名称" align="center" prop="deviceModeName"/>
<el-table-column label="所属租户" align="center" prop="tenantName"/>
<el-table-column label="所属场景" align="center" prop="sceneName"/>
<!-- <el-table-column label="定位标识" align="center" prop="gpsFlag">-->
<!-- <template slot-scope="scope">-->
<!-- <dict-tag :options="dict.type.hw_device_mode_gps_flag" :value="scope.row.gpsFlag"/>-->
<!-- </template>-->
<!-- </el-table-column>-->
<!-- <el-table-column label="模型分类" align="center" prop="modeClassfication">-->
<!-- <template slot-scope="scope">-->
<!-- <dict-tag :options="dict.type.hw_mode_function_mode_classfication" :value="scope.row.modeClassfication"/>-->
<!-- </template>-->
<!-- </el-table-column>-->
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['business:deviceMode:edit']"
>修改
</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['business:deviceMode:remove']"
>删除
</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
</div>
</template>
<script>
import {listDeviceMode, getDeviceMode, delDeviceMode, addDeviceMode, updateDeviceMode,getScenes,rebuildTdSuperTables} from "@/api/plc/plcDeviceMode";
import {getLanguages} from "@/api/basic/language";
export default {
dicts: ['hw_device_mode_gps_flag', 'hw_mode_function_mode_classfication'],
name: "DeviceMode",
data() {
return {
//
loading: true,
//
ids: [],
//
checkedHwDeviceModeFunction: [],
//
single: true,
//
multiple: true,
//
showSearch: true,
//
total: 0,
//
deviceModeList: [],
//
hwDeviceModeFunctionList: [],
//
title: "",
//
open: false,
//
scenes: [],
//
languages: [],
//
queryParams: {
pageNum: 1,
pageSize: 10,
deviceModeName: null,
tenantId: null,
sceneId: null,
languageCode: null,
gpsFlag: null,
deviceModeStatus: null,
commonFlag: null,
modeClassfication: null,
deviceModePic: null,
dataVerifyLevel: null,
deviceModeField: null
},
//
form: {},
//
rules: {
deviceModeName: [
{required: true, message: "设备模型名称不能为空", trigger: "blur"}
],
gpsFlag: [
{required: true, message: "定位标识不能为空", trigger: "blur"}
],
deviceModeStatus: [
{required: true, message: "设备模型状态不能为空", trigger: "change"}
],
commonFlag: [
{required: true, message: "是否通用物模型不能为空", trigger: "blur"}
],
}
};
},
created() {
this.getList();
getLanguages().then(response => {
this.languages = response.data;
});
getScenes().then(response => {
this.scenes = response.data;
});
},
computed: {
formatRow() {
return (row) => {
let languages = this.languages;
for (let i = 0; i < languages.length; i++) {
if (languages[i].languageCode === row.languageCode) {
return languages[i].languageName;
}
}
};
},
},
activated() {
const time = this.$route.query.t;
if (time != null && time != this.uniqueId) {
this.uniqueId = time;
this.queryParams.pageNum = Number(this.$route.query.pageNum);
this.getList();
}
},
methods: {
/** 查询设备模型列表 */
getList() {
this.loading = true;
listDeviceMode(this.queryParams).then(response => {
this.deviceModeList = response.rows;
this.total = response.total;
this.loading = false;
});
},
//
cancel() {
this.open = false;
this.reset();
},
//
reset() {
this.form = {
deviceModeId: null,
deviceModeName: null,
tenantId: null,
sceneId: null,
languageCode: null,
gpsFlag: null,
deviceModeStatus: null,
commonFlag: null,
modeClassfication: null,
deviceModePic: null,
dataVerifyLevel: null,
remark: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
deviceModeField: null
};
this.hwDeviceModeFunctionList = [];
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.deviceModeId)
this.single = selection.length !== 1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
const params = {pageNum: this.queryParams.pageNum};
this.$tab.openPage("添加设备模型", '/plcDeviceMode/mode-add/index', params);
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const deviceModeId = row.deviceModeId || this.ids
const deviceModeName = row.deviceModeName || this.tableNames[0];
const params = {pageNum: this.queryParams.pageNum};
this.$tab.openPage("修改设备模型[" + deviceModeName + "]", '/plcDeviceMode/mode-edit/index/' + deviceModeId, params);
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
this.form.hwDeviceModeFunctionList = this.hwDeviceModeFunctionList;
if (this.form.deviceModeId != null) {
updateDeviceMode(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addDeviceMode(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const deviceModeIds = row.deviceModeId || this.ids;
this.$modal.confirm('是否确认删除设备模型ID为"' + deviceModeIds + '"的数据项?').then(function () {
return delDeviceMode(deviceModeIds);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {
});
},
/** 设备模型功能序号 */
rowHwDeviceModeFunctionIndex({row, rowIndex}) {
row.index = rowIndex + 1;
},
/** 设备模型功能添加按钮操作 */
handleAddHwDeviceModeFunction() {
let obj = {};
obj.functionMode = "";
obj.coordinate = "";
obj.functionName = "";
obj.functionIdentifier = "";
obj.functionType = "";
obj.dataType = "";
obj.dataDefinition = "";
obj.functionFormula = "";
obj.propertyUnit = "";
obj.displayFlag = "";
obj.rwFlag = "";
obj.invokeMethod = "";
obj.eventType = "";
obj.remark = "";
obj.acquisitionFormula = "";
obj.orderFlag = "";
obj.deviceRegister = "";
obj.propertyStep = "";
obj.propertyField = "";
this.hwDeviceModeFunctionList.push(obj);
},
/** 设备模型功能删除按钮操作 */
handleDeleteHwDeviceModeFunction() {
if (this.checkedHwDeviceModeFunction.length == 0) {
this.$modal.msgError("请先选择要删除的设备模型功能数据");
} else {
const hwDeviceModeFunctionList = this.hwDeviceModeFunctionList;
const checkedHwDeviceModeFunction = this.checkedHwDeviceModeFunction;
this.hwDeviceModeFunctionList = hwDeviceModeFunctionList.filter(function (item) {
return checkedHwDeviceModeFunction.indexOf(item.index) == -1
});
}
},
/** 复选框选中数据 */
handleHwDeviceModeFunctionSelectionChange(selection) {
this.checkedHwDeviceModeFunction = selection.map(item => item.index)
},
/** 导出按钮操作 */
handleExport() {
this.download('business/deviceMode/export', {
...this.queryParams
}, `deviceMode_${new Date().getTime()}.xlsx`)
this.download('business/deviceMode/exportFunction', {
}, `deviceModeFunction_${new Date().getTime()}.xlsx`)
},
/** 重建超级表按钮操作 */
handleRebuildTdSuperTables() {
this.$modal.confirm('是否确认重建所有设备监测数据超级表?').then(function () {
return rebuildTdSuperTables();
}).then(() => {
this.$modal.msgSuccess("重建成功");
}).catch(() => {
});
},
}
};
</script>
Loading…
Cancel
Save