| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import cn.hutool.core.collection.ListUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.sandu.common.domain.CommonPage; |
| | |
| | | import com.sandu.ximon.admin.param.C3ChargingAddParam; |
| | | import com.sandu.ximon.admin.param.C3ChargingParam; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.utils.ListPagingUtils; |
| | | import com.sandu.ximon.admin.utils.LogUtils; |
| | | import com.sandu.ximon.admin.utils.RedisUtils; |
| | | import com.sandu.ximon.admin.utils.StoreOperationRecordsUtils; |
| | | import com.sandu.ximon.admin.utils.*; |
| | | import com.sandu.ximon.admin.vo.EquipmentInfomation; |
| | | import com.sandu.ximon.dao.bo.C3ChargingBo; |
| | | import com.sandu.ximon.dao.domain.*; |
| | | import com.sandu.ximon.dao.enums.OrderByEnums; |
| | | import com.sandu.ximon.dao.enums.OrderStatus; |
| | | import com.sandu.ximon.dao.mapper.C3mChargingMapper; |
| | | import lombok.AllArgsConstructor; |
| | |
| | | one.setC3Mac(c3Mac); |
| | | flag = updateById(one); |
| | | } |
| | | //设置费率 |
| | | C3mCharging c3mCharging1 = getOne(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getMcuUdid, mcuUdid)); |
| | | List<C3mChargingCharge> list = c3mChargingChargeService.list(Wrappers.lambdaQuery(C3mChargingCharge.class).eq(C3mChargingCharge::getC3Id, c3mCharging1.getC3Id())); |
| | | if (list.size() == 0) {//费率表中没有此充电桩数据时 添加默认费率 |
| | | c3mChargingChargeService.initCharge((c3mCharging1.getC3Id()).intValue()); |
| | | } |
| | | // /** |
| | | // * 添加绑定关系开始 |
| | | // */ |
| | | // Pole pole = poleService.getOne(Wrappers.lambdaQuery(Pole.class).eq(Pole::getDeviceCode, deviceName)); |
| | | // if (pole == null) { |
| | | // Pole pole1 = new Pole(); |
| | | // pole1.setDeviceCode(deviceName); |
| | | // pole1.setPoleName(deviceName); |
| | | // pole1.setPoleCode(poleService.generatePoleCode()); |
| | | // poleService.save(pole1); |
| | | // } |
| | | // |
| | | // Long poleId = poleService.getOne(Wrappers.lambdaQuery(Pole.class).eq(Pole::getDeviceCode, deviceName)).getId(); |
| | | // PoleBindingParam poleBindingParam = new PoleBindingParam(); |
| | | // poleBindingParam.setDeviceType(2); |
| | | // poleBindingParam.setDeviceCode(mcuUdid); |
| | | // bindingService.bindPole(poleId, poleBindingParam); |
| | | |
| | | /** |
| | | * 添加绑定关系结束 |
| | | */ |
| | | |
| | | //同步时间戳 |
| | | System.out.println("同步时间戳开始"); |
| | | String date = new SimpleDateFormat("yyMMddHHmmss").format(new Date()); |
| | | String s = SetCalendar(c3Mac, Integer.parseInt(date.substring(0, 2)), Integer.parseInt(date.substring(2, 4)), |
| | | Integer.parseInt(date.substring(4, 6)), Integer.parseInt(date.substring(6, 8)), |
| | |
| | | LogUtils.error("发送设置C3时间同步失败!"); |
| | | return false; |
| | | } |
| | | System.out.println("同步时间戳结束"); |
| | | |
| | | //设置费率 |
| | | System.out.println("设置费率开始"); |
| | | C3mCharging c3mCharging1 = getOne(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getMcuUdid, mcuUdid)); |
| | | List<C3mChargingCharge> list = c3mChargingChargeService.list(Wrappers.lambdaQuery(C3mChargingCharge.class).eq(C3mChargingCharge::getC3Id, c3mCharging1.getC3Id())); |
| | | if (list.size() == 0) {//费率表中没有此充电桩数据时 添加默认费率 |
| | | c3mChargingChargeService.initCharge((c3mCharging1.getC3Id()).intValue()); |
| | | } |
| | | String rateState = setRate(c3Mac, list); |
| | | System.out.println("设置费率结果:" + rateState); |
| | | System.out.println("设置费率结束"); |
| | | |
| | | /** 跳包时间同步 |
| | | * 设置时间规则:充电时为1倍,非充电状态为1.5倍时间 |
| | | */ |
| | | System.out.println("设置心跳包间隔时间开始"); |
| | | Set<String> keys = RedisUtils.getBean().keys(C3mRedisConstant.C3_STATUS.getCode() + "*"); |
| | | |
| | | C3mRedisConfig.reFlushTime(keys.size()); |
| | |
| | | LogUtils.error("C3空闲心跳包时间同步响应结果:" + time1); |
| | | String time2 = SetHeartbeatPacketTimeCharging(c3Mac, C3mRedisConfig.parseInt(C3mRedisConfig.HEART_BEAT_TIME), true); |
| | | LogUtils.error("C3充电时心跳包时间同步响应结果:" + time2); |
| | | System.out.println("设置心跳包间隔时间结束"); |
| | | |
| | | |
| | | /** |
| | | * 获取心跳包,判断在线 |
| | | */ |
| | | System.out.println("获取心跳包开始"); |
| | | A5C3HeartbeatReportInnerFrame.HeartBeatDataPackage aPackage = ReadTheHeartbeatPackage(c3Mac); |
| | | if (aPackage == null) { |
| | | LogUtils.error("读取心跳包为空"); |
| | |
| | | JSON.toJSONString(aPackage), |
| | | C3mRedisConfig.OUTLINE_TIME |
| | | ); |
| | | System.out.println("获取心跳包结束"); |
| | | |
| | | /** |
| | | * finally、同步结束 |
| | | */ |
| | | System.out.println("同步结束 开始"); |
| | | String end = EndOfTheSynchronization(c3Mac); |
| | | if (!"操作成功".equals(end)) { |
| | | LogUtils.error("C3同步结束响应结果" + end); |
| | | return false; |
| | | } |
| | | System.out.println("同步结束 结束"); |
| | | |
| | | return flag; |
| | | } |
| | | |
| | |
| | | * |
| | | * @return |
| | | */ |
| | | public Map getC3ChargingListByKeyword(BaseConditionVO baseConditionVO, C3ChargingParam c3ChargingParam) { |
| | | public Map getC3ChargingListByKeyword(BaseConditionVO baseConditionVO, C3ChargingParam c3ChargingParam, Integer order, Integer seq) { |
| | | if (c3ChargingParam == null) { |
| | | c3ChargingParam = new C3ChargingParam(); |
| | | } |
| | |
| | | if (c3ChargingParam.getKeyword() != null) { |
| | | c3ChargingParam.setKeyword(c3ChargingParam.getKeyword().trim()); |
| | | } |
| | | //排序字段 |
| | | String orderByResult = "t1.c3_id"; |
| | | //正序、倒叙 |
| | | String orderBySeq = OrderByEnums.ASC.getCode(); |
| | | if (order != null) { |
| | | switch (order) { |
| | | case 1: |
| | | orderByResult = OrderByEnums.CHARGE_POLE_CREATE_TIME.getCode(); |
| | | break; |
| | | default: |
| | | } |
| | | } |
| | | if (seq != null) { |
| | | switch (seq) { |
| | | case 1: |
| | | orderBySeq = " ASC"; |
| | | break; |
| | | case 2: |
| | | orderBySeq = " DESC"; |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | //排序方式 |
| | | String orderBy = orderByResult + " " + orderBySeq; |
| | | |
| | | List<C3ChargingBo> c3ChargingBoList; |
| | | if (SecurityUtils.getClientId() == null) { |
| | | c3ChargingBoList = c3mChargingMapper.listC3mChargingDto(c3ChargingParam.getKeyword(), null); |
| | | c3ChargingBoList = c3mChargingMapper.listC3mChargingDto(c3ChargingParam.getKeyword(), null, orderBy); |
| | | } else { |
| | | c3ChargingBoList = c3mChargingMapper.listC3mChargingDto(c3ChargingParam.getKeyword(), SecurityUtils.getUserId()); |
| | | c3ChargingBoList = c3mChargingMapper.listC3mChargingDto(c3ChargingParam.getKeyword(), SecurityUtils.getUserId(), orderBy); |
| | | } |
| | | //在线数量 |
| | | int onlineNumber = 0; |
| | |
| | | |
| | | List<C3ChargingBo> c3ChargingBoList; |
| | | if (SecurityUtils.getClientId() == null) { |
| | | c3ChargingBoList = c3mChargingMapper.listC3mChargingDto(null, null); |
| | | c3ChargingBoList = c3mChargingMapper.listC3mChargingDto(null, null, "c3_id ASC"); |
| | | } else { |
| | | c3ChargingBoList = c3mChargingMapper.listC3mChargingDto(null, SecurityUtils.getUserId()); |
| | | c3ChargingBoList = c3mChargingMapper.listC3mChargingDto(null, SecurityUtils.getUserId(), "c3_id ASC"); |
| | | } |
| | | return c3ChargingBoList; |
| | | } |
| | |
| | | chargingDto.setC3Id(one.getC3Id()); |
| | | //C3Mac |
| | | chargingDto.setC3Mac(one.getC3Mac()); |
| | | //在线状态 |
| | | //在线状态 1.空闲 2.充电中 3.充电中断,等待服务器确认 4.充电结束,等待服务器确认 5.有故障 6.与充电桩对接中 |
| | | chargingDto.setStatusBit(Integer.valueOf(beatDataPackage.getStatusBit())); |
| | | //电压 |
| | | chargingDto.setGridVoltage(beatDataPackage.getGridVoltage()); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 设置费率 |
| | | * |
| | | * @param c3Mac |
| | | * @param list |
| | | * @return |
| | | */ |
| | | public String setRate(String c3Mac, List<C3mChargingCharge> list) { |
| | | if (StringUtil.strIsNullOrEmpty(c3Mac)) { |
| | | throw new BusinessException("C3Mac地址不能为空!"); |
| | | } |
| | | if (list.isEmpty()) { |
| | | throw new BusinessException("费率数据不能为空!"); |
| | | } |
| | | C3SetRateReqInnerFrame c3SetRateReqInnerFrame = new C3SetRateReqInnerFrame(c3Mac, list); |
| | | |
| | | A5Frame a5Frame = new A5Frame(A5OrderEnum.REQUEST_C3_DATA.getCode(), c3SetRateReqInnerFrame); |
| | | System.out.println(a5Frame + " -----a5Frame"); |
| | | C3mCharging c3mCharging = getOne(Wrappers.lambdaQuery(C3mCharging.class).eq(C3mCharging::getC3Mac, c3Mac)); |
| | | if (c3mCharging == null) { |
| | | throw new BusinessException("C3充电桩硬件mcu_udid不存在"); |
| | | } |
| | | CommonFrame commonFrame = MainBoardInvokeSyncService.getInstance().sendRRPC(c3mCharging.getPoleDevicesCode(), a5Frame); |
| | | StoreOperationRecordsUtils.storeInnerFrameData(c3Mac, "C3帧-设置费率", a5Frame, commonFrame); |
| | | System.out.println(commonFrame + " -----commonFrame"); |
| | | |
| | | A5C3OperationReportInnerFrame operationReportInnerFrame = new A5C3OperationReportInnerFrame().transformFrame(commonFrame.getPayload()); |
| | | if (operationReportInnerFrame.isValidate()) { |
| | | return operationReportInnerFrame.getState(); |
| | | } else { |
| | | throw new BusinessException("数据校验错误,请重新请求"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 故障码上报清除 |
| | | * |
| | | * @param c3Mac |