| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.doumee.biz.system.SystemDictDataBiz; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.dingTalk.DingTalk; |
| | | import com.doumee.core.dingTalk.DingTalkStream; |
| | |
| | | import com.doumee.core.haikang.model.HKConstants; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.DateUtil; |
| | | import com.doumee.core.utils.HttpsUtil; |
| | | import com.doumee.dao.business.*; |
| | | import com.doumee.dao.business.dao.MemberMapper; |
| | | import com.doumee.dao.business.dto.*; |
| | |
| | | import com.doumee.service.business.third.model.PageWrap; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import com.hikvision.artemis.sdk.config.ArtemisConfig; |
| | | import io.swagger.models.auth.In; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | private JkCabinetLogMapper jkCabinetLogMapper; |
| | | |
| | | @Autowired |
| | | private WarningMapper warningMapper; |
| | | private WarningEventMapper warningEventMapper; |
| | | |
| | | @Autowired |
| | | private MemberMapper memberMapper; |
| | | |
| | | @Autowired |
| | | private WarningMapper warningMapper; |
| | | @Autowired |
| | | private WarningRuleMapper warningRuleMapper; |
| | | |
| | | @Autowired |
| | | private WarningRuleDetailMapper warningRuleDetailMapper; |
| | | |
| | | @Autowired |
| | | private WarningPushMapper warningPushMapper; |
| | | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | |
| | | @Autowired |
| | | private DingTalk dingTalk; |
| | | |
| | | @Autowired |
| | | private CarUseBookMapper carUseBookMapper; |
| | | |
| | | @Override |
| | | public Integer create(JkCabinetGrid jkCabinetGrid) { |
| | |
| | | MPJLambdaWrapper<JkCabinetGrid> wrapper = new MPJLambdaWrapper<JkCabinetGrid>() |
| | | .selectAll(JkCabinetGrid.class) |
| | | .selectAs(JkCabinet::getName,JkCabinetGrid::getCabinetName) |
| | | .selectAs(JkKeys::getCode,JkCabinetGrid::getKeyCode) |
| | | .selectAs(JkKeys::getRfidLable,JkCabinetGrid::getKeyCode) |
| | | .leftJoin(JkCabinet.class,JkCabinet::getId,JkCabinetGrid::getCabinetId) |
| | | .leftJoin(JkKeys.class,JkKeys::getId,JkCabinetGrid::getKeyId) |
| | | .eq(JkCabinetGrid::getIsdeleted,Constants.ZERO) |
| | |
| | | } |
| | | List<JkCabinetGrid> jkCabinetGridList = jkCabinetGridMapper.selectJoinList(JkCabinetGrid.class, |
| | | new MPJLambdaWrapper<JkCabinetGrid>().selectAll(JkCabinetGrid.class) |
| | | .selectAs(JkKeys::getCode,JkCabinetGrid::getKeyCode) |
| | | .selectAs(JkKeys::getRfidLable,JkCabinetGrid::getKeyCode) |
| | | .selectAs(JkKeys::getCarCode,JkCabinetGrid::getCarCode) |
| | | .selectAs(JkKeys::getCarId,JkCabinetGrid::getCarId) |
| | | .leftJoin(JkKeys.class,JkKeys::getId,JkCabinetGrid::getKeyId) |
| | |
| | | jkCabinetLog.setAuthType(Constants.TWO); |
| | | jkCabinetLog.setMemberId(loginUserInfo.getMemberId()); |
| | | jkCabinetLog.setStatus(Constants.ZERO); |
| | | jkCabinetLog.setIsNotice(Constants.ZERO); |
| | | jkCabinetLog.setInfo(Objects.isNull(dto.getOpenType())||Constants.equalsInteger(dto.getOpenType(),Constants.ZERO)?"系统开启":"手动开启"); |
| | | if(Objects.nonNull(jkCabinetGrid.getKeyId())){ |
| | | jkCabinetLog.setKeyId(jkCabinetGrid.getKeyId()); |
| | | JkKeys jkKeys = jkKeysMapper.selectById(jkCabinetGrid.getKeyId()); |
| | |
| | | jkCabinetLog.setType(Constants.ZERO); |
| | | jkCabinetLogs.add(jkCabinetLog); |
| | | } |
| | | |
| | | jkCabinetLogMapper.insert(jkCabinetLogs); |
| | | } |
| | | } |
| | |
| | | .set(JkKeys::getStatus,dto.getKeyStatus()) |
| | | .eq(JkKeys::getId,jkKeys.getId()) |
| | | ); |
| | | //归还钥匙/借出钥匙 都要去查询最后一次开门记录 获取具体的开门的方式 是随车/派车/保洁 赋予当前关门记录内 如果是派车单数据 需要调起简道云推送 |
| | | JkCabinetLog lastOutLog = jkCabinetLogMapper.selectOne(new QueryWrapper<JkCabinetLog>().lambda() |
| | | .eq(JkCabinetLog::getKeyId,jkCabinetLog.getKeyId()) |
| | | .eq(JkCabinetLog::getType,Constants.ZERO) |
| | | .last( "limit 1 ")); |
| | | if(Objects.nonNull(lastOutLog)){ |
| | | if(Objects.nonNull(lastOutLog.getCarUseBookId())) { |
| | | CarUseBook carUseBook = carUseBookMapper.selectById(lastOutLog.getCarUseBookId()); |
| | | if (Objects.nonNull(carUseBook) && Constants.equalsInteger(carUseBook.getKeyStatus(), Constants.ZERO)) { |
| | | carUseBookMapper.update(new UpdateWrapper<CarUseBook>().lambda() |
| | | .set(CarUseBook::getKeyStatus, Constants.ONE) |
| | | .eq(CarUseBook::getId, carUseBook.getId()) |
| | | ); |
| | | //推送简道云 标记业务数据已被领取钥匙 |
| | | if (StringUtils.isNotBlank(carUseBook.getJdyId())) { |
| | | JDYKeyUseByBookDTO jdyKeyUseByBookDTO = new JDYKeyUseByBookDTO(); |
| | | jdyKeyUseByBookDTO.setCreate_date(System.currentTimeMillis()); |
| | | jdyKeyUseByBookDTO.setStart_date(Constants.equalsInteger(dto.getKeyStatus(),Constants.TWO)?System.currentTimeMillis():null); |
| | | jdyKeyUseByBookDTO.setEnd_date(Constants.equalsInteger(dto.getKeyStatus(),Constants.ONE)?System.currentTimeMillis():null); |
| | | jdyKeyUseByBookDTO.setType(Constants.equalsInteger(dto.getKeyStatus(),Constants.TWO)?Constants.ZERO:Constants.ONE); |
| | | jdyKeyUseByBookDTO.setId(carUseBook.getJdyId()); |
| | | this.pushJDYKeyInfo(jdyKeyUseByBookDTO); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | jkCabinetLog.setIsNotice(Constants.ZERO); |
| | | jkCabinetLog.setType(Constants.ONE); |
| | | jkCabinetLogMapper.insert(jkCabinetLog); |
| | | |
| | | //查询钥匙的开门记录 进行添加关门记录主键 |
| | | jkCabinetLogMapper.update(null,new UpdateWrapper<JkCabinetLog>().lambda() |
| | | .set(JkCabinetLog::getCloseLogId,jkCabinetLog.getId()) |
| | | .eq(JkCabinetLog::getKeyId,jkCabinetLog.getKeyId()) |
| | | .eq(JkCabinetLog::getType,Constants.ZERO) |
| | | .isNull(JkCabinetLog::getCloseLogId)); |
| | | if(Constants.equalsInteger(dto.getKeyStatus(),Constants.ONE)){ |
| | | jkCabinetLogMapper.update(null,new UpdateWrapper<JkCabinetLog>().lambda() |
| | | .set(JkCabinetLog::getCloseLogId,jkCabinetLog.getId()) |
| | | .eq(JkCabinetLog::getKeyId,jkCabinetLog.getKeyId()) |
| | | .eq(JkCabinetLog::getType,Constants.ONE) |
| | | .eq(JkCabinetLog::getKeyStatus,Constants.TWO) |
| | | .isNull(JkCabinetLog::getCloseLogId)); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | // public void saveAbnormalOpenGridLog(AbnormalOpenGridDTO dto){ |
| | | // if(Objects.isNull(dto) |
| | | // || StringUtils.isBlank(dto.getBoardCode()) |
| | | // || StringUtils.isBlank(dto.getBoardCode()) |
| | | // || Objects.isNull(dto.getCabinetId()) |
| | | // || Objects.isNull(dto.getKeyStatus()) |
| | | // || Objects.isNull(dto.getAuthType()) |
| | | // ){ |
| | | // throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | // } |
| | | // JkCabinetGrid jkCabinetGrid = jkCabinetGridMapper.selectOne(new QueryWrapper<JkCabinetGrid>().lambda().eq(JkCabinetGrid::getIsdeleted,Constants.ZERO) |
| | | // .eq(JkCabinetGrid::getCabinetId,dto.getCabinetId()) |
| | | // .eq(JkCabinetGrid::getId,dto.getGridId()) |
| | | // .last(" limit 1 ") |
| | | // ); |
| | | // JkCabinetLog jkCabinetLog = new JkCabinetLog(); |
| | | // jkCabinetLog.setCreateDate(new Date()); |
| | | // jkCabinetLog.setIsdeleted(Constants.ZERO); |
| | | // jkCabinetLog.setCabinetId(dto.getCabinetId()); |
| | | // jkCabinetLog.setGridId(jkCabinetGrid.getId()); |
| | | // jkCabinetLog.setAuthType(dto.getAuthType()); |
| | | // jkCabinetLog.setMemberId(dto.getMemberId()); |
| | | // jkCabinetLog.setKeyStatus(Constants.ZERO); |
| | | // jkCabinetLog.setStatus(Constants.ZERO); |
| | | // |
| | | // } |
| | | |
| | | |
| | | /** |
| | |
| | | return jkCabinetGridList; |
| | | } |
| | | } |
| | | jkCabinetGridList = jkCabinetGridMapper.selectJoinList(JkCabinetGrid.class, |
| | | new MPJLambdaWrapper<JkCabinetGrid>().selectAll(JkCabinetGrid.class) |
| | | .selectAs(JkKeys::getCode,JkCabinetGrid::getKeyCode) |
| | | .selectAs(JkKeys::getCarCode,JkCabinetGrid::getCarCode) |
| | | .selectAs(JkKeys::getCarId,JkCabinetGrid::getCarId) |
| | | .selectAs(JkKeys::getStatus,JkCabinetGrid::getKeyStatus) |
| | | .leftJoin(JkKeys.class,JkKeys::getId,JkCabinetGrid::getKeyId) |
| | | .eq(JkCabinetGrid::getIsdeleted,Constants.ZERO) |
| | | .eq(JkCabinetGrid::getWorkingStatus,Constants.ZERO) |
| | | .eq(JkCabinetGrid::getCabinetId,dto.getCabinetId()) |
| | | .in(Constants.equalsInteger(dto.getType(),Constants.ONE),JkKeys::getStatus,Constants.TWO,Constants.THREE) |
| | | .in(Constants.equalsInteger(dto.getType(),Constants.ZERO),JkKeys::getStatus,Constants.ONE) |
| | | .isNotNull(JkCabinetGrid::getKeyId) |
| | | .apply(" t1.car_id in ( select c.id from cars c where c.ISDELETED = 0 and c.MEMBER_ID = "+dto.getMemberId()+" ) ") |
| | | .orderByAsc(JkCabinetGrid::getCode) |
| | | ); |
| | | |
| | | //如果是还钥匙 则直接查询已借出的钥匙的数据 |
| | | if(Constants.equalsInteger(dto.getType(),Constants.ONE)){ |
| | | jkCabinetGridList = jkCabinetGridMapper.selectJoinList(JkCabinetGrid.class, |
| | | new MPJLambdaWrapper<JkCabinetGrid>().selectAll(JkCabinetGrid.class) |
| | | .selectAs(JkKeys::getRfidLable,JkCabinetGrid::getKeyCode) |
| | | .selectAs(JkKeys::getCarCode,JkCabinetGrid::getCarCode) |
| | | .selectAs(JkKeys::getCarId,JkCabinetGrid::getCarId) |
| | | .selectAs(JkKeys::getStatus,JkCabinetGrid::getKeyStatus) |
| | | .innerJoin(JkKeys.class,JkKeys::getId,JkCabinetGrid::getKeyId) |
| | | .eq(JkCabinetGrid::getIsdeleted,Constants.ZERO) |
| | | .eq(JkCabinetGrid::getWorkingStatus,Constants.ZERO) |
| | | .eq(JkCabinetGrid::getStatus,Constants.ZERO) |
| | | .eq(JkCabinetGrid::getCabinetId,dto.getCabinetId()) |
| | | .in(JkKeys::getStatus,Constants.TWO,Constants.THREE) |
| | | .isNotNull(JkCabinetGrid::getKeyId) |
| | | .apply("t1.car_id in ( select c.id from cars c where c.ISDELETED = 0 and c.MEMBER_ID = "+dto.getMemberId()+" )") |
| | | |
| | | .orderByAsc(JkCabinetGrid::getCode) |
| | | ); |
| | | }else{ |
| | | //判断当前时间是否处于保洁时段内 |
| | | String cleanConfig = systemDictDataBiz.queryByCode(Constants.CABINET_CONFIG,Constants.CLEAN_TIME).getCode(); |
| | | String earlyConfig = systemDictDataBiz.queryByCode(Constants.CABINET_CONFIG,Constants.EARLY_CONFIG).getCode(); |
| | | Boolean isCleanTime = Constants.betweenTimeConfig(cleanConfig); |
| | | List<Integer> girdIdList = new ArrayList<>(); |
| | | //查询根据任务可以领取的数据 |
| | | jkCabinetGridList = jkCabinetGridMapper.selectJoinList(JkCabinetGrid.class, |
| | | new MPJLambdaWrapper<JkCabinetGrid>().selectAll(JkCabinetGrid.class) |
| | | .selectAs(JkKeys::getRfidLable,JkCabinetGrid::getKeyCode) |
| | | .selectAs(JkKeys::getCarCode,JkCabinetGrid::getCarCode) |
| | | .selectAs(JkKeys::getCarId,JkCabinetGrid::getCarId) |
| | | .selectAs(JkKeys::getStatus,JkCabinetGrid::getKeyStatus) |
| | | .selectAs(CarUseBook::getId,JkCabinetGrid::getCarUseBookId) |
| | | .select("1",JkCabinetGrid::getGetKeyWay) |
| | | .innerJoin(JkKeys.class,JkKeys::getId,JkCabinetGrid::getKeyId) |
| | | .innerJoin(CarUseBook.class,CarUseBook::getCarCode,JkKeys::getCarCode) |
| | | .innerJoin(Cars.class,Cars::getCode,CarUseBook::getCarCode) |
| | | .eq(JkCabinetGrid::getIsdeleted,Constants.ZERO) |
| | | .eq(CarUseBook::getIsdeleted,Constants.ZERO) |
| | | .eq(Cars::getIsdeleted,Constants.ZERO) |
| | | .eq(JkCabinetGrid::getWorkingStatus,Constants.ZERO) |
| | | .eq(JkCabinetGrid::getStatus,Constants.ZERO) |
| | | .eq(JkCabinetGrid::getCabinetId,dto.getCabinetId()) |
| | | .in(JkKeys::getStatus,Constants.ONE) |
| | | .eq(JkKeys::getRoleType,Constants.ONE) |
| | | .isNotNull(JkCabinetGrid::getKeyId) |
| | | .apply("and NOW() > DATE_SUB(t2.START_TIME, INTERVAL "+earlyConfig+" MINUTE) and now() < t2.end_time and t3.MEMBER_ID = "+dto.getMemberId()+" )") |
| | | |
| | | ); |
| | | if(CollectionUtils.isNotEmpty(jkCabinetGridList)){ |
| | | girdIdList = jkCabinetGridList.stream().map(i->i.getId()).collect(Collectors.toList()); |
| | | } |
| | | jkCabinetGridList.addAll(jkCabinetGridMapper.selectJoinList(JkCabinetGrid.class, |
| | | new MPJLambdaWrapper<JkCabinetGrid>().selectAll(JkCabinetGrid.class) |
| | | .selectAs(JkKeys::getRfidLable,JkCabinetGrid::getKeyCode) |
| | | .selectAs(JkKeys::getCarCode,JkCabinetGrid::getCarCode) |
| | | .selectAs(JkKeys::getCarId,JkCabinetGrid::getCarId) |
| | | .selectAs(JkKeys::getStatus,JkCabinetGrid::getKeyStatus) |
| | | .select(!isCleanTime?"0":"2",JkCabinetGrid::getGetKeyWay) |
| | | .innerJoin(JkKeys.class,JkKeys::getId,JkCabinetGrid::getKeyId) |
| | | .eq(JkCabinetGrid::getIsdeleted,Constants.ZERO) |
| | | .eq(JkCabinetGrid::getWorkingStatus,Constants.ZERO) |
| | | .eq(JkCabinetGrid::getStatus,Constants.ZERO) |
| | | .eq(JkCabinetGrid::getCabinetId,dto.getCabinetId()) |
| | | .eq(!isCleanTime,JkKeys::getRoleType,Constants.ZERO) |
| | | .in(JkKeys::getStatus,Constants.ONE) |
| | | .isNotNull(JkCabinetGrid::getKeyId) |
| | | .notIn(CollectionUtils.isNotEmpty(girdIdList),JkCabinetGrid::getId,jkCabinetGridList) |
| | | .apply("t1.car_id in ( select c.id from cars c where c.ISDELETED = 0 and c.MEMBER_ID = "+dto.getMemberId()+" ) ") |
| | | ) |
| | | ); |
| | | } |
| | | |
| | | for (JkCabinetGrid jkCabinetGrid:jkCabinetGridList) { |
| | | jkCabinetGrid.setBindStatus(Objects.isNull(jkCabinetGrid.getKeyId())?Constants.ZERO:Constants.ONE); |
| | | jkCabinetGrid.setKeyStatus(Objects.isNull(jkCabinetGrid.getKeyStatus())?Constants.ZERO:jkCabinetGrid.getKeyStatus()); |
| | |
| | | if(Objects.isNull(jkCabinetGrid)){ |
| | | return ; |
| | | } |
| | | // LoginUserInfo loginUserInfo = openGridDriverDTO.getLoginUserInfo(); |
| | | JkCabinetLog jkCabinetLog = new JkCabinetLog(); |
| | | jkCabinetLog.setCreateDate(new Date()); |
| | | // jkCabinetLog.setCreator(loginUserInfo.getId()); |
| | | jkCabinetLog.setIsdeleted(Constants.ZERO); |
| | | jkCabinetLog.setCabinetId(openGridDriverDTO.getCabinetId()); |
| | | jkCabinetLog.setGridId(jkCabinetGrid.getId()); |
| | | jkCabinetLog.setAuthType(openGridDriverDTO.getAuthType()); |
| | | jkCabinetLog.setMemberId(openGridDriverDTO.getMemberId()); |
| | | jkCabinetLog.setType(Constants.ZERO); |
| | | jkCabinetLog.setStatus(Constants.ZERO); |
| | | jkCabinetLog.setOpenWay(openGridDriverDTO.getOpenWay()); |
| | | jkCabinetLog.setCarUseBookId(openGridDriverDTO.getCarUseBookId()); |
| | | |
| | | jkCabinetLog.setInfo(Objects.isNull(openGridDriverDTO.getOpenType())||Constants.equalsInteger(openGridDriverDTO.getOpenType(),Constants.ZERO)?"系统开启":"手动开启"); |
| | | if(Objects.nonNull(jkCabinetGrid.getKeyId())){ |
| | | jkCabinetLog.setKeyId(jkCabinetGrid.getKeyId()); |
| | | JkKeys jkKeys = jkKeysMapper.selectById(jkCabinetGrid.getKeyId()); |
| | |
| | | jkCabinetLog.setRoleType(jkKeys.getRoleType()); |
| | | } |
| | | } |
| | | jkCabinetLog.setIsNotice(Constants.ZERO); |
| | | jkCabinetLogMapper.insert(jkCabinetLog); |
| | | |
| | | } |
| | | |
| | | |
| | | public void pushJDYKeyInfo(JDYKeyUseByBookDTO dto){ |
| | | String url = systemDictDataBiz.queryByCode(Constants.JDY_CONFIG,Constants.PUSH_URL_KEYS).getCode(); |
| | | // JSONObject object = new JSONObject(); |
| | | // object.put("create_date","20251104160000"); |
| | | // object.put("start_date",System.currentTimeMillis() ); |
| | | // object.put("end_date", System.currentTimeMillis() + 24*3600*1000); |
| | | // object.put("id","10000020251105");// |
| | | // object.put("type",1);//0=领用;1=归还 |
| | | log.error("【简道云】推送派车单数据领用与归还信息-请求入参:"+JSONObject.toJSONString(dto)); |
| | | String result = HttpsUtil.postJson(url,JSONObject.toJSONString(dto)); |
| | | log.error("【简道云】推送派车单数据领用与归还信息-请求结果:"+JSONObject.toJSONString(result)); |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | |
| | | .eq(JkCabinetGrid::getId,dto.getGridId()) |
| | | .last(" limit 1 ") |
| | | ); |
| | | |
| | | if(Objects.nonNull(jkCabinetGrid)){ |
| | | log.error("柜格开门超时未关闭告警信息:{}"+JSONObject.toJSONString(jkCabinetGrid)); |
| | | //规则类型 |
| | | Constants.WarningConfig warningConfig = Constants.WarningConfig.GRID_TIME_OUT_INFO; |
| | | Warning warning = warningMapper.selectOne(new QueryWrapper<Warning>().lambda() |
| | | .eq(Warning::getType,Constants.THREE).eq(Warning::getCode,Constants.WarningConfig.GRID_TIME_OUT_INFO.getKey()).eq(Warning::getIsdeleted,Constants.ZERO).last("limt 1")); |
| | | .eq(Warning::getIsdeleted,Constants.ZERO) |
| | | .eq(Warning::getStatus,Constants.ONE) |
| | | .eq(Warning::getCode,warningConfig.getKey()) |
| | | .last("limit 1") |
| | | ); |
| | | if(Objects.isNull(warning)){ |
| | | return; |
| | | } |
| | | List<Member> memberList = this.getWarningList(warning); |
| | | if(CollectionUtils.isEmpty(memberList)){ |
| | | List<Integer> ruleIdList = this.processWarnFront(warningConfig); |
| | | if(CollectionUtils.isEmpty(ruleIdList)){ |
| | | return; |
| | | } |
| | | //todo 存储异常日志 |
| | | for (Integer ruleId:ruleIdList) { |
| | | WarningRule warningRule = warningRuleMapper.selectById(ruleId); |
| | | if(Objects.isNull(warningRule)){ |
| | | continue; |
| | | } |
| | | List<Member> memberList = this.getWarningRuleMemberList(warningRule); |
| | | if(CollectionUtils.isEmpty(memberList)){ |
| | | return; |
| | | } |
| | | |
| | | String content = "【钥匙柜-"+jkCabinetGrid.getCabinetName()+"】下【柜格-"+jkCabinetGrid.getCode()+"】超时未关闭"; |
| | | |
| | | }else{ |
| | | JkCabinet jkCabinet = jkCabinetMapper.selectById(dto.getCabinetId()); |
| | | //存储报警异常记录 |
| | | WarningEvent warningEvent = new WarningEvent(); |
| | | warningEvent.setCreateDate(new Date()); |
| | | warningEvent.setWarningId(warning.getId()); |
| | | warningEvent.setTitle(warningConfig.getInfo()); |
| | | warningEvent.setContent(content ); |
| | | warningEvent.setStatus(Constants.ZERO); |
| | | warningEvent.setRegion(Objects.nonNull(jkCabinet)&&StringUtils.isNotBlank(jkCabinet.getLocation())?jkCabinet.getLocation():"未知位置"); |
| | | warningEventMapper.insert(warningEvent); |
| | | |
| | | } |
| | | } |
| | | } |
| | | try { |
| | | // 存储异常通知日志 |
| | | WarningPush warningPush = new WarningPush(); |
| | | warningPush.setCreateDate(new Date()); |
| | | warningPush.setIsdeleted(Constants.ZERO); |
| | | warningPush.setWarningId(warning.getId()); |
| | | warningPush.setTitle(warningConfig.getInfo()); |
| | | warningPush.setContent(content); |
| | | warningPush.setStatus(Constants.ZERO); |
| | | warningPush.setPushType(Constants.ZERO); |
| | | warningPush.setRegion(Objects.nonNull(jkCabinet)&&StringUtils.isNotBlank(jkCabinet.getLocation())?jkCabinet.getLocation():"未知位置"); |
| | | warningPush.setMemberIds( |
| | | StringUtils.join(memberList.stream().map(i->i.getId()).collect(Collectors.toList()),",") |
| | | ); |
| | | warningPush.setMemberIds( |
| | | StringUtils.join(memberList.stream().map(i->i.getId()).collect(Collectors.toList()),",") |
| | | ); |
| | | warningPush.setMemberNames(StringUtils.join(memberList.stream().map(i->i.getName()).collect(Collectors.toList()),",") |
| | | ); |
| | | //todo 暂时关闭 钉钉通知 |
| | | |
| | | // Boolean noticeFlag = dingTalk.workInfoOANotice(Long.valueOf(systemDictDataBiz.queryByCode(Constants.DD_TALK,Constants.AGENT_ID).getCode()), |
| | | // StringUtils.join(memberList.stream().filter(i->StringUtils.isNotBlank(i.getDdId())).map(i->i.getDdId()).collect(Collectors.toList()),","), |
| | | // dingTalk.getAlarmNoticeMsg(warningPush.getRegion(),DateUtil.getCurrDateTime(),content)); |
| | | // warningPush.setStatus(noticeFlag?Constants.ONE:Constants.TWO); |
| | | warningPushMapper.insert(warningPush); |
| | | warningEvent.setStatus(Constants.ONE); |
| | | warningEventMapper.updateById(warningEvent); |
| | | }catch (Exception e){ |
| | | warningEvent.setStatus(Constants.TWO); |
| | | warningEventMapper.updateById(warningEvent); |
| | | } |
| | | |
| | | public List<Member> getWarningList(Warning warning){ |
| | | if(Constants.equalsInteger(warning.getStatus(),Constants.ZERO)){ |
| | | return null; |
| | | } |
| | | //查询通知人员 |
| | | List<WarningRule> warningRuleList = warningRuleMapper.selectList(new QueryWrapper<WarningRule>().lambda() |
| | | .eq(WarningRule::getIsdeleted,Constants.ZERO) |
| | | .apply(" id in ( select w.RULE_ID from warning_rule_detail w where w.WARNING_ID = '"+warning.getId()+"' and w.ISDELETED = 0 ) ") |
| | | ); |
| | | List<Member> memberList = new ArrayList<>(); |
| | | if(org.apache.commons.collections.CollectionUtils.isNotEmpty(warningRuleList)){ |
| | | List<String> memberIdStr = warningRuleList.stream().map(i->i.getMemberIds()).collect(Collectors.toList()); |
| | | if(org.apache.commons.collections.CollectionUtils.isNotEmpty(memberIdStr)){ |
| | | List<String> memberIdList = new ArrayList<>(); |
| | | for (String s:memberIdStr) { |
| | | memberIdList.addAll( |
| | | Arrays.asList(s.split(",")) |
| | | ); |
| | | } |
| | | memberList = memberMapper.selectList(new QueryWrapper<Member>().lambda().eq(Member::getIsdeleted,Constants.ZERO) |
| | | .notIn(Member::getErpId) |
| | | .in(Member::getId,memberIdList) |
| | | ); |
| | | |
| | | } |
| | | } |
| | | return memberList; |
| | | } |
| | | |
| | | |
| | | public List<Integer> processWarnFront(Constants.WarningConfig warningConfig){ |
| | | List<WarningRuleDetail> warningRuleDetailList = warningRuleDetailMapper.selectJoinList(WarningRuleDetail.class,new MPJLambdaWrapper<WarningRuleDetail>() |
| | | .selectAll(WarningRuleDetail.class) |
| | | .leftJoin(Warning.class,Warning::getId,WarningRuleDetail::getWarningId) |
| | | .eq(WarningRuleDetail::getIsdeleted,Constants.ZERO) |
| | | .eq(Warning::getIsdeleted,Constants.ZERO) |
| | | .eq(Warning::getStatus,Constants.ONE) |
| | | .eq(Warning::getCode,warningConfig.getKey()) |
| | | ); |
| | | if(CollectionUtils.isEmpty(warningRuleDetailList)){ |
| | | return new ArrayList<>(); |
| | | } |
| | | //所有报警规则配置信息 |
| | | List<Integer> ruleIdList = warningRuleDetailList.stream().map(i->i.getRuleId()).collect(Collectors.toList());; |
| | | Set<Integer> ruleIdSet = new HashSet<>(ruleIdList); |
| | | if(CollectionUtils.isNotEmpty(ruleIdSet)){ |
| | | List<Integer> resultList = new ArrayList<>(); |
| | | for (Integer ruleId:ruleIdSet) { |
| | | WarningRule warningRule = warningRuleMapper.selectById(ruleId); |
| | | //查询其他规则信息 |
| | | List<WarningRuleDetail> warningRuleDetails = warningRuleDetailMapper.selectJoinList(WarningRuleDetail.class,new MPJLambdaWrapper<WarningRuleDetail>() |
| | | .selectAll(WarningRuleDetail.class) |
| | | .selectAs(Warning::getCode,WarningRuleDetail::getCode) |
| | | .leftJoin(Warning.class,Warning::getId,WarningRuleDetail::getWarningId) |
| | | .eq(WarningRuleDetail::getIsdeleted,Constants.ZERO) |
| | | .eq(Warning::getIsdeleted,Constants.ZERO) |
| | | .eq(Warning::getStatus,Constants.ONE) |
| | | .eq(WarningRuleDetail::getRuleId,ruleId) |
| | | .in(Warning::getCode,Constants.WarningConfig.ALARM_TEST.getKey(), |
| | | Constants.WarningConfig.GRID_TIME_OUT_INFO.getKey(), |
| | | Constants.WarningConfig.KEY_TIME_OUT_BACK.getKey() |
| | | ) |
| | | ); |
| | | //无任何规则 直接跳过 |
| | | if(CollectionUtils.isEmpty(warningRuleDetails)){ |
| | | return resultList; |
| | | }else if(!Constants.equalsInteger(warningRuleDetails.stream().filter(i->!i.getCode().equals(warningConfig.getKey())).collect(Collectors.toList()).size(),Constants.ZERO)){ |
| | | List<WarningRuleDetail> wList = warningRuleDetails.stream().filter(i->!i.getCode().equals(warningConfig.getKey())).collect(Collectors.toList()); |
| | | //获取所有其他所有事件主键信息 |
| | | List<Integer> warningIdList = wList.stream().map(i->i.getWarningId()).collect(Collectors.toList()); |
| | | Set<Integer> setWarningIdList = new HashSet<>(warningIdList); |
| | | //获取时间内所有事件信息 |
| | | List<WarningEvent> warningEventList = warningEventMapper.selectList(new QueryWrapper<WarningEvent>().lambda() |
| | | .eq(WarningEvent::getIsdeleted,Constants.ZERO) |
| | | .in(WarningEvent::getWarningId,setWarningIdList) |
| | | .apply(" DATE_ADD(CREATE_DATE , INTERVAL "+warningRule.getIntervalSec()+" SECOND) > now() ") |
| | | ); |
| | | if(this.processWarnFlag(wList,warningEventList)){ |
| | | resultList.add(ruleId); |
| | | }; |
| | | }else{ |
| | | List<WarningRuleDetail> wList = warningRuleDetails.stream().filter(i->i.getCode().equals(warningConfig.getKey())).collect(Collectors.toList()); |
| | | //获取本次事件主键信息 |
| | | List<Integer> warningIdList = wList.stream().map(i->i.getWarningId()).collect(Collectors.toList()); |
| | | Set<Integer> setWarningIdList = new HashSet<>(warningIdList); |
| | | //获取时间内所有事件信息 |
| | | List<WarningEvent> warningEventList = warningEventMapper.selectList(new QueryWrapper<WarningEvent>().lambda() |
| | | .eq(WarningEvent::getIsdeleted,Constants.ZERO) |
| | | .in(WarningEvent::getWarningId,setWarningIdList) |
| | | .apply(" DATE_ADD(CREATE_DATE , INTERVAL "+warningRule.getIntervalSec()+" SECOND) > now() ") |
| | | ); |
| | | if(this.processWarnFlag(wList,warningEventList)){ |
| | | resultList.add(ruleId); |
| | | } |
| | | } |
| | | } |
| | | return resultList; |
| | | } |
| | | return new ArrayList<>(); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 判断处理是否可以发送通知 当前告警配置的数据列表是否满足 |
| | | * @param warningRuleDetails |
| | | * @return |
| | | */ |
| | | public boolean processWarnFlag(List<WarningRuleDetail> warningRuleDetails,List<WarningEvent> warningEventList){ |
| | | if(CollectionUtils.isEmpty(warningEventList)){ |
| | | return false; |
| | | } |
| | | for (WarningRuleDetail warningRuleDetail:warningRuleDetails) { |
| | | if(Objects.nonNull(warningRuleDetail.getRegionId())){ |
| | | if(warningEventList.stream().filter(i->Constants.equalsInteger(i.getWarningId(),warningRuleDetail.getWarningId()) |
| | | && StringUtils.isNotBlank(i.getRegionId()) && i.getRegionId().equals(warningRuleDetail.getRegionId()) |
| | | ).collect(Collectors.toList()).size()<=Constants.ZERO){ |
| | | return false; |
| | | } |
| | | }else{ |
| | | if(warningEventList.stream().filter(i->Constants.equalsInteger(i.getWarningId(),warningRuleDetail.getWarningId()) |
| | | ).collect(Collectors.toList()).size()<=Constants.ZERO){ |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | |
| | | public List<Member> getWarningRuleMemberList(WarningRule warningRule){ |
| | | List<Member> memberList = memberMapper.selectList(new QueryWrapper<Member>().lambda().eq(Member::getIsdeleted,Constants.ZERO) |
| | | .isNotNull(Member::getErpId) |
| | | .in(Member::getId,Arrays.asList(warningRule.getMemberIds().split(","))) |
| | | ); |
| | | return memberList; |
| | | } |
| | | |
| | | |
| | | @Override |
| | |
| | | .last(" limit 1 ") |
| | | ); |
| | | |
| | | JkCabinet jkCabinet = jkCabinetMapper.selectById(dto.getCabinetId()); |
| | | Constants.WarningConfig warningConfig = Constants.WarningConfig.ALARM_TEST; |
| | | Warning warning = warningMapper.selectOne(new QueryWrapper<Warning>().lambda() |
| | | .eq(Warning::getType,Constants.THREE).eq(Warning::getCode,Constants.WarningConfig.KEY_TIME_OUT_BACK.getKey()).eq(Warning::getIsdeleted,Constants.ZERO).last("limt 1")); |
| | | .eq(Warning::getIsdeleted,Constants.ZERO) |
| | | .eq(Warning::getStatus,Constants.ONE) |
| | | .eq(Warning::getCode,warningConfig.getKey()) |
| | | .last("limit 1") |
| | | ); |
| | | if(Objects.isNull(warning)){ |
| | | return; |
| | | } |
| | | List<Member> memberList = this.getWarningList(warning); |
| | | if(CollectionUtils.isEmpty(memberList)){ |
| | | List<Integer> ruleIdList = this.processWarnFront(warningConfig); |
| | | if(CollectionUtils.isEmpty(ruleIdList)){ |
| | | return; |
| | | } |
| | | //todo 存储异常日志 |
| | | if(CollectionUtils.isEmpty(ruleIdList)){ |
| | | return; |
| | | } |
| | | for (Integer ruleId:ruleIdList) { |
| | | WarningRule warningRule = warningRuleMapper.selectById(ruleId); |
| | | if (Objects.isNull(warningRule)) { |
| | | continue; |
| | | } |
| | | List<Member> memberList = this.getWarningRuleMemberList(warningRule); |
| | | |
| | | //存储异常日志 |
| | | if(Objects.nonNull(systemUser)){ |
| | | log.error("司机酒精检测,超出酒精值告警信息:{}"+JSONObject.toJSONString(systemUser)); |
| | | String content = ""; |
| | | if(Objects.nonNull(systemUser.getRealname())){ |
| | | content = content + systemUser.getRealname(); |
| | | } |
| | | if(Objects.nonNull(jkCabinet)){ |
| | | content = content + "于"+jkCabinet.getName()+"钥匙柜"; |
| | | } |
| | | content = content + "酒精检测异常"; |
| | | if(Objects.nonNull(dto.getAlcoholNum())){ |
| | | content = content + ",酒精度数【"+dto.getAlcoholNum()+"°】"; |
| | | } |
| | | |
| | | //存储报警异常记录 |
| | | WarningEvent warningEvent = new WarningEvent(); |
| | | warningEvent.setCreateDate(new Date()); |
| | | warningEvent.setWarningId(warning.getId()); |
| | | warningEvent.setTitle(warningConfig.getInfo()); |
| | | warningEvent.setContent(content ); |
| | | warningEvent.setStatus(Constants.ZERO); |
| | | warningEvent.setRegion(Objects.nonNull(jkCabinet)&&StringUtils.isNotBlank(jkCabinet.getLocation())?jkCabinet.getLocation():"未知位置"); |
| | | warningEventMapper.insert(warningEvent); |
| | | |
| | | try{ |
| | | WarningPush warningPush = new WarningPush(); |
| | | warningPush.setCreateDate(new Date()); |
| | | warningPush.setIsdeleted(Constants.ZERO); |
| | | warningPush.setWarningId(warning.getId()); |
| | | warningPush.setTitle(warningConfig.getInfo()); |
| | | warningPush.setContent(content); |
| | | warningPush.setStatus(Constants.ZERO); |
| | | warningPush.setPushType(Constants.ZERO); |
| | | warningPush.setRegion(Objects.nonNull(jkCabinet)&&StringUtils.isNotBlank(jkCabinet.getLocation())?jkCabinet.getLocation():"未知位置"); |
| | | warningPush.setMemberId(dto.getMemberId()); |
| | | warningPush.setMemberIds( |
| | | StringUtils.join(memberList.stream().map(i->i.getId()).collect(Collectors.toList()),",") |
| | | ); |
| | | warningPush.setMemberIds( |
| | | StringUtils.join(memberList.stream().map(i->i.getId()).collect(Collectors.toList()),",") |
| | | ); |
| | | warningPush.setMemberNames(StringUtils.join(memberList.stream().map(i->i.getName()).collect(Collectors.toList()),",") |
| | | ); |
| | | //todo 暂时关闭 钉钉通知 |
| | | // Boolean noticeFlag = dingTalk.workInfoOANotice(Long.valueOf(systemDictDataBiz.queryByCode(Constants.DD_TALK,Constants.AGENT_ID).getCode()), |
| | | // StringUtils.join(memberList.stream().filter(i->StringUtils.isNotBlank(i.getDdId())).map(i->i.getDdId()).collect(Collectors.toList()),","), |
| | | // dingTalk.getAlarmNoticeMsg(warningPush.getRegion(),DateUtil.getCurrDateTime(),warningConfig.getInfo())); |
| | | // warningPush.setStatus(noticeFlag?Constants.ONE:Constants.TWO); |
| | | warningPushMapper.insert(warningPush); |
| | | warningEvent.setStatus(Constants.ONE); |
| | | warningEventMapper.updateById(warningEvent); |
| | | }catch (Exception e){ |
| | | warningEvent.setStatus(Constants.TWO); |
| | | warningEventMapper.updateById(warningEvent); |
| | | } |
| | | |
| | | |
| | | //存储异常日志 |
| | | if(Objects.nonNull(systemUser)){ |
| | | log.error("司机酒精检测,超出酒精值告警信息:{}"+JSONObject.toJSONString(systemUser)); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |