package com.rj.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.rj.entity.QweiUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface QweiUserMapper extends BaseMapper<QweiUser> {

    @InterceptorIgnore(tenantLine = "1")
    @Select("""
            SELECT id, tenant_id, userid, user_name, mobile, email, biz_email, telephone, position, gender, status,
                   main_department_id, department_ids_json, alias_name, avatar, thumb_avatar, address,
                   is_deleted, created_at, updated_at
            FROM qwei_user
            WHERE userid = #{userid}
            LIMIT 1
            """)
    QweiUser selectByUseridIgnoreTenant(@Param("userid") String userid);

    @InterceptorIgnore(tenantLine = "1")
    @Update("""
            UPDATE qwei_user
            SET tenant_id = #{tenantId},
                user_name = #{userName},
                mobile = #{mobile},
                email = #{email},
                biz_email = #{bizEmail},
                telephone = #{telephone},
                position = #{position},
                gender = #{gender},
                status = #{status},
                main_department_id = #{mainDepartmentId},
                department_ids_json = #{departmentIdsJson},
                alias_name = #{aliasName},
                avatar = #{avatar},
                thumb_avatar = #{thumbAvatar},
                address = #{address},
                is_deleted = #{isDeleted},
                updated_at = #{updatedAt}
            WHERE id = #{id}
            """)
    int updateLegacyTenantAndFieldsByIdIgnoreTenant(@Param("id") String id,
                                                    @Param("tenantId") String tenantId,
                                                    @Param("userName") String userName,
                                                    @Param("mobile") String mobile,
                                                    @Param("email") String email,
                                                    @Param("bizEmail") String bizEmail,
                                                    @Param("telephone") String telephone,
                                                    @Param("position") String position,
                                                    @Param("gender") Integer gender,
                                                    @Param("status") Integer status,
                                                    @Param("mainDepartmentId") Long mainDepartmentId,
                                                    @Param("departmentIdsJson") String departmentIdsJson,
                                                    @Param("aliasName") String aliasName,
                                                    @Param("avatar") String avatar,
                                                    @Param("thumbAvatar") String thumbAvatar,
                                                    @Param("address") String address,
                                                    @Param("isDeleted") Integer isDeleted,
                                                    @Param("updatedAt") java.time.LocalDateTime updatedAt);
}

