package com.zy.asrs.task; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.core.common.Cools; import com.zy.asrs.entity.BasDevp; import com.zy.asrs.entity.BasShuttle; import com.zy.asrs.entity.TaskWrk; import com.zy.asrs.entity.param.GetShuttleStatusParam; import com.zy.asrs.entity.param.Result; import com.zy.asrs.service.ApiLogService; import com.zy.asrs.service.BasDevpService; import com.zy.asrs.service.BasShuttleService; import com.zy.common.utils.HttpHandler; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.io.IOException; import java.util.HashMap; import java.util.List; @Slf4j @Component public class GetshuttlerStatusScheduler { @Value("${wcs.urlWcs}") private String wcsUrl; @Value("${wcs.shuttleStatus}") private String shuttleStatus; @Autowired private ApiLogService apiLogService; @Autowired private BasShuttleService basShuttleService; /** * 获取rcs小车信息 * * @throws IOException */ @Scheduled(cron = "0/3 * * * * ? ") public void execute() throws IOException { String response = ""; Boolean bool = false; try { // log.info("wcs获取rcs小车信息"); response = new HttpHandler.Builder() // .setHeaders(headParam) .setUri(wcsUrl) .setPath(shuttleStatus) .setJson(JSON.toJSONString("")) .build() .doPost(); JSONObject jsonObject = JSON.parseObject(response); if (jsonObject.get("code").equals(200)) { JSONObject data = JSON.parseObject(jsonObject.get("data").toString()); List shuttles = JSON.parseArray(data.get("shuttle").toString(), GetShuttleStatusParam.class); for (GetShuttleStatusParam shuttle : shuttles) { //对小车二维码进行处理 Integer lev=1; //小车模式 Integer mode=0; //小车是否在充电 Integer autoCharge=0; if(!Cools.isEmpty(shuttle.getCurrentCode())){ JSONObject jsonObject1 = JSON.parseObject(shuttle.getCurrentCode()); lev=jsonObject1.getInteger("z"); } if(!Cools.isEmpty(shuttle.getMode())){ mode=shuttle.getMode(); } if(!Cools.isEmpty(shuttle.getHasCharge())&&shuttle.getHasCharge()){ mode=2; } BasShuttle shuttle1 = basShuttleService.selectOne(new EntityWrapper().eq("shuttle_no", shuttle.getShuttleNo())); shuttle1.setStatus(mode);//小车模式 shuttle1.setShuttleStatus(shuttle.getProtocolStatus());//小车状态 shuttle1.setDeviceStatus(shuttle.getProtocolStatus$());//小车状态中文版 shuttle1.setChargeLine(lev);//小车所在层 shuttle1.setErrorCode(shuttle.getErrorCode());//异常码 basShuttleService.updateById(shuttle1); } bool = true; } } catch (Exception e) { log.error("wcs获取小车状态失败"); } } }