package com.hr.repository.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hr.repository.domain.IpInterfacePO;
import com.hr.repository.domain.IpLogPO;
import com.hr.repository.jpa.IpLogRepository;
import com.hr.repository.service.IpLogService;
import com.hr.vo.IpLogVO;
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;

/**
 * 接口日志表;(ip_log)表服务接口实现类
 * @author : http://www.yonsum.com
 * @date : 2025-10-10
 */
@Service
public class IpLogServiceImpl implements IpLogService {
    @Autowired
    private IpLogRepository ipLogRepository;

     /**
      * 通过ID查询单条数据
      *
      * @param lid 主键
      * @return 实例对象
      */
     @Override
     public IpLogVO queryById(Long lid) {
         IpLogVO vo = new IpLogVO();
         IpLogPO ipLogPO = ipLogRepository.queryById(lid);
         if(ipLogPO != null){
             BeanUtils.copyProperties(ipLogPO,vo);
             return vo;
         }

         return null;
     }

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

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