图片报警上传方法

jni
liuguijing 2 years ago
parent 4a88fddee8
commit a8a0ce72ed

@ -7,7 +7,9 @@ import com.shxy.xymanager_common.bean.ServiceBody;
import com.shxy.xymanager_common.bean.ServiceStatus; import com.shxy.xymanager_common.bean.ServiceStatus;
import com.shxy.xymanager_common.model.DyLineTreeListModel; import com.shxy.xymanager_common.model.DyLineTreeListModel;
import com.shxy.xymanager_common.model.DyListModel; import com.shxy.xymanager_common.model.DyListModel;
import com.shxy.xymanager_common.vo.PageVo;
import com.shxy.xymanager_common.vo.TerminalIdVo; import com.shxy.xymanager_common.vo.TerminalIdVo;
import com.shxy.xymanager_common.vo.TestVo;
import com.shxy.xymanager_service.service.DyLevelService; import com.shxy.xymanager_service.service.DyLevelService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -20,6 +22,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Api(value = "电压等级接口", tags = "电压等级接口描述") @Api(value = "电压等级接口", tags = "电压等级接口描述")
@RestController @RestController
@ -54,4 +58,17 @@ public class DyLevelController extends BaseController {
return ResponseReult.error(serviceBody.getCode(), serviceBody.getMsg()); return ResponseReult.error(serviceBody.getCode(), serviceBody.getMsg());
} }
} }
@ApiOperation(value = "测试测试", notes = "测试测试", httpMethod = "POST")
@ApiResponses({@ApiResponse(code = 200, message = "请求成功"), @ApiResponse(code = 400, message = "请求参数没填好"), @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对")})
@RequestMapping("/gettest")
@Log(title = "测试测试", type = "查询")
public ResponseReult<String> gettest(@RequestBody List<TestVo> vo) {
ServiceBody<String> serviceBody = dyLevelService.gettest(vo);
if (serviceBody.getCode() == ServiceStatus.SUCCESS) {
return ResponseReult.success(serviceBody.getData());
} else {
return ResponseReult.error(serviceBody.getCode(), serviceBody.getMsg());
}
}
} }

@ -0,0 +1,81 @@
package com.shxy.xymanager_admin.test;
import java.sql.Date;
public class AlarmImgBean {
public AlarmImgBean() {
}
private Integer termid;
private Integer channelid;
private Integer orgid;
private Date time;
private String alarminfo;
private String path;
private String cmdid;
private Integer mediatype;
public Integer getMediatype() {
return mediatype;
}
public void setMediatype(Integer mediatype) {
this.mediatype = mediatype;
}
public Integer getTermid() {
return termid;
}
public void setTermid(Integer termid) {
this.termid = termid;
}
public Integer getChannelid() {
return channelid;
}
public void setChannelid(Integer channelid) {
this.channelid = channelid;
}
public Integer getOrgid() {
return orgid;
}
public void setOrgid(Integer orgid) {
this.orgid = orgid;
}
public Date getTime() {
return time;
}
public void setTime(Date time) {
this.time = time;
}
public String getAlarminfo() {
return alarminfo;
}
public void setAlarminfo(String alarminfo) {
this.alarminfo = alarminfo;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getCmdid() {
return cmdid;
}
public void setCmdid(String cmdid) {
this.cmdid = cmdid;
}
}

@ -0,0 +1,61 @@
package com.shxy.xymanager_admin.test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
public class PostUtil {
public static String sendPost(String url, String param) {
PrintWriter out = null;
BufferedReader in = null;
String result = "";
try {
URL realUrl = new URL(url);
// 打开和URL之间的连接
URLConnection conn = realUrl.openConnection();
// 设置通用的请求属性
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
// 发送POST请求必须设置如下两行
conn.setDoOutput(true);
conn.setDoInput(true);
// 获取URLConnection对象对应的输出流
out = new PrintWriter(conn.getOutputStream());
// 发送请求参数
out.print(param);
// flush输出流的缓冲
out.flush();
// 定义BufferedReader输入流来读取URL的响应
in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.err.println("发送POST请求出现异常" + e);
e.printStackTrace();
}
//使用finally块来关闭输出流、输入流
finally {
try {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
return result;
}
}

@ -0,0 +1,64 @@
package com.shxy.xymanager_admin.test;
import com.mysql.cj.xdevapi.JsonValue;
public class RequestAlarmImgBean implements JsonValue {
public RequestAlarmImgBean() {
}
private String deviceld;
private String alarmDate;
private String alarmType;
private String message;
private String picurl;
private String companyld;
public String getDeviceld() {
return deviceld;
}
public void setDeviceld(String deviceld) {
this.deviceld = deviceld;
}
public String getAlarmDate() {
return alarmDate;
}
public void setAlarmDate(String alarmDate) {
this.alarmDate = alarmDate;
}
public String getAlarmType() {
return alarmType;
}
public void setAlarmType(String alarmType) {
this.alarmType = alarmType;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getPicurl() {
return picurl;
}
public void setPicurl(String picurl) {
this.picurl = picurl;
}
public String getCompanyld() {
return companyld;
}
public void setCompanyld(String companyld) {
this.companyld = companyld;
}
}

@ -0,0 +1,120 @@
package com.shxy.xymanager_admin.test;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.mysql.cj.xdevapi.JsonArray;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
public class Test {
private static Connection con;
public static void main(String[] args) throws Exception {
String driver = "com.mysql.jdbc.Driver";
//这里我的数据库是cgjr
String url = "jdbc:mysql://47.96.238.157:3306/xymp?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8";
String user = "xymp";
String password = "Xymp@2023";
try {
Class.forName(driver);
con = DriverManager.getConnection(url, user, password);
if (!con.isClosed()) {
System.out.println("数据库连接成功");
}
Statement statement = con.createStatement();
int checkid = 0;
String checksql = "SELECT * FROM terminal_img_alarms_check where `key` = 'alarm_check';";//查询记录表
ResultSet checkresultSet = statement.executeQuery(checksql);
while (checkresultSet.next()) {
checkid = checkresultSet.getInt("value");
}
checkresultSet.close();
// 执行查询语句
String sql = String.format("SELECT * FROM v_img_alarms where id > %d;", checkid);//查询报警图片视图
ResultSet resultSet = statement.executeQuery(sql);
// 打印查询出来的东西
Integer id = null;//
List<AlarmImgBean> list = new ArrayList<>();
while (resultSet.next()) {
id = resultSet.getInt("id");
Integer termid = resultSet.getInt("term_id");
Integer channelid = resultSet.getInt("channel_id");
Integer orgid = resultSet.getInt("photo_org_id");
Date time = resultSet.getDate("alarm_time");
String alarminfo = resultSet.getString("alarm_info");
String path = resultSet.getString("path");
String cmdid = resultSet.getString("cmdid");
Integer mediatype = resultSet.getInt("media_type");
AlarmImgBean alarmImgBean = new AlarmImgBean();
alarmImgBean.setTermid(termid);
alarmImgBean.setChannelid(channelid);
alarmImgBean.setOrgid(orgid);
alarmImgBean.setTime(time);
alarmImgBean.setAlarminfo(alarminfo);
alarmImgBean.setPath(path);
alarmImgBean.setCmdid(cmdid);
alarmImgBean.setMediatype(mediatype);
list.add(alarmImgBean);
}
// 关闭连接
resultSet.close();
System.out.println("数据库已关闭连接");
if (list.size() >0) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
JsonArray jsonArray = new JsonArray();
for (AlarmImgBean item : list) {
String info = item.getAlarminfo();
JSONObject jsonObject = JSONObject.parseObject(info);
JSONArray alarmlist = jsonObject.getJSONArray("list");
for (Object ite : alarmlist) {
JSONObject jo = JSONObject.parseObject(String.valueOf(ite));
String nameCn = jo.getString("nameCn");
RequestAlarmImgBean bean = new RequestAlarmImgBean();
bean.setDeviceld(item.getCmdid());
String date = sdf.format(item.getTime());
bean.setAlarmDate(date);
bean.setAlarmType(nameCn);
bean.setMessage(nameCn);
//TODO 图片路径待完善
if (item.getMediatype() == 0) {
bean.setPicurl(item.getPath());
} else {
bean.setPicurl(item.getPath());
}
//TODO 公司id待确认
bean.setCompanyld("xy");
jsonArray.add(bean);
}
}
String s = PostUtil.sendPost("http://127.0.0.1:8093/api/gettest", JSON.toJSONString(jsonArray));
JSONObject jsonObject = JSON.parseObject(s);
if (jsonObject.getInteger("code") == 200) {
if (id != null) {
String updatesql = String.format("update terminal_img_alarms_check SET value = %d where `key` = 'alarm_check';", id);//查询报警图片视图
int i = statement.executeUpdate(updatesql);
}
} else {
System.out.println("失败");
}
}else {
System.out.println("没有需要上传的报错数据");
}
} catch (ClassNotFoundException e) {
System.out.println("数据库驱动没有安装");
} catch (SQLException e) {
System.out.println("数据库连接失败");
} catch (Exception e) {
e.printStackTrace();
} finally {
con.close();
}
}
}

@ -2,7 +2,7 @@
spring: spring:
datasource: datasource:
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://47.96.238.157:3306/xymp?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 url: jdbc:mysql://127.0.0.1:3306/xymp?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: xymp username: xymp
password: Xymp@2023 password: Xymp@2023
type: com.alibaba.druid.pool.DruidDataSource type: com.alibaba.druid.pool.DruidDataSource
@ -173,3 +173,5 @@ upload:
path: http://47.96.238.157/usr/local/home/manager/download/ path: http://47.96.238.157/usr/local/home/manager/download/
photo: photo:
address: http://47.96.238.157/photos/ address: http://47.96.238.157/photos/
video:
address: http://47.96.238.157/videos/

@ -1,13 +1,19 @@
package com.shxy.xymanager_admin; package com.shxy.xymanager_admin;
import com.shxy.xymanager_dao.dao.LinesDao; import cn.hutool.core.bean.BeanUtil;
import com.shxy.xymanager_dao.dao.TerminalScheduleRuleDao; import cn.hutool.core.date.DateTime;
import com.shxy.xymanager_dao.dao.TerminalsDao; import com.shxy.xymanager_common.entity.DyLevel;
import com.shxy.xymanager_service.interaction.Cma; import com.shxy.xymanager_common.enums.CommonStatus;
import com.shxy.xymanager_common.model.LineAndGtAndChannelListModel;
import com.shxy.xymanager_common.util.MyDateUtils;
import com.shxy.xymanager_dao.dao.*;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import java.math.BigInteger;
import java.util.List;
@SpringBootTest @SpringBootTest
class XymanagerAdminApplicationTests { class XymanagerAdminApplicationTests {
@ -16,8 +22,11 @@ class XymanagerAdminApplicationTests {
@Autowired @Autowired
TerminalScheduleRuleDao terminalScheduleRuleDao; TerminalScheduleRuleDao terminalScheduleRuleDao;
@Autowired @Autowired
TerminalScheduleDao terminalScheduleDao;
@Autowired
LinesDao linesDao; LinesDao linesDao;
@Autowired
private DyLevelDao dyLevelDao;
@Test @Test
void contextLoads() { void contextLoads() {
@ -50,11 +59,42 @@ class XymanagerAdminApplicationTests {
// } // }
// System.out.println(dateTime.toString()); // System.out.println(dateTime.toString());
Cma cma = new Cma("47.96.238.157", 6891); // Cma cma = new Cma("47.96.238.157", 6891);
boolean b = cma.requestCapture("XYH10H00000000022", (short) 1, (short) 255, (short) 0); // boolean b = cma.requestCapture("XYH10H00000000022", (short) 1, (short) 255, (short) 0);
System.out.println(b); // System.out.println(b);
// CmaDLL cmaDLL =
// TerminalSchedule terminalSchedule = new TerminalSchedule();
// terminalSchedule.setName("ces");
// terminalSchedule.setRemark("vo.getRemark()");
// Date date = new Date();
//// TerminalSchedule bean = terminalScheduleDao.insertSelectiv|e(terminalSchedule, CommonStatus.EFFECTIVE.value(), date, date);
// int i = terminalScheduleDao.insertSelective(terminalSchedule);
// System.out.println(i);
// ArrayList<TerminalScheduleRule> list = new ArrayList<>();
// for (TerminalRuleVo item : vo.getList()) {
// TerminalScheduleRule rule = new TerminalScheduleRule();
// rule.setScheduleId(bean.getId());
// rule.setStartTime(item.getStartTime());
// rule.setEndTime(item.getEndTime());
// rule.setSpan(item.getSpan());
// list.add(rule);
// }
// int i = terminalScheduleRuleDao.insertList(list, CommonStatus.EFFECTIVE.value(), date, date);
// List<DyLevel> list = dyLevelDao.selectAll(CommonStatus.EFFECTIVE.value());
// List<LineAndGtAndChannelListModel.Bean> beans = BeanUtil.copyToList(list, LineAndGtAndChannelListModel.Bean.class);
// System.out.println(beans.toArray());
// CmaDLL cmaDLL = new CmaDLL(); BigInteger time = MyDateUtils.TimeSecond2MillSecond(1683682322);
DateTime date = MyDateUtils.date(time.longValue());
BigInteger time1 = MyDateUtils.TimeSecond2MillSecond(1683683185);
DateTime date1 = MyDateUtils.date(time1.longValue());
BigInteger time2 = MyDateUtils.TimeSecond2MillSecond(1683683196);
DateTime date2 = MyDateUtils.date(time2.longValue());
System.out.println(date + " " + date2 );
} }
} }

@ -0,0 +1,19 @@
package com.shxy.xymanager_common.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.Min;
@Data
@ApiModel(value = "请求对象", description = "请求对象")
public class TestVo {
private String deviceld;
private String alarmDate;
private String alarmType;
private String message;
private String picurl;
private String companyld;
}

@ -15,6 +15,7 @@ import com.shxy.xymanager_common.model.DyLineTreeListModel;
import com.shxy.xymanager_common.model.DyListModel; import com.shxy.xymanager_common.model.DyListModel;
import com.shxy.xymanager_common.util.MyDateUtils; import com.shxy.xymanager_common.util.MyDateUtils;
import com.shxy.xymanager_common.vo.TerminalIdVo; import com.shxy.xymanager_common.vo.TerminalIdVo;
import com.shxy.xymanager_common.vo.TestVo;
import com.shxy.xymanager_dao.dao.DyLevelDao; import com.shxy.xymanager_dao.dao.DyLevelDao;
import com.shxy.xymanager_service.service.DyLevelService; import com.shxy.xymanager_service.service.DyLevelService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -94,4 +95,10 @@ public class DyLevelServiceImpl implements DyLevelService {
} }
return Asserts.success(model); return Asserts.success(model);
} }
@Override
public ServiceBody<String> gettest(List<TestVo> vo) {
log.info(vo.toString());
return Asserts.success("success");
}
} }

@ -4,6 +4,9 @@ import com.shxy.xymanager_common.bean.ServiceBody;
import com.shxy.xymanager_common.model.DyLineTreeListModel; import com.shxy.xymanager_common.model.DyLineTreeListModel;
import com.shxy.xymanager_common.model.DyListModel; import com.shxy.xymanager_common.model.DyListModel;
import com.shxy.xymanager_common.vo.TerminalIdVo; import com.shxy.xymanager_common.vo.TerminalIdVo;
import com.shxy.xymanager_common.vo.TestVo;
import java.util.List;
/** /**
* *
@ -26,4 +29,6 @@ public interface DyLevelService {
*/ */
ServiceBody<DyListModel> getdyList(); ServiceBody<DyListModel> getdyList();
ServiceBody<String> gettest(List<TestVo> vo);
} }

Loading…
Cancel
Save