119 lines
5.0 KiB
Java
119 lines
5.0 KiB
Java
package com.cm.bigdata.utils;
|
|
|
|
import com.cm.bigdata.pojo.pos.kpi.BasePopulationInfoCountPO;
|
|
import com.cm.bigdata.pojo.pos.kpi.UserLocationPO;
|
|
import com.cm.bigdata.pojo.pos.kpi.UserSigninPO;
|
|
import com.cm.bigdata.pojo.pos.kpi.UserSignoutPO;
|
|
import com.cm.bigdata.service.kpi.IBasePopulationInfoService;
|
|
import com.cm.bigdata.service.kpi.IUserLocationService;
|
|
import com.cm.bigdata.service.kpi.IUserSignService;
|
|
import com.cm.common.utils.point.Point;
|
|
import com.cm.common.utils.point.PointUtil;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
public class KpiUtil {
|
|
|
|
/**
|
|
* 签到map
|
|
*
|
|
* @param userSigninService
|
|
* @param userIds
|
|
* @return
|
|
*/
|
|
public static Map<String, List<UserSigninPO>> mapSignin(IUserSignService userSignService, List<String> userIds, String day) {
|
|
List<UserSigninPO> userSigninDTOS = userSignService.listInPOByUserIdsAndDay(userIds, day);
|
|
Map<String, List<UserSigninPO>> userSigninMap = new HashMap<>();
|
|
userSigninDTOS.forEach(userSigninPO -> {
|
|
List<UserSigninPO> userSigninDTOList = userSigninMap.get(userSigninPO.getCreator());
|
|
if (userSigninDTOList == null) {
|
|
userSigninDTOList = new ArrayList<>();
|
|
}
|
|
userSigninDTOList.add(userSigninPO);
|
|
userSigninMap.put(userSigninPO.getCreator(), userSigninDTOList);
|
|
});
|
|
return userSigninMap;
|
|
}
|
|
|
|
/**
|
|
* 签退map
|
|
*
|
|
* @param userSignoutService
|
|
* @param userIds
|
|
* @return
|
|
*/
|
|
public static Map<String, List<UserSignoutPO>> mapSignout(IUserSignService userSignService, List<String> userIds, String day) {
|
|
List<UserSignoutPO> userSignoutDTOS = userSignService.listOutPOByUserIdsAndDay(userIds, day);
|
|
Map<String, List<UserSignoutPO>> userSigninMap = new HashMap<>();
|
|
userSignoutDTOS.forEach(userSignoutPO -> {
|
|
List<UserSignoutPO> userSignoutDTOList = userSigninMap.get(userSignoutPO.getCreator());
|
|
if (userSignoutDTOList == null) {
|
|
userSignoutDTOList = new ArrayList<>();
|
|
}
|
|
userSignoutDTOList.add(userSignoutPO);
|
|
userSigninMap.put(userSignoutPO.getCreator(), userSignoutDTOList);
|
|
});
|
|
return userSigninMap;
|
|
}
|
|
|
|
/**
|
|
* 计算工作距离
|
|
*
|
|
* @param userLocationService
|
|
* @param userId
|
|
* @param day af535c78-f0ba-4ccf-891b-cf7c6e42e9e8
|
|
* @return
|
|
*/
|
|
public static Double calculateWorkDistance(IUserLocationService userLocationService, String userId, String day) {
|
|
double workDistance = 0D;
|
|
if (!StringUtils.equals(userId, "af535c78-f0ba-4ccf-891b-cf7c6e42e9e8")) {
|
|
return workDistance;
|
|
}
|
|
List<UserLocationPO> userLocationPOS = userLocationService.listPOByUserIdAndDate(userId, day);
|
|
Point tempPoint = null;
|
|
for (UserLocationPO userLocationPO : userLocationPOS) {
|
|
Point point = new Point(Double.parseDouble(userLocationPO.getUserLatitude()), Double.parseDouble(userLocationPO.getUserLongitude()));
|
|
if (tempPoint == null) {
|
|
tempPoint = point;
|
|
continue;
|
|
}
|
|
workDistance += PointUtil.getDistance(tempPoint, point);
|
|
tempPoint = point;
|
|
}
|
|
return workDistance;
|
|
}
|
|
|
|
public static Map<String, Integer> mapPopulationCount(IBasePopulationInfoService basePopulationInfoService, List<String> userIds) {
|
|
List<BasePopulationInfoCountPO> basePopulationInfoCountPOS = basePopulationInfoService.listPopulationSaveCountByUserIds(userIds);
|
|
Map<String, Integer> map = new HashMap<>();
|
|
basePopulationInfoCountPOS.forEach(basePopulationInfoCountPO -> {
|
|
map.put(basePopulationInfoCountPO.getUserId(), basePopulationInfoCountPO.getTotal());
|
|
});
|
|
return map;
|
|
}
|
|
|
|
public static Map<String, Integer> mapPopulationSaveCount(IBasePopulationInfoService basePopulationInfoService, List<String> userIds, String date) {
|
|
List<BasePopulationInfoCountPO> basePopulationInfoCountPOS = basePopulationInfoService.listPopulationSaveCountByUserIdsAndDay(userIds, date);
|
|
Map<String, Integer> map = new HashMap<>();
|
|
basePopulationInfoCountPOS.forEach(basePopulationInfoCountPO -> {
|
|
map.put(basePopulationInfoCountPO.getUserId(), basePopulationInfoCountPO.getTotal());
|
|
});
|
|
return map;
|
|
}
|
|
|
|
public static Map<String, Integer> mapPopulationUpdateCount(IBasePopulationInfoService basePopulationInfoService, List<String> userIds, String date) {
|
|
List<BasePopulationInfoCountPO> basePopulationInfoCountPOS = basePopulationInfoService.listPopulationUpdateCountByUserIdsAndDay(userIds, date);
|
|
Map<String, Integer> map = new HashMap<>();
|
|
basePopulationInfoCountPOS.forEach(basePopulationInfoCountPO -> {
|
|
map.put(basePopulationInfoCountPO.getUserId(), basePopulationInfoCountPO.getTotal());
|
|
});
|
|
return map;
|
|
}
|
|
|
|
|
|
}
|