QpTaskMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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.zd.airbottle.mapper.QpTaskMapper">
  6. <resultMap type="com.zd.airbottle.domain.vo.QpTaskVO" id="QpTaskResult">
  7. <result property="id" column="id"/>
  8. <result property="location" column="location"/>
  9. <result property="locationId" column="location_id"/>
  10. <result property="userId" column="user_id"/>
  11. <result property="userName" column="user_name"/>
  12. <result property="phone" column="phone"/>
  13. <result property="deptId" column="dept_id"/>
  14. <result property="deptName" column="dept_name"/>
  15. <result property="type" column="type"/>
  16. <result property="createTime" column="create_time"/>
  17. </resultMap>
  18. <resultMap type="com.zd.airbottle.domain.vo.QpAirGoodsConfigRelationVo" id="QpAirGoodsConfigRelationVo">
  19. </resultMap>
  20. <sql id="selectQpTaskVo">
  21. select id,
  22. location,
  23. location_id,
  24. user_id,
  25. user_name,
  26. phone,
  27. dept_id,
  28. dept_name,
  29. type,
  30. create_time
  31. from qp_task
  32. </sql>
  33. <sql id="selectQpTaskListVo">
  34. select t.id,
  35. t.location,
  36. t.location_id,
  37. t.user_id,
  38. t.user_name,
  39. t.phone,
  40. t.dept_id,
  41. t.dept_name,
  42. t.type,
  43. t.create_time,
  44. (select f.name
  45. from lab_build_floor f
  46. where f.type = 1
  47. and f.id = (
  48. select f.parent_id
  49. from lab_build_floor f
  50. where f.id =
  51. (select bfl.build_id
  52. from lab_build_floor_layout bfl
  53. where bfl.sub_id = t.location_id))) campus,/**校区**/
  54. (select f.`name`
  55. from lab_build_floor f
  56. where f.type = 2
  57. and f.id =
  58. (select bfl.build_id
  59. from lab_build_floor_layout bfl
  60. where bfl.sub_id = t.location_id)) building,/**楼栋*/
  61. (select bfl.room_num
  62. from lab_build_floor_layout bfl
  63. where bfl.sub_id = t.location_id) room,/*房间号**/
  64. (select COALESCE(sum(bottle_number), 0)
  65. from qp_task_detail d
  66. where d.task_id = t.id) applyNum, /**申请总数**/
  67. (select count(1)
  68. from qp_bottle_storage st
  69. where st.task_id = t.id
  70. and st.air_status = 0) storageNum, /** 入库总数 **/
  71. (select count(1)
  72. from qp_bottle_storage st
  73. where st.task_id = t.id
  74. and st.air_status = 1) refuseNum, /** 拒收总数 **/
  75. (select COALESCE(sum(bottle_number), 0)
  76. from qp_task_detail td
  77. where td.task_id = t.id
  78. and qp_status = 0) wpsNum,/** 未派送总数 **/
  79. ((select ifnull((SELECT sum(td.bottle_number)
  80. FROM qp_task_detail td
  81. WHERE td.task_id = t.id
  82. AND qp_status = 1), 0)
  83. from dual) - (select count(1) from qp_bottle_storage where task_id = t.id)) drkNum /** 待入库总数 **/
  84. from qp_task as t
  85. LEFT JOIN sys_dept d on t.dept_id = d.dept_id
  86. LEFT JOIN sys_user u on t.user_id = u.user_id
  87. </sql>
  88. <select id="selectQpTaskList" parameterType="com.zd.airbottle.domain.vo.QpTaskVO" resultMap="QpTaskResult">
  89. <include refid="selectQpTaskListVo"/>
  90. <where>
  91. <if test="searchValue != null and searchValue != ''">
  92. and ( t.user_name like concat('%', #{searchValue}, '%')
  93. or t.phone like concat('%', #{searchValue}, '%')
  94. or t.location like concat('%', #{searchValue}, '%') )
  95. </if>
  96. <if test="location != null and location != ''">and t.location like concat('%', #{location}, '%')</if>
  97. <if test="locationId != null ">and t.location_id = #{locationId}</if>
  98. <if test="userId != null ">and t.user_id = #{userId}</if>
  99. <if test="userName != null and userName != ''">and t.user_name like concat('%', #{userName}, '%')</if>
  100. <if test="phone != null and phone != ''">and t.phone = #{phone}</if>
  101. <if test="deptId != null ">and t.dept_id = #{deptId}</if>
  102. <if test="deptName != null and deptName != ''">and t.dept_name like concat('%', #{deptName}, '%')</if>
  103. <if test="type != null ">and t.type = #{type}</if>
  104. <if test="createTime != null">and
  105. DATE_FORMAT(t.create_time,'%Y-%m-%d')=DATE_FORMAT(#{createTime},'%Y-%m-%d')
  106. </if>
  107. <if test="startTime != null and startTime != ''"><!-- 开始时间检索 -->
  108. AND DATE_FORMAT(t.create_time,'%Y-%m-%d') &gt;= date_format(#{startTime},'%Y-%m-%d')
  109. </if>
  110. <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
  111. AND DATE_FORMAT(t.create_time,'%Y-%m-%d') &lt;= date_format(#{endTime},'%Y-%m-%d')
  112. </if>
  113. <if test="ids !=null">
  114. AND t.id in
  115. <foreach item="id" collection="ids" open="(" separator="," close=")">
  116. #{id}
  117. </foreach>
  118. </if>
  119. <!-- 数据范围过滤 -->
  120. ${params.dataScope}
  121. </where>
  122. order by create_time desc
  123. </select>
  124. <select id="selectQpTaskById" resultMap="QpTaskResult">
  125. <include refid="selectQpTaskListVo"/>
  126. where id = #{id}
  127. </select>
  128. <insert id="insertQpTask" parameterType="com.zd.airbottle.domain.QpTask" useGeneratedKeys="true" keyProperty="id">
  129. insert into qp_task
  130. <trim prefix="(" suffix=")" suffixOverrides=",">
  131. <if test="location != null">location,</if>
  132. <if test="locationId != null">location_id,</if>
  133. <if test="userId != null">user_id,</if>
  134. <if test="userName != null">user_name,</if>
  135. <if test="phone != null">phone,</if>
  136. <if test="deptId != null">dept_id,</if>
  137. <if test="deptName != null">dept_name,</if>
  138. <if test="type != null">type,</if>
  139. <if test="createTime != null">create_time,</if>
  140. </trim>
  141. <trim prefix="values (" suffix=")" suffixOverrides=",">
  142. <if test="location != null">#{location},</if>
  143. <if test="locationId != null">#{locationId},</if>
  144. <if test="userId != null">#{userId},</if>
  145. <if test="userName != null">#{userName},</if>
  146. <if test="phone != null">#{phone},</if>
  147. <if test="deptId != null">#{deptId},</if>
  148. <if test="deptName != null">#{deptName},</if>
  149. <if test="type != null">#{type},</if>
  150. <if test="createTime != null">#{createTime},</if>
  151. </trim>
  152. </insert>
  153. <update id="updateQpTask" parameterType="com.zd.airbottle.domain.QpTask">
  154. update qp_task
  155. <trim prefix="SET" suffixOverrides=",">
  156. <if test="location != null">location = #{location},</if>
  157. <if test="locationId != null">location_id = #{locationId},</if>
  158. <if test="userId != null">user_id = #{userId},</if>
  159. <if test="userName != null">user_name = #{userName},</if>
  160. <if test="phone != null">phone = #{phone},</if>
  161. <if test="deptId != null">dept_id = #{deptId},</if>
  162. <if test="deptName != null">dept_name = #{deptName},</if>
  163. <if test="type != null">type = #{type},</if>
  164. <if test="createTime != null">create_time = #{createTime},</if>
  165. </trim>
  166. where id = #{id}
  167. </update>
  168. <delete id="deleteQpTaskById">
  169. delete
  170. from qp_task
  171. where id = #{id}
  172. </delete>
  173. <delete id="deleteQpTaskByIds">
  174. delete from qp_task where id in
  175. <foreach item="id" collection="array" open="(" separator="," close=")">
  176. #{id}
  177. </foreach>
  178. </delete>
  179. <!-- 小程序待办事项时间分组 -->
  180. <select id="selectQpTaskListOrderByDate" parameterType="com.zd.airbottle.domain.vo.QpTaskVO"
  181. resultMap="QpTaskResult">
  182. select create_time createTimeApp, create_time as strTime
  183. from (select date_format(ta.create_time, '%Y-%m-%d') create_time
  184. from qp_task ta,
  185. qp_task_detail td
  186. where ta.id = td.task_id
  187. and td.is_dispose = 0
  188. and td.dispose_userid is null
  189. and td.supplier_id = #{companyId}
  190. GROUP BY date_format(ta.create_time, '%Y-%m-%d')
  191. UNION ALL
  192. select date_format(bs.create_time, '%Y-%m-%d') create_time
  193. from qp_bottle_storage bs,
  194. qp_task_detail td
  195. where bs.air_status = 1
  196. and bs.rejection_userid is null
  197. and bs.task_detail_id = td.id
  198. and td.supplier_id = #{companyId}
  199. GROUP BY date_format(bs.create_time, '%Y-%m-%d')
  200. UNION ALL
  201. select date_format(bso.create_time, '%Y-%m-%d') create_time
  202. from qp_bottle_storage_out bso,
  203. qp_bottle_storage bs,
  204. qp_task_detail td
  205. where bso.storage_id = bs.id
  206. and bs.task_detail_id = td.id
  207. and bso.out_status = 0
  208. and td.supplier_id = #{companyId}
  209. GROUP BY date_format(bso.create_time, '%Y-%m-%d')) t
  210. GROUP BY t.create_time
  211. order by t.create_time desc
  212. </select>
  213. <!-- 小程序供气回收记录时间分组 -->
  214. <select id="selectQpTaskListOrderByDateReclaim" parameterType="com.zd.airbottle.domain.vo.QpTaskVO"
  215. resultMap="QpTaskResult">
  216. select create_time createTimeApp,
  217. create_time
  218. from (
  219. select date_format(ta.create_time,'%Y-%m-%d') create_time from qp_task ta,qp_task_detail td
  220. where ta.id=td.task_id
  221. <if test="companyId !=null ">and td.supplier_id=#{companyId}</if>
  222. <if test="remarkStatus==0 ">and td.is_dispose=0</if> <!-- 未处理-->
  223. <if test="remarkStatus==1 ">and td.is_dispose=1</if> <!-- 已处理-->
  224. GROUP BY date_format(ta.create_time,'%Y-%m-%d')
  225. UNION ALL
  226. select date_format(bs.create_time,'%Y-%m-%d') create_time from qp_bottle_storage bs,qp_task_detail td
  227. where bs.task_detail_id=td.id
  228. <if test="companyId !=null ">and td.supplier_id=#{companyId}</if>
  229. <if test="remarkStatus==0 ">and bs.air_status=1 and rejection_userid is null</if> <!-- 未处理-->
  230. <if test="remarkStatus==1 ">and bs.air_status=1 and rejection_userid is not null</if> <!-- 已处理-->
  231. GROUP BY date_format(bs.create_time,'%Y-%m-%d')
  232. UNION ALL
  233. select date_format(bso.create_time,'%Y-%m-%d') create_time from qp_bottle_storage_out bso,qp_bottle_storage
  234. bs,qp_task_detail td
  235. where bso.storage_id=bs.id and bs.task_detail_id=td.id and bso.out_status = 0
  236. <if test="companyId !=null ">and td.supplier_id=#{companyId}</if>
  237. <if test="remarkStatus==0 ">and bso.out_status=0</if> <!-- 未处理-->
  238. <if test="remarkStatus==1 ">and (bso.out_status=2 or bso.out_status=1)</if> <!-- 已处理-->
  239. GROUP BY date_format(bso.create_time,'%Y-%m-%d')
  240. ) t GROUP BY t.create_time order by t.create_time desc
  241. </select>
  242. <select id="getApplyList" resultType="com.zd.airbottle.domain.QpTask">
  243. <include refid="selectQpTaskVo"/>
  244. <where>
  245. type=1
  246. <if test="applyName != null and applyName != ''">
  247. and ( location like concat('%', #{applyName}, '%')
  248. or user_name like concat('%', #{applyName}, '%')
  249. or phone like concat('%', #{applyName}, '%')
  250. )
  251. </if>
  252. <if test="applyTime != null">and DATE_FORMAT(create_time,'%Y-%m-%d')=DATE_FORMAT(#{applyTime},'%Y-%m-%d')
  253. </if>
  254. </where>
  255. order by create_time desc
  256. </select>
  257. <!-- 实验室信息关联查询 -->
  258. <select id="selectQpTaskBySubjectRelation" parameterType="com.zd.airbottle.domain.vo.QpTaskVO"
  259. resultMap="QpTaskResult">
  260. select
  261. ta.id,ta.create_time,
  262. (select f.name
  263. from lab_build_floor f
  264. where f.type = 1
  265. and f.id = (
  266. select f.parent_id
  267. from lab_build_floor f
  268. where f.id =
  269. (select bfl.build_id
  270. from lab_build_floor_layout bfl
  271. where bfl.sub_id = ta.location_id)))
  272. campus,
  273. (select f.`name`
  274. from lab_build_floor f
  275. where f.type = 2
  276. and f.id =
  277. (select bfl.build_id
  278. from lab_build_floor_layout bfl
  279. where bfl.sub_id = ta.location_id))
  280. building,
  281. (select bfl.room_num
  282. from lab_build_floor_layout bfl
  283. where bfl.sub_id = ta.location_id)
  284. room
  285. from qp_task ta where 1=1
  286. <if test="id != null">and ta.id = #{id}</if>
  287. <if test="createTime != null">and date_format(ta.create_time,'%Y-%m-%d') = date_format(
  288. #{createTime},'%Y-%m-%d')
  289. </if>
  290. <if test="companyId != null">and (ta.id in (select td.task_id from qp_task_detail td where
  291. td.supplier_id=#{companyId}))
  292. </if>
  293. <if test="isDispose != null">and (ta.id in (select td.task_id from qp_task_detail td where
  294. td.is_dispose=#{isDispose}
  295. <if test="companyId != null">
  296. and td.supplier_id=#{companyId}) )
  297. </if>
  298. </if>
  299. </select>
  300. <!-- 气瓶使用记录 按照实验室分组 -->
  301. <select id="selectUseRecord" parameterType="com.zd.airbottle.domain.vo.QpTaskVO" resultMap="QpTaskResult">
  302. select
  303. ta.location,ta.location_id,
  304. (select l.room room from lab_subject s,lab_subject_layout l where s.layout_id =l.id and s.id=ta.location_id)
  305. room
  306. from qp_bottle_storage bs
  307. left JOIN qp_task ta on ta.id = bs.task_id
  308. left join qp_task_detail td on td.task_id=ta.id
  309. left JOIN qp_use_record ur on ur.storage_id=bs.id
  310. where bs.air_status=0 and (bs.storage_status=1 or bs.storage_status=2 )
  311. <if test="companyId != null">td.supplier_id=#{companyId}</if>
  312. <if test="userId != null">and ta.user_id=#{userId}</if>
  313. GROUP BY ta.location,ta.location_id
  314. </select>
  315. <!-- 查询实验室下的气瓶使用信息 -->
  316. <select id="selectUseRecordBySubjectId" parameterType="com.zd.airbottle.domain.vo.QpTaskVO"
  317. resultMap="QpAirGoodsConfigRelationVo">
  318. select
  319. bs.id,qtd.task_id,qtd.bottle_number,qab.air_name,bs.id bottle_storage_id,
  320. qps.company_name,qab.air_constituents,agc.name specValue,ta.location,
  321. bs.current_pressure pressure,agc.name configName,
  322. (select u.back_time from qp_use_record u where id=(select max(id) from qp_use_record where storage_id=bs.id ) )
  323. back_time,
  324. (select u.use_time from qp_use_record u where id=(select max(id) from qp_use_record where storage_id=bs.id ) )
  325. use_time
  326. from qp_bottle_storage bs
  327. INNER JOIN qp_task ta on ta.id = bs.task_id
  328. inner join qp_task_detail qtd on qtd.task_id =ta.id and qtd.id=bs.task_detail_id
  329. inner join qp_air_bottle_config abc on abc.id=qtd.air_bottle_config_id
  330. INNER JOIN qp_air_bottle qab on qab.id=abc.bottle_id
  331. INNER JOIN qp_supplier qps on qps.id = qab.supplier_id
  332. inner join qp_air_goods_config agc on agc.id=abc.config_id
  333. where bs.air_status=0 and (bs.storage_status=1 or bs.storage_status=2) /**已入库 、闲置、使用中***/
  334. <if test="locationId != null">and ta.location_id = #{locationId}</if>
  335. <if test="userId != null">and ta.user_id = #{userId}</if>
  336. order by bs.create_time desc
  337. </select>
  338. <!--获取当前登录用户的申请记录 -->
  339. <select id="selectQpTaskListCount" parameterType="com.zd.airbottle.domain.vo.QpTaskVO" resultMap="QpTaskResult">
  340. <include refid="selectQpTaskListVo"/>
  341. <where>
  342. <if test="userId != null ">and t.user_id = #{userId}</if>
  343. </where>
  344. order by create_time desc
  345. </select>
  346. <!-- 查询某个实验室配置的气瓶数量信息-->
  347. <select id="selectSubjectDetail" resultType="java.util.Map">
  348. select id, subject_id subjectId, bottle_total bottleTotal, bottle_user_total bottleUserTotal
  349. from lab_qp_subject_relation
  350. where subject_id = #{subjectId}
  351. </select>
  352. <select id="getByIds" resultType="com.zd.airbottle.domain.QpTask">
  353. <include refid="selectQpTaskListVo"/>
  354. <where>
  355. <if test="list != null and list.size>0">
  356. id in
  357. <foreach item="id" collection="list" open="(" separator="," close=")">
  358. #{id}
  359. </foreach>
  360. </if>
  361. </where>
  362. </select>
  363. </mapper>