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.BasLift; import com.zy.asrs.service.BasLiftService; 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 BasLiftController extends BaseController { @Autowired private BasLiftService basLiftService; @Value("${wcs-slave.url}") private String wcsUrl; @RequestMapping(value = "/basLift/{id}/auth") @ManagerAuth public R get(@PathVariable("id") String id) { return R.ok(basLiftService.selectById(String.valueOf(id))); } @RequestMapping(value = "/basLift/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 param){ EntityWrapper wrapper = new EntityWrapper<>(); excludeTrash(param); convert(param, wrapper); allLike(BasLift.class, param.keySet(), wrapper, condition); if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} return R.ok(basLiftService.selectPage(new Page<>(curr, limit), wrapper)); } private void convert(Map map, EntityWrapper wrapper){ for (Map.Entry 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 = "/basLift/add/auth") @ManagerAuth public R add(BasLift basLift) { basLiftService.insert(basLift); return R.ok(); } @RequestMapping(value = "/basLift/update/auth") @ManagerAuth public R update(BasLift basLift){ if (Cools.isEmpty(basLift) || null==basLift.getLiftNo()){ return R.error(); } basLiftService.updateById(basLift); return R.ok(); } @RequestMapping(value = "/basLift/delete/auth") @ManagerAuth public R delete(@RequestParam(value="ids[]") Long[] ids){ for (Long id : ids){ basLiftService.deleteById(id); } return R.ok(); } @RequestMapping(value = "/basLift/export/auth") @ManagerAuth public R export(@RequestBody JSONObject param){ EntityWrapper wrapper = new EntityWrapper<>(); List fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); Map map = excludeTrash(param.getJSONObject("basLift")); convert(map, wrapper); List list = basLiftService.selectList(wrapper); return R.ok(exportSupport(list, fields)); } @RequestMapping(value = "/basLiftQuery/auth") @ManagerAuth public R query(String condition) { EntityWrapper wrapper = new EntityWrapper<>(); wrapper.like("lift_no", condition); Page page = basLiftService.selectPage(new Page<>(0, 10), wrapper); List> result = new ArrayList<>(); for (BasLift basLift : page.getRecords()){ Map map = new HashMap<>(); map.put("id", basLift.getLiftNo()); map.put("value", basLift.getLiftNo()); result.add(map); } return R.ok(result); } @RequestMapping(value = "/basLift/check/column/auth") @ManagerAuth public R query(@RequestBody JSONObject param) { Wrapper wrapper = new EntityWrapper().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val")); if (null != basLiftService.selectOne(wrapper)){ return R.parse(BaseRes.REPEAT).add(getComment(BasLift.class, String.valueOf(param.get("key")))); } return R.ok(); } @RequestMapping(value = "/basLift/command/list/auth") @ManagerAuth public R liftCommandQuery(@RequestParam Integer wrkNo) { HashMap hashMap = new HashMap<>(); hashMap.put("total", 0); hashMap.put("records", null); try { HashMap map = new HashMap<>(); map.put("wrkNo", wrkNo); String response = new HttpHandler.Builder() .setUri(wcsUrl) .setPath("/lift/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 = "/basLift/command/rollback/auth") @ManagerAuth public R liftCommandRollback(@RequestBody JSONObject param) { try { String response = new HttpHandler.Builder() .setUri(wcsUrl) .setPath("/lift/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 = "/basLift/command/completeSwitch/auth") @ManagerAuth public R liftCommandCompleteSwitch(@RequestBody JSONObject param) { try { String response = new HttpHandler.Builder() .setUri(wcsUrl) .setPath("/lift/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 = "/basLift/command/restart/auth") @ManagerAuth public R liftCommandRestart(@RequestBody JSONObject param) { try { String response = new HttpHandler.Builder() .setUri(wcsUrl) .setPath("/lift/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 = "/basLift/command/del/auth") @ManagerAuth public R liftCommandDel(@RequestBody JSONObject param) { try { String response = new HttpHandler.Builder() .setUri(wcsUrl) .setPath("/lift/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(); } } }