master
parent
d73cc53ac3
commit
048de5eeba
|
|
@ -0,0 +1,45 @@
|
|||
package com.boot.security.server.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import com.boot.security.server.model.Permission;
|
||||
|
||||
@Mapper
|
||||
public interface PermissionDao {
|
||||
|
||||
@Select("select * from sys_permission t order by t.sort")
|
||||
List<Permission> listAll();
|
||||
|
||||
@Select("select * from sys_permission t where t.type = 1 order by t.sort")
|
||||
List<Permission> listParents();
|
||||
|
||||
@Select("select distinct p.* from sys_permission p inner join sys_role_permission rp on p.id = rp.permissionId inner join sys_role_user ru on ru.roleId = rp.roleId where ru.userId = #{userId} order by p.sort")
|
||||
List<Permission> listByUserId(Long userId);
|
||||
|
||||
@Select("select p.* from sys_permission p inner join sys_role_permission rp on p.id = rp.permissionId where rp.roleId = #{roleId} order by p.sort")
|
||||
List<Permission> listByRoleId(Long roleId);
|
||||
|
||||
@Select("select * from sys_permission t where t.id = #{id}")
|
||||
Permission getById(Long id);
|
||||
|
||||
@Insert("insert into sys_permission(parentId, name, css, href, type, permission, sort) values(#{parentId}, #{name}, #{css}, #{href}, #{type}, #{permission}, #{sort})")
|
||||
int save(Permission permission);
|
||||
|
||||
@Update("update sys_permission t set parentId = #{parentId}, name = #{name}, css = #{css}, href = #{href}, type = #{type}, permission = #{permission}, sort = #{sort} where t.id = #{id}")
|
||||
int update(Permission permission);
|
||||
|
||||
@Delete("delete from sys_permission where id = #{id}")
|
||||
int delete(Long id);
|
||||
|
||||
@Delete("delete from sys_permission where parentId = #{id}")
|
||||
int deleteByParentId(Long id);
|
||||
|
||||
@Delete("delete from sys_role_permission where permissionId = #{permissionId}")
|
||||
int deleteRolePermission(Long permissionId);
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package com.boot.security.server.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Options;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import com.boot.security.server.model.Role;
|
||||
|
||||
@Mapper
|
||||
public interface RoleDao {
|
||||
|
||||
@Options(useGeneratedKeys = true, keyProperty = "id")
|
||||
@Insert("insert into sys_role(name, description, createTime, updateTime) values(#{name}, #{description}, now(),now())")
|
||||
int save(Role role);
|
||||
|
||||
int count(@Param("params") Map<String, Object> params);
|
||||
|
||||
List<Role> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset,
|
||||
@Param("limit") Integer limit);
|
||||
|
||||
@Select("select * from sys_role t where t.id = #{id}")
|
||||
Role getById(Long id);
|
||||
|
||||
@Select("select * from sys_role t where t.name = #{name}")
|
||||
Role getRole(String name);
|
||||
|
||||
@Update("update sys_role t set t.name = #{name}, t.description = #{description}, updateTime = now() where t.id = #{id}")
|
||||
int update(Role role);
|
||||
|
||||
@Select("select * from sys_role r inner join sys_role_user ru on r.id = ru.roleId where ru.userId = #{userId}")
|
||||
List<Role> listByUserId(Long userId);
|
||||
|
||||
@Delete("delete from sys_role_permission where roleId = #{roleId}")
|
||||
int deleteRolePermission(Long roleId);
|
||||
|
||||
int saveRolePermission(@Param("roleId") Long roleId, @Param("permissionIds") List<Long> permissionIds);
|
||||
|
||||
@Delete("delete from sys_role where id = #{id}")
|
||||
int delete(Long id);
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package com.boot.security.server.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Options;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import com.boot.security.server.model.User;
|
||||
|
||||
@Mapper
|
||||
public interface UserDao {
|
||||
|
||||
@Options(useGeneratedKeys = true, keyProperty = "id")
|
||||
@Insert("insert into sys_user(username, password, salt, nickname, headImgUrl, phone, telephone, email, birthday, sex, status, intro, createTime, updateTime) values(#{username}, #{password}, #{salt}, #{nickname}, #{headImgUrl}, #{phone}, #{telephone}, #{email}, #{birthday}, #{sex}, #{status}, #{intro}, now(), now())")
|
||||
int save(User user);
|
||||
|
||||
@Select("select * from sys_user t where t.id = #{id}")
|
||||
User getById(Long id);
|
||||
|
||||
@Select("select * from sys_user t where t.username = #{username}")
|
||||
User getUser(String username);
|
||||
|
||||
@Update("update sys_user t set t.password = #{password} where t.id = #{id}")
|
||||
int changePassword(@Param("id") Long id, @Param("password") String password);
|
||||
|
||||
Integer count(@Param("params") Map<String, Object> params);
|
||||
|
||||
List<User> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset,
|
||||
@Param("limit") Integer limit);
|
||||
|
||||
@Delete("delete from sys_role_user where userId = #{userId}")
|
||||
int deleteUserRole(Long userId);
|
||||
|
||||
int saveUserRoles(@Param("userId") Long userId, @Param("roleIds") List<Long> roleIds);
|
||||
|
||||
int update(User user);
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.zw.admin.server.dao.RoleDao">
|
||||
|
||||
<sql id="where">
|
||||
<where>
|
||||
<if test="params.name != null and params.name != ''">
|
||||
and t.name like concat('%', #{params.name}, '%')
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<select id="count" resultType="int">
|
||||
select count(1) from sys_role t
|
||||
<include refid="where" />
|
||||
</select>
|
||||
|
||||
<select id="list" resultType="Role">
|
||||
select * from sys_role t
|
||||
<include refid="where" />
|
||||
${params.orderBy}
|
||||
<if test="offset != null and offset >= 0 and limit != null and limit >= 0">
|
||||
limit #{offset}, #{limit}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<insert id="saveRolePermission">
|
||||
insert into sys_role_permission(roleId, permissionId) values
|
||||
<foreach collection="permissionIds" item="permissionId"
|
||||
separator=",">
|
||||
(#{roleId}, #{permissionId})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.zw.admin.server.dao.UserDao">
|
||||
|
||||
<sql id="where">
|
||||
<where>
|
||||
<if test="params.username != null and params.username != ''">
|
||||
and t.username like concat('%', #{params.username}, '%')
|
||||
</if>
|
||||
<if test="params.nickname != null and params.nickname != ''">
|
||||
and t.nickname like concat('%', #{params.nickname}, '%')
|
||||
</if>
|
||||
<if test="params.status != null and params.status != ''">
|
||||
and t.status = #{params.status}
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<select id="count" resultType="int">
|
||||
select count(1) from sys_user t
|
||||
<include refid="where" />
|
||||
</select>
|
||||
|
||||
<select id="list" resultType="User">
|
||||
select * from sys_user t
|
||||
<include refid="where" />
|
||||
${params.orderBy}
|
||||
limit #{offset}, #{limit}
|
||||
</select>
|
||||
|
||||
<insert id="saveUserRoles">
|
||||
insert into sys_role_user(roleId, userId) values
|
||||
<foreach collection="roleIds" item="roleId" separator=",">
|
||||
(#{roleId}, #{userId})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
update sys_user t
|
||||
<set>
|
||||
<if test="username != null">
|
||||
username = #{username},
|
||||
</if>
|
||||
<if test="nickname != null">
|
||||
nickname = #{nickname},
|
||||
</if>
|
||||
<if test="headImgUrl != null">
|
||||
headImgUrl = #{headImgUrl},
|
||||
</if>
|
||||
<if test="phone != null">
|
||||
phone = #{phone},
|
||||
</if>
|
||||
<if test="telephone != null">
|
||||
telephone = #{telephone},
|
||||
</if>
|
||||
<if test="email != null">
|
||||
email = #{email},
|
||||
</if>
|
||||
<if test="birthday != null">
|
||||
birthday = #{birthday},
|
||||
</if>
|
||||
<if test="sex != null">
|
||||
sex = #{sex},
|
||||
</if>
|
||||
<if test="status != null">
|
||||
status = #{status},
|
||||
</if>
|
||||
<if test="intro != null">
|
||||
intro = #{intro},
|
||||
</if>
|
||||
updateTime = #{updateTime}
|
||||
</set>
|
||||
where t.id = #{id}
|
||||
</update>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue