北斗定位
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

74 lines
1.9KB

  1. package com.telpo.dipperposition.service.impl;
  2. import com.telpo.dipperposition.entity.mongo.IPProvinceEntity;
  3. import com.telpo.dipperposition.mapper.IpProvinceMapper;
  4. import com.telpo.dipperposition.service.IpProvinceService;
  5. import lombok.extern.slf4j.Slf4j;
  6. import org.apache.commons.lang3.ObjectUtils;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Service;
  9. import java.util.List;
  10. /**
  11. * @program: DataPushServer
  12. * @description: 推送记录服务接口实现类
  13. * @author: linwl
  14. * @create: 2020-07-20 11:09
  15. */
  16. @Slf4j
  17. @Service
  18. public class IpProvinceServiceImpl implements IpProvinceService {
  19. @Autowired
  20. private IpProvinceMapper ipProvinceMapper;
  21. private static IpProvinceService ipProvinceService;
  22. /**
  23. * spring会自动从ioc容器当中根据IPProvinceService类型找到ipProvinceService,当做参数传进来
  24. *
  25. */
  26. @Override
  27. public void setIPProvinceService(IpProvinceService ipProvinceService) {
  28. this.ipProvinceService = ipProvinceService;
  29. }
  30. @Override
  31. public boolean saveIpProvince(IPProvinceEntity entity) {
  32. ipProvinceMapper.saveIp(entity);
  33. return true;
  34. }
  35. @Override
  36. public boolean updateIPProvince(
  37. IPProvinceEntity query, IPProvinceEntity update) {
  38. ipProvinceMapper.updateIpFirst(query, update);
  39. return true;
  40. }
  41. @Override
  42. public boolean romveById(String id) {
  43. ipProvinceMapper.deleteIpById(id);
  44. return false;
  45. }
  46. @Override
  47. public IPProvinceEntity getIpProvince(String ipAddress) {
  48. try {
  49. IPProvinceEntity query = new IPProvinceEntity();
  50. query.setIp(ipAddress);
  51. List<IPProvinceEntity> pushRecords = ipProvinceMapper.queryIpList(query);
  52. if (ObjectUtils.isNotEmpty(pushRecords)) {
  53. return pushRecords.get(0);
  54. } else {
  55. return null;
  56. }
  57. } catch (Exception e) {
  58. log.error("获取IP省份异常:", e);
  59. return null;
  60. }
  61. }
  62. }