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