package com.rj.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.rj.entity.QweiDepartment;
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 QweiDepartmentMapper extends BaseMapper<QweiDepartment> {

    @InterceptorIgnore(tenantLine = "1")
    @Select("""
            SELECT id, tenant_id, dept_id, dept_name, parent_dept_id, order_num, is_deleted, created_at, updated_at
            FROM qwei_department
            WHERE dept_id = #{deptId}
            LIMIT 1
            """)
    QweiDepartment selectByDeptIdIgnoreTenant(@Param("deptId") Long deptId);

    @InterceptorIgnore(tenantLine = "1")
    @Update("""
            UPDATE qwei_department
            SET tenant_id = #{tenantId},
                dept_name = #{deptName},
                parent_dept_id = #{parentDeptId},
                order_num = #{orderNum},
                is_deleted = #{isDeleted},
                updated_at = #{updatedAt}
            WHERE id = #{id}
            """)
    int updateLegacyTenantAndFieldsByIdIgnoreTenant(@Param("id") String id,
                                                    @Param("tenantId") String tenantId,
                                                    @Param("deptName") String deptName,
                                                    @Param("parentDeptId") Long parentDeptId,
                                                    @Param("orderNum") Integer orderNum,
                                                    @Param("isDeleted") Integer isDeleted,
                                                    @Param("updatedAt") java.time.LocalDateTime updatedAt);
}

