package com.yeshi.location.app.service.impl.location;
|
|
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.location.LocationUsersDao;
|
import com.yeshi.location.app.entity.location.LocationUsers;
|
import com.yeshi.location.app.service.inter.location.LocationUsersService;
|
import com.yeshi.location.app.service.query.location.LocationUsersQuery;
|
import com.yeshi.location.app.dao.location.LocationUsersDao.DaoQuery;
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
import org.springframework.data.mongodb.core.query.Query;
|
|
@Service
|
public class LocationUsersServiceImpl implements LocationUsersService{
|
|
@Resource
|
private LocationUsersDao locationUsersDao;
|
|
@Override
|
public List<LocationUsers> list(LocationUsersQuery locationUsersQuery, int page, int pageSize) {
|
DaoQuery daoQuery = new DaoQuery();
|
try {
|
BeanUtil.copyProperties(locationUsersQuery, 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 locationUsersDao.list(daoQuery);
|
}
|
|
@Override
|
public long count(LocationUsersQuery locationUsersQuery) {
|
DaoQuery daoQuery = new DaoQuery();
|
try {
|
BeanUtil.copyProperties(locationUsersQuery, daoQuery);
|
} catch (IllegalAccessException e) {
|
e.printStackTrace();
|
}
|
return locationUsersDao.count(daoQuery);
|
}
|
|
@Override
|
public LocationUsers get(String id) {
|
Query query=new Query();
|
query.addCriteria(Criteria.where("_id").is(id));
|
return locationUsersDao.findOne(query);
|
}
|
|
@Override
|
public void add(LocationUsers locationUsers) throws Exception {
|
//查询主键ID是否存在
|
if(locationUsersDao.get(locationUsers.getId())!=null){
|
throw new Exception("已存在");
|
}
|
|
if(locationUsers.getCreateTime()==null){
|
locationUsers.setCreateTime(new Date());
|
}
|
//保存
|
locationUsersDao.save(locationUsers);
|
}
|
|
@Override
|
public void update(LocationUsers locationUsers) {
|
if(locationUsers.getUpdateTime()==null){
|
locationUsers.setUpdateTime(new Date());
|
}
|
//更新
|
locationUsersDao.updateSelective(locationUsers);
|
}
|
|
@Override
|
public void delete(List<String> idList) {
|
for (String id : idList){
|
locationUsersDao.delete(id);
|
}
|
}
|
|
|
}
|