package org.agt.module.license.dal.mysql.customer;

import org.agt.framework.common.pojo.PageResult;
import org.agt.framework.mybatis.core.mapper.BaseMapperX;
import org.agt.framework.mybatis.core.query.LambdaQueryWrapperX;
import org.agt.module.license.controller.admin.customer.vo.CustomerPageReqVO;
import org.agt.module.license.controller.admin.customer.vo.CustomerRespVO;
import org.agt.module.license.controller.admin.customer.vo.DashboardRespVO;
import org.agt.module.license.dal.dataobject.customer.CustomerDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 客户 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface CustomerMapper extends BaseMapperX<CustomerDO> {

    default PageResult<CustomerDO> selectPage(CustomerPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CustomerDO>()
                .likeIfPresent(CustomerDO::getName, reqVO.getName())
                .likeIfPresent(CustomerDO::getCode, reqVO.getCode())
                .eqIfPresent(CustomerDO::getType, reqVO.getType())
                .eqIfPresent(CustomerDO::getAreaId, reqVO.getAreaId())
                .eqIfPresent(CustomerDO::getContacts, reqVO.getContacts())
                .betweenIfPresent(CustomerDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CustomerDO::getCreateTime));
    }

    default List<CustomerDO> selectList() {
        return selectList(new LambdaQueryWrapperX<CustomerDO>().orderByDesc(CustomerDO::getCreateTime));
    }

    default CustomerDO selectByName(String name) {
        return selectOne(CustomerDO::getName, name);
    }

    default CustomerDO selectByCode(String code) {
        return selectOne(CustomerDO::getCode, code);
    }

    Integer selectMaxCode();

    Long selectUserCount();

    Long getUserByName(@Param("nickname") String nickname);

    Integer selectOldMaxCode();

    List<CustomerRespVO> getLicenseCustomers();

    DashboardRespVO getLicenseCount();

    DashboardRespVO getProjectCount();
}
