package com.clx.performance.dao.impl.borrower;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.clx.performance.dao.borrower.BorrowerConfigDao;
import com.clx.performance.enums.borrower.BorrowerConfigEnum;
import com.clx.performance.enums.borrower.BorrowerEnum;
import com.clx.performance.mapper.borrower.BorrowerConfigMapper;
import com.clx.performance.model.borrower.Borrower;
import com.clx.performance.model.borrower.BorrowerConfig;
import com.clx.performance.param.pc.borrower.PageBorrowerConfigParam;
import com.clx.performance.vo.pc.borrower.BorrowerConfigVO;
import com.clx.performance.vo.pc.borrower.BorrowerVO;
import com.msl.common.base.Optional;
import com.msl.common.dao.impl.BaseDaoImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: aiqinguo
 * @Description: 借款配置
 * @Date: 2024/01/17 13:42:57
 * @Version: 1.0
 */
@Repository
public class BorrowerConfigDaoImpl extends BaseDaoImpl<BorrowerConfigMapper, BorrowerConfig, Integer> implements BorrowerConfigDao {


    @Override
    public boolean update(BorrowerConfig item) {
        return update(lUdWrapper()
                .eq(BorrowerConfig::getId, item.getId())
                .set(BorrowerConfig::getBorrowerId, item.getBorrowerId())
                .set(BorrowerConfig::getBorrowerName, item.getBorrowerName())
                .set(BorrowerConfig::getType, item.getType())
                .set(BorrowerConfig::getDay, item.getDay())

                .set(BorrowerConfig::getOpUserNo, item.getOpUserNo())
                .set(BorrowerConfig::getOpUserName, item.getOpUserName())
                .set(BorrowerConfig::getOpTime, item.getOpTime())
        );
    }

    @Override
    public boolean updateStatus(BorrowerConfig item) {
        return update(lUdWrapper()
                .eq(BorrowerConfig::getId, item.getId())
                .set(BorrowerConfig::getStatus, item.getStatus())

                .set(BorrowerConfig::getOpUserNo, item.getOpUserNo())
                .set(BorrowerConfig::getOpUserName, item.getOpUserName())
                .set(BorrowerConfig::getOpTime, item.getOpTime())
        );
    }

    @Override
    public boolean updateDelete(BorrowerConfig item) {
        return update(lUdWrapper()
                .eq(BorrowerConfig::getId, item.getId())
                .set(BorrowerConfig::getDeleteStatus, item.getDeleteStatus())

                .set(BorrowerConfig::getOpUserNo, item.getOpUserNo())
                .set(BorrowerConfig::getOpUserName, item.getOpUserName())
                .set(BorrowerConfig::getOpTime, item.getOpTime())
        );
    }

    @Override
    public Optional<BorrowerConfig> selectByBorrowerId(Integer borrowerId) {
        return Optional.of(borrowerId)
                .map(item -> lQrWrapper()
                        .eq(BorrowerConfig::getBorrowerId, item)
                        .eq(BorrowerConfig::getDeleteStatus, BorrowerConfigEnum.DeleteStatus.NO.getCode())
                        .last("limit 1")
                )
                .map(super::getOne);
    }

    @Override
    public List<BorrowerConfig> listEnable() {
        return list(lQrWrapper()
                .eq(BorrowerConfig::getDeleteStatus, BorrowerConfigEnum.DeleteStatus.NO.getCode())
                .eq(BorrowerConfig::getStatus, BorrowerConfigEnum.Status.ENABLE.getCode())
        );
    }

    @Override
    public IPage<BorrowerConfigVO> pageByParam(PageBorrowerConfigParam param) {
        Page<BorrowerConfigVO> page = Page.of(param.getPage(), param.getPageSize());
        return baseMapper.pageByParam(page,param);
    }
}
