1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.example.opc_da.dao.ReportTableDao">
- <sql id="tableTemplate">
- id
- , user_id, template_name, template_type, template_data, event_num, is_gen_count_time,
- variable_type, start_item_id, start_value, end_item_id, end_value, version, update_time, create_time
- </sql>
- <sql id="tableTemplateNoData">
- id
- , user_id, template_name , template_type, event_num, is_gen_count_time,
- variable_type, start_item_id, start_value, end_item_id, end_value, version, update_time, create_time
- </sql>
- <sql id="tableTemplateTableItem">
- id
- , table_template_id, item_id , time_item_type, place_holder, xaxis, yaxis, value_taking_mode, value_type, bucket_type,
- bucket_value, standby
- </sql>
- <sql id="tableTemplateChart">
- id
- , table_template_id, chart_type, chart_name, value_taking_mode, value_type, bucket_type,
- bucket_value, standby
- </sql>
- <sql id="tableTemplateChartItem">
- id
- , table_template_chart_id, item_id
- </sql>
- <sql id="reportTable">
- id
- , report_table_type, table_template_id, user_id, report_table_name, report_table_data, start_time,
- current_num, is_gen_count_time, version, is_run_print, print_ip, print_config_id, create_time, is_delete
- </sql>
- <sql id="reportTableItem">
- id
- , report_table_id, item_id, time_item_type, value_type, xaxis, yaxis, standby, value_list, value_time_list, value_index_list
- </sql>
- <sql id="reportTableNoData">
- id
- , report_table_type, table_template_id, user_id, report_table_name, start_time, current_num,
- is_gen_count_time, version, is_run_print, print_ip, print_config_id, create_time, is_delete
- </sql>
- <sql id="reportTableCron">
- id
- , report_table_type, table_template_id, user_id, report_table_name, report_table_data, start_time,
- 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
- </sql>
- <sql id="reportTableCronAndNoData">
- id
- , report_table_type, table_template_id, user_id, report_table_name, start_time,
- 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
- </sql>
- <sql id="reportTableCronNoData">
- id
- , report_table_type, table_template_id, user_id, report_table_name, start_time, 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
- </sql>
- <sql id="reportChart">
- id
- , report_table_id, template_chart_id, chart_type, chart_name, value_type, standby
- </sql>
- <sql id="reportChartItem">
- id
- , report_chart_id, item_id, value_list, value_time_list, value_index_list
- </sql>
- <sql id="dataSource">
- id
- , type_id, data_source_name, data_source_describe, ip_address, ip_port, ip_user_name, ip_password,
- security_mode, security_policy, identity_provider, certificate_dir, certificate_key, cls_id, prog_id, driver_describe, create_time
- </sql>
- <sql id="dataSourceType">
- id
- , parent_id, data_source_type_name, data_source_type_key, sort_num, data_source_type_describe
- </sql>
- <sql id="item">
- id
- , item_group_id, item_name, item_read_name, node_index , data_type, `describe`, data_model_id
- </sql>
- <insert id="addTableTemplate" parameterType="com.example.opc_common.entity.TableTemplate" useGeneratedKeys="true"
- keyProperty="id">
- insert into t_table_template(user_id, template_name, template_type, template_data,
- event_num, is_gen_count_time, variable_type, start_item_id,
- start_value, end_item_id, end_value, version,
- update_time,
- create_time)
- VALUE ( #{userId},
- #{templateName}, #{templateType},
- #{templateData}, #{eventNum}, #{isGenCountTime},#{variableType},#{startItemId},#{startValue},
- #{endItemId},#{endValue},
- #{version},#{updateTime},#{createTime}
- )
- </insert>
- <insert id="addReportTable" parameterType="com.example.opc_common.entity.ReportTable" useGeneratedKeys="true"
- keyProperty="id">
- insert into t_report_table(id, report_table_type, table_template_id, user_id, report_table_name,
- report_table_data, start_time, current_num, is_gen_count_time, version, cron_id,
- cron,
- create_time, is_delete) VALUE
- (#{id},#{reportTableType},#{tableTemplateId}, #{userId}, #{reportTableName}, #{reportTableData}, #{startTime},
- #{currentNum}, #{isGenCountTime}, #{version},
- #{cronId}, #{cron}, #{createTime}, #{isDelete})
- </insert>
- <insert id="addHaveKeyReport">
- insert into t_report_table(id, report_table_type, table_template_id, user_id, report_table_name,
- report_table_data, start_time, current_num, is_gen_count_time, version,
- is_run_print, print_ip, print_config_id, cron_id,cron,
- create_time, is_delete) VALUE
- (#{id},#{reportTableType},#{tableTemplateId}, #{userId}, #{reportTableName}, #{reportTableData}, #{startTime},
- #{currentNum}, #{isGenCountTime}, #{version}, #{isRunPrint}, #{printIp}, #{printConfigId},
- #{cronId}, #{cron}, #{createTime}, #{isDelete})
- </insert>
- <!--(丢弃,使用addTableUserGroupUser)-->
- <insert id="addTableUserGroup">
- insert into t_table_user_group (table_id, user_group_id)
- values
- <foreach collection="userGroupList" item="userGroup" index="index" separator=",">
- (#{reportTableId}, #{userGroup.id})
- </foreach>
- </insert>
- <insert id="addTableTemplateLog">
- insert into t_table_template_log(table_template_id, table_template_version, create_time)
- value (#{tableTemplateId},#{tableTemplateVersion},#{createTime})
- </insert>
- <insert id="addTableAutoLog">
- insert into t_table_auto_log (auto_table_id, auto_ch_table_id)
- value (#{autoTableId},#{autoChTableId})
- </insert>
- <insert id="addTableTemplateTableItem">
- <if test="tableTemplateTableItemList!= null and tableTemplateTableItemList.size() >0">
- insert into t_table_template_table_item (table_template_id, item_id, time_item_type, place_holder, xaxis,
- yaxis,
- value_taking_mode, value_type, bucket_type, bucket_value, standby)
- values
- <foreach collection="tableTemplateTableItemList" item="tableTemplateTableItem" separator=",">
- (#{tableTemplateTableItem.tableTemplateId},
- #{tableTemplateTableItem.itemId},
- #{tableTemplateTableItem.timeItemType},
- #{tableTemplateTableItem.placeHolder},
- #{tableTemplateTableItem.xaxis}
- , #{tableTemplateTableItem.yaxis},
- #{tableTemplateTableItem.valueTakingMode},#{tableTemplateTableItem.valueType},
- #{tableTemplateTableItem.bucketType},
- #{tableTemplateTableItem.bucketValue},
- #{tableTemplateTableItem.standby})
- </foreach>
- </if>
- </insert>
- <insert id="addReportTableItem">
- insert into t_report_table_item (report_table_id, item_id, time_item_type, value_type, xaxis, yaxis, standby,
- value_list, value_time_list, value_index_list)
- value (#{reportTableId}, #{itemId}, #{timeItemType}, #{valueType}, #{xaxis}, #{yaxis}, #{standby},
- #{valueList}, #{valueTimeList}, #{valueIndexList})
- </insert>
- <insert id="addReportTableItemList">
- insert into t_report_table_item (report_table_id, item_id, time_item_type, value_type, xaxis, yaxis, standby,
- value_list, value_time_list, value_index_list)
- values
- <foreach collection="reportTableItemList" item="reportTableItem" separator=",">
- (#{reportTableItem.reportTableId}, #{reportTableItem.itemId},
- #{reportTableItem.timeItemType},#{reportTableItem.valueType},
- #{reportTableItem.xaxis},
- #{reportTableItem.yaxis}, #{reportTableItem.standby},
- #{reportTableItem.valueList}, #{reportTableItem.valueTimeList}, #{reportTableItem.valueIndexList})
- </foreach>
- </insert>
- <insert id="addTableTemplateChart" parameterType="com.example.opc_common.entity.TableTemplateChart"
- useGeneratedKeys="true"
- keyProperty="id">
- insert into t_table_template_chart(table_template_id, chart_type, chart_name, value_taking_mode, value_type,
- bucket_type,
- bucket_value, standby) VALUE
- (#{tableTemplateId},#{chartType},#{chartName}, #{valueTakingMode}, #{valueType},
- #{bucketType}, #{bucketValue}, #{standby})
- </insert>
- <insert id="addTableTemplateChartItem">
- insert into t_table_template_chart_item(table_template_chart_id, item_id) VALUES
- <foreach collection="tableTemplateChartItemList" item="tableTemplateChartItem" separator=",">
- (#{tableTemplateChartId}, #{tableTemplateChartItem.itemId})
- </foreach>
- </insert>
- <insert id="addReportChart" parameterType="com.example.opc_common.entity.ReportChart"
- useGeneratedKeys="true"
- keyProperty="id">
- insert into t_report_chart(report_table_id, template_chart_id, chart_type, chart_name, value_type, standby)
- value (#{reportTableId},#{templateChartId},#{chartType},#{chartName},#{valueType},#{standby})
- </insert>
- <insert id="addReportChartItem">
- insert into t_report_chart_item(report_chart_id,item_id,value_list,value_time_list,value_index_list)
- values
- <foreach collection="reportChartItemList" item="reportChartItem" separator=",">
- (#{reportChartItem.reportChartId},#{reportChartItem.itemId},#{reportChartItem.valueList},
- #{reportChartItem.valueTimeList},#{reportChartItem.valueIndexList})
- </foreach>
- </insert>
- <update id="updateTableTemplate">
- update t_table_template
- set template_name=#{templateName},
- template_data=#{templateData},
- event_num=#{eventNum},
- version=#{version},
- update_time=#{updateTime}
- where id = #{id}
- </update>
- <update id="updateReportTable">
- update t_report_table
- set report_table_name=#{reportTableName},
- report_table_data=#{reportTableData},
- version=#{version}
- where id = #{id}
- </update>
- <update id="updateReportTableDataById">
- update t_report_table
- set report_table_data=#{reportTableData}
- where id = #{id}
- </update>
- <update id="updateTableNameById">
- update t_report_table
- set report_table_name=#{reportTableName}
- where id = #{id}
- </update>
- <update id="updateTableNameByTableTemplateId">
- update t_report_table
- set report_table_name=#{reportTableName}
- where table_template_id = #{tableTemplateId}
- and report_table_type = #{templateType}
- </update>
- <update id="updateTableTemplateNameById">
- update t_table_template
- set template_name=#{templateName}
- where id = #{id}
- </update>
- <update id="updateReportTableNum">
- update t_report_table
- set current_num=#{currentNum}
- where id = #{id}
- </update>
- <update id="runAutoTableById">
- update t_report_table
- set run_state=#{runState}
- where id = #{id}
- </update>
- <update id="updateReportTableItem">
- update t_report_table_item
- set value_list=#{valueList},
- value_time_list=#{valueTimeList},
- value_index_list=#{valueIndexList}
- where id = #{id}
- </update>
- <update id="setAutoTableTime">
- update t_report_table
- set report_table_name=#{reportTableName},
- is_run_print=#{isRunPrint},
- print_ip=#{printIp},
- print_config_id=#{printConfigId},
- cron_id=#{cronId},
- type=#{type},
- cron=#{cron}
- where id = #{id}
- </update>
- <update id="logicDeleteReportTable">
- update t_report_table
- set is_delete=#{isDelete}
- where id = #{reportTableId}
- </update>
- <delete id="delTableTemplateById">
- delete
- from t_table_template
- where id = #{id}
- </delete>
- <delete id="delReportTableById">
- delete
- from t_report_table
- where id = #{id}
- </delete>
- <delete id="delChReportTableList">
- delete
- from t_report_table
- where id in
- <foreach collection="idList" item="id" separator="," open="(" close=")">
- #{id}
- </foreach>
- </delete>
- <!--(丢弃,使用delTableUserGroupUser)-->
- <delete id="delTableUserGroup">
- delete
- from t_table_user_group
- where table_id = #{reportTableId}
- </delete>
- <delete id="delTableTemplateLogByTtId">
- delete
- from t_table_template_log
- where table_template_id = #{tableTemplateId}
- </delete>
- <delete id="delAutoChLogList">
- delete
- from t_table_auto_log
- where auto_ch_table_id in
- <foreach collection="idList" item="id" separator="," open="(" close=")">
- #{id}
- </foreach>
- </delete>
- <delete id="delAutoChLog">
- delete
- from t_table_auto_log
- where auto_ch_table_id = #{autoChTableId}
- </delete>
- <!--(丢弃,使用delTableUserGroupUserList)-->
- <delete id="delTableUserGroupList">
- delete
- from t_table_user_group
- where table_id in
- <foreach collection="tableIdList" item="tableId" separator="," open="(" close=")">
- #{tableId}
- </foreach>
- </delete>
- <select id="getTableTemplateByName" resultType="com.example.opc_common.entity.TableTemplate">
- select
- <include refid="tableTemplateNoData"/>
- from t_table_template
- where user_id = #{userId}
- AND template_name = #{templateName}
- </select>
- <select id="getTableTemplateCount" resultType="java.lang.Long">
- select count(*)
- from t_table_template
- where user_id = #{userId}
- <if test="templateName != null and templateName != ''">
- AND template_name LIKE CONCAT('%', #{templateName}, '%')
- </if>
- <if test="templateType != null">
- and template_type=#{templateType}
- </if>
- </select>
- <select id="getAllTableTemplate" resultType="com.example.opc_common.entity.TableTemplate">
- select
- <include refid="tableTemplateNoData"/>
- from t_table_template
- where user_id = #{userId}
- <if test="templateName != null and templateName != ''">
- AND template_name LIKE CONCAT('%', #{templateName}, '%')
- </if>
- <if test="templateType != null">
- and template_type=#{templateType}
- </if>
- ORDER BY template_type,template_name
- limit #{startNum},#{limitNum}
- </select>
- <select id="getTableTemplateById" resultType="com.example.opc_common.entity.TableTemplate">
- select
- <include refid="tableTemplate"/>
- from t_table_template
- where id = #{id}
- </select>
- <select id="getTableTemplateNoDataById" resultType="com.example.opc_common.entity.TableTemplate">
- select
- <include refid="tableTemplateNoData"/>
- from t_table_template
- where id = #{id}
- </select>
- <select id="getTableTemplateByNameNoId" resultType="com.example.opc_common.entity.TableTemplate">
- select
- <include refid="tableTemplateNoData"/>
- from t_table_template
- where id != #{id}
- and user_id = #{userId}
- and template_name = #{templateName}
- </select>
- <select id="getReportTableByName" resultType="com.example.opc_common.entity.ReportTable">
- select
- <include refid="reportTableNoData"/>
- from t_report_table
- where user_id = #{userId}
- and report_table_name = #{reportTableName}
- </select>
- <select id="getReportTableByNameNoId" resultType="com.example.opc_common.entity.ReportTable">
- select
- <include refid="reportTableNoData"/>
- from t_report_table
- where user_id = #{userId}
- and report_table_name = #{reportTableName}
- and id != #{id}
- </select>
- <select id="getReportTableCount" resultType="java.lang.Integer">
- select count(DISTINCT r.id)
- from t_report_table r
- left join t_table_user_group_user g on r.id=g.report_table_id and g.user_id = #{userId}
- left join sys_user u on u.user_id=g.create_user_id
- where (r.user_id = #{userId} or g.user_id = #{userId})
- <if test="reportTableName != null and reportTableName != ''">
- AND report_table_name LIKE CONCAT('%', #{reportTableName}, '%')
- </if>
- <if test="reportTableType == null">
- AND r.report_table_type IN ( 0, 1, 2 ,5 )
- </if>
- <if test="reportTableType != null">
- AND report_table_type = #{reportTableType}
- </if>
- </select>
- <!--<select id="getAllReportTable" resultType="com.example.opc_common.entity.ReportTable">
- select
- r.id
- , r.report_table_type, r.table_template_id, r.user_id, r.report_table_name, r.start_time, r.current_num,
- 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,
- (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
- from t_report_table r
- where r.user_id = #{userId}
- <if test="reportTableName != null and reportTableName != ''">
- AND r.report_table_name LIKE CONCAT('%', #{reportTableName}, '%')
- </if>
- AND r.report_table_type IN ( 0, 1, 2 ,5 )
- <if test="reportTableType != null">
- AND r.report_table_type = #{reportTableType}
- </if>
- order by r.create_time desc
- limit #{startNum},#{limitNum}
- </select>-->
- <select id="getAllReportTable" resultType="com.example.opc_common.entity.ReportTable">
- select DISTINCT
- r.id
- , r.report_table_type, r.table_template_id, r.user_id, r.report_table_name, r.start_time, r.current_num,
- 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,
- (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,
- u.user_name byShare
- from t_report_table r
- left join t_table_user_group_user g on r.id=g.report_table_id and g.user_id = #{userId}
- left join sys_user u on u.user_id=g.create_user_id
- where (r.user_id = #{userId} or g.user_id = #{userId})
- <if test="reportTableName != null and reportTableName != ''">
- AND r.report_table_name LIKE CONCAT('%', #{reportTableName}, '%')
- </if>
- <if test="reportTableType == null">
- AND r.report_table_type IN ( 0, 1, 2 ,5 )
- </if>
- <if test="reportTableType != null">
- AND r.report_table_type = #{reportTableType}
- </if>
- order by r.create_time desc
- limit #{startNum},#{limitNum}
- </select>
- <select id="getAllReportTable2" resultType="com.example.opc_common.entity.ReportTable">
- select
- <include refid="reportTableCronNoData"/>
- from t_report_table
- where user_id = #{userId}
- <if test="reportTableName != null and reportTableName != ''">
- AND report_table_name LIKE CONCAT('%', #{reportTableName}, '%')
- </if>
- AND report_table_type IN ( 0, 1, 2 ,5 )
- <if test="reportTableType != null">
- AND report_table_type = #{reportTableType}
- </if>
- order by create_time desc
- limit #{startNum},#{limitNum}
- </select>
- <select id="getReportTableById" resultType="com.example.opc_common.entity.ReportTable">
- select
- <include refid="reportTableCron"/>
- from t_report_table
- where id = #{id}
- </select>
- <select id="getReportTableNoDataById" resultType="com.example.opc_common.entity.ReportTable">
- select
- <include refid="reportTableCronNoData"/>
- from t_report_table
- where id = #{id}
- </select>
- <select id="getReportTableNoDataByIds" resultType="com.example.opc_common.entity.ReportTable">
- select
- <include refid="reportTableCronNoData"/>
- from t_report_table
- where id in
- <foreach collection="idList" item="id" separator="," open="(" close=")">
- #{id}
- </foreach>
- </select>
- <select id="queryTableNum" resultType="java.lang.Integer">
- SELECT COUNT(*)
- FROM t_report_table
- where report_table_type IN ( 0, 1, 2 ,5 )
- </select>
- <select id="getAllAutoReportTable" resultType="com.example.opc_common.entity.ReportTable">
- select
- <include refid="reportTableCron"/>
- from t_report_table
- where report_table_type = #{isAutoReport}
- and run_state=#{startUp}
- </select>
- <!--(丢弃,使用getTableUserGroupUserCountByExp)-->
- <select id="getReportTableByUserGroupId" resultType="com.example.opc_common.entity.ReportTable">
- SELECT trt.id,
- trt.table_template_id,
- trt.user_id,
- trt.report_table_name,
- trt.start_time,
- trt.report_table_type,
- trt.version,
- trt.cron_id,
- trt.cron,
- trt.run_state,
- trt.create_time
- FROM t_report_table trt
- INNER JOIN (SELECT table_id FROM t_table_user_group WHERE user_group_id = #{userGroupId}) ttug
- ON trt.id = ttug.table_id;
- </select>
- <select id="getSysTableTemplate" resultType="com.example.opc_common.entity.SysTableTemplate">
- select
- id,
- dict_id,
- template_name,
- logo,
- create_time
- from t_sys_table_template
- WHERE 1=1
- <if test="dictIdList!= null and dictIdList.size() >0">
- AND dict_id IN
- <foreach collection="dictIdList" item="dictId" separator="," open="(" close=")">
- #{dictId}
- </foreach>
- </if>
- <if test="templateName != null">
- AND template_name LIKE CONCAT('%', #{templateName}, '%')
- </if>
- </select>
- <select id="getSysTableTemplateById" resultType="com.example.opc_common.entity.SysTableTemplate">
- select id,
- dict_id,
- template_name,
- template_data,
- logo,
- create_time
- from t_sys_table_template
- where id = #{id}
- </select>
- <!--(弃用,不执行reportTable.setUserGroupList(reportTableDao.getTableUserGroup(id));)-->
- <select id="getTableUserGroup" resultType="com.example.opc_common.entity.UserGroup">
- select ttug.user_group_id as id,
- tug.user_group_name as userGroupName
- from t_table_user_group ttug
- left join t_user_group tug on ttug.user_group_id = tug.id
- where table_id = #{reportTableId}
- </select>
- <!--(弃用,使用getAllReportTable)-->
- <select id="getAllOkReportTableCount" resultType="java.lang.Integer">
- select count(a.id) from ((select
- <include refid="reportTableNoData"/>
- from t_report_table
- where
- user_id = #{userId}
- <if test="reportTableName != null">
- AND report_table_name LIKE CONCAT('%', #{reportTableName}, '%')
- </if>
- AND report_table_type IN ( 0, 1, 2, 5 )
- <if test="reportTableType != null">
- AND report_table_type = #{reportTableType}
- </if>
- <if test="isDelete != null">
- AND is_delete = #{isDelete}
- </if>
- )
- UNION
- ( SELECT
- <include refid="reportTableNoData"/>
- FROM
- t_report_table
- WHERE
- 1=1
- <if test="reportTableName != null">
- AND report_table_name LIKE CONCAT('%', #{reportTableName}, '%')
- </if>
- AND report_table_type IN ( 0, 1, 2, 5 )
- <if test="reportTableType != null">
- AND report_table_type = #{reportTableType}
- </if>
- <if test="isDelete != null">
- AND is_delete = #{isDelete}
- </if>
- AND id IN (
- SELECT DISTINCT
- ( table_id )
- FROM
- t_table_user_group
- WHERE
- user_group_id IN
- ( SELECT user_group_id FROM t_user_group_user WHERE
- user_id = #{userId} )
- ))) a
- </select>
- <resultMap type="com.example.opc_common.entity.ReportTable" id="allReportTable">
- <id property="id" column="id"/>
- <result property="reportTableType" column="report_table_type"/>
- <result property="tableTemplateId" column="table_template_id"/>
- <result property="userId" column="user_id"/>
- <result property="userName" column="user_name"/>
- <result property="reportTableName" column="report_table_name"/>
- <result property="startTime" column="start_time"/>
- <result property="cronId" column="cron_id"/>
- <result property="cron" column="cron"/>
- <result property="runState" column="run_state"/>
- <result property="createTime" column="create_time"/>
- <result property="isDelete" column="is_delete"/>
- <!--<collection column="id" property="userGroupList"
- ofType="com.example.opc_common.entity.UserGroup" select="getUserGroupById">
- <id column="id" property="id"/>
- <id column="user_group_name" property="userGroupName"/>
- </collection>-->
- </resultMap>
- <!--(弃用)-->
- <select id="getUserGroupById" parameterType="STRING" resultType="com.example.opc_common.entity.UserGroup">
- select ttug.user_group_id as id,
- tug.user_group_name as userGroupName
- from t_table_user_group ttug
- left join t_user_group tug on ttug.user_group_id = tug.id
- where table_id = #{id}
- </select>
- <!--(弃用,使用getAllReportTable)-->
- <select id="getAllOkReportTable" resultMap="allReportTable">
- select
- trt.id,
- trt.report_table_type,
- trt.table_template_id,
- trt.user_id,
- su.user_name,
- trt.report_table_name,
- trt.start_time,
- trt.current_num,
- trt.version,
- trt.cron_id,
- trt.cron,
- trt.run_state,
- trt.create_time,
- trt.is_delete
- from ((select
- <include refid="reportTableCronNoData"/>
- from t_report_table
- where
- user_id = #{userId}
- <if test="reportTableName != null">
- AND report_table_name LIKE CONCAT('%', #{reportTableName}, '%')
- </if>
- AND report_table_type IN ( 0, 1, 2, 5 )
- <if test="reportTableType != null">
- AND report_table_type = #{reportTableType}
- </if>
- <if test="isDelete != null">
- AND is_delete = #{isDelete}
- </if>
- )
- UNION
- ( SELECT
- <include refid="reportTableCronNoData"/>
- FROM
- t_report_table
- WHERE
- 1=1
- <if test="reportTableName != null">
- AND report_table_name LIKE CONCAT('%', #{reportTableName}, '%')
- </if>
- AND report_table_type IN ( 0, 1, 2, 5 )
- <if test="reportTableType != null">
- AND report_table_type = #{reportTableType}
- </if>
- <if test="isDelete != null">
- AND is_delete = #{isDelete}
- </if>
- AND id IN (
- SELECT DISTINCT
- ( table_id )
- FROM
- t_table_user_group
- WHERE
- user_group_id IN
- ( SELECT user_group_id FROM t_user_group_user WHERE
- user_id = #{userId} )
- ))) trt LEFT JOIN sys_user su ON trt.user_id = su.user_id
- order by trt.create_time desc
- limit #{startNum},#{limitNum}
- </select>
- <select id="getAutoChReportTableCount" resultType="java.lang.Integer">
- select count(*)
- from t_report_table trt inner join t_table_auto_log ttal
- on trt.id=ttal.auto_ch_table_id
- where ttal.auto_table_id = #{tableId}
- <if test="reportTableName != null">
- AND trt.report_table_name LIKE CONCAT('%', #{reportTableName}, '%')
- </if>
- <if test="startTime != null and startTime != ''">
- AND trt.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND trt.create_time <= #{endTime}
- </if>
- </select>
- <select id="getAutoChReportTable" resultMap="allReportTable">
- select trt.id,
- trt.report_table_type,
- trt.table_template_id,
- trt.user_id,
- trt.report_table_name,
- trt.start_time,
- trt.report_table_type,
- trt.version,
- trt.cron_id,
- trt.cron,
- trt.run_state,
- trt.create_time,
- trt.is_delete
- from t_report_table trt inner join t_table_auto_log ttal
- on trt.id=ttal.auto_ch_table_id
- where ttal.auto_table_id = #{autoTableId}
- <if test="reportTableName != null">
- AND trt.report_table_name LIKE CONCAT('%', #{reportTableName}, '%')
- </if>
- <if test="startTime != null and startTime != ''">
- AND trt.create_time >= #{startTime}
- </if>
- <if test="endTime != null and endTime != ''">
- AND trt.create_time <= #{endTime}
- </if>
- order by trt.create_time desc
- limit #{startNum},#{limitNum}
- </select>
- <select id="getAutoChTable" resultType="com.example.opc_common.entity.ReportTable">
- select
- <include refid="reportTableNoData"/>
- from t_report_table where id in
- ( select auto_ch_table_id from t_table_auto_log
- where auto_table_id=#{tableId})
- </select>
- <select id="getTableByItemId" resultType="java.lang.String">
- SELECT id
- FROM t_report_table
- WHERE table_template_id IN
- (SELECT DISTINCT (table_template_id) AS table_template_id
- FROM t_table_template_table_item
- WHERE 1=1
- <if test="itemList!= null and itemList.size() >0">
- and item_id in
- <foreach collection="itemList" item="item" separator="," open="(" close=")">
- #{item.id}
- </foreach>
- </if>
- )
- AND report_table_type = #{reportTableType}
- </select>
- <select id="getEventChTableId" resultType="java.lang.String">
- select id
- from t_report_table
- where id in
- (select auto_ch_table_id
- from t_table_auto_log
- where auto_table_id = #{tableId})
- order by id desc limit 1
- </select>
- <select id="getSecondChTableId" resultType="java.lang.String">
- select id
- from t_report_table
- where id in
- (select auto_ch_table_id
- from t_table_auto_log
- where auto_table_id = #{tableId})
- order by id desc limit 1,1
- </select>
- <select id="getLastChTableIdByVersion" resultType="java.lang.String">
- select id
- from t_report_table
- where id in
- (select auto_ch_table_id
- from t_table_auto_log
- where auto_table_id = #{tableId})
- and version = #{version}
- order by id desc limit 1
- </select>
- <select id="getReportTableItem" resultType="com.example.opc_common.entity.ReportTableItem">
- select
- <include refid="reportTableItem"/>
- from t_report_table_item
- where report_table_id = #{tableId}
- and item_id = #{itemId}
- <if test="timeItemType != null">
- AND time_item_type = #{timeItemType}
- </if>
- </select>
- <select id="getReportDataSource" resultType="com.example.opc_common.entity.DataSource">
- SELECT
- <include refid="dataSource"/>
- FROM
- t_data_source
- WHERE
- id IN (
- SELECT DISTINCT
- ( tig.data_source_id )
- FROM
- t_item ti
- LEFT JOIN t_item_group tig ON ti.item_group_id = tig.id
- LEFT JOIN t_data_source tds ON tig.data_source_id = tds.id
- WHERE
- ti.id IN
- <foreach collection="itemIdList" item="itemId" separator="," open="(" close=")">
- #{itemId}
- </foreach>
- )
- </select>
- <select id="getItemListByDataSource" resultType="com.example.opc_common.entity.Item">
- SELECT
- <include refid="item"/>
- FROM
- t_item
- WHERE
- id IN (
- SELECT DISTINCT
- ( allItem.item_id ) FROM ((SELECT DISTINCT
- ( item_id )
- FROM
- t_report_table_item
- WHERE
- report_table_id = #{id}) UNION ALL (SELECT DISTINCT ( item_id ) FROM t_report_chart_item WHERE report_chart_id
- in (SELECT id FROM t_report_chart WHERE
- report_table_id = #{id}) )) allItem
- WHERE allItem.item_id IN (
- SELECT
- id
- FROM
- t_item
- WHERE
- item_group_id IN ( SELECT id FROM t_item_group WHERE data_source_id = #{dataSource.id} )))
- </select>
- <select id="getChartDataSource" resultType="com.example.opc_common.entity.DataSource">
- SELECT
- <include refid="dataSource"/>
- FROM
- t_data_source
- WHERE
- id IN (
- SELECT DISTINCT
- ( tig.data_source_id )
- FROM
- t_item ti
- LEFT JOIN t_item_group tig ON ti.item_group_id = tig.id
- LEFT JOIN t_data_source tds ON tig.data_source_id = tds.id
- WHERE
- ti.id IN ( SELECT item_id FROM t_report_chart_item WHERE report_chart_id in
- (SELECT id FROM t_report_chart WHERE report_table_id = #{id})
- ))
- </select>
- <select id="getReportTableByTemplate" resultType="com.example.opc_common.entity.ReportTable">
- select
- <include refid="reportTableCron"/>
- from t_report_table
- where report_table_type = #{templateType}
- and table_template_id=#{id}
- </select>
- <select id="getReportTableByTemplateAndNoData" resultType="com.example.opc_common.entity.ReportTable">
- select
- <include refid="reportTableCronAndNoData"/>
- from t_report_table
- where report_table_type = #{templateType}
- and table_template_id=#{id}
- </select>
- <select id="getTtciByTtcId" resultType="com.example.opc_common.entity.TableTemplateChartItem">
- select tttci.id,
- tttci.table_template_chart_id,
- tttci.item_id,
- ti.item_group_id,
- ti.item_name,
- ti.item_type,
- tig.data_source_id
- from t_table_template_chart_item tttci
- LEFT JOIN t_item ti ON tttci.item_id = ti.id
- LEFT JOIN t_item_group tig ON ti.item_group_id = tig.id
- where tttci.table_template_chart_id = #{tableTemplateChartId}
- </select>
- <select id="getTtciCountByItemId" resultType="com.example.opc_common.entity.TableTemplate">
- SELECT
- <include refid="tableTemplateNoData"/>
- FROM
- t_table_template
- WHERE
- id IN (
- SELECT DISTINCT
- table_template_id
- FROM
- t_table_template_chart
- WHERE
- id IN (
- SELECT DISTINCT
- table_template_chart_id
- FROM
- t_table_template_chart_item
- WHERE
- item_id IN
- <foreach collection="itemList" item="item" separator="," open="(" close=")">
- #{item.id}
- </foreach>))
- </select>
- <resultMap type="com.example.opc_common.entity.TableTemplate" id="allTableTemplate">
- <id property="id" column="id"/>
- <result property="userId" column="user_id"/>
- <result property="templateName" column="template_name"/>
- <result property="templateType" column="template_type"/>
- <result property="eventNum" column="event_num"/>
- <result property="isGenCountTime" column="is_gen_count_time"/>
- <result property="variableType" column="variable_type"/>
- <result property="startItemId" column="start_item_id"/>
- <result property="startValue" column="start_value"/>
- <result property="endItemId" column="end_item_id"/>
- <result property="endValue" column="end_value"/>
- <result property="version" column="version"/>
- <result property="updateTime" column="update_time"/>
- <result property="createTime" column="create_time"/>
- <collection column="id" property="tableTemplateItemList"
- ofType="com.example.opc_common.entity.TableTemplateTableItem" select="getTttiByTemplateId">
- <id column="id" property="id"/>
- <id column="table_template_id" property="tableTemplateId"/>
- <id column="item_id" property="itemId"/>
- <id column="item_group_id" property="itemGroupId"/>
- <id column="item_name" property="itemName"/>
- <id column="item_read_name" property="itemReadName"/>
- <id column="item_type" property="itemType"/>
- <id column="data_source_id" property="dataSourceId"/>
- <id column="time_item_type" property="timeItemType"/>
- <id column="place_holder" property="placeHolder"/>
- <id column="xaxis" property="xaxis"/>
- <id column="yaxis" property="yaxis"/>
- <id column="value_taking_mode" property="valueTakingMode"/>
- <id column="value_type" property="valueType"/>
- <id column="bucket_type" property="bucketType"/>
- <id column="bucket_value" property="bucketValue"/>
- <id column="standby" property="standby"/>
- </collection>
- </resultMap>
- <select id="getDeviceTtByItemList" resultMap="allTableTemplate">
- SELECT
- <include refid="tableTemplateNoData"/>
- FROM
- t_table_template
- WHERE
- 1=1
- <if test="itemList!= null and itemList.size() >0">
- and start_item_id in
- <foreach collection="itemList" item="item" separator="," open="(" close=")">
- #{item.id}
- </foreach>
- or end_item_id in
- <foreach collection="itemList" item="item" separator="," open="(" close=")">
- #{item.id}
- </foreach>
- </if>
- AND template_type = #{templateType}
- </select>
- <select id="getTableItemId" resultType="java.lang.Integer">
- (SELECT item_id FROM t_report_table_item WHERE report_table_id = #{reportTableId})
- UNION ALL
- (SELECT item_id
- FROM t_report_chart_item
- WHERE report_chart_id in
- (SELECT id
- FROM t_report_chart
- WHERE report_table_id = #{reportTableId}))
- </select>
- <select id="getReportTableByttList" resultType="com.example.opc_common.entity.ReportTable">
- SELECT
- <include refid="reportTable"/>
- FROM
- t_report_table
- WHERE
- 1=1
- <if test="tableTemplateList!= null and tableTemplateList.size() >0">
- AND table_template_id in
- <foreach collection="tableTemplateList" item="tableTemplate" separator="," open="(" close=")">
- #{tableTemplate.id}
- </foreach>
- </if>
- AND report_table_type=#{reportTableType}
- </select>
- <select id="getMainTableBychTableId" resultType="com.example.opc_common.entity.ReportTable">
- select
- <include refid="reportTableCron"/>
- from t_report_table
- where id = (select auto_table_id from t_table_auto_log where auto_ch_table_id=#{chTableId})
- </select>
- <select id="getTttiByTemplateIdGroup" resultType="com.example.opc_common.entity.TableTemplateTableItem">
- SELECT ti.item_group_id,
- tig.data_source_id,
- tttti.bucket_type
- FROM t_table_template_table_item tttti
- LEFT JOIN t_item ti ON tttti.item_id = ti.id
- LEFT JOIN t_item_group tig ON ti.item_group_id = tig.id
- WHERE tttti.table_template_id = #{tableTemplateId}
- GROUP BY tttti.bucket_type,
- ti.item_group_id,
- tig.data_source_id
- </select>
- <select id="getTttiByGroup" resultType="com.example.opc_common.entity.TableTemplateTableItem">
- SELECT tttti.id,
- tttti.table_template_id,
- tttti.item_id,
- ti.item_group_id,
- ti.item_name,
- ti.item_read_name,
- ti.item_type,
- tig.data_source_id,
- tttti.time_item_type,
- tttti.place_holder,
- tttti.xaxis,
- tttti.yaxis,
- tttti.value_taking_mode,
- tttti.value_type,
- tttti.bucket_type,
- tttti.bucket_value,
- tttti.standby
- FROM t_table_template_table_item tttti
- LEFT JOIN t_item ti ON tttti.item_id = ti.id
- LEFT JOIN t_item_group tig ON ti.item_group_id = tig.id
- WHERE tttti.table_template_id = #{tableTemplateId}
- AND ti.item_group_id = #{itemGroupId}
- AND tig.data_source_id = #{dataSourceId}
- AND tttti.bucket_type = #{bucketType}
- </select>
- <select id="getTableTemplateByItemList" resultMap="allTableTemplate">
- SELECT
- <include refid="tableTemplateNoData"/>
- FROM
- t_table_template
- WHERE
- id IN (
- SELECT DISTINCT
- table_template_id
- FROM
- t_table_template_table_item
- WHERE
- item_id IN
- <foreach collection="itemList" item="item" separator="," open="(" close=")">
- #{item.id}
- </foreach>)
- AND template_type = #{templateType}
- </select>
- <select id="getReportTableByTypeAndRunState" resultType="com.example.opc_common.entity.ReportTable">
- select
- <include refid="reportTable"/>
- from t_report_table
- where 1=1
- <if test="runState != null ">
- AND run_state = #{runState}
- </if>
- <if test="reportTableType != null">
- AND report_table_type = #{reportTableType}
- </if>
- </select>
- <insert id="addReportTableIdAndPolicyIdAndItemId">
- insert into t_report_table_policy_item(report_table_id,policy_id,item_id)
- values
- <foreach collection="list" item="item" separator=",">
- (#{item.reportTableId},#{item.policyId},#{item.itemId})
- </foreach>
- </insert>
- <delete id="delReportTableIdAndPolicyIdAndItemIdByReportTableId">
- delete
- from t_report_table_policy_item
- where report_table_id = #{reportTableId}
- </delete>
- <delete id="delReportTableIdAndPolicyIdAndItemIdByReportTableIds">
- delete
- from t_report_table_policy_item
- where report_table_id in
- <foreach collection="idList" item="id" separator="," open="(" close=")">
- #{id}
- </foreach>
- </delete>
- <select id="getReportTableNameByPolicyId" resultType="String">
- select DISTINCT trt.report_table_name
- from t_report_table_policy_item trtpi,t_report_table trt
- where trtpi.report_table_id = trt.id and trtpi.policy_id = #{policyId}
- ORDER BY trt.report_table_name
- </select>
- <select id="getReportTableAndItemByPolicyIdAndItemIdList" resultType="map">
- SELECT ti.id,ti.itemReadName,GROUP_CONCAT(ti.reportTableId SEPARATOR ',') reportTableId
- ,GROUP_CONCAT(ti.reportTableName order by ti.reportTableName SEPARATOR '、') reportTableName,ti.reportTableType
- from (
- SELECT DISTINCT ti.id,ti.item_read_name itemReadName
- ,trt.id reportTableId,trt.report_table_name reportTableName,trt.report_table_type reportTableType
- FROM t_report_table_policy_item trtpi,t_report_table trt,t_item ti
- WHERE trtpi.report_table_id = trt.id AND trtpi.item_id = ti.id AND trtpi.policy_id = #{policyId}
- AND trtpi.item_id IN
- <foreach collection="itemIdList" item="id" separator="," open="(" close=")">
- #{id}
- </foreach>
- ) ti
- GROUP BY ti.id,ti.itemReadName,ti.reportTableType
- ORDER BY ti.itemReadName
- </select>
- <!--查询报表策略使用报表采集策略的正在运行的报表名称-->
- <select id="getRunReportTableByReportDataPolicyId" resultType="map">
- select DISTINCT trt.report_table_name reportTableName,trt.report_table_type reportTableType
- from t_report_table_policy_item trtpi,t_report_table trt
- where trtpi.report_table_id = trt.id and trtpi.policy_id = #{policyId} and trt.run_state = 1 and trt.is_delete = 0
- ORDER BY trt.report_table_name
- </select>
- <insert id="addTableUserGroupUser">
- insert into t_table_user_group_user (report_table_id, user_group_id,user_id,create_user_id)
- values
- <foreach collection="tableUserGroupUserList" item="tableUserGroupUser" index="index" separator=",">
- (#{tableUserGroupUser.reportTableId}, #{tableUserGroupUser.userGroupId}, #{tableUserGroupUser.userId}, #{createUserId})
- </foreach>
- </insert>
- <delete id="delTableUserGroupUser">
- delete
- from t_table_user_group_user
- where report_table_id = #{reportTableId}
- </delete>
- <delete id="delTableUserGroupUserList">
- delete
- from t_table_user_group_user
- where report_table_id in
- <foreach collection="reportTableIdList" item="reportTableId" separator="," open="(" close=")">
- #{reportTableId}
- </foreach>
- </delete>
- <select id="getTableUserGroupUserList" resultType="com.example.opc_common.entity.TableUserGroupUser">
- 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
- from t_table_user_group_user ttugu,t_user_group tug,sys_user su
- where ttugu.report_table_id = #{reportTableId} and ttugu.user_group_id = tug.id and ttugu.user_id = su.user_id
- GROUP BY ttugu.report_table_id,ttugu.user_group_id,tug.user_group_name
- </select>
- <select id="getTableUserGroupUserCountByExp" resultType="Integer">
- SELECT count(*)
- FROM t_table_user_group_user
- <where>
- <if test="userGroupId != null">
- and user_group_id = #{userGroupId}
- </if>
- <if test="noDelUserIdList != null">
- and user_id not in
- <foreach collection="noDelUserIdList" item="userId" separator="," open="(" close=")">
- #{userId}
- </foreach>
- </if>
- </where>
- </select>
- <delete id="delTableUserGroupUserByExp">
- DELETE
- FROM t_table_user_group_user
- <where>
- <if test="userGroupId != null">
- and user_group_id = #{userGroupId}
- </if>
- <if test="noDelUserIdList != null">
- and user_id not in
- <foreach collection="noDelUserIdList" item="userId" separator="," open="(" close=")">
- #{userId}
- </foreach>
- </if>
- </where>
- </delete>
- <!--查询报表记录数据项对应的小数位数(item_id为t_report_data_policy_item.id)-->
- <select id="getItemScaleByReportTableIdOrPolicyIdOrItemId" resultType="com.example.opc_common.entity.ReportDataPolicyItem">
- select DISTINCT trdpi.id,ti.id item_id,ti.scale
- from t_report_table_policy_item trtpi,t_item ti,t_report_data_policy_item trdpi
- where trtpi.item_id = ti.id and trdpi.report_data_policy_id = trtpi.policy_id and trdpi.item_id = trtpi.item_id
- <if test="itemId != null">
- and trtpi.item_id = #{itemId}
- </if>
- <if test="policyId != null">
- and trtpi.policy_id = #{policyId}
- </if>
- <if test="reportTableId != null">
- and trtpi.report_table_id = #{reportTableId}
- </if>
- </select>
- </mapper>
|