New file |
| | |
| | | package com.whyc.schedule; |
| | | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.WmsPallet; |
| | | import com.whyc.dto.WmsPalletDto; |
| | | import com.whyc.dto.WmsResponse; |
| | | import com.whyc.pojo.db_wms.BattWarehouse; |
| | | import com.whyc.pojo.db_wms.Task; |
| | | import com.whyc.service.BattWarehouseService; |
| | | import com.whyc.service.TaskService; |
| | | import com.whyc.service.WmsService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 仓储系统的智能活化任务 |
| | | * 解释来源:任务的来源,在 发生 入库任务时,所入库的电池 就需要 活化. 以及在仓储库内的所有电池都需要活化.活化周期为每n月活化一次. |
| | | * 实现思路: |
| | | * 1.创建仓储库所有电池单体编号的库存表,写明入库时间和上次活化时间-数据的来源分为2部分,1-初始已在库的电池,2-测压入库的新入电池 |
| | | * 2.对于没有活化的电池单体,下发活化任务. |
| | | * 3.下发活化任务的选择: 每天早上9点,且没有正在进行的活化任务的时候. 对周期大于n月的单体进行任务下发 |
| | | */ |
| | | |
| | | @EnableScheduling |
| | | @Component |
| | | @Slf4j |
| | | public class WmsTaskSchedule { |
| | | |
| | | @Autowired |
| | | private BattWarehouseService battWarehouseService; |
| | | |
| | | @Autowired |
| | | private TaskService taskService; |
| | | |
| | | @Autowired |
| | | private WmsService wmsService; |
| | | |
| | | /**每天早上9点执行一次*/ |
| | | //@Scheduled(cron= "0 0 9 * * ?") |
| | | public void checkAndActivate() { |
| | | //查询数据库记录的仓库内所有的电池 |
| | | List<BattWarehouse> listInDB = battWarehouseService.getAll(); |
| | | List<BattWarehouse> listNew = new ArrayList<>(); |
| | | Date now = new Date(); |
| | | List<Integer> monIdListInDB = listInDB.stream().map(BattWarehouse::getMonId).collect(Collectors.toList()); |
| | | //查询当前实际存在的仓库内的所有电池 |
| | | Response palletList = wmsService.getPalletList(2, 4); |
| | | WmsResponse data = (WmsResponse) palletList.getData(); |
| | | if (palletList.getCode() == 1 && (data).getCode() == 0) { //查询到了所有库内电池 |
| | | List<WmsPallet> palletsNow = (List<WmsPallet>) data.getData(); |
| | | palletsNow.stream().forEach(item -> { |
| | | //palletCode就是电池单体编号 |
| | | if(!monIdListInDB.contains(Integer.valueOf(item.getPalletCode()))){ |
| | | BattWarehouse battWarehouse = new BattWarehouse(); |
| | | battWarehouse.setMonId(Integer.valueOf(item.getPalletCode())); |
| | | battWarehouse.setStorageTime(now); |
| | | battWarehouse.setOnPlan(0); |
| | | String volStr = item.getV().replace("v", ""); |
| | | int vol = Integer.parseInt(volStr); |
| | | battWarehouse.setVol(vol); |
| | | |
| | | listNew.add(battWarehouse); |
| | | } |
| | | }); |
| | | } |
| | | //不在数据库内的电池单体,保存 |
| | | if(listNew.size() > 0){ |
| | | battWarehouseService.addBatch(listNew); |
| | | } |
| | | |
| | | //查询需要活化的电池列表 |
| | | List<BattWarehouse> list = battWarehouseService.getActivateList(); |
| | | //通过电压进行分组list |
| | | Map<Integer, List<BattWarehouse>> mapToActivate = list.stream().collect(Collectors.groupingBy(BattWarehouse::getVol)); |
| | | Set<Integer> volSet = mapToActivate.keySet(); |
| | | //永远只对一类电压进行活化任务下发!!!因为连续下发活化,后续的会失败 |
| | | Integer vol; |
| | | String[] activateParameterStr = null; |
| | | if (volSet.size()>0){ |
| | | vol = volSet.iterator().next(); |
| | | list = mapToActivate.get(vol); |
| | | }else{ |
| | | //本次终止 |
| | | 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); |
| | | //活化参数设置 |
| | | //{ |
| | | // num: 1, // 电池编号 |
| | | // cap: 350, // 标称容量 |
| | | // vol: 200, // 电池类型-不可改动 |
| | | // dTime: 10, // 放电时间 900 |
| | | // dCurrent: 10, // 放电电流0.1A-需要根据容量实际设置 (实际容量/10) |
| | | // volLow: 1.8, // 组端电压下限0.001V |
| | | // dCap: 10, // 预放容量0.1AH-需要根据容量实际设置 等于实际容量 |
| | | // cTime: 10, // 充电时间 900 |
| | | // cCurrent: 10, // 充电电流0.1A-需要根据容量实际设置(实际容量/10) |
| | | // sCurrent: 5, // 截至电流0.1A-需要根据容量实际设置(实际容量/10/2) |
| | | // volHigh: 2.35, // 充电电压上限0.001V |
| | | // volFloat: 2.25, // 浮充电压0.001V |
| | | // cCap: 10, // 预充容量0.1AH-需要根据容量实际设置 等于实际容量 |
| | | // tTimes: 1, // 充放次数 |
| | | // standTime: 1, // 静置时间 |
| | | // startType: 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待提供 |
| | | 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待提供 |
| | | 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); |
| | | 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.setOnPlan(1); |
| | | item.setTaskNo(taskNoList.get(i)); |
| | | } |
| | | //批量更新BattWarehouse |
| | | battWarehouseService.updateBatchById(list); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |