| | |
| | | import com.ruoyi.common.log.enums.BusinessType; |
| | | import com.ruoyi.common.log.enums.OperatorType; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.order.api.feignClient.ChargingOrderClient; |
| | | import com.ruoyi.order.api.model.TChargingOrder; |
| | | import com.ruoyi.order.api.vo.TChargingOrderVo; |
| | | import com.ruoyi.other.api.domain.TVip; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | |
| | | @Resource |
| | | private TFaultMessageService faultMessageService; |
| | | |
| | | @Resource |
| | | private ChargingOrderClient chargingOrderClient; |
| | | |
| | | |
| | | @Autowired |
| | |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/getChargingPileById/{id}") |
| | | public R<TChargingPile> getChargingPileById(@PathVariable Integer id){ |
| | | public R<TChargingPile> getChargingPileById(@PathVariable("id") Integer id){ |
| | | TChargingPile chargingPile = chargingPileService.getById(id); |
| | | return R.ok(chargingPile); |
| | | } |
| | |
| | | |
| | | /** |
| | | * 更新充电桩状态 |
| | | * @param code |
| | | * @param status |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/updateChargingPileStatus") |
| | | public void updateChargingPileStatus(@RequestParam("code") String code, @RequestParam("status") Integer status){ |
| | | TChargingPile chargingPile = chargingPileService.getOne(new LambdaQueryWrapper<TChargingPile>() |
| | | .eq(TChargingPile::getCode, code).eq(TChargingPile::getDelFlag, 0)); |
| | | if(null != chargingPile){ |
| | | //充电桩正常,返回异常,处理充电桩状态和添加故障记录 |
| | | if(chargingPile.getStatus() == 1 && 1 == status){ |
| | | TFaultMessage faultMessage = faultMessageService.getOne(new LambdaQueryWrapper<TFaultMessage>().eq(TFaultMessage::getChargingPileId, chargingPile.getId()) |
| | | .eq(TFaultMessage::getStatus, 2).eq(TFaultMessage::getDelFlag, 0).isNull(TFaultMessage::getEndTime)); |
| | | if(null == faultMessage){ |
| | | faultMessage = new TFaultMessage(); |
| | | faultMessage.setSiteId(chargingPile.getSiteId()); |
| | | faultMessage.setChargingPileId(chargingPile.getId()); |
| | | faultMessage.setStatus(2); |
| | | faultMessage.setDownTime(LocalDateTime.now()); |
| | | faultMessage.setCreateTime(LocalDateTime.now()); |
| | | faultMessage.setDelFlag(false); |
| | | faultMessage.setContent("设备故障"); |
| | | faultMessageService.save(faultMessage); |
| | | |
| | | chargingPile.setStatus(0 == status ? 1 : 3); |
| | | chargingPileService.updateById(chargingPile); |
| | | public void updateChargingPileStatus(@RequestParam("pile_code") String pile_code, @RequestParam("gun_code") String gun_code, @RequestParam("status") Integer status){ |
| | | Map<String, Object> charging_pile_online = redisService.getCacheMap("charging_gun_online"); |
| | | Long time = (Long) charging_pile_online.get(pile_code + gun_code); |
| | | //小于30秒才处理数据,防止频繁查询数据 |
| | | if(null != time && (System.currentTimeMillis() - time) < 30000){ |
| | | return; |
| | | } |
| | | TChargingGun tChargingGun = chargingGunService.getOne(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getFullNumber, (pile_code + gun_code)).eq(TChargingGun::getDelFlag, 0)); |
| | | if(null != tChargingGun){ |
| | | TChargingPile chargingPile = chargingPileService.getById(tChargingGun.getChargingPileId()); |
| | | //枪处于离线或者故障,返回状态为正常,则修改其状态 |
| | | if(0 == status && tChargingGun.getStatus() != 2){ |
| | | TChargingGun tChargingGun1 = new TChargingGun(); |
| | | tChargingGun1.setId(tChargingGun.getId()); |
| | | tChargingGun1.setStatus(2); |
| | | chargingGunService.updateById(tChargingGun1); |
| | | if(chargingPile.getStatus() != 1){ |
| | | TChargingPile chargingPile1 = new TChargingPile(); |
| | | chargingPile1.setId(chargingPile.getId()); |
| | | chargingPile1.setStatus(1); |
| | | chargingPileService.updateById(chargingPile1); |
| | | } |
| | | } |
| | | if(chargingPile.getStatus() != 1 && 0 == status){ |
| | | TFaultMessage one = faultMessageService.getOne(new LambdaQueryWrapper<TFaultMessage>().eq(TFaultMessage::getChargingPileId, chargingPile.getId()) |
| | | |
| | | List<TFaultMessage> list = faultMessageService.list(new LambdaQueryWrapper<TFaultMessage>().eq(TFaultMessage::getChargingGunId, tChargingGun.getId()) |
| | | .isNull(TFaultMessage::getEndTime)); |
| | | if(null != one){ |
| | | one.setEndTime(LocalDateTime.now()); |
| | | faultMessageService.updateById(one); |
| | | if(!list.isEmpty()){ |
| | | list.forEach(s->s.setEndTime(LocalDateTime.now())); |
| | | faultMessageService.updateBatchById(list); |
| | | } |
| | | |
| | | chargingPile.setStatus(0 == status ? 1 : 3); |
| | | chargingPileService.updateById(chargingPile); |
| | | } |
| | | if(0 == status){ |
| | | Map<String, Object> charging_pile_online = redisService.getCacheMap("charging_pile_online"); |
| | | charging_pile_online.put(code, System.currentTimeMillis()); |
| | | redisService.setCacheMap("charging_pile_online", charging_pile_online); |
| | | //枪处于正常,返回状态为故障,则修改其状态 |
| | | if(1 == status && tChargingGun.getStatus() != 1 && tChargingGun.getStatus() != 7){ |
| | | TChargingGun tChargingGun1 = new TChargingGun(); |
| | | tChargingGun1.setId(tChargingGun.getId()); |
| | | tChargingGun1.setStatus(7); |
| | | chargingGunService.updateById(tChargingGun1); |
| | | |
| | | //桩处于正常,桩所属的枪都处于非正常,修改桩状态为异常 |
| | | List<TChargingGun> list = chargingGunService.list(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getChargingPileId, chargingPile.getId()).eq(TChargingGun::getDelFlag, 0)); |
| | | int size = list.stream().filter(s -> s.getStatus() == 1 || s.getStatus() == 7).collect(Collectors.toList()).size(); |
| | | if(chargingPile.getStatus() == 1 && list.size() == size){ |
| | | TChargingPile chargingPile1 = new TChargingPile(); |
| | | chargingPile1.setId(chargingPile.getId()); |
| | | chargingPile1.setStatus(3); |
| | | chargingPileService.updateById(chargingPile1); |
| | | } |
| | | |
| | | TFaultMessage faultMessage = new TFaultMessage(); |
| | | faultMessage.setSiteId(chargingPile.getSiteId()); |
| | | faultMessage.setChargingPileId(chargingPile.getId()); |
| | | faultMessage.setChargingGunId(tChargingGun.getId()); |
| | | faultMessage.setStatus(2); |
| | | faultMessage.setDownTime(LocalDateTime.now()); |
| | | faultMessage.setCreateTime(LocalDateTime.now()); |
| | | faultMessage.setDelFlag(false); |
| | | faultMessage.setContent("设备故障"); |
| | | faultMessageService.save(faultMessage); |
| | | } |
| | | |
| | | if(1 != status){ |
| | | charging_pile_online.put(tChargingGun.getFullNumber(), System.currentTimeMillis()); |
| | | redisService.setCacheMap("charging_gun_online", charging_pile_online); |
| | | } |
| | | if(2 == status){ |
| | | TChargingOrderVo order = new TChargingOrderVo(); |
| | | order.setChargingPileId(tChargingGun.getChargingPileId()); |
| | | order.setChargingGunId(tChargingGun.getId()); |
| | | order.setStatusList(Arrays.asList(1, 2, 3, 4, 5)); |
| | | List<TChargingOrder> orders = chargingOrderClient.getChargingOrder(order).getData(); |
| | | if(orders.size() > 0){ |
| | | TChargingOrder chargingOrder = orders.get(0); |
| | | TChargingGun tChargingGun1 = new TChargingGun(); |
| | | if(Arrays.asList(1, 2).contains(chargingOrder.getStatus())){ |
| | | tChargingGun1.setStatus(3); |
| | | } |
| | | if(Arrays.asList(3).contains(chargingOrder.getStatus())){ |
| | | tChargingGun1.setStatus(4); |
| | | } |
| | | if(Arrays.asList(4).contains(chargingOrder.getStatus()) && chargingOrder.getEndMode() == 2){ |
| | | tChargingGun1.setStatus(5); |
| | | } |
| | | tChargingGun1.setId(tChargingGun.getId()); |
| | | chargingGunService.updateById(tChargingGun1); |
| | | } |
| | | } |
| | | } |
| | | } |