btxtgxq-system-city/src/main/java/com/cm/systemcity/utils/KpiUtil.java

90 lines
3.4 KiB
Java

package com.cm.systemcity.utils;
import com.cm.common.utils.point.Point;
import com.cm.common.utils.point.PointUtil;
import com.cm.systemcity.pojo.dtos.usersignin.UserSigninDTO;
import com.cm.systemcity.pojo.dtos.usersignout.UserSignoutDTO;
import com.cm.systemcity.pojo.pos.userlocation.UserLocationPO;
import com.cm.systemcity.service.userlocation.IUserLocationService;
import com.cm.systemcity.service.usersignin.IUserSigninService;
import com.cm.systemcity.service.usersignout.IUserSignoutService;
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<UserSigninDTO>> mapSignIn(IUserSigninService userSigninService, List<String> userIds, String day) {
List<UserSigninDTO> userSigninDTOS = userSigninService.listUserSignInByUserIdsAndDay(userIds, day);
Map<String, List<UserSigninDTO>> userSigninMap = new HashMap<>();
userSigninDTOS.forEach(userSigninDTO -> {
List<UserSigninDTO> userSigninDTOList = userSigninMap.get(userSigninDTO.getUserId());
if (userSigninDTOList == null) {
userSigninDTOList = new ArrayList<>();
}
userSigninDTOList.add(userSigninDTO);
userSigninMap.put(userSigninDTO.getCreator(), userSigninDTOList);
});
return userSigninMap;
}
/**
* 签退map
*
* @param userSignoutService
* @param userIds
* @return
*/
public static Map<String, List<UserSignoutDTO>> mapSignOut(IUserSignoutService userSignoutService, List<String> userIds, String day) {
List<UserSignoutDTO> userSignoutDTOS = userSignoutService.listUserSignOutByUserIdsAndDay(userIds, day);
Map<String, List<UserSignoutDTO>> userSigninMap = new HashMap<>();
userSignoutDTOS.forEach(userSignoutDTO -> {
List<UserSignoutDTO> userSignoutDTOList = userSigninMap.get(userSignoutDTO.getUserId());
if (userSignoutDTOList == null) {
userSignoutDTOList = new ArrayList<>();
}
userSignoutDTOList.add(userSignoutDTO);
userSigninMap.put(userSignoutDTO.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.listUserLocationPOByUserIdAndDate(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;
}
}