package com.zteits.park.job.freeberth; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.clouds.common.cache.park.MessageTempletCacheUtil; import com.clouds.common.cache.park.ParkOperatorRelationCacheUtil; import com.clouds.common.cache.park.ParkingLotCacheUtil; import com.clouds.common.cache.park.ParkingLotExtendCacheUtil; import com.clouds.common.cache.sys.SysCodeValueCacheUtil; import com.clouds.common.constants.CodeValKindEnum; import com.clouds.common.constants.SysAdviceConstant; import com.clouds.common.utils.HttpClientTutorial; import com.clouds.common.utils.MsgTemplateUtil; import com.clouds.common.utils.ResultUtils; import com.clouds.common.utils.aes.CfLfAESUtils; import com.xiaoleilu.hutool.date.DateUnit; import com.xiaoleilu.hutool.date.DateUtil; import com.xiaoleilu.hutool.date.TimeInterval; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.context.XxlJobHelper; import com.xxl.job.core.handler.annotation.XxlJob; import com.zteits.clouds.api.apibase.bean.BizResult; import com.zteits.clouds.api.apibase.constants.BasicEnum; import com.zteits.clouds.api.apibase.constants.DataStatusEnum; import com.zteits.clouds.api.apibase.constants.SourceTypeEnum; import com.zteits.clouds.api.apibase.constants.WorkOrderEnum; import com.zteits.clouds.api.dto.clouds.dto.EqpAndPdaEntryListDTO; import com.zteits.clouds.api.dto.clouds.param.EqpAbnormalStaticRequest; import com.zteits.clouds.api.dto.clouds.param.QueryParkListAllRequest; import com.zteits.clouds.api.dto.order.workorder.param.SaveOrderWorkRequest; import com.zteits.clouds.api.dto.park.dto.ParkingLotDTO; import com.zteits.clouds.api.dto.park.dto.ParkingLotExtendDTO; import com.zteits.clouds.api.dto.park.param.parksource.QueryParkSourceByPlNoRequest; import com.zteits.clouds.api.dto.sys.SysOpAdviceRelDTO; import com.zteits.clouds.api.dto.sys.param.SysOpAdviceRelRequest; import com.zteits.clouds.api.dto.sys.param.SysOpAdviceSaveRequest; import com.zteits.clouds.api.service.order.workorder.oper.OrderWorkOperService; import com.zteits.clouds.api.service.park.ParkingLotQueryService; import com.zteits.clouds.api.service.sys.advice.SysOpAdviceRelService; import com.zteits.clouds.api.service.sys.advice.SysOpAdviceService; import com.zteits.park.dao.ParkingLotDao; import com.zteits.park.dao.TpEEmployeeChargeDao; import com.zteits.park.dao.TpPEqpInoutRecordDAO; import com.zteits.park.domain.ParkingLot; import com.zteits.park.domain.ParkingLotExample; import com.zteits.park.domain.TpEEmployeeCharge; import com.zteits.park.mapper.ParkingLotMapper; import com.zteits.park.service.berths.oper.ParkFreeBerthOperInnerService; import org.apache.commons.codec.binary.Base64; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import java.security.Key; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.CountDownLatch; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; /** * 查询赤峰立方的空闲车位的定时任务 * Copyright: Copyright (c) 2018 * * @Description: * @version: v1.0.0 * @author: xiejianpeng * @date: 2020/10/27 18:01 * Modification History: * Date Author Version Description *---------------------------------------------------------* * 2020/10/27 xiejianpeng v1.0.0 创建 */ @Component public class QueryCfLfParkFreeBerthJob { private static final Logger logger = LoggerFactory.getLogger(QueryCfLfParkFreeBerthJob.class); @Autowired private ParkingLotMapper parkingLotMapper; @Autowired private ParkFreeBerthOperInnerService freeBerthOperInnerService; @XxlJob(value = "queryCfLfParkFreeBerthJob") public ReturnT execute(String... params) throws Exception { String param = XxlJobHelper.getJobParam(); if (StringUtils.isNotEmpty(param) && params == null) { params = param.split(","); } TimeInterval timer = DateUtil.timer(); timer.start(); ParkingLotExample example = new ParkingLotExample(); example.createCriteria() .andSourceTypeEqualTo(SourceTypeEnum.CF_LIFANG.getValue()) .andDataStatusEqualTo(DataStatusEnum.DATA_STATUS_VALID.value()); List parkingLots = parkingLotMapper.selectByExample(example); if (CollectionUtils.isEmpty(parkingLots)) { logger.info("赤峰高铁站的车场没查到!"); return ReturnT.FAIL; } logger.info("{},地磁上报异常信息统计,待统计停车场个数为:{}", parkingLots.size()); Map failMap = new HashMap<>(); CountDownLatch countDownLatch = new CountDownLatch(parkingLots.size()); for(ParkingLot parkingLot : parkingLots) { try { ParkingLotExtendDTO parkingLotExtend = ParkingLotExtendCacheUtil.getParkingLotExtend(parkingLot.getPlNo()); Map map = new HashMap(); map.put("stationNo", parkingLot.getPlOutNo()); Key k = CfLfAESUtils.toKey(Base64.decodeBase64("cmVmb3JtZXJyZWZvcm1lcg==")); byte[] encryptData = CfLfAESUtils.encrypt(JSONObject.toJSONString(map).getBytes(), k); String encryptStr = CfLfAESUtils.parseByte2HexStr(encryptData); Map headers = new HashMap<>(); headers.put("Content-Type", "application/json"); /**查询地址*/ String url = parkingLotExtend.getAddrUrl() + "/GetParkingLotInfo"; String aaa = HttpClientTutorial.httpPostRequest(url, headers, encryptStr); System.out.println(aaa); byte[] decryptData = CfLfAESUtils.decrypt(CfLfAESUtils.parseHexStr2Byte(aaa), k); String decryptStr = new String(decryptData); if(StringUtils.isEmpty(decryptStr)){ failMap.put(parkingLot.getPlNo(), "捕获异常,返回信息:" + decryptStr); } logger.info("赤峰高铁站第三方车场上报请求信息解密后参数:{}", decryptStr); JSONObject jsonObject = JSONObject.parseObject(decryptStr); String resCode = jsonObject.getString("resCode"); String resMsg = jsonObject.getString("resMsg"); if("0".equals(resCode)){ Integer totalNum = jsonObject.getInteger("totalNum"); Integer totalStopNum = jsonObject.getInteger("totalStopNum"); Integer totalRemainNum = jsonObject.getInteger("totalRemainNum"); freeBerthOperInnerService.updateFreeBerthsNumByPlNo(parkingLot.getPlNo(), totalNum, totalRemainNum); }else{ failMap.put(parkingLot.getPlNo(), "捕获异常,返回信息:" + resMsg); } } catch (Exception e) { failMap.put(parkingLot.getPlNo(), "捕获异常:" + e.getMessage()); logger.info("{},赤峰高铁站捕获异常:", parkingLot.getPlNo(), e); } finally { countDownLatch.countDown(); } } countDownLatch.await(); logger.info("地磁上报异常信息结束,总计停车场为{},统计失败个数为{},总耗时{}分钟{}秒", parkingLots.size(), failMap.size(), timer.intervalMinute(), timer.intervalSecond()); logger.info("地磁上报异常信息统计结束====end====={}", DateUtil.now()); if (org.springframework.util.CollectionUtils.isEmpty(failMap)) { return ReturnT.SUCCESS; } else { return new ReturnT<>(ReturnT.FAIL_CODE + ",地磁上报异常信息统计失败:" + JSONObject.toJSONString(failMap)); } } }