Commit 105810b7 authored by 喻训浩's avatar 喻训浩

fix: avi修改

parent 5a5c3c1b
......@@ -57,7 +57,7 @@ public class PaintshopStation implements Serializable {
private String laneCode;
@ApiModelProperty(notes = "平移车道编号")
//@JoinColumn(tableName = PaintshopLane.class, name = "vehicle_lane_code")
@Column(name = "vehicle_lane_code")
@Search
private String vehicleLaneCode;
......@@ -89,6 +89,10 @@ public class PaintshopStation implements Serializable {
@ApiModelProperty(value = "车体类型")
private ProductionType busType;
@ApiModelProperty(notes = "状态", hidden = true)
@Column(name = "status")
private String status;
@ApiModelProperty(notes = "旧状态", hidden = true)
private StationState oldState;
......@@ -98,6 +102,9 @@ public class PaintshopStation implements Serializable {
@ApiModelProperty(notes = "当前绑定滑撬", hidden = true)
private Skid skid;
@ApiModelProperty(notes = "工位正反转,正转true,翻转false", hidden = true)
private Boolean turn;
@ApiModelProperty(notes = "工位反转", hidden = true)
private Boolean turnR;
@ApiModelProperty(notes = "工位正转", hidden = true)
private Boolean turnF;
}
......@@ -32,4 +32,14 @@ public class CacheConfig {
Cache laneStationCache(ConcurrentMapCacheManager cacheManager) {
return cacheManager.getCache("laneStationCache");
}
@Bean
Cache vehicleCache(ConcurrentMapCacheManager cacheManager) {
return cacheManager.getCache("vehicleCache");
}
@Bean
Cache skidCache(ConcurrentMapCacheManager cacheManager) {
return cacheManager.getCache("skidCache");
}
}
......@@ -6,9 +6,9 @@ public class Constant {
public static final String STATION_PREFIX = "station:";
public static final String HANZHUANG_VEHICLE1_RFID = "11111";
public static final String HANZHUANG_VEHICLE1_RFID = "rfid68";
public static final String HANZHUANG_VEHICLE2_RFID = "22222";
public static final String HANZHUANG_VEHICLE2_RFID = "rfid69";
public static final String HANZHUANG_VEHICLE1_BUSNO_KEY = "HZC1";
......
......@@ -4,24 +4,35 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Table;
@ApiModel("平移车")
@Data
@Table(name = "vehicle")
public class Vehicle {
@Column(name = "id")
private Long id;
@ApiModelProperty(notes = "别名(平移车号)")
private String alias;
@ApiModelProperty(notes = "所属平移车道(从东向西(1,2,3,4))")
@Column(name = "lane")
private Integer lane;
@ApiModelProperty(notes = " 转动:正转(true),反转(false)")
private Boolean turn;
@Column(name = "code")
@ApiModelProperty(notes = "rfid信息")
private String code;
@Column(name = "mqtt_prefix")
@ApiModelProperty(notes = "rfid信息")
private String mqttPrefix;
@ApiModelProperty(notes = "左侧有无车信号")
private Boolean leftSignal;
......
package net.vtstar.zhongtong.avi.monitoring.domain.bo;
import lombok.Data;
import java.util.Date;
@Data
public class MQTTMessageBO {
private Integer State;
private String ID;
private String createDate;
}
......@@ -100,12 +100,24 @@ public class AVIMonitorJob extends GatherJob {
log.info("读取失败。ip{},端口{},slave{},start{}", poolKey.getHost(), poolKey.getPort(), slaveId, startAddress);
continue;
}
log.debug("___");
log.debug("slaveID:" + slaveId + " start:" + startAddress + " count:" + count + " functionCode:" + startTemplate.getFunctionCode());
if (null == response) {
log.error("读取异常!");
continue;
}
if (!response.isSuccess()) {
log.error(response.getError());
continue;
}
for (EquipDataTemplateItem item : itemList) {
String fieldName = item.getFieldName();
if (fieldName.startsWith("station:ve")) {
String stationCode = fieldName.split(":")[2];
PaintshopStation station = (PaintshopStation) valueOperations.get(Constant.STATION_PREFIX + stationCode);
log.debug("__________________");
log.debug("stationCode " + stationCode);
if (null == station) {
station = stationCache.get(stationCode, PaintshopStation.class);
}
......@@ -116,12 +128,15 @@ public class AVIMonitorJob extends GatherJob {
} else {
state = 1;
}
log.debug(station.toString());
station.setOldState(station.getState());
station.setState(state == 0 ? StationState.FREE : StationState.USE);
station.setArrive(state == 1 ? true : false);
valueOperations.set(Constant.STATION_PREFIX + stationCode, station);
}
if (fieldName.startsWith("station:turn")) {
String stationCode = fieldName.split(":")[3];
String[] split = fieldName.split(":");
String stationCode = fieldName.split(":")[2];
PaintshopStation station = (PaintshopStation) valueOperations.get(Constant.STATION_PREFIX + stationCode);
if (null == station) {
station = stationCache.get(stationCode, PaintshopStation.class);
......@@ -133,7 +148,13 @@ public class AVIMonitorJob extends GatherJob {
state = 1;
}
station.setOldState(station.getState());
station.setTurn(state == 0 ? true : false);
String turn = split[1];
if (turn.endsWith("F")) {
station.setTurnF(state == 1 ? true : false);
}
if (turn.endsWith("R")) {
station.setTurnR(state == 1 ? true : false);
}
valueOperations.set(Constant.STATION_PREFIX + stationCode, station);
}
}
......
package net.vtstar.zhongtong.avi.monitoring.mapper;
import net.vtstar.user.mybatis.BaseMapper;
import net.vtstar.zhongtong.avi.monitoring.domain.Skid;
import net.vtstar.zhongtong.avi.monitoring.domain.Vehicle;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface VehicleMapper extends BaseMapper<Vehicle> {
}
......@@ -9,7 +9,9 @@ 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.domain.Vehicle;
import net.vtstar.zhongtong.avi.monitoring.mapper.SkidMapper;
import net.vtstar.zhongtong.avi.monitoring.mapper.VehicleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.cache.Cache;
......@@ -29,16 +31,22 @@ public class ReadStationToCacheRunner implements CommandLineRunner {
@Resource(name = "stationCache")
private Cache stationCache;
@Resource(name = "vehicleCache")
private Cache vehicleCache;
@Resource(name = "laneStationCache")
private Cache laneStationCache;
@Resource(name = "redisTemplate")
protected HashOperations hashOperations;
@Autowired
private SearchService searchService;
@Autowired
private PaintshopStationMapper stationMapper;
@Autowired
private VehicleMapper vehicleMapper;
@Autowired
private SkidMapper skidMapper;
@Resource(name = "redisTemplate")
protected HashOperations hashOperations;
@Override
public void run(String... args) throws Exception {
......@@ -53,6 +61,16 @@ public class ReadStationToCacheRunner implements CommandLineRunner {
stationCache.put(station.getCode(),station);
}
Map<String, List<PaintshopStation>> stationMap = stations.stream().filter(sta -> sta.getVehicleLaneCode() != null).collect(Collectors.groupingBy(PaintshopStation::getVehicleLaneCode));
for (Map.Entry<String, List<PaintshopStation>> entry : stationMap.entrySet()) {
laneStationCache.put(entry.getKey(),entry.getValue());
}
List<Vehicle> vehicles = vehicleMapper.findList(new WhereFilter(), Vehicle.class);
for (Vehicle vehicle : vehicles) {
vehicleCache.put(vehicle.getMqttPrefix(),vehicle);
}
//
// Map<String, Skid> skidMap = hashOperations.entries("skid");
// if (null == skidMap) {
......
......@@ -14,6 +14,7 @@ import net.vtstar.zhongtong.avi.equipment.mapper.PaintshopStationMapper;
import net.vtstar.zhongtong.avi.global.constant.Constant;
import net.vtstar.zhongtong.avi.monitoring.domain.Skid;
import net.vtstar.zhongtong.avi.monitoring.domain.Vehicle;
import net.vtstar.zhongtong.avi.monitoring.domain.bo.MQTTMessageBO;
import net.vtstar.zhongtong.avi.monitoring.domain.enums.StationState;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
......@@ -26,18 +27,20 @@ import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.MessagingException;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import springfox.documentation.spring.web.json.Json;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Component
public class RfidMessageHandler extends AbstractTesterMessageHandler {
public static MQTTMessageBO messageBO = new MQTTMessageBO();
public static SimpleDateFormat format =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@Autowired
private RedisTemplate redisTemplate;
......@@ -52,6 +55,10 @@ public class RfidMessageHandler extends AbstractTesterMessageHandler {
@Resource(name = "laneStationCache")
private Cache laneStationCache;
@Resource(name = "stationCache")
private Cache stationCache;
@Resource(name = "vehicleCache")
private Cache vehicleCache;
@Autowired
private ModbusService modbusService;
......@@ -61,104 +68,120 @@ public class RfidMessageHandler extends AbstractTesterMessageHandler {
private PaintshopStationMapper stationMapper;
public RfidMessageHandler() {
super("skid", "data/all");
super("translation", "data/all");
}
@Override
public void handleMessage(Message<?> message) throws MessagingException {
JSONObject json = (JSONObject) message.getPayload();
Object payload = message.getPayload();
JSONObject json = JSONObject.parseObject(payload.toString());
String id = json.getString("ID");
Integer state = json.getIntValue("state");
Integer state = json.getIntValue("State");
messageBO.setID(id);
messageBO.setState(state);
messageBO.setCreateDate(format.format(new Date()));
MessageHeaders headers = message.getHeaders();
String vehicleCode = headers.get(MqttConstants.MSG_HEADER_KEY_EQUIPMENTNUMBER, String.class);
Map<String, Vehicle> vehicleMap = hashOperations.entries("vehicle");
Skid skid = (Skid) valueOperations.get(Constant.SKID_PREFIX + id);
if (vehicleCode.equals(Constant.HANZHUANG_VEHICLE1_RFID) || vehicleCode.equals(Constant.HANZHUANG_VEHICLE1_RFID)) {
String busNo = (String) valueOperations.get(vehicleCode);
skid.setBusNo(busNo);
valueOperations.set(Constant.SKID_PREFIX + id, skid);
}
Vehicle vehicle = vehicleMap.get(vehicleCode);
// TODO: 2019-11-02 获得正反转信息,以及相邻的工位
Integer land = vehicle.getLane();
Set<String> keys = redisTemplate.keys(Constant.STATION_PREFIX + land + ":*");
List<PaintshopStation> arriveList = new ArrayList<>();
List<PaintshopStation> stationList = laneStationCache.get(land.toString(), ArrayList.class);
for (PaintshopStation station : stationList) {
String code = station.getCode();
PaintshopStation sta = (PaintshopStation) valueOperations.get(Constant.STATION_PREFIX + code);
if (sta.getArrive()) {
arriveList.add(sta);
}
}
if (CollectionUtils.isEmpty(stationList)) {
log.error("找不到对平移车到位信号! 平移车 id:{},滑撬 {}", vehicle.getCode(), id);
return;
}
Map<String, List<PaintshopStation>> listMap = stationList.stream().filter(sta -> sta.getTurn() != null)
.collect(Collectors.groupingBy(PaintshopStation::getLaneCode));
PaintshopStation sourceStation = new PaintshopStation();
if (listMap.size() > 1) {
Set<String> veKeys = redisTemplate.keys(Constant.VEHICLE_PREFIX);
if (CollectionUtils.isEmpty(veKeys) || veKeys.size() != listMap.size()) {
log.error("平移车读写信号数量:{} 与 到位信号数量不一致!{}", veKeys.size(), listMap.size());
return;
}
for (String veKey : veKeys) {
Vehicle v = (Vehicle) valueOperations.get(veKey);
}
} else {
List<PaintshopStation> stations = listMap.get(0);
if (stations.size() == 1) {
sourceStation = stations.get(0);
} else {
}
}
Long laneId = sourceStation.getLaneId();
vehicle.setCurrentRfid(id);
StationState oldState = null;
String oldSkidId = null;
if (state == 1) {
//获得正反转信息,得到平移车相邻工位信息
List<PaintshopStation> stations;
stations = stationMapper.findList(new WhereFilter() {{
addFilter(PaintshopStation.class, "lane_id", Operation.EQUAL, laneId);
addOrderBy(RuntimeRecord.class, "sequence", OrderBy.DESC);
}}, PaintshopStation.class);
for (PaintshopStation station : stations) {
station.setOldState(oldState);
station.setSkidID(oldSkidId);
oldState = station.getState();
oldSkidId = station.getSkidID();
station.setState(StationState.USE);
station.setSkidID(id);
}
String currentRfid = vehicle.getCurrentRfid();
vehicle.setCurrentRfid(null);
} else if (state == 0) {
List<PaintshopStation> stations = new ArrayList<>();
for (PaintshopStation station : stations) {
station.setOldState(oldState);
station.setSkidID(oldSkidId);
oldState = station.getState();
oldSkidId = station.getSkidID();
station.setState(StationState.FREE);
station.setSkidID(id);
}
PaintshopStation station = new PaintshopStation();
station.setState(StationState.FREE);
station.setSkidID(null);
}
log.info(vehicleCode + "______" + json.toJSONString());
listOperations.rightPush("rfid:log:" + vehicleCode,messageBO);
// Map<String, Vehicle> vehicleMap = hashOperations.entries("vehicle");
//
// Skid skid = (Skid) valueOperations.get(Constant.SKID_PREFIX + id);
// if (vehicleCode.equals(Constant.HANZHUANG_VEHICLE1_RFID) || vehicleCode.equals(Constant.HANZHUANG_VEHICLE1_RFID)) {
// String busNo = (String) valueOperations.get(vehicleCode);
// skid.setBusNo(busNo);
// valueOperations.set(Constant.SKID_PREFIX + id, skid);
// }
// Vehicle vehicle = vehicleMap.get(vehicleCode);
// if (null == vehicle) {
// vehicle = vehicleCache.get(vehicleCode, Vehicle.class);
// }
// // TODO: 2019-11-02 获得正反转信息,以及相邻的工位
// Integer land = vehicle.getLane();
// Set<String> keys = redisTemplate.keys(Constant.STATION_PREFIX + land + ":*");
//
// List<PaintshopStation> arriveList = new ArrayList<>();
//
// List<PaintshopStation> stationList = laneStationCache.get(land.toString(), ArrayList.class);
// for (PaintshopStation station : stationList) {
// String code = station.getCode();
// PaintshopStation sta = (PaintshopStation) valueOperations.get(Constant.STATION_PREFIX + code);
// if (null == sta) {
// sta = stationCache.get(code, PaintshopStation.class);
// }
// if (null == sta.getArrive()) {
// continue;
// }
// if (sta.getArrive()) {
// arriveList.add(sta);
// }
// }
// if (CollectionUtils.isEmpty(stationList)) {
// log.error("找不到对平移车到位信号! 平移车 id:{},滑撬 {}", vehicle.getCode(), id);
// return;
// }
//
// Map<String, List<PaintshopStation>> listMap = stationList.stream().filter(sta -> sta.getTurnF() != null && sta.getTurnR() !=null)
// .collect(Collectors.groupingBy(PaintshopStation::getLaneCode));
//
// PaintshopStation sourceStation = new PaintshopStation();
//
// if (listMap.size() > 1) {
// Set<String> veKeys = redisTemplate.keys(Constant.VEHICLE_PREFIX);
// if (CollectionUtils.isEmpty(veKeys) || veKeys.size() != listMap.size()) {
// log.error("平移车读写信号数量:{} 与 到位信号数量不一致!{}", veKeys.size(), listMap.size());
// return;
// }
// for (String veKey : veKeys) {
// Vehicle v = (Vehicle) valueOperations.get(veKey);
// }
// } else {
// List<PaintshopStation> stations = listMap.get(0);
// if (stations.size() == 1) {
// sourceStation = stations.get(0);
// } else {
// }
// }
//
// Long laneId = sourceStation.getLaneId();
//
// vehicle.setCurrentRfid(id);
// StationState oldState = null;
// String oldSkidId = null;
// if (state == 1) {
// //获得正反转信息,得到平移车相邻工位信息
// List<PaintshopStation> stations;
// stations = stationMapper.findList(new WhereFilter() {{
// addFilter(PaintshopStation.class, "lane_id", Operation.EQUAL, laneId);
// addOrderBy(RuntimeRecord.class, "sequence", OrderBy.DESC);
// }}, PaintshopStation.class);
//
// for (PaintshopStation station : stations) {
// station.setOldState(oldState);
// station.setSkidID(oldSkidId);
// oldState = station.getState();
// oldSkidId = station.getSkidID();
// station.setState(StationState.USE);
// station.setSkidID(id);
// }
// String currentRfid = vehicle.getCurrentRfid();
// vehicle.setCurrentRfid(null);
// } else if (state == 0) {
// List<PaintshopStation> stations = new ArrayList<>();
// for (PaintshopStation station : stations) {
// station.setOldState(oldState);
// station.setSkidID(oldSkidId);
// oldState = station.getState();
// oldSkidId = station.getSkidID();
// station.setState(StationState.FREE);
// station.setSkidID(id);
// }
// PaintshopStation station = new PaintshopStation();
// station.setState(StationState.FREE);
// station.setSkidID(null);
// }
}
}
spring.profiles.include=mybatis,quartz,swagger,security,mqtt,ztip
spring.profiles.include=mybatis,quartz,swagger,security,mqtt,ztip,modbus
# Mysql
#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
......
modbus.tcp.netty.thread-num=200
modbus.tcp.netty.pool.max-connections=10
modbus.tcp.netty.option.so-keep-alive=true
modbus.tcp.netty.max-frame-length=260
modbus.tcp.netty.idle-state.reader-time-millis=3000
modbus.tcp.netty.event-executor-group.thread-num=64
......@@ -16,27 +16,27 @@ mqtt.subscribe.data-system-topic-suffix=system
mqtt.subscribe.data-alarm-topic-suffix=alarm
mqtt.subscribe.data-all-topic-suffix=all
mqtt.subscribe.topics=\
ZT/translation/rfid01/data/all,\
ZT/translation/rfid02/data/all,\
ZT/translation/rfid03/data/all,\
ZT/translation/rfid04/data/all,\
ZT/translation/rfid05/data/all,\
ZT/translation/rfid06/data/all,\
ZT/translation/rfid07/data/all,\
ZT/translation/rfid08/data/all,\
ZT/translation/rfid09/data/all,\
ZT/translation/rfid10/data/all,\
ZT/translation/rfid11/data/all,\
ZT/translation/rfid12/data/all,\
ZT/translation/rfid13/data/all,\
ZT/skid/rfid01/data/all,\
ZT/skid/rfid02/data/all,\
ZT/skid/rfid03/data/all,\
ZT/skid/rfid04/data/all,\
ZT/skid/rfid05/data/all,\
ZT/skid/rfid06/data/all,\
ZT/skid/rfid07/data/all,\
ZT/skid/rfid08/data/all,\
ZT/skid/rfid09/data/all,\
ZT/skid/rfid10/data/all,\
ZT/skid/rfid11/data/all
ZT/translation/rfid51/data/all,\
ZT/translation/rfid52/data/all,\
ZT/translation/rfid53/data/all,\
ZT/translation/rfid54/data/all,\
ZT/translation/rfid55/data/all,\
ZT/translation/rfid56/data/all,\
ZT/translation/rfid57/data/all,\
ZT/translation/rfid58/data/all,\
ZT/translation/rfid59/data/all,\
ZT/translation/rfid60/data/all,\
ZT/translation/rfid61/data/all,\
ZT/translation/rfid62/data/all,\
ZT/translation/rfid63/data/all,\
ZT/translation/rfid64/data/all,\
ZT/translation/rfid65/data/all,\
ZT/translation/rfid66/data/all,\
ZT/translation/rfid67/data/all,\
ZT/translation/rfid68/data/all,\
ZT/translation/rfid69/data/all,\
ZT/translation/rfid70/data/all,\
ZT/translation/rfid71/data/all,\
ZT/translation/rfid72/data/all,\
ZT/translation/rfid73/data/all,\
ZT/translation/rfid74/data/all
......@@ -203,8 +203,8 @@ quartz.job.taskInfos[20].start=false
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=true
quartz.job.taskInfos[24].cronExpression=0/20 * * * * ?
quartz.job.taskInfos[24].start=false
#mes 工单同步
quartz.job.taskInfos[26].jobName=net.vtstar.zhongtong.avi.sqlserver.job.MesWorkOrderJob
......
......@@ -2,7 +2,7 @@
spring.output.ansi.enabled=always
spring.main.banner-mode=off
logging.level.root=info
logging.level.net.vtstar=trace
logging.level.net.vtstar=debug
#logging.file=D://zhongtong/logs/zhongtong-service.log
spring.aop.auto=true
......
......@@ -13,6 +13,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import javax.validation.constraints.NotNull;
import java.util.List;
@Slf4j
......@@ -27,14 +28,53 @@ public class StationTest {
private EquipDataTemplateItemMapper itemMapper;
@Test
public void test(){
List<EquipDataTemplateItem> tem = itemMapper.findByTemplateId(1);
EquipDataTemplateItem item = tem.get(0);
for (int i = 0; i < 130; i++) {
item.setAddress(0);
public void test() {
List<EquipDataTemplateItem> tem = itemMapper.findByTemplateId(2);
for (EquipDataTemplateItem item : tem) {
item.setTemplateId(1);
item.setFieldDesc("正转信号");
item.setFunctionCode(1);
item.setAddress(null);
item.setId(null);
itemMapper.insert(item);
item.setFieldDesc("反转信号");
itemMapper.insert(item);
}
}
@Test
public void stationTest() {
List<EquipDataTemplateItem> list = itemMapper.findByTemplateId(2);
for (EquipDataTemplateItem station : list) {
String newCdoe;
if (station.getId() <= 145) {
continue;
}
String code = station.getFieldName();
String[] split = code.split(":");
String stationCode = split[2];
String s = split[1];
if (s.endsWith("F")){
newCdoe = "station:turnF:" + stationCode;
}else {
newCdoe = "station:turnR:" + stationCode;
}
station.setFieldName(newCdoe);
itemMapper.update(station);
}
}
@Test
public void createStation() {
PaintshopStation station = new PaintshopStation();
station.setWorkshopCode("1");
station.setKeyStation(true);
station.setStatus("1");
for (int i = 1; i < 34; i++) {
station.setCode("HDG5-" + i);
stationMapper.insert(station);
}
}
}
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