UserMapper.xml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.fuzamei.mapperInterface.UserInterface">
  4. <select id="getUserCount" parameterType="com.fuzamei.entity.User" resultType="com.fuzamei.entity.User">
  5. SELECT
  6. a.user_id,
  7. b.role_id,
  8. c.role_name,
  9. a.account,
  10. a.password,
  11. a.person_name,
  12. a.account_balance,
  13. a.random
  14. FROM
  15. t_user a
  16. LEFT JOIN user_role b ON a.user_id = b.user_id
  17. LEFT JOIN t_role c ON b.role_id = c.role_id
  18. where a.account = #{account} and a.password = #{password} and a.user_id = #{user_id};
  19. </select>
  20. <insert id="insertUsers">
  21. INSERT INTO t_user (
  22. user_id,
  23. user_name,
  24. password,
  25. random,
  26. public_key,
  27. private_key,
  28. organization_name,
  29. person_name
  30. )
  31. VALUES
  32. <foreach collection="list" item = "item" index="index" separator=",">
  33. (#{item.user_id},
  34. #{item.user_name},
  35. #{item.password},
  36. #{item.random},
  37. #{item.public_key},
  38. #{item.private_key},
  39. #{item.organization_name},
  40. #{item.person_name})
  41. </foreach>
  42. </insert>
  43. <insert id="addUserToUser" parameterType="com.fuzamei.entity.User">
  44. insert into t_user(user_id,account,password,person_name,random,public_key,private_key,account_balance,create_time,update_time)values(#{user_id},#{account},#{password},#{person_name},#{random},#{public_key},#{private_key},#{account_balance},#{create_time},#{update_time});
  45. </insert>
  46. <insert id="addUserToUserRole" parameterType="com.fuzamei.entity.User">
  47. insert into user_role(user_id,role_id)values(#{user_id},#{role_id});
  48. </insert>
  49. <update id="updateUserById" parameterType="com.fuzamei.entity.User">
  50. update t_user set account = #{account},password = #{password},person_name = #{person_name},account_balance = #{account_balance},update_time = #{update_time} where user_id = #{user_id};
  51. </update>
  52. <update id="updataRoleById" parameterType="com.fuzamei.entity.User">
  53. update user_role set role_id = #{role_id} where user_id = #{user_id};
  54. </update>
  55. <select id="getUsers" parameterType="java.util.Map" resultType="int">
  56. SELECT
  57. count(1)
  58. FROM
  59. t_user a
  60. LEFT JOIN user_role b ON a.user_id = b.user_id
  61. LEFT JOIN t_role c ON b.role_id = c.role_id
  62. <where>
  63. <if test="role_name!=null and role_name!=''">
  64. and c.role_name = #{role_name}
  65. </if>
  66. <if test="account!=null and account!=''">
  67. and a.account = #{account}
  68. </if>
  69. <if test="person_name!=null and person_name!=''">
  70. and a.person_name = #{person_name}
  71. </if>
  72. </where>
  73. </select>
  74. <select id="getUsersByPage" parameterType="java.util.Map" resultType="com.fuzamei.entity.User">
  75. SELECT
  76. a.user_id,
  77. c.role_name,
  78. a.account,
  79. a.password,
  80. a.person_name,
  81. a.create_time,
  82. a.update_time
  83. FROM
  84. t_user a
  85. LEFT JOIN user_role b ON a.user_id = b.user_id
  86. LEFT JOIN t_role c ON b.role_id = c.role_id
  87. <where>
  88. <if test="role_name!=null and role_name!=''">
  89. and c.role_name = #{role_name}
  90. </if>
  91. <if test="account!=null and account!=''">
  92. and a.account = #{account}
  93. </if>
  94. <if test="person_name!=null and person_name!=''">
  95. and a.person_name = #{person_name}
  96. </if>
  97. </where>
  98. limit #{startNum},#{endNum};
  99. </select>
  100. <select id="findUserById" parameterType="com.fuzamei.entity.User" resultType = "com.fuzamei.entity.User">
  101. select * from t_user where user_id = #{user_id} or account = #{account};
  102. </select>
  103. <select id="findUserById1" parameterType="java.lang.String" resultType = "com.fuzamei.entity.User">
  104. select a.user_id,b.role_id,c.role_name,a.account,a.password,a.person_name,a.account_balance from t_user a LEFT JOIN user_role b ON a.user_id = b.user_id LEFT JOIN t_role c ON b.role_id = c.role_id
  105. where a.user_id = #{user_id};
  106. </select>
  107. </mapper>