| | |
| | | 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 |
| | |
| | | @Resource |
| | | private UserInfoService userInfoService; |
| | | |
| | | |
| | | /** |
| | | * 上传位置 |
| | | * |
| | |
| | | */ |
| | | |
| | | @UserLogin(uid = "#uid") |
| | | @RequestMapping("getLocation") |
| | | @RequestMapping("uploadLocation") |
| | | @ResponseBody |
| | | public String uploadLocation(AcceptData acceptData, Long uid, SimpleLocationInfo locationInfo) { |
| | | |
| | |
| | | targetUid = uid; |
| | | } |
| | | |
| | | if (targetUid != uid) { |
| | | if (!targetUid.equals(uid)) { |
| | | LocationUsers users = locationUsersService.selectByUidAndTargetUid(uid, targetUid); |
| | | if (users == null) { |
| | | return JsonUtil.loadFalseResult("对方不是您的定位对象"); |
| | |
| | | } |
| | | } |
| | | |
| | | 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("尚未获取到对方的位置信息"); |
| | |
| | | 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)); |
| | | } |
| | | |
| | | |
| | |
| | | @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); |
| | |
| | | @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()); |
| | |
| | | } |
| | | |
| | | 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) { |
| | |
| | | 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(""); |
| | | } |
| | | |
| | |
| | | @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))); |
| | |
| | | @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("暂无对方定位权限"); |
| | |
| | | } |
| | | |
| | | //获取轨迹记录 |
| | | |
| | | //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); |
| | | } |
| | | |
| | | |