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.csfclientuser.ApiCsfClientUserPageRequest;
import com.yd.csf.feign.response.csfclientuser.ApiCsfClientUserPageResponse;
import com.yd.csf.service.dto.query.QueryCsfClientUserDTO;
import com.yd.csf.service.model.CsfClientUser;
import com.yd.csf.service.dao.CsfClientUserMapper;
import com.yd.csf.service.service.ICsfClientUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * CSF客户端用户表（中台客户端用户表的项目扩展表） 服务实现类
 * </p>
 *
 * @author zxm
 * @since 2026-06-11
 */
@Service
public class CsfClientUserServiceImpl extends ServiceImpl<CsfClientUserMapper, CsfClientUser> implements ICsfClientUserService {

    @Override
    public IPage<ApiCsfClientUserPageResponse> iPage(Page<ApiCsfClientUserPageResponse> page,
                                                     ApiCsfClientUserPageRequest request) {
        return this.baseMapper.page(page,request);
    }

    @Override
    public List<CsfClientUser> queryList(QueryCsfClientUserDTO userDTO) {
        return this.baseMapper.selectList(new LambdaQueryWrapper<CsfClientUser>()
                .eq(StringUtils.isNotBlank(userDTO.getPhone()),CsfClientUser::getPhone,userDTO.getPhone())
                .ne(userDTO.getIsMy(),CsfClientUser::getCsfClientUserBizId,userDTO.getCsfClientUserBizId())
        );
    }

    @Override
    public CsfClientUser queryOne(String csfClientUserBizId) {
        return this.getOne(new LambdaQueryWrapper<CsfClientUser>()
                .eq(CsfClientUser::getCsfClientUserBizId,csfClientUserBizId)
                .last(" limit 1 ")
        );
    }
}
