admin
2021-11-22 ec21251764082bebde0f68966332751c288d786c
app/src/main/java/com/yeshi/location/app/service/impl/location/LocationUsersServiceImpl.java
@@ -8,8 +8,11 @@
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;
@@ -20,72 +23,112 @@
import org.springframework.data.mongodb.core.query.Query;
@Service
public class LocationUsersServiceImpl implements LocationUsersService{
public class LocationUsersServiceImpl implements LocationUsersService {
  @Resource
  private LocationUsersDao locationUsersDao;
    @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();
    @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);
    }
    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();
    @Override
    public long count(LocationUsersQuery locationUsersQuery) {
        DaoQuery daoQuery = new DaoQuery();
        try {
            BeanUtil.copyProperties(locationUsersQuery, daoQuery);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return locationUsersDao.count(daoQuery);
    }
    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 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("已存在");
     }
    @Override
    public void add(LocationUsers locationUsers) throws Exception {
     if(locationUsers.getCreateTime()==null){
        locationUsers.setCreateTime(new Date());
     }
     //保存
     locationUsersDao.save(locationUsers);
  }
        if (locationUsers.getId() == null) {
            locationUsers.setId(LocationUsers.createId(locationUsers.getUid(), locationUsers.getTargetUid()));
        }
  @Override
  public void update(LocationUsers locationUsers)  {
     if(locationUsers.getUpdateTime()==null){
        locationUsers.setUpdateTime(new Date());
     }
     //更新
     locationUsersDao.updateSelective(locationUsers);
  }
        //查询主键ID是否存在
        if (locationUsersDao.get(locationUsers.getId()) != null) {
            throw new Exception("已存在");
        }
  @Override
  public void delete(List<String> idList)  {
     for (String id : idList){
        locationUsersDao.delete(id);
     }
  }
        if (locationUsers.getStatus() == null) {
            locationUsers.setStatus(LocationUsers.LocationInviteStatus.sentInvite);
        }
        if (locationUsers.getSentCount() == null) {
            locationUsers.setSentCount(0);
        }
        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);
        }
    }
    @Override
    public List<LocationUsers> listMyLocationUser(Long uid, LocationUsers.LocationInviteStatus status, int page, int pageSize) {
        DaoQuery daoQuery = new DaoQuery();
        daoQuery.start = (page - 1) * pageSize;
        daoQuery.count = pageSize;
        daoQuery.status = status;
        daoQuery.uid = uid;
        return locationUsersDao.list(daoQuery);
    }
    @Override
    public long countMyLocationUser(Long uid, LocationUsers.LocationInviteStatus status) {
        DaoQuery daoQuery = new DaoQuery();
        daoQuery.uid = uid;
        daoQuery.status = status;
        return locationUsersDao.count(daoQuery);
    }
    @Override
    public LocationUsers selectByUidAndTargetUid(Long uid, Long targetUid) {
        DaoQuery daoQuery = new DaoQuery();
        daoQuery.uid = uid;
        daoQuery.targetUid = targetUid;
        daoQuery.count = 1;
        List<LocationUsers> list = locationUsersDao.list(daoQuery);
        return list != null && list.size() > 0 ? list.get(0) : null;
    }
}