Browse Source

Merge branch 'develop' of http://39.106.31.193:9211/mengff/jihe-dc into develop

develop
xiepufeng 8 months ago
parent
commit
71e1e8edeb
  1. 2
      zc-business/src/main/java/com/zc/business/controller/BroadcastController.java
  2. 2
      zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java
  3. 1
      zc-business/src/main/java/com/zc/business/controller/DeviceStatus.java
  4. 42
      zc-business/src/main/java/com/zc/business/controller/StatusController.java
  5. 17
      zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java
  6. 2
      zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java
  7. 1
      zc-business/src/main/java/com/zc/business/mapper/StatusMapper.java
  8. 2
      zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java
  9. 4
      zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java
  10. 34
      zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java
  11. 3
      zc-business/src/main/java/com/zc/business/service/impl/StatusService.java
  12. 9
      zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml
  13. 14
      zc-business/src/main/resources/mapper/business/StatusMapper.xml

2
zc-business/src/main/java/com/zc/business/controller/BroadcastController.java

@ -39,7 +39,7 @@ public class BroadcastController extends BaseController {
private static final String SECRET = "21232f297a57a5a743894a0e4a801fc3";
private static final String CALLBACKURL = "http://10.0.81.209/broadcast/logIn";
private static final String CALLBACKURL = "http://10.0.81.202/broadcast/logIn";
private final static String URL = HTTP + "10.0.81.106/api/REST-API/";

2
zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java

@ -229,6 +229,8 @@ public class DcDeviceController extends BaseController {
// 将日期列表以逗号分隔并设置为查询条件的值
props.put("terms[0].value", String.join(",", dateList));
props.put("paging", false);
props.put("sorts[0].order","asc");
props.put("sorts[0].name","timestamp");
AjaxResult ajaxResult = queryDeviceProperties(deviceId, propertyId, props);
if (!ajaxResult.get("code").equals(200)) {
return ajaxResult;

1
zc-business/src/main/java/com/zc/business/controller/DeviceStatus.java

@ -49,7 +49,6 @@ public class DeviceStatus {
StatusService statusService= SpringUtils.getBean(StatusService.class);
ExecutorService executor = Executors.newFixedThreadPool(100);
LambdaQueryWrapper<DcDevice> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(DcDevice::getUseState,1);
List<DcDevice> deviceList = deviceService.list(lambdaQueryWrapper);
List<Future<Void>> futures = new ArrayList<>();

42
zc-business/src/main/java/com/zc/business/controller/StatusController.java

@ -13,10 +13,7 @@ import com.zc.business.service.impl.StatusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;
@ -99,9 +96,8 @@ public class StatusController extends BaseController {
@ApiOperation("根据设备Id查询折线图数据")
@GetMapping("/deviceStatusList")
public AjaxResult getDeviceStatusList(Long deviceId) {
@GetMapping("/deviceStatusList/{deviceId}")
public AjaxResult getDeviceStatusList(@PathVariable Long deviceId) {
LocalDateTime thirtyDaysAgo = LocalDateTime.now().minusDays(30);
LocalDateTime currentTime = LocalDateTime.now();
@ -110,20 +106,22 @@ public class StatusController extends BaseController {
status.setTime(currentTime);
status.setDeviceId(deviceId);
List<Status> listStatus = statusService.list(status);
List<Status> listStatus = statusService.deviceStatusListById(status);
// Group by day and calculate average successRate with two decimal places
Map<Integer, Integer> averageSuccessRateByDay = listStatus.stream()
// Calculate average successRate by day
Map<Integer, Double> averageSuccessRateByDay = listStatus.stream()
.collect(Collectors.groupingBy(s -> s.getTime().getDayOfMonth(),
Collectors.collectingAndThen(
Collectors.averagingDouble(s -> Double.parseDouble(s.getSuccessRate().replace("%", ""))),
avg -> Math.round(Float.parseFloat(String.format("%.2f", avg)))
)));
Collectors.averagingDouble(s -> Double.parseDouble(s.getSuccessRate().replace("%", "")))));
if (averageSuccessRateByDay.isEmpty()) {
return AjaxResult.success("暂无数据");
}
return AjaxResult.success(averageSuccessRateByDay);
// Round average successRate to two decimal places
Map<Integer, Double> roundedAverageSuccessRateByDay = averageSuccessRateByDay.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, entry -> Math.round(entry.getValue() * 100.0) / 100.0));
return AjaxResult.success(roundedAverageSuccessRateByDay);
}
//按类型划分设备
@ -131,7 +129,9 @@ public class StatusController extends BaseController {
@GetMapping ("/type")
public AjaxResult getTypeList()
{
List<DcDevice> dcDeviceList = dcDeviceService.numberOfDevicesByType();
DcDevice dcDevice = new DcDevice();
dcDevice.setUseState(1);
List<DcDevice> dcDeviceList = dcDeviceService.numberOfDevicesByType(dcDevice);
HashMap<String, String> itemTypeMap = new HashMap<>();
itemTypeMap.put("1-1", "高清网络枪型固定摄像机");
itemTypeMap.put("1-2", "高清网络球形摄像机");
@ -155,7 +155,6 @@ public class StatusController extends BaseController {
Status status = new Status();
status.setStartTime(todayStart);
status.setTime(currentTime);
status.setUseState(1);
List<Status> listStatus = statusService.list(status);
//根据时间分组
Map<Integer, List<Status>> map = listStatus.stream()
@ -186,9 +185,9 @@ public class StatusController extends BaseController {
//离线率
maps.put("failRate",failRate);
//已使用数量
maps.put("sumUseState",String.valueOf(groupItems.size()));
maps.put("sum",String.valueOf(groupItems.size()));
//总数
maps.put("sum", String.valueOf(dcDeviceList.stream().filter(item -> Objects.equals(item.getDeviceType(), entrys.getKey())).map(DcDevice::getSumAll).collect(Collectors.toList()).get(0)));
maps.put("sumUseState", String.valueOf(dcDeviceList.stream().filter(item -> Objects.equals(item.getDeviceType(), entrys.getKey())).map(DcDevice::getSumAll).collect(Collectors.toList()).get(0)));
if(itemTypeMap.get(entrys.getKey())!=null) {
subMap.put(itemTypeMap.get(entrys.getKey()), maps);
}
@ -207,8 +206,11 @@ public class StatusController extends BaseController {
maps.put("sucessRate",String.format("%.2f", sucessRate)+"%");
//离线率
maps.put("failRate",failRate);
//已使用数量
List<DcDevice> list = dcDeviceService.list();
maps.put("sumUseState",String.valueOf(lastEntry.size()));
//总数
maps.put("sum",String.valueOf(lastEntry.size()));
maps.put("sum",String.valueOf(list.size()));
subMap.put("全部设备",maps);
return AjaxResult.success(subMap);

17
zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java

@ -116,15 +116,14 @@ public class WeatherForecastController extends BaseController {
JSONArray meteorologicalEarlyWarning6 = jsonObject.getJSONArray("meteorologicalEarlyWarning6");
JSONArray meteorologicalEarlyWarning7 = jsonObject.getJSONArray("meteorologicalEarlyWarning7");
JSONArray meteorologicalEarlyWarning8 = jsonObject.getJSONArray("meteorologicalEarlyWarning8");
return AjaxResult.success(meteorologicalEarlyWarning1.size() +
meteorologicalEarlyWarning2.size() +
meteorologicalEarlyWarning3.size() +
meteorologicalEarlyWarning4.size() +
meteorologicalEarlyWarning5.size() +
meteorologicalEarlyWarning6.size() +
meteorologicalEarlyWarning7.size() +
meteorologicalEarlyWarning8.size()
);
return AjaxResult.success((meteorologicalEarlyWarning1 == null ? 0 : meteorologicalEarlyWarning1.size()) +
(meteorologicalEarlyWarning2 == null ? 0 : meteorologicalEarlyWarning2.size()) +
(meteorologicalEarlyWarning3 == null ? 0 : meteorologicalEarlyWarning3.size()) +
(meteorologicalEarlyWarning4 == null ? 0 : meteorologicalEarlyWarning4.size()) +
(meteorologicalEarlyWarning5 == null ? 0 : meteorologicalEarlyWarning5.size()) +
(meteorologicalEarlyWarning6 == null ? 0 : meteorologicalEarlyWarning6.size()) +
(meteorologicalEarlyWarning7 == null ? 0 : meteorologicalEarlyWarning7.size()) +
(meteorologicalEarlyWarning8 == null ? 0 : meteorologicalEarlyWarning8.size()));
}

2
zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java

@ -15,7 +15,7 @@ import java.util.List;
public interface DcDeviceMapper extends BaseMapper<DcDevice> {
List<DcDevice> selectDcDeviceList(DcDevice dcDevice);
List<DcDevice> numberOfDevicesByType();
List<DcDevice> numberOfDevicesByType(DcDevice dcDevice);
}

1
zc-business/src/main/java/com/zc/business/mapper/StatusMapper.java

@ -17,5 +17,6 @@ public interface StatusMapper {
int Add(@Param("status")Status status);
List<Status> listStatus(@Param("status")Status status);
List<Status> deviceStatusListById(@Param("status")Status status);
}

2
zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java

@ -78,5 +78,5 @@ public interface IDcDeviceService extends IService<DcDevice> {
List<DcDevice> devicePileNumberQueryDevice(Map<String,Object> parameter);
List<DcDevice> numberOfDevicesByType();
List<DcDevice> numberOfDevicesByType(DcDevice dcDevice);
}

4
zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java

@ -448,8 +448,8 @@ public class DcDeviceServiceImpl extends ServiceImpl<DcDeviceMapper, DcDevice> i
}
@Override
public List<DcDevice> numberOfDevicesByType() {
return dcDeviceMapper.numberOfDevicesByType();
public List<DcDevice> numberOfDevicesByType(DcDevice dcDevice) {
return dcDeviceMapper.numberOfDevicesByType(dcDevice);
}
public static <T> List<T> castList(Object obj, Class<T> clazz) {

34
zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java

@ -89,27 +89,23 @@ public class DcWarningServiceImpl implements IDcWarningService
@Override
public int insertDcWarning(DcWarning dcWarning)
{
dcWarning.setCreateTime(DateUtils.getNowDate());
//设置事件Id UUID无下划线格式32
String uuid = IdUtils.fastSimpleUUID();
dcWarning.setId(uuid);
int priority = new DcWarningServiceImpl().priority(dcWarning);
if (priority==0){
return 0;
}
return dcWarningMapper.insertDcWarning(dcWarning);
}
//优先级策略
public int priority(DcWarning dcWarning){
if (StringUtils.isBlank(dcWarning.getStakeMark())||dcWarning.getWarningSource()==null||dcWarning.getWarningType()==null||
StringUtils.isBlank(dcWarning.getWarningSubclass())||StringUtils.isBlank(dcWarning.getDirection())){
StringUtils.isBlank(dcWarning.getWarningSubclass())||StringUtils.isBlank(dcWarning.getDirection())){
return 0;
}
String redisKye=dcWarning.getWarningSource().toString()+dcWarning.getWarningType().toString()+dcWarning.getWarningSubclass();//配置数据的key 事件源+事件类型+策略
Map<String, JSONObject> redisWarningStrategy = redisCache.getCacheMap(WARNINGSTRATEGY);//获取缓存全部的配置数据
if (redisWarningStrategy==null){//如果缓存为空,查询数据重新加入缓存
Map<String, HashMap> redisWarningStrategy = redisCache.getCacheMap(WARNINGSTRATEGY);//获取缓存全部的配置数据
if (redisWarningStrategy==null||redisWarningStrategy.size()==0){//如果缓存为空,查询数据重新加入缓存
Map<String, JSONObject> redisMap = new HashMap<>();
List<DcWaringStrategy> dcWaringStrategies = dcWarningMapper.selectDcWaringStrategyList();//数据库全部配置数据
for (DcWaringStrategy waringStrategy : dcWaringStrategies) {
@ -118,7 +114,7 @@ public class DcWarningServiceImpl implements IDcWarningService
JSONObject jsonObject = new JSONObject();
jsonObject.put("strategy", waringStrategy.getStrategy());//策略模式
jsonObject.put("strategyTime", waringStrategy.getStrategyTime());//模式时长,单位为分钟
jsonObject.put("priority", waringStrategy.getPriority());//策略模式
jsonObject.put("priority", waringStrategy.getPriority());//优先级
redisMap.put(key, jsonObject);
}
redisCache.setCacheMap(WARNINGSTRATEGY, redisMap);//数据库配置数据加入缓存中
@ -127,24 +123,28 @@ public class DcWarningServiceImpl implements IDcWarningService
String key=dcWarning.getStakeMark()+dcWarning.getDirection()+dcWarning.getWarningSource().
toString()+dcWarning.getWarningType().toString()+dcWarning.getWarningSubclass();//key,redis存储事件的key(桩号+方向+事件源+类型)
String dataId = redisCache.getCacheObject(WARNINGDATA + key);//查看redis是否存在数据(id的值)
JSONObject redisValueOne = redisWarningStrategy.get(redisKye+"1");//查看传入的事件类型是否配置策略1(优先级策略)
HashMap redisValueOne = redisWarningStrategy.get(redisKye+"1");//查看传入的事件类型是否配置策略1(优先级策略)
if(redisValueOne!=null){//执行策略1(暂时未定义,定义后开发)
}
JSONObject redisValueTwo = redisWarningStrategy.get(redisKye+"2");//查看传入的事件类型是否配置策略2(延迟策略)
HashMap redisValueTwo = redisWarningStrategy.get(redisKye+"2");//查看传入的事件类型是否配置策略2(延迟策略)
if (redisValueOne==null&&redisValueTwo!=null){ //执行策略2,执行到这里说明1不存在或者1未满足过滤条件
String strategyTime = redisValueTwo.getString("strategyTime").toString();//策略时长
String strategyTime = redisValueTwo.get("strategyTime").toString();//策略时长
if (dataId==null){//如果不存在直接加入数据库,加入缓存,配置对应的过期时间
int insertDcWarning = new DcWarningServiceImpl().insertDcWarning(dcWarning);//加入数据库
int insertDcWarning = dcWarningMapper.insertDcWarning(dcWarning);//加入数据库
if (insertDcWarning==0){
return 0;
}
String id = dcWarning.getId();//取出加入后的id作为value
redisCache.setCacheObject(WARNINGDATA+key,id,Integer.parseInt(strategyTime),TimeUnit.MINUTES);//加入缓存并设置延迟时间(单位分钟)
return 1;//结束
}
//redis存在数据,取出redis的id找对对应事件的配置,合成事件配置,重新定义延迟时间
HashMap<String, Object> map = dcWarningMapper.selectDcWarningById(dataId);
String otherConfig = map.get("otherConfig").toString();//取出原id的配置信息
String otherConfig="";
if (map.get("otherConfig")!=null){
otherConfig = map.get("otherConfig").toString(); //取出原id的配置信息
}
String otherConfigString = dcWarning.getOtherConfig();//新增的配置信息
JSONObject jsonObjectOne = new JSONObject(otherConfig);
JSONObject jsonObjectTwo = new JSONObject(otherConfigString);
@ -156,7 +156,7 @@ public class DcWarningServiceImpl implements IDcWarningService
}
return 1;
}
JSONObject redisValueThree = redisWarningStrategy.get(redisKye+"3");//查看传入的事件类型是否配置策略3(时间窗口策略)
HashMap redisValueThree = redisWarningStrategy.get(redisKye+"3");//查看传入的事件类型是否配置策略3(时间窗口策略)
if (redisValueOne==null&&redisValueTwo==null&&redisValueThree!=null){ //执行策略3,执行到这里说明1不存在或者2不存在或者1未满足过滤条件
if (dataId==null){//如果不存在直接加入数据库,加入缓存,配置对应的过期时间(30分钟)
int insertDcWarning = new DcWarningServiceImpl().insertDcWarning(dcWarning);//加入数据库
@ -179,7 +179,7 @@ public class DcWarningServiceImpl implements IDcWarningService
}
return 1;
}
JSONObject redisValueFour = redisWarningStrategy.get(redisKye+"4");//查看传入的事件类型是否配置策略3(自动结束策略)
HashMap redisValueFour = redisWarningStrategy.get(redisKye+"4");//查看传入的事件类型是否配置策略3(自动结束策略)
if (redisValueOne==null&&redisValueTwo==null&&redisValueThree==null&&redisValueFour!=null){ //执行策略4,执行到这里说明1不存在或者2、3不存在或者1未满足过滤条件
if (dataId==null){//如果不存在直接加入数据库,加入缓存
int insertDcWarning = new DcWarningServiceImpl().insertDcWarning(dcWarning);//加入数据库
@ -203,7 +203,7 @@ public class DcWarningServiceImpl implements IDcWarningService
}
return 1;
}
return 1;
return dcWarningMapper.insertDcWarning(dcWarning);//如果没有配置策略直接加入数据库;
}
private JSONObject mergeJsonObjects(JSONObject jsonObjectOne, JSONObject jsonObjectTwo){
// 合并videoList

3
zc-business/src/main/java/com/zc/business/service/impl/StatusService.java

@ -30,4 +30,7 @@ public class StatusService {
return list;
}
public List<Status> deviceStatusListById(Status status) {
return statusMapper.deviceStatusListById(status);
}
}

9
zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml

@ -32,6 +32,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="longitude" column="longitude"/>
<result property="latitude" column="latitude"/>
<result property="childType" column="child_type"/>
<result property="manufacturer" column="manufacturer"/>
</resultMap>
<resultMap id="dcStakeMarkResult" type="dcStakeMark">
@ -73,9 +74,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select t1.id, t1.iot_device_id, t1.group_id, t1.product_id, t1.stake_mark, t1.direction, t1.device_name, t1.device_code, t1.device_type,
t1.installation_Date,t1.production_date,t1.durable_years,t1.installation_site,t1.use_state,t1.device_state,t1.other_config,t1.remark,
t1.create_time,t1.update_time,t1.facilities_type,t1.device_ip,t1.stake_mark_range,t1.device_img,t1.child_type,
t1.facilities_type,t2.longitude,t2.latitude
t1.facilities_type,t2.longitude,t2.latitude,t3.manufacturer
from dc_device t1
left join dc_stake_mark t2 on t1.stake_mark = t2.stake_mark and t1.direction = t2.direction
left join dc_product t3 on t3.id = t1.product_id
<where>
<if test="id != null and id != ''">and t1.id = #{id}</if>
<if test="iotDeviceId != null and iotDeviceId != ''">and t1.iot_device_id = #{iotDeviceId}</if>
@ -108,6 +110,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="numberOfDevicesByType" parameterType="dcDevice" resultMap="DcDevice">
SELECT COALESCE(child_type, device_type) AS device_type, COUNT(*) AS sumAll
FROM dc_device
<where>
<if test="useState!=null">
use_state = #{useState}
</if>
</where>
GROUP BY device_type, child_type;
</select>

14
zc-business/src/main/resources/mapper/business/StatusMapper.xml

@ -103,8 +103,18 @@
<if test="status.deviceId != null">
AND s.device_id = #{status.deviceId}
</if>
<if test="status.useState != null and status.useState != 0">
AND d.use_state = #{status.useState}
</where>
</select>
<select id="deviceStatusListById" parameterType="com.zc.business.domain.Status" resultMap="BaseResultMap">
select s.id,s.time,s.success_rate,s.lost_rate
from status s
<where>
<if test="status.time != null">
AND s.time BETWEEN #{status.startTime,jdbcType=DATE} AND #{status.time,jdbcType=DATE}
</if>
<if test="status.deviceId != null">
AND s.device_id = #{status.deviceId}
</if>
</where>
</select>

Loading…
Cancel
Save