admin
2021-11-19 7511509c68bd2892aad48a0612d497387660214d
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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);
     }
  }
 
 
}