LedgerSeizureStatsMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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.sundot.airport.ledger.mapper.LedgerSeizureStatsMapper">
  4. <resultMap id="BaseResultMap" type="com.sundot.airport.ledger.domain.LedgerSeizureStats">
  5. <id property="id" column="id" />
  6. <result property="recordDate" column="record_date" />
  7. <result property="deptName" column="dept_name" />
  8. <result property="deptId" column="dept_id" />
  9. <result property="teamName" column="team_name" />
  10. <result property="teamId" column="team_id" />
  11. <result property="groupName" column="group_name" />
  12. <result property="groupId" column="group_id" />
  13. <result property="workArea" column="work_area" />
  14. <result property="areaId" column="area_id" />
  15. <result property="qualificationLevel" column="qualification_level" />
  16. <result property="position" column="position" />
  17. <result property="positionId" column="position_id" />
  18. <result property="inspectorName" column="inspector_name" />
  19. <result property="inspectorId" column="inspector_id" />
  20. <result property="passengerName" column="passenger_name" />
  21. <result property="passengerGender" column="passenger_gender" />
  22. <result property="passengerEthnicity" column="passenger_ethnicity" />
  23. <result property="passengerAge" column="passenger_age" />
  24. <result property="flightNo" column="flight_no" />
  25. <result property="destination" column="destination" />
  26. <result property="inOutPort" column="in_out_port" />
  27. <result property="violationSubject" column="violation_subject" />
  28. <result property="itemCategory" column="item_category" />
  29. <result property="secondaryCategory" column="secondary_category" />
  30. <result property="itemName" column="item_name" />
  31. <result property="itemQuantity" column="item_quantity" />
  32. <result property="concealmentPart" column="concealment_part" />
  33. <result property="eventBrief" column="event_brief" />
  34. <result property="handlingMethod" column="handling_method" />
  35. <result property="addScore" column="add_score" />
  36. <result property="scoreDimension" column="score_dimension" />
  37. <result property="scoreIndicator" column="score_indicator" />
  38. <result property="evidenceFile" column="evidence_file" />
  39. <result property="remark" column="remark" />
  40. <result property="importBatch" column="import_batch" />
  41. <result property="sourceType" column="source_type" />
  42. <result property="createBy" column="create_by" />
  43. <result property="createTime" column="create_time" />
  44. <result property="updateBy" column="update_by" />
  45. <result property="updateTime" column="update_time" />
  46. <result property="syncFlag" column="sync_flag" />
  47. </resultMap>
  48. <sql id="selectVo">
  49. SELECT id, record_date, dept_name, dept_id, team_name, team_id, group_name, group_id,
  50. work_area, area_id, qualification_level, position, position_id,
  51. inspector_name, inspector_id,
  52. passenger_name, passenger_gender, passenger_ethnicity, passenger_age,
  53. flight_no, destination, in_out_port, violation_subject,
  54. item_category, secondary_category, item_name, item_quantity,
  55. concealment_part, event_brief, handling_method,
  56. add_score, score_dimension, score_indicator, evidence_file, remark,
  57. import_batch, source_type, create_by, create_time, update_by, update_time, sync_flag
  58. FROM ledger_seizure_stats
  59. WHERE del_flag = '0'
  60. </sql>
  61. <select id="selectList" parameterType="com.sundot.airport.ledger.domain.LedgerSeizureStats" resultMap="BaseResultMap">
  62. <include refid="selectVo"/>
  63. <if test="deptName != null and deptName != ''">AND dept_name LIKE CONCAT('%', #{deptName}, '%')</if>
  64. <if test="teamName != null and teamName != ''">AND team_name LIKE CONCAT('%', #{teamName}, '%')</if>
  65. <if test="syncFlag != null and syncFlag != ''">AND sync_flag = #{syncFlag}</if>
  66. <if test="params != null and params.beginTime != null and params.beginTime != ''">
  67. AND record_date &gt;= #{params.beginTime}
  68. </if>
  69. <if test="params != null and params.endTime != null and params.endTime != ''">
  70. AND record_date &lt;= #{params.endTime}
  71. </if>
  72. ORDER BY id DESC
  73. </select>
  74. <update id="updateSyncFlag">
  75. update ledger_seizure_stats
  76. set sync_flag = '1'
  77. where sync_flag = '0'
  78. </update>
  79. <select id="countByInspectorAndDateRange" resultType="int">
  80. SELECT count(*)
  81. FROM ledger_seizure_stats
  82. WHERE del_flag = '0'
  83. AND inspector_name = #{inspectorName}
  84. <if test="beginTime != null and beginTime != ''">
  85. AND record_date &gt;= STR_TO_DATE(#{beginTime}, '%Y-%m-%d')
  86. </if>
  87. <if test="endTime != null and endTime != ''">
  88. AND record_date &lt;= STR_TO_DATE(#{endTime}, '%Y-%m-%d')
  89. </if>
  90. </select>
  91. <select id="countSeizureTotalQuantity" parameterType="com.sundot.airport.ledger.domain.vo.CountQueryReqVO" resultType="com.sundot.airport.ledger.domain.vo.CountSeizureTotalQuantityResVO">
  92. SELECT
  93. record_date AS recordDate,
  94. <!-- 动态分组名称 -->
  95. <choose>
  96. <when test="groupId != null">group_name AS groupName</when>
  97. <when test="teamId != null">team_name AS groupName</when>
  98. <when test="deptId != null">dept_name AS groupName</when>
  99. <otherwise>'站' AS groupName</otherwise>
  100. </choose>,
  101. IFNULL(SUM(item_quantity), 0) AS seizeQuantity
  102. FROM ledger_seizure_stats
  103. <where>
  104. <include refid="FILTER_FIXED_DATE_CRITERIA_SQL"/>
  105. </where>
  106. <!-- 动态分组:重点!全为空时仅按日期分组 -->
  107. GROUP BY
  108. <choose>
  109. <when test="groupId != null">group_id, record_date, group_name</when>
  110. <when test="teamId != null">team_id, record_date, team_name</when>
  111. <when test="deptId != null">dept_id, record_date, dept_name</when>
  112. <otherwise>record_date</otherwise>
  113. </choose>
  114. ORDER BY record_date ASC
  115. </select>
  116. <select id="countSeizureSingleQuantity" parameterType="com.sundot.airport.ledger.domain.vo.CountQueryReqVO" resultType="com.sundot.airport.ledger.domain.vo.CountSeizureSingleQuantityResVO">
  117. SELECT
  118. record_date AS recordDate,
  119. <!-- 动态显示维度名称:员工/小组/班组/部门 -->
  120. <choose>
  121. <when test="groupId != null">inspector_name AS groupName</when>
  122. <when test="teamId != null">group_name AS groupName</when>
  123. <when test="deptId != null">team_name AS groupName</when>
  124. <otherwise>dept_name AS groupName</otherwise>
  125. </choose>,
  126. IFNULL(SUM(item_quantity), 0) AS seizeQuantity
  127. FROM ledger_seizure_stats
  128. <where>
  129. <include refid="FILTER_FIXED_DATE_CRITERIA_SQL"/>
  130. </where>
  131. <!-- 动态分组,严格层级下钻 -->
  132. GROUP BY
  133. <choose>
  134. <when test="groupId != null">inspector_id, record_date, inspector_name</when>
  135. <when test="teamId != null">group_id, record_date, group_name</when>
  136. <when test="deptId != null">team_id, record_date, team_name</when>
  137. <otherwise>dept_id, record_date, dept_name</otherwise>
  138. </choose>
  139. ORDER BY record_date ASC
  140. </select>
  141. <!-- 明细查询:动态下钻维度 -->
  142. <select id="statsTimeRangeItem" parameterType="com.sundot.airport.ledger.domain.vo.CountQueryReqVO" resultType="com.sundot.airport.ledger.domain.vo.SeizeItemVO">
  143. SELECT
  144. <choose>
  145. <when test="groupId != null">inspector_name AS name</when>
  146. <when test="teamId != null">group_name AS name</when>
  147. <when test="deptId != null">team_name AS name</when>
  148. <otherwise>dept_name AS name</otherwise>
  149. </choose>,
  150. IFNULL(SUM(item_quantity), 0) AS seizeNum
  151. FROM ledger_seizure_stats
  152. <where>
  153. <include refid="FILTER_FIXED_CRITERIA_SQL"/>
  154. </where>
  155. GROUP BY
  156. <choose>
  157. <when test="groupId != null">inspector_id, inspector_name</when>
  158. <when test="teamId != null">group_id, group_name</when>
  159. <when test="deptId != null">team_id, team_name</when>
  160. <otherwise>dept_id, dept_name</otherwise>
  161. </choose>
  162. ORDER BY seizeNum DESC
  163. </select>
  164. <!-- 总查获数查询 -->
  165. <select id="statsTimeRangeTotal" parameterType="com.sundot.airport.ledger.domain.vo.CountQueryReqVO" resultType="java.lang.Integer">
  166. SELECT IFNULL(SUM(item_quantity), 0)
  167. FROM ledger_seizure_stats
  168. <where>
  169. <include refid="FILTER_FIXED_CRITERIA_SQL"/>
  170. </where>
  171. </select>
  172. <select id="countSeizeSubjectItemQuantity" parameterType="com.sundot.airport.ledger.domain.vo.CountQueryReqVO" resultType="com.sundot.airport.ledger.domain.vo.SeizeCategoryQuantityVO">
  173. SELECT item_name AS itemName, IFNULL(SUM(item_quantity), 0) AS itemNum
  174. FROM ledger_seizure_stats
  175. <where>
  176. <include refid="FILTER_FIXED_CRITERIA_SQL"/>
  177. <!-- 过滤空类别,避免脏数据 -->
  178. AND item_name IS NOT NULL
  179. AND item_name != ''
  180. </where>
  181. GROUP BY item_name
  182. ORDER BY itemNum DESC
  183. </select>
  184. <select id="countSeizeAreaQuantity" parameterType="com.sundot.airport.ledger.domain.vo.CountQueryReqVO" resultType="com.sundot.airport.ledger.domain.vo.SeizureAreaVO">
  185. SELECT area_id AS areaId, work_area AS workArea, IFNULL(SUM(item_quantity), 0) AS areaSeizeNum
  186. FROM ledger_seizure_stats
  187. <where>
  188. <include refid="FILTER_FIXED_CRITERIA_SQL"/>
  189. <!-- 过滤空区域脏数据 -->
  190. AND work_area IS NOT NULL AND work_area != ''
  191. </where>
  192. GROUP BY area_id, work_area
  193. ORDER BY areaSeizeNum DESC
  194. </select>
  195. <sql id="FILTER_FIXED_CRITERIA_SQL">
  196. del_flag = '0'
  197. <if test="startDate != null and endDate != null">
  198. AND record_date BETWEEN #{startDate,jdbcType=TIMESTAMP} AND #{endDate,jdbcType=TIMESTAMP}
  199. </if>
  200. <include refid="FILTER_CRITERIA_SQL"/>
  201. </sql>
  202. <sql id="FILTER_FIXED_DATE_CRITERIA_SQL">
  203. del_flag = '0'
  204. <!-- 近30天自然日 -->
  205. AND record_date >= DATE_SUB(CURDATE(), INTERVAL 29 DAY)
  206. AND record_date &lt;= CURDATE()
  207. <include refid="FILTER_CRITERIA_SQL"/>
  208. </sql>
  209. <sql id="FILTER_CRITERIA_SQL">
  210. <!-- 三级联动筛选 -->
  211. <if test="deptId != null">AND dept_id = #{deptId}</if>
  212. <if test="teamId != null">AND team_id = #{teamId}</if>
  213. <if test="groupId != null">AND group_id = #{groupId}</if>
  214. <!-- 筛选空值 -->
  215. AND dept_id IS NOT NULL AND dept_id != ''
  216. AND team_id IS NOT NULL AND team_id != ''
  217. AND inspector_id IS NOT NULL AND inspector_id != ''
  218. </sql>
  219. </mapper>