ManagerMapper.xml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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.fdkankan.order.mapper.IManagerMapper">
  4. <resultMap id="resultMap" type="com.fdkankan.order.entity.Manager">
  5. <id column="id" jdbcType="VARCHAR" property="id" />
  6. <result column="nickname" jdbcType="VARCHAR" property="nickname" />
  7. <result column="username" jdbcType="VARCHAR" property="username" />
  8. <result column="password" jdbcType="VARCHAR" property="password" />
  9. <result column="is_company" jdbcType="INTEGER" property="isCompany" />
  10. <result column="agent_framework_id" jdbcType="VARCHAR" property="agentFrameworkId" />
  11. <result column="manager_role_id" jdbcType="VARCHAR" property="managerRoleId" />
  12. <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  13. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  14. <result column="rec_status" jdbcType="VARCHAR" property="recStatus" />
  15. <result column="tb_status" jdbcType="INTEGER" property="tbStatus" />
  16. </resultMap>
  17. <sql id="columnList">
  18. id,nickname,username,password,is_company,agent_framework_id,manager_role_id,create_time,update_time,rec_status,tb_status </sql>
  19. <insert id="insert" useGeneratedKeys="true" keyProperty="entity.id">
  20. INSERT INTO ${tableName} (
  21. nickname, username, password, is_company, agent_framework_id, manager_role_id, rec_status
  22. ) VALUES (
  23. #{entity.nickname}, #{entity.username}, #{entity.password}, #{entity.isCompany}, #{entity.agentFrameworkId}, #{entity.managerRoleId}, #{entity.recStatus}
  24. ) </insert>
  25. <insert id="insertByBatch" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id" >
  26. INSERT INTO ${tableName} (
  27. nickname, username, password, is_company, agent_framework_id, manager_role_id, rec_status
  28. ) VALUES
  29. <foreach collection="list" item="entity" index="index" separator=",">
  30. (#{entity.nickname}, #{entity.username}, #{entity.password}, #{entity.isCompany}, #{entity.agentFrameworkId}, #{entity.managerRoleId}, #{entity.recStatus})
  31. </foreach>
  32. </insert>
  33. <update id="update" parameterType="java.util.List" >
  34. <foreach collection="list" item="entity" index="index" separator=";">
  35. UPDATE ${tableName} SET
  36. nickname=#{entity.nickname}, username=#{entity.username}, password=#{entity.password}, is_company=#{entity.isCompany}, agent_framework_id=#{entity.agentFrameworkId}, manager_role_id=#{entity.managerRoleId}, rec_status=#{entity.recStatus}, tb_status=#{entity.tbStatus}
  37. WHERE
  38. id = #{entity.id}
  39. </foreach>
  40. </update>
  41. <update id="updateByBatch" >
  42. UPDATE ${tableName} SET
  43. ${field}
  44. <where>
  45. <foreach collection="condition" index="key" item="value">
  46. ${value} ${key}
  47. </foreach>
  48. </where>
  49. </update>
  50. <select id="getById" parameterType="java.lang.Integer" resultMap="resultMap">
  51. select
  52. <include refid="columnList" />
  53. from ${tableName}
  54. where id = #{id}
  55. </select>
  56. <select id="getOne" parameterType="java.util.Map" resultMap="resultMap">
  57. select
  58. <if test="field == null">
  59. <include refid="columnList" />
  60. </if>
  61. <if test="field != null">
  62. ${field}
  63. </if>
  64. from ${tableName}
  65. <where>
  66. <foreach collection="condition" index="key" item="value">
  67. ${value} ${key}
  68. </foreach>
  69. </where>
  70. limit 1;
  71. </select>
  72. <select id="getCount" parameterType="java.util.Map" resultType="java.lang.Integer">
  73. select
  74. count(id)
  75. from ${tableName}
  76. <where>
  77. <foreach collection="condition" index="key" item="value">
  78. ${value} ${key}
  79. </foreach>
  80. </where>
  81. </select>
  82. <!-- 这部分为根据传递参数,自动生成SQL -->
  83. <select id="getList" parameterType="java.util.Map" resultMap="resultMap">
  84. select
  85. <if test="field == null">
  86. <include refid="columnList" />
  87. </if>
  88. <if test="field != null">
  89. ${field}
  90. </if>
  91. from ${tableName}
  92. <where>
  93. <foreach collection="condition" index="key" item="value">
  94. ${value} ${key}
  95. </foreach>
  96. </where>
  97. <if test="order != null">
  98. order by ${order}
  99. </if>
  100. <if test="limit != 0">
  101. <if test="offset != 0">
  102. limit ${offset}, ${limit}
  103. </if>
  104. <if test="offset == 0">
  105. limit ${limit}
  106. </if>
  107. </if>
  108. </select>
  109. <!-- 判断表格是否存在,如果不存在可以配合createTable使用,用于动态创建表格 -->
  110. <select id="existTable" parameterType="String" resultType="java.lang.Integer">
  111. select count(table_name) from information_schema.TABLES WHERE table_name=#{tableName} ;
  112. </select>
  113. <update id="createTable" parameterType="String">
  114. <!-- 这里是创建表格的SQL,复制过来,表名作为参数传递 -->
  115. <!-- create table ${tableName} ( // 表名要这样写 -->
  116. </update>
  117. </mapper>