BusDeviceMapper.xml 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.coffee.bus.mapper.BusDeviceMapper">
  4. <resultMap id="pageQueryResult" type="com.coffee.bus.service.dto.DeviceResult">
  5. <result column="id" property="id"/>
  6. <result column="device_id" property="deviceId"/>
  7. <result column="alias" property="alias"/>
  8. <result column="type" property="type"/>
  9. <result column="run_state" property="runState"/>
  10. <result column="alarm" property="alarm"/>
  11. <result column="config" property="config" typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"/>
  12. <result column="sim_iccid" property="simIccid"/>
  13. <result column="sim_mno" property="simMno"/>
  14. <result column="enable" property="enable"/>
  15. <result column="status" property="status"/>
  16. <result column="create_time" property="createTime"/>
  17. <result column="update_time" property="updateTime"/>
  18. <result column="tenant_id" property="tenantName" typeHandler="com.coffee.common.config.mybatis.TenantNameHandler"/>
  19. </resultMap>
  20. <resultMap id="deviceResult" type="com.coffee.bus.entity.BusDeviceEntity" autoMapping="true">
  21. <result property="config" column="config" typeHandler="com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler"></result>
  22. </resultMap>
  23. <select id="selectOneByDeviceId" resultMap="deviceResult">
  24. SELECT * from bus_device
  25. WHERE device_id = #{deviceId}
  26. </select>
  27. <update id="notDelete">
  28. UPDATE bus_device
  29. SET is_delete = 0
  30. WHERE device_id = #{deviceId}
  31. </update>
  32. <select id="pageQuery" resultMap="pageQueryResult" parameterType="com.coffee.bus.service.dto.DeviceQuery">
  33. select
  34. d.id as id,
  35. d.device_id as device_id,
  36. d.alias as alias,
  37. ifnull(i.type,3) as type,
  38. i.run_state as run_state,
  39. i.alarm as alarm,
  40. d.config as config,
  41. d.sim_iccid as sim_iccid,
  42. d.sim_mno as sim_mno,
  43. d.`enable` as enable,
  44. d.`status` as `status`,
  45. d.create_time as create_time,
  46. d.update_time as update_time,
  47. d.tenant_id as tenant_id
  48. from (select * from bus_device
  49. <where>
  50. <if test="query.deviceId!=null">
  51. and device_id like concat('%',#{query.deviceId},'%')
  52. </if>
  53. <if test="query.deviceTypes != null and query.deviceTypes.size > 0">
  54. and type in
  55. <foreach item="type" index="index" collection="query.deviceTypes" open="(" separator="," close=")">
  56. #{type, jdbcType=VARCHAR}
  57. </foreach>
  58. </if>
  59. <if test="query.alias!=null">
  60. and alias like concat('%',#{query.alias},'%')
  61. </if>
  62. </where>
  63. ) AS d
  64. LEFT JOIN (select * from bus_infusion_history
  65. <where>
  66. finished=0
  67. <if test="query.runStates != null and query.runStates.size > 0">
  68. and run_state in
  69. <foreach item="state" index="index" collection="query.runStates" open="(" separator="," close=")">
  70. #{state, jdbcType=VARCHAR}
  71. </foreach>
  72. </if>
  73. <if test="query.alarms != null and query.alarms.size > 0">
  74. and alarm in
  75. <foreach item="alarm" index="index" collection="query.alarms" open="(" separator="," close=")">
  76. #{alarm, jdbcType=VARCHAR}
  77. </foreach>
  78. </if>
  79. </where>
  80. ) as i
  81. on i.device_id=d.device_id
  82. order by d.create_time desc
  83. </select>
  84. </mapper>