Browse Source

新增:德联一键控制功能

zhongwei
ty 4 months ago
parent
commit
ab0b0f7ee1
  1. 54
      hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/constants/DeLianConstants.java
  2. 43
      hzims-service/equipment/src/main/java/com/hnac/hzims/delian/controller/DeLianController.java
  3. 14
      hzims-service/equipment/src/main/java/com/hnac/hzims/delian/service/IDeLianService.java
  4. 92
      hzims-service/equipment/src/main/java/com/hnac/hzims/delian/service/impl/DeLianServiceImpl.java
  5. 20
      hzims-service/equipment/src/main/java/com/hnac/hzims/delian/vo/StrategyDataVO.java
  6. 6
      hzims-service/equipment/src/main/resources/template/template.yml

54
hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/constants/DeLianConstants.java

@ -0,0 +1,54 @@
package com.hnac.hzims.constants;
import lombok.Getter;
/**
* @Author: ty
* 交接班状态值
*/
@Getter
public enum DeLianConstants {
OAUTHTOKEN("DLF_GetOauthToken","获取Token"),
DEVTYPES("DLF_GetDevTypes","获取设备类型"),
ACTIONTYPES("DLF_GetActionTypes","获取动作类型"),
UNITTYPES("DLF_GetUnitTypes","获取所有单位类型"),
ALLVALUEENUMDETAIL("DLF_GetAllValueEnumDetail","获取所有动作值类型"),
HOSTINFO("DLF_GetHostInfo","获取设备类型"),
GROUPINFO("DLF_GetGroupInfo","获取设备类型"),
CONTROLTERMINALACTOIN("DLF_ControlTerminalActoin","获取设备类型"),
STRATEGYS("DLF_GetStrategys","获取策略目录"),
EXECUTESCENE("DLF_ExecuteScene","执行一键场景");
private String code;
private String name;
DeLianConstants(String code, String name) {
this.code = code;
this.name = name;
}
public void setCode(String code) {
this.code = code;
}
public void setName(String name) {
this.name = name;
}
/**
* 根据值获取枚举
* @param code
* @return
*/
public static DeLianConstants getCodeByData(String code){
for (DeLianConstants status: DeLianConstants.values()) {
if(status.getCode().equals(code)){
return status;
}
}
return OAUTHTOKEN;
}
}

43
hzims-service/equipment/src/main/java/com/hnac/hzims/delian/controller/DeLianController.java

@ -0,0 +1,43 @@
package com.hnac.hzims.delian.controller;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hnac.hzims.delian.service.IDeLianService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;
/**
* 设备控制器
*
* @author moze
*/
@RestController
@AllArgsConstructor
@RequestMapping("/deLian")
@Api(value = "德联", tags = "德联信息管理")
public class DeLianController extends BladeController {
private final IDeLianService iDeLianService;
/**
* 获取策略详情
*/
@GetMapping("/getStrategys")
@ApiOperationSupport(order = 1)
@ApiOperation(value = "获取策略详情")
public R getStrategys() {
return R.data(iDeLianService.getStrategys());
}
/**
* 执行一键场景
*/
@GetMapping ("/executeScene")
@ApiOperationSupport(order = 1)
@ApiOperation(value = "执行一键场景", notes = "传入key")
public R executeScene(@RequestParam(value = "key") String key) {
return iDeLianService.executeScene(key);
}
}

14
hzims-service/equipment/src/main/java/com/hnac/hzims/delian/service/IDeLianService.java

@ -0,0 +1,14 @@
package com.hnac.hzims.delian.service;
import com.hnac.hzims.delian.vo.StrategyDataVO;
import com.hnac.hzims.equipment.vo.StationEmVideoVO;
import org.springblade.core.tool.api.R;
import java.util.List;
public interface IDeLianService {
List<StrategyDataVO> getStrategys();
R executeScene(String key);
}

92
hzims-service/equipment/src/main/java/com/hnac/hzims/delian/service/impl/DeLianServiceImpl.java

@ -0,0 +1,92 @@
package com.hnac.hzims.delian.service.impl;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hnac.hzims.common.logs.utils.StringUtils;
import com.hnac.hzims.constants.DeLianConstants;
import com.hnac.hzims.delian.service.IDeLianService;
import com.hnac.hzims.delian.vo.StrategyDataVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@Service
@RequiredArgsConstructor
@Slf4j
public class DeLianServiceImpl implements IDeLianService {
@Value("${url.deLianUrl}")
private String deLianUrl;
@Value("${deLian.hostId}")
private String hostId;
@Value("${deLian.passWord}")
private String passWord;
@Override
public List<StrategyDataVO> getStrategys() {
HashMap<String, Object> param = getOauthToken();
HashMap<String, Object> requestData = new HashMap<String, Object>() {{
put("Strategy_Type", 0);
}};
param.put("request_data",requestData);
param.put("request_cmd",DeLianConstants.STRATEGYS.getCode());
String jsonString = JSON.toJSONString(param);
HttpResponse response = HttpRequest.post(deLianUrl).body(jsonString).execute();
if(response.getStatus() == HttpServletResponse.SC_OK ) {
List<StrategyDataVO> responseData = JSONObject.parseArray(JSONObject.parseObject(response.body()).getString("response_data"), StrategyDataVO.class);
return responseData;
}
return new ArrayList<>();
}
@Override
public R executeScene(String key) {
HashMap<String, Object> param = getOauthToken();
param.put("request_cmd",DeLianConstants.EXECUTESCENE.getCode());
List<StrategyDataVO> strategys = getStrategys();
for (StrategyDataVO strategy : strategys) {
if (key.equals(strategy.getSn())){
param.put("request_data",strategy.getSID());
}
}
HttpResponse response = HttpRequest.post(deLianUrl).body(JSON.toJSONString(param)).execute();
if(response.getStatus() == HttpServletResponse.SC_OK ) {
return R.success("执行成功");
}
return R.fail("执行成功");
}
public HashMap<String, Object> getOauthToken() {
HashMap<String, Object> requestData = new HashMap<String, Object>() {{
put("HOST_ID", hostId);
put("HOST_PW", passWord);
}};
HashMap<String, Object> param = new HashMap<String, Object>() {{
put("request_cmd", DeLianConstants.OAUTHTOKEN.getCode());
put("request_code", "wjf6s3a8i0mjuiv0");
put("request_data", requestData);
}};
String jsonString = JSON.toJSONString(param);
HttpResponse response = HttpRequest.post(deLianUrl).body(jsonString).execute();
String token = JSONObject.parseObject(response.body()).getString("request_token");
if(response.getStatus() == HttpServletResponse.SC_OK &&
StringUtils.isNotBlank(token)) {
param.remove("request_data");
param.remove("request_cmd");
param.put("request_token",token);
return param;
}else {
throw new ServiceException("获取权限失败,请稍后重试!");
}
}
}

20
hzims-service/equipment/src/main/java/com/hnac/hzims/delian/vo/StrategyDataVO.java

@ -0,0 +1,20 @@
package com.hnac.hzims.delian.vo;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
/**
* @author ty
* @date 2024/07/16
*/
@Data
public class StrategyDataVO {
@JSONField(name = "S_ID")
private Integer sID;
@JSONField(name = "S_N")
private String sn;
@JSONField(name = "Dc")
private String dc;
@JSONField(name = "En")
private Integer en;
}

6
hzims-service/equipment/src/main/resources/template/template.yml

@ -148,4 +148,8 @@ url:
# 获取智能诊断历史趋势图
searchFaultHistoryState: http://${hzims.fdp.url.ip}:${hzims.fdp.url.port}/diagnose/searchFaultHistoryState
# 获取故障相关的实时数据
getRealByFault: http://${hzims.fdp.url.ip}:${hzims.fdp.url.port}/diagnose/getRealByFault
getRealByFault: http://${hzims.fdp.url.ip}:${hzims.fdp.url.port}/diagnose/getRealByFault
deLianUrl: http://iot.delianfa.com:8081/api/Docking/DockingData
deLian:
hostId: 400184
passWord: 654321
Loading…
Cancel
Save