bobol
7 months ago
28 changed files with 1546 additions and 40 deletions
@ -0,0 +1,42 @@ |
|||
package com.lzbi.common.config; |
|||
|
|||
import com.alibaba.fastjson2.JSONObject; |
|||
import com.lzbi.common.core.domain.message.MessageSendReq; |
|||
import lombok.Data; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.context.properties.ConfigurationProperties; |
|||
import org.springframework.http.HttpEntity; |
|||
import org.springframework.http.HttpHeaders; |
|||
import org.springframework.http.MediaType; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.web.client.RestTemplate; |
|||
|
|||
@Slf4j |
|||
@Data |
|||
@Component |
|||
@ConfigurationProperties("message-send") |
|||
public class MessageSendConfig { |
|||
|
|||
@Autowired |
|||
private RestTemplate restTemplate; |
|||
|
|||
/** |
|||
* 消息发送地址 |
|||
*/ |
|||
private String url; |
|||
|
|||
public void send(MessageSendReq messageSendReq) { |
|||
HttpHeaders headers = new HttpHeaders(); |
|||
headers.setContentType(MediaType.APPLICATION_JSON); |
|||
String bodyStr = JSONObject.toJSONString(messageSendReq); |
|||
HttpEntity<String> entity = new HttpEntity<>(bodyStr, headers); |
|||
String result = ""; |
|||
try { |
|||
result = restTemplate.postForObject(this.url, entity, String.class); |
|||
} finally { |
|||
log.info("消息体:{},发送结果:{}", bodyStr, result); |
|||
} |
|||
} |
|||
|
|||
} |
@ -0,0 +1,54 @@ |
|||
package com.lzbi.common.config; |
|||
|
|||
|
|||
import lombok.Data; |
|||
import org.springframework.boot.context.properties.ConfigurationProperties; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
/** |
|||
* 巡检服务API |
|||
*/ |
|||
@Data |
|||
@Component |
|||
@ConfigurationProperties(prefix = "patrol-server") |
|||
public class PatrolServerApiConfig { |
|||
/** |
|||
* 用户名 |
|||
*/ |
|||
private String userName; |
|||
/** |
|||
* 密码 |
|||
*/ |
|||
private String userPwd; |
|||
/** |
|||
* 消息详情访问路径 |
|||
*/ |
|||
private String messageDetailUrl; |
|||
/** |
|||
* API |
|||
*/ |
|||
private Api api; |
|||
|
|||
/** |
|||
* API |
|||
*/ |
|||
@Data |
|||
public static class Api { |
|||
/** |
|||
* 登录 |
|||
*/ |
|||
private String login; |
|||
/** |
|||
* 验证 Token 值是否有效 |
|||
*/ |
|||
private String checkToken; |
|||
/** |
|||
* 获取线路列表 |
|||
*/ |
|||
private String routeList; |
|||
/** |
|||
* 获取报警列表 |
|||
*/ |
|||
private String alarmList; |
|||
} |
|||
} |
@ -0,0 +1,70 @@ |
|||
package com.lzbi.common.core.domain; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* elementUI树形控件节点 |
|||
*/ |
|||
public class ElementTreeNode { |
|||
|
|||
/** |
|||
* 值 |
|||
*/ |
|||
private Object value; |
|||
/** |
|||
* 标签 |
|||
*/ |
|||
private String label; |
|||
/** |
|||
* 是否可用 |
|||
*/ |
|||
private boolean disabled; |
|||
/** |
|||
* 是否叶子节点 |
|||
*/ |
|||
private boolean leaf; |
|||
/** |
|||
* 子节点 |
|||
*/ |
|||
private List<ElementTreeNode> children; |
|||
|
|||
public Object getValue() { |
|||
return value; |
|||
} |
|||
|
|||
public void setValue(Object value) { |
|||
this.value = value; |
|||
} |
|||
|
|||
public String getLabel() { |
|||
return label; |
|||
} |
|||
|
|||
public void setLabel(String label) { |
|||
this.label = label; |
|||
} |
|||
|
|||
public boolean isDisabled() { |
|||
return disabled; |
|||
} |
|||
|
|||
public void setDisabled(boolean disabled) { |
|||
this.disabled = disabled; |
|||
} |
|||
|
|||
public boolean isLeaf() { |
|||
return leaf; |
|||
} |
|||
|
|||
public void setLeaf(boolean leaf) { |
|||
this.leaf = leaf; |
|||
} |
|||
|
|||
public List<ElementTreeNode> getChildren() { |
|||
return children; |
|||
} |
|||
|
|||
public void setChildren(List<ElementTreeNode> children) { |
|||
this.children = children; |
|||
} |
|||
} |
@ -0,0 +1,58 @@ |
|||
package com.lzbi.common.core.domain.message; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import javax.validation.constraints.NotEmpty; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 消息发送请求实体类 |
|||
*/ |
|||
@Data |
|||
public class MessageSendReq { |
|||
|
|||
/** |
|||
* 系统 |
|||
*/ |
|||
@NotBlank(message = "系统不能为空") |
|||
protected String sys; |
|||
/** |
|||
* 平台 |
|||
*/ |
|||
@NotBlank(message = "平台不能为空") |
|||
protected String platform; |
|||
/** |
|||
* 消息类型(1、告警,2、公告) |
|||
*/ |
|||
@NotBlank(message = "消息类型不能为空") |
|||
protected String type; |
|||
/** |
|||
* 消息内容 |
|||
*/ |
|||
@NotBlank(message = "消息内容不能为空") |
|||
protected String content; |
|||
/** |
|||
* 告警设备 |
|||
*/ |
|||
@NotBlank(message = "告警设备不能为空") |
|||
protected String device; |
|||
/** |
|||
* 提醒时间 |
|||
*/ |
|||
@NotBlank(message = "提醒时间不能为空") |
|||
protected String time; |
|||
/** |
|||
* 温馨提示 |
|||
*/ |
|||
protected String hint; |
|||
/** |
|||
* 详情链接 |
|||
*/ |
|||
protected String url; |
|||
/** |
|||
* 手机号列表 |
|||
*/ |
|||
@NotEmpty(message = "手机号列表不能为空") |
|||
protected List<String> phoneList; |
|||
} |
@ -0,0 +1,30 @@ |
|||
package com.lzbi.common.core.domain.message; |
|||
|
|||
import com.alibaba.fastjson2.annotation.JSONField; |
|||
import com.lzbi.common.config.PatrolServerApiConfig; |
|||
import com.lzbi.common.constant.BizConstants; |
|||
import com.lzbi.common.utils.spring.SpringUtils; |
|||
import lombok.Data; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 巡检消息发送请求参数 |
|||
*/ |
|||
@Data |
|||
public class PatrolMessageSendReq extends MessageSendReq { |
|||
|
|||
@JSONField(serialize=false) |
|||
private PatrolServerApiConfig patrolServerApiConfig = SpringUtils.getBean(PatrolServerApiConfig.class); |
|||
|
|||
public PatrolMessageSendReq(String content, String time, List<String> phoneList) { |
|||
this.sys = "patrol"; |
|||
this.platform = BizConstants.MessagePlatform.WECOM; |
|||
this.type = BizConstants.MessageType.ALARM; |
|||
this.time = time; |
|||
this.phoneList = phoneList; |
|||
this.content = content; |
|||
this.hint = "请及时处理"; |
|||
this.setUrl(patrolServerApiConfig.getMessageDetailUrl()); |
|||
} |
|||
} |
@ -0,0 +1,166 @@ |
|||
package com.lzbi.patrol.controller; |
|||
import io.swagger.annotations.ApiImplicitParam; |
|||
import io.swagger.annotations.ApiImplicitParams; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import java.util.List; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
import javax.validation.constraints.NotEmpty; |
|||
|
|||
import org.springframework.security.access.prepost.PreAuthorize; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.validation.annotation.Validated; |
|||
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.lzbi.common.annotation.Log; |
|||
import com.lzbi.common.core.controller.BaseController; |
|||
import com.lzbi.common.core.domain.AjaxResult; |
|||
import com.lzbi.common.enums.BusinessType; |
|||
import com.lzbi.patrol.domain. DcBusiDeptPatrolRoute; |
|||
import com.lzbi.patrol.service.DcBusiDeptPatrolRouteService; |
|||
import com.lzbi.common.utils.poi.ExcelUtil; |
|||
import com.lzbi.common.core.page.TableDataInfo; |
|||
|
|||
/** |
|||
* 部门与巡检系统线路关系Controller |
|||
* |
|||
* @author Enbo Li |
|||
* @date 2024-05-08 |
|||
*/ |
|||
@Validated |
|||
@RestController |
|||
@RequestMapping("/lzbi/DcBusiDeptPatrolRoute") |
|||
public class DcBusiDeptPatrolRouteController extends BaseController |
|||
{ |
|||
@Autowired |
|||
private DcBusiDeptPatrolRouteService dcBusiDeptPatrolRouteService; |
|||
|
|||
/** |
|||
* 查询部门与巡检系统线路关系列表 |
|||
*/ |
|||
@ApiOperation("查询部门与巡检系统线路关系列表") |
|||
@ApiImplicitParams({ |
|||
@ApiImplicitParam(name = "DcBusiDeptPatrolRoute", value = "", dataType = "DcBusiDeptPatrolRoute", dataTypeClass = DcBusiDeptPatrolRoute.class), |
|||
}) |
|||
@PreAuthorize("@ss.hasPermi('lzbi:DcBusiDeptPatrolRoute:list')") |
|||
@GetMapping("/list") |
|||
public TableDataInfo list(DcBusiDeptPatrolRoute DcBusiDeptPatrolRoute) |
|||
{ |
|||
startPage(); |
|||
List< DcBusiDeptPatrolRoute> list = dcBusiDeptPatrolRouteService.selectDcBusiDeptPatrolRouteList(DcBusiDeptPatrolRoute); |
|||
return getDataTable(list); |
|||
} |
|||
|
|||
/** |
|||
* 导出部门与巡检系统线路关系列表 |
|||
*/ |
|||
@ApiOperation("导出部门与巡检系统线路关系列表") |
|||
@ApiImplicitParams({ |
|||
@ApiImplicitParam(name = "DcBusiDeptPatrolRoute", value = "", dataType = "DcBusiDeptPatrolRoute", dataTypeClass = DcBusiDeptPatrolRoute.class), |
|||
}) |
|||
@PreAuthorize("@ss.hasPermi('lzbi:DcBusiDeptPatrolRoute:export')") |
|||
@Log(title = "部门与巡检系统线路关系", businessType = BusinessType.EXPORT) |
|||
@PostMapping("/export") |
|||
public void export(HttpServletResponse response,DcBusiDeptPatrolRoute DcBusiDeptPatrolRoute) |
|||
{ |
|||
List<DcBusiDeptPatrolRoute> list = dcBusiDeptPatrolRouteService.selectDcBusiDeptPatrolRouteList(DcBusiDeptPatrolRoute); |
|||
ExcelUtil<DcBusiDeptPatrolRoute> util = new ExcelUtil<DcBusiDeptPatrolRoute>(DcBusiDeptPatrolRoute.class); |
|||
util.exportExcel(response, list, "部门与巡检系统线路关系数据"); |
|||
} |
|||
|
|||
/** |
|||
* 获取部门与巡检系统线路关系详细信息 |
|||
*/ |
|||
@ApiOperation("获取部门与巡检系统线路关系详细信息") |
|||
@ApiImplicitParams({ |
|||
@ApiImplicitParam(name = "deptId", value = "", dataType = "Long", dataTypeClass = Long.class), |
|||
}) |
|||
@PreAuthorize("@ss.hasPermi('lzbi:DcBusiDeptPatrolRoute:query')") |
|||
@GetMapping(value = "/{deptId}") |
|||
public AjaxResult getInfo(@PathVariable("deptId") Long deptId) |
|||
{ |
|||
return success(dcBusiDeptPatrolRouteService.selectDcBusiDeptPatrolRouteByDeptId(deptId)); |
|||
} |
|||
|
|||
/** |
|||
* 获取线路ID列表 |
|||
*/ |
|||
@ApiOperation("获取线路ID列表") |
|||
@ApiImplicitParams({ |
|||
@ApiImplicitParam(name = "deptId", value = "", dataType = "Long", dataTypeClass = Long.class), |
|||
}) |
|||
@PreAuthorize("@ss.hasPermi('lzbi:DcBusiDeptPatrolRoute:query')") |
|||
@GetMapping(value = "/routeIdList/{deptId}") |
|||
public AjaxResult getRouteIdList(@PathVariable("deptId") Long deptId) |
|||
{ |
|||
return success(dcBusiDeptPatrolRouteService.getRouteIdList(deptId)); |
|||
} |
|||
|
|||
/** |
|||
* 新增部门与巡检系统线路关系 |
|||
*/ |
|||
@ApiOperation("新增部门与巡检系统线路关系") |
|||
@ApiImplicitParams({ |
|||
@ApiImplicitParam(name = "DcBusiDeptPatrolRoute", value = "", dataType = "DcBusiDeptPatrolRoute", dataTypeClass = DcBusiDeptPatrolRoute.class), |
|||
}) |
|||
@PreAuthorize("@ss.hasPermi('lzbi:DcBusiDeptPatrolRoute:add')") |
|||
@Log(title = "部门与巡检系统线路关系", businessType = BusinessType.INSERT) |
|||
@PostMapping |
|||
public AjaxResult add(@RequestBody DcBusiDeptPatrolRoute DcBusiDeptPatrolRoute) |
|||
{ |
|||
return toAjax(dcBusiDeptPatrolRouteService.insertDcBusiDeptPatrolRoute(DcBusiDeptPatrolRoute)); |
|||
} |
|||
|
|||
/** |
|||
* 修改部门与巡检系统线路关系 |
|||
*/ |
|||
|
|||
@ApiOperation("修改部门与巡检系统线路关系") |
|||
@ApiImplicitParams({ |
|||
@ApiImplicitParam(name = "DcBusiDeptPatrolRoute", value = "", dataType = "DcBusiDeptPatrolRoute", dataTypeClass = DcBusiDeptPatrolRoute.class), |
|||
}) |
|||
@PreAuthorize("@ss.hasPermi('lzbi:DcBusiDeptPatrolRoute:edit')") |
|||
@Log(title = "部门与巡检系统线路关系", businessType = BusinessType.UPDATE) |
|||
@PutMapping |
|||
public AjaxResult edit(@RequestBody DcBusiDeptPatrolRoute DcBusiDeptPatrolRoute) |
|||
{ |
|||
return toAjax(dcBusiDeptPatrolRouteService.updateDcBusiDeptPatrolRoute(DcBusiDeptPatrolRoute)); |
|||
} |
|||
|
|||
/** |
|||
* 修改部门与巡检系统线路关系 |
|||
*/ |
|||
|
|||
@ApiOperation("更新部门与巡检系统线路关系") |
|||
@ApiImplicitParams({ |
|||
@ApiImplicitParam(name = "deptId", value = "", dataType = "Long", dataTypeClass = Long.class), |
|||
}) |
|||
@PreAuthorize("@ss.hasPermi('lzbi:DcBusiDeptPatrolRoute:edit')") |
|||
@Log(title = "更新部门与巡检系统线路关系", businessType = BusinessType.UPDATE) |
|||
@PutMapping("/{deptId}") |
|||
public AjaxResult update(@PathVariable("deptId") Long deptId, |
|||
@NotEmpty(message = "请选择线路") @RequestBody List<Long> routeIdList) |
|||
{ |
|||
return toAjax(dcBusiDeptPatrolRouteService.update(deptId, routeIdList)); |
|||
} |
|||
|
|||
/** |
|||
* 删除部门与巡检系统线路关系 |
|||
*/ |
|||
@ApiOperation("删除部门与巡检系统线路关系") |
|||
@ApiImplicitParams({ |
|||
@ApiImplicitParam(name = "deptIds", value = "", dataType = "Long", dataTypeClass =Long.class), |
|||
}) |
|||
@PreAuthorize("@ss.hasPermi('lzbi:DcBusiDeptPatrolRoute:remove')") |
|||
@Log(title = "部门与巡检系统线路关系", businessType = BusinessType.DELETE) |
|||
@DeleteMapping("/{deptIds}") |
|||
public AjaxResult remove(@PathVariable Long[] deptIds) |
|||
{ |
|||
return toAjax(dcBusiDeptPatrolRouteService.deleteDcBusiDeptPatrolRouteByDeptIds(deptIds)); |
|||
} |
|||
} |
@ -0,0 +1,60 @@ |
|||
package com.lzbi.patrol.controller; |
|||
|
|||
import com.lzbi.common.core.domain.AjaxResult; |
|||
import com.lzbi.patrol.service.PatrolSysService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 巡检系统 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("/patrol-sys") |
|||
public class PatrolSysController { |
|||
|
|||
@Autowired |
|||
private PatrolSysService patrolSysService; |
|||
|
|||
/** |
|||
* 获取线路树形结构 |
|||
* @return |
|||
*/ |
|||
@GetMapping("/route-tree") |
|||
public AjaxResult getRouteTree() { |
|||
return AjaxResult.success(patrolSysService.getRouteTree()); |
|||
} |
|||
|
|||
/** |
|||
* 获取告警列表 |
|||
* @return |
|||
*/ |
|||
@GetMapping("/alarm-list") |
|||
public AjaxResult getAlarmList(@RequestParam("startTime") String startTime, |
|||
@RequestParam("endTime") String endTime, |
|||
@RequestParam("pageIndex") Integer pageIndex, |
|||
@RequestParam("pageSize") Integer pageSize) { |
|||
return AjaxResult.success(patrolSysService.getAlarmList(startTime, endTime, pageIndex, pageSize)); |
|||
} |
|||
|
|||
/** |
|||
* 获取告警列表 |
|||
* @return |
|||
*/ |
|||
@GetMapping("/alarm-list/{routeId}") |
|||
public AjaxResult getAlarmListByRouteId(@PathVariable("routeId") String routeId) { |
|||
return AjaxResult.success(patrolSysService.getAlarmListByRouteId(routeId)); |
|||
} |
|||
|
|||
/** |
|||
* 触发告警 |
|||
* @return |
|||
*/ |
|||
@PostMapping("/trigger/alarm") |
|||
public AjaxResult triggerAlarm(@RequestBody Map<Long, Integer> routeAlarmCountMap) { |
|||
patrolSysService.triggerAlarm(routeAlarmCountMap); |
|||
return AjaxResult.success(); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,29 @@ |
|||
package com.lzbi.patrol.domain; |
|||
|
|||
import com.baomidou.mybatisplus.extension.activerecord.Model; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
import lombok.experimental.Accessors; |
|||
|
|||
/** |
|||
* 部门与巡检系统线路关系对象 dc_busi_dept_patrol_route |
|||
* |
|||
* @author Enbo Li |
|||
* @date 2024-05-08 |
|||
*/ |
|||
@Data |
|||
@Accessors(chain = true) |
|||
@AllArgsConstructor |
|||
@NoArgsConstructor |
|||
public class DcBusiDeptPatrolRoute extends Model<DcBusiDeptPatrolRoute> |
|||
{ |
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** 部门id */ |
|||
private Long deptId; |
|||
|
|||
/** 线路id */ |
|||
private Long routeId; |
|||
|
|||
} |
@ -0,0 +1,63 @@ |
|||
package com.lzbi.patrol.mapper; |
|||
|
|||
import java.util.List; |
|||
import com.lzbi.patrol.domain.DcBusiDeptPatrolRoute; |
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
|
|||
/** |
|||
* 部门与巡检系统线路关系Mapper接口 |
|||
* |
|||
* @author Enbo Li |
|||
* @date 2024-05-08 |
|||
*/ |
|||
|
|||
public interface DcBusiDeptPatrolRouteMapper extends BaseMapper<DcBusiDeptPatrolRoute> |
|||
{ |
|||
/** |
|||
* 查询部门与巡检系统线路关系 |
|||
* |
|||
* @param deptId 部门与巡检系统线路关系主键 |
|||
* @return 部门与巡检系统线路关系 |
|||
*/ |
|||
public DcBusiDeptPatrolRoute selectDcBusiDeptPatrolRouteByDeptId(Long deptId); |
|||
|
|||
/** |
|||
* 查询部门与巡检系统线路关系列表 |
|||
* |
|||
* @param dcBusiDeptPatrolRoute 部门与巡检系统线路关系 |
|||
* @return 部门与巡检系统线路关系集合 |
|||
*/ |
|||
public List<DcBusiDeptPatrolRoute> selectDcBusiDeptPatrolRouteList(DcBusiDeptPatrolRoute dcBusiDeptPatrolRoute); |
|||
|
|||
/** |
|||
* 新增部门与巡检系统线路关系 |
|||
* |
|||
* @param dcBusiDeptPatrolRoute 部门与巡检系统线路关系 |
|||
* @return 结果 |
|||
*/ |
|||
public int insertDcBusiDeptPatrolRoute(DcBusiDeptPatrolRoute dcBusiDeptPatrolRoute); |
|||
|
|||
/** |
|||
* 修改部门与巡检系统线路关系 |
|||
* |
|||
* @param dcBusiDeptPatrolRoute 部门与巡检系统线路关系 |
|||
* @return 结果 |
|||
*/ |
|||
public int updateDcBusiDeptPatrolRoute(DcBusiDeptPatrolRoute dcBusiDeptPatrolRoute); |
|||
|
|||
/** |
|||
* 删除部门与巡检系统线路关系 |
|||
* |
|||
* @param deptId 部门与巡检系统线路关系主键 |
|||
* @return 结果 |
|||
*/ |
|||
public int deleteDcBusiDeptPatrolRouteByDeptId(Long deptId); |
|||
|
|||
/** |
|||
* 批量删除部门与巡检系统线路关系 |
|||
* |
|||
* @param deptIds 需要删除的数据主键集合 |
|||
* @return 结果 |
|||
*/ |
|||
public int deleteDcBusiDeptPatrolRouteByDeptIds(Long[] deptIds); |
|||
} |
@ -0,0 +1,112 @@ |
|||
package com.lzbi.patrol.service; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.stream.Collectors; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import org.springframework.stereotype.Service; |
|||
import com.lzbi.patrol.domain.DcBusiDeptPatrolRoute; |
|||
import com.lzbi.patrol.mapper.DcBusiDeptPatrolRouteMapper; |
|||
import com.baomidou.mybatisplus.extension.service.IService; |
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.springframework.util.CollectionUtils; |
|||
|
|||
/** |
|||
* 部门与巡检系统线路关系Service业务层处理 |
|||
* |
|||
* @author Enbo Li |
|||
* @date 2024-05-08 |
|||
*/ |
|||
@Service |
|||
public class DcBusiDeptPatrolRouteService extends ServiceImpl<DcBusiDeptPatrolRouteMapper, DcBusiDeptPatrolRoute> implements IService<DcBusiDeptPatrolRoute> |
|||
{ |
|||
|
|||
/** |
|||
* 查询部门与巡检系统线路关系 |
|||
* |
|||
* @param deptId 部门与巡检系统线路关系主键 |
|||
* @return 部门与巡检系统线路关系 |
|||
*/ |
|||
public DcBusiDeptPatrolRoute selectDcBusiDeptPatrolRouteByDeptId(Long deptId) |
|||
{ |
|||
return baseMapper.selectDcBusiDeptPatrolRouteByDeptId(deptId); |
|||
} |
|||
|
|||
/** |
|||
* 查询部门与巡检系统线路关系列表 |
|||
* |
|||
* @param dcBusiDeptPatrolRoute 部门与巡检系统线路关系 |
|||
* @return 部门与巡检系统线路关系 |
|||
*/ |
|||
public List<DcBusiDeptPatrolRoute> selectDcBusiDeptPatrolRouteList(DcBusiDeptPatrolRoute dcBusiDeptPatrolRoute) |
|||
{ |
|||
return baseMapper.selectDcBusiDeptPatrolRouteList(dcBusiDeptPatrolRoute); |
|||
} |
|||
|
|||
/** |
|||
* 新增部门与巡检系统线路关系 |
|||
* |
|||
* @param dcBusiDeptPatrolRoute 部门与巡检系统线路关系 |
|||
* @return 结果 |
|||
*/ |
|||
|
|||
public int insertDcBusiDeptPatrolRoute(DcBusiDeptPatrolRoute dcBusiDeptPatrolRoute) |
|||
{ |
|||
return baseMapper.insertDcBusiDeptPatrolRoute(dcBusiDeptPatrolRoute); |
|||
} |
|||
|
|||
/** |
|||
* 修改部门与巡检系统线路关系 |
|||
* |
|||
* @param dcBusiDeptPatrolRoute 部门与巡检系统线路关系 |
|||
* @return 结果 |
|||
*/ |
|||
|
|||
public int updateDcBusiDeptPatrolRoute(DcBusiDeptPatrolRoute dcBusiDeptPatrolRoute) |
|||
{ |
|||
return baseMapper.updateDcBusiDeptPatrolRoute(dcBusiDeptPatrolRoute); |
|||
} |
|||
|
|||
/** |
|||
* 批量删除部门与巡检系统线路关系 |
|||
* |
|||
* @param deptIds 需要删除的部门与巡检系统线路关系主键 |
|||
* @return 结果 |
|||
*/ |
|||
|
|||
public int deleteDcBusiDeptPatrolRouteByDeptIds(Long[] deptIds) |
|||
{ |
|||
return baseMapper.deleteDcBusiDeptPatrolRouteByDeptIds(deptIds); |
|||
} |
|||
|
|||
/** |
|||
* 删除部门与巡检系统线路关系信息 |
|||
* |
|||
* @param deptId 部门与巡检系统线路关系主键 |
|||
* @return 结果 |
|||
*/ |
|||
|
|||
public int deleteDcBusiDeptPatrolRouteByDeptId(Long deptId) |
|||
{ |
|||
return baseMapper.deleteDcBusiDeptPatrolRouteByDeptId(deptId); |
|||
} |
|||
|
|||
public List<Long> getRouteIdList(Long deptId) { |
|||
QueryWrapper<DcBusiDeptPatrolRoute> wrapper = new QueryWrapper<>(); |
|||
wrapper.eq("dept_id", deptId); |
|||
List<DcBusiDeptPatrolRoute> list = this.list(wrapper); |
|||
if (!CollectionUtils.isEmpty(list)) { |
|||
return list.stream().map(DcBusiDeptPatrolRoute::getRouteId).collect(Collectors.toList()); |
|||
} |
|||
return new ArrayList<>(); |
|||
} |
|||
|
|||
@Transactional(rollbackFor = Exception.class) |
|||
public boolean update(Long deptId, List<Long> routeIdList) { |
|||
this.remove(new QueryWrapper<DcBusiDeptPatrolRoute>().eq("dept_id", deptId)); |
|||
List<DcBusiDeptPatrolRoute> dcBusiDeptPatrolRouteList = routeIdList.stream().map(routeId -> new DcBusiDeptPatrolRoute(deptId, routeId)).collect(Collectors.toList()); |
|||
return this.saveBatch(dcBusiDeptPatrolRouteList); |
|||
} |
|||
} |
@ -0,0 +1,181 @@ |
|||
package com.lzbi.patrol.service; |
|||
|
|||
import com.alibaba.fastjson2.JSONArray; |
|||
import com.alibaba.fastjson2.JSONObject; |
|||
import com.lzbi.common.config.PatrolServerApiConfig; |
|||
import com.lzbi.common.constant.CacheConstants; |
|||
import com.lzbi.common.core.redis.RedisCache; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.util.CollectionUtils; |
|||
import org.springframework.web.client.RestTemplate; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 巡检系统API业务 |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
public class PatrolSysApiService { |
|||
|
|||
@Autowired |
|||
private RestTemplate restTemplate; |
|||
|
|||
@Autowired |
|||
private PatrolServerApiConfig patrolServerApiConfig; |
|||
|
|||
@Autowired |
|||
private RedisCache redisCache; |
|||
|
|||
/** |
|||
* 登录 |
|||
* @param userName |
|||
* @param userPwd |
|||
* @return |
|||
*/ |
|||
public String login(String userName, String userPwd) { |
|||
String key = CacheConstants.PATROL_SYS_BASE + CacheConstants.PATROL_SYS_TOKEN + userName; |
|||
String token = redisCache.getCacheObject(key); |
|||
if (StringUtils.isBlank(token)) { |
|||
Map<String, String> params = new HashMap<>(); |
|||
params.put("userName", userName); |
|||
params.put("userPwd", userPwd); |
|||
String result = restTemplate.getForObject(patrolServerApiConfig.getApi().getLogin(), String.class, params); |
|||
log.info("登录返回值:{},参数:{}/{}", result, userName, userPwd); |
|||
if (StringUtils.isBlank(result)) { |
|||
log.error("登录失败,无返回值"); |
|||
throw new RuntimeException("登录失败,无返回值"); |
|||
} |
|||
JSONObject resultJson = JSONObject.parseObject(result); |
|||
JSONObject d = resultJson.getJSONObject("d"); |
|||
if (d == null) { |
|||
log.error("登录失败,返回值中无d字段"); |
|||
throw new RuntimeException("登录失败,返回值中无d字段"); |
|||
} |
|||
token = d.getString("Token"); |
|||
if (StringUtils.isBlank(token)) { |
|||
log.error("登录失败,返回值中无token字段"); |
|||
throw new RuntimeException("登录失败,返回值中无token字段"); |
|||
} |
|||
redisCache.setCacheObject(key, token); |
|||
} |
|||
return token; |
|||
} |
|||
|
|||
/** |
|||
* 验证 Token 值是否有效 |
|||
* @param token |
|||
* @return |
|||
*/ |
|||
public boolean checkToken(String token) { |
|||
Map<String, String> params = new HashMap<>(); |
|||
params.put("token", token); |
|||
String result = restTemplate.getForObject(patrolServerApiConfig.getApi().getCheckToken(), String.class, params); |
|||
log.info("验证 Token 值是否有效返回值:{}, 参数:{}", result, JSONObject.toJSONString(params)); |
|||
if (StringUtils.isBlank(result)) { |
|||
log.error("验证 Token 值是否有效失败,无返回值"); |
|||
throw new RuntimeException("登录失败,无返回值"); |
|||
} |
|||
JSONObject resultJson = JSONObject.parseObject(result); |
|||
String d = resultJson.getString("d"); |
|||
if (StringUtils.isBlank(d)) { |
|||
log.error("验证 Token 值是否有效失败,返回值中无d字段"); |
|||
throw new RuntimeException("登录失败,返回值中无d字段"); |
|||
} |
|||
if ("\"{success:true}\"".equals(d)) { |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
/** |
|||
* 获取 Token 值 |
|||
* @return |
|||
*/ |
|||
public String getToken() { |
|||
String token = this.login(patrolServerApiConfig.getUserName(), patrolServerApiConfig.getUserPwd()); |
|||
if (StringUtils.isBlank(token)) { |
|||
log.error("获取 Token 值失败"); |
|||
throw new RuntimeException("获取 Token 值失败"); |
|||
} |
|||
// 如果token无效,就清除redis中的token,重新获取
|
|||
if (!this.checkToken(token)) { |
|||
log.error("第一次获取 Token 值失败,Token 值无效"); |
|||
String key = CacheConstants.PATROL_SYS_BASE + CacheConstants.PATROL_SYS_TOKEN + patrolServerApiConfig.getUserName(); |
|||
redisCache.deleteObject(key); |
|||
token = this.login(patrolServerApiConfig.getUserName(), patrolServerApiConfig.getUserPwd()); |
|||
if (!this.checkToken(token)) { |
|||
log.error("第二次获取 Token 值失败,Token 值无效"); |
|||
throw new RuntimeException("获取 Token 值失败,Token 值无效"); |
|||
} |
|||
} |
|||
return token; |
|||
} |
|||
|
|||
/** |
|||
* 获取巡检线路列表 |
|||
* @return |
|||
*/ |
|||
public JSONArray getRouteList() { |
|||
String token = getToken(); |
|||
Map<String, String> params = new HashMap<>(); |
|||
params.put("token", token); |
|||
String result = restTemplate.getForObject(patrolServerApiConfig.getApi().getRouteList(), String.class, params); |
|||
log.info("获取巡检线路列表返回值:{},参数:{}", result, JSONObject.toJSONString(params)); |
|||
if (StringUtils.isBlank(result)) { |
|||
log.error("获取巡检线路列表失败,无返回值"); |
|||
throw new RuntimeException("获取巡检线路列表失败,无返回值"); |
|||
} |
|||
JSONObject resultJson = JSONObject.parseObject(result); |
|||
JSONArray d = resultJson.getJSONArray("d"); |
|||
if (CollectionUtils.isEmpty(d)) { |
|||
log.error("获取巡检线路列表失败,返回值中无d字段"); |
|||
throw new RuntimeException("获取巡检线路列表失败,返回值中无d字段"); |
|||
} |
|||
log.info("获取巡检线路列表成功,线路列表:{}", d.toJSONString()); |
|||
return d; |
|||
} |
|||
|
|||
/** |
|||
* 获取巡检报警列表 |
|||
* @param startTime |
|||
* @param endTime |
|||
* @param routeId |
|||
* @param pageIndex |
|||
* @param pageSize |
|||
* @return |
|||
*/ |
|||
public JSONArray getAlarmList(String startTime, String endTime, Long routeId, int pageIndex, int pageSize) { |
|||
String token = getToken(); |
|||
JSONObject params = new JSONObject(); |
|||
params.put("token", token); |
|||
params.put("startTime", startTime); |
|||
params.put("endTime", endTime); |
|||
params.put("routeId", routeId); |
|||
params.put("pageIndex", pageIndex); |
|||
params.put("pageSize", pageSize); |
|||
String result = restTemplate.getForObject(patrolServerApiConfig.getApi().getAlarmList(), String.class, params); |
|||
log.info("获取报警列表返回值:{},参数:{}", result, params.toJSONString()); |
|||
if (StringUtils.isBlank(result)) { |
|||
log.error("获取报警列表失败,无返回值"); |
|||
throw new RuntimeException("获取报警列表失败,无返回值"); |
|||
} |
|||
JSONObject resultJson = JSONObject.parseObject(result); |
|||
JSONObject d = resultJson.getJSONObject("d"); |
|||
if (null == d) { |
|||
log.error("获取报警列表失败,返回值中无d字段"); |
|||
throw new RuntimeException("获取报警列表失败,返回值中无d字段"); |
|||
} |
|||
JSONArray data = d.getJSONArray("data"); |
|||
if (null == data) { |
|||
log.error("获取报警列表失败,返回值中无data字段"); |
|||
throw new RuntimeException("获取报警列表失败,返回值中无data字段"); |
|||
} |
|||
log.info("获取报警列表成功,线路列表:{}", data.toJSONString()); |
|||
return data; |
|||
} |
|||
} |
@ -0,0 +1,296 @@ |
|||
package com.lzbi.patrol.service; |
|||
|
|||
import com.alibaba.fastjson2.JSONArray; |
|||
import com.alibaba.fastjson2.JSONObject; |
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.lzbi.common.config.MessageSendConfig; |
|||
import com.lzbi.common.constant.BizConstants; |
|||
import com.lzbi.common.constant.CacheConstants; |
|||
import com.lzbi.common.core.domain.ElementTreeNode; |
|||
import com.lzbi.common.core.domain.message.MessageSendReq; |
|||
import com.lzbi.common.core.domain.entity.SysDept; |
|||
import com.lzbi.common.core.domain.entity.SysUser; |
|||
import com.lzbi.common.core.domain.message.PatrolMessageSendReq; |
|||
import com.lzbi.common.core.redis.RedisCache; |
|||
import com.lzbi.patrol.domain.DcBusiDeptPatrolRoute; |
|||
import com.lzbi.system.service.ISysDeptService; |
|||
import com.lzbi.system.service.ISysUserService; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.util.CollectionUtils; |
|||
|
|||
import java.time.LocalDateTime; |
|||
import java.time.format.DateTimeFormatter; |
|||
import java.util.*; |
|||
import java.util.concurrent.TimeUnit; |
|||
import java.util.stream.Collectors; |
|||
|
|||
/** |
|||
* 巡检系统业务 |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
public class PatrolSysService { |
|||
|
|||
@Autowired |
|||
private PatrolSysApiService patrolSysApiService; |
|||
|
|||
@Autowired |
|||
private DcBusiDeptPatrolRouteService dcBusiDeptPatrolRouteService; |
|||
|
|||
@Autowired |
|||
private ISysDeptService sysDeptService; |
|||
|
|||
@Autowired |
|||
private ISysUserService sysUserService; |
|||
|
|||
@Autowired |
|||
private ThreadPoolTaskExecutor threadPoolTaskExecutor; |
|||
|
|||
@Autowired |
|||
private MessageSendConfig messageSendConfig; |
|||
|
|||
@Autowired |
|||
private RedisCache redisCache; |
|||
|
|||
private final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
|||
private final DateTimeFormatter dateTimeFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
|||
|
|||
/** |
|||
* 获取告警列表 |
|||
* |
|||
* @param startTime |
|||
* @param endTime |
|||
* @param pageIndex |
|||
* @param pageSize |
|||
* @return |
|||
*/ |
|||
public Map<String, List<JSONObject>> getAlarmList(String startTime, String endTime, Integer pageIndex, Integer pageSize) { |
|||
Map<String, List<JSONObject>> map = new HashMap<>(); |
|||
JSONArray routeList = patrolSysApiService.getRouteList(); |
|||
if (CollectionUtils.isEmpty(routeList)) { |
|||
return new HashMap<>(); |
|||
} |
|||
LocalDateTime nowTime = LocalDateTime.now(); |
|||
if (StringUtils.isBlank(startTime)) { |
|||
startTime = nowTime.toLocalDate().format(dateFormat) + "00:00:00"; |
|||
} |
|||
if (StringUtils.isBlank(endTime)) { |
|||
endTime = nowTime.format(dateTimeFormat); |
|||
} |
|||
if (null == pageIndex) { |
|||
pageIndex = 1; |
|||
} |
|||
if (null == pageSize) { |
|||
pageSize = Integer.MAX_VALUE; |
|||
} |
|||
// 线路报警数量map
|
|||
Map<Long, Integer> routeAlarmCountMap = new HashMap<>(); |
|||
// 获取告警列表
|
|||
for (Object route : routeList) { |
|||
JSONObject routeObj = (JSONObject) route; |
|||
Long routeId = routeObj.getLong("RouteID"); |
|||
// 获取线路的告警列表
|
|||
JSONArray alarmList = patrolSysApiService.getAlarmList(startTime, endTime, routeId, pageIndex, pageSize); |
|||
if (!CollectionUtils.isEmpty(alarmList)) { |
|||
// 过滤出漏检提醒类型的告警列表
|
|||
List<Object> missedReminderList = alarmList.stream().filter(item -> { |
|||
JSONObject alarm = ((JSONObject) item); |
|||
String alarmType = alarm.getString("AlarmType"); |
|||
if (BizConstants.PatrolAlarmType.MISSED_REMINDER.equals(alarmType)) { |
|||
return true; |
|||
} |
|||
return false; |
|||
}).collect(Collectors.toList()); |
|||
List<JSONObject> list; |
|||
String routeIdStr = routeId.toString(); |
|||
if (map.containsKey(routeIdStr)) { |
|||
list = map.get(routeIdStr); |
|||
} else { |
|||
list= new ArrayList<>(); |
|||
} |
|||
missedReminderList.forEach(alarm -> list.add((JSONObject) alarm)); |
|||
map.put(routeIdStr, list); |
|||
if (routeAlarmCountMap.containsKey(routeId)) { |
|||
Integer count = routeAlarmCountMap.get(routeId); |
|||
count = count + missedReminderList.size(); |
|||
routeAlarmCountMap.put(routeId, count); |
|||
} else { |
|||
routeAlarmCountMap.put(routeId, missedReminderList.size()); |
|||
} |
|||
} |
|||
} |
|||
// 触发报警
|
|||
this.triggerAlarm(routeAlarmCountMap); |
|||
// 将告警列表添加到缓存
|
|||
redisCache.setCacheMap(CacheConstants.PATROL_SYS_BASE + CacheConstants.PATROL_SYS_ALARM_MAP, map); |
|||
return map; |
|||
} |
|||
|
|||
public List<JSONObject> getAlarmListByRouteId(String routeId) { |
|||
String key = CacheConstants.PATROL_SYS_BASE + CacheConstants.PATROL_SYS_ALARM_MAP; |
|||
List<JSONObject> list = redisCache.getCacheMapValue(key, routeId); |
|||
if (CollectionUtils.isEmpty(list)) { |
|||
LocalDateTime nowTime = LocalDateTime.now(); |
|||
String startTime = nowTime.toLocalDate().format(dateFormat) + "00:00:00"; |
|||
String endTime = nowTime.format(dateTimeFormat); |
|||
int pageIndex = 1; |
|||
int pageSize = Integer.MAX_VALUE; |
|||
// 获取线路的告警列表
|
|||
JSONArray alarmList = patrolSysApiService.getAlarmList(startTime, endTime, Long.parseLong(routeId), pageIndex, pageSize); |
|||
list = alarmList.toJavaList(JSONObject.class); |
|||
redisCache.setCacheMapValue(key, routeId, list); |
|||
} |
|||
return list; |
|||
} |
|||
|
|||
/** |
|||
* 触发告警 |
|||
* @param routeAlarmCountMap |
|||
*/ |
|||
public void triggerAlarm(Map<Long, Integer> routeAlarmCountMap) { |
|||
List<MessageSendReq> messageSendReqList = this.buildPatrolAlarmMessage(routeAlarmCountMap); |
|||
if (!CollectionUtils.isEmpty(messageSendReqList)) { |
|||
messageSendReqList.forEach(messageSendReq -> threadPoolTaskExecutor.execute(() -> messageSendConfig.send(messageSendReq))); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 构建巡检告警消息 |
|||
* @param routeAlarmCountMap |
|||
* @return |
|||
*/ |
|||
private List<MessageSendReq> buildPatrolAlarmMessage(Map<Long, Integer> routeAlarmCountMap) { |
|||
List<MessageSendReq> list = new ArrayList<>(); |
|||
if (!CollectionUtils.isEmpty(routeAlarmCountMap)) { |
|||
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); |
|||
LocalDateTime now = LocalDateTime.now(); |
|||
String time = now.format(dateTimeFormatter); |
|||
Set<Long> routeIdSet = routeAlarmCountMap.keySet(); |
|||
// 根据线路查询部门与线路关系表数据
|
|||
List<DcBusiDeptPatrolRoute> dcBusiDeptPatrolRouteList = dcBusiDeptPatrolRouteService.list(new QueryWrapper<DcBusiDeptPatrolRoute>().in("route_id", routeIdSet)); |
|||
if (CollectionUtils.isEmpty(dcBusiDeptPatrolRouteList)) { |
|||
log.error("巡检系统配置中的线路没有对应的部门,线路:{}", JSONArray.toJSONString(routeIdSet)); |
|||
} else { |
|||
// 按部门id分组
|
|||
Map<Long, List<DcBusiDeptPatrolRoute>> deptIdRouteIdGroupMap = dcBusiDeptPatrolRouteList.stream().collect(Collectors.groupingBy(DcBusiDeptPatrolRoute::getDeptId)); |
|||
// 获取部门id列表
|
|||
List<Long> deptIdList = dcBusiDeptPatrolRouteList.stream().map(DcBusiDeptPatrolRoute::getDeptId).collect(Collectors.toList()); |
|||
// 获取部门列表
|
|||
List<SysDept> deptList = sysDeptService.getDeptListByDeptIdList(deptIdList); |
|||
if (CollectionUtils.isEmpty(deptList)) { |
|||
log.error("巡检系统配置中的部门id不在系统中,部门:{}", JSONArray.toJSONString(deptList)); |
|||
} else { |
|||
// 部门id: 部门名称
|
|||
Map<Long, String> deptNameMap = deptList.stream().collect(Collectors.toMap(SysDept::getDeptId, SysDept::getDeptName)); |
|||
// 部门id: 部门层级
|
|||
Map<Long, String> deptAncestorsMap = deptList.stream().collect(Collectors.toMap(SysDept::getDeptId, SysDept::getAncestors)); |
|||
// 遍历部门id分组map,key: 部门id,value: 部门线路列表
|
|||
deptIdRouteIdGroupMap.forEach((deptId, deptRouteList) -> { |
|||
if (deptNameMap.containsKey(deptId)) { |
|||
// 报警部门的报警总数
|
|||
int sum = 0; |
|||
// 计算总数
|
|||
for (DcBusiDeptPatrolRoute dcBusiDeptPatrolRoute : deptRouteList) { |
|||
Long routeId = dcBusiDeptPatrolRoute.getRouteId(); |
|||
if (routeAlarmCountMap.containsKey(routeId)) { |
|||
Integer count = routeAlarmCountMap.get(routeId); |
|||
sum += count; |
|||
} |
|||
} |
|||
String ancestors = deptAncestorsMap.get(deptId); |
|||
// 拼接需要发送消息的部门
|
|||
String deptIds = ancestors + "," + deptId; |
|||
// 根据部门和巡检通知角色查询用户
|
|||
List<SysUser> sysUserList = sysUserService.selectUserListByDeptIdsStrAndRoleKey(deptIds, BizConstants.RoleKey.PATROL_NOTIFY); |
|||
if (CollectionUtils.isEmpty(sysUserList)) { |
|||
log.error("系统中未配置相关部门的巡检通知角色的用户,部门id:{}", deptId); |
|||
} else { |
|||
String deptName = deptNameMap.get(deptId); |
|||
List<String> phoneList = sysUserList.stream().map(SysUser::getPhonenumber).collect(Collectors.toList()); |
|||
String content = deptName + "发生了 " + sum + " 次漏检告警"; |
|||
list.add(new PatrolMessageSendReq(content, time, phoneList)); |
|||
} |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
return list; |
|||
} |
|||
|
|||
/** |
|||
* 获取线路树形结构 |
|||
* |
|||
* @return |
|||
*/ |
|||
public List<ElementTreeNode> getRouteTree() { |
|||
String key = CacheConstants.PATROL_SYS_BASE + CacheConstants.PATROL_SYS_ROUTE_TREE; |
|||
String routeTreeJsonStr = redisCache.getCacheObject(key); |
|||
if (StringUtils.isBlank(routeTreeJsonStr)) { |
|||
JSONArray routeList = patrolSysApiService.getRouteList(); |
|||
List<ElementTreeNode> elementTreeNodes = this.buildRouteTree(routeList); |
|||
redisCache.setCacheObject(key, JSONArray.toJSONString(elementTreeNodes), 30, TimeUnit.MINUTES); |
|||
return elementTreeNodes; |
|||
} else { |
|||
return JSONArray.parseArray(routeTreeJsonStr, ElementTreeNode.class); |
|||
} |
|||
} |
|||
|
|||
private List<ElementTreeNode> buildRouteTree(JSONArray routeList) { |
|||
if (CollectionUtils.isEmpty(routeList)) { |
|||
return new ArrayList<>(); |
|||
} |
|||
List<ElementTreeNode> list = new ArrayList<>(); |
|||
// 根节点线路id
|
|||
Long rootRouteId = 0L; |
|||
// 获取根节点的下级节点
|
|||
for (int i = routeList.size() - 1; i > -1; i--) { |
|||
JSONObject route = routeList.getJSONObject(i); |
|||
Long routeId = route.getLong("ParentID"); |
|||
if (routeId.equals(rootRouteId)) { |
|||
routeList.remove(i); |
|||
list.add(this.buildRouteTreeNode(route)); |
|||
break; |
|||
} |
|||
} |
|||
if (!list.isEmpty()) { |
|||
for (ElementTreeNode elementTreeNode : list) { |
|||
this.recursionTransRouteTree(elementTreeNode, routeList); |
|||
} |
|||
} |
|||
return list; |
|||
} |
|||
|
|||
private void recursionTransRouteTree(ElementTreeNode parentMode, JSONArray routeList) { |
|||
if (null != parentMode && !CollectionUtils.isEmpty(routeList)) { |
|||
Long parentRouteId = (Long) parentMode.getValue(); |
|||
for (Object o : routeList) { |
|||
JSONObject route = (JSONObject) o; |
|||
Long routeParentId = route.getLong("ParentID"); |
|||
if (parentRouteId.equals(routeParentId)) { |
|||
ElementTreeNode elementTreeNode = this.buildRouteTreeNode(route); |
|||
parentMode.getChildren().add(elementTreeNode); |
|||
this.recursionTransRouteTree(elementTreeNode, routeList); |
|||
} |
|||
} |
|||
if (CollectionUtils.isEmpty(parentMode.getChildren())) { |
|||
parentMode.setLeaf(true); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private ElementTreeNode buildRouteTreeNode(JSONObject route) { |
|||
if (null == route) { |
|||
return null; |
|||
} |
|||
ElementTreeNode node = new ElementTreeNode(); |
|||
node.setValue(route.getLong("RouteID")); |
|||
node.setLabel(route.getString("RouteName")); |
|||
node.setChildren(new ArrayList<>()); |
|||
return node; |
|||
} |
|||
} |
@ -0,0 +1,57 @@ |
|||
<?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.lzbi.patrol.mapper.DcBusiDeptPatrolRouteMapper"> |
|||
|
|||
<resultMap type="com.lzbi.patrol.domain.DcBusiDeptPatrolRoute" id="DcBusiDeptPatrolRouteResult"> |
|||
<result property="deptId" column="dept_id" /> |
|||
<result property="routeId" column="route_id" /> |
|||
</resultMap> |
|||
|
|||
<sql id="selectDcBusiDeptPatrolRouteVo"> |
|||
select dept_id, route_id from dc_busi_dept_patrol_route |
|||
</sql> |
|||
|
|||
<select id="selectDcBusiDeptPatrolRouteList" parameterType="DcBusiDeptPatrolRoute" resultMap="DcBusiDeptPatrolRouteResult"> |
|||
<include refid="selectDcBusiDeptPatrolRouteVo"/> |
|||
<where> |
|||
</where> |
|||
</select> |
|||
|
|||
<select id="selectDcBusiDeptPatrolRouteByDeptId" parameterType="Long" resultMap="DcBusiDeptPatrolRouteResult"> |
|||
<include refid="selectDcBusiDeptPatrolRouteVo"/> |
|||
where dept_id = #{deptId} |
|||
</select> |
|||
|
|||
<insert id="insertDcBusiDeptPatrolRoute" parameterType="DcBusiDeptPatrolRoute"> |
|||
insert into dc_busi_dept_patrol_route |
|||
<trim prefix="(" suffix=")" suffixOverrides=","> |
|||
<if test="deptId != null">dept_id,</if> |
|||
<if test="routeId != null">route_id,</if> |
|||
</trim> |
|||
<trim prefix="values (" suffix=")" suffixOverrides=","> |
|||
<if test="deptId != null">#{deptId},</if> |
|||
<if test="routeId != null">#{routeId},</if> |
|||
</trim> |
|||
</insert> |
|||
|
|||
<update id="updateDcBusiDeptPatrolRoute" parameterType="DcBusiDeptPatrolRoute"> |
|||
update dc_busi_dept_patrol_route |
|||
<trim prefix="SET" suffixOverrides=","> |
|||
<if test="routeId != null">route_id = #{routeId},</if> |
|||
</trim> |
|||
where dept_id = #{deptId} |
|||
</update> |
|||
|
|||
<delete id="deleteDcBusiDeptPatrolRouteByDeptId" parameterType="Long"> |
|||
delete from dc_busi_dept_patrol_route where dept_id = #{deptId} |
|||
</delete> |
|||
|
|||
<delete id="deleteDcBusiDeptPatrolRouteByDeptIds" parameterType="String"> |
|||
delete from dc_busi_dept_patrol_route where dept_id in |
|||
<foreach item="deptId" collection="array" open="(" separator="," close=")"> |
|||
#{deptId} |
|||
</foreach> |
|||
</delete> |
|||
</mapper> |
Loading…
Reference in new issue