package io.renren.modules.admin.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.renren.modules.admin.entity.EmployeeEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 *
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-02-17 13:38:28
 */
@Mapper
public interface EmployeeDao extends BaseMapper<EmployeeEntity> {
    List<EmployeeEntity> findAllByisDel(int isDel);

    boolean updatePasswordByid(Long id);

//    boolean delete(Long id);

    //多表联查 + 分页
    @Select("select e.id,e.truename,e.username,e.password,e.phone,e.email,e.create_time,e.modify_time,e.is_del,c.companyname,c.id as cid " +
            " from employee e left JOIN company c on e.company_id = c.id" +
            " where e.is_del = 0 AND (e.truename like '%${key}%' or e.username like '%${key2}%') limit #{page},#{limit}")
    List<Map<String,Object>> queryListBykey( String key,String key2 ,int page, int limit);

    @Select("select count(*) from employee where is_del=0 and (truename like '%${key}%' or username like '%${key2}%')")
    Integer queryTotalCount(String key,String key2);
//    IPage<EmployeeEntity> selectMyPage(Page page, Wrapper<EmployeeEntity> queryWrapper);

    /**
     * 根据真实姓名模糊查询
     * @param truename
     * @return
     */
    @Select("select * from employee where truename like '%${truename}%'")
    List<EmployeeEntity> findAllByTrueName(String truename);

    /**
     * 根据真实姓名模糊查询id
     * @param truename
     * @return
     */
    @Select("select id,truename from employee where truename like '%${truename}%'")
    List<Map<String, Object>> selectNameList(String truename);

    @Select("SELECT `id`,`truename` FROM `employee` WHERE `company_id`=#{companyId};")
    List<Map<String, Object>> selectNameListByCompanyId(Long companyId);

    /**
     * 获取联系工作人员联系方式
     */
    @Select("SELECT `id`,`truename`,`phone` FROM `employee` WHERE `id` IN(${ids});")
    List<Map<String, Object>> getContact(String ids);
}