From b06e4004a2ff3c4562da8b6d44decffa643b686b Mon Sep 17 00:00:00 2001 From: gdg <764716047@qq.com> Date: 星期二, 29 十二月 2020 09:44:24 +0800 Subject: [PATCH] 问题:人员预警时间 修改:超过现在时间 不做操作 --- src/main/java/com/nanometer/smartlab/service/InterfaceServiceImpl.java | 24 ++++++++++++++++++------ 1 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/nanometer/smartlab/service/InterfaceServiceImpl.java b/src/main/java/com/nanometer/smartlab/service/InterfaceServiceImpl.java index 34928bf..1e79b44 100644 --- a/src/main/java/com/nanometer/smartlab/service/InterfaceServiceImpl.java +++ b/src/main/java/com/nanometer/smartlab/service/InterfaceServiceImpl.java @@ -1347,7 +1347,7 @@ // 人员违规预警接口 @Override - public void alarmperson(JSONObject jsonObject) throws ApiException, IOException { + public void alarmperson(JSONObject jsonObject) throws Exception { JSONArray dataArr = jsonObject.getJSONArray("data"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @@ -1406,12 +1406,19 @@ Timestamp warnTime; try { Date warningTime = sdf.parse(warningTimeStr); + //不接收时间超过现在的数据 + if (warningTime.after(new Date())) { + throw new Exception("柜子时间发生错误"); + } warnTime = new Timestamp(warningTime.getTime()); sysAlarmPerson.setWarningTime(warnTime); } catch (ParseException e) { throw new ApiException(ApiStatus.PARAM_ERR); - } - // 将人员违规预警记录保存到数据库表 + } catch (Exception e) { + e.printStackTrace(); + throw new Exception(e.getMessage()); + } + // 将人员违规预警记录保存到数据库表 int count = sysAlarmPersonDao.repeatedJudgment(containerCode, warningLevelInt, warnTime); if (count<1){ //获取实验室条码和具体地点 @@ -1490,9 +1497,8 @@ }); } if (phones.length() >0){ - phones.deleteCharAt(phones.length() - 1); - String memo = String.format("短信已发送[%s]", phones); - sysAlarmPerson.setMemo(memo); + phones.deleteCharAt(phones.length() - 1); + } String suffix = String.format("?head=%s&signature=%s&content=%s&telnumber=%s", head, signature, content, phones.toString().replace(" ", "")); @@ -1501,6 +1507,12 @@ post.setHeader("Content-Type", "application/json;charset=UTF-8"); CloseableHttpResponse response = client.execute(post); String resData = EntityUtils.toString(response.getEntity(),"UTF-8"); + client.close(); + JSONObject res = JSONObject.parseObject(resData); + if ("200".equals(res.getString("code")) && phones.length() >0){ + String memo = String.format("短信已发送[%s]", phones); + sysAlarmPerson.setMemo(memo); + } logger.info(resData); } -- Gitblit v1.9.2