diff --git a/pom.xml b/pom.xml index db1bbc0..841ce6e 100644 --- a/pom.xml +++ b/pom.xml @@ -170,6 +170,12 @@ junit test + + com.alibaba + tools + 1.8.0 + compile + diff --git a/src/main/java/com/cm/systemcity/controller/apis/kpi/KpiController.java b/src/main/java/com/cm/systemcity/controller/apis/kpi/KpiController.java new file mode 100644 index 0000000..0456914 --- /dev/null +++ b/src/main/java/com/cm/systemcity/controller/apis/kpi/KpiController.java @@ -0,0 +1,29 @@ +package com.cm.systemcity.controller.apis.kpi; + +import com.cm.common.base.AbstractController; +import com.cm.common.constants.ISystemConstant; +import com.cm.common.result.SuccessResult; +import com.cm.common.result.SuccessResultData; +import com.cm.systemcity.service.kpi.IKpiService; +import io.swagger.annotations.Api; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "网格员接口") +@RestController +@RequestMapping(ISystemConstant.API_PREFIX + "/kpi") +public class KpiController extends AbstractController { + + @Autowired + private IKpiService kpiService; + + @GetMapping("update-community-boss-day-count/{level}") + public SuccessResultData updateCommunityBossDayCount(@PathVariable("level") Integer level, + @RequestParam("dayDate") String dayDate) { + long startTime = System.currentTimeMillis(); + kpiService.updateCommunityBossDayCount(dayDate, level); + long endTime = System.currentTimeMillis(); + return new SuccessResultData<>("used "+ (endTime - startTime) +" ms"); + } + +} diff --git a/src/main/java/com/cm/systemcity/dao/kpi/IKpiDao.java b/src/main/java/com/cm/systemcity/dao/kpi/IKpiDao.java new file mode 100644 index 0000000..6196ac7 --- /dev/null +++ b/src/main/java/com/cm/systemcity/dao/kpi/IKpiDao.java @@ -0,0 +1,19 @@ +package com.cm.systemcity.dao.kpi; + +import com.cm.systemcity.pojo.pos.kpi.CommunityBossDayCountPO; +import org.springframework.stereotype.Repository; + +import java.util.Map; + +@Repository +public interface IKpiDao { + + void saveCommunityBossDayCount(Map params); + + void deleteCommunityBossDayCount(Map params); + + void updateCommunityBossDayCount(Map params); + + CommunityBossDayCountPO getCommunityBossDayCountPO(Map params); + +} diff --git a/src/main/java/com/cm/systemcity/dao/userlocation/IUserLocationDao.java b/src/main/java/com/cm/systemcity/dao/userlocation/IUserLocationDao.java index 0921fd1..ad917df 100755 --- a/src/main/java/com/cm/systemcity/dao/userlocation/IUserLocationDao.java +++ b/src/main/java/com/cm/systemcity/dao/userlocation/IUserLocationDao.java @@ -6,6 +6,7 @@ import com.cm.common.exception.SearchException; import com.cm.common.exception.UpdateException; import com.cm.systemcity.pojo.bos.userlocation.BaiduOffsetBO; import com.cm.systemcity.pojo.dtos.userlocation.UserLocationDTO; +import com.cm.systemcity.pojo.pos.userlocation.UserLocationPO; import org.springframework.stereotype.Repository; import java.util.List; @@ -118,4 +119,7 @@ public interface IUserLocationDao { Map getUserInfoById(String userId); List> listUserByIds(Map params); + + List listUserLocationPO(Map params); + } diff --git a/src/main/java/com/cm/systemcity/pojo/pos/kpi/CommunityBossDayCountPO.java b/src/main/java/com/cm/systemcity/pojo/pos/kpi/CommunityBossDayCountPO.java new file mode 100644 index 0000000..e12b460 --- /dev/null +++ b/src/main/java/com/cm/systemcity/pojo/pos/kpi/CommunityBossDayCountPO.java @@ -0,0 +1,21 @@ +package com.cm.systemcity.pojo.pos.kpi; + +import lombok.Data; +import lombok.ToString; + +@Data +@ToString +public class CommunityBossDayCountPO { + + private Long id; + private String userId; + private String dayDate; + private Integer isSignin; + private Integer isSigninLate; + private Integer isSignout; + private Integer isSignoutEarly; + private Double workDistance; + private Integer savePopulationCount; + private Integer updatePopulationCount; + +} diff --git a/src/main/java/com/cm/systemcity/pojo/pos/userlocation/UserLocationPO.java b/src/main/java/com/cm/systemcity/pojo/pos/userlocation/UserLocationPO.java new file mode 100644 index 0000000..efb1b86 --- /dev/null +++ b/src/main/java/com/cm/systemcity/pojo/pos/userlocation/UserLocationPO.java @@ -0,0 +1,22 @@ +package com.cm.systemcity.pojo.pos.userlocation; + +import lombok.Data; +import lombok.ToString; + +import java.io.Serializable; + +@Data +@ToString +public class UserLocationPO implements Serializable { + + private Long id; + private String userLocationId; + private String userLongitude; + private String userLatitude; + private String userLocation; + private String isOverstep; + private String userName; + private String creator; + private String gmtCreate; + +} diff --git a/src/main/java/com/cm/systemcity/service/communityboss/ICommunityBossService.java b/src/main/java/com/cm/systemcity/service/communityboss/ICommunityBossService.java index acdac52..0e79843 100755 --- a/src/main/java/com/cm/systemcity/service/communityboss/ICommunityBossService.java +++ b/src/main/java/com/cm/systemcity/service/communityboss/ICommunityBossService.java @@ -228,4 +228,6 @@ public interface ICommunityBossService { List> listNPeopleByRoleId(String roleId); List listGridUser(Map params); + + List listCommunityBossByLevel(int level); } diff --git a/src/main/java/com/cm/systemcity/service/communityboss/impl/CommunityBossServiceImpl.java b/src/main/java/com/cm/systemcity/service/communityboss/impl/CommunityBossServiceImpl.java index dfd350a..10d4b0e 100755 --- a/src/main/java/com/cm/systemcity/service/communityboss/impl/CommunityBossServiceImpl.java +++ b/src/main/java/com/cm/systemcity/service/communityboss/impl/CommunityBossServiceImpl.java @@ -432,6 +432,13 @@ public class CommunityBossServiceImpl extends AbstractService implements ICommun return list; } + @Override + public List listCommunityBossByLevel(int level) { + Map params = getHashMap(2); + params.put("communityBossLevel", level); + return listCommunityBoss(params); + } + @Override public SuccessResultData countCommunityBoss(Map params) throws SearchException { int count = communityBossDao.countCommunityBoss(params); diff --git a/src/main/java/com/cm/systemcity/service/kpi/IKpiService.java b/src/main/java/com/cm/systemcity/service/kpi/IKpiService.java new file mode 100644 index 0000000..71689fa --- /dev/null +++ b/src/main/java/com/cm/systemcity/service/kpi/IKpiService.java @@ -0,0 +1,15 @@ +package com.cm.systemcity.service.kpi; + +/** + * 绩效考核 + */ +public interface IKpiService { + + /** + * 更新4、5级网格员日统计 + * @param date + */ + void updateCommunityBossDayCount(String date, int level); + + +} diff --git a/src/main/java/com/cm/systemcity/service/kpi/impl/KpiServiceImpl.java b/src/main/java/com/cm/systemcity/service/kpi/impl/KpiServiceImpl.java new file mode 100644 index 0000000..73c3cc4 --- /dev/null +++ b/src/main/java/com/cm/systemcity/service/kpi/impl/KpiServiceImpl.java @@ -0,0 +1,99 @@ +package com.cm.systemcity.service.kpi.impl; + +import com.cm.systemcity.dao.kpi.IKpiDao; +import com.cm.systemcity.pojo.dtos.communityboss.CommunityBossDTO; +import com.cm.systemcity.pojo.dtos.usersignin.UserSigninDTO; +import com.cm.systemcity.pojo.dtos.usersignout.UserSignoutDTO; +import com.cm.systemcity.pojo.pos.kpi.CommunityBossDayCountPO; +import com.cm.systemcity.pojo.pos.userlocation.UserLocationPO; +import com.cm.systemcity.service.communityboss.ICommunityBossService; +import com.cm.systemcity.service.kpi.IKpiService; +import com.cm.systemcity.service.userlocation.IUserLocationService; +import com.cm.systemcity.service.usersignin.IUserSigninService; +import com.cm.systemcity.service.usersignout.IUserSignoutService; +import com.cm.systemcity.utils.KpiUtil; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Service +public class KpiServiceImpl implements IKpiService { + + @Autowired + private IKpiDao kpiDao; + @Autowired + private ICommunityBossService communityBossService; + @Autowired + private IUserSigninService userSigninService; + @Autowired + private IUserSignoutService userSignoutService; + @Autowired + private IUserLocationService userLocationService; + + @Override + public void updateCommunityBossDayCount(String date, int level) { + // communityBoss表中的level位1-4,对应的是2-5级网格员 + final int communityBossLevel = level - 1; + List communityBoss4DTOList = communityBossService.listCommunityBossByLevel(communityBossLevel); + List userIds = communityBoss4DTOList.stream().map(CommunityBossDTO::getCommunityBossUserId).filter(StringUtils::isNotBlank).collect(Collectors.toList()); + Map> userSigninMap = KpiUtil.mapSignIn(userSigninService, userIds, date); + Map> userSignoutMap = KpiUtil.mapSignOut(userSignoutService, userIds, date); + // 删除当日数据 + deleteCommunityBossDayCount(date, communityBossLevel); + communityBoss4DTOList.forEach(communityBossDTO -> { + String userId = communityBossDTO.getCommunityBossUserId(); + List userSigninDTOS = userSigninMap.get(userId); + int isSignin = userSigninDTOS == null || userSigninDTOS.size() == 0 ? 0 : 1; + int isSigninLate = userSigninDTOS == null || userSigninDTOS.size() == 0 ? 0 : Integer.parseInt(userSigninDTOS.get(0).getIsLate()); + List userSignoutDTOS = userSignoutMap.get(userId); + int isSignout = userSignoutDTOS == null || userSignoutDTOS.size() == 0 ? 0 : 1; + int isSignoutEarly = userSignoutDTOS == null || userSignoutDTOS.size() == 0 ? 0 : Integer.parseInt(userSignoutDTOS.get(0).getIsEarly()); + double workDistance = KpiUtil.calculateWorkDistance(userLocationService, userId, date); + double savePopulationCount = 0; + double updatePopulationCount = 0; + // 新增 + Map params = new HashMap<>(); + params.put("userId", userId); + params.put("dayDate", date); + params.put("isSignin", isSignin); + params.put("isSigninLate", isSigninLate); + params.put("isSignout", isSignout); + params.put("isSignoutEarly", isSignoutEarly); + params.put("workDistance", workDistance); + params.put("savePopulationCount", savePopulationCount); + params.put("updatePopulationCount", updatePopulationCount); + params.put("level", communityBossLevel); + kpiDao.saveCommunityBossDayCount(params); + }); + } + + private void deleteCommunityBossDayCount(String date, int level) { + Map params = new HashMap<>(4); + params.put("dayDate", date); + params.put("level", level); + kpiDao.deleteCommunityBossDayCount(params); + } + + /** + * 网格员日统计 + * + * @param userId + * @param date + * @param level + * @return + */ + private CommunityBossDayCountPO getCommunityBossDayCountPO(String userId, String date, int level) { + Map params = new HashMap<>(8); + params.put("userId", userId); + params.put("dayDate", date); + params.put("level", level); + return kpiDao.getCommunityBossDayCountPO(params); + } + + +} diff --git a/src/main/java/com/cm/systemcity/service/userlocation/IUserLocationService.java b/src/main/java/com/cm/systemcity/service/userlocation/IUserLocationService.java index df50bf5..aec4c65 100755 --- a/src/main/java/com/cm/systemcity/service/userlocation/IUserLocationService.java +++ b/src/main/java/com/cm/systemcity/service/userlocation/IUserLocationService.java @@ -10,6 +10,7 @@ import com.cm.plugin.map.pojo.dto.GridDTO; import com.cm.systemcity.pojo.dtos.userlocation.UserLocationDTO; import com.cm.systemcity.pojo.dtos.userlocation.UserSignLocationDTO; import com.cm.systemcity.pojo.dtos.userpoints.UserAndPointsDTO; +import com.cm.systemcity.pojo.pos.userlocation.UserLocationPO; import java.util.List; import java.util.Map; @@ -290,4 +291,6 @@ public interface IUserLocationService { * @return */ List> listUserByIds(Map params); + + List listUserLocationPOByUserIdAndDate(String communityBossUserId, String date); } diff --git a/src/main/java/com/cm/systemcity/service/userlocation/impl/UserLocationServiceImpl.java b/src/main/java/com/cm/systemcity/service/userlocation/impl/UserLocationServiceImpl.java index d37bb8d..b20308e 100755 --- a/src/main/java/com/cm/systemcity/service/userlocation/impl/UserLocationServiceImpl.java +++ b/src/main/java/com/cm/systemcity/service/userlocation/impl/UserLocationServiceImpl.java @@ -3,6 +3,7 @@ package com.cm.systemcity.service.userlocation.impl; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.cm.common.component.SecurityComponent; +import com.cm.common.constants.ISystemConstant; import com.cm.common.exception.*; import com.cm.common.plugin.oauth.service.user.IUserService; import com.cm.common.pojo.ListPage; @@ -36,6 +37,7 @@ import com.cm.systemcity.pojo.dtos.userpoints.UserDTO; import com.cm.systemcity.pojo.dtos.usersignin.UserSigninDTO; import com.cm.systemcity.pojo.dtos.usersignout.UserSignoutDTO; import com.cm.systemcity.pojo.pos.communityboss.CommunityBossPO; +import com.cm.systemcity.pojo.pos.userlocation.UserLocationPO; import com.cm.systemcity.service.BaseService; import com.cm.systemcity.service.bossleader.IBossLeaderService; import com.cm.systemcity.service.community.ICommunityService; @@ -49,6 +51,7 @@ import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.apache.commons.lang3.StringUtils; import org.joda.time.DateTime; +import org.joda.time.LocalDateTime; import org.joda.time.format.DateTimeFormat; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -257,7 +260,7 @@ public class UserLocationServiceImpl extends BaseService implements IUserLocatio Map config = CacheManager.getInstance().getConfig(); String startTime = Objects.isNull(params.get("startTime")) ? String.format("%s %s", today, "09:00:00") : params.get("startTime").toString(); String endTime = Objects.isNull(params.get("endTime")) ? String.format("%s %s", today, "18:00:00") : params.get("endTime").toString(); - if(today.equals(startTime.substring(0, 10))){ + if (today.equals(startTime.substring(0, 10))) { params.put("today", null); } if (!isStartAndEndTimeParams(startTime, endTime, params)) { @@ -500,15 +503,15 @@ public class UserLocationServiceImpl extends BaseService implements IUserLocatio List userIds = new ArrayList<>(); String roleId = "bc405346-8714-4ded-89ac-9cc4d755f66a"; List> nPeopleList = communityBossService.listNPeopleByRoleId(roleId); - if(nPeopleList != null && nPeopleList.size() > 0){ - for (Map item : nPeopleList){ + if (nPeopleList != null && nPeopleList.size() > 0) { + for (Map item : nPeopleList) { userIds.add(item.get("userId").toString()); } } params.put("communityBossLevel", "4"); List communityBossDTOS = communityBossService.listCommunityBossV2(params); - if(communityBossDTOS != null && communityBossDTOS.size() > 0){ - for (CommunityBossDTO item : communityBossDTOS){ + if (communityBossDTOS != null && communityBossDTOS.size() > 0) { + for (CommunityBossDTO item : communityBossDTOS) { userIds.add(item.getCommunityBossUserId()); } } @@ -519,7 +522,7 @@ public class UserLocationServiceImpl extends BaseService implements IUserLocatio params.put("startTime", DateUtil.getDay()); // "2022-09-22" List userSigninDTOS = userSigninService.listUserSignin(params); List signInUserList = new ArrayList<>(); - for(UserSigninDTO item : userSigninDTOS){ + for (UserSigninDTO item : userSigninDTOS) { UserDTO user = new UserDTO(); user.setUserId(item.getCreator()); user.setUserName(item.getUserName()); @@ -529,15 +532,15 @@ public class UserLocationServiceImpl extends BaseService implements IUserLocatio res.setUnSignInUsers(signInUserList); // 未签到人员列表 List unSignInUserList = new ArrayList<>(); - for(String userId : userIds){ + for (String userId : userIds) { String flag = "0"; - for(UserDTO item : signInUserList){ - if(userId.equals(item.getUserId())){ + for (UserDTO item : signInUserList) { + if (userId.equals(item.getUserId())) { flag = "1"; break; } } - if("0".equals(flag)){ + if ("0".equals(flag)) { Map userInfo = userLocationDao.getUserInfoById(userId); UserDTO user = new UserDTO(); user.setUserId(userId); @@ -547,7 +550,7 @@ public class UserLocationServiceImpl extends BaseService implements IUserLocatio params.put("userId", user.getUserId()); params.put("nowTime", DateUtil.getTime()); LeaveDTO leave = leaveService.getLeave(params); - if(leave != null && leave.getLeaveState() == 1){ + if (leave != null && leave.getLeaveState() == 1) { user.setUserName(user.getUserName() + "【已请假】"); } unSignInUserList.add(user); @@ -556,7 +559,7 @@ public class UserLocationServiceImpl extends BaseService implements IUserLocatio res.setUnSignOutUsers(unSignInUserList); // 人员定位列表 List workingUserList = new ArrayList<>(); - for(UserSigninDTO item : userSigninDTOS){ + for (UserSigninDTO item : userSigninDTOS) { UserLocationDTO userLocationDTO = new UserLocationDTO(); userLocationDTO.setCreator(item.getCreator()); userLocationDTO.setUserName(item.getUserName()); @@ -576,9 +579,7 @@ public class UserLocationServiceImpl extends BaseService implements IUserLocatio @Deprecated public List listOnlineUserLastLocationOld(Map params) throws SearchException { // 如果有关键字检索 - if (params.get("keywords") != null && !StringUtils.isBlank(params.get("keywords").toString()) || - params.get("startTime") != null && !StringUtils.isBlank(params.get("startTime").toString()) || - params.get("endTime") != null && !StringUtils.isBlank(params.get("endTime").toString())) { + if (params.get("keywords") != null && !StringUtils.isBlank(params.get("keywords").toString()) || params.get("startTime") != null && !StringUtils.isBlank(params.get("startTime").toString()) || params.get("endTime") != null && !StringUtils.isBlank(params.get("endTime").toString())) { return listUserLastLocation(params); } List appTokenUsers = AppTokenManager.getInstance().listCurrentUsers(); @@ -805,7 +806,7 @@ public class UserLocationServiceImpl extends BaseService implements IUserLocatio } // 得到用户列表 List userIds = listGridUserIds(relationIdList); - if(userIds == null || userIds.size() == 0){ + if (userIds == null || userIds.size() == 0) { return new HashMap<>(0); } String currentUserId = userIds.get(0); @@ -818,13 +819,13 @@ public class UserLocationServiceImpl extends BaseService implements IUserLocatio userCardInfo.put("userAvatar", sysUserInfo.get("user_avatar") == null ? "" : sysUserInfo.get("user_avatar").toString()); CommunityBossDTO communityBoss = communityBossService.getCommunityBoss(params); // 专管员 - if(communityBoss == null){ + if (communityBoss == null) { userCardInfo.put("userType", "1"); List> deptList = bindDao.getDepartmentInfoByUserId(sysUserInfo.get("user_id").toString()); String departmentNames = ""; userCardInfo.put("departmentName", departmentNames); - for(Map deptItem : deptList){ - if("".equals(departmentNames)){ + for (Map deptItem : deptList) { + if ("".equals(departmentNames)) { departmentNames += deptItem.get("department_name").toString(); } else { departmentNames += "," + deptItem.get("department_name").toString(); @@ -836,14 +837,14 @@ public class UserLocationServiceImpl extends BaseService implements IUserLocatio userCardInfo.put("roleSummary", roleInfo.get("role_summary").toString()); } // 网格员 - if(communityBoss != null){ + if (communityBoss != null) { userCardInfo.put("userType", "2"); userCardInfo.put("areaName", communityBoss.getAreaName()); userCardInfo.put("communityName", ""); List communities = communityBoss.getCommunities(); String communityNames = ""; - for(CommunityDTO community : communities){ - if("".equals(communityNames)){ + for (CommunityDTO community : communities) { + if ("".equals(communityNames)) { communityNames += community.getCommunityName(); } else { communityNames += "," + community.getCommunityName(); @@ -938,12 +939,12 @@ public class UserLocationServiceImpl extends BaseService implements IUserLocatio List relationArray = new ArrayList<>(); relationArray.add(userId); List gridDTOS = gridDao.listGridByRelationIds(relationArray); - for(GridDTO item : gridDTOS){ + for (GridDTO item : gridDTOS) { List gridPointArray = new ArrayList<>(); queryMap.clear(); queryMap.put("gridId", item.getGridId()); List areaPointsList = userPointsDao.listPointByGridId(queryMap); - for(AreaPointsDTO point : areaPointsList){ + for (AreaPointsDTO point : areaPointsList) { GridPointDTO gridPointDTO = new GridPointDTO(); gridPointDTO.setGridId(item.getGridId()); gridPointDTO.setLat(point.getLatitude()); @@ -1067,18 +1068,25 @@ public class UserLocationServiceImpl extends BaseService implements IUserLocatio LOG.debug("无百度地图定位可处理偏移数据"); return new double[]{lng, lat}; } - return new double[]{ - (lngFor6Accuracy * 1000000 + baiduOffsetBO.getLngOffset()) / 1000000, - (latFor6Accuracy * 1000000 + baiduOffsetBO.getLatOffset()) / 1000000 - }; + return new double[]{(lngFor6Accuracy * 1000000 + baiduOffsetBO.getLngOffset()) / 1000000, (latFor6Accuracy * 1000000 + baiduOffsetBO.getLatOffset()) / 1000000}; } @Override public List> listUserByIds(Map params) { - if(params.get("userIds") == null || params.get("userIds").toString().length() == 0){ + if (params.get("userIds") == null || params.get("userIds").toString().length() == 0) { return new ArrayList<>(); } List> list = userLocationDao.listUserByIds(params); return list; } + + @Override + public List listUserLocationPOByUserIdAndDate(String userId, String date) { + String currentDate = LocalDateTime.now().toString(DateTimeFormat.forPattern(ISystemConstant.DATE_FORMATTER_YYYY_MM_DD)); + Map params = getHashMap(4); + params.put("userId", userId); + params.put("dayDate", date); + params.put("tableSuffix", StringUtils.equals(currentDate, date) ? "" : "_history"); + return userLocationDao.listUserLocationPO(params); + } } \ No newline at end of file diff --git a/src/main/java/com/cm/systemcity/service/usersignin/IUserSigninService.java b/src/main/java/com/cm/systemcity/service/usersignin/IUserSigninService.java index acfbd4d..771f690 100755 --- a/src/main/java/com/cm/systemcity/service/usersignin/IUserSigninService.java +++ b/src/main/java/com/cm/systemcity/service/usersignin/IUserSigninService.java @@ -177,4 +177,6 @@ public interface IUserSigninService { * @return */ SuccessResultList>> listPageGridUserSignIn(ListPage page); + + List listUserSignInByUserIdsAndDay(List userIds, String day); } diff --git a/src/main/java/com/cm/systemcity/service/usersignin/impl/UserSigninServiceImpl.java b/src/main/java/com/cm/systemcity/service/usersignin/impl/UserSigninServiceImpl.java index 6312a32..27542aa 100755 --- a/src/main/java/com/cm/systemcity/service/usersignin/impl/UserSigninServiceImpl.java +++ b/src/main/java/com/cm/systemcity/service/usersignin/impl/UserSigninServiceImpl.java @@ -191,6 +191,14 @@ public class UserSigninServiceImpl extends BaseService implements IUserSigninSer return new SuccessResultList<>(new ArrayList<>(), 0, 0L); } + @Override + public List listUserSignInByUserIdsAndDay(List userIds, String day) { + Map params = getHashMap(2); + params.put("userIds", userIds); + params.put("signTime", day); + return listUserSignin(params); + } + @Override public SuccessResultData getCheckUserSignin(String token, Map params) throws SearchException { UserSigninStatusDTO userSigninStatusDTO = new UserSigninStatusDTO(); diff --git a/src/main/java/com/cm/systemcity/service/usersignout/IUserSignoutService.java b/src/main/java/com/cm/systemcity/service/usersignout/IUserSignoutService.java index d6dcf7f..2ac6702 100755 --- a/src/main/java/com/cm/systemcity/service/usersignout/IUserSignoutService.java +++ b/src/main/java/com/cm/systemcity/service/usersignout/IUserSignoutService.java @@ -154,4 +154,6 @@ public interface IUserSignoutService { * @throws SearchException */ Integer countUserSignout(Map params) throws SearchException; + + List listUserSignOutByUserIdsAndDay(List userIds, String day); } diff --git a/src/main/java/com/cm/systemcity/service/usersignout/impl/UserSignoutServiceImpl.java b/src/main/java/com/cm/systemcity/service/usersignout/impl/UserSignoutServiceImpl.java index 3163f0d..547ea38 100755 --- a/src/main/java/com/cm/systemcity/service/usersignout/impl/UserSignoutServiceImpl.java +++ b/src/main/java/com/cm/systemcity/service/usersignout/impl/UserSignoutServiceImpl.java @@ -257,6 +257,14 @@ public class UserSignoutServiceImpl extends BaseService implements IUserSignoutS return userSignoutDao.countUserSignout(params); } + @Override + public List listUserSignOutByUserIdsAndDay(List userIds, String day) { + Map params = getHashMap(2); + params.put("userIds", userIds); + params.put("signTime", day); + return listUserSignout(params); + } + /** * 检查用户是否签到 * diff --git a/src/main/java/com/cm/systemcity/utils/KpiUtil.java b/src/main/java/com/cm/systemcity/utils/KpiUtil.java new file mode 100644 index 0000000..cd56e3c --- /dev/null +++ b/src/main/java/com/cm/systemcity/utils/KpiUtil.java @@ -0,0 +1,89 @@ +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; + } + +} diff --git a/src/main/resources/mybatis/mapper/kpi/kpi-mapper.xml b/src/main/resources/mybatis/mapper/kpi/kpi-mapper.xml new file mode 100644 index 0000000..0f37265 --- /dev/null +++ b/src/main/resources/mybatis/mapper/kpi/kpi-mapper.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + + + INSERT INTO kpi_community_boss_${level}_day_count( + user_id, + day_date, + is_signin, + is_signin_late, + is_signout, + is_signout_early, + work_distance, + save_population_count, + update_population_count + ) VALUES ( + #{userId}, + #{dayDate}, + #{isSignin}, + #{isSigninLate}, + #{isSignout}, + #{isSignoutEarly}, + #{workDistance}, + #{savePopulationCount}, + #{updatePopulationCount} + ) + + + + + DELETE FROM + kpi_community_boss_${level}_day_count + WHERE + day_date = #{dayDate} + + + + + UPDATE + kpi_community_boss_${level}_day_count + SET + is_signin = #{isSignin}, + is_signin_late = #{isSigninLate}, + is_signout = #{isSignout}, + is_signout_early = #{isSignoutEarly}, + work_distance = #{workDistance}, + save_population_count = #{savePopulationCount}, + update_population_count = #{updatePopulationCount} + WHERE + user_id = #{userId} + AND + day_date = #{dayDate} + + + + + + \ No newline at end of file diff --git a/src/main/resources/mybatis/mapper/userlocation/userlocation-mapper.xml b/src/main/resources/mybatis/mapper/userlocation/userlocation-mapper.xml index 589d652..f06502b 100755 --- a/src/main/resources/mybatis/mapper/userlocation/userlocation-mapper.xml +++ b/src/main/resources/mybatis/mapper/userlocation/userlocation-mapper.xml @@ -15,6 +15,18 @@ + + + + + + + + + + + + @@ -429,4 +441,30 @@ FIND_IN_SET(user_id, #{userIds}) + + + \ No newline at end of file diff --git a/src/main/resources/mybatis/mapper/usersignout/usersignout-mapper.xml b/src/main/resources/mybatis/mapper/usersignout/usersignout-mapper.xml index b8c3458..aac5084 100755 --- a/src/main/resources/mybatis/mapper/usersignout/usersignout-mapper.xml +++ b/src/main/resources/mybatis/mapper/usersignout/usersignout-mapper.xml @@ -169,6 +169,13 @@ #{userSignoutIds[${index}]} + + AND + t1.creator IN + + #{userIds[${index}]} + + ORDER BY t1.gmt_create DESC