RoleMapper.java 1.54 KB
package com.uccc.admin.mapper;

import com.uccc.admin.domain.Role;
import com.uccc.pretty.common.User;
import org.apache.ibatis.annotations.*;

/**
 * Created by bert on 2021-09-13 22:23
 */
public interface RoleMapper {
    static final String TABLE_NAME_1 = "user_role";
    static final String TABLE_NAME_2 = "roles";

    @Insert({
            "<script>",
            "insert into user_role (",
            "role_id, user_id, cts, uts ) values (",
            "#{roleId}, #{userId}, now(), now() )",
            "</script>",
    })
    int createUserRole(@Param("userId") Long userId, @Param("roleId") int roleId);

    @Delete("delete from " + TABLE_NAME_1 + " where user_id = #{user.id}")
    int deleteUserRole(@Param("user") User user);

    @Select({
            "<script>",
            "select count(id) from " + TABLE_NAME_2,
            "where name = #{name}",
            "</script>"
    })
    int selectCountByName(@Param("name") String name);

    @Insert({
            "<script>",
            "insert into " + TABLE_NAME_2,
            "(",
            "name, cts, uts, edit, en_name",
            ")",
            "values",
            "(",
            "#{role.name}, now(), now(), 1, #{role.enName}",
            ")",
            "</script>"
    })
    @Options(useGeneratedKeys = true, keyColumn = "id")
    int createRole(@Param("role") Role role);

    @Select({
            "<script>",
            "select * from " + TABLE_NAME_2,
            "where name = #{name}",
            "</script>",
    })
    Role SelectRoleByName(@Param("name") String name);
}