Junjie
10 天以前 9532957e33f90720b3d458c6dbc085929918b2ec
#新增定时自动充电
3个文件已添加
141 ■■■■■ 已修改文件
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/domain/param/ShuttleTimedPowerRangeParam.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/task/ShuttleChargePowerScheduler.java 125 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-wcs/src/main/resources/sql/自动充电Dict数据.txt 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/domain/param/ShuttleTimedPowerRangeParam.java
New file
@@ -0,0 +1,12 @@
package com.zy.asrs.wcs.core.domain.param;
import lombok.Data;
@Data
public class ShuttleTimedPowerRangeParam {
    private Integer startTime;
    private Integer endTime;
}
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/task/ShuttleChargePowerScheduler.java
New file
@@ -0,0 +1,125 @@
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;
    }
}
zy-asrs-wcs/src/main/resources/sql/×Ô¶¯³äµçDictÊý¾Ý.txt
New file
@@ -0,0 +1,4 @@
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);