whycxzp
2025-06-10 5005f4916ae1240cf4cd91bb4ed82be43598f568
自动充放电自动化流程
4个文件已修改
213 ■■■■■ 已修改文件
src/main/java/com/whyc/mapper/BattWarehouseMapper.java 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/schedule/WmsTaskSchedule.java 134 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/BattWarehouseService.java 42 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/BattWarehouseMapper.xml 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/BattWarehouseMapper.java
@@ -5,6 +5,9 @@
import java.util.List;
public interface BattWarehouseMapper extends CustomMapper<BattWarehouse> {
    void updateBatchById(List<BattWarehouse> list);
    void updateActivateBatchById(List<BattWarehouse> list);
    void updateChargeBatchById(List<BattWarehouse> list);
    void updateDischargeBatchById(List<BattWarehouse> list);
}
src/main/java/com/whyc/schedule/WmsTaskSchedule.java
@@ -41,7 +41,11 @@
    @Autowired
    private WmsService wmsService;
    /**每天早上9点执行一次*/
    /**
     * 仓储库所有电池的活化任务,任务之前还检查并加入 之前未放入仓储库表中的单体
     * 活化周期: 在参数表里设置
     * 每天早上9点执行一次
     * */
    //@Scheduled(cron= "0 0 9 * * ?")
    public void checkAndActivate() {
        //查询数据库记录的仓库内所有的电池
@@ -61,6 +65,8 @@
                    battWarehouse.setMonId(Integer.valueOf(item.getPalletCode()));
                    battWarehouse.setStorageTime(now);
                    battWarehouse.setOnPlan(0);
                    battWarehouse.setChargeOnPlan(0);
                    battWarehouse.setDischargeOnPlan(0);
                    String volStr = item.getV().replace("v", "");
                    int vol = Integer.parseInt(volStr);
                    battWarehouse.setVol(vol);
@@ -76,8 +82,8 @@
        //查询需要活化的电池列表
        List<BattWarehouse> list = battWarehouseService.getActivateList();
        //通过电压进行分组list
        Map<Integer, List<BattWarehouse>> mapToActivate = list.stream().collect(Collectors.groupingBy(BattWarehouse::getVol));
        /*//通过电压进行分组list
        Map<Integer, List<BattWarehouse>> mapToActivate = list.stream().filter(item->item.getVol() == 2).collect(Collectors.groupingBy(BattWarehouse::getVol));
        Set<Integer> volSet = mapToActivate.keySet();
        //永远只对一类电压进行活化任务下发!!!因为连续下发活化,后续的会失败
        Integer vol;
@@ -88,7 +94,14 @@
        }else{
            //本次终止
            return;
        }*/
        if(list.size() == 0){
            //没有需要活化的电池
            return;
        }
        int vol =2;
        String[] activateParameterStr = null;
        list = list.stream().filter(item -> item.getVol() == 2).collect(Collectors.toList());
        //查询是否存在正在进行的任务
        List<Task> ongoingList = taskService.getOngoingList();
        if (ongoingList.size() == 0) {
@@ -116,25 +129,26 @@
            //   cCap: 10,      // 预充容量0.1AH-需要根据容量实际设置 等于实际容量
            //   tTimes: 1,    // 充放次数
            //   standTime: 1,   // 静置时间
            //   startType: 1,   // 测试起点-默认充电
            //   startType: 1,   // 测试起点-默认充电. 测试起点:0放电,1充电
            //}
            if(vol == 2) {
                activateParameterStr = new String[]{
                        "1", "350", "200", "10", "350", "1800", "3500", "10", "350", "175", "2350", "2250", "3500", "1", "1", "1"
                };
            }
            //TODO 6V待提供
            //暂不考虑6V和12V,只存在2V
            /*//6V待提供
            else if(vol==6){
                activateParameterStr = new String[]{
                        "1", "350", "200", "10", "350", "1800", "3500", "10", "350", "175", "2350", "2250", "3500", "1", "1", "1"
                };
            }
            //TODO 12V待提供
            //12V待提供
            else if(vol==12){
                activateParameterStr = new String[]{
                        "1", "350", "200", "10", "350", "1800", "3500", "10", "350", "175", "2350", "2250", "3500", "1", "1", "1"
                };
            }
            }*/
            List<String> activateParameter = Arrays.asList(activateParameterStr);
            wmsPalletDto.setActivateParameter(activateParameter);
            Response response = wmsService.sendTask(wmsPalletDto);
@@ -149,7 +163,111 @@
                        item.setTaskNo(taskNoList.get(i));
                    }
                    //批量更新BattWarehouse
                    battWarehouseService.updateBatchById(list);
                    battWarehouseService.updateActivateBatchById(list);
                }
            }
        }
    }
    /**
     * 仓储库所有电池的充电任务
     * 充电周期:1个月
     * 传入的活化参数:cTime=0,startType=1
     * 每天早上10点执行一次
     * */
    //@Scheduled(cron= "0 0 10 * * ?")
    public void checkAndCharge() {
        //查询需要充电的电池列表
        List<BattWarehouse> list = battWarehouseService.getChargeList();
        list = list.stream().filter(item -> item.getVol() == 2).collect(Collectors.toList());
        if(list.size() == 0){
            //没有需要充电的电池
            return;
        }
        //查询是否存在正在进行的任务
        List<Task> ongoingList = taskService.getOngoingList();
        if (ongoingList.size() == 0) {
            //没有正在进行的活化任务,则下发活化任务
            WmsPalletDto wmsPalletDto = new WmsPalletDto();
            wmsPalletDto.setDes(3);
            List<String> pallets = list.stream().map(item -> String.valueOf(item.getMonId())).collect(Collectors.toList());
            //pallets从List类型转LinkedList类型
            LinkedList<String> palletsLinked = new LinkedList<>(pallets);
            wmsPalletDto.setPallets(palletsLinked);
            //活化参数设置
            String[] activateParameterStr = new String[]{
                        "1", "350", "200", "10", "350", "1800", "3500", "10", "350", "175", "2350", "2250", "3500", "0", "1", "1"
                };
            List<String> activateParameter = Arrays.asList(activateParameterStr);
            wmsPalletDto.setActivateParameter(activateParameter);
            Response response = wmsService.sendTask(wmsPalletDto);
            if (response.getCode() == 1) {
                WmsResponse responseInside = (WmsResponse) response.getData();
                if(responseInside.getCode() == 0){//下发成功
                    LinkedList<String> taskNoList = responseInside.getTask_no();
                    //进行标志位和任务编号的更新
                    for (int i = 0; i < taskNoList.size(); i++) {
                        BattWarehouse item = list.get(i);
                        item.setChargeOnPlan(1);
                        item.setChargeTaskNo(taskNoList.get(i));
                    }
                    //批量更新BattWarehouse
                    battWarehouseService.updateChargeBatchById(list);
                }
            }
        }
    }
    /**
     * 仓储库所有电池的放电任务
     * 放电周期:2个月
     * 传入的活化参数:cTime=0,startType=0
     * 每天早上11点执行一次
     * */
    //@Scheduled(cron= "0 0 11 * * ?")
    public void checkAndDischarge() {
        //查询需要放电的电池列表
        List<BattWarehouse> list = battWarehouseService.getDischargeList();
        list = list.stream().filter(item -> item.getVol() == 2).collect(Collectors.toList());
        if(list.size() == 0){
            //没有需要放电的电池
            return;
        }
        //查询是否存在正在进行的任务
        List<Task> ongoingList = taskService.getOngoingList();
        if (ongoingList.size() == 0) {
            //没有正在进行的活化任务,则下发活化任务
            WmsPalletDto wmsPalletDto = new WmsPalletDto();
            wmsPalletDto.setDes(3);
            List<String> pallets = list.stream().map(item -> String.valueOf(item.getMonId())).collect(Collectors.toList());
            //pallets从List类型转LinkedList类型
            LinkedList<String> palletsLinked = new LinkedList<>(pallets);
            wmsPalletDto.setPallets(palletsLinked);
            //活化参数设置
            String[] activateParameterStr = new String[]{
                    "1", "350", "200", "10", "350", "1800", "3500", "10", "350", "175", "2350", "2250", "3500", "0", "1", "0"
            };
            List<String> activateParameter = Arrays.asList(activateParameterStr);
            wmsPalletDto.setActivateParameter(activateParameter);
            Response response = wmsService.sendTask(wmsPalletDto);
            if (response.getCode() == 1) {
                WmsResponse responseInside = (WmsResponse) response.getData();
                if(responseInside.getCode() == 0){//下发成功
                    LinkedList<String> taskNoList = responseInside.getTask_no();
                    //进行标志位和任务编号的更新
                    for (int i = 0; i < taskNoList.size(); i++) {
                        BattWarehouse item = list.get(i);
                        item.setDischargeOnPlan(1);
                        item.setDischargeTaskNo(taskNoList.get(i));
                    }
                    //批量更新BattWarehouse
                    battWarehouseService.updateDischargeBatchById(list);
                }
            }
        }
src/main/java/com/whyc/service/BattWarehouseService.java
@@ -34,12 +34,36 @@
        PageParam param = pageParamService.getActivatePeriod();
        Integer period = param.getValue();
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE,-period);
        calendar.add(Calendar.DAY_OF_MONTH,-period);
        QueryWrapper<BattWarehouse> query = Wrappers.query();
        query.eq("on_plan",0);
        //为活化过 或者 活化时间超过活化周期
        query.isNull("activate_time").or().le("activate_time",calendar);
        //未活化过 或者 活化时间超过活化周期
        query.isNull("activate_time").or().le("activate_time",calendar.getTime());
        return mapper.selectList(query);
    }
    public List<BattWarehouse> getChargeList() {
        Integer period = 1;
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH,-period);
        QueryWrapper<BattWarehouse> query = Wrappers.query();
        query.eq("charge_on_plan",0);
        //未充电过 或者 充电时间超过充电周期
        query.isNull("charge_time").or().le("charge_time",calendar.getTime());
        return mapper.selectList(query);
    }
    public List<BattWarehouse> getDischargeList() {
        Integer period = 2;
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH,-period);
        QueryWrapper<BattWarehouse> query = Wrappers.query();
        query.eq("discharge_on_plan",0);
        //未放电过 或者 放电时间超过放电周期
        query.isNull("discharge_time").or().le("discharge_time",calendar.getTime());
        return mapper.selectList(query);
    }
@@ -51,8 +75,16 @@
        mapper.insertBatchSomeColumn(listNew);
    }
    public void updateBatchById(List<BattWarehouse> list) {
        mapper.updateBatchById(list);
    public void updateActivateBatchById(List<BattWarehouse> list) {
        mapper.updateActivateBatchById(list);
    }
    public void updateChargeBatchById(List<BattWarehouse> list) {
        mapper.updateChargeBatchById(list);
    }
    public void updateDischargeBatchById(List<BattWarehouse> list) {
        mapper.updateDischargeBatchById(list);
    }
    public BattWarehouse getByTaskNo(String taskNo) {
src/main/resources/mapper/BattWarehouseMapper.xml
@@ -3,7 +3,7 @@
<mapper namespace="com.whyc.mapper.BattWarehouseMapper" >
    <update id="updateBatchById">
    <update id="updateActivateBatchById">
        <foreach collection="list" item="item" index="index" separator=";">
            update tb_batt_warehouse
            <set>
@@ -17,4 +17,34 @@
            where id = #{item.id}
        </foreach>
    </update>
    <update id="updateChargeBatchById">
        <foreach collection="list" item="item" index="index" separator=";">
            update tb_batt_warehouse
            <set>
                <if test="item.chargeTaskNo != null">
                    charge_task_no = #{item.chargeTaskNo},
                </if>
                <if test="item.chargeOnPlan != null">
                    charge_on_plan = #{item.chargeOnPlan},
                </if>
            </set>
            where id = #{item.id}
        </foreach>
    </update>
    <update id="updateDischargeBatchById">
        <foreach collection="list" item="item" index="index" separator=";">
            update tb_batt_warehouse
            <set>
                <if test="item.dischargeTaskNo != null">
                    discharge_task_no = #{item.dischargeTaskNo},
                </if>
                <if test="item.dischargeOnPlan != null">
                    discharge_on_plan = #{item.dischargeOnPlan},
                </if>
            </set>
            where id = #{item.id}
        </foreach>
    </update>
</mapper>