FmsBlockMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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.yunfeiyun.agmp.fms.mapper.FmsBlockMapper">
  6. <sql id="selectFmsBlockVo">
  7. select blockId, landId, blockName, blockType, blockManager, blockManagername, blockArea, blockAreaplant,blockSeq,
  8. blockLngrange, blockColor, blockRemark, blockIcon, tid, blockIstransfer, blockTransferinfo, blockOwnerinfo from FmsBlock
  9. </sql>
  10. <sql id="selectFmsBlockHasResVo">
  11. select b.blockId, b.landId, b.blockName, b.blockType, b.blockManager, b.blockManagername, b.blockArea, b.blockSeq, b.blockAreaplant, b.blockLngrange, b.blockColor, b.blockRemark, b.blockIcon, b.blockIstransfer, b.blockTransferinfo, b.blockOwnerinfo,
  12. (select GROUP_CONCAT(resUrl) from SysRes r where r.resBusId = b.blockId) blockPreview,
  13. (select GROUP_CONCAT(resId) from SysRes r where r.resBusId = b.blockId) resIds,
  14. b.tid
  15. from FmsBlock b
  16. </sql>
  17. <sql id="selectFmsBlockHasResVo2">
  18. select b.blockId, b.landId, b.blockName, b.blockType, b.blockManager, b.blockManagername, b.blockArea,
  19. b.blockSeq, b.tid, b.blockAreaplant, b.blockLngrange, b.blockColor, b.blockRemark, b.blockIcon, l.landName,
  20. b.blockIstransfer, b.blockTransferinfo, b.blockOwnerinfo,
  21. (select GROUP_CONCAT(c.cropName) from FmsCrop c
  22. left join FmsPlan p on p.cropId = c.cropId
  23. where p.blockId = b.blockId) cropName,
  24. (select GROUP_CONCAT(r.resUrl) from FmsCrop c
  25. left join FmsPlan p on p.cropId = c.cropId
  26. left join SysRes r on r.resBusId = c.cropId
  27. where p.blockId = b.blockId and r.resBiztype = 'CROP') cropPreview,
  28. (select GROUP_CONCAT(resUrl) from SysRes r where r.resBusId = b.blockId) blockPreview,
  29. (select GROUP_CONCAT(resId) from SysRes r where r.resBusId = b.blockId) resIds
  30. from FmsBlock b
  31. left join FmsLand l on b.landId = l.landId
  32. </sql>
  33. <select id="selectFmsBlockList" parameterType="FmsBlock" resultType="com.yunfeiyun.agmp.fms.domain.FmsBlock">
  34. <include refid="selectFmsBlockHasResVo"/>
  35. <where>
  36. b.tid = #{tid}
  37. <if test="landId != null and landId != ''"> and landId = #{landId}</if>
  38. <if test="blockName != null and blockName != ''"> and blockName like concat('%', #{blockName}, '%')</if>
  39. <if test="blockNameEq != null and blockNameEq != ''"> and blockName = #{blockNameEq}</if>
  40. <if test="blockType != null and blockType != ''"> and blockType = #{blockType}</if>
  41. <if test="blockManager != null and blockManager != ''"> and blockManager = #{blockManager}</if>
  42. <if test="blockManagername != null and blockManagername != ''"> and blockManagername like concat('%', #{blockManagername}, '%')</if>
  43. <if test="blockArea != null "> and blockArea = #{blockArea}</if>
  44. <if test="blockAreaplant != null "> and blockAreaplant = #{blockAreaplant}</if>
  45. <if test="blockLngrange != null and blockLngrange != ''"> and blockLngrange = #{blockLngrange}</if>
  46. <if test="blockColor != null and blockColor != ''"> and blockColor = #{blockColor}</if>
  47. <if test="blockRemark != null and blockRemark != ''"> and blockRemark = #{blockRemark}</if>
  48. <if test="dataFilter == true and blockIds !=null and blockIds.size()>0">
  49. and b.blockId in
  50. <foreach collection="blockIds" item="blockId" index="index" open="(" close=")" separator=",">
  51. #{blockId}
  52. </foreach>
  53. </if>
  54. </where>
  55. order by b.blockSeq
  56. </select>
  57. <select id="selectFmsBlockByBlockId" parameterType="String" resultType="com.yunfeiyun.agmp.fms.domain.FmsBlock">
  58. <include refid="selectFmsBlockHasResVo"/>
  59. <where>
  60. blockId = #{blockId}
  61. and tid = #{tid}
  62. </where>
  63. </select>
  64. <select id="selectFmsBlockInfoByBlockId" parameterType="String" resultType="com.yunfeiyun.agmp.fms.domain.resvo.FmsBlockResVo">
  65. SELECT b.blockId, b.landId, b.blockName, b.blockType, b.blockManager, b.blockArea,
  66. b.blockSeq, b.blockAreaplant, b.blockLngrange, b.blockColor, b.blockRemark, b.blockIcon,
  67. b.blockIstransfer, b.blockTransferinfo, b.blockOwnerinfo,
  68. b.tid, l.landName,
  69. u.userName as blockManagername, (select GROUP_CONCAT(resUrl) from SysRes r where r.resBusId = b.blockId) blockPreview
  70. from FmsBlock b
  71. LEFT JOIN FmsLand l ON b.landId = l.landId
  72. LEFT JOIN SysUser u ON b.blockManager = u.userId
  73. <where>
  74. blockId = #{blockId}
  75. and b.tid = #{tid}
  76. </where>
  77. </select>
  78. <select id="selectCountByLandId" parameterType="String" resultType="Integer">
  79. select count(1) from FmsBlock
  80. <where>
  81. tid = #{tid}
  82. <if test="landId != null and landId != ''"> and landId = #{landId}</if>
  83. </where>
  84. </select>
  85. <select id="selectSumAreaByLandId" parameterType="FmsLand" resultType="java.math.BigDecimal">
  86. select sum(blockArea) from FmsBlock
  87. <where>
  88. tid = #{tid}
  89. <if test="landId != null and landId != ''"> and landId = #{landId}</if>
  90. <if test="dataFilter == true and blockIds !=null and blockIds.size()>0">
  91. and blockId in
  92. <foreach collection="blockIds" item="blockId" index="index" open="(" close=")" separator=",">
  93. #{blockId}
  94. </foreach>
  95. </if>
  96. </where>
  97. </select>
  98. <select id="selectSumArea" parameterType="FmsBlockReqVo" resultType="java.math.BigDecimal">
  99. select sum(b.blockArea) from FmsBlock b LEFT JOIN FmsLand l ON b.landId = l.landId WHERE l.landId is not null
  100. and b.tid = #{tid}
  101. <if test="landId != null and landId != ''"> and l.landId = #{landId}</if>
  102. <if test="dataFilter == true and blockIds !=null and blockIds.size()>0">
  103. and b.blockId in
  104. <foreach collection="blockIds" item="blockId" index="index" open="(" close=")" separator=",">
  105. #{blockId}
  106. </foreach>
  107. </if>
  108. </select>
  109. <select id="selectFmsBlockHasPlan" parameterType="FmsBlockReqVo" resultType="com.yunfeiyun.agmp.fms.domain.resvo.FmsBlockResVo">
  110. select b.* , l.landName,
  111. tb1.blockPreview,
  112. tb1.resIds,
  113. (SELECT GROUP_CONCAT(c.cropName) FROM FmsPlan p LEFT JOIN FmsCrop c ON p.cropId = c.cropId WHERE p.blockId = b.blockId and (p.planStatus = 0 or p.planStatus = 1) limit 1) cropNames
  114. from FmsBlock b
  115. left join FmsLand l on b.landId = l.landId
  116. left join (select GROUP_CONCAT(resUrl) blockPreview, GROUP_CONCAT(resId) resIds, resBusId from SysRes
  117. WHERE resBiztype = 'BLOCK' group by resBusId ) tb1 on b.blockId = tb1.resBusId
  118. having 1=1
  119. and b.tid = #{tid}
  120. <if test="hasPlan != null and hasPlan == '0'.toString() "> and cropNames is null</if>
  121. <if test="hasPlan != null and hasPlan == '1'.toString() "> and cropNames is not null</if>
  122. <if test="landId != null and landId != ''"> and landId = #{landId}</if>
  123. <if test="blockId != null and blockId != ''"> and blockId = #{blockId}</if>
  124. <if test="cropName != null and cropName != ''"> and cropNames like concat('%', #{cropName}, '%')</if>
  125. <if test="blockName != null and blockName != ''"> and b.blockName like concat('%', #{blockName}, '%')</if>
  126. <if test="dataFilter == true and blockIds !=null and blockIds.size()>0">
  127. and b.blockId in
  128. <foreach collection="blockIds" item="blockId" index="index" open="(" close=")" separator=",">
  129. #{blockId}
  130. </foreach>
  131. </if>
  132. order by b.blockSeq
  133. </select>
  134. <select id="selectFmsLandByBlockIds" parameterType="String" resultType="com.yunfeiyun.agmp.fms.domain.FmsLand">
  135. select l.* from FmsBlock b LEFT JOIN FmsLand l ON b.landId = l.landId
  136. <where>
  137. b.blockId in
  138. <foreach item="blockId" collection="array" open="(" separator="," close=")">
  139. #{blockId}
  140. </foreach>
  141. and b.tid = #{tid}
  142. </where>
  143. group by b.landId
  144. </select>
  145. <select id="selectValidDataNumber" parameterType="String" resultType="java.lang.Integer">
  146. select sum(num) from
  147. <trim prefix="(" suffix=")">
  148. <include refid="selectFmsPlanValidData"/>
  149. UNION ALL
  150. <include refid="selectIcsIrrgrcdValidData"/>
  151. </trim>
  152. AS validDataNum
  153. </select>
  154. <select id="selectFmsBlockListByLandManager" resultType="com.yunfeiyun.agmp.fms.domain.FmsBlock">
  155. select * from FmsBlock
  156. where landId in (
  157. select landId from FmsLand where landManager = #{userId} and tid = #{tid}
  158. )
  159. </select>
  160. <sql id="selectFmsPlanValidData">
  161. SELECT
  162. count( 1 ) AS num
  163. FROM
  164. FmsPlan
  165. <where>
  166. blockId = #{blockId} and tid = #{tid}
  167. </where>
  168. </sql>
  169. <sql id="selectIcsIrrgrcdValidData">
  170. SELECT
  171. count( 1 ) AS num
  172. FROM
  173. IcsIrrgrcd
  174. <where>
  175. blockId = #{blockId} and tid = #{tid}
  176. </where>
  177. </sql>
  178. <insert id="bindUser" parameterType="FmsBlockBindUserReqVo">
  179. insert into FmsBlockUser
  180. <trim prefix="(" suffix=")" suffixOverrides=",">
  181. userId,
  182. blockId,
  183. tid
  184. </trim>
  185. values
  186. <foreach item="blockId" collection="blockIds" separator=",">
  187. (
  188. #{userId},
  189. #{blockId},
  190. #{tid}
  191. )
  192. </foreach>
  193. </insert>
  194. <select id="userBindList" resultType="java.lang.String">
  195. select blockId from FmsBlockUser where userId =#{userId} and tid = #{tid}
  196. </select>
  197. <delete id="unbindUser">
  198. delete from FmsBlockUser where userId = #{userId} and tid = #{tid}
  199. </delete>
  200. <update id="updateFmsBlock" parameterType="FmsBlock">
  201. update FmsBlock
  202. <trim prefix="SET" suffixOverrides=",">
  203. <if test="landId != null">landId = #{landId},</if>
  204. <if test="blockName != null">blockName = #{blockName},</if>
  205. <if test="blockType != null">blockType = #{blockType},</if>
  206. <if test="blockManager != null">blockManager = #{blockManager},</if>
  207. <if test="blockManagername != null">blockManagername = #{blockManagername},</if>
  208. <if test="blockArea != null">blockArea = #{blockArea},</if>
  209. <if test="blockAreaplant != null">blockAreaplant = #{blockAreaplant},</if>
  210. <if test="blockLngrange != null">blockLngrange = #{blockLngrange},</if>
  211. <if test="blockColor != null">blockColor = #{blockColor},</if>
  212. <if test="blockRemark != null">blockRemark = #{blockRemark},</if>
  213. <if test="blockSeq != null">blockSeq =#{blockSeq},</if>
  214. <if test="blockIcon != null">blockIcon = #{blockIcon},</if>
  215. <if test="tid != null">tid = #{tid},</if>
  216. </trim>
  217. <where>
  218. blockId = #{blockId}
  219. and tid = #{tid}
  220. </where>
  221. </update>
  222. <select id="selectFmsBlockBindUserList" resultType="com.yunfeiyun.agmp.common.core.domain.entity.SysUser">
  223. select * from SysUser where userId in ( select userId from FmsBlockUser where blockId = #{blockId} )
  224. </select>
  225. </mapper>