西藏巴青项目

LivestockResourceScreenMapper.xml 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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.ruoyi.web.modules.screen.mapper.LivestockResourceScreenMapper">
  4. <sql id="aiSession">
  5. consult_type = 2
  6. </sql>
  7. <sql id="aiMessageJoin">
  8. inner join biz_consult_session s on s.id = m.session_id and s.consult_type = 2
  9. </sql>
  10. <sql id="aiMessageFilter">
  11. m.sender_role = 3
  12. and m.sender_user_id = 0
  13. </sql>
  14. <select id="sumRuralThreeAssetsFixed"
  15. resultType="com.ruoyi.web.modules.screen.domain.dto.LivestockResourceThreeAssetsSumDto">
  16. select
  17. ifnull(sum(operating_fixed_assets), 0) as operatingFixedAssets,
  18. ifnull(sum(non_operating_fixed_assets), 0) as nonOperatingFixedAssets,
  19. ifnull(sum(fixed_assets), 0) as fixedAssets
  20. from biz_rural_three_assets
  21. </select>
  22. <select id="countThreeAssetsProblemByLevel"
  23. resultType="com.ruoyi.web.modules.screen.domain.dto.LivestockResourceProblemLevelCountDto">
  24. select
  25. problem_level as problemLevel,
  26. count(1) as count
  27. from biz_three_assets_problem_report
  28. where report_time &gt;= #{yearStart}
  29. and report_time &lt;= #{yearEnd}
  30. group by problem_level
  31. </select>
  32. <select id="selectLatestLivestockProductOutputStatPeriodByYear"
  33. resultType="com.ruoyi.web.modules.screen.domain.dto.HomeScreenStatPeriodDto">
  34. select
  35. stat_year as statYear,
  36. max(stat_month) as statMonth
  37. from biz_livestock_product_output
  38. where stat_year = #{statYear}
  39. group by stat_year
  40. </select>
  41. <select id="sumLivestockProductOutputByStatYearMonth"
  42. resultType="com.ruoyi.web.modules.screen.domain.dto.LivestockResourceProductOutputSumDto">
  43. select
  44. ifnull(sum(meat_output), 0) as meatOutput,
  45. ifnull(sum(milk_output), 0) as milkOutput
  46. from biz_livestock_product_output
  47. where stat_year = #{statYear}
  48. and stat_month = #{statMonth}
  49. </select>
  50. <select id="sumLivestockProductOutputMonthlyUpTo"
  51. resultType="com.ruoyi.web.modules.screen.domain.dto.LivestockResourceProductOutputMonthDto">
  52. select
  53. stat_month as statMonth,
  54. ifnull(sum(meat_output), 0) as meatOutput,
  55. ifnull(sum(milk_output), 0) as milkOutput
  56. from biz_livestock_product_output
  57. where stat_year = #{statYear}
  58. and stat_month &gt;= 1
  59. and stat_month &lt;= #{maxMonth}
  60. group by stat_month
  61. order by stat_month asc
  62. </select>
  63. <select id="selectLatestVaccinationStatPeriodByYear"
  64. resultType="com.ruoyi.web.modules.screen.domain.dto.HomeScreenStatPeriodDto">
  65. select
  66. stat_year as statYear,
  67. max(stat_month) as statMonth
  68. from biz_vaccination_data
  69. where stat_year = #{statYear}
  70. group by stat_year
  71. </select>
  72. <select id="sumVaccinationByStatYearMonth"
  73. resultType="com.ruoyi.web.modules.screen.domain.dto.LivestockResourceVaccinationSumDto">
  74. select
  75. ifnull(sum(should_vaccinate_count), 0) as shouldVaccinateCount,
  76. ifnull(sum(actual_vaccinate_count), 0) as actualVaccinateCount
  77. from biz_vaccination_data
  78. where stat_year = #{statYear}
  79. and stat_month = #{statMonth}
  80. </select>
  81. <select id="countVetMedicalResource" resultType="long">
  82. select count(1)
  83. from biz_medical_resource
  84. where resource_type = '004001'
  85. and del_flag = '0'
  86. </select>
  87. <select id="selectVetCountByTown"
  88. resultType="com.ruoyi.web.modules.screen.domain.vo.LivestockResourceVetCountListItemVo">
  89. select r.town_name as townName,
  90. count(1) as vetCount
  91. from biz_medical_resource r
  92. left join sys_dept d on r.town_dept_id = d.dept_id
  93. where r.resource_type = '004001'
  94. and r.del_flag = '0'
  95. <if test="townDeptId != null">
  96. and r.town_dept_id = #{townDeptId}
  97. </if>
  98. group by r.town_dept_id, r.town_name, d.order_num
  99. order by ifnull(d.order_num, 999999) asc, r.town_dept_id asc
  100. </select>
  101. <select id="countMedicalOrgResource" resultType="long">
  102. select count(1)
  103. from biz_medical_resource
  104. where resource_type = '004003'
  105. and del_flag = '0'
  106. </select>
  107. <select id="countTechExpertResource" resultType="long">
  108. select count(1)
  109. from biz_tech_resource
  110. where resource_type = '004005'
  111. and del_flag = '0'
  112. </select>
  113. <select id="selectTechServicePersonnelTotals"
  114. resultType="com.ruoyi.web.modules.screen.domain.dto.LivestockResourceTechPersonnelDto">
  115. select
  116. ifnull(envoy_male_count, 0) as envoyMaleCount,
  117. ifnull(envoy_female_count, 0) as envoyFemaleCount,
  118. ifnull(envoy_party_member_count, 0) as envoyPartyMemberCount,
  119. ifnull(envoy_total_count, 0) as envoyTotalCount,
  120. ifnull(agri_junior_count, 0) as agriJuniorCount,
  121. ifnull(agri_clerk_count, 0) as agriClerkCount,
  122. ifnull(agri_intermediate_count, 0) as agriIntermediateCount,
  123. ifnull(agri_associate_senior_count, 0) as agriAssociateSeniorCount,
  124. ifnull(agri_management_count, 0) as agriManagementCount,
  125. ifnull(agri_total_count, 0) as agriTotalCount
  126. from biz_tech_service_personnel
  127. where id = 1
  128. limit 1
  129. </select>
  130. <select id="selectYearOverviewMetrics" resultType="com.ruoyi.web.modules.screen.domain.dto.LivestockResourceOverviewDto">
  131. select
  132. (select count(distinct asker_user_id)
  133. from biz_consult_session
  134. where <include refid="aiSession"/>
  135. and create_time &gt;= #{yearStart}
  136. and create_time &lt;= #{yearEnd}) as totalUsers,
  137. (select count(*)
  138. from biz_consult_session
  139. where <include refid="aiSession"/>
  140. and create_time &gt;= #{yearStart}
  141. and create_time &lt;= #{yearEnd}) as totalSessions,
  142. (select count(*)
  143. from biz_consult_message m
  144. <include refid="aiMessageJoin"/>
  145. where <include refid="aiMessageFilter"/>
  146. and m.create_time &gt;= #{yearStart}
  147. and m.create_time &lt;= #{yearEnd}) as totalQuestionCount,
  148. (select avg(m.cost_time)
  149. from biz_consult_message m
  150. <include refid="aiMessageJoin"/>
  151. where <include refid="aiMessageFilter"/>
  152. and m.cost_time is not null
  153. and m.create_time &gt;= #{yearStart}
  154. and m.create_time &lt;= #{yearEnd}) as avgCostTimeMs
  155. </select>
  156. <select id="countTodayActiveUsers" resultType="long">
  157. select count(distinct asker_user_id)
  158. from biz_consult_session
  159. where <include refid="aiSession"/>
  160. and update_time &gt;= #{dayStart}
  161. and update_time &lt;= #{dayEnd}
  162. </select>
  163. <select id="countTodayNewUsers" resultType="long">
  164. select count(distinct asker_user_id)
  165. from biz_consult_session
  166. where <include refid="aiSession"/>
  167. and create_time &gt;= #{dayStart}
  168. and create_time &lt;= #{dayEnd}
  169. and update_time &gt;= #{dayStart}
  170. and update_time &lt;= #{dayEnd}
  171. and asker_user_id not in (
  172. select distinct asker_user_id
  173. from biz_consult_session
  174. where <include refid="aiSession"/>
  175. and create_time &lt; #{dayStart}
  176. )
  177. </select>
  178. <select id="countTodaySessions" resultType="long">
  179. select count(*)
  180. from biz_consult_session
  181. where <include refid="aiSession"/>
  182. and create_time &gt;= #{dayStart}
  183. and create_time &lt;= #{dayEnd}
  184. </select>
  185. <select id="countTodayQuestionCount" resultType="long">
  186. select count(*)
  187. from biz_consult_message m
  188. <include refid="aiMessageJoin"/>
  189. where <include refid="aiMessageFilter"/>
  190. and m.create_time &gt;= #{dayStart}
  191. and m.create_time &lt;= #{dayEnd}
  192. </select>
  193. <select id="selectDailySessionCounts" resultType="com.ruoyi.web.modules.screen.domain.dto.LivestockResourceDateCountDto">
  194. select date_format(create_time, '%Y-%m-%d') as bucketKey,
  195. count(*) as count
  196. from biz_consult_session
  197. where <include refid="aiSession"/>
  198. and create_time &gt;= #{rangeStart}
  199. and create_time &lt;= #{rangeEnd}
  200. group by date_format(create_time, '%Y-%m-%d')
  201. </select>
  202. <select id="selectDailyAiReplyCounts" resultType="com.ruoyi.web.modules.screen.domain.dto.LivestockResourceDateCountDto">
  203. select date_format(m.create_time, '%Y-%m-%d') as bucketKey,
  204. count(*) as count
  205. from biz_consult_message m
  206. <include refid="aiMessageJoin"/>
  207. where <include refid="aiMessageFilter"/>
  208. and m.create_time &gt;= #{rangeStart}
  209. and m.create_time &lt;= #{rangeEnd}
  210. group by date_format(m.create_time, '%Y-%m-%d')
  211. </select>
  212. <select id="selectUserStructure" resultType="com.ruoyi.web.modules.screen.domain.dto.LivestockResourceUserStructureDto">
  213. select coalesce(sum(case when datediff(last_use_time, first_use_time) &lt;= 180 then 1 else 0 end), 0) as newUserCount,
  214. coalesce(sum(case when datediff(last_use_time, first_use_time) &gt; 180 then 1 else 0 end), 0) as oldUserCount
  215. from biz_consult_user
  216. </select>
  217. <select id="countAskerMessagesInYear" resultType="long">
  218. select count(*)
  219. from biz_consult_message m
  220. <include refid="aiMessageJoin"/>
  221. where <include refid="aiMessageFilter"/>
  222. and m.create_time &gt;= #{yearStart}
  223. and m.create_time &lt;= #{yearEnd}
  224. </select>
  225. <select id="selectAskerCategoryCounts" resultType="com.ruoyi.web.modules.screen.domain.dto.LivestockResourceCategoryCountDto">
  226. select category_code as categoryCode,
  227. count(*) as count,
  228. max(last_time) as lastEventTime
  229. from (
  230. select m.id,
  231. case
  232. when trim(coalesce((
  233. select m2.ai_category
  234. from biz_consult_message m2
  235. where m2.session_id = m.session_id
  236. and m2.sender_role = 1
  237. and m2.send_time &lt;= m.send_time
  238. order by m2.send_time desc
  239. limit 1
  240. ), '')) is null
  241. or trim(coalesce((
  242. select m2.ai_category
  243. from biz_consult_message m2
  244. where m2.session_id = m.session_id
  245. and m2.sender_role = 1
  246. and m2.send_time &lt;= m.send_time
  247. order by m2.send_time desc
  248. limit 1
  249. ), '')) = '' then 'UNCAT'
  250. else trim(coalesce((
  251. select m2.ai_category
  252. from biz_consult_message m2
  253. where m2.session_id = m.session_id
  254. and m2.sender_role = 1
  255. and m2.send_time &lt;= m.send_time
  256. order by m2.send_time desc
  257. limit 1
  258. ), ''))
  259. end as category_code,
  260. m.create_time as last_time
  261. from biz_consult_message m
  262. <include refid="aiMessageJoin"/>
  263. where <include refid="aiMessageFilter"/>
  264. and m.create_time &gt;= #{yearStart}
  265. and m.create_time &lt;= #{yearEnd}
  266. ) t
  267. group by category_code
  268. </select>
  269. <select id="selectHourlySessionCounts" resultType="com.ruoyi.web.modules.screen.domain.dto.LivestockResourceDateCountDto">
  270. select date_format(create_time, '%Y%m%d%H') as bucketKey,
  271. count(*) as count
  272. from biz_consult_session
  273. where <include refid="aiSession"/>
  274. and create_time &gt;= #{windowStart}
  275. and create_time &lt;= #{windowEnd}
  276. group by date_format(create_time, '%Y%m%d%H')
  277. </select>
  278. <select id="selectHourlyAiReplyCounts" resultType="com.ruoyi.web.modules.screen.domain.dto.LivestockResourceDateCountDto">
  279. select date_format(m.create_time, '%Y%m%d%H') as bucketKey,
  280. count(*) as count
  281. from biz_consult_message m
  282. <include refid="aiMessageJoin"/>
  283. where <include refid="aiMessageFilter"/>
  284. and m.create_time &gt;= #{windowStart}
  285. and m.create_time &lt;= #{windowEnd}
  286. group by date_format(m.create_time, '%Y%m%d%H')
  287. </select>
  288. <select id="countYearSessions" resultType="long">
  289. select count(*)
  290. from biz_consult_session
  291. where <include refid="aiSession"/>
  292. and create_time &gt;= #{yearStart}
  293. and create_time &lt;= #{yearEnd}
  294. </select>
  295. <select id="selectSessionReplyBuckets" resultType="com.ruoyi.web.modules.screen.domain.dto.LivestockResourceBandCountDto">
  296. select band_code as bandCode,
  297. count(*) as sessionCount
  298. from (
  299. select s.id,
  300. case
  301. when r.cnt between 1 and 2 then 'LIGHT'
  302. when r.cnt between 3 and 4 then 'NORMAL'
  303. when r.cnt between 5 and 10 then 'ACTIVE'
  304. else 'DEEP'
  305. end as band_code
  306. from biz_consult_session s
  307. inner join (
  308. select m.session_id, count(*) as cnt
  309. from biz_consult_message m
  310. inner join biz_consult_session s2 on s2.id = m.session_id and s2.consult_type = 2
  311. where m.sender_role = 3
  312. and m.sender_user_id = 0
  313. and m.create_time &gt;= #{yearStart}
  314. and m.create_time &lt;= #{yearEnd}
  315. group by m.session_id
  316. ) r on r.session_id = s.id
  317. where s.consult_type = 2
  318. and s.create_time &gt;= #{yearStart}
  319. and s.create_time &lt;= #{yearEnd}
  320. ) t
  321. group by band_code
  322. </select>
  323. <select id="countAiRepliesOk" resultType="long">
  324. select count(*)
  325. from biz_consult_message m
  326. <include refid="aiMessageJoin"/>
  327. where <include refid="aiMessageFilter"/>
  328. and m.cost_time is not null
  329. and m.create_time &gt;= #{yearStart}
  330. and m.create_time &lt;= #{yearEnd}
  331. </select>
  332. <select id="countAiRepliesFail" resultType="long">
  333. select count(*)
  334. from biz_consult_message m
  335. <include refid="aiMessageJoin"/>
  336. where <include refid="aiMessageFilter"/>
  337. and m.cost_time is null
  338. and m.create_time &gt;= #{yearStart}
  339. and m.create_time &lt;= #{yearEnd}
  340. </select>
  341. <select id="selectTextAskerContents" resultType="string">
  342. select m.content
  343. from biz_consult_message m
  344. <include refid="aiMessageJoin"/>
  345. where m.sender_role = 1
  346. and m.sender_user_id &lt;&gt; 0
  347. and m.msg_type = 1
  348. and m.content is not null
  349. and trim(m.content) != ''
  350. and m.send_time &gt;= #{yearStart}
  351. and m.send_time &lt;= #{yearEnd}
  352. </select>
  353. <select id="selectDistinctSessionYears" resultType="int">
  354. select distinct year(create_time)
  355. from biz_consult_session
  356. where <include refid="aiSession"/>
  357. and create_time is not null
  358. order by year(create_time) desc
  359. </select>
  360. </mapper>