Commit 5a8023a0 by levphon

首页统计-数据精确授权处理

1 parent 3c6a537a
......@@ -3,6 +3,7 @@ package cn.com.glsx.admin.modules.mapper;
import cn.com.glsx.admin.modules.entity.VehicleDevice;
import cn.com.glsx.admin.modules.model.stat.StatActiveVehicleDevice;
import cn.com.glsx.admin.modules.model.stat.StatCountModel;
import cn.com.glsx.admin.modules.model.stat.StatSearch;
import com.glsx.plat.common.annotation.DataPerm;
import com.glsx.plat.common.annotation.DataPermShare;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
......@@ -73,7 +74,7 @@ public interface VehicleDeviceMapper extends CommonBaseMapper<VehicleDevice> {
*/
@DataPerm(permTable = "tv", showSql = true)
@DataPermShare(linkTable = "t_vehicle", showSql = true)
List<StatActiveVehicleDevice> getActiveDeviceWithAuth();
List<StatActiveVehicleDevice> getActiveDeviceWithAuth(@Param("search") StatSearch search);
/**
* 根据权限获取该账户下 所有激活设备和当天激活的设备总数
......
package cn.com.glsx.admin.modules.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 设备激活Vo
......@@ -8,15 +10,18 @@ import lombok.Data;
* @author yll
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ActiveDeviceVo {
/**
* 已激活设备的数量
* 激活设备的时间
*/
private int activeNumber;
private String activeDate;
/**
* 激活设备的时间
* 已激活设备的数量
*/
private String activeDate;
private int activeNumber;
}
......@@ -8,7 +8,9 @@ package cn.com.glsx.admin.modules.model;
* @history 2018-9-4
*/
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 绑定设备VO
......@@ -16,14 +18,18 @@ import lombok.Data;
* @author yll
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class DeviceBindVo {
/**
* 已绑定设备的数量
*/
private int bindDeviceNumber;
/**
* 绑定设备的时间
*/
private String bindDate;
/**
* 已绑定设备的数量
*/
private int bindDeviceNumber;
}
package cn.com.glsx.admin.modules.model.stat;
import lombok.Data;
import lombok.experimental.Accessors;
@Data
@Accessors(chain = true)
public class StatSearch {
private String statPattern;
private String statScope;
private String statBeginScope;
private String statEndScope;
private String appendSql;
}
......@@ -9,6 +9,7 @@ import cn.com.glsx.admin.modules.model.comparator.ComparatorBindDeviceModel;
import cn.com.glsx.admin.modules.model.comparator.ComparatorDeviceModel;
import cn.com.glsx.admin.modules.model.stat.StatActiveVehicleDevice;
import cn.com.glsx.admin.modules.model.stat.StatCountModel;
import cn.com.glsx.admin.modules.model.stat.StatSearch;
import cn.com.glsx.admin.modules.remote.RemoteAlarmService;
import cn.com.glsx.admin.modules.remote.RemoteStuJudgeAlarmService;
import cn.com.glsx.admin.modules.utils.DateUtil;
......@@ -19,6 +20,7 @@ import com.glsx.plat.context.utils.PropertiesUtils;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -75,9 +77,12 @@ public class HomeService {
// Integer activeNumForToday = activeStatList.stream().map(StatCountModel::getCnt1).filter(Objects::nonNull).reduce(0, Integer::sum);
//方案二
List<StatActiveVehicleDevice> activeDeviceList = vehicleDeviceMapper.getActiveDeviceWithAuth();
List<StatActiveVehicleDevice> activeDeviceList = vehicleDeviceMapper.getActiveDeviceWithAuth(new StatSearch().setStatPattern("%Y-%m-%d"));
List<StatActiveVehicleDevice> activeTodayList = activeDeviceList.stream().filter(device -> today.equals(device.getActiveTime())).collect(Collectors.toList());
Set<Long> allBindVehicles = activeDeviceList.stream().map(StatActiveVehicleDevice::getVehicleId).collect(Collectors.toSet());
Set<Long> bindForTodayVehicles = activeTodayList.stream().map(StatActiveVehicleDevice::getVehicleId).collect(Collectors.toSet());
//总激活数
returnMap.put("allActiveNumber", activeDeviceList.size());
//今日激活数
......@@ -87,9 +92,6 @@ public class HomeService {
// Integer allBindNumber = bindStatList.stream().map(StatCountModel::getCnt).filter(Objects::nonNull).reduce(0, Integer::sum);
// Integer bindNumForToday = bindStatList.stream().map(StatCountModel::getCnt1).filter(Objects::nonNull).reduce(0, Integer::sum);
Set<Long> allBindVehicles = activeDeviceList.stream().map(StatActiveVehicleDevice::getVehicleId).collect(Collectors.toSet());
Set<Long> bindForTodayVehicles = activeTodayList.stream().map(StatActiveVehicleDevice::getVehicleId).collect(Collectors.toSet());
//总绑定数
returnMap.put("allBindNumber", allBindVehicles.size());
//今日绑定数
......@@ -164,7 +166,22 @@ public class HomeService {
public List<ActiveDeviceVo> getActiveDeviceInfo(Integer period) throws ParseException {
String appendSql = DateUtil.appendSqlByTimeRange(period, "tvd.created_date");
List<ActiveDeviceVo> list = vehicleMapper.getActiveDeviceInfoWithAuth(appendSql, period);
//List<ActiveDeviceVo> list = vehicleMapper.getActiveDeviceInfoWithAuth(appendSql, period);
StatSearch search = new StatSearch();
if (period == 1 || period == 2) {
search.setStatPattern("%H");
} else {
search.setStatPattern("%Y-%m-%d");
}
search.setAppendSql(appendSql);
List<StatActiveVehicleDevice> activeDeviceList = vehicleDeviceMapper.getActiveDeviceWithAuth(search);
Map<String, List<StatActiveVehicleDevice>> groupByActiveTimeMap = activeDeviceList.stream().collect(Collectors.groupingBy(StatActiveVehicleDevice::getActiveTime));
List<ActiveDeviceVo> list = convertActiveDeviceVoList(groupByActiveTimeMap);
if (list != null && list.size() == 0) {
list = null;
}
......@@ -213,6 +230,12 @@ public class HomeService {
return retList;
}
public List<ActiveDeviceVo> convertActiveDeviceVoList(Map<String, List<StatActiveVehicleDevice>> groupByActiveTimeMap) {
List<ActiveDeviceVo> list = Lists.newArrayList();
groupByActiveTimeMap.forEach((k, v) -> list.add(new ActiveDeviceVo(k, v.size())));
return list;
}
/**
* 当列表中不包含1到24小时对应的DeviceVo对象,则填充之
*
......@@ -310,12 +333,20 @@ public class HomeService {
return retList;
}
public List<DeviceBindVo> getNewBindDeviceInfo() throws ParseException {
List<DeviceBindVo> retList = Lists.newArrayList();
String appendSql = DateUtil.appendSqlByTimeRange(11, "tvd.created_date");
List<DeviceBindVo> list = vehicleMapper.getBindDeviceInfoWithAuth(appendSql);
if (list != null && list.size() == 0) {
//List<DeviceBindVo> list = vehicleMapper.getBindDeviceInfoWithAuth(appendSql);
StatSearch search = new StatSearch().setStatPattern("%Y-%m-%d");
search.setAppendSql(appendSql);
List<StatActiveVehicleDevice> activeDeviceList = vehicleDeviceMapper.getActiveDeviceWithAuth(search);
Map<String, List<StatActiveVehicleDevice>> groupByActiveTimeMap = activeDeviceList.stream().collect(Collectors.groupingBy(StatActiveVehicleDevice::getActiveTime));
List<DeviceBindVo> list = convertDeviceBindVoList(groupByActiveTimeMap);
if (CollectionUtils.isEmpty(list)) {
list = null;
}
Date recThirtyBegin = DateUtils.parseDate(DateUtil.getReductionDay(29), PARSE_PATTERN);
......@@ -327,6 +358,12 @@ public class HomeService {
return retList;
}
public List<DeviceBindVo> convertDeviceBindVoList(Map<String, List<StatActiveVehicleDevice>> groupByActiveTimeMap) {
List<DeviceBindVo> list = Lists.newArrayList();
groupByActiveTimeMap.forEach((k, v) -> list.add(new DeviceBindVo(k, v.size())));
return list;
}
/**
* 当列表中不包含开始日期到结束日期的对应的DeviceVo对象,则填充之
*
......
......@@ -86,12 +86,15 @@
</update>
<select id="getActiveDeviceWithAuth" resultType="cn.com.glsx.admin.modules.model.stat.StatActiveVehicleDevice">
select tvd.id, tvd.vehicle_id vehicleId, date_format(tvd.created_date, '%Y-%m-%d') activeTime
select tvd.id, tvd.vehicle_id vehicleId, date_format(tvd.created_date, #{search.statPattern}) activeTime
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
where tvd.bind_status = 1
and tvd.del_flag = 0
and tv.del_flag = 0
and tvd.del_flag = 0
and tv.del_flag = 0
<if test="search.appendSql != null and search.appendSql !=''">
${search.appendSql}
</if>
</select>
<select id="getActiveNumberWithAuth" resultType="cn.com.glsx.admin.modules.model.stat.StatCountModel">
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!