New file |
| | |
| | | package com.zy.asrs.wcs.core.domain.param; |
| | | |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class ShuttleTimedPowerRangeParam { |
| | | |
| | | private Integer startTime; |
| | | |
| | | private Integer endTime; |
| | | |
| | | } |
New file |
| | |
| | | package com.zy.asrs.wcs.core.task; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.zy.asrs.wcs.core.domain.param.ShuttleTimedPowerRangeParam; |
| | | import com.zy.asrs.wcs.core.entity.BasShuttle; |
| | | import com.zy.asrs.wcs.core.service.BasShuttleService; |
| | | import com.zy.asrs.wcs.core.utils.RedisUtil; |
| | | import com.zy.asrs.wcs.system.entity.Dict; |
| | | import com.zy.asrs.wcs.system.service.DictService; |
| | | 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 DictService dictService; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | @Autowired |
| | | private BasShuttleService basShuttleService; |
| | | |
| | | /** |
| | | * å°è½¦å
çµçº¿èªå¨è°è |
| | | * æ¯5éæ§è¡ä¸æ¬¡ |
| | | */ |
| | | @Scheduled(cron = "0 5 * * * ? ") |
| | | public void run() { |
| | | boolean timedCharge = false; |
| | | Dict timedChargeDict = dictService.getOne(new LambdaQueryWrapper<Dict>().eq(Dict::getFlag, "timedCharge")); |
| | | if (timedChargeDict != null) { |
| | | if("Y".equals(timedChargeDict.getValue())) { |
| | | timedCharge = true; |
| | | } |
| | | } |
| | | |
| | | if(!timedCharge) { |
| | | return; |
| | | } |
| | | |
| | | Dict timedChargeRangeDict = dictService.getOne(new LambdaQueryWrapper<Dict>().eq(Dict::getFlag, "timedChargeRange")); |
| | | if (timedChargeRangeDict == null) { |
| | | return; |
| | | } |
| | | |
| | | Integer timedChargePowerLine = 90; |
| | | Dict timedChargePowerLineDict = dictService.getOne(new LambdaQueryWrapper<Dict>().eq(Dict::getFlag, "timedChargePowerLine")); |
| | | if (timedChargePowerLineDict == null) { |
| | | return; |
| | | } |
| | | timedChargePowerLine = Integer.parseInt(timedChargePowerLineDict.getValue()); |
| | | |
| | | Integer shuttleDefaultChargePowerLine = 70; |
| | | Dict shuttleDefaultChargePowerLineDict = dictService.getOne(new LambdaQueryWrapper<Dict>().eq(Dict::getFlag, "shuttleDefaultChargePowerLine")); |
| | | if (shuttleDefaultChargePowerLineDict != null) { |
| | | shuttleDefaultChargePowerLine = Integer.parseInt(shuttleDefaultChargePowerLineDict.getValue()); |
| | | } |
| | | |
| | | List<ShuttleTimedPowerRangeParam> list = JSON.parseArray(timedChargeRangeDict.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.list(new LambdaQueryWrapper<BasShuttle>().ne(BasShuttle::getChargeLine, timedChargePowerLine)); |
| | | if (shuttleList.isEmpty()) { |
| | | return false; |
| | | } |
| | | |
| | | for (BasShuttle basShuttle : shuttleList) { |
| | | basShuttle.setChargeLine(timedChargePowerLine); |
| | | basShuttleService.updateById(basShuttle); |
| | | } |
| | | |
| | | redisUtil.set("timedCharge", shuttleList.size()); |
| | | return true; |
| | | } |
| | | |
| | | public boolean subPower(Integer shuttleDefaultChargePowerLine) { |
| | | List<BasShuttle> shuttleList = basShuttleService.list(new LambdaQueryWrapper<BasShuttle>()); |
| | | if (shuttleList.isEmpty()) { |
| | | return false; |
| | | } |
| | | |
| | | for (BasShuttle basShuttle : shuttleList) { |
| | | basShuttle.setChargeLine(shuttleDefaultChargePowerLine); |
| | | basShuttleService.updateById(basShuttle); |
| | | } |
| | | |
| | | redisUtil.del("timedCharge"); |
| | | return true; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | INSERT INTO `jxgtasrs`.`sys_dict` (`uuid`, `name`, `type`, `flag`, `value`, `sort`, `host_id`, `status`, `deleted`, `create_time`, `create_by`, `update_time`, `update_by`, `memo`) VALUES (NULL, '宿¶å
çµå¼å
³', 3, 'timedCharge', 'Y', NULL, 1, 1, 0, '2025-04-18 15:43:19', NULL, '2025-04-18 15:43:19', NULL, NULL); |
| | | INSERT INTO `jxgtasrs`.`sys_dict` (`uuid`, `name`, `type`, `flag`, `value`, `sort`, `host_id`, `status`, `deleted`, `create_time`, `create_by`, `update_time`, `update_by`, `memo`) VALUES (NULL, '宿¶å
çµæ¶é´æ®µ', 3, 'timedChargeRange', '[{\"startTime\":\"5\",\"endTime\":\"6\"}]', NULL, 1, 1, 0, '2025-04-18 15:43:37', NULL, '2025-04-18 15:43:37', NULL, NULL); |
| | | INSERT INTO `jxgtasrs`.`sys_dict` (`uuid`, `name`, `type`, `flag`, `value`, `sort`, `host_id`, `status`, `deleted`, `create_time`, `create_by`, `update_time`, `update_by`, `memo`) VALUES (NULL, 'å°è½¦é»è®¤å
çµçº¿', 3, 'shuttleDefaultChargePowerLine', '50', NULL, 1, 1, 0, '2025-04-18 15:43:58', NULL, '2025-04-18 15:43:58', NULL, NULL); |
| | | INSERT INTO `jxgtasrs`.`sys_dict` (`uuid`, `name`, `type`, `flag`, `value`, `sort`, `host_id`, `status`, `deleted`, `create_time`, `create_by`, `update_time`, `update_by`, `memo`) VALUES (NULL, 'å°è½¦å®æ¶å
çµçº¿', 3, 'timedChargePowerLine', '95', NULL, 1, 1, 0, '2025-04-18 15:44:11', NULL, '2025-04-18 15:44:11', NULL, NULL); |