package com.yd.csf.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yd.csf.feign.request.salary.ApiSalaryPageRequest;
import com.yd.csf.feign.request.salary.ApiSalaryPushPageRequest;
import com.yd.csf.feign.response.salary.ApiSalaryPageResponse;
import com.yd.csf.feign.response.salary.ApiSalaryPushPageResponse;
import com.yd.csf.service.model.Salary;
import com.yd.csf.service.dao.SalaryMapper;
import com.yd.csf.service.service.ISalaryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 薪资单表 服务实现类
 * </p>
 *
 * @author zxm
 * @since 2026-05-08
 */
@Service
public class SalaryServiceImpl extends ServiceImpl<SalaryMapper, Salary> implements ISalaryService {

    @Override
    public IPage<ApiSalaryPageResponse> page(Page<ApiSalaryPageResponse> page,
                                             ApiSalaryPageRequest request) {
        return this.baseMapper.page(page,request);
    }

    @Override
    public IPage<ApiSalaryPushPageResponse> pushPage(Page<ApiSalaryPushPageResponse> page,
                                                     ApiSalaryPushPageRequest request) {
        return this.baseMapper.pushPage(page,request);
    }

    @Override
    public Salary queryOne(String brokerBizId, String month,
                           String salaryBizId,Boolean isExcludeMy) {
        return this.baseMapper.selectOne(new LambdaQueryWrapper<Salary>()
                .eq(Salary::getBrokerBizId,brokerBizId)
                .eq(Salary::getMonth,month)
                .ne(isExcludeMy,Salary::getSalaryBizId,salaryBizId)
                .last(" limit 1 ")
        );
    }

    @Override
    public Salary queryOne(String salaryBizId) {
        return this.baseMapper.selectOne(new LambdaQueryWrapper<Salary>()
                .eq(Salary::getSalaryBizId,salaryBizId)
                .last(" limit 1 ")
        );
    }
}
