BisInspSelAreaDao.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  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="cn.com.goldenwater.dcproj.dao.BisInspSelAreaDao">
  4. <resultMap type="cn.com.goldenwater.dcproj.model.BisInspSelArea" id="bisInspSelAreaResultMap">
  5. <result property="areaId" column="AREA_ID"/>
  6. <result property="id" column="ID"/>
  7. <result property="adCode" column="AD_CODE"/>
  8. <result property="adName" column="AD_NAME"/>
  9. <result property="idtm" column="IDTM"/>
  10. <result property="pnm" column="PNM"/>
  11. <result property="impData" column="IMP_DATA"/>
  12. <result property="orgId" column="ORG_ID"/>
  13. </resultMap>
  14. <resultMap type="cn.com.goldenwater.dcproj.model.BisInspSelArea" id="bisInspSelAreaResultMap2">
  15. <result property="areaId" column="AREA_ID"/>
  16. <result property="id" column="ID"/>
  17. <result property="adCode" column="AD_CODE"/>
  18. <result property="adName" column="AD_NAME"/>
  19. <result property="idtm" column="IDTM"/>
  20. <result property="pnm" column="PNM"/>
  21. <result property="orgId" column="ORG_ID"/>
  22. </resultMap>
  23. <sql id="table_columns">
  24. AREA_ID,
  25. ID,
  26. AD_CODE,
  27. AD_NAME,
  28. IDTM,
  29. IMP_DATA,ORG_ID
  30. </sql>
  31. <sql id="table_columns2">
  32. a.AREA_ID,
  33. a.ID,
  34. a.AD_CODE,
  35. a.AD_NAME,
  36. a.IDTM,
  37. b.PNM,
  38. a.ORG_ID
  39. </sql>
  40. <sql id="entity_properties">
  41. #{areaId},
  42. #{id},
  43. #{adCode},
  44. #{adName},
  45. #{idtm},
  46. #{impData},#{orgId}
  47. </sql>
  48. <!-- 使用like用法:columnName like concat('%',#columnName#,'%') -->
  49. <sql id="page_where">
  50. <trim prefix="where" prefixOverrides="and | or ">
  51. <if test="id != null and id != ''">and ID = #{id}</if>
  52. <if test='adCode != null and adCode != ""'>and AD_CODE like '${adCode}%'</if>
  53. <if test='adName != null and adName != ""'>and AD_NAME like '%${adName}%'</if>
  54. <if test="idtm != null">and IDTM = #{idtm}</if>
  55. <if test="orgId != null and orgId !=''">and ORG_ID = #{orgId}</if>
  56. </trim>
  57. </sql>
  58. <sql id="page_where4">
  59. <trim prefix="where" prefixOverrides="and | or ">
  60. <if test="adCodes != null and adCodes != ''">and AD_CODE in
  61. <foreach collection="adCodes.split(',')" index="index" item="item" open="(" separator="," close=")">
  62. #{item}
  63. </foreach>
  64. </if>
  65. </trim>
  66. </sql>
  67. <sql id="page_where3">
  68. <trim prefix="where" prefixOverrides="and | or ">
  69. <if test="id != null and id != ''">and a.ID = #{id}</if>
  70. <if test='adCode != null and adCode != ""'>and a.AD_CODE like CONCAT(#{adCode},'%') </if>
  71. <if test='adName != null and adName != ""'>and a.AD_NAME like '%${adName}%'</if>
  72. <if test="idtm != null">and a.IDTM = #{idtm}</if>
  73. <include refid="choseSql"/>
  74. </trim>
  75. </sql>
  76. <sql id="page_where2">
  77. <trim prefix="where" prefixOverrides="and | or ">
  78. <if test='id != null and id != "" '>and a.ID like CONCAT(#{id},'%')</if>
  79. <if test='adCode != null and adCode != "" '>and a.AD_CODE = #{adCode}</if>
  80. <if test='adName != null and adName != "" '>and a.AD_NAME like '%${adName}%'</if>
  81. <if test="idtm != null">and a.IDTM = #{idtm}</if>
  82. <include refid="choseSql"/>
  83. <choose>
  84. <when test="province !=null and province !=''">
  85. and a.AD_CODE like '${province}%'
  86. </when>
  87. </choose>
  88. </trim>
  89. </sql>
  90. <select id="get" resultMap="bisInspSelAreaResultMap" parameterType="String">
  91. select
  92. <include refid="table_columns"/>
  93. from BIS_INSP_SEL_AREA where AREA_ID = #{areaId}
  94. </select>
  95. <select id="getBy" resultMap="bisInspSelAreaResultMap">
  96. select
  97. <include refid="table_columns"/>
  98. from BIS_INSP_SEL_AREA
  99. <include refid="page_where"/>
  100. </select>
  101. <select id="getAllSub" resultMap="bisInspSelAreaResultMap2">
  102. select
  103. <include refid="table_columns2"/>
  104. from BIS_INSP_SEL_AREA a
  105. LEFT JOIN BIS_INSP_ALL b ON a.ID = b.ID
  106. <include refid="page_where2"/>
  107. </select>
  108. <sql id="choseSql">
  109. <choose>
  110. <when test="orgId !=null and orgId !=''">
  111. and a.org_id=#{orgId}
  112. </when>
  113. <otherwise>
  114. and a.org_id is null
  115. </otherwise>
  116. </choose>
  117. </sql>
  118. <select id="findAll" resultMap="bisInspSelAreaResultMap">
  119. select
  120. <include refid="table_columns"/>
  121. from BIS_INSP_SEL_AREA
  122. </select>
  123. <select id="findList" resultMap="bisInspSelAreaResultMap2">
  124. <choose>
  125. <when test="id!=null and id!=''">
  126. select
  127. <include refid="table_columns2"/>
  128. from BIS_INSP_SEL_AREA a
  129. LEFT JOIN BIS_INSP_ALL b ON a.ID = b.ID
  130. <include refid="page_where3"/>
  131. </when>
  132. <otherwise>
  133. SELECT GUID ID,AD_CODE,AD_NAME
  134. from att_ad_x_base
  135. <include refid="page_where4"/>
  136. </otherwise>
  137. </choose>
  138. </select>
  139. <select id="selectCount" resultType="int">
  140. select count(ID) from BIS_INSP_SEL_AREA
  141. <include refid="page_where"/>
  142. </select>
  143. <insert id="insert" parameterType="cn.com.goldenwater.dcproj.model.BisInspSelArea">
  144. insert into BIS_INSP_SEL_AREA(
  145. <include refid="table_columns"/>
  146. )
  147. values (
  148. <include refid="entity_properties"/>
  149. )
  150. </insert>
  151. <delete id="delete" parameterType="java.lang.String">
  152. delete from BIS_INSP_SEL_AREA where AREA_ID = #{areaId}
  153. </delete>
  154. <delete id="deleteBy" parameterType="cn.com.goldenwater.dcproj.model.BisInspSelArea">
  155. delete from BIS_INSP_SEL_AREA
  156. <include refid="page_where"/>
  157. </delete>
  158. <update id="deleteInFlag" parameterType="java.lang.String">
  159. update BIS_INSP_SEL_AREA set flag_valid = 0 where AREA_ID = #{areaId}
  160. </update>
  161. <update id="update" parameterType="cn.com.goldenwater.dcproj.model.BisInspSelArea">
  162. update BIS_INSP_SEL_AREA
  163. <trim prefix="set" suffixOverrides=",">
  164. <if test="id != null and id != ''">ID = #{id},</if>
  165. <if test="adCode != null and adCode != ''">AD_CODE = #{adCode},</if>
  166. <if test="adName != null and adName != ''">AD_NAME = #{adName},</if>
  167. <if test="idtm != null">IDTM = #{idtm},</if>
  168. <if test="impData != null">IMP_DATA = #{impData},</if>
  169. <if test="orgId != null and orgId !=''">ORG_ID = #{orgId},</if>
  170. </trim>
  171. <where>AREA_ID = #{areaId}</where>
  172. </update>
  173. <update id="updateBy" parameterType="cn.com.goldenwater.dcproj.model.BisInspSelArea">
  174. update BIS_INSP_SEL_AREA
  175. <trim prefix="set" suffixOverrides=",">
  176. <if test="id != null and id != ''">ID = #{id},</if>
  177. <if test="adCode != null and adCode != ''">AD_CODE = #{adCode},</if>
  178. <if test="adName != null and adName != ''">AD_NAME = #{adName},</if>
  179. <if test="idtm != null">IDTM = #{idtm},</if>
  180. <if test="impData != null">IMP_DATA = #{impData},</if>
  181. <if test="orgId != null and orgId !=''">ORG_ID = #{orgId},</if>
  182. </trim>
  183. <include refid="page_where"/>
  184. </update>
  185. <!-- 其他自定义SQL -->
  186. <!-- 根据人员id查询可选区域 -->
  187. <select id="getAreaByPersid" resultType="java.util.HashMap">
  188. SELECT
  189. d.AREA_ID,
  190. d.ID,
  191. DATE_FORMAT(d.IDTM,'%Y-%m-%d %T') idtm,
  192. d.AD_NAME,
  193. d.AD_CODE
  194. FROM BIS_INSP_ALL_RLATION_PERS e
  195. LEFT JOIN BIS_INSP_ALL_RLATION b ON E.GUID = B.PERSID
  196. LEFT JOIN BIS_INSP_ALL c ON b.ID = c.ID
  197. LEFT JOIN BIS_INSP_SEL_AREA a ON a.ID like CONCAT(c.ID, '%')
  198. WHERE E.GUID = #{persId} AND a.AREA_ID IS NOT NULL
  199. <include refid="choseSql"/>
  200. </select>
  201. <!-- 根据人员id查询可选区域 -->
  202. <select id="getProvinceAreaByPersid" resultType="java.util.HashMap">
  203. SELECT DISTINCT
  204. B.AD_CODE,
  205. B.AD_NAME
  206. FROM
  207. (
  208. SELECT
  209. concat(substr( e.AD_CODE, 1, #{end} ), #{str}) AD_CODE2,
  210. e.AD_NAME
  211. FROM
  212. (
  213. SELECT
  214. a.*
  215. FROM
  216. BIS_INSP_SEL_AREA a
  217. LEFT JOIN BIS_INSP_ALL_RLATION b ON a.ID LIKE CONCAT( b.ID, '%' )
  218. LEFT JOIN BIS_INSP_ALL_RLATION_PERS c ON c.guid = b.PERSID
  219. <!--JOIN BIS_INSP_ALL l on b.id=l.id
  220. JOIN BIS_INSP_ALL_OBJ j on b.id=j.id-->
  221. WHERE
  222. c.guid = #{persId}
  223. <include refid="choseSql"/>
  224. ) e
  225. WHERE
  226. AD_CODE like concat('%',#{pattern},'%')
  227. ) a
  228. LEFT JOIN ATT_AD_BASE b ON a.AD_CODE2 = b.AD_CODE
  229. WHERE B.AD_CODE != #{adCode}
  230. ORDER BY B.AD_CODE
  231. </select>
  232. <select id="getAddvcdByAdCode" resultType="java.util.HashMap">
  233. SELECT
  234. AD_CODE,
  235. AD_NAME
  236. FROM
  237. ATT_AD_BASE
  238. WHERE
  239. AD_CODE LIKE #{adCode}
  240. <if test="adGrad != null and adGrad.length()>0">AND AD_GRAD = #{adGrad}</if>
  241. ORDER BY
  242. AD_CODE
  243. </select>
  244. <select id="getAddvcdCacheByAdCode" resultType="java.util.HashMap">
  245. SELECT
  246. AD_CODE,
  247. AD_NAME
  248. FROM
  249. ATT_AD_BASE
  250. WHERE
  251. AD_CODE like concat('%',#{adCode},'%')
  252. <if test="adGrad != null and adGrad.length()>0">AND AD_GRAD = #{adGrad}</if>
  253. ORDER BY
  254. AD_CODE
  255. </select>
  256. <!-- 根据区域id,查询区域包含人员信息 -->
  257. <select id="getPersByArea" resultType="java.util.HashMap">
  258. SELECT E.* FROM BIS_INSP_ALL_RLATION_PERS e
  259. LEFT JOIN BIS_INSP_ALL_RLATION a ON E.GUID = A.PERSID
  260. LEFT JOIN BIS_INSP_ALL c ON A.ID = c.ID
  261. LEFT JOIN BIS_INSP_SEL_AREA d ON c.ID = d.ID
  262. WHERE d.AD_CODE = #{adCode} AND d.AREA_ID IS NOT NULL
  263. <include refid="choseSql"/>
  264. </select>
  265. <!-- 水库同组范围内只能督查一次 -->
  266. <select id="getResByArea" resultType="java.util.HashMap">
  267. SELECT
  268. a.*,j.obj_id,rg.RGSTR_ID,rg.STATE
  269. FROM
  270. ATT_RS_BASE a
  271. LEFT JOIN ( SELECT * FROM BIS_INSP_ALL_OBJ
  272. WHERE FIND_IN_SET(ID, getSubNodes_bis_insp_all( #{id},1,0)) &gt; 0
  273. ) b ON b.CODE = a.RS_CODE
  274. LEFT JOIN BIS_INSP_ALL_OBJ J ON a.RS_CODE = J.code
  275. left join BIS_INSP_RSVR_RGSTR rg on j.obj_id = rg.obj_id
  276. WHERE
  277. a.ADM_DIV like concat('%',#{adCode},'%')
  278. <if test="province !=null and province !=''">
  279. and a.ADM_DIV like '${province}%'
  280. </if>
  281. AND b.CODE IS NULL
  282. <if test="adName != null and adName.length()>0">AND a.RS_NAME like CONCAT('%',CONCAT(#{adName}, '%'))</if>
  283. <if test="areaId != null and areaId.length()>0">AND a.ENG_SCAL in (${areaId})</if>
  284. <if test="pType =='1'.toString()">
  285. AND a.ENG_SCAL in(4,5)
  286. </if>
  287. <if test="pType =='36'.toString()">
  288. AND a.ENG_SCAL in(1,2,3)
  289. </if>
  290. </select>
  291. <!-- 稽察项目同组范围内只能督查一次 -->
  292. <select id="getPawpByArea" resultType="java.util.HashMap">
  293. SELECT
  294. a.*,j.obj_id,rg.RGSTR_ID,rg.STATE
  295. FROM
  296. TAC_ATT_PAWP_BASE a
  297. LEFT JOIN ( SELECT * FROM BIS_INSP_ALL_OBJ a
  298. WHERE FIND_IN_SET(a.ID ,getSubNodes_bis_insp_all(#{id},1,0) ) &gt; 0
  299. ) b ON b.CODE = a.ID
  300. LEFT JOIN BIS_INSP_ALL_OBJ J ON a.ID = J.code
  301. left join TAC_PAWP_RGSTR rg on j.obj_id = rg.obj_id
  302. WHERE
  303. 1=1
  304. AND b.CODE IS NULL
  305. <if test="province !=null and province !=''">
  306. AND a.ad_code like '${province}%'
  307. </if>
  308. <if test="orgId != null and orgId !=''">AND J.ORG_ID = #{orgId}</if>
  309. <if test="adCode != null and adCode.length()>0">AND a.AD_CODE like concat('%',#{adCode},'%') </if>
  310. <if test="objName != null and objName.length()>0">AND a.NAME like CONCAT('%',CONCAT(#{objName}, '%'))</if>
  311. </select>
  312. <!--根据节点id查询可选行政区-->
  313. <select id="getOptionalArea" resultType="java.util.HashMap">
  314. SELECT A.AD_CODE, A.AD_NAME, A.AD_GRAD
  315. FROM ATT_AD_BASE A
  316. WHERE A.AD_GRAD != '1'
  317. AND A.AD_CODE NOT IN (
  318. SELECT AD_CODE FROM BIS_INSP_SEL_AREA A WHERE ID = #{id})
  319. AND a.AD_CODE like #{adGrid}
  320. AND a.AD_CODE != #{adCode}
  321. <if test="adName != null">AND a.AD_NAME like CONCAT('%',CONCAT(#{adName}, '%'))</if>
  322. ORDER BY a.AD_CODE
  323. </select>
  324. <!--根据节点id查询可选行政区-->
  325. <select id="getPnmByBatchAndAdCode" resultType="java.util.HashMap">
  326. SELECT A.ID, P.PNM
  327. FROM BIS_INSP_SEL_AREA A
  328. JOIN BIS_INSP_ALL P ON A.ID = P.ID
  329. WHERE A.ID LIKE CONCAT(#{id},'%') AND A.AD_CODE = #{adCode}
  330. </select>
  331. <select id="getResByGroup" parameterType="cn.com.goldenwater.dcproj.param.InGroupResParam"
  332. resultType="cn.com.goldenwater.dcproj.model.AttRsBase">
  333. SELECT * FROM (
  334. SELECT A.rs_code,
  335. A.rs_name,
  336. A.longitude,
  337. A.latitude,
  338. A.location,
  339. A.eng_scal,
  340. A.lim_stag,
  341. A.tot_cap,
  342. A.rs_adm_name,
  343. A.rs_adm_code,
  344. A.rs_adm_dep,
  345. A.adm_att_rel,
  346. A.adm_div,
  347. A.rs_type,
  348. A.dam_type_mat,
  349. A.dam_type_str,
  350. A.dam_size_hig,
  351. A.center_x,
  352. A.center_y,
  353. A.src,
  354. A.data_quality,
  355. A.center_x_gd,
  356. A.center_y_gd,
  357. A.rs_loc,
  358. A.reg_code,
  359. A.comp_date,
  360. A.intm,
  361. A.reg_no,
  362. ifnull(B.state, 0) as hst_insp,
  363. A.pers_id,
  364. A.uptm,
  365. A.chk_state,
  366. A.edtr_pesr,
  367. A.slpc_adm_div,
  368. A.adm_div_name,
  369. A.PROVINCIAL
  370. FROM ATT_RS_BASE A
  371. LEFT JOIN (
  372. SELECT a.RS_CODE, '1' as state
  373. FROM ATT_RS_BASE a
  374. WHERE Exists (select code FROM BIS_INSP_ALL_OBJ o
  375. where o.code = a.RS_CODE
  376. <if test="pType != null and pType != '' ">
  377. and o.ptype = #{pType}
  378. </if>
  379. and DATE_FORMAT(o.OBJ_INTM,'%Y')=DATE_FORMAT(now(),'%Y')
  380. )
  381. ) B ON A.RS_CODE = B.RS_CODE
  382. ) A
  383. WHERE RS_CODE NOT IN (
  384. SELECT CODE FROM BIS_INSP_ALL_OBJ a WHERE ID = #{groupId}
  385. )
  386. <if test="hstInsp !=null and hstInsp !=''">
  387. and hst_insp = #{hstInsp}
  388. </if>
  389. <if test="province !=null and province !=''">
  390. and adm_div like '${province}%'
  391. </if>
  392. <!--四川加入部分中型水库,按照小水库督查来检查-->
  393. <choose>
  394. <when test="pType =='1'.toString() and province =='51'.toString()">
  395. and ENG_SCAL in (3,4,5)
  396. </when>
  397. <otherwise>
  398. and ENG_SCAL in (4,5)
  399. </otherwise>
  400. </choose>
  401. <if test="pType =='36'.toString()">
  402. and ENG_SCAL in (1,2,3)
  403. </if>
  404. <if test="pType =='26'.toString()">
  405. and ENG_SCAL in (1,2,3)
  406. </if>
  407. <if test="province =='51'.toString()">
  408. and ENG_SCAL in (3,4,5)
  409. </if>
  410. <if test="adcd != null and adcd != ''">and ${adcd}</if>
  411. <if test="adnm != null and adnm != ''">and ADM_DIV_NAME LIKE '%${adnm}%'</if>
  412. <if test="rsName != null and rsName != ''">and RS_NAME LIKE '%${rsName}%'</if>
  413. <if test="engScal != null and engScal != ''">and ENG_SCAL = #{engScal}</if>
  414. <if test="isTask != null and isTask != ''">and A.IS_TASK = #{isTask}</if>
  415. order by rs_code
  416. </select>
  417. <delete id="deleteByGroupId">
  418. DELETE FROM BIS_INSP_SEL_AREA a WHERE ID = #{id} AND AD_CODE = #{adCode}
  419. <include refid="choseSql"/>
  420. </delete>
  421. <sql id="choseSqlBak">
  422. <choose>
  423. <when test="orgId !=null and orgId !=''">
  424. and B.org_id =#{orgId}
  425. </when>
  426. <otherwise>
  427. and B.org_id is null
  428. </otherwise>
  429. </choose>
  430. </sql>
  431. <select id="getAreaByGroup" resultType="java.util.HashMap">
  432. SELECT A.AD_CODE,
  433. A.AD_NAME,
  434. A.AD_GRAD FROM ATT_AD_X_BASE A LEFT JOIN BIS_INSP_SEL_AREA B ON A.AD_CODE = B.AD_CODE
  435. WHERE B.ID = #{id}
  436. <if test="adGrid !=null and adGrid !=''">
  437. AND A.AD_CODE LIKE #{adGrid}
  438. </if>
  439. AND A.AD_CODE != #{adCode}
  440. <if test="adName != null and adName != ''">AND A.AD_NAME like CONCAT('%',CONCAT(#{adName}, '%'))</if>
  441. <if test="province !=null and province !=''">
  442. AND A.AD_CODE like '${province}%'
  443. </if>
  444. ORDER BY A.AD_CODE
  445. </select>
  446. <select id="getAreaByAdCode" resultType="java.util.HashMap">
  447. SELECT AD_CODE,AD_NAME,AD_GRAD FROM ATT_AD_BASE WHERE AD_FCODE = #{adCode}
  448. <if test="adName != null and adName != ''">AND AD_NAME like CONCAT('%',CONCAT(#{adName}, '%'))</if>
  449. ORDER BY AD_CODE
  450. </select>
  451. </mapper>