package com.yeshi.location.app.service.impl.sos;
|
|
import java.lang.Exception;
|
import javax.annotation.Resource;
|
|
import org.springframework.data.domain.Sort;
|
import org.springframework.stereotype.Service;
|
|
import java.util.Arrays;
|
import java.util.Date;
|
|
import org.yeshi.utils.bean.BeanUtil;
|
|
import java.util.List;
|
|
import com.yeshi.location.app.dao.sos.SOSRecordDao;
|
import com.yeshi.location.app.entity.sos.SOSRecord;
|
import com.yeshi.location.app.service.inter.sos.SOSRecordService;
|
import com.yeshi.location.app.service.query.sos.SOSRecordQuery;
|
import com.yeshi.location.app.dao.sos.SOSRecordDao.DaoQuery;
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
import org.springframework.data.mongodb.core.query.Query;
|
|
@Service
|
public class SOSRecordServiceImpl implements SOSRecordService {
|
|
@Resource
|
private SOSRecordDao sOSRecordDao;
|
|
@Override
|
public List<SOSRecord> list(SOSRecordQuery sOSRecordQuery, int page, int pageSize) {
|
DaoQuery daoQuery = new DaoQuery();
|
try {
|
BeanUtil.copyProperties(sOSRecordQuery, 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 sOSRecordDao.list(daoQuery);
|
}
|
|
@Override
|
public long count(SOSRecordQuery sOSRecordQuery) {
|
DaoQuery daoQuery = new DaoQuery();
|
try {
|
BeanUtil.copyProperties(sOSRecordQuery, daoQuery);
|
} catch (IllegalAccessException e) {
|
e.printStackTrace();
|
}
|
return sOSRecordDao.count(daoQuery);
|
}
|
|
@Override
|
public SOSRecord get(String id) {
|
Query query = new Query();
|
query.addCriteria(Criteria.where("_id").is(id));
|
return sOSRecordDao.findOne(query);
|
}
|
|
@Override
|
public void add(SOSRecord sOSRecord) throws Exception {
|
//查询主键ID是否存在
|
if (sOSRecordDao.get(sOSRecord.getId()) != null) {
|
throw new Exception("已存在");
|
}
|
|
if (sOSRecord.getCreateTime() == null) {
|
sOSRecord.setCreateTime(new Date());
|
}
|
//保存
|
sOSRecordDao.save(sOSRecord);
|
}
|
|
@Override
|
public void update(SOSRecord sOSRecord) {
|
if (sOSRecord.getUpdateTime() == null) {
|
sOSRecord.setUpdateTime(new Date());
|
}
|
//更新
|
sOSRecordDao.updateSelective(sOSRecord);
|
}
|
|
@Override
|
public void delete(List<String> idList) {
|
for (String id : idList) {
|
sOSRecordDao.delete(id);
|
}
|
}
|
|
|
}
|