SysPlantMapper.xml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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.cpms.system.mapper.SysPlantMapper">
  6. <resultMap type="SysPlant" id="SysPlantResult">
  7. <result property="plantId" column="plant_id" />
  8. <result property="parentId" column="parent_id" />
  9. <result property="name" column="name" />
  10. <result property="orderNum" column="order_num" />
  11. <result property="delFlag" column="del_flag" />
  12. <result property="cname" column="cname" />
  13. <result property="deptCode" column="dept_code" />
  14. <result property="remarks" column="remarks" />
  15. <result property="pType" column="p_type" />
  16. <result property="parentName" column="parent_name" />
  17. <result property="deptName" column="dept_name" />
  18. </resultMap>
  19. <sql id="selectSysPlantVo">
  20. select d.plant_id, d.parent_id, d.name, d.order_num, d.del_flag, d.cname, d.dept_code, d.remarks, d.p_type from sys_plant d
  21. </sql>
  22. <select id="selectSysPlantList" parameterType="SysPlant" resultMap="SysPlantResult">
  23. <include refid="selectSysPlantVo"/>
  24. <where>
  25. <if test="name != null and name != ''"> and name like concat(concat('%', #{name}), '%')</if>
  26. <if test="cname != null and cname != ''"> and cname like concat(concat('%', #{cname}), '%')</if>
  27. <if test="deptCode != null and deptCode != ''"> and dept_code = #{deptCode}</if>
  28. <if test="pType != null "> and p_type = #{pType}</if>
  29. and d.del_flag = 0
  30. </where>
  31. order by order_num , name
  32. </select>
  33. <select id="selectMySysPlantList" parameterType="SysPlant" resultMap="SysPlantResult">
  34. SELECT
  35. sp.NAME
  36. FROM
  37. SYS_PLANT sp
  38. WHERE
  39. sp.DEPT_CODE IN (
  40. SELECT DISTINCT
  41. m.DEPT_NAME
  42. FROM
  43. SYS_DEPT m
  44. LEFT JOIN SYS_USER_DEPT ur ON m.DEPT_ID = ur.DEPT_ID
  45. WHERE
  46. ur.user_id = #{plantId}
  47. )
  48. and sp.del_flag = 0
  49. order by sp.order_num , sp.name
  50. </select>
  51. <select id="selectMySysPlantList3" parameterType="SysPlant" resultMap="SysPlantResult">
  52. SELECT
  53. sp.NAME
  54. FROM
  55. SYS_PLANT sp
  56. WHERE
  57. sp.DEPT_CODE IN (
  58. SELECT DISTINCT
  59. m.DEPT_NAME
  60. FROM
  61. SYS_DEPT m
  62. LEFT JOIN SYS_USER ur ON m.DEPT_ID = ur.DEPT_ID
  63. WHERE
  64. ur.user_id = #{plantId}
  65. )
  66. and sp.del_flag = 0
  67. order by sp.order_num , sp.name
  68. </select>
  69. <select id="selectSysPlantByDeptId" parameterType="Long" resultMap="SysPlantResult">
  70. SELECT
  71. sp.NAME
  72. FROM
  73. SYS_PLANT sp
  74. LEFT JOIN SYS_DEPT sd on sp.DEPT_CODE = sd.DEPT_NAME
  75. where sd.DEPT_ID = #{deptId} or FIND_IN_SET(#{deptId}, sd.ancestors) > 0
  76. </select>
  77. <select id="selectSysPlantById" parameterType="Long" resultMap="SysPlantResult">
  78. select t.plant_id, t.parent_id, t.name, t.order_num, t.del_flag, t.cname, t.dept_code, t.remarks, t.p_type, p.name as parent_name
  79. from sys_plant t
  80. left join sys_plant p on p.plant_id = t.parent_id
  81. where t.plant_id = #{plantId}
  82. </select>
  83. <insert id="insertSysPlant" parameterType="SysPlant">
  84. insert into sys_plant
  85. <trim prefix="(" suffix=")" suffixOverrides=",">
  86. <if test="plantId != null">plant_id,</if>
  87. <if test="parentId != null">parent_id,</if>
  88. <if test="name != null">name,</if>
  89. <if test="orderNum != null">order_num,</if>
  90. <if test="delFlag != null">del_flag,</if>
  91. <if test="cname != null">cname,</if>
  92. <if test="deptCode != null">dept_code,</if>
  93. <if test="remarks != null">remarks,</if>
  94. <if test="pType != null">p_type,</if>
  95. </trim>
  96. <trim prefix="values (" suffix=")" suffixOverrides=",">
  97. <if test="plantId != null">#{plantId},</if>
  98. <if test="parentId != null">#{parentId},</if>
  99. <if test="name != null">#{name},</if>
  100. <if test="orderNum != null">#{orderNum},</if>
  101. <if test="delFlag != null">#{delFlag},</if>
  102. <if test="cname != null">#{cname},</if>
  103. <if test="deptCode != null">#{deptCode},</if>
  104. <if test="remarks != null">#{remarks},</if>
  105. <if test="pType != null">#{pType},</if>
  106. </trim>
  107. </insert>
  108. <update id="updateSysPlant" parameterType="SysPlant">
  109. update sys_plant
  110. <trim prefix="SET" suffixOverrides=",">
  111. <if test="parentId != null">parent_id = #{parentId},</if>
  112. <if test="name != null">name = #{name},</if>
  113. <if test="orderNum != null">order_num = #{orderNum},</if>
  114. <if test="delFlag != null">del_flag = #{delFlag},</if>
  115. <if test="cname != null">cname = #{cname},</if>
  116. <if test="deptCode != null">dept_code = #{deptCode},</if>
  117. <if test="remarks != null">remarks = #{remarks},</if>
  118. <if test="pType != null">p_type = #{pType},</if>
  119. </trim>
  120. where plant_id = #{plantId}
  121. </update>
  122. <update id="deleteSysPlantById" parameterType="Long">
  123. update sys_plant set del_flag = 2 where plant_id = #{plantId}
  124. </update>
  125. <update id="deleteSysPlantByIds" parameterType="String">
  126. update sys_plant set del_flag = 2 where plant_id in
  127. <foreach item="plantId" collection="array" open="(" separator="," close=")">
  128. #{plantId}
  129. </foreach>
  130. </update>
  131. <select id="selectSysPlantByPlants" parameterType="List" resultMap="SysPlantResult">
  132. <include refid="selectSysPlantVo"/>
  133. <where>
  134. parent_id in
  135. (SELECT PLANT_ID from SYS_PLANT where
  136. name in
  137. <choose>
  138. <when test="list != null and list.size > 0">
  139. <foreach collection="list" item="id" index="index" open="(" close=")" separator="," >
  140. #{id}
  141. </foreach>
  142. </when>
  143. <otherwise>
  144. null
  145. </otherwise>
  146. </choose>
  147. )
  148. and d.del_flag = 0
  149. and p_type = 2
  150. </where>
  151. order by order_num , name
  152. <!-- 数据范围过滤 -->
  153. </select>
  154. </mapper>