package com.zy.asrs.wcs.core.controller;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.zy.asrs.framework.common.Cools;
|
import com.zy.asrs.framework.common.R;
|
import com.zy.asrs.framework.common.SnowflakeIdWorker;
|
import com.zy.asrs.wcs.common.annotation.OperationLog;
|
import com.zy.asrs.wcs.common.domain.BaseParam;
|
import com.zy.asrs.wcs.common.domain.KeyValVo;
|
import com.zy.asrs.wcs.common.domain.PageParam;
|
import com.zy.asrs.wcs.core.domain.param.LiftOperatorParam;
|
import com.zy.asrs.wcs.core.entity.BasLift;
|
import com.zy.asrs.wcs.core.entity.Motion;
|
import com.zy.asrs.wcs.core.entity.Task;
|
import com.zy.asrs.wcs.core.entity.TaskCtg;
|
import com.zy.asrs.wcs.core.kernel.AnalyzeService;
|
import com.zy.asrs.wcs.core.model.enums.DeviceCtgType;
|
import com.zy.asrs.wcs.core.model.enums.TaskStsType;
|
import com.zy.asrs.wcs.core.service.BasLiftService;
|
import com.zy.asrs.wcs.core.service.MotionService;
|
import com.zy.asrs.wcs.core.service.TaskCtgService;
|
import com.zy.asrs.wcs.core.service.TaskService;
|
import com.zy.asrs.wcs.core.utils.Utils;
|
import com.zy.asrs.wcs.rcs.News;
|
import com.zy.asrs.wcs.rcs.cache.SlaveConnection;
|
import com.zy.asrs.wcs.rcs.entity.Device;
|
import com.zy.asrs.wcs.rcs.model.enums.LiftProtocolStatusType;
|
import com.zy.asrs.wcs.rcs.model.enums.SlaveType;
|
import com.zy.asrs.wcs.rcs.service.DeviceService;
|
import com.zy.asrs.wcs.rcs.thread.LiftThread;
|
import com.zy.asrs.wcs.system.controller.BaseController;
|
import com.zy.asrs.wcs.system.entity.Dict;
|
import com.zy.asrs.wcs.system.service.DictService;
|
import com.zy.asrs.wcs.utils.ExcelUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.util.*;
|
|
@RestController
|
@RequestMapping("/api")
|
public class BasLiftController extends BaseController {
|
|
@Autowired
|
private BasLiftService basLiftService;
|
@Autowired
|
private TaskCtgService taskCtgService;
|
@Autowired
|
private DeviceService deviceService;
|
@Autowired
|
private SnowflakeIdWorker snowflakeIdWorker;
|
@Autowired
|
private TaskService taskService;
|
@Autowired
|
private AnalyzeService analyzeService;
|
@Autowired
|
private MotionService motionService;
|
@Autowired
|
private DictService dictService;
|
|
@PreAuthorize("hasAuthority('core:basLift:list')")
|
@PostMapping("/basLift/page")
|
public R page(@RequestBody Map<String, Object> map) {
|
BaseParam baseParam = buildParam(map, BaseParam.class);
|
PageParam<BasLift, BaseParam> pageParam = new PageParam<>(baseParam, BasLift.class);
|
return R.ok().add(basLiftService.page(pageParam, pageParam.buildWrapper(true)));
|
}
|
|
@PreAuthorize("hasAuthority('core:basLift:list')")
|
@PostMapping("/basLift/list")
|
public R list(@RequestBody Map<String, Object> map) {
|
return R.ok().add(basLiftService.list());
|
}
|
|
@PreAuthorize("hasAuthority('core:basLift:list')")
|
@GetMapping("/basLift/{id}")
|
public R get(@PathVariable("id") Long id) {
|
return R.ok().add(basLiftService.getById(id));
|
}
|
|
@PreAuthorize("hasAuthority('core:basLift:save')")
|
@OperationLog("添加提升机列表")
|
@PostMapping("/basLift/save")
|
public R save(@RequestBody BasLift basLift) {
|
if (!basLiftService.save(basLift)) {
|
return R.error("添加失败");
|
}
|
return R.ok("添加成功");
|
}
|
|
@PreAuthorize("hasAuthority('core:basLift:update')")
|
@OperationLog("修改提升机列表")
|
@PostMapping("/basLift/update")
|
public R update(@RequestBody BasLift basLift) {
|
if (!basLiftService.updateById(basLift)) {
|
return R.error("修改失败");
|
}
|
return R.ok("修改成功");
|
}
|
|
@PreAuthorize("hasAuthority('core:basLift:remove')")
|
@OperationLog("删除提升机列表")
|
@PostMapping("/basLift/remove/{ids}")
|
public R remove(@PathVariable Long[] ids) {
|
if (!basLiftService.removeByIds(Arrays.asList(ids))) {
|
return R.error("删除失败");
|
}
|
return R.ok("删除成功");
|
}
|
|
@PreAuthorize("hasAuthority('core:basLift:list')")
|
@PostMapping("/basLift/query")
|
public R query(@RequestParam(required = false) String condition) {
|
List<KeyValVo> vos = new ArrayList<>();
|
LambdaQueryWrapper<BasLift> wrapper = new LambdaQueryWrapper<>();
|
if (!Cools.isEmpty(condition)) {
|
wrapper.like(BasLift::getLiftNo, condition);
|
}
|
basLiftService.page(new Page<>(1, 30), wrapper).getRecords().forEach(
|
item -> vos.add(new KeyValVo(item.getId(), item.getLiftNo()))
|
);
|
return R.ok().add(vos);
|
}
|
|
@PreAuthorize("hasAuthority('core:basLift:list')")
|
@PostMapping("/basLift/export")
|
public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception {
|
ExcelUtil.build(ExcelUtil.create(basLiftService.list(), BasLift.class), response);
|
}
|
|
//获取楼层
|
@PreAuthorize("hasAuthority('core:basLift:list')")
|
@PostMapping("/basLift/getMapLev")
|
public R getMapLev() {
|
List<Dict> dicts = dictService.list(new LambdaQueryWrapper<Dict>()
|
.like(Dict::getFlag, "map")
|
.eq(Dict::getStatus, 1));
|
return R.ok().add(dicts.size());
|
}
|
|
@PreAuthorize("hasAuthority('core:basLift:operator')")
|
@PostMapping("/basLift/operator/lift")
|
public R liftOperator(@RequestBody LiftOperatorParam param) {
|
if (Cools.isEmpty(param.getLiftNo())) {
|
return R.error("参数为空");
|
}
|
|
Integer liftNo = param.getLiftNo();
|
|
//获取手动任务类型
|
TaskCtg taskCtg = taskCtgService.getOne(new LambdaQueryWrapper<TaskCtg>()
|
.eq(TaskCtg::getFlag, "MANUAL")
|
.eq(TaskCtg::getStatus, 1));
|
if (taskCtg == null) {
|
return R.error();
|
}
|
|
Device device = deviceService.getOne(new LambdaQueryWrapper<Device>()
|
.eq(Device::getDeviceType, DeviceCtgType.LIFT.val())
|
.eq(Device::getStatus, 1)
|
.eq(Device::getDeviceNo, liftNo));
|
if (device == null) {
|
return R.error("设备不存在");
|
}
|
|
LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, device.getId().intValue());
|
if (liftThread == null) {
|
return R.error("设备离线");
|
}
|
|
if (param.getLiftTaskMode().equals("reset")) {
|
//提升机复位
|
liftThread.setSyncTaskNo(0);
|
liftThread.setProtocolStatus(LiftProtocolStatusType.IDLE);
|
return R.ok("复位成功");
|
}
|
|
Task task = new Task();
|
task.setUuid(String.valueOf(snowflakeIdWorker.nextId()));
|
task.setTaskNo(String.valueOf(Utils.getTaskNo("MANUAL")));
|
task.setTaskSts(TaskStsType.NEW_MANUAL.sts);
|
task.setTaskCtg(taskCtg.getId());
|
task.setPriority(10);
|
task.setOriginSite(null);
|
task.setOriginLoc(param.getSourceStaNo());
|
task.setDestSite(param.getLiftTaskMode());
|
task.setDestLoc(param.getStaNo());
|
task.setIoTime(new Date());
|
task.setStartTime(new Date());
|
task.setStatus(1);
|
task.setMemo("manual");
|
task.setLiftNo(liftNo);
|
boolean result = taskService.save(task);
|
if (!result) {
|
return R.error();
|
}
|
|
task = taskService.getById(task.getId());
|
|
// generate motion list
|
List<Motion> motionList = analyzeService.generateLiftManualMotion(task);
|
if (Cools.isEmpty(motionList)) {
|
News.error("保存{}提升机手动任务失败!!!", liftNo);
|
return R.error();
|
}
|
motionService.batchInsert(motionList, task.getUuid(), Integer.valueOf(task.getTaskNo()));
|
|
task.setTaskSts(TaskStsType.ANALYZE_MANUAL.sts);
|
if (!taskService.updateById(task)) {
|
News.error("保存{}提升机手动任务失败!!!", liftNo);
|
return R.error();
|
}
|
return R.ok();
|
}
|
|
}
|