mybatis query多级List级联类 之collection标签使用《示例》上

需求:查询时需要对比stationStatsInfo 充电设备,接口信息的基本信息的最后修改时间,三者只要有一处修改,就认为是最新修改时间,然后与输入参数lastQueryTime进行对比,最后符合条件的站信息数据全部显示。

sql:比较lastQueryTime   PK  updateTime

 <select id="query_Stations_info" parameterType="java.util.Map" resultMap="StationInfoMap" > 
  SELECT a.GRID_STATION_SEQ,a.GRID_STATION_NAME,a.AREACODE,a.ADDRESS,a.CONTACT_MOBILE,a.station_type,
FROM
${projectSchema}.grid_station a where UNIX_TIMESTAMP(a.UPDATED_TIME)>UNIX_TIMESTAMP(#{LastQueryTime,jdbcType=VARCHAR}) 
or ( EXISTS  ( select 1 from ${projectSchema}.carport_info b LEFT JOIN ${projectSchema}.grid_stake c ON b.GRID_STAKE_SEQ = c.GRID_STAKE_SEQ  where b.GRID_STATION_SEQ = a.GRID_STATION_SEQ and (UNIX_TIMESTAMP(b.UPDATED_TIME)>UNIX_TIMESTAMP(#{LastQueryTime,jdbcType=VARCHAR}) orUNIX_TIMESTAMP(c.UPDATED_TIME)>UNIX_TIMESTAMP(#{LastQueryTime,jdbcType=VARCHAR})) )  )ORDER BY a.GRID_STATION_SEQ 


javaBean-------------------------------------------------------------

第一级:stationStatsInfo.java

第二级:EquipementStatsInfo.java

第三极:ConnectStatsInfo.java



mapper=-------------------------------------------------------------

   <resultMap id="StatsResultMap" type="com.extracme.evshare.business.tfriftbean.StationStatsInfo">
    <result column="Station_Id" jdbcType="VARCHAR" property="StationID" />
    <result column="Station_Electricity" jdbcType="DOUBLE" property="StationElectricity" />
    <result column="Start_Time" jdbcType="TIMESTAMP" property="StartTime" />
    <result column="End_Time" jdbcType="TIMESTAMP" property="EndTime" />
    <collection property="EquipmentStatsInfos" javaType="ArrayList"  select="com.extracme.evshare.business.tserver.mapper.EquipmentStatsMapper.queryEquipmentStatsInfoByStatsId"
                column="{StationStatsId=stationStatsId}" ofType="com.extracme.evshare.business.entity.EquipmentStatsInfo">
     </collection>

  </resultMap>
      <!-- 此查询用于定期获取充电站,在某个周期内的统计信息 -->
  <select id="queryStationStats" parameterType="java.util.Map" resultMap="StatsResultMap">
    
    select 
   Station_Stats_Id stationStatsId ,Station_Id, Station_Electricity, Start_Time, End_Time
    from station_stats
    where 1=1 
     <if test="stationId != null and stationId !='' " >
     and Station_Id = #{stationId,jdbcType=VARCHAR}
     </if>
     <if test="startTime != null and startTime !='' " >
     and Start_Time = #{startTime,jdbcType=TIMESTAMP}
     </if>
     <if test="endTime != null and endTime !='' " >
     and End_Time = #{endTime,jdbcType=TIMESTAMP}
     </if>
     ORDER BY End_Time 
  </select>




   <resultMap id="EquipmentResultMap" type="com.extracme.evshare.business.tfriftbean.EquipmentStatsInfo">
   <!--  <id column="Equipment_Stats_Id" jdbcType="BIGINT" property="EquipmentStatsId" /> -->
    <result column="Equipment_Id" jdbcType="VARCHAR" property="EquipmentID" />
    <result column="Equipment_Electricity" jdbcType="DOUBLE" property="EquipmentElectricity" />
    <!-- <collection property="ConnectorStatsInfos" resultMap="ConnectorResultMap" /> -->
     <collection property="ConnectorStatsInfos" javaType="ArrayList"  select="com.extracme.evshare.business.tserver.mapper.ConnectorStatsMapper.queryStatsInfoById"
                column="{EquipmentStatsId=equipmentStatsId}" ofType="com.extracme.evshare.business.tfriftbean.ConnectorStatsInfo">
     </collection>
  </resultMap>

    <!-- 此查询用于定期获取充电站下,在某个周期内的设备接口统计信息 -->
     <select id="queryEquipmentStatsInfoByStatsId" parameterType="java.util.Map" resultMap="EquipmentResultMap">
    select 
    e.Equipment_Stats_Id as equipmentStatsId,
   e.Equipment_Id EquipmentID,
   e.Equipment_Electricity
   <!-- ,c.Connector_Id  ConnectorID,
   c.Connector_Electricity -->

    from 
    equipment_stats e
    <!-- LEFT JOIN connector_stats c ON e.Equipment_Stats_Id = c.Equipment_Stats_Id -->
    where e.Station_Stats_Id = #{StationStatsId,jdbcType=INTEGER}
  </select>


---------------------分级依次查询List--------------------------


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值