北斗定位
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.5KB

  1. package com.telpo.dipperposition.service.impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.collection.CollectionUtil;
  4. import com.telpo.dipperposition.entity.mongo.IpProvinceEntity;
  5. import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity;
  6. import com.telpo.dipperposition.mapper.ProvinceInfoMapper;
  7. import com.telpo.dipperposition.service.IProvinceInfoService;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.apache.commons.lang3.ObjectUtils;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.data.domain.Example;
  12. import org.springframework.data.domain.Page;
  13. import org.springframework.data.domain.PageRequest;
  14. import org.springframework.stereotype.Service;
  15. import tools.BeanTools;
  16. import java.util.List;
  17. import java.util.Optional;
  18. /**
  19. * @program: DataPushServer
  20. * @description: 推送记录服务接口实现类
  21. * @author: linwl
  22. * @create: 2020-07-20 11:09
  23. */
  24. @Slf4j
  25. @Service
  26. public class ProvinceInfoServiceImpl implements IProvinceInfoService {
  27. @Autowired
  28. private ProvinceInfoMapper provinceInfoMapper;
  29. @Override
  30. public boolean saveProvinceInfo(ProvinceInfoEntity entity) {
  31. provinceInfoMapper.save(entity);
  32. return false;
  33. }
  34. @Override
  35. public boolean updateProvinceInfoEntity(ProvinceInfoEntity entity) {
  36. provinceInfoMapper.save(entity);
  37. return false;
  38. }
  39. @Override
  40. public boolean romveById(String id) {
  41. provinceInfoMapper.deleteById(id);
  42. return false;
  43. }
  44. @Override
  45. public ProvinceInfoEntity getProvinceInfo(String provicne) {
  46. try {
  47. ProvinceInfoEntity query = new ProvinceInfoEntity();
  48. query.setProvince(provicne);
  49. Example<ProvinceInfoEntity> example = Example.of(query);
  50. PageRequest pageable = PageRequest.of(0, 1);
  51. Page<ProvinceInfoEntity> data = provinceInfoMapper.findAll(example, pageable);
  52. if (CollectionUtil.isNotEmpty(data.getContent())) {
  53. List<ProvinceInfoEntity> records = BeanTools.copyList(data.getContent(), ProvinceInfoEntity.class);
  54. return records.get(0);
  55. } else {
  56. return null;
  57. }
  58. } catch (Exception e) {
  59. log.error("获取省份异常:", e);
  60. return null;
  61. }
  62. }
  63. @Override
  64. public List<ProvinceInfoEntity> getProvinceInfoEntitys() {
  65. try {
  66. List<ProvinceInfoEntity> records = provinceInfoMapper.findAll();
  67. if (ObjectUtils.isNotEmpty(records)) {
  68. return records;
  69. } else {
  70. return null;
  71. }
  72. } catch (Exception e) {
  73. log.error("获取IP省份异常:", e);
  74. return null;
  75. }
  76. }
  77. }