add:导入、同步功能
This commit is contained in:
@@ -68,7 +68,7 @@ public class NDCAgvServiceImpl implements NDCAgvService {
|
||||
};
|
||||
log.info("下发删除AGV指令--{}", Bytes2HexString(b));
|
||||
|
||||
// NDCSocketConnectionAutoRun.write(b);
|
||||
OneNDCSocketConnectionAutoRun.write(b);
|
||||
System.out.println("下发删除agv指令数据:" + Bytes2HexString(b));
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ public class NDCAgvServiceImpl implements NDCAgvService {
|
||||
str1 += "优先级 /priority:" + hexToString(prioritylow & 0xFF);
|
||||
|
||||
byte[] b = new byte[]{};
|
||||
if (ObjectUtil.isNotEmpty(inst.getCarno())){
|
||||
if (ObjectUtil.isNotEmpty(inst.getCarno())) {
|
||||
int carNo = Integer.parseInt(inst.getCarno());
|
||||
byte agvnohigh = (byte) IntToHexHigh(carNo);
|
||||
byte agvnolow = (byte) IntToHexLow(carNo);
|
||||
@@ -143,7 +143,7 @@ public class NDCAgvServiceImpl implements NDCAgvService {
|
||||
(byte) fhdhigh, (byte) fhdlow,
|
||||
(byte) agvnohigh, (byte) agvnolow
|
||||
};
|
||||
}else {
|
||||
} else {
|
||||
b = new byte[]{(byte) 0X87, (byte) 0XCD,
|
||||
(byte) 0X00, (byte) 0X08,
|
||||
(byte) 0X00, (byte) 0X12,
|
||||
@@ -195,8 +195,8 @@ public class NDCAgvServiceImpl implements NDCAgvService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] sendAgvOneModeInst(int phase, int index, int result,Instruction inst) {
|
||||
if (inst.getAgv_inst_type().equals("1")){
|
||||
public byte[] sendAgvOneModeInst(int phase, int index, int result, Instruction inst) {
|
||||
if (inst.getAgv_inst_type().equals("1")) {
|
||||
return sendAgvOneModeInst(phase, index, result);
|
||||
}
|
||||
DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class);
|
||||
@@ -217,7 +217,7 @@ public class NDCAgvServiceImpl implements NDCAgvService {
|
||||
}
|
||||
int startAddress = deviceService.queryAddressBydeviceCode(inst.getStart_point_code());
|
||||
int nextAddress = deviceService.queryAddressBynextdeviceCode(inst.getNext_point_code());
|
||||
if (!inst.getAgv_inst_type().equals("1")){
|
||||
if (!inst.getAgv_inst_type().equals("1")) {
|
||||
start2Address = deviceService.queryAddressBydeviceCode(inst.getStart_point_code2());
|
||||
next2Address = deviceService.queryAddressBynextdeviceCode(inst.getNext_point_code2());
|
||||
}
|
||||
@@ -234,45 +234,45 @@ public class NDCAgvServiceImpl implements NDCAgvService {
|
||||
byte indexlow = (byte) IntToHexLow(index);
|
||||
byte phasehigh = (byte) IntToHexHigh(phase);
|
||||
byte phaselow = (byte) IntToHexLow(phase);
|
||||
if (inst.getAgv_inst_type().equals("2")){
|
||||
if (inst.getAgv_inst_type().equals("2")) {
|
||||
if (phase == 0x09) {
|
||||
qhdhigh = (byte) IntToHexHigh(start2Address);
|
||||
qhdlow = (byte) IntToHexLow(start2Address);
|
||||
addrHigh = qhdhigh;
|
||||
addrLow = qhdlow;
|
||||
}else if (phase == 0x0D) {
|
||||
} else if (phase == 0x0D) {
|
||||
fhdhigh = (byte) IntToHexHigh(next2Address);
|
||||
fhdlow = (byte) IntToHexLow(next2Address);
|
||||
addrHigh = fhdhigh;
|
||||
addrLow = fhdlow;
|
||||
}
|
||||
}else if (inst.getAgv_inst_type().equals("3")) {
|
||||
} else if (inst.getAgv_inst_type().equals("3")) {
|
||||
if (phase == 0x09) {
|
||||
qhdhigh = (byte) IntToHexHigh(nextAddress);
|
||||
qhdlow = (byte) IntToHexLow(nextAddress);
|
||||
addrHigh = qhdhigh;
|
||||
addrLow = qhdlow;
|
||||
}else if (phase == 0x11) {
|
||||
} else if (phase == 0x11) {
|
||||
qhdhigh = (byte) IntToHexHigh(startLinkAddress);
|
||||
qhdlow = (byte) IntToHexLow(startLinkAddress);
|
||||
addrHigh = qhdhigh;
|
||||
addrLow = qhdlow;
|
||||
}else if (phase == 0x19){
|
||||
} else if (phase == 0x19) {
|
||||
qhdhigh = (byte) IntToHexHigh(nextLinkAddress);
|
||||
qhdlow = (byte) IntToHexLow(nextLinkAddress);
|
||||
addrHigh = qhdhigh;
|
||||
addrLow = qhdlow;
|
||||
}else if (phase == 0x0D){
|
||||
} else if (phase == 0x0D) {
|
||||
fhdhigh = (byte) IntToHexHigh(nextLinkAddress);
|
||||
fhdlow = (byte) IntToHexLow(nextLinkAddress);
|
||||
addrHigh = fhdhigh;
|
||||
addrLow = fhdlow;
|
||||
}else if (phase == 0x15){
|
||||
} else if (phase == 0x15) {
|
||||
fhdhigh = (byte) IntToHexHigh(start2Address);
|
||||
fhdlow = (byte) IntToHexLow(start2Address);
|
||||
addrHigh = fhdhigh;
|
||||
addrLow = fhdlow;
|
||||
}else if (phase == 0x1D){
|
||||
} else if (phase == 0x1D) {
|
||||
fhdhigh = (byte) IntToHexHigh(next2Address);
|
||||
fhdlow = (byte) IntToHexLow(next2Address);
|
||||
addrHigh = fhdhigh;
|
||||
|
||||
@@ -154,8 +154,8 @@ public class OneNDCSocketConnectionAutoRun extends AbstractAutoRunnable {
|
||||
inst.setAgv_jobno(String.valueOf(index));
|
||||
inst.setSend_status("1");
|
||||
instructionService.update(inst);
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
}
|
||||
data = NDCAgvService.sendAgvOneModeInst(phase, index, 0);
|
||||
}
|
||||
//任务完毕
|
||||
//(无车id及状态)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
package org.nl.acs.device.rest;
|
||||
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -392,4 +393,14 @@ public class DeviceController {
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/reload")
|
||||
@Log("数据同步")
|
||||
@ApiOperation("数据同步")
|
||||
@SaIgnore
|
||||
//@PreAuthorize("@el.check('task:list')")
|
||||
public ResponseEntity<Object> reload() {
|
||||
deviceService.reload();
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,9 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
@@ -74,4 +76,12 @@ public class StorageCellController {
|
||||
public void download(HttpServletResponse response, @RequestParam Map whereJson) throws IOException {
|
||||
storageCellService.download(storageCellService.queryAll(whereJson), response);
|
||||
}
|
||||
|
||||
@PostMapping("/excelImport")
|
||||
@Log("excel导入")
|
||||
@ApiOperation("excel导入")
|
||||
public ResponseEntity<Object> excelImport(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
|
||||
storageCellService.excelImport(file, request);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@ package org.nl.acs.device.service;
|
||||
|
||||
import org.nl.acs.device.service.dto.StorageCellDto;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@@ -87,4 +89,12 @@ public interface StorageCellService {
|
||||
* @throws IOException /
|
||||
*/
|
||||
void download(List<StorageCellDto> dtos, HttpServletResponse response) throws IOException;
|
||||
|
||||
|
||||
/**
|
||||
* 导入数据
|
||||
* @param file
|
||||
* @param request
|
||||
*/
|
||||
void excelImport(MultipartFile file, HttpServletRequest request);
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -76,7 +77,7 @@ public class DeviceServiceImpl implements DeviceService, ApplicationAutoInitial
|
||||
private final DeviceDriverDefinationAppService deviceDriverDefinationAppService;
|
||||
private final DeviceAppService deviceAppService;
|
||||
private final ParamService paramService;
|
||||
List<StorageCellDto> storageCells = new ArrayList<>();
|
||||
private List<StorageCellDto> storageCells = new CopyOnWriteArrayList<>();
|
||||
private Map<String, Integer> storage_address = new HashMap();
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(DeviceServiceImpl.class);
|
||||
|
||||
@@ -2,16 +2,20 @@
|
||||
package org.nl.acs.device.service.impl;
|
||||
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.poi.excel.ExcelReader;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.device.service.StorageCellService;
|
||||
import org.nl.acs.device.service.dto.DeviceDto;
|
||||
import org.nl.acs.device.service.dto.StorageCellDto;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.common.utils.FileUtil;
|
||||
@@ -22,9 +26,12 @@ import org.nl.modules.wql.util.WqlUtil;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@@ -73,7 +80,7 @@ public class StorageCellServiceImpl implements StorageCellService {
|
||||
public StorageCellDto findById(String storage_id) {
|
||||
WQLObject wo = WQLObject.getWQLObject("acs_storage_cell");
|
||||
JSONObject json = wo.query("storage_id ='" + storage_id + "'").uniqueResult(0);
|
||||
if (ObjectUtil.isNotEmpty(json)){
|
||||
if (ObjectUtil.isNotEmpty(json)) {
|
||||
final StorageCellDto obj = json.toJavaObject(StorageCellDto.class);
|
||||
return obj;
|
||||
}
|
||||
@@ -83,8 +90,8 @@ public class StorageCellServiceImpl implements StorageCellService {
|
||||
@Override
|
||||
public StorageCellDto findByCode(String code) {
|
||||
WQLObject wo = WQLObject.getWQLObject("acs_storage_cell");
|
||||
JSONObject json = wo.query("code ='" + code + "'").uniqueResult(0);
|
||||
if (ObjectUtil.isNotEmpty(json)){
|
||||
JSONObject json = wo.query("storage_code ='" + code + "'").uniqueResult(0);
|
||||
if (ObjectUtil.isNotEmpty(json)) {
|
||||
final StorageCellDto obj = json.toJavaObject(StorageCellDto.class);
|
||||
return obj;
|
||||
}
|
||||
@@ -95,7 +102,7 @@ public class StorageCellServiceImpl implements StorageCellService {
|
||||
public StorageCellDto findByAddress(String address) {
|
||||
WQLObject wo = WQLObject.getWQLObject("acs_storage_cell");
|
||||
JSONObject json = wo.query("address ='" + address + "'").uniqueResult(0);
|
||||
if (ObjectUtil.isNotEmpty(json)){
|
||||
if (ObjectUtil.isNotEmpty(json)) {
|
||||
final StorageCellDto obj = json.toJavaObject(StorageCellDto.class);
|
||||
return obj;
|
||||
}
|
||||
@@ -167,4 +174,91 @@ public class StorageCellServiceImpl implements StorageCellService {
|
||||
}
|
||||
FileUtil.downloadExcel(list, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void excelImport(MultipartFile file, HttpServletRequest request) {
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw new BadRequestException("文件为空,请添加数据后重新导入");
|
||||
}
|
||||
|
||||
String nickName = SecurityUtils.getCurrentNickName();
|
||||
String now = DateUtil.now();
|
||||
|
||||
WQLObject wo = WQLObject.getWQLObject("acs_storage_cell");
|
||||
|
||||
List<StorageCellDto> exists = new ArrayList<>();
|
||||
List<String> notExists = new ArrayList<>();
|
||||
List<String> badMsg = new ArrayList<>();
|
||||
|
||||
try (InputStream in = file.getInputStream();
|
||||
ExcelReader reader = ExcelUtil.getReader(in)) {
|
||||
|
||||
List<List<Object>> rows = reader.read(1, reader.getRowCount());
|
||||
|
||||
for (int i = 0; i < rows.size(); i++) {
|
||||
int excelRowNo = i + 2;
|
||||
List<Object> row = rows.get(i);
|
||||
|
||||
if (row == null || row.size() < 3 || (ObjectUtil.isEmpty(row.get(0)) && ObjectUtil.isEmpty(row.get(1)) && ObjectUtil.isEmpty(row.get(2)))) {
|
||||
badMsg.add("第" + excelRowNo + "行, 数据不完整!");
|
||||
continue;
|
||||
}
|
||||
|
||||
Object storage_code = row.get(0);
|
||||
Object pick_address = row.get(1);
|
||||
Object drop_address = row.get(2);
|
||||
|
||||
if (ObjectUtil.isEmpty(storage_code)) {
|
||||
badMsg.add("第" + excelRowNo + "行,货位编码不能为空");
|
||||
continue;
|
||||
}
|
||||
if (ObjectUtil.isEmpty(pick_address)) {
|
||||
badMsg.add("第" + excelRowNo + "行,取货地址不能为空");
|
||||
continue;
|
||||
}
|
||||
if (ObjectUtil.isEmpty(drop_address)) {
|
||||
badMsg.add("第" + excelRowNo + "行,卸货地址不能为空");
|
||||
continue;
|
||||
}
|
||||
|
||||
String code = storage_code.toString().trim();
|
||||
|
||||
StorageCellDto dto = this.findByCode(code);
|
||||
if (dto == null) {
|
||||
notExists.add(code);
|
||||
continue;
|
||||
}
|
||||
|
||||
Integer pick = Convert.toInt(pick_address, null);
|
||||
Integer drop = Convert.toInt(drop_address, null);
|
||||
if (pick == null || drop == null) {
|
||||
badMsg.add("第" + excelRowNo + "行:地址必须是整数(取货/放货)");
|
||||
continue;
|
||||
}
|
||||
dto.setAddress(pick);
|
||||
dto.setAddress1(drop);
|
||||
dto.setUpdate_time(now);
|
||||
dto.setUpdate_by(nickName);
|
||||
exists.add(dto);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new BadRequestException("读取Excel失败:" + e.getMessage());
|
||||
}
|
||||
|
||||
if (!badMsg.isEmpty()) {
|
||||
throw new BadRequestException("数据格式错误:" + String.join(",", badMsg));
|
||||
}
|
||||
|
||||
if (!notExists.isEmpty()) {
|
||||
throw new BadRequestException("设备信息不存在:" + String.join(",", notExists));
|
||||
}
|
||||
|
||||
for (StorageCellDto dto : exists) {
|
||||
JSONObject json = (JSONObject) JSONObject.toJSON(dto);
|
||||
wo.update(json);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user