feat: 增加装置上传心跳并返回命令,上传命令结果

dev
huangfeng 11 months ago
parent 3ccee70910
commit e914e5a6ec

@ -0,0 +1,50 @@
package com.shxy.xymanager_admin.controller;
import com.shxy.xymanager_common.base.BaseController;
import com.shxy.xymanager_common.base.ResponseReult;
import com.shxy.xymanager_common.util.HttpRequestUtil;
import com.shxy.xymanager_service.service.MntnService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
@RestController
@Api(tags = {"设备接入接口"})
@RequestMapping("mntn")
@Slf4j
public class MntnController extends BaseController {
@Resource
MntnService service;
@PostMapping("")
@ApiOperation("上传心跳并返回命令")
public ResponseReult<HashMap<String, Object>> sync(@RequestParam("cmdid") String cmdid,
@RequestBody HashMap<String, Object> data,
HttpServletRequest req, HttpServletResponse resp) throws Exception {
String ip = HttpRequestUtil.getRemoteIp(req);
String multi = req.getHeader("Accept-Cmds");
HashMap<String, Object> result = service.sync(cmdid, ip, multi, data);
resp.setHeader("ResSyncTime", String.valueOf(System.currentTimeMillis()));
return ResponseReult.success(result);
}
@GetMapping("status")
@ApiOperation("上传命令结果")
public ResponseReult<String> status(@RequestParam("cid") Integer cid,
@RequestParam("res") Integer res,
@RequestParam("content") String content) {
service.result(cid, res, content);
ResponseReult resp = new ResponseReult();
resp.setCode(0);
return resp;
}
}

@ -1,60 +0,0 @@
//package com.shxy.xymanager_admin.controller;
//
//import com.shxy.xymanager_common.annotation.Log;
//import com.shxy.xymanager_common.base.BaseController;
//import com.shxy.xymanager_common.base.ResponseReult;
//import com.shxy.xymanager_common.bean.ServiceBody;
//import com.shxy.xymanager_common.bean.ServiceStatus;
//import com.shxy.xymanager_common.vo.*;
//import com.shxy.xymanager_service.service.YwService;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import io.swagger.annotations.ApiResponse;
//import io.swagger.annotations.ApiResponses;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.validation.annotation.Validated;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//
//@Api(value = "运维接口", tags = "运维接口相关")
//@RestController
//@Slf4j
//public class YunWeiController extends BaseController {
//
// @Autowired
// YwService ywService;
//
// @ApiOperation(value = "获取运维指令", notes = "获取运维指令接口", httpMethod = "POST")
// @ApiResponses({@ApiResponse(code = 200, message = "请求成功"), @ApiResponse(code = 400, message = "请求参数没填好"), @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对")})
// @RequestMapping("/postYwCmd")
// @Log(title = "获取运维指令", type = "查询")
// public ResponseReult<String> postYwCmd(@RequestBody @Validated YWCmdVo vo) {
// ServiceBody<String> serviceBody = ywService.postYwCmd(vo);
// if (serviceBody.getCode() == ServiceStatus.SUCCESS) {
// return ResponseReult.success(serviceBody.getData());
//
//
// } else {
// return ResponseReult.error(serviceBody.getCode(), serviceBody.getMsg());
// }
// }
//
//// @ApiOperation(value = "前端查询指令列表", notes = "前端查询指令列表接口", httpMethod = "POST")
//// @ApiResponses({@ApiResponse(code = 200, message = "请求成功"), @ApiResponse(code = 400, message = "请求参数没填好"), @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对")})
//// @RequestMapping("/getYwCmdList")
//// @Log(title = "获取运维指令", type = "查询")
//// public ResponseReult<String> postYwCmd(@RequestBody @Validated YWCmdVo vo) {
//// ServiceBody<String> serviceBody = ywService.postYwCmd(vo);
//// if (serviceBody.getCode() == ServiceStatus.SUCCESS) {
//// return ResponseReult.success(serviceBody.getData());
//// } else {
//// return ResponseReult.error(serviceBody.getCode(), serviceBody.getMsg());
//// }
//// }
//
//
//
//}

@ -77,6 +77,7 @@ public class SecurityConfig {
urlWhiteList.add("/xymanager/henan/**");
urlWhiteList.add("/xymanager/kaptcha");
urlWhiteList.add("/xymanager/test/**");
urlWhiteList.add("/xymanager/mntn/**");
StreamReadConstraints streamReadConstraints = StreamReadConstraints
.builder()

@ -0,0 +1,137 @@
package com.shxy.xymanager_common.entity;
import java.util.Date;
public class MntnCmdResults {
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column mntn_cmd_results.cid
*
* @mbg.generated
*/
private Integer cid;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column mntn_cmd_results.result
*
* @mbg.generated
*/
private Integer result;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column mntn_cmd_results.create_time
*
* @mbg.generated
*/
private Date createTime;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column mntn_cmd_results.content
*
* @mbg.generated
*/
private String content;
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column mntn_cmd_results.cid
*
* @return the value of mntn_cmd_results.cid
*
* @mbg.generated
*/
public Integer getCid() {
return cid;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column mntn_cmd_results.cid
*
* @param cid the value for mntn_cmd_results.cid
*
* @mbg.generated
*/
public void setCid(Integer cid) {
this.cid = cid;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column mntn_cmd_results.result
*
* @return the value of mntn_cmd_results.result
*
* @mbg.generated
*/
public Integer getResult() {
return result;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column mntn_cmd_results.result
*
* @param result the value for mntn_cmd_results.result
*
* @mbg.generated
*/
public void setResult(Integer result) {
this.result = result;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column mntn_cmd_results.create_time
*
* @return the value of mntn_cmd_results.create_time
*
* @mbg.generated
*/
public Date getCreateTime() {
return createTime;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column mntn_cmd_results.create_time
*
* @param createTime the value for mntn_cmd_results.create_time
*
* @mbg.generated
*/
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column mntn_cmd_results.content
*
* @return the value of mntn_cmd_results.content
*
* @mbg.generated
*/
public String getContent() {
return content;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column mntn_cmd_results.content
*
* @param content the value for mntn_cmd_results.content
*
* @mbg.generated
*/
public void setContent(String content) {
this.content = content;
}
}

@ -0,0 +1,482 @@
package com.shxy.xymanager_common.entity;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class MntnCmdResultsExample {
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
protected String orderByClause;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
protected boolean distinct;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
protected List<Criteria> oredCriteria;
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
public MntnCmdResultsExample() {
oredCriteria = new ArrayList<>();
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
public String getOrderByClause() {
return orderByClause;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
public boolean isDistinct() {
return distinct;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
public List<Criteria> getOredCriteria() {
return oredCriteria;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
public void or(Criteria criteria) {
oredCriteria.add(criteria);
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
public Criteria or() {
Criteria criteria = createCriteriaInternal();
oredCriteria.add(criteria);
return criteria;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
public Criteria createCriteria() {
Criteria criteria = createCriteriaInternal();
if (oredCriteria.size() == 0) {
oredCriteria.add(criteria);
}
return criteria;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
protected Criteria createCriteriaInternal() {
Criteria criteria = new Criteria();
return criteria;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
public void clear() {
oredCriteria.clear();
orderByClause = null;
distinct = false;
}
/**
* This class was generated by MyBatis Generator.
* This class corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<>();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
}
public List<Criterion> getCriteria() {
return criteria;
}
protected void addCriterion(String condition) {
if (condition == null) {
throw new RuntimeException("Value for condition cannot be null");
}
criteria.add(new Criterion(condition));
}
protected void addCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value));
}
protected void addCriterion(String condition, Object value1, Object value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value1, value2));
}
public Criteria andCidIsNull() {
addCriterion("cid is null");
return (Criteria) this;
}
public Criteria andCidIsNotNull() {
addCriterion("cid is not null");
return (Criteria) this;
}
public Criteria andCidEqualTo(Integer value) {
addCriterion("cid =", value, "cid");
return (Criteria) this;
}
public Criteria andCidNotEqualTo(Integer value) {
addCriterion("cid <>", value, "cid");
return (Criteria) this;
}
public Criteria andCidGreaterThan(Integer value) {
addCriterion("cid >", value, "cid");
return (Criteria) this;
}
public Criteria andCidGreaterThanOrEqualTo(Integer value) {
addCriterion("cid >=", value, "cid");
return (Criteria) this;
}
public Criteria andCidLessThan(Integer value) {
addCriterion("cid <", value, "cid");
return (Criteria) this;
}
public Criteria andCidLessThanOrEqualTo(Integer value) {
addCriterion("cid <=", value, "cid");
return (Criteria) this;
}
public Criteria andCidIn(List<Integer> values) {
addCriterion("cid in", values, "cid");
return (Criteria) this;
}
public Criteria andCidNotIn(List<Integer> values) {
addCriterion("cid not in", values, "cid");
return (Criteria) this;
}
public Criteria andCidBetween(Integer value1, Integer value2) {
addCriterion("cid between", value1, value2, "cid");
return (Criteria) this;
}
public Criteria andCidNotBetween(Integer value1, Integer value2) {
addCriterion("cid not between", value1, value2, "cid");
return (Criteria) this;
}
public Criteria andResultIsNull() {
addCriterion("`result` is null");
return (Criteria) this;
}
public Criteria andResultIsNotNull() {
addCriterion("`result` is not null");
return (Criteria) this;
}
public Criteria andResultEqualTo(Integer value) {
addCriterion("`result` =", value, "result");
return (Criteria) this;
}
public Criteria andResultNotEqualTo(Integer value) {
addCriterion("`result` <>", value, "result");
return (Criteria) this;
}
public Criteria andResultGreaterThan(Integer value) {
addCriterion("`result` >", value, "result");
return (Criteria) this;
}
public Criteria andResultGreaterThanOrEqualTo(Integer value) {
addCriterion("`result` >=", value, "result");
return (Criteria) this;
}
public Criteria andResultLessThan(Integer value) {
addCriterion("`result` <", value, "result");
return (Criteria) this;
}
public Criteria andResultLessThanOrEqualTo(Integer value) {
addCriterion("`result` <=", value, "result");
return (Criteria) this;
}
public Criteria andResultIn(List<Integer> values) {
addCriterion("`result` in", values, "result");
return (Criteria) this;
}
public Criteria andResultNotIn(List<Integer> values) {
addCriterion("`result` not in", values, "result");
return (Criteria) this;
}
public Criteria andResultBetween(Integer value1, Integer value2) {
addCriterion("`result` between", value1, value2, "result");
return (Criteria) this;
}
public Criteria andResultNotBetween(Integer value1, Integer value2) {
addCriterion("`result` not between", value1, value2, "result");
return (Criteria) this;
}
public Criteria andCreateTimeIsNull() {
addCriterion("create_time is null");
return (Criteria) this;
}
public Criteria andCreateTimeIsNotNull() {
addCriterion("create_time is not null");
return (Criteria) this;
}
public Criteria andCreateTimeEqualTo(Date value) {
addCriterion("create_time =", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotEqualTo(Date value) {
addCriterion("create_time <>", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeGreaterThan(Date value) {
addCriterion("create_time >", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeGreaterThanOrEqualTo(Date value) {
addCriterion("create_time >=", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeLessThan(Date value) {
addCriterion("create_time <", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeLessThanOrEqualTo(Date value) {
addCriterion("create_time <=", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeIn(List<Date> values) {
addCriterion("create_time in", values, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotIn(List<Date> values) {
addCriterion("create_time not in", values, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeBetween(Date value1, Date value2) {
addCriterion("create_time between", value1, value2, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotBetween(Date value1, Date value2) {
addCriterion("create_time not between", value1, value2, "createTime");
return (Criteria) this;
}
}
/**
* This class was generated by MyBatis Generator.
* This class corresponds to the database table mntn_cmd_results
*
* @mbg.generated do_not_delete_during_merge
*/
public static class Criteria extends GeneratedCriteria {
protected Criteria() {
super();
}
}
/**
* This class was generated by MyBatis Generator.
* This class corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
public static class Criterion {
private String condition;
private Object value;
private Object secondValue;
private boolean noValue;
private boolean singleValue;
private boolean betweenValue;
private boolean listValue;
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
this.typeHandler = null;
this.noValue = true;
}
protected Criterion(String condition, Object value, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.typeHandler = typeHandler;
if (value instanceof List<?>) {
this.listValue = true;
} else {
this.singleValue = true;
}
}
protected Criterion(String condition, Object value) {
this(condition, value, null);
}
protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.secondValue = secondValue;
this.typeHandler = typeHandler;
this.betweenValue = true;
}
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
}
}

@ -0,0 +1,67 @@
package com.shxy.xymanager_common.util;
import org.apache.commons.lang3.StringUtils;
import javax.servlet.http.HttpServletRequest;
public class HttpRequestUtil {
/**
* ip
*/
public static String getRemoteIp(HttpServletRequest req) {
String ip = req.getHeader("X-Forwarded-For");
if (checkIp(ip)) {
return ip;
}
// 多次反向代理后会有多个ip值第一个ip才是真实ip
if (StringUtils.isNotBlank(ip) && ip.contains(",")) {
ip = ip.split(",")[0];
if (checkIp(ip)) {
return ip;
}
}
ip = req.getHeader("X-Forwarded-For-Pound");
if (checkIp(ip)) {
return ip;
}
ip = req.getHeader("Proxy-Client-IP");
if (checkIp(ip)) {
return ip;
}
ip = req.getHeader("WL-Proxy-Client-IP");
if (checkIp(ip)) {
return ip;
}
ip = req.getHeader("HTTP_CLIENT_IP");
if (checkIp(ip)) {
return ip;
}
ip = req.getHeader("HTTP_X_FORWARDED_FOR");
if (checkIp(ip)) {
return ip;
}
ip = req.getHeader("X-Real-IP");
if (checkIp(ip)) {
return ip;
}
ip = req.getHeader("RemoteIp");
if (checkIp(ip)) {
return ip;
}
ip = req.getRemoteAddr();
return ip;
}
/**
* check ip
*/
public static boolean checkIp(String ip) {
return (ip != null
&& ip.length() != 0
&& !"unkown".equalsIgnoreCase(ip)
&& ip.split("\\.").length == 4);
}
}

@ -0,0 +1,121 @@
package com.shxy.xymanager_dao.dao;
import com.shxy.xymanager_common.entity.MntnCmdResults;
import com.shxy.xymanager_common.entity.MntnCmdResultsExample;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface MntnCmdResultsMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
long countByExample(MntnCmdResultsExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
int deleteByExample(MntnCmdResultsExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
int deleteByPrimaryKey(Integer cid);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
int insert(MntnCmdResults row);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
int insertSelective(MntnCmdResults row);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
List<MntnCmdResults> selectByExampleWithBLOBs(MntnCmdResultsExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
List<MntnCmdResults> selectByExample(MntnCmdResultsExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
MntnCmdResults selectByPrimaryKey(Integer cid);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
int updateByExampleSelective(@Param("row") MntnCmdResults row, @Param("example") MntnCmdResultsExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
int updateByExampleWithBLOBs(@Param("row") MntnCmdResults row, @Param("example") MntnCmdResultsExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
int updateByExample(@Param("row") MntnCmdResults row, @Param("example") MntnCmdResultsExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
int updateByPrimaryKeySelective(MntnCmdResults row);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
int updateByPrimaryKeyWithBLOBs(MntnCmdResults row);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table mntn_cmd_results
*
* @mbg.generated
*/
int updateByPrimaryKey(MntnCmdResults row);
}

@ -0,0 +1,314 @@
<?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.shxy.xymanager_dao.dao.MntnCmdResultsMapper">
<resultMap id="BaseResultMap" type="com.shxy.xymanager_common.entity.MntnCmdResults">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<id column="cid" jdbcType="INTEGER" property="cid" />
<result column="result" jdbcType="INTEGER" property="result" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.shxy.xymanager_common.entity.MntnCmdResults">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<result column="content" jdbcType="LONGVARCHAR" property="content" />
</resultMap>
<sql id="Example_Where_Clause">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
cid, `result`, create_time
</sql>
<sql id="Blob_Column_List">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
content
</sql>
<select id="selectByExampleWithBLOBs" parameterType="com.shxy.xymanager_common.entity.MntnCmdResultsExample" resultMap="ResultMapWithBLOBs">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from mntn_cmd_results
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByExample" parameterType="com.shxy.xymanager_common.entity.MntnCmdResultsExample" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from mntn_cmd_results
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="ResultMapWithBLOBs">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from mntn_cmd_results
where cid = #{cid,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
delete from mntn_cmd_results
where cid = #{cid,jdbcType=INTEGER}
</delete>
<delete id="deleteByExample" parameterType="com.shxy.xymanager_common.entity.MntnCmdResultsExample">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
delete from mntn_cmd_results
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.shxy.xymanager_common.entity.MntnCmdResults">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
insert into mntn_cmd_results (cid, `result`, create_time,
content)
values (#{cid,jdbcType=INTEGER}, #{result,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP},
#{content,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.shxy.xymanager_common.entity.MntnCmdResults">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
insert into mntn_cmd_results
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="cid != null">
cid,
</if>
<if test="result != null">
`result`,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="content != null">
content,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="cid != null">
#{cid,jdbcType=INTEGER},
</if>
<if test="result != null">
#{result,jdbcType=INTEGER},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="content != null">
#{content,jdbcType=LONGVARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.shxy.xymanager_common.entity.MntnCmdResultsExample" resultType="java.lang.Long">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select count(*) from mntn_cmd_results
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update mntn_cmd_results
<set>
<if test="row.cid != null">
cid = #{row.cid,jdbcType=INTEGER},
</if>
<if test="row.result != null">
`result` = #{row.result,jdbcType=INTEGER},
</if>
<if test="row.createTime != null">
create_time = #{row.createTime,jdbcType=TIMESTAMP},
</if>
<if test="row.content != null">
content = #{row.content,jdbcType=LONGVARCHAR},
</if>
</set>
<if test="example != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExampleWithBLOBs" parameterType="map">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update mntn_cmd_results
set cid = #{row.cid,jdbcType=INTEGER},
`result` = #{row.result,jdbcType=INTEGER},
create_time = #{row.createTime,jdbcType=TIMESTAMP},
content = #{row.content,jdbcType=LONGVARCHAR}
<if test="example != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update mntn_cmd_results
set cid = #{row.cid,jdbcType=INTEGER},
`result` = #{row.result,jdbcType=INTEGER},
create_time = #{row.createTime,jdbcType=TIMESTAMP}
<if test="example != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.shxy.xymanager_common.entity.MntnCmdResults">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update mntn_cmd_results
<set>
<if test="result != null">
`result` = #{result,jdbcType=INTEGER},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="content != null">
content = #{content,jdbcType=LONGVARCHAR},
</if>
</set>
where cid = #{cid,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKeyWithBLOBs" parameterType="com.shxy.xymanager_common.entity.MntnCmdResults">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update mntn_cmd_results
set `result` = #{result,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=TIMESTAMP},
content = #{content,jdbcType=LONGVARCHAR}
where cid = #{cid,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.shxy.xymanager_common.entity.MntnCmdResults">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update mntn_cmd_results
set `result` = #{result,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=TIMESTAMP}
where cid = #{cid,jdbcType=INTEGER}
</update>
</mapper>

@ -0,0 +1,154 @@
package com.shxy.xymanager_service.impl;
import com.shxy.xymanager_common.entity.*;
import com.shxy.xymanager_common.exception.ApiException;
import com.shxy.xymanager_common.util.JSONUtil;
import com.shxy.xymanager_dao.dao.*;
import com.shxy.xymanager_service.service.TerminalExtService;
import com.shxy.xymanager_service.service.MntnService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class MntnServiceImpl implements MntnService {
@Resource
MntnCmdsMapper cmdsMapper;
@Resource
MntnCmdHistoryMapper historyMapper;
@Resource
MntnStatusMapper statusMapper;
@Resource
MntnRawReportsMapper rawReportsMapper;
@Resource
TerminalExtService terminalExtService;
@Resource
MntnCmdResultsMapper resultsMapper;
@Override
public HashMap<String, Object> sync(String cmdid, String ip, String multi, HashMap<String, Object> data) throws Exception {
Terminals term = terminalExtService.getByCmdid(cmdid);
if (term == null) {
throw new ApiException("该装置不存在");
}
this.insertReport(term.getId(), ip, data);
MntnStatus status = statusMapper.selectByPrimaryKey(term.getId());
MntnCmdsExample example = new MntnCmdsExample();
MntnCmdsExample.Criteria criteria = example.createCriteria();
criteria.andTermIdEqualTo(term.getId());
List<MntnCmds> list = cmdsMapper.selectByExample(example);
if (CollectionUtils.isEmpty(list)) {
return this.buildResult(status);
} else if (list.size() > 1 && "Multiple".equalsIgnoreCase(multi)) {
return this.buildResult(status, list);
} else {
MntnCmds cmd = list.get(0);
return this.buildResult(status, cmd);
}
}
private HashMap<String, Object> buildResult(MntnStatus status, List<MntnCmds> list) throws Exception {
HashMap<String, Object> result = this.buildResult(status);
List<HashMap<String, Object>> cmds = new ArrayList<>();
for (MntnCmds cmd : list) {
HashMap<String, Object> map = this.buildCmdMap(cmd);
cmds.add(map);
this.moveToHistory(cmd);
}
result.put("cmds", cmds);
return result;
}
private HashMap<String, Object> buildResult(MntnStatus status, MntnCmds cmd) throws Exception {
HashMap<String, Object> result = this.buildResult(status);
HashMap<String, Object> map = this.buildCmdMap(cmd);
this.moveToHistory(cmd);
result.putAll(map);
return result;
}
private HashMap<String, Object> buildResult(MntnStatus status) throws Exception {
HashMap<String, Object> result = new HashMap<>();
if (status != null) {
if (status.getInMaintain() != null && status.getInMaintain().intValue() > 0) {
result.put("yw", 1);
} else {
result.put("yw", 0);
}
if (status.getQuickHb() != null && status.getQuickHb().intValue() > 0) {
result.put("kxt", 1);
} else {
result.put("kxt", 0);
}
}
return result;
}
private HashMap<String, Object> buildCmdMap(MntnCmds cmd) throws Exception {
HashMap<String, Object> result = new HashMap<>();
HashMap<String, Object> data = JSONUtil.json2Object(cmd.getCmd(), HashMap.class);
result.putAll(data);
result.put("cid", cmd.getId());
result.put("cmd", cmd.getName());
if ("upgrade".equalsIgnoreCase(cmd.getName())) {
result.put("isUpgrade", 1);
result.put("sj", 1);
} else {
result.put("isUpgrade", 0);
result.put("sj", 0);
}
return result;
}
private void insertReport(Integer termId, String ip, HashMap<String, Object> data) {
String json = JSONUtil.object2Json(data);
MntnRawReports item = new MntnRawReports();
item.setTermId(termId);
item.setContent(json);
item.setIp(ip);
item.setCreateTime(System.currentTimeMillis() / 1000);
rawReportsMapper.insert(item);
}
private void moveToHistory(MntnCmds cmd) {
MntnCmdHistory history = new MntnCmdHistory();
history.setId(cmd.getId());
history.setCmd(cmd.getCmd());
history.setDesc(cmd.getDesc());
history.setName(cmd.getName());
history.setTermId(cmd.getTermId());
history.setCreateTime(cmd.getCreateTime());
history.setStatus(Byte.valueOf("1"));
history.setPublishTime(new Date());
historyMapper.insert(history);
cmdsMapper.deleteByPrimaryKey(cmd.getId());
}
@Override
public void result(Integer cid, Integer res, String content) {
MntnCmdResults item = new MntnCmdResults();
item.setCid(cid);
item.setResult(res);
item.setContent(content);
resultsMapper.insert(item);
}
}

@ -0,0 +1,10 @@
package com.shxy.xymanager_service.service;
import java.util.HashMap;
public interface MntnService {
HashMap<String, Object> sync(String cmdid, String ip, String multi, HashMap<String, Object> data) throws Exception;
void result(Integer cid, Integer res, String content);
}
Loading…
Cancel
Save