| | |
| | | import com.alibaba.fastjson.TypeReference; |
| | | import com.zy.acs.framework.common.Cools; |
| | | import com.zy.acs.framework.common.R; |
| | | import com.zy.acs.framework.common.SnowflakeIdWorker; |
| | | import com.zy.acs.manager.common.config.UplinkProperties; |
| | | import com.zy.acs.manager.common.constant.Constants; |
| | | import com.zy.acs.manager.common.utils.HttpGo; |
| | | import com.zy.acs.manager.core.domain.type.NamespaceType; |
| | | import com.zy.acs.manager.core.integrate.dto.HttpResult; |
| | | import com.zy.acs.manager.core.integrate.dto.TaskUplinkParam; |
| | | import com.zy.acs.manager.core.service.ThreadPoolRegulator; |
| | | import com.zy.acs.manager.manager.entity.Bus; |
| | | import com.zy.acs.manager.manager.entity.IntegrationRecord; |
| | | import com.zy.acs.manager.manager.entity.Task; |
| | | import com.zy.acs.manager.manager.enums.IntegrationDirectionType; |
| | | import com.zy.acs.manager.manager.enums.StatusType; |
| | | import com.zy.acs.manager.manager.enums.TaskStsType; |
| | | import com.zy.acs.manager.manager.enums.TaskUplinkStateType; |
| | | import com.zy.acs.manager.manager.service.BusService; |
| | | import com.zy.acs.manager.manager.service.IntegrationRecordService; |
| | | import com.zy.acs.manager.manager.service.TaskService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.time.Duration; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.concurrent.CompletableFuture; |
| | |
| | | private ThreadPoolRegulator threadPoolRegulator; |
| | | @Autowired |
| | | private BusService busService; |
| | | @Autowired |
| | | private SnowflakeIdWorker snowflakeIdWorker; |
| | | @Autowired |
| | | private IntegrationRecordService integrationRecordService; |
| | | |
| | | private HttpGo http; |
| | | |
| | |
| | | ) { |
| | | return false; |
| | | } |
| | | |
| | | Date now = new Date(); |
| | | // block |
| | | // Future<R> future = threadPoolRegulator.getInstance().submit(() -> { |
| | | // mapDataDispatcher.modifyDynamicMatrix(null, null, param.getAgvNo(), true); |
| | |
| | | // params |
| | | TaskUplinkParam param = new TaskUplinkParam(); |
| | | if (null != task.getBusId()) { |
| | | Bus bus = busService.getById(task); |
| | | Bus bus = busService.getById(task.getBusId()); |
| | | param.setBatchNo(bus.getBusNo()); |
| | | } |
| | | param.setTaskNo(task.getSeqNum()); |
| | | param.setTimestamp(null == task.getEndTime() ? System.currentTimeMillis() : task.getEndTime().getTime()); |
| | | |
| | | IntegrationRecord integrationRecord = new IntegrationRecord( |
| | | String.valueOf(snowflakeIdWorker.nextId()).substring(3), // 编号 |
| | | NamespaceType.RCS_TASK_REPORT.desc, // 名称空间 |
| | | uplinkProperties.getUrl(), // 接口地址 |
| | | null, // 平台密钥 |
| | | Constants.RCS, // 调用方标识 |
| | | IntegrationDirectionType.OUTBOUND.value, // 方向[非空] |
| | | String.valueOf(now.getTime()), // 时间戳 |
| | | uplinkProperties.getHost(), // 客户端IP |
| | | JSON.toJSONString(param), // 请求内容 |
| | | null, // 响应内容 |
| | | null, // 异常内容 |
| | | 0, // 结果 |
| | | null, // 耗时 |
| | | StatusType.ENABLE.val, // 状态 |
| | | now, // 添加时间[非空] |
| | | now, // 修改时间[非空] |
| | | null // 备注 |
| | | ); |
| | | HttpResult<?> result; |
| | | try { |
| | | result = postForResult(url, headers, param); |
| | | integrationRecord.setResponse(JSON.toJSONString(result)); |
| | | |
| | | Integer code = result.getCode(); |
| | | if (null == code || 200 != code) { |
| | | return false; |
| | |
| | | // if (Cools.isEmpty(data)) { |
| | | // return false; |
| | | // } |
| | | |
| | | integrationRecord.setResult(1); |
| | | } catch (Exception e) { |
| | | log.error("Uplink report failed, taskId={}", |
| | | JSON.toJSONString(task), |
| | | e); |
| | | integrationRecord.setErr(e.getMessage()); |
| | | return false; |
| | | } finally { |
| | | integrationRecord.setCostMs((int) (System.currentTimeMillis() - now.getTime())); |
| | | integrationRecordService.syncRecord(integrationRecord); |
| | | } |
| | | return true; |
| | | } |