Browse Source

add:新增一体机接口

master
涂强 2 months ago
parent
commit
607a04451a
  1. 63
      acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/region/domain/Region.java
  2. 9
      acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/region/rest/RegionController.java
  3. 12
      acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/region/service/RegionService.java
  4. 39
      acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/region/service/dto/RegionDto.java
  5. 63
      acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/region/service/impl/RegionServiceImpl.java
  6. 9
      acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/region/service/mapper/RegionMapper.java
  7. 3
      acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/TaskService.java
  8. 2
      acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java
  9. 5
      acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/HeadDto.java
  10. 5
      acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/HeadTaskDto.java
  11. 109
      acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/rest/PdaController.java
  12. 31
      acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/service/PdaService.java
  13. 245
      acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/service/impl/PdaServiceImpl.java
  14. 2
      acs2/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/dict/dao/mapper/SysDictMapper.java

63
acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/region/domain/Region.java

@ -0,0 +1,63 @@
package org.nl.acs.region.domain;
import com.baomidou.mybatisplus.annotation.*;
import lombok.*;
import lombok.experimental.Accessors;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.math.BigDecimal;
@Data
@Builder
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@TableName("acs_region")
public class Region implements Serializable {
private static final long serialVersionUID = 1L;
@TableField(exist = false)
private String id;
@TableId(type = IdType.ASSIGN_ID)
private String region_id;
@NotBlank
private String region_code;
@NotBlank
private String region_name;
@NotBlank
private String is_charge;
@NotBlank
private String has_agv;
@NotBlank
@TableField(fill = FieldFill.INSERT)
private String create_by;
@NotBlank
@TableField(fill = FieldFill.INSERT)
private String create_time;
@TableField(fill = FieldFill.INSERT_UPDATE)
private String update_by;
private String update_time;
}

9
acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/region/rest/RegionController.java

@ -0,0 +1,9 @@
package org.nl.acs.region.rest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequiredArgsConstructor
public class RegionController {
}

12
acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/region/service/RegionService.java

@ -0,0 +1,12 @@
package org.nl.acs.region.service;
import com.alibaba.fastjson.JSONArray;
import org.nl.acs.common.base.CommonService;
import org.nl.acs.region.domain.Region;
import org.nl.acs.region.service.dto.RegionDto;
public interface RegionService extends CommonService<Region> {
JSONArray queryAllRegions();
Region findByCode(String code);
}

39
acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/region/service/dto/RegionDto.java

@ -0,0 +1,39 @@
package org.nl.acs.region.service.dto;
import lombok.*;
import lombok.experimental.Accessors;
import java.io.Serializable;
@Data
@Builder
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class RegionDto implements Serializable {
private static final long serialVersionUID = 1L;
private String region_code;
private String region_name;
private String is_charge;
private String has_agv;
private String create_by;
private String create_time;
private String update_by;
private String update_time;
}

63
acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/region/service/impl/RegionServiceImpl.java

@ -0,0 +1,63 @@
package org.nl.acs.region.service.impl;
import cn.hutool.core.collection.CollectionUtil;
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.extension.conditions.query.LambdaQueryChainWrapper;
import lombok.AllArgsConstructor;
import org.nl.acs.auto.initial.ApplicationAutoInitial;
import org.nl.acs.common.base.impl.CommonServiceImpl;
import org.nl.acs.region.domain.Region;
import org.nl.acs.region.service.RegionService;
import org.nl.acs.region.service.mapper.RegionMapper;
import org.nl.common.exception.BadRequestException;
import org.nl.config.language.LangProcess;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
@AllArgsConstructor
// @CacheConfig(cacheNames = RouteLineService.CACHE_KEY)
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class RegionServiceImpl extends CommonServiceImpl<RegionMapper,Region> implements RegionService{
@Autowired
RegionService regionService;
@Autowired
RegionMapper regionMapper;
@Override
public JSONArray queryAllRegions() {
//查询所有区域
List<Region> list = regionService.lambdaQuery().list();
if (CollectionUtil.isEmpty(list)) {
throw new BadRequestException(LangProcess.msg("error_no_regional"));
}
JSONArray arr = JSONArray.parseArray(JSON.toJSONString(list));
JSONArray result = new JSONArray();
for (int i = 0; i < arr.size(); i++) {
JSONObject obj = arr.getJSONObject(i);
JSONObject json = new JSONObject();
json.put("region_code", obj.getString("region_code"));
json.put("region_name", obj.getString("region_name"));
json.put("is_charge", obj.getString("is_charge"));
json.put("has_agv", obj.getString("has_agv"));
result.add(json);
}
return result;
}
@Override
public Region findByCode(String code) {
Region region = new LambdaQueryChainWrapper<>(regionMapper)
.eq(StrUtil.isNotEmpty(code), Region::getRegion_code, code)
.one();
return region;
}
}

9
acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/region/service/mapper/RegionMapper.java

@ -0,0 +1,9 @@
package org.nl.acs.region.service.mapper;
import org.nl.acs.common.base.CommonMapper;
import org.nl.acs.region.domain.Region;
import org.springframework.stereotype.Repository;
@Repository
public interface RegionMapper extends CommonMapper<Region> {
}

3
acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/TaskService.java

@ -171,10 +171,9 @@ public interface TaskService extends CommonService<Task> {
/**
* 查询所有未完成任务
*
* @param whereJson 条件参数
* @return List<AcsTaskDto>
*/
List<TaskDto> queryAllUnfinished(Map whereJson);
List<TaskDto> queryAllUnfinished();
/**
* 根据状态查询

2
acs2/nladmin-system/nlsso-server/src/main/java/org/nl/acs/task/service/impl/TaskServiceImpl.java

@ -403,7 +403,7 @@ public class TaskServiceImpl extends CommonServiceImpl<TaskMapper, Task> impleme
@Override
public List<TaskDto> queryAllUnfinished(Map whereJson) {
public List<TaskDto> queryAllUnfinished() {
List<Task> taskList = new LambdaQueryChainWrapper<>(taskMapper)
.lt(Task::getTask_status, TaskStatusEnum.FINISHED.getIndex())
.list();

5
acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/HeadDto.java

@ -26,4 +26,9 @@ public class HeadDto implements Serializable {
*/
private String task_type;
/**
* 物料类型
*/
private String material;
}

5
acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/dto/HeadTaskDto.java

@ -36,4 +36,9 @@ public class HeadTaskDto implements Serializable {
* 2 强制完成
*/
private String type;
/**
* 任务id
*/
private String task_id;
}

109
acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/rest/PdaController.java

@ -0,0 +1,109 @@
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.acs.task.service.dto.TaskIdAndStatusDTO;
import org.nl.common.logging.annotation.Log;
import org.nl.hand.dto.HeadDto;
import org.nl.hand.dto.HeadTaskDto;
import org.nl.hand.dto.RegionDto;
import org.nl.hand.service.PdaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequiredArgsConstructor
@Api(tags = "一体机接口")
@RequestMapping("api/pda")
@Slf4j
public class PdaController {
@Autowired
PdaService pdaService;
@PostMapping("/queryAllPoints")
@Log("查询所有点位")
@ApiOperation("查询所有点位")
@SaIgnore
//@PreAuthorize("@el.check('sect:list')")
public ResponseEntity<Object> queryAllPoints() {
return new ResponseEntity<>(pdaService.queryAllPoints(), HttpStatus.OK);
}
@PostMapping("/queryAreas")
@Log("查询所有区域")
@ApiOperation("查询所有区域")
@SaIgnore
//@PreAuthorize("@el.check('sect:list')")
public ResponseEntity<Object> queryAreas() {
return new ResponseEntity<>(pdaService.queryAreas(), HttpStatus.OK);
}
@PostMapping("/queryMaterials/{material_type}")
@Log("查询物料类型")
@ApiOperation("查询物料类型")
@SaIgnore
//@PreAuthorize("@el.check('sect:list')")
public ResponseEntity<Object> queryMaterials(@RequestParam String material_type) {
return new ResponseEntity<>(pdaService.queryMaterials(material_type), HttpStatus.OK);
}
@PostMapping("/callTask")
@Log("一体机创建任务")
@ApiOperation("一体机创建任务")
@SaIgnore
//@PreAuthorize("@el.check('sect:list')")
public ResponseEntity<Object> callTask(@RequestBody HeadDto dto) {
return new ResponseEntity<>(pdaService.callTask(dto), HttpStatus.OK);
}
@PostMapping("/areaControl")
@Log(value = "区域控制")
@ApiOperation("区域控制")
@SaIgnore
public ResponseEntity<Object> areaControl(@RequestBody String whereJson){
return new ResponseEntity<>(pdaService.areaControl(whereJson), HttpStatus.OK);
}
@PostMapping("/putAction")
@Log(value = "一体机下发动作信号")
@ApiOperation("一体机下发动作信号")
@SaIgnore
public ResponseEntity<Object> putAction(@RequestBody String whereJson){
return new ResponseEntity<>(pdaService.putAction(whereJson), HttpStatus.OK);
}
@PostMapping("/forceFinish")
@Log("强制完成")
@ApiOperation("强制完成")
@SaIgnore
//@PreAuthorize("@el.check('sect:list')")
public ResponseEntity<Object> forceFinish(@RequestBody HeadTaskDto dto) throws Exception {
return new ResponseEntity<>(pdaService.forceFinish(dto), HttpStatus.OK);
}
@PostMapping("/queryTaskIds")
@Log("查询任务号")
@ApiOperation("查询任务号")
@SaIgnore
//@PreAuthorize("@el.check('sect:list')")
public ResponseEntity<Object> queryTaskIds() throws Exception {
return new ResponseEntity<>(pdaService.queryTaskIds(), HttpStatus.OK);
}
@PostMapping("/cancel")
@Log("取消任务")
@ApiOperation("取消任务")
@SaIgnore
//@PreAuthorize("@el.check('sect:list')")
public ResponseEntity<Object> cancel(TaskIdAndStatusDTO dto) throws Exception {
return new ResponseEntity<>(pdaService.cancel(dto), HttpStatus.OK);
}
}

31
acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/service/PdaService.java

@ -0,0 +1,31 @@
package org.nl.hand.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.nl.acs.task.service.dto.TaskIdAndStatusDTO;
import org.nl.hand.dto.HeadDto;
import org.nl.hand.dto.HeadTaskDto;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Map;
public interface PdaService {
JSONArray queryAllPoints();
JSONArray queryMaterials(String code);
Map<String, Object> callTask(HeadDto dto);
Map<String, Object> areaControl(String whereJson);
Map<String, Object> forceFinish(HeadTaskDto dto);
JSONArray queryTaskIds();
Map<String, Object> cancel(TaskIdAndStatusDTO dto) throws Exception;
JSONArray queryAreas();
Map<String, Object> putAction(String whereJson);
}

245
acs2/nladmin-system/nlsso-server/src/main/java/org/nl/hand/service/impl/PdaServiceImpl.java

@ -0,0 +1,245 @@
package org.nl.hand.service.impl;
import cn.hutool.core.collection.CollectionUtil;
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.common.base.CommonFinalParam;
import org.nl.acs.device.domain.Device;
import org.nl.acs.device.service.DeviceService;
import org.nl.acs.device_driver.conveyor.standard_ordinary_site.StandardOrdinarySiteDeviceDriver;
import org.nl.acs.opc.DeviceAppService;
import org.nl.acs.region.domain.Region;
import org.nl.acs.region.service.RegionService;
import org.nl.acs.task.service.TaskService;
import org.nl.acs.task.service.dto.TaskDto;
import org.nl.acs.task.service.dto.TaskIdAndStatusDTO;
import org.nl.common.exception.BadRequestException;
import org.nl.config.language.LangProcess;
import org.nl.hand.dto.HeadDto;
import org.nl.hand.dto.HeadTaskDto;
import org.nl.hand.service.HandService;
import org.nl.hand.service.PdaService;
import org.nl.system.service.dict.dao.Dict;
import org.nl.system.service.dict.dao.mapper.SysDictMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
@Service
@RequiredArgsConstructor
@Slf4j
public class PdaServiceImpl implements PdaService {
@Autowired
private DeviceService deviceService;
@Autowired
private SysDictMapper sysDictMapper;
@Autowired
DeviceAppService deviceAppService;
@Autowired
RegionService regionService;
@Autowired
private TaskService taskserver;
@Override
public JSONArray queryAllPoints() {
JSONArray data = new JSONArray();
//查询所有设备
List<Device> list = deviceService.lambdaQuery()
.list();
if (CollectionUtil.isEmpty(list)) {
throw new BadRequestException(LangProcess.msg("error_no_regional"));
}
JSONArray arr = JSONArray.parseArray(JSON.toJSONString(list));
JSONArray result = new JSONArray();
for (int i = 0; i < arr.size(); i++) {
JSONObject obj = arr.getJSONObject(i);
JSONObject json = new JSONObject();
json.put("device_code", obj.getString("device_code"));
json.put("device_name", obj.getString("device_name"));
result.add(json);
}
return result;
}
@Override
public JSONArray queryMaterials(String code) {
List<Dict> list = sysDictMapper.selectList(new LambdaQueryWrapper<Dict>()
.eq(ObjectUtil.isNotEmpty(code), Dict::getCode, code));
if (ObjectUtil.isNotEmpty(list)) {
throw new BadRequestException(LangProcess.msg("error_checkExist",code));
}
JSONArray arr = JSONArray.parseArray(JSON.toJSONString(list));
JSONArray result = new JSONArray();
for (int i = 0; i < arr.size(); i++) {
JSONObject obj = arr.getJSONObject(i);
JSONObject json = new JSONObject();
json.put("label", obj.getString("label"));
json.put("value", obj.getString("value"));
result.add(json);
}
return result;
}
@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 material = dto.getMaterial();
if (StrUtil.isEmpty(start_device_code)) {
throw new BadRequestException("起点不能为空");
}
if (StrUtil.isEmpty(next_device_code)) {
throw new BadRequestException("终点不能为空");
}
if (StrUtil.isEmpty(material)) {
throw new BadRequestException("物料类型不能为空");
}
JSONObject jo = new JSONObject();
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("material", material);
jo.put("task_type", "1");
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> areaControl(String whereJson) {
JSONObject jsonObject = JSON.parseObject(whereJson);
JSONArray errArr = new JSONArray();
String region_code = jsonObject.getString("region_code");
String option = jsonObject.getString("option");
Region region = regionService.findByCode(region_code);
region.setIs_charge(option);
regionService.updateById(region);
JSONObject resultJson = new JSONObject();
if (ObjectUtil.isEmpty(errArr)) {
resultJson.put("status", HttpStatus.OK.value());
resultJson.put("message", "操作成功");
} else {
resultJson.put("status", HttpStatus.BAD_REQUEST.value());
resultJson.put("message", "操作失败");
if (ObjectUtil.isNotEmpty(errArr)) {
resultJson.put("errArr", errArr);
}
}
return resultJson;
}
@Override
public Map<String, Object> forceFinish(HeadTaskDto dto) {
JSONObject resultJson = new JSONObject();
TaskIdAndStatusDTO taskIdAndStatusDTO = new TaskIdAndStatusDTO();
taskIdAndStatusDTO.setTask_id(dto.getTask_id());
try {
taskserver.finish(taskIdAndStatusDTO);
} catch (Exception e) {
resultJson.put("message", e.getMessage());
return resultJson;
}
resultJson.put("message", "操作成功");
return resultJson;
}
@Override
public JSONArray queryTaskIds() {
//查询所有就绪或者执行中的任务
List<TaskDto> list = taskserver.queryAllUnfinished();
if (CollectionUtil.isEmpty(list)) {
throw new BadRequestException(LangProcess.msg("error_no_regional"));
}
JSONArray arr = JSONArray.parseArray(JSON.toJSONString(list));
JSONArray result = new JSONArray();
for (int i = 0; i < arr.size(); i++) {
JSONObject obj = arr.getJSONObject(i);
JSONObject json = new JSONObject();
json.put("task_id", obj.getString("task_id"));
result.add(json);
}
return result;
}
@Override
public Map<String, Object> cancel(TaskIdAndStatusDTO dto) {
JSONObject resultJson = new JSONObject();
try {
taskserver.cancelAndInst(dto.getTask_id());
} catch (Exception e) {
resultJson.put("message", e.getMessage());
return resultJson;
}
resultJson.put("message", "取消成功");
return resultJson;
}
@Override
public JSONArray queryAreas() {
return regionService.queryAllRegions();
}
@Override
public Map<String, Object> putAction(String whereJson) {
JSONObject jsonObject = JSON.parseObject(whereJson);
JSONArray errArr = new JSONArray();
String device_code = jsonObject.getString("device_code");
String option = jsonObject.getString("option");
StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver;
Device device_k = deviceAppService.findDeviceByCode(device_code);
if (device_k.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) {
standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) device_k.getDeviceDriver();
standardOrdinarySiteDeviceDriver.setOption(Integer.parseInt(option));
}
JSONObject resultJson = new JSONObject();
if (ObjectUtil.isEmpty(errArr)) {
resultJson.put("status", HttpStatus.OK.value());
resultJson.put("message", "操作成功");
} else {
resultJson.put("status", HttpStatus.BAD_REQUEST.value());
resultJson.put("message", "操作失败");
if (ObjectUtil.isNotEmpty(errArr)) {
resultJson.put("errArr", errArr);
}
}
return resultJson;
}
}

2
acs2/nladmin-system/nlsso-server/src/main/java/org/nl/system/service/dict/dao/mapper/SysDictMapper.java

@ -1,5 +1,6 @@
package org.nl.system.service.dict.dao.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.nl.system.service.dict.dao.Dict;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@ -11,6 +12,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* @author generator
* @since 2022-12-14
*/
@Mapper
public interface SysDictMapper extends BaseMapper<Dict> {
}

Loading…
Cancel
Save