Commit 0f52ca5c authored by wangjinjing's avatar wangjinjing

添加推送设备功能

parent eb774678
...@@ -60,16 +60,21 @@ public class ScheduleTaskConfig { ...@@ -60,16 +60,21 @@ public class ScheduleTaskConfig {
} }
@Scheduled(cron = "0 */2 * * * ?")//每2分钟执行一次 // @Scheduled(cron = "0 */2 * * * ?")//每2分钟执行一次
private void sendToguangda() { private void sendToguangda() {
//查询所有未推送的数据 //查询所有未推送的数据
List<Traffalarmrecord> resultlist=traffalarmrecordService.getTraffalarmrecordBystatus(); List<Traffalarmrecord> resultlist=traffalarmrecordService.getTraffalarmrecordBystatus();
for(Traffalarmrecord record:resultlist) for(Traffalarmrecord record:resultlist)
{ {
ResultObj obj = eventWriteService.updateAndAutoSendEvent(record); try {
if (obj.getStatus() != 200) { ResultObj obj = eventWriteService.updateAndAutoSendEvent(record);
log.error(record.getRecordid()+" send to guangda fail"); if (obj.getStatus() != 200) {
log.error(record.getRecordid() + " send to guangda fail");
} else {
log.info(record.getRecordid() + " send to guangda success");
}
}catch (Exception ex){
log.error(record.getRecordid() + " send to guangda fail"+ex.toString());
} }
} }
......
...@@ -62,17 +62,17 @@ public class TraffdevicewriteresultService { ...@@ -62,17 +62,17 @@ public class TraffdevicewriteresultService {
Traffdevicewriteresult param = new Traffdevicewriteresult(); Traffdevicewriteresult param = new Traffdevicewriteresult();
for (SbtdspsrParams val : sbtdspsrs) { for (SbtdspsrParams val : sbtdspsrs) {
threadService.submit(() -> { //threadService.submit(() -> {
// log.info("sendtoguangda"+val.toString()); log.info("sendtoguangda"+val.toString());
ResultObj obj = sendToGuangda(val, param); ResultObj obj = sendToGuangda(val, param);
obj.setData(val.getSbbh() + "_" + val.getTdbh()); obj.setData(val.getXh());
return obj; resultObj.add( obj);
}); // });
}
for (int i = 0; i < sbtdspsrs.size(); i++) {
resultObj.add(threadService.poll(10, TimeUnit.SECONDS).get());
} }
// for (int i = 0; i < sbtdspsrs.size(); i++) {
// resultObj.add(threadService.poll(10, TimeUnit.SECONDS).get());
// }
} catch (Exception e) { } catch (Exception e) {
log.error("devicewrite - sendEvent 异常:" + e.toString()); log.error("devicewrite - sendEvent 异常:" + e.toString());
...@@ -81,7 +81,7 @@ public class TraffdevicewriteresultService { ...@@ -81,7 +81,7 @@ public class TraffdevicewriteresultService {
return resultObj; return resultObj;
} }
public ResultObj sendToGuangda(SbtdspsrParams val, Traffdevicewriteresult param) throws Exception { public ResultObj sendToGuangda(SbtdspsrParams val, Traffdevicewriteresult param){
if (val.getXzbh() == null) { if (val.getXzbh() == null) {
log.error("deviceWritePost {} : regist remsg...", "设备所属单位机构编码必填"); log.error("deviceWritePost {} : regist remsg...", "设备所属单位机构编码必填");
return ResultObj.error(ResponseEnum.E_1002.getCode(), "设备所属单位机构编码必填"); return ResultObj.error(ResponseEnum.E_1002.getCode(), "设备所属单位机构编码必填");
......
...@@ -33,8 +33,8 @@ public class FTPUtil { ...@@ -33,8 +33,8 @@ public class FTPUtil {
@PostConstruct @PostConstruct
private void initHostMap(){ private void initHostMap(){
if(ftpHost==null){ if(ftpHost==null){
log.error("ftp存储组未配置,请先配置"); log.error("ftp�洢��δ���ã���������");
log.error("ftp存储组未配置,请先配置"); log.error("ftp�洢��δ���ã���������");
return; return;
} }
...@@ -57,7 +57,7 @@ public class FTPUtil { ...@@ -57,7 +57,7 @@ public class FTPUtil {
return; return;
} }
} catch (Exception e) { } catch (Exception e) {
log.error("FTP下载图片出错", e); log.error("FTP����ͼƬ����", e);
} finally { } finally {
IOUtils.closeQuietly(toClient); IOUtils.closeQuietly(toClient);
IOUtils.closeQuietly(is); IOUtils.closeQuietly(is);
...@@ -70,25 +70,29 @@ public class FTPUtil { ...@@ -70,25 +70,29 @@ public class FTPUtil {
try { try {
url = new URL(path); url = new URL(path);
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
log.error("FTP URL路径错误"+e.toString()); log.error("FTP URL error"+e.toString());
} }
byte[] buffer = null; byte[] buffer = null;
try (InputStream is = url.openStream();ByteArrayOutputStream bos = new ByteArrayOutputStream(1000)){ try {
byte[] b = new byte[1000]; InputStream is = url.openStream();
int n; if(null!=is) {
while ((n = is.read(b)) != -1) { ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);
bos.write(b, 0, n); byte[] b = new byte[1000];
int n;
while ((n = is.read(b)) != -1) {
bos.write(b, 0, n);
}
buffer = bos.toByteArray();
} }
buffer = bos.toByteArray();
}catch (Exception e) { }catch (Exception e) {
log.error("FTP下载图片出错", e); log.error("FTPerror", e);
} }
return buffer; return buffer;
} }
//ftp图片上传,图片参数为base64封装的String //ftpͼƬ�ϴ���ͼƬ����Ϊbase64��װ��String
public static boolean uploadFile(Ftp ftpUrl, String path, String filename, String inputImg) { public static boolean uploadFile(Ftp ftpUrl, String path, String filename, String inputImg) {
boolean flag = true; boolean flag = true;
FTPClient ftpClient = null; FTPClient ftpClient = null;
...@@ -97,7 +101,7 @@ public class FTPUtil { ...@@ -97,7 +101,7 @@ public class FTPUtil {
if (inputImg == null) { if (inputImg == null) {
return false; return false;
} }
//base64解码 //base64����
BASE64Decoder decoder = new BASE64Decoder(); BASE64Decoder decoder = new BASE64Decoder();
byte[] b_img = decoder.decodeBuffer(inputImg); byte[] b_img = decoder.decodeBuffer(inputImg);
input = new ByteArrayInputStream(b_img); input = new ByteArrayInputStream(b_img);
...@@ -107,15 +111,15 @@ public class FTPUtil { ...@@ -107,15 +111,15 @@ public class FTPUtil {
changeWorkingDirectory(ftpClient, path); changeWorkingDirectory(ftpClient, path);
flag = ftpClient.storeFile(filename, input); flag = ftpClient.storeFile(filename, input);
if (flag) { if (flag) {
// log.info("FTP上传文件成功!"); // log.info("FTP�ϴ��ļ��ɹ���");
} else { } else {
flag = false; flag = false;
log.info("FTP上传文件失败!"); log.info("FTP�ϴ��ļ�ʧ�ܣ�");
} }
} }
} catch (Exception e) { } catch (Exception e) {
flag = false; flag = false;
log.error("FTP文件上传失败!", e.toString()); log.error("FTP�ļ��ϴ�ʧ�ܣ�", e.toString());
} finally { } finally {
IOUtils.closeQuietly(input); IOUtils.closeQuietly(input);
closeConnect(ftpClient); closeConnect(ftpClient);
...@@ -132,20 +136,20 @@ public class FTPUtil { ...@@ -132,20 +136,20 @@ public class FTPUtil {
changeWorkingDirectory(ftpClient, path); changeWorkingDirectory(ftpClient, path);
flag = ftpClient.storeFile(filename, input); flag = ftpClient.storeFile(filename, input);
if (flag) { if (flag) {
// log.info("FTP upload success"); // log.info("FTP upload success��");
} else { } else {
log.info("FTP upload fail"); log.info("FTP upload fail��");
} }
} else { } else {
flag = false; flag = false;
// log.info("FTP server refused connection "); // log.info("FTP server refused connection ��");
} }
} catch (IOException e) { } catch (IOException e) {
flag = false; flag = false;
log.error("FTP upload fail", e); log.error("FTP upload fail��", e);
} catch (Exception e) { } catch (Exception e) {
flag = false; flag = false;
log.error("FTP upload fail", e); log.error("FTP upload fail��", e);
} finally { } finally {
IOUtils.closeQuietly(input); IOUtils.closeQuietly(input);
closeConnect(ftpClient); closeConnect(ftpClient);
...@@ -154,7 +158,7 @@ public class FTPUtil { ...@@ -154,7 +158,7 @@ public class FTPUtil {
} }
/* /*
* 得到配置文件中的FTP服务器地 * �õ������ļ��е�FTP��������ַ
*/ */
public static String getFtpUrl(Ftp ftpUrl) { public static String getFtpUrl(Ftp ftpUrl) {
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
...@@ -179,13 +183,13 @@ public class FTPUtil { ...@@ -179,13 +183,13 @@ public class FTPUtil {
* @param ftpUrl * @param ftpUrl
* @return * @return
* @throws Exception * @throws Exception
* @description 删除ftp上的文件 * @description ɾ��ftp�ϵ��ļ�
* @author sunw * @author sunw
*/ */
public static boolean deleteFileFromFtpUrl(String ftpUrl) throws Exception { public static boolean deleteFileFromFtpUrl(String ftpUrl) throws Exception {
boolean flag = false; boolean flag = false;
if (null == ftpUrl || StringUtils.isBlank(ftpUrl)) { if (null == ftpUrl || StringUtils.isBlank(ftpUrl)) {
throw new Exception("ftpUrl串为空"); throw new Exception("ftpUrl��Ϊ��");
} }
Map<String, String> result = getFtpInfoMapByFullPath(ftpUrl); Map<String, String> result = getFtpInfoMapByFullPath(ftpUrl);
String ftpUser = result.get("ftpUser"); String ftpUser = result.get("ftpUser");
...@@ -197,7 +201,7 @@ public class FTPUtil { ...@@ -197,7 +201,7 @@ public class FTPUtil {
Ftp ftp = FTPUtil.getFtpUrlObj(ftpIp, ftpPort, ftpUser, ftpPassword); Ftp ftp = FTPUtil.getFtpUrlObj(ftpIp, ftpPort, ftpUser, ftpPassword);
FTPClient ftpClient = connectServer(ftp); FTPClient ftpClient = connectServer(ftp);
if (null == ftpClient) { if (null == ftpClient) {
throw new Exception("ftp登录失败 "); throw new Exception("ftp��¼ʧ�� ");
} else { } else {
String fullPath = (null == path || "".equals(path.trim())) ? fileName : (path + "/" + fileName); String fullPath = (null == path || "".equals(path.trim())) ? fileName : (path + "/" + fileName);
try { try {
...@@ -215,12 +219,12 @@ public class FTPUtil { ...@@ -215,12 +219,12 @@ public class FTPUtil {
* @param ftpUrlStr * @param ftpUrlStr
* @return * @return
* @throws Exception * @throws Exception
* @author sunw 通过图片路径 * @author sunw ͨ��ͼƬ·��
* 获得ftpuser,ftppassword,ftpip,ftpport,在fpt上的文件路径,文件realname * ���ftpuser,ftppassword,ftpip,ftpport,��fpt�ϵ��ļ�·��,�ļ�realname
*/ */
private static Map<String, String> getFtpInfoMapByFullPath(String ftpUrlStr) throws Exception { private static Map<String, String> getFtpInfoMapByFullPath(String ftpUrlStr) throws Exception {
if (null == ftpUrlStr || "".equals(ftpUrlStr.trim())) { if (null == ftpUrlStr || "".equals(ftpUrlStr.trim())) {
throw new Exception("ftpstr串为空"); throw new Exception("ftpstr��Ϊ��");
} }
ftpUrlStr = ftpUrlStr.replaceAll("\\\\", "/"); ftpUrlStr = ftpUrlStr.replaceAll("\\\\", "/");
ftpUrlStr = changeUrlCharater(ftpUrlStr); ftpUrlStr = changeUrlCharater(ftpUrlStr);
...@@ -232,7 +236,7 @@ public class FTPUtil { ...@@ -232,7 +236,7 @@ public class FTPUtil {
String ftpPassword = ftpUserAndPassword[1]; String ftpPassword = ftpUserAndPassword[1];
String ftpIp = ftpIpAndPort[0]; String ftpIp = ftpIpAndPort[0];
String ftpPort = ftpIpAndPort.length > 1 ? ftpIpAndPort[1] : ""; String ftpPort = ftpIpAndPort.length > 1 ? ftpIpAndPort[1] : "";
String fileName = array[array.length - 1];// 获得文件名 String fileName = array[array.length - 1];// ����ļ���
Map<String, String> resultMap = new HashMap<String, String>(); Map<String, String> resultMap = new HashMap<String, String>();
resultMap.put("ftpUser", ftpUser); resultMap.put("ftpUser", ftpUser);
resultMap.put("ftpPassword", ftpPassword); resultMap.put("ftpPassword", ftpPassword);
...@@ -257,7 +261,7 @@ public class FTPUtil { ...@@ -257,7 +261,7 @@ public class FTPUtil {
boolean flag = deleteFileFromFtpUrl(temp); boolean flag = deleteFileFromFtpUrl(temp);
System.out.println(flag); System.out.println(flag);
} catch (Exception e) { } catch (Exception e) {
System.out.println("删除文件失败"); System.out.println(���ļ�ʧ��");
} }
// String [] strSplit = temp.split("/"); // String [] strSplit = temp.split("/");
// for(int i = 0 ; i < strSplit.length ; i++) { // for(int i = 0 ; i < strSplit.length ; i++) {
...@@ -272,7 +276,7 @@ public class FTPUtil { ...@@ -272,7 +276,7 @@ public class FTPUtil {
} }
/** /**
* 连接到服务器 * ���ӵ�������
*/ */
private static FTPClient connectServer(Ftp ftpUrl) { private static FTPClient connectServer(Ftp ftpUrl) {
FTPClient ftpClient = null; FTPClient ftpClient = null;
...@@ -292,18 +296,18 @@ public class FTPUtil { ...@@ -292,18 +296,18 @@ public class FTPUtil {
if (!FTPReply.isPositiveCompletion(reply)) { if (!FTPReply.isPositiveCompletion(reply)) {
ftpClient.disconnect(); ftpClient.disconnect();
System.err.println("FTP server refused connection."); System.err.println("FTP server refused connection.");
log.info("FTP 服务拒绝连接!"); log.info("FTP ����ܾ����ӣ�");
} }
} catch (SocketException e) { } catch (SocketException e) {
log.error("登录ftp服务器 " + ftpUrl.getFtpIp() + " 失败,连接超时!", e); log.error("��¼ftp������ " + ftpUrl.getFtpIp() + " ʧ��,���ӳ�ʱ��", e);
} catch (IOException e) { } catch (IOException e) {
log.error("登录ftp服务器 " + ftpUrl.getFtpIp() + " 失败,FTP服务器无法打开!", e); log.error("��¼ftp������ " + ftpUrl.getFtpIp() + " ʧ�ܣ�FTP�������޷��򿪣�", e);
} }
return ftpClient; return ftpClient;
} }
/** /**
* 关闭连接 * �ر�����
*/ */
private static void closeConnect(FTPClient ftpClient) { private static void closeConnect(FTPClient ftpClient) {
try { try {
...@@ -314,12 +318,12 @@ public class FTPUtil { ...@@ -314,12 +318,12 @@ public class FTPUtil {
ftpClient.disconnect(); ftpClient.disconnect();
} }
} catch (Exception e) { } catch (Exception e) {
log.error("关闭ftp连接失败", e); log.error("�ر�ftp����ʧ��", e);
} }
} }
/** /**
* 进入到服务器的某个目录下 * ���뵽��������ij��Ŀ¼��
* *
* @param directory * @param directory
*/ */
...@@ -336,12 +340,12 @@ public class FTPUtil { ...@@ -336,12 +340,12 @@ public class FTPUtil {
ftpClient.changeWorkingDirectory(subPath); ftpClient.changeWorkingDirectory(subPath);
} }
} catch (IOException ioe) { } catch (IOException ioe) {
log.error("改变ftp工作路径失败", ioe); log.error("�ı�ftp����·��ʧ��", ioe);
} }
} }
/** /**
* 转码[ISO-8859-1 -> GBK] 不同的平台需要不同的转码 * ת��[ISO-8859-1 -> GBK] ��ͬ��ƽ̨��Ҫ��ͬ��ת��
* *
* @param obj * @param obj
* @return "" * @return ""
......
...@@ -2,25 +2,26 @@ ...@@ -2,25 +2,26 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hzjt.mapper.TraffdevicewriteresultMapper"> <mapper namespace="com.hzjt.mapper.TraffdevicewriteresultMapper">
<select id="querySbtdspsrByXh" resultType="com.hzjt.domain.SbtdspsrParams"> <select id="querySbtdspsrByXh" resultType="com.hzjt.domain.SbtdspsrParams">
SELECT select
TA.*, ta.*,
A.CREATETIME, a.createtime,
A.PUSHSTATUS, a.pushstatus,
A.PUSHCOUNT, a.pushcount,
A.REMARK, a.remark,
A.PUSHDESC, a.pushdesc,
p.dept_name AS xztreename, p.dept_name as xztreename,
B.remark1 AS deviceconfig b.remark1 as deviceconfig
FROM SBTDSPSR TA from sbtdspsr ta
LEFT JOIN TRAFFDEVICEWRITERESULT A ON A.SBBH = TA.SBBH AND A.TDBH = TA.TDBH left join traffdevicewriteresult a on a.sbbh = ta.sbbh and a.tdbh = ta.tdbh
LEFT JOIN TRAFFDEVICECONFIG B ON B.FDID = TA.SBBH AND B.CHANNELID = TA.TDBH left join traffdeviceconfig b on b.fdid = ta.sbbh and b.channelid = ta.tdbh
LEFT JOIN dept P ON P .dept_id = TA.xzbh left join dept p on p .dept_id = ta.xzbh
WHERE 1=1 <where>
<if test="xhs !=null and xhs.size>0 "> <if test="xhs !=null and xhs.size>0 ">
and TA.XH IN and TA.XH IN
<foreach item="xh" collection="xhs" open="(" separator="," close=")"> <foreach item="xh" collection="xhs" open="(" separator="," close=")">
#{xh} #{xh}
</foreach> </foreach>
</if> </if>
</where>
</select> </select>
</mapper> </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