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> mapSignIn(IUserSigninService userSigninService, List userIds, String day) { List userSigninDTOS = userSigninService.listUserSignInByUserIdsAndDay(userIds, day); Map> userSigninMap = new HashMap<>(); userSigninDTOS.forEach(userSigninDTO -> { List 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> mapSignOut(IUserSignoutService userSignoutService, List userIds, String day) { List userSignoutDTOS = userSignoutService.listUserSignOutByUserIdsAndDay(userIds, day); Map> userSigninMap = new HashMap<>(); userSignoutDTOS.forEach(userSignoutDTO -> { List 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 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; } }