Compare commits
29 Commits
platform-a
...
master
Author | SHA1 | Date |
---|---|---|
|
0e4caa0216 | 2 years ago |
|
8d1a28ec6f | 2 years ago |
|
94a70a1f75 | 2 years ago |
|
edab7791aa | 2 years ago |
|
9486148630 | 2 years ago |
|
c3e3d6e632 | 2 years ago |
|
2d7c1d2f15 | 2 years ago |
|
1ee59d5b4e | 2 years ago |
|
1a704d3bd9 | 2 years ago |
|
f50379f22e | 2 years ago |
|
5009e66ce8 | 2 years ago |
|
ba3853b57c | 3 years ago |
|
51fa1451a7 | 3 years ago |
|
063d606f45 | 3 years ago |
|
999d9a4467 | 3 years ago |
|
d0dd6cc70f | 3 years ago |
|
e938cf385a | 3 years ago |
|
09fa98edcc | 3 years ago |
|
19cfa8fa61 | 3 years ago |
|
b531d72178 | 3 years ago |
|
0b2d805f73 | 3 years ago |
|
d54b83fcc1 | 3 years ago |
|
493299cffd | 3 years ago |
|
fc4ff1d833 | 3 years ago |
|
fed7dea24a | 3 years ago |
|
1d8350292c | 3 years ago |
|
3579e66a56 | 3 years ago |
|
7955843341 | 3 years ago |
|
fbb438800c | 3 years ago |
89 changed files with 4448 additions and 430 deletions
@ -1,2 +1,97 @@ |
|||||||
程序运行需要将本地jar包安装到maven仓库 |
<p align="center"> |
||||||
mvn install:install-file -Dfile=lib/jna.jar -DgroupId=com.sun -DartifactId=jna -Dversion=1.0 -Dpackaging=jar |
<img alt="logo" src="https://oscimg.oschina.net/oscnet/up-d3d0a9303e11d522a06cd263f3079027715.png"> |
||||||
|
</p> |
||||||
|
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">RuoYi v3.8.2</h1> |
||||||
|
<h4 align="center">基于SpringBoot+Vue前后端分离的Java快速开发框架</h4> |
||||||
|
<p align="center"> |
||||||
|
<a href="https://gitee.com/y_project/RuoYi-Vue/stargazers"><img src="https://gitee.com/y_project/RuoYi-Vue/badge/star.svg?theme=dark"></a> |
||||||
|
<a href="https://gitee.com/y_project/RuoYi-Vue"><img src="https://img.shields.io/badge/RuoYi-v3.8.2-brightgreen.svg"></a> |
||||||
|
<a href="https://gitee.com/y_project/RuoYi-Vue/blob/master/LICENSE"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"></a> |
||||||
|
</p> |
||||||
|
|
||||||
|
## 平台简介 |
||||||
|
|
||||||
|
若依是一套全部开源的快速开发平台,毫无保留给个人及企业免费使用。 |
||||||
|
|
||||||
|
* 前端采用Vue、Element UI。 |
||||||
|
* 后端采用Spring Boot、Spring Security、Redis & Jwt。 |
||||||
|
* 权限认证使用Jwt,支持多终端认证系统。 |
||||||
|
* 支持加载动态权限菜单,多方式轻松权限控制。 |
||||||
|
* 高效率开发,使用代码生成器可以一键生成前后端代码。 |
||||||
|
* 提供了技术栈([Vue3](https://v3.cn.vuejs.org) [Element Plus](https://element-plus.org/zh-CN) [Vite](https://cn.vitejs.dev))版本[RuoYi-Vue3](https://github.com/yangzongzhuan/RuoYi-Vue3),保持同步更新。 |
||||||
|
* 提供了单应用版本[RuoYi-Vue-fast](https://github.com/yangzongzhuan/RuoYi-Vue-fast),Oracle版本[RuoYi-Vue-Oracle](https://github.com/yangzongzhuan/RuoYi-Vue-Oracle),保持同步更新。 |
||||||
|
* 不分离版本,请移步[RuoYi](https://gitee.com/y_project/RuoYi),微服务版本,请移步[RuoYi-Cloud](https://gitee.com/y_project/RuoYi-Cloud) |
||||||
|
* 特别鸣谢:[element](https://github.com/ElemeFE/element),[vue-element-admin](https://github.com/PanJiaChen/vue-element-admin),[eladmin-web](https://github.com/elunez/eladmin-web)。 |
||||||
|
* 阿里云折扣场:[点我进入](http://aly.ruoyi.vip),腾讯云秒杀场:[点我进入](http://txy.ruoyi.vip) |
||||||
|
* 阿里云优惠券:[点我领取](https://www.aliyun.com/minisite/goods?userCode=brki8iof&share_source=copy_link),腾讯云优惠券:[点我领取](https://cloud.tencent.com/redirect.php?redirect=1025&cps_key=198c8df2ed259157187173bc7f4f32fd&from=console) |
||||||
|
|
||||||
|
## 内置功能 |
||||||
|
|
||||||
|
1. 用户管理:用户是系统操作者,该功能主要完成系统用户配置。 |
||||||
|
2. 部门管理:配置系统组织机构(公司、部门、小组),树结构展现支持数据权限。 |
||||||
|
3. 岗位管理:配置系统用户所属担任职务。 |
||||||
|
4. 菜单管理:配置系统菜单,操作权限,按钮权限标识等。 |
||||||
|
5. 角色管理:角色菜单权限分配、设置角色按机构进行数据范围权限划分。 |
||||||
|
6. 字典管理:对系统中经常使用的一些较为固定的数据进行维护。 |
||||||
|
7. 参数管理:对系统动态配置常用参数。 |
||||||
|
8. 通知公告:系统通知公告信息发布维护。 |
||||||
|
9. 操作日志:系统正常操作日志记录和查询;系统异常信息日志记录和查询。 |
||||||
|
10. 登录日志:系统登录日志记录查询包含登录异常。 |
||||||
|
11. 在线用户:当前系统中活跃用户状态监控。 |
||||||
|
12. 定时任务:在线(添加、修改、删除)任务调度包含执行结果日志。 |
||||||
|
13. 代码生成:前后端代码的生成(java、html、xml、sql)支持CRUD下载 。 |
||||||
|
14. 系统接口:根据业务代码自动生成相关的api接口文档。 |
||||||
|
15. 服务监控:监视当前系统CPU、内存、磁盘、堆栈等相关信息。 |
||||||
|
16. 缓存监控:对系统的缓存信息查询,命令统计等。 |
||||||
|
17. 在线构建器:拖动表单元素生成相应的HTML代码。 |
||||||
|
18. 连接池监视:监视当前系统数据库连接池状态,可进行分析SQL找出系统性能瓶颈。 |
||||||
|
|
||||||
|
## 在线体验 |
||||||
|
|
||||||
|
- admin/admin123 |
||||||
|
- 陆陆续续收到一些打赏,为了更好的体验已用于演示服务器升级。谢谢各位小伙伴。 |
||||||
|
|
||||||
|
演示地址:http://vue.ruoyi.vip |
||||||
|
文档地址:http://doc.ruoyi.vip |
||||||
|
|
||||||
|
## 演示图 |
||||||
|
|
||||||
|
<table> |
||||||
|
<tr> |
||||||
|
<td><img src="https://oscimg.oschina.net/oscnet/cd1f90be5f2684f4560c9519c0f2a232ee8.jpg"/></td> |
||||||
|
<td><img src="https://oscimg.oschina.net/oscnet/1cbcf0e6f257c7d3a063c0e3f2ff989e4b3.jpg"/></td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td><img src="https://oscimg.oschina.net/oscnet/up-8074972883b5ba0622e13246738ebba237a.png"/></td> |
||||||
|
<td><img src="https://oscimg.oschina.net/oscnet/up-9f88719cdfca9af2e58b352a20e23d43b12.png"/></td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td><img src="https://oscimg.oschina.net/oscnet/up-39bf2584ec3a529b0d5a3b70d15c9b37646.png"/></td> |
||||||
|
<td><img src="https://oscimg.oschina.net/oscnet/up-936ec82d1f4872e1bc980927654b6007307.png"/></td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td><img src="https://oscimg.oschina.net/oscnet/up-b2d62ceb95d2dd9b3fbe157bb70d26001e9.png"/></td> |
||||||
|
<td><img src="https://oscimg.oschina.net/oscnet/up-d67451d308b7a79ad6819723396f7c3d77a.png"/></td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td><img src="https://oscimg.oschina.net/oscnet/5e8c387724954459291aafd5eb52b456f53.jpg"/></td> |
||||||
|
<td><img src="https://oscimg.oschina.net/oscnet/644e78da53c2e92a95dfda4f76e6d117c4b.jpg"/></td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td><img src="https://oscimg.oschina.net/oscnet/up-8370a0d02977eebf6dbf854c8450293c937.png"/></td> |
||||||
|
<td><img src="https://oscimg.oschina.net/oscnet/up-49003ed83f60f633e7153609a53a2b644f7.png"/></td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td><img src="https://oscimg.oschina.net/oscnet/up-d4fe726319ece268d4746602c39cffc0621.png"/></td> |
||||||
|
<td><img src="https://oscimg.oschina.net/oscnet/up-c195234bbcd30be6927f037a6755e6ab69c.png"/></td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td><img src="https://oscimg.oschina.net/oscnet/b6115bc8c31de52951982e509930b20684a.jpg"/></td> |
||||||
|
<td><img src="https://oscimg.oschina.net/oscnet/up-5e4daac0bb59612c5038448acbcef235e3a.png"/></td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
|
||||||
|
|
||||||
|
## 若依前后端分离交流群 |
||||||
|
|
||||||
|
QQ群: [](https://jq.qq.com/?_wv=1027&k=5bVB1og) [](https://jq.qq.com/?_wv=1027&k=5eiA4DH) [](https://jq.qq.com/?_wv=1027&k=5AxMKlC) [](https://jq.qq.com/?_wv=1027&k=51G72yr) [](https://jq.qq.com/?_wv=1027&k=VvjN2nvu) [](https://jq.qq.com/?_wv=1027&k=5vYAqA05) [](https://jq.qq.com/?_wv=1027&k=kOIINEb5) [](https://jq.qq.com/?_wv=1027&k=UKtX5jhs) [](https://jq.qq.com/?_wv=1027&k=EI9an8lJ) [](https://jq.qq.com/?_wv=1027&k=SWCtLnMz) 点击按钮入群。 |
@ -0,0 +1,43 @@ |
|||||||
|
package com.ruoyi.api.app; |
||||||
|
|
||||||
|
import com.ruoyi.api.controller.AbstractApiController; |
||||||
|
import com.ruoyi.api.params.AlarmDataParams; |
||||||
|
import com.ruoyi.api.params.WaterDataParams; |
||||||
|
import com.ruoyi.api.service.AlarmDataApiService; |
||||||
|
import com.ruoyi.api.service.WaterDataApiService; |
||||||
|
import com.ruoyi.code.warning.service.IWaAlarmService; |
||||||
|
import com.ruoyi.common.core.page.R; |
||||||
|
import com.ruoyi.common.validator.ValidatorUtils; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 系统对外接口-检测信息 |
||||||
|
*/ |
||||||
|
@RestController |
||||||
|
@RequestMapping("/api") |
||||||
|
@Slf4j |
||||||
|
public class AlarmDataApiController extends AbstractApiController { |
||||||
|
|
||||||
|
@Resource |
||||||
|
private AlarmDataApiService alarmDataApiService; |
||||||
|
/** |
||||||
|
* 预警数据查询 |
||||||
|
* |
||||||
|
* @param params |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
@PostMapping("v1/alarm_data/query") |
||||||
|
public R query(@RequestBody AlarmDataParams params) { |
||||||
|
log.info("[预警数据查询接口查询参数为{}]", params); |
||||||
|
ValidatorUtils.validateV2(params); |
||||||
|
return alarmDataApiService.query(params); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
package com.ruoyi.api.app; |
||||||
|
|
||||||
|
import com.ruoyi.api.domain.RegularTime; |
||||||
|
import com.ruoyi.api.service.IRegularTimeService; |
||||||
|
import com.ruoyi.api.util.RegularTimeUtil; |
||||||
|
import com.ruoyi.common.core.controller.BaseController; |
||||||
|
import com.ruoyi.common.core.page.R; |
||||||
|
import com.ruoyi.common.utils.StringUtils; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
/** |
||||||
|
* 定时报Controller |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-23 |
||||||
|
*/ |
||||||
|
@RestController |
||||||
|
@RequestMapping("/api/regular/time") |
||||||
|
public class RegularTimeController extends BaseController |
||||||
|
{ |
||||||
|
@Resource |
||||||
|
private IRegularTimeService regularTimeService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 新增 |
||||||
|
*/ |
||||||
|
@RequestMapping("/add") |
||||||
|
public R add(String asciiCode){ |
||||||
|
if (StringUtils.isEmpty(asciiCode)){ |
||||||
|
return R.error("asciiCode不能为空!"); |
||||||
|
} |
||||||
|
RegularTime regularTime = RegularTimeUtil.hourlyReportASCII(asciiCode); |
||||||
|
regularTimeService.save(regularTime); |
||||||
|
return R.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,66 @@ |
|||||||
|
package com.ruoyi.api.domain; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 定时报对象 regular_time |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-23 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@TableName("regular_time") |
||||||
|
public class RegularTime implements Serializable |
||||||
|
{ |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
/** id */ |
||||||
|
@TableId(type = IdType.INPUT) |
||||||
|
private Long id; |
||||||
|
|
||||||
|
/** 中心站地址 */ |
||||||
|
private String centralStationAddr; |
||||||
|
|
||||||
|
/** 遥测站地址 */ |
||||||
|
private String stationAddr; |
||||||
|
|
||||||
|
/** 密码 */ |
||||||
|
private String password; |
||||||
|
|
||||||
|
/** 功能码 */ |
||||||
|
private String code; |
||||||
|
|
||||||
|
/** 报文上下行标识和长度 */ |
||||||
|
private String msgIdAndLength; |
||||||
|
|
||||||
|
/** 流水号 */ |
||||||
|
private String serialNum; |
||||||
|
|
||||||
|
/** 发报时间 */ |
||||||
|
private String dispatchTime; |
||||||
|
|
||||||
|
/** 遥测站分类码 */ |
||||||
|
private String stationTypeCode; |
||||||
|
|
||||||
|
/** 观测时间 */ |
||||||
|
private String observationTime; |
||||||
|
|
||||||
|
/** 瞬时水位 */ |
||||||
|
private String waterLevel; |
||||||
|
|
||||||
|
/** 电压 */ |
||||||
|
private String voltage; |
||||||
|
|
||||||
|
/** 温度 */ |
||||||
|
private String temperature; |
||||||
|
|
||||||
|
/** 校验 */ |
||||||
|
private String checkCode; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
package com.ruoyi.api.mapper; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import org.apache.ibatis.annotations.Mapper; |
||||||
|
import com.ruoyi.api.domain.RegularTime; |
||||||
|
|
||||||
|
/** |
||||||
|
* Mapper接口 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-23 |
||||||
|
*/ |
||||||
|
@Mapper |
||||||
|
public interface RegularTimeMapper extends BaseMapper<RegularTime> |
||||||
|
{ |
||||||
|
|
||||||
|
} |
@ -0,0 +1,16 @@ |
|||||||
|
package com.ruoyi.api.params; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
import javax.validation.constraints.NotNull; |
||||||
|
|
||||||
|
@Data |
||||||
|
public class AlarmDataParams { |
||||||
|
|
||||||
|
private Long stnmId; |
||||||
|
|
||||||
|
private String startTime; |
||||||
|
|
||||||
|
private String endTime; |
||||||
|
} |
@ -0,0 +1,31 @@ |
|||||||
|
package com.ruoyi.api.service; |
||||||
|
|
||||||
|
import com.ruoyi.api.params.AlarmDataParams; |
||||||
|
import com.ruoyi.api.params.WaterDataParams; |
||||||
|
import com.ruoyi.code.warning.domain.WaAlarm; |
||||||
|
import com.ruoyi.code.warning.service.IWaAlarmService; |
||||||
|
import com.ruoyi.common.core.page.R; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
@Service |
||||||
|
public class AlarmDataApiService { |
||||||
|
|
||||||
|
@Resource |
||||||
|
private IWaAlarmService waAlarmService; |
||||||
|
|
||||||
|
public R query(AlarmDataParams params) { |
||||||
|
Map<String,Object> map = new HashMap<>(); |
||||||
|
map.put("stnmId",params.getStnmId()); |
||||||
|
map.put("startTime",params.getStartTime()); |
||||||
|
map.put("endTime",params.getEndTime()); |
||||||
|
|
||||||
|
List<WaAlarm> list = waAlarmService.queryAlarm(map); |
||||||
|
return R.ok().put("data", list); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,22 @@ |
|||||||
|
package com.ruoyi.api.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||||
|
import com.ruoyi.api.domain.RegularTime; |
||||||
|
import com.ruoyi.common.core.page.R; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* Service接口 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-23 |
||||||
|
*/ |
||||||
|
public interface IRegularTimeService extends IService<RegularTime> |
||||||
|
{ |
||||||
|
/** |
||||||
|
* 查询 |
||||||
|
*/ |
||||||
|
R queryPage(Map<String, Object> params); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,34 @@ |
|||||||
|
package com.ruoyi.api.service.impl; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||||
|
import com.ruoyi.api.domain.RegularTime; |
||||||
|
import com.ruoyi.api.mapper.RegularTimeMapper; |
||||||
|
import com.ruoyi.api.service.IRegularTimeService; |
||||||
|
import com.ruoyi.common.core.page.R; |
||||||
|
import com.ruoyi.common.utils.Query; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* Service业务层处理 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-23 |
||||||
|
*/ |
||||||
|
@Service("regularTimeService") |
||||||
|
public class RegularTimeServiceImpl extends ServiceImpl<RegularTimeMapper, RegularTime> implements IRegularTimeService |
||||||
|
{ |
||||||
|
@Override |
||||||
|
public R queryPage(Map<String, Object> params) { |
||||||
|
IPage<RegularTime> page = this.page( |
||||||
|
new Query<RegularTime>().getPage(params), |
||||||
|
new QueryWrapper<RegularTime>() |
||||||
|
); |
||||||
|
|
||||||
|
return R.ok().put("count", page.getTotal()).put("data", page.getRecords()); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,127 @@ |
|||||||
|
package com.ruoyi.api.util; |
||||||
|
import org.apache.commons.codec.binary.Hex; |
||||||
|
import org.apache.commons.lang3.Validate; |
||||||
|
|
||||||
|
import java.security.GeneralSecurityException; |
||||||
|
import java.security.MessageDigest; |
||||||
|
import java.security.SecureRandom; |
||||||
|
import java.util.Random; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author wcy |
||||||
|
* @date 2021/8/13 下午3:03 |
||||||
|
*/ |
||||||
|
|
||||||
|
public class Digests { |
||||||
|
private static SecureRandom random = new SecureRandom(); |
||||||
|
/** |
||||||
|
* 加密遵循RFC2671规范 将相关参数加密生成一个MD5字符串,并返回 |
||||||
|
*/ |
||||||
|
public static String http_da_calc_HA1(String username, String realm, String password, |
||||||
|
String nonce, String nc, String cnonce, String qop, |
||||||
|
String method, String uri, String algorithm) { |
||||||
|
String HA1, HA2; |
||||||
|
if ("MD5-sess".equals(algorithm)) { |
||||||
|
HA1 = HA1_MD5_sess(username, realm, password, nonce, cnonce); |
||||||
|
} else { |
||||||
|
HA1 = HA1_MD5(username, realm, password); |
||||||
|
} |
||||||
|
byte[] md5Byte = md5(HA1.getBytes()); |
||||||
|
HA1 = new String(Hex.encodeHex(md5Byte)); |
||||||
|
|
||||||
|
md5Byte = md5(HA2(method, uri).getBytes()); |
||||||
|
HA2 = new String(Hex.encodeHex(md5Byte)); |
||||||
|
|
||||||
|
String original = HA1 + ":" + (nonce + ":" + nc + ":" + cnonce + ":" + qop) + ":" + HA2; |
||||||
|
|
||||||
|
md5Byte = md5(original.getBytes()); |
||||||
|
return new String(Hex.encodeHex(md5Byte)); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* algorithm值为MD5时规则 |
||||||
|
*/ |
||||||
|
private static String HA1_MD5(String username, String realm, String password) { |
||||||
|
return username + ":" + realm + ":" + password; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* algorithm值为MD5-sess时规则 |
||||||
|
*/ |
||||||
|
private static String HA1_MD5_sess(String username, String realm, String password, String nonce, String cnonce) { |
||||||
|
// MD5(username:realm:password):nonce:cnonce
|
||||||
|
|
||||||
|
String s = HA1_MD5(username, realm, password); |
||||||
|
byte[] md5Byte = md5(s.getBytes()); |
||||||
|
String smd5 = new String(Hex.encodeHex(md5Byte)); |
||||||
|
|
||||||
|
return smd5 + ":" + nonce + ":" + cnonce; |
||||||
|
} |
||||||
|
|
||||||
|
private static String HA2(String method, String uri) { |
||||||
|
return method + ":" + uri; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 对输入字符串进行md5散列. |
||||||
|
*/ |
||||||
|
public static byte[] md5(byte[] input) { |
||||||
|
return digest(input, "MD5", null, 1); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 对字符串进行散列, 支持md5与sha1算法. |
||||||
|
*/ |
||||||
|
private static byte[] digest(byte[] input, String algorithm, byte[] salt, int iterations) { |
||||||
|
try { |
||||||
|
MessageDigest digest = MessageDigest.getInstance(algorithm); |
||||||
|
|
||||||
|
if (salt != null) { |
||||||
|
digest.update(salt); |
||||||
|
} |
||||||
|
|
||||||
|
byte[] result = digest.digest(input); |
||||||
|
|
||||||
|
for (int i = 1; i < iterations; i++) { |
||||||
|
digest.reset(); |
||||||
|
result = digest.digest(result); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} catch (GeneralSecurityException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 随机生成numBytes长度数组 |
||||||
|
* @param numBytes |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static byte[] generateSalt(int numBytes) { |
||||||
|
Validate.isTrue(numBytes > 0, "numBytes argument must be a positive integer (1 or larger)", (long)numBytes); |
||||||
|
byte[] bytes = new byte[numBytes]; |
||||||
|
random.nextBytes(bytes); |
||||||
|
return bytes; |
||||||
|
} |
||||||
|
|
||||||
|
@Deprecated |
||||||
|
public static String generateSalt2(int length) { |
||||||
|
String val = ""; |
||||||
|
Random random = new Random(); |
||||||
|
//参数length,表示生成几位随机数
|
||||||
|
for(int i = 0; i < length; i++) { |
||||||
|
String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num"; |
||||||
|
//输出字母还是数字
|
||||||
|
if( "char".equalsIgnoreCase(charOrNum) ) { |
||||||
|
//输出是大写字母还是小写字母
|
||||||
|
int temp = random.nextInt(2)%2 == 0 ? 65 : 97; |
||||||
|
val += (char)(random.nextInt(26) + temp); |
||||||
|
} else if( "num".equalsIgnoreCase(charOrNum) ) { |
||||||
|
val += String.valueOf(random.nextInt(10)); |
||||||
|
} |
||||||
|
} |
||||||
|
return val.toLowerCase(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,498 @@ |
|||||||
|
package com.ruoyi.api.util; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON; |
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import org.apache.commons.lang3.StringUtils; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
import java.io.BufferedReader; |
||||||
|
import java.io.IOException; |
||||||
|
import java.io.InputStreamReader; |
||||||
|
import java.io.OutputStream; |
||||||
|
import java.net.HttpURLConnection; |
||||||
|
import java.net.URL; |
||||||
|
import java.net.URLConnection; |
||||||
|
import java.util.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author wcy |
||||||
|
* @date 2021/8/13 下午3:04 |
||||||
|
*/ |
||||||
|
|
||||||
|
public class HttpRequestUtils { |
||||||
|
private static final Logger logger = LoggerFactory.getLogger(HttpRequestUtils.class); |
||||||
|
|
||||||
|
public static void main(String[] args) { |
||||||
|
|
||||||
|
// String json = HttpRequestUtils.sendPost("http://112.13.167.212:10000/uas/v1/api/dev/list",
|
||||||
|
// "", "nb012105", "Fhsw123456", "{}", "json");
|
||||||
|
|
||||||
|
String devListUrl = "http://112.13.167.212:10000/uas/v1/api/dev/list"; |
||||||
|
String mediaLiveUrl = "http://112.13.167.212:10000/mss/v1/api/media/live"; |
||||||
|
|
||||||
|
|
||||||
|
String jsonRtsp = HttpRequestUtils.sendPost(mediaLiveUrl, |
||||||
|
"", "nb012105", "Fhsw123456", "{\n" + |
||||||
|
" \"cameraId\": \"33021322031505040301000000581506\",\n" + |
||||||
|
" \"streamType\": 1,\n" + |
||||||
|
" \"urlType\": 1,\n" + |
||||||
|
" \"agentType\": 1\n" + |
||||||
|
"}", "json"); |
||||||
|
|
||||||
|
// String json = HttpRequestUtils.sendPost("http://112.13.167.212:10000/uas/v1/api/ptz/control",
|
||||||
|
//// String json = HttpRequestUtils.sendPost("http://112.13.167.212:10000/dcs/v1/api/preset/get",
|
||||||
|
// "", "nb012105", "Fhsw123456", "{\n" +
|
||||||
|
//// " \"cameraId\": \"33021323010505040301020001151452\"" +
|
||||||
|
// " \"cameraId\": \"33021323010505040301020001151452\",\n" +
|
||||||
|
// " \"opCode\": \"PTZ_PREFAB_BIT_RUN\",\n" +
|
||||||
|
// " \"param1\": 1,\n" +
|
||||||
|
// " \"param2\": 10\n" +
|
||||||
|
// "}", "json");
|
||||||
|
System.out.println(jsonRtsp); |
||||||
|
JSONObject object = JSON.parseObject(jsonRtsp); |
||||||
|
System.out.println(object.getString("url")); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
static int nc = 0; //调用次数
|
||||||
|
private static final String GET = "GET"; |
||||||
|
private static final String POST = "POST"; |
||||||
|
private static final String PUT = "PUT"; |
||||||
|
private static final String DELETE = "DELETE"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 向指定URL发送DELETE方法的请求 |
||||||
|
* @param url 发送请求的URL |
||||||
|
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。 |
||||||
|
* @param username 验证所需的用户名 |
||||||
|
* @param password 验证所需的密码 |
||||||
|
* @param json 请求json字符串 |
||||||
|
* @param type 返回xml和json格式数据,默认xml,传入json返回json数据 |
||||||
|
* @return URL 所代表远程资源的响应结果 |
||||||
|
*/ |
||||||
|
public static String sendDelete(String url, String param, String username, String password, String json, String type) { |
||||||
|
StringBuilder result = new StringBuilder(); |
||||||
|
BufferedReader in = null; |
||||||
|
try { |
||||||
|
String wwwAuth = sendGet(url, param); //发起一次授权请求
|
||||||
|
if (wwwAuth.startsWith("WWW-Authenticate:")) { |
||||||
|
wwwAuth = wwwAuth.replaceFirst("WWW-Authenticate:", ""); |
||||||
|
} else { |
||||||
|
return wwwAuth; |
||||||
|
} |
||||||
|
nc ++; |
||||||
|
String urlNameString = url + (StringUtils.isNotEmpty(param) ? "?" + param : ""); |
||||||
|
URL realUrl = new URL(urlNameString); |
||||||
|
// 打开和URL之间的连接
|
||||||
|
HttpURLConnection connection = (HttpURLConnection)realUrl.openConnection(); |
||||||
|
|
||||||
|
// 设置是否向connection输出,因为这个是post请求,参数要放在
|
||||||
|
// http正文内,因此需要设为true
|
||||||
|
connection.setDoOutput(true); |
||||||
|
// Read from the connection. Defaultis true.
|
||||||
|
connection.setDoInput(true); |
||||||
|
// 默认是 GET方式
|
||||||
|
connection.setRequestMethod(DELETE); |
||||||
|
|
||||||
|
// 设置通用的请求属性
|
||||||
|
setRequestProperty(connection, wwwAuth, realUrl, username, password, DELETE, type); |
||||||
|
|
||||||
|
if (!StringUtils.isEmpty(json)) { |
||||||
|
byte[] writebytes =json.getBytes(); |
||||||
|
connection.setRequestProperty("Content-Length",String.valueOf(writebytes.length)); |
||||||
|
OutputStream outwritestream = connection.getOutputStream(); |
||||||
|
outwritestream.write(json.getBytes()); |
||||||
|
outwritestream.flush(); |
||||||
|
outwritestream.close(); |
||||||
|
} |
||||||
|
|
||||||
|
if (connection.getResponseCode() == 200) { |
||||||
|
in = new BufferedReader(new InputStreamReader(connection.getInputStream())); |
||||||
|
String line; |
||||||
|
while ((line = in.readLine()) != null) { |
||||||
|
result.append(line); |
||||||
|
} |
||||||
|
} else { |
||||||
|
String errResult = formatResultInfo(connection, type); |
||||||
|
logger.info(errResult); |
||||||
|
return errResult; |
||||||
|
} |
||||||
|
|
||||||
|
nc = 0; |
||||||
|
} catch (Exception e) { |
||||||
|
nc = 0; |
||||||
|
throw new RuntimeException(e); |
||||||
|
} finally { |
||||||
|
try { |
||||||
|
if (in != null) in.close(); |
||||||
|
} catch (Exception e2) { |
||||||
|
e2.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
return result.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 向指定URL发送PUT方法的请求 |
||||||
|
* @param url 发送请求的URL |
||||||
|
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。 |
||||||
|
* @param username 验证所需的用户名 |
||||||
|
* @param password 验证所需的密码 |
||||||
|
* @param json 请求json字符串 |
||||||
|
* @param type 返回xml和json格式数据,默认xml,传入json返回json数据 |
||||||
|
* @return URL 所代表远程资源的响应结果 |
||||||
|
*/ |
||||||
|
public static String sendPUT(String url, String param, String username, String password, String json, String type) { |
||||||
|
StringBuilder result = new StringBuilder(); |
||||||
|
BufferedReader in = null; |
||||||
|
try { |
||||||
|
String wwwAuth = sendGet(url, param); //发起一次授权请求
|
||||||
|
if (wwwAuth.startsWith("WWW-Authenticate:")) { |
||||||
|
wwwAuth = wwwAuth.replaceFirst("WWW-Authenticate:", ""); |
||||||
|
} else { |
||||||
|
return wwwAuth; |
||||||
|
} |
||||||
|
nc ++; |
||||||
|
String urlNameString = url + (StringUtils.isNotEmpty(param) ? "?" + param : ""); |
||||||
|
URL realUrl = new URL(urlNameString); |
||||||
|
// 打开和URL之间的连接
|
||||||
|
HttpURLConnection connection = (HttpURLConnection)realUrl.openConnection(); |
||||||
|
|
||||||
|
// 设置是否向connection输出,因为这个是post请求,参数要放在
|
||||||
|
// http正文内,因此需要设为true
|
||||||
|
connection.setDoOutput(true); |
||||||
|
// Read from the connection. Defaultis true.
|
||||||
|
connection.setDoInput(true); |
||||||
|
// 默认是 GET方式
|
||||||
|
connection.setRequestMethod(PUT); |
||||||
|
// Post 请求不能使用缓存
|
||||||
|
connection.setUseCaches(false); |
||||||
|
|
||||||
|
// 设置通用的请求属性
|
||||||
|
setRequestProperty(connection, wwwAuth,realUrl, username, password, PUT, type); |
||||||
|
|
||||||
|
if (!StringUtils.isEmpty(json)) { |
||||||
|
byte[] writebytes =json.getBytes(); |
||||||
|
connection.setRequestProperty("Content-Length",String.valueOf(writebytes.length)); |
||||||
|
OutputStream outwritestream = connection.getOutputStream(); |
||||||
|
outwritestream.write(json.getBytes()); |
||||||
|
outwritestream.flush(); |
||||||
|
outwritestream.close(); |
||||||
|
} |
||||||
|
|
||||||
|
if (connection.getResponseCode() == 200) { |
||||||
|
in = new BufferedReader(new InputStreamReader(connection.getInputStream())); |
||||||
|
String line; |
||||||
|
while ((line = in.readLine()) != null) { |
||||||
|
result.append(line); |
||||||
|
} |
||||||
|
} else { |
||||||
|
String errResult = formatResultInfo(connection, type); |
||||||
|
logger.info(errResult); |
||||||
|
return errResult; |
||||||
|
} |
||||||
|
|
||||||
|
nc = 0; |
||||||
|
} catch (Exception e) { |
||||||
|
nc = 0; |
||||||
|
throw new RuntimeException(e); |
||||||
|
} finally { |
||||||
|
try { |
||||||
|
if (in != null) in.close(); |
||||||
|
} catch (Exception e2) { |
||||||
|
e2.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
return result.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 向指定URL发送POST方法的请求 |
||||||
|
* @param url 发送请求的URL |
||||||
|
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。 |
||||||
|
* @param username 验证所需的用户名 |
||||||
|
* @param password 验证所需的密码 |
||||||
|
* @param json 请求json字符串 |
||||||
|
* @param type 返回xml和json格式数据,默认xml,传入json返回json数据 |
||||||
|
* @return URL 所代表远程资源的响应结果 |
||||||
|
*/ |
||||||
|
public static String sendPost(String url, String param, String username, String password, String json, String type) { |
||||||
|
StringBuilder result = new StringBuilder(); |
||||||
|
BufferedReader in = null; |
||||||
|
try { |
||||||
|
String wwwAuth = sendGet(url, param); //发起一次授权请求
|
||||||
|
if (wwwAuth.startsWith("WWW-Authenticate:")) { |
||||||
|
wwwAuth = wwwAuth.replaceFirst("WWW-Authenticate:", ""); |
||||||
|
} else { |
||||||
|
return wwwAuth; |
||||||
|
} |
||||||
|
nc ++; |
||||||
|
String urlNameString = url + (StringUtils.isNotEmpty(param) ? "?" + param : ""); |
||||||
|
URL realUrl = new URL(urlNameString); |
||||||
|
// 打开和URL之间的连接
|
||||||
|
HttpURLConnection connection = (HttpURLConnection)realUrl.openConnection(); |
||||||
|
|
||||||
|
// 设置是否向connection输出,因为这个是post请求,参数要放在
|
||||||
|
// http正文内,因此需要设为true
|
||||||
|
connection.setDoOutput(true); |
||||||
|
// Read from the connection. Defaultis true.
|
||||||
|
connection.setDoInput(true); |
||||||
|
// 默认是 GET方式
|
||||||
|
connection.setRequestMethod(POST); |
||||||
|
// Post 请求不能使用缓存
|
||||||
|
connection.setUseCaches(false); |
||||||
|
|
||||||
|
// 设置通用的请求属性
|
||||||
|
setRequestProperty(connection, wwwAuth,realUrl, username, password, POST, type); |
||||||
|
|
||||||
|
if (!StringUtils.isEmpty(json)) { |
||||||
|
byte[] writebytes =json.getBytes(); |
||||||
|
connection.setRequestProperty("Content-Length",String.valueOf(writebytes.length)); |
||||||
|
OutputStream outwritestream = connection.getOutputStream(); |
||||||
|
outwritestream.write(json.getBytes()); |
||||||
|
outwritestream.flush(); |
||||||
|
outwritestream.close(); |
||||||
|
} |
||||||
|
if (connection.getResponseCode() == 200 || connection.getResponseCode() == 201) { |
||||||
|
in = new BufferedReader(new InputStreamReader(connection.getInputStream())); |
||||||
|
String line; |
||||||
|
while ((line = in.readLine()) != null) { |
||||||
|
result.append(line); |
||||||
|
} |
||||||
|
} else { |
||||||
|
String errResult = formatResultInfo(connection, type); |
||||||
|
logger.info(errResult); |
||||||
|
return errResult; |
||||||
|
} |
||||||
|
|
||||||
|
nc = 0; |
||||||
|
} catch (Exception e) { |
||||||
|
nc = 0; |
||||||
|
throw new RuntimeException(e); |
||||||
|
} finally { |
||||||
|
try { |
||||||
|
if (in != null) in.close(); |
||||||
|
} catch (Exception e2) { |
||||||
|
e2.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
return result.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 向指定URL发送GET方法的请求 |
||||||
|
* @param url 发送请求的URL |
||||||
|
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。 |
||||||
|
* @param username 验证所需的用户名 |
||||||
|
* @param password 验证所需的密码 |
||||||
|
* @param type 返回xml和json格式数据,默认xml,传入json返回json数据 |
||||||
|
* @return URL 所代表远程资源的响应结果 |
||||||
|
*/ |
||||||
|
public static String sendGet(String url, String param, String username, String password, String type) { |
||||||
|
|
||||||
|
StringBuilder result = new StringBuilder(); |
||||||
|
BufferedReader in = null; |
||||||
|
try { |
||||||
|
String wwwAuth = sendGet(url, param); //发起一次授权请求
|
||||||
|
if (wwwAuth.startsWith("WWW-Authenticate:")) { |
||||||
|
wwwAuth = wwwAuth.replaceFirst("WWW-Authenticate:", ""); |
||||||
|
} else { |
||||||
|
return wwwAuth; |
||||||
|
} |
||||||
|
nc ++; |
||||||
|
String urlNameString = url + (StringUtils.isNotEmpty(param) ? "?" + param : ""); |
||||||
|
URL realUrl = new URL(urlNameString); |
||||||
|
// 打开和URL之间的连接
|
||||||
|
HttpURLConnection connection = (HttpURLConnection)realUrl.openConnection(); |
||||||
|
// 设置通用的请求属性
|
||||||
|
setRequestProperty(connection, wwwAuth,realUrl, username, password, GET, type); |
||||||
|
// 建立实际的连接
|
||||||
|
// connection.connect();
|
||||||
|
in = new BufferedReader(new InputStreamReader(connection.getInputStream())); |
||||||
|
String line; |
||||||
|
while ((line = in.readLine()) != null) { |
||||||
|
result.append(line); |
||||||
|
} |
||||||
|
nc = 0; |
||||||
|
} catch (Exception e) { |
||||||
|
nc = 0; |
||||||
|
throw new RuntimeException(e); |
||||||
|
} finally { |
||||||
|
try { |
||||||
|
if (in != null) in.close(); |
||||||
|
} catch (Exception e2) { |
||||||
|
e2.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
return result.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 生成授权信息 |
||||||
|
* @param authorization 上一次调用返回401的WWW-Authenticate数据 |
||||||
|
* @param username 用户名 |
||||||
|
* @param password 密码 |
||||||
|
* @return 授权后的数据, 应放在http头的Authorization里 |
||||||
|
* @throws IOException 异常 |
||||||
|
*/ |
||||||
|
private static String getAuthorization(String authorization, String uri, String username, String password, String method) throws IOException { |
||||||
|
|
||||||
|
uri = StringUtils.isEmpty(uri) ? "/" : uri; |
||||||
|
// String temp = authorization.replaceFirst("Digest", "").trim();
|
||||||
|
String temp = authorization.replaceFirst("Digest", "").trim().replace("MD5","\"MD5\""); |
||||||
|
// String json = "{\"" + temp.replaceAll("=", "\":").replaceAll(",", ",\"") + "}";
|
||||||
|
String json = withdrawJson(authorization); |
||||||
|
// String json = "{ \"realm\": \"Wowza\", \" domain\": \"/\", \" nonce\": \"MTU1NzgxMTU1NzQ4MDo2NzI3MWYxZTZkYjBiMjQ2ZGRjYTQ3ZjNiOTM2YjJjZA==\", \" algorithm\": \"MD5\", \" qop\": \"auth\" }";
|
||||||
|
|
||||||
|
JSONObject jsonObject = JSON.parseObject(json); |
||||||
|
String cnonce = Digests.generateSalt2(8); |
||||||
|
String ncstr = ("00000000" + nc).substring(Integer.toString(nc).length()); //认证的次数,第一次是1,第二次是2...
|
||||||
|
// String algorithm = jsonObject.getString("algorithm");
|
||||||
|
String algorithm = jsonObject.getString("algorithm"); |
||||||
|
String qop = jsonObject.getString("qop"); |
||||||
|
String nonce = jsonObject.getString("nonce"); |
||||||
|
String realm = jsonObject.getString("realm"); |
||||||
|
|
||||||
|
String response = Digests.http_da_calc_HA1(username, realm, password, |
||||||
|
nonce, ncstr, cnonce, qop, |
||||||
|
method, uri, algorithm); |
||||||
|
|
||||||
|
//组成响应authorization
|
||||||
|
authorization = "Digest username=\"" + username + "\"," + temp; |
||||||
|
authorization += ",uri=\"" + uri |
||||||
|
+ "\",nc=\"" + ncstr |
||||||
|
+ "\",cnonce=\"" + cnonce |
||||||
|
+ "\",response=\"" + response+"\""; |
||||||
|
return authorization; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 将返回的Authrization信息转成json |
||||||
|
* @param authorization authorization info |
||||||
|
* @return 返回authrization json格式数据 如:String json = "{ \"realm\": \"Wowza\", \" domain\": \"/\", \" nonce\": \"MTU1NzgxMTU1NzQ4MDo2NzI3MWYxZTZkYjBiMjQ2ZGRjYTQ3ZjNiOTM2YjJjZA==\", \" algorithm\": \"MD5\", \" qop\": \"auth\" }"; |
||||||
|
*/ |
||||||
|
private static String withdrawJson(String authorization) { |
||||||
|
String temp = authorization.replaceFirst("Digest", "").trim().replaceAll("\"",""); |
||||||
|
// String noncetemp = temp.substring(temp.indexOf("nonce="), temp.indexOf("uri="));
|
||||||
|
// String json = "{\"" + temp.replaceAll("=", "\":").replaceAll(",", ",\"") + "}";
|
||||||
|
String[] split = temp.split(","); |
||||||
|
Map<String, String> map = new HashMap<>(); |
||||||
|
Arrays.asList(split).forEach(c -> { |
||||||
|
String c1 = c.replaceFirst("=",":"); |
||||||
|
String[] split1 = c1.split(":"); |
||||||
|
map.put(split1[0].trim(), split1[1].trim()); |
||||||
|
}); |
||||||
|
return JSONObject.toJSONString(map); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 向指定URL发送GET方法的请求 |
||||||
|
* @param url 发送请求的URL |
||||||
|
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。 |
||||||
|
* @return URL 所代表远程资源的响应结果 |
||||||
|
*/ |
||||||
|
public static String sendGet(String url, String param) { |
||||||
|
StringBuilder result = new StringBuilder(); |
||||||
|
BufferedReader in = null; |
||||||
|
try { |
||||||
|
|
||||||
|
String urlNameString = url + (StringUtils.isNotEmpty(param) ? "?" + param : ""); |
||||||
|
URL realUrl = new URL(urlNameString); |
||||||
|
// 打开和URL之间的连接
|
||||||
|
URLConnection connection = realUrl.openConnection(); |
||||||
|
// 设置通用的请求属性
|
||||||
|
connection.setRequestProperty("accept", "*/*"); |
||||||
|
connection.setRequestProperty("connection", "Keep-Alive"); |
||||||
|
connection.setRequestProperty("user-agent", |
||||||
|
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); |
||||||
|
|
||||||
|
connection.connect(); |
||||||
|
|
||||||
|
//返回401时需再次用用户名和密码请求
|
||||||
|
//此情况返回服务器的 WWW-Authenticate 信息
|
||||||
|
if (((HttpURLConnection) connection).getResponseCode() == 401) { |
||||||
|
Map<String, List<String>> map = connection.getHeaderFields(); |
||||||
|
return "WWW-Authenticate:" + map.get("WWW-Authenticate").get(0); |
||||||
|
} |
||||||
|
|
||||||
|
in = new BufferedReader(new InputStreamReader(connection.getInputStream())); |
||||||
|
String line; |
||||||
|
while ((line = in.readLine()) != null) { |
||||||
|
result.append(line); |
||||||
|
} |
||||||
|
} catch (Exception e) { |
||||||
|
throw new RuntimeException("get请求发送失败",e); |
||||||
|
} |
||||||
|
// 使用finally块来关闭输入流
|
||||||
|
finally { |
||||||
|
try { |
||||||
|
if (in != null) in.close(); |
||||||
|
} catch (Exception e2) { |
||||||
|
e2.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
return result.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* HTTP set request property |
||||||
|
* |
||||||
|
* @param connection HttpConnection |
||||||
|
* @param wwwAuth 授权auth |
||||||
|
* @param realUrl 实际url |
||||||
|
* @param username 验证所需的用户名 |
||||||
|
* @param password 验证所需的密码 |
||||||
|
* @param method 请求方式 |
||||||
|
* @param type 返回xml和json格式数据,默认xml,传入json返回json数据 |
||||||
|
*/ |
||||||
|
private static void setRequestProperty(HttpURLConnection connection, String wwwAuth, URL realUrl, String username, String password, String method, String type) |
||||||
|
throws IOException { |
||||||
|
if (type != null && type.equals("json")) { |
||||||
|
// 返回json
|
||||||
|
connection.setRequestProperty("accept", "application/json;charset=UTF-8"); |
||||||
|
connection.setRequestProperty("Content-Type","application/json;charset=UTF-8"); |
||||||
|
connection.setRequestProperty("connection", "Keep-Alive"); |
||||||
|
connection.setRequestProperty("user-agent", |
||||||
|
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); |
||||||
|
} else { |
||||||
|
// 返回xml
|
||||||
|
if (!method.equals(GET)) { |
||||||
|
connection.setRequestProperty("Content-Type","application/json;charset=UTF-8"); |
||||||
|
} |
||||||
|
connection.setRequestProperty("accept", "*/*"); |
||||||
|
connection.setRequestProperty("connection", "Keep-Alive"); |
||||||
|
// connection.setRequestProperty("Cache-Control", "no-cache");
|
||||||
|
connection.setRequestProperty("user-agent", |
||||||
|
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); |
||||||
|
|
||||||
|
} |
||||||
|
//授权信息
|
||||||
|
String authentication = getAuthorization(wwwAuth, realUrl.getPath(), username, password, method); |
||||||
|
connection.setRequestProperty("Authorization", authentication); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 格式化请求返回信息,支持json和xml格式 |
||||||
|
* @param connection HttpConnection |
||||||
|
* @param type 指定返回数据格式,json、xml,默认xml |
||||||
|
* @return 返回数据 |
||||||
|
*/ |
||||||
|
private static String formatResultInfo(HttpURLConnection connection, String type) throws IOException { |
||||||
|
String result = ""; |
||||||
|
if (type != null && type.equals("json")) { |
||||||
|
result = String.format("{\"errCode\":%s, \"message\":%s}",connection.getResponseCode(),connection.getResponseMessage()); |
||||||
|
} else { |
||||||
|
result = String.format(" <?xml version=\"1.0\" encoding=\"UTF-8\" ?> " |
||||||
|
+ " <wmsResponse>" |
||||||
|
+ " <errCode>%d</errCode>" |
||||||
|
+ " <message>%s</message>" |
||||||
|
+ " </wmsResponse>",connection.getResponseCode(),connection.getResponseMessage()); |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,53 @@ |
|||||||
|
package com.ruoyi.api.util; |
||||||
|
|
||||||
|
import com.ruoyi.api.domain.RegularTime; |
||||||
|
|
||||||
|
public class RegularTimeUtil { |
||||||
|
|
||||||
|
// 每天整点报 整点 ASCII
|
||||||
|
public static RegularTime hourlyReportASCII(String asciiCode) { |
||||||
|
RegularTime regularTime = new RegularTime(); |
||||||
|
String[] strArr = asciiCode.split(" "); |
||||||
|
String s1 = strArr[0]; |
||||||
|
// 中心站地址
|
||||||
|
String centralStationAddr = s1.substring(0, 2); |
||||||
|
regularTime.setCentralStationAddr(centralStationAddr); |
||||||
|
// 遥测站地址
|
||||||
|
String stationAddr = s1.substring(2, 12); |
||||||
|
regularTime.setStationAddr(stationAddr); |
||||||
|
// 密码
|
||||||
|
String password = s1.substring(12, 16); |
||||||
|
regularTime.setPassword(password); |
||||||
|
//功能码
|
||||||
|
String code = s1.substring(16, 18); |
||||||
|
regularTime.setCode(code); |
||||||
|
//报文上下行标识和长度 报文标识和长度
|
||||||
|
String msgIDAndLength = s1.substring(18, 22); |
||||||
|
regularTime.setMsgIdAndLength(msgIDAndLength); |
||||||
|
// 流水号
|
||||||
|
String serialNum = s1.substring(22, 26); |
||||||
|
regularTime.setSerialNum(serialNum); |
||||||
|
// 发报时间
|
||||||
|
String dispatchTime = s1.substring(26, 38); |
||||||
|
regularTime.setDispatchTime(dispatchTime); |
||||||
|
// 遥测站分类码
|
||||||
|
String stationTypeCode = strArr[2]; |
||||||
|
regularTime.setStationTypeCode(stationTypeCode); |
||||||
|
// 观测时间
|
||||||
|
String observationTime = strArr[4]; |
||||||
|
regularTime.setObservationTime(observationTime); |
||||||
|
// 瞬时水位
|
||||||
|
String waterLevel = strArr[6]; |
||||||
|
regularTime.setWaterLevel(waterLevel); |
||||||
|
// 电压
|
||||||
|
String voltage = strArr[8]; |
||||||
|
regularTime.setVoltage(voltage); |
||||||
|
// 温度
|
||||||
|
String temperature = strArr[10]; |
||||||
|
regularTime.setTemperature(temperature); |
||||||
|
// 校验
|
||||||
|
String checkCode = strArr[11]; |
||||||
|
regularTime.setCheckCode(checkCode); |
||||||
|
return regularTime; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,105 @@ |
|||||||
|
package com.ruoyi.code.camera.controller; |
||||||
|
|
||||||
|
import com.ruoyi.code.camera.domain.CameraBrand; |
||||||
|
import com.ruoyi.code.camera.service.ICameraBrandService; |
||||||
|
import com.ruoyi.common.annotation.Log; |
||||||
|
import com.ruoyi.common.core.controller.BaseController; |
||||||
|
import com.ruoyi.common.core.page.R; |
||||||
|
import com.ruoyi.common.enums.BusinessType; |
||||||
|
import com.ruoyi.common.utils.poi.ExcelUtil; |
||||||
|
import org.springframework.security.access.prepost.PreAuthorize; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.util.Arrays; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
/** |
||||||
|
* brandController |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-26 |
||||||
|
*/ |
||||||
|
@RestController |
||||||
|
@RequestMapping("/web/brand") |
||||||
|
public class CameraBrandController extends BaseController |
||||||
|
{ |
||||||
|
@Resource |
||||||
|
private ICameraBrandService cameraBrandService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 查询列表 |
||||||
|
*/ |
||||||
|
@PreAuthorize("@ss.hasPermi('web:brand:list')") |
||||||
|
@RequestMapping("/list") |
||||||
|
public R list(@RequestParam Map<String, Object> params){ |
||||||
|
return cameraBrandService.queryPage(params); |
||||||
|
} |
||||||
|
/** |
||||||
|
* 查询列表 不带分页 |
||||||
|
*/ |
||||||
|
@RequestMapping("/brands") |
||||||
|
public R listBrand(){ |
||||||
|
return R.ok().put("data",cameraBrandService.list()); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取详细信息 |
||||||
|
*/ |
||||||
|
@RequestMapping("/info/{id}") |
||||||
|
@PreAuthorize("@ss.hasPermi('web:brand:query')") |
||||||
|
public R info(@PathVariable("id") Long id){ |
||||||
|
CameraBrand cameraBrand = cameraBrandService.getById(id); |
||||||
|
|
||||||
|
return R.ok().put("data", cameraBrand); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 导出列表 |
||||||
|
*/ |
||||||
|
@PreAuthorize("@ss.hasPermi('web:brand:export')") |
||||||
|
@Log(title = "列表", businessType = BusinessType.EXPORT) |
||||||
|
@PostMapping("/export") |
||||||
|
public void export(HttpServletResponse response, CameraBrand cameraBrand) |
||||||
|
{ |
||||||
|
List<CameraBrand> list = cameraBrandService.list(); |
||||||
|
ExcelUtil<CameraBrand> util = new ExcelUtil<CameraBrand>(CameraBrand.class); |
||||||
|
util.exportExcel(response, list, "列表数据"); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 新增 |
||||||
|
*/ |
||||||
|
@RequestMapping("/add") |
||||||
|
@Log(title = "CameraBrand", businessType = BusinessType.INSERT) |
||||||
|
@PreAuthorize("@ss.hasPermi('web:brand:add')") |
||||||
|
public R add(@RequestBody CameraBrand cameraBrand){ |
||||||
|
cameraBrandService.save(cameraBrand); |
||||||
|
return R.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 修改 |
||||||
|
*/ |
||||||
|
@RequestMapping("/edit") |
||||||
|
@PreAuthorize("@ss.hasPermi('web:brand:edit')") |
||||||
|
@Log(title = "CameraBrand", businessType = BusinessType.UPDATE) |
||||||
|
public R edit(@RequestBody CameraBrand cameraBrand){ |
||||||
|
cameraBrandService.updateById(cameraBrand); |
||||||
|
return R.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 删除 |
||||||
|
*/ |
||||||
|
@RequestMapping("/delete/{ids}") |
||||||
|
@PreAuthorize("@ss.hasPermi('web:brand:remove')") |
||||||
|
@Log(title = "CameraBrand", businessType = BusinessType.DELETE) |
||||||
|
public R delete(@PathVariable Long[] ids){ |
||||||
|
cameraBrandService.removeByIds(Arrays.asList(ids)); |
||||||
|
return R.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
package com.ruoyi.code.camera.domain; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import org.apache.commons.lang3.builder.ToStringBuilder; |
||||||
|
import org.apache.commons.lang3.builder.ToStringStyle; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.ruoyi.common.annotation.Excel; |
||||||
|
import java.io.Serializable; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* brand对象 camera_brand |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-26 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@TableName("camera_brand") |
||||||
|
public class CameraBrand implements Serializable |
||||||
|
{ |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
/** id */ |
||||||
|
@TableId(type = IdType.INPUT) |
||||||
|
private Long id; |
||||||
|
|
||||||
|
/** 品牌名称 */ |
||||||
|
private String name; |
||||||
|
|
||||||
|
/** 品牌型号 */ |
||||||
|
private String model; |
||||||
|
|
||||||
|
/** rtsp地址 */ |
||||||
|
private String rtsp; |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,15 @@ |
|||||||
|
package com.ruoyi.code.camera.domain; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
@Data |
||||||
|
public class CameraParams { |
||||||
|
/** */ |
||||||
|
private Double lstart; |
||||||
|
/** 某一时刻水位+水位上水尺长度,单位m */ |
||||||
|
private Double tlen; |
||||||
|
/** 某一时刻水面上水尺长度(单位米)*/ |
||||||
|
private Double clen; |
||||||
|
/** 和水面上的水尺长度对应像素 */ |
||||||
|
private Double cp; |
||||||
|
} |
@ -0,0 +1,18 @@ |
|||||||
|
package com.ruoyi.code.camera.mapper; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import org.apache.ibatis.annotations.Mapper; |
||||||
|
import com.ruoyi.code.camera.domain.CameraBrand; |
||||||
|
|
||||||
|
/** |
||||||
|
* Mapper接口 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-26 |
||||||
|
*/ |
||||||
|
@Mapper |
||||||
|
public interface CameraBrandMapper extends BaseMapper<CameraBrand> |
||||||
|
{ |
||||||
|
|
||||||
|
} |
@ -1,60 +1,64 @@ |
|||||||
//package com.ruoyi.code.camera.scheduled;
|
package com.ruoyi.code.camera.scheduled; |
||||||
//
|
|
||||||
//import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON; |
||||||
//import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray; |
||||||
//import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject; |
||||||
//import com.ruoyi.code.camera.domain.Camera;
|
import com.ruoyi.code.camera.domain.Camera; |
||||||
//import com.ruoyi.code.camera.service.ICameraService;
|
import com.ruoyi.code.camera.service.ICameraService; |
||||||
//import com.ruoyi.common.core.page.R;
|
import com.ruoyi.common.core.page.R; |
||||||
//import com.ruoyi.common.utils.IPUtils;
|
import com.ruoyi.common.utils.IPUtils; |
||||||
//import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j; |
||||||
//import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
//import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration; |
||||||
//import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment; |
||||||
//import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling; |
||||||
//import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled; |
||||||
//import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component; |
||||||
//
|
|
||||||
//import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct; |
||||||
//import java.util.ArrayList;
|
import java.util.ArrayList; |
||||||
//import java.util.List;
|
import java.util.List; |
||||||
//
|
|
||||||
///*@Author: tongw
|
/*@Author: tongw |
||||||
// *@CreateDate: 2020/8/11 8:58
|
*@CreateDate: 2020/8/11 8:58 |
||||||
// *@Description:
|
*@Description: |
||||||
// **/
|
**/ |
||||||
//
|
|
||||||
//@Component
|
@Component |
||||||
//@Configuration
|
@Configuration |
||||||
//@EnableScheduling
|
@EnableScheduling |
||||||
//public class RegisterServer {
|
public class RegisterServer { |
||||||
// private static String sercer_ip = "";
|
private static String localip = ""; |
||||||
//
|
private static String accessmode = ""; |
||||||
// @Autowired
|
|
||||||
// private Environment env;
|
@Autowired |
||||||
//
|
private Environment env; |
||||||
// @PostConstruct
|
|
||||||
// public void config() {
|
@PostConstruct |
||||||
// sercer_ip = env.getProperty("localip");
|
public void config() { |
||||||
// }
|
localip = env.getProperty("localip"); |
||||||
// @Autowired
|
accessmode = env.getProperty("accessmode"); |
||||||
// private ICameraService cameraService;
|
} |
||||||
//
|
@Autowired |
||||||
// @Scheduled(initialDelay = 5000, fixedRate = Long.MAX_VALUE)
|
private ICameraService cameraService; |
||||||
// public void synStart(){
|
|
||||||
// start();
|
@Scheduled(initialDelay = 5000, fixedRate = Long.MAX_VALUE) |
||||||
// }
|
public void synStart(){ |
||||||
//
|
start(); |
||||||
// private void start(){
|
} |
||||||
|
|
||||||
|
private void start(){ |
||||||
// String ip = IPUtils.getLocalIpAddress();
|
// String ip = IPUtils.getLocalIpAddress();
|
||||||
// if(sercer_ip.equals(ip)){
|
String ip = "192.168.16.219"; |
||||||
// R result = cameraService.register();
|
System.out.println(ip); |
||||||
// if("0".equals(result.get("code").toString())){
|
if(localip.equals(ip) && "0".equals(accessmode)){ |
||||||
// System.out.println("主动注册服务已启动");
|
R result = cameraService.register(localip); |
||||||
// }else{
|
if("0".equals(result.get("code").toString())){ |
||||||
// System.out.println("主动注册服务启动失败");
|
System.out.println("主动注册服务已启动"); |
||||||
// }
|
}else{ |
||||||
// }
|
System.out.println("主动注册服务启动失败"); |
||||||
// }
|
} |
||||||
//
|
} |
||||||
//}
|
} |
||||||
|
|
||||||
|
} |
||||||
|
@ -0,0 +1,36 @@ |
|||||||
|
package com.ruoyi.code.camera.scheduled; |
||||||
|
|
||||||
|
import com.ruoyi.code.camera.service.ICameraService; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.context.annotation.Configuration; |
||||||
|
import org.springframework.core.env.Environment; |
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling; |
||||||
|
import org.springframework.scheduling.annotation.Scheduled; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import javax.annotation.PostConstruct; |
||||||
|
|
||||||
|
@Component |
||||||
|
@Configuration |
||||||
|
@EnableScheduling |
||||||
|
public class RtspScreenshotTask { |
||||||
|
private static String accessmode = ""; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private Environment env; |
||||||
|
|
||||||
|
@PostConstruct |
||||||
|
public void config() { |
||||||
|
accessmode = env.getProperty("accessmode"); |
||||||
|
} |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ICameraService cameraService; |
||||||
|
|
||||||
|
@Scheduled(cron = "0 0/5 * * * ?") |
||||||
|
public void rtspScreenshot(){ |
||||||
|
if("1".equals(accessmode)){ |
||||||
|
cameraService.pullRtspPhoto(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
package com.ruoyi.code.camera.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||||
|
import com.ruoyi.common.core.page.R; |
||||||
|
import java.util.Map; |
||||||
|
import com.ruoyi.code.camera.domain.CameraBrand; |
||||||
|
|
||||||
|
/** |
||||||
|
* Service接口 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-26 |
||||||
|
*/ |
||||||
|
public interface ICameraBrandService extends IService<CameraBrand> |
||||||
|
{ |
||||||
|
/** |
||||||
|
* 查询 |
||||||
|
*/ |
||||||
|
R queryPage(Map<String, Object> params); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,33 @@ |
|||||||
|
package com.ruoyi.code.camera.service.impl; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||||
|
import com.ruoyi.common.core.page.R; |
||||||
|
import com.ruoyi.common.utils.Query; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
import com.ruoyi.code.camera.mapper.CameraBrandMapper; |
||||||
|
import com.ruoyi.code.camera.domain.CameraBrand; |
||||||
|
import com.ruoyi.code.camera.service.ICameraBrandService; |
||||||
|
|
||||||
|
/** |
||||||
|
* Service业务层处理 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-26 |
||||||
|
*/ |
||||||
|
@Service("cameraBrandService") |
||||||
|
public class CameraBrandServiceImpl extends ServiceImpl<CameraBrandMapper, CameraBrand> implements ICameraBrandService |
||||||
|
{ |
||||||
|
@Override |
||||||
|
public R queryPage(Map<String, Object> params) { |
||||||
|
IPage<CameraBrand> page = this.page( |
||||||
|
new Query<CameraBrand>().getPage(params), |
||||||
|
new QueryWrapper<CameraBrand>() |
||||||
|
); |
||||||
|
|
||||||
|
return R.ok().put("count", page.getTotal()).put("data", page.getRecords()); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,98 @@ |
|||||||
|
package com.ruoyi.code.warning.controller; |
||||||
|
|
||||||
|
import com.ruoyi.code.warning.domain.WaAlarm; |
||||||
|
import com.ruoyi.code.warning.service.IWaAlarmService; |
||||||
|
import com.ruoyi.common.annotation.Log; |
||||||
|
import com.ruoyi.common.core.controller.BaseController; |
||||||
|
import com.ruoyi.common.core.page.R; |
||||||
|
import com.ruoyi.common.enums.BusinessType; |
||||||
|
import com.ruoyi.common.utils.poi.ExcelUtil; |
||||||
|
import org.springframework.security.access.prepost.PreAuthorize; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.util.Arrays; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
/** |
||||||
|
* 预警管理Controller |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-19 |
||||||
|
*/ |
||||||
|
@RestController |
||||||
|
@RequestMapping("/warning/alarm") |
||||||
|
public class WaAlarmController extends BaseController |
||||||
|
{ |
||||||
|
@Resource |
||||||
|
private IWaAlarmService waAlarmService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 查询列表 |
||||||
|
*/ |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:alarm:list')") |
||||||
|
@RequestMapping("/list") |
||||||
|
public R list(@RequestParam Map<String, Object> params){ |
||||||
|
return waAlarmService.queryPage(params); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取详细信息 |
||||||
|
*/ |
||||||
|
@RequestMapping("/info/{id}") |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:alarm:query')") |
||||||
|
public R info(@PathVariable("id") Long id){ |
||||||
|
WaAlarm waAlarm = waAlarmService.getById(id); |
||||||
|
|
||||||
|
return R.ok().put("data", waAlarm); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 导出列表 |
||||||
|
*/ |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:alarm:export')") |
||||||
|
@Log(title = "列表", businessType = BusinessType.EXPORT) |
||||||
|
@PostMapping("/export") |
||||||
|
public void export(HttpServletResponse response, WaAlarm waAlarm) |
||||||
|
{ |
||||||
|
List<WaAlarm> list = waAlarmService.list(); |
||||||
|
ExcelUtil<WaAlarm> util = new ExcelUtil<WaAlarm>(WaAlarm.class); |
||||||
|
util.exportExcel(response, list, "列表数据"); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 新增 |
||||||
|
*/ |
||||||
|
@RequestMapping("/add") |
||||||
|
@Log(title = "WaAlarm", businessType = BusinessType.INSERT) |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:alarm:add')") |
||||||
|
public R add(@RequestBody WaAlarm waAlarm){ |
||||||
|
waAlarmService.save(waAlarm); |
||||||
|
return R.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 修改 |
||||||
|
*/ |
||||||
|
@RequestMapping("/edit") |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:alarm:edit')") |
||||||
|
@Log(title = "WaAlarm", businessType = BusinessType.UPDATE) |
||||||
|
public R edit(@RequestBody WaAlarm waAlarm){ |
||||||
|
waAlarmService.updateById(waAlarm); |
||||||
|
return R.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 删除 |
||||||
|
*/ |
||||||
|
@RequestMapping("/delete/{ids}") |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:alarm:remove')") |
||||||
|
@Log(title = "WaAlarm", businessType = BusinessType.DELETE) |
||||||
|
public R delete(@PathVariable Long[] ids){ |
||||||
|
waAlarmService.removeByIds(Arrays.asList(ids)); |
||||||
|
return R.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,96 @@ |
|||||||
|
package com.ruoyi.code.warning.controller; |
||||||
|
|
||||||
|
import com.ruoyi.code.warning.domain.WaEmployee; |
||||||
|
import com.ruoyi.code.warning.service.IWaEmployeeService; |
||||||
|
import com.ruoyi.common.annotation.Log; |
||||||
|
import com.ruoyi.common.core.controller.BaseController; |
||||||
|
import com.ruoyi.common.core.page.R; |
||||||
|
import com.ruoyi.common.enums.BusinessType; |
||||||
|
import com.ruoyi.common.utils.poi.ExcelUtil; |
||||||
|
import org.springframework.security.access.prepost.PreAuthorize; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.util.Arrays; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
/** |
||||||
|
* 人员管理Controller |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-19 |
||||||
|
*/ |
||||||
|
@RestController |
||||||
|
@RequestMapping("/warning/employee") |
||||||
|
public class WaEmployeeController extends BaseController |
||||||
|
{ |
||||||
|
@Resource |
||||||
|
private IWaEmployeeService waEmployeeService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 查询列表 |
||||||
|
*/ |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:employee:list')") |
||||||
|
@RequestMapping("/list") |
||||||
|
public R list(@RequestParam Map<String, Object> params){ |
||||||
|
return waEmployeeService.queryPage(params); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取详细信息 |
||||||
|
*/ |
||||||
|
@RequestMapping("/info/{id}") |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:employee:query')") |
||||||
|
public R info(@PathVariable("id") Long id){ |
||||||
|
WaEmployee waEmployee = waEmployeeService.getById(id); |
||||||
|
return R.ok().put("data", waEmployee); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 导出列表 |
||||||
|
*/ |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:employee:export')") |
||||||
|
@Log(title = "列表", businessType = BusinessType.EXPORT) |
||||||
|
@PostMapping("/export") |
||||||
|
public void export(HttpServletResponse response, WaEmployee waEmployee) |
||||||
|
{ |
||||||
|
List<WaEmployee> list = waEmployeeService.list(); |
||||||
|
ExcelUtil<WaEmployee> util = new ExcelUtil<WaEmployee>(WaEmployee.class); |
||||||
|
util.exportExcel(response, list, "列表数据"); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 新增 |
||||||
|
*/ |
||||||
|
@RequestMapping("/add") |
||||||
|
@Log(title = "WaEmployee", businessType = BusinessType.INSERT) |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:employee:add')") |
||||||
|
public R add(@RequestBody WaEmployee waEmployee){ |
||||||
|
waEmployeeService.save(waEmployee); |
||||||
|
return R.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 修改 |
||||||
|
*/ |
||||||
|
@RequestMapping("/edit") |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:employee:edit')") |
||||||
|
@Log(title = "WaEmployee", businessType = BusinessType.UPDATE) |
||||||
|
public R edit(@RequestBody WaEmployee waEmployee){ |
||||||
|
waEmployeeService.updateById(waEmployee); |
||||||
|
return R.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 删除 |
||||||
|
*/ |
||||||
|
@RequestMapping("/delete/{ids}") |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:employee:remove')") |
||||||
|
@Log(title = "WaEmployee", businessType = BusinessType.DELETE) |
||||||
|
public R delete(@PathVariable Long[] ids){ |
||||||
|
return waEmployeeService.delByIds(Arrays.asList(ids)); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,96 @@ |
|||||||
|
package com.ruoyi.code.warning.controller; |
||||||
|
|
||||||
|
import com.ruoyi.code.warning.domain.WaMessage; |
||||||
|
import com.ruoyi.code.warning.service.IWaMessageService; |
||||||
|
import com.ruoyi.common.annotation.Log; |
||||||
|
import com.ruoyi.common.core.controller.BaseController; |
||||||
|
import com.ruoyi.common.core.page.R; |
||||||
|
import com.ruoyi.common.enums.BusinessType; |
||||||
|
import com.ruoyi.common.utils.poi.ExcelUtil; |
||||||
|
import org.springframework.security.access.prepost.PreAuthorize; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import java.util.Arrays; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
/** |
||||||
|
* 短信管理Controller |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-19 |
||||||
|
*/ |
||||||
|
@RestController |
||||||
|
@RequestMapping("/warning/message") |
||||||
|
public class WaMessageController extends BaseController |
||||||
|
{ |
||||||
|
@Resource |
||||||
|
private IWaMessageService waMessageService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 查询列表 |
||||||
|
*/ |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:message:list')") |
||||||
|
@RequestMapping("/list") |
||||||
|
public R list(@RequestParam Map<String, Object> params){ |
||||||
|
return waMessageService.queryPage(params); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取详细信息 |
||||||
|
*/ |
||||||
|
@RequestMapping("/info/{id}") |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:message:query')") |
||||||
|
public R info(@PathVariable("id") Long id){ |
||||||
|
WaMessage waMessage = waMessageService.selectById(id); |
||||||
|
return R.ok().put("data", waMessage); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 导出列表 |
||||||
|
*/ |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:message:export')") |
||||||
|
@Log(title = "列表", businessType = BusinessType.EXPORT) |
||||||
|
@PostMapping("/export") |
||||||
|
public void export(HttpServletResponse response, WaMessage waMessage) |
||||||
|
{ |
||||||
|
List<WaMessage> list = waMessageService.list(); |
||||||
|
ExcelUtil<WaMessage> util = new ExcelUtil<WaMessage>(WaMessage.class); |
||||||
|
util.exportExcel(response, list, "列表数据"); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 新增 |
||||||
|
*/ |
||||||
|
@RequestMapping("/add") |
||||||
|
@Log(title = "WaMessage", businessType = BusinessType.INSERT) |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:message:add')") |
||||||
|
public R add(@RequestBody WaMessage waMessage){ |
||||||
|
return waMessageService.saveMessage(waMessage); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 修改 |
||||||
|
*/ |
||||||
|
@RequestMapping("/edit") |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:message:edit')") |
||||||
|
@Log(title = "WaMessage", businessType = BusinessType.UPDATE) |
||||||
|
public R edit(@RequestBody WaMessage waMessage){ |
||||||
|
waMessageService.updateByMessage(waMessage); |
||||||
|
return R.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 删除 |
||||||
|
*/ |
||||||
|
@RequestMapping("/delete/{ids}") |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:message:remove')") |
||||||
|
@Log(title = "WaMessage", businessType = BusinessType.DELETE) |
||||||
|
public R delete(@PathVariable Long[] ids){ |
||||||
|
waMessageService.delByIds(Arrays.asList(ids)); |
||||||
|
return R.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,106 @@ |
|||||||
|
package com.ruoyi.code.warning.controller; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Arrays; |
||||||
|
import java.util.Map; |
||||||
|
import javax.servlet.http.HttpServletResponse; |
||||||
|
import javax.annotation.Resource; |
||||||
|
import com.ruoyi.common.core.page.R; |
||||||
|
import org.springframework.security.access.prepost.PreAuthorize; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||||
|
import org.springframework.web.bind.annotation.PutMapping; |
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping; |
||||||
|
import org.springframework.web.bind.annotation.PathVariable; |
||||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
import com.ruoyi.common.annotation.Log; |
||||||
|
import com.ruoyi.common.core.controller.BaseController; |
||||||
|
import com.ruoyi.common.enums.BusinessType; |
||||||
|
import com.ruoyi.code.warning.domain.WaThreshold; |
||||||
|
import com.ruoyi.code.warning.service.IWaThresholdService; |
||||||
|
import com.ruoyi.common.utils.poi.ExcelUtil; |
||||||
|
/** |
||||||
|
* 阈值管理Controller |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-19 |
||||||
|
*/ |
||||||
|
@RestController |
||||||
|
@RequestMapping("/warning/threshold") |
||||||
|
public class WaThresholdController extends BaseController |
||||||
|
{ |
||||||
|
@Resource |
||||||
|
private IWaThresholdService waThresholdService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 查询列表 |
||||||
|
*/ |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:threshold:list')") |
||||||
|
@RequestMapping("/list") |
||||||
|
public R list(@RequestParam Map<String, Object> params){ |
||||||
|
return waThresholdService.queryPage(params); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取详细信息 |
||||||
|
*/ |
||||||
|
@RequestMapping("/info/{id}") |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:threshold:query')") |
||||||
|
public R info(@PathVariable("id") Long id){ |
||||||
|
WaThreshold waThreshold = waThresholdService.getById(id); |
||||||
|
|
||||||
|
return R.ok().put("data", waThreshold); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 导出列表 |
||||||
|
*/ |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:threshold:export')") |
||||||
|
@Log(title = "列表", businessType = BusinessType.EXPORT) |
||||||
|
@PostMapping("/export") |
||||||
|
public void export(HttpServletResponse response, WaThreshold waThreshold) |
||||||
|
{ |
||||||
|
List<WaThreshold> list = waThresholdService.list(); |
||||||
|
ExcelUtil<WaThreshold> util = new ExcelUtil<WaThreshold>(WaThreshold.class); |
||||||
|
util.exportExcel(response, list, "列表数据"); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 新增 |
||||||
|
*/ |
||||||
|
@RequestMapping("/add") |
||||||
|
@Log(title = "WaThreshold", businessType = BusinessType.INSERT) |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:threshold:add')") |
||||||
|
public R add(@RequestBody WaThreshold waThreshold){ |
||||||
|
waThresholdService.save(waThreshold); |
||||||
|
return R.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 修改 |
||||||
|
*/ |
||||||
|
@RequestMapping("/edit") |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:threshold:edit')") |
||||||
|
@Log(title = "WaThreshold", businessType = BusinessType.UPDATE) |
||||||
|
public R edit(@RequestBody WaThreshold waThreshold){ |
||||||
|
waThresholdService.updateById(waThreshold); |
||||||
|
return R.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 删除 |
||||||
|
*/ |
||||||
|
@RequestMapping("/delete/{ids}") |
||||||
|
@PreAuthorize("@ss.hasPermi('warning:threshold:remove')") |
||||||
|
@Log(title = "WaThreshold", businessType = BusinessType.DELETE) |
||||||
|
public R delete(@PathVariable Long[] ids){ |
||||||
|
waThresholdService.removeByIds(Arrays.asList(ids)); |
||||||
|
return R.ok(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,49 @@ |
|||||||
|
package com.ruoyi.code.warning.domain; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableField; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||||
|
import lombok.Data; |
||||||
|
import org.springframework.format.annotation.DateTimeFormat; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 预警管理对象 wa_alarm |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-19 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@TableName("wa_alarm") |
||||||
|
public class WaAlarm implements Serializable |
||||||
|
{ |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
/** 预警id */ |
||||||
|
@TableId(type = IdType.INPUT) |
||||||
|
private Long id; |
||||||
|
|
||||||
|
/** 测站id */ |
||||||
|
private Long stnmId; |
||||||
|
|
||||||
|
/** 预警内容 */ |
||||||
|
private String alarmContent; |
||||||
|
|
||||||
|
/** 预警时间 */ |
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
||||||
|
private Date alarmTime; |
||||||
|
|
||||||
|
/** 0 未删除 1 删除 */ |
||||||
|
// @TableLogic
|
||||||
|
private Long deleted; |
||||||
|
|
||||||
|
|
||||||
|
@TableField(exist = false) |
||||||
|
private String stnm; |
||||||
|
} |
@ -0,0 +1,36 @@ |
|||||||
|
package com.ruoyi.code.warning.domain; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import org.apache.commons.lang3.builder.ToStringBuilder; |
||||||
|
import org.apache.commons.lang3.builder.ToStringStyle; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.ruoyi.common.annotation.Excel; |
||||||
|
import java.io.Serializable; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 短信人员对象 wa_emp_msg |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-20 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@TableName("wa_emp_msg") |
||||||
|
public class WaEmpMsg implements Serializable |
||||||
|
{ |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
/** id */ |
||||||
|
@TableId(type = IdType.INPUT) |
||||||
|
private Long id; |
||||||
|
|
||||||
|
/** 人员id */ |
||||||
|
private Long empId; |
||||||
|
|
||||||
|
/** 消息id */ |
||||||
|
private Long msgId; |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
package com.ruoyi.code.warning.domain; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 人员管理对象 wa_employee |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-19 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@TableName("wa_employee") |
||||||
|
public class WaEmployee implements Serializable |
||||||
|
{ |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
/** id */ |
||||||
|
@TableId(type = IdType.INPUT) |
||||||
|
private Long id; |
||||||
|
|
||||||
|
/** 姓名 */ |
||||||
|
private String name; |
||||||
|
|
||||||
|
/** 手机号 */ |
||||||
|
private Long phone; |
||||||
|
|
||||||
|
/** 备注 */ |
||||||
|
private String remarks; |
||||||
|
|
||||||
|
/** 0 未删除 1 删除 */ |
||||||
|
// @TableLogic
|
||||||
|
private Long deleted; |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,50 @@ |
|||||||
|
package com.ruoyi.code.warning.domain; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 短信管理对象 wa_message |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-19 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@TableName("wa_message") |
||||||
|
public class WaMessage implements Serializable |
||||||
|
{ |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
/** 短信id */ |
||||||
|
@TableId(value = "id",type = IdType.AUTO) |
||||||
|
private Long id; |
||||||
|
|
||||||
|
/** 短信名称 */ |
||||||
|
private String msgName; |
||||||
|
|
||||||
|
/** 短信内容 */ |
||||||
|
private String msgContent; |
||||||
|
|
||||||
|
/** 发送时间 */ |
||||||
|
private Date sendTime; |
||||||
|
|
||||||
|
/** 消息状态 */ |
||||||
|
private String sendStaus; |
||||||
|
|
||||||
|
/** 测站id */ |
||||||
|
private Long stnmId; |
||||||
|
|
||||||
|
/** 人员id */ |
||||||
|
@TableField(exist = false) |
||||||
|
private Long empId; |
||||||
|
|
||||||
|
/** 0 未删除 1 删除 */ |
||||||
|
// @TableLogic
|
||||||
|
private Long deleted; |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,40 @@ |
|||||||
|
package com.ruoyi.code.warning.domain; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 阈值管理对象 wa_threshold |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-19 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@TableName("wa_threshold") |
||||||
|
public class WaThreshold implements Serializable |
||||||
|
{ |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
/** 阈值id */ |
||||||
|
@TableId(type = IdType.INPUT) |
||||||
|
private Long id; |
||||||
|
|
||||||
|
/** 阈值一级 */ |
||||||
|
private String thresholdLevelL; |
||||||
|
|
||||||
|
/** 阈值二级 */ |
||||||
|
private String thresholdLevelLl; |
||||||
|
|
||||||
|
/** 阈值三级 */ |
||||||
|
private String thresholdLevelLll; |
||||||
|
|
||||||
|
/** 测站id */ |
||||||
|
private Long stnmId; |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,22 @@ |
|||||||
|
package com.ruoyi.code.warning.mapper; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import com.ruoyi.code.warning.domain.WaAlarm; |
||||||
|
import org.apache.ibatis.annotations.Mapper; |
||||||
|
import org.apache.ibatis.annotations.Param; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* Mapper接口 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-19 |
||||||
|
*/ |
||||||
|
@Mapper |
||||||
|
public interface WaAlarmMapper extends BaseMapper<WaAlarm> |
||||||
|
{ |
||||||
|
|
||||||
|
List<WaAlarm> queryAlarm(@Param("params") Map<String, Object> params); |
||||||
|
} |
@ -0,0 +1,23 @@ |
|||||||
|
package com.ruoyi.code.warning.mapper; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import com.ruoyi.code.warning.domain.WaEmpMsg; |
||||||
|
import org.apache.ibatis.annotations.Mapper; |
||||||
|
import org.apache.ibatis.annotations.Param; |
||||||
|
|
||||||
|
/** |
||||||
|
* Mapper接口 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-20 |
||||||
|
*/ |
||||||
|
@Mapper |
||||||
|
public interface WaEmpMsgMapper extends BaseMapper<WaEmpMsg> |
||||||
|
{ |
||||||
|
|
||||||
|
boolean saveMessageAndStation(@Param("empId")Long empId, @Param("msgId")Long msgId); |
||||||
|
|
||||||
|
Long selectEmpIdByMsgId(Long msgId); |
||||||
|
|
||||||
|
WaEmpMsg selectByMsgId(Long id); |
||||||
|
} |
@ -0,0 +1,18 @@ |
|||||||
|
package com.ruoyi.code.warning.mapper; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import org.apache.ibatis.annotations.Mapper; |
||||||
|
import com.ruoyi.code.warning.domain.WaEmployee; |
||||||
|
|
||||||
|
/** |
||||||
|
* Mapper接口 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-19 |
||||||
|
*/ |
||||||
|
@Mapper |
||||||
|
public interface WaEmployeeMapper extends BaseMapper<WaEmployee> |
||||||
|
{ |
||||||
|
|
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
package com.ruoyi.code.warning.mapper; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import com.ruoyi.code.warning.domain.WaMessage; |
||||||
|
import org.apache.ibatis.annotations.Mapper; |
||||||
|
|
||||||
|
/** |
||||||
|
* Mapper接口 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-19 |
||||||
|
*/ |
||||||
|
@Mapper |
||||||
|
public interface WaMessageMapper extends BaseMapper<WaMessage> |
||||||
|
{ |
||||||
|
|
||||||
|
} |
@ -0,0 +1,18 @@ |
|||||||
|
package com.ruoyi.code.warning.mapper; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import org.apache.ibatis.annotations.Mapper; |
||||||
|
import com.ruoyi.code.warning.domain.WaThreshold; |
||||||
|
|
||||||
|
/** |
||||||
|
* Mapper接口 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-19 |
||||||
|
*/ |
||||||
|
@Mapper |
||||||
|
public interface WaThresholdMapper extends BaseMapper<WaThreshold> |
||||||
|
{ |
||||||
|
|
||||||
|
} |
@ -0,0 +1,24 @@ |
|||||||
|
package com.ruoyi.code.warning.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||||
|
import com.ruoyi.code.warning.domain.WaAlarm; |
||||||
|
import com.ruoyi.common.core.page.R; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* Service接口 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-19 |
||||||
|
*/ |
||||||
|
public interface IWaAlarmService extends IService<WaAlarm> |
||||||
|
{ |
||||||
|
/** |
||||||
|
* 查询 |
||||||
|
*/ |
||||||
|
R queryPage(Map<String, Object> params); |
||||||
|
|
||||||
|
List<WaAlarm> queryAlarm(Map<String, Object> params); |
||||||
|
} |
@ -0,0 +1,21 @@ |
|||||||
|
package com.ruoyi.code.warning.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||||
|
import com.ruoyi.common.core.page.R; |
||||||
|
import java.util.Map; |
||||||
|
import com.ruoyi.code.warning.domain.WaEmpMsg; |
||||||
|
|
||||||
|
/** |
||||||
|
* Service接口 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-20 |
||||||
|
*/ |
||||||
|
public interface IWaEmpMsgService extends IService<WaEmpMsg> |
||||||
|
{ |
||||||
|
/** |
||||||
|
* 查询 |
||||||
|
*/ |
||||||
|
R queryPage(Map<String, Object> params); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,24 @@ |
|||||||
|
package com.ruoyi.code.warning.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||||
|
import com.ruoyi.code.warning.domain.WaEmployee; |
||||||
|
import com.ruoyi.common.core.page.R; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* Service接口 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-19 |
||||||
|
*/ |
||||||
|
public interface IWaEmployeeService extends IService<WaEmployee> |
||||||
|
{ |
||||||
|
/** |
||||||
|
* 查询 |
||||||
|
*/ |
||||||
|
R queryPage(Map<String, Object> params); |
||||||
|
|
||||||
|
R delByIds(List<Long> asList); |
||||||
|
} |
@ -0,0 +1,35 @@ |
|||||||
|
package com.ruoyi.code.warning.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||||
|
import com.ruoyi.code.warning.domain.WaMessage; |
||||||
|
import com.ruoyi.common.core.page.R; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* Service接口 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-19 |
||||||
|
*/ |
||||||
|
public interface IWaMessageService extends IService<WaMessage> |
||||||
|
{ |
||||||
|
/** |
||||||
|
* 查询 |
||||||
|
*/ |
||||||
|
R queryPage(Map<String, Object> params); |
||||||
|
|
||||||
|
/** |
||||||
|
* 保存短信 |
||||||
|
* @param waMessage |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
R saveMessage(WaMessage waMessage); |
||||||
|
|
||||||
|
WaMessage selectById(Long id); |
||||||
|
|
||||||
|
void updateByMessage(WaMessage waMessage); |
||||||
|
|
||||||
|
void delByIds(List<Long> asList); |
||||||
|
} |
@ -0,0 +1,22 @@ |
|||||||
|
package com.ruoyi.code.warning.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService; |
||||||
|
import com.ruoyi.code.warning.domain.WaThreshold; |
||||||
|
import com.ruoyi.common.core.page.R; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* Service接口 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-19 |
||||||
|
*/ |
||||||
|
public interface IWaThresholdService extends IService<WaThreshold> |
||||||
|
{ |
||||||
|
/** |
||||||
|
* 查询 |
||||||
|
*/ |
||||||
|
R queryPage(Map<String, Object> params); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,44 @@ |
|||||||
|
package com.ruoyi.code.warning.service.impl; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||||
|
import com.ruoyi.code.warning.domain.WaAlarm; |
||||||
|
import com.ruoyi.code.warning.mapper.WaAlarmMapper; |
||||||
|
import com.ruoyi.code.warning.service.IWaAlarmService; |
||||||
|
import com.ruoyi.common.core.page.R; |
||||||
|
import com.ruoyi.common.utils.Query; |
||||||
|
import com.ruoyi.common.utils.StringUtils; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* Service业务层处理 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-19 |
||||||
|
*/ |
||||||
|
@Service("waAlarmService") |
||||||
|
public class WaAlarmServiceImpl extends ServiceImpl<WaAlarmMapper, WaAlarm> implements IWaAlarmService |
||||||
|
{ |
||||||
|
@Override |
||||||
|
public R queryPage(Map<String, Object> params) { |
||||||
|
Object stnmId = params.get("stnmId"); |
||||||
|
Object alarmTime = params.get("alarmTime"); |
||||||
|
IPage<WaAlarm> page = this.page( |
||||||
|
new Query<WaAlarm>().getPage(params), |
||||||
|
new QueryWrapper<WaAlarm>() |
||||||
|
.eq(StringUtils.isNotNull(stnmId),"stnm_id",stnmId) |
||||||
|
.eq(StringUtils.isNotNull(alarmTime),"alarm_time",alarmTime) |
||||||
|
); |
||||||
|
|
||||||
|
return R.ok().put("count", page.getTotal()).put("data", page.getRecords()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public List<WaAlarm> queryAlarm(Map<String, Object> params){ |
||||||
|
return baseMapper.queryAlarm(params); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,33 @@ |
|||||||
|
package com.ruoyi.code.warning.service.impl; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||||
|
import com.ruoyi.common.core.page.R; |
||||||
|
import com.ruoyi.common.utils.Query; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
import com.ruoyi.code.warning.mapper.WaEmpMsgMapper; |
||||||
|
import com.ruoyi.code.warning.domain.WaEmpMsg; |
||||||
|
import com.ruoyi.code.warning.service.IWaEmpMsgService; |
||||||
|
|
||||||
|
/** |
||||||
|
* Service业务层处理 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-20 |
||||||
|
*/ |
||||||
|
@Service("waEmpMsgService") |
||||||
|
public class WaEmpMsgServiceImpl extends ServiceImpl<WaEmpMsgMapper, WaEmpMsg> implements IWaEmpMsgService |
||||||
|
{ |
||||||
|
@Override |
||||||
|
public R queryPage(Map<String, Object> params) { |
||||||
|
IPage<WaEmpMsg> page = this.page( |
||||||
|
new Query<WaEmpMsg>().getPage(params), |
||||||
|
new QueryWrapper<WaEmpMsg>() |
||||||
|
); |
||||||
|
|
||||||
|
return R.ok().put("count", page.getTotal()).put("data", page.getRecords()); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,59 @@ |
|||||||
|
package com.ruoyi.code.warning.service.impl; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||||
|
import com.ruoyi.code.warning.domain.WaEmpMsg; |
||||||
|
import com.ruoyi.code.warning.domain.WaEmployee; |
||||||
|
import com.ruoyi.code.warning.mapper.WaEmpMsgMapper; |
||||||
|
import com.ruoyi.code.warning.mapper.WaEmployeeMapper; |
||||||
|
import com.ruoyi.code.warning.service.IWaEmployeeService; |
||||||
|
import com.ruoyi.common.core.page.R; |
||||||
|
import com.ruoyi.common.utils.Query; |
||||||
|
import org.apache.commons.lang3.ObjectUtils; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* Service业务层处理 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-19 |
||||||
|
*/ |
||||||
|
@Service("waEmployeeService") |
||||||
|
public class WaEmployeeServiceImpl extends ServiceImpl<WaEmployeeMapper, WaEmployee> implements IWaEmployeeService |
||||||
|
{ |
||||||
|
@Autowired |
||||||
|
private WaEmpMsgMapper waEmpMsgMapper; |
||||||
|
|
||||||
|
@Override |
||||||
|
public R queryPage(Map<String, Object> params) { |
||||||
|
Object name = params.get("name"); |
||||||
|
Object phone = params.get("phone"); |
||||||
|
IPage<WaEmployee> page = this.page( |
||||||
|
new Query<WaEmployee>().getPage(params), |
||||||
|
new QueryWrapper<WaEmployee>() |
||||||
|
.like(ObjectUtils.isNotEmpty(name),"name",name) |
||||||
|
.eq(ObjectUtils.isNotEmpty(phone),"phone",phone) |
||||||
|
); |
||||||
|
|
||||||
|
return R.ok().put("count", page.getTotal()).put("data", page.getRecords()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public R delByIds(List<Long> asList) { |
||||||
|
if (asList.size() > 0){ |
||||||
|
List<WaEmpMsg> list = waEmpMsgMapper.selectList(new LambdaQueryWrapper<WaEmpMsg>() |
||||||
|
.in(WaEmpMsg::getEmpId, asList)); |
||||||
|
if (list.size() == 0) { |
||||||
|
baseMapper.deleteBatchIds(asList); |
||||||
|
return R.ok(); |
||||||
|
} |
||||||
|
} |
||||||
|
return R.error("该用户有短信消息,不能删除!"); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,90 @@ |
|||||||
|
package com.ruoyi.code.warning.service.impl; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||||
|
import com.ruoyi.code.warning.domain.WaEmpMsg; |
||||||
|
import com.ruoyi.code.warning.domain.WaMessage; |
||||||
|
import com.ruoyi.code.warning.mapper.WaEmpMsgMapper; |
||||||
|
import com.ruoyi.code.warning.mapper.WaMessageMapper; |
||||||
|
import com.ruoyi.code.warning.service.IWaMessageService; |
||||||
|
import com.ruoyi.common.core.page.R; |
||||||
|
import com.ruoyi.common.utils.Query; |
||||||
|
import org.apache.commons.lang3.ObjectUtils; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
import org.springframework.transaction.annotation.Transactional; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* Service业务层处理 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-19 |
||||||
|
*/ |
||||||
|
@Service("waMessageService") |
||||||
|
public class WaMessageServiceImpl extends ServiceImpl<WaMessageMapper, WaMessage> implements IWaMessageService |
||||||
|
{ |
||||||
|
@Autowired |
||||||
|
private WaEmpMsgMapper waEmpMsgMapper; |
||||||
|
|
||||||
|
@Override |
||||||
|
public R queryPage(Map<String, Object> params) { |
||||||
|
Object stnmId = params.get("stnmId"); |
||||||
|
Object sendTime = params.get("sendTime"); |
||||||
|
Object sendStatus = params.get("sendStaus"); |
||||||
|
IPage<WaMessage> page = this.page( |
||||||
|
new Query<WaMessage>().getPage(params), |
||||||
|
new QueryWrapper<WaMessage>() |
||||||
|
.eq(ObjectUtils.isNotEmpty(stnmId),"stnm_id",stnmId) |
||||||
|
.eq(ObjectUtils.isNotEmpty(sendTime),"send_time",sendTime) |
||||||
|
.eq(ObjectUtils.isNotEmpty(sendStatus),"send_staus",sendStatus) |
||||||
|
); |
||||||
|
|
||||||
|
return R.ok().put("count", page.getTotal()).put("data", page.getRecords()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
@Transactional |
||||||
|
public R saveMessage(WaMessage waMessage) { |
||||||
|
int result = baseMapper.insert(waMessage); |
||||||
|
System.out.println(waMessage.getId()); |
||||||
|
if (result > 0){ |
||||||
|
boolean flag = waEmpMsgMapper.saveMessageAndStation(waMessage.getEmpId(),waMessage.getId()); |
||||||
|
if(flag){ |
||||||
|
return R.ok(); |
||||||
|
} |
||||||
|
} |
||||||
|
return R.error(); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
public WaMessage selectById(Long id) { |
||||||
|
WaMessage waMessage = baseMapper.selectById(id); |
||||||
|
Long msgId = waMessage.getId(); |
||||||
|
Long empId = waEmpMsgMapper.selectEmpIdByMsgId(msgId); |
||||||
|
waMessage.setEmpId(empId); |
||||||
|
return waMessage; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void updateByMessage(WaMessage waMessage) { |
||||||
|
baseMapper.updateById(waMessage); |
||||||
|
Long empId = waMessage.getEmpId(); |
||||||
|
WaEmpMsg waEmpMsg = waEmpMsgMapper.selectByMsgId(waMessage.getId()); |
||||||
|
waEmpMsg.setEmpId(empId); |
||||||
|
waEmpMsgMapper.updateById(waEmpMsg); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void delByIds(List<Long> asList) { |
||||||
|
baseMapper.deleteBatchIds(asList); |
||||||
|
waEmpMsgMapper.delete(new LambdaQueryWrapper<WaEmpMsg>() |
||||||
|
.in(WaEmpMsg::getMsgId,asList)); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,36 @@ |
|||||||
|
package com.ruoyi.code.warning.service.impl; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||||
|
import com.ruoyi.code.warning.domain.WaThreshold; |
||||||
|
import com.ruoyi.code.warning.mapper.WaThresholdMapper; |
||||||
|
import com.ruoyi.code.warning.service.IWaThresholdService; |
||||||
|
import com.ruoyi.common.core.page.R; |
||||||
|
import com.ruoyi.common.utils.Query; |
||||||
|
import org.apache.commons.lang3.ObjectUtils; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* Service业务层处理 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
* @date 2022-09-19 |
||||||
|
*/ |
||||||
|
@Service("waThresholdService") |
||||||
|
public class WaThresholdServiceImpl extends ServiceImpl<WaThresholdMapper, WaThreshold> implements IWaThresholdService |
||||||
|
{ |
||||||
|
@Override |
||||||
|
public R queryPage(Map<String, Object> params) { |
||||||
|
IPage<WaThreshold> page = this.page( |
||||||
|
new Query<WaThreshold>().getPage(params), |
||||||
|
new QueryWrapper<WaThreshold>() |
||||||
|
.eq(ObjectUtils.isNotEmpty(params.get("stnmId")),"stnm_id",params.get("stnmId")) |
||||||
|
); |
||||||
|
|
||||||
|
return R.ok().put("count", page.getTotal()).put("data", page.getRecords()); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,79 @@ |
|||||||
|
package utils; |
||||||
|
|
||||||
|
|
||||||
|
import org.apache.commons.codec.binary.Base64; |
||||||
|
|
||||||
|
import java.io.*; |
||||||
|
|
||||||
|
public class Base64Utils { |
||||||
|
/** |
||||||
|
* 图片转化成base64字符串 |
||||||
|
* |
||||||
|
* @param imgPath |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String GetImageStr(String imgPath) {// 将图片文件转化为字节数组字符串,并对其进行Base64编码处理
|
||||||
|
String imgFile = imgPath;// 待处理的图片
|
||||||
|
InputStream in = null; |
||||||
|
byte[] data = null; |
||||||
|
String encode = null; // 返回Base64编码过的字节数组字符串
|
||||||
|
// 对字节数组Base64编码
|
||||||
|
Base64 encoder = new Base64(); |
||||||
|
try { |
||||||
|
// 读取图片字节数组
|
||||||
|
in = new FileInputStream(imgFile); |
||||||
|
data = new byte[in.available()]; |
||||||
|
in.read(data); |
||||||
|
encode = encoder.encodeToString(data); |
||||||
|
} catch (IOException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} finally { |
||||||
|
try { |
||||||
|
in.close(); |
||||||
|
} catch (IOException e) { |
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
return encode; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* base64字符串转化成图片 |
||||||
|
* |
||||||
|
* @param imgData 图片编码 |
||||||
|
* @param imgFilePath 存放到本地路径 |
||||||
|
* @return |
||||||
|
* @throws IOException |
||||||
|
*/ |
||||||
|
@SuppressWarnings("finally") |
||||||
|
public static boolean GenerateImage(String imgData, String imgFilePath) throws IOException { // 对字节数组字符串进行Base64解码并生成图片
|
||||||
|
if (imgData == null) // 图像数据为空
|
||||||
|
return false; |
||||||
|
Base64 decoder = new Base64(); |
||||||
|
OutputStream out = null; |
||||||
|
try { |
||||||
|
out = new FileOutputStream(imgFilePath); |
||||||
|
// Base64解码
|
||||||
|
byte[] b = decoder.decode(imgData); |
||||||
|
for (int i = 0; i < b.length; ++i) { |
||||||
|
if (b[i] < 0) {// 调整异常数据
|
||||||
|
b[i] += 256; |
||||||
|
} |
||||||
|
} |
||||||
|
out.write(b); |
||||||
|
} catch (FileNotFoundException e) { |
||||||
|
// TODO Auto-generated catch block
|
||||||
|
System.out.println(e.getMessage()); |
||||||
|
e.printStackTrace(); |
||||||
|
} catch (IOException e) { |
||||||
|
// TODO Auto-generated catch block
|
||||||
|
System.out.println(e.getMessage()); |
||||||
|
e.printStackTrace(); |
||||||
|
} finally { |
||||||
|
out.flush(); |
||||||
|
out.close(); |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,301 @@ |
|||||||
|
package utils; |
||||||
|
|
||||||
|
import cn.hutool.core.util.RuntimeUtil; |
||||||
|
import com.alibaba.fastjson.JSON; |
||||||
|
import com.ruoyi.common.config.RuoYiConfig; |
||||||
|
import com.ruoyi.common.utils.DateUtils; |
||||||
|
import com.ruoyi.common.utils.http.HttpUtils; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.apache.commons.io.FileUtils; |
||||||
|
import org.apache.commons.lang3.StringUtils; |
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling; |
||||||
|
import org.springframework.scheduling.annotation.Scheduled; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
import org.springframework.transaction.annotation.Transactional; |
||||||
|
|
||||||
|
import javax.annotation.PreDestroy; |
||||||
|
import java.io.*; |
||||||
|
import java.util.Date; |
||||||
|
import java.util.concurrent.ConcurrentHashMap; |
||||||
|
|
||||||
|
/** |
||||||
|
* rtsp 转 hlv协议 |
||||||
|
* |
||||||
|
* @author kzw |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
@Slf4j |
||||||
|
@EnableScheduling |
||||||
|
public class RtspConvert { |
||||||
|
//转换map
|
||||||
|
private static ConcurrentHashMap<String, CoverThread> coverMap = new ConcurrentHashMap<>(); |
||||||
|
//拉流命令
|
||||||
|
private static final String ffmpegCmd = "ffmpeg -i \"%s\" -c copy -f hls -hls_time 5.0 -hls_list_size 2 -hls_flags 2 %s"; |
||||||
|
|
||||||
|
//ffmpeg -i "rtsp://admin:admin123@192.168.1.40:554/stream/realtime?channel=1&streamtype=0" -c copy -f hls -hls_time 4.0 -hls_list_size 2 -hls_flags 2 "D:\video\test.m3u8"
|
||||||
|
@PreDestroy |
||||||
|
public void closeProcess() { |
||||||
|
log.info("关闭ffmpeg转换进程,java程序不一定关闭process进程"); |
||||||
|
closeAllProcess(); |
||||||
|
for (String ip : coverMap.keySet()) { |
||||||
|
try { |
||||||
|
log.error("开始停止{}", ip); |
||||||
|
coverMap.get(ip).stopTask(); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* ffmpeg -i "rtsp://admin:xxx@192.168.0.251:554/Streaming/Channels/101" -c copy -f hls -hls_time 5.0 -hls_list_size 5 -hls_flags 2 F:\resources\hls\2000\live.m3u8 |
||||||
|
*/ |
||||||
|
/** |
||||||
|
* 检查设备ip是否能正常访问 |
||||||
|
*/ |
||||||
|
private boolean checkDeviceOnline(String ip) { |
||||||
|
String res = HttpUtils.sendGet("http://" + ip); |
||||||
|
if (StringUtils.isNotBlank(res)) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 转换rtsp并获取hls文件路径 |
||||||
|
* 视频地址 http.../control-api/upload/hls/{ip}/live.m3u8 |
||||||
|
*/ |
||||||
|
public String rtsp2Hls(String ip, String userName, String pwd) { |
||||||
|
System.out.println(JSON.toJSON(coverMap)); |
||||||
|
if (coverMap.containsKey(ip)) { |
||||||
|
CoverThread thread = coverMap.get(ip); |
||||||
|
if (thread == null || thread.getTaskState() != CoverThread.running) { |
||||||
|
} else { |
||||||
|
return StringUtils.replace(thread.getM3U8File(), RuoYiConfig.getProfile(), ""); |
||||||
|
} |
||||||
|
} |
||||||
|
String rtspUrl = "rtsp://" + userName + ":" + pwd + "@" + ip + ":554/stream/realtime?channel=1&streamtype=0"; |
||||||
|
String m3u8File = RuoYiConfig.getProfile() + File.separator+"upload" + File.separator + "hls" |
||||||
|
// String m3u8File = "D:" + File.separator + "ruoyi" + File.separator + "uploadPath" + File.separator + "hls"
|
||||||
|
+ File.separator + ip.replaceAll("\\.", "_") + File.separator + "live.m3u8"; |
||||||
|
startTransform(ip, rtspUrl, m3u8File, userName, pwd); |
||||||
|
CoverThread thread = coverMap.get(ip); |
||||||
|
if (thread != null) { |
||||||
|
return StringUtils.replace(thread.getM3U8File(), RuoYiConfig.getProfile(), ""); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 开启转换 |
||||||
|
*/ |
||||||
|
private void startTransform(String ip, String rtspUrl, String m3u8Path, String userName, String pwd) { |
||||||
|
log.info("转换rtsp, {},{},{}", ip, rtspUrl, m3u8Path); |
||||||
|
String memKey = "startLive" + ip; |
||||||
|
synchronized (memKey.intern()) { |
||||||
|
if (coverMap.containsKey(ip)) { |
||||||
|
stopTransform(ip); |
||||||
|
} |
||||||
|
CoverThread thread = new CoverThread(ip, rtspUrl, m3u8Path, userName, pwd); |
||||||
|
coverMap.put(ip, thread); |
||||||
|
thread.start(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 停止转换 |
||||||
|
*/ |
||||||
|
public void stopTransform(String ip) { |
||||||
|
String memKey = "startLive" + ip; |
||||||
|
synchronized (memKey.intern()) { |
||||||
|
System.out.println(JSON.toJSON(coverMap)); |
||||||
|
if (coverMap.containsKey(ip)) { |
||||||
|
CoverThread thread = coverMap.get(ip); |
||||||
|
if (thread != null && thread.getTaskState() != CoverThread.fail) { |
||||||
|
System.out.println("停止转换ip"+ip); |
||||||
|
thread.stopTask(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 监控所有的转换线程 |
||||||
|
*/ |
||||||
|
@Scheduled(cron = "0 0/8 * * * ?") |
||||||
|
public synchronized void monitorThreads() { |
||||||
|
for (String ip : coverMap.keySet()) { |
||||||
|
CoverThread thread = coverMap.get(ip); |
||||||
|
if (thread != null && thread.getTaskState() != CoverThread.running) { |
||||||
|
//线程出现异常
|
||||||
|
rtsp2Hls(ip, thread.getUserName(), thread.getPwd()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void closeAllProcess(){ |
||||||
|
String command = "taskkill /f /im ffmpeg.exe"; |
||||||
|
if(!isWin()){ |
||||||
|
command = "/usr/local/water-monitor-api/closeFFmpeg.sh"; |
||||||
|
} |
||||||
|
System.out.println("command ["+command+"]"); |
||||||
|
String result = RuntimeUtil.execForStr(command); |
||||||
|
System.out.println("command result ["+result+"]"); |
||||||
|
coverMap.clear(); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean isWin(){ |
||||||
|
String os = System.getProperty("os.name"); |
||||||
|
return os.toLowerCase().startsWith("win"); |
||||||
|
} |
||||||
|
|
||||||
|
public class RunThread extends Thread { |
||||||
|
private InputStream is; |
||||||
|
private String printType; |
||||||
|
|
||||||
|
RunThread(InputStream is, String printType) { |
||||||
|
this.is = is; |
||||||
|
this.printType = printType; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void run() { |
||||||
|
try { |
||||||
|
InputStreamReader isr = new InputStreamReader(is); |
||||||
|
BufferedReader br = new BufferedReader(isr); |
||||||
|
String line; |
||||||
|
while ((line = br.readLine()) != null) { |
||||||
|
log.info(printType + ">" + line); |
||||||
|
} |
||||||
|
} catch (IOException ioe) { |
||||||
|
log.info("RunThread error:", ioe); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 执行命令线程 |
||||||
|
*/ |
||||||
|
private class CoverThread extends Thread { |
||||||
|
private String ip; |
||||||
|
private String rtspUrl; |
||||||
|
private String m3u8File; |
||||||
|
private String userName; |
||||||
|
private String pwd; |
||||||
|
private int taskState = 0; //运行状态 0未开始 1进行中 -1失败
|
||||||
|
private static final int notStart = 0; |
||||||
|
private static final int running = 1; |
||||||
|
private static final int fail = -1; |
||||||
|
private Process process = null; |
||||||
|
|
||||||
|
CoverThread(String ip, String rtspUrl, String m3u8File, String userName, String pwd) { |
||||||
|
this.ip = ip; |
||||||
|
this.rtspUrl = rtspUrl; |
||||||
|
this.m3u8File = m3u8File; |
||||||
|
this.userName = userName; |
||||||
|
this.pwd = pwd; |
||||||
|
setName("m3u8-" + ip); |
||||||
|
this.taskState = notStart; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void run() { |
||||||
|
try { |
||||||
|
FileUtils.forceMkdir(new File(m3u8File).getParentFile()); |
||||||
|
if (!checkDeviceOnline(ip)) { |
||||||
|
log.warn("设备{},离线", ip); |
||||||
|
this.taskState = fail; |
||||||
|
return; |
||||||
|
} |
||||||
|
String command = String.format(ffmpegCmd, rtspUrl, m3u8File); |
||||||
|
this.taskState = running; |
||||||
|
|
||||||
|
//判断是操作系统是linu2x还是windows
|
||||||
|
String[] comds; |
||||||
|
if (isWin()) { |
||||||
|
comds = new String[]{"cmd", "/c", command}; |
||||||
|
// comds = new String[]{"cmd", "/c", "start", "/b", "cmd.exe", "/k", command};
|
||||||
|
} else { |
||||||
|
comds = new String[]{"/bin/sh", "-c", command}; |
||||||
|
} |
||||||
|
|
||||||
|
// 开始执行命令
|
||||||
|
log.info("执行命令:" + command); |
||||||
|
process = Runtime.getRuntime().exec(comds); |
||||||
|
|
||||||
|
//开启线程监听(此处解决 waitFor() 阻塞/锁死 问题)
|
||||||
|
new RunThread(process.getInputStream(), "INFO").start(); |
||||||
|
new RunThread(process.getErrorStream(), "ERROR").start(); |
||||||
|
int flag = process.waitFor(); |
||||||
|
log.info("结束{}", ip); |
||||||
|
} catch (Exception e) { |
||||||
|
log.error("出现异常" + e.getMessage(), e); |
||||||
|
this.taskState = fail; |
||||||
|
} finally { |
||||||
|
if (process != null) { |
||||||
|
try { |
||||||
|
process.exitValue(); |
||||||
|
} catch (Exception e) { |
||||||
|
} |
||||||
|
try { |
||||||
|
process.destroyForcibly(); |
||||||
|
} catch (Exception e) { |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 获取任务执行状态 |
||||||
|
*/ |
||||||
|
public int getTaskState() { |
||||||
|
return taskState; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 立即停止任务 |
||||||
|
*/ |
||||||
|
public void stopTask() { |
||||||
|
if (process != null) { |
||||||
|
try { |
||||||
|
process.destroy(); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public String getM3U8File() { |
||||||
|
return this.m3u8File; |
||||||
|
} |
||||||
|
|
||||||
|
public String getUserName() { |
||||||
|
return userName; |
||||||
|
} |
||||||
|
|
||||||
|
public String getPwd() { |
||||||
|
return pwd; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void openTask(){ |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception { |
||||||
|
RtspConvert convert = new RtspConvert(); |
||||||
|
convert.closeAllProcess(); |
||||||
|
String ip = "192.168.1.40"; |
||||||
|
String userName = "admin"; |
||||||
|
String pwd = "admin123"; |
||||||
|
String m3u8 = convert.rtsp2Hls(ip, userName, pwd); |
||||||
|
System.out.println("***********************************" + m3u8); |
||||||
|
// Thread.sleep(10 * 1000);
|
||||||
|
// convert.stopTransform(ip);
|
||||||
|
// System.out.println("************************************结束**************");
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,20 @@ |
|||||||
|
<?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.ruoyi.code.warning.mapper.WaAlarmMapper"> |
||||||
|
|
||||||
|
<select id="queryAlarm" resultType="com.ruoyi.code.warning.domain.WaAlarm"> |
||||||
|
select a.*,b.stnm from wa_alarm a |
||||||
|
left join sc_station_info b on a.stnm_id=b.id |
||||||
|
where a.deleted=0 |
||||||
|
<if test="params.stnmId != null and params.stnmId !=''"> |
||||||
|
and a.stnm_id = #{stnmId} |
||||||
|
</if> |
||||||
|
<if test="params.startTime != null and params.startTime !=''"> |
||||||
|
and a.alarm_time >= #{params.startTime } |
||||||
|
</if> |
||||||
|
<if test="params.endTime != null and params.endTime !=''"> |
||||||
|
and a.alarm_time <= #{params.endTime} |
||||||
|
</if> |
||||||
|
order by alarm_time desc |
||||||
|
</select> |
||||||
|
</mapper> |
@ -0,0 +1,15 @@ |
|||||||
|
<?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.ruoyi.code.warning.mapper.WaEmpMsgMapper"> |
||||||
|
<insert id="saveMessageAndStation"> |
||||||
|
insert into wa_emp_msg(emp_id,msg_id) value(#{empId},#{msgId}) |
||||||
|
</insert> |
||||||
|
<select id="selectEmpIdByMsgId" resultType="java.lang.Long"> |
||||||
|
select emp_id from wa_emp_msg where msg_id = #{msgId} |
||||||
|
</select> |
||||||
|
<select id="selectByMsgId" resultType="com.ruoyi.code.warning.domain.WaEmpMsg"> |
||||||
|
select * from wa_emp_msg where msg_id = #{msgId} |
||||||
|
</select> |
||||||
|
</mapper> |
@ -0,0 +1,5 @@ |
|||||||
|
<?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.ruoyi.code.warning.mapper.WaMessageMapper"> |
||||||
|
|
||||||
|
</mapper> |
@ -0,0 +1,24 @@ |
|||||||
|
package com.ruoyi.common.annotation; |
||||||
|
|
||||||
|
import java.lang.annotation.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* 数据权限过滤注解 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
*/ |
||||||
|
@Target(ElementType.METHOD) |
||||||
|
@Retention(RetentionPolicy.RUNTIME) |
||||||
|
@Documented |
||||||
|
public @interface DeptDataScope |
||||||
|
{ |
||||||
|
/** |
||||||
|
* 部门表的别名 |
||||||
|
*/ |
||||||
|
public String deptAlias() default ""; |
||||||
|
|
||||||
|
/** |
||||||
|
* 用户表的别名 |
||||||
|
*/ |
||||||
|
public String userAlias() default ""; |
||||||
|
} |
@ -0,0 +1,166 @@ |
|||||||
|
package com.ruoyi.framework.aspectj; |
||||||
|
|
||||||
|
import com.ruoyi.common.annotation.DataScope; |
||||||
|
import com.ruoyi.common.annotation.DeptDataScope; |
||||||
|
import com.ruoyi.common.core.domain.BaseEntity; |
||||||
|
import com.ruoyi.common.core.domain.entity.SysRole; |
||||||
|
import com.ruoyi.common.core.domain.entity.SysUser; |
||||||
|
import com.ruoyi.common.core.domain.model.LoginUser; |
||||||
|
import com.ruoyi.common.utils.SecurityUtils; |
||||||
|
import com.ruoyi.common.utils.StringUtils; |
||||||
|
import org.aspectj.lang.JoinPoint; |
||||||
|
import org.aspectj.lang.annotation.Aspect; |
||||||
|
import org.aspectj.lang.annotation.Before; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* 数据过滤处理 |
||||||
|
* |
||||||
|
* @author ruoyi |
||||||
|
*/ |
||||||
|
@Aspect |
||||||
|
@Component |
||||||
|
public class DeptDataScopeAspect |
||||||
|
{ |
||||||
|
/** |
||||||
|
* 全部数据权限 |
||||||
|
*/ |
||||||
|
public static final String DATA_SCOPE_ALL = "1"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 自定数据权限 |
||||||
|
*/ |
||||||
|
public static final String DATA_SCOPE_CUSTOM = "2"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 部门数据权限 |
||||||
|
*/ |
||||||
|
public static final String DATA_SCOPE_DEPT = "3"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 部门及以下数据权限 |
||||||
|
*/ |
||||||
|
public static final String DATA_SCOPE_DEPT_AND_CHILD = "4"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 仅本人数据权限 |
||||||
|
*/ |
||||||
|
public static final String DATA_SCOPE_SELF = "5"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 数据权限过滤关键字 |
||||||
|
*/ |
||||||
|
public static final String DATA_SCOPE = "dataScope"; |
||||||
|
|
||||||
|
@Before("@annotation(controllerDataScope)") |
||||||
|
public void doBefore(JoinPoint point, DeptDataScope controllerDataScope) throws Throwable |
||||||
|
{ |
||||||
|
clearDataScope(point); |
||||||
|
handleDataScope(point, controllerDataScope); |
||||||
|
} |
||||||
|
|
||||||
|
protected void handleDataScope(final JoinPoint joinPoint, DeptDataScope controllerDataScope) |
||||||
|
{ |
||||||
|
// 获取当前的用户
|
||||||
|
LoginUser loginUser = SecurityUtils.getLoginUser(); |
||||||
|
if (StringUtils.isNotNull(loginUser)) |
||||||
|
{ |
||||||
|
SysUser currentUser = loginUser.getUser(); |
||||||
|
// 如果是超级管理员,则不过滤数据
|
||||||
|
if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin()) |
||||||
|
{ |
||||||
|
dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(), |
||||||
|
controllerDataScope.userAlias()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 数据范围过滤 |
||||||
|
* |
||||||
|
* @param joinPoint 切点 |
||||||
|
* @param user 用户 |
||||||
|
* @param userAlias 别名 |
||||||
|
*/ |
||||||
|
public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias) |
||||||
|
{ |
||||||
|
StringBuilder sqlString = new StringBuilder(); |
||||||
|
|
||||||
|
|
||||||
|
for (SysRole role : user.getRoles()) |
||||||
|
{ |
||||||
|
String dataScope = role.getDataScope(); |
||||||
|
if (DATA_SCOPE_ALL.equals(dataScope)) |
||||||
|
{ |
||||||
|
sqlString = new StringBuilder(); |
||||||
|
break; |
||||||
|
} |
||||||
|
else if (DATA_SCOPE_CUSTOM.equals(dataScope)) |
||||||
|
{ |
||||||
|
if(StringUtils.isNotBlank(deptAlias)){ |
||||||
|
sqlString.append(StringUtils.format( |
||||||
|
" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias, |
||||||
|
role.getRoleId())); |
||||||
|
}else{ |
||||||
|
sqlString.append(StringUtils.format( |
||||||
|
" OR dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", role.getRoleId())); |
||||||
|
} |
||||||
|
} |
||||||
|
else if (DATA_SCOPE_DEPT.equals(dataScope)) |
||||||
|
{ |
||||||
|
if(StringUtils.isNotBlank(deptAlias)){ |
||||||
|
sqlString.append(StringUtils.format(" OR {}.dept_id = {} ", deptAlias, user.getDeptId())); |
||||||
|
}else{ |
||||||
|
sqlString.append(StringUtils.format(" OR dept_id = {} ", user.getDeptId())); |
||||||
|
} |
||||||
|
} |
||||||
|
else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope)) |
||||||
|
{ |
||||||
|
if(StringUtils.isNotBlank(deptAlias)){ |
||||||
|
sqlString.append(StringUtils.format( |
||||||
|
" OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )", |
||||||
|
deptAlias, user.getDeptId(), user.getDeptId())); |
||||||
|
}else{ |
||||||
|
sqlString.append(StringUtils.format( |
||||||
|
" OR dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )", |
||||||
|
user.getDeptId(), user.getDeptId())); |
||||||
|
} |
||||||
|
} |
||||||
|
else if (DATA_SCOPE_SELF.equals(dataScope)) |
||||||
|
{ |
||||||
|
if (StringUtils.isNotBlank(userAlias)) |
||||||
|
{ |
||||||
|
sqlString.append(StringUtils.format(" OR {}.user_id = {} ", userAlias, user.getUserId())); |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
// 数据权限为仅本人且没有userAlias别名不查询任何数据
|
||||||
|
sqlString.append(" OR 1=0 "); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(sqlString.toString())) |
||||||
|
{ |
||||||
|
Map<String,Object> params = (Map<String, Object>) joinPoint.getArgs()[0]; |
||||||
|
if (params != null) |
||||||
|
{ |
||||||
|
params.put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 拼接权限sql前先清空params.dataScope参数防止注入 |
||||||
|
*/ |
||||||
|
private void clearDataScope(final JoinPoint joinPoint) |
||||||
|
{ |
||||||
|
Map<String,Object> params = (Map<String, Object>) joinPoint.getArgs()[0]; |
||||||
|
if (params != null) |
||||||
|
{ |
||||||
|
params.put(DATA_SCOPE, ""); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue