CheckRecordStatisMapper.xml 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  4. <mapper namespace="com.zhyc.xps.aqpt.mapper.CheckRecordStatisMapper">
  5. <!-- 按状态统计 -->
  6. <select id="counterByStatus" parameterType="java.util.Map" resultType="com.zhyc.xps.aqpt.vo.CheckRecordByStatusVo">
  7. SELECT
  8. IFNULL(SUM( CASE WHEN A.check_result = 1 THEN 1 ELSE 0 END ), 0) AS 'passed',
  9. IFNULL(SUM( CASE WHEN A.check_result = -1 THEN 1 ELSE 0 END ), 0) AS 'failed'
  10. FROM check_record AS A
  11. LEFT JOIN s_group AS B ON (A.oc_id = B.oc_id AND A.group_id = B.group_id)
  12. WHERE 1 = 1
  13. <if test="ocId != null">
  14. AND A.oc_id = #{ocId}
  15. </if>
  16. <if test="account_id != null">
  17. AND A.account_id = #{account_id, jdbcType=BIGINT}
  18. </if>
  19. <if test="checklistId != null">
  20. AND A.checklist_id = #{checklistId, jdbcType=BIGINT}
  21. </if>
  22. <if test="nodeLeft != null and nodeRight != null">
  23. <![CDATA[
  24. AND B.node_left >= #{nodeLeft, jdbcType=BIGINT}
  25. AND B.node_right <= #{nodeRight, jdbcType=BIGINT}
  26. ]]>
  27. </if>
  28. <if test="day != null">
  29. AND date_format(A.check_time , '%Y-%m-%d') = #{day}
  30. </if>
  31. <if test="startDate != null and endDate != null">
  32. AND A.check_time BETWEEN #{startDate} and #{endDate}
  33. </if>
  34. </select>
  35. <!-- 按条件统计 -->
  36. <select id="counterByCondition" resultType="int" parameterType="java.util.Map">
  37. SELECT
  38. count( 0 ) AS count
  39. FROM check_record AS A
  40. LEFT JOIN s_group AS B ON (A.oc_id = B.oc_id AND A.group_id = B.group_id)
  41. WHERE 1 = 1
  42. <if test="ocId != null">
  43. AND A.oc_id = #{ocId, jdbcType=BIGINT}
  44. </if>
  45. <if test="accountId != null">
  46. AND A.account_id = #{accountId, jdbcType=BIGINT}
  47. </if>
  48. <if test="nodeLeft != null and nodeRight != null">
  49. <![CDATA[
  50. AND B.node_left >= #{nodeLeft, jdbcType=BIGINT}
  51. AND B.node_right <= #{nodeRight, jdbcType=BIGINT}
  52. ]]>
  53. </if>
  54. <if test="day != null">
  55. AND date_format(A.check_time , '%Y-%m-%d') = #{day}
  56. </if>
  57. <if test="startDate != null and endDate != null">
  58. AND A.check_time BETWEEN #{startDate} and #{endDate}
  59. </if>
  60. </select>
  61. <!-- 按清单统计 -->
  62. <select id="counterByChecklist" parameterType="java.util.Map" resultType="com.zhyc.xps.aqpt.vo.CheckRecordByChecklistVo">
  63. SELECT
  64. A.checklist_id,
  65. count( 0 ) AS num
  66. FROM check_record A
  67. LEFT JOIN s_group B ON ( A.oc_id = B.oc_id AND A.group_id = B.group_id )
  68. LEFT JOIN checklist C ON ( A.oc_id = C.oc_id AND A.checklist_id = C.checklist_id)
  69. WHERE 1 = 1
  70. <if test="ocId != null">
  71. AND A.oc_id = #{ocId, jdbcType=BIGINT}
  72. </if>
  73. <if test="accountId != null">
  74. AND A.account_id = #{accountId, jdbcType=BIGINT}
  75. </if>
  76. <if test="nodeLeft != null and nodeRight != null">
  77. <![CDATA[
  78. AND B.node_left >= #{nodeLeft, jdbcType=BIGINT}
  79. AND B.node_right <= #{nodeRight, jdbcType=BIGINT}
  80. ]]>
  81. </if>
  82. <if test="day != null">
  83. AND date_format(A.check_time , '%Y-%m-%d') = #{day}
  84. </if>
  85. <if test="startDate != null and endDate != null">
  86. AND A.check_time BETWEEN #{startDate} and #{endDate}
  87. </if>
  88. GROUP BY A.checklist_id ASC
  89. </select>
  90. </mapper>