已添加9个文件
已重命名1个文件
已修改12个文件
| | |
| | | <artifactId>forest-spring-boot-starter</artifactId> |
| | | <version>1.5.22</version> |
| | | </dependency> |
| | | <!--mqtt--> |
| | | <dependency> |
| | | <groupId>org.springframework.integration</groupId> |
| | | <artifactId>spring-integration-mqtt</artifactId> |
| | | <version>6.0.3</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.ruoyi</groupId> |
| | | <artifactId>ruoyi-system</artifactId> |
| | |
| | | package com.ruoyi.alarm.globalAlarm.service; |
| | | |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.ruoyi.alarm.globalAlarm.domain.GlobalAlarmCondition; |
| | | import com.ruoyi.alarm.stealAlarm.domain.ArdAlarmStealelec; |
| | | import com.ruoyi.alarm.stealAlarm.mapper.ArdAlarmStealelecMapper; |
| | | import com.ruoyi.alarm.tubeAlarm.domain.ArdAlarmTube; |
| | | import com.ruoyi.alarm.tubeAlarm.mapper.ArdAlarmTubeMapper; |
| | | import com.ruoyi.alarm.tubeAlarm.service.IArdAlarmTubeService; |
| | | import com.ruoyi.alarmpoints.tube.domain.ArdTubes; |
| | | import com.ruoyi.alarmpoints.tube.domain.ArdTubesDetails; |
| | | import com.ruoyi.alarmpoints.tube.mapper.ArdTubesDetailsMapper; |
| | | import com.ruoyi.alarmpoints.tube.mapper.ArdTubesMapper; |
| | | import com.ruoyi.common.utils.uuid.UUID; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | public class GlobalAlarmServiceImpl implements IGlobalAlarmService { |
| | | @Resource |
| | | ArdAlarmStealelecMapper ardAlarmStealelecMapper; |
| | | |
| | | @Resource |
| | | IArdAlarmTubeService ardAlarmTubeService; |
| | | @Resource |
| | | ArdTubesMapper ardTubesMapper; |
| | | @Resource |
| | | ArdTubesDetailsMapper ardTubesDetailsMapper; |
| | | @Override |
| | | public List<Object> selectAlarmLogs(GlobalAlarmCondition condition) { |
| | | switch (condition.getCommand()) { |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Async("alarmExecutor") |
| | | public void receiveAlarm(String topic,String message) |
| | | { |
| | | switch (topic) |
| | | { |
| | | case "tube": |
| | | ArdAlarmTube ardAlarmTube = JSONObject.parseObject(message,ArdAlarmTube.class); |
| | | ardAlarmTube.setId(UUID.randomUUID().toString().replace("-","")); |
| | | ArdTubesDetails atd=new ArdTubesDetails(); |
| | | atd.setReelNumber(ardAlarmTube.getTubeId()); |
| | | List<ArdTubesDetails> ardTubesDetails = ardTubesDetailsMapper.selectArdTubesDetailsList(atd); |
| | | if(ardTubesDetails.size()>0) |
| | | { |
| | | String tubeId = ardTubesDetails.get(0).getTubeId(); |
| | | ArdTubes ardTubes = ardTubesMapper.selectArdTubesById(tubeId); |
| | | ardAlarmTube.setTubeName(ardTubes.getName()); |
| | | ardAlarmTube.setColor(ardTubes.getColor()); |
| | | ardAlarmTube.setPipeDiameter(ardTubes.getPipeDiameter()); |
| | | ardAlarmTube.setTubeType(ardTubes.getType()); |
| | | } |
| | | int i = ardAlarmTubeService.insertArdAlarmTube(ardAlarmTube); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | |
| | | **/ |
| | | public interface IGlobalAlarmService { |
| | | public List<Object> selectAlarmLogs(GlobalAlarmCondition condition); |
| | | |
| | | public void receiveAlarm(String topic,String message); |
| | | } |
| 对比新文件 |
| | |
| | | package com.ruoyi.alarm.tubeAlarm.controller; |
| | | |
| | | import java.util.List; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import com.ruoyi.alarm.tubeAlarm.domain.ArdAlarmTube; |
| | | import com.ruoyi.alarm.tubeAlarm.service.IArdAlarmTubeService; |
| | | 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.RestController; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | |
| | | /** |
| | | * 管线泄露报警Controller |
| | | * |
| | | * @author 刘苏义 |
| | | * @date 2023-06-06 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/alarm/tubeAlarm") |
| | | public class ArdAlarmTubeController extends BaseController |
| | | { |
| | | @Autowired |
| | | private IArdAlarmTubeService ardAlarmTubeService; |
| | | |
| | | /** |
| | | * 查询管线泄露报警列表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('alarm:tubeAlarm:list')") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(ArdAlarmTube ardAlarmTube) |
| | | { |
| | | startPage(); |
| | | List<ArdAlarmTube> list = ardAlarmTubeService.selectArdAlarmTubeList(ardAlarmTube); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | /** |
| | | * 导出管线泄露报警列表 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('alarm:tubeAlarm:export')") |
| | | @Log(title = "管线泄露报警", businessType = BusinessType.EXPORT) |
| | | @PostMapping("/export") |
| | | public void export(HttpServletResponse response, ArdAlarmTube ardAlarmTube) |
| | | { |
| | | List<ArdAlarmTube> list = ardAlarmTubeService.selectArdAlarmTubeList(ardAlarmTube); |
| | | ExcelUtil<ArdAlarmTube> util = new ExcelUtil<ArdAlarmTube>(ArdAlarmTube.class); |
| | | util.exportExcel(response, list, "管线泄露报警数据"); |
| | | } |
| | | |
| | | /** |
| | | * 获取管线泄露报警详细信息 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('alarm:tubeAlarm:query')") |
| | | @GetMapping(value = "/{id}") |
| | | public AjaxResult getInfo(@PathVariable("id") String id) |
| | | { |
| | | return success(ardAlarmTubeService.selectArdAlarmTubeById(id)); |
| | | } |
| | | |
| | | /** |
| | | * 新增管线泄露报警 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('alarm:tubeAlarm:add')") |
| | | @Log(title = "管线泄露报警", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@RequestBody ArdAlarmTube ardAlarmTube) |
| | | { |
| | | return toAjax(ardAlarmTubeService.insertArdAlarmTube(ardAlarmTube)); |
| | | } |
| | | |
| | | /** |
| | | * 修改管线泄露报警 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('alarm:tubeAlarm:edit')") |
| | | @Log(title = "管线泄露报警", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@RequestBody ArdAlarmTube ardAlarmTube) |
| | | { |
| | | return toAjax(ardAlarmTubeService.updateArdAlarmTube(ardAlarmTube)); |
| | | } |
| | | |
| | | /** |
| | | * 删除管线泄露报警 |
| | | */ |
| | | @PreAuthorize("@ss.hasPermi('alarm:tubeAlarm:remove')") |
| | | @Log(title = "管线泄露报警", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{ids}") |
| | | public AjaxResult remove(@PathVariable String[] ids) |
| | | { |
| | | return toAjax(ardAlarmTubeService.deleteArdAlarmTubeByIds(ids)); |
| | | } |
| | | } |
| 对比新文件 |
| | |
| | | package com.ruoyi.alarm.tubeAlarm.domain; |
| | | |
| | | import java.util.Date; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import org.apache.commons.lang3.builder.ToStringBuilder; |
| | | import org.apache.commons.lang3.builder.ToStringStyle; |
| | | import com.ruoyi.common.annotation.Excel; |
| | | import com.ruoyi.common.core.domain.BaseEntity; |
| | | |
| | | /** |
| | | * 管线泄露报警对象 ard_alarm_tube |
| | | * |
| | | * @author 刘苏义 |
| | | * @date 2023-06-06 |
| | | */ |
| | | public class ArdAlarmTube extends BaseEntity |
| | | { |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** 主键 */ |
| | | private String id; |
| | | |
| | | /** 报警主机 */ |
| | | @Excel(name = "报警主机") |
| | | private String host; |
| | | |
| | | /** 管线id */ |
| | | @Excel(name = "管线id") |
| | | private String tubeId; |
| | | |
| | | /** 管线名称 */ |
| | | @Excel(name = "管线名称") |
| | | private String tubeName; |
| | | |
| | | /** 管线类型-油管-水管 */ |
| | | @Excel(name = "管线类型-油管-水管") |
| | | private String tubeType; |
| | | |
| | | /** 管径 */ |
| | | @Excel(name = "管径") |
| | | private String pipeDiameter; |
| | | |
| | | /** 颜色 */ |
| | | @Excel(name = "颜色") |
| | | private String color; |
| | | |
| | | /** 位置 */ |
| | | @Excel(name = "位置") |
| | | private String position; |
| | | |
| | | /** 类型GXALARM */ |
| | | @Excel(name = "类型GXALARM") |
| | | private String type; |
| | | |
| | | /** 类型中文 */ |
| | | @Excel(name = "类型中文") |
| | | private String alarmType; |
| | | |
| | | /** 报警时间 */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @Excel(name = "报警时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") |
| | | private Date alarmTime; |
| | | |
| | | /** 用户名 */ |
| | | @Excel(name = "用户名") |
| | | private String watcher; |
| | | |
| | | /** 查看时间 */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
| | | @Excel(name = "查看时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") |
| | | private Date viewTime; |
| | | |
| | | public void setId(String id) |
| | | { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getId() |
| | | { |
| | | return id; |
| | | } |
| | | public void setHost(String host) |
| | | { |
| | | this.host = host; |
| | | } |
| | | |
| | | public String getHost() |
| | | { |
| | | return host; |
| | | } |
| | | public void setTubeId(String tubeId) |
| | | { |
| | | this.tubeId = tubeId; |
| | | } |
| | | |
| | | public String getTubeId() |
| | | { |
| | | return tubeId; |
| | | } |
| | | public void setTubeName(String tubeName) |
| | | { |
| | | this.tubeName = tubeName; |
| | | } |
| | | |
| | | public String getTubeName() |
| | | { |
| | | return tubeName; |
| | | } |
| | | public void setTubeType(String tubeType) |
| | | { |
| | | this.tubeType = tubeType; |
| | | } |
| | | |
| | | public String getTubeType() |
| | | { |
| | | return tubeType; |
| | | } |
| | | public void setPipeDiameter(String pipeDiameter) |
| | | { |
| | | this.pipeDiameter = pipeDiameter; |
| | | } |
| | | |
| | | public String getPipeDiameter() |
| | | { |
| | | return pipeDiameter; |
| | | } |
| | | public void setColor(String color) |
| | | { |
| | | this.color = color; |
| | | } |
| | | |
| | | public String getColor() |
| | | { |
| | | return color; |
| | | } |
| | | public void setPosition(String position) |
| | | { |
| | | this.position = position; |
| | | } |
| | | |
| | | public String getPosition() |
| | | { |
| | | return position; |
| | | } |
| | | public void setType(String type) |
| | | { |
| | | this.type = type; |
| | | } |
| | | |
| | | public String getType() |
| | | { |
| | | return type; |
| | | } |
| | | public void setAlarmType(String alarmType) |
| | | { |
| | | this.alarmType = alarmType; |
| | | } |
| | | |
| | | public String getAlarmType() |
| | | { |
| | | return alarmType; |
| | | } |
| | | public void setAlarmTime(Date alarmTime) |
| | | { |
| | | this.alarmTime = alarmTime; |
| | | } |
| | | |
| | | public Date getAlarmTime() |
| | | { |
| | | return alarmTime; |
| | | } |
| | | public void setWatcher(String watcher) |
| | | { |
| | | this.watcher = watcher; |
| | | } |
| | | |
| | | public String getWatcher() |
| | | { |
| | | return watcher; |
| | | } |
| | | public void setViewTime(Date viewTime) |
| | | { |
| | | this.viewTime = viewTime; |
| | | } |
| | | |
| | | public Date getViewTime() |
| | | { |
| | | return viewTime; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) |
| | | .append("id", getId()) |
| | | .append("host", getHost()) |
| | | .append("tubeId", getTubeId()) |
| | | .append("tubeName", getTubeName()) |
| | | .append("tubeType", getTubeType()) |
| | | .append("pipeDiameter", getPipeDiameter()) |
| | | .append("color", getColor()) |
| | | .append("position", getPosition()) |
| | | .append("type", getType()) |
| | | .append("alarmType", getAlarmType()) |
| | | .append("alarmTime", getAlarmTime()) |
| | | .append("watcher", getWatcher()) |
| | | .append("createTime", getCreateTime()) |
| | | .append("viewTime", getViewTime()) |
| | | .toString(); |
| | | } |
| | | } |
| 对比新文件 |
| | |
| | | package com.ruoyi.alarm.tubeAlarm.mapper; |
| | | |
| | | import java.util.List; |
| | | import com.ruoyi.alarm.tubeAlarm.domain.ArdAlarmTube; |
| | | |
| | | |
| | | /** |
| | | * 管线泄露报警Mapper接口 |
| | | * |
| | | * @author 刘苏义 |
| | | * @date 2023-06-06 |
| | | */ |
| | | public interface ArdAlarmTubeMapper |
| | | { |
| | | /** |
| | | * 查询管线泄露报警 |
| | | * |
| | | * @param id 管线泄露报警主键 |
| | | * @return 管线泄露报警 |
| | | */ |
| | | public ArdAlarmTube selectArdAlarmTubeById(String id); |
| | | |
| | | /** |
| | | * 查询管线泄露报警列表 |
| | | * |
| | | * @param ardAlarmTube 管线泄露报警 |
| | | * @return 管线泄露报警集合 |
| | | */ |
| | | public List<ArdAlarmTube> selectArdAlarmTubeList(ArdAlarmTube ardAlarmTube); |
| | | |
| | | /** |
| | | * 新增管线泄露报警 |
| | | * |
| | | * @param ardAlarmTube 管线泄露报警 |
| | | * @return 结果 |
| | | */ |
| | | public int insertArdAlarmTube(ArdAlarmTube ardAlarmTube); |
| | | |
| | | /** |
| | | * 修改管线泄露报警 |
| | | * |
| | | * @param ardAlarmTube 管线泄露报警 |
| | | * @return 结果 |
| | | */ |
| | | public int updateArdAlarmTube(ArdAlarmTube ardAlarmTube); |
| | | |
| | | /** |
| | | * 删除管线泄露报警 |
| | | * |
| | | * @param id 管线泄露报警主键 |
| | | * @return 结果 |
| | | */ |
| | | public int deleteArdAlarmTubeById(String id); |
| | | |
| | | /** |
| | | * 批量删除管线泄露报警 |
| | | * |
| | | * @param ids 需要删除的数据主键集合 |
| | | * @return 结果 |
| | | */ |
| | | public int deleteArdAlarmTubeByIds(String[] ids); |
| | | } |
| 对比新文件 |
| | |
| | | package com.ruoyi.alarm.tubeAlarm.service; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.ruoyi.alarm.tubeAlarm.domain.ArdAlarmTube; |
| | | |
| | | /** |
| | | * 管线泄露报警Service接口 |
| | | * |
| | | * @author 刘苏义 |
| | | * @date 2023-06-06 |
| | | */ |
| | | public interface IArdAlarmTubeService |
| | | { |
| | | /** |
| | | * 查询管线泄露报警 |
| | | * |
| | | * @param id 管线泄露报警主键 |
| | | * @return 管线泄露报警 |
| | | */ |
| | | public ArdAlarmTube selectArdAlarmTubeById(String id); |
| | | |
| | | /** |
| | | * 查询管线泄露报警列表 |
| | | * |
| | | * @param ardAlarmTube 管线泄露报警 |
| | | * @return 管线泄露报警集合 |
| | | */ |
| | | public List<ArdAlarmTube> selectArdAlarmTubeList(ArdAlarmTube ardAlarmTube); |
| | | |
| | | /** |
| | | * 新增管线泄露报警 |
| | | * |
| | | * @param ardAlarmTube 管线泄露报警 |
| | | * @return 结果 |
| | | */ |
| | | public int insertArdAlarmTube(ArdAlarmTube ardAlarmTube); |
| | | |
| | | /** |
| | | * 修改管线泄露报警 |
| | | * |
| | | * @param ardAlarmTube 管线泄露报警 |
| | | * @return 结果 |
| | | */ |
| | | public int updateArdAlarmTube(ArdAlarmTube ardAlarmTube); |
| | | |
| | | /** |
| | | * 批量删除管线泄露报警 |
| | | * |
| | | * @param ids 需要删除的管线泄露报警主键集合 |
| | | * @return 结果 |
| | | */ |
| | | public int deleteArdAlarmTubeByIds(String[] ids); |
| | | |
| | | /** |
| | | * 删除管线泄露报警信息 |
| | | * |
| | | * @param id 管线泄露报警主键 |
| | | * @return 结果 |
| | | */ |
| | | public int deleteArdAlarmTubeById(String id); |
| | | } |
| 对比新文件 |
| | |
| | | package com.ruoyi.alarm.tubeAlarm.service.impl; |
| | | |
| | | import com.ruoyi.alarm.tubeAlarm.domain.ArdAlarmTube; |
| | | import com.ruoyi.alarm.tubeAlarm.mapper.ArdAlarmTubeMapper; |
| | | import com.ruoyi.alarm.tubeAlarm.service.IArdAlarmTubeService; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | |
| | | |
| | | /** |
| | | * 管线泄露报警Service业务层处理 |
| | | * |
| | | * @author 刘苏义 |
| | | * @date 2023-06-06 |
| | | */ |
| | | @Service |
| | | public class ArdAlarmTubeServiceImpl implements IArdAlarmTubeService { |
| | | @Autowired |
| | | private ArdAlarmTubeMapper ardAlarmTubeMapper; |
| | | |
| | | /** |
| | | * 查询管线泄露报警 |
| | | * |
| | | * @param id 管线泄露报警主键 |
| | | * @return 管线泄露报警 |
| | | */ |
| | | @Override |
| | | public ArdAlarmTube selectArdAlarmTubeById(String id) { |
| | | return ardAlarmTubeMapper.selectArdAlarmTubeById(id); |
| | | } |
| | | |
| | | /** |
| | | * 查询管线泄露报警列表 |
| | | * |
| | | * @param ardAlarmTube 管线泄露报警 |
| | | * @return 管线泄露报警 |
| | | */ |
| | | @Override |
| | | public List<ArdAlarmTube> selectArdAlarmTubeList(ArdAlarmTube ardAlarmTube) { |
| | | return ardAlarmTubeMapper.selectArdAlarmTubeList(ardAlarmTube); |
| | | } |
| | | |
| | | /** |
| | | * 新增管线泄露报警 |
| | | * |
| | | * @param ardAlarmTube 管线泄露报警 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int insertArdAlarmTube(ArdAlarmTube ardAlarmTube) { |
| | | ardAlarmTube.setCreateTime(DateUtils.getNowDate()); |
| | | return ardAlarmTubeMapper.insertArdAlarmTube(ardAlarmTube); |
| | | } |
| | | |
| | | /** |
| | | * 修改管线泄露报警 |
| | | * |
| | | * @param ardAlarmTube 管线泄露报警 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int updateArdAlarmTube(ArdAlarmTube ardAlarmTube) { |
| | | return ardAlarmTubeMapper.updateArdAlarmTube(ardAlarmTube); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除管线泄露报警 |
| | | * |
| | | * @param ids 需要删除的管线泄露报警主键 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deleteArdAlarmTubeByIds(String[] ids) { |
| | | return ardAlarmTubeMapper.deleteArdAlarmTubeByIds(ids); |
| | | } |
| | | |
| | | /** |
| | | * 删除管线泄露报警信息 |
| | | * |
| | | * @param id 管线泄露报警主键 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deleteArdAlarmTubeById(String id) { |
| | | return ardAlarmTubeMapper.deleteArdAlarmTubeById(id); |
| | | } |
| | | } |
| 文件名从 ard-work/src/main/java/com/ruoyi/device/hiksdk/config/AsyncConfiguration.java 修改 |
| | |
| | | package com.ruoyi.device.hiksdk.config; |
| | | package com.ruoyi.config; |
| | | |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | |
| | | executor.initialize(); |
| | | return executor; |
| | | } |
| | | @Bean("alarmExecutor") |
| | | public Executor alarmExecutor(){ |
| | | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
| | | //配置核心线程数 |
| | | executor.setCorePoolSize(15); |
| | | //配置最大线程数 |
| | | executor.setMaxPoolSize(30); |
| | | //配置队列大小 |
| | | executor.setQueueCapacity(1000); |
| | | //线程的名称前缀 |
| | | executor.setThreadNamePrefix("alarmExecutor-"); |
| | | //线程活跃时间(秒) |
| | | //executor.setKeepAliveSeconds(60); |
| | | //等待所有任务结束后再关闭线程池 |
| | | executor.setWaitForTasksToCompleteOnShutdown(true); |
| | | //设置拒绝策略 |
| | | //executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); |
| | | //执行初始化 |
| | | executor.initialize(); |
| | | return executor; |
| | | } |
| | | } |
| | |
| | | import com.ruoyi.inspect.domain.ArdVideoInspectTaskStep; |
| | | import com.ruoyi.inspect.service.IArdVideoInspectTaskStepService; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * 视频巡检步骤Service业务层处理 |
| | | * |
| | |
| | | */ |
| | | @Service |
| | | public class ArdVideoInspectTaskStepServiceImpl implements IArdVideoInspectTaskStepService { |
| | | @Autowired |
| | | @Resource |
| | | private ArdVideoInspectTaskStepMapper ardVideoInspectTaskStepMapper; |
| | | |
| | | /** |
| 对比新文件 |
| | |
| | | package com.ruoyi.utils.mqtt; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.eclipse.paho.client.mqttv3.*; |
| | | import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; |
| | | import org.springframework.boot.ApplicationArguments; |
| | | import org.springframework.boot.ApplicationRunner; |
| | | import org.springframework.stereotype.Component; |
| | | import java.io.UnsupportedEncodingException; |
| | | /** |
| | | * @Description: mqtt消费客户端 |
| | | * @ClassName: MqttConsumer |
| | | * @Author: 刘苏义 |
| | | * @Date: 2023年05月29日9:55 |
| | | * @Version: 1.0 |
| | | **/ |
| | | @Component |
| | | @Slf4j(topic = "mqtt") |
| | | public class MqttConsumer implements ApplicationRunner { |
| | | |
| | | private static MqttClient client; |
| | | |
| | | @Override |
| | | public void run(ApplicationArguments args) { |
| | | log.info("初始化并启动mqtt......"); |
| | | if(PropertiesUtil.MQTT_ENABLED) |
| | | { |
| | | this.connect(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 连接mqtt服务器 |
| | | */ |
| | | private void connect() { |
| | | try { |
| | | // 1 创建客户端 |
| | | getClient(); |
| | | // 2 设置配置 |
| | | MqttConnectOptions options = getOptions(); |
| | | String[] topic = PropertiesUtil.MQTT_TOPIC.split(","); |
| | | // 3 消息发布质量 |
| | | int[] qos = getQos(topic.length); |
| | | // 4 最后设置 |
| | | create(options, topic, qos); |
| | | } catch (Exception e) { |
| | | log.error("mqtt连接异常:" + e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建客户端 --- 1 --- |
| | | */ |
| | | public void getClient() { |
| | | try { |
| | | if (null == client) { |
| | | client = new MqttClient(PropertiesUtil.MQTT_HOST, PropertiesUtil.MQTT_CLIENT_ID, new MemoryPersistence()); |
| | | } |
| | | log.info("--创建mqtt客户端"); |
| | | } catch (Exception e) { |
| | | log.error("创建mqtt客户端异常:" + e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 生成配置对象,用户名,密码等 --- 2 --- |
| | | */ |
| | | public MqttConnectOptions getOptions() { |
| | | MqttConnectOptions options = new MqttConnectOptions(); |
| | | //设置用户名密码 |
| | | options.setUserName(PropertiesUtil.MQTT_USER_NAME); |
| | | options.setPassword(PropertiesUtil.MQTT_PASSWORD.toCharArray()); |
| | | // 设置超时时间 |
| | | options.setConnectionTimeout(PropertiesUtil.MQTT_TIMEOUT); |
| | | // 设置会话心跳时间 |
| | | options.setKeepAliveInterval(PropertiesUtil.MQTT_KEEP_ALIVE); |
| | | // 是否清除session |
| | | options.setCleanSession(false); |
| | | log.info("--生成mqtt配置对象"); |
| | | return options; |
| | | } |
| | | |
| | | /** |
| | | * qos --- 3 --- |
| | | */ |
| | | public int[] getQos(int length) { |
| | | |
| | | int[] qos = new int[length]; |
| | | for (int i = 0; i < length; i++) { |
| | | /** |
| | | * MQTT协议中有三种消息发布服务质量: |
| | | * |
| | | * QOS0: “至多一次”,消息发布完全依赖底层 TCP/IP 网络。会发生消息丢失或重复。这一级别可用于如下情况,环境传感器数据,丢失一次读记录无所谓,因为不久后还会有第二次发送。 |
| | | * QOS1: “至少一次”,确保消息到达,但消息重复可能会发生。 |
| | | * QOS2: “只有一次”,确保消息到达一次。这一级别可用于如下情况,在计费系统中,消息重复或丢失会导致不正确的结果,资源开销大 |
| | | */ |
| | | qos[i] = 1; |
| | | } |
| | | log.info("--设置消息发布质量"); |
| | | return qos; |
| | | } |
| | | |
| | | /** |
| | | * 装载各种实例和订阅主题 --- 4 --- |
| | | */ |
| | | public void create(MqttConnectOptions options, String[] topic, int[] qos) { |
| | | try { |
| | | client.setCallback(new MqttConsumerCallback(client, options, topic, qos)); |
| | | log.info("--添加回调处理类"); |
| | | client.connect(options); |
| | | } catch (Exception e) { |
| | | log.info("装载实例或订阅主题异常:" + e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 订阅某个主题 |
| | | * |
| | | * @param topic |
| | | * @param qos |
| | | */ |
| | | public void subscribe(String topic, int qos) { |
| | | try { |
| | | log.info("topic:" + topic); |
| | | client.subscribe(topic, qos); |
| | | } catch (MqttException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 发布,非持久化 |
| | | * |
| | | * qos根据文档设置为1 |
| | | * |
| | | * @param topic |
| | | * @param msg |
| | | */ |
| | | public static void publish(String topic, String msg) { |
| | | publish(1, false, topic, msg); |
| | | } |
| | | |
| | | /** |
| | | * 发布 |
| | | */ |
| | | public static void publish(int qos, boolean retained, String topic, String pushMessage) { |
| | | log.info("【主题】:" + topic + "【qos】:" + qos + "【pushMessage】:" + pushMessage); |
| | | MqttMessage message = new MqttMessage(); |
| | | message.setQos(qos); |
| | | message.setRetained(retained); |
| | | try { |
| | | message.setPayload(pushMessage.getBytes("UTF-8")); |
| | | } catch (UnsupportedEncodingException e) { |
| | | log.error("mqtt编码异常:" + e.getMessage()); |
| | | } |
| | | MqttTopic mTopic = client.getTopic(topic); |
| | | if (null == mTopic) { |
| | | log.error("topic:" + topic + " 不存在"); |
| | | } |
| | | MqttDeliveryToken token; |
| | | try { |
| | | token = mTopic.publish(message); |
| | | token.waitForCompletion(); |
| | | if (token.isComplete()) { |
| | | log.info("消息发送成功"); |
| | | } |
| | | } catch (MqttPersistenceException e) { |
| | | e.printStackTrace(); |
| | | } catch (MqttException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| 对比新文件 |
| | |
| | | package com.ruoyi.utils.mqtt; |
| | | |
| | | import com.ruoyi.alarm.globalAlarm.service.GlobalAlarmServiceImpl; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.eclipse.paho.client.mqttv3.*; |
| | | |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.Arrays; |
| | | |
| | | /** |
| | | * @Description: mqtt回调处理类 |
| | | * @ClassName: MqttConsumerCallback |
| | | * @Author: 刘苏义 |
| | | * @Date: 2023年05月29日9:55 |
| | | * @Version: 1.0 |
| | | **/ |
| | | @Slf4j(topic = "mqtt") |
| | | public class MqttConsumerCallback implements MqttCallbackExtended { |
| | | |
| | | private MqttClient client; |
| | | private MqttConnectOptions options; |
| | | private String[] topic; |
| | | private int[] qos; |
| | | |
| | | public MqttConsumerCallback(MqttClient client, MqttConnectOptions options, String[] topic, int[] qos) { |
| | | this.client = client; |
| | | this.options = options; |
| | | this.topic = topic; |
| | | this.qos = qos; |
| | | } |
| | | |
| | | /** |
| | | * 断开重连 |
| | | */ |
| | | @Override |
| | | public void connectionLost(Throwable cause) { |
| | | log.info("MQTT连接断开,发起重连......"); |
| | | try { |
| | | while (!client.isConnected()) { |
| | | Thread.sleep(5000); |
| | | if (null != client && !client.isConnected()) { |
| | | client.reconnect(); |
| | | log.error("尝试重新连接"); |
| | | } else { |
| | | client.connect(options); |
| | | log.error("尝试建立新连接"); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 接收到消息调用令牌中调用 |
| | | */ |
| | | @Override |
| | | public void deliveryComplete(IMqttDeliveryToken token) { |
| | | |
| | | //log.info("deliveryComplete---------" + Arrays.toString(topic)); |
| | | } |
| | | |
| | | /** |
| | | * 消息处理 |
| | | */ |
| | | @Override |
| | | public void messageArrived(String topic, MqttMessage message) { |
| | | try { |
| | | // subscribe后得到的消息会执行到这里面 |
| | | log.info("接收消息 【主题】:" + topic + " 【内容】:" + new String(message.getPayload())); |
| | | //进行业务处理(接收报警数据) |
| | | GlobalAlarmServiceImpl globalAlarmService = SpringUtils.getBean(GlobalAlarmServiceImpl.class); |
| | | globalAlarmService.receiveAlarm(topic, new String(message.getPayload(), StandardCharsets.UTF_8)); |
| | | } catch (Exception e) { |
| | | log.info("处理mqtt消息异常:" + e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * mqtt连接后订阅主题 |
| | | */ |
| | | @Override |
| | | public void connectComplete(boolean b, String s) { |
| | | try { |
| | | if (null != topic && null != qos) { |
| | | if (client.isConnected()) { |
| | | client.subscribe(topic, qos); |
| | | log.info("mqtt连接成功,客户端ID:" + PropertiesUtil.MQTT_CLIENT_ID); |
| | | log.info("--订阅主题::" + Arrays.toString(topic)); |
| | | } else { |
| | | log.info("mqtt连接失败,客户端ID:" + PropertiesUtil.MQTT_CLIENT_ID); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.info("mqtt订阅主题异常:" + e); |
| | | } |
| | | } |
| | | } |
| | | |
| 对比新文件 |
| | |
| | | package com.ruoyi.utils.mqtt; |
| | | |
| | | import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; |
| | | import org.springframework.core.io.ClassPathResource; |
| | | import org.springframework.core.io.Resource; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.Objects; |
| | | import java.util.Properties; |
| | | |
| | | /** |
| | | * @Description: 获取配置信息 |
| | | * @ClassName: PropertiesUtil |
| | | * @Author: 刘苏义 |
| | | * @Date: 2023年06月06日9:40 |
| | | * @Version: 1.0 |
| | | **/ |
| | | @Component |
| | | public class PropertiesUtil { |
| | | |
| | | public static String MQTT_HOST; |
| | | public static String MQTT_CLIENT_ID; |
| | | public static String MQTT_USER_NAME; |
| | | public static String MQTT_PASSWORD; |
| | | public static String MQTT_TOPIC; |
| | | public static Integer MQTT_TIMEOUT; |
| | | public static Integer MQTT_KEEP_ALIVE; |
| | | public static Boolean MQTT_ENABLED; |
| | | static { |
| | | MQTT_HOST = getYmlNew("mqtt.host"); |
| | | MQTT_CLIENT_ID = getYmlNew("mqtt.clientId"); |
| | | MQTT_USER_NAME = getYmlNew("mqtt.username"); |
| | | MQTT_PASSWORD = getYmlNew("mqtt.password"); |
| | | MQTT_TOPIC = getYmlNew("mqtt.topic"); |
| | | MQTT_TIMEOUT = Integer.valueOf(Objects.requireNonNull(getYmlNew("mqtt.timeout"))); |
| | | MQTT_KEEP_ALIVE = Integer.valueOf(Objects.requireNonNull(getYmlNew("mqtt.keepalive"))); |
| | | MQTT_ENABLED = Boolean.valueOf(getYmlNew("mqtt.enabled")); |
| | | } |
| | | |
| | | public static String getYmlNew(String key) { |
| | | Resource resource = new ClassPathResource("application-ard.yml"); |
| | | Properties properties; |
| | | try { |
| | | YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean(); |
| | | yamlFactory.setResources(resource); |
| | | properties = yamlFactory.getObject(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | assert properties != null; |
| | | return properties.get(key).toString(); |
| | | } |
| | | } |
| 对比新文件 |
| | |
| | | <?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.alarm.tubeAlarm.mapper.ArdAlarmTubeMapper"> |
| | | |
| | | <resultMap type="ArdAlarmTube" id="ArdAlarmTubeResult"> |
| | | <result property="id" column="id" /> |
| | | <result property="host" column="host" /> |
| | | <result property="tubeId" column="tube_id" /> |
| | | <result property="tubeName" column="tube_name" /> |
| | | <result property="tubeType" column="tube_type" /> |
| | | <result property="pipeDiameter" column="pipe_diameter" /> |
| | | <result property="color" column="color" /> |
| | | <result property="position" column="position" /> |
| | | <result property="type" column="type" /> |
| | | <result property="alarmType" column="alarm_type" /> |
| | | <result property="alarmTime" column="alarm_time" /> |
| | | <result property="watcher" column="watcher" /> |
| | | <result property="createTime" column="create_time" /> |
| | | <result property="viewTime" column="view_time" /> |
| | | </resultMap> |
| | | |
| | | <sql id="selectArdAlarmTubeVo"> |
| | | select id, host, tube_id, tube_name, tube_type, pipe_diameter, color, position, type, alarm_type, alarm_time, watcher, create_time, view_time from ard_alarm_tube |
| | | </sql> |
| | | |
| | | <select id="selectArdAlarmTubeList" parameterType="ArdAlarmTube" resultMap="ArdAlarmTubeResult"> |
| | | <include refid="selectArdAlarmTubeVo"/> |
| | | <where> |
| | | <if test="host != null and host != ''"> and host = #{host}</if> |
| | | <if test="tubeId != null "> and tube_id = #{tubeId}</if> |
| | | <if test="tubeName != null and tubeName != ''"> and tube_name like '%'||#{tubeName}||'%'</if> |
| | | <if test="tubeType != null and tubeType != ''"> and tube_type = #{tubeType}</if> |
| | | <if test="pipeDiameter != null and pipeDiameter != ''"> and pipe_diameter = #{pipeDiameter}</if> |
| | | <if test="color != null and color != ''"> and color = #{color}</if> |
| | | <if test="position != null and position != ''"> and position = #{position}</if> |
| | | <if test="type != null and type != ''"> and type = #{type}</if> |
| | | <if test="alarmType != null and alarmType != ''"> and alarm_type = #{alarmType}</if> |
| | | <if test="alarmTime != null "> and alarm_time = #{alarmTime}</if> |
| | | <if test="watcher != null and watcher != ''"> and watcher = #{watcher}</if> |
| | | <if test="viewTime != null "> and view_time = #{viewTime}</if> |
| | | </where> |
| | | </select> |
| | | |
| | | <select id="selectArdAlarmTubeById" parameterType="String" resultMap="ArdAlarmTubeResult"> |
| | | <include refid="selectArdAlarmTubeVo"/> |
| | | where id = #{id} |
| | | </select> |
| | | |
| | | <insert id="insertArdAlarmTube" parameterType="ArdAlarmTube"> |
| | | insert into ard_alarm_tube |
| | | <trim prefix="(" suffix=")" suffixOverrides=","> |
| | | <if test="id != null">id,</if> |
| | | <if test="host != null">host,</if> |
| | | <if test="tubeId != null">tube_id,</if> |
| | | <if test="tubeName != null">tube_name,</if> |
| | | <if test="tubeType != null">tube_type,</if> |
| | | <if test="pipeDiameter != null">pipe_diameter,</if> |
| | | <if test="color != null">color,</if> |
| | | <if test="position != null">position,</if> |
| | | <if test="type != null">type,</if> |
| | | <if test="alarmType != null">alarm_type,</if> |
| | | <if test="alarmTime != null">alarm_time,</if> |
| | | <if test="watcher != null">watcher,</if> |
| | | <if test="createTime != null">create_time,</if> |
| | | <if test="viewTime != null">view_time,</if> |
| | | </trim> |
| | | <trim prefix="values (" suffix=")" suffixOverrides=","> |
| | | <if test="id != null">#{id},</if> |
| | | <if test="host != null">#{host},</if> |
| | | <if test="tubeId != null">#{tubeId},</if> |
| | | <if test="tubeName != null">#{tubeName},</if> |
| | | <if test="tubeType != null">#{tubeType},</if> |
| | | <if test="pipeDiameter != null">#{pipeDiameter},</if> |
| | | <if test="color != null">#{color},</if> |
| | | <if test="position != null">#{position},</if> |
| | | <if test="type != null">#{type},</if> |
| | | <if test="alarmType != null">#{alarmType},</if> |
| | | <if test="alarmTime != null">#{alarmTime},</if> |
| | | <if test="watcher != null">#{watcher},</if> |
| | | <if test="createTime != null">#{createTime},</if> |
| | | <if test="viewTime != null">#{viewTime},</if> |
| | | </trim> |
| | | </insert> |
| | | |
| | | <update id="updateArdAlarmTube" parameterType="ArdAlarmTube"> |
| | | update ard_alarm_tube |
| | | <trim prefix="SET" suffixOverrides=","> |
| | | <if test="host != null">host = #{host},</if> |
| | | <if test="tubeId != null">tube_id = #{tubeId},</if> |
| | | <if test="tubeName != null">tube_name = #{tubeName},</if> |
| | | <if test="tubeType != null">tube_type = #{tubeType},</if> |
| | | <if test="pipeDiameter != null">pipe_diameter = #{pipeDiameter},</if> |
| | | <if test="color != null">color = #{color},</if> |
| | | <if test="position != null">position = #{position},</if> |
| | | <if test="type != null">type = #{type},</if> |
| | | <if test="alarmType != null">alarm_type = #{alarmType},</if> |
| | | <if test="alarmTime != null">alarm_time = #{alarmTime},</if> |
| | | <if test="watcher != null">watcher = #{watcher},</if> |
| | | <if test="createTime != null">create_time = #{createTime},</if> |
| | | <if test="viewTime != null">view_time = #{viewTime},</if> |
| | | </trim> |
| | | where id = #{id} |
| | | </update> |
| | | |
| | | <delete id="deleteArdAlarmTubeById" parameterType="String"> |
| | | delete from ard_alarm_tube where id = #{id} |
| | | </delete> |
| | | |
| | | <delete id="deleteArdAlarmTubeByIds" parameterType="String"> |
| | | delete from ard_alarm_tube where id in |
| | | <foreach item="id" collection="array" open="(" separator="," close=")"> |
| | | #{id} |
| | | </foreach> |
| | | </delete> |
| | | </mapper> |
| | |
| | | </select> |
| | | <select id="selectArdTubesDetailsByReelNumber" parameterType="String" resultMap="ArdTubesDetailsResult"> |
| | | <include refid="selectArdTubesDetailsVo"/> |
| | | where reel_number = #{reelNumber} and tube_id=#{tubeId} |
| | | where reel_number = #{reelNumber} |
| | | </select> |
| | | <insert id="insertArdTubesDetails" parameterType="ArdTubesDetails"> |
| | | insert into ard_tubes_details |
| | |
| | | </resultMap> |
| | | |
| | | <sql id="selectArdVideoInspectRecordVo"> |
| | | select id, start_time, end_time, record_file_path, step_id, dept_id, user_id from ard_video_inspect_record |
| | | select id, start_time, end_time, record_file_path, step_id, dept_id, user_id,well_name from ard_video_inspect_record |
| | | </sql> |
| | | |
| | | <select id="selectArdVideoInspectRecordList" parameterType="ArdVideoInspectRecord" resultMap="ArdVideoInspectRecordResult"> |
| | |
| | | <if test="startTime != null and startTime != ''">and start_time like ('${startTime}%')</if> |
| | | <if test="stepId != null and stepId != ''">and step_id = #{stepId}</if> |
| | | </where> |
| | | |
| | | order by start_time desc |
| | | </select> |
| | | <!--按月份统计文件数量--> |
| | | <select id="selectArdVideoInspectRecordCountByStartMonth" parameterType="String" resultType="java.util.HashMap"> |
| | |
| | | connect-timeout: 3000 # 连接超时时间,单位为毫秒, 默认值为2000 |
| | | retry-count: 0 # 请求失败后重试次数,默认为0次不重试 |
| | | ssl-protocol: SSLv3 # 单向验证的HTTPS的默认SSL协议,默认为SSLv3 |
| | | logEnabled: true # 打开或关闭日志,默认为true |
| | | logEnabled: true # 打开或关闭日志,默认为true |
| | | #mqtt |
| | | mqtt: |
| | | host: tcp://192.168.1.15:1883 |
| | | clientId: m3 |
| | | username: admin |
| | | password: xzx12345 |
| | | topic: tube |
| | | timeout: 100 |
| | | keepalive: 60 |
| | | enabled: true |
| | |
| | | druid: |
| | | # 主库数据源 |
| | | master: |
| | | url: jdbc:postgresql://111.40.46.199:15432/ry-vue?stringtype=unspecified |
| | | username: postgres |
| | | password: Yykj.2021 |
| | | # url: jdbc:postgresql://127.0.0.1:5432/ry-vue?stringtype=unspecified |
| | | # url: jdbc:postgresql://111.40.46.199:15432/ry-vue?stringtype=unspecified |
| | | # username: postgres |
| | | # password: postgres |
| | | # password: Yykj.2021 |
| | | url: jdbc:postgresql://192.168.1.15:5432/ry-vue?stringtype=unspecified |
| | | username: postgres |
| | | password: postgres |
| | | # 从库数据源 |
| | | slave: |
| | | # 从数据源开关/默认关闭 |
| | |
| | | # 日志配置 |
| | | logging: |
| | | level: |
| | | com.ruoyi.inspect: debug |
| | | com.ruoyi.inspect: info |
| | | org.springframework: warn |
| | | |
| | | # 用户配置 |
| | |
| | | <pattern>${log.pattern}</pattern> |
| | | </encoder> |
| | | </appender> |
| | | <!--mqtt日志输出--> |
| | | <appender name="mqtt" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
| | | <file>${log.path}/mqtt.log</file> |
| | | <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
| | | <!--按天回滚daily--> |
| | | <fileNamePattern>${log.path}/mqtt.%d{yyyy-MM-dd}.log</fileNamePattern> |
| | | <!--日志最大的历史60天--> |
| | | <maxHistory>60</maxHistory> |
| | | </rollingPolicy> |
| | | <encoder> |
| | | <pattern>${log.pattern}</pattern> |
| | | </encoder> |
| | | </appender> |
| | | <!--PatrolInspectionTask日志输出--> |
| | | <appender name="PatrolInspectionTask" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
| | | <file>${log.path}/PatrolInspectionTask.log</file> |
| | |
| | | <logger name="websocket" level="INFO"> |
| | | <appender-ref ref="websocket"/> |
| | | </logger> |
| | | <!--websocket日志打印等级--> |
| | | <!--光电巡检日志打印等级--> |
| | | <logger name="PatrolInspectionTask" level="INFO"> |
| | | <appender-ref ref="PatrolInspectionTask"/> |
| | | </logger> |
| | | <!--mqtt日志打印等级--> |
| | | <logger name="mqtt" level="INFO"> |
| | | <appender-ref ref="mqtt"/> |
| | | </logger> |
| | | </configuration> |
| | |
| | | import java.util.Map; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import org.aspectj.lang.JoinPoint; |
| | | import org.aspectj.lang.annotation.AfterReturning; |
| | | import org.aspectj.lang.annotation.AfterThrowing; |
| | |
| | | |
| | | /** |
| | | * 操作日志记录处理 |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Aspect |
| | | @Component |
| | | public class LogAspect |
| | | { |
| | | public class LogAspect { |
| | | private static final Logger log = LoggerFactory.getLogger(LogAspect.class); |
| | | |
| | | /** 排除敏感属性字段 */ |
| | | public static final String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" }; |
| | | /** |
| | | * 排除敏感属性字段 |
| | | */ |
| | | public static final String[] EXCLUDE_PROPERTIES = {"password", "oldPassword", "newPassword", "confirmPassword"}; |
| | | |
| | | /** |
| | | * 处理完请求后执行 |
| | |
| | | * @param joinPoint 切点 |
| | | */ |
| | | @AfterReturning(pointcut = "@annotation(controllerLog)", returning = "jsonResult") |
| | | public void doAfterReturning(JoinPoint joinPoint, Log controllerLog, Object jsonResult) |
| | | { |
| | | public void doAfterReturning(JoinPoint joinPoint, Log controllerLog, Object jsonResult) { |
| | | handleLog(joinPoint, controllerLog, null, jsonResult); |
| | | } |
| | | |
| | | /** |
| | | * 拦截异常操作 |
| | | * |
| | | * |
| | | * @param joinPoint 切点 |
| | | * @param e 异常 |
| | | * @param e 异常 |
| | | */ |
| | | @AfterThrowing(value = "@annotation(controllerLog)", throwing = "e") |
| | | public void doAfterThrowing(JoinPoint joinPoint, Log controllerLog, Exception e) |
| | | { |
| | | public void doAfterThrowing(JoinPoint joinPoint, Log controllerLog, Exception e) { |
| | | handleLog(joinPoint, controllerLog, e, null); |
| | | } |
| | | |
| | | protected void handleLog(final JoinPoint joinPoint, Log controllerLog, final Exception e, Object jsonResult) |
| | | { |
| | | try |
| | | { |
| | | protected void handleLog(final JoinPoint joinPoint, Log controllerLog, final Exception e, Object jsonResult) { |
| | | try { |
| | | // 获取当前的用户 |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | |
| | |
| | | String ip = IpUtils.getIpAddr(ServletUtils.getRequest()); |
| | | operLog.setOperIp(ip); |
| | | operLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255)); |
| | | if (loginUser != null) |
| | | { |
| | | if (loginUser != null) { |
| | | operLog.setOperName(loginUser.getUsername()); |
| | | } |
| | | |
| | | if (e != null) |
| | | { |
| | | if (e != null) { |
| | | operLog.setStatus(BusinessStatus.FAIL.ordinal()); |
| | | operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000)); |
| | | } |
| | |
| | | // 处理设置注解上的参数 |
| | | getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult); |
| | | //判断状态码 |
| | | Map resultMap=(Map)jsonResult; |
| | | if(resultMap.get("code").equals(500)) |
| | | { |
| | | operLog.setStatus(BusinessStatus.FAIL.ordinal()); |
| | | Map resultMap = (Map) jsonResult; |
| | | if (StringUtils.isNotNull(resultMap)) { |
| | | if (resultMap.get("code").equals(500)) { |
| | | operLog.setStatus(BusinessStatus.FAIL.ordinal()); |
| | | } |
| | | } |
| | | // 保存数据库 |
| | | AsyncManager.me().execute(AsyncFactory.recordOper(operLog)); |
| | | } |
| | | catch (Exception exp) |
| | | { |
| | | } catch (Exception exp) { |
| | | // 记录本地异常日志 |
| | | log.error("异常信息:{}", exp.getMessage()); |
| | | exp.printStackTrace(); |
| | |
| | | |
| | | /** |
| | | * 获取注解中对方法的描述信息 用于Controller层注解 |
| | | * |
| | | * @param log 日志 |
| | | * |
| | | * @param log 日志 |
| | | * @param operLog 操作日志 |
| | | * @throws Exception |
| | | */ |
| | | public void getControllerMethodDescription(JoinPoint joinPoint, Log log, SysOperLog operLog, Object jsonResult) throws Exception |
| | | { |
| | | public void getControllerMethodDescription(JoinPoint joinPoint, Log log, SysOperLog operLog, Object jsonResult) throws Exception { |
| | | // 设置action动作 |
| | | operLog.setBusinessType(log.businessType().ordinal()); |
| | | // 设置标题 |
| | |
| | | // 设置操作人类别 |
| | | operLog.setOperatorType(log.operatorType().ordinal()); |
| | | // 是否需要保存request,参数和值 |
| | | if (log.isSaveRequestData()) |
| | | { |
| | | if (log.isSaveRequestData()) { |
| | | // 获取参数的信息,传入到数据库中。 |
| | | setRequestValue(joinPoint, operLog); |
| | | } |
| | | // 是否需要保存response,参数和值 |
| | | if (log.isSaveResponseData() && StringUtils.isNotNull(jsonResult)) |
| | | { |
| | | if (log.isSaveResponseData() && StringUtils.isNotNull(jsonResult)) { |
| | | operLog.setJsonResult(StringUtils.substring(JSON.toJSONString(jsonResult), 0, 2000)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取请求的参数,放到log中 |
| | | * |
| | | * |
| | | * @param operLog 操作日志 |
| | | * @throws Exception 异常 |
| | | */ |
| | | private void setRequestValue(JoinPoint joinPoint, SysOperLog operLog) throws Exception |
| | | { |
| | | private void setRequestValue(JoinPoint joinPoint, SysOperLog operLog) throws Exception { |
| | | String requestMethod = operLog.getRequestMethod(); |
| | | if (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)) |
| | | { |
| | | if (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)) { |
| | | String params = argsArrayToString(joinPoint.getArgs()); |
| | | operLog.setOperParam(StringUtils.substring(params, 0, 2000)); |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | Map<?, ?> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest()); |
| | | operLog.setOperParam(StringUtils.substring(JSON.toJSONString(paramsMap, excludePropertyPreFilter()), 0, 2000)); |
| | | } |
| | |
| | | /** |
| | | * 参数拼装 |
| | | */ |
| | | private String argsArrayToString(Object[] paramsArray) |
| | | { |
| | | private String argsArrayToString(Object[] paramsArray) { |
| | | String params = ""; |
| | | if (paramsArray != null && paramsArray.length > 0) |
| | | { |
| | | for (Object o : paramsArray) |
| | | { |
| | | if (StringUtils.isNotNull(o) && !isFilterObject(o)) |
| | | { |
| | | try |
| | | { |
| | | if (paramsArray != null && paramsArray.length > 0) { |
| | | for (Object o : paramsArray) { |
| | | if (StringUtils.isNotNull(o) && !isFilterObject(o)) { |
| | | try { |
| | | String jsonObj = JSON.toJSONString(o, excludePropertyPreFilter()); |
| | | params += jsonObj.toString() + " "; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } |
| | |
| | | /** |
| | | * 忽略敏感属性 |
| | | */ |
| | | public PropertyPreExcludeFilter excludePropertyPreFilter() |
| | | { |
| | | public PropertyPreExcludeFilter excludePropertyPreFilter() { |
| | | return new PropertyPreExcludeFilter().addExcludes(EXCLUDE_PROPERTIES); |
| | | } |
| | | |
| | | /** |
| | | * 判断是否需要过滤的对象。 |
| | | * |
| | | * |
| | | * @param o 对象信息。 |
| | | * @return 如果是需要过滤的对象,则返回true;否则返回false。 |
| | | */ |
| | | @SuppressWarnings("rawtypes") |
| | | public boolean isFilterObject(final Object o) |
| | | { |
| | | public boolean isFilterObject(final Object o) { |
| | | Class<?> clazz = o.getClass(); |
| | | if (clazz.isArray()) |
| | | { |
| | | if (clazz.isArray()) { |
| | | return clazz.getComponentType().isAssignableFrom(MultipartFile.class); |
| | | } |
| | | else if (Collection.class.isAssignableFrom(clazz)) |
| | | { |
| | | } else if (Collection.class.isAssignableFrom(clazz)) { |
| | | Collection collection = (Collection) o; |
| | | for (Object value : collection) |
| | | { |
| | | for (Object value : collection) { |
| | | return value instanceof MultipartFile; |
| | | } |
| | | } |
| | | else if (Map.class.isAssignableFrom(clazz)) |
| | | { |
| | | } else if (Map.class.isAssignableFrom(clazz)) { |
| | | Map map = (Map) o; |
| | | for (Object value : map.entrySet()) |
| | | { |
| | | for (Object value : map.entrySet()) { |
| | | Map.Entry entry = (Map.Entry) value; |
| | | return entry.getValue() instanceof MultipartFile; |
| | | } |