FmsBlockMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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 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,
  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. (select GROUP_CONCAT(c.cropName) from FmsCrop c
  21. left join FmsPlan p on p.cropId = c.cropId
  22. where p.blockId = b.blockId) cropName,
  23. (select GROUP_CONCAT(r.resUrl) from FmsCrop c
  24. left join FmsPlan p on p.cropId = c.cropId
  25. left join SysRes r on r.resBusId = c.cropId
  26. where p.blockId = b.blockId and r.resBiztype = 'CROP') cropPreview,
  27. (select GROUP_CONCAT(resUrl) from SysRes r where r.resBusId = b.blockId) blockPreview,
  28. (select GROUP_CONCAT(resId) from SysRes r where r.resBusId = b.blockId) resIds
  29. from FmsBlock b
  30. left join FmsLand l on b.landId = l.landId
  31. </sql>
  32. <select id="selectFmsBlockList" parameterType="FmsBlock" resultType="FmsBlock">
  33. <include refid="selectFmsBlockHasResVo"/>
  34. <where>
  35. b.tid = #{tid}
  36. <if test="landId != null and landId != ''"> and landId = #{landId}</if>
  37. <if test="blockName != null and blockName != ''"> and blockName like concat('%', #{blockName}, '%')</if>
  38. <if test="blockNameEq != null and blockNameEq != ''"> and blockName = #{blockNameEq}</if>
  39. <if test="blockType != null and blockType != ''"> and blockType = #{blockType}</if>
  40. <if test="blockManager != null and blockManager != ''"> and blockManager = #{blockManager}</if>
  41. <if test="blockManagername != null and blockManagername != ''"> and blockManagername like concat('%', #{blockManagername}, '%')</if>
  42. <if test="blockArea != null "> and blockArea = #{blockArea}</if>
  43. <if test="blockAreaplant != null "> and blockAreaplant = #{blockAreaplant}</if>
  44. <if test="blockLngrange != null and blockLngrange != ''"> and blockLngrange = #{blockLngrange}</if>
  45. <if test="blockColor != null and blockColor != ''"> and blockColor = #{blockColor}</if>
  46. <if test="blockRemark != null and blockRemark != ''"> and blockRemark = #{blockRemark}</if>
  47. <if test="dataFilter == true and blockIds !=null and blockIds.size()>0">
  48. and b.blockId in
  49. <foreach collection="blockIds" item="blockId" index="index" open="(" close=")" separator=",">
  50. #{blockId}
  51. </foreach>
  52. </if>
  53. </where>
  54. order by b.blockSeq
  55. </select>
  56. <select id="selectFmsBlockByBlockId" parameterType="String" resultType="FmsBlock">
  57. <include refid="selectFmsBlockHasResVo"/>
  58. <where>
  59. blockId = #{blockId}
  60. and tid = #{tid}
  61. </where>
  62. </select>
  63. <select id="selectFmsBlockInfoByBlockId" parameterType="String" resultType="FmsBlockResVo">
  64. SELECT b.blockId, b.landId, b.blockName, b.blockType, b.blockManager, b.blockArea,
  65. b.blockSeq, b.blockAreaplant, b.blockLngrange, b.blockColor, b.blockRemark, b.blockIcon,
  66. b.tid, l.landName,
  67. u.userName as blockManagername, (select GROUP_CONCAT(resUrl) from SysRes r where r.resBusId = b.blockId) blockPreview
  68. from FmsBlock b
  69. LEFT JOIN FmsLand l ON b.landId = l.landId
  70. LEFT JOIN SysUser u ON b.blockManager = u.userId
  71. <where>
  72. blockId = #{blockId}
  73. and b.tid = #{tid}
  74. </where>
  75. </select>
  76. <select id="selectCountByLandId" parameterType="String" resultType="Integer">
  77. select count(1) from FmsBlock
  78. <where>
  79. tid = #{tid}
  80. <if test="landId != null and landId != ''"> and landId = #{landId}</if>
  81. </where>
  82. </select>
  83. <select id="selectCountByPlanStatus" parameterType="SelectCountByPlanStatusReqVo" resultType="Integer">
  84. SELECT count(1) FROM
  85. (SELECT b.blockId,(SELECT count(1) FROM FmsPlan p
  86. <where>
  87. p.blockId = b.blockId
  88. and p.tid = #{tid}
  89. <if test="planStatus != null and planStatus != ''">
  90. and p.planStatus in
  91. <foreach collection="planStatus.split(',')" item="item" index="index" open="(" close=")" separator=",">
  92. #{item}
  93. </foreach>
  94. </if>
  95. </where>
  96. ) count FROM FmsBlock b
  97. <where>
  98. b.tid = #{tid}
  99. <if test="landId != null and landId != ''">and b.landId = #{landId}</if>
  100. </where>
  101. ) tb
  102. WHERE tb.count > 0
  103. </select>
  104. <select id="selectSumAreaByLandId" parameterType="FmsLand" resultType="BigDecimal">
  105. select sum(blockArea) from FmsBlock
  106. <where>
  107. tid = #{tid}
  108. <if test="landId != null and landId != ''"> and landId = #{landId}</if>
  109. <if test="dataFilter == true and blockIds !=null and blockIds.size()>0">
  110. and blockId in
  111. <foreach collection="blockIds" item="blockId" index="index" open="(" close=")" separator=",">
  112. #{blockId}
  113. </foreach>
  114. </if>
  115. </where>
  116. </select>
  117. <select id="selectSumArea" parameterType="FmsBlockReqVo" resultType="BigDecimal">
  118. select sum(b.blockArea) from FmsBlock b LEFT JOIN FmsLand l ON b.landId = l.landId WHERE l.landId is not null
  119. and b.tid = #{tid}
  120. <if test="landId != null and landId != ''"> and l.landId = #{landId}</if>
  121. <if test="dataFilter == true and blockIds !=null and blockIds.size()>0">
  122. and b.blockId in
  123. <foreach collection="blockIds" item="blockId" index="index" open="(" close=")" separator=",">
  124. #{blockId}
  125. </foreach>
  126. </if>
  127. </select>
  128. <select id="selectFmsBlockHasPlan" parameterType="FmsBlockReqVo" resultType="FmsBlockResVo">
  129. select b.* , l.landName,
  130. tb1.blockPreview,
  131. tb1.resIds,
  132. (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
  133. from FmsBlock b
  134. left join FmsLand l on b.landId = l.landId
  135. left join (select GROUP_CONCAT(resUrl) blockPreview, GROUP_CONCAT(resId) resIds, resBusId from SysRes
  136. WHERE resBiztype = 'BLOCK' group by resBusId ) tb1 on b.blockId = tb1.resBusId
  137. having 1=1
  138. and b.tid = #{tid}
  139. <if test="hasPlan != null and hasPlan == '0'.toString() "> and cropNames is null</if>
  140. <if test="hasPlan != null and hasPlan == '1'.toString() "> and cropNames is not null</if>
  141. <if test="landId != null and landId != ''"> and landId = #{landId}</if>
  142. <if test="blockId != null and blockId != ''"> and blockId = #{blockId}</if>
  143. <if test="cropName != null and cropName != ''"> and cropNames like concat('%', #{cropName}, '%')</if>
  144. <if test="blockName != null and blockName != ''"> and b.blockName like concat('%', #{blockName}, '%')</if>
  145. <if test="dataFilter == true and blockIds !=null and blockIds.size()>0">
  146. and b.blockId in
  147. <foreach collection="blockIds" item="blockId" index="index" open="(" close=")" separator=",">
  148. #{blockId}
  149. </foreach>
  150. </if>
  151. order by b.blockSeq
  152. </select>
  153. <insert id="insertFmsBlock" parameterType="FmsBlock">
  154. insert into FmsBlock
  155. <trim prefix="(" suffix=")" suffixOverrides=",">
  156. <if test="blockId != null">blockId,</if>
  157. <if test="landId != null">landId,</if>
  158. <if test="blockName != null">blockName,</if>
  159. <if test="blockType != null">blockType,</if>
  160. <if test="blockManager != null">blockManager,</if>
  161. <if test="blockManagername != null">blockManagername,</if>
  162. <if test="blockArea != null">blockArea,</if>
  163. <if test="blockAreaplant != null">blockAreaplant,</if>
  164. <if test="blockLngrange != null">blockLngrange,</if>
  165. <if test="blockColor != null">blockColor,</if>
  166. <if test="blockRemark != null">blockRemark,</if>
  167. <if test="blockIcon != null">blockIcon,</if>
  168. <if test="blockSeq != null">blockSeq,</if>
  169. <if test="tid != null">tid,</if>
  170. </trim>
  171. <trim prefix="values (" suffix=")" suffixOverrides=",">
  172. <if test="blockId != null">#{blockId},</if>
  173. <if test="landId != null">#{landId},</if>
  174. <if test="blockName != null">#{blockName},</if>
  175. <if test="blockType != null">#{blockType},</if>
  176. <if test="blockManager != null">#{blockManager},</if>
  177. <if test="blockManagername != null">#{blockManagername},</if>
  178. <if test="blockArea != null">#{blockArea},</if>
  179. <if test="blockAreaplant != null">#{blockAreaplant},</if>
  180. <if test="blockLngrange != null">#{blockLngrange},</if>
  181. <if test="blockColor != null">#{blockColor},</if>
  182. <if test="blockRemark != null">#{blockRemark},</if>
  183. <if test="blockIcon != null">#{blockIcon},</if>
  184. <if test="blockSeq != null">#{blockSeq},</if>
  185. <if test="tid != null">#{tid},</if>
  186. </trim>
  187. </insert>
  188. <update id="updateFmsBlock" parameterType="FmsBlock">
  189. update FmsBlock
  190. <trim prefix="SET" suffixOverrides=",">
  191. <if test="landId != null">landId = #{landId},</if>
  192. <if test="blockName != null">blockName = #{blockName},</if>
  193. <if test="blockType != null">blockType = #{blockType},</if>
  194. <if test="blockManager != null">blockManager = #{blockManager},</if>
  195. <if test="blockManagername != null">blockManagername = #{blockManagername},</if>
  196. <if test="blockArea != null">blockArea = #{blockArea},</if>
  197. <if test="blockAreaplant != null">blockAreaplant = #{blockAreaplant},</if>
  198. <if test="blockLngrange != null">blockLngrange = #{blockLngrange},</if>
  199. <if test="blockColor != null">blockColor = #{blockColor},</if>
  200. <if test="blockRemark != null">blockRemark = #{blockRemark},</if>
  201. <if test="blockSeq != null">blockSeq =#{blockSeq},</if>
  202. <if test="blockIcon != null">blockIcon = #{blockIcon},</if>
  203. <if test="tid != null">tid = #{tid},</if>
  204. </trim>
  205. <where>
  206. blockId = #{blockId}
  207. and tid = #{tid}
  208. </where>
  209. </update>
  210. <update id="updateFmsBlockBatch" parameterType="FmsBlock">
  211. <foreach collection="list" item="block" separator=";">
  212. update FmsBlock
  213. <trim prefix="SET" suffixOverrides=",">
  214. <if test="block.landId != null">landId = #{block.landId},</if>
  215. <if test="block.blockName != null">blockName = #{block.blockName},</if>
  216. <if test="block.blockType != null">blockType = #{block.blockType},</if>
  217. <if test="block.blockManager != null">blockManager = #{block.blockManager},</if>
  218. <if test="block.blockManagername != null">blockManagername = #{block.blockManagername},</if>
  219. <if test="block.blockArea != null">blockArea = #{block.blockArea},</if>
  220. <if test="block.blockAreaplant != null">blockAreaplant = #{block.blockAreaplant},</if>
  221. <if test="block.blockLngrange != null">blockLngrange = #{block.blockLngrange},</if>
  222. <if test="block.blockColor != null">blockColor = #{block.blockColor},</if>
  223. <if test="block.blockRemark != null">blockRemark = #{block.blockRemark},</if>
  224. <if test="block.blockSeq != null">blockSeq =#{block.blockSeq},</if>
  225. <if test="block.blockIcon != null">blockIcon = #{block.blockIcon},</if>
  226. <if test="block.tid != null">tid = #{block.tid},</if>
  227. </trim>
  228. <where>
  229. blockId = #{block.blockId}
  230. and tid = #{block.tid}
  231. </where>
  232. </foreach>
  233. </update>
  234. <update id="updateManagerByBlockIds">
  235. update FmsBlock set blockManager = #{manager},blockManagername = #{managerName}
  236. <where>
  237. blockId in
  238. <foreach collection="blockIds" index="index" item="item" open="(" separator="," close=")">
  239. #{item}
  240. </foreach>
  241. and tid = #{tid}
  242. </where>
  243. </update>
  244. <update id="clearManagerByManagerId">
  245. update FmsBlock set blockManager = null
  246. <where>
  247. blockManager = #{manager}
  248. and tid = #{tid}
  249. </where>
  250. </update>
  251. <delete id="deleteFmsBlockByBlockId" parameterType="String">
  252. delete from FmsBlock
  253. <where>
  254. blockId = #{blockId}
  255. and tid = #{tid}
  256. </where>
  257. </delete>
  258. <delete id="deleteFmsBlockByBlockIds" parameterType="String">
  259. delete from FmsBlock
  260. <where>
  261. blockId in
  262. <foreach item="blockId" collection="array" open="(" separator="," close=")">
  263. #{blockId}
  264. </foreach>
  265. and tid = #{tid}
  266. </where>
  267. </delete>
  268. <select id="selectFmsLandByBlockIds" parameterType="String" resultType="FmsLand">
  269. select l.* from FmsBlock b LEFT JOIN FmsLand l ON b.landId = l.landId
  270. <where>
  271. b.blockId in
  272. <foreach item="blockId" collection="array" open="(" separator="," close=")">
  273. #{blockId}
  274. </foreach>
  275. and tid = #{tid}
  276. </where>
  277. group by b.landId
  278. </select>
  279. <select id="selectValidDataNumber" parameterType="String" resultType="java.lang.Integer">
  280. select sum(num) from
  281. <trim prefix="(" suffix=")">
  282. <include refid="selectFmsPlanValidData"/>
  283. UNION ALL
  284. <include refid="selectIcsIrrgrcdValidData"/>
  285. </trim>
  286. AS validDataNum
  287. </select>
  288. <select id="selectBlockManagerAndLandManager"
  289. resultType="SysUser">
  290. select u.userId, u.deptId, u.userLoginname, u.userName, u.userEmail, u.userMobile, u.userLoginpwd, u.userSex, u.userLockstatus, u.userDelstatus, u.userLastloginip, u.userLastlogindate, u.userCreator, u.userCreateddate, u.userRemark,u.userRegion,
  291. GROUP_CONCAT(r.roleId) as roleId,
  292. GROUP_CONCAT(r.roleName) as roleName,
  293. GROUP_CONCAT(r.roleKey) as roleKey,
  294. res.resUrl as userAvatar
  295. from SysUser u
  296. left join SysUserrole ur on u.userId = ur.userId
  297. left join SysRole r on r.roleId = ur.roleId
  298. left join SysRes res on res.resBusId = u.userId
  299. <where>
  300. r.roleKey in ('land_admin','block_admin') and u.tid = #{tid}
  301. <if test="roleName != null and roleName != ''">and r.roleName like CONCAT('%',#{roleName},'%')</if>
  302. <if test="userName != null and userName != ''">and u.userName like CONCAT('%',#{userName},'%')</if>
  303. <if test="userLoginname != null and userLoginname !=''">and u.userLoginname = #{userLoginname}</if>
  304. <if test="userMobile != null and userMobile !=''">and u.userMobile = #{userMobile}</if>
  305. </where>
  306. GROUP BY u.userId
  307. </select>
  308. <select id="selectFmsBlockBaseDataList" resultType="com.yunfeiyun.agmp.fms.domain.FmsBlock">
  309. <include refid="selectFmsBlockVo"/>
  310. <where>
  311. and tid = #{tid}
  312. <if test="landId != null and landId != ''"> and landId = #{landId}</if>
  313. <if test="blockName != null and blockName != ''"> and blockName like concat('%', #{blockName}, '%')</if>
  314. <if test="blockNameEq != null and blockNameEq != ''"> and blockName = #{blockNameEq}</if>
  315. <if test="blockType != null and blockType != ''"> and blockType = #{blockType}</if>
  316. <if test="blockManager != null and blockManager != ''"> and blockManager = #{blockManager}</if>
  317. <if test="blockManagername != null and blockManagername != ''"> and blockManagername like concat('%', #{blockManagername}, '%')</if>
  318. <if test="blockArea != null "> and blockArea = #{blockArea}</if>
  319. <if test="blockAreaplant != null "> and blockAreaplant = #{blockAreaplant}</if>
  320. <if test="blockLngrange != null and blockLngrange != ''"> and blockLngrange = #{blockLngrange}</if>
  321. <if test="blockColor != null and blockColor != ''"> and blockColor = #{blockColor}</if>
  322. <if test="blockRemark != null and blockRemark != ''"> and blockRemark = #{blockRemark}</if>
  323. <if test="dataFilter == true and blockIds !=null and blockIds.size()>0">
  324. and blockId in
  325. <foreach collection="blockIds" item="blockId" index="index" open="(" close=")" separator=",">
  326. #{blockId}
  327. </foreach>
  328. </if>
  329. <if test="landIds != null and landIds.size()!=0">
  330. and landId in
  331. <foreach collection="landIds" item="item" index="index" open="(" separator="," close=")">
  332. #{item}
  333. </foreach>
  334. </if>
  335. </where>
  336. </select>
  337. <select id="selectFmsBlockListByManager" resultType="com.yunfeiyun.agmp.fms.domain.FmsBlock">
  338. select * from FmsBlock
  339. where landId in (
  340. select landId from FmsLand where landManager = #{userId} and tid = #{tid}
  341. ) or blockManager = #{userId}
  342. </select>
  343. <sql id="selectFmsPlanValidData">
  344. SELECT
  345. count( 1 ) AS num
  346. FROM
  347. FmsPlan
  348. <where>
  349. blockId = #{blockId} and tid = #{tid}
  350. </where>
  351. </sql>
  352. <sql id="selectIcsIrrgrcdValidData">
  353. SELECT
  354. count( 1 ) AS num
  355. FROM
  356. IcsIrrgrcd
  357. <where>
  358. blockId = #{blockId} and tid = #{tid}
  359. </where>
  360. </sql>
  361. <insert id="bindUser" parameterType="FmsBlockBindUserReqVo">
  362. insert into FmsBlockUser
  363. <trim prefix="(" suffix=")" suffixOverrides=",">
  364. userId,
  365. blockId,
  366. tid
  367. </trim>
  368. values
  369. <foreach item="blockId" collection="blockIds" separator=",">
  370. (
  371. #{userId},
  372. #{blockId},
  373. #{tid}
  374. )
  375. </foreach>
  376. </insert>
  377. <select id="userBindList" resultType="java.lang.String">
  378. select blockId from FmsBlockUser where userId =#{userId} and tid = #{tid}
  379. </select>
  380. <delete id="unbindUser">
  381. delete from FmsBlockUser where userId = #{userId} and tid = #{tid}
  382. </delete>
  383. </mapper>