ssm学习2

本文介绍了一个设备网关注册消息的处理流程,包括解析XML格式的消息内容、更新数据库中的设备状态,并返回相应的配置参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 http://blog.youkuaiyun.com/jaune161/article/details/17640071



 <select id="selectBySn" parameterType="java.lang.String" resultMap="BaseResultMap">

    select 
    <include refid="Base_Column_List" />
    from table_device_gw
    where sn = #{sn,jdbcType=VARCHAR}

  </select>

controller:

String handleRegMsg(HttpServletRequest request) throws UnsupportedEncodingException{
String type = request.getParameter("type");
String content = request.getParameter("content");

String parseStr = new String(Base64.decode(content), "UTF-8");


System.out.println("type="+type+"parseStr=\r\n"+parseStr);

String strRet = "";
if(type.equals("2"))
{

strRet =  deviceGwService.handleRegMsg(parseStr);
}
else if(type.equals("3"))
{
strRet = deviceGwService.handle_cur_JiaYouQiang(parseStr);
}
else
strRet = "haha";

return Base64.encode(strRet.getBytes());

}


DeviceGw

    public void Init() {
id = 0;


sn = "";


name = "";


comment = "";


regionid = "";


version = "";


ip = "";


locProvince = "";


locCity = "";


sdspace = 0;


faban = 0;


almax = 0;


almin = 0;


ylhigh = 0;


yllow = 0;


logsw = 0;


logudp = 0;


loglevel = 0;


gwDate = "";


lastlogin = "";


autoupver = 0;


reboot = 0;


ctlparm = 0;


ltime = 0;


edit = "";


}
    
public void setNull() {
id = null;


sn = null;


name = null;


comment = null;


regionid = null;


version = null;


ip = null;


locProvince = null;


locCity = null;


sdspace = null;


faban = null;


almax = null;


almin = null;


ylhigh = null;


yllow = null;


logsw = null;


logudp = null;


loglevel = null;


gwDate = null;


lastlogin = null;


autoupver = null;


reboot = null;


ctlparm = null;


ltime = null;


edit = null;


}


package com.cn.hnust.service.impl;


import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.List;


import javax.annotation.Resource;


import org.springframework.stereotype.Service;


import com.cn.hnust.controller.Base64;
import com.cn.hnust.controller.DOMParser;
import com.cn.hnust.dao.ICnjyqDao;
import com.cn.hnust.dao.IDeviceGwDao;
import com.cn.hnust.dao.IDeviceGwSetDao;
import com.cn.hnust.pojo.Cnjyq;
import com.cn.hnust.pojo.DeviceGw;
import com.cn.hnust.pojo.DeviceGwSet;
import com.cn.hnust.service.IDeviceGwService;


import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;


import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;


@Service("deviceGwService")
public class DeviceGwServiceImpl implements IDeviceGwService {
@Resource
private IDeviceGwDao deviceGwDao;


@Resource
private IDeviceGwSetDao deviceGwSetDao;

@Resource
private ICnjyqDao cnjyqDao;


@Override
public List<DeviceGw> getAllDeviceGws() {
return deviceGwDao.getAllDeviceGws();
}




public void handleRegMsg1(String content) throws UnsupportedEncodingException {
System.out.println("cme");
DeviceGw dev1 = deviceGwDao.selectBySn("0102020102010120");
System.out.println(dev1.getName());

DeviceGw gw = new DeviceGw();


gw.setNull();
gw.setId(dev1.getId());
gw.setGwDate("longlongago");





gw.setLtime(0);


deviceGwDao.updateByPrimaryKeySelective(gw);
return;
}

@Override
public String handleRegMsg(String parseStr) throws UnsupportedEncodingException {
/*
System.out.println("cme");
DeviceGw dev1 = deviceGwDao.selectBySn("00112233445515100100004");
System.out.println(dev1.getName());
return;
*/

String autoupver="";

Document doc = DOMParser.parse(parseStr);


String sfaban = doc.getElementsByTagName("FaBan").item(0).getFirstChild().getNodeValue();
String salmax = doc.getElementsByTagName("ALMax").item(0).getFirstChild().getNodeValue();
String salmin = doc.getElementsByTagName("ALMin").item(0).getFirstChild().getNodeValue();
String sylhigh = doc.getElementsByTagName("YLHigh").item(0).getFirstChild().getNodeValue();
String syllow = doc.getElementsByTagName("YLLow").item(0).getFirstChild().getNodeValue();
String slogsw = doc.getElementsByTagName("LogSwit").item(0).getFirstChild().getNodeValue();
String slogudp = doc.getElementsByTagName("LogUdp").item(0).getFirstChild().getNodeValue();
String sloglevel = doc.getElementsByTagName("LogLevel").item(0).getFirstChild().getNodeValue();


String sn = doc.getElementsByTagName("SN").item(0).getFirstChild().getNodeValue();
String userid = doc.getElementsByTagName("USERID").item(0).getFirstChild().getNodeValue();
String lip = doc.getElementsByTagName("LIP").item(0).getFirstChild().getNodeValue();
String ssdspace = doc.getElementsByTagName("SPACE").item(0).getFirstChild().getNodeValue();
String rdate = doc.getElementsByTagName("DATE").item(0).getFirstChild().getNodeValue();
String ver = doc.getElementsByTagName("VER").item(0).getFirstChild().getNodeValue();
Integer sdspace = Integer.valueOf(ssdspace);


Integer faban = Integer.valueOf(sfaban);
Integer almax = Integer.valueOf(salmax);
Integer almin = Integer.valueOf(salmin);
Integer ylhigh = Integer.valueOf(sylhigh);
Integer yllow = Integer.valueOf(syllow);
Integer logsw = Integer.valueOf(slogsw);
Integer logudp = Integer.valueOf(slogudp);
Integer loglevel = Integer.valueOf(sloglevel);


System.out.println("Hello:" + parseStr);
DeviceGw dev = deviceGwDao.selectBySn(sn);
if (dev != null) {
// 更新路由器相关信息(云不能修改的)

if(dev.getAutoupver()==1)
autoupver="<VER>CNGW10 V0.1.1R27_BJ</VER>";
DeviceGw gw = new DeviceGw();
gw.setNull();
gw.setId(dev.getId());
gw.setSn(sn);
gw.setLastlogin(new Date().toString());
gw.setRegionid(userid);
gw.setVersion(ver);
gw.setIp(lip);
gw.setSdspace(sdspace);
gw.setGwDate(rdate);
gw.setLtime(0);
deviceGwDao.updateByPrimaryKeySelective(gw);
// 更新路由器上报的当前的可修改的值
DeviceGwSet set = new DeviceGwSet();
set.setNull();
set.setSn(sn);
set.setId(dev.getId());
set.setFaban(dev.getFaban());
set.setAlmax(dev.getAlmax());
set.setAlmin(dev.getAlmin());


set.setYlhigh(dev.getYlhigh());
set.setYllow(dev.getYllow());
set.setLogsw(dev.getLogsw());
set.setLogudp(dev.getLogudp());
set.setLoglevel(dev.getLoglevel());


deviceGwSetDao.updateByPrimaryKeySelective(set);
} else {
DeviceGw gw = new DeviceGw();
gw.Init();
//gw.setId(dev.getId());
gw.setSn(sn);
gw.setRegionid(userid);
gw.setVersion(ver);
gw.setIp(lip);
gw.setSdspace(sdspace);

gw.setFaban(faban);
gw.setAlmax(almax);
gw.setAlmin(almin);


gw.setYlhigh(ylhigh);
gw.setYllow(yllow);
gw.setLogsw((byte) logsw.intValue());
gw.setLogudp((byte) logudp.intValue());
gw.setLoglevel((byte) loglevel.intValue());



gw.setGwDate(rdate);
gw.setLastlogin(new Date().toString());
gw.setLtime(0);
deviceGwDao.insert(gw);

DeviceGwSet set = new DeviceGwSet();
//set.setNull();
set.setSn(sn);
set.setFaban(faban);
set.setAlmax(almax);
set.setAlmin(almin);


set.setYlhigh(ylhigh);
set.setYllow(yllow);
set.setLogsw((byte) logsw.intValue());
set.setLogudp((byte) logudp.intValue());
set.setLoglevel((byte) loglevel.intValue());


deviceGwSetDao.insert(set);
}

String ret_pre="<?xml version='1.0' encoding='US-ASCII'?><RSP><TYPE>2</TYPE><SN>";
ret_pre=ret_pre+sn+"</SN><USERID>"+userid+"</USERID>";
ret_pre=ret_pre+autoupver;
ret_pre=ret_pre+"<FaBan>"+ret_pre+"</FaBan><ALMax>"+almax+"</ALMax><ALMin>"+almin+"</ALMin><YLHigh>";
ret_pre=ret_pre+ylhigh+"</YLHigh><YLLow>"+yllow+"</YLLow><LogSwit>"+logsw+"</LogSwit><LogUdp>"+logudp+"</LogUdp><LogLevel>"+loglevel+"</LogLevel></RSP>";


return ret_pre;
}

@Override
public String handle_cur_JiaYouQiang(String parseStr) throws UnsupportedEncodingException
{
Document doc = DOMParser.parse(parseStr);


String sn = doc.getElementsByTagName("SN").item(0).getFirstChild().getNodeValue();
String userid = doc.getElementsByTagName("USERID").item(0).getFirstChild().getNodeValue();

String rawdata = doc.getElementsByTagName("CONTENT").item(0).getFirstChild().getNodeValue();
String[] strJYQs = rawdata.split(":");
if(strJYQs.length< 16)
return "";

String JYQID=strJYQs[5];

Float ALf=Float.parseFloat(strJYQs[7]);
Integer AL=(int)(ALf*100);

Float QLLf=Float.parseFloat(strJYQs[11]);
Integer QLL=(int)(QLLf*100);


Float YLLf=Float.parseFloat(strJYQs[15]);
Integer YLL=(int)(YLLf*100);

//还有一个tha式子---

Cnjyq cn = new Cnjyq();


cnjyqDao.updateByPrimaryKeySelective(cn);
//insert
return "";
}
}




http://download.youkuaiyun.com/download/zhanglikui/7665823


内容概要:该研究通过在黑龙江省某示范村进行24小时实地测试,比较了燃煤炉具与自动/手动进料生物质炉具的污染物排放特征。结果显示,生物质炉具相比燃煤炉具显著降低了PM2.5、CO和SO2的排放(自动进料分别降低41.2%、54.3%、40.0%;手动进料降低35.3%、22.1%、20.0%),但NOx排放未降低甚至有所增加。研究还发现,经济性和便利性是影响生物质炉具推广的重要因素。该研究不仅提供了实际排放数据支持,还通过Python代码详细复现了排放特征比较、减排效果计算和结果可视化,进一步探讨了燃料性质、动态排放特征、碳平衡计算以及政策建议。 适合人群:从事环境科学研究的学者、政府环保部门工作人员、能源政策制定者、关注农村能源转型的社会人士。 使用场景及目标:①评估生物质炉具在农村地区的推广潜力;②为政策制定者提供科学依据,优化补贴政策;③帮助研究人员深入了解生物质炉具的排放特征和技术改进方向;④为企业研发更高效的生物质炉具提供参考。 其他说明:该研究通过大量数据分析和模拟,揭示了生物质炉具在实际应用中的优点和挑战,特别是NOx排放增加的问题。研究还提出了多项具体的技术改进方向和政策建议,如优化进料方式、提高热效率、建设本地颗粒厂等,为生物质炉具的广泛推广提供了可行路径。此外,研究还开发了一个智能政策建议生成系统,可以根据不同地区的特征定制化生成政策建议,为农村能源转型提供了有力支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值