diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/common/base/CommonFinalParam.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/common/base/CommonFinalParam.java new file mode 100644 index 0000000..d75199c --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/common/base/CommonFinalParam.java @@ -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"; +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/common/enums/TaskStatusEnum.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/common/enums/TaskStatusEnum.java new file mode 100644 index 0000000..693c4f0 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/common/enums/TaskStatusEnum.java @@ -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; + } + +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/HeadDeviceDto.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/HeadDeviceDto.java new file mode 100644 index 0000000..7fe53c2 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/HeadDeviceDto.java @@ -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; +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/HeadDto.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/HeadDto.java new file mode 100644 index 0000000..35bc4b7 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/HeadDto.java @@ -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; + +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/HeadInstDto.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/HeadInstDto.java new file mode 100644 index 0000000..a061a14 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/HeadInstDto.java @@ -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; +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/HeadTaskDto.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/HeadTaskDto.java new file mode 100644 index 0000000..89ff13c --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/HeadTaskDto.java @@ -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; +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/RegionDto.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/RegionDto.java new file mode 100644 index 0000000..9d3ea03 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/RegionDto.java @@ -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; +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/TaskIdAndStatusDTO.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/TaskIdAndStatusDTO.java new file mode 100644 index 0000000..6328d1e --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/TaskIdAndStatusDTO.java @@ -0,0 +1,10 @@ +package org.nl.hand.dto; + +import lombok.Data; + +@Data +public class TaskIdAndStatusDTO { + private String task_id; + + private String task_status; +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/rest/HandController.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/rest/HandController.java new file mode 100644 index 0000000..c77b078 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/rest/HandController.java @@ -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 queryArea() { + return new ResponseEntity<>(handService.queryArea(), HttpStatus.OK); + } + + @PostMapping("/queryPointByArea") + @Log("根据区域编码查点位") + @ApiOperation("根据区域编码查点位") + @SaIgnore + //@PreAuthorize("@el.check('sect:list')") + public ResponseEntity 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 callTask(@RequestBody HeadDto dto) { + return new ResponseEntity<>(handService.callTask(dto), HttpStatus.OK); + } + + @PostMapping("/insts") + @Log("查询未完成指令") + @ApiOperation("查询未完成指令") + @SaIgnore + //@PreAuthorize("@el.check('sect:list')") + public ResponseEntity queryInst(@RequestBody HeadInstDto dto) { + return new ResponseEntity<>(handService.queryInst(dto), HttpStatus.OK); + } + + @PostMapping("/inst") + @Log("指令操作") + @ApiOperation("指令操作") + @SaIgnore + //@PreAuthorize("@el.check('sect:list')") + public ResponseEntity 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 querytasks(@RequestBody HeadTaskDto dto) { + return new ResponseEntity<>(handService.querytasks(dto), HttpStatus.OK); + } + + @PostMapping("/taskoperation") + @Log("指令操作") + @ApiOperation("指令操作") + @SaIgnore + //@PreAuthorize("@el.check('sect:list')") + public ResponseEntity taskOperation(@RequestBody HeadTaskDto dto) throws Exception { + return new ResponseEntity<>(handService.taskOperation(dto), HttpStatus.OK); + } +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/rest/MobileAuthorizationController.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/rest/MobileAuthorizationController.java new file mode 100644 index 0000000..43919da --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/rest/MobileAuthorizationController.java @@ -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 login(@Validated @RequestBody AuthUserDto authUser, HttpServletRequest request) throws Exception { + // 密码解密 - 前端的加密规则: encrypt(根据实际更改) + String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword()); + // 校验数据库 + // 根据用户名查询,在比对密码 + // 拿到多个已经抛出异常 + SysUser userInfo = userService.getOne(new LambdaQueryWrapper() + .eq(SysUser::getUsername, authUser.getUsername())); + // 这里需要密码加密 + if (ObjectUtil.isEmpty(userInfo) || !userInfo.getPassword().equals(SaSecureUtil.md5BySalt(password, "salt"))) { + throw new BadRequestException("账号或密码错误!"); + } + // 获取权限列表 - 登录查找权限 + List 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); + } +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/service/HandService.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/service/HandService.java new file mode 100644 index 0000000..1260ee7 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/service/HandService.java @@ -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 queryPointByArea(String region_code); + + /** + * 手持创建任务 + * + * @param dto + * @return + */ + Map callTask(HeadDto dto); + + Map queryArea(); + + Map queryInst(HeadInstDto dto); + + Map instOpt(HeadInstDto dto) throws Exception; + + Map querytasks(HeadTaskDto dto); + + Map taskOperation(HeadTaskDto dto); +} diff --git a/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/service/impl/HandServiceImpl.java b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/service/impl/HandServiceImpl.java new file mode 100644 index 0000000..874bb62 --- /dev/null +++ b/acs/nladmin-system/nlsso-server/src/main/java/org/nl/hand/service/impl/HandServiceImpl.java @@ -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 queryPointByArea(String region_code) { + JSONArray data = new JSONArray(); + if (StrUtil.isEmpty(region_code)) { + throw new BadRequestException("区域编码不能为空!"); + } + + //根据区域编码查询所有设备 + List 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 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 queryArea() { + JSONArray data = new JSONArray(); + List 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 queryInst(HeadInstDto dto) { + //查询未完成的指令 + String key = dto.getKeyword(); + String start_point = dto.getStart_devicecode(); + String next_point = dto.getNext_devicecode(); + + List 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 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 querytasks(HeadTaskDto dto) { + String key = dto.getKeyword(); + String start_point = dto.getStart_devicecode(); + String next_point = dto.getNext_devicecode(); + + List 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 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; + } +} diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/mes/controller/MesController.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/mes/controller/MesController.java index e69db1d..55ba987 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/mes/controller/MesController.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/mes/controller/MesController.java @@ -96,6 +96,8 @@ public class MesController { List qpmes098ResponseBodyArrayList=new ArrayList<>(); PdmBdWorkorder entity = new PdmBdWorkorder(); if("1".equals(qpmes098Request.getBODY().get(0).getZSTAT())) { + //先删除原来的工单信息,再新增,不然会出现重复的情况 + pdmBdWorkorderService.updateState(qpmes098Request.getBODY().get(0).getAUFNR(),"2"); entity.setExt_data(JSONObject.toJSONString(qpmes098Request)); entity.setWorkorder_code(qpmes098Request.getBODY().get(0).getAUFNR()); entity.setPlan_qty(new BigDecimal((qpmes098Request.getBODY().get(0).getGAMNG()))); diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pda/service/impl/PdaServiceImpl.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pda/service/impl/PdaServiceImpl.java index fadd292..45ad890 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pda/service/impl/PdaServiceImpl.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pda/service/impl/PdaServiceImpl.java @@ -9,6 +9,7 @@ import lombok.extern.slf4j.Slf4j; import org.nl.common.exception.BadRequestException; import org.nl.wms.database.material.service.IMdBaseMaterialService; import org.nl.wms.ext.service.AcsToWmsService; +import org.nl.wms.ext.service.dto.to.BaseResponse; import org.nl.wms.pda.service.PdaService; import org.nl.wms.pda.service.dao.mapper.PdaMapper; import org.nl.wms.pda.service.dao.vo.PdaResponseVo; @@ -65,16 +66,16 @@ public class PdaServiceImpl implements PdaService { param.put("request_medthod_code", "YCLRKTask"); param.put("request_medthod_name", "原材料入库"); param.put("device_code",param.getString("start_point")); - acsToWmsService.acsApply(param); - return PdaResponseVo.pdaResultOk("原材料入库成功"); + BaseResponse baseResponse=acsToWmsService.acsApply(param); + return PdaResponseVo.pdaResultOk(baseResponse.getMessage()); } @Override public PdaResponseVo yclck(JSONObject param) { param.put("request_medthod_code", "YCLCKTask"); param.put("request_medthod_name", "原材料出库"); param.put("device_code",param.getString("start_point")); - acsToWmsService.acsApply(param); - return PdaResponseVo.pdaResultOk("原材料出库成功"); + BaseResponse baseResponse=acsToWmsService.acsApply(param); + return PdaResponseVo.pdaResultOk(baseResponse.getMessage()); } @Override @@ -82,8 +83,8 @@ public class PdaServiceImpl implements PdaService { param.put("request_medthod_code", "POINTTask"); param.put("request_medthod_name", "点对点任务"); param.put("device_code",param.getString("start_point")); - acsToWmsService.acsApply(param); - return PdaResponseVo.pdaResultOk("任务生成成功"); + BaseResponse baseResponse=acsToWmsService.acsApply(param); + return PdaResponseVo.pdaResultOk(baseResponse.getMessage()); } diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/service/IPdmBdWorkorderService.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/service/IPdmBdWorkorderService.java index 333a16b..283cce4 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/service/IPdmBdWorkorderService.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/service/IPdmBdWorkorderService.java @@ -52,4 +52,6 @@ public interface IPdmBdWorkorderService extends IService { IPage queryAllDetail(PdmBdWorkorderQuery query, PageQuery page); IPage queryPointDetail(String productname, PageQuery page); + + void updateState(String workorder_code,String workorder_status); } diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/service/impl/PdmBdWorkorderServiceImpl.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/service/impl/PdmBdWorkorderServiceImpl.java index 5fa1092..b6f066f 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/service/impl/PdmBdWorkorderServiceImpl.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/pdm/service/impl/PdmBdWorkorderServiceImpl.java @@ -13,6 +13,7 @@ import org.nl.common.domain.query.PageQuery; import org.nl.common.exception.BadRequestException; import org.nl.common.utils.CodeUtil; import org.nl.common.utils.SecurityUtils; +import org.nl.system.service.coderule.dao.SysCodeRuleDetail; import org.nl.wms.pdm.service.IPdmBdWorkorderService; import org.nl.wms.pdm.service.dao.PdmBdWorkorder; import org.nl.wms.pdm.service.dao.PdmBdWorkorderDetail; @@ -108,4 +109,13 @@ public class PdmBdWorkorderServiceImpl extends ServiceImpl() + .eq(PdmBdWorkorder::getWorkorder_code, workorder_code)); + entity.setWorkorder_status(workorder_status); + pdmBdWorkorderMapper.updateById(entity); + pdmBdWorkorderDetailMapper.delete(new LambdaQueryWrapper().eq(PdmBdWorkorderDetail::getWorkorder_code, workorder_code)); + } } diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/POINTTask.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/POINTTask.java index 29af301..c5e6103 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/POINTTask.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/task/tasks/POINTTask.java @@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; import org.nl.common.exception.BadRequestException; import org.nl.wms.ext.service.WmsToAcsService; import org.nl.wms.ext.service.dto.to.BaseResponse; @@ -135,10 +136,13 @@ public class POINTTask extends AbstractTask { if (status.equals(TaskStatus.FINISHED)) { // 完成 String vehicleCode=taskObj.getVehicle_code(); String vehicleCode2= taskObj.getVehicle_code2(); - SchBaseVehiclematerialgroup one = vehiclematerialgroupService.getOne(new LambdaQueryWrapper() - .eq(SchBaseVehiclematerialgroup::getVehicle_code, vehicleCode) - .eq(SchBaseVehiclematerialgroup::getGroup_bind_material_status, - GroupBindMaterialStatusEnum.BOUND.getValue())); + SchBaseVehiclematerialgroup one =null; + if(StringUtils.isNotEmpty(vehicleCode)) { + one = vehiclematerialgroupService.getOne(new LambdaQueryWrapper() + .eq(SchBaseVehiclematerialgroup::getVehicle_code, vehicleCode) + .eq(SchBaseVehiclematerialgroup::getGroup_bind_material_status, + GroupBindMaterialStatusEnum.BOUND.getValue())); + } if (ObjectUtil.isNotEmpty(one)) { // throw new BadRequestException(vehicleCode + " => " + startPointObj.getVehicle_type() + "的组盘信息未找到"); // } @@ -152,10 +156,12 @@ public class POINTTask extends AbstractTask { one.setUpdate_time(DateUtil.now()); vehiclematerialgroupService.updateById(one); } - one = vehiclematerialgroupService.getOne(new LambdaQueryWrapper() - .eq(SchBaseVehiclematerialgroup::getVehicle_code, vehicleCode2) - .eq(SchBaseVehiclematerialgroup::getGroup_bind_material_status, - GroupBindMaterialStatusEnum.BOUND.getValue())); + if(StringUtils.isNotEmpty(vehicleCode2)) { + one = vehiclematerialgroupService.getOne(new LambdaQueryWrapper() + .eq(SchBaseVehiclematerialgroup::getVehicle_code, vehicleCode2) + .eq(SchBaseVehiclematerialgroup::getGroup_bind_material_status, + GroupBindMaterialStatusEnum.BOUND.getValue())); + } if (ObjectUtil.isNotEmpty(one)) { // throw new BadRequestException(vehicleCode + " => " + startPointObj.getVehicle_type() + "的组盘信息未找到"); // }