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