| 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.baomidou.mybatisplus.mapper.Wrapper; | 
| import com.baomidou.mybatisplus.plugins.Page; | 
| import com.core.common.DateUtils; | 
| import com.zy.asrs.entity.BasShuttle; | 
| import com.zy.asrs.service.BasShuttleService; | 
| import com.core.annotations.ManagerAuth; | 
| 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.*; | 
|   | 
| @RestController | 
| public class BasShuttleController extends BaseController { | 
|   | 
|     @Autowired | 
|     private BasShuttleService basShuttleService; | 
|   | 
|     @Value("${wcs-slave.url}") | 
|     private String wcsUrl; | 
|   | 
|     @RequestMapping(value = "/basShuttle/{id}/auth") | 
|     @ManagerAuth | 
|     public R get(@PathVariable("id") String id) { | 
|         return R.ok(basShuttleService.selectById(String.valueOf(id))); | 
|     } | 
|   | 
|     @RequestMapping(value = "/basShuttle/list/auth") | 
|     @ManagerAuth | 
|     public R list(@RequestParam(defaultValue = "1")Integer curr, | 
|                   @RequestParam(defaultValue = "10")Integer limit, | 
|                   @RequestParam(required = false)String orderByField, | 
|                   @RequestParam(required = false)String orderByType, | 
|                   @RequestParam(required = false)String condition, | 
|                   @RequestParam Map<String, Object> param){ | 
|         EntityWrapper<BasShuttle> wrapper = new EntityWrapper<>(); | 
|         excludeTrash(param); | 
|         convert(param, wrapper); | 
|         allLike(BasShuttle.class, param.keySet(), wrapper, condition); | 
|         if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} | 
|         return R.ok(basShuttleService.selectPage(new Page<>(curr, limit), wrapper)); | 
|     } | 
|   | 
|     private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){ | 
|         for (Map.Entry<String, Object> entry : map.entrySet()){ | 
|             String val = String.valueOf(entry.getValue()); | 
|             if (val.contains(RANGE_TIME_LINK)){ | 
|                 String[] dates = val.split(RANGE_TIME_LINK); | 
|                 wrapper.ge(entry.getKey(), DateUtils.convert(dates[0])); | 
|                 wrapper.le(entry.getKey(), DateUtils.convert(dates[1])); | 
|             } else { | 
|                 wrapper.like(entry.getKey(), val); | 
|             } | 
|         } | 
|     } | 
|   | 
|     @RequestMapping(value = "/basShuttle/add/auth") | 
|     @ManagerAuth | 
|     public R add(BasShuttle basShuttle) { | 
|         basShuttleService.insert(basShuttle); | 
|         return R.ok(); | 
|     } | 
|   | 
|     @RequestMapping(value = "/basShuttle/update/auth") | 
|     @ManagerAuth | 
|     public R update(BasShuttle basShuttle){ | 
|         if (Cools.isEmpty(basShuttle) || null==basShuttle.getShuttleNo()){ | 
|             return R.error(); | 
|         } | 
|         basShuttleService.updateById(basShuttle); | 
|         return R.ok(); | 
|     } | 
|   | 
|     @RequestMapping(value = "/basShuttle/delete/auth") | 
|     @ManagerAuth | 
|     public R delete(@RequestParam(value="ids[]") Long[] ids){ | 
|          for (Long id : ids){ | 
|             basShuttleService.deleteById(id); | 
|         } | 
|         return R.ok(); | 
|     } | 
|   | 
|     @RequestMapping(value = "/basShuttle/export/auth") | 
|     @ManagerAuth | 
|     public R export(@RequestBody JSONObject param){ | 
|         EntityWrapper<BasShuttle> wrapper = new EntityWrapper<>(); | 
|         List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); | 
|         Map<String, Object> map = excludeTrash(param.getJSONObject("basShuttle")); | 
|         convert(map, wrapper); | 
|         List<BasShuttle> list = basShuttleService.selectList(wrapper); | 
|         return R.ok(exportSupport(list, fields)); | 
|     } | 
|   | 
|     @RequestMapping(value = "/basShuttleQuery/auth") | 
|     @ManagerAuth | 
|     public R query(String condition) { | 
|         EntityWrapper<BasShuttle> wrapper = new EntityWrapper<>(); | 
|         wrapper.like("shuttle_no", condition); | 
|         Page<BasShuttle> page = basShuttleService.selectPage(new Page<>(0, 10), wrapper); | 
|         List<Map<String, Object>> result = new ArrayList<>(); | 
|         for (BasShuttle basShuttle : page.getRecords()){ | 
|             Map<String, Object> map = new HashMap<>(); | 
|             map.put("id", basShuttle.getShuttleNo()); | 
|             map.put("value", basShuttle.getShuttleNo()); | 
|             result.add(map); | 
|         } | 
|         return R.ok(result); | 
|     } | 
|   | 
|     @RequestMapping(value = "/basShuttle/check/column/auth") | 
|     @ManagerAuth | 
|     public R query(@RequestBody JSONObject param) { | 
|         Wrapper<BasShuttle> wrapper = new EntityWrapper<BasShuttle>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val")); | 
|         if (null != basShuttleService.selectOne(wrapper)){ | 
|             return R.parse(BaseRes.REPEAT).add(getComment(BasShuttle.class, String.valueOf(param.get("key")))); | 
|         } | 
|         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(); | 
|         } | 
|     } | 
|   | 
| } |