|
|
@@ -0,0 +1,261 @@
|
|
|
+package com.shkpr.service.alambizplugin.controller;
|
|
|
+
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.global.base.log.LogLevelFlag;
|
|
|
+import com.global.base.log.LogPrintMgr;
|
|
|
+import com.shkpr.service.alambizplugin.apiparam.PipeBustWarningInfoListParams;
|
|
|
+import com.shkpr.service.alambizplugin.commtools.CommTool;
|
|
|
+import com.shkpr.service.alambizplugin.constants.ApiURI;
|
|
|
+import com.shkpr.service.alambizplugin.constants.LogFlagBusiType;
|
|
|
+import com.shkpr.service.alambizplugin.constants.ResponseCode;
|
|
|
+import com.shkpr.service.alambizplugin.controllerfilter.TokenAuthenticationService;
|
|
|
+import com.shkpr.service.alambizplugin.controllervalid.CommonParamValidSK;
|
|
|
+import com.shkpr.service.alambizplugin.dbdao.services.intef.PipeBurstDeviceStatusService;
|
|
|
+import com.shkpr.service.alambizplugin.dbdao.services.intef.PipeBurstWaringInfoService;
|
|
|
+import com.shkpr.service.alambizplugin.dto.*;
|
|
|
+import com.shkpr.service.alambizplugin.exception.SelfException;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.validation.BindingResult;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 爆管分析controller
|
|
|
+ *
|
|
|
+ * @author 欧阳劲驰
|
|
|
+ * @since 1.0.0
|
|
|
+ */
|
|
|
+@RequestMapping(ApiURI.URI_PIPE_BURST_H)
|
|
|
+@RestController
|
|
|
+public class ApiPipeBurstController {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * log
|
|
|
+ */
|
|
|
+ private final String mStrClassName;
|
|
|
+ private final String mBizType;
|
|
|
+ /**
|
|
|
+ * 计数器
|
|
|
+ */
|
|
|
+ private final AtomicInteger mSeqDeviceStatusListReq;
|
|
|
+
|
|
|
+ private final ObjectMapper objectMapper;
|
|
|
+ private final PipeBurstDeviceStatusService deviceStatusService;
|
|
|
+ private final PipeBurstWaringInfoService waringInfoService;
|
|
|
+
|
|
|
+ public ApiPipeBurstController(ObjectMapper objectMapper, PipeBurstDeviceStatusService deviceStatusService, PipeBurstWaringInfoService waringInfoService) {
|
|
|
+ mStrClassName = "ApiPipeBurstController";
|
|
|
+ mBizType = LogFlagBusiType.BUSI_PIPE_BURST.toStrValue();
|
|
|
+ this.mSeqDeviceStatusListReq = new AtomicInteger(0);
|
|
|
+ this.objectMapper = objectMapper;
|
|
|
+ this.deviceStatusService = deviceStatusService;
|
|
|
+ this.waringInfoService = waringInfoService;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设备状态列表
|
|
|
+ *
|
|
|
+ * @param request request
|
|
|
+ * @param strClientType 客户端类型
|
|
|
+ * @param strUserAgent 用户信息
|
|
|
+ * @param offset 偏移数据
|
|
|
+ * @param limit 分页大小
|
|
|
+ * @return 清除状态
|
|
|
+ */
|
|
|
+ @GetMapping(value = ApiURI.URI_XXX_DEVICE_STATUS_LIST)
|
|
|
+ public ResponseRes<String> deviceStatusList(HttpServletRequest request
|
|
|
+ , @RequestHeader(value = ApiURI.HEADER_CLIENT_TYPE, required = false) String strClientType
|
|
|
+ , @RequestHeader(value = ApiURI.HEADER_USER_AGENT, required = false) String strUserAgent
|
|
|
+ , @RequestParam(value = "offset", required = false, defaultValue = "0") Integer offset
|
|
|
+ , @RequestParam(value = "limit", required = false, defaultValue = "20") Integer limit) {
|
|
|
+ //入参校验
|
|
|
+ final String URI_PATH = request.getRequestURI();
|
|
|
+ final String strPlatform = CommTool.getPlatformByAgent(strClientType, strUserAgent);
|
|
|
+ final String strUserId = (String) request.getAttribute(TokenAuthenticationService.HEADER_USERID);
|
|
|
+
|
|
|
+ //begin
|
|
|
+ long llReqBefore = System.currentTimeMillis();
|
|
|
+ String strRunSeq = String.format("%d-%d", llReqBefore, mSeqDeviceStatusListReq.incrementAndGet());
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, strUserId
|
|
|
+ , String.format("%s:%s seq:{%s} begin====>"
|
|
|
+ , strPlatform
|
|
|
+ , URI_PATH
|
|
|
+ , strRunSeq));
|
|
|
+
|
|
|
+
|
|
|
+ //构建result
|
|
|
+ ResponseRes<String> resResult = new ResponseRes<>();
|
|
|
+ resResult.setRescode(ResponseCode.RESULT_BAD.toStrCode());
|
|
|
+ resResult.setResmsg(ResponseCode.RESULT_BAD.toStrMsg());
|
|
|
+
|
|
|
+ //查询
|
|
|
+ PageResponse<PipeBurstDeviceStatus> pageResponse = deviceStatusService.findAll(PageRequest.of(offset, limit));
|
|
|
+ resResult.setRescode(ResponseCode.RESULT_NORMAL.toStrCode());
|
|
|
+ resResult.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg());
|
|
|
+ String pageStr = null;
|
|
|
+ try {
|
|
|
+ if (pageResponse != null) pageStr = objectMapper.writeValueAsString(pageResponse);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
|
|
|
+ , String.format("Json序列化异常: error:%s", e));
|
|
|
+ }
|
|
|
+ resResult.setResdata(pageStr);
|
|
|
+
|
|
|
+ //end
|
|
|
+ resResult.setTimestamp(System.currentTimeMillis());
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, strUserId
|
|
|
+ , String.format("%s:%s seq:{%s} rescode:{%s} resmsg:{%s} time:{%d ms} end<===="
|
|
|
+ , strPlatform
|
|
|
+ , URI_PATH
|
|
|
+ , strRunSeq
|
|
|
+ , resResult.getRescode()
|
|
|
+ , resResult.getResmsg()
|
|
|
+ , resResult.getTimestamp() - llReqBefore));
|
|
|
+ return resResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 预警信息列表
|
|
|
+ *
|
|
|
+ * @param request request
|
|
|
+ * @param strClientType 客户端类型
|
|
|
+ * @param strUserAgent 用户信息
|
|
|
+ * @return 预警信息列表
|
|
|
+ * @throws SelfException selfException
|
|
|
+ */
|
|
|
+ @PostMapping(value = ApiURI.URI_XXX_WARING_INFO_LIST)
|
|
|
+ public ResponseRes<String> waringInfoList(HttpServletRequest request
|
|
|
+ , @RequestHeader(value = ApiURI.HEADER_CLIENT_TYPE, required = false) String strClientType
|
|
|
+ , @RequestHeader(value = ApiURI.HEADER_USER_AGENT, required = false) String strUserAgent
|
|
|
+ , @RequestBody(required = false) @Validated(value = {CommonParamValidSK.class}) PipeBustWarningInfoListParams oJsonParam
|
|
|
+ , BindingResult bindRes) throws Exception {
|
|
|
+ //入参校验
|
|
|
+ final String URI_PATH = request.getRequestURI();
|
|
|
+ final String strPlatform = CommTool.getPlatformByAgent(strClientType, strUserAgent);
|
|
|
+ final String strUserId = (String) request.getAttribute(TokenAuthenticationService.HEADER_USERID);
|
|
|
+ if (oJsonParam == null | bindRes.hasErrors() || !oJsonParam.checkValid()) {
|
|
|
+ throw new SelfException(ResponseCode.STATUS_ERROR_JSON_FORMAT.toStrCode()
|
|
|
+ , String.format(ApiURI.EXCEPTION_FORMAT
|
|
|
+ , strPlatform
|
|
|
+ , URI_PATH
|
|
|
+ , ResponseCode.STATUS_ERROR_JSON_FORMAT.toStrMsg()));
|
|
|
+ }
|
|
|
+
|
|
|
+ //begin
|
|
|
+ long llReqBefore = System.currentTimeMillis();
|
|
|
+ String strRunSeq = String.format("%d-%d", llReqBefore, mSeqDeviceStatusListReq.incrementAndGet());
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, strUserId
|
|
|
+ , String.format("%s:%s seq:{%s} begin====>"
|
|
|
+ , strPlatform
|
|
|
+ , URI_PATH
|
|
|
+ , strRunSeq));
|
|
|
+
|
|
|
+
|
|
|
+ //构建result
|
|
|
+ ResponseRes<String> resResult = new ResponseRes<>();
|
|
|
+ resResult.setRescode(ResponseCode.RESULT_BAD.toStrCode());
|
|
|
+ resResult.setResmsg(ResponseCode.RESULT_BAD.toStrMsg());
|
|
|
+
|
|
|
+ //查询
|
|
|
+ PageResponse<PipeBurstWaringInfo> pageResponse = waringInfoService.findAll(oJsonParam);
|
|
|
+ resResult.setRescode(ResponseCode.RESULT_NORMAL.toStrCode());
|
|
|
+ resResult.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg());
|
|
|
+ String pageStr = null;
|
|
|
+ try {
|
|
|
+ if (pageResponse != null) pageStr = objectMapper.writeValueAsString(pageResponse);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
|
|
|
+ , String.format("Json序列化异常: error:%s", e));
|
|
|
+ }
|
|
|
+ resResult.setResdata(pageStr);
|
|
|
+
|
|
|
+ //end
|
|
|
+ resResult.setTimestamp(System.currentTimeMillis());
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, strUserId
|
|
|
+ , String.format("%s:%s seq:{%s} rescode:{%s} resmsg:{%s} time:{%d ms} end<===="
|
|
|
+ , strPlatform
|
|
|
+ , URI_PATH
|
|
|
+ , strRunSeq
|
|
|
+ , resResult.getRescode()
|
|
|
+ , resResult.getResmsg()
|
|
|
+ , resResult.getTimestamp() - llReqBefore));
|
|
|
+ return resResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 预警信息清除
|
|
|
+ *
|
|
|
+ * @param request request
|
|
|
+ * @param strClientType 客户端类型
|
|
|
+ * @param strUserAgent 用户信息
|
|
|
+ * @param warnId 预警id
|
|
|
+ * @return 清除状态
|
|
|
+ * @throws SelfException selfException
|
|
|
+ */
|
|
|
+ @GetMapping(value = ApiURI.URI_XXX_WARING_INFO_REMOVE)
|
|
|
+ public ResponseRes<String> waringInfoRemove(HttpServletRequest request
|
|
|
+ , @RequestHeader(value = ApiURI.HEADER_CLIENT_TYPE, required = false) String strClientType
|
|
|
+ , @RequestHeader(value = ApiURI.HEADER_USER_AGENT, required = false) String strUserAgent
|
|
|
+ , @RequestParam(value = "warnId", required = false) String warnId) throws Exception {
|
|
|
+ //入参校验
|
|
|
+ final String URI_PATH = request.getRequestURI();
|
|
|
+ final String strPlatform = CommTool.getPlatformByAgent(strClientType, strUserAgent);
|
|
|
+ final String strUserId = (String) request.getAttribute(TokenAuthenticationService.HEADER_USERID);
|
|
|
+ if (StringUtils.isAnyBlank(warnId) || StringUtils.length(warnId) > 64) {
|
|
|
+ throw new SelfException(ResponseCode.STATUS_ERROR_PARAM_FORMAT.toStrCode()
|
|
|
+ , String.format(ApiURI.EXCEPTION_FORMAT
|
|
|
+ , strPlatform
|
|
|
+ , URI_PATH
|
|
|
+ , ResponseCode.STATUS_ERROR_PARAM_FORMAT.toStrMsg()));
|
|
|
+ }
|
|
|
+
|
|
|
+ //begin
|
|
|
+ long llReqBefore = System.currentTimeMillis();
|
|
|
+ String strRunSeq = String.format("%d-%d", llReqBefore, mSeqDeviceStatusListReq.incrementAndGet());
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, strUserId
|
|
|
+ , String.format("%s:%s seq:{%s} param:%s begin====>"
|
|
|
+ , strPlatform
|
|
|
+ , URI_PATH
|
|
|
+ , strRunSeq
|
|
|
+ , warnId));
|
|
|
+
|
|
|
+
|
|
|
+ //构建result
|
|
|
+ ResponseRes<String> resResult = new ResponseRes<>();
|
|
|
+ resResult.setRescode(ResponseCode.RESULT_BAD.toStrCode());
|
|
|
+ resResult.setResmsg(ResponseCode.RESULT_BAD.toStrMsg());
|
|
|
+
|
|
|
+ //查询
|
|
|
+ Boolean removed = waringInfoService.remove(warnId);
|
|
|
+ if (removed != null && removed) {
|
|
|
+ resResult.setRescode(ResponseCode.RESULT_NORMAL.toStrCode());
|
|
|
+ resResult.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg());
|
|
|
+ String pageStr = null;
|
|
|
+ try {
|
|
|
+ pageStr = objectMapper.writeValueAsString(true);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, mBizType, mStrClassName
|
|
|
+ , String.format("Json序列化异常: error:%s", e));
|
|
|
+ }
|
|
|
+ resResult.setResdata(pageStr);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //end
|
|
|
+ resResult.setTimestamp(System.currentTimeMillis());
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, mBizType, mStrClassName, strUserId
|
|
|
+ , String.format("%s:%s seq:{%s} rescode:{%s} resmsg:{%s} time:{%d ms} end<===="
|
|
|
+ , strPlatform
|
|
|
+ , URI_PATH
|
|
|
+ , strRunSeq
|
|
|
+ , resResult.getRescode()
|
|
|
+ , resResult.getResmsg()
|
|
|
+ , resResult.getTimestamp() - llReqBefore));
|
|
|
+ return resResult;
|
|
|
+ }
|
|
|
+}
|