Commit 9a18238b authored by 夏东伟's avatar 夏东伟

设备实时状态功能开发;

parent e8ec2f2a
...@@ -11,6 +11,7 @@ import net.vtstar.user.mybatis.provider.WhereFilter; ...@@ -11,6 +11,7 @@ import net.vtstar.user.mybatis.provider.WhereFilter;
import net.vtstar.utils.DateUtils; import net.vtstar.utils.DateUtils;
import net.vtstar.zhongtong.avi.access.domain.AssemblyNewEnergy; import net.vtstar.zhongtong.avi.access.domain.AssemblyNewEnergy;
import net.vtstar.zhongtong.avi.access.mapper.AssemblyNewEnergyMapper; import net.vtstar.zhongtong.avi.access.mapper.AssemblyNewEnergyMapper;
import net.vtstar.zhongtong.avi.equipment.service.EquipStatusRealTimeService;
import net.vtstar.zhongtong.avi.utils.PingIpUtils; import net.vtstar.zhongtong.avi.utils.PingIpUtils;
import net.vtstar.zhongtong.avi.utils.SmbFileUtil; import net.vtstar.zhongtong.avi.utils.SmbFileUtil;
import org.quartz.DisallowConcurrentExecution; import org.quartz.DisallowConcurrentExecution;
...@@ -55,6 +56,9 @@ public class AssemblyNewEnergyJob extends QuartzJobBean { ...@@ -55,6 +56,9 @@ public class AssemblyNewEnergyJob extends QuartzJobBean {
private String baseUrl = "D:/scada/assemblynewenergy/"; private String baseUrl = "D:/scada/assemblynewenergy/";
@Autowired
private EquipStatusRealTimeService realTimeService;
@Override @Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException { protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
List<String> ipAddressList = Arrays.asList(ipAddress1, ipAddress2, ipAddress3, ipAddress4); List<String> ipAddressList = Arrays.asList(ipAddress1, ipAddress2, ipAddress3, ipAddress4);
...@@ -63,10 +67,27 @@ public class AssemblyNewEnergyJob extends QuartzJobBean { ...@@ -63,10 +67,27 @@ public class AssemblyNewEnergyJob extends QuartzJobBean {
Date startOfDay = DateUtils.getStartOfDay(0); Date startOfDay = DateUtils.getStartOfDay(0);
String dateString = DateUtils.parseDateToString(startOfDay, "yyyy-MM-dd"); String dateString = DateUtils.parseDateToString(startOfDay, "yyyy-MM-dd");
for (String ipAddress : ipAddressList){ for (String ipAddress : ipAddressList){
String equipCode = "";
switch (ipAddress){
case "10.1.25.128":
equipCode = "742609-87";
break;
case "10.1.25.129":
equipCode = "742609-88";
break;
case "10.1.25.130":
equipCode = "742609-89";
break;
case "10.1.25.131":
equipCode = "742609-107";
break;
}
if (!PingIpUtils.ping(ipAddress, pingTimes, timeOut)) { if (!PingIpUtils.ping(ipAddress, pingTimes, timeOut)) {
log.error("ping: {}失败, 此次同步总装新能源检测点数据操作结束!", ipAddress); log.error("ping: {}失败, 此次同步总装新能源检测点数据操作结束!", ipAddress);
realTimeService.saveEquip("总装车间", equipCode, "新能源检测点", "关机");
continue; continue;
} }
realTimeService.saveEquip("总装车间", equipCode, "新能源检测点", "开机");
//todo:账户, 密码需要变 //todo:账户, 密码需要变
String url = "smb://admin:123456@" + ipAddress + "/AN9637H/testdata@" + dateString + ".mdb"; String url = "smb://admin:123456@" + ipAddress + "/AN9637H/testdata@" + dateString + ".mdb";
// String url = "smb://admin:123456@10.1.25.128/an9637h/test/data@2018-05-04.mdb"; // String url = "smb://admin:123456@10.1.25.128/an9637h/test/data@2018-05-04.mdb";
......
...@@ -11,6 +11,7 @@ import net.vtstar.user.mybatis.provider.WhereFilter; ...@@ -11,6 +11,7 @@ import net.vtstar.user.mybatis.provider.WhereFilter;
import net.vtstar.utils.DateUtils; import net.vtstar.utils.DateUtils;
import net.vtstar.zhongtong.avi.access.domain.WheelAlignment; import net.vtstar.zhongtong.avi.access.domain.WheelAlignment;
import net.vtstar.zhongtong.avi.access.mapper.WheelAlignmentMapper; import net.vtstar.zhongtong.avi.access.mapper.WheelAlignmentMapper;
import net.vtstar.zhongtong.avi.equipment.service.EquipStatusRealTimeService;
import net.vtstar.zhongtong.avi.sqlserver.domain.TestLineResult; import net.vtstar.zhongtong.avi.sqlserver.domain.TestLineResult;
import net.vtstar.zhongtong.avi.utils.PingIpUtils; import net.vtstar.zhongtong.avi.utils.PingIpUtils;
import net.vtstar.zhongtong.avi.utils.SmbFileUtil; import net.vtstar.zhongtong.avi.utils.SmbFileUtil;
...@@ -53,6 +54,8 @@ public class WheelAlignmentJob extends QuartzJobBean { ...@@ -53,6 +54,8 @@ public class WheelAlignmentJob extends QuartzJobBean {
private int timeOut; private int timeOut;
private String baseUrl = "D:/scada/wheelalignment/"; private String baseUrl = "D:/scada/wheelalignment/";
@Autowired
private EquipStatusRealTimeService realTimeService;
@Override @Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException { protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
...@@ -65,10 +68,28 @@ public class WheelAlignmentJob extends QuartzJobBean { ...@@ -65,10 +68,28 @@ public class WheelAlignmentJob extends QuartzJobBean {
String newDateString = sdf.format(new Date()); String newDateString = sdf.format(new Date());
String dataBaseFileName = "BL_Align"; String dataBaseFileName = "BL_Align";
for (String ipAddress : ipAddressList){ for (String ipAddress : ipAddressList){
String equipCode = "";
String equipName = "";
switch (ipAddress){
case "10.1.25.86":
equipCode = "742609-50";
equipName = "四轮定位B线";
break;
case "10.1.25.87":
equipCode = "742609-17";
equipName = "四轮定位A线";
break;
case "10.1.25.88":
equipCode = "742609-61";
equipName = "四轮定位C线";
break;
}
if (!PingIpUtils.ping(ipAddress, pingTimes, timeOut)) { if (!PingIpUtils.ping(ipAddress, pingTimes, timeOut)) {
log.error("ping: {}失败, 此次同步底盘四轮定位数据操作结束!", ipAddress); log.error("ping: {}失败, 此次同步底盘四轮定位数据操作结束!", ipAddress);
realTimeService.saveEquip("底盘车间", equipCode, equipName, "关机");
continue; continue;
} }
realTimeService.saveEquip("底盘车间", equipCode, equipName, "开机");
//todo:账户, 密码, 文件位置需要变 BL_Align(数据库文件) //todo:账户, 密码, 文件位置需要变 BL_Align(数据库文件)
String url = "smb://" + ipAddress + "/Database/" + dataBaseFileName + ".mdb"; String url = "smb://" + ipAddress + "/Database/" + dataBaseFileName + ".mdb";
SmbFile file = null; SmbFile file = null;
......
...@@ -10,6 +10,7 @@ import net.vtstar.utils.domain.Return; ...@@ -10,6 +10,7 @@ import net.vtstar.utils.domain.Return;
import net.vtstar.zhongtong.avi.equipment.domain.EquipInfo; import net.vtstar.zhongtong.avi.equipment.domain.EquipInfo;
import net.vtstar.zhongtong.avi.equipment.domain.PaintshopStation; import net.vtstar.zhongtong.avi.equipment.domain.PaintshopStation;
import net.vtstar.zhongtong.avi.equipment.service.BasicInfoService; import net.vtstar.zhongtong.avi.equipment.service.BasicInfoService;
import net.vtstar.zhongtong.avi.equipment.service.EquipStatusRealTimeService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -30,6 +31,9 @@ public class BasicInfoController { ...@@ -30,6 +31,9 @@ public class BasicInfoController {
@Autowired @Autowired
BasicInfoService basicInfoService; BasicInfoService basicInfoService;
@Autowired
private EquipStatusRealTimeService realTimeService;
@ApiOperation(value = "分页查询设备列表", notes = "使用通用搜索组件,searchCode:SCADA_EQUIP_INFO\n" + @ApiOperation(value = "分页查询设备列表", notes = "使用通用搜索组件,searchCode:SCADA_EQUIP_INFO\n" +
"字段含义:\n{\n" + "字段含义:\n{\n" +
" \"workshopName\": \"车间,字符串类型\",\n" + " \"workshopName\": \"车间,字符串类型\",\n" +
...@@ -151,4 +155,15 @@ public class BasicInfoController { ...@@ -151,4 +155,15 @@ public class BasicInfoController {
public Return getWorkOrder(@RequestBody SearchVo pageFilter) { public Return getWorkOrder(@RequestBody SearchVo pageFilter) {
return Return.success(new PageInfo<>(basicInfoService.getWorkOrder(pageFilter.toJSONObject()))); return Return.success(new PageInfo<>(basicInfoService.getWorkOrder(pageFilter.toJSONObject())));
} }
@ApiOperation(value = "设备实时状态查询", notes = "字段含义:\n{\n" +
" \"equipWorkshop\": \"车间,字符串类型\",\n" +
" \"equipCode\": \"设备编号,字符串类型\",\n" +
" \"equipName\": \"设备名称,字符串类型\",\n" +
" \"equipState\": \"实时状态,字符串类型\",\n" +
"}")
@PostMapping("/equipStatusRealTime")
public Return equipStatusRealTime(@RequestBody SearchVo pageFilter) {
return Return.success(new PageInfo<>(realTimeService.findPageEquipRealStatus(pageFilter.toJSONObject())));
}
} }
package net.vtstar.zhongtong.avi.equipment.domain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import net.vtstar.user.search.Search;
import net.vtstar.zhongtong.avi.equipment.domain.enums.WorkshopNames;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
/**
* @Author: xiadongwei
* @Date: 2020/3/11 16:53
*/
@ApiModel("设备实时状态表")
@Data
@Search(code = "REAL_TIME_STATUS")
@Table(name = "equip_status_real_time")
public class EquipStatusRealTime {
@Id
private Long id;
@ApiModelProperty(notes = "车间")
@Column(name = "equip_workshop")
@Search
private WorkshopNames equipWorkshop;
@ApiModelProperty(notes = "设备编号")
@Column(name = "equip_code")
@Search
private String equipCode;
@ApiModelProperty(notes = "设备名称")
@Column(name = "equip_name")
@Search
private String equipName;
@ApiModelProperty(notes = "实时状态")
@Column(name = "equip_state")
private String equipState;
@ApiModelProperty(notes = "创建时间")
@Column(name = "create_time")
private Date createTime;
}
package net.vtstar.zhongtong.avi.equipment.domain.enums;
/**
* @Author: xiadongwei
* @Date: 2020/3/13 13:44
*/
public enum WorkshopNames {
制件车间,
焊装车间,
涂装车间,
底盘车间,
装配车间,
试交车间,
质量管理部,
其他
}
...@@ -5,18 +5,21 @@ import net.vtstar.scada.base.equipmgt.service.EquipDataService; ...@@ -5,18 +5,21 @@ import net.vtstar.scada.base.equipmgt.service.EquipDataService;
import net.vtstar.scada.base.gather.domain.EquipmentData; import net.vtstar.scada.base.gather.domain.EquipmentData;
import net.vtstar.scada.base.redis.service.SimpleRedisService; import net.vtstar.scada.base.redis.service.SimpleRedisService;
import net.vtstar.scada.base.redis.util.EquipDataUtil; import net.vtstar.scada.base.redis.util.EquipDataUtil;
import net.vtstar.zhongtong.avi.equipment.domain.EquipInfo;
import net.vtstar.zhongtong.avi.equipment.mapper.EquipmentDataMapper; import net.vtstar.zhongtong.avi.equipment.mapper.EquipmentDataMapper;
import net.vtstar.zhongtong.avi.equipment.service.BasicInfoService;
import net.vtstar.zhongtong.avi.equipment.service.EquipStatusRealTimeService;
import org.quartz.DisallowConcurrentExecution; import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext; import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException; import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.scheduling.quartz.QuartzJobBean; import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
...@@ -28,12 +31,18 @@ public class CleanStatusDataJob extends QuartzJobBean { ...@@ -28,12 +31,18 @@ public class CleanStatusDataJob extends QuartzJobBean {
@Resource(name = "redisTemplate") @Resource(name = "redisTemplate")
private RedisTemplate redisTemplate; private RedisTemplate redisTemplate;
@Resource(name = "redisTemplate")
protected ValueOperations valueOperations;
@Autowired @Autowired
private EquipDataService equipDataService; private EquipDataService equipDataService;
@Autowired @Autowired
private SimpleRedisService simpleRedisService; private SimpleRedisService simpleRedisService;
@Autowired @Autowired
private EquipmentDataMapper equipmentDataMapper; private EquipmentDataMapper equipmentDataMapper;
@Autowired
private BasicInfoService basicInfoService;
@Autowired
private EquipStatusRealTimeService realTimeService;
@Override @Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException { protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
...@@ -41,66 +50,101 @@ public class CleanStatusDataJob extends QuartzJobBean { ...@@ -41,66 +50,101 @@ public class CleanStatusDataJob extends QuartzJobBean {
log.info("_______________________________________________________________"); log.info("_______________________________________________________________");
log.info("开始清洗设备状态数据..."); log.info("开始清洗设备状态数据...");
Set<String> keys = redisTemplate.keys(EquipDataUtil.getStatusKey("*")); Set<String> keys = redisTemplate.keys(EquipDataUtil.getStatusKey("*"));
if (CollectionUtils.isEmpty(keys)) { if (!CollectionUtils.isEmpty(keys)) {
return; log.info("开始清洗设备状态数据 key.size: {}", keys.size());
}
log.info("开始清洗设备状态数据 key.size: {}", keys.size());
for (String key : keys) {
List<EquipmentData> dataList = (List<EquipmentData>) simpleRedisService.getListDelDefaultSize(key);
if (CollectionUtils.isEmpty(dataList)) {
continue;
}
if (key.contains("DRYING_ROOM_TEMP")){
//插入设备监控数据
equipmentDataMapper.insert(dataList.get(0));
}else{
//插入设备监控数据
equipmentDataMapper.insertList(dataList);
}
if (key.contains("DRYING_ROOM_TEMP") || key.contains("SPRAY_BOOTH")){
continue;
}
equipDataService.updateLastStatus(dataList.get(dataList.size() - 1));
String equipCode = dataList.get(0).getEquipCode();
EquipmentData last = equipDataService.getLast(equipCode);
final EquipmentData first = last;
int index = 1;
for (int i = 0; i < dataList.size(); i++) {
if (last == null) { for (String key : keys) {
last = dataList.get(0); List<EquipmentData> dataList = (List<EquipmentData>) simpleRedisService.getListDelDefaultSize(key);
if (CollectionUtils.isEmpty(dataList)) {
continue; continue;
} }
if (key.contains("DRYING_ROOM_TEMP")){
if (last.getBeginTime() == null || last.getEquipStatus() == null) { //插入设备监控数据
redisTemplate.delete(key); equipmentDataMapper.insert(dataList.get(0));
break; }else{
//插入设备监控数据
equipmentDataMapper.insertList(dataList);
} }
if (key.contains("DRYING_ROOM_TEMP") || key.contains("SPRAY_BOOTH")){
continue;
}
equipDataService.updateLastStatus(dataList.get(dataList.size() - 1));
String equipCode = dataList.get(0).getEquipCode();
EquipmentData last = equipDataService.getLast(equipCode);
final EquipmentData first = last;
int index = 1;
for (int i = 0; i < dataList.size(); i++) {
if (last == null) {
last = dataList.get(0);
continue;
}
EquipmentData d = dataList.get(i); if (last.getBeginTime() == null || last.getEquipStatus() == null) {
last.setEndTime(d.getBeginTime()); redisTemplate.delete(key);
break;
}
EquipmentData d = dataList.get(i);
last.setEndTime(d.getBeginTime());
if (d.getEquipStatus() != last.getEquipStatus()) { if (d.getEquipStatus() != last.getEquipStatus()) {
if (index == 1) { if (index == 1) {
equipDataService.update(last); equipDataService.update(last);
} else { } else {
// 保存 // 保存
equipDataService.save(last); equipDataService.save(last);
}
last = d;
index++;
} }
last = d;
index++;
} }
}
if (first != null && first.getBeginTime().equals(last.getBeginTime())) { if (first != null && first.getBeginTime().equals(last.getBeginTime())) {
equipDataService.update(last); equipDataService.update(last);
} else { } else {
equipDataService.save(last); equipDataService.save(last);
}
} }
}
log.info("_______________________________________________________________");
List<EquipInfo> allEquip = basicInfoService.findAllEquip();
log.info("开始清洗设备实时状态数据 allEquip.size: {}", allEquip.size());
for (EquipInfo info : allEquip) {
if ("PLC".equals(info.getEquipType())){
continue;
}
EquipmentData data = (EquipmentData) valueOperations.get(EquipDataUtil.getLastStatusKey(info.getAlias()));
if (null == data || null == data.getEquipStatus()){
realTimeService.saveEquip(info.getWorkshopName(), info.getEquipCode(), info.getAlias(), "关机");
continue;
}
String state = "";
switch (data.getEquipStatus().name()){
case "RUN":
state = "运行";
break;
case "IDLE":
state = "待机";
break;
case "PAUSE":
state = "暂定";
break;
case "ALARM":
state = "报警";
break;
case "SHUTDOWN":
state = "关机";
break;
default:
state = "关机";
break;
}
realTimeService.saveEquip(info.getWorkshopName(), info.getEquipCode(), info.getAlias(), state);
} }
log.info("_______________________________________________________________");
} }
} }
package net.vtstar.zhongtong.avi.equipment.mapper;
import net.vtstar.user.mybatis.BaseMapper;
import net.vtstar.zhongtong.avi.equipment.domain.EquipStatusRealTime;
import org.apache.ibatis.annotations.Mapper;
/**
* @Author: xiadongwei
* @Date: 2020/3/11 9:31
*/
@Mapper
public interface EquipStatusRealTimeMapper extends BaseMapper<EquipStatusRealTime> {
}
...@@ -71,6 +71,15 @@ public class BasicInfoService { ...@@ -71,6 +71,15 @@ public class BasicInfoService {
return basicInfoMapper.findList(searchService.pageFilter2Filter(pageFilter), EquipInfo.class); return basicInfoMapper.findList(searchService.pageFilter2Filter(pageFilter), EquipInfo.class);
} }
/**
* 查询所有设备
*/
public List<EquipInfo> findAllEquip() {
return basicInfoMapper.findList(new WhereFilter(){{
addOrderBy("workshop_name", OrderBy.ASC);
}}, EquipInfo.class);
}
/** /**
* 新增设备 * 新增设备
*/ */
......
package net.vtstar.zhongtong.avi.equipment.service;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import net.vtstar.user.mybatis.provider.Operation;
import net.vtstar.user.mybatis.provider.OrderBy;
import net.vtstar.user.mybatis.provider.WhereFilter;
import net.vtstar.user.search.service.SearchService;
import net.vtstar.utils.CollecUtils;
import net.vtstar.zhongtong.avi.equipment.domain.EquipStatusRealTime;
import net.vtstar.zhongtong.avi.equipment.domain.enums.WorkshopNames;
import net.vtstar.zhongtong.avi.equipment.mapper.EquipStatusRealTimeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
* @Author: xiadongwei
* @Date: 2020/3/11 19:31
*/
@Slf4j
@Service
public class EquipStatusRealTimeService {
@Autowired
private EquipStatusRealTimeMapper mapper;
@Autowired
private SearchService searchService;
/**
* 分页查询设备
*/
public List<EquipStatusRealTime> findPageEquipRealStatus(JSONObject pageFilter) {
PageHelper.startPage(pageFilter.getIntValue("pageNum"), pageFilter.getIntValue("pageSize"));
return mapper.findList(searchService.pageFilter2Filter(pageFilter, new WhereFilter(){{
addOrderBy("equip_workshop", OrderBy.ASC);
}}), EquipStatusRealTime.class);
}
/**
* 新增/更新设备状态
*/
public void saveEquip(String equipWorkshop, String equipCode, String equipName, String equipState) {
List<EquipStatusRealTime> list = mapper.findList(new WhereFilter() {{
addFilter("equip_workshop", Operation.EQUAL, equipWorkshop);
addFilter("equip_code", Operation.EQUAL, equipCode);
addFilter("equip_name", Operation.EQUAL, equipName);
}}, EquipStatusRealTime.class);
if (CollecUtils.isEmpty(list)){
EquipStatusRealTime realTimeState = new EquipStatusRealTime();
realTimeState.setEquipWorkshop(WorkshopNames.valueOf(equipWorkshop));
realTimeState.setEquipCode(equipCode);
realTimeState.setEquipName(equipName);
realTimeState.setEquipState(equipState);
realTimeState.setCreateTime(new Date());
mapper.insert(realTimeState);
}else{
EquipStatusRealTime equipStatusRealTime = list.get(0);
equipStatusRealTime.setEquipState(equipState);
equipStatusRealTime.setCreateTime(new Date());
mapper.update(equipStatusRealTime);
}
}
}
...@@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
import net.vtstar.protocol.modbus.tcp.netty.utils.NettyUtils; import net.vtstar.protocol.modbus.tcp.netty.utils.NettyUtils;
import net.vtstar.protocol.modbus.tcp.netty.utils.PoolKey; import net.vtstar.protocol.modbus.tcp.netty.utils.PoolKey;
import net.vtstar.scada.base.global.service.ModbusService; import net.vtstar.scada.base.global.service.ModbusService;
import net.vtstar.zhongtong.avi.equipment.service.EquipStatusRealTimeService;
import net.vtstar.zhongtong.avi.gateway.parts.domain.WeldingRobotMachine; import net.vtstar.zhongtong.avi.gateway.parts.domain.WeldingRobotMachine;
import net.vtstar.zhongtong.avi.gateway.parts.mapper.WeldingRobotMapper; import net.vtstar.zhongtong.avi.gateway.parts.mapper.WeldingRobotMapper;
import net.vtstar.zhongtong.avi.utils.PingIpUtils; import net.vtstar.zhongtong.avi.utils.PingIpUtils;
...@@ -45,14 +46,39 @@ public class WeldingRobotMachineJob extends QuartzJobBean { ...@@ -45,14 +46,39 @@ public class WeldingRobotMachineJob extends QuartzJobBean {
@Autowired @Autowired
private WeldingRobotMapper mapper; private WeldingRobotMapper mapper;
@Autowired
private EquipStatusRealTimeService realTimeService;
@Override @Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException { protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
List<String> ipAddressList = Arrays.asList(ipAddress1, ipAddress2, ipAddress3, ipAddress4); List<String> ipAddressList = Arrays.asList(ipAddress1, ipAddress2, ipAddress3, ipAddress4);
for (String ipAddress : ipAddressList) { for (String ipAddress : ipAddressList) {
String equipCode = "";
String equipFactory = "";
switch (ipAddress){
case "10.1.25.186":
equipCode = "076102-1324";
equipFactory = "西北过道东侧";
break;
case "10.1.25.187":
equipCode = "076102-1326";
equipFactory = "西北过道东侧";
break;
case "10.1.25.188":
equipCode = "076102-1327";
equipFactory = "西北过道东侧";
break;
case "10.1.25.189":
equipCode = "076102-1325";
equipFactory = "西北过道东侧";
break;
}
if (!PingIpUtils.ping(ipAddress, pingTimes, timeOut)) { if (!PingIpUtils.ping(ipAddress, pingTimes, timeOut)) {
log.error("ping: {}失败, 读取焊接机器人数据操作结束!", ipAddress); log.error("ping: {}失败, 读取焊接机器人数据操作结束!", ipAddress);
realTimeService.saveEquip("制件车间", equipCode, "焊接机器人", "关机");
continue; continue;
} }
realTimeService.saveEquip("制件车间", equipCode, "焊接机器人", "开机");
//1.获得当天日期,2.通过日期去查询当天的开机时间和焊接时间 //1.获得当天日期,2.通过日期去查询当天的开机时间和焊接时间
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
int date = calendar.get(Calendar.DATE); int date = calendar.get(Calendar.DATE);
...@@ -78,31 +104,14 @@ public class WeldingRobotMachineJob extends QuartzJobBean { ...@@ -78,31 +104,14 @@ public class WeldingRobotMachineJob extends QuartzJobBean {
Integer.valueOf(secondWelding.toString()) + "秒"; Integer.valueOf(secondWelding.toString()) + "秒";
WeldingRobotMachine machine = new WeldingRobotMachine(); WeldingRobotMachine machine = new WeldingRobotMachine();
machine.setEquipCode("焊接机器人单体工作站"); machine.setEquipCode("焊接机器人单体工作站");
switch (ipAddress){ machine.setAlias(equipCode);
case "10.1.25.186": machine.setEquipFactory(equipFactory);
machine.setAlias("076102-1324");
machine.setEquipFactory("西北过道东侧");
break;
case "10.1.25.187":
machine.setAlias("076102-1326");
machine.setEquipFactory("西北过道东侧");
break;
case "10.1.25.188":
machine.setAlias("076102-1327");
machine.setEquipFactory("西北过道东侧");
break;
case "10.1.25.189":
machine.setAlias("076102-1325");
machine.setEquipFactory("西北过道东侧");
break;
}
machine.setTurnOnTime(turnOnTime); machine.setTurnOnTime(turnOnTime);
machine.setWeldingTime(weldingTime); machine.setWeldingTime(weldingTime);
machine.setCreateTime(new Date()); machine.setCreateTime(new Date());
mapper.insert(machine); mapper.insert(machine);
} catch (Exception e) { } catch (Exception e) {
log.error("读取焊接机器人数据失败! e : {}", e.getMessage()); log.error("读取焊接机器人数据失败! e : {}", e.getMessage());
return;
} }
} }
......
...@@ -6,6 +6,7 @@ import net.vtstar.user.mybatis.provider.Operation; ...@@ -6,6 +6,7 @@ import net.vtstar.user.mybatis.provider.Operation;
import net.vtstar.user.mybatis.provider.WhereFilter; import net.vtstar.user.mybatis.provider.WhereFilter;
import net.vtstar.utils.CollecUtils; import net.vtstar.utils.CollecUtils;
import net.vtstar.utils.DateUtils; import net.vtstar.utils.DateUtils;
import net.vtstar.zhongtong.avi.equipment.service.EquipStatusRealTimeService;
import net.vtstar.zhongtong.avi.sqlserver.domain.TestSpeedResult; import net.vtstar.zhongtong.avi.sqlserver.domain.TestSpeedResult;
import net.vtstar.zhongtong.avi.sqlserver.mapper.TestSpeedMapper; import net.vtstar.zhongtong.avi.sqlserver.mapper.TestSpeedMapper;
import net.vtstar.zhongtong.avi.utils.PingIpUtils; import net.vtstar.zhongtong.avi.utils.PingIpUtils;
...@@ -45,6 +46,9 @@ public class ErrorFrameJob extends QuartzJobBean { ...@@ -45,6 +46,9 @@ public class ErrorFrameJob extends QuartzJobBean {
private String baseUrl = "D:/scada/errorframe/"; private String baseUrl = "D:/scada/errorframe/";
@Autowired
private EquipStatusRealTimeService realTimeService;
@Override @Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException { protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
log.info("--------开始同步试交车间错误帧数据--------"); log.info("--------开始同步试交车间错误帧数据--------");
...@@ -52,8 +56,10 @@ public class ErrorFrameJob extends QuartzJobBean { ...@@ -52,8 +56,10 @@ public class ErrorFrameJob extends QuartzJobBean {
String dateString = DateUtils.parseDateToString(new Date(), "yyyy-MM-dd"); String dateString = DateUtils.parseDateToString(new Date(), "yyyy-MM-dd");
if (!PingIpUtils.ping(ipAddress, pingTimes, timeOut)) { if (!PingIpUtils.ping(ipAddress, pingTimes, timeOut)) {
log.error("ping: {}失败, 此次同步试交车间错误帧数据操作结束!", ipAddress); log.error("ping: {}失败, 此次同步试交车间错误帧数据操作结束!", ipAddress);
realTimeService.saveEquip("质量管理部", "", "错误帧", "关机");
return; return;
} }
realTimeService.saveEquip("质量管理部", "", "错误帧", "开机");
//todo:账户, 密码需要变 //todo:账户, 密码需要变
String url = "smb://" + ipAddress + "/ztlog/"; String url = "smb://" + ipAddress + "/ztlog/";
SmbFile file = null; SmbFile file = null;
......
...@@ -155,31 +155,4 @@ public class AreaController { ...@@ -155,31 +155,4 @@ public class AreaController {
return Return.success(bus); return Return.success(bus);
} }
/*@GetMapping("/test")
private Return test() {
PoolKey key = new PoolKey("localhost", 502);
ReadCoilsRequest readCoilsRequest = new ReadCoilsRequest(1, 0, 50);
try {
int capacity = body.capacity();
//byte b = body.readByte();
byte aByte4 = body.getByte(0);
byte aByte1 = body.getByte(1);
byte aByte = body.getByte(2);
int length = body.readableBytes();
// byte[] bytes = new byte[lenght];
// ByteBuf bytes1 = body.getBytes(body.readerIndex(), bytes);
int a = 1;
} catch (Exception e) {
}
return Return.success();
}
*/
} }
package net.vtstar.zhongtong.avi.monitoring.controller;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.vtstar.user.search.controller.vo.SearchVo;
import net.vtstar.utils.domain.Return;
import net.vtstar.zhongtong.avi.monitoring.domain.StationPassInfo;
import net.vtstar.zhongtong.avi.monitoring.service.StationPassInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @Author: xiadongwei
* @Date: 2020/3/5 14:10
*/
@Slf4j
@Api(description = "过站信息模块")
@RestController
@RequestMapping("/pass")
public class StationPassInfoController {
@Autowired
private StationPassInfoService passInfoService;
@ApiOperation(value = "报工点补扫--查询所有待补扫的过站记录", notes =
"字段含义:\n{\n" +
" \"VIN\": \"工单号, 字符串类型\",\n" +
" \"stationName\": \"报工点,字符串类型\",\n" +
" \"stationNo\": \"工位编码,字符串类型\",\n" +
" \"passTime\": \"过站时间,时间类型\"\n" +
" \"createBy\": \"操作人,字符串类型\"\n" +
"}")
@PostMapping("/findPassInfoByNoFind")
public Return findPassInfoByNoFind(){
List<StationPassInfo> list = passInfoService.findPassInfoByNoFind();
return Return.success(list);
}
@ApiOperation(value = "查询过站记录", notes = "使用通用搜索组件,searchCode:PASS_INFO\n" +
"字段含义:\n{\n" +
" \"VIN\": \"工单号, 字符串类型\",\n" +
" \"stationName\": \"报工点,字符串类型\",\n" +
" \"stationNo\": \"工位编码,字符串类型\",\n" +
" \"passTime\": \"过站时间,时间类型\"\n" +
" \"createBy\": \"操作人,字符串类型\"\n" +
"}")
@PostMapping("/findPassInfoBySearchCode")
public Return findPassInfoBySearchCode(@RequestBody SearchVo searchVo){
List<StationPassInfo> list = passInfoService.findPassInfoBySearchCode(searchVo.toJSONObject());
return Return.success(new PageInfo<>(list));
}
@ApiOperation(value = "根据报工点获取工位编码")
@GetMapping("/getStationNo/{stationName}")
public Return getStationNoByName(@PathVariable("stationName") String stationName){
String[] stationNo = passInfoService.getStationNoByName(stationName);
return Return.success(stationNo);
}
@ApiOperation(value = "保存缺失的过站记录", notes = "字段含义:\n{\n" +
" \"VIN\": \"工单号, 字符串类型\",\n" +
" \"stationName\": \"报工点,字符串类型\",\n" +
" \"stationNo\": \"工位编码,字符串类型\",\n" +
" \"createTime\": \"过站时间,字符串类型\"\n" +
" \"createBy\": \"操作人,字符串类型\"\n" +
"}")
@PostMapping("/savePassInfo")
public Return savePassInfo(@RequestBody StationPassInfo stationPassInfo){
passInfoService.savePassInfo(stationPassInfo);
return Return.success();
}
@ApiOperation(value = "自动补扫开启")
@GetMapping("/startReplenishScan")
public Return startReplenishScan(@RequestParam Integer beginTimeInt,
@RequestParam Integer endTimeInt){
passInfoService.startReplenishScan(beginTimeInt, endTimeInt);
return Return.success();
}
@ApiOperation(value = "自动补扫关闭")
@GetMapping("/stopReplenishScan")
public Return stopReplenishScan(){
passInfoService.stopReplenishScan();
return Return.success();
}
}
package net.vtstar.zhongtong.avi.monitoring.domain; package net.vtstar.zhongtong.avi.monitoring.domain;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import net.vtstar.user.search.Search;
import net.vtstar.zhongtong.avi.global.web.Show;
import net.vtstar.zhongtong.avi.global.web.domain.enums.FieldType;
import net.vtstar.zhongtong.avi.monitoring.domain.enums.ScanType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Id; import javax.persistence.Id;
...@@ -10,13 +15,21 @@ import java.util.Date; ...@@ -10,13 +15,21 @@ import java.util.Date;
@ApiModel("过站信息") @ApiModel("过站信息")
@Data @Data
@Search(code = "PASS_INFO")
@Table(name = "vehicle_passing_info") @Table(name = "vehicle_passing_info")
public class StationPassInfo { public class StationPassInfo {
@Id @Id
private Long id; private Long id;
@ApiModelProperty(notes = "报工点补扫")
@Search
private ScanType scanType;
@Show(label = "工单号")
@ApiModelProperty(notes = "工单号")
@Column(name = "VIN") @Column(name = "VIN")
@Search
private String VIN; private String VIN;
@Column(name = "rfid") @Column(name = "rfid")
...@@ -25,17 +38,37 @@ public class StationPassInfo { ...@@ -25,17 +38,37 @@ public class StationPassInfo {
@Column(name = "area_no") @Column(name = "area_no")
private String areaNo; private String areaNo;
@Column(name = "station_no")
private String stationNo;
@Column(name = "in_time") @Column(name = "in_time")
private Date inTime; private Date inTime;
@Column(name = "out_time") @Column(name = "out_time")
private Date outTime; private Date outTime;
@Show(label = "报工点")
@ApiModelProperty(notes = "报工点名称")
@Column(name = "station_name")
@Search
private String stationName;
@Show(label = "工位编码")
@Column(name = "station_no")
private String stationNo;
@Show(label = "过站时间", dataType = FieldType.DATETIME)
@ApiModelProperty(notes = "过站时间")
@Column(name = "pass_time")
private Date passTime;
private String busType;
@Show(label = "操作者")
@ApiModelProperty(name = "操作者")
@Column(name = "create_by")
private String createBy;
@ApiModelProperty(notes = "过站时间")
@Column(name = "create_time") @Column(name = "create_time")
@Search
private Date createTime; private Date createTime;
private String busType;
} }
package net.vtstar.zhongtong.avi.monitoring.domain.enums;
import io.swagger.annotations.ApiModel;
@ApiModel("补扫类型")
public enum ScanType {
NULL("只查补扫"),
ALL("查询所有");
private String value;
ScanType(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
...@@ -116,7 +116,8 @@ public class AVIElectrophoresisJob extends GatherJob { ...@@ -116,7 +116,8 @@ public class AVIElectrophoresisJob extends GatherJob {
transaction.execute(); transaction.execute();
response = transaction.getResponse(); response = transaction.getResponse();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.error("PLC连接异常, PLC地址: {}, 端口:{}", poolKey.getHost(), poolKey.getPort());
continue;
} }
if (null == response) { if (null == response) {
log.error("读取失败! response 为空!"); log.error("读取失败! response 为空!");
......
...@@ -7,6 +7,7 @@ import net.vtstar.scada.base.equipmgt.domain.*; ...@@ -7,6 +7,7 @@ import net.vtstar.scada.base.equipmgt.domain.*;
import net.vtstar.scada.base.equipmgt.service.EquipInfoService; import net.vtstar.scada.base.equipmgt.service.EquipInfoService;
import net.vtstar.scada.base.gather.job.GatherJob; import net.vtstar.scada.base.gather.job.GatherJob;
import net.vtstar.scada.base.global.service.ModbusService; import net.vtstar.scada.base.global.service.ModbusService;
import net.vtstar.utils.CollecUtils;
import net.vtstar.zhongtong.avi.equipment.domain.PaintshopStation; import net.vtstar.zhongtong.avi.equipment.domain.PaintshopStation;
import net.vtstar.zhongtong.avi.global.constant.Constant; import net.vtstar.zhongtong.avi.global.constant.Constant;
import net.vtstar.zhongtong.avi.monitoring.domain.Skid; import net.vtstar.zhongtong.avi.monitoring.domain.Skid;
...@@ -18,12 +19,10 @@ import net.vtstar.zhongtong.avi.mqtt.handle.RfidMessageHandler; ...@@ -18,12 +19,10 @@ import net.vtstar.zhongtong.avi.mqtt.handle.RfidMessageHandler;
import net.wimpi.modbus.io.ModbusTCPTransaction; import net.wimpi.modbus.io.ModbusTCPTransaction;
import net.wimpi.modbus.msg.*; import net.wimpi.modbus.msg.*;
import net.wimpi.modbus.net.TCPMasterConnection; import net.wimpi.modbus.net.TCPMasterConnection;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext; import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException; import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache; import org.springframework.cache.Cache;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations; import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -32,14 +31,13 @@ import org.springframework.util.CollectionUtils; ...@@ -32,14 +31,13 @@ import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@Slf4j @Slf4j
@Component @Component
@DisallowConcurrentExecution
public class AVIMonitorJob extends GatherJob { public class AVIMonitorJob extends GatherJob {
private static final String EQUIPMENT_TYPE = "PLC"; private static final String EQUIPMENT_TYPE = "PLC";
public static List<String> rfidList1 = Arrays.asList("rfid51", "rfid52", "rfid53", "rfid54");
@Autowired @Autowired
private EquipInfoService equipInfoService; private EquipInfoService equipInfoService;
...@@ -47,19 +45,16 @@ public class AVIMonitorJob extends GatherJob { ...@@ -47,19 +45,16 @@ public class AVIMonitorJob extends GatherJob {
private ModbusService modbusService; private ModbusService modbusService;
@Autowired @Autowired
private StationPassInfoService passInfoService; private StationPassInfoService passInfoService;
@Resource(name = "stationCache")
private Cache stationCache;
@Resource(name = "vehicleCache") @Resource(name = "vehicleCache")
private Cache vehicleCache; private Cache vehicleCache;
@Resource(name = "laneStationCache") @Resource(name = "laneStationCache")
private Cache laneStationCache; private Cache laneStationCache;
@Resource(name = "redisTemplate") @Resource(name = "redisTemplate")
protected HashOperations<String, String, PaintshopStation> hashOperations;
@Resource(name = "redisTemplate")
private ValueOperations valueOperations; private ValueOperations valueOperations;
@Resource(name = "redisTemplate") @Resource(name = "redisTemplate")
private RedisTemplate redisTemplate; private RedisTemplate redisTemplate;
@Resource(name = "laneRfidStationCache")
private Cache laneRfidStationCache;
@Override @Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException { protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
...@@ -71,8 +66,7 @@ public class AVIMonitorJob extends GatherJob { ...@@ -71,8 +66,7 @@ public class AVIMonitorJob extends GatherJob {
if (CollectionUtils.isEmpty(equipInfoList)) { if (CollectionUtils.isEmpty(equipInfoList)) {
return; return;
} }
//处理工位正反转用 //处理平移车正反转用
List<PaintshopStation> stations = new ArrayList<>();
for (EquipInfo equipInfo : equipInfoList) { for (EquipInfo equipInfo : equipInfoList) {
List<EquipCommunication> commList = equipInfoService.getCommunicationListByEquipType(equipInfo.getEquipCode(), 1); List<EquipCommunication> commList = equipInfoService.getCommunicationListByEquipType(equipInfo.getEquipCode(), 1);
...@@ -81,7 +75,7 @@ public class AVIMonitorJob extends GatherJob { ...@@ -81,7 +75,7 @@ public class AVIMonitorJob extends GatherJob {
} }
for (EquipCommunication communication : commList) { for (EquipCommunication communication : commList) {
EquipDataChannel dataChannel = communication.getDataChannel(); EquipDataChannel dataChannel = communication.getDataChannel();
if (null != dataChannel.getEquipCode() && !dataChannel.getEquipCode().startsWith(EQUIPMENT_TYPE)){ if (null != dataChannel.getEquipCode() && !dataChannel.getEquipCode().startsWith(EQUIPMENT_TYPE)) {
continue; continue;
} }
String ip = dataChannel.getIp(); String ip = dataChannel.getIp();
...@@ -95,7 +89,7 @@ public class AVIMonitorJob extends GatherJob { ...@@ -95,7 +89,7 @@ public class AVIMonitorJob extends GatherJob {
} }
List<EquipDataTemplateItem> templateItemList = template.getTemplateItemList(); List<EquipDataTemplateItem> templateItemList = template.getTemplateItemList();
if (CollectionUtils.isEmpty(templateItemList)) { if (CollectionUtils.isEmpty(templateItemList)) {
log.info("无法获取数据模板的条目,设备编号:{},模板名称:{}", dataChannel.getEquipCode(), template.getName()); // log.info("无法获取数据模板的条目,设备编号:{},模板名称:{}", dataChannel.getEquipCode(), template.getName());
continue; continue;
} }
...@@ -111,21 +105,6 @@ public class AVIMonitorJob extends GatherJob { ...@@ -111,21 +105,6 @@ public class AVIMonitorJob extends GatherJob {
Integer quantity = end + size - start; Integer quantity = end + size - start;
Integer functionCode = entry.getKey(); Integer functionCode = entry.getKey();
/*ModbusResponse response = null;
try {
if (1 == functionCode) {
response = modbusService.readCoilRegister(slaveId, poolKey, start, quantity);
} else if (2 == functionCode) {
response = modbusService.readInputDiscretes(slaveId, poolKey, start, quantity);
} else if (3 == functionCode) {
response = modbusService.readMultipleRegister(slaveId, poolKey, start, quantity);
} else if (4 == functionCode) {
response = modbusService.readInputRegister(slaveId, poolKey, start, quantity);
}
} catch (Exception e) {
log.error("读取失败。ip{}, 端口{}, slave{}, start{}, size{}", poolKey.getHost(), poolKey.getPort(), slaveId, start, quantity);
return;
}*/
ModbusRequest modbusRequest = null; ModbusRequest modbusRequest = null;
net.wimpi.modbus.msg.ModbusResponse response = null; net.wimpi.modbus.msg.ModbusResponse response = null;
if (1 == functionCode) { if (1 == functionCode) {
...@@ -149,25 +128,13 @@ public class AVIMonitorJob extends GatherJob { ...@@ -149,25 +128,13 @@ public class AVIMonitorJob extends GatherJob {
transaction.execute(); transaction.execute();
response = transaction.getResponse(); response = transaction.getResponse();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.error("PLC连接异常, PLC地址: {}, 端口:{}", poolKey.getHost(), poolKey.getPort());
continue;
} }
if (null == response) { if (null == response) {
log.error("读取失败! response 为空!"); log.error("读取失败! response 为空!");
return; return;
} }
/*if (!response.isSuccess()){
log.error("读取失败! response isSuccess 为 false!");
return;
}
ByteBuf body = response.getBody();
if (null == body) {
log.error("response.body is null!!");
//若出现一次读取错误, 则将本次读取结束, 必须保证读取到所有的工位旋转情况
return;
}
int length = body.readableBytes();
byte[] bytes = new byte[length];
body.getBytes(body.readerIndex(), bytes);*/
String[] hexStrs = response.getHexMessage().split(" "); String[] hexStrs = response.getHexMessage().split(" ");
if (hexStrs.length == 9) { if (hexStrs.length == 9) {
log.error("读取失败! length 为9!"); log.error("读取失败! length 为9!");
...@@ -176,71 +143,51 @@ public class AVIMonitorJob extends GatherJob { ...@@ -176,71 +143,51 @@ public class AVIMonitorJob extends GatherJob {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i = 9; i < hexStrs.length; i++) { for (int i = 9; i < hexStrs.length; i++) {
Integer newValue = Integer.valueOf(hexStrs[i], 16); Integer newValue = Integer.valueOf(hexStrs[i], 16);
for (int j = 7;j >= 0; j--){ int j = 0;
sb.append(newValue >>> j & 1); while (j < 8){
sb.append(newValue % 2);
newValue = newValue / 2;
j ++;
} }
} }
byte[] bytes = sb.toString().getBytes(); byte[] bytes = sb.toString().getBytes();
log.error("读取读取数据。ip{}, 端口{}, slave{}, start{}, size{}", poolKey.getHost(), poolKey.getPort(), slaveId, start, quantity); /*log.error("读取读取平移车正反转数据。ip{}, 端口{}, slave{}, start{}, size{}", poolKey.getHost(), poolKey.getPort(), slaveId, start, quantity);
log.error("data:{}", Arrays.toString(hexStrs)); log.error("data:{}", Arrays.toString(hexStrs));*/
for (EquipDataTemplateItem templateItem : value) { for (EquipDataTemplateItem templateItem : value) {
Integer address = templateItem.getAddress(); Integer address = templateItem.getAddress();
int quality = address - start; int quality = address - start;
int register = quality / 8; byte state = bytes[quality];
int offset = quality % 8;
byte state = bytes[register + offset];
String fieldName = templateItem.getFieldName(); String fieldName = templateItem.getFieldName();
if (fieldName.startsWith("station:ve")) { if (fieldName.startsWith("vehicle:turn")) {
String stationCode = fieldName.split(":")[2];
PaintshopStation station = (PaintshopStation) valueOperations.get(Constant.STATION_PREFIX + stationCode);
if (null == station) {
station = stationCache.get(stationCode, PaintshopStation.class);
}
if (state == 48) {
state = 0;
} else {
state = 1;
}
station.setOldState(station.getState());
station.setArrive(state == 1 ? true : false);
stations.add(station);
valueOperations.set(Constant.STATION_PREFIX + stationCode, station);
} else if (fieldName.startsWith("station:turn")) {
String[] split = fieldName.split(":"); String[] split = fieldName.split(":");
String stationCode = fieldName.split(":")[2]; String vehicleCode = fieldName.split(":")[2];
PaintshopStation station = (PaintshopStation) valueOperations.get(Constant.STATION_PREFIX + stationCode); Vehicle vehicle = (Vehicle) valueOperations.get(Constant.VEHICLE_PREFIX + vehicleCode);
if (null == station) { if (null == vehicle) {
station = stationCache.get(stationCode, PaintshopStation.class); vehicle = vehicleCache.get(vehicleCode, Vehicle.class);
} }
if (state == 48) { if (state == 48) {
state = 0; state = 0;
} else { } else {
state = 1; state = 1;
} }
station.setOldState(station.getState());
String turn = split[1]; String turn = split[1];
if (turn.endsWith("F")) { if (turn.endsWith("F")) {
station.setTurnF(state == 1 ? true : false); vehicle.setTurnF(state == 1);
} }
if (turn.endsWith("R")) { if (turn.endsWith("R")) {
station.setTurnR(state == 1 ? true : false); vehicle.setTurnR(state == 1);
} }
valueOperations.set(Constant.STATION_PREFIX + stationCode, station); valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle);
} }
} }
} }
} }
} }
if (CollectionUtils.isEmpty(stations) || stations.size() != 144) {
log.error("没有维护工位信息!");
return;
}
List<Vehicle> vehicles = new ArrayList<>(); List<Vehicle> vehicles = new ArrayList<>();
Set<String> veKeys = redisTemplate.keys(Constant.VEHICLE_PREFIX + "*"); Set<String> veKeys = redisTemplate.keys(Constant.VEHICLE_PREFIX + "*");
for (String veKey : veKeys) { for (String veKey : veKeys) {
...@@ -248,88 +195,76 @@ public class AVIMonitorJob extends GatherJob { ...@@ -248,88 +195,76 @@ public class AVIMonitorJob extends GatherJob {
if (null == ve) { if (null == ve) {
ve = vehicleCache.get(veKey.split(":")[1], Vehicle.class); ve = vehicleCache.get(veKey.split(":")[1], Vehicle.class);
} }
if (null == ve){ if (null == ve) {
log.error("平移车:{} 未在到缓存中!", veKey); log.error("平移车:{} 未在到缓存中!", veKey);
continue; continue;
} }
if (null != ve.getState() && ve.getState() == false){ //判断平移车是否有下车信号
vehicles.add(ve); if (null == ve.getState() || ve.getState() == true) {
}
}
Map<String, List<Vehicle>> veMap = vehicles.stream().collect(Collectors.groupingBy(Vehicle::getLane));
Map<String, List<PaintshopStation>> listMap = stations.stream().filter(a -> false != a.getTurnR() || false != a.getTurnF()).
collect(Collectors.groupingBy(PaintshopStation::getVehicleLaneCode));
for (Map.Entry<String, List<Vehicle>> ve : veMap.entrySet()) {
String key = ve.getKey();
if (Integer.valueOf(key) > 4){
continue; continue;
} }
List<PaintshopStation> landStations = listMap.get(key); //判断当前平移车是否在转动
if (null == landStations){ if (null != ve.getTurnF() && ve.getTurnF()) {
landStations = new ArrayList<>(); log.error("----------平移车:{}的正转信号为true!--------------", ve.getMqttPrefix());
} //判断下车时间和当前旋转时间是否大于10s
List<Vehicle> value = ve.getValue(); if (((System.currentTimeMillis() - ve.getDownTime().getTime()) / 1000) > 10 && ve.getDownTimeMin() > 5) {
List<PaintshopStation> turnStation = new ArrayList<>(); vehicles.add(ve);
for (PaintshopStation landStation : landStations) { } else {
//获得 西侧加正转=下车 西+反=上 东+反=下 东+正=上 ve.setDownTimeMin(ve.getDownTimeMin() + 2);
if (landStation.getTurnF() && Direction.WEST.equals(landStation.getDirection())) { valueOperations.set(veKey, ve);
turnStation.add(landStation);
}
if (landStation.getTurnR() && Direction.EAST.equals(landStation.getDirection())) {
turnStation.add(landStation);
} }
} }
int stationSize = 0; if (null != ve.getTurnR() && ve.getTurnR()) {
log.error("----------平移车:{}的反转信号为true!--------------", ve.getMqttPrefix());
Map<String, PaintshopStation> entries = hashOperations.entries(Constant.STATION_OUT_PREFIX + key); //判断下车时间和当前旋转时间是否大于10s
for (PaintshopStation station : turnStation) { if (((System.currentTimeMillis() - ve.getDownTime().getTime()) / 1000) > 10 && ve.getDownTimeMin() > 5) {
//若当前工位已进车的方式旋转, 且之前一分钟内没有进过车, 则此工位可再次进车 vehicles.add(ve);
if (station.getInTime() == null || ((System.currentTimeMillis() - station.getInTime().getTime()) > 60 * 1000)){ } else {
entries.put(station.getCode(), station); ve.setDownTimeMin(ve.getDownTimeMin() + 2);
valueOperations.set(veKey, ve);
} }
} }
}
if (CollecUtils.isEmpty(vehicles)){
return;
}
if (!CollectionUtils.isEmpty(entries)) { for (Vehicle vehicle : vehicles) {
stationSize = entries.size(); log.error("--------------开始下车逻辑------------------");
if (null == vehicle.getLaneRfid()){
log.error("----下车平移车没有当前车道信息!LaneRfid = null!");
continue;
} }
//TODO: 临时校验错误, 每条平移车道存在其旋转工位数, 若超过此值, 则按照当前下车数进行依次下车, 多余旋转工位舍弃; List<PaintshopStation> stations = laneRfidStationCache.get(vehicle.getLaneRfid(), ArrayList.class);
int maxStationSize = 0; if (CollecUtils.isEmpty(stations)) {
switch (key){ log.error("----下车逻辑1-----");
case "1": return;
maxStationSize = 1;
break;
case "2":
maxStationSize = 4;
break;
case "3":
maxStationSize = 3;
break;
case "4":
maxStationSize = 7;
break;
} }
//若平移车下车信号与与工位下车信号不等,存入工位信息返回 for (PaintshopStation station : stations) {
if (value.size() != stationSize && stationSize <= maxStationSize) { //若平移车正转, 且工位在平移车西侧; 或者平移车反转, 且工位在平移车东侧
hashOperations.putAll(Constant.STATION_OUT_PREFIX + key, entries); if ((vehicle.getTurnF() && Direction.WEST.equals(station.getDirection())) || (vehicle.getTurnR() && Direction.EAST.equals(station.getDirection()))) {
log.error("当前车道: {}旋转的工位数量为: {}", key, stationSize); log.error("----下车逻辑2");
} else {
log.error("--------------开始下车逻辑------------------");
value.sort(Comparator.comparing(v -> v.getSequence()));
List<PaintshopStation> collect = entries.values().stream().sorted(Comparator.comparing(e -> e.getVehicleLaneCode())).collect(Collectors.toList());
for (int i = 0; i < value.size(); i++) {
//找到滑撬上绑定平移车,找到工位对应车道上所有工位信息
Vehicle vehicle = value.get(i);
PaintshopStation station = collect.get(i);
Skid skid = vehicle.getSkid(); Skid skid = vehicle.getSkid();
//TODO: 若平移车上车时找不到对应的滑撬, 则skid为空, 下车时不做处理 //TODO: 若平移车上车时找不到对应的滑撬, 则skid为空, 下车时不做处理
if (null == skid){ if (null == skid) {
log.error("平移车上车时找不到对应的滑撬: {}", vehicle.getMqttPrefix()); log.error("平移车上车时找不到对应的滑撬: {}", vehicle.getMqttPrefix());
continue; continue;
} }
//todo: 若平移车位于HXG2-1位置, 且平移车反转(向东), 则认为是向底盘下车操作, 判断工序补扫情况
if ("439".equals(vehicle.getLaneRfid()) && vehicle.getTurnR()){
passInfoService.checkPassInfo(skid.getWorkOrderNo(), skid.getRfid());
}
log.error("平移车: {} 下车到工位:{}", vehicle.getMqttPrefix(), station.getCode()); log.error("平移车: {} 下车到工位:{}", vehicle.getMqttPrefix(), station.getCode());
vehicle.setSkid(null);
vehicle.setCurrentRfid(null);
vehicle.setState(null);
vehicle.setDownTime(null);
vehicle.setDownTimeMin(0);
vehicle.setMqttCode(null);
//更新平移车
valueOperations.set(Constant.VEHICLE_PREFIX + vehicle.getMqttPrefix(), vehicle);
log.error("-------------重置平移车------------------");
Long laneId = station.getLaneId(); Long laneId = station.getLaneId();
List<PaintshopStation> lands = new ArrayList<>(); List<PaintshopStation> lands = new ArrayList<>();
...@@ -345,44 +280,38 @@ public class AVIMonitorJob extends GatherJob { ...@@ -345,44 +280,38 @@ public class AVIMonitorJob extends GatherJob {
PaintshopStation end = lands.get(lands.size() - 1); PaintshopStation end = lands.get(lands.size() - 1);
//下车时, 记录进去车道的开始时间, 并将记录ID绑定在工位上 //下车时, 记录进去车道的开始时间, 并将记录ID绑定在工位上
Long passInfoId = 0L; Long passInfoId = 0L;
/*if (null != skid){ passInfoId = passInfoService.createPassInfo(skid.getWorkOrderNo(), skid.getRfid(), station.getAreaName(), station.getCode());
passInfoId = passInfoService.createPassInfo(skid.getWorkOrderNo(), skid.getRfid(), station.getAreaName(), station.getLandNo());
}*/
if (start.getCode().equals(station.getCode())) { if (start.getCode().equals(station.getCode())) {
//车道西头下车, 所有工位向东平移一位
for (int j = lands.size() - 1; j > 0; j--) { for (int j = lands.size() - 1; j > 0; j--) {
PaintshopStation tem = lands.get(j); PaintshopStation tem = lands.get(j);
PaintshopStation tem2 = lands.get(j - 1); PaintshopStation tem2 = lands.get(j - 1);
if (tem.getSkid() != null) { tem.setSkid(tem2.getSkid());
tem2.setSkid(tem.getSkid()); tem.setState(tem2.getState());
tem2.setState(StationState.USE); tem.setBusType(tem2.getBusType());
} else { tem.setWorkOrderNo(tem2.getWorkOrderNo());
tem2.setSkid(null); tem.setBusNo(tem2.getBusNo());
tem2.setState(StationState.FREE);
}
} }
start.setSkid(skid); start.setSkid(skid);
start.setState(StationState.USE); start.setState(StationState.USE);
start.setInTime(new Date()); start.setInTime(new Date());
if (passInfoId != 0L){ if (passInfoId != 0L) {
start.setPassInfoId(passInfoId); start.setPassInfoId(passInfoId);
} }
} else if (end.getCode().equals(station.getCode())) { } else if (end.getCode().equals(station.getCode())) {
for (int j = 0; j < lands.size() - 1; j++) { for (int j = 0; j < lands.size() - 1; j++) {
PaintshopStation tem = lands.get(j); PaintshopStation tem = lands.get(j);
PaintshopStation tem2 = lands.get(j + 1); PaintshopStation tem2 = lands.get(j + 1);
if (null != tem2.getSkid()) { tem.setSkid(tem2.getSkid());
tem.setState(StationState.USE); tem.setState(tem2.getState());
tem.setSkid(tem2.getSkid()); tem.setBusType(tem2.getBusType());
} else { tem.setWorkOrderNo(tem2.getWorkOrderNo());
tem2.setSkid(null); tem.setBusNo(tem2.getBusNo());
tem2.setState(StationState.FREE);
}
} }
end.setState(StationState.USE); end.setState(StationState.USE);
end.setSkid(skid); end.setSkid(skid);
end.setInTime(new Date()); end.setInTime(new Date());
if (passInfoId != 0L){ if (passInfoId != 0L) {
end.setPassInfoId(passInfoId); end.setPassInfoId(passInfoId);
} }
} }
...@@ -402,18 +331,9 @@ public class AVIMonitorJob extends GatherJob { ...@@ -402,18 +331,9 @@ public class AVIMonitorJob extends GatherJob {
for (PaintshopStation land : lands) { for (PaintshopStation land : lands) {
valueOperations.set(Constant.STATION_PREFIX + land.getCode(), land); valueOperations.set(Constant.STATION_PREFIX + land.getCode(), land);
} }
vehicle.setSkid(null);
vehicle.setCurrentRfid(null);
vehicle.setState(null);
//更新平移车
valueOperations.set(Constant.VEHICLE_PREFIX + vehicle.getCode().replace("ZT/translation/", "").replace("/data/all", "").trim(), vehicle);
}
for (PaintshopStation station : collect){
//清除工位缓存
hashOperations.delete(Constant.STATION_OUT_PREFIX + key, station.getCode());
} }
log.error("-------------下车逻辑结束------------------");
} }
log.error("-------------下车逻辑结束------------------");
} }
} }
} }
\ No newline at end of file
package net.vtstar.zhongtong.avi.monitoring.job;
import lombok.extern.slf4j.Slf4j;
import net.vtstar.protocol.modbus.tcp.netty.utils.NettyUtils;
import net.vtstar.protocol.modbus.tcp.netty.utils.PoolKey;
import net.vtstar.scada.base.equipmgt.domain.*;
import net.vtstar.scada.base.equipmgt.service.EquipInfoService;
import net.vtstar.scada.base.gather.job.GatherJob;
import net.vtstar.scada.base.global.service.ModbusService;
import net.vtstar.utils.CollecUtils;
import net.vtstar.zhongtong.avi.equipment.domain.PaintshopStation;
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.enums.Direction;
import net.vtstar.zhongtong.avi.monitoring.domain.enums.StationState;
import net.vtstar.zhongtong.avi.monitoring.service.StationPassInfoService;
import net.vtstar.zhongtong.avi.mqtt.handle.RfidMessageHandler;
import net.wimpi.modbus.io.ModbusTCPTransaction;
import net.wimpi.modbus.msg.*;
import net.wimpi.modbus.net.TCPMasterConnection;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.net.InetAddress;
import java.util.*;
@Slf4j
@Component
public class AVIMonitorJob1 extends GatherJob {
private static final String EQUIPMENT_TYPE = "PLC";
public static List<String> rfidList1 = Arrays.asList("rfid51", "rfid52", "rfid53", "rfid54");
@Autowired
private EquipInfoService equipInfoService;
@Autowired
private ModbusService modbusService;
@Autowired
private StationPassInfoService passInfoService;
@Resource(name = "vehicleCache")
private Cache vehicleCache;
@Resource(name = "laneStationCache")
private Cache laneStationCache;
@Resource(name = "redisTemplate")
private ValueOperations valueOperations;
@Resource(name = "redisTemplate")
private RedisTemplate redisTemplate;
@Resource(name = "laneRfidStationCache")
private Cache laneRfidStationCache;
@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
log.info("-------------------------------");
log.info("AVIMonitorJob start");
List<EquipInfo> equipInfoList = equipInfoService.getEquipInfoList(EQUIPMENT_TYPE);
if (CollectionUtils.isEmpty(equipInfoList)) {
return;
}
//处理平移车正反转用
for (EquipInfo equipInfo : equipInfoList) {
List<EquipCommunication> commList = equipInfoService.getCommunicationListByEquipType(equipInfo.getEquipCode(), 1);
if (CollectionUtils.isEmpty(commList)) {
return;
}
for (EquipCommunication communication : commList) {
EquipDataChannel dataChannel = communication.getDataChannel();
if (null != dataChannel.getEquipCode() && !dataChannel.getEquipCode().startsWith(EQUIPMENT_TYPE)) {
continue;
}
String ip = dataChannel.getIp();
Integer port = dataChannel.getPort();
PoolKey poolKey = NettyUtils.wrapPoolKey(ip, port);
Integer slaveId = dataChannel.getNo();
EquipDataTemplate template = communication.getDataTemplate();
if (template == null) {
log.info("无法获取设备的数据模板,设备编号:{}", dataChannel.getEquipCode());
continue;
}
List<EquipDataTemplateItem> templateItemList = template.getTemplateItemList();
if (CollectionUtils.isEmpty(templateItemList)) {
// log.info("无法获取数据模板的条目,设备编号:{},模板名称:{}", dataChannel.getEquipCode(), template.getName());
continue;
}
Map<Integer, List<EquipDataTemplateItem>> listMap = modbusService.groupByFuntionCode(templateItemList);
for (Map.Entry<Integer, List<EquipDataTemplateItem>> entry : listMap.entrySet()) {
List<EquipDataTemplateItem> value = entry.getValue();
if (CollectionUtils.isEmpty(value)) {
continue;
}
Integer start = value.get(0).getAddress();
Integer end = value.get(value.size() - 1).getAddress();
Integer size = value.get(value.size() - 1).getLength();
Integer quantity = end + size - start;
Integer functionCode = entry.getKey();
ModbusRequest modbusRequest = null;
net.wimpi.modbus.msg.ModbusResponse response = null;
if (1 == functionCode) {
modbusRequest = new ReadCoilsRequest(start, quantity);
} else if (2 == functionCode) {
modbusRequest = new ReadInputDiscretesRequest(start, quantity);
} else if (3 == functionCode) {
modbusRequest = new ReadMultipleRegistersRequest(start, quantity);
} else if (4 == functionCode) {
modbusRequest = new ReadInputRegistersRequest(start, quantity);
}
modbusRequest.setUnitID(slaveId);
try {
TCPMasterConnection connection = new TCPMasterConnection(InetAddress.getByName(poolKey.getHost()));
connection.setPort(port);
connection.setTimeout(3000);
connection.connect();
ModbusTCPTransaction transaction = new ModbusTCPTransaction(connection);
transaction.setReconnecting(false);
transaction.setRequest(modbusRequest);
transaction.execute();
response = transaction.getResponse();
} catch (Exception e) {
e.printStackTrace();
return;
}
if (null == response) {
log.error("读取失败! response 为空!");
return;
}
String[] hexStrs = response.getHexMessage().split(" ");
if (hexStrs.length == 9) {
log.error("读取失败! length 为9!");
return;
}
StringBuilder sb = new StringBuilder();
for (int i = 9; i < hexStrs.length; i++) {
Integer newValue = Integer.valueOf(hexStrs[i], 16);
int j = 0;
while (j < 8){
sb.append(newValue % 2);
newValue = newValue / 2;
j ++;
}
}
byte[] bytes = sb.toString().getBytes();
/*log.error("读取读取平移车正反转数据。ip{}, 端口{}, slave{}, start{}, size{}", poolKey.getHost(), poolKey.getPort(), slaveId, start, quantity);
log.error("data:{}", Arrays.toString(hexStrs));*/
for (EquipDataTemplateItem templateItem : value) {
Integer address = templateItem.getAddress();
int quality = address - start;
byte state = bytes[quality];
String fieldName = templateItem.getFieldName();
if (fieldName.startsWith("vehicle:turn")) {
String[] split = fieldName.split(":");
String vehicleCode = fieldName.split(":")[2];
Vehicle vehicle = (Vehicle) valueOperations.get(Constant.VEHICLE_PREFIX + vehicleCode);
if (null == vehicle) {
vehicle = vehicleCache.get(vehicleCode, Vehicle.class);
}
if (state == 48) {
state = 0;
} else {
state = 1;
}
String turn = split[1];
if (turn.endsWith("F")) {
vehicle.setTurnF(state == 1);
}
if (turn.endsWith("R")) {
vehicle.setTurnR(state == 1);
}
valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle);
}
}
}
}
}
List<Vehicle> vehicles = new ArrayList<>();
Set<String> veKeys = redisTemplate.keys(Constant.VEHICLE_PREFIX + "*");
for (String veKey : veKeys) {
Vehicle ve = (Vehicle) valueOperations.get(veKey);
if (null == ve) {
ve = vehicleCache.get(veKey.split(":")[1], Vehicle.class);
}
if (null == ve) {
log.error("平移车:{} 未在到缓存中!", veKey);
continue;
}
//判断平移车是否有下车信号
if (null == ve.getState() || ve.getState() == true) {
continue;
}
//判断当前平移车是否在转动
if (null != ve.getTurnF() && ve.getTurnF()) {
log.error("----------平移车:{}的正转信号为true!--------------", ve.getMqttPrefix());
//判断下车时间和当前旋转时间是否大于10s
if (((System.currentTimeMillis() - ve.getDownTime().getTime()) / 1000) > 10 && ve.getDownTimeMin() > 5) {
vehicles.add(ve);
} else {
ve.setDownTimeMin(ve.getDownTimeMin() + 2);
valueOperations.set(veKey, ve);
}
}
if (null != ve.getTurnR() && ve.getTurnR()) {
log.error("----------平移车:{}的反转信号为true!--------------", ve.getMqttPrefix());
//判断下车时间和当前旋转时间是否大于10s
if (((System.currentTimeMillis() - ve.getDownTime().getTime()) / 1000) > 10 && ve.getDownTimeMin() > 5) {
vehicles.add(ve);
} else {
ve.setDownTimeMin(ve.getDownTimeMin() + 2);
valueOperations.set(veKey, ve);
}
}
}
if (CollecUtils.isEmpty(vehicles)){
return;
}
for (Vehicle vehicle : vehicles) {
log.error("--------------开始下车逻辑------------------");
if (null == vehicle.getLaneRfid()){
log.error("----下车平移车没有当前车道信息!LaneRfid = null!");
continue;
}
List<PaintshopStation> stations = laneRfidStationCache.get(vehicle.getLaneRfid(), ArrayList.class);
if (CollecUtils.isEmpty(stations)) {
log.error("----下车逻辑1-----");
return;
}
for (PaintshopStation station : stations) {
//若平移车正转, 且工位在平移车西侧; 或者平移车反转, 且工位在平移车东侧
if ((vehicle.getTurnF() && Direction.WEST.equals(station.getDirection())) || (vehicle.getTurnR() && Direction.EAST.equals(station.getDirection()))) {
log.error("----下车逻辑2");
Skid skid = vehicle.getSkid();
//TODO: 若平移车上车时找不到对应的滑撬, 则skid为空, 下车时不做处理
if (null == skid) {
log.error("平移车上车时找不到对应的滑撬: {}", vehicle.getMqttPrefix());
continue;
}
log.error("平移车: {} 下车到工位:{}", vehicle.getMqttPrefix(), station.getCode());
vehicle.setSkid(null);
vehicle.setCurrentRfid(null);
vehicle.setState(null);
vehicle.setDownTime(null);
vehicle.setDownTimeMin(0);
vehicle.setMqttCode(null);
//更新平移车
valueOperations.set(Constant.VEHICLE_PREFIX + vehicle.getMqttPrefix(), vehicle);
log.error("-------------重置平移车------------------");
Long laneId = station.getLaneId();
List<PaintshopStation> lands = new ArrayList<>();
List<PaintshopStation> temStation = laneStationCache.get(laneId, ArrayList.class);
for (PaintshopStation land : temStation) {
PaintshopStation s = (PaintshopStation) valueOperations.get(Constant.STATION_PREFIX + land.getCode());
lands.add(s);
}
lands.sort(Comparator.comparing(v -> v.getSequence()));
PaintshopStation start = lands.get(0);
PaintshopStation end = lands.get(lands.size() - 1);
//下车时, 记录进去车道的开始时间, 并将记录ID绑定在工位上
Long passInfoId = 0L;
passInfoId = passInfoService.createPassInfo(skid.getWorkOrderNo(), skid.getRfid(), station.getAreaName(), station.getCode());
if (start.getCode().equals(station.getCode())) {
//车道西头下车, 所有工位向东平移一位
for (int j = lands.size() - 1; j > 0; j--) {
PaintshopStation tem = lands.get(j);
PaintshopStation tem2 = lands.get(j - 1);
tem.setSkid(tem2.getSkid());
tem.setState(tem2.getState());
tem.setBusType(tem2.getBusType());
tem.setWorkOrderNo(tem2.getWorkOrderNo());
tem.setBusNo(tem2.getBusNo());
}
start.setSkid(skid);
start.setState(StationState.USE);
start.setInTime(new Date());
if (passInfoId != 0L) {
start.setPassInfoId(passInfoId);
}
} else if (end.getCode().equals(station.getCode())) {
for (int j = 0; j < lands.size() - 1; j++) {
PaintshopStation tem = lands.get(j);
PaintshopStation tem2 = lands.get(j + 1);
tem.setSkid(tem2.getSkid());
tem.setState(tem2.getState());
tem.setBusType(tem2.getBusType());
tem.setWorkOrderNo(tem2.getWorkOrderNo());
tem.setBusNo(tem2.getBusNo());
}
end.setState(StationState.USE);
end.setSkid(skid);
end.setInTime(new Date());
if (passInfoId != 0L) {
end.setPassInfoId(passInfoId);
}
}
String today = RfidMessageHandler.dateFormat.format(new Date());
//记录过站信息
String areaCode = station.getAreaId().toString();
String areaKey = Constant.BUS_SIZE_IN + areaCode + ":" + today;
Integer size = (Integer) valueOperations.get(areaKey);
if (null == size) {
size = 1;
} else {
size++;
}
valueOperations.set(areaKey, size);
//更新工位
for (PaintshopStation land : lands) {
valueOperations.set(Constant.STATION_PREFIX + land.getCode(), land);
}
}
}
log.error("-------------下车逻辑结束------------------");
}
}
}
\ No newline at end of file
...@@ -15,14 +15,12 @@ import net.vtstar.zhongtong.avi.monitoring.domain.vo.CarStatisticsVO; ...@@ -15,14 +15,12 @@ import net.vtstar.zhongtong.avi.monitoring.domain.vo.CarStatisticsVO;
import org.quartz.JobExecutionContext; import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException; import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration; import org.springframework.cache.Cache;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations; import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.cache.Cache;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
...@@ -50,10 +48,8 @@ public class RedisToCacheJob extends GatherJob { ...@@ -50,10 +48,8 @@ public class RedisToCacheJob extends GatherJob {
log.info("______________"); log.info("______________");
log.info("RedisToCacheJob start"); log.info("RedisToCacheJob start");
//处理报警 //处理报警
Set<String> warningKeys = redisTemplate.keys(Constant.WARNING_PREFIX + "*"); Set<String> warningKeys = redisTemplate.keys(Constant.WARNING_PREFIX + "*");
Map<String, List<String>> warningKeyMap = warningKeys.stream().collect(Collectors.groupingBy(a -> a.split(":")[1])); Map<String, List<String>> warningKeyMap = warningKeys.stream().collect(Collectors.groupingBy(a -> a.split(":")[1]));
List<Warning> list = new ArrayList<>(); List<Warning> list = new ArrayList<>();
for (Map.Entry<String, List<String>> warningKey : warningKeyMap.entrySet()) { for (Map.Entry<String, List<String>> warningKey : warningKeyMap.entrySet()) {
...@@ -130,12 +126,7 @@ public class RedisToCacheJob extends GatherJob { ...@@ -130,12 +126,7 @@ public class RedisToCacheJob extends GatherJob {
Integer todaySize = (Integer) valueOperations.get(Constant.BUS_SIZE_IN + code + ":" + today); Integer todaySize = (Integer) valueOperations.get(Constant.BUS_SIZE_IN + code + ":" + today);
vo.setDateType(dateType); vo.setDateType(dateType);
if (null == todaySize) { if (null == todaySize) {
// if (code.equals("0")) {
// vo.setSize(BigDecimal.valueOf(40));
// } else {
vo.setSize(BigDecimal.ZERO); vo.setSize(BigDecimal.ZERO);
// vo.setSize(BigDecimal.valueOf(10).add(new BigDecimal(r.nextInt(20))));
// }
} else { } else {
vo.setSize(BigDecimal.valueOf(todaySize)); vo.setSize(BigDecimal.valueOf(todaySize));
} }
...@@ -146,12 +137,7 @@ public class RedisToCacheJob extends GatherJob { ...@@ -146,12 +137,7 @@ public class RedisToCacheJob extends GatherJob {
Integer todayOut = (Integer) valueOperations.get(Constant.BUS_SIZE_OUT + code + ":" + today); Integer todayOut = (Integer) valueOperations.get(Constant.BUS_SIZE_OUT + code + ":" + today);
out.setDateType(dateType); out.setDateType(dateType);
if (null == todayOut) { if (null == todayOut) {
// if (code.equals("0")) {
// out.setSize(BigDecimal.valueOf(40));
// } else {
out.setSize(BigDecimal.ZERO); out.setSize(BigDecimal.ZERO);
// out.setSize(BigDecimal.valueOf(10).add(new BigDecimal(r.nextInt(20))));
// }
} else { } else {
out.setSize(BigDecimal.valueOf(todayOut)); out.setSize(BigDecimal.valueOf(todayOut));
} }
......
...@@ -10,11 +10,8 @@ import net.vtstar.zhongtong.avi.equipment.domain.PaintshopStation; ...@@ -10,11 +10,8 @@ import net.vtstar.zhongtong.avi.equipment.domain.PaintshopStation;
import net.vtstar.zhongtong.avi.equipment.mapper.PaintshopAreaMapper; import net.vtstar.zhongtong.avi.equipment.mapper.PaintshopAreaMapper;
import net.vtstar.zhongtong.avi.equipment.mapper.PaintshopStationMapper; import net.vtstar.zhongtong.avi.equipment.mapper.PaintshopStationMapper;
import net.vtstar.zhongtong.avi.global.constant.Constant; 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.Vehicle;
import net.vtstar.zhongtong.avi.monitoring.domain.Warning; import net.vtstar.zhongtong.avi.monitoring.domain.Warning;
import net.vtstar.zhongtong.avi.monitoring.domain.WorkRoom;
import net.vtstar.zhongtong.avi.monitoring.domain.enums.ProductionType;
import net.vtstar.zhongtong.avi.monitoring.domain.enums.StationState; import net.vtstar.zhongtong.avi.monitoring.domain.enums.StationState;
import net.vtstar.zhongtong.avi.monitoring.mapper.SkidMapper; import net.vtstar.zhongtong.avi.monitoring.mapper.SkidMapper;
import net.vtstar.zhongtong.avi.monitoring.mapper.VehicleMapper; import net.vtstar.zhongtong.avi.monitoring.mapper.VehicleMapper;
...@@ -82,21 +79,13 @@ public class ReadDataToCacheRunner implements CommandLineRunner { ...@@ -82,21 +79,13 @@ public class ReadDataToCacheRunner implements CommandLineRunner {
warningCache.put(warning.getCode(), warning); warningCache.put(warning.getCode(), warning);
} }
// List<WorkRoom> rooms = workRoomMapper.findList(new WhereFilter(), WorkRoom.class);
//
//
// Map<String, List<WorkRoom>> listMap = rooms.stream().collect(Collectors.groupingBy(WorkRoom::getLedNo));
// for (Map.Entry<String, List<WorkRoom>> entry : listMap.entrySet()) {
// roomCache.put(Constant.LED_PREFIX + entry.getKey(), entry.getValue());
// }
List<PaintshopStation> stations = stationMapper.findList(new WhereFilter() {{ List<PaintshopStation> stations = stationMapper.findList(new WhereFilter() {{
addJoin(PaintshopStation.class, "area_id", PaintshopArea.class, "id"); addJoin(PaintshopStation.class, "area_id", PaintshopArea.class, "id");
addJoin(PaintshopStation.class, "lane_id", PaintshopLane.class, "id"); addJoin(PaintshopStation.class, "lane_id", PaintshopLane.class, "id");
addOrderBy(PaintshopStation.class, "id", OrderBy.ASC); addOrderBy(PaintshopStation.class, "id", OrderBy.ASC);
}}, PaintshopStation.class); }}, PaintshopStation.class);
//todo: 初始化工位信息 //todo: 初始化工位信息
/*for (int i = 0; i < stations.size(); i++) { /*for (int i = 0; i < stations.size(); i++) {
PaintshopStation station = stations.get(i); PaintshopStation station = stations.get(i);
if (i % 5 == 0) { if (i % 5 == 0) {
...@@ -119,13 +108,6 @@ public class ReadDataToCacheRunner implements CommandLineRunner { ...@@ -119,13 +108,6 @@ public class ReadDataToCacheRunner implements CommandLineRunner {
station.setState(StationState.FREE); station.setState(StationState.FREE);
valueOperations.set(Constant.STATION_PREFIX + station.getCode(), station); valueOperations.set(Constant.STATION_PREFIX + station.getCode(), station);
} }
// station.setTurnF(false);
// station.setTurnR(false);
// station.setArrive(false);
// station.setBusType(ProductionType.OWN);
// station.setBusNo("eee");
// station.setState(StationState.USE);
// valueOperations.set(Constant.STATION_PREFIX + station.getCode() ,station);
} }
stationCache.put("ALL", stations); stationCache.put("ALL", stations);
//将工位按照车道号进行分组 //将工位按照车道号进行分组
...@@ -144,17 +126,6 @@ public class ReadDataToCacheRunner implements CommandLineRunner { ...@@ -144,17 +126,6 @@ public class ReadDataToCacheRunner implements CommandLineRunner {
vehicleCache.put(vehicle.getMqttPrefix(), vehicle); vehicleCache.put(vehicle.getMqttPrefix(), vehicle);
} }
//
// 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);
// }
// List<Skid> skids = skidMapper.findList(new WhereFilter(), Skid.class);
// for (PaintshopStation station : stations) {
// stationCache.put(station.getCode(), station);
// }
List<PaintshopArea> list = areaMapper.findList(new WhereFilter(), PaintshopArea.class); List<PaintshopArea> list = areaMapper.findList(new WhereFilter(), PaintshopArea.class);
webStationCache.put("stationList", list); webStationCache.put("stationList", list);
......
package net.vtstar.zhongtong.avi.monitoring.service; package net.vtstar.zhongtong.avi.monitoring.service;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import net.vtstar.user.mybatis.provider.Operation;
import net.vtstar.user.mybatis.provider.OrderBy;
import net.vtstar.user.mybatis.provider.WhereFilter;
import net.vtstar.user.search.service.SearchService;
import net.vtstar.utils.CollecUtils;
import net.vtstar.utils.DateUtils; import net.vtstar.utils.DateUtils;
import net.vtstar.zhongtong.avi.equipment.domain.PaintshopStation; import net.vtstar.zhongtong.avi.equipment.domain.PaintshopStation;
import net.vtstar.zhongtong.avi.monitoring.domain.StationPassInfo; import net.vtstar.zhongtong.avi.monitoring.domain.StationPassInfo;
import net.vtstar.zhongtong.avi.monitoring.domain.enums.ScanType;
import net.vtstar.zhongtong.avi.monitoring.mapper.StationPassInfoMapper; import net.vtstar.zhongtong.avi.monitoring.mapper.StationPassInfoMapper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.*;
import java.util.stream.Collectors;
/** /**
* @Author: xiadongwei * @Author: xiadongwei
* @Date: 2019/12/13 15:18 * @Date: 2019/12/13 15:18
*/ */
@Slf4j
@Service @Service
public class StationPassInfoService { public class StationPassInfoService {
public static String statusR = "replenish.scan.state";
public static String startTimeR = "replenish.scan.start";
public static String endTimeR = "replenish.scan.end";
private static List<String> passNames = Arrays.asList("3070-交验及防护", "3050-二遍清漆", "3130-水磨", "3120-色漆喷涂",
"3140-图案粘贴", "3100-面漆喷涂", "3160-中涂漆及打磨", "3020-车身附件安装", "3150-纹理漆", "3030-底漆找补", "3110-腻子刮磨",
"3170-阻尼胶喷涂", "3060-发泡喷涂", "3010-玻璃钢安装", "3090-密封", "3040-电泳");
@Resource(name = "mesSqlServerJdbcTemplate") @Resource(name = "mesSqlServerJdbcTemplate")
private JdbcTemplate mesSqlServerJdbcTemplate; private JdbcTemplate mesSqlServerJdbcTemplate;
@Autowired @Autowired
private StationPassInfoMapper passInfoMapper; private StationPassInfoMapper passInfoMapper;
/*//创建过站信息记录 @Autowired
public Long createPassInfo(String workOrderNo, String rfid, String areaNo, String stationNo){ private SearchService searchService;
StationPassInfo info = new StationPassInfo();
info.setVIN(workOrderNo); @Resource(name = "redisTemplate")
info.setRfid(rfid); private ValueOperations valueOperations;
info.setAreaNo(areaNo);
info.setStationNo(stationNo);
info.setInTime(new Date());
passInfoMapper.insert(info);
return info.getId();
}
public void endPassInfo(PaintshopStation station){
if (null == station || null == station.getPassInfoId()){
return;
}
StationPassInfo passInfo = passInfoMapper.getById(station.getPassInfoId(), StationPassInfo.class);
if (null == passInfo){
return;
}
passInfo.setOutTime(new Date());
passInfoMapper.update(passInfo);
//todo:!!!!!!!!!!!!!!!!
String sql = "INSERT INTO VEHICLE_PASSING_INFO VALUES (?,?,?,?,?,?,?)";
mesSqlServerJdbcTemplate.update(sql, new Object[]{passInfo.getVIN(), passInfo.getRfid(), passInfo.getAreaNo(),
passInfo.getStationNo(), DateUtils.parseDateToString(passInfo.getInTime(), "yyyy-MM-dd HH:mm:ss"),
DateUtils.parseDateToString(passInfo.getOutTime(), "yyyy-MM-dd HH:mm:ss"), 1});
}*/
//创建过站信息记录 //创建过站信息记录
public Long createPassInfo(String workOrderNo, String rfid, String areaNo, String stationNo){ public Long createPassInfo(String workOrderNo, String rfid, String areaNo, String stationNo) {
StationPassInfo info = new StationPassInfo(); StationPassInfo info = new StationPassInfo();
info.setVIN(workOrderNo); info.setVIN(workOrderNo);
info.setAreaNo(areaNo); info.setAreaNo(areaNo);
if (null == workOrderNo){ if (null == workOrderNo) {
info.setVIN(""); info.setVIN("");
} }
if (null == areaNo){ if (null == areaNo) {
info.setAreaNo(""); info.setAreaNo("");
} }
info.setRfid(rfid); info.setRfid(rfid);
info.setStationNo(stationNo); info.setStationNo(stationNo);
info.setStationName(getPassNameByStationNo(stationNo));
info.setInTime(new Date()); info.setInTime(new Date());
info.setPassTime(new Date());
info.setCreateTime(new Date()); info.setCreateTime(new Date());
info.setCreateBy("RFID");
passInfoMapper.insert(info); passInfoMapper.insert(info);
String sql = "INSERT INTO VEHICLE_PASSING_INFO VALUES (?,?,?,?,?,?,?)"; String sql = "INSERT INTO VEHICLE_PASSING_INFO VALUES (?,?,?,?,?,?,?)";
mesSqlServerJdbcTemplate.update(sql, new Object[]{info.getVIN(), info.getRfid(), info.getAreaNo(), mesSqlServerJdbcTemplate.update(sql, new Object[]{info.getVIN(), info.getRfid(), info.getAreaNo(),
info.getStationNo(), DateUtils.parseDateToString(info.getInTime(), "yyyy-MM-dd HH:mm:ss"), info.getStationNo(), DateUtils.parseDateToString(info.getPassTime(), "yyyy-MM-dd HH:mm:ss"),
info.getOutTime(), 1}); null, 1});
return info.getId(); return info.getId();
} }
public void endPassInfo(PaintshopStation station){ public void endPassInfo(PaintshopStation station) {
StationPassInfo info = new StationPassInfo(); StationPassInfo info = new StationPassInfo();
info.setVIN(station.getSkid().getWorkOrderNo()); info.setVIN(station.getSkid().getWorkOrderNo());
info.setAreaNo(station.getAreaName()); info.setAreaNo(station.getAreaName());
if (null == station.getSkid().getWorkOrderNo()){ if (null == station.getSkid().getWorkOrderNo()) {
info.setVIN(""); info.setVIN("");
} }
if (null == station.getAreaName()){ if (null == station.getAreaName()) {
info.setAreaNo(""); info.setAreaNo("");
} }
info.setRfid(station.getSkid().getRfid()); info.setRfid(station.getSkid().getRfid());
info.setStationNo(station.getCode()); info.setStationNo(station.getCode());
info.setStationName(getPassNameByStationNo(station.getCode()));
info.setOutTime(new Date()); info.setOutTime(new Date());
info.setPassTime(new Date());
info.setCreateTime(new Date()); info.setCreateTime(new Date());
info.setCreateBy("RFID");
passInfoMapper.insert(info); passInfoMapper.insert(info);
//todo:!!!!!!!!!!!!!!!! //todo:!!!!!!!!!!!!!!!!
String sql = "INSERT INTO VEHICLE_PASSING_INFO VALUES (?,?,?,?,?,?,?)"; String sql = "INSERT INTO VEHICLE_PASSING_INFO VALUES (?,?,?,?,?,?,?)";
mesSqlServerJdbcTemplate.update(sql, new Object[]{info.getVIN(), info.getRfid(), info.getAreaNo(), mesSqlServerJdbcTemplate.update(sql, new Object[]{info.getVIN(), info.getRfid(), info.getAreaNo(),
info.getStationNo(), info.getInTime(), info.getStationNo(), DateUtils.parseDateToString(info.getPassTime(), "yyyy-MM-dd HH:mm:ss"),
DateUtils.parseDateToString(info.getOutTime(), "yyyy-MM-dd HH:mm:ss"), 1}); null, 1});
}
public List<StationPassInfo> findPassInfoByNoFind() {
return passInfoMapper.findList(new WhereFilter() {{
addFilter("pass_time", Operation.IS, "null");
addFilter("station_name", Operation.IS_NOT, "null");
addOrderBy("create_time", OrderBy.DESC);
}}, StationPassInfo.class);
}
public List<StationPassInfo> findPassInfoBySearchCode(JSONObject pageFilter) {
PageHelper.startPage(pageFilter.getIntValue("pageNum"), pageFilter.getIntValue("pageSize"));
if (ScanType.NULL.name().equals(pageFilter.get("scanType"))){
return passInfoMapper.findList(searchService.pageFilter2Filter(pageFilter, new WhereFilter(){{
addFilter("pass_time", Operation.IS, "null");
addFilter("station_name", Operation.IS_NOT, "null");
}}), StationPassInfo.class);
}
return passInfoMapper.findList(searchService.pageFilter2Filter(pageFilter), StationPassInfo.class);
} }
public void savePassInfo(StationPassInfo info) {
StationPassInfo byId = passInfoMapper.getById(info.getId(), StationPassInfo.class);
byId.setPassTime(info.getPassTime());
byId.setStationNo(info.getStationNo());
byId.setCreateBy(info.getCreateBy());
byId.setCreateTime(new Date());
passInfoMapper.update(byId);
String sql = "INSERT INTO VEHICLE_PASSING_INFO VALUES (?,?,?,?,?,?,?)";
mesSqlServerJdbcTemplate.update(sql, new Object[]{info.getVIN(), byId.getRfid(), byId.getAreaNo(),
info.getStationNo(), DateUtils.parseDateToString(info.getPassTime(), "yyyy-MM-dd HH:mm:ss"),
null, 1});
}
public void startReplenishScan(Integer beginTimeInt, Integer endTimeInt) {
valueOperations.set(statusR, true);
valueOperations.set(startTimeR, beginTimeInt);
valueOperations.set(endTimeR, endTimeInt);
}
public void stopReplenishScan() {
valueOperations.set(statusR, false);
}
public void checkPassInfo(String workOrderNo, String rfid) {
Boolean status = (Boolean) valueOperations.get(statusR);
Integer startInt = (Integer) valueOperations.get(startTimeR);
Integer endInt = (Integer) valueOperations.get(endTimeR);
if (null == startInt || null == endInt){
startInt = 0;
endInt = 10;
}
if (null == status || !status){
return;
}
List<StationPassInfo> list = passInfoMapper.findList(new WhereFilter() {{
addFilter("VIN", Operation.EQUAL, workOrderNo);
addFilter("rfid", Operation.EQUAL, rfid);
}}, StationPassInfo.class);
Map<String, List<StationPassInfo>> listMap = list.stream().filter(s -> s.getStationName() != null).collect(Collectors.groupingBy(StationPassInfo::getStationName));
for (int i = 0; i < passNames.size(); i++){
String passName = passNames.get(i);
if (null != listMap.get(passName)){
continue;
}
if (i == 0){
StationPassInfo info = new StationPassInfo();
info.setVIN(workOrderNo);
info.setAreaNo(getAreaNoByName(passName));
info.setStationNo(getStationNoByName(passName)[0]);
info.setRfid(rfid);
info.setStationName(passName);
info.setPassTime(new Date());
info.setCreateTime(new Date());
info.setCreateBy("rfid");
passInfoMapper.insert(info);
continue;
}
String lastPassName = passNames.get(i - 1);
List<StationPassInfo> lastInfo = passInfoMapper.findList(new WhereFilter() {{
addFilter("VIN", Operation.EQUAL, workOrderNo);
addFilter("rfid", Operation.EQUAL, rfid);
addFilter("station_name", Operation.EQUAL, lastPassName);
}}, StationPassInfo.class);
if (!CollecUtils.isEmpty(lastInfo)){
int time = (int)(Math.random() * (endInt - startInt) + startInt);
StationPassInfo stationPassInfo = lastInfo.get(0);
StationPassInfo info = new StationPassInfo();
info.setVIN(workOrderNo);
info.setAreaNo(getAreaNoByName(passName));
info.setStationNo(getStationNoByName(passName)[0]);
info.setRfid(rfid);
info.setStationName(passName);
info.setPassTime(new Date(stationPassInfo.getCreateTime().getTime() - (time * 60 * 1000)));
info.setCreateTime(new Date());
info.setCreateBy("rfid");
passInfoMapper.insert(info);
}else{
log.error("自动补扫失败, 没有找到其下一工序的信息");
}
}
}
public String[] getStationNoByName(String stationName) {
String[] str;
switch (stationName) {
case "3040-电泳":
str = new String[]{"HDG2-2"};
break;
case "3090-密封":
str = new String[]{"HDG1-57", "HDG1-58", "HDG1-75"};
break;
case "3010-玻璃钢安装":
str = new String[]{"HDG1-70", "HDG1-74"};
break;
case "3060-发泡喷涂":
str = new String[]{"HDG1-89", "HDG1-94"};
break;
case "3170-阻尼胶喷涂":
str = new String[]{"HDG1-85", "HDG1-90"};
break;
case "3110-腻子刮磨":
str = new String[]{"HDG1-109", "HDG1-114"};
break;
case "3030-底漆找补":
str = new String[]{"HDG1-109", "HDG1-114"};
break;
case "3150-纹理漆":
str = new String[]{"HDG1-109", "HDG1-114"};
break;
case "3020-车身附件安装":
str = new String[]{"HDG1-105", "HDG1-110"};
break;
case "3160-中涂漆及打磨":
str = new String[]{"HDG1-119", "HDG1-129"};
break;
case "3100-面漆喷涂":
str = new String[]{"HDG1-168", "HDG1-170", "HDG1-171", "HDG1-196"};
break;
case "3140-图案粘贴":
str = new String[]{"HDG1-150", "HDG1-151", "HDG1-152", "HDG1-156", "HDG1-157"};
break;
case "3120-色漆喷涂":
str = new String[]{"HDG1-181", "HDG1-184", "HDG1-190", "HDG1-195"};
break;
case "3130-水磨":
str = new String[]{"HDG5-24", "HDG5-25"};
break;
case "3050-二遍清漆":
str = new String[]{"HDG1-168", "HDG1-170", "HDG1-171", "HDG1-196"};
break;
case "3070-交验及防护":
str = new String[]{"HDG1-153", "HDG1-154", "HDG1-155", "HDG1-158", "HDG1-159", "HDG1-160"};
break;
default:
str = new String[]{};
break;
}
return str;
}
private String getPassNameByStationNo(String stationNo) {
String passName;
switch (stationNo) {
case "HDG2-2":
passName = "3040-电泳";
break;
case "HDG1-57":
passName = "3090-密封";
break;
case "HDG1-58":
passName = "3090-密封";
break;
case "HDG1-75":
passName = "3090-密封";
break;
case "HDG1-70":
passName = "3010-玻璃钢安装";
break;
case "HDG1-74":
passName = "3010-玻璃钢安装";
break;
case "HDG1-89":
passName = "3060-发泡喷涂";
break;
case "HDG1-94":
passName = "3060-发泡喷涂";
break;
case "HDG1-85":
passName = "3170-阻尼胶喷涂";
break;
case "HDG1-90":
passName = "3170-阻尼胶喷涂";
break;
case "HDG1-109":
passName = "3110-腻子刮磨";
break;
case "HDG1-114":
passName = "3110-腻子刮磨";
break;
case "HDG1-105":
passName = "3020-车身附件安装";
break;
case "HDG1-110":
passName = "3020-车身附件安装";
break;
case "HDG1-119":
passName = "3160-中涂漆及打磨";
break;
case "HDG1-129":
passName = "3160-中涂漆及打磨";
break;
case "HDG1-168":
passName = "3100-面漆喷涂";
break;
case "HDG1-170":
passName = "3100-面漆喷涂";
break;
case "HDG1-171":
passName = "3100-面漆喷涂";
break;
case "HDG1-196":
passName = "3100-面漆喷涂";
break;
case "HDG1-150":
passName = "3140-图案粘贴";
break;
case "HDG1-151":
passName = "3140-图案粘贴";
break;
case "HDG1-152":
passName = "3140-图案粘贴";
break;
case "HDG1-156":
passName = "3140-图案粘贴";
break;
case "HDG1-157":
passName = "3140-图案粘贴";
break;
case "HDG1-181":
passName = "3120-色漆喷涂";
break;
case "HDG1-184":
passName = "3120-色漆喷涂";
break;
case "HDG1-190":
passName = "3120-色漆喷涂";
break;
case "HDG1-195":
passName = "3120-色漆喷涂";
break;
case "HDG5-24":
passName = "3130-水磨";
break;
case "HDG5-25":
passName = "3130-水磨";
break;
case "HDG1-153":
passName = "3070-交验及防护";
break;
case "HDG1-154":
passName = "3070-交验及防护";
break;
case "HDG1-155":
passName = "3070-交验及防护";
break;
case "HDG1-158":
passName = "3070-交验及防护";
break;
case "HDG1-159":
passName = "3070-交验及防护";
break;
case "HDG1-160":
passName = "3070-交验及防护";
break;
default:
passName = "";
break;
}
return passName;
}
public String getAreaNoByName(String stationName) {
String str;
switch (stationName) {
case "3040-电泳":
str = "电泳";
break;
case "3090-密封":
str = "密封防腐";
break;
case "3010-玻璃钢安装":
str = "密封防腐";
break;
case "3060-发泡喷涂":
str = "密封防腐";
break;
case "3170-阻尼胶喷涂":
str = "密封防腐";
break;
case "3110-腻子刮磨":
str = "腻子";
break;
case "3030-底漆找补":
str = "腻子";
break;
case "3150-纹理漆":
str = "腻子";
break;
case "3020-车身附件安装":
str = "腻子";
break;
case "3160-中涂漆及打磨":
str = "面/色漆";
break;
case "3100-面漆喷涂":
str = "面/色漆";
break;
case "3140-图案粘贴":
str = "面/色漆";
break;
case "3120-色漆喷涂":
str = "面/色漆";
break;
case "3130-水磨":
str = "面/色漆";
break;
case "3050-二遍清漆":
str = "面/色漆";
break;
case "3070-交验及防护":
str = "成品";
break;
default:
str = "";
break;
}
return str;
}
} }
...@@ -3,62 +3,53 @@ package net.vtstar.zhongtong.avi.mqtt.handle; ...@@ -3,62 +3,53 @@ package net.vtstar.zhongtong.avi.mqtt.handle;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.vtstar.protocol.modbus.tcp.netty.service.ModbusTemplate;
import net.vtstar.scada.base.global.service.ModbusService;
import net.vtstar.scada.base.mqtt.utils.MqttConstants; import net.vtstar.scada.base.mqtt.utils.MqttConstants;
import net.vtstar.user.mybatis.provider.Operation; import net.vtstar.utils.CollecUtils;
import net.vtstar.user.mybatis.provider.OrderBy;
import net.vtstar.user.mybatis.provider.WhereFilter;
import net.vtstar.zhongtong.avi.equipment.domain.PaintshopArea;
import net.vtstar.zhongtong.avi.equipment.domain.PaintshopStation; import net.vtstar.zhongtong.avi.equipment.domain.PaintshopStation;
import net.vtstar.zhongtong.avi.equipment.domain.RuntimeRecord;
import net.vtstar.zhongtong.avi.equipment.mapper.PaintshopStationMapper; import net.vtstar.zhongtong.avi.equipment.mapper.PaintshopStationMapper;
import net.vtstar.zhongtong.avi.global.constant.Constant; import net.vtstar.zhongtong.avi.global.constant.Constant;
import net.vtstar.zhongtong.avi.monitoring.domain.Skid; import net.vtstar.zhongtong.avi.monitoring.domain.Skid;
import net.vtstar.zhongtong.avi.monitoring.domain.StationPassInfo;
import net.vtstar.zhongtong.avi.monitoring.domain.Vehicle; import net.vtstar.zhongtong.avi.monitoring.domain.Vehicle;
import net.vtstar.zhongtong.avi.monitoring.domain.bo.MQTTMessageBO; import net.vtstar.zhongtong.avi.monitoring.domain.bo.MQTTMessageBO;
import net.vtstar.zhongtong.avi.monitoring.domain.enums.Direction;
import net.vtstar.zhongtong.avi.monitoring.domain.enums.ProductionType; import net.vtstar.zhongtong.avi.monitoring.domain.enums.ProductionType;
import net.vtstar.zhongtong.avi.monitoring.domain.enums.StationState; import net.vtstar.zhongtong.avi.monitoring.domain.enums.StationState;
import net.vtstar.zhongtong.avi.monitoring.mapper.StationPassInfoMapper;
import net.vtstar.zhongtong.avi.monitoring.service.StationPassInfoService; import net.vtstar.zhongtong.avi.monitoring.service.StationPassInfoService;
import net.vtstar.zhongtong.avi.utils.EquipDataUtil; import net.vtstar.zhongtong.avi.utils.EquipDataUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache; import org.springframework.cache.Cache;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.ListOperations; import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations; import org.springframework.data.redis.core.ValueOperations;
import org.springframework.messaging.Message; import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.MessagingException; import org.springframework.messaging.MessagingException;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@Slf4j @Slf4j
@Order(value = 99) @Order(value = 99)
//@Component @Component
public class RfidMessageHandler extends AbstractTesterMessageHandler { public class RfidMessageHandler extends AbstractTesterMessageHandler {
public static MQTTMessageBO messageBO = new MQTTMessageBO(); public static MQTTMessageBO messageBO = new MQTTMessageBO();
public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy:MM:dd"); public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy:MM:dd");
public static List<String> rfidList1 = Arrays.asList("rfid51", "rfid52", "rfid53", "rfid54");
@Autowired public static List<String> rfidList2 = Arrays.asList("rfid71", "rfid72", "rfid73", "rfid74");
private RedisTemplate redisTemplate; //电泳换撬平移车
public static List<String> rfidList3 = Arrays.asList("rfid52", "rfid53", "rfid54");
public static List<String> stationList1 = Arrays.asList("HDG1-30", "HDG1-53", "HDG1-55", "HDG1-57", "HDG1-58", "HDG1-75");
//4车道换撬车道上撬
public static List<String> rfidList4 = Arrays.asList("rfid59", "rfid60", "rfid61", "rfid62", "rfid63", "rfid64");
public static List<String> stationList2 = Arrays.asList("HDG1-70", "HDG1-74", "HDG1-79", "HDG5-8", "HDG5-9");
@Resource(name = "redisTemplate") @Resource(name = "redisTemplate")
private ListOperations listOperations; private ListOperations listOperations;
@Resource(name = "redisTemplate")
private HashOperations hashOperations;
@Resource(name = "redisTemplate") @Resource(name = "redisTemplate")
private ValueOperations valueOperations; private ValueOperations valueOperations;
...@@ -70,15 +61,13 @@ public class RfidMessageHandler extends AbstractTesterMessageHandler { ...@@ -70,15 +61,13 @@ public class RfidMessageHandler extends AbstractTesterMessageHandler {
private Cache vehicleCache; private Cache vehicleCache;
@Resource(name = "webStationCache") @Resource(name = "webStationCache")
private Cache webStationCache; private Cache webStationCache;
@Resource(name = "laneRfidStationCache")
private Cache laneRfidStationCache;
@Autowired @Autowired
private StationPassInfoService passInfoService; private StationPassInfoService passInfoService;
@Autowired @Autowired
private ModbusTemplate modbusTemplate;
@Autowired
private PaintshopStationMapper stationMapper; private PaintshopStationMapper stationMapper;
@Autowired
private StationPassInfoMapper passInfoMapper;
@Resource(name = "redisTemplate") @Resource(name = "redisTemplate")
protected ValueOperations testValueOperations; protected ValueOperations testValueOperations;
...@@ -93,215 +82,412 @@ public class RfidMessageHandler extends AbstractTesterMessageHandler { ...@@ -93,215 +82,412 @@ public class RfidMessageHandler extends AbstractTesterMessageHandler {
Object payload = message.getPayload(); Object payload = message.getPayload();
JSONObject json = JSONObject.parseObject(payload.toString()); JSONObject json = JSONObject.parseObject(payload.toString());
String id = json.getString("ID"); //平移车扫到滑撬ID
if (null == id){ String id = json.getString("TID");
id = json.getString("TID"); if (StringUtil.isNullOrEmpty(id)) {
id = json.getString("ID");
}
String uId = json.getString("UID");
if (null != id && id.length() == 20) {
uId = id;
id = null;
} }
//平移车扫描车道ID
Integer state = json.getIntValue("State"); Integer state = json.getIntValue("State");
if (StringUtil.isNullOrEmpty(id)) { if (StringUtil.isNullOrEmpty(id) && StringUtil.isNullOrEmpty(uId)) {
return; return;
} }
String today = dateFormat.format(date);
//存rfid log日志
messageBO.setID(id);
messageBO.setState(state);
String currentDate = format.format(date);
messageBO.setCreateDate(currentDate);
MessageHeaders headers = message.getHeaders(); MessageHeaders headers = message.getHeaders();
String vehicleCode = headers.get(MqttConstants.MSG_HEADER_KEY_EQUIPMENTNUMBER, String.class); String vehicleCode = headers.get(MqttConstants.MSG_HEADER_KEY_EQUIPMENTNUMBER, String.class);
Vehicle vehicle = (Vehicle) valueOperations.get(Constant.VEHICLE_PREFIX + vehicleCode);
log.info(vehicleCode + "______" + json.toJSONString() + " code:" + vehicleCode); if (null == vehicle) {
vehicle = vehicleCache.get(vehicleCode, Vehicle.class);
if (id.startsWith("A61A")) {
log.error("过滤掉乱发信息!:{},平移车:{}", id, vehicleCode);
return;
} }
if (!StringUtil.isNullOrEmpty(id)) {
if (id.length() == 30) {
id = id.substring(0, 29);
}
//针对电泳处有两个读写头的情况, 将两个读写头的情况都合并到小端的Vehicle上进行处理;
String otherCode = getOtherVehicleCode(vehicleCode);
if (rfidList2.contains(vehicleCode)) {
vehicle = (Vehicle) valueOperations.get(Constant.VEHICLE_PREFIX + otherCode);
if (null == vehicle) {
vehicle = vehicleCache.get(otherCode, Vehicle.class);
}
}
String today = dateFormat.format(date);
//存rfid log日志
messageBO.setID(id);
messageBO.setState(state);
String currentDate = format.format(date);
messageBO.setCreateDate(currentDate);
Skid skid = (Skid) valueOperations.get(Constant.SKID_PREFIX + id); // log.info(vehicleCode + "______" + json.toJSONString() + " code:" + vehicleCode);
//若是焊装车间进车,绑定滑撬与车身关系
if (state == 1 && (vehicleCode.equals(Constant.HANZHUANG_VEHICLE1_RFID) || vehicleCode.equals(Constant.HANZHUANG_VEHICLE2_RFID))) {
//记录焊装上车的信息
listOperations.rightPush("rfid:log:" + vehicleCode, messageBO);
String busNo = (String) valueOperations.get(Constant.HANZHUANG_VEHICLE_BUSNO_KEY + vehicleCode); if (id.startsWith("A61A")) {
String workOrderNo = (String) valueOperations.get(Constant.HANZHUANG_VEHICLE_WORKNO_KEY + vehicleCode); log.error("过滤掉乱发信息!:{},平移车:{}", id, vehicleCode);
if (null == busNo) {
log.error("未录入PDA车身号! :" + vehicleCode);
return; return;
} }
if (null == skid) {
skid = new Skid(); Skid skid = (Skid) valueOperations.get(Constant.SKID_PREFIX + id);
skid.setRfid(id); //平移车下车信息, 记录此时的下车时间
skid.setBusNo(busNo); if (state == 0) {
skid.setWorkOrderNo(workOrderNo); //在rfid51,rfid52,rfid53,rfid54端上撬
skid.setBusType(ProductionType.OWN); if (rfidList1.contains(vehicleCode)) {
valueOperations.set(Constant.SKID_PREFIX + id, skid); if (null == vehicle.getMqttCode()) {
//若state=0时, 还没有绑定上撬侧编号, 则说明上撬逻辑有问题
log.error("平移车: {}, state=0时, 没有绑定上撬侧编号", vehicleCode);
return;
} else if (vehicleCode.equals(vehicle.getMqttCode())) {
//若为上撬侧读写头发出的state=0, 全部屏蔽掉
return;
}
}
if (rfidList2.contains(vehicleCode)) {
if (null == vehicle.getMqttCode()) {
//若state=0时, 还没有绑定上撬侧编号, 则说明上撬逻辑有问题
log.error("平移车: {}, state=0时, 没有绑定上撬侧编号", vehicleCode);
return;
} else if (vehicleCode.equals(vehicle.getMqttCode())) {
//若为上撬侧读写头发出的state=0, 全部屏蔽掉
return;
} else {
//若为另一侧读写头发出的state=0, 则认为是下车信号;
vehicleCode = otherCode;
}
}
if (null == skid) {
//因上车必定会绑定一次skid, 所以若skid为null, 则记录为异常情况
// log.error("----------平移车: {}下车, 但是未查询到滑撬信息, ID为: {}---------------", vehicleCode, id);
return;
}
vehicle.setState(false);
vehicle.setCurrentRfid(id);
vehicle.setSkid(skid);
vehicle.setDownTime(date);
vehicle.setDownTimeMin(0);
valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle);
return;
} }
String format = dateFormat.format(date); if (state != 1) {
String key = Constant.BUS_SIZE_IN + "0:" + format; log.error("mqtt接收到的state不为0也不为1!!!");
Integer size = (Integer) valueOperations.get(key); return;
if (null == size) {
size = 1;
}else {
size ++;
} }
valueOperations.set(key, size); String rfid = vehicle.getCurrentRfid();
String keyW = EquipDataUtil.getTestValueKey(Constant.ROTARY_ROLLER_BED_C); //若当前平移车上绑定了RFID, 并且与当前mqtt信息中的ID一致, 并且state=1, 则认为这是读写头的重发现象
testValueOperations.set(keyW, null == testValueOperations.get(keyW) ? 0 : ((int)testValueOperations.get(keyW)) + 1); if (null != rfid && id.equals(rfid)) {
return;
}
//todo: 因PDA未使用, 暂不做此逻辑判断
/*if (null == skid) {
log.error("无滑撬信息! :" + vehicleCode);
return;
}*/
Vehicle vehicle = (Vehicle) valueOperations.get(Constant.VEHICLE_PREFIX + vehicleCode);
if (null == vehicle) {
vehicle = vehicleCache.get(vehicleCode, Vehicle.class);
}
String rfid = vehicle.getCurrentRfid();
//若当前平移车上绑定了RFID, 并且与当前mqtt信息中的ID一致, 并且state=1, 则认为这是读写头的重发现象
if (null != rfid && id.equals(rfid)) {
if (state == 1) {
Date occurTime = vehicle.getOccurTime(); Date occurTime = vehicle.getOccurTime();
if (null != occurTime) { if (null != occurTime) {
long l = (date.getTime() - occurTime.getTime()) / 1000; long l = (date.getTime() - occurTime.getTime()) / 1000;
if (l < 30) { if (l < 5) {
// log.error("{} 平移车发生重发现象 ,滑撬id {}", vehicleCode, id); //log.error("{} 平移车发生重发现象 ,滑撬id {}", vehicleCode, id);
vehicle.setOccurTime(date); vehicle.setOccurTime(date);
valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle); if (rfidList2.contains(vehicleCode)) {
valueOperations.set(Constant.VEHICLE_PREFIX + otherCode, vehicle);
} else {
valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle);
}
return; return;
} }
} }
} }
} //判断是否为返修
//平移车过车信息 Object reWorkVehicle = valueOperations.get(Constant.VEHICLE_PREFIX_REWORK);
listOperations.rightPush("rfid:log:" + vehicleCode, messageBO); if (null != reWorkVehicle && !"".equals(reWorkVehicle.toString())) {
if (vehicleCode.equals(reWorkVehicle.toString())) {
if (state == 0) { //记录返修上车的信息
vehicle.setState(false); listOperations.rightPush("rfid:log:fanxiu:" + vehicleCode, messageBO);
if (null != skid){ String busNo = (String) valueOperations.get(Constant.VEHICLE_PREFIX_REWORK_BUSNO);
vehicle.setSkid(skid); if (null == skid) {
skid = new Skid();
skid.setRfid(id);
}
skid.setBusNo(busNo);
skid.setWorkOrderNo(null);
skid.setBusType(ProductionType.OTHER);
valueOperations.set(Constant.SKID_PREFIX + id, skid);
valueOperations.set(Constant.VEHICLE_PREFIX_REWORK, "");
valueOperations.set(Constant.VEHICLE_PREFIX_REWORK_BUSNO, "");
passInfoService.createPassInfo(skid.getWorkOrderNo(), skid.getRfid(), "返修上线", "");
return;
}
} }
vehicle.setOccurTime(new Date()); //若是焊装车间进车,绑定滑撬与车身关系
valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle); if ((vehicleCode.equals(Constant.HANZHUANG_VEHICLE1_RFID) || vehicleCode.equals(Constant.HANZHUANG_VEHICLE2_RFID))) {
return; //记录焊装上车的信息
} listOperations.rightPush("rfid:log:shangqiao:" + vehicleCode, messageBO);
//TODO: 若上车时, 发现此滑撬号未被绑定过, 则有两种情况: 漏读/系统启动前就上线的 String format = dateFormat.format(date);
if (null == skid){ String key = Constant.BUS_SIZE_IN + "0:" + format;
skid = new Skid(); Integer size = (Integer) valueOperations.get(key);
skid.setRfid(id); if (null == size) {
skid.setBusNo(""); size = 1;
skid.setWorkOrderNo("TZ0010051107_0011"); } else {
skid.setBusType(ProductionType.OWN); size++;
valueOperations.set(Constant.SKID_PREFIX + id, skid); }
} valueOperations.set(key, size);
vehicle.setState(true); String keyW = EquipDataUtil.getTestValueKey(Constant.ROTARY_ROLLER_BED_W);
vehicle.setOccurTime(date); testValueOperations.set(keyW, null == testValueOperations.get(keyW) ? 0 : ((int) testValueOperations.get(keyW)) + 1);
vehicle.setCurrentRfid(id);
vehicle.setSkid(skid); String busNo = (String) valueOperations.get(Constant.HANZHUANG_VEHICLE_BUSNO_KEY + vehicleCode);
// valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle); String workOrderNo = (String) valueOperations.get(Constant.HANZHUANG_VEHICLE_WORKNO_KEY + vehicleCode);
if (StringUtil.isNullOrEmpty(busNo)) {
log.error("未录入PDA车身号! :" + vehicleCode);
return;
}
if (null == skid) {
skid = new Skid();
skid.setRfid(id);
}
skid.setBusNo(busNo);
skid.setWorkOrderNo(workOrderNo);
skid.setBusType(ProductionType.OWN);
valueOperations.set(Constant.SKID_PREFIX + id, skid);
List<PaintshopArea> areas = webStationCache.get("stationList", ArrayList.class); valueOperations.set(Constant.HANZHUANG_VEHICLE_BUSNO_KEY + vehicleCode, "");
if (null == areas){ valueOperations.set(Constant.HANZHUANG_VEHICLE_WORKNO_KEY + vehicleCode, "");
return; passInfoService.createPassInfo(skid.getWorkOrderNo(), skid.getRfid(), "涂装上线", "HXG1-1");
} return;
for (PaintshopArea area : areas) {
Map<String, PaintshopStation> stationMap = area.getStationMap();
if (null == stationMap){
continue;
} }
for (Map.Entry<String, PaintshopStation> entry : stationMap.entrySet()) { //底盘读写头
PaintshopStation value = entry.getValue(); if (vehicleCode.equals(Constant.TUZHUANG_VEHICLE4_RFID)) {
//因目前无法保证上撬工位一定位于平移车道两侧, 所以不再判断车道信息 String keyW = EquipDataUtil.getTestValueKey(Constant.ROTARY_ROLLER_BED_C);
/*if (!vehicle.getLane().equals(value.getVehicleLaneCode())) { testValueOperations.set(keyW, null == testValueOperations.get(keyW) ? 0 : ((int) testValueOperations.get(keyW)) + 1);
continue; }
}*/ //判断是否为轻客上车
if (vehicleCode.equals(Constant.TUZHUANG_VEHICLE2_RFID)) {
if (StationState.FREE.equals(value.getState())) { //判断此时rfid51上是否绑定了滑撬, 若已绑定, 则说明是从电泳方向上车, 若未绑定, 则说明是属于轻客上车
continue; if (null != vehicle && null == vehicle.getMqttCode()) {
if (null == skid) {
skid = new Skid();
skid.setRfid(id);
}
skid.setBusType(ProductionType.OTHER);
valueOperations.set(Constant.SKID_PREFIX + id, skid);
passInfoService.createPassInfo(skid.getWorkOrderNo(), skid.getRfid(), "轻客上线", "");
listOperations.rightPush("rfid:log:qingke:" + vehicleCode, messageBO);
} }
//TODO: 因当前环境中存在未上线的滑撬, 所以skid有可能为空 //此时为在电泳一侧上车, 并且停到了第二个读写头的位置, 和其他两个读写头的平移车相同处理方式
if(null == value.getSkid()){ }
continue; //若为涂装末工位, 记录出涂装交车数量
if (vehicleCode.equals(Constant.TUZHUANG_VEHICLE3_RFID)) {
String keyW = EquipDataUtil.getTestValueKey(Constant.ROTARY_ROLLER_BED_P2);
testValueOperations.set(keyW, null == testValueOperations.get(keyW) ? 0 : ((int) testValueOperations.get(keyW)) + 1);
String areaKey = Constant.BUS_SIZE_OUT + "0:" + today;
Integer size = (Integer) valueOperations.get(areaKey);
if (null == size) {
size = 1;
} else {
size++;
} }
if (id.equals(value.getSkid().getRfid())) { valueOperations.set(areaKey, size);
List<PaintshopStation> lands = new ArrayList<>(); if (null != skid) {
List<PaintshopStation> temStation = laneStationCache.get(value.getLaneId(), ArrayList.class); passInfoService.createPassInfo(skid.getWorkOrderNo(), skid.getRfid(), "涂装下线", "HXG2-1");
for (PaintshopStation land : temStation) { //todo: 校验工单是否存在漏扫的工序
PaintshopStation s = (PaintshopStation) valueOperations.get(Constant.STATION_PREFIX + land.getCode()); passInfoService.checkPassInfo(skid.getWorkOrderNo(), skid.getRfid());
lands.add(s); }
} listOperations.rightPush("rfid:log:chuche:" + vehicleCode, messageBO);
return;
lands.sort(Comparator.comparing(v -> v.getSequence())); }
//todo: 因PDA未使用, 暂不做此逻辑判断
PaintshopStation start = lands.get(0); if (null == skid) {
PaintshopStation end = lands.get(lands.size() - 1); // log.error("查询到未在Redis中的滑撬信息!vehicleCode: {}, ID: {} :", vehicleCode, id);
if (start.getCode().equals(value.getCode())) { //todo:
// return;
if(null == start.getSkid()){ skid = new Skid();
start.setSkid(value.getSkid()); skid.setRfid(id);
} skid.setBusNo("");
vehicle.setSkid(start.getSkid()); skid.setWorkOrderNo("");
vehicle.setCurrentRfid(start.getSkid().getRfid()); skid.setBusType(ProductionType.OWN);
valueOperations.set(Constant.SKID_PREFIX + id, skid);
for (int j = 1; j <= lands.size() - 2; j++) { }
PaintshopStation tem = lands.get(j); log.error("扫描到滑撬:" + skid.getRfid() + "读写头: " + vehicleCode);
PaintshopStation tem2 = lands.get(j - 1); //处理是否为2车道换撬
if (tem.getSkid() != null) { if (rfidList3.contains(vehicleCode) && null == vehicle.getMqttCode()) {
tem2.setSkid(tem.getSkid()); //若mqttCode为null, 则说明为小端上撬
tem2.setState(StationState.USE); List<PaintshopStation> stations = laneRfidStationCache.get(vehicle.getLaneRfid(), ArrayList.class);
} else { if (CollecUtils.isEmpty(stations)) {
tem2.setState(StationState.FREE); return;
tem2.setSkid(null); }
for (PaintshopStation station : stations) {
//只判断换撬区的工位
if (stationList1.contains(station.getCode())) {
List<PaintshopStation> temStation = laneStationCache.get(station.getLaneId(), ArrayList.class);
temStation.sort((s1, s2) -> s2.getSequence().compareTo(s1.getSequence()));
for (PaintshopStation item : temStation) {
PaintshopStation s = (PaintshopStation) valueOperations.get(Constant.STATION_PREFIX + item.getCode());
if (null == s.getSkid() && null != s.getWorkOrderNo()) {
skid.setWorkOrderNo(s.getWorkOrderNo());
skid.setBusNo(s.getBusNo());
skid.setBusType(s.getBusType());
valueOperations.set(Constant.SKID_PREFIX + id, skid);
//将工位上的工单信息绑定到滑撬上, 再将滑撬绑定到工位上
s.setSkid(skid);
s.setWorkOrderNo(null);
s.setBusNo(null);
valueOperations.set(Constant.STATION_PREFIX + item.getCode(), s);
break;
} }
tem.setState(StationState.FREE);
tem.setSkid(null);
}
if (null != start.getPassInfoId()){
passInfoService.endPassInfo(start);
} }
} else if (end.getCode().equals(value.getCode())) { }
if(null == end.getSkid()){ }
end.setSkid(value.getSkid()); }
} //处理是否为4车道换撬
vehicle.setSkid(end.getSkid()); if (rfidList4.contains(vehicleCode)) {
vehicle.setCurrentRfid(end.getSkid().getRfid()); List<PaintshopStation> stations = laneRfidStationCache.get(vehicle.getLaneRfid(), ArrayList.class);
if (CollecUtils.isEmpty(stations)) {
for (int j = lands.size() - 2; j >= 0; j--) { return;
PaintshopStation tem = lands.get(j); }
PaintshopStation tem2 = lands.get(j + 1); for (PaintshopStation station : stations) {
if (tem.getSkid() != null) { //TODO: 上线时东侧工位有影响
tem2.setState(StationState.USE); if (Direction.WEST.equals(station.getDirection()) && stationList2.contains(station.getCode())) {
tem2.setSkid(tem.getSkid()); List<PaintshopStation> temStation = laneStationCache.get(station.getLaneId(), ArrayList.class);
} else { temStation.sort(Comparator.comparing(v -> v.getSequence()));
tem2.setState(StationState.FREE); for (PaintshopStation item : temStation) {
tem2.setSkid(null); PaintshopStation s = (PaintshopStation) valueOperations.get(Constant.STATION_PREFIX + item.getCode());
if (null == s.getSkid() && null != s.getWorkOrderNo()) {
skid.setWorkOrderNo(s.getWorkOrderNo());
skid.setBusNo(s.getBusNo());
skid.setBusType(s.getBusType());
valueOperations.set(Constant.SKID_PREFIX + id, skid);
//将工位上的工单信息绑定到滑撬上, 再将滑撬绑定到工位上
s.setSkid(skid);
s.setWorkOrderNo(null);
s.setBusNo(null);
valueOperations.set(Constant.STATION_PREFIX + item.getCode(), s);
break;
} }
tem.setState(StationState.FREE);
tem.setSkid(null);
} }
if (null != end.getPassInfoId()){ }
passInfoService.endPassInfo(end); }
}
//在rfid51,rfid52,rfid53,rfid54端上撬
if (rfidList1.contains(vehicleCode)) {
if (null == vehicle.getMqttCode()) {
if (null != vehicle.getTurnR() && vehicle.getTurnR()) {
//若在小端扫rfid, 但是此时平移车正在反转, 说明此时平移车正在下车, 且上车时未扫到rfid
if (null == skid) {
return;
} }
}else{ log.error("----------平移车: {}下车信号, 漏读下车, 滑撬信息ID为: {}---------------", vehicleCode, id);
//因现场错误干扰, 导致滑撬不在两端工位 vehicle.setState(false);
for (PaintshopStation land : lands) { vehicle.setCurrentRfid(id);
if (land.getSkid() != null && id.equals(land.getSkid().getRfid())){ vehicle.setSkid(skid);
land.setSkid(null); vehicle.setDownTime(date);
land.setState(StationState.FREE); vehicle.setDownTimeMin(0);
if (null != land.getPassInfoId()){ valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle);
passInfoService.endPassInfo(land); return;
} }
} //若没有绑定平移车在哪侧上撬, 说明此时平移车刚刚在此侧上撬, 除了绑定上撬侧之外, 和正常上撬没有区别;
vehicle.setMqttCode(vehicleCode);
log.error("------------平移车在小端上撬, 平移车:{}---------", vehicleCode);
} else if (vehicleCode.equals(vehicle.getMqttCode())) {
//因为已经过滤过重发现象, 说明此时平移车上撬已经过去了10秒, 此时再有state=1的情况, 说明在此侧上车且在此侧下车;
if (null == skid) {
//因上车必定会绑定一次skid, 所以若skid为null, 则记录为异常情况
log.error("----------平移车: {}上车, 但是未查询到滑撬信息, ID为: {}---------------", vehicleCode, id);
return;
}
log.error("----------平移车: {}下车信号, 同侧下车, 滑撬信息ID为: {}---------------", vehicleCode, id);
vehicle.setState(false);
vehicle.setCurrentRfid(id);
vehicle.setSkid(skid);
vehicle.setDownTime(date);
vehicle.setDownTimeMin(0);
valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle);
return;
} else {
//上撬侧不为空, 且上撬侧不为小端, 则说明是在另外一侧上的车, 此时只改变平移车的上车时间
vehicle.setOccurTime(date);
valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle);
return;
}
}
//在rfid71,rfid72,rfid73,rfid74端上撬
if (rfidList2.contains(vehicleCode)) {
if (null == vehicle.getMqttCode()) {
if (null != vehicle.getTurnF() && vehicle.getTurnF()) {
//若在大端扫rfid, 但是此时平移车正在正转, 说明此时平移车正在下车, 且上车时未扫到rfid
if (null == skid) {
return;
} }
log.error("----------平移车: {}下车信号, 漏读下车, 滑撬信息ID为: {}---------------", vehicleCode, id);
vehicle.setState(false);
vehicle.setCurrentRfid(id);
vehicle.setSkid(skid);
vehicle.setDownTime(date);
vehicle.setDownTimeMin(0);
valueOperations.set(Constant.VEHICLE_PREFIX + otherCode, vehicle);
return;
}
//首先判断当前小端代表的平移车是否绑定了上撬端, 若没有, 则说明是在大端上撬, 此时将大端code绑定到平移车上, 并记录上车时间等到小端代表平移车上;
vehicle.setMqttCode(vehicleCode);
vehicleCode = otherCode;
} else if (vehicleCode.equals(vehicle.getMqttCode())) {
//此时小端平移车上已绑定了上撬端, 并且是在大端上撬, 那么此时state=1的情况, 则需要判断上撬时间是否大于10秒, 若不大于则为重发现象, 若大于则代表在大端侧进行下车;
if (null == skid) {
//因上车必定会绑定一次skid, 所以若skid为null, 则记录为异常情况
log.error("----------平移车: {}上车, 但是未查询到滑撬信息, ID为: {}---------------", vehicleCode, id);
return;
} }
vehicle.setState(false);
vehicle.setCurrentRfid(id);
vehicle.setSkid(skid);
vehicle.setDownTime(date);
vehicle.setDownTimeMin(0);
valueOperations.set(Constant.VEHICLE_PREFIX + otherCode, vehicle);
return;
} else {
//此时小端平移车已经绑定了滑撬, 并且在小端上撬, 那么此时state=1的情况, 则只改变平移车的上车时间
vehicle.setOccurTime(date);
valueOperations.set(Constant.VEHICLE_PREFIX + otherCode, vehicle);
return;
}
}
//平移车上车信息
listOperations.rightPush("rfid:log:" + vehicleCode, messageBO);
//TODO: 记录过站信息 //平移车上车
vehicle.setState(true);
vehicle.setOccurTime(date);
vehicle.setDownTime(null);
vehicle.setDownTimeMin(0);
vehicle.setCurrentRfid(id);
vehicle.setSkid(skid);
//若为涂装首工位上车, 且为焊装刚刚过来的, 此时无法从工位列表中找到滑撬信息, 所以单独处理
if (vehicleCode.equals(Constant.TUZHUANG_VEHICLE1_RFID) && Constant.TUZHUANG_LANE1_RFID.equals(vehicle.getLaneRfid())) {
valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle);
String keyW = EquipDataUtil.getTestValueKey(Constant.ROTARY_ROLLER_BED_P1);
testValueOperations.set(keyW, null == testValueOperations.get(keyW) ? 0 : ((int) testValueOperations.get(keyW)) + 1);
return;
}
//根据平移车所在车道RFID编号查询车道两边的工位
List<PaintshopStation> stations = laneRfidStationCache.get(vehicle.getLaneRfid(), ArrayList.class);
if (CollecUtils.isEmpty(stations)) {
return;
}
boolean isFind = false;
//首先在平移车所在车道两边工位查询
for (PaintshopStation value : stations) {
List<PaintshopStation> lands = new ArrayList<>();
List<PaintshopStation> temStation = laneStationCache.get(value.getLaneId(), ArrayList.class);
for (PaintshopStation land : temStation) {
PaintshopStation s = (PaintshopStation) valueOperations.get(Constant.STATION_PREFIX + land.getCode());
lands.add(s);
}
for (PaintshopStation land : lands) {
if (land.getSkid() != null && id.equals(land.getSkid().getRfid())) {
passInfoService.endPassInfo(land);
isFind = true;
land.setSkid(null);
land.setState(StationState.FREE);
}
}
if (isFind) {
//记录过站数量
String areaCode = value.getAreaId().toString(); String areaCode = value.getAreaId().toString();
String areaKey = Constant.BUS_SIZE_OUT + areaCode + ":" + today; String areaKey = Constant.BUS_SIZE_OUT + areaCode + ":" + today;
Integer size = (Integer) valueOperations.get(areaKey); Integer size = (Integer) valueOperations.get(areaKey);
...@@ -316,139 +502,89 @@ public class RfidMessageHandler extends AbstractTesterMessageHandler { ...@@ -316,139 +502,89 @@ public class RfidMessageHandler extends AbstractTesterMessageHandler {
valueOperations.set(Constant.STATION_PREFIX + land.getCode(), land); valueOperations.set(Constant.STATION_PREFIX + land.getCode(), land);
} }
valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle); valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle);
return;
} }
} }
} //若在平移车两侧未找到此滑撬, 则在所有工位中查找
valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle); List<PaintshopStation> stationByCache = stationCache.get("ALL", ArrayList.class);
//若为涂装首工位上车, 且为焊装刚刚过来的, 此时无法从工位列表中找到滑撬信息, 所以单独处理 if (CollecUtils.isEmpty(stationByCache)) {
if (vehicleCode.equals(Constant.TUZHUANG_VEHICLE1_RFID)){ return;
valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle); }
String keyW = EquipDataUtil.getTestValueKey(Constant.ROTARY_ROLLER_BED_P1); for (PaintshopStation station : stationByCache) {
testValueOperations.set(keyW, null == testValueOperations.get(keyW) ? 0 : ((int)testValueOperations.get(keyW)) + 1); PaintshopStation land = (PaintshopStation) valueOperations.get(Constant.STATION_PREFIX + station.getCode());
} if (land.getSkid() != null && id.equals(land.getSkid().getRfid())) {
if (vehicleCode.equals("rfid67")){ passInfoService.endPassInfo(land);
String keyW = EquipDataUtil.getTestValueKey(Constant.ROTARY_ROLLER_BED_P2); land.setSkid(null);
testValueOperations.set(keyW, null == testValueOperations.get(keyW) ? 0 : ((int)testValueOperations.get(keyW)) + 1); land.setState(StationState.FREE);
String areaKey = Constant.BUS_SIZE_OUT + "1" + ":" + today; isFind = true;
Integer size = (Integer) valueOperations.get(areaKey); valueOperations.set(Constant.STATION_PREFIX + land.getCode(), land);
if (null == size) { valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle);
size = 1; //记录过站数量
String areaCode = land.getAreaId().toString();
String areaKey = Constant.BUS_SIZE_OUT + areaCode + ":" + today;
Integer size = (Integer) valueOperations.get(areaKey);
if (null == size) {
size = 1;
} else {
size++;
}
valueOperations.set(areaKey, size);
}
}
if (isFind) {
log.error("----------------查询到滑撬: {}, 上车到平移车: {}-------------------", id, vehicleCode);
} else { } else {
size++; log.error("----------------未查询到滑撬: {}所在位置, 平移车为: {}--------------------------", id, vehicleCode);
}
} else {
//记录平移车车道位置
if (state == 1) {
String rfidLand = String.valueOf(uId.substring(17).trim());
vehicle.setLaneRfid(rfidLand);
String otherCode = getOtherVehicleCode(vehicleCode);
if (rfidList2.contains(vehicleCode)) {
vehicle = (Vehicle) valueOperations.get(Constant.VEHICLE_PREFIX + otherCode);
if (null == vehicle) {
vehicle = vehicleCache.get(otherCode, Vehicle.class);
}
vehicle.setLaneRfid(rfidLand);
valueOperations.set(Constant.VEHICLE_PREFIX + otherCode, vehicle);
return;
}
valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle);
// log.error("------平移车: {} 当前位于车道: {}", vehicleCode, rfidLand);
} }
valueOperations.set(areaKey, size);
} }
}
// // TODO: 2019-11-02 获得正反转信息,以及相邻的工位 private String getOtherVehicleCode(String vehicleCode) {
// Integer land = vehicle.getLane(); String otherCode = "01";
// //Set<String> keys = redisTemplate.keys(Constant.STATION_PREFIX + land + ":*"); switch (vehicleCode) {
// case "rfid51":
// List<PaintshopStation> arriveList = new ArrayList<>(); otherCode = "rfid72";
// break;
// List<PaintshopStation> stationList = laneStationCache.get(land.toString(), ArrayList.class); case "rfid52":
// for (PaintshopStation station : stationList) { otherCode = "rfid71";
// String code = station.getCode(); break;
// PaintshopStation sta = (PaintshopStation) valueOperations.get(Constant.STATION_PREFIX + code); case "rfid53":
// if (null == sta) { otherCode = "rfid73";
// sta = stationCache.get(code, PaintshopStation.class); break;
// } case "rfid54":
// if (null == sta.getArrive()) { otherCode = "rfid74";
// continue; break;
// } case "rfid72":
// if (sta.getArrive()) { otherCode = "rfid51";
// arriveList.add(sta); break;
// } case "rfid71":
// } otherCode = "rfid52";
// if (CollectionUtils.isEmpty(arriveList)) { break;
// log.error("找不到对平移车到位信号! 平移车 id:{},滑撬 {}", vehicle.getCode(), id); case "rfid73":
// return; otherCode = "rfid53";
// } break;
// case "rfid74":
// List<PaintshopStation> collect = arriveList.stream().filter(sta -> (sta.getTurnF() != null && sta.getTurnR() != null)).collect(Collectors.toList()); otherCode = "rfid54";
// Map<String, List<PaintshopStation>> listMap = collect.stream().collect(Collectors.groupingBy(PaintshopStation::getLandNo)); break;
// }
// PaintshopStation sourceStation = new PaintshopStation(); return otherCode;
// if (CollectionUtils.isEmpty(listMap)) {
// return;
// }
// 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 {
// PaintshopStation sta = stations.get(0);
// // if (state == 1 && (sta.getTurnR() && )){
// }
// }
// 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);
//
// //记录过站数及信息
// savePassInfo(today, currentDate, skid, sourceStation);
// } 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);
//
// //记录过站数及信息
// String areaCode = sourceStation.getAreaId().toString();
// String key = Constant.BUS_SIZE_IN + areaCode + ":" + today;
// Integer size = (Integer) valueOperations.get(key);
// if (null == size) {
// size = 0;
// } else {
// size++;
// }
// valueOperations.set(key, size);
//
// List<StationPassInfo> list = passInfoMapper.findList(new WhereFilter() {{
// addFilter("area_no", Operation.EQUAL, areaCode);
// addFilter("out_time", Operation.IS, "null");
// }}, StationPassInfo.class);
// if (CollectionUtils.isEmpty(list)) {
//
// }
// }
} }
} }
package net.vtstar.zhongtong.avi.mqtt.handle;
import com.alibaba.fastjson.JSONObject;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import net.vtstar.scada.base.mqtt.utils.MqttConstants;
import net.vtstar.utils.CollecUtils;
import net.vtstar.zhongtong.avi.equipment.domain.PaintshopStation;
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.Direction;
import net.vtstar.zhongtong.avi.monitoring.domain.enums.ProductionType;
import net.vtstar.zhongtong.avi.monitoring.domain.enums.StationState;
import net.vtstar.zhongtong.avi.monitoring.service.StationPassInfoService;
import net.vtstar.zhongtong.avi.utils.EquipDataUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.MessagingException;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;
@Slf4j
@Order(value = 99)
@Component
public class RfidMessageHandler1 extends AbstractTesterMessageHandler {
public static MQTTMessageBO messageBO = new MQTTMessageBO();
public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy:MM:dd");
public static List<String> rfidList1 = Arrays.asList("rfid51", "rfid52", "rfid53", "rfid54");
public static List<String> rfidList2 = Arrays.asList("rfid71", "rfid72", "rfid73", "rfid74");
//电泳换撬平移车
public static List<String> rfidList3 = Arrays.asList("rfid52", "rfid53", "rfid54");
public static List<String> stationList1 = Arrays.asList("HDG1-30", "HDG1-53", "HDG1-55", "HDG1-57", "HDG1-58", "HDG1-75");
//4车道换撬车道上撬
public static List<String> rfidList4 = Arrays.asList("rfid59", "rfid60", "rfid61", "rfid62", "rfid63", "rfid64");
public static List<String> stationList2 = Arrays.asList("HDG1-70", "HDG1-74", "HDG1-79", "HDG5-8", "HDG5-9");
@Resource(name = "redisTemplate")
private ListOperations listOperations;
@Resource(name = "redisTemplate")
private ValueOperations valueOperations;
@Resource(name = "laneStationCache")
private Cache laneStationCache;
@Resource(name = "stationCache")
private Cache stationCache;
@Resource(name = "vehicleCache")
private Cache vehicleCache;
@Resource(name = "webStationCache")
private Cache webStationCache;
@Resource(name = "laneRfidStationCache")
private Cache laneRfidStationCache;
@Autowired
private StationPassInfoService passInfoService;
@Autowired
private PaintshopStationMapper stationMapper;
@Resource(name = "redisTemplate")
protected ValueOperations testValueOperations;
public RfidMessageHandler1() {
super("translation", "data/all");
}
@Override
public void handleMessage(Message<?> message) throws MessagingException {
Date date = new Date();
Object payload = message.getPayload();
JSONObject json = JSONObject.parseObject(payload.toString());
//平移车扫到滑撬ID
String id = json.getString("TID");
if (StringUtil.isNullOrEmpty(id)) {
id = json.getString("ID");
}
String uId = json.getString("UID");
if (null != id && id.length() == 20) {
uId = id;
id = null;
}
//平移车扫描车道ID
Integer state = json.getIntValue("State");
if (StringUtil.isNullOrEmpty(id) && StringUtil.isNullOrEmpty(uId)) {
return;
}
MessageHeaders headers = message.getHeaders();
String vehicleCode = headers.get(MqttConstants.MSG_HEADER_KEY_EQUIPMENTNUMBER, String.class);
Vehicle vehicle = (Vehicle) valueOperations.get(Constant.VEHICLE_PREFIX + vehicleCode);
if (null == vehicle) {
vehicle = vehicleCache.get(vehicleCode, Vehicle.class);
}
if (!StringUtil.isNullOrEmpty(id)) {
if (id.length() == 30) {
id = id.substring(0, 29);
}
//针对电泳处有两个读写头的情况, 将两个读写头的情况都合并到小端的Vehicle上进行处理;
String otherCode = getOtherVehicleCode(vehicleCode);
if (rfidList2.contains(vehicleCode)) {
vehicle = (Vehicle) valueOperations.get(Constant.VEHICLE_PREFIX + otherCode);
if (null == vehicle) {
vehicle = vehicleCache.get(otherCode, Vehicle.class);
}
}
String today = dateFormat.format(date);
//存rfid log日志
messageBO.setID(id);
messageBO.setState(state);
String currentDate = format.format(date);
messageBO.setCreateDate(currentDate);
// log.info(vehicleCode + "______" + json.toJSONString() + " code:" + vehicleCode);
if (id.startsWith("A61A")) {
log.error("过滤掉乱发信息!:{},平移车:{}", id, vehicleCode);
return;
}
Skid skid = (Skid) valueOperations.get(Constant.SKID_PREFIX + id);
//平移车下车信息, 记录此时的下车时间
if (state == 0) {
//在rfid51,rfid52,rfid53,rfid54端上撬
if (rfidList1.contains(vehicleCode)) {
if (null == vehicle.getMqttCode()) {
//若state=0时, 还没有绑定上撬侧编号, 则说明上撬逻辑有问题
log.error("平移车: {}, state=0时, 没有绑定上撬侧编号", vehicleCode);
return;
} else if (vehicleCode.equals(vehicle.getMqttCode())) {
//若为上撬侧读写头发出的state=0, 全部屏蔽掉
return;
}
}
if (rfidList2.contains(vehicleCode)) {
if (null == vehicle.getMqttCode()) {
//若state=0时, 还没有绑定上撬侧编号, 则说明上撬逻辑有问题
log.error("平移车: {}, state=0时, 没有绑定上撬侧编号", vehicleCode);
return;
} else if (vehicleCode.equals(vehicle.getMqttCode())) {
//若为上撬侧读写头发出的state=0, 全部屏蔽掉
return;
} else {
//若为另一侧读写头发出的state=0, 则认为是下车信号;
vehicleCode = otherCode;
}
}
if (null == skid) {
//因上车必定会绑定一次skid, 所以若skid为null, 则记录为异常情况
// log.error("----------平移车: {}下车, 但是未查询到滑撬信息, ID为: {}---------------", vehicleCode, id);
return;
}
vehicle.setState(false);
vehicle.setCurrentRfid(id);
vehicle.setSkid(skid);
vehicle.setDownTime(date);
vehicle.setDownTimeMin(0);
valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle);
return;
}
if (state != 1) {
log.error("mqtt接收到的state不为0也不为1!!!");
return;
}
String rfid = vehicle.getCurrentRfid();
//若当前平移车上绑定了RFID, 并且与当前mqtt信息中的ID一致, 并且state=1, 则认为这是读写头的重发现象
if (null != rfid && id.equals(rfid)) {
Date occurTime = vehicle.getOccurTime();
if (null != occurTime) {
long l = (date.getTime() - occurTime.getTime()) / 1000;
if (l < 5) {
//log.error("{} 平移车发生重发现象 ,滑撬id {}", vehicleCode, id);
vehicle.setOccurTime(date);
if (rfidList2.contains(vehicleCode)) {
valueOperations.set(Constant.VEHICLE_PREFIX + otherCode, vehicle);
} else {
valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle);
}
return;
}
}
}
//判断是否为返修
Object reWorkVehicle = valueOperations.get(Constant.VEHICLE_PREFIX_REWORK);
if (null != reWorkVehicle && !"".equals(reWorkVehicle.toString())) {
if (vehicleCode.equals(reWorkVehicle.toString())) {
//记录返修上车的信息
listOperations.rightPush("rfid:log:fanxiu:" + vehicleCode, messageBO);
String busNo = (String) valueOperations.get(Constant.VEHICLE_PREFIX_REWORK_BUSNO);
if (null == skid) {
skid = new Skid();
skid.setRfid(id);
}
skid.setBusNo(busNo);
skid.setWorkOrderNo(null);
skid.setBusType(ProductionType.OTHER);
valueOperations.set(Constant.SKID_PREFIX + id, skid);
valueOperations.set(Constant.VEHICLE_PREFIX_REWORK, "");
valueOperations.set(Constant.VEHICLE_PREFIX_REWORK_BUSNO, "");
passInfoService.createPassInfo(skid.getWorkOrderNo(), skid.getRfid(), "返修上线", "");
return;
}
}
//若是焊装车间进车,绑定滑撬与车身关系
if ((vehicleCode.equals(Constant.HANZHUANG_VEHICLE1_RFID) || vehicleCode.equals(Constant.HANZHUANG_VEHICLE2_RFID))) {
//记录焊装上车的信息
listOperations.rightPush("rfid:log:shangqiao:" + vehicleCode, messageBO);
String format = dateFormat.format(date);
String key = Constant.BUS_SIZE_IN + "0:" + format;
Integer size = (Integer) valueOperations.get(key);
if (null == size) {
size = 1;
} else {
size++;
}
valueOperations.set(key, size);
String keyW = EquipDataUtil.getTestValueKey(Constant.ROTARY_ROLLER_BED_W);
testValueOperations.set(keyW, null == testValueOperations.get(keyW) ? 0 : ((int) testValueOperations.get(keyW)) + 1);
String busNo = (String) valueOperations.get(Constant.HANZHUANG_VEHICLE_BUSNO_KEY + vehicleCode);
String workOrderNo = (String) valueOperations.get(Constant.HANZHUANG_VEHICLE_WORKNO_KEY + vehicleCode);
if (StringUtil.isNullOrEmpty(busNo)) {
log.error("未录入PDA车身号! :" + vehicleCode);
return;
}
if (null == skid) {
skid = new Skid();
skid.setRfid(id);
}
skid.setBusNo(busNo);
skid.setWorkOrderNo(workOrderNo);
skid.setBusType(ProductionType.OWN);
valueOperations.set(Constant.SKID_PREFIX + id, skid);
valueOperations.set(Constant.HANZHUANG_VEHICLE_BUSNO_KEY + vehicleCode, "");
valueOperations.set(Constant.HANZHUANG_VEHICLE_WORKNO_KEY + vehicleCode, "");
passInfoService.createPassInfo(skid.getWorkOrderNo(), skid.getRfid(), "涂装上线", "HXG1-1");
return;
}
//底盘读写头
if (vehicleCode.equals(Constant.TUZHUANG_VEHICLE4_RFID)) {
String keyW = EquipDataUtil.getTestValueKey(Constant.ROTARY_ROLLER_BED_C);
testValueOperations.set(keyW, null == testValueOperations.get(keyW) ? 0 : ((int) testValueOperations.get(keyW)) + 1);
}
//判断是否为轻客上车
if (vehicleCode.equals(Constant.TUZHUANG_VEHICLE2_RFID)) {
//判断此时rfid51上是否绑定了滑撬, 若已绑定, 则说明是从电泳方向上车, 若未绑定, 则说明是属于轻客上车
if (null != vehicle && null == vehicle.getMqttCode()) {
if (null == skid) {
skid = new Skid();
skid.setRfid(id);
}
skid.setBusType(ProductionType.OTHER);
valueOperations.set(Constant.SKID_PREFIX + id, skid);
passInfoService.createPassInfo(skid.getWorkOrderNo(), skid.getRfid(), "轻客上线", "");
listOperations.rightPush("rfid:log:qingke:" + vehicleCode, messageBO);
}
//此时为在电泳一侧上车, 并且停到了第二个读写头的位置, 和其他两个读写头的平移车相同处理方式
}
//若为涂装末工位, 记录出涂装交车数量
if (vehicleCode.equals(Constant.TUZHUANG_VEHICLE3_RFID)) {
String keyW = EquipDataUtil.getTestValueKey(Constant.ROTARY_ROLLER_BED_P2);
testValueOperations.set(keyW, null == testValueOperations.get(keyW) ? 0 : ((int) testValueOperations.get(keyW)) + 1);
String areaKey = Constant.BUS_SIZE_OUT + "0:" + today;
Integer size = (Integer) valueOperations.get(areaKey);
if (null == size) {
size = 1;
} else {
size++;
}
valueOperations.set(areaKey, size);
if (null != skid) {
passInfoService.createPassInfo(skid.getWorkOrderNo(), skid.getRfid(), "涂装下线", "HXG2-1");
}
listOperations.rightPush("rfid:log:chuche:" + vehicleCode, messageBO);
return;
}
//todo: 因PDA未使用, 暂不做此逻辑判断
if (null == skid) {
// log.error("查询到未在Redis中的滑撬信息!vehicleCode: {}, ID: {} :", vehicleCode, id);
//todo:
// return;
skid = new Skid();
skid.setRfid(id);
skid.setBusNo("");
skid.setWorkOrderNo("");
skid.setBusType(ProductionType.OWN);
valueOperations.set(Constant.SKID_PREFIX + id, skid);
}
log.error("扫描到滑撬:" + skid.getRfid() + "读写头: " + vehicleCode);
//处理是否为2车道换撬
if (rfidList3.contains(vehicleCode) && null == vehicle.getMqttCode()) {
//若mqttCode为null, 则说明为小端上撬
List<PaintshopStation> stations = laneRfidStationCache.get(vehicle.getLaneRfid(), ArrayList.class);
if (CollecUtils.isEmpty(stations)) {
return;
}
for (PaintshopStation station : stations) {
//只判断换撬区的工位
if (stationList1.contains(station.getCode())) {
List<PaintshopStation> temStation = laneStationCache.get(station.getLaneId(), ArrayList.class);
temStation.sort((s1, s2) -> s2.getSequence().compareTo(s1.getSequence()));
for (PaintshopStation item : temStation) {
PaintshopStation s = (PaintshopStation) valueOperations.get(Constant.STATION_PREFIX + item.getCode());
if (null == s.getSkid() && null != s.getWorkOrderNo()) {
skid.setWorkOrderNo(s.getWorkOrderNo());
skid.setBusNo(s.getBusNo());
skid.setBusType(s.getBusType());
valueOperations.set(Constant.SKID_PREFIX + id, skid);
//将工位上的工单信息绑定到滑撬上, 再将滑撬绑定到工位上
s.setSkid(skid);
s.setWorkOrderNo(null);
s.setBusNo(null);
valueOperations.set(Constant.STATION_PREFIX + item.getCode(), s);
break;
}
}
}
}
}
//处理是否为4车道换撬
if (rfidList4.contains(vehicleCode)) {
List<PaintshopStation> stations = laneRfidStationCache.get(vehicle.getLaneRfid(), ArrayList.class);
if (CollecUtils.isEmpty(stations)) {
return;
}
for (PaintshopStation station : stations) {
//TODO: 上线时东侧工位有影响
if (Direction.WEST.equals(station.getDirection()) && stationList2.contains(station.getCode())) {
List<PaintshopStation> temStation = laneStationCache.get(station.getLaneId(), ArrayList.class);
temStation.sort(Comparator.comparing(v -> v.getSequence()));
for (PaintshopStation item : temStation) {
PaintshopStation s = (PaintshopStation) valueOperations.get(Constant.STATION_PREFIX + item.getCode());
if (null == s.getSkid() && null != s.getWorkOrderNo()) {
skid.setWorkOrderNo(s.getWorkOrderNo());
skid.setBusNo(s.getBusNo());
skid.setBusType(s.getBusType());
valueOperations.set(Constant.SKID_PREFIX + id, skid);
//将工位上的工单信息绑定到滑撬上, 再将滑撬绑定到工位上
s.setSkid(skid);
s.setWorkOrderNo(null);
s.setBusNo(null);
valueOperations.set(Constant.STATION_PREFIX + item.getCode(), s);
break;
}
}
}
}
}
//在rfid51,rfid52,rfid53,rfid54端上撬
if (rfidList1.contains(vehicleCode)) {
if (null == vehicle.getMqttCode()) {
if (null != vehicle.getTurnR() && vehicle.getTurnR()) {
//若在小端扫rfid, 但是此时平移车正在反转, 说明此时平移车正在下车, 且上车时未扫到rfid
if (null == skid) {
return;
}
log.error("----------平移车: {}下车信号, 漏读下车, 滑撬信息ID为: {}---------------", vehicleCode, id);
vehicle.setState(false);
vehicle.setCurrentRfid(id);
vehicle.setSkid(skid);
vehicle.setDownTime(date);
vehicle.setDownTimeMin(0);
valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle);
return;
}
//若没有绑定平移车在哪侧上撬, 说明此时平移车刚刚在此侧上撬, 除了绑定上撬侧之外, 和正常上撬没有区别;
vehicle.setMqttCode(vehicleCode);
log.error("------------平移车在小端上撬, 平移车:{}---------", vehicleCode);
} else if (vehicleCode.equals(vehicle.getMqttCode())) {
//因为已经过滤过重发现象, 说明此时平移车上撬已经过去了10秒, 此时再有state=1的情况, 说明在此侧上车且在此侧下车;
if (null == skid) {
//因上车必定会绑定一次skid, 所以若skid为null, 则记录为异常情况
log.error("----------平移车: {}上车, 但是未查询到滑撬信息, ID为: {}---------------", vehicleCode, id);
return;
}
log.error("----------平移车: {}下车信号, 同侧下车, 滑撬信息ID为: {}---------------", vehicleCode, id);
vehicle.setState(false);
vehicle.setCurrentRfid(id);
vehicle.setSkid(skid);
vehicle.setDownTime(date);
vehicle.setDownTimeMin(0);
valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle);
return;
} else {
//上撬侧不为空, 且上撬侧不为小端, 则说明是在另外一侧上的车, 此时只改变平移车的上车时间
vehicle.setOccurTime(date);
valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle);
return;
}
}
//在rfid71,rfid72,rfid73,rfid74端上撬
if (rfidList2.contains(vehicleCode)) {
if (null == vehicle.getMqttCode()) {
if (null != vehicle.getTurnF() && vehicle.getTurnF()) {
//若在大端扫rfid, 但是此时平移车正在正转, 说明此时平移车正在下车, 且上车时未扫到rfid
if (null == skid) {
return;
}
log.error("----------平移车: {}下车信号, 漏读下车, 滑撬信息ID为: {}---------------", vehicleCode, id);
vehicle.setState(false);
vehicle.setCurrentRfid(id);
vehicle.setSkid(skid);
vehicle.setDownTime(date);
vehicle.setDownTimeMin(0);
valueOperations.set(Constant.VEHICLE_PREFIX + otherCode, vehicle);
return;
}
//首先判断当前小端代表的平移车是否绑定了上撬端, 若没有, 则说明是在大端上撬, 此时将大端code绑定到平移车上, 并记录上车时间等到小端代表平移车上;
vehicle.setMqttCode(vehicleCode);
vehicleCode = otherCode;
} else if (vehicleCode.equals(vehicle.getMqttCode())) {
//此时小端平移车上已绑定了上撬端, 并且是在大端上撬, 那么此时state=1的情况, 则需要判断上撬时间是否大于10秒, 若不大于则为重发现象, 若大于则代表在大端侧进行下车;
if (null == skid) {
//因上车必定会绑定一次skid, 所以若skid为null, 则记录为异常情况
log.error("----------平移车: {}上车, 但是未查询到滑撬信息, ID为: {}---------------", vehicleCode, id);
return;
}
vehicle.setState(false);
vehicle.setCurrentRfid(id);
vehicle.setSkid(skid);
vehicle.setDownTime(date);
vehicle.setDownTimeMin(0);
valueOperations.set(Constant.VEHICLE_PREFIX + otherCode, vehicle);
return;
} else {
//此时小端平移车已经绑定了滑撬, 并且在小端上撬, 那么此时state=1的情况, 则只改变平移车的上车时间
vehicle.setOccurTime(date);
valueOperations.set(Constant.VEHICLE_PREFIX + otherCode, vehicle);
return;
}
}
//平移车上车信息
listOperations.rightPush("rfid:log:" + vehicleCode, messageBO);
//平移车上车
vehicle.setState(true);
vehicle.setOccurTime(date);
vehicle.setDownTime(null);
vehicle.setDownTimeMin(0);
vehicle.setCurrentRfid(id);
vehicle.setSkid(skid);
//若为涂装首工位上车, 且为焊装刚刚过来的, 此时无法从工位列表中找到滑撬信息, 所以单独处理
if (vehicleCode.equals(Constant.TUZHUANG_VEHICLE1_RFID) && Constant.TUZHUANG_LANE1_RFID.equals(vehicle.getLaneRfid())) {
valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle);
String keyW = EquipDataUtil.getTestValueKey(Constant.ROTARY_ROLLER_BED_P1);
testValueOperations.set(keyW, null == testValueOperations.get(keyW) ? 0 : ((int) testValueOperations.get(keyW)) + 1);
return;
}
//根据平移车所在车道RFID编号查询车道两边的工位
List<PaintshopStation> stations = laneRfidStationCache.get(vehicle.getLaneRfid(), ArrayList.class);
if (CollecUtils.isEmpty(stations)) {
return;
}
boolean isFind = false;
//首先在平移车所在车道两边工位查询
for (PaintshopStation value : stations) {
List<PaintshopStation> lands = new ArrayList<>();
List<PaintshopStation> temStation = laneStationCache.get(value.getLaneId(), ArrayList.class);
for (PaintshopStation land : temStation) {
PaintshopStation s = (PaintshopStation) valueOperations.get(Constant.STATION_PREFIX + land.getCode());
lands.add(s);
}
for (PaintshopStation land : lands) {
if (land.getSkid() != null && id.equals(land.getSkid().getRfid())) {
passInfoService.endPassInfo(land);
isFind = true;
land.setSkid(null);
land.setState(StationState.FREE);
}
}
if (isFind) {
//记录过站数量
String areaCode = value.getAreaId().toString();
String areaKey = Constant.BUS_SIZE_OUT + areaCode + ":" + today;
Integer size = (Integer) valueOperations.get(areaKey);
if (null == size) {
size = 1;
} else {
size++;
}
valueOperations.set(areaKey, size);
for (PaintshopStation land : lands) {
valueOperations.set(Constant.STATION_PREFIX + land.getCode(), land);
}
valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle);
}
}
//若在平移车两侧未找到此滑撬, 则在所有工位中查找
List<PaintshopStation> stationByCache = stationCache.get("ALL", ArrayList.class);
if (CollecUtils.isEmpty(stationByCache)) {
return;
}
for (PaintshopStation station : stationByCache) {
PaintshopStation land = (PaintshopStation) valueOperations.get(Constant.STATION_PREFIX + station.getCode());
if (land.getSkid() != null && id.equals(land.getSkid().getRfid())) {
passInfoService.endPassInfo(land);
land.setSkid(null);
land.setState(StationState.FREE);
isFind = true;
valueOperations.set(Constant.STATION_PREFIX + land.getCode(), land);
valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle);
//记录过站数量
String areaCode = land.getAreaId().toString();
String areaKey = Constant.BUS_SIZE_OUT + areaCode + ":" + today;
Integer size = (Integer) valueOperations.get(areaKey);
if (null == size) {
size = 1;
} else {
size++;
}
valueOperations.set(areaKey, size);
}
}
if (isFind) {
log.error("----------------查询到滑撬: {}, 上车到平移车: {}-------------------", id, vehicleCode);
} else {
log.error("----------------未查询到滑撬: {}所在位置, 平移车为: {}--------------------------", id, vehicleCode);
}
} else {
//记录平移车车道位置
if (state == 1) {
String rfidLand = String.valueOf(uId.substring(17).trim());
vehicle.setLaneRfid(rfidLand);
String otherCode = getOtherVehicleCode(vehicleCode);
if (rfidList2.contains(vehicleCode)) {
vehicle = (Vehicle) valueOperations.get(Constant.VEHICLE_PREFIX + otherCode);
if (null == vehicle) {
vehicle = vehicleCache.get(otherCode, Vehicle.class);
}
vehicle.setLaneRfid(rfidLand);
valueOperations.set(Constant.VEHICLE_PREFIX + otherCode, vehicle);
return;
}
valueOperations.set(Constant.VEHICLE_PREFIX + vehicleCode, vehicle);
// log.error("------平移车: {} 当前位于车道: {}", vehicleCode, rfidLand);
}
}
}
private String getOtherVehicleCode(String vehicleCode) {
String otherCode = "01";
switch (vehicleCode) {
case "rfid51":
otherCode = "rfid72";
break;
case "rfid52":
otherCode = "rfid71";
break;
case "rfid53":
otherCode = "rfid73";
break;
case "rfid54":
otherCode = "rfid74";
break;
case "rfid72":
otherCode = "rfid51";
break;
case "rfid71":
otherCode = "rfid52";
break;
case "rfid73":
otherCode = "rfid53";
break;
case "rfid74":
otherCode = "rfid54";
break;
}
return otherCode;
}
}
...@@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
import net.vtstar.user.mybatis.provider.Operation; import net.vtstar.user.mybatis.provider.Operation;
import net.vtstar.user.mybatis.provider.WhereFilter; import net.vtstar.user.mybatis.provider.WhereFilter;
import net.vtstar.utils.DateUtils; import net.vtstar.utils.DateUtils;
import net.vtstar.zhongtong.avi.equipment.service.EquipStatusRealTimeService;
import net.vtstar.zhongtong.avi.sqlserver.domain.AssemblyTorqueWrench; import net.vtstar.zhongtong.avi.sqlserver.domain.AssemblyTorqueWrench;
import net.vtstar.zhongtong.avi.sqlserver.mapper.AssemblyTorqueWrenchMapper; import net.vtstar.zhongtong.avi.sqlserver.mapper.AssemblyTorqueWrenchMapper;
import net.vtstar.zhongtong.avi.utils.PingIpUtils; import net.vtstar.zhongtong.avi.utils.PingIpUtils;
...@@ -37,6 +38,9 @@ public class AssemblyTorqueWrenchJob extends QuartzJobBean { ...@@ -37,6 +38,9 @@ public class AssemblyTorqueWrenchJob extends QuartzJobBean {
@Autowired @Autowired
private AssemblyTorqueWrenchMapper assemblyTorqueWrenchMapper; private AssemblyTorqueWrenchMapper assemblyTorqueWrenchMapper;
@Autowired
private EquipStatusRealTimeService realTimeService;
@Value("${zt.ip.assemblytorquewrench}") @Value("${zt.ip.assemblytorquewrench}")
private String ipAddress; private String ipAddress;
@Value("${zt.ip.pingtimes}") @Value("${zt.ip.pingtimes}")
...@@ -48,8 +52,10 @@ public class AssemblyTorqueWrenchJob extends QuartzJobBean { ...@@ -48,8 +52,10 @@ public class AssemblyTorqueWrenchJob extends QuartzJobBean {
protected void executeInternal(JobExecutionContext context) throws JobExecutionException { protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
if (!PingIpUtils.ping(ipAddress, pingTimes, timeOut)){ if (!PingIpUtils.ping(ipAddress, pingTimes, timeOut)){
log.error("ping: {}失败, 此次同步总装车间智能扭力扳手数据操作结束!", ipAddress); log.error("ping: {}失败, 此次同步总装车间智能扭力扳手数据操作结束!", ipAddress);
realTimeService.saveEquip("总装车间", "", "智能扭力扳手", "关机");
return; return;
} }
realTimeService.saveEquip("总装车间", "", "智能扭力扳手", "开机");
log.info("--------开始同步总装车间智能扭力扳手数据--------"); log.info("--------开始同步总装车间智能扭力扳手数据--------");
Date startOfDay = DateUtils.getStartOfDay(0); Date startOfDay = DateUtils.getStartOfDay(0);
String dateString = DateUtils.parseDateToString(startOfDay, "yyyy-MM-dd HH:mm:ss"); String dateString = DateUtils.parseDateToString(startOfDay, "yyyy-MM-dd HH:mm:ss");
......
...@@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
import net.vtstar.user.mybatis.provider.Operation; import net.vtstar.user.mybatis.provider.Operation;
import net.vtstar.user.mybatis.provider.WhereFilter; import net.vtstar.user.mybatis.provider.WhereFilter;
import net.vtstar.utils.DateUtils; import net.vtstar.utils.DateUtils;
import net.vtstar.zhongtong.avi.equipment.service.EquipStatusRealTimeService;
import net.vtstar.zhongtong.avi.sqlserver.domain.TestLineResult; import net.vtstar.zhongtong.avi.sqlserver.domain.TestLineResult;
import net.vtstar.zhongtong.avi.sqlserver.mapper.TestLineResultMapper; import net.vtstar.zhongtong.avi.sqlserver.mapper.TestLineResultMapper;
import net.vtstar.zhongtong.avi.utils.PingIpUtils; import net.vtstar.zhongtong.avi.utils.PingIpUtils;
...@@ -35,6 +36,9 @@ public class TestLineResultJob extends QuartzJobBean { ...@@ -35,6 +36,9 @@ public class TestLineResultJob extends QuartzJobBean {
@Autowired @Autowired
private TestLineResultMapper testLineResultMapper; private TestLineResultMapper testLineResultMapper;
@Autowired
private EquipStatusRealTimeService realTimeService;
@Value("${zt.ip.testlineresult}") @Value("${zt.ip.testlineresult}")
private String ipAddress; private String ipAddress;
@Value("${zt.ip.pingtimes}") @Value("${zt.ip.pingtimes}")
...@@ -46,8 +50,10 @@ public class TestLineResultJob extends QuartzJobBean { ...@@ -46,8 +50,10 @@ public class TestLineResultJob extends QuartzJobBean {
protected void executeInternal(JobExecutionContext context) throws JobExecutionException { protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
if (!PingIpUtils.ping(ipAddress, pingTimes, timeOut)){ if (!PingIpUtils.ping(ipAddress, pingTimes, timeOut)){
log.error("ping: {}失败, 此次同步试交车间检测线数据操作结束!", ipAddress); log.error("ping: {}失败, 此次同步试交车间检测线数据操作结束!", ipAddress);
realTimeService.saveEquip("质量管理部", "769000-04", "检测线", "关机");
return; return;
} }
realTimeService.saveEquip("质量管理部", "769000-04", "检测线", "开机");
log.info("--------开始同步试交车间检测线数据--------"); log.info("--------开始同步试交车间检测线数据--------");
Date startOfDay = DateUtils.getStartOfDay(0); Date startOfDay = DateUtils.getStartOfDay(0);
String dateString = DateUtils.parseDateToString(startOfDay, "yyyy-MM-dd HH:mm:ss"); String dateString = DateUtils.parseDateToString(startOfDay, "yyyy-MM-dd HH:mm:ss");
......
...@@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
import net.vtstar.user.mybatis.provider.Operation; import net.vtstar.user.mybatis.provider.Operation;
import net.vtstar.user.mybatis.provider.WhereFilter; import net.vtstar.user.mybatis.provider.WhereFilter;
import net.vtstar.utils.DateUtils; import net.vtstar.utils.DateUtils;
import net.vtstar.zhongtong.avi.equipment.service.EquipStatusRealTimeService;
import net.vtstar.zhongtong.avi.sqlserver.domain.TestSpeedResult; import net.vtstar.zhongtong.avi.sqlserver.domain.TestSpeedResult;
import net.vtstar.zhongtong.avi.sqlserver.mapper.TestSpeedMapper; import net.vtstar.zhongtong.avi.sqlserver.mapper.TestSpeedMapper;
import net.vtstar.zhongtong.avi.utils.PingIpUtils; import net.vtstar.zhongtong.avi.utils.PingIpUtils;
...@@ -35,6 +36,9 @@ public class TestSpeedResultJob extends QuartzJobBean { ...@@ -35,6 +36,9 @@ public class TestSpeedResultJob extends QuartzJobBean {
@Autowired @Autowired
private TestSpeedMapper testSpeedMapper; private TestSpeedMapper testSpeedMapper;
@Autowired
private EquipStatusRealTimeService realTimeService;
@Value("${zt.ip.testspeedresult}") @Value("${zt.ip.testspeedresult}")
private String ipAddress; private String ipAddress;
@Value("${zt.ip.pingtimes}") @Value("${zt.ip.pingtimes}")
...@@ -46,8 +50,10 @@ public class TestSpeedResultJob extends QuartzJobBean { ...@@ -46,8 +50,10 @@ public class TestSpeedResultJob extends QuartzJobBean {
protected void executeInternal(JobExecutionContext context) throws JobExecutionException { protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
if (!PingIpUtils.ping(ipAddress, pingTimes, timeOut)){ if (!PingIpUtils.ping(ipAddress, pingTimes, timeOut)){
log.error("ping: {}失败, 此次同步试交车间限速值数据操作结束!", ipAddress); log.error("ping: {}失败, 此次同步试交车间限速值数据操作结束!", ipAddress);
realTimeService.saveEquip("质量管理部", "", "限速值", "关机");
return; return;
} }
realTimeService.saveEquip("质量管理部", "", "限速值", "开机");
log.info("--------开始同步试交车间限速值数据--------"); log.info("--------开始同步试交车间限速值数据--------");
Date startOfDay = DateUtils.getStartOfDay(0); Date startOfDay = DateUtils.getStartOfDay(0);
String dateString = DateUtils.parseDateToString(startOfDay, "yyyy-MM-dd HH:mm:ss"); String dateString = DateUtils.parseDateToString(startOfDay, "yyyy-MM-dd HH:mm:ss");
......
package net.vtstar.zhongtong.avi.utils;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.*;
/**
* @Author: xiadongwei
* @Date: 2019/8/28 11:03
*/
public class ExpertUtils {
private static String tempFileHomePath = "D:/vtstar/template/";
public static void main(String[] arg){
exportExcel();
}
/**
* 生成excel并下载
*/
public static void exportExcel(){
File newFile = createNewFile();
//File newFile = new File("d:/ss.xls");
//新文件写入数据,并下载*****************************************************
InputStream is = null;
XSSFWorkbook workbook = null;
XSSFSheet sheet = null;
try {
is = new FileInputStream(newFile);
workbook = new XSSFWorkbook(is);
//获取第一个sheet
sheet = workbook.getSheetAt(0);
} catch (Exception e1) {
e1.printStackTrace();
}
if(sheet != null){
try {
//写数据
FileOutputStream fos = new FileOutputStream(newFile);
XSSFRow row = sheet.getRow(4);
XSSFCell cell = row.getCell(1);
System.out.println(cell.getStringCellValue());
cell.setCellValue("ssssssssssssssssssssssssssssssssssssssssssss");
workbook.write(fos);
fos.flush();
fos.close();
//下载
/*InputStream fis = new BufferedInputStream(new FileInputStream(newFile));
HttpServletResponse response = this.getResponse();
byte[] buffer = new byte[fis.available()];
fis.read(buffer);
fis.close();
response.reset();
response.setContentType("text/html;charset=UTF-8");
OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
response.setContentType("application/x-msdownload");
String newName = URLEncoder.encode("采购合同"+System.currentTimeMillis()+".xls", "UTF-8");
response.addHeader("Content-Disposition", "attachment;filename=\""+ newName + "\"");
response.addHeader("Content-Length", "" + newFile.length());
toClient.write(buffer);
toClient.flush();*/
}
catch(Exception e) {
e.printStackTrace();
}finally {
try {
if (null != is) {
is.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
//删除创建的新文件
//this.deleteFile(newFile);
}
/**
* 复制文件
*
* @param s
* 源文件
* @param t
* 复制到的新文件
*/
public static void fileChannelCopy(File s, File t) {
try {
InputStream in = null;
OutputStream out = null;
try {
in = new BufferedInputStream(new FileInputStream(s),1024);
out = new BufferedOutputStream(new FileOutputStream(t),1024);
byte[] buffer = new byte[1024];
int len;
while ((len=in.read(buffer))!=-1) {
out.write(buffer,0,len);
}
} finally {
if (null != in) {
in.close();
}
if (null != out) {
out.close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 读取excel模板,并复制到新文件中供写入和下载
* @return
*/
public static File createNewFile(){
//读取模板,并赋值到新文件************************************************************
//文件模板路径
String fileName = "向阳生产计划模板";
File file = new File(tempFileHomePath, fileName + ".xls");
//新的文件名
String newFileName = "日常检测报告" + System.currentTimeMillis() + ".xls";
//写入到新的excel
File newFile = new File(tempFileHomePath, newFileName);
try {
newFile.createNewFile();
//复制模板到新文件
fileChannelCopy(file, newFile);
} catch (Exception e) {
e.printStackTrace();
}
return newFile;
}
/**
* 下载成功后删除
*
* @param files
*/
private void deleteFile(File... files) {
for (File file : files) {
if (file.exists()) {
file.delete();
}
}
}
}
package net.vtstar.zhongtong.avi.utils;
import java.io.File;
/**
* @Author: xiadongwei
* @Date: 2019/10/20 18:56
*/
public class PrintDemo {
public static boolean printOfficeFile(File f) {
return true;
/*if (f != null && f.exists()) {
String fileNameString = f.getName();
String postfixString = Utils.getPostfix(fileNameString);
if (postfixString.equalsIgnoreCase("xls") || postfixString.equalsIgnoreCase("xlsx")) {
*//**
* 功能:实现excel打印工作
*//*
ComThread.InitSTA();
ActiveXComponent xl = new ActiveXComponent("Excel.Application");
try {
// System.out.println("version=" +
// xl.getProperty("Version"));
// 不打开文档
Dispatch.put(xl, "Visible", new Variant(false));
Dispatch workbooks = xl.getProperty("Workbooks").toDispatch();
// 打开文档
Dispatch excel = Dispatch.call(workbooks, "Open", f.getAbsolutePath()).toDispatch();
// 横向打印(2013/05/24)
// Dispatch currentSheet = Dispatch.get(excel,
// "ActiveSheet")
// .toDispatch();
// Dispatch pageSetup = Dispatch
// .get(currentSheet, "PageSetup").toDispatch();
// Dispatch.put(pageSetup, "Orientation", new Variant(2));
// 每张表都横向打印2013-10-31
Dispatch sheets = Dispatch.get((Dispatch) excel, "Sheets").toDispatch();
// 获得几个sheet
int count = Dispatch.get(sheets, "Count").getInt();
// System.out.println(count);
for (int j = 1; j <= count; j++) {
Dispatch sheet = Dispatch
.invoke(sheets, "Item", Dispatch.Get, new Object[] { new Integer(j) }, new int[1])
.toDispatch();
Dispatch pageSetup = Dispatch.get(sheet, "PageSetup").toDispatch();
Dispatch.put(pageSetup, "Orientation", new Variant(2));
Dispatch.call(sheet, "PrintOut");
}
// 开始打印
if (excel != null) {
// Dispatch.call(excel, "PrintOut");
// 增加以下三行代码解决文件无法删除bug
Dispatch.call(excel, "save");
Dispatch.call(excel, "Close", new Variant(true));
excel = null;
}
xl.invoke("Quit", new Variant[] {});
xl = null;
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
// 始终释放资源
ComThread.Release();
}
} else if (postfixString.equalsIgnoreCase("doc") || postfixString.equalsIgnoreCase("docx")) {
ComThread.InitSTA();
ActiveXComponent wd = new ActiveXComponent("Word.Application");
try {
// 不打开文档
Dispatch.put(wd, "Visible", new Variant(false));
Dispatch document = wd.getProperty("Documents").toDispatch();
// 打开文档
Dispatch doc = Dispatch
.invoke(document, "Open", Dispatch.Method, new Object[] { f.getAbsolutePath() }, new int[1])
.toDispatch();
// 开始打印
if (doc != null) {
Dispatch.call(doc, "PrintOut");
// 增加以下三行代码解决文件无法删除bug
Dispatch.call(doc, "save");
Dispatch.call(doc, "Close", new Variant(true));
doc = null;
}
wd.invoke("Quit", new Variant[] {});
wd = null;
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
// 始终释放资源
ComThread.Release();
}
} else {
return false;
}
} else {
return false;
}*/
}
public static void main(String[] args) {
PrintDemo.printOfficeFile(new File("hehe.xls"));
}
}
...@@ -31,8 +31,8 @@ quartz.job.taskInfos[1].jobName=net.vtstar.zhongtong.avi.equipment.job.CleanStat ...@@ -31,8 +31,8 @@ quartz.job.taskInfos[1].jobName=net.vtstar.zhongtong.avi.equipment.job.CleanStat
quartz.job.taskInfos[1].jobGroup=CleanStatusDataJob quartz.job.taskInfos[1].jobGroup=CleanStatusDataJob
quartz.job.taskInfos[1].jobDescription=\u6E05\u6D17\u8BBE\u5907\u72B6\u6001Job 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 0 0 * * ?
quartz.job.taskInfos[1].cronExpression=0 0/5 * * * ? quartz.job.taskInfos[1].cronExpression=0/10 * * * * ?
quartz.job.taskInfos[1].start=false quartz.job.taskInfos[1].start=true
quartz.job.taskInfos[2].jobName=net.vtstar.zhongtong.avi.equipment.job.StatisticsTimeJob quartz.job.taskInfos[2].jobName=net.vtstar.zhongtong.avi.equipment.job.StatisticsTimeJob
quartz.job.taskInfos[2].jobGroup=StatisticsTimeJob quartz.job.taskInfos[2].jobGroup=StatisticsTimeJob
...@@ -117,8 +117,8 @@ quartz.job.taskInfos[12].start=false ...@@ -117,8 +117,8 @@ quartz.job.taskInfos[12].start=false
quartz.job.taskInfos[13].jobName=net.vtstar.zhongtong.avi.gateway.painting.job.SprayBoothStateMachineJob quartz.job.taskInfos[13].jobName=net.vtstar.zhongtong.avi.gateway.painting.job.SprayBoothStateMachineJob
quartz.job.taskInfos[13].jobGroup=SprayBoothStateMachineJob quartz.job.taskInfos[13].jobGroup=SprayBoothStateMachineJob
quartz.job.taskInfos[13].jobDescription=\u6d82\u88c5\u55b7\u6d82\u5ba4Job quartz.job.taskInfos[13].jobDescription=\u6d82\u88c5\u55b7\u6d82\u5ba4Job
quartz.job.taskInfos[13].cronExpression=0 0/5 * * * ? quartz.job.taskInfos[13].cronExpression=0/15 * * * * ?
quartz.job.taskInfos[13].start=false quartz.job.taskInfos[13].start=true
#烘干室 #烘干室
quartz.job.taskInfos[14].jobName=net.vtstar.zhongtong.avi.gateway.painting.job.DryingRoomTempMachineJob quartz.job.taskInfos[14].jobName=net.vtstar.zhongtong.avi.gateway.painting.job.DryingRoomTempMachineJob
...@@ -278,8 +278,8 @@ quartz.job.taskInfos[35].cronExpression=0 0/1 * * * ? ...@@ -278,8 +278,8 @@ quartz.job.taskInfos[35].cronExpression=0 0/1 * * * ?
quartz.job.taskInfos[35].start=false quartz.job.taskInfos[35].start=false
#AVI plc 采集 #AVI plc 采集
quartz.job.taskInfos[36].jobName=net.vtstar.zhongtong.avi.monitoring.job.AVIMonitorJob1 quartz.job.taskInfos[36].jobName=net.vtstar.zhongtong.avi.monitoring.job.AVIMonitorJob
quartz.job.taskInfos[36].jobGroup=AVIMonitorJob1 quartz.job.taskInfos[36].jobGroup=AVIMonitorJob
quartz.job.taskInfos[36].jobDescription=\u76d1\u63a7\u0041\u0056\u0049Job quartz.job.taskInfos[36].jobDescription=\u76d1\u63a7\u0041\u0056\u0049Job
quartz.job.taskInfos[36].cronExpression=0/3 * * * * ? quartz.job.taskInfos[36].cronExpression=0/3 * * * * ?
quartz.job.taskInfos[36].start=false quartz.job.taskInfos[36].start=false
......
package net.vtstar.zhongtong.avi; package net.vtstar.zhongtong.avi;
import jcifs.smb.SmbFile;
import lombok.extern.slf4j.Slf4j;
import net.vtstar.utils.DateUtils;
import net.vtstar.zhongtong.avi.utils.SmbFileUtil;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Date;
@ActiveProfiles("xdw")
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest @SpringBootTest
@Slf4j
public class ApplicationTests { public class ApplicationTests {
@Test @Test
public void contextLoads() { public void contextLoads() {
} }
private String baseUrl = "D:/scada/assemblynewenergy/";
@Test
public void shareTestxgsk() throws Exception {
Date startOfDay = DateUtils.getStartOfDay(0);
String dateString = DateUtils.parseDateToString(startOfDay, "yyyy-MM-dd");
// String url = "smb://10.1.4.107/数控下料/下料计划01.06.xls";
log.error(String.valueOf(new Date().getTime()));
String url = "smb://admin:123456@10.1.25.128/an9637h/testdata@2019-04-10.mdb";
SmbFile file = new SmbFile(url);
if (file.exists()) {
SmbFileUtil.smbGet(url, baseUrl);
// SmbFileUtil.smbPut("smb://10.1.4.107/数控下料/", "D:/error.xls");
}else {
log.error("日期: {} 的总装车间新能源检测点共享文件不存在!", dateString);
}
log.error(String.valueOf(new Date().getTime()));
}
@Test
public void socketTest() throws Exception{
String aByte = "<get><var>.P107</var><auto>yes</auto></get>\n";
Socket socket = new Socket("172.18.81.191",62944);
OutputStream outputStream = socket.getOutputStream();
outputStream.write(aByte.getBytes());
outputStream.flush();
socket.shutdownOutput();
InputStream inputStream = socket.getInputStream();
byte[] bytes = new byte[1024];
int len;
StringBuilder sb = new StringBuilder();
while ((len = inputStream.read(bytes)) != -1) {
//注意指定编码格式,发送方和接收方一定要统一,建议使用UTF-8
sb.append(new String(bytes, 0, len,"UTF-8"));
}
System.out.println("get message from server: " + sb);
inputStream.close();
outputStream.close();
socket.close();
}
} }
...@@ -6,31 +6,198 @@ import net.vtstar.protocol.modbus.tcp.netty.packet.ReadCoilsRequest; ...@@ -6,31 +6,198 @@ 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.packet.ReadCoilsResponse;
import net.vtstar.protocol.modbus.tcp.netty.service.ModbusTemplate; import net.vtstar.protocol.modbus.tcp.netty.service.ModbusTemplate;
import net.vtstar.protocol.modbus.tcp.netty.utils.PoolKey; import net.vtstar.protocol.modbus.tcp.netty.utils.PoolKey;
import net.vtstar.scada.base.equipmgt.domain.EquipDataTemplate;
import net.vtstar.scada.base.equipmgt.domain.EquipDataTemplateItem;
import net.vtstar.scada.base.equipmgt.mapper.EquipDataTemplateItemMapper;
import net.vtstar.scada.base.equipmgt.mapper.EquipDataTemplateMapper;
import net.vtstar.user.mybatis.provider.WhereFilter;
import net.vtstar.utils.asserts.ParamAssert;
import net.vtstar.zhongtong.avi.monitoring.domain.Warning;
import net.vtstar.zhongtong.avi.monitoring.mapper.WarningMapper;
import net.vtstar.zhongtong.avi.sqlserver.domain.MesWorkOrderInfo;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j @Slf4j
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class) @SpringBootTest(classes = Application.class)
@ActiveProfiles("dev-yxh") @ActiveProfiles("xdw")
public class ModbusTest { public class ModbusTest {
@Autowired @Autowired
private ModbusTemplate modbusTemplate; private ModbusTemplate modbusTemplate;
@Autowired
private WarningMapper warningMapper;
@Autowired
private EquipDataTemplateItemMapper itemMapper;
@Autowired
private EquipDataTemplateMapper templateMapper;
@Test @Test
public void test() throws Exception { public void test() throws Exception {
ReadCoilsRequest readCoilsRequest = new ReadCoilsRequest(1,0,5); ReadCoilsRequest readCoilsRequest = new ReadCoilsRequest(1, 0, 5);
PoolKey poolKey = new PoolKey("localhost",502); PoolKey poolKey = new PoolKey("localhost", 502);
ReadCoilsResponse response= modbusTemplate.execute(poolKey, readCoilsRequest, ReadCoilsResponse.class); ReadCoilsResponse response = modbusTemplate.execute(poolKey, readCoilsRequest, ReadCoilsResponse.class);
ByteBuf body = response.getBody(); ByteBuf body = response.getBody();
byte b = body.readByte(); byte b = body.readByte();
System.out.println("___" + b); System.out.println("___" + b);
// byte[] array = body.array(); // byte[] array = body.array();
} }
private static final String SUFFIX_2003 = ".xls";
private static final String SUFFIX_2007 = ".xlsx";
private Map<String, Integer> map = new HashMap<>();
@Test
public void parsingExcel() {
map.put("KS111腻子烘干室335", 3);
map.put("KS1053工位电泳烘干室302", 1);
map.put("KS1062工位电泳烘干室303", 1);
map.put("KS113腻子烘干室336", 3);
map.put("KS112腻子烘干室377", 3);
map.put("KS114中途烘干室351", 3);
map.put("KS115中途烘干室352", 3);
map.put("KS116面漆烘干室360", 7);
map.put("KS117面漆烘干室362", 7);
map.put("KS118面漆烘干室364", 7);
map.put("KS119彩条烘干室366", 6);
map.put("KS120彩条烘干室368", 6);
map.put("KS121彩条烘干室370", 6);
map.put("KS122彩条烘干室372", 6);
map.put("KS123罩光漆烘干室373", 6);
map.put("KS142A中涂喷漆室349", 4);
map.put("KS143A中涂喷漆室350", 4);
map.put("KS144A面漆喷漆室359", 5);
map.put("KS145面漆喷漆室361", 5);
map.put("KS146A面漆喷漆室363", 5);
map.put("KS147A彩条喷漆室365", 6);
map.put("KS149A彩条喷漆室367", 6);
map.put("KS148A彩条喷漆室369", 6);
map.put("KS150A彩条喷漆室371", 6);
map.put("KS151A罩光喷漆室374", 6);
map.put("前处理", 1);
map.put("超滤UF", 1);
map.put("纯水OR", 1);
map.put("前处理空中行车", 1);
List<Warning> list = new ArrayList<>();
File file = new File("Y:/前处理纯水超滤行车.xlsx");
//获取文件的名字
Workbook workbook = null;
String fileName = file.getName();
try {
if (fileName.endsWith(SUFFIX_2003)) {
workbook = new HSSFWorkbook(new FileInputStream(file));
} else if (fileName.endsWith(SUFFIX_2007)) {
workbook = new XSSFWorkbook(new FileInputStream(file));
}
} catch (Exception e) {
log.error("读取文件错误: {}", e.getMessage());
}
ParamAssert.notNull(workbook, "文件名 :" + file + "不符合EXCEL的格式要求!标准格式:.xls/.xlsx");
//获取所有的工作表的的数量
int numOfSheet = workbook.getNumberOfSheets();
//遍历这个这些表
for (int i = 0; i < numOfSheet; i++) {
//获取一个sheet也就是一个工作簿
Sheet sheet = workbook.getSheetAt(i);
int lastRowNum = sheet.getLastRowNum();
//从第一行开始第一行一般是标题
for (int j = 0; j <= lastRowNum; j++) {
Row row = sheet.getRow(j);
if (null == row) {
continue;
}
Warning warning = new Warning();
//描述
if (row.getCell(0) != null) {
row.getCell(0).setCellType(CellType.STRING);
String info = row.getCell(0).getStringCellValue();
if (StringUtils.isEmpty(info)) {
continue;
}
warning.setInfo(info);
}
//类型
if (row.getCell(3) != null) {
row.getCell(3).setCellType(CellType.STRING);
String type = row.getCell(3).getStringCellValue();
if (null == type) {
continue;
}
warning.setType(type);
}
//解决
if (row.getCell(4) != null) {
row.getCell(4).setCellType(CellType.STRING);
String name = row.getCell(4).getStringCellValue();
warning.setName(name);
}
//创建warning, 获取code
warningMapper.insertRecord(warning);
Long id = warning.getId();
//产线
String name = "";
if (row.getCell(1) != null) {
row.getCell(1).setCellType(CellType.STRING);
name = row.getCell(1).getStringCellValue();
}
String address = "";
if (row.getCell(2) != null) {
row.getCell(2).setCellType(CellType.STRING);
address = row.getCell(2).getStringCellValue();
}
EquipDataTemplate byName = templateMapper.findByName(name);
if (byName == null){
log.error(name);
return;
}
EquipDataTemplateItem item = new EquipDataTemplateItem();
item.setTemplateId(byName.getId());
item.setFieldName("warning:" + map.get(name) + ":" + id);
if (address.contains(".")){
String[] split = address.substring(1).split("\\.");
item.setAddress(Integer.valueOf(split[0]) * 8 + Integer.valueOf(split[1]));
}else{
item.setAddress(Integer.valueOf(address.substring(1)) * 8);
}
item.setFunctionCode(2);
item.setFieldType("BIT");
item.setLength(1);
item.setFieldDesc(name);
itemMapper.insert(item);
list.add(warning);
}
log.error("加载数据: {} 条", list.size());
List<Warning> list1 = warningMapper.findList(new WhereFilter(), Warning.class);
for (Warning warning : list1){
warning.setCode(warning.getId() + "");
warningMapper.update(warning);
}
}
}
} }
...@@ -3,6 +3,8 @@ package net.vtstar.zhongtong.avi; ...@@ -3,6 +3,8 @@ package net.vtstar.zhongtong.avi;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.vtstar.scada.base.equipmgt.domain.EquipDataTemplateItem; import net.vtstar.scada.base.equipmgt.domain.EquipDataTemplateItem;
import net.vtstar.scada.base.equipmgt.mapper.EquipDataTemplateItemMapper; import net.vtstar.scada.base.equipmgt.mapper.EquipDataTemplateItemMapper;
import net.vtstar.user.mybatis.provider.Operation;
import net.vtstar.user.mybatis.provider.OrderBy;
import net.vtstar.user.mybatis.provider.WhereFilter; import net.vtstar.user.mybatis.provider.WhereFilter;
import net.vtstar.zhongtong.avi.equipment.domain.PaintshopStation; import net.vtstar.zhongtong.avi.equipment.domain.PaintshopStation;
import net.vtstar.zhongtong.avi.equipment.mapper.PaintshopStationMapper; import net.vtstar.zhongtong.avi.equipment.mapper.PaintshopStationMapper;
...@@ -10,10 +12,13 @@ import net.vtstar.zhongtong.avi.global.constant.Constant; ...@@ -10,10 +12,13 @@ import net.vtstar.zhongtong.avi.global.constant.Constant;
import net.vtstar.zhongtong.avi.monitoring.domain.Skid; import net.vtstar.zhongtong.avi.monitoring.domain.Skid;
import net.vtstar.zhongtong.avi.monitoring.domain.enums.ProductionType; import net.vtstar.zhongtong.avi.monitoring.domain.enums.ProductionType;
import net.vtstar.zhongtong.avi.monitoring.domain.enums.StationState; import net.vtstar.zhongtong.avi.monitoring.domain.enums.StationState;
import net.vtstar.zhongtong.avi.sqlserver.domain.MesWorkOrderInfo;
import net.vtstar.zhongtong.avi.sqlserver.mapper.MesWorkOrderMapper;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations; import org.springframework.data.redis.core.ValueOperations;
import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
...@@ -22,12 +27,13 @@ import javax.annotation.Resource; ...@@ -22,12 +27,13 @@ import javax.annotation.Resource;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Slf4j @Slf4j
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class) @SpringBootTest(classes = Application.class)
@ActiveProfiles("dev-yxh") @ActiveProfiles("xdw")
public class StationTest { public class StationTest {
@Autowired @Autowired
...@@ -36,6 +42,11 @@ public class StationTest { ...@@ -36,6 +42,11 @@ public class StationTest {
private EquipDataTemplateItemMapper itemMapper; private EquipDataTemplateItemMapper itemMapper;
@Resource(name = "redisTemplate") @Resource(name = "redisTemplate")
private ValueOperations valueOperations; private ValueOperations valueOperations;
@Resource(name = "redisTemplate")
private RedisTemplate redisTemplate;
@Autowired
private MesWorkOrderMapper mesWorkOrderMapper;
@Test @Test
public void test() { public void test() {
...@@ -99,4 +110,33 @@ public class StationTest { ...@@ -99,4 +110,33 @@ public class StationTest {
paintshopStation.setSkid(skid); paintshopStation.setSkid(skid);
valueOperations.set("station:HDG1-13",paintshopStation); valueOperations.set("station:HDG1-13",paintshopStation);
} }
@Test
public void skidTest() {
List<MesWorkOrderInfo> mesWorkOrderInfos = mesWorkOrderMapper.findList(new WhereFilter() {{
addFilter("status", Operation.EQUAL, "4");
addOrderBy("crt_date", OrderBy.DESC);
}}, MesWorkOrderInfo.class);
Set<String> veKeys = redisTemplate.keys(Constant.SKID_PREFIX + "*");
int num = 0;
for (String veKey : veKeys) {
Skid skid = (Skid)valueOperations.get(veKey);
MesWorkOrderInfo mesWorkOrderInfo = mesWorkOrderInfos.get(num);
num ++;
skid.setWorkOrderNo(mesWorkOrderInfo.getWorkOrderNo());
skid.setBusNo(mesWorkOrderInfo.getVehicleModel());
valueOperations.set(veKey, skid);
}
Set<String> veKeyStation = redisTemplate.keys(Constant.STATION_PREFIX + "*");
for (String key : veKeyStation){
PaintshopStation station = (PaintshopStation) valueOperations.get(key);
if (null != station.getSkid()){
Skid skid = (Skid)valueOperations.get(Constant.SKID_PREFIX + station.getSkid().getRfid());
station.setSkid(skid);
station.setWorkOrderNo(skid.getWorkOrderNo());
station.setBusNo(skid.getBusNo());
valueOperations.set(key, 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