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);
|
}
|
}
|