psh
7 months ago
17 changed files with 1035 additions and 14 deletions
@ -0,0 +1,84 @@ |
|||
/** |
|||
* @author ls |
|||
* @date 2023/12/6 16:04 |
|||
*/ |
|||
package org.nl.common.base; |
|||
|
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class CommonFinalParam { |
|||
|
|||
public static final String DELETE = "0"; |
|||
/** |
|||
* 分隔符 |
|||
*/ |
|||
private final String BARRE = "-"; |
|||
private final String POINT = "."; |
|||
|
|||
public static final String ZERO = "0"; |
|||
public static final String ONE = "1"; |
|||
|
|||
public static final String TWO = "2"; |
|||
|
|||
public static final String THREE = "3"; |
|||
public static final String FOUR = "4"; |
|||
public static final String FIVE = "5"; |
|||
public static final String SIX = "6"; |
|||
public static final String SEVEN = "7"; |
|||
public static final String EIGHT = "8"; |
|||
public static final String NINE = "9"; |
|||
public static final String TEN = "10"; |
|||
public static final String ELEVEN = "11"; |
|||
|
|||
|
|||
/** |
|||
* 无货 |
|||
*/ |
|||
public static final int DEVICE_MOVE_ZERO = 0; |
|||
/** |
|||
* 设备联机等待 |
|||
*/ |
|||
public static final int DEVICE_MODE_TWO = 2; |
|||
/** |
|||
* 成功状态 |
|||
*/ |
|||
public static final int STATUS_OPEN = 200; |
|||
|
|||
/** |
|||
* 动作信号 |
|||
*/ |
|||
public static final int ACTION_ONE = 1; |
|||
public static final int ACTION_TWO = 2; |
|||
public static final int ACTION_THREE = 3; |
|||
|
|||
/** |
|||
* 申请任务type类型 |
|||
*/ |
|||
public static final String TYPE_ONE = "1"; |
|||
public static final String TYPE_TWO = "2"; |
|||
public static final String TYPE_THREE = "3"; |
|||
public static final String TYPE_FOUR = "4"; |
|||
public static final String TYPE_FIVE = "5"; |
|||
public static final String TYPE_SIX = "6"; |
|||
public static final String TYPE_SEVEN = "7"; |
|||
|
|||
|
|||
|
|||
|
|||
/** |
|||
* 切割点符号 |
|||
*/ |
|||
public static final String DOT = "."; |
|||
/** |
|||
* 切割横杠符号 |
|||
*/ |
|||
public static final String HYPHEN_ = "-"; |
|||
|
|||
|
|||
|
|||
/** |
|||
* 自动门 |
|||
*/ |
|||
public static final String DOORS = "doors"; |
|||
} |
@ -0,0 +1,74 @@ |
|||
package org.nl.common.enums; |
|||
|
|||
import cn.hutool.core.util.StrUtil; |
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Getter; |
|||
/** |
|||
* @author 20220102CG\noblelift |
|||
*/ |
|||
@Getter |
|||
@AllArgsConstructor |
|||
public enum TaskStatusEnum { |
|||
/** |
|||
* 任务状态 |
|||
*/ |
|||
READY("0", "READY", "就绪"), |
|||
BUSY("1", "BUSY", "执行中"), |
|||
FINISHED("2", "FINISHED", "完成"), |
|||
CANCEL("3", "CANCEL", "取消"), |
|||
FORCED_COMPLETION("4", "", "强制完成"), |
|||
ERROR("99", "ERROR", "异常"); |
|||
|
|||
/** |
|||
* 索引 |
|||
*/ |
|||
private String index; |
|||
/** |
|||
* 编码 |
|||
*/ |
|||
private String code; |
|||
/** |
|||
* 名字 |
|||
*/ |
|||
private String name; |
|||
/** |
|||
* 描述 |
|||
*/ |
|||
private String desc; |
|||
|
|||
/** |
|||
* 构造方法 |
|||
* @param index |
|||
* @param code |
|||
* @param name |
|||
*/ |
|||
TaskStatusEnum(String index, String code, String name) { |
|||
this.index = index; |
|||
this.code = code; |
|||
this.name = name; |
|||
|
|||
} |
|||
|
|||
public static JSONArray getList() { |
|||
JSONArray arr = new JSONArray(); |
|||
JSONObject json = new JSONObject(); |
|||
for (TaskStatusEnum em : TaskStatusEnum.values()) { |
|||
json.put("code", em.getCode()); |
|||
json.put("name", em.getName()); |
|||
arr.add(json); |
|||
} |
|||
return arr; |
|||
} |
|||
|
|||
public static String getName(String index) { |
|||
for (TaskStatusEnum c : TaskStatusEnum.values()) { |
|||
if (c.index.equals(index)) { |
|||
return c.name; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,26 @@ |
|||
package org.nl.hand.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @Author : TuQiang |
|||
* @create 2024/4/15 15:04 |
|||
*/ |
|||
@Data |
|||
public class HeadDeviceDto implements Serializable { |
|||
/** |
|||
* 设备号 |
|||
*/ |
|||
private String device_code; |
|||
|
|||
/** |
|||
* 操作类型 |
|||
* 0-禁止进出; |
|||
* 1-允许取放 |
|||
* 2-允许离开 |
|||
* |
|||
*/ |
|||
private String option; |
|||
} |
@ -0,0 +1,29 @@ |
|||
package org.nl.hand.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @Author : TuQiang |
|||
* @create 2024/4/2 16:54 |
|||
*/ |
|||
@Data |
|||
public class HeadDto implements Serializable { |
|||
|
|||
/** |
|||
* 起始设备编码 |
|||
*/ |
|||
private String start_device_code; |
|||
|
|||
/** |
|||
* 目标设备编码 |
|||
*/ |
|||
private String next_device_code; |
|||
|
|||
/** |
|||
* 任务类型 |
|||
*/ |
|||
private String task_type; |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package org.nl.hand.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @Author : TuQiang |
|||
* @create 2024/4/4 14:07 |
|||
*/ |
|||
@Data |
|||
public class HeadInstDto implements Serializable { |
|||
/** |
|||
* 关键字 可为载具号、指令号、agv车号 |
|||
*/ |
|||
private String keyword; |
|||
|
|||
/** |
|||
* 起始设备编码 |
|||
*/ |
|||
private String start_devicecode; |
|||
|
|||
/** |
|||
* 目标设备编码 |
|||
*/ |
|||
private String next_devicecode; |
|||
|
|||
/** |
|||
* 指令uuid |
|||
*/ |
|||
private String inst_uuid; |
|||
|
|||
/** |
|||
* 操作类型 |
|||
* 1 指令撤销 |
|||
* 2 重新下发 |
|||
* 3 强制完成 |
|||
*/ |
|||
private String type; |
|||
} |
@ -0,0 +1,39 @@ |
|||
package org.nl.hand.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @Author : TuQiang |
|||
* @create 2024/4/4 16:06 |
|||
*/ |
|||
@Data |
|||
public class HeadTaskDto implements Serializable { |
|||
/** |
|||
* 关键字 可为载具号、指令号、agv车号 |
|||
*/ |
|||
private String keyword; |
|||
|
|||
/** |
|||
* 起始设备编码 |
|||
*/ |
|||
private String start_devicecode; |
|||
|
|||
/** |
|||
* 目标设备编码 |
|||
*/ |
|||
private String next_devicecode; |
|||
|
|||
/** |
|||
* 任务uuid |
|||
*/ |
|||
private String task_uuid; |
|||
|
|||
/** |
|||
* 操作类型 |
|||
* 1 重新生成 |
|||
* 2 强制完成 |
|||
*/ |
|||
private String type; |
|||
} |
@ -0,0 +1,17 @@ |
|||
package org.nl.hand.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @Author : TuQiang |
|||
* @create 2024/4/2 16:50 |
|||
*/ |
|||
@Data |
|||
public class RegionDto implements Serializable { |
|||
/** |
|||
* 区域编号 |
|||
*/ |
|||
private String region_code; |
|||
} |
@ -0,0 +1,10 @@ |
|||
package org.nl.hand.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class TaskIdAndStatusDTO { |
|||
private String task_id; |
|||
|
|||
private String task_status; |
|||
} |
@ -0,0 +1,99 @@ |
|||
package org.nl.hand.rest; |
|||
|
|||
import cn.dev33.satoken.annotation.SaIgnore; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.nl.common.logging.annotation.Log; |
|||
import org.nl.hand.dto.HeadDto; |
|||
import org.nl.hand.dto.HeadInstDto; |
|||
import org.nl.hand.dto.HeadTaskDto; |
|||
import org.nl.hand.dto.RegionDto; |
|||
import org.nl.hand.service.HandService; |
|||
import org.nl.system.service.dict.dao.Dict; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.http.HttpStatus; |
|||
import org.springframework.http.ResponseEntity; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @Author : TuQiang |
|||
* @create 2024/4/2 10:18 |
|||
*/ |
|||
|
|||
@RestController |
|||
@RequiredArgsConstructor |
|||
@Api(tags = "手持接口") |
|||
@RequestMapping("/api/hand") |
|||
@Slf4j |
|||
public class HandController { |
|||
@Autowired |
|||
private HandService handService; |
|||
|
|||
@PostMapping("/queryArea") |
|||
@Log("查询区域") |
|||
@ApiOperation("查询区域") |
|||
@SaIgnore |
|||
//@PreAuthorize("@el.check('sect:list')")
|
|||
public ResponseEntity<Object> queryArea() { |
|||
return new ResponseEntity<>(handService.queryArea(), HttpStatus.OK); |
|||
} |
|||
|
|||
@PostMapping("/queryPointByArea") |
|||
@Log("根据区域编码查点位") |
|||
@ApiOperation("根据区域编码查点位") |
|||
@SaIgnore |
|||
//@PreAuthorize("@el.check('sect:list')")
|
|||
public ResponseEntity<Object> queryPointByArea(@RequestBody RegionDto dto) { |
|||
String region_code = dto.getRegion_code(); |
|||
return new ResponseEntity<>(handService.queryPointByArea(region_code), HttpStatus.OK); |
|||
} |
|||
|
|||
@PostMapping("/callTask") |
|||
@Log("手持创建任务") |
|||
@ApiOperation("手持创建任务") |
|||
@SaIgnore |
|||
//@PreAuthorize("@el.check('sect:list')")
|
|||
public ResponseEntity<Object> callTask(@RequestBody HeadDto dto) { |
|||
return new ResponseEntity<>(handService.callTask(dto), HttpStatus.OK); |
|||
} |
|||
|
|||
@PostMapping("/insts") |
|||
@Log("查询未完成指令") |
|||
@ApiOperation("查询未完成指令") |
|||
@SaIgnore |
|||
//@PreAuthorize("@el.check('sect:list')")
|
|||
public ResponseEntity<Object> queryInst(@RequestBody HeadInstDto dto) { |
|||
return new ResponseEntity<>(handService.queryInst(dto), HttpStatus.OK); |
|||
} |
|||
|
|||
@PostMapping("/inst") |
|||
@Log("指令操作") |
|||
@ApiOperation("指令操作") |
|||
@SaIgnore |
|||
//@PreAuthorize("@el.check('sect:list')")
|
|||
public ResponseEntity<Object> instOpt(@RequestBody HeadInstDto dto) throws Exception { |
|||
return new ResponseEntity<>(handService.instOpt(dto), HttpStatus.OK); |
|||
} |
|||
|
|||
@PostMapping("/tasks") |
|||
@Log("查询未完成指令") |
|||
@ApiOperation("查询未完成指令") |
|||
@SaIgnore |
|||
//@PreAuthorize("@el.check('sect:list')")
|
|||
public ResponseEntity<Object> querytasks(@RequestBody HeadTaskDto dto) { |
|||
return new ResponseEntity<>(handService.querytasks(dto), HttpStatus.OK); |
|||
} |
|||
|
|||
@PostMapping("/taskoperation") |
|||
@Log("指令操作") |
|||
@ApiOperation("指令操作") |
|||
@SaIgnore |
|||
//@PreAuthorize("@el.check('sect:list')")
|
|||
public ResponseEntity<Object> taskOperation(@RequestBody HeadTaskDto dto) throws Exception { |
|||
return new ResponseEntity<>(handService.taskOperation(dto), HttpStatus.OK); |
|||
} |
|||
} |
@ -0,0 +1,87 @@ |
|||
package org.nl.hand.rest; |
|||
|
|||
import cn.dev33.satoken.annotation.SaIgnore; |
|||
import cn.dev33.satoken.secure.SaSecureUtil; |
|||
import cn.dev33.satoken.stp.SaLoginModel; |
|||
import cn.dev33.satoken.stp.StpUtil; |
|||
import cn.hutool.core.util.ObjectUtil; |
|||
import com.alibaba.fastjson.JSON; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.nl.common.exception.BadRequestException; |
|||
import org.nl.common.utils.RsaUtils; |
|||
import org.nl.common.utils.dto.CurrentUser; |
|||
import org.nl.config.RsaProperties; |
|||
import org.nl.system.service.role.ISysRoleService; |
|||
import org.nl.system.service.secutiry.dto.AuthUserDto; |
|||
import org.nl.system.service.user.ISysUserService; |
|||
import org.nl.system.service.user.dao.SysUser; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.http.ResponseEntity; |
|||
import org.springframework.validation.annotation.Validated; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @Author : TuQiang |
|||
* @create 2024/4/2 16:00 |
|||
*/ |
|||
@Slf4j |
|||
@RestController |
|||
@RequestMapping("/api/pda") |
|||
public class MobileAuthorizationController { |
|||
@Autowired |
|||
private ISysUserService userService; |
|||
@Autowired |
|||
private ISysRoleService roleService; |
|||
|
|||
@PostMapping(value = "/handlogin") |
|||
@SaIgnore |
|||
public ResponseEntity<Object> login(@Validated @RequestBody AuthUserDto authUser, HttpServletRequest request) throws Exception { |
|||
// 密码解密 - 前端的加密规则: encrypt(根据实际更改)
|
|||
String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword()); |
|||
// 校验数据库
|
|||
// 根据用户名查询,在比对密码
|
|||
// 拿到多个已经抛出异常
|
|||
SysUser userInfo = userService.getOne(new LambdaQueryWrapper<SysUser>() |
|||
.eq(SysUser::getUsername, authUser.getUsername())); |
|||
// 这里需要密码加密
|
|||
if (ObjectUtil.isEmpty(userInfo) || !userInfo.getPassword().equals(SaSecureUtil.md5BySalt(password, "salt"))) { |
|||
throw new BadRequestException("账号或密码错误!"); |
|||
} |
|||
// 获取权限列表 - 登录查找权限
|
|||
List<String> permissionList = roleService.getPermissionList((JSONObject) JSON.toJSON(userInfo)); |
|||
|
|||
// 登录输入,登出删除
|
|||
CurrentUser user = new CurrentUser(); |
|||
user.setId(userInfo.getUser_id()); |
|||
user.setUsername(userInfo.getUsername()); |
|||
user.setPresonName(userInfo.getPerson_name()); |
|||
user.setUser(userInfo); |
|||
user.setPermissions(permissionList); |
|||
|
|||
// SaLoginModel 配置登录相关参数
|
|||
StpUtil.login(userInfo.getUser_id(), new SaLoginModel() |
|||
// 此次登录的客户端设备类型, 用于[同端互斥登录]时指定此次登录的设备类型
|
|||
.setDevice("PE") |
|||
// Token挂载的扩展参数 (此方法只有在集成jwt插件时才会生效)
|
|||
.setExtra("loginInfo", user) |
|||
); |
|||
|
|||
// 返回 token 与 用户信息
|
|||
JSONObject jsonObject = new JSONObject(); |
|||
jsonObject.put("user", userInfo); |
|||
JSONObject authInfo = new JSONObject(2) {{ |
|||
put("token", "Bearer " + StpUtil.getTokenValue()); |
|||
put("user", jsonObject); |
|||
}}; |
|||
|
|||
return ResponseEntity.ok(authInfo); |
|||
} |
|||
} |
@ -0,0 +1,36 @@ |
|||
package org.nl.hand.service; |
|||
|
|||
|
|||
import org.nl.hand.dto.HeadDto; |
|||
import org.nl.hand.dto.HeadInstDto; |
|||
import org.nl.hand.dto.HeadTaskDto; |
|||
|
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @Author : TuQiang |
|||
* @create 2024/4/2 10:19 |
|||
*/ |
|||
public interface HandService { |
|||
|
|||
|
|||
Map<String, Object> queryPointByArea(String region_code); |
|||
|
|||
/** |
|||
* 手持创建任务 |
|||
* |
|||
* @param dto |
|||
* @return |
|||
*/ |
|||
Map<String, Object> callTask(HeadDto dto); |
|||
|
|||
Map<String, Object> queryArea(); |
|||
|
|||
Map<String, Object> queryInst(HeadInstDto dto); |
|||
|
|||
Map<String, Object> instOpt(HeadInstDto dto) throws Exception; |
|||
|
|||
Map<String, Object> querytasks(HeadTaskDto dto); |
|||
|
|||
Map<String, Object> taskOperation(HeadTaskDto dto); |
|||
} |
@ -0,0 +1,459 @@ |
|||
package org.nl.hand.service.impl; |
|||
|
|||
import cn.hutool.core.bean.BeanUtil; |
|||
import cn.hutool.core.collection.CollectionUtil; |
|||
import cn.hutool.core.date.DateUtil; |
|||
import cn.hutool.core.util.IdUtil; |
|||
import cn.hutool.core.util.ObjectUtil; |
|||
import cn.hutool.core.util.StrUtil; |
|||
import com.alibaba.fastjson.JSON; |
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.nl.acs.agv.server.AgvService; |
|||
import org.nl.acs.agv.server.NDCAgvService; |
|||
import org.nl.acs.device.domain.Device; |
|||
import org.nl.acs.device.service.DeviceService; |
|||
import org.nl.acs.ext.wms.data.JsonUtl; |
|||
import org.nl.acs.instruction.domain.Instruction; |
|||
import org.nl.acs.instruction.domain.InstructionMybatis; |
|||
import org.nl.acs.instruction.service.InstructionService; |
|||
import org.nl.acs.instruction.service.dto.InstructionDto; |
|||
import org.nl.acs.opc.DeviceAppService; |
|||
import org.nl.acs.opc.DeviceAppServiceImpl; |
|||
import org.nl.acs.task.domain.Task; |
|||
import org.nl.acs.task.service.TaskService; |
|||
import org.nl.acs.task.service.dto.TaskDto; |
|||
import org.nl.common.base.CommonFinalParam; |
|||
import org.nl.common.enums.TaskStatusEnum; |
|||
import org.nl.common.exception.BadRequestException; |
|||
import org.nl.common.utils.CodeUtil; |
|||
import org.nl.config.SpringContextHolder; |
|||
import org.nl.hand.dto.HeadDto; |
|||
import org.nl.hand.dto.HeadInstDto; |
|||
import org.nl.hand.dto.HeadTaskDto; |
|||
import org.nl.hand.dto.TaskIdAndStatusDTO; |
|||
import org.nl.hand.service.HandService; |
|||
import org.nl.system.service.dict.ISysDictService; |
|||
import org.nl.system.service.dict.dao.Dict; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.http.HttpStatus; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.math.BigDecimal; |
|||
import java.util.ArrayList; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @Author : TuQiang |
|||
* @create 2024/4/2 10:20 |
|||
*/ |
|||
@Service |
|||
@RequiredArgsConstructor |
|||
@Slf4j |
|||
public class HandServiceImpl implements HandService { |
|||
|
|||
@Autowired |
|||
private DeviceService deviceService; |
|||
@Autowired |
|||
private TaskService taskserver; |
|||
@Autowired |
|||
private ISysDictService dictService; |
|||
@Autowired |
|||
private InstructionService instructionService; |
|||
@Autowired |
|||
NDCAgvService ndcAgvService; |
|||
@Autowired |
|||
DeviceAppService deviceAppService; |
|||
|
|||
|
|||
|
|||
@Override |
|||
public Map<String, Object> queryPointByArea(String region_code) { |
|||
JSONArray data = new JSONArray(); |
|||
if (StrUtil.isEmpty(region_code)) { |
|||
throw new BadRequestException("区域编码不能为空!"); |
|||
} |
|||
|
|||
//根据区域编码查询所有设备
|
|||
List<Device> list = deviceService.lambdaQuery() |
|||
.eq(Device::getRegion, region_code) |
|||
.list(); |
|||
if (CollectionUtil.isEmpty(list)) { |
|||
throw new BadRequestException("未查到该区域的设备!"); |
|||
} |
|||
for (int i = 0; i < list.size(); i++) { |
|||
JSONObject jo = new JSONObject(); |
|||
Device device = list.get(i); |
|||
String device_id = device.getDevice_id(); |
|||
String device_code = device.getDevice_code(); |
|||
String device_name = device.getDevice_name(); |
|||
BigDecimal seq_num = device.getSeq_num(); |
|||
jo.put("device_id", device_id); |
|||
jo.put("device_code", device_code); |
|||
jo.put("device_name", device_name); |
|||
jo.put("seq_num", seq_num); |
|||
data.add(jo); |
|||
} |
|||
JSONObject resultJson = new JSONObject(); |
|||
resultJson.put("message", "操作成功"); |
|||
resultJson.put("data", data); |
|||
return resultJson; |
|||
} |
|||
|
|||
@Override |
|||
public Map<String, Object> callTask(HeadDto dto) { |
|||
JSONArray errArr = new JSONArray(); |
|||
String start_device_code = dto.getStart_device_code(); |
|||
String next_device_code = dto.getNext_device_code(); |
|||
String task_type = dto.getTask_type(); |
|||
|
|||
if (StrUtil.isEmpty(start_device_code)) { |
|||
throw new BadRequestException("起点不能为空"); |
|||
} |
|||
if (StrUtil.isEmpty(next_device_code)) { |
|||
throw new BadRequestException("终点不能为空"); |
|||
} |
|||
if (StrUtil.isEmpty(task_type)) { |
|||
throw new BadRequestException("任务类型不能为空"); |
|||
} |
|||
|
|||
String start_device_code2 = ""; |
|||
String next_device_code2 = ""; |
|||
JSONObject jo = new JSONObject(); |
|||
if (StrUtil.equals(task_type, CommonFinalParam.TYPE_ONE)) { |
|||
String s = start_device_code.substring(start_device_code.length() - 1); |
|||
if (StrUtil.equals("K", s)) { |
|||
start_device_code2 = next_device_code.substring(0, next_device_code.length() - 1) + "M"; |
|||
next_device_code2 = start_device_code.substring(0, start_device_code.length() - 1) + "M"; |
|||
jo.put("start_device_code2", start_device_code2); |
|||
jo.put("next_device_code2", next_device_code2); |
|||
jo.put("start_point_code2", start_device_code2); |
|||
jo.put("next_point_code2", next_device_code2); |
|||
}else{ |
|||
throw new BadRequestException("起点设备名称不符"); |
|||
} |
|||
} else if (StrUtil.equals(task_type, CommonFinalParam.TYPE_TWO)) { |
|||
String s = start_device_code.substring(start_device_code.length() - 1); |
|||
String n = next_device_code.substring(next_device_code.length() - 1); |
|||
if (StrUtil.equals("M", s) && StrUtil.equals("M", n)) { |
|||
start_device_code2 = next_device_code.substring(0, next_device_code.length() - 1) + "K"; |
|||
next_device_code2 = start_device_code.substring(0, start_device_code.length() - 1) + "K"; |
|||
jo.put("start_device_code2", start_device_code2); |
|||
jo.put("next_device_code2", next_device_code2); |
|||
jo.put("start_point_code2", start_device_code2); |
|||
jo.put("next_point_code2", next_device_code2); |
|||
}else if(StrUtil.equals("S", n) && StrUtil.equals("M", s)){ |
|||
start_device_code2 = next_device_code.substring(0, next_device_code.length() - 1) + "X"; |
|||
next_device_code2 = start_device_code.substring(0, start_device_code.length() - 1) + "K"; |
|||
jo.put("start_device_code2", start_device_code2); |
|||
jo.put("next_device_code2", next_device_code2); |
|||
jo.put("start_point_code2", start_device_code2); |
|||
jo.put("next_point_code2", next_device_code2); |
|||
}else{ |
|||
throw new BadRequestException("起点设备名称不符"); |
|||
} |
|||
} |
|||
Device startDevice = deviceAppService.findDeviceByCode(start_device_code2); |
|||
Device nextDevice = deviceAppService.findDeviceByCode(next_device_code2); |
|||
if(StrUtil.isAllNotEmpty(start_device_code2,next_device_code2) && ObjectUtil.isAllEmpty(startDevice,nextDevice)){ |
|||
throw new BadRequestException("起点终点设备不存在"); |
|||
} |
|||
jo.put("start_device_code", start_device_code); |
|||
jo.put("next_device_code", next_device_code); |
|||
jo.put("start_point_code", start_device_code); |
|||
jo.put("next_point_code", next_device_code); |
|||
jo.put("task_type", task_type); |
|||
jo.put("agv_system_type", "2"); |
|||
jo.put("priority", "1"); |
|||
|
|||
TaskDto task_dto = jo.toJavaObject(TaskDto.class); |
|||
try { |
|||
taskserver.create(task_dto); |
|||
} catch (Exception e) { |
|||
// e.printStackTrace();
|
|||
JSONObject json = new JSONObject(); |
|||
json.put("message", e.getMessage()); |
|||
errArr.add(json); |
|||
throw new RuntimeException(e.getMessage()); |
|||
} |
|||
JSONArray data = new JSONArray(); |
|||
JSONObject resultJson = new JSONObject(); |
|||
if (ObjectUtil.isEmpty(errArr)) { |
|||
resultJson.put("message", "操作成功"); |
|||
resultJson.put("data", data); |
|||
} else { |
|||
resultJson.put("message", "操作失败"); |
|||
resultJson.put("data", data); |
|||
} |
|||
return resultJson; |
|||
} |
|||
|
|||
@Override |
|||
public Map<String, Object> queryArea() { |
|||
JSONArray data = new JSONArray(); |
|||
List<Dict> list = dictService.lambdaQuery() |
|||
.eq(Dict::getCode, "region_type") |
|||
.list(); |
|||
if (CollectionUtil.isEmpty(list)) { |
|||
throw new BadRequestException("未查到该区域的设备!"); |
|||
} |
|||
for (int i = 0; i < list.size(); i++) { |
|||
JSONObject jo = new JSONObject(); |
|||
Dict dict = list.get(i); |
|||
String region_id = dict.getDict_id(); |
|||
String region_code = dict.getValue(); |
|||
String region_name = dict.getLabel(); |
|||
jo.put("region_id", region_id); |
|||
jo.put("region_code", region_code); |
|||
jo.put("region_name", region_name); |
|||
data.add(jo); |
|||
} |
|||
JSONObject resultJson = new JSONObject(); |
|||
resultJson.put("message", "操作成功"); |
|||
resultJson.put("data", data); |
|||
return resultJson; |
|||
} |
|||
|
|||
@Override |
|||
public Map<String, Object> queryInst(HeadInstDto dto) { |
|||
//查询未完成的指令
|
|||
String key = dto.getKeyword(); |
|||
String start_point = dto.getStart_devicecode(); |
|||
String next_point = dto.getNext_devicecode(); |
|||
|
|||
List<InstructionMybatis> list; |
|||
if (StrUtil.isEmpty(key)&&StrUtil.isEmpty(start_point)&&StrUtil.isEmpty(next_point)){ |
|||
list = instructionService.lambdaQuery() |
|||
.orderByDesc(InstructionMybatis::getCreate_time) |
|||
.list(); |
|||
}else { |
|||
list = instructionService.lambdaQuery() |
|||
.like(InstructionMybatis::getStart_device_code, start_point) |
|||
.like(InstructionMybatis::getNext_device_code, next_point) |
|||
.ne(InstructionMybatis::getInstruction_status, "2") |
|||
.eq(InstructionMybatis::getInstruction_code, key) |
|||
.or() |
|||
.eq(InstructionMybatis::getCarno, key) |
|||
.or() |
|||
.eq(InstructionMybatis::getVehicle_code, key) |
|||
.orderByDesc(InstructionMybatis::getCreate_time) |
|||
.list(); |
|||
} |
|||
if (CollectionUtil.isEmpty(list)){ |
|||
throw new BadRequestException("没有指令存在!"); |
|||
} |
|||
JSONArray data = new JSONArray(); |
|||
for (int i = 0; i < list.size(); i++) { |
|||
JSONObject inst = new JSONObject(); |
|||
inst.put("inst_uuid",list.get(i).getInstruction_id()); |
|||
inst.put("task_no",list.get(i).getTask_code()); |
|||
inst.put("instruction_code",list.get(i).getInstruction_code()); |
|||
inst.put("start_devicecode",list.get(i).getStart_device_code()); |
|||
inst.put("next_devicecode",list.get(i).getNext_device_code()); |
|||
inst.put("inst_status",list.get(i).getInstruction_status()); |
|||
inst.put("inst_status_name", TaskStatusEnum.getName(list.get(i).getInstruction_status())); |
|||
inst.put("carrier",list.get(i).getVehicle_code()==null?"":list.get(i).getVehicle_code()); |
|||
inst.put("inst_step",list.get(i).getExecute_message()==null?"":list.get(i).getExecute_message()); |
|||
inst.put("priority",list.get(i).getPriority()); |
|||
inst.put("create_time",list.get(i).getCreate_time()); |
|||
inst.put("carno",list.get(i).getCarno()==null?"":list.get(i).getCarno()); |
|||
data.add(inst); |
|||
} |
|||
JSONObject resultJson = new JSONObject(); |
|||
resultJson.put("message", "操作成功"); |
|||
resultJson.put("data", data); |
|||
return resultJson; |
|||
} |
|||
|
|||
@Override |
|||
public Map<String, Object> instOpt(HeadInstDto dto) throws Exception { |
|||
JSONObject resultJson = new JSONObject(); |
|||
JSONArray data = new JSONArray(); |
|||
String type = dto.getType(); |
|||
String inst_uuid = dto.getInst_uuid(); |
|||
InstructionMybatis instruction= instructionService.lambdaQuery() |
|||
.eq(InstructionMybatis::getInstruction_id, inst_uuid) |
|||
.one(); |
|||
if(instruction==null){ |
|||
resultJson.put("message", "未找到该指令!"); |
|||
resultJson.put("data", data); |
|||
return resultJson; |
|||
} |
|||
if (StrUtil.equals(instruction.getInstruction_status(),"2")|| |
|||
StrUtil.equals(instruction.getInstruction_status(),"3")){ |
|||
resultJson.put("message", "指令已完成或已取消,无法操作!"); |
|||
resultJson.put("data", data); |
|||
return resultJson; |
|||
} |
|||
|
|||
/* 1 指令撤销 |
|||
2 重新下发 |
|||
3 强制完成*/ |
|||
if ("1".equals(type)){ |
|||
try { |
|||
if (StrUtil.isEmpty(instruction.getAgv_jobno())){ |
|||
instructionService.cancelNOSendAgv(inst_uuid); |
|||
}else { |
|||
ndcAgvService.deleteAgvInstToNDC(BeanUtil.copyProperties(instruction, Instruction.class)); |
|||
} |
|||
} catch (Exception e) { |
|||
resultJson.put("message", "下发agv失败!"); |
|||
resultJson.put("data", data); |
|||
return resultJson; |
|||
} |
|||
}else if ("2".equals(type)){ |
|||
try { |
|||
ndcAgvService.sendAgvInstToNDC(instruction.getAgv_system_type(),BeanUtil.copyProperties(instruction, Instruction.class)); |
|||
} catch (Exception e) { |
|||
resultJson.put("message", "下发agv失败!"); |
|||
resultJson.put("data", data); |
|||
return resultJson; |
|||
} |
|||
}else if ("3".equals(type)){ |
|||
try { |
|||
instructionService.finish(inst_uuid); |
|||
} catch (Exception e) { |
|||
resultJson.put("message", e.getMessage()); |
|||
resultJson.put("data", data); |
|||
return resultJson; |
|||
} |
|||
} |
|||
|
|||
resultJson.put("message", "操作成功"); |
|||
resultJson.put("data", data); |
|||
return resultJson; |
|||
} |
|||
|
|||
@Override |
|||
public Map<String, Object> querytasks(HeadTaskDto dto) { |
|||
String key = dto.getKeyword(); |
|||
String start_point = dto.getStart_devicecode(); |
|||
String next_point = dto.getNext_devicecode(); |
|||
|
|||
List<Task> list; |
|||
if (StrUtil.isEmpty(key)&&StrUtil.isEmpty(start_point)&&StrUtil.isEmpty(next_point)){ |
|||
list = taskserver.lambdaQuery() |
|||
.orderByDesc(Task::getCreate_time) |
|||
.list(); |
|||
}else { |
|||
list = taskserver.lambdaQuery() |
|||
.like(Task::getStart_device_code, start_point) |
|||
.like(Task::getNext_device_code, next_point) |
|||
.lt(Task::getTask_status, "2") |
|||
.eq(Task::getTask_code, key) |
|||
.or() |
|||
.eq(Task::getVehicle_code, key) |
|||
.or() |
|||
.eq(Task::getTask_id, key) |
|||
.orderByDesc(Task::getCreate_time) |
|||
.list(); |
|||
} |
|||
if (CollectionUtil.isEmpty(list)){ |
|||
throw new BadRequestException("没有指令存在!"); |
|||
} |
|||
JSONArray data = new JSONArray(); |
|||
for (int i = 0; i < list.size(); i++) { |
|||
JSONObject task = new JSONObject(); |
|||
task.put("task_uuid",list.get(i).getTask_id()); |
|||
task.put("task_no",list.get(i).getTask_code()); |
|||
task.put("start_devicecode",list.get(i).getStart_device_code()); |
|||
task.put("next_devicecode",list.get(i).getNext_device_code()); |
|||
task.put("task_status",list.get(i).getTask_status()); |
|||
task.put("task_status_name", TaskStatusEnum.getName(list.get(i).getTask_status())); |
|||
task.put("priority",list.get(i).getPriority()); |
|||
task.put("create_time",list.get(i).getCreate_time()); |
|||
task.put("carrier",list.get(i).getVehicle_code()==null?"":list.get(i).getVehicle_code()); |
|||
data.add(task); |
|||
} |
|||
JSONObject resultJson = new JSONObject(); |
|||
resultJson.put("message", "操作成功"); |
|||
resultJson.put("data", data); |
|||
return resultJson; |
|||
} |
|||
|
|||
@Override |
|||
public Map<String, Object> taskOperation(HeadTaskDto dto) { |
|||
JSONObject resultJson = new JSONObject(); |
|||
JSONArray data = new JSONArray(); |
|||
String type = dto.getType(); |
|||
String task_uuid = dto.getTask_uuid(); |
|||
if (StrUtil.isEmpty(type)){ |
|||
throw new BadRequestException("操作类型不能为空!"); |
|||
} |
|||
if (StrUtil.isEmpty(task_uuid)){ |
|||
throw new BadRequestException("id不能为空!"); |
|||
} |
|||
TaskDto taskDto = taskserver.findById(task_uuid); |
|||
if (BeanUtil.isEmpty(taskDto)){ |
|||
throw new BadRequestException("任务为空!"); |
|||
} |
|||
String task_code = taskDto.getTask_code(); |
|||
String start_device_code = taskDto.getStart_device_code(); |
|||
String next_device_code = taskDto.getNext_device_code(); |
|||
String task_id = taskDto.getTask_id(); |
|||
|
|||
if(StrUtil.equals(taskDto.getTask_status(),"2")||StrUtil.equals(taskDto.getTask_status(),"3")){ |
|||
resultJson.put("message", "任务已完成或已取消,无法操作"); |
|||
resultJson.put("data", data); |
|||
return resultJson; |
|||
} |
|||
if ("1".equals(type)){ |
|||
//重新生成指令
|
|||
Instruction instdto = new Instruction(); |
|||
instdto.setInstruction_id(IdUtil.simpleUUID()); |
|||
instdto.setInstruction_code(CodeUtil.getNewCode("INSTRUCT_NO")); |
|||
instdto.setRemark(taskDto.getRemark()); |
|||
instdto.setMaterial(taskDto.getMaterial()); |
|||
instdto.setTask_id(task_id); |
|||
instdto.setTask_code(task_code); |
|||
instdto.setVehicle_code(taskDto.getVehicle_code()); |
|||
String now = DateUtil.now(); |
|||
instdto.setCreate_time(now); |
|||
instdto.setCreate_by("auto"); |
|||
instdto.setStart_point_code(taskDto.getStart_point_code()); |
|||
instdto.setNext_point_code(taskDto.getNext_point_code()); |
|||
instdto.setStart_device_code(start_device_code); |
|||
instdto.setNext_device_code(next_device_code); |
|||
instdto.setInstruction_status("0"); |
|||
InstructionMybatis instructionMybatis = instructionService.lambdaQuery() |
|||
.eq(InstructionMybatis::getStart_device_code, start_device_code) |
|||
.eq(InstructionMybatis::getNext_device_code, next_device_code) |
|||
.lt(InstructionMybatis::getInstruction_status, "2") |
|||
.eq(InstructionMybatis::getTask_id,task_uuid) |
|||
.one(); |
|||
if (BeanUtil.isNotEmpty(instructionMybatis)){ |
|||
resultJson.put("message", task_code + ":该任务已存在待完成指令!"); |
|||
resultJson.put("data", data); |
|||
return resultJson; |
|||
} |
|||
try{ |
|||
instructionService.create(instdto); |
|||
} catch (Exception e){ |
|||
resultJson.put("message", e.getMessage()); |
|||
resultJson.put("data", data); |
|||
return resultJson; |
|||
} |
|||
instdto.setExecute_code(start_device_code); |
|||
}else if ("2".equals(type)){ |
|||
//强制完成
|
|||
Instruction instruction = instructionService.findByTaskid(task_uuid, "instruction_status <2 "); |
|||
if (instruction!=null){ |
|||
resultJson.put("message", "有指令未完成!"); |
|||
resultJson.put("data", data); |
|||
return resultJson; |
|||
} |
|||
TaskIdAndStatusDTO taskIdAndStatusDTO = new TaskIdAndStatusDTO(); |
|||
taskIdAndStatusDTO.setTask_id(task_uuid); |
|||
taskIdAndStatusDTO.setTask_status(TaskStatusEnum.FINISHED.getIndex()); |
|||
taskserver.finish(task_uuid); |
|||
} |
|||
resultJson.put("message", "操作成功"); |
|||
resultJson.put("data", data); |
|||
return resultJson; |
|||
} |
|||
} |
Loading…
Reference in new issue