|  |  |  | 
|---|
|  |  |  | package com.zy.asrs.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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.BaseRes; | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | import com.core.common.R; | 
|---|
|  |  |  | import com.zy.common.utils.HttpHandler; | 
|---|
|  |  |  | import com.zy.common.web.BaseController; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private BasShuttleService basShuttleService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Value("${wcs-slave.url}") | 
|---|
|  |  |  | private String wcsUrl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/basShuttle/{id}/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "/basShuttle/command/list/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R shuttleCommandQuery(@RequestParam Integer wrkNo) { | 
|---|
|  |  |  | HashMap<String, Object> hashMap = new HashMap<>(); | 
|---|
|  |  |  | hashMap.put("total", 0); | 
|---|
|  |  |  | hashMap.put("records", null); | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | HashMap<String, Object> map = new HashMap<>(); | 
|---|
|  |  |  | map.put("wrkNo", wrkNo); | 
|---|
|  |  |  | String response = new HttpHandler.Builder() | 
|---|
|  |  |  | .setUri(wcsUrl) | 
|---|
|  |  |  | .setPath("/shuttle/command/query") | 
|---|
|  |  |  | .setParams(map) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | Integer code = jsonObject.getInteger("code"); | 
|---|
|  |  |  | if (code.equals(200)) { | 
|---|
|  |  |  | JSONObject data = jsonObject.getJSONObject("data"); | 
|---|
|  |  |  | JSONObject assignCommand = data.getJSONObject("assignCommand"); | 
|---|
|  |  |  | JSONArray commands = assignCommand.getJSONArray("commands"); | 
|---|
|  |  |  | Integer commandStep = data.getInteger("commandStep");//当前步序 | 
|---|
|  |  |  | for (int i = 0; i < commands.size(); i++) { | 
|---|
|  |  |  | JSONObject object = commands.getJSONObject(i); | 
|---|
|  |  |  | object.put("commandStep", commandStep);//当前步序 | 
|---|
|  |  |  | commands.set(i, object); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | hashMap.put("total", commands.size()); | 
|---|
|  |  |  | hashMap.put("records", commands); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return R.ok().add(hashMap); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //回退命令 | 
|---|
|  |  |  | @RequestMapping(value = "/basShuttle/command/rollback/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R shuttleCommandRollback(@RequestBody JSONObject param) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | String response = new HttpHandler.Builder() | 
|---|
|  |  |  | .setUri(wcsUrl) | 
|---|
|  |  |  | .setPath("/shuttle/command/rollback") | 
|---|
|  |  |  | .setParams(param) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | Integer code = jsonObject.getInteger("code"); | 
|---|
|  |  |  | if (code.equals(200)) { | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //命令完成状态切换 | 
|---|
|  |  |  | @RequestMapping(value = "/basShuttle/command/completeSwitch/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R shuttleCommandCompleteSwitch(@RequestBody JSONObject param) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | String response = new HttpHandler.Builder() | 
|---|
|  |  |  | .setUri(wcsUrl) | 
|---|
|  |  |  | .setPath("/shuttle/command/completeSwitch") | 
|---|
|  |  |  | .setParams(param) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | Integer code = jsonObject.getInteger("code"); | 
|---|
|  |  |  | if (code.equals(200)) { | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //重启任务(命令) | 
|---|
|  |  |  | @RequestMapping(value = "/basShuttle/command/restart/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R shuttleCommandRestart(@RequestBody JSONObject param) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | String response = new HttpHandler.Builder() | 
|---|
|  |  |  | .setUri(wcsUrl) | 
|---|
|  |  |  | .setPath("/shuttle/command/restart") | 
|---|
|  |  |  | .setParams(param) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | Integer code = jsonObject.getInteger("code"); | 
|---|
|  |  |  | if (code.equals(200)) { | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.error("重启失败"); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //删除任务(命令) | 
|---|
|  |  |  | @RequestMapping(value = "/basShuttle/command/del/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R shuttleCommandDel(@RequestBody JSONObject param) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | String response = new HttpHandler.Builder() | 
|---|
|  |  |  | .setUri(wcsUrl) | 
|---|
|  |  |  | .setPath("/shuttle/command/del") | 
|---|
|  |  |  | .setParams(param) | 
|---|
|  |  |  | .build() | 
|---|
|  |  |  | .doPost(); | 
|---|
|  |  |  | JSONObject jsonObject = JSON.parseObject(response); | 
|---|
|  |  |  | Integer code = jsonObject.getInteger("code"); | 
|---|
|  |  |  | if (code.equals(200)) { | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.error("删除失败"); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | return R.error(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|