add:MES接口
This commit is contained in:
@@ -41,6 +41,11 @@
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 获取系统信息 -->
|
||||
<dependency>
|
||||
<groupId>com.github.oshi</groupId>
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.nl.wms.ext_manage.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.logging.annotation.Log;
|
||||
import org.nl.wms.ext_manage.dto.mes.MesCallMaterialRequestDto;
|
||||
import org.nl.wms.ext_manage.service.MesToWmsService;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* MES接口controller
|
||||
*
|
||||
* @author zhengxuming
|
||||
* @since 2025年7月28日
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/mes")
|
||||
@Slf4j
|
||||
public class MesToWmsController {
|
||||
|
||||
@Resource
|
||||
private MesToWmsService mesToWmsService;
|
||||
|
||||
@PostMapping("/callMaterial")
|
||||
@SaIgnore
|
||||
@Log("MES请求叫料")
|
||||
public ResponseEntity<Object> callMaterial(@RequestBody @Validated MesCallMaterialRequestDto param) {
|
||||
return new ResponseEntity<>(mesToWmsService.callMaterial(param), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/backMaterial")
|
||||
@SaIgnore
|
||||
@Log("MES请求退料/空桶")
|
||||
public ResponseEntity<Object> backMaterial(@RequestBody @Validated MesCallMaterialRequestDto param) {
|
||||
return new ResponseEntity<>(mesToWmsService.backMaterial(param), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.nl.wms.ext_manage.dto.mes;
|
||||
|
||||
import lombok.Data;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
@Data
|
||||
public class MesCallMaterialRequestDto {
|
||||
@NotBlank(message = "设备号不为空")
|
||||
private String device_code;
|
||||
|
||||
@NotBlank(message = "货位号不为空")
|
||||
private String struct_code;
|
||||
|
||||
@NotBlank(message = "物料编码不为空")
|
||||
private String material_code;
|
||||
|
||||
@NotBlank(message = "料桶号不为空")
|
||||
private String vehicle_code;
|
||||
|
||||
@NotBlank(message = "组盘标识不为空")
|
||||
private String storagevehicleext_id;
|
||||
|
||||
@NotBlank(message = "物料编码不为空")
|
||||
private String pcsn;
|
||||
|
||||
private String qty_unit_name;
|
||||
|
||||
private String qty;
|
||||
|
||||
private String remark;
|
||||
|
||||
@NotBlank(message = "任务号不为空")
|
||||
private String task_code;
|
||||
@NotBlank(message = "任务类型不为空")
|
||||
private String task_type;
|
||||
|
||||
private String supp_code;
|
||||
|
||||
private String supp_name;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package org.nl.wms.ext_manage.dto.mes;
|
||||
|
||||
import cn.hutool.http.HttpStatus;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import org.nl.common.base.TableDataInfo;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mes调用WMS 返回结果
|
||||
* </p>
|
||||
*
|
||||
* @author zhengxuming
|
||||
* @since 2025年7月29日09:22:57
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
public class MesResponse<T> {
|
||||
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
private String message;
|
||||
|
||||
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 返回数据
|
||||
*/
|
||||
private T data;
|
||||
|
||||
/**
|
||||
* 不带数据反馈
|
||||
* @return MesResponse
|
||||
*/
|
||||
public static MesResponse requestOk() {
|
||||
return MesResponse.builder()
|
||||
.message("操作成功!")
|
||||
.status(0)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 带数据反馈
|
||||
* @return MesResponse
|
||||
*/
|
||||
public static <T> MesResponse requestParamOk(T data) {
|
||||
return MesResponse.builder()
|
||||
.message("操作成功!")
|
||||
.data(data)
|
||||
.status(0)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static <T> TableDataInfo<T> build(IPage<T> page) {
|
||||
TableDataInfo<T> rspData = new TableDataInfo<>();
|
||||
rspData.setCode(String.valueOf(HttpStatus.HTTP_OK));
|
||||
rspData.setMsg("查询成功");
|
||||
rspData.setContent(page.getRecords());
|
||||
rspData.setTotalElements(page.getTotal());
|
||||
return rspData;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.nl.wms.ext_manage.service;
|
||||
|
||||
import org.nl.wms.ext_manage.dto.mes.MesCallMaterialRequestDto;
|
||||
import org.nl.wms.ext_manage.dto.mes.MesResponse;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* MES调用WMS 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author zhengxuming
|
||||
* @since 2025年7月28日
|
||||
*/
|
||||
public interface MesToWmsService {
|
||||
/**
|
||||
* MES下发设备叫料任务
|
||||
* @param
|
||||
* @return MesResponse
|
||||
*/
|
||||
MesResponse callMaterial(MesCallMaterialRequestDto dto);
|
||||
|
||||
/**
|
||||
* MES 请求退料/空桶
|
||||
* @param
|
||||
* @return MesResponse
|
||||
*/
|
||||
MesResponse backMaterial(MesCallMaterialRequestDto dto);
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package org.nl.wms.ext_manage.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.wms.ext_manage.dto.mes.MesCallMaterialRequestDto;
|
||||
import org.nl.wms.ext_manage.dto.mes.MesResponse;
|
||||
import org.nl.wms.ext_manage.enums.ResultAcsStatus;
|
||||
import org.nl.wms.ext_manage.service.AcsToWmsService;
|
||||
import org.nl.wms.ext_manage.service.MesToWmsService;
|
||||
import org.nl.wms.ext_manage.service.util.AcsResponse;
|
||||
import org.nl.wms.sch_manage.enums.TaskStatus;
|
||||
import org.nl.wms.sch_manage.service.ISchBasePointService;
|
||||
import org.nl.wms.sch_manage.service.ISchBaseTaskService;
|
||||
import org.nl.wms.sch_manage.service.dao.SchBasePoint;
|
||||
import org.nl.wms.sch_manage.service.dao.SchBaseTask;
|
||||
import org.nl.wms.sch_manage.service.util.AbstractTask;
|
||||
import org.nl.wms.sch_manage.service.util.TaskFactory;
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* MES调用WMS 实现类
|
||||
* </p>
|
||||
*
|
||||
* @author zhengxuming
|
||||
* @since 2025年7月28日16:12:19
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class MesToWmsServiceImpl implements MesToWmsService {
|
||||
|
||||
/*
|
||||
* redisson连接服务
|
||||
*/
|
||||
@Autowired
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
/*
|
||||
* 任务服务
|
||||
*/
|
||||
@Autowired
|
||||
private ISchBaseTaskService iSchBaseTaskService;
|
||||
@Autowired
|
||||
private ISchBasePointService pointService;
|
||||
|
||||
/**
|
||||
* 任务工厂服务
|
||||
*/
|
||||
@Autowired
|
||||
private TaskFactory taskFactory;
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public MesResponse callMaterial(MesCallMaterialRequestDto dto) {
|
||||
log.info("MES下发设备叫料信息输入参数:-------------------: {}", dto);
|
||||
RLock lock = redissonClient.getLock(dto.getTask_code());
|
||||
boolean tryLock = lock.tryLock(1, TimeUnit.SECONDS);
|
||||
try {
|
||||
if (tryLock) {
|
||||
log.info("MES下发设备叫料信息输入参数:--------------------------------------" + MesResponse.requestOk());
|
||||
//1、判断当前节点的左右子节点是否存在执行中的任务,如果有则报错
|
||||
//
|
||||
//2、
|
||||
|
||||
|
||||
return MesResponse.requestOk();
|
||||
} else {
|
||||
throw new BadRequestException("任务标识为:" + dto.getTask_code() + "的任务正在操作中!");
|
||||
}
|
||||
} finally {
|
||||
if (tryLock) {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public MesResponse backMaterial(MesCallMaterialRequestDto dto) {
|
||||
log.info("MES下发设备叫料信息输入参数:-------------------: {}", dto);
|
||||
RLock lock = redissonClient.getLock(dto.getTask_code());
|
||||
boolean tryLock = lock.tryLock(1, TimeUnit.SECONDS);
|
||||
try {
|
||||
if (tryLock) {
|
||||
log.info("MES下发设备叫料信息输入参数:--------------------------------------" + MesResponse.requestOk());
|
||||
return MesResponse.requestOk();
|
||||
} else {
|
||||
throw new BadRequestException("任务标识为:" + dto.getTask_code() + "的任务正在操作中!");
|
||||
}
|
||||
} finally {
|
||||
if (tryLock) {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user