FsPrescribeMapper.xml 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.fs.his.mapper.FsPrescribeMapper">
  6. <resultMap type="FsPrescribe" id="FsPrescribeResult">
  7. <result property="prescribeId" column="prescribe_id" />
  8. <result property="prescribeType" column="prescribe_type" />
  9. <result property="inquiryOrderId" column="inquiry_order_id" />
  10. <result property="storeOrderId" column="store_order_id" />
  11. <result property="userId" column="user_id" />
  12. <result property="patientId" column="patient_id" />
  13. <result property="prescribeCode" column="prescribe_code" />
  14. <result property="patientDescs" column="patient_descs" />
  15. <result property="nowIllness" column="now_illness" />
  16. <result property="historyIllness" column="history_illness" />
  17. <result property="patientAge" column="patient_age" />
  18. <result property="patientName" column="patient_name" />
  19. <result property="weight" column="weight" />
  20. <result property="isHistoryAllergic" column="is_history_allergic" />
  21. <result property="historyAllergic" column="history_allergic" />
  22. <result property="liverUnusual" column="liver_unusual" />
  23. <result property="renalUnusual" column="renal_unusual" />
  24. <result property="isLactation" column="is_lactation" />
  25. <result property="patientTel" column="patient_tel" />
  26. <result property="patientGender" column="patient_gender" />
  27. <result property="recordPic" column="record_pic" />
  28. <result property="prescribeImgUrl" column="prescribe_img_url" />
  29. <result property="auditReason" column="audit_reason" />
  30. <result property="diagnose" column="diagnose" />
  31. <result property="doctorId" column="doctor_id" />
  32. <result property="drugDoctorId" column="drug_doctor_id" />
  33. <result property="createTime" column="create_time" />
  34. <result property="status" column="status" />
  35. <result property="auditTime" column="audit_time" />
  36. <result property="remark" column="remark" />
  37. <result property="usageJson" column="usage_json" />
  38. <result property="storeId" column="store_id" />
  39. <result property="prescribeDoctorId" column="prescribe_doctor_id" />
  40. <result property="doctorSignUrl" column="doctor_sign_url" />
  41. <result property="prescribeDoctorSignUrl" column="prescribe_doctor_sign_url" />
  42. <result property="drugDoctorSignUrl" column="drug_doctor_sign_url" />
  43. <result property="patientBirthday" column="patient_birthday" />
  44. <result property="recipeType" column="recipe_type" />
  45. <result property="prescribeCodeUrl" column="prescribe_code_url" />
  46. <result property="cycle" column="cycle" />
  47. <result property="icdCode" column="icd_code" />
  48. <result property="source" column="source" />
  49. <result property="prescribeImgStoreUrl" column="prescribe_img_store_url" />
  50. <result property="doctorConfirm" column="doctor_confirm" />
  51. <result property="startOperateTime" column="start_operate_time" />
  52. <result property="endOperateTime" column="end_operate_time" />
  53. <result property="operateSecond" column="operate_second" />
  54. </resultMap>
  55. <sql id="selectFsPrescribeVo">
  56. select prescribe_id,prescribe_code_url
  57. ,prescribe_img_store_url,source,cycle,icd_code,prescribe_type
  58. ,recipe_type,patient_birthday,drug_doctor_sign_url,prescribe_doctor_id
  59. ,doctor_sign_url,prescribe_doctor_sign_url, inquiry_order_id, store_order_id
  60. , user_id, patient_id, prescribe_code, patient_descs, now_illness, history_illness
  61. , patient_age, patient_name, weight, is_history_allergic, history_allergic, liver_unusual
  62. , renal_unusual, is_lactation, patient_tel, patient_gender, record_pic, prescribe_img_url
  63. , audit_reason, diagnose, doctor_id,drug_doctor_id, create_time, status, audit_time,remark
  64. ,usage_json,store_id,doctor_confirm, start_operate_time,end_operate_time,operate_second from fs_prescribe
  65. </sql>
  66. <select id="selectFsPrescribeList" parameterType="FsPrescribe" resultMap="FsPrescribeResult">
  67. <include refid="selectFsPrescribeVo"/>
  68. <where>
  69. <if test="prescribeType != null "> and prescribe_type = #{prescribeType}</if>
  70. <if test="inquiryOrderId != null "> and inquiry_order_id = #{inquiryOrderId}</if>
  71. <if test="storeOrderId != null "> and store_order_id = #{storeOrderId}</if>
  72. <if test="userId != null "> and user_id = #{userId}</if>
  73. <if test="patientId != null "> and patient_id = #{patientId}</if>
  74. <if test="prescribeCode != null and prescribeCode != ''"> and prescribe_code = #{prescribeCode}</if>
  75. <if test="patientDescs != null and patientDescs != ''"> and patient_descs = #{patientDescs}</if>
  76. <if test="nowIllness != null and nowIllness != ''"> and now_illness = #{nowIllness}</if>
  77. <if test="historyIllness != null and historyIllness != ''"> and history_illness = #{historyIllness}</if>
  78. <if test="patientAge != null and patientAge != ''"> and patient_age = #{patientAge}</if>
  79. <if test="patientName != null and patientName != ''"> and patient_name like concat('%', #{patientName}, '%')</if>
  80. <if test="weight != null and weight != ''"> and weight = #{weight}</if>
  81. <if test="isHistoryAllergic != null and isHistoryAllergic != ''"> and is_history_allergic = #{isHistoryAllergic}</if>
  82. <if test="historyAllergic != null and historyAllergic != ''"> and history_allergic = #{historyAllergic}</if>
  83. <if test="liverUnusual != null and liverUnusual != ''"> and liver_unusual = #{liverUnusual}</if>
  84. <if test="renalUnusual != null and renalUnusual != ''"> and renal_unusual = #{renalUnusual}</if>
  85. <if test="isLactation != null and isLactation != ''"> and is_lactation = #{isLactation}</if>
  86. <if test="patientTel != null and patientTel != ''"> and patient_tel = #{patientTel}</if>
  87. <if test="patientGender != null and patientGender != ''"> and patient_gender = #{patientGender}</if>
  88. <if test="recordPic != null and recordPic != ''"> and record_pic = #{recordPic}</if>
  89. <if test="prescribeImgUrl != null and prescribeImgUrl != ''"> and prescribe_img_url = #{prescribeImgUrl}</if>
  90. <if test="auditReason != null and auditReason != ''"> and audit_reason = #{auditReason}</if>
  91. <if test="diagnose != null and diagnose != ''"> and diagnose = #{diagnose}</if>
  92. <if test="doctorId != null and doctorId != ''"> and doctor_id = #{doctorId}</if>
  93. <if test="status != null "> and status = #{status}</if>
  94. <if test="auditTime != null "> and audit_time = #{auditTime}</if>
  95. <if test="doctorConfirm != null "> and doctor_confirm = #{doctorConfirm}</if>
  96. </where>
  97. order by prescribe_id desc
  98. </select>
  99. <select id="selectFsPrescribeByPrescribeId" parameterType="Long" resultMap="FsPrescribeResult">
  100. <include refid="selectFsPrescribeVo"/>
  101. where prescribe_id = #{prescribeId}
  102. </select>
  103. <insert id="insertFsPrescribe" parameterType="FsPrescribe" useGeneratedKeys="true" keyProperty="prescribeId">
  104. insert into fs_prescribe
  105. <trim prefix="(" suffix=")" suffixOverrides=",">
  106. <if test="prescribeType != null">prescribe_type,</if>
  107. <if test="inquiryOrderId != null">inquiry_order_id,</if>
  108. <if test="storeOrderId != null">store_order_id,</if>
  109. <if test="userId != null">user_id,</if>
  110. <if test="patientId != null">patient_id,</if>
  111. <if test="prescribeCode != null">prescribe_code,</if>
  112. <if test="patientDescs != null">patient_descs,</if>
  113. <if test="nowIllness != null">now_illness,</if>
  114. <if test="historyIllness != null">history_illness,</if>
  115. <if test="patientAge != null">patient_age,</if>
  116. <if test="patientName != null">patient_name,</if>
  117. <if test="weight != null">weight,</if>
  118. <if test="isHistoryAllergic != null">is_history_allergic,</if>
  119. <if test="historyAllergic != null">history_allergic,</if>
  120. <if test="liverUnusual != null">liver_unusual,</if>
  121. <if test="renalUnusual != null">renal_unusual,</if>
  122. <if test="isLactation != null">is_lactation,</if>
  123. <if test="patientTel != null">patient_tel,</if>
  124. <if test="patientGender != null">patient_gender,</if>
  125. <if test="recordPic != null">record_pic,</if>
  126. <if test="prescribeImgUrl != null">prescribe_img_url,</if>
  127. <if test="auditReason != null">audit_reason,</if>
  128. <if test="diagnose != null">diagnose,</if>
  129. <if test="doctorId != null">doctor_id,</if>
  130. <if test="drugDoctorId != null">drug_doctor_id,</if>
  131. <if test="createTime != null">create_time,</if>
  132. <if test="status != null">status,</if>
  133. <if test="auditTime != null">audit_time,</if>
  134. <if test="remark != null">remark,</if>
  135. <if test="usageJson != null">usage_json,</if>
  136. <if test="storeId != null">store_id,</if>
  137. <if test="prescribeDoctorId != null">prescribe_doctor_id,</if>
  138. <if test="doctorSignUrl != null">doctor_sign_url,</if>
  139. <if test="prescribeDoctorSignUrl != null">prescribe_doctor_sign_url,</if>
  140. <if test="drugDoctorSignUrl != null">drug_doctor_sign_url,</if>
  141. <if test="patientBirthday != null">patient_birthday,</if>
  142. <if test="recipeType != null">recipe_type,</if>
  143. <if test="prescribeCodeUrl != null">prescribe_code_url,</if>
  144. <if test="cycle != null">cycle,</if>
  145. <if test="icdCode != null">icd_code,</if>
  146. <if test="source != null">source,</if>
  147. <if test="prescribeImgStoreUrl != null">prescribe_img_store_url,</if>
  148. <if test="doctorConfirm != null">doctor_confirm,</if>
  149. <if test="startOperateTime != null">start_operate_time,</if>
  150. <if test="endOperateTime != null">end_operate_time,</if>
  151. <if test="operateSecond != null">operate_second,</if>
  152. </trim>
  153. <trim prefix="values (" suffix=")" suffixOverrides=",">
  154. <if test="prescribeType != null">#{prescribeType},</if>
  155. <if test="inquiryOrderId != null">#{inquiryOrderId},</if>
  156. <if test="storeOrderId != null">#{storeOrderId},</if>
  157. <if test="userId != null">#{userId},</if>
  158. <if test="patientId != null">#{patientId},</if>
  159. <if test="prescribeCode != null">#{prescribeCode},</if>
  160. <if test="patientDescs != null">#{patientDescs},</if>
  161. <if test="nowIllness != null">#{nowIllness},</if>
  162. <if test="historyIllness != null">#{historyIllness},</if>
  163. <if test="patientAge != null">#{patientAge},</if>
  164. <if test="patientName != null">#{patientName},</if>
  165. <if test="weight != null">#{weight},</if>
  166. <if test="isHistoryAllergic != null">#{isHistoryAllergic},</if>
  167. <if test="historyAllergic != null">#{historyAllergic},</if>
  168. <if test="liverUnusual != null">#{liverUnusual},</if>
  169. <if test="renalUnusual != null">#{renalUnusual},</if>
  170. <if test="isLactation != null">#{isLactation},</if>
  171. <if test="patientTel != null">#{patientTel},</if>
  172. <if test="patientGender != null">#{patientGender},</if>
  173. <if test="recordPic != null">#{recordPic},</if>
  174. <if test="prescribeImgUrl != null">#{prescribeImgUrl},</if>
  175. <if test="auditReason != null">#{auditReason},</if>
  176. <if test="diagnose != null">#{diagnose},</if>
  177. <if test="doctorId != null">#{doctorId},</if>
  178. <if test="drugDoctorId != null">#{drugDoctorId},</if>
  179. <if test="createTime != null">#{createTime},</if>
  180. <if test="status != null">#{status},</if>
  181. <if test="auditTime != null">#{auditTime},</if>
  182. <if test="remark != null">#{remark},</if>
  183. <if test="usageJson != null">#{usageJson},</if>
  184. <if test="storeId != null">#{storeId},</if>
  185. <if test="prescribeDoctorId != null">#{prescribeDoctorId},</if>
  186. <if test="doctorSignUrl != null">#{doctorSignUrl},</if>
  187. <if test="prescribeDoctorSignUrl != null">#{prescribeDoctorSignUrl},</if>
  188. <if test="drugDoctorSignUrl != null">#{drugDoctorSignUrl},</if>
  189. <if test="patientBirthday != null">#{patientBirthday},</if>
  190. <if test="recipeType != null">#{recipeType},</if>
  191. <if test="prescribeCodeUrl != null">#{prescribeCodeUrl},</if>
  192. <if test="cycle != null">#{cycle},</if>
  193. <if test="icdCode != null">#{icdCode},</if>
  194. <if test="source != null">#{source},</if>
  195. <if test="prescribeImgStoreUrl != null">#{prescribeImgStoreUrl},</if>
  196. <if test="doctorConfirm != null">#{doctorConfirm},</if>
  197. <if test="startOperateTime != null">#{startOperateTime},</if>
  198. <if test="endOperateTime != null">#{endOperateTime},</if>
  199. <if test="operateSecond != null">#{operateSecond},</if>
  200. </trim>
  201. </insert>
  202. <update id="updateFsPrescribe" parameterType="FsPrescribe">
  203. update fs_prescribe
  204. <trim prefix="SET" suffixOverrides=",">
  205. <if test="prescribeType != null">prescribe_type = #{prescribeType},</if>
  206. <if test="inquiryOrderId != null">inquiry_order_id = #{inquiryOrderId},</if>
  207. <if test="storeOrderId != null">store_order_id = #{storeOrderId},</if>
  208. <if test="userId != null">user_id = #{userId},</if>
  209. <if test="patientId != null">patient_id = #{patientId},</if>
  210. <if test="prescribeCode != null">prescribe_code = #{prescribeCode},</if>
  211. <if test="patientDescs != null">patient_descs = #{patientDescs},</if>
  212. <if test="nowIllness != null">now_illness = #{nowIllness},</if>
  213. <if test="historyIllness != null">history_illness = #{historyIllness},</if>
  214. <if test="patientAge != null">patient_age = #{patientAge},</if>
  215. <if test="patientName != null">patient_name = #{patientName},</if>
  216. <if test="weight != null">weight = #{weight},</if>
  217. <if test="isHistoryAllergic != null">is_history_allergic = #{isHistoryAllergic},</if>
  218. <if test="historyAllergic != null">history_allergic = #{historyAllergic},</if>
  219. <if test="liverUnusual != null">liver_unusual = #{liverUnusual},</if>
  220. <if test="renalUnusual != null">renal_unusual = #{renalUnusual},</if>
  221. <if test="isLactation != null">is_lactation = #{isLactation},</if>
  222. <if test="patientTel != null">patient_tel = #{patientTel},</if>
  223. <if test="patientGender != null">patient_gender = #{patientGender},</if>
  224. <if test="recordPic != null">record_pic = #{recordPic},</if>
  225. <if test="prescribeImgUrl != null">prescribe_img_url = #{prescribeImgUrl},</if>
  226. <if test="auditReason != null">audit_reason = #{auditReason},</if>
  227. <if test="diagnose != null">diagnose = #{diagnose},</if>
  228. <if test="doctorId != null">doctor_id = #{doctorId},</if>
  229. <if test="drugDoctorId != null">drug_doctor_id = #{drugDoctorId},</if>
  230. <if test="createTime != null">create_time = #{createTime},</if>
  231. <if test="status != null">status = #{status},</if>
  232. <if test="auditTime != null">audit_time = #{auditTime},</if>
  233. <if test="remark != null">remark = #{remark},</if>
  234. <if test="usageJson != null">usage_json = #{usageJson},</if>
  235. <if test="storeId != null">store_id = #{storeId},</if>
  236. <if test="prescribeDoctorId != null">prescribe_doctor_id = #{prescribeDoctorId},</if>
  237. <if test="doctorSignUrl != null">doctor_sign_url = #{doctorSignUrl},</if>
  238. <if test="prescribeDoctorSignUrl != null">prescribe_doctor_sign_url = #{prescribeDoctorSignUrl},</if>
  239. <if test="drugDoctorSignUrl != null">drug_doctor_sign_url = #{drugDoctorSignUrl},</if>
  240. <if test="patientBirthday != null">patient_birthday = #{patientBirthday},</if>
  241. <if test="recipeType != null">recipe_type = #{recipeType},</if>
  242. <if test="prescribeCodeUrl != null">prescribe_code_url = #{prescribeCodeUrl},</if>
  243. <if test="cycle != null">cycle = #{cycle},</if>
  244. <if test="icdCode != null">icd_code = #{icdCode},</if>
  245. <if test="source != null">source = #{source},</if>
  246. <if test="prescribeImgStoreUrl != null">prescribe_img_store_url = #{prescribeImgStoreUrl},</if>
  247. <if test="doctorConfirm != null">doctor_confirm = #{doctorConfirm},</if>
  248. <if test="startOperateTime != null">start_operate_time = #{startOperateTime},</if>
  249. <if test="endOperateTime != null">end_operate_time = #{endOperateTime},</if>
  250. <if test="operateSecond != null">operate_second = #{operateSecond},</if>
  251. </trim>
  252. where prescribe_id = #{prescribeId}
  253. </update>
  254. <delete id="deleteFsPrescribeByPrescribeId" parameterType="Long">
  255. delete from fs_prescribe where prescribe_id = #{prescribeId}
  256. </delete>
  257. <delete id="deleteFsPrescribeByPrescribeIds" parameterType="String">
  258. delete from fs_prescribe where prescribe_id in
  259. <foreach item="prescribeId" collection="array" open="(" separator="," close=")">
  260. #{prescribeId}
  261. </foreach>
  262. </delete>
  263. <select id="selectFsPrescribeListVO_COUNT" parameterType="com.fs.his.param.FsStoreOrderParam" resultType="Long">
  264. select count(1) from fs_prescribe so
  265. <if test="companyId != null or companyUserId != null or orderCode != null or orderStatus != null "> LEFT JOIN fs_store_order fso ON fso.order_id = so.store_order_id </if>
  266. <if test="doctorName != null and doctorName != ''"> LEFT JOIN fs_doctor dc ON dc.doctor_id = so.doctor_id </if>
  267. where 1=1
  268. <if test="companyId != null "> and fso.company_id = #{companyId}</if>
  269. <if test="companyUserId != null "> and fso.company_user_id = #{companyUserId}</if>
  270. <if test="prescribeType != null "> and so.prescribe_type = #{prescribeType}</if>
  271. <if test="inquiryOrderId != null "> and so.inquiry_order_id = #{inquiryOrderId}</if>
  272. <if test="storeOrderId != null "> and so.store_order_id = #{storeOrderId}</if>
  273. <if test="userId != null "> and so.user_id = #{userId}</if>
  274. <if test="prescribeCode != null and prescribeCode != ''"> and so.prescribe_code = #{prescribeCode}</if>
  275. <if test="patientName != null and patientName != ''"> and so.patient_name like concat('%', #{patientName}, '%')</if>
  276. <if test="doctorName != null and doctorName != ''"> and dc.doctor_name like concat('%', #{doctorName}, '%')</if>
  277. <if test="patientTel != null and patientTel != ''"> and so.patient_tel = #{patientTel}</if>
  278. <if test="doctorId != null and doctorId != ''"> and so.doctor_id = #{doctorId}</if>
  279. <if test="status != null "> and so.status = #{status}</if>
  280. <if test="sTime != null "> and DATE(so.create_time) &gt;= DATE(#{sTime})</if>
  281. <if test="eTime != null "> and DATE(so.create_time) &lt;= DATE(#{eTime})</if>
  282. <if test="auditSTime != null "> and DATE(so.audit_time) &gt;= DATE(#{auditSTime})</if>
  283. <if test="auditETime != null "> and DATE(so.audit_time) &lt;= DATE(#{auditETime})</if>
  284. <if test="auditTime != null "> and so.audit_time = #{auditTime}</if>
  285. <if test="orderCode != null "> and fso.order_code = #{orderCode}</if>
  286. <if test="orderStatus != null "> and fso.`status` = #{orderStatus}</if>
  287. <if test="storeId != null "> and so.store_id = #{storeId}</if>
  288. </select>
  289. <select id="selectFsPrescribeListVOWithConfirm" resultType="com.fs.his.vo.FsPrescribeListVO">
  290. select so.*,CAST(operate_second AS CHAR) operateTime,us.nick_name,dc.doctor_name,
  291. dp.doctor_name doctor_drug_name,
  292. fso.order_code,fso.`status` order_status,
  293. fse.store_name FROM fs_prescribe so
  294. LEFT JOIN fs_user us ON us.user_id=so.user_id
  295. LEFT JOIN fs_doctor dc ON dc.doctor_id = so.doctor_id
  296. LEFT JOIN fs_doctor dp ON dp.doctor_id =so.drug_doctor_id
  297. LEFT JOIN fs_store_order fso ON fso.order_id = so.store_order_id
  298. LEFT JOIN fs_store fse ON fse.store_id = so.store_id
  299. <where>
  300. doctor_confirm != -1
  301. <if test="companyId != null "> and fso.company_id = #{companyId}</if>
  302. <if test="companyUserId != null "> and fso.company_user_id = #{companyUserId}</if>
  303. <if test="prescribeType != null "> and so.prescribe_type = #{prescribeType}</if>
  304. <if test="inquiryOrderId != null "> and so.inquiry_order_id = #{inquiryOrderId}</if>
  305. <if test="storeOrderId != null "> and so.store_order_id = #{storeOrderId}</if>
  306. <if test="userId != null "> and so.user_id = #{userId}</if>
  307. <if test="prescribeCode != null and prescribeCode != ''"> and so.prescribe_code = #{prescribeCode}</if>
  308. <if test="patientName != null and patientName != ''"> and so.patient_name like concat('%', #{patientName}, '%')</if>
  309. <if test="doctorName != null and doctorName != ''"> and dc.doctor_name like concat('%', #{doctorName}, '%')</if>
  310. <if test="patientTel != null and patientTel != ''"> and so.patient_tel = #{patientTel}</if>
  311. <if test="doctorId != null and doctorId != ''"> and so.doctor_id = #{doctorId}</if>
  312. <if test="status != null "> and so.status = #{status}</if>
  313. <if test="sTime != null "> and DATE(so.create_time) &gt;= DATE(#{sTime})</if>
  314. <if test="eTime != null "> and DATE(so.create_time) &lt;= DATE(#{eTime})</if>
  315. <if test="auditSTime != null "> and DATE(so.audit_time) &gt;= DATE(#{auditSTime})</if>
  316. <if test="auditETime != null "> and DATE(so.audit_time) &lt;= DATE(#{auditETime})</if>
  317. <if test="auditTime != null "> and so.audit_time = #{auditTime}</if>
  318. <if test="orderCode != null "> and fso.order_code = #{orderCode}</if>
  319. <if test="orderStatus != null "> and fso.`status` = #{orderStatus}</if>
  320. <if test="storeId != null "> and so.store_id = #{storeId}</if>
  321. </where>
  322. order by
  323. CASE WHEN doctor_confirm = 0 THEN 0 ELSE 1 END,
  324. prescribe_id desc
  325. </select>
  326. <select id="selectDoctorOperateStatList" resultType="com.fs.his.vo.DoctorOperateStatVO">
  327. SELECT
  328. fp.doctor_id,
  329. fd.doctor_name,
  330. fd.dept_id,
  331. fd.hospital_id,
  332. fd.group_code,
  333. -- 平均操作时长
  334. AVG(fp.operate_second) AS avgOperateSecond,
  335. -- 操作次数 (等于总处方数)
  336. COUNT(*) as operation,
  337. -- 开方数量
  338. COUNT(DISTINCT fp.prescribe_code) as prescribeNum,
  339. -- 拒方率计算
  340. ROUND(COUNT(CASE WHEN fp.status = 2 THEN 1 END) * 1.0 / COUNT(*), 4) AS rejectRate,
  341. de.dept_name,
  342. ho.hospital_name
  343. FROM fs_prescribe fp
  344. LEFT JOIN fs_doctor fd ON fp.doctor_id = fd.doctor_id
  345. LEFT JOIN fs_department de ON de.dept_id=fd.dept_id
  346. LEFT JOIN fs_hospital ho ON ho.hospital_id=fd.hospital_id
  347. WHERE
  348. fp.start_operate_time IS NOT NULL
  349. AND fp.end_operate_time IS NOT NULL
  350. AND fp.operate_second IS NOT NULL
  351. <if test="groupCode != null and groupCode != ''">
  352. AND fd.group_code = #{groupCode}
  353. </if>
  354. <if test="doctorName != null and doctorName != ''">
  355. AND fd.doctor_name LIKE CONCAT('%', #{doctorName}, '%')
  356. </if>
  357. <if test="deptId != null and deptId != ''">
  358. AND de.dept_id = #{deptId}
  359. </if>
  360. <if test="hospitalId != null and hospitalId != ''">
  361. AND ho.hospital_id = #{hospitalId}
  362. </if>
  363. <!-- 日期范围筛选 -->
  364. <if test="!(queryYear != null and queryMonth != null) and startOperateTime != null">
  365. AND fp.start_operate_time &gt;= #{startOperateTime}
  366. </if>
  367. <if test="!(queryYear != null and queryMonth != null) and endOperateTime != null">
  368. AND fp.end_operate_time &lt;= #{endOperateTime}
  369. </if>
  370. <!-- 新增:月度筛选条件 -->
  371. <if test="queryYear != null">
  372. AND YEAR(fp.start_operate_time) = #{queryYear}
  373. </if>
  374. <if test="queryMonth != null">
  375. AND MONTH(fp.start_operate_time) = #{queryMonth}
  376. </if>
  377. GROUP BY
  378. fp.doctor_id,
  379. fd.doctor_name,
  380. fd.dept_id,
  381. fd.hospital_id
  382. <if test="minRejectRate != null or maxRejectRate != null">
  383. HAVING 1=1
  384. </if>
  385. <if test="minRejectRate != null">
  386. AND ROUND(COUNT(CASE WHEN fp.status = 2 THEN 1 END) * 1.0 / COUNT(*), 4) &gt;= #{minRejectRate}
  387. </if>
  388. <if test="maxRejectRate != null">
  389. AND ROUND(COUNT(CASE WHEN fp.status = 2 THEN 1 END) * 1.0 / COUNT(*), 4) &lt;= #{maxRejectRate}
  390. </if>
  391. ORDER BY
  392. <choose>
  393. <when test="orderByColumn == 'prescribeNum' or orderByColumn == 'operation'">prescribeNum</when>
  394. <when test="orderByColumn == 'rejectRate'">rejectRate</when>
  395. <!-- 默认排序字段 -->
  396. <otherwise>avgOperateSecond</otherwise>
  397. </choose>
  398. <choose>
  399. <when test="sort != null and sort == 'desc'">DESC</when>
  400. <otherwise>ASC</otherwise>
  401. </choose>
  402. </select>
  403. </mapper>