diff --git a/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/MntnController.java b/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/MntnController.java new file mode 100644 index 0000000..f6d7c93 --- /dev/null +++ b/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/MntnController.java @@ -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> sync(@RequestParam("cmdid") String cmdid, + @RequestBody HashMap data, + HttpServletRequest req, HttpServletResponse resp) throws Exception { + String ip = HttpRequestUtil.getRemoteIp(req); + String multi = req.getHeader("Accept-Cmds"); + HashMap result = service.sync(cmdid, ip, multi, data); + resp.setHeader("ResSyncTime", String.valueOf(System.currentTimeMillis())); + return ResponseReult.success(result); + } + + @GetMapping("status") + @ApiOperation("上传命令结果") + public ResponseReult 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; + } + +} diff --git a/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/YunWeiController.java b/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/YunWeiController.java deleted file mode 100644 index 2009ef5..0000000 --- a/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/YunWeiController.java +++ /dev/null @@ -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 postYwCmd(@RequestBody @Validated YWCmdVo vo) { -// ServiceBody 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 postYwCmd(@RequestBody @Validated YWCmdVo vo) { -//// ServiceBody serviceBody = ywService.postYwCmd(vo); -//// if (serviceBody.getCode() == ServiceStatus.SUCCESS) { -//// return ResponseReult.success(serviceBody.getData()); -//// } else { -//// return ResponseReult.error(serviceBody.getCode(), serviceBody.getMsg()); -//// } -//// } -// -// -// -//} diff --git a/xymanager_common/src/main/java/com/shxy/xymanager_common/config/SecurityConfig.java b/xymanager_common/src/main/java/com/shxy/xymanager_common/config/SecurityConfig.java index 86bdf65..4f68424 100644 --- a/xymanager_common/src/main/java/com/shxy/xymanager_common/config/SecurityConfig.java +++ b/xymanager_common/src/main/java/com/shxy/xymanager_common/config/SecurityConfig.java @@ -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() diff --git a/xymanager_common/src/main/java/com/shxy/xymanager_common/entity/MntnCmdResults.java b/xymanager_common/src/main/java/com/shxy/xymanager_common/entity/MntnCmdResults.java new file mode 100644 index 0000000..57ee0f2 --- /dev/null +++ b/xymanager_common/src/main/java/com/shxy/xymanager_common/entity/MntnCmdResults.java @@ -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; + } +} \ No newline at end of file diff --git a/xymanager_common/src/main/java/com/shxy/xymanager_common/entity/MntnCmdResultsExample.java b/xymanager_common/src/main/java/com/shxy/xymanager_common/entity/MntnCmdResultsExample.java new file mode 100644 index 0000000..4016f03 --- /dev/null +++ b/xymanager_common/src/main/java/com/shxy/xymanager_common/entity/MntnCmdResultsExample.java @@ -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 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 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 criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList<>(); + } + + public boolean isValid() { + return criteria.size() > 0; + } + + public List getAllCriteria() { + return criteria; + } + + public List 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 values) { + addCriterion("cid in", values, "cid"); + return (Criteria) this; + } + + public Criteria andCidNotIn(List 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 values) { + addCriterion("`result` in", values, "result"); + return (Criteria) this; + } + + public Criteria andResultNotIn(List 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 values) { + addCriterion("create_time in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotIn(List 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); + } + } +} \ No newline at end of file diff --git a/xymanager_common/src/main/java/com/shxy/xymanager_common/util/HttpRequestUtil.java b/xymanager_common/src/main/java/com/shxy/xymanager_common/util/HttpRequestUtil.java new file mode 100644 index 0000000..088a440 --- /dev/null +++ b/xymanager_common/src/main/java/com/shxy/xymanager_common/util/HttpRequestUtil.java @@ -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); + } + +} diff --git a/xymanager_dao/src/main/java/com/shxy/xymanager_dao/dao/MntnCmdResultsMapper.java b/xymanager_dao/src/main/java/com/shxy/xymanager_dao/dao/MntnCmdResultsMapper.java new file mode 100644 index 0000000..6f851b2 --- /dev/null +++ b/xymanager_dao/src/main/java/com/shxy/xymanager_dao/dao/MntnCmdResultsMapper.java @@ -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 selectByExampleWithBLOBs(MntnCmdResultsExample example); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table mntn_cmd_results + * + * @mbg.generated + */ + List 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); +} \ No newline at end of file diff --git a/xymanager_dao/src/main/resources/mappers/MntnCmdResultsMapper.xml b/xymanager_dao/src/main/resources/mappers/MntnCmdResultsMapper.xml new file mode 100644 index 0000000..efc0fb1 --- /dev/null +++ b/xymanager_dao/src/main/resources/mappers/MntnCmdResultsMapper.xml @@ -0,0 +1,314 @@ + + + + + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + cid, `result`, create_time + + + + content + + + + + + + delete from mntn_cmd_results + where cid = #{cid,jdbcType=INTEGER} + + + + delete from mntn_cmd_results + + + + + + + insert into mntn_cmd_results (cid, `result`, create_time, + content) + values (#{cid,jdbcType=INTEGER}, #{result,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, + #{content,jdbcType=LONGVARCHAR}) + + + + insert into mntn_cmd_results + + + cid, + + + `result`, + + + create_time, + + + content, + + + + + #{cid,jdbcType=INTEGER}, + + + #{result,jdbcType=INTEGER}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{content,jdbcType=LONGVARCHAR}, + + + + + + + update mntn_cmd_results + + + cid = #{row.cid,jdbcType=INTEGER}, + + + `result` = #{row.result,jdbcType=INTEGER}, + + + create_time = #{row.createTime,jdbcType=TIMESTAMP}, + + + content = #{row.content,jdbcType=LONGVARCHAR}, + + + + + + + + + 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} + + + + + + + update mntn_cmd_results + set cid = #{row.cid,jdbcType=INTEGER}, + `result` = #{row.result,jdbcType=INTEGER}, + create_time = #{row.createTime,jdbcType=TIMESTAMP} + + + + + + + update mntn_cmd_results + + + `result` = #{result,jdbcType=INTEGER}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + content = #{content,jdbcType=LONGVARCHAR}, + + + where cid = #{cid,jdbcType=INTEGER} + + + + update mntn_cmd_results + set `result` = #{result,jdbcType=INTEGER}, + create_time = #{createTime,jdbcType=TIMESTAMP}, + content = #{content,jdbcType=LONGVARCHAR} + where cid = #{cid,jdbcType=INTEGER} + + + + update mntn_cmd_results + set `result` = #{result,jdbcType=INTEGER}, + create_time = #{createTime,jdbcType=TIMESTAMP} + where cid = #{cid,jdbcType=INTEGER} + + \ No newline at end of file diff --git a/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/MntnServiceImpl.java b/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/MntnServiceImpl.java new file mode 100644 index 0000000..3e7087d --- /dev/null +++ b/xymanager_service/src/main/java/com/shxy/xymanager_service/impl/MntnServiceImpl.java @@ -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 sync(String cmdid, String ip, String multi, HashMap 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 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 buildResult(MntnStatus status, List list) throws Exception { + HashMap result = this.buildResult(status); + + List> cmds = new ArrayList<>(); + for (MntnCmds cmd : list) { + HashMap map = this.buildCmdMap(cmd); + cmds.add(map); + this.moveToHistory(cmd); + } + result.put("cmds", cmds); + return result; + } + + private HashMap buildResult(MntnStatus status, MntnCmds cmd) throws Exception { + HashMap result = this.buildResult(status); + + HashMap map = this.buildCmdMap(cmd); + this.moveToHistory(cmd); + result.putAll(map); + + return result; + } + + private HashMap buildResult(MntnStatus status) throws Exception { + HashMap 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 buildCmdMap(MntnCmds cmd) throws Exception { + HashMap result = new HashMap<>(); + HashMap 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 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); + } + +} diff --git a/xymanager_service/src/main/java/com/shxy/xymanager_service/service/MntnService.java b/xymanager_service/src/main/java/com/shxy/xymanager_service/service/MntnService.java new file mode 100644 index 0000000..689bab0 --- /dev/null +++ b/xymanager_service/src/main/java/com/shxy/xymanager_service/service/MntnService.java @@ -0,0 +1,10 @@ +package com.shxy.xymanager_service.service; + +import java.util.HashMap; + +public interface MntnService { + + HashMap sync(String cmdid, String ip, String multi, HashMap data) throws Exception; + + void result(Integer cid, Integer res, String content); +}