SpAdminMapper.xml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. <update id="updateOpenid">
  17. update sp_admin set openid=#{openid} where id=#{id}
  18. </update>
  19. <update id="updateAdmin">
  20. update sp_admin set name=#{name},role_id=#{roleId},status=#{status} where id=#{id}
  21. </update>
  22. <!-- 删 -->
  23. <delete id="delete">
  24. delete from sp_admin where id = #{id}
  25. </delete>
  26. <!-- 改 -->
  27. <delete id="update">
  28. update sp_admin set
  29. name = #{name}
  30. where id = #{id}
  31. </delete>
  32. <delete id="removeByCustomerId">
  33. delete from sp_admin where customer_id=#{customerId}
  34. </delete>
  35. <!-- 自己改自己 -->
  36. <!-- <delete id="updateBy">
  37. update sp_admin set
  38. name = #{name}
  39. where id = #{id}
  40. </delete> -->
  41. <!-- =================== 查询相关 =================== -->
  42. <!-- 通用映射 -->
  43. <resultMap id="model" type="com.pj.project4sp.admin.SpAdmin">
  44. <result property="id" column="id"/>
  45. <result property="name" column="name"/>
  46. <result property="avatar" column="avatar"/>
  47. <result property="password" column="password"/>
  48. <result property="pw" column="pw"/>
  49. <result property="phone" column="phone"/>
  50. <result property="roleId" column="role_id"/>
  51. <result property="status" column="status"/>
  52. <result property="createByAid" column="create_by_aid"/>
  53. <result property="createTime" column="create_time"/>
  54. <result property="loginTime" column="login_time"/>
  55. <result property="loginIp" column="login_ip"/>
  56. <result property="loginCount" column="login_count"/>
  57. <result property="roleName" column="role_name"/>
  58. </resultMap>
  59. <!-- 查询sql -->
  60. <sql id="select_sql">
  61. select *,
  62. (select name from sp_role where id = sp_admin.role_id) as role_name
  63. from sp_admin
  64. </sql>
  65. <!-- 查询,根据id -->
  66. <select id="getById" resultMap="model">
  67. <include refid="select_sql"></include>
  68. where id = #{id}
  69. </select>
  70. <!-- 查询,根据名称 -->
  71. <select id="getByName" resultMap="model">
  72. <include refid="select_sql"></include>
  73. where name = #{name}
  74. </select>
  75. <!-- 查询,根据名称 -->
  76. <select id="getByPhone" resultMap="model">
  77. <include refid="select_sql"></include>
  78. where phone = #{phone}
  79. </select>
  80. <!-- 查询,根据customerId -->
  81. <select id="getByCostomerId" resultMap="model">
  82. <include refid="select_sql"></include>
  83. where customer_id = #{customerId}
  84. </select>
  85. <!-- 查询 -->
  86. <select id="getList" resultMap="model">
  87. <include refid="select_sql"></include>
  88. where customer_id=#{customerId}
  89. <if test=' this.has("id") '>and id = #{id}</if>
  90. <if test=' this.has("name") '>and name like concat('%', #{name}, '%')</if>
  91. <if test=' this.has("roleId") '>and role_id = #{roleId}</if>
  92. order by
  93. <choose>
  94. <when test='sort_type == 0'>id desc</when>
  95. <when test='sort_type == 1'>id asc</when>
  96. <when test='sort_type == 2'>login_time desc</when>
  97. <when test='sort_type == 3'>login_count desc</when>
  98. <otherwise>id desc</otherwise>
  99. </choose>
  100. </select>
  101. <select id="findByOpenid" resultType="com.pj.project4sp.admin.SpAdmin">
  102. <include refid="select_sql"></include>
  103. where openid = #{openid}
  104. </select>
  105. <select id="findByCustomerId" resultType="com.pj.project4sp.admin.SpAdmin">
  106. <include refid="select_sql"></include>
  107. where customer_id = #{customerId}
  108. </select>
  109. </mapper>