Commit b3c27a8f authored by 喻训浩's avatar 喻训浩

fix: avi修改

parent 13268530
......@@ -86,5 +86,6 @@ public class PaintshopStation {
@ApiModelProperty(notes = "旧状态",hidden = true)
private StationState oldState;
@ApiModelProperty(notes = "平移车到位信号",hidden = true)
private Boolean arrive;
}
......@@ -23,7 +23,8 @@ import javax.sql.DataSource;
"net.vtstar.zhongtong.avi.sqlserver.mapper",
"net.vtstar.zhongtong.avi.access.mapper",
"net.vtstar.zhongtong.avi.laboratory.mapper",
"net.vtstar.zhongtong.avi.gateway.parts.mapper"
"net.vtstar.zhongtong.avi.gateway.parts.mapper",
"net.vtstar.zhongtong.avi.monitoring.mapper"
},
sqlSessionFactoryRef = "sqlSessionFactoryMySQL")
public class MybatisMySQLConfig {
......
......@@ -24,6 +24,7 @@ public class PDAController {
@PostMapping("/hanzhuang/bound")
private Return hanZhuangBound(@RequestBody JSONObject json) {
log.info(json.toJSONString());
ParamAssert.notNull(json.get("vehicleNo"),"param is null");
ParamAssert.notNull(json.get("busNo"),"param is null");
return Return.success();
......@@ -33,6 +34,7 @@ public class PDAController {
@PostMapping("/change/skid")
private Return changeSkid(@RequestBody JSONObject json) {
log.info(json.toJSONString());
ParamAssert.notNull(json.get("sourceStation"),"param is null");
ParamAssert.notNull(json.get("sourceStation"),"param is null");
return Return.success();
......@@ -42,6 +44,7 @@ public class PDAController {
@PostMapping("/repair")
private Return repair(@RequestBody JSONObject json) {
log.info(json.toJSONString());
ParamAssert.notNull(json.get("busNo"),"param is null");
return Return.success();
}
......
package net.vtstar.zhongtong.avi.monitoring.domain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Table;
@Data
@ApiModel("滑撬")
@Table(name = "skid")
public class Skid {
@Column(name = "id")
private Long id;
@Column(name = "rfid")
@ApiModelProperty(notes = "滑撬rfid")
private String rfid;
@Column(name = "State")
@ApiModelProperty(notes = "状态:1上车 0下车")
private Integer State;
@ApiModelProperty(notes = "绑定车身号")
private String busNo;
}
......@@ -10,7 +10,16 @@ public class Vehicle {
private Long id;
@ApiModelProperty(notes = "平移车编号")
@ApiModelProperty(notes = "别名(平移车号)")
private String alias;
@ApiModelProperty(notes = "所属平移车道(从东向西(1,2,3,4))")
private Integer lane;
@ApiModelProperty(notes = " 转动:正转(true),反转(false)")
private Boolean turn;
@ApiModelProperty(notes = "rfid信息")
private String code;
@ApiModelProperty(notes = "左侧有无车信号")
......@@ -24,4 +33,10 @@ public class Vehicle {
@ApiModelProperty(notes = "当前右侧所在车道")
private String rightLane;
@ApiModelProperty(notes = "Rfid上下车信号,上车 1, 下车0")
private Boolean state;
@ApiModelProperty(notes = "当前绑定滑撬")
private String currentRfid;
}
package net.vtstar.zhongtong.avi.monitoring.job;
import lombok.extern.slf4j.Slf4j;
import net.vtstar.protocol.modbus.tcp.netty.packet.AbstractModbusResponse;
import net.vtstar.protocol.modbus.tcp.netty.packet.ReadCoilsResponse;
import net.vtstar.protocol.modbus.tcp.netty.packet.ReadMultipleRegistersResponse;
import net.vtstar.protocol.modbus.tcp.netty.utils.NettyUtils;
......@@ -54,6 +55,9 @@ public class AVIMonitorJob extends GatherJob {
if (CollectionUtils.isEmpty(equipInfoList)) {
return;
}
Map<String, PaintshopStation> stationMap = hashOperations.entries("station");
Map<String, Vehicle> vehicleMap = hashOperations.entries("vehicle_signal");
equipInfoList.forEach(equipInfo -> {
List<EquipCommunication> commList = equipInfoService.getCommunicationList(equipInfo.getEquipCode(), 1);
if (CollectionUtils.isEmpty(commList)) {
......@@ -83,53 +87,48 @@ public class AVIMonitorJob extends GatherJob {
Integer endAddress = itemList.get(itemList.size() - 1).getAddress();
Integer quantity = itemList.get(itemList.size() - 1).getLength();
Integer count = endAddress + quantity - startAddress;
if (1 == startTemplate.getFunctionCode()) {
try {
ReadCoilsResponse response = modbusService.readCoilRegister(slaveId, poolKey, startAddress, count);
Map<String, PaintshopStation> stationMap = stationCache.get("station", HashMap.class);
for (EquipDataTemplateItem item : itemList) {
String fieldName = item.getFieldName();
if (fieldName.startsWith("stationState")) {
String stationCode = fieldName.split("_")[1];
PaintshopStation station = stationCache.get(stationCode, PaintshopStation.class);
byte state = response.getBody().readByte();
station.setOldState(station.getState());
station.setState(state == 0 ? StationState.FREE : StationState.USE);
stationMap.put(stationCode, station);
}
if (fieldName.startsWith("vehicle_signal")) {
String[] split = fieldName.split("_");
String vehicleCode = split[3];
Map<String, Vehicle> map = hashOperations.entries("vehicle_signal");
Vehicle vehicle = map.get(vehicleCode);
byte state = response.getBody().readByte();
if (split[2].equals("left")) {
vehicle.setLeftSignal(state == 0 ? true : false);
}
if (split[2].equals("right")) {
vehicle.setRightSignal(state == 0 ? true : false);
}
}
}
stationCache.put("station", stationMap);
} catch (Exception e) {
log.info("读取失败。ip{},端口{},slave{},start{}", poolKey.getHost(), poolKey.getPort(), slaveId, startAddress);
AbstractModbusResponse response = null;
try {
if (1 == startTemplate.getFunctionCode()) {
response = modbusService.readCoilRegister(slaveId, poolKey, startAddress, count);
} else if (2 == startTemplate.getFunctionCode()) {
response = modbusService.readInputDiscretes(slaveId, poolKey, startAddress, count);
} else if (3 == startTemplate.getFunctionCode()) {
response = modbusService.readMultipleRegister(slaveId, poolKey, startAddress, count);
} else if (4 == startTemplate.getFunctionCode()) {
response = modbusService.readInputRegister(slaveId, poolKey, startAddress, count);
}
} catch (Exception e) {
log.info("读取失败。ip{},端口{},slave{},start{}", poolKey.getHost(), poolKey.getPort(), slaveId, startAddress);
continue;
}
if (3 == startTemplate.getFunctionCode()) {
try {
ReadMultipleRegistersResponse response = modbusService.readMultipleRegister(slaveId, poolKey, startAddress, count);
} catch (Exception e) {
log.info("读取失败。ip{},端口{},slave{},start{}", poolKey.getHost(), poolKey.getPort(), slaveId, startAddress);
for (EquipDataTemplateItem item : itemList) {
String fieldName = item.getFieldName();
if (fieldName.startsWith("stationState")) {
String stationCode = fieldName.split("_")[1];
PaintshopStation station = stationCache.get(stationCode, PaintshopStation.class);
byte state = response.getBody().readByte();
station.setOldState(station.getState());
station.setState(state == 0 ? StationState.FREE : StationState.USE);
// stationMap.put(stationCode, station);
}
if (fieldName.startsWith("station_vehicle_signal")) {
String[] split = fieldName.split("_");
String stationCode = split[3];
PaintshopStation station = stationMap.get(stationCode);
byte state = response.getBody().readByte();
station.setArrive(state == 1 ? true : false);
}
}
}
}
});
// stationCache.put("station", stationMap);
// hashOperations.putAll("station", stationMap);
}
public Object handleValue(String fieldName, Object value) {
if (fieldName.startsWith("stationState")) {
String stationCode = fieldName.split("_")[1];
......
package net.vtstar.zhongtong.avi.monitoring.mapper;
import net.vtstar.user.mybatis.BaseMapper;
import net.vtstar.zhongtong.avi.monitoring.domain.Skid;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface SkidMapper extends BaseMapper<Skid> {
}
......@@ -8,14 +8,19 @@ import net.vtstar.zhongtong.avi.equipment.domain.PaintshopArea;
import net.vtstar.zhongtong.avi.equipment.domain.PaintshopLane;
import net.vtstar.zhongtong.avi.equipment.domain.PaintshopStation;
import net.vtstar.zhongtong.avi.equipment.mapper.PaintshopStationMapper;
import net.vtstar.zhongtong.avi.monitoring.domain.Skid;
import net.vtstar.zhongtong.avi.monitoring.mapper.SkidMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.cache.Cache;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@Order(value = 1)
......@@ -28,6 +33,12 @@ public class ReadStationToCacheRunner implements CommandLineRunner {
private SearchService searchService;
@Autowired
private PaintshopStationMapper stationMapper;
@Autowired
private SkidMapper skidMapper;
// @Resource(name = "redisTemplate")
// protected HashOperations hashOperations;
@Override
public void run(String... args) throws Exception {
......@@ -38,11 +49,16 @@ public class ReadStationToCacheRunner implements CommandLineRunner {
addOrderBy(PaintshopStation.class, "sequence", OrderBy.ASC);
}}, PaintshopStation.class);
//
// Map<String, Skid> skidMap = hashOperations.entries("skid");
// if (null == skidMap) {
// List<Skid> skids = skidMapper.findList(null, Skid.class);
// Map<String, Skid> skid = skids.stream().collect(Collectors.toMap(Skid::getRfid, s -> s, (k1, k2) -> k1));
// hashOperations.putAll("skid", skid);
// }
for (PaintshopStation station : stations) {
stationCache.put(station.getCode(),station);
stationCache.put(station.getCode(), station);
}
}
}
......@@ -2,6 +2,9 @@ package net.vtstar.zhongtong.avi.mqtt.handle;
import lombok.extern.slf4j.Slf4j;
import net.vtstar.scada.base.mqtt.utils.MqttConstants;
import net.vtstar.zhongtong.avi.monitoring.domain.Skid;
import net.vtstar.zhongtong.avi.monitoring.domain.Vehicle;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.messaging.Message;
......@@ -10,40 +13,34 @@ import org.springframework.messaging.MessagingException;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Map;
@Slf4j
@Component
public class RfidMessageHandler extends AbstractTesterMessageHandler {
@Resource(name = "redisTemplate")
private ListOperations listOperations;
@Resource(name = "redisTemplate")
private ValueOperations valueOperations;
public RfidMessageHandler() {
super("skid", "data/all");
}
@Override
public void handleMessage(Message<?> message) throws MessagingException {
String payload = (String) message.getPayload();
System.out.println(payload);
MessageHeaders headers = message.getHeaders();
String equipmentNumber = headers.get(MqttConstants.MSG_HEADER_KEY_EQUIPMENTNUMBER, String.class);
/*try {
ChipCheckData data = new ChipCheckData();
data.setEquipCode(equipmentNumber);
data.setFangzuyi(new BigDecimal(payload).setScale(3, RoundingMode.HALF_UP));
data.setBeginTime(new Date());
log.info("方阻仪:" + data.getFangzuyi());
BaseKey baseKey = new BaseKey(ChipEquipType.FANGZUYI.getValue(), equipmentNumber);
listOperations.rightPush(baseKey.listKey(), data);
valueOperations.set(baseKey.lastKey(), data);
} catch (Exception e) {
log.error("handleMessage error:", e);
}*/
}
@Resource(name = "redisTemplate")
private ListOperations listOperations;
@Resource(name = "redisTemplate")
private HashOperations hashOperations;
@Resource(name = "redisTemplate")
private ValueOperations valueOperations;
public RfidMessageHandler() {
super("skid", "data/all");
}
@Override
public void handleMessage(Message<?> message) throws MessagingException {
Skid skid = (Skid) message.getPayload();
System.out.println(skid);
MessageHeaders headers = message.getHeaders();
String code = headers.get(MqttConstants.MSG_HEADER_KEY_EQUIPMENTNUMBER, String.class);
Map<String, Vehicle> vehicleMap = hashOperations.entries("vehicle");
Vehicle vehicle = vehicleMap.get(code);
vehicle.setState(skid.getState() == 1 ? true : false);
vehicle.setCurrentRfid(skid.getRfid());
valueOperations.set(code,vehicle);
}
}
......@@ -8,7 +8,7 @@ spring.profiles.include=mybatis,quartz,swagger,security,mqtt,ztip
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/zhongtong_dev?useSSL=false&useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.username =root
spring.datasource.password=123456
# sql server(试交车间--检测线192.168.1.200)
......
......@@ -31,7 +31,7 @@ quartz.job.taskInfos[1].jobGroup=CleanStatusDataJob
quartz.job.taskInfos[1].jobDescription=\u6E05\u6D17\u8BBE\u5907\u72B6\u6001Job
#quartz.job.taskInfos[1].cronExpression=0 0 0 * * ?
quartz.job.taskInfos[1].cronExpression=0/10 * * * * ?
quartz.job.taskInfos[1].start=true
quartz.job.taskInfos[1].start=false
quartz.job.taskInfos[2].jobName=net.vtstar.zhongtong.avi.equipment.job.StatisticsTimeJob
quartz.job.taskInfos[2].jobGroup=StatisticsTimeJob
......@@ -192,6 +192,14 @@ quartz.job.taskInfos[20].jobDescription=\u5145\u7535\u6869Job
quartz.job.taskInfos[20].cronExpression=0 0/15 * * * ?
quartz.job.taskInfos[20].start=false
#AVI plc 采集
quartz.job.taskInfos[24].jobName=net.vtstar.zhongtong.avi.monitoring.job.AVIMonitorJob
quartz.job.taskInfos[24].jobGroup=AVIMonitorJob
quartz.job.taskInfos[24].jobDescription=\u76d1\u63a7\u0041\u0056\u0049Job
quartz.job.taskInfos[24].cronExpression=0/10 * * * * ?
quartz.job.taskInfos[24].start=false
#quartz.job.taskInfos[8].jobName=net.vtstar.scada.base.equipmgt.job.CleanEquipStatusJob
##quartz.job.taskInfos[8].jobGroup=CleanEquipStatusJob
##quartz.job.taskInfos[8].jobDescription=\u6E05\u6D17\u8BBE\u5907\u72B6\u6001Job
......
......@@ -22,7 +22,7 @@ zt.ip.wheelalignment2=10.1.25.86
#底盘车间--四轮定位3
zt.ip.wheelalignment3=10.1.25.87
#试交车间--检测线
#试交车间]====================--检测线
zt.ip.testlineresult=10.100.172.150
#试交车间--限速值
zt.ip.testspeedresult=10.1.25.134
......
......@@ -9,7 +9,7 @@ spring.aop.auto=true
spring.main.allow-bean-definition-overriding=true
# server
server.port=8086
server.port=8080
spring.servlet.multipart.max-file-size=1000MB
spring.servlet.multipart.max-request-size=2000MB
spring.servlet.multipart.enabled=true
......
package net.vtstar.zhongtong.avi;
import io.netty.buffer.ByteBuf;
import lombok.extern.slf4j.Slf4j;
import net.vtstar.protocol.modbus.tcp.netty.packet.ReadCoilsRequest;
import net.vtstar.protocol.modbus.tcp.netty.packet.ReadCoilsResponse;
import net.vtstar.protocol.modbus.tcp.netty.service.ModbusTemplate;
import net.vtstar.protocol.modbus.tcp.netty.utils.PoolKey;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@ActiveProfiles("dev-yxh")
public class ModbusTest {
@Autowired
private ModbusTemplate modbusTemplate;
@Test
public void test() throws Exception {
ReadCoilsRequest readCoilsRequest = new ReadCoilsRequest(1,0,5);
PoolKey poolKey = new PoolKey("localhost",502);
ReadCoilsResponse response= modbusTemplate.execute(poolKey, readCoilsRequest, ReadCoilsResponse.class);
ByteBuf body = response.getBody();
byte b = body.readByte();
System.out.println("___" + b);
// byte[] array = body.array();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment