Commit 315815b3 authored by 耿迪迪's avatar 耿迪迪

工业报警器数据上报

parent f185aab1
package com.zehong.gassdevicereport.dao;
import com.zehong.gassdevicereport.entity.TRelationDeviceData;
import java.util.List;
/**
* 关联设备数据Mapper接口
*
* @author zehong
* @date 2023-03-27
*/
public interface TRelationDeviceDataDao {
/**
* 查询关联设备数据
*
* @param dataId 关联设备数据ID
* @return 关联设备数据
*/
TRelationDeviceData selectTRelationDeviceDataById(Long dataId);
/**
* 查询关联设备数据列表
*
* @param tRelationDeviceData 关联设备数据
* @return 关联设备数据集合
*/
List<TRelationDeviceData> selectTRelationDeviceDataList(TRelationDeviceData tRelationDeviceData);
/**
* 新增关联设备数据
*
* @param tRelationDeviceData 关联设备数据
* @return 结果
*/
int insertTRelationDeviceData(TRelationDeviceData tRelationDeviceData);
/**
* 修改关联设备数据
*
* @param tRelationDeviceData 关联设备数据
* @return 结果
*/
int updateTRelationDeviceData(TRelationDeviceData tRelationDeviceData);
/**
* 删除关联设备数据
*
* @param dataId 关联设备数据ID
* @return 结果
*/
int deleteTRelationDeviceDataById(Long dataId);
/**
* 批量删除关联设备数据
*
* @param dataIds 需要删除的数据ID
* @return 结果
*/
int deleteTRelationDeviceDataByIds(Long[] dataIds);
}
package com.zehong.gassdevicereport.dao;
import com.zehong.gassdevicereport.entity.TRelationDeviceInfo;
import java.util.List;
/**
* 关联设备Mapper接口
*
* @author zehong
* @date 2023-03-27
*/
public interface TRelationDeviceInfoDao {
/**
* 查询关联设备
*
* @param relationId 关联设备ID
* @return 关联设备
*/
TRelationDeviceInfo selectTRelationDeviceInfoById(Long relationId);
/**
* 查询关联设备列表
*
* @param tRelationDeviceInfo 关联设备
* @return 关联设备集合
*/
List<TRelationDeviceInfo> selectTRelationDeviceInfoList(TRelationDeviceInfo tRelationDeviceInfo);
/**
* 新增关联设备
*
* @param tRelationDeviceInfo 关联设备
* @return 结果
*/
int insertTRelationDeviceInfo(TRelationDeviceInfo tRelationDeviceInfo);
/**
* 修改关联设备
*
* @param tRelationDeviceInfo 关联设备
* @return 结果
*/
int updateTRelationDeviceInfo(TRelationDeviceInfo tRelationDeviceInfo);
/**
* 删除关联设备
*
* @param relationId 关联设备ID
* @return 结果
*/
int deleteTRelationDeviceInfoById(Long relationId);
/**
* 批量删除关联设备
*
* @param relationIds 需要删除的数据ID
* @return 结果
*/
int deleteTRelationDeviceInfoByIds(Long[] relationIds);
List<TRelationDeviceInfo> getDeviceInfoByDeviceCode(String deviceCode);
}
package com.zehong.gassdevicereport.entity;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
/**
* 关联设备数据对象 t_relation_device_data
*
* @author zehong
* @date 2023-03-27
*/
@Data
public class TRelationDeviceData {
/** 主键id */
private Long dataId;
/** 设备编号 */
private String deviceCode;
/** 设备状态:0.预热 1.正常 2.错误 3.传感器故障 4.报警 5.低报 6.高报 7.通信故障 8.通信故障 9.离线 10.电量低 11.主电故障 12.备电故障 13.无此节点 14.低电压 15.故障 16.报警联动 17.低低报 18.高高报 19.水位淹没报警 */
private String status;
/** 浓度 */
private BigDecimal potency;
/** 是否删除:0否,1是 */
private String isDel;
/** 创建时间 */
private Date createTime;
/** 更新时间 */
private Date updateTime;
private String remark;
}
package com.zehong.gassdevicereport.entity;
import lombok.Data;
import java.util.Date;
/**
* 关联设备对象 t_relation_device_info
*
* @author zehong
* @date 2023-03-27
*/
@Data
public class TRelationDeviceInfo {
/** 主键id */
private Long relationId;
/** 关联设备id */
private Long relationDeviceId;
/** 设备名称 */
private String deviceName;
/** 设备编号 */
private String deviceCode;
/** 是否删除:0否,1是 */
private String isDel;
/** 创建时间 */
private Date createTime;
/** 更新时间 */
private Date updateTime;
private String remark;
private Long deviceId;
private String deviceType;
}
package com.zehong.gassdevicereport.netty;
import com.zehong.gassdevicereport.netty.handler.FactoryDetectorUdpServerHandler;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioDatagramChannel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
/**
* @author geng
* 工业探测器数据接收
*/
@Component
public class FactoryDetectorUdpStart {
private Logger logger = LoggerFactory.getLogger(FactoryDetectorUdpStart.class);
@Resource
private FactoryDetectorUdpServerHandler factoryDetectorUdpServerHandler;
private EventLoopGroup bossGroup = new NioEventLoopGroup();
/**
* 启动netty服务
* @throws InterruptedException
*/
@PostConstruct
public void start() throws InterruptedException {
Bootstrap b=new Bootstrap ();
b.group(bossGroup)
.channel(NioDatagramChannel.class)
.option(ChannelOption.SO_BACKLOG,128)
.handler(factoryDetectorUdpServerHandler);
//开启需要监听 的端口
ChannelFuture future = b.bind(65012).sync();
if (future.isSuccess()) {
logger.info("FactoryDetector UDP server启动 65012 成功");
}
}
/**
* 销毁
*/
@PreDestroy
public void destroy() {
bossGroup.shutdownGracefully().syncUninterruptibly();
logger.info("FactoryDetector UDP server关闭 Netty 成功");
}
}
package com.zehong.gassdevicereport.netty.handler;
import com.zehong.gassdevicereport.entity.TDeviceAlarm;
import com.zehong.gassdevicereport.entity.TRelationDeviceData;
import com.zehong.gassdevicereport.entity.TRelationDeviceInfo;
import com.zehong.gassdevicereport.service.ITDeviceAlarmService;
import com.zehong.gassdevicereport.service.ITRelationDeviceDataService;
import com.zehong.gassdevicereport.service.ITRelationDeviceInfoService;
import com.zehong.gassdevicereport.utils.DateUtils;
import com.zehong.gassdevicereport.utils.HttpUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.DatagramPacket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
/**
* @author geng
* 工业报警器数据解析类
*/
@Component
@Sharable
public class FactoryDetectorUdpServerHandler extends SimpleChannelInboundHandler<DatagramPacket> {
private Logger logger = LoggerFactory.getLogger(FactoryDetectorUdpServerHandler.class);
@Autowired
private ITRelationDeviceDataService itRelationDeviceDataService;
@Value("${webSocektUrl}")
private String webSocektUrl;
@Autowired
private ITDeviceAlarmService itDeviceAlarmService;
@Autowired
private ITRelationDeviceInfoService itRelationDeviceInfoService;
@Override
protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg)throws Exception{
//获取上传参数
ByteBuf buf = msg.content();
String msgStr = convertByteBufToString(buf);
logger.info("FactoryDetectorUdp 入参:" + msgStr);
//解析上传参数 参数实例:ZHGM130001801001/7/000
String[] msgInfo = msgStr.split("/");
//保存上报数据
saveDeviceData(msgInfo);
//根据设备状态报警
judgeDeviceStatus(msgInfo);
}
/**
* 保存上报数据
* @param msgInfo 信息
*/
private void saveDeviceData(String[] msgInfo) {
//设备上报数据入库
TRelationDeviceData tRelationDeviceData = new TRelationDeviceData();
tRelationDeviceData.setDeviceCode(msgInfo[0]);
tRelationDeviceData.setStatus(msgInfo[1]);
tRelationDeviceData.setPotency(new BigDecimal(msgInfo[2]));
itRelationDeviceDataService.insertTRelationDeviceData(tRelationDeviceData);
}
private void judgeDeviceStatus(String[] msgInfo) {
List<TRelationDeviceInfo> relationDeviceInfos = itRelationDeviceInfoService.getDeviceInfoByDeviceCode(msgInfo[0]);
TDeviceAlarm alarm = itDeviceAlarmService.selectTDeviceAlarmByDeviceId(relationDeviceInfos.get(0).getDeviceId());
if(!"0".equals(msgInfo[1]) && !"1".equals(msgInfo[1])){
if(null != relationDeviceInfos){
if(null != alarm){
alarm.setCreateTime(DateUtils.getNowDate());
alarm.setAlarmType(msgInfo[1]);
alarm.setAlarmValue(String.valueOf(Integer.parseInt(msgInfo[2])));
itDeviceAlarmService.updateTDeviceAlarm(alarm);
return;
}
TDeviceAlarm tDeviceAlarm = new TDeviceAlarm();
tDeviceAlarm.setDeviceId(relationDeviceInfos.get(0).getDeviceId());
tDeviceAlarm.setAlarmType(msgInfo[1]);
tDeviceAlarm.setDeviceType(relationDeviceInfos.get(0).getDeviceType());
tDeviceAlarm.setStartTime(new Date());
tDeviceAlarm.setAlarmValue(String.valueOf(Integer.parseInt(msgInfo[2])));
itDeviceAlarmService.insertTDeviceAlarm(tDeviceAlarm);
pushWedSocket(tDeviceAlarm.getAlarmId());
}
}else {
if(null != alarm){
alarm.setEndTime(new Date());
alarm.setDealStatus("4");
itDeviceAlarmService.updateTDeviceAlarm(alarm);
}
}
}
/**
* 推送报警信息
* @param alarmId 报警id
*/
private void pushWedSocket(Long alarmId){
//推送信息至websocket
StringBuilder url = new StringBuilder(webSocektUrl)
.append("?")
.append("alarmId=")
.append(alarmId);
try {
HttpUtil.doGet(url.toString());
} catch (IOException e) {
logger.error("websocket推送失败:"+e);
}
}
/**
* buf转字符串
* @param buf
* @return
*/
private String convertByteBufToString(ByteBuf buf) {
String str;
if(buf.hasArray()) {
// 处理堆缓冲区
str = new String(buf.array(), buf.arrayOffset() + buf.readerIndex(), buf.readableBytes());
} else { // 处理直接缓冲区以及复合缓冲区
byte[] bytes = new byte[buf.readableBytes()];
buf.getBytes(buf.readerIndex(), bytes);
str = new String(bytes, 0, buf.readableBytes());
}
return str;
}
private String deviceStatus(String code){
switch (code){
case "0":
return "预热";
case "1":
return "正常";
case "2":
return "错误";
case "3":
return "传感器故障";
case "4":
return "报警";
case "5":
return "低报";
case "6":
return "高报";
case "7":
return "通信故障";
case "8":
return "通信故障";
case "9":
return "离线";
case "10":
return "电量低";
case "11":
return "主电故障";
case "12":
return "备电故障";
case "13":
return "无此节点";
case "14":
return "低电压";
case "15":
return "故障";
case "16":
return "报警联动";
case "17":
return "低低报";
case "18":
return "高高报";
case "19":
return "水位淹没报警";
default:
return "";
}
}
}
package com.zehong.gassdevicereport.service;
import com.zehong.gassdevicereport.entity.TRelationDeviceData;
import java.util.List;
/**
* 关联设备数据Service接口
*
* @author zehong
* @date 2023-03-27
*/
public interface ITRelationDeviceDataService {
/**
* 查询关联设备数据
*
* @param dataId 关联设备数据ID
* @return 关联设备数据
*/
TRelationDeviceData selectTRelationDeviceDataById(Long dataId);
/**
* 查询关联设备数据列表
*
* @param tRelationDeviceData 关联设备数据
* @return 关联设备数据集合
*/
List<TRelationDeviceData> selectTRelationDeviceDataList(TRelationDeviceData tRelationDeviceData);
/**
* 新增关联设备数据
*
* @param tRelationDeviceData 关联设备数据
* @return 结果
*/
int insertTRelationDeviceData(TRelationDeviceData tRelationDeviceData);
/**
* 修改关联设备数据
*
* @param tRelationDeviceData 关联设备数据
* @return 结果
*/
int updateTRelationDeviceData(TRelationDeviceData tRelationDeviceData);
/**
* 批量删除关联设备数据
*
* @param dataIds 需要删除的关联设备数据ID
* @return 结果
*/
int deleteTRelationDeviceDataByIds(Long[] dataIds);
/**
* 删除关联设备数据信息
*
* @param dataId 关联设备数据ID
* @return 结果
*/
int deleteTRelationDeviceDataById(Long dataId);
}
package com.zehong.gassdevicereport.service;
import com.zehong.gassdevicereport.entity.TRelationDeviceInfo;
import java.util.List;
/**
* 关联设备Service接口
*
* @author zehong
* @date 2023-03-27
*/
public interface ITRelationDeviceInfoService {
/**
* 查询关联设备
*
* @param relationId 关联设备ID
* @return 关联设备
*/
TRelationDeviceInfo selectTRelationDeviceInfoById(Long relationId);
/**
* 查询关联设备列表
*
* @param tRelationDeviceInfo 关联设备
* @return 关联设备集合
*/
List<TRelationDeviceInfo> selectTRelationDeviceInfoList(TRelationDeviceInfo tRelationDeviceInfo);
/**
* 新增关联设备
*
* @param tRelationDeviceInfo 关联设备
* @return 结果
*/
int insertTRelationDeviceInfo(TRelationDeviceInfo tRelationDeviceInfo);
/**
* 修改关联设备
*
* @param tRelationDeviceInfo 关联设备
* @return 结果
*/
int updateTRelationDeviceInfo(TRelationDeviceInfo tRelationDeviceInfo);
/**
* 批量删除关联设备
*
* @param relationIds 需要删除的关联设备ID
* @return 结果
*/
int deleteTRelationDeviceInfoByIds(Long[] relationIds);
/**
* 删除关联设备信息
*
* @param relationId 关联设备ID
* @return 结果
*/
int deleteTRelationDeviceInfoById(Long relationId);
List<TRelationDeviceInfo> getDeviceInfoByDeviceCode(String deviceCode);
}
package com.zehong.gassdevicereport.service.impl;
import com.zehong.gassdevicereport.dao.TRelationDeviceDataDao;
import com.zehong.gassdevicereport.entity.TRelationDeviceData;
import com.zehong.gassdevicereport.service.ITRelationDeviceDataService;
import com.zehong.gassdevicereport.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* 关联设备数据Service业务层处理
*
* @author zehong
* @date 2023-03-27
*/
@Service
public class TRelationDeviceDataServiceImpl implements ITRelationDeviceDataService {
@Resource
private TRelationDeviceDataDao tRelationDeviceDataDao;
/**
* 查询关联设备数据
*
* @param dataId 关联设备数据ID
* @return 关联设备数据
*/
@Override
public TRelationDeviceData selectTRelationDeviceDataById(Long dataId) {
return tRelationDeviceDataDao.selectTRelationDeviceDataById(dataId);
}
/**
* 查询关联设备数据列表
*
* @param tRelationDeviceData 关联设备数据
* @return 关联设备数据
*/
@Override
public List<TRelationDeviceData> selectTRelationDeviceDataList(TRelationDeviceData tRelationDeviceData) {
return tRelationDeviceDataDao.selectTRelationDeviceDataList(tRelationDeviceData);
}
/**
* 新增关联设备数据
*
* @param tRelationDeviceData 关联设备数据
* @return 结果
*/
@Override
public int insertTRelationDeviceData(TRelationDeviceData tRelationDeviceData) {
tRelationDeviceData.setCreateTime(DateUtils.getNowDate());
return tRelationDeviceDataDao.insertTRelationDeviceData(tRelationDeviceData);
}
/**
* 修改关联设备数据
*
* @param tRelationDeviceData 关联设备数据
* @return 结果
*/
@Override
public int updateTRelationDeviceData(TRelationDeviceData tRelationDeviceData) {
tRelationDeviceData.setUpdateTime(DateUtils.getNowDate());
return tRelationDeviceDataDao.updateTRelationDeviceData(tRelationDeviceData);
}
/**
* 批量删除关联设备数据
*
* @param dataIds 需要删除的关联设备数据ID
* @return 结果
*/
@Override
public int deleteTRelationDeviceDataByIds(Long[] dataIds) {
return tRelationDeviceDataDao.deleteTRelationDeviceDataByIds(dataIds);
}
/**
* 删除关联设备数据信息
*
* @param dataId 关联设备数据ID
* @return 结果
*/
@Override
public int deleteTRelationDeviceDataById(Long dataId) {
return tRelationDeviceDataDao.deleteTRelationDeviceDataById(dataId);
}
}
package com.zehong.gassdevicereport.service.impl;
import com.zehong.gassdevicereport.dao.TRelationDeviceInfoDao;
import com.zehong.gassdevicereport.entity.TRelationDeviceInfo;
import com.zehong.gassdevicereport.service.ITRelationDeviceInfoService;
import com.zehong.gassdevicereport.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 关联设备Service业务层处理
*
* @author zehong
* @date 2023-03-27
*/
@Service
public class TRelationDeviceInfoServiceImpl implements ITRelationDeviceInfoService {
@Autowired
private TRelationDeviceInfoDao tRelationDeviceInfoDao;
/**
* 查询关联设备
*
* @param relationId 关联设备ID
* @return 关联设备
*/
@Override
public TRelationDeviceInfo selectTRelationDeviceInfoById(Long relationId) {
return tRelationDeviceInfoDao.selectTRelationDeviceInfoById(relationId);
}
/**
* 查询关联设备列表
*
* @param tRelationDeviceInfo 关联设备
* @return 关联设备
*/
@Override
public List<TRelationDeviceInfo> selectTRelationDeviceInfoList(TRelationDeviceInfo tRelationDeviceInfo) {
return tRelationDeviceInfoDao.selectTRelationDeviceInfoList(tRelationDeviceInfo);
}
/**
* 新增关联设备
*
* @param tRelationDeviceInfo 关联设备
* @return 结果
*/
@Override
public int insertTRelationDeviceInfo(TRelationDeviceInfo tRelationDeviceInfo) {
tRelationDeviceInfo.setCreateTime(DateUtils.getNowDate());
return tRelationDeviceInfoDao.insertTRelationDeviceInfo(tRelationDeviceInfo);
}
/**
* 修改关联设备
*
* @param tRelationDeviceInfo 关联设备
* @return 结果
*/
@Override
public int updateTRelationDeviceInfo(TRelationDeviceInfo tRelationDeviceInfo) {
tRelationDeviceInfo.setUpdateTime(DateUtils.getNowDate());
return tRelationDeviceInfoDao.updateTRelationDeviceInfo(tRelationDeviceInfo);
}
/**
* 批量删除关联设备
*
* @param relationIds 需要删除的关联设备ID
* @return 结果
*/
@Override
public int deleteTRelationDeviceInfoByIds(Long[] relationIds) {
return tRelationDeviceInfoDao.deleteTRelationDeviceInfoByIds(relationIds);
}
/**
* 删除关联设备信息
*
* @param relationId 关联设备ID
* @return 结果
*/
@Override
public int deleteTRelationDeviceInfoById(Long relationId) {
return tRelationDeviceInfoDao.deleteTRelationDeviceInfoById(relationId);
}
@Override
public List<TRelationDeviceInfo> getDeviceInfoByDeviceCode(String deviceCode){
return tRelationDeviceInfoDao.getDeviceInfoByDeviceCode(deviceCode);
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zehong.gassdevicereport.dao.TRelationDeviceDataDao">
<resultMap type="TRelationDeviceData" id="TRelationDeviceDataResult">
<result property="dataId" column="data_id" />
<result property="deviceCode" column="device_code" />
<result property="status" column="status" />
<result property="potency" column="potency" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
<result property="isDel" column="is_del" />
<result property="remark" column="remark" />
</resultMap>
<sql id="selectTRelationDeviceDataVo">
select data_id, device_code, status, potency, create_time, update_time, is_del, remark from t_relation_device_data
</sql>
<select id="selectTRelationDeviceDataList" parameterType="TRelationDeviceData" resultMap="TRelationDeviceDataResult">
<include refid="selectTRelationDeviceDataVo"/>
<where>
<if test="deviceCode != null "> and device_code = #{deviceCode}</if>
<if test="status != null and status != ''"> and status = #{status}</if>
<if test="potency != null "> and potency = #{potency}</if>
<if test="isDel != null and isDel != ''"> and is_del = #{isDel}</if>
</where>
</select>
<select id="selectTRelationDeviceDataById" parameterType="Long" resultMap="TRelationDeviceDataResult">
<include refid="selectTRelationDeviceDataVo"/>
where data_id = #{dataId}
</select>
<insert id="insertTRelationDeviceData" parameterType="TRelationDeviceData" useGeneratedKeys="true" keyProperty="dataId">
insert into t_relation_device_data
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="deviceCode != null">device_code,</if>
<if test="status != null">status,</if>
<if test="potency != null">potency,</if>
<if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if>
<if test="isDel != null">is_del,</if>
<if test="remark != null">remark,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="deviceCode != null">#{deviceCode},</if>
<if test="status != null">#{status},</if>
<if test="potency != null">#{potency},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="isDel != null">#{isDel},</if>
<if test="remark != null">#{remark},</if>
</trim>
</insert>
<update id="updateTRelationDeviceData" parameterType="TRelationDeviceData">
update t_relation_device_data
<trim prefix="SET" suffixOverrides=",">
<if test="deviceCode != null">device_code = #{deviceCode},</if>
<if test="status != null">status = #{status},</if>
<if test="potency != null">potency = #{potency},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="isDel != null">is_del = #{isDel},</if>
<if test="remark != null">remark = #{remark},</if>
</trim>
where data_id = #{dataId}
</update>
<delete id="deleteTRelationDeviceDataById" parameterType="Long">
delete from t_relation_device_data where data_id = #{dataId}
</delete>
<delete id="deleteTRelationDeviceDataByIds" parameterType="String">
delete from t_relation_device_data where data_id in
<foreach item="dataId" collection="array" open="(" separator="," close=")">
#{dataId}
</foreach>
</delete>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zehong.gassdevicereport.dao.TRelationDeviceInfoDao">
<resultMap type="TRelationDeviceInfo" id="TRelationDeviceInfoResult">
<result property="relationId" column="relation_id" />
<result property="relationDeviceId" column="relation_device_id" />
<result property="deviceName" column="device_name" />
<result property="deviceCode" column="device_code" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
<result property="isDel" column="is_del" />
<result property="remark" column="remark" />
<result property="deviceType" column="device_type"/>
<result property="deviceId" column="device_id"/>
</resultMap>
<sql id="selectTRelationDeviceInfoVo">
select relation_id, relation_device_id, device_name, device_code, create_time, update_time, is_del, remark from t_relation_device_info
</sql>
<select id="selectTRelationDeviceInfoList" parameterType="TRelationDeviceInfo" resultMap="TRelationDeviceInfoResult">
<include refid="selectTRelationDeviceInfoVo"/>
<where>
<if test="relationDeviceId != null "> and relation_device_id = #{relationDeviceId}</if>
<if test="deviceName != null and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if>
<if test="deviceCode != null and deviceCode != ''"> and device_code = #{deviceCode}</if>
<if test="isDel != null and isDel != ''"> and is_del = #{isDel}</if>
</where>
</select>
<select id="selectTRelationDeviceInfoById" parameterType="Long" resultMap="TRelationDeviceInfoResult">
<include refid="selectTRelationDeviceInfoVo"/>
where relation_id = #{relationId}
</select>
<insert id="insertTRelationDeviceInfo" parameterType="TRelationDeviceInfo" useGeneratedKeys="true" keyProperty="relationId">
insert into t_relation_device_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="relationDeviceId != null">relation_device_id,</if>
<if test="deviceName != null">device_name,</if>
<if test="deviceCode != null">device_code,</if>
<if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if>
<if test="isDel != null">is_del,</if>
<if test="remark != null">remark,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="relationDeviceId != null">#{relationDeviceId},</if>
<if test="deviceName != null">#{deviceName},</if>
<if test="deviceCode != null">#{deviceCode},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="isDel != null">#{isDel},</if>
<if test="remark != null">#{remark},</if>
</trim>
</insert>
<update id="updateTRelationDeviceInfo" parameterType="TRelationDeviceInfo">
update t_relation_device_info
<trim prefix="SET" suffixOverrides=",">
<if test="relationDeviceId != null">relation_device_id = #{relationDeviceId},</if>
<if test="deviceName != null">device_name = #{deviceName},</if>
<if test="deviceCode != null">device_code = #{deviceCode},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="isDel != null">is_del = #{isDel},</if>
<if test="remark != null">remark = #{remark},</if>
</trim>
where relation_id = #{relationId}
</update>
<delete id="deleteTRelationDeviceInfoById" parameterType="Long">
delete from t_relation_device_info where relation_id = #{relationId}
</delete>
<delete id="deleteTRelationDeviceInfoByIds" parameterType="String">
delete from t_relation_device_info where relation_id in
<foreach item="relationId" collection="array" open="(" separator="," close=")">
#{relationId}
</foreach>
</delete>
<select id="getDeviceInfoByDeviceCode" parameterType="java.lang.String" resultMap="TRelationDeviceInfoResult">
SELECT
device.device_type,
device.device_id
FROM
t_relation_device_info relation
LEFT JOIN t_device_info device ON device.device_id = relation.relation_device_id
WHERE relation.device_code = #{deviceCode}
</select>
</mapper>
\ No newline at end of file
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