FsSopCompanyUserTaskMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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.qw.mapper.FsSopCompanyUserTaskMapper">
  6. <resultMap type="FsSopCompanyUserTask" id="FsSopCompanyUserTaskResult">
  7. <result property="id" column="id" />
  8. <result property="packageId" column="package_id" />
  9. <result property="orderCode" column="order_code" />
  10. <result property="companyUserId" column="company_user_id" />
  11. <result property="doctorId" column="doctor_id" />
  12. <result property="userId" column="user_id" />
  13. <result property="status" column="status" />
  14. <result property="createTime" column="create_time" />
  15. <result property="updateTime" column="update_time" />
  16. <result property="remark" column="remark" />
  17. <result property="type" column="type" />
  18. <result property="qwExternalContactId" column="qw_external_contact_id" />
  19. </resultMap>
  20. <resultMap type="com.fs.qw.vo.SopCompanyUserTaskVo" id="SopCompanyUserTaskVoResult">
  21. <!-- 主键可 -->
  22. <result property="id" column="id" />
  23. <!-- fs_sop_company_user_task 表字段 -->
  24. <result property="packageId" column="package_id" />
  25. <result property="orderCode" column="order_code" />
  26. <result property="companyUserId" column="company_user_id" />
  27. <result property="doctorId" column="doctor_id" />
  28. <result property="userId" column="user_id" />
  29. <result property="status" column="status" />
  30. <result property="remark" column="remark" />
  31. <result property="createTime" column="create_time" />
  32. <result property="updateTime" column="update_time" />
  33. <result property="type" column="type" />
  34. <result property="qwExternalContactId" column="qw_external_contact_id" />
  35. <!-- 关联表字段 -->
  36. <result property="name" column="name" /> <!-- qwec.name -->
  37. <result property="doctorName" column="doctor_name" /> <!-- fd.doctor_name -->
  38. <result property="avatar" column="avatar" />
  39. <result property="phone" column="phone" />
  40. <result property="packageName" column="package_name" />
  41. <result property="companyUserName" column="nick_name" />
  42. </resultMap>
  43. <sql id="selectFsSopCompanyUserTaskVo">
  44. select id, package_id,order_code,company_user_id, doctor_id, user_id, status, create_time, update_time, remark,type,qw_external_contact_id from fs_sop_company_user_task
  45. </sql>
  46. <select id="selectFsSopCompanyUserTaskVoList" parameterType="com.fs.qw.dto.SopCompanyUserTaskDto" resultMap="SopCompanyUserTaskVoResult">
  47. SELECT
  48. sct.id,
  49. sct.user_id,
  50. sct.package_id,
  51. sct.order_code,
  52. sct.company_user_id,
  53. qwec.name,
  54. qwec.avatar,
  55. fu.phone,
  56. sct.doctor_id,
  57. fd.doctor_name,
  58. sct.STATUS,
  59. sct.create_time,
  60. sct.update_time,
  61. sct.remark,
  62. sct.type,
  63. cu.nick_name,
  64. sct.qw_external_contact_id
  65. FROM
  66. fs_sop_company_user_task sct
  67. LEFT JOIN fs_doctor fd ON sct.doctor_id = fd.doctor_id
  68. LEFT JOIN qw_external_contact qwec ON sct.qw_external_contact_id = qwec.id
  69. LEFT JOIN fs_user fu ON qwec.fs_user_id = fu.user_id
  70. LEFT JOIN company_user cu ON cu.user_id = sct.company_user_id
  71. <where>
  72. <if test="id != null "> and sct.id = #{id}</if>
  73. <if test="doctorId != null "> and sct.doctor_id = #{doctorId}</if>
  74. <if test="userId != null "> and sct.user_id = #{userId}</if>
  75. <if test="packageId != null "> and sct.package_id = #{packageId}</if>
  76. <if test="orderCode != null "> and sct.order_code = #{orderCode}</if>
  77. <if test="type != null "> and sct.type = #{type}</if>
  78. <if test="companyUserId != null "> and sct.company_user_id = #{companyUserId}</if>
  79. <if test="status != null "> and sct.status = #{status}</if>
  80. <if test="qwUserId != null "> and qwec.qw_user_id = #{qwUserId}</if>
  81. <if test="name != null and name !='' "> and qwec.name like concat('%', #{name}, '%')</if>
  82. <if test="doctorName != null and doctorName != ''"> and fd.doctor_name like concat('%', #{doctorName}, '%')</if>
  83. <if test="companyUserName != null and companyUserName !=''"> and cu.nick_name like concat('%', #{companyUserName}, '%')</if>
  84. <if test="beginTime != null and beginTime != ''">
  85. and sct.create_time &gt;= str_to_date(#{beginTime}, '%Y-%m-%d %H:%i:%s')
  86. </if>
  87. <if test="endTime != null and endTime != ''">
  88. and sct.create_time &lt;= str_to_date(#{endTime}, '%Y-%m-%d %H:%i:%s')
  89. </if>
  90. </where>
  91. ORDER BY sct.id DESC
  92. </select>
  93. <select id="selectFsSopCompanyUserTaskVoById" parameterType="Long" resultMap="SopCompanyUserTaskVoResult">
  94. SELECT
  95. sct.id,
  96. sct.user_id,
  97. sct.package_id,
  98. sct.order_code,
  99. sct.company_user_id,
  100. qwec.name,
  101. qwec.avatar,
  102. fu.phone,
  103. sct.doctor_id,
  104. fd.doctor_name,
  105. sct.STATUS,
  106. sct.create_time,
  107. sct.update_time,
  108. sct.remark,
  109. sct.type,
  110. sct.qw_external_contact_id
  111. FROM
  112. fs_sop_company_user_task sct
  113. LEFT JOIN fs_doctor fd ON sct.doctor_id = fd.doctor_id
  114. LEFT JOIN qw_external_contact qwec ON sct.qw_external_contact_id = qwec.id
  115. LEFT JOIN fs_user fu ON qwec.fs_user_id = fu.user_id
  116. where sct.id = #{id}
  117. </select>
  118. <!-- 统计指定时间段内已处理/待处理数量 -->
  119. <select id="selectAllTimeRangeStats" resultType="map">
  120. SELECT
  121. -- 今日
  122. SUM(CASE WHEN DATE(create_time) = CURDATE() AND status = 1 THEN 1 ELSE 0 END) AS day_processed,
  123. SUM(CASE WHEN DATE(create_time) = CURDATE() AND status = 0 THEN 1 ELSE 0 END) AS day_pending,
  124. -- 本周(周一到今天)
  125. SUM(CASE
  126. WHEN create_time >= DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY)
  127. AND create_time &lt; CURDATE() + INTERVAL 1 DAY
  128. AND status = 1
  129. THEN 1 ELSE 0 END) AS week_processed,
  130. SUM(CASE
  131. WHEN create_time >= DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY)
  132. AND create_time &lt; CURDATE() + INTERVAL 1 DAY
  133. AND status = 0
  134. THEN 1 ELSE 0 END) AS week_pending,
  135. -- 本月
  136. SUM(CASE WHEN YEAR(create_time) = YEAR(CURDATE())
  137. AND MONTH(create_time) = MONTH(CURDATE())
  138. AND status = 1
  139. THEN 1 ELSE 0 END) AS month_processed,
  140. SUM(CASE WHEN YEAR(create_time) = YEAR(CURDATE())
  141. AND MONTH(create_time) = MONTH(CURDATE())
  142. AND status = 0
  143. THEN 1 ELSE 0 END) AS month_pending
  144. FROM fs_sop_company_user_task
  145. WHERE create_time >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH) <!-- 只查最近1个月数据,减少扫描量 -->
  146. </select>
  147. <!-- 最近7天每日任务量(含今天) -->
  148. <select id="getTaskCountLast7Days" resultType="map">
  149. SELECT
  150. DATE_FORMAT(create_time, '%m-%d') AS date,
  151. COUNT(*) AS total
  152. FROM fs_sop_company_user_task
  153. WHERE create_time &gt;= DATE_SUB(CURDATE(), INTERVAL 6 DAY)
  154. AND create_time &lt; CURDATE() + INTERVAL 1 DAY
  155. GROUP BY DATE(create_time)
  156. ORDER BY DATE(create_time) ASC
  157. </select>
  158. <insert id="insertFsSopCompanyUserTask" parameterType="FsSopCompanyUserTask" useGeneratedKeys="true" keyProperty="id">
  159. insert into fs_sop_company_user_task
  160. <trim prefix="(" suffix=")" suffixOverrides=",">
  161. <if test="packageId != null">package_id,</if>
  162. <if test="orderCode != null">order_code,</if>
  163. <if test="companyUserId != null">company_user_id,</if>
  164. <if test="doctorId != null">doctor_id,</if>
  165. <if test="userId != null">user_id,</if>
  166. <if test="status != null">status,</if>
  167. <if test="createTime != null">create_time,</if>
  168. <if test="updateTime != null">update_time,</if>
  169. <if test="remark != null">remark,</if>
  170. <if test="type != null">type,</if>
  171. <if test="qwExternalContactId != null">qw_external_contact_id,</if>
  172. </trim>
  173. <trim prefix="values (" suffix=")" suffixOverrides=",">
  174. <if test="packageId != null">#{packageId},</if>
  175. <if test="orderCode != null">#{orderCode},</if>
  176. <if test="companyUserId != null">#{companyUserId},</if>
  177. <if test="doctorId != null">#{doctorId},</if>
  178. <if test="userId != null">#{userId},</if>
  179. <if test="status != null">#{status},</if>
  180. <if test="createTime != null">#{createTime},</if>
  181. <if test="updateTime != null">#{updateTime},</if>
  182. <if test="remark != null">#{remark},</if>
  183. <if test="type != null">#{type},</if>
  184. <if test="qwExternalContactId != null">#{qwExternalContactId},</if>
  185. </trim>
  186. </insert>
  187. <update id="updateFsSopCompanyUserTask" parameterType="FsSopCompanyUserTask">
  188. update fs_sop_company_user_task
  189. <trim prefix="SET" suffixOverrides=",">
  190. <if test="packageId != null">package_id = #{packageId},</if>
  191. <if test="orderCode != null">order_code = #{orderCode},</if>
  192. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  193. <if test="doctorId != null">doctor_id = #{doctorId},</if>
  194. <if test="userId != null">user_id = #{userId},</if>
  195. <if test="status != null">status = #{status},</if>
  196. <if test="createTime != null">create_time = #{createTime},</if>
  197. <if test="updateTime != null">update_time = #{updateTime},</if>
  198. <if test="remark != null">remark = #{remark},</if>
  199. <if test="type != null">type = #{type},</if>
  200. <if test="qwExternalContactId != null">qw_external_contact_id=#{qwExternalContactId},</if>
  201. </trim>
  202. where id = #{id}
  203. </update>
  204. <delete id="deleteFsSopCompanyUserTaskById" parameterType="Long">
  205. delete from fs_sop_company_user_task where id = #{id}
  206. </delete>
  207. <delete id="deleteFsSopCompanyUserTaskByIds" parameterType="String">
  208. delete from fs_sop_company_user_task where id in
  209. <foreach item="id" collection="array" open="(" separator="," close=")">
  210. #{id}
  211. </foreach>
  212. </delete>
  213. </mapper>