| | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.vincent.rsf.framework.common.R; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.openApi.entity.dto.CommonResponse; |
| | | import com.vincent.rsf.openApi.entity.phyz.Task; |
| | | import com.vincent.rsf.openApi.feign.wms.WmsServerFeignClient; |
| | | import com.vincent.rsf.openApi.feign.wms.fallback.WmsServerFeignClientFallback; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | |
| | | @Slf4j |
| | | public class TaskController { |
| | | |
| | | @Autowired(required = false) |
| | | private WmsServerFeignClient wmsServerFeignClient; |
| | | |
| | | @ApiOperation("点对点创建AGV搬运任务") |
| | | @PostMapping("/agv/transTask/add") |
| | | public CommonResponse addAgvTask(@RequestBody Object objParams) { |
| | | if (Objects.isNull(objParams)) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | | // 返回模拟数据 |
| | | if (SIMULATED_DATA_ENABLE.equals("1")) { |
| | | return CommonResponse.ok(); |
| | | } |
| | | // // 返回模拟数据 |
| | | // if (SIMULATED_DATA_ENABLE.equals("1")) { |
| | | // return CommonResponse.ok(); |
| | | // } |
| | | |
| | | JSONArray params = paramsFormat(objParams); |
| | | List<Task> tasks = JSON.parseArray(params.toJSONString(), Task.class); |
| | | // 数据处理,转发server |
| | | int success = 0; |
| | | StringBuilder errorMsg = new StringBuilder(); |
| | | for (Task task : tasks) { |
| | | try { |
| | | if (wmsServerFeignClient == null) { |
| | | log.warn("WmsServerFeignClient未注入,无法进行调用"); |
| | | return CommonResponse.error("服务未初始化"); |
| | | } |
| | | |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("type", task.getPalletType()); |
| | | jsonObject.put("taskNo", task.getTaskNo()); |
| | | jsonObject.put("staNo", task.getEndStationId()); |
| | | jsonObject.put("taskOrigin", "mes"); |
| | | |
| | | log.info("mes下发agv运输任务参数: {}", JSON.toJSONString(jsonObject)); |
| | | |
| | | // 直接传递实体类,Feign会自动序列化为JSON |
| | | R result = wmsServerFeignClient.mesAddTask(jsonObject); |
| | | |
| | | log.info("mes下发agv运输任务返回结果: {}", JSON.toJSONString(result)); |
| | | |
| | | if (result != null) { |
| | | Integer code = (Integer) result.get("code"); |
| | | if (code != null && code == 200) { |
| | | success++; |
| | | } else { |
| | | errorMsg.append((String) result.get("msg")); |
| | | } |
| | | } else { |
| | | return CommonResponse.error("mes下发agv运输任务执行失败:返回结果为空"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("mes下发agv运输任务执行失败", e); |
| | | String errorMessage = WmsServerFeignClientFallback.filterErrorMessage(e); |
| | | errorMsg.append(errorMessage); |
| | | } |
| | | } |
| | | |
| | | if (success == tasks.size()) { |
| | | return CommonResponse.ok(); |
| | | } else { |
| | | return CommonResponse.error(errorMsg.toString()); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation("点对点取消AGV搬运任务") |
| | |
| | | if (Objects.isNull(objParams)) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | | // 返回模拟数据 |
| | | if (SIMULATED_DATA_ENABLE.equals("1")) { |
| | | return CommonResponse.ok(); |
| | | } |
| | | // // 返回模拟数据 |
| | | // if (SIMULATED_DATA_ENABLE.equals("1")) { |
| | | // return CommonResponse.ok(); |
| | | // } |
| | | |
| | | JSONArray params = paramsFormat(objParams); |
| | | List<Task> tasks = JSON.parseArray(params.toJSONString(), Task.class); |
| | | // 数据处理,转发server |
| | | int success = 0; |
| | | StringBuilder errorMsg = new StringBuilder(); |
| | | for (Task task : tasks) { |
| | | try { |
| | | if (wmsServerFeignClient == null) { |
| | | log.warn("WmsServerFeignClient未注入,无法进行调用"); |
| | | return CommonResponse.error("服务未初始化"); |
| | | } |
| | | |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("taskNo", task.getTaskNo()); |
| | | |
| | | log.info("mes取消agv运输任务参数: {}", JSON.toJSONString(jsonObject)); |
| | | |
| | | // 直接传递实体类,Feign会自动序列化为JSON |
| | | R result = wmsServerFeignClient.mesAddTask(jsonObject); |
| | | |
| | | log.info("mes取消agv运输任务返回结果: {}", JSON.toJSONString(result)); |
| | | |
| | | if (result != null) { |
| | | Integer code = (Integer) result.get("code"); |
| | | if (code != null && code == 200) { |
| | | success++; |
| | | } else { |
| | | errorMsg.append((String) result.get("msg")); |
| | | } |
| | | } else { |
| | | return CommonResponse.error("mes取消agv运输任务执行失败:返回结果为空"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("mes取消agv运输任务执行失败", e); |
| | | String errorMessage = WmsServerFeignClientFallback.filterErrorMessage(e); |
| | | errorMsg.append(errorMessage); |
| | | } |
| | | } |
| | | |
| | | if (success == tasks.size()) { |
| | | return CommonResponse.ok(); |
| | | } else { |
| | | return CommonResponse.error(errorMsg.toString()); |
| | | } |
| | | } |
| | | } |