ReportTableDao.xml 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  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="com.example.opc_da.dao.ReportTableDao">
  4. <sql id="tableTemplate">
  5. id
  6. , user_id, template_name, template_type, template_data, event_num, is_gen_count_time,
  7. variable_type, start_item_id, start_value, end_item_id, end_value, version, update_time, create_time
  8. </sql>
  9. <sql id="tableTemplateNoData">
  10. id
  11. , user_id, template_name , template_type, event_num, is_gen_count_time,
  12. variable_type, start_item_id, start_value, end_item_id, end_value, version, update_time, create_time
  13. </sql>
  14. <sql id="tableTemplateTableItem">
  15. id
  16. , table_template_id, item_id , time_item_type, place_holder, xaxis, yaxis, value_taking_mode, value_type, bucket_type,
  17. bucket_value, standby
  18. </sql>
  19. <sql id="tableTemplateChart">
  20. id
  21. , table_template_id, chart_type, chart_name, value_taking_mode, value_type, bucket_type,
  22. bucket_value, standby
  23. </sql>
  24. <sql id="tableTemplateChartItem">
  25. id
  26. , table_template_chart_id, item_id
  27. </sql>
  28. <sql id="reportTable">
  29. id
  30. , report_table_type, table_template_id, user_id, report_table_name, report_table_data, start_time,
  31. current_num, is_gen_count_time, version, is_run_print, print_ip, print_config_id, create_time, is_delete
  32. </sql>
  33. <sql id="reportTableItem">
  34. id
  35. , report_table_id, item_id, time_item_type, value_type, xaxis, yaxis, standby, value_list, value_time_list, value_index_list
  36. </sql>
  37. <sql id="reportTableNoData">
  38. id
  39. , report_table_type, table_template_id, user_id, report_table_name, start_time, current_num,
  40. is_gen_count_time, version, is_run_print, print_ip, print_config_id, create_time, is_delete
  41. </sql>
  42. <sql id="reportTableCron">
  43. id
  44. , report_table_type, table_template_id, user_id, report_table_name, report_table_data, start_time,
  45. current_num, is_gen_count_time, version, is_run_print, print_ip, print_config_id, cron_id, type, cron , run_state, create_time, is_delete
  46. </sql>
  47. <sql id="reportTableCronAndNoData">
  48. id
  49. , report_table_type, table_template_id, user_id, report_table_name, start_time,
  50. current_num, is_gen_count_time, version, is_run_print, print_ip, print_config_id, cron_id, type, cron , run_state, create_time, is_delete
  51. </sql>
  52. <sql id="reportTableCronNoData">
  53. id
  54. , report_table_type, table_template_id, user_id, report_table_name, start_time, current_num,
  55. is_gen_count_time, version, is_run_print, print_ip, print_config_id, cron_id, type, cron , run_state, create_time, is_delete
  56. </sql>
  57. <sql id="reportChart">
  58. id
  59. , report_table_id, template_chart_id, chart_type, chart_name, value_type, standby
  60. </sql>
  61. <sql id="reportChartItem">
  62. id
  63. , report_chart_id, item_id, value_list, value_time_list, value_index_list
  64. </sql>
  65. <sql id="dataSource">
  66. id
  67. , type_id, data_source_name, data_source_describe, ip_address, ip_port, ip_user_name, ip_password,
  68. security_mode, security_policy, identity_provider, certificate_dir, certificate_key, cls_id, prog_id, driver_describe, create_time
  69. </sql>
  70. <sql id="dataSourceType">
  71. id
  72. , parent_id, data_source_type_name, data_source_type_key, sort_num, data_source_type_describe
  73. </sql>
  74. <sql id="item">
  75. id
  76. , item_group_id, item_name, item_read_name, node_index , data_type, `describe`, data_model_id
  77. </sql>
  78. <insert id="addTableTemplate" parameterType="com.example.opc_common.entity.TableTemplate" useGeneratedKeys="true"
  79. keyProperty="id">
  80. insert into t_table_template(user_id, template_name, template_type, template_data,
  81. event_num, is_gen_count_time, variable_type, start_item_id,
  82. start_value, end_item_id, end_value, version,
  83. update_time,
  84. create_time)
  85. VALUE ( #{userId},
  86. #{templateName}, #{templateType},
  87. #{templateData}, #{eventNum}, #{isGenCountTime},#{variableType},#{startItemId},#{startValue},
  88. #{endItemId},#{endValue},
  89. #{version},#{updateTime},#{createTime}
  90. )
  91. </insert>
  92. <insert id="addReportTable" parameterType="com.example.opc_common.entity.ReportTable" useGeneratedKeys="true"
  93. keyProperty="id">
  94. insert into t_report_table(id, report_table_type, table_template_id, user_id, report_table_name,
  95. report_table_data, start_time, current_num, is_gen_count_time, version, cron_id,
  96. cron,
  97. create_time, is_delete) VALUE
  98. (#{id},#{reportTableType},#{tableTemplateId}, #{userId}, #{reportTableName}, #{reportTableData}, #{startTime},
  99. #{currentNum}, #{isGenCountTime}, #{version},
  100. #{cronId}, #{cron}, #{createTime}, #{isDelete})
  101. </insert>
  102. <insert id="addHaveKeyReport">
  103. insert into t_report_table(id, report_table_type, table_template_id, user_id, report_table_name,
  104. report_table_data, start_time, current_num, is_gen_count_time, version,
  105. is_run_print, print_ip, print_config_id, cron_id,cron,
  106. create_time, is_delete) VALUE
  107. (#{id},#{reportTableType},#{tableTemplateId}, #{userId}, #{reportTableName}, #{reportTableData}, #{startTime},
  108. #{currentNum}, #{isGenCountTime}, #{version}, #{isRunPrint}, #{printIp}, #{printConfigId},
  109. #{cronId}, #{cron}, #{createTime}, #{isDelete})
  110. </insert>
  111. <!--(丢弃,使用addTableUserGroupUser)-->
  112. <insert id="addTableUserGroup">
  113. insert into t_table_user_group (table_id, user_group_id)
  114. values
  115. <foreach collection="userGroupList" item="userGroup" index="index" separator=",">
  116. (#{reportTableId}, #{userGroup.id})
  117. </foreach>
  118. </insert>
  119. <insert id="addTableTemplateLog">
  120. insert into t_table_template_log(table_template_id, table_template_version, create_time)
  121. value (#{tableTemplateId},#{tableTemplateVersion},#{createTime})
  122. </insert>
  123. <insert id="addTableAutoLog">
  124. insert into t_table_auto_log (auto_table_id, auto_ch_table_id)
  125. value (#{autoTableId},#{autoChTableId})
  126. </insert>
  127. <insert id="addTableTemplateTableItem">
  128. <if test="tableTemplateTableItemList!= null and tableTemplateTableItemList.size() >0">
  129. insert into t_table_template_table_item (table_template_id, item_id, time_item_type, place_holder, xaxis,
  130. yaxis,
  131. value_taking_mode, value_type, bucket_type, bucket_value, standby)
  132. values
  133. <foreach collection="tableTemplateTableItemList" item="tableTemplateTableItem" separator=",">
  134. (#{tableTemplateTableItem.tableTemplateId},
  135. #{tableTemplateTableItem.itemId},
  136. #{tableTemplateTableItem.timeItemType},
  137. #{tableTemplateTableItem.placeHolder},
  138. #{tableTemplateTableItem.xaxis}
  139. , #{tableTemplateTableItem.yaxis},
  140. #{tableTemplateTableItem.valueTakingMode},#{tableTemplateTableItem.valueType},
  141. #{tableTemplateTableItem.bucketType},
  142. #{tableTemplateTableItem.bucketValue},
  143. #{tableTemplateTableItem.standby})
  144. </foreach>
  145. </if>
  146. </insert>
  147. <insert id="addReportTableItem">
  148. insert into t_report_table_item (report_table_id, item_id, time_item_type, value_type, xaxis, yaxis, standby,
  149. value_list, value_time_list, value_index_list)
  150. value (#{reportTableId}, #{itemId}, #{timeItemType}, #{valueType}, #{xaxis}, #{yaxis}, #{standby},
  151. #{valueList}, #{valueTimeList}, #{valueIndexList})
  152. </insert>
  153. <insert id="addReportTableItemList">
  154. insert into t_report_table_item (report_table_id, item_id, time_item_type, value_type, xaxis, yaxis, standby,
  155. value_list, value_time_list, value_index_list)
  156. values
  157. <foreach collection="reportTableItemList" item="reportTableItem" separator=",">
  158. (#{reportTableItem.reportTableId}, #{reportTableItem.itemId},
  159. #{reportTableItem.timeItemType},#{reportTableItem.valueType},
  160. #{reportTableItem.xaxis},
  161. #{reportTableItem.yaxis}, #{reportTableItem.standby},
  162. #{reportTableItem.valueList}, #{reportTableItem.valueTimeList}, #{reportTableItem.valueIndexList})
  163. </foreach>
  164. </insert>
  165. <insert id="addTableTemplateChart" parameterType="com.example.opc_common.entity.TableTemplateChart"
  166. useGeneratedKeys="true"
  167. keyProperty="id">
  168. insert into t_table_template_chart(table_template_id, chart_type, chart_name, value_taking_mode, value_type,
  169. bucket_type,
  170. bucket_value, standby) VALUE
  171. (#{tableTemplateId},#{chartType},#{chartName}, #{valueTakingMode}, #{valueType},
  172. #{bucketType}, #{bucketValue}, #{standby})
  173. </insert>
  174. <insert id="addTableTemplateChartItem">
  175. insert into t_table_template_chart_item(table_template_chart_id, item_id) VALUES
  176. <foreach collection="tableTemplateChartItemList" item="tableTemplateChartItem" separator=",">
  177. (#{tableTemplateChartId}, #{tableTemplateChartItem.itemId})
  178. </foreach>
  179. </insert>
  180. <insert id="addReportChart" parameterType="com.example.opc_common.entity.ReportChart"
  181. useGeneratedKeys="true"
  182. keyProperty="id">
  183. insert into t_report_chart(report_table_id, template_chart_id, chart_type, chart_name, value_type, standby)
  184. value (#{reportTableId},#{templateChartId},#{chartType},#{chartName},#{valueType},#{standby})
  185. </insert>
  186. <insert id="addReportChartItem">
  187. insert into t_report_chart_item(report_chart_id,item_id,value_list,value_time_list,value_index_list)
  188. values
  189. <foreach collection="reportChartItemList" item="reportChartItem" separator=",">
  190. (#{reportChartItem.reportChartId},#{reportChartItem.itemId},#{reportChartItem.valueList},
  191. #{reportChartItem.valueTimeList},#{reportChartItem.valueIndexList})
  192. </foreach>
  193. </insert>
  194. <update id="updateTableTemplate">
  195. update t_table_template
  196. set template_name=#{templateName},
  197. template_data=#{templateData},
  198. event_num=#{eventNum},
  199. version=#{version},
  200. update_time=#{updateTime}
  201. where id = #{id}
  202. </update>
  203. <update id="updateReportTable">
  204. update t_report_table
  205. set report_table_name=#{reportTableName},
  206. report_table_data=#{reportTableData},
  207. version=#{version}
  208. where id = #{id}
  209. </update>
  210. <update id="updateReportTableDataById">
  211. update t_report_table
  212. set report_table_data=#{reportTableData}
  213. where id = #{id}
  214. </update>
  215. <update id="updateTableNameById">
  216. update t_report_table
  217. set report_table_name=#{reportTableName}
  218. where id = #{id}
  219. </update>
  220. <update id="updateTableNameByTableTemplateId">
  221. update t_report_table
  222. set report_table_name=#{reportTableName}
  223. where table_template_id = #{tableTemplateId}
  224. and report_table_type = #{templateType}
  225. </update>
  226. <update id="updateTableTemplateNameById">
  227. update t_table_template
  228. set template_name=#{templateName}
  229. where id = #{id}
  230. </update>
  231. <update id="updateReportTableNum">
  232. update t_report_table
  233. set current_num=#{currentNum}
  234. where id = #{id}
  235. </update>
  236. <update id="runAutoTableById">
  237. update t_report_table
  238. set run_state=#{runState}
  239. where id = #{id}
  240. </update>
  241. <update id="updateReportTableItem">
  242. update t_report_table_item
  243. set value_list=#{valueList},
  244. value_time_list=#{valueTimeList},
  245. value_index_list=#{valueIndexList}
  246. where id = #{id}
  247. </update>
  248. <update id="setAutoTableTime">
  249. update t_report_table
  250. set report_table_name=#{reportTableName},
  251. is_run_print=#{isRunPrint},
  252. print_ip=#{printIp},
  253. print_config_id=#{printConfigId},
  254. cron_id=#{cronId},
  255. type=#{type},
  256. cron=#{cron}
  257. where id = #{id}
  258. </update>
  259. <update id="logicDeleteReportTable">
  260. update t_report_table
  261. set is_delete=#{isDelete}
  262. where id = #{reportTableId}
  263. </update>
  264. <delete id="delTableTemplateById">
  265. delete
  266. from t_table_template
  267. where id = #{id}
  268. </delete>
  269. <delete id="delReportTableById">
  270. delete
  271. from t_report_table
  272. where id = #{id}
  273. </delete>
  274. <delete id="delChReportTableList">
  275. delete
  276. from t_report_table
  277. where id in
  278. <foreach collection="idList" item="id" separator="," open="(" close=")">
  279. #{id}
  280. </foreach>
  281. </delete>
  282. <!--(丢弃,使用delTableUserGroupUser)-->
  283. <delete id="delTableUserGroup">
  284. delete
  285. from t_table_user_group
  286. where table_id = #{reportTableId}
  287. </delete>
  288. <delete id="delTableTemplateLogByTtId">
  289. delete
  290. from t_table_template_log
  291. where table_template_id = #{tableTemplateId}
  292. </delete>
  293. <delete id="delAutoChLogList">
  294. delete
  295. from t_table_auto_log
  296. where auto_ch_table_id in
  297. <foreach collection="idList" item="id" separator="," open="(" close=")">
  298. #{id}
  299. </foreach>
  300. </delete>
  301. <delete id="delAutoChLog">
  302. delete
  303. from t_table_auto_log
  304. where auto_ch_table_id = #{autoChTableId}
  305. </delete>
  306. <!--(丢弃,使用delTableUserGroupUserList)-->
  307. <delete id="delTableUserGroupList">
  308. delete
  309. from t_table_user_group
  310. where table_id in
  311. <foreach collection="tableIdList" item="tableId" separator="," open="(" close=")">
  312. #{tableId}
  313. </foreach>
  314. </delete>
  315. <select id="getTableTemplateByName" resultType="com.example.opc_common.entity.TableTemplate">
  316. select
  317. <include refid="tableTemplateNoData"/>
  318. from t_table_template
  319. where user_id = #{userId}
  320. AND template_name = #{templateName}
  321. </select>
  322. <select id="getTableTemplateCount" resultType="java.lang.Long">
  323. select count(*)
  324. from t_table_template
  325. where user_id = #{userId}
  326. <if test="templateName != null and templateName != ''">
  327. AND template_name LIKE CONCAT('%', #{templateName}, '%')
  328. </if>
  329. <if test="templateType != null">
  330. and template_type=#{templateType}
  331. </if>
  332. </select>
  333. <select id="getAllTableTemplate" resultType="com.example.opc_common.entity.TableTemplate">
  334. select
  335. <include refid="tableTemplateNoData"/>
  336. from t_table_template
  337. where user_id = #{userId}
  338. <if test="templateName != null and templateName != ''">
  339. AND template_name LIKE CONCAT('%', #{templateName}, '%')
  340. </if>
  341. <if test="templateType != null">
  342. and template_type=#{templateType}
  343. </if>
  344. ORDER BY template_type,template_name
  345. limit #{startNum},#{limitNum}
  346. </select>
  347. <select id="getTableTemplateById" resultType="com.example.opc_common.entity.TableTemplate">
  348. select
  349. <include refid="tableTemplate"/>
  350. from t_table_template
  351. where id = #{id}
  352. </select>
  353. <select id="getTableTemplateNoDataById" resultType="com.example.opc_common.entity.TableTemplate">
  354. select
  355. <include refid="tableTemplateNoData"/>
  356. from t_table_template
  357. where id = #{id}
  358. </select>
  359. <select id="getTableTemplateByNameNoId" resultType="com.example.opc_common.entity.TableTemplate">
  360. select
  361. <include refid="tableTemplateNoData"/>
  362. from t_table_template
  363. where id != #{id}
  364. and user_id = #{userId}
  365. and template_name = #{templateName}
  366. </select>
  367. <select id="getReportTableByName" resultType="com.example.opc_common.entity.ReportTable">
  368. select
  369. <include refid="reportTableNoData"/>
  370. from t_report_table
  371. where user_id = #{userId}
  372. and report_table_name = #{reportTableName}
  373. </select>
  374. <select id="getReportTableByNameNoId" resultType="com.example.opc_common.entity.ReportTable">
  375. select
  376. <include refid="reportTableNoData"/>
  377. from t_report_table
  378. where user_id = #{userId}
  379. and report_table_name = #{reportTableName}
  380. and id != #{id}
  381. </select>
  382. <select id="getReportTableCount" resultType="java.lang.Integer">
  383. select count(DISTINCT r.id)
  384. from t_report_table r
  385. left join t_table_user_group_user g on r.id=g.report_table_id and g.user_id = #{userId}
  386. left join sys_user u on u.user_id=g.create_user_id
  387. where (r.user_id = #{userId} or g.user_id = #{userId})
  388. <if test="reportTableName != null and reportTableName != ''">
  389. AND report_table_name LIKE CONCAT('%', #{reportTableName}, '%')
  390. </if>
  391. <if test="reportTableType == null">
  392. AND r.report_table_type IN ( 0, 1, 2 ,5 )
  393. </if>
  394. <if test="reportTableType != null">
  395. AND report_table_type = #{reportTableType}
  396. </if>
  397. </select>
  398. <!--<select id="getAllReportTable" resultType="com.example.opc_common.entity.ReportTable">
  399. select
  400. r.id
  401. , r.report_table_type, r.table_template_id, r.user_id, r.report_table_name, r.start_time, r.current_num,
  402. r.is_gen_count_time, r.version, r.is_run_print, r.print_ip, r.print_config_id, r.cron_id, r.type, r.cron , r.run_state, r.create_time, r.is_delete,
  403. (select GROUP_CONCAT(u.user_group_name) from t_table_user_group g left outer join t_user_group u on u.id=g.user_group_id where r.id=g.table_id) shareGroup
  404. from t_report_table r
  405. where r.user_id = #{userId}
  406. <if test="reportTableName != null and reportTableName != ''">
  407. AND r.report_table_name LIKE CONCAT('%', #{reportTableName}, '%')
  408. </if>
  409. AND r.report_table_type IN ( 0, 1, 2 ,5 )
  410. <if test="reportTableType != null">
  411. AND r.report_table_type = #{reportTableType}
  412. </if>
  413. order by r.create_time desc
  414. limit #{startNum},#{limitNum}
  415. </select>-->
  416. <select id="getAllReportTable" resultType="com.example.opc_common.entity.ReportTable">
  417. select DISTINCT
  418. r.id
  419. , r.report_table_type, r.table_template_id, r.user_id, r.report_table_name, r.start_time, r.current_num,
  420. r.is_gen_count_time, r.version, r.is_run_print, r.print_ip, r.print_config_id, r.cron_id, r.type, r.cron , r.run_state, r.create_time, r.is_delete,
  421. (select GROUP_CONCAT(DISTINCT u.user_name) from t_table_user_group_user g inner join sys_user u on u.user_id=g.user_id where r.id=g.report_table_id) toShare,
  422. u.user_name byShare
  423. from t_report_table r
  424. left join t_table_user_group_user g on r.id=g.report_table_id and g.user_id = #{userId}
  425. left join sys_user u on u.user_id=g.create_user_id
  426. where (r.user_id = #{userId} or g.user_id = #{userId})
  427. <if test="reportTableName != null and reportTableName != ''">
  428. AND r.report_table_name LIKE CONCAT('%', #{reportTableName}, '%')
  429. </if>
  430. <if test="reportTableType == null">
  431. AND r.report_table_type IN ( 0, 1, 2 ,5 )
  432. </if>
  433. <if test="reportTableType != null">
  434. AND r.report_table_type = #{reportTableType}
  435. </if>
  436. order by r.create_time desc
  437. limit #{startNum},#{limitNum}
  438. </select>
  439. <select id="getAllReportTable2" resultType="com.example.opc_common.entity.ReportTable">
  440. select
  441. <include refid="reportTableCronNoData"/>
  442. from t_report_table
  443. where user_id = #{userId}
  444. <if test="reportTableName != null and reportTableName != ''">
  445. AND report_table_name LIKE CONCAT('%', #{reportTableName}, '%')
  446. </if>
  447. AND report_table_type IN ( 0, 1, 2 ,5 )
  448. <if test="reportTableType != null">
  449. AND report_table_type = #{reportTableType}
  450. </if>
  451. order by create_time desc
  452. limit #{startNum},#{limitNum}
  453. </select>
  454. <select id="getReportTableById" resultType="com.example.opc_common.entity.ReportTable">
  455. select
  456. <include refid="reportTableCron"/>
  457. from t_report_table
  458. where id = #{id}
  459. </select>
  460. <select id="getReportTableNoDataById" resultType="com.example.opc_common.entity.ReportTable">
  461. select
  462. <include refid="reportTableCronNoData"/>
  463. from t_report_table
  464. where id = #{id}
  465. </select>
  466. <select id="getReportTableNoDataByIds" resultType="com.example.opc_common.entity.ReportTable">
  467. select
  468. <include refid="reportTableCronNoData"/>
  469. from t_report_table
  470. where id in
  471. <foreach collection="idList" item="id" separator="," open="(" close=")">
  472. #{id}
  473. </foreach>
  474. </select>
  475. <select id="queryTableNum" resultType="java.lang.Integer">
  476. SELECT COUNT(*)
  477. FROM t_report_table
  478. where report_table_type IN ( 0, 1, 2 ,5 )
  479. </select>
  480. <select id="getAllAutoReportTable" resultType="com.example.opc_common.entity.ReportTable">
  481. select
  482. <include refid="reportTableCron"/>
  483. from t_report_table
  484. where report_table_type = #{isAutoReport}
  485. and run_state=#{startUp}
  486. </select>
  487. <!--(丢弃,使用getTableUserGroupUserCountByExp)-->
  488. <select id="getReportTableByUserGroupId" resultType="com.example.opc_common.entity.ReportTable">
  489. SELECT trt.id,
  490. trt.table_template_id,
  491. trt.user_id,
  492. trt.report_table_name,
  493. trt.start_time,
  494. trt.report_table_type,
  495. trt.version,
  496. trt.cron_id,
  497. trt.cron,
  498. trt.run_state,
  499. trt.create_time
  500. FROM t_report_table trt
  501. INNER JOIN (SELECT table_id FROM t_table_user_group WHERE user_group_id = #{userGroupId}) ttug
  502. ON trt.id = ttug.table_id;
  503. </select>
  504. <select id="getSysTableTemplate" resultType="com.example.opc_common.entity.SysTableTemplate">
  505. select
  506. id,
  507. dict_id,
  508. template_name,
  509. logo,
  510. create_time
  511. from t_sys_table_template
  512. WHERE 1=1
  513. <if test="dictIdList!= null and dictIdList.size() >0">
  514. AND dict_id IN
  515. <foreach collection="dictIdList" item="dictId" separator="," open="(" close=")">
  516. #{dictId}
  517. </foreach>
  518. </if>
  519. <if test="templateName != null">
  520. AND template_name LIKE CONCAT('%', #{templateName}, '%')
  521. </if>
  522. </select>
  523. <select id="getSysTableTemplateById" resultType="com.example.opc_common.entity.SysTableTemplate">
  524. select id,
  525. dict_id,
  526. template_name,
  527. template_data,
  528. logo,
  529. create_time
  530. from t_sys_table_template
  531. where id = #{id}
  532. </select>
  533. <!--(弃用,不执行reportTable.setUserGroupList(reportTableDao.getTableUserGroup(id));)-->
  534. <select id="getTableUserGroup" resultType="com.example.opc_common.entity.UserGroup">
  535. select ttug.user_group_id as id,
  536. tug.user_group_name as userGroupName
  537. from t_table_user_group ttug
  538. left join t_user_group tug on ttug.user_group_id = tug.id
  539. where table_id = #{reportTableId}
  540. </select>
  541. <!--(弃用,使用getAllReportTable)-->
  542. <select id="getAllOkReportTableCount" resultType="java.lang.Integer">
  543. select count(a.id) from ((select
  544. <include refid="reportTableNoData"/>
  545. from t_report_table
  546. where
  547. user_id = #{userId}
  548. <if test="reportTableName != null">
  549. AND report_table_name LIKE CONCAT('%', #{reportTableName}, '%')
  550. </if>
  551. AND report_table_type IN ( 0, 1, 2, 5 )
  552. <if test="reportTableType != null">
  553. AND report_table_type = #{reportTableType}
  554. </if>
  555. <if test="isDelete != null">
  556. AND is_delete = #{isDelete}
  557. </if>
  558. )
  559. UNION
  560. ( SELECT
  561. <include refid="reportTableNoData"/>
  562. FROM
  563. t_report_table
  564. WHERE
  565. 1=1
  566. <if test="reportTableName != null">
  567. AND report_table_name LIKE CONCAT('%', #{reportTableName}, '%')
  568. </if>
  569. AND report_table_type IN ( 0, 1, 2, 5 )
  570. <if test="reportTableType != null">
  571. AND report_table_type = #{reportTableType}
  572. </if>
  573. <if test="isDelete != null">
  574. AND is_delete = #{isDelete}
  575. </if>
  576. AND id IN (
  577. SELECT DISTINCT
  578. ( table_id )
  579. FROM
  580. t_table_user_group
  581. WHERE
  582. user_group_id IN
  583. ( SELECT user_group_id FROM t_user_group_user WHERE
  584. user_id = #{userId} )
  585. ))) a
  586. </select>
  587. <resultMap type="com.example.opc_common.entity.ReportTable" id="allReportTable">
  588. <id property="id" column="id"/>
  589. <result property="reportTableType" column="report_table_type"/>
  590. <result property="tableTemplateId" column="table_template_id"/>
  591. <result property="userId" column="user_id"/>
  592. <result property="userName" column="user_name"/>
  593. <result property="reportTableName" column="report_table_name"/>
  594. <result property="startTime" column="start_time"/>
  595. <result property="cronId" column="cron_id"/>
  596. <result property="cron" column="cron"/>
  597. <result property="runState" column="run_state"/>
  598. <result property="createTime" column="create_time"/>
  599. <result property="isDelete" column="is_delete"/>
  600. <!--<collection column="id" property="userGroupList"
  601. ofType="com.example.opc_common.entity.UserGroup" select="getUserGroupById">
  602. <id column="id" property="id"/>
  603. <id column="user_group_name" property="userGroupName"/>
  604. </collection>-->
  605. </resultMap>
  606. <!--(弃用)-->
  607. <select id="getUserGroupById" parameterType="STRING" resultType="com.example.opc_common.entity.UserGroup">
  608. select ttug.user_group_id as id,
  609. tug.user_group_name as userGroupName
  610. from t_table_user_group ttug
  611. left join t_user_group tug on ttug.user_group_id = tug.id
  612. where table_id = #{id}
  613. </select>
  614. <!--(弃用,使用getAllReportTable)-->
  615. <select id="getAllOkReportTable" resultMap="allReportTable">
  616. select
  617. trt.id,
  618. trt.report_table_type,
  619. trt.table_template_id,
  620. trt.user_id,
  621. su.user_name,
  622. trt.report_table_name,
  623. trt.start_time,
  624. trt.current_num,
  625. trt.version,
  626. trt.cron_id,
  627. trt.cron,
  628. trt.run_state,
  629. trt.create_time,
  630. trt.is_delete
  631. from ((select
  632. <include refid="reportTableCronNoData"/>
  633. from t_report_table
  634. where
  635. user_id = #{userId}
  636. <if test="reportTableName != null">
  637. AND report_table_name LIKE CONCAT('%', #{reportTableName}, '%')
  638. </if>
  639. AND report_table_type IN ( 0, 1, 2, 5 )
  640. <if test="reportTableType != null">
  641. AND report_table_type = #{reportTableType}
  642. </if>
  643. <if test="isDelete != null">
  644. AND is_delete = #{isDelete}
  645. </if>
  646. )
  647. UNION
  648. ( SELECT
  649. <include refid="reportTableCronNoData"/>
  650. FROM
  651. t_report_table
  652. WHERE
  653. 1=1
  654. <if test="reportTableName != null">
  655. AND report_table_name LIKE CONCAT('%', #{reportTableName}, '%')
  656. </if>
  657. AND report_table_type IN ( 0, 1, 2, 5 )
  658. <if test="reportTableType != null">
  659. AND report_table_type = #{reportTableType}
  660. </if>
  661. <if test="isDelete != null">
  662. AND is_delete = #{isDelete}
  663. </if>
  664. AND id IN (
  665. SELECT DISTINCT
  666. ( table_id )
  667. FROM
  668. t_table_user_group
  669. WHERE
  670. user_group_id IN
  671. ( SELECT user_group_id FROM t_user_group_user WHERE
  672. user_id = #{userId} )
  673. ))) trt LEFT JOIN sys_user su ON trt.user_id = su.user_id
  674. order by trt.create_time desc
  675. limit #{startNum},#{limitNum}
  676. </select>
  677. <select id="getAutoChReportTableCount" resultType="java.lang.Integer">
  678. select count(*)
  679. from t_report_table trt inner join t_table_auto_log ttal
  680. on trt.id=ttal.auto_ch_table_id
  681. where ttal.auto_table_id = #{tableId}
  682. <if test="reportTableName != null">
  683. AND trt.report_table_name LIKE CONCAT('%', #{reportTableName}, '%')
  684. </if>
  685. <if test="startTime != null and startTime != ''">
  686. AND trt.create_time &gt;= #{startTime}
  687. </if>
  688. <if test="endTime != null and endTime != ''">
  689. AND trt.create_time &lt;= #{endTime}
  690. </if>
  691. </select>
  692. <select id="getAutoChReportTable" resultMap="allReportTable">
  693. select trt.id,
  694. trt.report_table_type,
  695. trt.table_template_id,
  696. trt.user_id,
  697. trt.report_table_name,
  698. trt.start_time,
  699. trt.report_table_type,
  700. trt.version,
  701. trt.cron_id,
  702. trt.cron,
  703. trt.run_state,
  704. trt.create_time,
  705. trt.is_delete
  706. from t_report_table trt inner join t_table_auto_log ttal
  707. on trt.id=ttal.auto_ch_table_id
  708. where ttal.auto_table_id = #{autoTableId}
  709. <if test="reportTableName != null">
  710. AND trt.report_table_name LIKE CONCAT('%', #{reportTableName}, '%')
  711. </if>
  712. <if test="startTime != null and startTime != ''">
  713. AND trt.create_time &gt;= #{startTime}
  714. </if>
  715. <if test="endTime != null and endTime != ''">
  716. AND trt.create_time &lt;= #{endTime}
  717. </if>
  718. order by trt.create_time desc
  719. limit #{startNum},#{limitNum}
  720. </select>
  721. <select id="getAutoChTable" resultType="com.example.opc_common.entity.ReportTable">
  722. select
  723. <include refid="reportTableNoData"/>
  724. from t_report_table where id in
  725. ( select auto_ch_table_id from t_table_auto_log
  726. where auto_table_id=#{tableId})
  727. </select>
  728. <select id="getTableByItemId" resultType="java.lang.String">
  729. SELECT id
  730. FROM t_report_table
  731. WHERE table_template_id IN
  732. (SELECT DISTINCT (table_template_id) AS table_template_id
  733. FROM t_table_template_table_item
  734. WHERE 1=1
  735. <if test="itemList!= null and itemList.size() >0">
  736. and item_id in
  737. <foreach collection="itemList" item="item" separator="," open="(" close=")">
  738. #{item.id}
  739. </foreach>
  740. </if>
  741. )
  742. AND report_table_type = #{reportTableType}
  743. </select>
  744. <select id="getEventChTableId" resultType="java.lang.String">
  745. select id
  746. from t_report_table
  747. where id in
  748. (select auto_ch_table_id
  749. from t_table_auto_log
  750. where auto_table_id = #{tableId})
  751. order by id desc limit 1
  752. </select>
  753. <select id="getSecondChTableId" resultType="java.lang.String">
  754. select id
  755. from t_report_table
  756. where id in
  757. (select auto_ch_table_id
  758. from t_table_auto_log
  759. where auto_table_id = #{tableId})
  760. order by id desc limit 1,1
  761. </select>
  762. <select id="getLastChTableIdByVersion" resultType="java.lang.String">
  763. select id
  764. from t_report_table
  765. where id in
  766. (select auto_ch_table_id
  767. from t_table_auto_log
  768. where auto_table_id = #{tableId})
  769. and version = #{version}
  770. order by id desc limit 1
  771. </select>
  772. <select id="getReportTableItem" resultType="com.example.opc_common.entity.ReportTableItem">
  773. select
  774. <include refid="reportTableItem"/>
  775. from t_report_table_item
  776. where report_table_id = #{tableId}
  777. and item_id = #{itemId}
  778. <if test="timeItemType != null">
  779. AND time_item_type = #{timeItemType}
  780. </if>
  781. </select>
  782. <select id="getReportDataSource" resultType="com.example.opc_common.entity.DataSource">
  783. SELECT
  784. <include refid="dataSource"/>
  785. FROM
  786. t_data_source
  787. WHERE
  788. id IN (
  789. SELECT DISTINCT
  790. ( tig.data_source_id )
  791. FROM
  792. t_item ti
  793. LEFT JOIN t_item_group tig ON ti.item_group_id = tig.id
  794. LEFT JOIN t_data_source tds ON tig.data_source_id = tds.id
  795. WHERE
  796. ti.id IN
  797. <foreach collection="itemIdList" item="itemId" separator="," open="(" close=")">
  798. #{itemId}
  799. </foreach>
  800. )
  801. </select>
  802. <select id="getItemListByDataSource" resultType="com.example.opc_common.entity.Item">
  803. SELECT
  804. <include refid="item"/>
  805. FROM
  806. t_item
  807. WHERE
  808. id IN (
  809. SELECT DISTINCT
  810. ( allItem.item_id ) FROM ((SELECT DISTINCT
  811. ( item_id )
  812. FROM
  813. t_report_table_item
  814. WHERE
  815. report_table_id = #{id}) UNION ALL (SELECT DISTINCT ( item_id ) FROM t_report_chart_item WHERE report_chart_id
  816. in (SELECT id FROM t_report_chart WHERE
  817. report_table_id = #{id}) )) allItem
  818. WHERE allItem.item_id IN (
  819. SELECT
  820. id
  821. FROM
  822. t_item
  823. WHERE
  824. item_group_id IN ( SELECT id FROM t_item_group WHERE data_source_id = #{dataSource.id} )))
  825. </select>
  826. <select id="getChartDataSource" resultType="com.example.opc_common.entity.DataSource">
  827. SELECT
  828. <include refid="dataSource"/>
  829. FROM
  830. t_data_source
  831. WHERE
  832. id IN (
  833. SELECT DISTINCT
  834. ( tig.data_source_id )
  835. FROM
  836. t_item ti
  837. LEFT JOIN t_item_group tig ON ti.item_group_id = tig.id
  838. LEFT JOIN t_data_source tds ON tig.data_source_id = tds.id
  839. WHERE
  840. ti.id IN ( SELECT item_id FROM t_report_chart_item WHERE report_chart_id in
  841. (SELECT id FROM t_report_chart WHERE report_table_id = #{id})
  842. ))
  843. </select>
  844. <select id="getReportTableByTemplate" resultType="com.example.opc_common.entity.ReportTable">
  845. select
  846. <include refid="reportTableCron"/>
  847. from t_report_table
  848. where report_table_type = #{templateType}
  849. and table_template_id=#{id}
  850. </select>
  851. <select id="getReportTableByTemplateAndNoData" resultType="com.example.opc_common.entity.ReportTable">
  852. select
  853. <include refid="reportTableCronAndNoData"/>
  854. from t_report_table
  855. where report_table_type = #{templateType}
  856. and table_template_id=#{id}
  857. </select>
  858. <select id="getTtciByTtcId" resultType="com.example.opc_common.entity.TableTemplateChartItem">
  859. select tttci.id,
  860. tttci.table_template_chart_id,
  861. tttci.item_id,
  862. ti.item_group_id,
  863. ti.item_name,
  864. ti.item_type,
  865. tig.data_source_id
  866. from t_table_template_chart_item tttci
  867. LEFT JOIN t_item ti ON tttci.item_id = ti.id
  868. LEFT JOIN t_item_group tig ON ti.item_group_id = tig.id
  869. where tttci.table_template_chart_id = #{tableTemplateChartId}
  870. </select>
  871. <select id="getTtciCountByItemId" resultType="com.example.opc_common.entity.TableTemplate">
  872. SELECT
  873. <include refid="tableTemplateNoData"/>
  874. FROM
  875. t_table_template
  876. WHERE
  877. id IN (
  878. SELECT DISTINCT
  879. table_template_id
  880. FROM
  881. t_table_template_chart
  882. WHERE
  883. id IN (
  884. SELECT DISTINCT
  885. table_template_chart_id
  886. FROM
  887. t_table_template_chart_item
  888. WHERE
  889. item_id IN
  890. <foreach collection="itemList" item="item" separator="," open="(" close=")">
  891. #{item.id}
  892. </foreach>))
  893. </select>
  894. <resultMap type="com.example.opc_common.entity.TableTemplate" id="allTableTemplate">
  895. <id property="id" column="id"/>
  896. <result property="userId" column="user_id"/>
  897. <result property="templateName" column="template_name"/>
  898. <result property="templateType" column="template_type"/>
  899. <result property="eventNum" column="event_num"/>
  900. <result property="isGenCountTime" column="is_gen_count_time"/>
  901. <result property="variableType" column="variable_type"/>
  902. <result property="startItemId" column="start_item_id"/>
  903. <result property="startValue" column="start_value"/>
  904. <result property="endItemId" column="end_item_id"/>
  905. <result property="endValue" column="end_value"/>
  906. <result property="version" column="version"/>
  907. <result property="updateTime" column="update_time"/>
  908. <result property="createTime" column="create_time"/>
  909. <collection column="id" property="tableTemplateItemList"
  910. ofType="com.example.opc_common.entity.TableTemplateTableItem" select="getTttiByTemplateId">
  911. <id column="id" property="id"/>
  912. <id column="table_template_id" property="tableTemplateId"/>
  913. <id column="item_id" property="itemId"/>
  914. <id column="item_group_id" property="itemGroupId"/>
  915. <id column="item_name" property="itemName"/>
  916. <id column="item_read_name" property="itemReadName"/>
  917. <id column="item_type" property="itemType"/>
  918. <id column="data_source_id" property="dataSourceId"/>
  919. <id column="time_item_type" property="timeItemType"/>
  920. <id column="place_holder" property="placeHolder"/>
  921. <id column="xaxis" property="xaxis"/>
  922. <id column="yaxis" property="yaxis"/>
  923. <id column="value_taking_mode" property="valueTakingMode"/>
  924. <id column="value_type" property="valueType"/>
  925. <id column="bucket_type" property="bucketType"/>
  926. <id column="bucket_value" property="bucketValue"/>
  927. <id column="standby" property="standby"/>
  928. </collection>
  929. </resultMap>
  930. <select id="getDeviceTtByItemList" resultMap="allTableTemplate">
  931. SELECT
  932. <include refid="tableTemplateNoData"/>
  933. FROM
  934. t_table_template
  935. WHERE
  936. 1=1
  937. <if test="itemList!= null and itemList.size() >0">
  938. and start_item_id in
  939. <foreach collection="itemList" item="item" separator="," open="(" close=")">
  940. #{item.id}
  941. </foreach>
  942. or end_item_id in
  943. <foreach collection="itemList" item="item" separator="," open="(" close=")">
  944. #{item.id}
  945. </foreach>
  946. </if>
  947. AND template_type = #{templateType}
  948. </select>
  949. <select id="getTableItemId" resultType="java.lang.Integer">
  950. (SELECT item_id FROM t_report_table_item WHERE report_table_id = #{reportTableId})
  951. UNION ALL
  952. (SELECT item_id
  953. FROM t_report_chart_item
  954. WHERE report_chart_id in
  955. (SELECT id
  956. FROM t_report_chart
  957. WHERE report_table_id = #{reportTableId}))
  958. </select>
  959. <select id="getReportTableByttList" resultType="com.example.opc_common.entity.ReportTable">
  960. SELECT
  961. <include refid="reportTable"/>
  962. FROM
  963. t_report_table
  964. WHERE
  965. 1=1
  966. <if test="tableTemplateList!= null and tableTemplateList.size() >0">
  967. AND table_template_id in
  968. <foreach collection="tableTemplateList" item="tableTemplate" separator="," open="(" close=")">
  969. #{tableTemplate.id}
  970. </foreach>
  971. </if>
  972. AND report_table_type=#{reportTableType}
  973. </select>
  974. <select id="getMainTableBychTableId" resultType="com.example.opc_common.entity.ReportTable">
  975. select
  976. <include refid="reportTableCron"/>
  977. from t_report_table
  978. where id = (select auto_table_id from t_table_auto_log where auto_ch_table_id=#{chTableId})
  979. </select>
  980. <select id="getTttiByTemplateIdGroup" resultType="com.example.opc_common.entity.TableTemplateTableItem">
  981. SELECT ti.item_group_id,
  982. tig.data_source_id,
  983. tttti.bucket_type
  984. FROM t_table_template_table_item tttti
  985. LEFT JOIN t_item ti ON tttti.item_id = ti.id
  986. LEFT JOIN t_item_group tig ON ti.item_group_id = tig.id
  987. WHERE tttti.table_template_id = #{tableTemplateId}
  988. GROUP BY tttti.bucket_type,
  989. ti.item_group_id,
  990. tig.data_source_id
  991. </select>
  992. <select id="getTttiByGroup" resultType="com.example.opc_common.entity.TableTemplateTableItem">
  993. SELECT tttti.id,
  994. tttti.table_template_id,
  995. tttti.item_id,
  996. ti.item_group_id,
  997. ti.item_name,
  998. ti.item_read_name,
  999. ti.item_type,
  1000. tig.data_source_id,
  1001. tttti.time_item_type,
  1002. tttti.place_holder,
  1003. tttti.xaxis,
  1004. tttti.yaxis,
  1005. tttti.value_taking_mode,
  1006. tttti.value_type,
  1007. tttti.bucket_type,
  1008. tttti.bucket_value,
  1009. tttti.standby
  1010. FROM t_table_template_table_item tttti
  1011. LEFT JOIN t_item ti ON tttti.item_id = ti.id
  1012. LEFT JOIN t_item_group tig ON ti.item_group_id = tig.id
  1013. WHERE tttti.table_template_id = #{tableTemplateId}
  1014. AND ti.item_group_id = #{itemGroupId}
  1015. AND tig.data_source_id = #{dataSourceId}
  1016. AND tttti.bucket_type = #{bucketType}
  1017. </select>
  1018. <select id="getTableTemplateByItemList" resultMap="allTableTemplate">
  1019. SELECT
  1020. <include refid="tableTemplateNoData"/>
  1021. FROM
  1022. t_table_template
  1023. WHERE
  1024. id IN (
  1025. SELECT DISTINCT
  1026. table_template_id
  1027. FROM
  1028. t_table_template_table_item
  1029. WHERE
  1030. item_id IN
  1031. <foreach collection="itemList" item="item" separator="," open="(" close=")">
  1032. #{item.id}
  1033. </foreach>)
  1034. AND template_type = #{templateType}
  1035. </select>
  1036. <select id="getReportTableByTypeAndRunState" resultType="com.example.opc_common.entity.ReportTable">
  1037. select
  1038. <include refid="reportTable"/>
  1039. from t_report_table
  1040. where 1=1
  1041. <if test="runState != null ">
  1042. AND run_state = #{runState}
  1043. </if>
  1044. <if test="reportTableType != null">
  1045. AND report_table_type = #{reportTableType}
  1046. </if>
  1047. </select>
  1048. <insert id="addReportTableIdAndPolicyIdAndItemId">
  1049. insert into t_report_table_policy_item(report_table_id,policy_id,item_id)
  1050. values
  1051. <foreach collection="list" item="item" separator=",">
  1052. (#{item.reportTableId},#{item.policyId},#{item.itemId})
  1053. </foreach>
  1054. </insert>
  1055. <delete id="delReportTableIdAndPolicyIdAndItemIdByReportTableId">
  1056. delete
  1057. from t_report_table_policy_item
  1058. where report_table_id = #{reportTableId}
  1059. </delete>
  1060. <delete id="delReportTableIdAndPolicyIdAndItemIdByReportTableIds">
  1061. delete
  1062. from t_report_table_policy_item
  1063. where report_table_id in
  1064. <foreach collection="idList" item="id" separator="," open="(" close=")">
  1065. #{id}
  1066. </foreach>
  1067. </delete>
  1068. <select id="getReportTableNameByPolicyId" resultType="String">
  1069. select DISTINCT trt.report_table_name
  1070. from t_report_table_policy_item trtpi,t_report_table trt
  1071. where trtpi.report_table_id = trt.id and trtpi.policy_id = #{policyId}
  1072. ORDER BY trt.report_table_name
  1073. </select>
  1074. <select id="getReportTableAndItemByPolicyIdAndItemIdList" resultType="map">
  1075. SELECT ti.id,ti.itemReadName,GROUP_CONCAT(ti.reportTableId SEPARATOR ',') reportTableId
  1076. ,GROUP_CONCAT(ti.reportTableName order by ti.reportTableName SEPARATOR '、') reportTableName,ti.reportTableType
  1077. from (
  1078. SELECT DISTINCT ti.id,ti.item_read_name itemReadName
  1079. ,trt.id reportTableId,trt.report_table_name reportTableName,trt.report_table_type reportTableType
  1080. FROM t_report_table_policy_item trtpi,t_report_table trt,t_item ti
  1081. WHERE trtpi.report_table_id = trt.id AND trtpi.item_id = ti.id AND trtpi.policy_id = #{policyId}
  1082. AND trtpi.item_id IN
  1083. <foreach collection="itemIdList" item="id" separator="," open="(" close=")">
  1084. #{id}
  1085. </foreach>
  1086. ) ti
  1087. GROUP BY ti.id,ti.itemReadName,ti.reportTableType
  1088. ORDER BY ti.itemReadName
  1089. </select>
  1090. <!--查询报表策略使用报表采集策略的正在运行的报表名称-->
  1091. <select id="getRunReportTableByReportDataPolicyId" resultType="map">
  1092. select DISTINCT trt.report_table_name reportTableName,trt.report_table_type reportTableType
  1093. from t_report_table_policy_item trtpi,t_report_table trt
  1094. where trtpi.report_table_id = trt.id and trtpi.policy_id = #{policyId} and trt.run_state = 1 and trt.is_delete = 0
  1095. ORDER BY trt.report_table_name
  1096. </select>
  1097. <insert id="addTableUserGroupUser">
  1098. insert into t_table_user_group_user (report_table_id, user_group_id,user_id,create_user_id)
  1099. values
  1100. <foreach collection="tableUserGroupUserList" item="tableUserGroupUser" index="index" separator=",">
  1101. (#{tableUserGroupUser.reportTableId}, #{tableUserGroupUser.userGroupId}, #{tableUserGroupUser.userId}, #{createUserId})
  1102. </foreach>
  1103. </insert>
  1104. <delete id="delTableUserGroupUser">
  1105. delete
  1106. from t_table_user_group_user
  1107. where report_table_id = #{reportTableId}
  1108. </delete>
  1109. <delete id="delTableUserGroupUserList">
  1110. delete
  1111. from t_table_user_group_user
  1112. where report_table_id in
  1113. <foreach collection="reportTableIdList" item="reportTableId" separator="," open="(" close=")">
  1114. #{reportTableId}
  1115. </foreach>
  1116. </delete>
  1117. <select id="getTableUserGroupUserList" resultType="com.example.opc_common.entity.TableUserGroupUser">
  1118. select ttugu.report_table_id,ttugu.user_group_id,tug.user_group_name,GROUP_CONCAT(su.user_name) user_name,GROUP_CONCAT(su.user_id)user_ids
  1119. from t_table_user_group_user ttugu,t_user_group tug,sys_user su
  1120. where ttugu.report_table_id = #{reportTableId} and ttugu.user_group_id = tug.id and ttugu.user_id = su.user_id
  1121. GROUP BY ttugu.report_table_id,ttugu.user_group_id,tug.user_group_name
  1122. </select>
  1123. <select id="getTableUserGroupUserCountByExp" resultType="Integer">
  1124. SELECT count(*)
  1125. FROM t_table_user_group_user
  1126. <where>
  1127. <if test="userGroupId != null">
  1128. and user_group_id = #{userGroupId}
  1129. </if>
  1130. <if test="noDelUserIdList != null">
  1131. and user_id not in
  1132. <foreach collection="noDelUserIdList" item="userId" separator="," open="(" close=")">
  1133. #{userId}
  1134. </foreach>
  1135. </if>
  1136. </where>
  1137. </select>
  1138. <delete id="delTableUserGroupUserByExp">
  1139. DELETE
  1140. FROM t_table_user_group_user
  1141. <where>
  1142. <if test="userGroupId != null">
  1143. and user_group_id = #{userGroupId}
  1144. </if>
  1145. <if test="noDelUserIdList != null">
  1146. and user_id not in
  1147. <foreach collection="noDelUserIdList" item="userId" separator="," open="(" close=")">
  1148. #{userId}
  1149. </foreach>
  1150. </if>
  1151. </where>
  1152. </delete>
  1153. <!--查询报表记录数据项对应的小数位数(item_id为t_report_data_policy_item.id)-->
  1154. <select id="getItemScaleByReportTableIdOrPolicyIdOrItemId" resultType="com.example.opc_common.entity.ReportDataPolicyItem">
  1155. select DISTINCT trdpi.id,ti.id item_id,ti.scale
  1156. from t_report_table_policy_item trtpi,t_item ti,t_report_data_policy_item trdpi
  1157. where trtpi.item_id = ti.id and trdpi.report_data_policy_id = trtpi.policy_id and trdpi.item_id = trtpi.item_id
  1158. <if test="itemId != null">
  1159. and trtpi.item_id = #{itemId}
  1160. </if>
  1161. <if test="policyId != null">
  1162. and trtpi.policy_id = #{policyId}
  1163. </if>
  1164. <if test="reportTableId != null">
  1165. and trtpi.report_table_id = #{reportTableId}
  1166. </if>
  1167. </select>
  1168. </mapper>