From 4f015b8c624484e0c3b2d88b944163ce43a48d1f Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期六, 27 十一月 2021 17:15:28 +0800 Subject: [PATCH] 功能完善 --- app/src/main/java/com/yeshi/location/app/controller/client/api/LocationController.java | 136 ++++++++++++++++++++++++++++++++++++--------- 1 files changed, 109 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/com/yeshi/location/app/controller/client/api/LocationController.java b/app/src/main/java/com/yeshi/location/app/controller/client/api/LocationController.java index ee03f12..f063c6c 100644 --- a/app/src/main/java/com/yeshi/location/app/controller/client/api/LocationController.java +++ b/app/src/main/java/com/yeshi/location/app/controller/client/api/LocationController.java @@ -10,22 +10,24 @@ import com.yeshi.location.app.service.inter.location.LocationUsersService; import com.yeshi.location.app.service.inter.location.UserLatestLocationService; import com.yeshi.location.app.service.inter.user.UserInfoService; +import com.yeshi.location.app.service.query.location.LocationTravelQuery; import com.yeshi.location.app.utils.Constant; import com.yeshi.location.app.utils.annotation.UserLogin; import com.yeshi.location.app.vo.AcceptAdminData; import com.yeshi.location.app.vo.AcceptData; +import com.yeshi.location.app.vo.user.SimpleUserInfo; import net.sf.json.JSONObject; import org.springframework.scheduling.support.SimpleTriggerContext; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.yeshi.utils.JsonUtil; +import org.yeshi.utils.StringUtil; +import org.yeshi.utils.TimeUtil; import javax.annotation.Resource; import java.lang.reflect.Type; -import java.util.Arrays; -import java.util.Date; -import java.util.List; +import java.util.*; /** * @author hxh @@ -49,6 +51,7 @@ @Resource private UserInfoService userInfoService; + /** * 涓婁紶浣嶇疆 * @@ -59,7 +62,7 @@ */ @UserLogin(uid = "#uid") - @RequestMapping("getLocation") + @RequestMapping("uploadLocation") @ResponseBody public String uploadLocation(AcceptData acceptData, Long uid, SimpleLocationInfo locationInfo) { @@ -92,7 +95,7 @@ targetUid = uid; } - if (targetUid != uid) { + if (!targetUid.equals(uid)) { LocationUsers users = locationUsersService.selectByUidAndTargetUid(uid, targetUid); if (users == null) { return JsonUtil.loadFalseResult("瀵规柟涓嶆槸鎮ㄧ殑瀹氫綅瀵硅薄"); @@ -101,6 +104,14 @@ } } + Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new JsonSerializer<Date>() { + + @Override + public JsonElement serialize(Date date, Type type, JsonSerializationContext jsonSerializationContext) { + return date == null ? new JsonPrimitive("") : new JsonPrimitive(TimeUtil.getGernalTime(date.getTime(), "yyyy.MM.dd HH:mm:ss")); + } + }).create(); + UserLatestLocation location = userLatestLocationService.get(targetUid); if (location == null) { return JsonUtil.loadFalseResult("灏氭湭鑾峰彇鍒板鏂圭殑浣嶇疆淇℃伅"); @@ -108,7 +119,11 @@ if (location.getUpdateTime() == null) { location.setUpdateTime(location.getCreateTime()); } - return JsonUtil.getApiCommonGson().toJson(location); + + LocationTravelQuery query = new LocationTravelQuery(); + query.setUid(uid); + location.setLocationCount((int) locationTravelService.count(query)); + return JsonUtil.loadTrueResult(gson.toJson(location)); } @@ -125,14 +140,29 @@ @ResponseBody public String getLocationUsers(AcceptData acceptData, Long uid, int page) { - List<LocationUsers> list = locationUsersService.listMyLocationUser(uid, null, page, Constant.PAGE_SIZE); + List<LocationUsers> list = locationUsersService.listMyLocationUser(uid, null, null, page, Constant.PAGE_SIZE); + if (list != null) { + List<Long> uidList = new ArrayList<>(); + for (LocationUsers u : list) { + uidList.add(u.getTargetUid()); + } + + List<UserInfo> userInfoList = userInfoService.list(uidList); + Map<Long, UserInfo> map = new HashMap<>(); + for (UserInfo user : userInfoList) { + map.put(user.getId(), user); + } + + for (LocationUsers users : list) { + if (map.get(users.getTargetUid()) != null) { + users.setUserInfo(SimpleUserInfo.create(map.get(users.getTargetUid()))); + } + } + + + } GsonBuilder gb = new GsonBuilder(); - gb.registerTypeAdapter(LocationUsers.LocationInviteStatus.class, new JsonSerializer<LocationUsers.LocationInviteStatus>() { - public JsonElement serialize(LocationUsers.LocationInviteStatus arg0, Type arg1, JsonSerializationContext arg2) { - return new JsonPrimitive(arg0 == null ? "" : arg0.getDesc()); - } - }).setDateFormat(1); gb.excludeFieldsWithoutExposeAnnotation(); Gson gson = gb.create(); long count = locationUsersService.countMyLocationUser(uid, null); @@ -155,11 +185,16 @@ @UserLogin(uid = "#uid") @RequestMapping("addLocationUser") @ResponseBody - public String addLocationUser(AcceptData acceptData, Long uid, String phone, String name) { + public String addLocationUser(AcceptData acceptData, Long uid, String phone, String name, LocationUsers.LocationUserType type) { - UserInfo user = userInfoService.selectValidByPhone(acceptData.getSystem(), phone); + UserInfo user = null; + if (StringUtil.isMobile(phone)) { + user = userInfoService.selectValidByPhone(acceptData.getSystem(), phone); + } else { + user = userInfoService.get(Long.parseLong(phone)); + } if (user == null) { - return JsonUtil.loadFalseResult("璇ョ數璇濆彿鐮佸皻鏈敞鍐�"); + return JsonUtil.loadFalseResult("璇ョ數璇濆彿鐮�/鐢ㄦ埛ID涓嶅瓨鍦紝璇峰厛娉ㄥ唽"); } LocationUsers locationUsers = locationUsersService.selectByUidAndTargetUid(uid, user.getId()); @@ -180,8 +215,12 @@ } locationUsers = new LocationUsers(); + locationUsers.setUid(uid); locationUsers.setTargetName(name); locationUsers.setTargetUid(user.getId()); + locationUsers.setTargetPhone(user.getPhone()); + + locationUsers.setUserType(type); try { locationUsersService.add(locationUsers); } catch (Exception e) { @@ -214,6 +253,31 @@ return JsonUtil.loadFalseResult("瀹氫綅瀵硅薄涓嶅瓨鍦�"); } locationUsersService.delete(Arrays.asList(new String[]{id})); + return JsonUtil.loadTrueResult(""); + } + + + @UserLogin(uid = "#uid") + @RequestMapping("updateLocationUser") + @ResponseBody + public String updateLocationUser(AcceptData acceptData, Long uid, String id, String phone, LocationUsers.LocationUserType type) { + + LocationUsers users = locationUsersService.get(id); + if (users == null) { + return JsonUtil.loadFalseResult("瀹氫綅瀵硅薄涓嶅瓨鍦�"); + } + + if (users.getUid().longValue() != uid) { + return JsonUtil.loadFalseResult("瀹氫綅瀵硅薄涓嶅瓨鍦�"); + } + LocationUsers update = new LocationUsers(); + update.setId(id); + update.setUserType(type); + if (type != null) { + update.setTargetName(type.getName()); + } + update.setTargetPhone(phone); + locationUsersService.update(update); return JsonUtil.loadTrueResult(""); } @@ -296,8 +360,8 @@ @RequestMapping("getInviteLocation") @ResponseBody public String getInviteLocation(AcceptData acceptData, Long uid) { - List<LocationUsers> list = locationUsersService.listMyLocationUser(uid, LocationUsers.LocationInviteStatus.sentInvite, 1, 1); - if (list != null || list.size() == 0) { + List<LocationUsers> list = locationUsersService.listMyLocationUser(null, uid, LocationUsers.LocationInviteStatus.sentInvite, 1, 1); + if (list == null || list.size() == 0) { return JsonUtil.loadFalseResult("鏆傛棤璁板綍"); } return JsonUtil.loadTrueResult(JsonUtil.getApiCommonGson().toJson(list.get(0))); @@ -314,13 +378,13 @@ @UserLogin(uid = "#uid") @RequestMapping("getTravel") @ResponseBody - public String getTravel(AcceptData acceptData, Long uid, Long targetUid, Long startTime, Long endTime) { + public String getTravel(AcceptData acceptData, Long uid, Long targetUid, Long startTime, Long endTime, int page) { if (targetUid == null) { targetUid = uid; } - if (targetUid != uid) { + if (!targetUid.equals(uid)) { LocationUsers locationUsers = locationUsersService.selectByUidAndTargetUid(uid, targetUid); if (locationUsers == null || locationUsers.getStatus() != LocationUsers.LocationInviteStatus.agree) { return JsonUtil.loadFalseResult("鏆傛棤瀵规柟瀹氫綅鏉冮檺"); @@ -328,15 +392,33 @@ } //鑾峰彇杞ㄨ抗璁板綍 - - //TODO - - - List<LocationUsers> list = locationUsersService.listMyLocationUser(uid, LocationUsers.LocationInviteStatus.sentInvite, 1, 1); - if (list != null || list.size() == 0) { - return JsonUtil.loadFalseResult("鏆傛棤璁板綍"); + List<LocationTravel> locationTravelList = locationTravelService.getTravelList(targetUid, startTime == null ? null : new Date(startTime), endTime == null ? null : new Date(endTime), page, 1); + List<UserLatestLocation> simpleLocationInfoList = new ArrayList<>(); + if (locationTravelList != null) { + for (LocationTravel lt : locationTravelList) { + UserLatestLocation location = new UserLatestLocation(); + location.setLocation(lt.getLocation()); + location.setUpdateTime(lt.getCreateTime()); + location.setUid(targetUid); + location.setLocationCount(1); + simpleLocationInfoList.add(location); + } } - return JsonUtil.loadTrueResult(JsonUtil.getApiCommonGson().toJson(list.get(0))); + + Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new JsonSerializer<Date>() { + + @Override + public JsonElement serialize(Date date, Type type, JsonSerializationContext jsonSerializationContext) { + return date == null ? new JsonPrimitive("") : new JsonPrimitive(TimeUtil.getGernalTime(date.getTime(), "yyyy.MM.dd HH:mm")); + } + }).create(); + + long count = locationTravelService.countTravel(targetUid, startTime == null ? null : new Date(startTime), endTime == null ? null : new Date(endTime)); + JSONObject data = new JSONObject(); + data.put("list", gson.toJson(simpleLocationInfoList)); + data.put("count", count); + + return JsonUtil.loadTrueResult(data); } -- Gitblit v1.8.0