Commit 264ca597 by 向延琳

低电量统计

1 parent 5fa76f09
...@@ -155,4 +155,9 @@ public final class Constants { ...@@ -155,4 +155,9 @@ public final class Constants {
* 99:光感报警 * 99:光感报警
*/ */
public final static Integer ALARM_TYPE_LIGHT =99; public final static Integer ALARM_TYPE_LIGHT =99;
/**
* 低电量
*/
public static final int LOW_POWER_THRESHOLD = 10;
} }
...@@ -48,12 +48,11 @@ public class DashboardController { ...@@ -48,12 +48,11 @@ public class DashboardController {
/** /**
* 低电量统计 * 低电量统计
*/ */
@ApiOperation(value = "低电量统计", notes = "低电量统计", httpMethod = "GET") @ApiOperation(value = "低电量统计", notes = "低电量统计", httpMethod = "GET")
@GetMapping("pageLowPower") @GetMapping("pageLowPower")
public R<List<LowPowerVO>> pageTodayLowPower(BasicSearch search) { public R<List<LowPowerVO>> pageTodayLowPower(BasicSearch search) {
List<LowPowerVO> list = dashboardService.listTodayLowPower(search); List<LowPowerVO> list = dashboardService.listTodayLowPower(search);
return R.ok().putPageData(list, list.size()); return R.ok().putPageData(new PageInfo<>(list));
} }
......
package cn.com.glsx.app.modules.converter;
import cn.com.glsx.app.modules.entity.DevicePowerDO;
import cn.com.glsx.app.modules.model.param.TrackPointSearch;
import cn.com.glsx.app.modules.model.view.LowPowerVO;
import cn.com.glsx.devicemonitor.api.dto.TrackPointRequestDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* @author xiangyanlin
* @date 2022/7/6
*/
@Mapper
public interface DashboardConverter {
DashboardConverter INSTANCE = Mappers.getMapper(DashboardConverter.class);
/**
* 转换
*
* @param source 源对象
* @return LowPowerVO
*/
LowPowerVO convertTo(DevicePowerDO source);
/**
* 转换
*
* @param source 源对象
* @return List<LowPowerVO>
*/
List<LowPowerVO> convertTo(List<DevicePowerDO> source);
}
package cn.com.glsx.app.modules.entity; package cn.com.glsx.app.modules.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
/** /**
* @author xiangyanlin * @author xiangyanlin
...@@ -13,17 +15,39 @@ import java.io.Serializable; ...@@ -13,17 +15,39 @@ import java.io.Serializable;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Data @Data
public class AlarmCountDO implements Serializable { public class DevicePowerDO implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* 报警类型 * 姓名
*/ */
private Integer alarmType; private String ownerName;
/** /**
* 报警数量 * 设备号
*/ */
private Integer count; private String sn;
/**
* 车架号
*/
private String vin;
/**
* 车辆id
*/
private String vehicleId;
/**
* 当前电量
*/
private Integer soc;
/**
* 报警时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date alarmTime;
} }
package cn.com.glsx.app.modules.mapper; package cn.com.glsx.app.modules.mapper;
import cn.com.glsx.app.modules.entity.DevicePower; import cn.com.glsx.app.modules.entity.DevicePower;
import cn.com.glsx.app.modules.entity.DevicePowerDO;
import cn.com.glsx.app.modules.model.DevicePowerQueryBO;
import com.glsx.plat.common.annotation.DataPerm;
import com.glsx.plat.common.annotation.DataPermShare;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper; import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper @Mapper
public interface DevicePowerMapper extends CommonBaseMapper<DevicePower> { public interface DevicePowerMapper extends CommonBaseMapper<DevicePower> {
...@@ -18,4 +24,14 @@ public interface DevicePowerMapper extends CommonBaseMapper<DevicePower> { ...@@ -18,4 +24,14 @@ public interface DevicePowerMapper extends CommonBaseMapper<DevicePower> {
*/ */
DevicePower selectBySn(@Param("sn") String sn, @Param("vdId") Long vdId); DevicePower selectBySn(@Param("sn") String sn, @Param("vdId") Long vdId);
/**
* 获取绑定中的设备电量
* @param query 查询条件
* @return 绑定中的设备电量
*/
@DataPerm(permTable = "tv", showSql = true)
@DataPermShare(linkTable = "t_vehicle", showSql = true)
List<DevicePowerDO> listBindDevicePowerByCondition(DevicePowerQueryBO query);
} }
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.app.modules.model;
import lombok.Data;
import java.io.Serializable;
/**
* @author xiangyanlin
* @date 2022/7/6
*/
@Data
public class DevicePowerQueryBO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 开始时间
*/
private String startTime;
/**
* 结束时间
*/
private String endTime;
/**
* 最小电量
*/
private Integer minBattery;
/**
* 最大电量
*/
private Integer maxBattery ;
}
...@@ -44,12 +44,6 @@ public class LowPowerVO implements Serializable { ...@@ -44,12 +44,6 @@ public class LowPowerVO implements Serializable {
private String alarmTime; private String alarmTime;
/** /**
* 激活时间
**/
@ApiModelProperty("激活时间")
private String activeDate;
/**
* 车辆ID * 车辆ID
*/ */
@ApiModelProperty("车辆ID") @ApiModelProperty("车辆ID")
......
...@@ -3,8 +3,11 @@ package cn.com.glsx.app.modules.service; ...@@ -3,8 +3,11 @@ package cn.com.glsx.app.modules.service;
import cn.com.glsx.admin.common.util.DateUtil; import cn.com.glsx.admin.common.util.DateUtil;
import cn.com.glsx.app.common.constants.Constants; import cn.com.glsx.app.common.constants.Constants;
import cn.com.glsx.app.common.enums.TypeConverseEunm; import cn.com.glsx.app.common.enums.TypeConverseEunm;
import cn.com.glsx.app.modules.converter.DashboardConverter;
import cn.com.glsx.app.modules.entity.DevicePowerDO;
import cn.com.glsx.app.modules.mapper.*; import cn.com.glsx.app.modules.mapper.*;
import cn.com.glsx.app.modules.model.AlarmTrackRecQueryBO; import cn.com.glsx.app.modules.model.AlarmTrackRecQueryBO;
import cn.com.glsx.app.modules.model.DevicePowerQueryBO;
import cn.com.glsx.app.modules.model.RangeTimeDTO; import cn.com.glsx.app.modules.model.RangeTimeDTO;
import cn.com.glsx.app.modules.model.param.BasicSearch; import cn.com.glsx.app.modules.model.param.BasicSearch;
import cn.com.glsx.app.modules.model.param.DeviceActiveSearch; import cn.com.glsx.app.modules.model.param.DeviceActiveSearch;
...@@ -17,6 +20,7 @@ import com.github.pagehelper.PageInfo; ...@@ -17,6 +20,7 @@ import com.github.pagehelper.PageInfo;
import com.glsx.plat.context.utils.PropertiesUtils; import com.glsx.plat.context.utils.PropertiesUtils;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.time.DateUtils; import org.apache.commons.lang.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -53,6 +57,9 @@ public class DashboardService extends AbstractCommonService { ...@@ -53,6 +57,9 @@ public class DashboardService extends AbstractCommonService {
@Autowired @Autowired
private VehicleMapper vehicleMapper; private VehicleMapper vehicleMapper;
@Autowired
private DevicePowerMapper devicePowerMapper;
public List<DeviceActiveVO> getActiveDeviceWeekReport(DeviceActiveSearch search) { public List<DeviceActiveVO> getActiveDeviceWeekReport(DeviceActiveSearch search) {
List<StatActivatedVehicleDevice> activeDeviceList = vehicleDeviceMapper.getActiveDeviceInfo(search); List<StatActivatedVehicleDevice> activeDeviceList = vehicleDeviceMapper.getActiveDeviceInfo(search);
Map<String, List<StatActivatedVehicleDevice>> groupByActiveTimeMap = activeDeviceList.stream().collect(Collectors.groupingBy(StatActivatedVehicleDevice::getActiveTime)); Map<String, List<StatActivatedVehicleDevice>> groupByActiveTimeMap = activeDeviceList.stream().collect(Collectors.groupingBy(StatActivatedVehicleDevice::getActiveTime));
...@@ -183,7 +190,19 @@ public class DashboardService extends AbstractCommonService { ...@@ -183,7 +190,19 @@ public class DashboardService extends AbstractCommonService {
} }
public List<LowPowerVO> listTodayLowPower(BasicSearch search) { /**
return null; * 今日低电量
*/
public List<LowPowerVO> listTodayLowPower(Page page) {
PageHelper.startPage(page.getPageNumber(), page.getPageSize());
DevicePowerQueryBO query = new DevicePowerQueryBO();
query.setStartTime(DateUtil.getTodayFirstDateTimeStr());
query.setStartTime(DateUtil.getTodayLastDateTimeStr());
query.setMaxBattery(Constants.LOW_POWER_THRESHOLD);
List<DevicePowerDO> list = devicePowerMapper.listBindDevicePowerByCondition(query);
if (CollectionUtils.isEmpty(list)) {
return Lists.newArrayList();
}
return DashboardConverter.INSTANCE.convertTo(list);
} }
} }
...@@ -17,6 +17,15 @@ ...@@ -17,6 +17,15 @@
<result column="updated_by" jdbcType="INTEGER" property="updatedBy"/> <result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
</resultMap> </resultMap>
<resultMap id="DevicePowerMap" type="cn.com.glsx.app.modules.entity.DevicePowerDO">
<result column="sn" jdbcType="VARCHAR" property="sn"/>
<result column="alarm_time" jdbcType="TIMESTAMP" property="alarmTime"/>
<result column="soc" jdbcType="INTEGER" property="soc"/>
<result column="owner_name" jdbcType="TINYINT" property="ownerName"/>
<result column="vin" jdbcType="TIMESTAMP" property="vin"/>
<result column="id" jdbcType="INTEGER" property="vehicleId"/>
</resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
<!-- <!--
...@@ -70,4 +79,32 @@ ...@@ -70,4 +79,32 @@
updated_by = values(updated_by) updated_by = values(updated_by)
</insert> </insert>
<select id="listBindDevicePowerByCondition" resultMap="DevicePowerMap">
select tvd.sn,
tv.owner_name,
tv.vin,
tv.id,
tdp.alarm_time
from t_device_power tdp
left join t_vehicle_device tvd on tvd.id = tdp.vd_id
left join t_vehicle tv on tvd.vehicle_id = tv.id
<where>
and tvd.del_flag = 0
and tvd.bind_status = 1
<if test="startTime != null">
and tdp.alarm_time <![CDATA[ >= ]]> #{startTime}
</if>
<if test="endTime != null">
and tdp.alarm_time <![CDATA[ <= ]]> #{endTime}
</if>
<if test="minBattery != null">
and tdp.soc <![CDATA[ >= ]]> #{minBattery}
</if>
<if test="maxBattery != null">
and tdp.soc <![CDATA[ < ]]> #{maxBattery}
</if>
</where>
</select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.app.modules.service; package cn.com.glsx.app.modules.service;
import cn.com.glsx.app.Application; import cn.com.glsx.app.Application;
import cn.com.glsx.app.modules.model.param.BasicSearch;
import cn.com.glsx.app.modules.model.view.LowPowerVO;
import cn.com.glsx.app.modules.model.view.StatisticalInfoVO; import cn.com.glsx.app.modules.model.view.StatisticalInfoVO;
import cn.com.glsx.auth.api.AuthFeignClient; import cn.com.glsx.auth.api.AuthFeignClient;
import cn.com.glsx.auth.model.SyntheticUser; import cn.com.glsx.auth.model.SyntheticUser;
import cn.com.glsx.auth.utils.ShieldContextHolder; import cn.com.glsx.auth.utils.ShieldContextHolder;
import cn.hutool.db.Page;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.glsx.plat.core.web.R; import com.glsx.plat.core.web.R;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -16,6 +19,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -16,6 +19,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
/** /**
* @author xiangyanlin * @author xiangyanlin
* @date 2022/7/5 * @date 2022/7/5
...@@ -44,4 +49,10 @@ class DashboardServiceTest { ...@@ -44,4 +49,10 @@ class DashboardServiceTest {
System.out.println(JSON.toJSONString(statisticalInfo)); System.out.println(JSON.toJSONString(statisticalInfo));
} }
@Test
public void testListTodayLowPower() {
List<LowPowerVO> list = dashboardService.listTodayLowPower(new Page(1, 10));
System.out.println(JSON.toJSONString(list));
}
} }
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!