TaMachineryMapper.xml 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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.yunzhi.nanyang.mapper.TaMachineryMapper">
  4. <select id="getSummaryList" resultType="com.yunzhi.nanyang.vo.MachineSummary">
  5. SELECT
  6. *
  7. FROM
  8. ( SELECT
  9. t.*,
  10. fn_distance ( t.location, #{location} ) AS distance
  11. FROM ta_machinery t
  12. WHERE
  13. t.`status` &gt; -1
  14. <if test="orgId != null and orgId != ''">
  15. AND t.org_id = #{orgId}
  16. </if>
  17. <if test="typeId != null and typeId != ''">
  18. AND t.type_id = #{typeId}
  19. </if>
  20. ) AS a
  21. ORDER BY
  22. a.distance DESC
  23. </select>
  24. <select id="getSummaryDetail" resultType="com.yunzhi.nanyang.vo.MachineSummary">
  25. SELECT
  26. t.*,
  27. s.`name` as org_name,
  28. fn_distance(t.location, #{location}) as distance
  29. FROM
  30. ta_machinery t
  31. INNER JOIN ta_org s on t.org_id = s.org_id
  32. WHERE
  33. t.machinery_id = #{machineryId}
  34. AND t.`status` &gt; -1
  35. </select>
  36. <select id="getOneOfTypes" resultType="com.yunzhi.nanyang.vo.MachineSummary">
  37. SELECT
  38. t.*,
  39. fn_distance ( concat( m.lng, ',', m.lat ), #{location} ) AS distance,
  40. count( * ) AS num
  41. FROM
  42. ta_machinery t
  43. INNER JOIN ta_machinery s ON t.org_id = s.org_id
  44. AND t.type_id = s.type_id
  45. INNER JOIN ta_org m ON m.org_id = t.org_id
  46. INNER JOIN td_machinery_type n ON n.type_id = t.type_id
  47. WHERE
  48. t.`status` &gt; -1
  49. AND t.machinery_id &lt;= s.machinery_id
  50. <if test="typeId != null and typeId != ''">
  51. AND t.type_id = #{typeId}
  52. </if>
  53. <if test="q != null and q != ''">
  54. AND (
  55. t.`name` LIKE CONCAT('%', #{q}, '%')
  56. OR n.`name` LIKE CONCAT('%', #{q}, '%')
  57. )
  58. </if>
  59. GROUP BY
  60. t.org_id,
  61. t.type_id
  62. -- t.machinery_id
  63. -- HAVING
  64. -- num &lt;= 1
  65. ORDER BY
  66. distance ASC
  67. </select>
  68. <select id="getPageBy" resultType="com.yunzhi.nanyang.entity.TaMachinery">
  69. SELECT
  70. t.*,
  71. m.`name` as org_name
  72. FROM
  73. ta_machinery t
  74. INNER JOIN ta_org m ON m.org_id = t.org_id
  75. <if test="isBound != null and isBound">
  76. INNER JOIN td_device d on t.machinery_id = d.machinery_id
  77. </if>
  78. WHERE
  79. t.`status` &gt; -1
  80. <if test="name != null and name != ''">
  81. AND t.`name` LIKE CONCAT('%', #{name}, '%')
  82. </if>
  83. <if test="typeId != null and typeId != ''">
  84. AND t.type_id = #{typeId}
  85. </if>
  86. <if test="orgId != null and orgId != ''">
  87. AND t.org_id = #{orgId}
  88. </if>
  89. <if test="status != null">
  90. AND t.status = #{status}
  91. </if>
  92. ORDER BY
  93. t.create_date DESC
  94. </select>
  95. <select id="listByTypeWithLoc" resultType="com.yunzhi.nanyang.entity.TaMachinery">
  96. SELECT
  97. t.*,
  98. m.`name` as org_name
  99. FROM
  100. ta_machinery t
  101. INNER JOIN ta_org m ON m.org_id = t.org_id
  102. INNER JOIN td_machinery_type n ON n.type_id = t.type_id AND n.screen_statis = 1
  103. WHERE
  104. t.`status` &gt; -1
  105. <if test="typeId != null and typeId != ''">
  106. AND t.type_id = #{typeId}
  107. </if>
  108. -- AND t.online_status = 1
  109. AND t.location IS NOT NULL
  110. </select>
  111. </mapper>