Browse Source

处理pgsql方言问题

tianye 2 years ago
parent
commit
b9902ae4f1

+ 5 - 5
warning-web/src/main/resources/mappers-postgresql/AlarmCountMapper.xml

@@ -5,15 +5,15 @@
     <insert id="singleInsert" >
         insert into alarmcount (id, alarmdate, snapid, count)
         values
-        (#{item.id}, #{item.alarmdate}, #{item.snapId}, #{item.count})
+        (#{item.id}, cast(#{item.alarmDate} as  timestamp), #{item.snapId}, #{item.count})
     </insert>
 
     <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="false">
         insert into alarmcount ( ID, alarmdate, snapid, count,time )
         <foreach collection="list" item="item" index="index" separator="union all" >
             ( select
-            #{item.id}, #{item.alarmDate}, #{item.snapId}, #{item.count} ,#{item.time}
-            from dual )
+            #{item.id}, cast(#{item.alarmDate} as  timestamp), #{item.snapId}, #{item.count} ,#{item.time}
+            )
         </foreach>
     </insert>
 
@@ -29,7 +29,7 @@
 
     <select id="statAlarmCount1" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.entity.AlarmStat1"  >
         select t.*, s.stationid, s.windturbineid, s.alerttext from (
-            select snapid, sum(count) as count,sum(time) time from alarmcount a
+            select snapid, sum(count) as count,sum(time) as time from alarmcount a
             left join alarmsnap ss on a.snapid = ss.id
             where ss.stationid = #{stationid} and ss.windturbineid is not null
             and alarmdate &gt;= #{startdate,jdbcType=DATE} and alarmdate &lt; #{enddate,jdbcType=DATE}
@@ -73,7 +73,7 @@
         <where>
         1=1
             <if test="startdate !=null and enddate !=null">
-                and a.alarmdate &gt;= #{startdate,jdbcType=DATE} and a.alarmdate &lt;= #{enddate,jdbcType=DATE}
+                and a.alarmdate &gt;= #{startdate} and a.alarmdate &lt;= #{enddate}
             </if>
             <if test="stationid !=null and stationid !=''">
                 and ss.stationid=#{stationid}

+ 11 - 11
warning-web/src/main/resources/mappers-postgresql/AlarmHistoryMapper.xml

@@ -5,14 +5,14 @@
     <insert id="singleInsert" >
         insert into ${tbName} (id, alerttime, messagetype,snapid, datainfo)
         values
-        (#{item.id}, #{item.alertTime}, #{item.messageType},#{item.snapId},#{item.dataInfo})
+        (#{item.id}, cast(#{item.alertTime} as  timestamp), #{item.messageType},#{item.snapId},#{item.dataInfo})
     </insert>
 
     <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="false">
         insert into ${tbName} ( ID, ALERTTIME, MESSAGETYPE, SNAPID, DATAINFO,ALERTTEXTLAST)
         <foreach collection="list" item="item" index="index" separator="union all" >
             ( select
-            #{item.id}, #{item.alertTime}, #{item.messageType},#{item.snapId},#{item.dataInfo},#{item.alertTextLast}
+            #{item.id}, cast(#{item.alertTime} as  timestamp), #{item.messageType},#{item.snapId},#{item.dataInfo},#{item.alertTextLast}
             from dual )
         </foreach>
     </insert>
@@ -181,19 +181,19 @@
 
     <update id="timedCreatTable">
         CREATE TABLE alarmhistory_${stationname}_${yearmonth} (
-        "id"            numeric(20) not null
-        constraint pk_alarmhistory_${stationname}_${yearmonth}
-        primary key,
-        "alerttime"     timestamp   not null,
-        "messagetype"   char        not null,
-        "snapid"        numeric(20) not null,
-        "datainfo"      varchar(20),
-        "alerttextlast" varchar(50)
+            "id"            numeric(20) not null
+            constraint pk_alarmhistory_${stationname}_${yearmonth}
+            primary key,
+            "alerttime"     timestamp   not null,
+            "messagetype"   char        not null,
+            "snapid"        numeric(20) not null,
+            "datainfo"      varchar(20),
+            "alerttextlast" varchar(50)
         )
     </update>
     <update id="timedAlterTable">
         alter table alarmhistory_${stationname}_${yearmonth}
-        owner to gdprod
+            owner to gdprod
     </update>
     <update id="timedCreatAlerttimeIndex">
         create index IX_AH_${stationname}_${yearmonth}_alerttime on alarmhistory_${stationname}_${yearmonth} ("alerttime")

+ 52 - 89
warning-web/src/main/resources/mappers-postgresql/Alertrule2Mapper.xml

@@ -6,75 +6,47 @@
           WARNING - @mbg.generated
           This element is automatically generated by MyBatis Generator, do not modify.
         -->
-        <id column="id" property="id"/>
-        <result column="name" property="name"/>
-        <result column="description" property="description"/>
-        <result column="expression" property="expression"/>
-        <result column="rank" property="rank"/>
-        <result column="rank" property="rank"/>
-        <result column="enabled" property="enabled"/>
-        <result column="modelId" property="modelId"/>
-        <result column="ednaValue" property="ednaValue"/>
-        <result column="category" property="category"/>
-        <result column="range" property="range"/>
-        <result column="station" property="station"/>
-        <result column="windturbine" property="windturbine"/>
-        <result column="line" property="line"/>
-        <result column="project" property="project"/>
-        <result column="electrical" property="electrical"/>
-        <result column="taskstart" property="taskstart"/>
-        <result column="relatedParts" property="relatedParts"/>
+        <id column="id" property="id" />
+        <result column="name"  property="name" />
+        <result column="description"  property="description" />
+        <result column="expression"  property="expression" />
+        <result column="rank"  property="rank" />
+        <result column="rank"  property="rank" />
+        <result column="enabled"  property="enabled" />
+        <result column="modelId"  property="modelId" />
+        <result column="ednaValue"  property="ednaValue" />
+        <result column="category"  property="category" />
+        <result column="range"  property="range" />
+        <result column="station"  property="station" />
+        <result column="windturbine"  property="windturbine" />
+        <result column="line"  property="line" />
+        <result column="project"  property="project" />
+        <result column="electrical"  property="electrical" />
+        <result column="taskstart"  property="taskstart" />
+        <result column="relatedParts"  property="relatedParts" />
     </resultMap>
     <resultMap type="Alertrule2" id="Alertrule2Result">
-        <result property="id" column="id"/>
-        <result property="name" column="name"/>
-        <result property="station" column="station"/>
-        <result property="relatedParts" column="relatedParts"/>
-        <association property="windPowerStation" column="station" javaType="WindPowerStation"
-                     select="com.gyee.wisdom.alarm.sharding.mapper.WindPowerStationMapper.selectByid"/>
-        <association property="datadictionary" column="relatedParts" javaType="Datadictionary"
-                     select="com.gyee.wisdom.alarm.sharding.mapper.DatadictionaryMapper.selectBycode"/>
+        <result property="id"    column="id"    />
+        <result property="name"    column="name"    />
+        <result property="station"    column="station"    />
+        <result property="relatedParts"    column="relatedParts"    />
+        <association  property="windPowerStation"  column="station"     javaType="WindPowerStation"  select="com.gyee.wisdom.alarm.sharding.mapper.WindPowerStationMapper.selectByid"/>
+        <association  property="datadictionary"  column="relatedParts"     javaType="Datadictionary"  select="com.gyee.wisdom.alarm.sharding.mapper.DatadictionaryMapper.selectBycode"/>
     </resultMap>
-
-    <resultMap type="com.gyee.wisdom.alarm.sharding.entity.Alertrule2" id="alertRule2ResultToPostgreSql">
-        <result property="id" column="id"/>
-        <result property="name" column="name"/>
-        <result property="description" column="description"/>
-        <result property="expression" column="expression"/>
-        <result property="tag" column="tag"/>
-        <result property="rank" column="rank"/>
-        <result property="enabled" column="specialenable"/>
-        <result property="modelId" column="modelid"/>
-        <result property="ednaValue" column="ednavalue"/>
-        <result property="category" column="category"/>
-        <result property="range" column="range"/>
-        <result property="station" column="station"/>
-        <result property="windturbine" column="windturbine"/>
-        <result property="line" column="line"/>
-        <result property="project" column="project"/>
-        <result property="electrical" column="electrical"/>
-        <result property="taskstart" column="taskstart"/>
-        <result property="relatedParts" column="relatedParts"/>
-        <association property="windPowerStation" column="station" javaType="WindPowerStation"
-                     select="com.gyee.wisdom.alarm.sharding.mapper.WindPowerStationMapper.selectByid"/>
-        <association property="datadictionary" column="relatedParts" javaType="Datadictionary"
-                     select="com.gyee.wisdom.alarm.sharding.mapper.DatadictionaryMapper.selectBycode"/>
-    </resultMap>
-
-    <select id="pageQueryAll" parameterType="java.util.Map" resultMap="alertRule2ResultToPostgreSql">
-        select a.*, (case a.enabled   WHEN 't' then 1  when 'f' then 0  else 0 end) as specialenable from ALERTRULE2 a
+    <select id="pageQueryAll" parameterType="java.util.Map" resultMap="Alertrule2Result">
+        select a.* from  ALERTRULE2 a
         left join windpowerstation w on w.id = a.station
         <where>
             1=1
 
             <if test="name !=null and name !=''">
-                and a.name like '%${name}%'
+                and a.name like  '%${name}%'
             </if>
             <if test="station !=null and station !=''">
-                and a.station like '%${station}%'
+                and a.station like  '%${station}%'
             </if>
             <if test="modelId !=null and modelId !=''">
-                and a.modelid like '%${modelId}%'
+                and a.modelid like  '%${modelId}%'
             </if>
             <if test="rank !=null and rank !=''">
                 and a.rank = #{rank}
@@ -83,34 +55,27 @@
                 and a.category = #{category}
             </if>
             <if test="enabled !=null and enabled !=''">
-                <if test="enabled ='1'">
-                    and a.enabled = true
-                </if>
-                <if test="enabled ='0'">
-                    and a.enabled = false
-                </if>
+                and a.enabled = #{enabled}
             </if>
-
-            <!--            and a.range = 0-->
+<!--            and a.range = 0-->
         </where>
-
+        order by a.createtime desc
     </select>
 
     <select id="getMaxEdnaValue" parameterType="java.util.Map" resultType="java.lang.Integer">
-        select max(a.ednavalue) from ALERTRULE2 a
+        select max(a.ednavalue) from  ALERTRULE2 a
     </select>
-    <select id="getAllByStationIdAndModelId" parameterType="java.util.Map"
-            resultType="com.gyee.wisdom.alarm.sharding.entity.Alertrule2">
-        select * from ALERTRULE2 a
+    <select id="getAllByStationIdAndModelId" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.entity.Alertrule2">
+        select * from  ALERTRULE2 a
         <where>
             1=1
             <if test="idString !=null and idString !=''">
-                and a.id like '%${idString}%'
+                and a.id like  '%${idString}%'
             </if>
         </where>
     </select>
     <select id="getById" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.entity.Alertrule2">
-        select * from ALERTRULE2 a
+        select * from  ALERTRULE2 a
         <where>
             1=1
             <if test="idString !=null and idString !=''">
@@ -119,13 +84,13 @@
         </where>
     </select>
 
-    <select id="quertByrelatedParts" resultType="java.util.HashMap">
-        select a.name from ALERTRULE2 a
+    <select id="quertByrelatedParts"  resultType="java.util.HashMap">
+        select a.name from  ALERTRULE2 a
         where a.relatedparts = #{relatedParts}
         group by a.name
     </select>
 
-    <select id="queryTree" resultMap="Alertrule2Result">
+    <select id="queryTree" resultMap="Alertrule2Result" >
         select distinct a.relatedparts,a.name,d.name from alertrule2 a
         left join DATADICTIONARY d
         on d.code = a.relatedparts
@@ -135,14 +100,13 @@
 
     <select id="queryMap" resultType="com.gyee.wisdom.alarm.sharding.entity.Alertrule2">
         select t.relatedparts,d.name from
-        (select a.relatedparts from alertrule2 a
-        where relatedparts is not null
-        group by a.relatedparts) t
+            (select a.relatedparts from alertrule2 a
+             where relatedparts  is not null
+             group by a.relatedparts) t
         left join DATADICTIONARY d
         on d.code = t.relatedparts
     </select>
-    <insert id="insertAlerture2" parameterType="com.gyee.wisdom.alarm.sharding.entity.Alertrule2"
-            useGeneratedKeys="true" keyProperty="id">
+    <insert id="insertAlerture2" parameterType="com.gyee.wisdom.alarm.sharding.entity.Alertrule2" useGeneratedKeys="true" keyProperty="id">
         insert into alertrule2
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="id != null">id,</if>
@@ -189,7 +153,7 @@
     </insert>
     <update id="updateByAlertrule2Id" parameterType="com.gyee.wisdom.alarm.sharding.entity.Alertrule2">
         update alertrule2 a
-        <set>
+        <set >
             <if test="name != null">a.name = #{name},</if>
             <if test="description != null">a.description = #{description},</if>
             <if test="expression != null">a.expression = #{expression},</if>
@@ -213,12 +177,13 @@
     </update>
 
 
+
     <select id="selectByAlertrule2Id" resultType="com.gyee.wisdom.alarm.sharding.entity.Alertrule2">
-        select * from alertrule2 a where a.id=#{id}
+        select * from  alertrule2 a where a.id=#{id}
     </select>
 
     <select id="selectByNameAndSataionAndModelid" resultType="com.gyee.wisdom.alarm.sharding.entity.Alertrule2">
-        select * from alertrule2 a
+        select * from  alertrule2 a
         <where>
             1=1
             <if test="name !=null and name !=''">
@@ -233,8 +198,7 @@
         </where>
     </select>
 
-    <select id="selectByExample" parameterType="com.gyee.wisdom.alarm.sharding.model.Alertrule2Example"
-            resultMap="BaseResultMap">
+    <select id="selectByExample" parameterType="com.gyee.wisdom.alarm.sharding.model.Alertrule2Example" resultMap="BaseResultMap">
         <!--
           WARNING - @mbg.generated
           This element is automatically generated by MyBatis Generator, do not modify.
@@ -244,10 +208,10 @@
             distinct
         </if>
         *
-        <!--        <include refid="Base_Column_List" />-->
+<!--        <include refid="Base_Column_List" />-->
         from ALERTRULE2
         <if test="_parameter != null">
-            <include refid="Example_Where_Clause"/>
+            <include refid="Example_Where_Clause" />
         </if>
         <if test="orderByClause != null">
             order by ${orderByClause}
@@ -285,8 +249,7 @@
                                 </when>
                                 <when test="criterion.listValue">
                                     and ${criterion.condition}
-                                    <foreach close=")" collection="criterion.value" item="listItem" open="("
-                                             separator=",">
+                                    <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                                         #{listItem}
                                     </foreach>
                                 </when>

+ 2 - 1
warning-web/src/main/resources/mappers-postgresql/EarlyWarnScoreMapper.xml

@@ -10,9 +10,10 @@
             <if test="windturbineid !=null and windturbineid !=''">
                 and e.windturbineid = #{windturbineid}
             </if>
-            and e.statdate =DATE_SUB(curdate(),INTERVAL 1 day)
+            and e.statdate >= current_date-1 and e.statdate &lt; current_date;
         </where>
     </select>
 
 
+
 </mapper>

+ 3 - 24
warning-web/src/main/resources/mappers-postgresql/ScadabjMapper.xml

@@ -2,24 +2,8 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.gyee.wisdom.alarm.sharding.mapper.ScadabjMapper">
 
-
-    <resultMap type="com.gyee.wisdom.alarm.sharding.entity.Scadabj" id="scadabjResultToPostgreSql">
-        <result property="id" column="id"/>
-        <result property="pointKey" column="pointkey"/>
-        <result property="description" column="description"/>
-        <result property="category1" column="category1"/>
-        <result property="category2" column="category2"/>
-        <result property="category3" column="category3"/>
-        <result property="category4" column="category4"/>
-        <result property="stationId" column="stationid"/>
-        <result property="deviceId" column="deviceid"/>
-        <result property="rank" column="rank"/>
-        <result property="enabled" column="specialenable"/>
-        <result property="alarmType" column="alarmtype"/>
-    </resultMap>
-
-    <select id="pageQueryAll" parameterType="java.util.Map" resultMap="scadabjResultToPostgreSql">
-        select a.*,(case a.enabled   WHEN 't' then 1  when 'f' then 0  else 0 end) as specialenable from  SCADABJ a
+    <select id="pageQueryAll" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.entity.Scadabj">
+        select * from  SCADABJ a
         <where>
             1=1
             <if test="pointKey !=null and pointKey !=''">
@@ -29,12 +13,7 @@
                 and a.stationId=#{stationId}
             </if>
             <if test="enable !=null and enable !=''">
-                <if test="enable ='1'">
-                    and a.enabled = true
-                </if>
-                <if test="enable ='0'">
-                    and a.enabled = false
-                </if>
+                and a.enabled=#{enable}
             </if>
             <if test="description !=null and description !=''">
                 and a.description like  '%${description}%'

+ 2 - 2
warning-web/src/main/resources/mappers-postgresql/WindTurbineTestingPointAiMapper.xml

@@ -3,7 +3,7 @@
 <mapper namespace="com.gyee.wisdom.alarm.sharding.mapper.WindTurbineTestingPointAiMapper">
 
     <select id="getWindTurbineTestingPointAi" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.entity.WindTurbineTestingPointAi">
-        select * from  windturbinetestingpointai a
+        select * from  windturbinetestingpointnew a
         <where>
             1=1
             <if test="wtId !=null and wtId !=''">
@@ -16,7 +16,7 @@
     </select>
 
     <select id="getPointList" parameterType="java.util.Map" resultType="com.gyee.wisdom.alarm.sharding.entity.WindTurbineTestingPointAi">
-        select * from  windturbinetestingpointai a
+        select * from  windturbinetestingpointnew a
         <where>
             1=1
             <if test="uniformCodeList  !=null and uniformCodeList.size > 0 ">