|
- package com.telpo.dipperposition.service.impl;
-
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.core.collection.CollectionUtil;
- import com.telpo.dipperposition.entity.mongo.ProvinceInfoEntity;
- import com.telpo.dipperposition.mapper.ProvinceInfoMapper;
- import com.telpo.dipperposition.service.IProvinceInfoService;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.ObjectUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.domain.Example;
- import org.springframework.data.domain.Page;
- import org.springframework.data.domain.PageRequest;
- import org.springframework.stereotype.Service;
- import tools.BeanTools;
-
- import java.util.List;
-
- /**
- * @program: DataPushServer
- * @description: 推送记录服务接口实现类
- * @author: linwl
- * @create: 2020-07-20 11:09
- */
- @Slf4j
- @Service
- public class ProvinceInfoServiceImpl implements IProvinceInfoService {
-
- @Autowired
- private ProvinceInfoMapper provinceInfoMapper;
-
-
- @Override
- public boolean saveProvinceInfo(ProvinceInfoEntity entity) {
-
- provinceInfoMapper.save(entity);
- return false;
- }
-
- @Override
- public boolean updateProvinceInfoEntity(ProvinceInfoEntity entity) {
- provinceInfoMapper.save(entity);
- return false;
- }
-
- @Override
- public boolean romveById(String id) {
-
- provinceInfoMapper.deleteById(id);
- return false;
- }
-
- @Override
- public ProvinceInfoEntity getProvinceInfo(String provicne) {
- try {
- ProvinceInfoEntity query = new ProvinceInfoEntity();
- query.setProvince(provicne);
- Example<ProvinceInfoEntity> example = Example.of(query);
- PageRequest pageable = PageRequest.of(0, 1);
- Page<ProvinceInfoEntity> data = provinceInfoMapper.findAll(example, pageable);
- if (CollectionUtil.isNotEmpty(data.getContent())) {
- List<ProvinceInfoEntity> provinceInfos = BeanTools.copyList(data.getContent(), ProvinceInfoEntity.class);
- return provinceInfos.get(0);
- } else {
- return null;
- }
- } catch (Exception e) {
- log.error("获取省份异常:", e);
- return null;
- }
- }
-
- @Override
- public List<ProvinceInfoEntity> getProvinceInfoEntitys() {
- try {
- List<ProvinceInfoEntity> records = provinceInfoMapper.findAll();
- if (ObjectUtils.isNotEmpty(records)) {
- return records;
- } else {
- return null;
- }
- } catch (Exception e) {
- log.error("获取IP省份异常:", e);
- return null;
- }
- }
- }
|