fast()预警报警

car-ser
王熙朝 2024-06-23 10:43:36 +08:00
parent ad1accf68e
commit 32e2ff6ee6
14 changed files with 286 additions and 101 deletions

View File

@ -1,5 +1,8 @@
package com.business.common.Select;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.muyu.common.core.web.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@ -7,20 +10,18 @@ import lombok.NoArgsConstructor;
import java.util.Date;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BreakdownSel {
/**
*
*/
private String faultCode;
public class BreakdownSel{
/**
*
*/
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
// @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
@JsonProperty("faultStartTime")
private Date faultStartTime;
/**
*
*/
@JsonProperty("faultEndTime")
private Date faultEndTime;
}

View File

@ -1,5 +1,8 @@
package com.business.common.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.web.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
@ -8,36 +11,36 @@ import lombok.NoArgsConstructor;
import java.util.Date;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Breakdown {
/**
*
*/
public class Breakdown extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** $column.columnComment */
private Long id;
/**
*
*/
/** 故障码 */
@Excel(name = "故障码")
private String faultCode;
/**
*
*/
/** 车辆标识 */
@Excel(name = "车辆标识")
private String vin;
/**
*
*/
/** 故障状态 */
@Excel(name = "故障状态")
private Integer faultState;
/**
*
*/
/** 故障产生时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "故障产生时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date faultStartTime;
/**
*
*/
/** 故障解决时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "故障解决时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date faultEndTime;
/**
*
*/
/** 故障级别 */
@Excel(name = "故障级别")
private Integer faultLevel;
}

View File

@ -8,11 +8,13 @@ import com.business.common.psvm.FaultInfo;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.goods.incident.mq.Producer;
import com.muyu.goods.service.IBreakdownService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -22,37 +24,48 @@ import java.util.Map;
public class BreakdownController extends BaseController {
@Autowired
private IBreakdownService service;
@Autowired
private Producer producer;
/**
*
* @return
*/
/**
*
*/
@GetMapping("/list")
public Result<TableDataInfo<Breakdown>> list(BreakdownSel breakdownSel)
public Result<TableDataInfo<Breakdown>> list( )
{
startPage();
List<Breakdown> list = service.selectBreakdownList(breakdownSel);
List<Breakdown> list = service.selectBreakdownList();
return getDataTable(list);
}
@PostMapping("/lists")
public Result<List<Breakdown>> lists() {
List<Breakdown> list = service.lists();
return success(list);
}
/**
*
* @param faultInfo
* @param breakdown
* @return
*/
@PostMapping("indexBreakDown")
public Result indexBreakDown(@RequestBody FaultInfo faultInfo) {
return success(service.indexBreakDown(faultInfo));
public Result indexBreakDown(@RequestBody Breakdown breakdown) {
return success(service.indexBreakDown(breakdown));
}
/**
*
* @param faultInfo
* @param breakdown
* @return
*/
@PostMapping("updateBreakDown")
public Result updateBreakDown(@RequestBody FaultInfo faultInfo) {
return success(service.updateBreakDown(faultInfo));
public Result updateBreakDown(@RequestBody Breakdown breakdown) {
return success(service.updateBreakDown(breakdown));
}
/**
@ -64,8 +77,8 @@ public class BreakdownController extends BaseController {
return success(service.listFaultCode());
}
@PostMapping("selectVinEnterprise")
public Result<Sources> selectVinEnterprise(@RequestParam String vin) {
@PostMapping("selectVinEnterprise/{vin}")
public Result<Sources> selectVinEnterprise(@PathVariable String vin) {
return success(service.selectVinEnterprise(vin));
}
@ -74,7 +87,31 @@ public class BreakdownController extends BaseController {
* @return
*/
@PostMapping("pies")
public Result<List<Map<String,Object>>> pies() {
return success(service.pies());
public Result<List<Map<String,Object>>> pies(@RequestBody BreakdownSel breakdownSel) {
System.out.println(breakdownSel);
return success(service.pies(breakdownSel));
}
/**
*
*/
@PostMapping("start")
public void start() {
FaultInfo faultInfo = FaultInfo.builder()
.faultCode("456")
.vin("123")
.time(new Date())
.build();
producer.start_time(faultInfo);
}
@PostMapping("end")
public void end() {
FaultInfo faultInfo = FaultInfo.builder()
.faultCode("456")
.vin("123")
.time(new Date())
.build();
producer.end_time(faultInfo);
}
}

View File

@ -1,5 +1,7 @@
package com.muyu.goods.incident.mq;
import com.alibaba.fastjson2.JSONObject;
import com.business.common.psvm.FaultInfo;
import com.muyu.common.core.domain.Result;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
@ -13,4 +15,14 @@ public class Producer {
public void electronic(Integer id) {
rabbitTemplate.convertAndSend("vehicle.event","",id);
}
public void start_time(FaultInfo faultInfo) {
String jsonString = JSONObject.toJSONString(faultInfo);
rabbitTemplate.convertAndSend("fault.message","start",jsonString);
}
public void end_time(FaultInfo faultInfo) {
String jsonString = JSONObject.toJSONString(faultInfo);
rabbitTemplate.convertAndSend("fault.message","end",jsonString);
}
}

View File

@ -11,15 +11,18 @@ import java.util.List;
import java.util.Map;
public interface BreakdownMapper {
Integer indexBreakDown(FaultInfo faultInfo);
Integer indexBreakDown(Breakdown breakdown);
Integer updateBreakDown(FaultInfo faultInfo);
Integer updateBreakDown(Breakdown breakdown);
List<FaultCode> listFaultCode();
Car selectVinCar(@Param("vin") String vin);
List<Breakdown> selectBreakdownList(BreakdownSel breakdownSel);
List<Breakdown> selectBreakdownList();
List<Map<String, Object>> pies();
List<Map<String, Object>> pies(BreakdownSel breakdownSel);
List<Breakdown> lists();
}

View File

@ -1,39 +1,76 @@
package com.muyu.goods.monitor.mq;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.business.common.domain.Breakdown;
import com.business.common.domain.VehicleInfo;
import com.business.common.psvm.FaultInfo;
import com.rabbitmq.client.Channel;
import com.muyu.goods.controller.BreakdownController;
import com.muyu.goods.service.impl.ExecuteService;
import lombok.Data;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.Date;
import java.util.concurrent.TimeUnit;
@Component
@Log4j2
public class breakdownMqConsumer {
@Autowired
private AmqpAdmin amqpAdmin;
@Autowired
private ExecuteService executeService;
@Autowired
private BreakdownController breakdownController;
@Autowired
private RedisTemplate<String,String> redisTemplate;
/**
*
* @param message
*/
//监听交换机 Queue(队列名) @Exchange(value = "交换机名称", type = ExchangeTypes.FANOUT)
@RabbitListener(bindings = {@QueueBinding(value = @Queue("fault_start_message"),
exchange = @Exchange(value = "fault.message", type = ExchangeTypes.FANOUT))})
public void failureOccurrence(String message) {
FaultInfo faultInfo = JSONObject.parseObject(message, FaultInfo.class);
// @RabbitListener(queuesToDeclare = {@Queue("fault_start_message")})
// 监听交换机 Queue(队列名) @Exchange(value = "交换机名称", type = ExchangeTypes.FANOUT)
@RabbitListener(bindings = {@QueueBinding(value = @Queue(name = "fault_start_message"),
exchange = @Exchange(name = "fault.message", type = ExchangeTypes.DIRECT),
key = { "start" })})
// @RabbitListener(bindings = {@QueueBinding(value = @Queue("fault_start_message"),
// exchange = @Exchange(value = "fault.message", type = ExchangeTypes.FANOUT))})
public void failureOccurrence(String message, Channel channel, Message messageProperties) {
String parse = JSON.parse(message).toString();
FaultInfo faultInfo = JSON.parseObject(parse, FaultInfo.class);
log.info("获取存在:{}",faultInfo);
log.info("获取存在:{}",message);
// breakdownController.indexBreakDown(faultInfo);
amqpAdmin.deleteQueue("fault_start_message");
Breakdown breakdown = new Breakdown();
breakdown.setFaultLevel(1);
breakdown.setFaultStartTime(faultInfo.getTime());
breakdown.setFaultCode(faultInfo.getFaultCode());
breakdown.setVin(faultInfo.getVin());
breakdown.setFaultState(0);
System.out.println("取");
executeService.indexBreakdown(breakdown);
redisTemplate.opsForValue().set("vin",faultInfo.getVin(),10,TimeUnit.MINUTES);
executeService.selectVinEnterprise();
// 消费成功 手动确认
try {
channel.basicAck(messageProperties.getMessageProperties().getDeliveryTag(),false);
} catch (IOException e) {
throw new RuntimeException(e);
}
// 在这里处理接收到的消息
}
@ -41,14 +78,30 @@ public class breakdownMqConsumer {
*
* @param message
*/
@RabbitListener(bindings = {@QueueBinding(value = @Queue("fault_end_message"),
exchange = @Exchange(value = "fault.message", type = ExchangeTypes.FANOUT))})
public void failureShooting(String message) {
FaultInfo faultInfo = JSONObject.parseObject(message, FaultInfo.class);
// @RabbitListener(queuesToDeclare = {@Queue("fault_end_message")})
@RabbitListener(bindings = {@QueueBinding(value = @Queue(name = "fault_end_message"),
exchange = @Exchange(name = "fault.message", type = ExchangeTypes.DIRECT),
key = { "end" })})
// @RabbitListener(bindings = {@QueueBinding(value = @Queue("fault_end_message"),
// exchange = @Exchange(value = "fault.message", type = ExchangeTypes.FANOUT))})
public void failureShooting(String message, Channel channel, Message messageProperties) {
String parse = JSON.parse(message).toString();
FaultInfo faultInfo = JSON.parseObject(parse, FaultInfo.class);
log.info("解决:{}",message);
log.info("解决:{}",faultInfo);
// breakdownController.updateBreakDown(faultInfo);
amqpAdmin.deleteQueue("fault_end_message");
Breakdown breakdown = new Breakdown();
breakdown.setFaultEndTime(faultInfo.getTime());
breakdown.setFaultCode(faultInfo.getFaultCode());
breakdown.setVin(faultInfo.getVin());
breakdown.setFaultState(1);
System.out.println("改");
breakdownController.updateBreakDown(breakdown);
// 消费成功 手动确认
try {
channel.basicAck(messageProperties.getMessageProperties().getDeliveryTag(),false);
} catch (IOException e) {
throw new RuntimeException(e);
}
// 在这里处理接收到的消息
}
}

View File

@ -14,20 +14,23 @@ public interface IBreakdownService {
*
* @return
*/
List<Breakdown> selectBreakdownList(BreakdownSel breakdownSel);
List<Breakdown> selectBreakdownList();
List<Breakdown> lists();
/**
*
* @param faultInfo
* @param breakdown
* @return
*/
Integer indexBreakDown(FaultInfo faultInfo);
Integer indexBreakDown(Breakdown breakdown);
/**
*
* @param faultInfo
* @param breakdown
* @return
*/
Integer updateBreakDown(FaultInfo faultInfo);
Integer updateBreakDown(Breakdown breakdown);
List<FaultCode> listFaultCode();
@ -37,5 +40,7 @@ public interface IBreakdownService {
*
* @return
*/
List<Map<String,Object>> pies();
List<Map<String,Object>> pies(BreakdownSel breakdownSel);
}

View File

@ -30,22 +30,27 @@ public class BreakdownService implements IBreakdownService {
/**
*
* @param breakdownSel
* @param breakdown
* @return
*/
@Override
public List<Breakdown> selectBreakdownList(BreakdownSel breakdownSel) {
return mapper.selectBreakdownList(breakdownSel);
public List<Breakdown> selectBreakdownList() {
return mapper.selectBreakdownList();
}
@Override
public Integer indexBreakDown(FaultInfo faultInfo) {
return mapper.indexBreakDown(faultInfo);
public List<Breakdown> lists() {
return mapper.lists();
}
@Override
public Integer updateBreakDown(FaultInfo faultInfo) {
return mapper.updateBreakDown(faultInfo);
public Integer indexBreakDown(Breakdown breakdown) {
return mapper.indexBreakDown(breakdown);
}
@Override
public Integer updateBreakDown(Breakdown breakdown) {
return mapper.updateBreakDown(breakdown);
}
@Override
@ -57,14 +62,28 @@ public class BreakdownService implements IBreakdownService {
public Sources selectVinEnterprise(String vin) {
// 查询车辆
Car car = mapper.selectVinCar(vin);
if (car == null) {
System.out.println("查询不到车辆");
return null;
}
//根据车辆管理人查询员工
List<SysUser> userList = remoteUserService.lists().getData();
SysUser sysUser = userList.stream().filter(firm -> firm.getFirm() == car.getOwnerId()).collect(Collectors.toList()).get(0);
List<SysUser> sysUserList = userList.stream().filter(firm -> firm.getFirm() == car.getOwnerId()).collect(Collectors.toList());
if (sysUserList == null ){
System.out.println("该车负责人未找到");
return null;
}
SysUser sysUser = sysUserList.get(0);
//根据员工查询到企业
List<Enterprise> enterpriseList = remoteSourcesService.lists().getData();
Enterprise enterprise1 = enterpriseList.stream().filter(enterprise -> enterprise.getId() == sysUser.getFirm()).collect(Collectors.toList()).get(0);
List<Enterprise> enterprises = enterpriseList.stream().filter(enterprise -> enterprise.getId() == sysUser.getFirm()).collect(Collectors.toList());
if (enterprises == null) {
System.out.println("未成功定义企业");
return null;
}
Enterprise enterprise = enterprises.get(0);
//根据企业查询到企业数据源
com.muyu.common.goods.domain.Sources sources = remoteSourcesService.listSources().getData().stream().filter(sour -> sour.getEnterpriseId() == enterprise1.getId()).collect(Collectors.toList()).get(0);
com.muyu.common.goods.domain.Sources sources = remoteSourcesService.listSources().getData().stream().filter(sour -> sour.getEnterpriseId() == enterprise.getId()).collect(Collectors.toList()).get(0);
Sources sources1 = Sources.builder()
.id(sources.getId())
.enterpriseId(sources.getEnterpriseId())
@ -74,11 +93,12 @@ public class BreakdownService implements IBreakdownService {
.username(sources.getUsername())
.password(sources.getPassword())
.build();
System.out.println(sources1);
return sources1;
}
@Override
public List<Map<String, Object>> pies() {
return mapper.pies();
public List<Map<String, Object>> pies(BreakdownSel breakdownSel) {
return mapper.pies(breakdownSel);
}
}

View File

@ -1,10 +1,13 @@
package com.muyu.goods.service.impl;
import com.business.common.domain.Breakdown;
import com.business.common.middle.GroupFenceDev;
import com.business.common.domain.Car;
import com.business.common.psvm.FaultInfo;
import com.muyu.goods.mapper.MapMapper;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
@ -16,6 +19,10 @@ import java.util.stream.Collectors;
public class ExecuteService {
@Autowired
private MapMapper mapMapper;
@Autowired
private BreakdownService breakdownService;
@Autowired
private RedisTemplate<String,String> redisTemplate;
@Async
public void indexGroupFence(Car car) {
@ -35,4 +42,15 @@ public class ExecuteService {
mapMapper.deleteCarFence(carId);
log.info("delete完成");
}
@Async
public void indexBreakdown(Breakdown breakdown) {
breakdownService.indexBreakDown(breakdown);
}
@Async
public void selectVinEnterprise() {
String vin = redisTemplate.opsForValue().get("vin");
breakdownService.selectVinEnterprise(vin);
}
}

View File

@ -32,26 +32,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="faultCode != null">fault_code,</if>
<if test="vin != null">vin,</if>
fault_state,
<if test="faultState!=null">fault_state,</if>
<if test="faultStartTime != null">fault_start_time,</if>
fault_level,
<if test="faultLevel!=null">fault_level,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="faultCode != null">#{faultCode},</if>
<if test="vin != null">#{vin},</if>
<if test="faultState != null">0,</if>
<if test="faultStartTime != null">#{time},</if>
<if test="faultStartTime != null">#{faultStartTime},</if>
<if test="faultLevel != null">1,</if>
</trim>
</insert>
<update id="updateBreakDown">
update breakdown
set fault_end_time = #{time},
set fault_end_time = #{faultEndTime},
fault_state = 1
where
fault_code = #{faultCode} and
vin = #{vin} and
fault_end_time = null
fault_end_time is null
</update>
<select id="listFaultCode" resultType="com.business.common.domain.FaultCode">
<include refid="selectFaultCodeVo"></include>
@ -62,13 +62,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectBreakdownList" resultType="com.business.common.domain.Breakdown">
<include refid="selectBreakdownVo"></include>
<where>
<if test="faultCode != null and faultCode!=''">and fault_code like concat('%',#{faultCode},'%')</if>
<if test="faultStartTime != null and faultStartTime != ''">and fault_start_time >= #{faultStartTime} </if>
<if test="faultEndTime != null and faultEndTime != ''">and fault_start_time &lt; = #{faultEndTime} </if>
</where>
</select>
<select id="pies" resultType="java.util.Map">
select fault_code name, count(fault_code) value from breakdown group by fault_code
select fault_code name, count(fault_code) value from breakdown
<where>
<if test="faultStartTime != null">and fault_start_time >= #{faultStartTime} </if>
<if test="faultEndTime != null ">and fault_start_time &lt;= #{faultEndTime} </if>
</where>
group by fault_code
</select>
<select id="lists" resultType="com.business.common.domain.Breakdown"></select>
</mapper>

View File

@ -22,8 +22,6 @@ public class EnterpriseConfigRunner implements ApplicationRunner {
@Autowired
private RemoteSourcesService remoteSourcesService;
@Override
public void run(ApplicationArguments args) throws Exception {
Result<List<Sources>> listResult = remoteSourcesService.listSources();
System.out.println(listResult);
public void run(ApplicationArguments args){
}
}

View File

@ -0,0 +1,37 @@
package com.muyu.goods.config;
import com.alibaba.fastjson2.JSONObject;
import com.muyu.goods.controller.EnterpriseController;
import com.muyu.goods.domain.Enterprise;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import java.util.List;
@Log4j2
@Configuration
@ComponentScan
public class EnterpiseConfig implements ApplicationRunner {
@Autowired
private RedisTemplate<String,String> redisTemplate;
@Autowired
private EnterpriseController enterpriseController;
@Override
public void run(ApplicationArguments args) throws Exception {
List<Enterprise> enterprises = enterpriseController.lists().getData();
List<String> range = redisTemplate.opsForList().range("enterprises", 0, -1);
if (range.size() == 0){
for (Enterprise enterpris : enterprises) {
redisTemplate.opsForList().leftPushAll("enterprises",JSONObject.toJSONString(enterpris));
}
}
}
}

View File

@ -139,9 +139,7 @@ public class EnterpriseServiceImpl implements IEnterpriseService
throw new RuntimeException(e);
}
Sources sources = Sources.index(enterprise1.getId(),"enterprise" + enterprise1.getId(), String.valueOf((int) (enterprise.getId() + 3306)));
System.out.println(sources);
enterpriseMapper.indexSources(sources);
System.out.println(sources.getIp());
producer.datasource(sources.getIp());
}
return i;
@ -197,9 +195,6 @@ public class EnterpriseServiceImpl implements IEnterpriseService
@Override
public List<Enterprise> lists() {
List<Enterprise> enterprises = selectEnterpriseList(null);
for (Enterprise enterpris : enterprises) {
redisTemplate.opsForList().leftPush("enterprises",JSONObject.toJSONString(enterpris));
}
List<String> range = redisTemplate.opsForList().range("enterprises", 0, -1);
System.out.println(range);
return enterprises;

View File

@ -21,4 +21,6 @@ public class CloudManyDataSourceApplication {
public static void main(String[] args) {
SpringApplication.run(CloudManyDataSourceApplication.class,args);
}
}