AirSwitchInfoMapper.xml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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.welampiot.dao.AirSwitchInfoDao">
  4. <select id="getAirSwitchInfoByBoxId" resultType="AirSwitchInfoDTO" parameterType="Integer">
  5. select a.id,a.name,a.address,a.online,a.status,a.type,a.volA,a.curA,a.powerA,a.tempA,
  6. a.alarm_info alarmInfo,a.leakagecurA as leakageCurA,a.volB,a.curB,a.powerB,a.tempB,
  7. a.alarm_infoB alarmInfoB,a.leakagecurB as leakageCurB,a.volC,a.curC,a.powerC,a.tempC,
  8. a.alarm_infoC alarmInfoC,a.leakagecurC as leakageCurC,a.policyid as policyId,a.alarm_status alarmStatus,
  9. a.alarm_statusB alarmStatusB,a.alarm_statusC alarmStatusC,a.logtime as logTime,lp.name policyName,s.timezone
  10. from air_switch_info a left join loop_policy lp on a.policyId = lp.id left join electric_box e on a.box_id = e.id
  11. left join section s on e.sectionid = s.id
  12. where a.box_id = #{boxId}
  13. <choose>
  14. <when test="online == 1">
  15. and a.online = 1
  16. </when>
  17. <when test="online == 2">
  18. and a.online = 0
  19. </when>
  20. </choose>
  21. order by convert(a.name using gbk) asc,a.id desc
  22. </select>
  23. <select id="getCountByBoxId" resultType="Integer" parameterType="Integer">
  24. select count(a.id) from air_switch_info a where a.box_id = #{boxId}
  25. </select>
  26. <select id="getCountByBoxIdAndType" resultType="Integer" parameterType="Integer">
  27. select count(a.id) from air_switch_info a where a.box_id = #{boxId} and a.type = #{type}
  28. </select>
  29. <select id="getCountByBoxIdAndAlarmStatus" resultType="Integer" parameterType="Integer">
  30. select count(a.id) from air_switch_info a
  31. where a.box_id = #{boxId} and (a.alarm_status = 1 or a.alarm_statusB = 1 or a.alarm_statusC = 1)
  32. </select>
  33. <select id="getPolicyIdByBoxId" resultType="Integer" parameterType="Integer">
  34. select e.policyid from electric_box e where e.id = #{boxId}
  35. </select>
  36. <select id="getPolicyNameByPolicyId" resultType="String" parameterType="Integer">
  37. select lp.name policyName from loop_policy lp where lp.id = #{policyId}
  38. </select>
  39. <select id="getAirSwitchDetailById" resultType="AirSwitchInfoDTO" parameterType="Integer">
  40. select a.name,a.box_id boxId,a.address,a.type from air_switch_info a where a.id = #{id}
  41. </select>
  42. <insert id="add" parameterType="com.welampiot.dto.AirSwitchInfoDTO" useGeneratedKeys="true" keyProperty="id"
  43. >
  44. insert into air_switch_info(name,address,type,p_num,createtime,module_id
  45. <if test="boxId != null">,box_id</if>
  46. <if test="lampPoleId != null">,lamp_pole_id</if>
  47. <if test="boxAddress != null">,box_address</if>
  48. <if test="serialPort != null">,serial_port</if>
  49. )
  50. values
  51. (#{name},#{address},#{type},#{pNum},#{createTime},#{moduleId}
  52. <if test="boxId != null">,#{boxId}</if>
  53. <if test="lampPoleId != null">,#{lampPoleId}</if>
  54. <if test="boxAddress != null">,#{boxAddress}</if>
  55. <if test="serialPort != null">,#{serialPort}</if>
  56. )
  57. </insert>
  58. <update id="update" parameterType="com.welampiot.dto.AirSwitchInfoDTO"
  59. >
  60. update air_switch_info
  61. set
  62. name=#{name},
  63. address=#{address},
  64. type=#{type},
  65. p_num=#{pum},
  66. createtime=#{createTime},
  67. module_id=#{moduleId}
  68. <if test="boxId != null">,box_id=#{boxId},</if>
  69. <if test="lampPoleId != null">,lamp_pole_id=#{lampPoleId}</if>
  70. <if test="boxAddress != null">,box_address=#{boxAddress}</if>
  71. <if test="serialPort != null">,serial_port=#{serialPort}</if>
  72. where id = #{id}
  73. </update>
  74. <delete id="delete" parameterType="com.welampiot.dto.AirSwitchInfoDTO">
  75. delete from air_switch_info where id=#{id}
  76. </delete>
  77. <delete id="deleteByBoxId" parameterType="int">
  78. delete from air_switch_info where box_id=#{boxId}
  79. </delete>
  80. <select id="getAirSwitchAddressById" resultType="AirSwitchInfoDTO">
  81. select a.address,em.address as moduleAddress,a.module_id as moduleId
  82. from air_switch_info a
  83. left join electric_module em on a.module_id = em.id
  84. where a.id = #{id}
  85. </select>
  86. <select id="getAirSwitchAddressByModuleId" resultType="AirSwitchInfoDTO">
  87. select a.id,a.address,em.address as moduleAddress,a.policyid as policyId
  88. from air_switch_info a
  89. left join electric_module em on a.module_id = em.id
  90. where a.module_id = #{moduleId}
  91. </select>
  92. <update id="updateAirSwitchStatusById" parameterType="AirSwitchInfoDTO">
  93. update air_switch_info a
  94. set
  95. a.status = #{status}
  96. where a.id = #{id}
  97. </update>
  98. <select id="getAirSwitchAddressByEleBoxAddr" resultType="AirSwitchInfoDTO">
  99. select
  100. a.id,
  101. a.name,
  102. a.address,
  103. a.box_address as boxAddress
  104. from air_switch_info a
  105. left join electric_module e on a.module_id = e.id
  106. where e.address = #{address}
  107. </select>
  108. <select id="getAirSwitchCountByEleBoxAddr" resultType="Integer">
  109. select
  110. count(*)
  111. from air_switch_info a
  112. left join electric_module e on e.id = a.module_id
  113. where e.address = #{address}
  114. </select>
  115. <select id="getOneAirSwitch" parameterType="HashMap" resultType="AirSwitchInfoDTO">
  116. select E.id
  117. from air_switch_info M
  118. left join electric_box E on M.box_id = E.id
  119. where E.areaid = #{areaId} and E.sectionid = #{sectionid}
  120. <choose>
  121. <when test="address != null and name == null">
  122. and M.address = #{address}
  123. </when>
  124. <when test="address == null and name != null">
  125. and M.name = #{name}
  126. </when>
  127. <otherwise>
  128. and M.address = #{address} and M.name = #{name}
  129. </otherwise>
  130. </choose>
  131. </select>
  132. </mapper>