Merge remote-tracking branch 'origin/server_five_xiaoyao' into server_five_dongxiaodong
# Conflicts: # couplet-modules/couplet-analyze/couplet-analyze-msg/pom.xml # couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/resources/bootstrap.ymlserver_five_liuyunhu
commit
99dc4e832f
|
@ -35,7 +35,6 @@ public interface RemoteDeptService {
|
||||||
@GetMapping("/getSysDeptByDeptId/{deptId}")
|
@GetMapping("/getSysDeptByDeptId/{deptId}")
|
||||||
public Result<List<SysDept>> getSysDeptByDeptId(@PathVariable(value = "deptId") Long deptId);
|
public Result<List<SysDept>> getSysDeptByDeptId(@PathVariable(value = "deptId") Long deptId);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @param dept:
|
* @param dept:
|
||||||
* @return Result
|
* @return Result
|
||||||
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
package com.couplet.common.system.remote;
|
||||||
|
|
||||||
|
import com.couplet.common.core.constant.ServiceNameConstants;
|
||||||
|
import com.couplet.common.core.domain.Result;
|
||||||
|
import com.couplet.common.core.web.page.TableDataInfo;
|
||||||
|
import com.couplet.common.system.domain.SysUser;
|
||||||
|
import com.couplet.common.system.remote.factory.RemoteEmployeeFallbackFactory;
|
||||||
|
import lombok.extern.java.Log;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param null:
|
||||||
|
* @return null
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 远程调用用户服务
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
|
@FeignClient(contextId = "remoteEmployeeService",
|
||||||
|
value = ServiceNameConstants.SYSTEM_SERVICE,
|
||||||
|
fallbackFactory = RemoteEmployeeFallbackFactory.class,
|
||||||
|
path = "/user")
|
||||||
|
public interface RemoteEmployeeService {
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param user:
|
||||||
|
* @return Result<TableDataInfo<SysUser>>
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 调用用户列表
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
|
@PostMapping("/list")
|
||||||
|
public Result<TableDataInfo<SysUser>> list (SysUser user);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param user:
|
||||||
|
* @return Result
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 添加用户管理
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
|
@PostMapping
|
||||||
|
public Result add (@Validated @RequestBody SysUser user);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param user:
|
||||||
|
* @return Result
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 修改用户
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
|
@PutMapping
|
||||||
|
public Result edit (@Validated @RequestBody SysUser user);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param userIds:
|
||||||
|
* @return Result
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 删除用户
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/{userIds}")
|
||||||
|
public Result remove (@PathVariable(value = "userIds") Long[] userIds);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param null:
|
||||||
|
* @return null
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description X修改用户状态
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
|
@PutMapping("/changeStatus")
|
||||||
|
public Result changeStatus (@RequestBody SysUser user);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param deptId:
|
||||||
|
* @return Result<List<SysUser>>
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 根据deptId获取企业下有那些员工
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
|
@PostMapping("userList/{deptId}")
|
||||||
|
public Result<List<SysUser>> userList(@PathVariable(value = "deptId") Long deptId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -11,7 +11,7 @@ import java.util.List;
|
||||||
/**
|
/**
|
||||||
* @author fufanrui
|
* @author fufanrui
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @description: TODO
|
* @description: 企业服务降级处理
|
||||||
* @date 2024/3/27 15:29
|
* @date 2024/3/27 15:29
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ -30,7 +30,6 @@ public class RemoteDeptFallbackFactory implements FallbackFactory<RemoteDeptServ
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据企业ID获取企业下部门
|
* 根据企业ID获取企业下部门
|
||||||
*
|
*
|
||||||
|
@ -41,6 +40,7 @@ public class RemoteDeptFallbackFactory implements FallbackFactory<RemoteDeptServ
|
||||||
public Result<List<SysDept>> getSysDeptByDeptId(Long deptId) {
|
public Result<List<SysDept>> getSysDeptByDeptId(Long deptId) {
|
||||||
return Result.error("调用失败...."+cause.getMessage());
|
return Result.error("调用失败...."+cause.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @param cause:
|
* @param cause:
|
||||||
* @return RemoteDeptService
|
* @return RemoteDeptService
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
package com.couplet.common.system.remote.factory;
|
||||||
|
|
||||||
|
import com.couplet.common.core.domain.Result;
|
||||||
|
import com.couplet.common.core.web.page.TableDataInfo;
|
||||||
|
import com.couplet.common.system.domain.SysUser;
|
||||||
|
import com.couplet.common.system.remote.RemoteEmployeeService;
|
||||||
|
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fufanrui
|
||||||
|
* @version 1.0
|
||||||
|
* @description: 员工服务降级处理
|
||||||
|
* @date 2024/3/31 19:43
|
||||||
|
*/
|
||||||
|
public class RemoteEmployeeFallbackFactory implements FallbackFactory<RemoteEmployeeService> {
|
||||||
|
@Override
|
||||||
|
public RemoteEmployeeService create(Throwable cause) {
|
||||||
|
return new RemoteEmployeeService() {
|
||||||
|
/*
|
||||||
|
* @param user:
|
||||||
|
* @return Result<TableDataInfo<SysUser>>
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 员工列表
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Result<TableDataInfo<SysUser>> list(SysUser user) {
|
||||||
|
return Result.error("调用失败"+cause.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result add(SysUser user) {
|
||||||
|
return Result.error("调用失败"+cause.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result edit(SysUser user) {
|
||||||
|
return Result.error("调用失败"+cause.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result remove(Long[] userIds) {
|
||||||
|
return Result.error("调用失败"+cause.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result changeStatus(SysUser user) {
|
||||||
|
return Result.error("调用失败"+cause.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<List<SysUser>> userList(Long deptId) {
|
||||||
|
return Result.error("调用失败...."+cause.getMessage());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,3 +2,4 @@ com.couplet.common.system.remote.factory.RemoteUserFallbackFactory
|
||||||
com.couplet.common.system.remote.factory.RemoteLogFallbackFactory
|
com.couplet.common.system.remote.factory.RemoteLogFallbackFactory
|
||||||
com.couplet.common.system.remote.factory.RemoteFileFallbackFactory
|
com.couplet.common.system.remote.factory.RemoteFileFallbackFactory
|
||||||
com.couplet.common.system.remote.factory.RemoteDeptFallbackFactory
|
com.couplet.common.system.remote.factory.RemoteDeptFallbackFactory
|
||||||
|
com.couplet.common.system.remote.factory.RemoteEmployeeFallbackFactory
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>com.couplet</groupId>
|
|
||||||
<artifactId>couplet-analyze</artifactId>
|
|
||||||
<version>3.6.3</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<artifactId>couplet-analyze-incident</artifactId>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
</project>
|
|
|
@ -86,6 +86,13 @@
|
||||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||||
<version>1.2.5</version>
|
<version>1.2.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- RabbitMQ依赖-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.couplet.analyze.msg.config;
|
||||||
|
|
||||||
|
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||||
|
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class RabbitAdminConfig {
|
||||||
|
|
||||||
|
@Value("${spring.rabbitmq.host}")
|
||||||
|
private String host;
|
||||||
|
@Value("${spring.rabbitmq.username}")
|
||||||
|
private String username;
|
||||||
|
@Value("${spring.rabbitmq.password}")
|
||||||
|
private String password;
|
||||||
|
@Value("${spring.rabbitmq.virtualhost}")
|
||||||
|
private String virtualhost;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建RabbitMQ的连接工厂
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public ConnectionFactory connectionFactory() {
|
||||||
|
CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
|
||||||
|
connectionFactory.setAddresses(host);
|
||||||
|
connectionFactory.setUsername(username);
|
||||||
|
connectionFactory.setPassword(password);
|
||||||
|
connectionFactory.setVirtualHost(virtualhost);
|
||||||
|
return connectionFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化RabbitAdmin
|
||||||
|
* @param connectionFactory
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
|
||||||
|
RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
|
||||||
|
rabbitAdmin.setAutoStartup(true);
|
||||||
|
return rabbitAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,96 @@
|
||||||
|
package com.couplet.analyze.msg.consumer;
|
||||||
|
|
||||||
|
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
|
import com.couplet.analyze.msg.service.IncidentService;
|
||||||
|
import com.couplet.common.core.utils.SpringUtils;
|
||||||
|
import com.rabbitmq.client.Channel;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.amqp.core.Message;
|
||||||
|
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
||||||
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/2
|
||||||
|
* @Description: 消费传输过来的数据
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Log4j2
|
||||||
|
@RabbitListener(queues = "couplet-msg-queue")
|
||||||
|
public class IncidentConsumer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用事件服务接口
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private IncidentService incidentService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StringRedisTemplate redis;
|
||||||
|
|
||||||
|
static ArrayList<String> strings = new ArrayList<>(){
|
||||||
|
{
|
||||||
|
add("breakdown");
|
||||||
|
add("electronic-fence");
|
||||||
|
add("real-time-data");
|
||||||
|
add("stored-event");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@RabbitHandler
|
||||||
|
public void incidentConsumer(List<CoupletMsgData> list, Channel channel, Message message) throws IOException {
|
||||||
|
|
||||||
|
log.info("消费者收到的消息是:【{}】",list);
|
||||||
|
|
||||||
|
long deliveryTag = message.getMessageProperties().getDeliveryTag();
|
||||||
|
String messageId = message.getMessageProperties().getMessageId();
|
||||||
|
|
||||||
|
if (redis.hasKey("解析系统value:"+messageId)){
|
||||||
|
redis.opsForValue().set("解析系统value:"+messageId,deliveryTag+"",5, TimeUnit.MINUTES);
|
||||||
|
}
|
||||||
|
Long add = redis.opsForSet().add("解析系统:set" + messageId,messageId);
|
||||||
|
redis.expire("解析系统:set"+messageId,5,TimeUnit.MINUTES);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (0 < add){
|
||||||
|
log.info("消费者开始消费,消费者收到消息是:【{ }】"+list);
|
||||||
|
for (CoupletMsgData coupletMsgData : list) {
|
||||||
|
for (String string : strings) {
|
||||||
|
CoupletMsgData bean = SpringUtils.getBean(string);
|
||||||
|
incidentService.incident(coupletMsgData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
channel.basicAck(deliveryTag,false);
|
||||||
|
} else {
|
||||||
|
//重复消费
|
||||||
|
log.error("重复消费");
|
||||||
|
//拒绝消费
|
||||||
|
channel.basicReject(deliveryTag, false);
|
||||||
|
|
||||||
|
//删除缓存
|
||||||
|
redis.opsForSet().remove("解析系统:set"+messageId, messageId);
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("消息消费失败...消息信息为:【{ }】", list);
|
||||||
|
String s = redis.opsForValue().get("解析系统value:" + messageId);
|
||||||
|
Long o = Long.parseLong( s );
|
||||||
|
if (deliveryTag == o+2){
|
||||||
|
log.error("队列无法进入了,消息是:【{}】",list);
|
||||||
|
channel.basicNack(deliveryTag,false,false);
|
||||||
|
} else {
|
||||||
|
log.info("再一次进入队列,消息是:[{}]", list);
|
||||||
|
channel.basicNack(deliveryTag,false,true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.couplet.analyze.msg.controller;
|
||||||
|
|
||||||
|
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
|
import com.couplet.analyze.msg.service.IncidentService;
|
||||||
|
import com.couplet.common.core.domain.Result;
|
||||||
|
import com.couplet.common.core.web.controller.BaseController;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
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 java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/2
|
||||||
|
* 事件控制器
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/incident")
|
||||||
|
public class IncidentController extends BaseController {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 事件服务
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private IncidentService incidentService;
|
||||||
|
|
||||||
|
}
|
|
@ -260,4 +260,8 @@ public class CoupletMsgData {
|
||||||
* CHG(充电机)状态 1:正常 0:故障
|
* CHG(充电机)状态 1:正常 0:故障
|
||||||
*/
|
*/
|
||||||
private int chgStatus;
|
private int chgStatus;
|
||||||
|
|
||||||
|
public CoupletMsgData(String s) {
|
||||||
|
this.vin = s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.couplet.analyze.msg.mapper;
|
||||||
|
|
||||||
|
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/2
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface IncidentMapper {
|
||||||
|
/**
|
||||||
|
* 新增存储事件
|
||||||
|
* @param coupletMsgData
|
||||||
|
*/
|
||||||
|
public void reportMapper(CoupletMsgData coupletMsgData);
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.couplet.analyze.msg.service;
|
||||||
|
|
||||||
|
import com.couplet.analyze.msg.contents.MsgContent;
|
||||||
|
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/2
|
||||||
|
* @Description: 事件系统接口
|
||||||
|
*/
|
||||||
|
public interface IncidentService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 事件分析
|
||||||
|
*
|
||||||
|
* @param coupletMsgData
|
||||||
|
*/
|
||||||
|
void incident(CoupletMsgData coupletMsgData);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取事件名称
|
||||||
|
* @return 事件名称
|
||||||
|
*/
|
||||||
|
String getName();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.couplet.analyze.msg.service.impl;
|
||||||
|
|
||||||
|
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
|
import com.couplet.analyze.msg.service.IncidentService;
|
||||||
|
import com.couplet.common.log.annotation.Log;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/2
|
||||||
|
* @Description: 故障事件
|
||||||
|
*/
|
||||||
|
@Service("breakdown")
|
||||||
|
@Log4j2
|
||||||
|
public class BreakdownServiceImpl implements IncidentService {
|
||||||
|
/**
|
||||||
|
* 故障事件
|
||||||
|
*
|
||||||
|
* @param coupletMsgData
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void incident(CoupletMsgData coupletMsgData) {
|
||||||
|
|
||||||
|
log.info("故障事件开始.....");
|
||||||
|
log.info("故障事件结束.....");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 获取事件名称
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "breakdown";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.couplet.analyze.msg.service.impl;
|
||||||
|
|
||||||
|
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
|
import com.couplet.analyze.msg.service.IncidentService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/2
|
||||||
|
* @Description: 电子围栏事件服务实现类
|
||||||
|
*/
|
||||||
|
@Service("electronic-fence")
|
||||||
|
public class ElectronicFenceServiceImpl implements IncidentService {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 电子围栏事件
|
||||||
|
*
|
||||||
|
* @param coupletMsgData
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void incident(CoupletMsgData coupletMsgData) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 电子围栏service 名称
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "electronic-fence";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.couplet.analyze.msg.service.impl;
|
||||||
|
|
||||||
|
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
|
import com.couplet.analyze.msg.service.IncidentService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/2
|
||||||
|
* @Description: 实时数据事件
|
||||||
|
*/
|
||||||
|
@Service("real-time-data")
|
||||||
|
public class RealTimeDataServiceImpl implements IncidentService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实时数据事件
|
||||||
|
*
|
||||||
|
* @param coupletMsgData
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void incident(CoupletMsgData coupletMsgData) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实时数据事件
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "real-time-data";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.couplet.analyze.msg.service.impl;
|
||||||
|
|
||||||
|
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
|
import com.couplet.analyze.msg.mapper.IncidentMapper;
|
||||||
|
import com.couplet.analyze.msg.service.IncidentService;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/2
|
||||||
|
* @Description: 事件存储服务
|
||||||
|
*/
|
||||||
|
@Service("stored-event")
|
||||||
|
@Log4j2
|
||||||
|
public class StoredEventServiceImpl implements IncidentService {
|
||||||
|
@Autowired
|
||||||
|
private IncidentMapper incidentMapper;
|
||||||
|
/**
|
||||||
|
* 事件存储服务
|
||||||
|
*
|
||||||
|
* @param coupletMsgData
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void incident(CoupletMsgData coupletMsgData) {
|
||||||
|
|
||||||
|
log.info("开始存储......");
|
||||||
|
incidentMapper.reportMapper(coupletMsgData);
|
||||||
|
log.info("结束存储......");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 事件存储服务
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "stored-event";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
package com.couplet.analyze.msg.utils;
|
||||||
|
|
||||||
|
import org.springframework.amqp.core.Binding;
|
||||||
|
import org.springframework.amqp.core.BindingBuilder;
|
||||||
|
import org.springframework.amqp.core.DirectExchange;
|
||||||
|
import org.springframework.amqp.core.Queue;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DLXQueueUtil {
|
||||||
|
// routingKey
|
||||||
|
private static final String DEAD_ROUTING_KEY = "dead.routingkey";
|
||||||
|
private static final String ROUTING_KEY = "routingkey";
|
||||||
|
private static final String DEAD_EXCHANGE = "dead.exchange";
|
||||||
|
private static final String EXCHANGE = "common.exchange";
|
||||||
|
@Autowired
|
||||||
|
RabbitTemplate rabbitTemplate;
|
||||||
|
@Resource
|
||||||
|
RabbitAdmin rabbitAdmin;
|
||||||
|
/**
|
||||||
|
* 发送死信队列,过期后进入死信交换机,进入死信队列
|
||||||
|
* @param queueName 队列名称
|
||||||
|
* @param deadQueueName 死信队列名称
|
||||||
|
* @param params 消息内容
|
||||||
|
* @param expiration 过期时间 毫秒
|
||||||
|
*/
|
||||||
|
public void sendDLXQueue(String queueName, String deadQueueName, Object params, Integer expiration){
|
||||||
|
/**
|
||||||
|
* ----------------------------------先创建一个ttl队列和死信队列--------------------------------------------
|
||||||
|
*/
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
// 队列设置存活时间,单位ms, 必须是整形数据。
|
||||||
|
map.put("x-message-ttl",expiration);
|
||||||
|
// 设置死信交换机
|
||||||
|
map.put("x-dead-letter-exchange",DEAD_EXCHANGE);
|
||||||
|
// 设置死信交换器路由
|
||||||
|
map.put("x-dead-letter-routing-key", DEAD_ROUTING_KEY);
|
||||||
|
/*参数1:队列名称 参数2:持久化 参数3:是否排他 参数4:自动删除队列 参数5:队列参数*/
|
||||||
|
Queue queue = new Queue(queueName, true, false, false, map);
|
||||||
|
rabbitAdmin.declareQueue(queue);
|
||||||
|
/**
|
||||||
|
* ---------------------------------创建交换机---------------------------------------------
|
||||||
|
*/
|
||||||
|
DirectExchange directExchange = new DirectExchange(EXCHANGE, true, false);
|
||||||
|
rabbitAdmin.declareExchange(directExchange);
|
||||||
|
/**
|
||||||
|
* ---------------------------------队列绑定交换机---------------------------------------------
|
||||||
|
*/
|
||||||
|
Binding binding = BindingBuilder.bind(queue).to(directExchange).with(ROUTING_KEY);
|
||||||
|
rabbitAdmin.declareBinding(binding);
|
||||||
|
/**
|
||||||
|
* ---------------------------------在创建一个死信交换机和队列,接收死信队列---------------------------------------------
|
||||||
|
*/
|
||||||
|
DirectExchange deadExchange = new DirectExchange(DEAD_EXCHANGE, true, false);
|
||||||
|
rabbitAdmin.declareExchange(deadExchange);
|
||||||
|
|
||||||
|
Queue deadQueue = new Queue(deadQueueName,true,false,false);
|
||||||
|
rabbitAdmin.declareQueue(deadQueue);
|
||||||
|
/**
|
||||||
|
* ---------------------------------队列绑定死信交换机---------------------------------------------
|
||||||
|
*/
|
||||||
|
// 将队列和交换机绑定
|
||||||
|
Binding deadbinding = BindingBuilder.bind(deadQueue).to(deadExchange).with(DEAD_ROUTING_KEY);
|
||||||
|
rabbitAdmin.declareBinding(deadbinding);
|
||||||
|
// 发送消息
|
||||||
|
rabbitTemplate.convertAndSend(EXCHANGE,ROUTING_KEY,params);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
package com.couplet.analyze.msg.utils;
|
||||||
|
|
||||||
|
import org.springframework.amqp.AmqpException;
|
||||||
|
import org.springframework.amqp.core.*;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DelayedQueueUtil {
|
||||||
|
// routingKey
|
||||||
|
private static final String DELAYED_ROUTING_KEY = "delayed.routingkey";
|
||||||
|
|
||||||
|
// 延迟队列交换机
|
||||||
|
private static final String DELAYED_EXCHANGE = "delayed.exchange";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
RabbitAdmin rabbitAdmin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送延迟队列
|
||||||
|
*
|
||||||
|
* @param queueName 队列名称
|
||||||
|
* @param params 消息内容
|
||||||
|
* @param expiration 延迟时间 毫秒
|
||||||
|
*/
|
||||||
|
public void sendDelayedQueue(String queueName, Object params, Integer expiration) {
|
||||||
|
// 先创建一个队列
|
||||||
|
Queue queue = new Queue(queueName);
|
||||||
|
rabbitAdmin.declareQueue(queue);
|
||||||
|
// 创建延迟队列交换机
|
||||||
|
CustomExchange customExchange = createCustomExchange();
|
||||||
|
rabbitAdmin.declareExchange(customExchange);
|
||||||
|
// 将队列和交换机绑定
|
||||||
|
Binding binding = BindingBuilder.bind(queue).to(customExchange).with(DELAYED_ROUTING_KEY).noargs();
|
||||||
|
rabbitAdmin.declareBinding(binding);
|
||||||
|
// 发送延迟消息
|
||||||
|
rabbitTemplate.convertAndSend(DELAYED_EXCHANGE, DELAYED_ROUTING_KEY, params, message -> {
|
||||||
|
message.getMessageProperties().setDelay(expiration);
|
||||||
|
return message;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomExchange createCustomExchange() {
|
||||||
|
Map<String, Object> arguments = new HashMap<>();
|
||||||
|
/**
|
||||||
|
* 参数说明:
|
||||||
|
* 1.交换机的名称
|
||||||
|
* 2.交换机的类型
|
||||||
|
* 3.是否需要持久化
|
||||||
|
* 4.是否自动删除
|
||||||
|
* 5.其它参数
|
||||||
|
*/
|
||||||
|
arguments.put("x-delayed-type", "direct");
|
||||||
|
return new CustomExchange(DELAYED_EXCHANGE, "x-delayed-message", true, false, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,118 @@
|
||||||
|
package com.couplet.analyze.msg.utils;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.eclipse.paho.client.mqttv3.*;
|
||||||
|
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ProjectName: five-groups-couplet
|
||||||
|
* @Author: LiuYunHu
|
||||||
|
* @CreateTime: 2024/4/1
|
||||||
|
* @Description: mqtt监听者
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class MqttMonitor {
|
||||||
|
/*
|
||||||
|
* 路径
|
||||||
|
* */
|
||||||
|
@Value("${mqtt.server.broker}")
|
||||||
|
private String broker;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 主题
|
||||||
|
* */
|
||||||
|
@Value("${mqtt.server.topic}")
|
||||||
|
private String topic;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 客户端id
|
||||||
|
* */
|
||||||
|
@Value("${mqtt.server.clientId}")
|
||||||
|
private String clientId;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 用户名
|
||||||
|
* */
|
||||||
|
@Value("${mqtt.server.username}")
|
||||||
|
private String userName;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 密码
|
||||||
|
* */
|
||||||
|
@Value("${mqtt.server.password}")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 遗嘱消息qos
|
||||||
|
* */
|
||||||
|
@Value("${mqtt.server.qos}")
|
||||||
|
private Integer qos;
|
||||||
|
|
||||||
|
|
||||||
|
//随项目启动而执行这个方法
|
||||||
|
@PostConstruct
|
||||||
|
public void connect() {
|
||||||
|
log.info("mqtt监听者启动");
|
||||||
|
try {
|
||||||
|
MqttClient client = new MqttClient(broker, clientId, new MemoryPersistence());
|
||||||
|
|
||||||
|
MqttConnectOptions options = new MqttConnectOptions();
|
||||||
|
options.setUserName(userName);
|
||||||
|
options.setPassword(password.toCharArray());
|
||||||
|
|
||||||
|
//连接超时
|
||||||
|
options.setConnectionTimeout(10);
|
||||||
|
|
||||||
|
//心跳时间
|
||||||
|
options.setKeepAliveInterval(60);
|
||||||
|
|
||||||
|
log.info("mqtt监听者启动成功,连接到:{}", broker);
|
||||||
|
|
||||||
|
client.connect(options);
|
||||||
|
log.info("连接成功!");
|
||||||
|
|
||||||
|
//设置回调
|
||||||
|
client.setCallback(new MqttCallback() {
|
||||||
|
@Override
|
||||||
|
public void connectionLost(Throwable throwable) {
|
||||||
|
log.error("连接丢失:{}", throwable.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void messageArrived(String topic, MqttMessage mqttMessage) {
|
||||||
|
// log.info("消息已送达");
|
||||||
|
// log.info("接收消息主题:{}",topic);
|
||||||
|
// log.info("接收消息qos:{}", mqttMessage.getQos());
|
||||||
|
|
||||||
|
//接收到的原始报文
|
||||||
|
String message = new String(mqttMessage.getPayload());
|
||||||
|
|
||||||
|
log.info("接收消息原始内容:{}", message);
|
||||||
|
|
||||||
|
//去除空格 得到16进制字符串
|
||||||
|
String replaced = message.replaceAll(" ", "");
|
||||||
|
log.info("接收消息剪切后内容:{}", replaced);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
|
||||||
|
log.info("消息发送成功!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
client.subscribe(topic, qos);
|
||||||
|
|
||||||
|
|
||||||
|
} catch (MqttException e) {
|
||||||
|
log.error("mqtt监听者启动失败,{}", e.getMessage());
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
package com.couplet.analyze.msg.utils;
|
||||||
|
|
||||||
|
import org.springframework.amqp.core.*;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
@Component
|
||||||
|
public class TTLQueueUtil {
|
||||||
|
// routingKey
|
||||||
|
private static final String TTL_KEY = "ttl.routingkey";
|
||||||
|
private static final String TTL_EXCHANGE = "ttl.exchange";
|
||||||
|
@Autowired
|
||||||
|
RabbitTemplate rabbitTemplate;
|
||||||
|
@Resource
|
||||||
|
RabbitAdmin rabbitAdmin;
|
||||||
|
/**
|
||||||
|
* 发送TTL队列
|
||||||
|
* @param queueName 队列名称
|
||||||
|
* @param params 消息内容
|
||||||
|
* @param expiration 过期时间 毫秒
|
||||||
|
*/
|
||||||
|
public void sendTtlQueue(String queueName, Object params, Integer expiration) {
|
||||||
|
/**
|
||||||
|
* ----------------------------------先创建一个ttl队列--------------------------------------------
|
||||||
|
*/
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
// 队列设置存活时间,单位ms,必须是整形数据。
|
||||||
|
map.put("x-message-ttl",expiration);
|
||||||
|
/*参数1:队列名称 参数2:持久化 参数3:是否排他 参数4:自动删除队列 参数5:队列参数*/
|
||||||
|
Queue queue = new Queue(queueName,true,false,false,map);
|
||||||
|
rabbitAdmin.declareQueue(queue);
|
||||||
|
/**
|
||||||
|
* ---------------------------------创建交换机---------------------------------------------
|
||||||
|
*/
|
||||||
|
DirectExchange directExchange = new DirectExchange(TTL_EXCHANGE, true, false);
|
||||||
|
rabbitAdmin.declareExchange(directExchange);
|
||||||
|
/**
|
||||||
|
* ---------------------------------队列绑定交换机---------------------------------------------
|
||||||
|
*/
|
||||||
|
// 将队列和交换机绑定
|
||||||
|
Binding binding = BindingBuilder.bind(queue).to(directExchange).with(TTL_KEY);
|
||||||
|
rabbitAdmin.declareBinding(binding);
|
||||||
|
// 发送消息
|
||||||
|
rabbitTemplate.convertAndSend(TTL_EXCHANGE,TTL_KEY,params);
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,7 +29,10 @@ spring:
|
||||||
allow-bean-definition-overriding: true
|
allow-bean-definition-overriding: true
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
com.couplet.msg.mapper: DEBUG
|
com.couplet.analyze.msg.mapper: DEBUG
|
||||||
|
mybatis-plus:
|
||||||
|
configuration:
|
||||||
|
map-underscore-to-camel-case: true
|
||||||
# RabbitMQ配置
|
# RabbitMQ配置
|
||||||
#mq:
|
#mq:
|
||||||
# queueName: queue
|
# queueName: queue
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
<?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.couplet.analyze.msg.mapper.IncidentMapper">
|
||||||
|
|
||||||
|
|
||||||
|
<insert id="reportMapper">
|
||||||
|
INSERT INTO `vehicle-resolver`.`resolver_report_data`
|
||||||
|
(`vin`, `create_time`, `longitude`, `latitude`,
|
||||||
|
`speed`, `mileage`, `voltage`, `current`, `resistance`, `gear`,
|
||||||
|
`acceleration_pedal`, `fuel_consumption_rate`,
|
||||||
|
`motor_controller_temperature`, `motor_speed`,
|
||||||
|
`motor_torque`, `motor_temperature`, `motor_voltage`,
|
||||||
|
`motor_current`, `remaining_battery`, `maximum_feedback_power`,
|
||||||
|
`maximum_discharge_power`, `self_check_counter`,
|
||||||
|
`total_battery_current`, `total_battery_voltage`,
|
||||||
|
`single_battery_max_voltage`, `single_battery_min_voltage`,
|
||||||
|
`single_battery_max_temperature`, `single_battery_min_temperature`,
|
||||||
|
`available_battery_capacity`, `vehicle_status`, `charging_status`,
|
||||||
|
`operatingStatus`, `soc_status`, `charging_energy_storage_status`,
|
||||||
|
`drive_motor_status`, `position_status`, `eas_status`, `ptc_status`,
|
||||||
|
`eps_status`, `abs_status`, `mcu_status`, `heating_status`, `battery_status`,
|
||||||
|
`battery_insulation_status`, `dcdc_status`, `chg_status`, `brake_pedal`)
|
||||||
|
VALUES (#{vin},
|
||||||
|
#{createTime},
|
||||||
|
#{longitude},
|
||||||
|
#{latitude},
|
||||||
|
#{speed},
|
||||||
|
#{mileage},
|
||||||
|
#{voltage},
|
||||||
|
#{current},
|
||||||
|
#{resistance},
|
||||||
|
#{gear},
|
||||||
|
#{accelerationPedal},
|
||||||
|
#{fuelConsumptionRate},
|
||||||
|
#{motorControllerTemperature},
|
||||||
|
#{motorSpeed},
|
||||||
|
#{motorTorque},
|
||||||
|
#{motorTemperature},
|
||||||
|
#{motorVoltage},
|
||||||
|
#{motorCurrent},
|
||||||
|
#{remainingBattery},
|
||||||
|
#{maximumFeedbackPower},
|
||||||
|
#{maximumDischargePower},
|
||||||
|
#{selfCheckCounter},
|
||||||
|
#{totalBatteryCurrent},
|
||||||
|
#{totalBatteryVoltage},
|
||||||
|
#{singleBatteryMaxVoltage},
|
||||||
|
#{singleBatteryMinVoltage},
|
||||||
|
#{singleBatteryMaxTemperature},
|
||||||
|
#{singleBatteryMinTemperature},
|
||||||
|
#{availableBatteryCapacity},
|
||||||
|
#{vehicleStatus},
|
||||||
|
#{chargingStatus},
|
||||||
|
#{operatingStatus},
|
||||||
|
#{socStatus},
|
||||||
|
#{chargingEnergyStorageStatus},
|
||||||
|
#{driveMotorStatus},
|
||||||
|
#{positionStatus},
|
||||||
|
#{easStatus},
|
||||||
|
#{ptcStatus},
|
||||||
|
#{epsStatus},
|
||||||
|
#{absStatus},
|
||||||
|
#{mcuStatus},
|
||||||
|
#{heatingStatus},
|
||||||
|
#{batteryStatus},
|
||||||
|
#{batteryInsulationStatus},
|
||||||
|
#{dcdcStatus},
|
||||||
|
#{chgStatus},
|
||||||
|
#{brakePedal}
|
||||||
|
);
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
</mapper>
|
|
@ -0,0 +1,92 @@
|
||||||
|
package com.couplet.msg;
|
||||||
|
|
||||||
|
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
|
import com.couplet.analyze.msg.service.IncidentService;
|
||||||
|
import com.couplet.common.core.utils.SpringUtils;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/2
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
public class dome {
|
||||||
|
private static final List<String> msgList = new ArrayList<>(){{
|
||||||
|
add("7E 56 49 4e 31 32 33 34 35 36 37 38 39 44 49 4a 45 34 31 37 31 31 37 36 34 31 30 34 35 30 36 31 31 36 2e 36 36 34 33 38 30 30 33 39 2e 35 33 31 39 39 30 30 37 32 2e 30 30 30 33 31 2e 33 37 36 30 30 30 30 30 32 32 30 30 30 30 32 32 30 30 30 38 35 32 30 30 30 30 30 30 44 30 30 38 30 39 2e 36 30 30 39 34 30 30 30 30 35 38 39 30 36 36 37 39 30 39 33 30 30 30 30 32 30 33 30 30 32 30 33 30 30 30 30 30 34 34 32 38 32 2e 35 35 30 30 30 30 31 34 30 30 30 30 38 30 37 30 30 30 30 37 34 34 30 30 30 33 30 30 30 34 30 30 30 39 35 30 30 30 30 35 38 30 30 30 30 35 34 30 30 30 30 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 24 7E");
|
||||||
|
}};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 事件列表
|
||||||
|
*/
|
||||||
|
static List<String> list=new ArrayList<>(){
|
||||||
|
{
|
||||||
|
add("breakdown");
|
||||||
|
add("electronic-fence");
|
||||||
|
add("real-time-data");
|
||||||
|
add("stored-event");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static IncidentService incidentService;
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// 去头去尾
|
||||||
|
for (String string : msgList) {
|
||||||
|
String substring = string.substring(2, string.length() - 2);
|
||||||
|
System.out.println("去头去尾字符串:"+ substring);
|
||||||
|
|
||||||
|
String hexStringWithoutSpaces = substring.replaceAll("\\s+", "");
|
||||||
|
String asciiString = hexToString(hexStringWithoutSpaces);
|
||||||
|
System.out.println("16进制解析后的数据:"+asciiString);
|
||||||
|
// //截取前17位
|
||||||
|
String substring1 = asciiString.substring(0, 17);
|
||||||
|
System.out.println("VIN:"+substring1);
|
||||||
|
String substring2 = asciiString.substring(17, 30);
|
||||||
|
System.out.println("时间戳:"+substring2);
|
||||||
|
String substring3 = asciiString.substring(30, 40);
|
||||||
|
System.out.println("经度:" +substring3);
|
||||||
|
String substring4 = asciiString.substring(41, 50);
|
||||||
|
System.out.println("纬度:"+ substring4);
|
||||||
|
String substring5 = asciiString.substring(51, 56);
|
||||||
|
System.out.println("车速:"+ substring5);
|
||||||
|
String substring6 = asciiString.substring(57, 67);
|
||||||
|
System.out.println("总里程:"+ substring6);
|
||||||
|
String substring7 = asciiString.substring(68, 73);
|
||||||
|
System.out.println("总电压:"+ substring7);
|
||||||
|
String pattern = "(.{17})(.{10})(.{9})(.{8})(.{2})";
|
||||||
|
Pattern compile = Pattern.compile(pattern);
|
||||||
|
Matcher matcher = compile.matcher(asciiString);
|
||||||
|
if (matcher.find()) {
|
||||||
|
for (int i = 1; i < matcher.groupCount(); i++) {
|
||||||
|
System.out.println("Group "+ i + ":" + matcher.group(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CoupletMsgData coupletMsgData = new CoupletMsgData();
|
||||||
|
List<CoupletMsgData> objects = msgList.stream().map(CoupletMsgData::new).toList();
|
||||||
|
|
||||||
|
for (CoupletMsgData object : objects) {
|
||||||
|
//测试所有的事件
|
||||||
|
for (String s : list) {
|
||||||
|
IncidentService bean = SpringUtils.getBean(s);
|
||||||
|
|
||||||
|
incidentService.incident(object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
public static String hexToString(String hexString) {
|
||||||
|
StringBuilder asciiString = new StringBuilder();
|
||||||
|
for (int i = 0; i < hexString.length(); i += 2) {
|
||||||
|
String hex = hexString.substring(i, i + 2);
|
||||||
|
int decimal = Integer.parseInt(hex, 16);
|
||||||
|
asciiString.append((char) decimal);
|
||||||
|
}
|
||||||
|
return asciiString.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -12,7 +12,6 @@
|
||||||
<artifactId>couplet-analyze</artifactId>
|
<artifactId>couplet-analyze</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<modules>
|
<modules>
|
||||||
<module>couplet-analyze-incident</module>
|
|
||||||
<module>couplet-analyze-msg</module>
|
<module>couplet-analyze-msg</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
|
|
@ -52,9 +52,9 @@ public class FenceController extends BaseController {
|
||||||
@RequiresPermissions("couplet:fence:fenceAdd")
|
@RequiresPermissions("couplet:fence:fenceAdd")
|
||||||
@Log(title = "电子围栏新增",businessType = BusinessType.INSERT)
|
@Log(title = "电子围栏新增",businessType = BusinessType.INSERT)
|
||||||
public Result<?> fenceInsert(HttpServletRequest request, @RequestBody FenceRequest fenceRequest){
|
public Result<?> fenceInsert(HttpServletRequest request, @RequestBody FenceRequest fenceRequest){
|
||||||
if (!fenceService.checkFenceKeyUnique(fenceRequest.getFenceName())) {
|
// if (!fenceService.checkFenceKeyUnique(fenceRequest.getFenceName())) {
|
||||||
return error("新增参数'" + fenceRequest.getFenceName() + "'失败,参数键名已存在");
|
// return error("新增参数'" + fenceRequest.getFenceName() + "'失败,参数键名已存在");
|
||||||
}
|
// }
|
||||||
fenceService.fenceInsert(request,fenceRequest);
|
fenceService.fenceInsert(request,fenceRequest);
|
||||||
return Result.success("新增成功");
|
return Result.success("新增成功");
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,11 @@ public class FenAndLogoServiceImpl extends ServiceImpl<FenAndLogoMapper, Fence>
|
||||||
@Autowired
|
@Autowired
|
||||||
private StringRedisTemplate redisTemplate;
|
private StringRedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 业务实现:添加中间表
|
||||||
|
* @param fenceId
|
||||||
|
* @param logoIds
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void addBach(Integer fenceId, String[] logoIds) {
|
public void addBach(Integer fenceId, String[] logoIds) {
|
||||||
fenAndLogoMapper.addBach(fenceId,logoIds);
|
fenAndLogoMapper.addBach(fenceId,logoIds);
|
||||||
|
|
|
@ -52,14 +52,22 @@ public class FenceServiceImpl extends ServiceImpl<FenceMapper, Fence> implements
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 业务实现:添加围栏
|
||||||
|
* @param request
|
||||||
|
* @param fenceRequest
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void fenceInsert(HttpServletRequest request,FenceRequest fenceRequest) {
|
public void fenceInsert(HttpServletRequest request,FenceRequest fenceRequest) {
|
||||||
|
|
||||||
|
//先添加围栏
|
||||||
int a= fenceMapper.insertFence(fenceRequest);
|
int a= fenceMapper.insertFence(fenceRequest);
|
||||||
String[] logoIds = fenceRequest.getLogoIds();
|
String[] logoIds = fenceRequest.getLogoIds();
|
||||||
String[] parts = new String[0];
|
String[] parts = new String[0];
|
||||||
for (String logoId : logoIds) {
|
for (String logoId : logoIds) {
|
||||||
|
//把前台传入的字符串分割成数组
|
||||||
parts = logoId.split(",");
|
parts = logoId.split(",");
|
||||||
|
//再添加围栏和标识中间表
|
||||||
fenAndLogoService.addBach(fenceRequest.getFenceId(),parts);
|
fenAndLogoService.addBach(fenceRequest.getFenceId(),parts);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,9 @@ spring:
|
||||||
discovery:
|
discovery:
|
||||||
# 服务注册地址
|
# 服务注册地址
|
||||||
server-addr: 121.89.211.230:8848
|
server-addr: 121.89.211.230:8848
|
||||||
namespace: 172469
|
|
||||||
config:
|
config:
|
||||||
# 配置中心地址
|
# 配置中心地址
|
||||||
server-addr: 121.89.211.230:8848
|
server-addr: 121.89.211.230:8848
|
||||||
namespace: 172469
|
|
||||||
# 配置文件格式
|
# 配置文件格式
|
||||||
file-extension: yml
|
file-extension: yml
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
|
|
@ -0,0 +1,96 @@
|
||||||
|
package com.couplet.server.controller;
|
||||||
|
|
||||||
|
import com.couplet.common.core.domain.Result;
|
||||||
|
import com.couplet.common.core.web.controller.BaseController;
|
||||||
|
import com.couplet.common.core.web.page.TableDataInfo;
|
||||||
|
import com.couplet.common.security.annotation.RequiresPermissions;
|
||||||
|
import com.couplet.common.system.domain.SysUser;
|
||||||
|
import com.couplet.server.service.EmployeeService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.couplet.common.core.utils.PageUtils.startPage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fufanrui
|
||||||
|
* @version 1.0
|
||||||
|
* @description: 员工管理控制器
|
||||||
|
* @date 2024/3/31 19:41
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("employee")
|
||||||
|
public class EmployeeController extends BaseController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EmployeeService employeeservice;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param user:
|
||||||
|
* @return Result<List<SysUser>>
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 员工列表
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
|
@RequiresPermissions("system:user:list")
|
||||||
|
@PostMapping("employeeList")
|
||||||
|
public Result<TableDataInfo<SysUser>> userList (SysUser user){
|
||||||
|
startPage();
|
||||||
|
List<SysUser> list = employeeservice.userList(user);
|
||||||
|
return getDataTable(list);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* @param user:
|
||||||
|
* @return Result
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 添加员工
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
|
@PostMapping
|
||||||
|
@RequiresPermissions("system:user:add")
|
||||||
|
public Result insert (@RequestBody SysUser user) {
|
||||||
|
return employeeservice.insert(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param user:
|
||||||
|
* @return Result
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 修改员工
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
|
@RequiresPermissions("system:user:edit")
|
||||||
|
@PutMapping
|
||||||
|
public Result edit (@RequestBody SysUser user) {
|
||||||
|
return employeeservice.deit(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param userIds:
|
||||||
|
* @return Result
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 删除员工
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
|
@RequiresPermissions("system:user:remove")
|
||||||
|
@DeleteMapping("/{userIds}")
|
||||||
|
public Result remove (@PathVariable(value = "userIds") Long[] userIds) {
|
||||||
|
return employeeservice.remove(userIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param user:
|
||||||
|
* @return Result
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 修改员工状态
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
|
@RequiresPermissions("system:user:edit")
|
||||||
|
@PutMapping("/changeStatus")
|
||||||
|
public Result changeStatus(@RequestBody SysUser user){
|
||||||
|
return employeeservice.changeStatus(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -28,7 +28,7 @@ public class ManageController {
|
||||||
* @description 登入后获取到企业下的所有部门
|
* @description 登入后获取到企业下的所有部门
|
||||||
* @date
|
* @date
|
||||||
*/
|
*/
|
||||||
@GetMapping("manageList")
|
@PostMapping("manageList")
|
||||||
@RequiresPermissions("system:dept:list")
|
@RequiresPermissions("system:dept:list")
|
||||||
public Result<List<SysDept>> manageList() {
|
public Result<List<SysDept>> manageList() {
|
||||||
List<SysDept> sysDepts = manageServer.selectDeptList();
|
List<SysDept> sysDepts = manageServer.selectDeptList();
|
||||||
|
@ -51,6 +51,13 @@ public class ManageController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param sysDept:
|
||||||
|
* @return Result
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 修改企业部门信息
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
@RequiresPermissions("system:dept:edit")
|
@RequiresPermissions("system:dept:edit")
|
||||||
@Log(title = "部门管理", businessType = BusinessType.UPDATE)
|
@Log(title = "部门管理", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping
|
@PutMapping
|
||||||
|
@ -58,6 +65,13 @@ public class ManageController {
|
||||||
return manageServer.manageEdit(sysDept);
|
return manageServer.manageEdit(sysDept);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param deptId:
|
||||||
|
* @return Result
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 删除部门信息
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
@RequiresPermissions("system:dept:remove")
|
@RequiresPermissions("system:dept:remove")
|
||||||
@Log(title = "部门管理", businessType = BusinessType.DELETE)
|
@Log(title = "部门管理", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/{deptId}")
|
@DeleteMapping("/{deptId}")
|
||||||
|
@ -71,6 +85,13 @@ public class ManageController {
|
||||||
// return manageServer.getSysDeptByDeptId(deptId);
|
// return manageServer.getSysDeptByDeptId(deptId);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param deptId:
|
||||||
|
* @return Result
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 根据deptId获取信息
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
@RequiresPermissions("system:dept:query")
|
@RequiresPermissions("system:dept:query")
|
||||||
@GetMapping(value = "/{deptId}")
|
@GetMapping(value = "/{deptId}")
|
||||||
public Result getInfo(@PathVariable Long deptId) {
|
public Result getInfo(@PathVariable Long deptId) {
|
||||||
|
@ -79,15 +100,16 @@ public class ManageController {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param deptId:
|
||||||
|
* @return Result
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 获取企业列表
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
@RequiresPermissions("system:dept:list")
|
@RequiresPermissions("system:dept:list")
|
||||||
@GetMapping("/list/exclude/{deptId}")
|
@GetMapping("/list/exclude/{deptId}")
|
||||||
public Result excludeChild(@PathVariable(value = "deptId") Long deptId) {
|
public Result excludeChild(@PathVariable(value = "deptId") Long deptId) {
|
||||||
return manageServer.excludeChild(deptId);
|
return manageServer.excludeChild(deptId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.couplet.server.service;
|
||||||
|
|
||||||
|
import com.couplet.common.core.domain.Result;
|
||||||
|
import com.couplet.common.core.web.page.TableDataInfo;
|
||||||
|
import com.couplet.common.system.domain.SysUser;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface EmployeeService {
|
||||||
|
TableDataInfo<SysUser> employeeList(SysUser user);
|
||||||
|
|
||||||
|
Result insert(SysUser user);
|
||||||
|
|
||||||
|
Result deit(SysUser user);
|
||||||
|
|
||||||
|
Result remove(Long[] userIds);
|
||||||
|
|
||||||
|
Result changeStatus(SysUser user);
|
||||||
|
|
||||||
|
List<SysUser> userList(SysUser user);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,106 @@
|
||||||
|
package com.couplet.server.service.impl;
|
||||||
|
|
||||||
|
import com.couplet.common.core.constant.SecurityConstants;
|
||||||
|
import com.couplet.common.core.domain.Result;
|
||||||
|
import com.couplet.common.core.web.page.TableDataInfo;
|
||||||
|
import com.couplet.common.security.utils.SecurityUtils;
|
||||||
|
import com.couplet.common.system.domain.LoginUser;
|
||||||
|
import com.couplet.common.system.domain.SysUser;
|
||||||
|
import com.couplet.common.system.remote.RemoteEmployeeService;
|
||||||
|
import com.couplet.common.system.remote.RemoteUserService;
|
||||||
|
import com.couplet.server.service.EmployeeService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fufanrui
|
||||||
|
* @version 1.0
|
||||||
|
* @description: 员工管理服务实现类
|
||||||
|
* @date 2024/3/31 19:42
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class EmployeeServiceImpl implements EmployeeService{
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RemoteEmployeeService remoteEmployeeService;
|
||||||
|
@Autowired
|
||||||
|
private RemoteUserService remoteUserService;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param null:
|
||||||
|
* @return null
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 员工列表
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TableDataInfo<SysUser> employeeList(SysUser user) {
|
||||||
|
Result<TableDataInfo<SysUser>> list = remoteEmployeeService.list(user);
|
||||||
|
TableDataInfo<SysUser> employeeList = list.getData();
|
||||||
|
return employeeList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param user:
|
||||||
|
* @return Result
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 添加员工
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Result insert(SysUser user) {
|
||||||
|
return remoteEmployeeService.add(user);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* @param user:
|
||||||
|
* @return Result
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 修改员工信息
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Result deit(SysUser user) {
|
||||||
|
return remoteEmployeeService.edit(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param userIds:
|
||||||
|
* @return Result
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 删除员工信息
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Result remove(Long[] userIds) {
|
||||||
|
return remoteEmployeeService.remove(userIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param user:
|
||||||
|
* @return Result
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 修改员工状态
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Result changeStatus(SysUser user) {
|
||||||
|
return remoteEmployeeService.changeStatus(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SysUser> userList(SysUser user) {
|
||||||
|
String username = SecurityUtils.getUsername();
|
||||||
|
Result<LoginUser> userInfo = remoteUserService.getUserInfo(username, SecurityConstants.FROM_SOURCE);
|
||||||
|
LoginUser data = userInfo.getData();
|
||||||
|
SysUser sysUser = data.getSysUser();
|
||||||
|
Long deptId = sysUser.getDeptId();
|
||||||
|
Result<List<SysUser>> listResult = remoteEmployeeService.userList(deptId);
|
||||||
|
List<SysUser> userList = listResult.getData();
|
||||||
|
return userList;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -29,42 +29,78 @@ public class ManageServiceImpl implements ManageServer{
|
||||||
@Autowired
|
@Autowired
|
||||||
private RemoteUserService remoteUserService;
|
private RemoteUserService remoteUserService;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param :
|
||||||
|
* @return List<SysDept>
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 企业管理列表
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<SysDept> selectDeptList() {
|
public List<SysDept> selectDeptList() {
|
||||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||||
String username = loginUser.getUsername();
|
Long deptId = loginUser.getSysUser().getDeptId();
|
||||||
Result<LoginUser> userInfo = remoteUserService.getUserInfo(username, SecurityConstants.FROM_SOURCE);
|
|
||||||
LoginUser user = userInfo.getData();
|
|
||||||
Long deptId = user.getDeptId();
|
|
||||||
Result<List<SysDept>> sysDeptByDeptId = remoteDeptService.getSysDeptByDeptId(deptId);
|
Result<List<SysDept>> sysDeptByDeptId = remoteDeptService.getSysDeptByDeptId(deptId);
|
||||||
List<SysDept> dept = sysDeptByDeptId.getData();
|
List<SysDept> dept = sysDeptByDeptId.getData();
|
||||||
return dept;
|
return dept;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param sysDept:
|
||||||
|
* @return Result
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 添加企业部门
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Result insertDept(SysDept sysDept) {
|
public Result insertDept(SysDept sysDept) {
|
||||||
|
|
||||||
return remoteDeptService.add(sysDept);
|
return remoteDeptService.add(sysDept);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param sysDept:
|
||||||
|
* @return Result
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 修改企业部门信息
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Result manageEdit(SysDept sysDept) {
|
public Result manageEdit(SysDept sysDept) {
|
||||||
return remoteDeptService.edit(sysDept);
|
return remoteDeptService.edit(sysDept);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param deptId:
|
||||||
|
* @return Result
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 删除企业部门信息
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Result manageRemove(Long deptId) {
|
public Result manageRemove(Long deptId) {
|
||||||
return remoteDeptService.remove(deptId);
|
return remoteDeptService.remove(deptId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param deptId:
|
||||||
|
* @return Result
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 获取企业信息
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Result getInfo(Long deptId) {
|
public Result getInfo(Long deptId) {
|
||||||
return remoteDeptService.getInfo(deptId);
|
return remoteDeptService.getInfo(deptId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param deptId:
|
||||||
|
* @return Result
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 获取企业部门
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Result excludeChild(Long deptId) {
|
public Result excludeChild(Long deptId) {
|
||||||
return remoteDeptService.excludeChild(deptId);
|
return remoteDeptService.excludeChild(deptId);
|
||||||
|
|
|
@ -1,20 +1,31 @@
|
||||||
package com.couplet.system.controller;
|
package com.couplet.system.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.couplet.common.core.constant.SecurityConstants;
|
||||||
import com.couplet.common.core.constant.UserConstants;
|
import com.couplet.common.core.constant.UserConstants;
|
||||||
import com.couplet.common.core.utils.StringUtils;
|
import com.couplet.common.core.utils.StringUtils;
|
||||||
import com.couplet.common.core.web.controller.BaseController;
|
import com.couplet.common.core.web.controller.BaseController;
|
||||||
import com.couplet.common.core.domain.Result;
|
import com.couplet.common.core.domain.Result;
|
||||||
|
import com.couplet.common.core.web.page.PageDomain;
|
||||||
|
import com.couplet.common.core.web.page.TableDataInfo;
|
||||||
|
import com.couplet.common.core.web.page.TableSupport;
|
||||||
import com.couplet.common.log.annotation.Log;
|
import com.couplet.common.log.annotation.Log;
|
||||||
import com.couplet.common.log.enums.BusinessType;
|
import com.couplet.common.log.enums.BusinessType;
|
||||||
import com.couplet.common.security.annotation.RequiresPermissions;
|
import com.couplet.common.security.annotation.RequiresPermissions;
|
||||||
import com.couplet.common.security.utils.SecurityUtils;
|
import com.couplet.common.security.utils.SecurityUtils;
|
||||||
|
import com.couplet.common.system.domain.LoginUser;
|
||||||
import com.couplet.common.system.domain.SysDept;
|
import com.couplet.common.system.domain.SysDept;
|
||||||
|
import com.couplet.common.system.remote.RemoteUserService;
|
||||||
import com.couplet.system.service.SysDeptService;
|
import com.couplet.system.service.SysDeptService;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.commons.math3.analysis.solvers.BrentSolver;
|
import org.apache.commons.math3.analysis.solvers.BrentSolver;
|
||||||
|
import org.apache.commons.math3.analysis.solvers.SecantSolver;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
/**
|
/**
|
||||||
* 部门信息
|
* 部门信息
|
||||||
|
@ -26,7 +37,8 @@ public class SysDeptController extends BaseController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysDeptService deptService;
|
private SysDeptService deptService;
|
||||||
|
@Autowired
|
||||||
|
private RemoteUserService remoteUserService;
|
||||||
/**
|
/**
|
||||||
* 获取部门列表
|
* 获取部门列表
|
||||||
*/
|
*/
|
||||||
|
@ -110,14 +122,13 @@ public class SysDeptController extends BaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据企业ID获取企业下部门
|
*
|
||||||
* @param deptId 企业ID
|
|
||||||
* @return 企业信息,内含有部门
|
|
||||||
*/
|
*/
|
||||||
@GetMapping("/getSysDeptByDeptId/{deptId}")
|
@GetMapping("/getSysDeptByDeptId/{deptId}")
|
||||||
public Result<List<SysDept>> getSysDeptByDeptId(@PathVariable(value = "deptId") Long deptId){
|
public Result<List<SysDept>> getSysDeptByDeptId(@PathVariable(value = "deptId") Long deptId){
|
||||||
List<SysDept> sysDept = deptService.getSysDeptByDeptId(deptId);
|
List<SysDept> sysDepts = deptService.getSysDeptByDeptId(deptId);
|
||||||
Result<List<SysDept>> success = Result.success(sysDept);
|
Result<List<SysDept>> success = Result.success(sysDepts);
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class SysUserController extends BaseController {
|
||||||
* 获取用户列表
|
* 获取用户列表
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("system:user:list")
|
@RequiresPermissions("system:user:list")
|
||||||
@GetMapping("/list")
|
@PostMapping("/list")
|
||||||
public Result<TableDataInfo<SysUser>> list (SysUser user) {
|
public Result<TableDataInfo<SysUser>> list (SysUser user) {
|
||||||
startPage();
|
startPage();
|
||||||
List<SysUser> list = userService.selectUserList(user);
|
List<SysUser> list = userService.selectUserList(user);
|
||||||
|
@ -107,7 +107,7 @@ public class SysUserController extends BaseController {
|
||||||
// 权限集合
|
// 权限集合
|
||||||
Set<String> permissions = permissionService.getMenuPermission(sysUser);
|
Set<String> permissions = permissionService.getMenuPermission(sysUser);
|
||||||
// 查询企业信息
|
// 查询企业信息
|
||||||
Long deptId = deptService.selectDeptIdByLeader(sysUser.getUserName());
|
Long deptId = deptService.selectDeptIdByLeader(sysUser.getDept().getLeader());
|
||||||
LoginUser sysUserVo = new LoginUser();
|
LoginUser sysUserVo = new LoginUser();
|
||||||
sysUserVo.setSysUser(sysUser);
|
sysUserVo.setSysUser(sysUser);
|
||||||
sysUserVo.setRoles(roles);
|
sysUserVo.setRoles(roles);
|
||||||
|
@ -291,4 +291,19 @@ public class SysUserController extends BaseController {
|
||||||
public Result deptTree (SysDept dept) {
|
public Result deptTree (SysDept dept) {
|
||||||
return success(deptService.selectDeptTreeList(dept));
|
return success(deptService.selectDeptTreeList(dept));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param null:
|
||||||
|
* @return null
|
||||||
|
* @author 付凡芮
|
||||||
|
* @description 根据deptId获取企业下的员工
|
||||||
|
* @date
|
||||||
|
*/
|
||||||
|
@PostMapping("userList/{deptId}")
|
||||||
|
public Result<List<SysUser>> userList(@PathVariable(value = "deptId") Long deptId){
|
||||||
|
List<SysUser> userList = userService.userList(deptId);
|
||||||
|
Result<List<SysUser>> success = Result.success(userList);
|
||||||
|
return success;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,7 @@ public interface SysDeptMapper extends BaseMapper<SysDept> {
|
||||||
*/
|
*/
|
||||||
public int deleteDeptById (Long deptId);
|
public int deleteDeptById (Long deptId);
|
||||||
|
|
||||||
SysDept selectDeptIdByLeader(String userName);
|
List<SysDept> selectDeptIdByLeader(String userName);
|
||||||
|
|
||||||
List<SysDept> getSysDeptByDeptId(Long deptId);
|
List<SysDept> getSysDeptByDeptId(Long deptId);
|
||||||
|
|
||||||
|
|
|
@ -139,4 +139,6 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public SysUser checkEmailUnique (String email);
|
public SysUser checkEmailUnique (String email);
|
||||||
|
|
||||||
|
List<SysUser> userList(Long deptId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.couplet.system.service;
|
package com.couplet.system.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.couplet.common.core.web.page.TableDataInfo;
|
||||||
import com.couplet.common.system.domain.SysDept;
|
import com.couplet.common.system.domain.SysDept;
|
||||||
import com.couplet.system.domain.vo.TreeSelect;
|
import com.couplet.system.domain.vo.TreeSelect;
|
||||||
|
|
||||||
|
@ -138,15 +139,17 @@ public interface SysDeptService extends IService<SysDept> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过负责人查询企业ID
|
* 通过负责人查询企业ID
|
||||||
* @param userName 负责人
|
* @param leader 负责人
|
||||||
* @return 企业ID
|
* @return 企业ID
|
||||||
*/
|
*/
|
||||||
Long selectDeptIdByLeader (String userName);
|
Long selectDeptIdByLeader(String leader);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据企业ID获取企业下部门
|
* 根据企业ID获取企业下部门
|
||||||
* @param deptId 企业ID
|
* @param deptId 企业ID
|
||||||
* @return 企业信息,内含有部门
|
* @return 企业信息,内含有部门
|
||||||
*/
|
*/
|
||||||
List<SysDept> getSysDeptByDeptId(Long deptId);
|
List<SysDept> getSysDeptByDeptId(Long deptId);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,4 +225,6 @@ public interface SysUserService extends IService<SysUser> {
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public String importUser (List<SysUser> userList, Boolean isUpdateSupport, String operName);
|
public String importUser (List<SysUser> userList, Boolean isUpdateSupport, String operName);
|
||||||
|
|
||||||
|
List<SysUser> userList(Long deptId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import com.couplet.common.core.exception.ServiceException;
|
||||||
import com.couplet.common.core.text.Convert;
|
import com.couplet.common.core.text.Convert;
|
||||||
import com.couplet.common.core.utils.SpringUtils;
|
import com.couplet.common.core.utils.SpringUtils;
|
||||||
import com.couplet.common.core.utils.StringUtils;
|
import com.couplet.common.core.utils.StringUtils;
|
||||||
|
import com.couplet.common.core.web.page.TableDataInfo;
|
||||||
import com.couplet.common.datascope.annotation.DataScope;
|
import com.couplet.common.datascope.annotation.DataScope;
|
||||||
import com.couplet.common.security.utils.SecurityUtils;
|
import com.couplet.common.security.utils.SecurityUtils;
|
||||||
import com.couplet.common.system.domain.SysDept;
|
import com.couplet.common.system.domain.SysDept;
|
||||||
|
@ -284,16 +285,16 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||||
/**
|
/**
|
||||||
* 通过负责人查询企业ID
|
* 通过负责人查询企业ID
|
||||||
*
|
*
|
||||||
* @param userName 负责人
|
* @param leader 负责人
|
||||||
*
|
*
|
||||||
* @return 企业ID
|
* @return 企业ID
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Long selectDeptIdByLeader (String userName) {
|
public Long selectDeptIdByLeader (String leader) {
|
||||||
|
|
||||||
SysDept sysDept = deptMapper.selectDeptIdByLeader(userName);
|
List<SysDept> sysDept = deptMapper.selectDeptIdByLeader(leader);
|
||||||
|
Long deptId = sysDept.get(0).getDeptId();
|
||||||
return sysDept == null ? null : sysDept.getDeptId();
|
return sysDept == null ? null : deptId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -308,9 +309,9 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SysDept> getSysDeptByDeptId(Long deptId) {
|
public List<SysDept> getSysDeptByDeptId(Long deptId) {
|
||||||
|
|
||||||
return deptMapper.getSysDeptByDeptId(deptId);
|
return deptMapper.getSysDeptByDeptId(deptId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 递归列表
|
* 递归列表
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -502,4 +502,10 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||||
return successMsg.toString();
|
return successMsg.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SysUser> userList(Long deptId) {
|
||||||
|
|
||||||
|
return userMapper.userList(deptId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,7 @@ server:
|
||||||
|
|
||||||
# Spring
|
# Spring
|
||||||
spring:
|
spring:
|
||||||
main:
|
|
||||||
allow-bean-definition-overriding: true
|
|
||||||
application:
|
application:
|
||||||
# 应用名称
|
# 应用名称
|
||||||
name: couplet-system
|
name: couplet-system
|
||||||
|
|
|
@ -109,10 +109,13 @@
|
||||||
where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
|
where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
|
||||||
</select>
|
</select>
|
||||||
<select id="selectDeptIdByLeader" resultType="com.couplet.common.system.domain.SysDept">
|
<select id="selectDeptIdByLeader" resultType="com.couplet.common.system.domain.SysDept">
|
||||||
SELECT * FROM sys_dept d LEFT JOIN sys_user u on d.dept_id = u.dept_id WHERE u.user_name = #{userName}
|
SELECT * FROM sys_dept d WHERE d.leader = #{leader}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getSysDeptByDeptId" resultType="com.couplet.common.system.domain.SysDept">
|
<select id="getSysDeptByDeptId" resultType="com.couplet.common.system.domain.SysDept">
|
||||||
SELECT * FROM sys_dept WHERE parent_id = #{deptId}
|
SELECT d.*
|
||||||
|
FROM sys_dept AS d
|
||||||
|
WHERE CONCAT(',', d.ancestors, ',') LIKE CONCAT('%,', #{deptId}, ',%') AND d.dept_id != #{deptId} AND d.del_flag = '0'
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<insert id="insertDept" parameterType="com.couplet.common.system.domain.SysDept">
|
<insert id="insertDept" parameterType="com.couplet.common.system.domain.SysDept">
|
||||||
|
|
|
@ -183,6 +183,10 @@
|
||||||
and del_flag = '0'
|
and del_flag = '0'
|
||||||
limit 1
|
limit 1
|
||||||
</select>
|
</select>
|
||||||
|
<select id="userList" resultType="com.couplet.common.system.domain.SysUser">
|
||||||
|
<include refid="selectUserVo"/>
|
||||||
|
WHERE u.dept_id = #{deptId} AND u.del_flag=0
|
||||||
|
</select>
|
||||||
|
|
||||||
<insert id="insertUser" parameterType="com.couplet.common.system.domain.SysUser" useGeneratedKeys="true" keyProperty="userId">
|
<insert id="insertUser" parameterType="com.couplet.common.system.domain.SysUser" useGeneratedKeys="true" keyProperty="userId">
|
||||||
insert into sys_user(
|
insert into sys_user(
|
||||||
|
|
19
pom.xml
19
pom.xml
|
@ -260,6 +260,25 @@
|
||||||
<version>${couplet.version}</version>
|
<version>${couplet.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 事件系统远程调用 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.couplet</groupId>
|
||||||
|
<artifactId>couplet-incident-remote</artifactId>
|
||||||
|
<version>${couplet.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- 事件系统公共依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.couplet</groupId>
|
||||||
|
<artifactId>couplet-incident-common</artifactId>
|
||||||
|
<version>${couplet.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- 事件系统核心模块 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.couplet</groupId>
|
||||||
|
<artifactId>couplet-incident-server</artifactId>
|
||||||
|
<version>${couplet.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue