RelationService.java 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package com.zy.omp.service;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  4. import com.zy.omp.mapper.RelationMapper;
  5. import com.zy.omp.model.Relation;
  6. import org.springframework.stereotype.Service;
  7. import java.util.List;
  8. /**
  9. * 用户设备绑定关系Service
  10. *
  11. * @author chenyi
  12. * Create on 2020/4/10
  13. */
  14. @Service
  15. public class RelationService extends ServiceImpl<RelationMapper, Relation> {
  16. /**
  17. * 查询用户的所有设备
  18. *
  19. * @param openId 用户ID
  20. */
  21. public Relation getDefaultByOpenId(String openId) {
  22. QueryWrapper<Relation> queryWrapper = new QueryWrapper<>();
  23. queryWrapper.eq("openId", openId)
  24. .eq("isDefault", 1);
  25. return baseMapper.selectOne(queryWrapper);
  26. }
  27. /**
  28. * 查询用户的所有设备
  29. *
  30. * @param openId 用户ID
  31. */
  32. public List<Relation> getListByOpenId(String openId) {
  33. QueryWrapper<Relation> queryWrapper = new QueryWrapper<>();
  34. queryWrapper.eq("openId", openId)
  35. .orderByDesc("isDefault", "updateTime");
  36. return baseMapper.selectList(queryWrapper);
  37. }
  38. /**
  39. * 查询设备是否有绑定关系
  40. *
  41. * @param openNum 设备ID
  42. */
  43. public boolean checkBind(String openNum) {
  44. return baseMapper.checkBind(openNum) > 0;
  45. }
  46. /**
  47. * 查询设备是否属于该用户
  48. *
  49. * @param openId 用户ID
  50. * @param openNum 设备ID
  51. */
  52. public boolean checkBelong(String openNum, String openId) {
  53. return baseMapper.checkBelong(openNum, openId) > 0;
  54. }
  55. }