package com.hr.repository.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hr.repository.domain.IpTokenInterfacePO;
import com.hr.repository.domain.IpTokenPO;
import com.hr.repository.jpa.IpTokenRepository;
import com.hr.repository.service.IpTokenService;
import com.hr.vo.IpOrderVO;
import com.hr.vo.IpTokenVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * token表;(ip_token)表服务接口实现类
 * @author : http://www.yonsum.com
 * @date : 2025-10-10
 */
@Service
public class IpTokenServiceImpl implements IpTokenService {
    @Autowired
    private IpTokenRepository ipTokenRepository;
    
    /** 
     * 通过ID查询单条数据 
     *
     * @param id 主键
     * @return 实例对象
     */
    public IpTokenVO queryById(Long id){
        IpTokenPO ipTokenPO = ipTokenRepository.queryById(id);
        IpTokenVO ipOrderVO = new IpTokenVO();
        if(ipTokenPO != null){
            BeanUtils.copyProperties(ipTokenPO, ipOrderVO);
            return ipOrderVO;
        }
        return null;
    }

     @Override
     public Page<IpTokenPO> paginQuery(IpTokenPO ipTokenPO, Integer current, Integer size) {
         ExampleMatcher matcher = ExampleMatcher.matchingAll()
                 .withIgnoreNullValues()                              // 忽略 null 字段
                 .withIgnoreCase();
         Pageable pageAble = PageRequest.of(current, size);
         Example<IpTokenPO> example = Example.of(ipTokenPO, matcher);
         Page<IpTokenPO> result = ipTokenRepository.findAll(example, pageAble);
         return result;
     }

    
    /** 
     * 新增数据
     *
     * @param IpTokenPO 实例对象
     * @return 实例对象
     */
    public void insert(IpTokenPO IpTokenPO){
        ipTokenRepository.save(IpTokenPO);
    }
    
    /** 
     * 更新数据
     *
     * @param IpTokenPO 实例对象
     * @return 实例对象
     */
    public void update(IpTokenPO IpTokenPO){
        ipTokenRepository.save(IpTokenPO);
    }
    
    /** 
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    public boolean deleteById(Long id){
        ipTokenRepository.deleteById(id);
        return true;
    }
}