DzAgentMapper.xml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.ruoyi.dz.mapper.DzAgentMapper">
  6. <resultMap type="DzAgent" id="DzAgentResult">
  7. <result property="agentId" column="agent_id" />
  8. <result property="deptId" column="dept_id" />
  9. <result property="userId" column="user_id" />
  10. <result property="name" column="name" />
  11. <result property="phonenumber" column="phonenumber" />
  12. <result property="parentId" column="parent_id" />
  13. <result property="schools" column="schools" />
  14. <result property="remark" column="remark" />
  15. <association property="dept" javaType="SysDept" resultMap="deptResult" />
  16. </resultMap>
  17. <resultMap id="deptResult" type="SysDept">
  18. <id property="deptId" column="dept_id" />
  19. <result property="parentId" column="parent_id" />
  20. <result property="deptName" column="dept_name" />
  21. <result property="ancestors" column="ancestors" />
  22. <result property="orderNum" column="order_num" />
  23. <result property="leader" column="leader" />
  24. <result property="status" column="dept_status" />
  25. </resultMap>
  26. <sql id="selectDzAgentVo">
  27. select t1.agent_id, t1.dept_id, t1.user_id, t1.name, t1.phonenumber, t1.parent_id, t1.schools, t1.remark,
  28. d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status
  29. from dz_agent t1
  30. left join sys_dept d on t1.dept_id = d.dept_id
  31. </sql>
  32. <select id="selectDzAgentList" parameterType="DzAgent" resultMap="DzAgentResult">
  33. <include refid="selectDzAgentVo"/>
  34. <where>
  35. <if test="agentId != null "> and t1.agent_id = #{agentId}</if>
  36. <if test="userId != null "> and t1.user_id = #{userId}</if>
  37. <!-- <if test="deptId != null "> and t1.dept_id = #{deptId}</if>-->
  38. <if test="deptId != null ">
  39. AND (t1.dept_id = #{deptId} OR t1.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId}, ancestors) ))
  40. </if>
  41. <if test="teacherId != null ">
  42. AND t1.agent_id in (select distinct t.agent_id from `dz_teacher` t where t.`teacher_id` = #{teacherId} and t.agent_id is not null)
  43. </if>
  44. <if test="name != null and name != ''"> and t1.name like concat('%', #{name}, '%')</if>
  45. <if test="phonenumber != null and phonenumber != ''"> and t1.phonenumber like concat('%', #{phonenumber}, '%')</if>
  46. <if test="parentId != null "> and t1.parent_id = #{parentId}</if>
  47. <if test="schools != null and schools != ''"> and t1.schools = #{schools}</if>
  48. </where>
  49. </select>
  50. <select id="selectDzAgentByAgentId" parameterType="Long" resultMap="DzAgentResult">
  51. <include refid="selectDzAgentVo"/>
  52. where t1.agent_id = #{agentId}
  53. </select>
  54. <select id="selectDzAgentByUserId" parameterType="Long" resultMap="DzAgentResult">
  55. <include refid="selectDzAgentVo"/>
  56. where t1.user_id = #{userId}
  57. </select>
  58. <select id="selectDzAgentByAgentIds" resultMap="DzAgentResult">
  59. <include refid="selectDzAgentVo"/>
  60. where t1.agent_id in <foreach collection="ids" item="id" open="(" separator="," close=")">#{id}</foreach>
  61. </select>
  62. <select id="selectDzAgentByUserIds" resultMap="DzAgentResult">
  63. <include refid="selectDzAgentVo"/>
  64. where t1.user_id in <foreach collection="userIds" item="userId" open="(" separator="," close=")">#{userId}</foreach>
  65. </select>
  66. <insert id="insertDzAgent" parameterType="DzAgent" useGeneratedKeys="true" keyProperty="agentId">
  67. insert into dz_agent
  68. <trim prefix="(" suffix=")" suffixOverrides=",">
  69. <if test="deptId != null">dept_id,</if>
  70. <if test="userId != null">user_id,</if>
  71. <if test="name != null">name,</if>
  72. <if test="phonenumber != null">phonenumber,</if>
  73. <if test="parentId != null">parent_id,</if>
  74. <if test="schools != null">schools,</if>
  75. <if test="remark != null">remark,</if>
  76. </trim>
  77. <trim prefix="values (" suffix=")" suffixOverrides=",">
  78. <if test="deptId != null">#{deptId},</if>
  79. <if test="userId != null">#{userId},</if>
  80. <if test="name != null">#{name},</if>
  81. <if test="phonenumber != null">#{phonenumber},</if>
  82. <if test="parentId != null">#{parentId},</if>
  83. <if test="schools != null">#{schools},</if>
  84. <if test="remark != null">#{remark},</if>
  85. </trim>
  86. </insert>
  87. <update id="updateDzAgent" parameterType="DzAgent">
  88. update dz_agent
  89. <trim prefix="SET" suffixOverrides=",">
  90. <if test="userId != null">user_id = #{userId},</if>
  91. <if test="deptId != null">dept_id = #{deptId},</if>
  92. <if test="name != null">name = #{name},</if>
  93. <if test="phonenumber != null">phonenumber = #{phonenumber},</if>
  94. <if test="parentId != null">parent_id = #{parentId},</if>
  95. <if test="schools != null">schools = #{schools},</if>
  96. <if test="remark != null">remark = #{remark},</if>
  97. </trim>
  98. where agent_id = #{agentId}
  99. </update>
  100. <delete id="deleteDzAgentByAgentId" parameterType="Long">
  101. delete from dz_agent where agent_id = #{agentId}
  102. </delete>
  103. <delete id="deleteDzAgentByAgentIds" parameterType="String">
  104. delete from dz_agent where agent_id in
  105. <foreach item="agentId" collection="array" open="(" separator="," close=")">
  106. #{agentId}
  107. </foreach>
  108. </delete>
  109. </mapper>