admin
2021-11-27 4f015b8c624484e0c3b2d88b944163ce43a48d1f
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
package com.yeshi.location.app.service.impl.sos;
 
import com.yeshi.location.app.dao.sos.SOSRecordListDao;
import com.yeshi.location.app.entity.sos.SOSRecordList;
import com.yeshi.location.app.service.inter.sos.SOSRecordListService;
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 javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
 
/**
 * @author hxh
 * @title: SOSRecordListServiceImpl
 * @description:
 * @date 2021/11/27 10:55
 */
@Service
public class SOSRecordListServiceImpl implements SOSRecordListService {
 
    @Resource
    private SOSRecordListDao sosRecordListDao;
 
 
    @Override
    public void add(SOSRecordList recordList) throws Exception {
        if (recordList == null || recordList.getSourceId() == null || recordList.getUid() == null || recordList.getType() == null) {
            throw new Exception("参数不完整");
        }
 
        if (recordList.getCreateTime() == null) {
            recordList.setCreateTime(new Date());
        }
 
        if (recordList.getId() == null) {
            recordList.setId(SOSRecordList.createId(recordList.getType(), recordList.getSourceId()));
        }
        sosRecordListDao.save(recordList);
    }
 
    @Override
    public List<SOSRecordList> listByUid(Long uid, int page, int pageSize) {
        SOSRecordListDao.DaoQuery daoQuery = new SOSRecordListDao.DaoQuery();
        daoQuery.uid = uid;
        daoQuery.start = (page - 1) * pageSize;
        daoQuery.count = pageSize;
        daoQuery.sortList = Arrays.asList(new Sort.Order[]{Sort.Order.desc("createTime")});
        return sosRecordListDao.list(daoQuery);
    }
 
    @Override
    public long countByUid(Long uid) {
        SOSRecordListDao.DaoQuery daoQuery = new SOSRecordListDao.DaoQuery();
        daoQuery.uid = uid;
        return sosRecordListDao.count(daoQuery);
    }
 
    @Override
    public void deleteAll(Long uid) {
        Query query = new Query();
        query.addCriteria(Criteria.where("uid").is(uid));
        sosRecordListDao.delete(query);
    }
}