Commit 223e5917 authored by 王晓倩's avatar 王晓倩

共用方法拆分

parent 41078752
...@@ -16,6 +16,8 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -16,6 +16,8 @@ import org.springframework.web.bind.annotation.RestController;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -37,134 +39,236 @@ public class EquipmentDataCollection { ...@@ -37,134 +39,236 @@ public class EquipmentDataCollection {
private ITEquipmentAlarmDataService tEquipmentAlarmDataService; private ITEquipmentAlarmDataService tEquipmentAlarmDataService;
/** /**
* 老化柜、标定柜巡查 * 1.老化柜、标定柜巡查
* 2.老化层断电
*/ */
@GetMapping("/equipmentPatrol") @GetMapping("/equipmentPatrol")
public void equipmentPatrol(){ public void equipmentPatrol(){
String ip = null; List<String> type = new ArrayList<>();
Integer port = null; type.add("1");
type.add("2");
// 老化柜通讯 List<TEquipmentInfo> equipmentInfos = tEquipmentInfoService.selectTEquipmentList(type);
String sendMsg = "00010000000601040000000A";
String receiveMsg = null;
TEquipmentInfo equipment = new TEquipmentInfo();
equipment.setfEquipmentType("1");
List<TEquipmentInfo> equipmentInfos = tEquipmentInfoService.selectTEquipmentInfoList(equipment);
try{ try{
if(equipmentInfos.size() == 0){ if(equipmentInfos.size() == 0){
log.error("设备列表查询结果为空"); log.error("设备列表查询结果为空");
throw new Exception("无设备信息!"); throw new Exception("无设备信息!");
} }
if(equipmentInfos.size() > 0){ if(equipmentInfos.size() > 0){
String sendMsg = "00010000000601040000000A";
String receiveMsg;
TEquipmentAlarmData alarmData = new TEquipmentAlarmData(); TEquipmentAlarmData alarmData = new TEquipmentAlarmData();
for(TEquipmentInfo info : equipmentInfos){ for(TEquipmentInfo info : equipmentInfos){
ip = info.getfIp(); /* 1.老化柜、标定柜通讯 */
port = info.getfPort(); receiveMsg = agingCabinetCommunication(info, sendMsg);
if(ip == null || port == null){ if(receiveMsg == null){
log.error(info.getfEquipmentCode() + "号老化柜ip或端口号为空"); // 记录异常数据
} else { alarmData.setfAlarmType("01"); // 01.老化柜 02.标定柜 03.机械臂 04.老化层 05.点位
// 发送并接收数据 alarmData.setfEquipmentCode(info.getfEquipmentCode());
receiveMsg = TCPClient.PLCConnect(ip, port, sendMsg); alarmData.setfAlarmData("老化柜通讯失败,无响应");
if(receiveMsg == null){ tEquipmentAlarmDataService.insertTEquipmentAlarmData(alarmData);
// 记录异常数据 // 更新老化柜状态(“0”空闲,“1”运行,“2”故障)
alarmData.setfAlarmType("01"); //01.老化柜 02.标定柜 03.机械臂 04.老化层 info.setfStatus("2");
alarmData.setfEquipmentCode(info.getfEquipmentCode()); tEquipmentInfoService.updateTEquipmentInfo(info);
alarmData.setfAlarmData("2"); } else if (receiveMsg.length() != 58) {
tEquipmentAlarmDataService.insertTEquipmentAlarmData(alarmData); // 记录异常数据
alarmData.setfAlarmType("01"); // 01.老化柜 02.标定柜 03.机械臂 04.老化层 05.点位
alarmData.setfEquipmentCode(info.getfEquipmentCode());
alarmData.setfAlarmData("老化柜IP或端口号为空");
tEquipmentAlarmDataService.insertTEquipmentAlarmData(alarmData);
} else if (receiveMsg.length() == 58){
// 解析服务器返回信息
// 示例:00 01 00 00 00 17 01 04 14 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
String flag = receiveMsg.substring(18, 58);
if("0000000000000000000000000000000000000000".equals(flag) && !"0".equals(info.getfStatus())){
// 更新老化柜状态(“0”空闲,“1”运行,“2”故障) // 更新老化柜状态(“0”空闲,“1”运行,“2”故障)
info.setfStatus("2"); info.setfStatus("0");
info.setfUpdateTime(new Date());
tEquipmentInfoService.updateTEquipmentInfo(info); tEquipmentInfoService.updateTEquipmentInfo(info);
} else if (receiveMsg.length() == 58){ } else if (!"0000000000000000000000000000000000000000".equals(flag) && "0".equals(info.getfStatus())){
// 解析服务器返回信息 info.setfStatus("1");
// 示例:00 01 00 00 00 17 01 04 14 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 info.setfUpdateTime(new Date());
String flag = receiveMsg.substring(18, 58); tEquipmentInfoService.updateTEquipmentInfo(info);
if("0000000000000000000000000000000000000000".equals(flag) && !"0".equals(info.getfStatus())){
// 更新老化柜状态(“0”空闲,“1”运行,“2”故障) // 解析层状态,根据层编号修改状态
info.setfStatus("0"); int startIndex;
info.setfUpdateTime(new Date()); int endIndex;
tEquipmentInfoService.updateTEquipmentInfo(info); int code; //组成老化层编号
}else if(!"0000000000000000000000000000000000000000".equals(flag) && "0".equals(info.getfStatus())){ String status;
info.setfStatus("1"); TStoreyInfo storeyInfo = new TStoreyInfo();
info.setfUpdateTime(new Date()); for(startIndex = 18,endIndex = 22,code = 1; endIndex <= receiveMsg.length(); startIndex += 4,endIndex += 4,code++){
tEquipmentInfoService.updateTEquipmentInfo(info); status = receiveMsg.substring(startIndex, endIndex);
storeyInfo.setfStoreyCode(info.getfEquipmentCode() + "-" + code);
// 解析层状态 if("0000".equals(status)){
// int startIndex; /* 2.老化层断电 */
// int endIndex;
// int code; //组成老化层编号
// for(startIndex = 18,endIndex = 22,code = 1; endIndex <= receiveMsg.length(); startIndex += 4,endIndex += 4,code++){ storeyInfo.setfStatus("4"); //断电
// tStoreyInfoService.updateTStoreyInfoByCode(storeyInfo);
// } }
} }
} }
} }
} }
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); e.printStackTrace();
} }
} }
/** /**
* 老化层数据采集 * 上料:
* 1.由页面向机械臂发送上料指令,通讯机械臂
* 2.通讯老化柜,根据响应信息获取层状态
* 3.通讯老化层,分别获取72个点位状态,开始计时
* 4.向点位写入时间,分别写入年、月、日、时、分
*/ */
@GetMapping("/agingCabinet") @GetMapping("/agingCabinet")
public void agingCabinetData(){ // public void agingCabinetData(TStoreyInfo storeyInfo) throws Exception {
String ip = null; public void agingCabinetData() throws Exception {
Integer port = null; // 获取老化层信息,将用页面传参代替此步骤
// 1.老化层通讯
String sendMsg1 = "00010000000601030000000A";
String receiveMsg = null;
// 获取老化层信息
Long id = Long.valueOf(1); Long id = Long.valueOf(1);
TStoreyInfo storeyInfo = tStoreyInfoService.selectTStoreyInfoById(id); TStoreyInfo storeyInfo = tStoreyInfoService.selectTStoreyInfoById(id);
// List<TStoreyInfo> storeys = tStoreyInfoService.selectTStoreyInfoList(new TStoreyInfo());
// 获取老化柜信息 if (storeyInfo == null) {
// TEquipmentInfo equipmentInfo = tEquipmentInfoService.selectTEquipmentInfoById(storeyInfo.getfEquipmentId()); throw new Exception("无老化层信息!");
try { }
if (storeyInfo == null) { //获取老化柜信息
throw new Exception("无老化层信息!"); TEquipmentInfo equipmentInfo = tEquipmentInfoService.selectTEquipmentInfoById(storeyInfo.getfEquipmentId());
} if (equipmentInfo == null) {
ip = storeyInfo.getfIp(); throw new Exception("无老化柜信息!");
port = storeyInfo.getfPort(); }
if(ip == null || port == null){
throw new Exception("请确认老化层的IP和端口号是否正确!");
}
// 发送并接收数据
receiveMsg = TCPClient.PLCConnect(ip, port, sendMsg1);
if(receiveMsg == null){
// 记录异常日志
throw new Exception(storeyInfo.getfStoreyCode() + "号老化柜通讯故障!"); /* 1.机械臂通讯 */
}
if (receiveMsg.length() == 58) {
// 解析服务器返回信息 /* 2.老化柜通讯 */
// 示例:000100000017010314 浓度0000 状态0001 AD值01F7 标定AD值01F7 年07E9 月0005 日0004 时000E 分000F 秒0015 String sendMsg1 = "00010000000601040000000A";
String receiveMsg1 = agingCabinetCommunication(equipmentInfo, sendMsg1);
TEquipmentAlarmData alarmData = new TEquipmentAlarmData();
if (receiveMsg1 == null) {
// 记录异常数据
alarmData.setfAlarmType("01"); //01.老化柜 02.标定柜 03.机械臂 04.老化层
alarmData.setfEquipmentCode(equipmentInfo.getfEquipmentCode());
alarmData.setfAlarmData("老化柜通讯失败,无响应");
tEquipmentAlarmDataService.insertTEquipmentAlarmData(alarmData);
throw new Exception(storeyInfo.getfStoreyCode() + "号老化柜通讯故障!");
} else if(receiveMsg1.length() != 58){
throw new Exception(receiveMsg1);
}
if (receiveMsg1.length() == 58) {
// 解析服务器返回信息
// 示例:00 01 00 00 00 17 01 04 14 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
String storeyCode = storeyInfo.getfStoreyCode();
int code = Integer.parseInt(storeyCode.substring(storeyCode.indexOf("-")+1));
int startIndex;
int endIndex;
String status;
int flag = 1;
for(startIndex = 18,endIndex = 22,code = 1; endIndex <= receiveMsg1.length(); startIndex += 4,endIndex += 4,flag++){
status = receiveMsg1.substring(startIndex, endIndex);
if(flag == code && "0001".equals(status)){
String value = receiveMsg.substring(22, 26); //板子状态 /* 3.老化层通讯,72个点位 */
if("0000".equals(value)){ String sendMsg2 = "010000000601030000000A"; //第二个“01”位置代表点位地址
String senMsg2 = ""; String receiveMsg2 = null;
int num2 = 1;
//若无返回信息将再次通讯,最多通讯3次
while(receiveMsg2 == null && num2 >= 3){
receiveMsg2 = storeyCommunication(storeyInfo, sendMsg2);
num2++;
}
if(receiveMsg2 == null){
// 记录异常数据
alarmData.setfAlarmType("04"); //01.老化柜 02.标定柜 03.机械臂 04.老化层 05.点位
alarmData.setfEquipmentCode(storeyInfo.getfStoreyCode());
alarmData.setfAlarmData("老化层通讯失败,无响应");
tEquipmentAlarmDataService.insertTEquipmentAlarmData(alarmData);
}
// 解析服务器返回信息
// 示例:000100000017010314 浓度0000 状态0001 AD值01F7 标定AD值01F7 年07E9 月0005 日0004 时000E 分000F 秒0015
String value = receiveMsg2.substring(22, 26); //板子状态
if("0001".equals(value)){
/* 4.写入时间,年、月、日、时、分 */
// 示例:0100000006 设备地址01写时间06 寄存器地址04(年04月05日06时07分08) 年/月/日/时/分数值07E9(2025)
Calendar cal=Calendar.getInstance();
// 当前年
int y = cal.get(Calendar.YEAR);
// 当前月
int m = cal.get(Calendar.MONTH) + 1;
// 当前日
int d = cal.get(Calendar.DATE);
// 当前小时
int h = cal.get(Calendar.HOUR_OF_DAY);
// 当前分钟
int mm = cal.get(Calendar.MINUTE);
String minutes = Integer.toHexString(mm).length()<2?"0"+Integer.toHexString(mm):Integer.toHexString(mm);;
String hours = Integer.toHexString(h).length()<2?"0"+Integer.toHexString(h):Integer.toHexString(h);;
String date = Integer.toHexString(d).length()<2?"0"+Integer.toHexString(d):Integer.toHexString(d);;
String month = Integer.toHexString(m).length()<2?"0"+Integer.toHexString(m):Integer.toHexString(m);;
String year = Integer.toHexString(Integer.valueOf(String.valueOf(y).substring(2, 4)));
String sendMsgYear = "01000000060" + code + "0604" + year;
String receiveMsgYear = null;
int num3 = 1;
//写入时间失败将再次通讯,最多通讯3次
while(!sendMsgYear.equals(receiveMsgYear) || receiveMsgYear == null){
receiveMsgYear = storeyCommunication(storeyInfo, sendMsgYear);
num3++;
}
if(!sendMsgYear.equals(receiveMsgYear) || receiveMsgYear == null){
// 记录异常数据
alarmData.setfAlarmType("05"); //01.老化柜 02.标定柜 03.机械臂 04.老化层 05.点位
alarmData.setfEquipmentCode(storeyInfo.getfStoreyCode());
alarmData.setfAlarmData("写入时间失败");
tEquipmentAlarmDataService.insertTEquipmentAlarmData(alarmData);
}
}
} }
Integer.parseInt(value,16);
// int startIndex;
// int endIndex;
// int code = 1; //组成老化层编号
// for(startIndex = 18,endIndex = 22; endIndex <= receiveMsg.length(); startIndex += 4,endIndex += 4,code++){
// value = receiveMsg.substring(startIndex, endIndex);
//
// Integer.parseInt(value,16);
//
// }
} }
}
} catch (Exception e) { }
// 老化柜通讯
private String agingCabinetCommunication(TEquipmentInfo equipment, String sendMsg) {
String receiveMsg = null;
String ip = null;
Integer port = null;
try{
ip = equipment.getfIp();
port = equipment.getfPort();
if(ip == null || port == null){
receiveMsg = equipment.getfEquipmentCode();
return receiveMsg;
} else {
// 发送并接收数据
receiveMsg = TCPClient.PLCConnect(ip, port, sendMsg);
}
} catch(Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
return receiveMsg;
} }
//老化层通讯
private String storeyCommunication(TStoreyInfo storey, String sendMsg){
String ip = null;
Integer port = null;
String receiveMsg = null;
try{
ip = storey.getfIp();
port = storey.getfPort();
if(ip == null || port == null){
throw new Exception("请确认老化层的IP和端口号是否正确!");
}
// 发送并接收数据
receiveMsg = TCPClient.PLCConnect(ip, port, sendMsg);
}catch(Exception e){
throw new RuntimeException(e);
}
return receiveMsg;
}
} }
...@@ -2,6 +2,7 @@ package com.zehong.system.mapper; ...@@ -2,6 +2,7 @@ package com.zehong.system.mapper;
import java.util.List; import java.util.List;
import com.zehong.system.domain.TEquipmentInfo; import com.zehong.system.domain.TEquipmentInfo;
import org.apache.ibatis.annotations.Param;
/** /**
* 生产设备信息Mapper接口 * 生产设备信息Mapper接口
...@@ -27,6 +28,14 @@ public interface TEquipmentInfoMapper ...@@ -27,6 +28,14 @@ public interface TEquipmentInfoMapper
*/ */
public List<TEquipmentInfo> selectTEquipmentInfoList(TEquipmentInfo tEquipmentInfo); public List<TEquipmentInfo> selectTEquipmentInfoList(TEquipmentInfo tEquipmentInfo);
/**
* 查询老化柜、标定柜信息列表
*
* @param types 生产设备类型
* @return 生产设备信息集合
*/
public List<TEquipmentInfo> selectTEquipmentList(@Param("types") List<String> types);
/** /**
* 新增生产设备信息 * 新增生产设备信息
* *
......
...@@ -43,6 +43,14 @@ public interface TStoreyInfoMapper ...@@ -43,6 +43,14 @@ public interface TStoreyInfoMapper
*/ */
public int updateTStoreyInfo(TStoreyInfo tStoreyInfo); public int updateTStoreyInfo(TStoreyInfo tStoreyInfo);
/**
* 修改老化层信息
*
* @param tStoreyInfo 老化层信息
* @return 结果
*/
public int updateTStoreyInfoByCode(TStoreyInfo tStoreyInfo);
/** /**
* 删除老化层信息 * 删除老化层信息
* *
......
...@@ -27,6 +27,14 @@ public interface ITEquipmentInfoService ...@@ -27,6 +27,14 @@ public interface ITEquipmentInfoService
*/ */
public List<TEquipmentInfo> selectTEquipmentInfoList(TEquipmentInfo tEquipmentInfo); public List<TEquipmentInfo> selectTEquipmentInfoList(TEquipmentInfo tEquipmentInfo);
/**
* 查询老化柜、标定柜信息列表
*
* @param types 生产设备类型
* @return 生产设备信息集合
*/
public List<TEquipmentInfo> selectTEquipmentList(List<String> types);
/** /**
* 新增生产设备信息 * 新增生产设备信息
* *
......
...@@ -43,6 +43,14 @@ public interface ITStoreyInfoService ...@@ -43,6 +43,14 @@ public interface ITStoreyInfoService
*/ */
public int updateTStoreyInfo(TStoreyInfo tStoreyInfo); public int updateTStoreyInfo(TStoreyInfo tStoreyInfo);
/**
* 修改老化层信息
*
* @param tStoreyInfo 老化层信息
* @return 结果
*/
public int updateTStoreyInfoByCode(TStoreyInfo tStoreyInfo);
/** /**
* 批量删除老化层信息 * 批量删除老化层信息
* *
......
...@@ -43,6 +43,18 @@ public class TEquipmentInfoServiceImpl implements ITEquipmentInfoService ...@@ -43,6 +43,18 @@ public class TEquipmentInfoServiceImpl implements ITEquipmentInfoService
return tEquipmentInfoMapper.selectTEquipmentInfoList(tEquipmentInfo); return tEquipmentInfoMapper.selectTEquipmentInfoList(tEquipmentInfo);
} }
/**
* 查询老化柜、标定柜信息列表
*
* @param types 生产设备类型
* @return 生产设备信息集合
*/
@Override
public List<TEquipmentInfo> selectTEquipmentList(List<String> types)
{
return tEquipmentInfoMapper.selectTEquipmentList(types);
}
/** /**
* 新增生产设备信息 * 新增生产设备信息
* *
......
...@@ -67,6 +67,11 @@ public class TStoreyInfoServiceImpl implements ITStoreyInfoService ...@@ -67,6 +67,11 @@ public class TStoreyInfoServiceImpl implements ITStoreyInfoService
return tStoreyInfoMapper.updateTStoreyInfo(tStoreyInfo); return tStoreyInfoMapper.updateTStoreyInfo(tStoreyInfo);
} }
public int updateTStoreyInfoByCode(TStoreyInfo tStoreyInfo)
{
return tStoreyInfoMapper.updateTStoreyInfoByCode(tStoreyInfo);
}
/** /**
* 批量删除老化层信息 * 批量删除老化层信息
* *
......
...@@ -47,6 +47,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -47,6 +47,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="fAlarmTime != null and fAlarmTime != ''"> and f_alarm_time = #{fAlarmTime}</if> <if test="fAlarmTime != null and fAlarmTime != ''"> and f_alarm_time = #{fAlarmTime}</if>
</where> </where>
</select> </select>
<select id="selectTEquipmentList" parameterType="List" resultMap="TEquipmentInfoResult">
<include refid="selectTEquipmentInfoVo"/>
where f_equipment_type in
<foreach item="item" collection="types" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="selectTEquipmentInfoById" parameterType="Long" resultMap="TEquipmentInfoResult"> <select id="selectTEquipmentInfoById" parameterType="Long" resultMap="TEquipmentInfoResult">
<include refid="selectTEquipmentInfoVo"/> <include refid="selectTEquipmentInfoVo"/>
......
...@@ -85,6 +85,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -85,6 +85,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where f_storey_id = #{fStoreyId} where f_storey_id = #{fStoreyId}
</update> </update>
<update id="updateTStoreyInfoByCode" parameterType="TStoreyInfo">
update t_storey_info
<trim prefix="SET" suffixOverrides=",">
<if test="fEquipmentId != null">f_equipment_id = #{fEquipmentId},</if>
<if test="fStoreyCode != null">f_storey_code = #{fStoreyCode},</if>
<if test="fTrayCode != null">f_tray_code = #{fTrayCode},</if>
<if test="fIp != null">f_ip = #{fIp},</if>
<if test="fStatus != null">f_status = #{fStatus},</if>
<if test="fPort != null">f_port = #{fPort},</if>
<if test="fUpdateTime != null">f_update_time = #{fUpdateTime},</if>
<if test="fCreateTime != null">f_create_time = #{fCreateTime},</if>
<if test="fAlarmTime != null">f_alarm_time = #{fAlarmTime},</if>
</trim>
where f_storey_code = #{fStoreyCode}
</update>
<delete id="deleteTStoreyInfoById" parameterType="Long"> <delete id="deleteTStoreyInfoById" parameterType="Long">
delete from t_storey_info where f_storey_id = #{fStoreyId} delete from t_storey_info where f_storey_id = #{fStoreyId}
</delete> </delete>
......
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