SpAdminMapper.xml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.pj.project4sp.admin.SpAdminMapper">
  4. <!-- 增 -->
  5. <insert id="add">
  6. insert into
  7. sp_admin(name, customer_id,avatar, phone, role_id, create_by_aid, create_time)
  8. values (#{name},#{customerId}, #{avatar}, #{phone}, #{roleId}, #{createByAid}, now())
  9. </insert>
  10. <update id="setRole">
  11. update sp_admin set role_id=#{roleId} where id=#{id}
  12. </update>
  13. <update id="updateCustomerAdmin">
  14. update sp_admin set status=#{status} where customer_id=#{customerId}
  15. </update>
  16. <!-- 删 -->
  17. <delete id="delete">
  18. delete from sp_admin where id = #{id}
  19. </delete>
  20. <!-- 改 -->
  21. <delete id="update">
  22. update sp_admin set
  23. name = #{name}
  24. where id = #{id}
  25. </delete>
  26. <delete id="removeByCustomerId">
  27. delete from sp_admin where customer_id=#{customerId}
  28. </delete>
  29. <!-- 自己改自己 -->
  30. <!-- <delete id="updateBy">
  31. update sp_admin set
  32. name = #{name}
  33. where id = #{id}
  34. </delete> -->
  35. <!-- =================== 查询相关 =================== -->
  36. <!-- 通用映射 -->
  37. <resultMap id="model" type="com.pj.project4sp.admin.SpAdmin">
  38. <result property="id" column="id" />
  39. <result property="name" column="name" />
  40. <result property="avatar" column="avatar" />
  41. <result property="password" column="password" />
  42. <result property="pw" column="pw" />
  43. <result property="phone" column="phone" />
  44. <result property="roleId" column="role_id" />
  45. <result property="status" column="status" />
  46. <result property="createByAid" column="create_by_aid" />
  47. <result property="createTime" column="create_time" />
  48. <result property="loginTime" column="login_time" />
  49. <result property="loginIp" column="login_ip" />
  50. <result property="loginCount" column="login_count" />
  51. <result property="roleName" column="role_name" />
  52. </resultMap>
  53. <!-- 查询sql -->
  54. <sql id="select_sql">
  55. select *,
  56. (select name from sp_role where id = sp_admin.role_id) as role_name
  57. from sp_admin
  58. </sql>
  59. <!-- 查询,根据id -->
  60. <select id="getById" resultMap="model">
  61. <include refid="select_sql"></include>
  62. where id = #{id}
  63. </select>
  64. <!-- 查询,根据名称 -->
  65. <select id="getByName" resultMap="model">
  66. <include refid="select_sql"></include>
  67. where name = #{name}
  68. </select>
  69. <!-- 查询,根据名称 -->
  70. <select id="getByPhone" resultMap="model">
  71. <include refid="select_sql"></include>
  72. where phone = #{phone}
  73. </select>
  74. <!-- 查询,根据customerId -->
  75. <select id="getByCostomerId" resultMap="model">
  76. <include refid="select_sql"></include>
  77. where customer_id = #{customerId}
  78. </select>
  79. <!-- 查询 -->
  80. <select id="getList" resultMap="model">
  81. <include refid="select_sql"></include>
  82. where customer_id=#{customerId}
  83. <if test=' this.has("id") '>and id = #{id} </if>
  84. <if test=' this.has("name") '>and name like concat('%', #{name}, '%') </if>
  85. <if test=' this.has("roleId") '>and role_id = #{roleId} </if>
  86. order by
  87. <choose>
  88. <when test='sort_type == 0'>id desc</when>
  89. <when test='sort_type == 1'>id asc</when>
  90. <when test='sort_type == 2'>login_time desc</when>
  91. <when test='sort_type == 3'>login_count desc</when>
  92. <otherwise>id desc</otherwise>
  93. </choose>
  94. </select>
  95. </mapper>