admin
2021-11-19 7511509c68bd2892aad48a0612d497387660214d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package com.yeshi.location.app.service.impl.location;
 
import com.yeshi.location.app.dao.location.LocationTravelDao;
import com.yeshi.location.app.dao.location.LocationTravelDao.DaoQuery;
import com.yeshi.location.app.entity.location.LocationTravel;
import com.yeshi.location.app.entity.location.UserLatestLocation;
import com.yeshi.location.app.service.inter.location.LocationTravelService;
import com.yeshi.location.app.service.inter.location.UserLatestLocationService;
import com.yeshi.location.app.service.query.location.LocationTravelQuery;
import com.yeshi.location.app.utils.GeoUtils;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import org.yeshi.utils.bean.BeanUtil;
 
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
 
@Service
public class LocationTravelServiceImpl implements LocationTravelService {
 
    @Resource
    private LocationTravelDao locationTravelDao;
 
    @Resource
    private UserLatestLocationService userLatestLocationService;
 
    @Override
    public List<LocationTravel> list(LocationTravelQuery locationTravelQuery, int page, int pageSize) {
        DaoQuery daoQuery = new DaoQuery();
        try {
            BeanUtil.copyProperties(locationTravelQuery, daoQuery);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        daoQuery.start = (page - 1) * pageSize;
        daoQuery.count = pageSize;
        daoQuery.sortList= Arrays.asList(new Sort.Order[]{Sort.Order.desc("createTime")});
        return locationTravelDao.list(daoQuery);
    }
 
    @Override
    public long count(LocationTravelQuery locationTravelQuery) {
        DaoQuery daoQuery = new DaoQuery();
        try {
            BeanUtil.copyProperties(locationTravelQuery, daoQuery);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return locationTravelDao.count(daoQuery);
    }
 
    @Override
    public LocationTravel get(String id) {
        Query query = new Query();
        query.addCriteria(Criteria.where("_id").is(id));
        return locationTravelDao.findOne(query);
    }
 
    @Override
    public void add(LocationTravel locationTravel) throws Exception {
 
        if (locationTravel == null || locationTravel.getUid() == null || locationTravel.getLocation() == null) {
            throw new Exception("信息不完整");
        }
 
        if (locationTravel.getCreateTime() == null) {
            locationTravel.setCreateTime(new Date());
        }
 
        if (locationTravel.getId() == null) {
            locationTravel.setId(LocationTravel.createId(locationTravel.getUid(), locationTravel.getCreateTime()));
        }
        //保存
        locationTravelDao.save(locationTravel);
 
 
        UserLatestLocation latest =new UserLatestLocation();
        latest.setLocation(locationTravel.getLocation());
        latest.setUid(locationTravel.getUid());
        userLatestLocationService.add(latest);
    }
 
    @Override
    public void update(LocationTravel locationTravel) {
        //更新
        locationTravelDao.updateSelective(locationTravel);
    }
 
    @Override
    public void delete(List<String> idList) {
        for (String id : idList) {
            locationTravelDao.delete(id);
        }
    }
 
 
}