北斗定位
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.

88 lines
2.4KB

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