New file |
| | |
| | | package com.zy.asrs.task; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.zy.asrs.domain.param.ShuttleTimedPowerRangeParam; |
| | | import com.zy.asrs.entity.BasShuttle; |
| | | import com.zy.asrs.service.BasShuttleService; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.system.entity.Config; |
| | | import com.zy.system.service.ConfigService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.time.LocalTime; |
| | | import java.util.List; |
| | | |
| | | @Component |
| | | @Slf4j |
| | | public class ShuttleChargePowerScheduler { |
| | | |
| | | @Autowired |
| | | private ConfigService configService; |
| | | @Autowired |
| | | private BasShuttleService basShuttleService; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | | /** |
| | | * 小车充电线自动调节 |
| | | * 每5钟执行一次 |
| | | */ |
| | | @Scheduled(cron = "0 5 * * * ? ") |
| | | public void run() { |
| | | boolean timedCharge = false; |
| | | Config timedChargeConfig = configService.selectOne(new EntityWrapper<Config>() |
| | | .eq("code", "timedCharge") |
| | | .eq("status", 1)); |
| | | if (timedChargeConfig != null) { |
| | | if("Y".equals(timedChargeConfig.getValue())) { |
| | | timedCharge = true; |
| | | } |
| | | } |
| | | |
| | | if(!timedCharge) { |
| | | return; |
| | | } |
| | | |
| | | Config timedChargeRangeConfig = configService.selectOne(new EntityWrapper<Config>() |
| | | .eq("code", "timedChargeRange") |
| | | .eq("status", 1)); |
| | | if (timedChargeRangeConfig == null) { |
| | | return; |
| | | } |
| | | |
| | | Integer timedChargePowerLine = 90; |
| | | Config timedChargePowerLineConfig = configService.selectOne(new EntityWrapper<Config>() |
| | | .eq("code", "timedChargePowerLine") |
| | | .eq("status", 1)); |
| | | if (timedChargePowerLineConfig == null) { |
| | | return; |
| | | } |
| | | timedChargePowerLine = Integer.parseInt(timedChargePowerLineConfig.getValue()); |
| | | |
| | | Integer shuttleDefaultChargePowerLine = 70; |
| | | Config shuttleDefaultChargePowerLineConfig = configService.selectOne(new EntityWrapper<Config>() |
| | | .eq("code", "shuttleDefaultChargePowerLine") |
| | | .eq("status", 1)); |
| | | if (shuttleDefaultChargePowerLineConfig != null) { |
| | | shuttleDefaultChargePowerLine = Integer.parseInt(shuttleDefaultChargePowerLineConfig.getValue()); |
| | | } |
| | | |
| | | List<ShuttleTimedPowerRangeParam> list = JSON.parseArray(timedChargeRangeConfig.getValue(), ShuttleTimedPowerRangeParam.class); |
| | | for (ShuttleTimedPowerRangeParam rangeParam : list) { |
| | | Object timedChargeObject = redisUtil.get("timedCharge"); |
| | | |
| | | LocalTime startTime = LocalTime.of(rangeParam.getStartTime(), 0); |
| | | LocalTime endTime = LocalTime.of(rangeParam.getEndTime(), 0); |
| | | boolean checkTime = checkTime(startTime, endTime); |
| | | if(!checkTime) { |
| | | if (timedChargeObject != null) { |
| | | subPower(shuttleDefaultChargePowerLine); |
| | | } |
| | | continue; |
| | | } |
| | | |
| | | if(timedChargeObject != null) { |
| | | continue; |
| | | } |
| | | |
| | | addPower(timedChargePowerLine); |
| | | } |
| | | |
| | | } |
| | | |
| | | public boolean checkTime(LocalTime startTime, LocalTime endTime) { |
| | | LocalTime now = LocalTime.now(); |
| | | return !now.isBefore(startTime) && !now.isAfter(endTime); |
| | | } |
| | | |
| | | public boolean addPower(Integer timedChargePowerLine) { |
| | | //调整电量线 |
| | | List<BasShuttle> shuttleList = basShuttleService.selectList(new EntityWrapper<BasShuttle>().ne("charge_line", timedChargePowerLine)); |
| | | if (shuttleList.isEmpty()) { |
| | | return false; |
| | | } |
| | | |
| | | BasShuttle basShuttle = shuttleList.get(0); |
| | | basShuttle.setChargeLine(timedChargePowerLine); |
| | | basShuttleService.updateById(basShuttle); |
| | | |
| | | redisUtil.set("timedCharge", shuttleList.size()); |
| | | return true; |
| | | } |
| | | |
| | | public boolean subPower(Integer shuttleDefaultChargePowerLine) { |
| | | List<BasShuttle> shuttleList = basShuttleService.selectList(new EntityWrapper<BasShuttle>()); |
| | | if (shuttleList.isEmpty()) { |
| | | return false; |
| | | } |
| | | |
| | | for (BasShuttle basShuttle : shuttleList) { |
| | | basShuttle.setChargeLine(shuttleDefaultChargePowerLine); |
| | | basShuttleService.updateById(basShuttle); |
| | | } |
| | | |
| | | redisUtil.del("timedCharge"); |
| | | return true; |
| | | } |
| | | |
| | | } |