From b6576a4db959d2551e343a8bb0045aa67387aacc Mon Sep 17 00:00:00 2001 From: lyfO_o <764716047@qq.com> Date: 星期一, 28 二月 2022 13:12:44 +0800 Subject: [PATCH] 库房状态管理 --- src/main/java/com/nanometer/smartlab/service/InterfaceServiceImpl.java | 217 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 193 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/nanometer/smartlab/service/InterfaceServiceImpl.java b/src/main/java/com/nanometer/smartlab/service/InterfaceServiceImpl.java index 5c4d719..faa782d 100644 --- a/src/main/java/com/nanometer/smartlab/service/InterfaceServiceImpl.java +++ b/src/main/java/com/nanometer/smartlab/service/InterfaceServiceImpl.java @@ -22,6 +22,7 @@ import org.apache.http.util.EntityUtils; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @@ -33,15 +34,19 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; +import java.util.stream.Collectors; @Service("interfaceService") public class InterfaceServiceImpl implements InterfaceService { private static Logger logger = Logger.getLogger(ApiAction.class); - + @Lazy @Resource private OpeUseFlowService opeUseFlowService; - + @Resource + private SysWarningService sysWarningService; + @Resource(name = "sysWarningDao") + SysWarningDao sysWarningDao; @Resource(name = "sysWarehouseDao") SysWarehouseDao sysWarehouseDao; @@ -77,6 +82,8 @@ @Resource SysLaboratoryContainerService sysLaboratoryContainer; + @Resource + SysLaboratoryService sysLaboratoryService; @Value("${message.url}") String url; @@ -1004,7 +1011,7 @@ }else{ sysUser = sysUserDao.getSysUser(userID); // 如果是管理员也可以开柜 - if(sysUser.getSeeFlag() == SeeFlag.MANAGE){ + if(sysUser.getSeeFlag() == SeeFlag.MANAGE||sysUser.getSeeFlag() == SeeFlag.LEADING){ return "1"; } else { // 不可以打开柜子 @@ -1030,8 +1037,16 @@ if (containerCode==null||containerCode.isEmpty()) { throw new ApiException(ApiStatus.PARAM_NO_EXIST, ApiStatus.PARAM_NO_EXIST.getRetMsg() + "[containerCode]"); } - - return sysUserDao.getUserListByContainerCodeNew(containerCode, startTime, endTime); + List<String> projects = sysLaboratoryContainer.selectProjectsByContainerCode(containerCode); + List<SysUser> userList = null; + if (projects != null && projects.size() > 0){ + userList = new ArrayList<>(); + for (String project : projects) { + List<SysUser> dataList = sysUserDao.getUserListByProject(project, startTime, endTime); + userList.addAll(dataList); + } + } + return userList; } @@ -1241,7 +1256,8 @@ logger.error("The containerCode has not been exists!"); continue; } - } else if (status.equals(2)){ + } + else if (status.equals(2)){ /*SysWarehouseContainer container = sysWarehouseContainerDao .getSysWarehouseContainerByContainerCode(containerCode); if (Objects.isNull(container) == false) { @@ -1261,11 +1277,18 @@ logger.error("The containerCode has not been exists!"); } } - opeReagentStatusDao.syncOpeReagentStatus(params); - + //-1 状态 + if (status.equals(-1)){ + continue; + } + int i = opeReagentStatusDao.syncOpeReagentStatus(params); + if (i < 1){ + opeReagentStatusDao.syncOpeReagentStatus(params); + } } } + //货柜预警接口 @Override @Transactional(propagation = Propagation.REQUIRED) public void alarm(JSONObject jsonObject) throws ApiException { @@ -1293,7 +1316,7 @@ String containerCode = dataJson.getString("containerCode"); //check containerCode是否存在 - SysLaboratoryContainer sysLaboratoryContainer = sysLaboratoryContainerDao + SysLaboratoryContainer LaboratoryContainer = sysLaboratoryContainerDao .getSysLaboratoryContainerByContainerCode(containerCode); if (Objects.isNull(sysLaboratoryContainer) == true) { SysWarehouseContainer container = sysWarehouseContainerDao @@ -1330,8 +1353,81 @@ } catch (ParseException e) { throw new ApiException(ApiStatus.PARAM_ERR); } - + //判断是否重复 + if (sysAlarmDao.selectOne(containerCode, controllerCode, sysAlarm.getWarningId(), sysAlarm.getWarningTime()) > 0) { + continue; + } sysAlarmDao.insertSysAlarm(sysAlarm); + try { + if (enable && "01".equals(warningId)) { + SysLaboratory sysLaboratory = sysLaboratoryService.getSysLaboratory(LaboratoryContainer.getLaboratoryId()); + String project = sysLaboratory.getProject(); + //2.根据Lab的课题组判断人员 + List<Map> personsInCharge = null; + if (StringUtils.isBlank(project)) { + //没有课题组就是实验室部门下的负责人 + personsInCharge = sysLaboratoryContainer.getContainerPersonInCharge(containerCode); + } else { + //有课题组就是 所有课题组下的人员负责人 + personsInCharge = sysLaboratoryService.getPersonInChargeByProjects(project); + } + + Map param = new HashMap(); + param.put("groupId", "securityManager"); + List<BaseMeta> managers = baseMetaDao.getBaseMetaList(param); + StringBuffer phones = new StringBuffer(); + + //实验室负责人手机号 + if (personsInCharge != null && personsInCharge.size() > 0) { + personsInCharge.forEach(person -> { + Object phone = person.get("phone"); + if (phone != null && !"".equals(phone)) { + phones.append(phone); + phones.append(","); + } + + }); + } + //所及负责人手机号 + if (managers != null && managers.size() > 0) { + managers.forEach(manager -> { + String phone = manager.getMetaValue(); + if (phone != null && !"".equals(phone)) { + phones.append(phone); + phones.append(","); + } + }); + } + if (phones.length() > 0) { + phones.deleteCharAt(phones.length() - 1); + + } + + Map location = sysLaboratoryContainer.selectLocationByContainerCode(containerCode); + String messageFormat = "名称:%s,具体地点:%s,柜号:%s,"; + String content = String.format(messageFormat, location.get("name"),location.get("location"), containerCode); + + String suffix = String.format("?head=%s&signature=%s&content=%s&telnumber=%s", head, signature, content + baseMetaList.get(0).getMetaValue(), phones.toString().replace(" ", "")); + CloseableHttpClient client = HttpClients.createDefault(); + HttpPost post = new HttpPost(url + suffix); + 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); + } + logger.info(resData); + } + } catch (Exception e) { + e.printStackTrace(); + logger.warn(e); + } + //增加发送短信接口 key:01 value:主电掉电,备电工作 + + + // // Integer warningPoint = dataJson.getInteger("warningPoint"); // if(warningPoint == null){ @@ -1347,7 +1443,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 +1502,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){ //获取实验室条码和具体地点 @@ -1429,7 +1532,7 @@ } //给daping系统发送信息 - if(!"".equals(alarmUrl) && ("1".equals(warningId) || "2".equals(warningId)|| "6".equals(warningId)) ) { + if(!"".equals(alarmUrl) && ("1".equals(warningId) || "2".equals(warningId))){ JSONObject json = new JSONObject(); json.put("barCode", location.get("barCode")); json.put("type", alarmType); @@ -1462,7 +1565,20 @@ } if(enable && "2".equals(warningId) ) { - List<Map> personsInCharge = sysLaboratoryContainer.getContainerPersonInCharge(containerCode); + //1.根据containerCode获取lab + SysLaboratoryContainer container = sysLaboratoryContainer.getSysLaboratoryContainerByContainerCode(containerCode); + SysLaboratory sysLaboratory = sysLaboratoryService.getSysLaboratory(container.getLaboratoryId()); + String project = sysLaboratory.getProject(); + //2.根据Lab的课题组判断人员 + List<Map> personsInCharge = null; + if (StringUtils.isBlank(project)) { + //没有课题组就是实验室部门下的负责人 + personsInCharge = sysLaboratoryContainer.getContainerPersonInCharge(containerCode); + } else { + //有课题组就是 所有课题组下的人员负责人 + personsInCharge = sysLaboratoryService.getPersonInChargeByProjects(project); + } + Map param = new HashMap(); param.put("groupId", "securityManager"); List<BaseMeta> managers = baseMetaDao.getBaseMetaList(param); @@ -1510,15 +1626,16 @@ } sysAlarmPersonDao.insertSysAlarmPerson(sysAlarmPerson); + // 将人员扣分更新到人员表 + if (warningPoint == null) { + warningPoint = 0; + } + // SysUser user = sysUserDao.getSysUser(userId); + if (user != null) { + sysUserDao.updateUserPointBySelective(user.getPoint() - warningPoint, user.getId()); + } } - // 将人员扣分更新到人员表 - if (warningPoint == null) { - warningPoint = 0; - } -// SysUser user = sysUserDao.getSysUser(userId); - if (user != null) { - sysUserDao.updateUserPointBySelective(user.getPoint() - warningPoint, user.getId()); - } + } } @@ -1690,8 +1807,11 @@ continue; } } + int count = opeUseFlowService.getOpeUseFlow(opeUseFlow); + if (count < 1) { - this.opeUseFlowService.insertOpeUseFlow(opeUseFlow); + this.opeUseFlowService.insertOpeUseFlow(opeUseFlow); + } } } @@ -1709,4 +1829,53 @@ public JSONObject getUserInfo(JSONObject jsonObject) { return null; } + + // 人员违规预警接口 + @Override + public void delalarmperson(JSONObject jsonObject) throws Exception { + JSONArray dataArr = jsonObject.getJSONArray("data"); + Iterator<Object> dataIt = dataArr.iterator(); + while (dataIt.hasNext()) { + JSONObject dataJson = JSONObject.parseObject(dataIt.next().toString()); + // 货柜条码 containerCode String ○ + // 报警类别 warningId Integer ○ + if (!dataJson.containsKey("warningId") || !dataJson.containsKey("containerCode")) { + throw new ApiException(ApiStatus.PARAM_NO_EXIST); + } + String containerCode = dataJson.getString("containerCode"); + String warningId = dataJson.getString("warningId"); + List<String> warningList = Arrays.asList(warningId.split(",")); + List<String> warningList1 = new ArrayList<>(Arrays.asList("1","2","3","4","5","6")); + List<String> delWarnings = warningList1.stream().filter(o->!warningList.contains(o)).collect(Collectors.toList());//新的不在原有里面的 + + for (String warning : delWarnings){ + Map<String, String> metaMap = new HashMap<>(); + metaMap.put("groupId", "user_violate_type"); + metaMap.put("metaKey", warning); + + List<BaseMeta> baseMetaList = baseMetaDao.getBaseMetaList(metaMap); + if (baseMetaList == null || baseMetaList.size() != 1) { + throw new ApiException(ApiStatus.PARAM_ERR, ApiStatus.PARAM_ERR.getRetMsg() + "[warningId]"); + } + SysAlarmPerson sysAlarmPerson = new SysAlarmPerson(); + sysAlarmPerson.setContainerCode(containerCode); + sysAlarmPerson.setWarningId(baseMetaList.get(0).getId()); + List<SysAlarmPerson> sysAlarmPersonList = sysAlarmPersonDao.selectByCode(containerCode, baseMetaList.get(0).getId()); + for (SysAlarmPerson sysAlarm : sysAlarmPersonList) { + if (!"".equals(alarmUrl) && StringUtils.isNotBlank(sysAlarm.getRefId()) && ("1".equals(warning) || "2".equals(warning))) { + SysWarning sysWarning = new SysWarning(); + sysWarning.setId(String.valueOf(sysAlarm.getId())); + sysWarning.setStatus(1); + sysWarning.setAlarmId(sysAlarm.getRefId()); + sysWarningService.updateSysWarning(sysWarning); + }else { + Map<String,Object> params = new HashMap<>(); + params.put("status",1); + params.put("id", String.valueOf(sysAlarm.getId())); + sysWarningDao.updateSysWarning(params); + } + } + } + } + } } -- Gitblit v1.9.2