IsMaterialsLoanMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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.ktg.iscs.mapper.IsMaterialsLoanMapper">
  6. <resultMap type="IsMaterialsLoan" id="IsMaterialsLoanResult">
  7. <result property="materialsLoanId" column="materials_loan_id" />
  8. <result property="materialsId" column="materials_id" />
  9. <result property="loanUserId" column="loan_user_id" />
  10. <result property="loanFromId" column="loan_from_id" />
  11. <result property="loanTime" column="loan_time" />
  12. <result property="reminderTime" column="reminder_time" />
  13. <result property="restitutionUserId" column="restitution_user_id" />
  14. <result property="restitutionToId" column="restitution_to_id" />
  15. <result property="restitutionTime" column="restitution_time" />
  16. <result property="restitutionRequired" column="restitution_required" />
  17. <result property="remark" column="remark" />
  18. <result property="delFlag" column="del_flag" />
  19. <result property="createBy" column="create_by" />
  20. <result property="createTime" column="create_time" />
  21. <result property="updateTime" column="update_time" />
  22. <result property="updateBy" column="update_by" />
  23. <result property="actualRestitutionTime" column="actual_restitution_time" />
  24. <result property="timeoutAlarm" column="timeout_alarm" />
  25. </resultMap>
  26. <sql id="selectIsMaterialsLoanVo">
  27. select materials_loan_id, materials_id, loan_user_id, loan_from_id, loan_time, reminder_time, restitution_user_id,
  28. restitution_to_id, restitution_time, remark, del_flag, create_by, create_time, update_time, update_by,
  29. actual_restitution_time, timeout_alarm
  30. from is_materials_loan
  31. </sql>
  32. <select id="selectIsMaterialsLoanList" parameterType="IsMaterialsLoan" resultMap="IsMaterialsLoanResult">
  33. <include refid="selectIsMaterialsLoanVo"/>
  34. <where>
  35. <if test="materialsId != null "> and materials_id = #{materialsId}</if>
  36. <if test="loanUserId != null "> and loan_user_id = #{loanUserId}</if>
  37. <if test="loanFromId != null "> and loan_from_id = #{loanFromId}</if>
  38. <if test="loanTime != null "> and loan_time = #{loanTime}</if>
  39. <if test="reminderTime != null "> and reminder_time = #{reminderTime}</if>
  40. <if test="restitutionUserId != null "> and restitution_user_id = #{restitutionUserId}</if>
  41. <if test="restitutionToId != null "> and restitution_to_id = #{restitutionToId}</if>
  42. <if test="restitutionTime != null "> and restitution_time = #{restitutionTime}</if>
  43. </where>
  44. </select>
  45. <select id="selectIsMaterialsLoanByMaterialsLoanId" parameterType="Long" resultMap="IsMaterialsLoanResult">
  46. <include refid="selectIsMaterialsLoanVo"/>
  47. where materials_loan_id = #{materialsLoanId}
  48. </select>
  49. <insert id="insertIsMaterialsLoan" parameterType="IsMaterialsLoan" useGeneratedKeys="true" keyProperty="materialsLoanId">
  50. insert into is_materials_loan
  51. <trim prefix="(" suffix=")" suffixOverrides=",">
  52. <if test="materialsId != null">materials_id,</if>
  53. <if test="loanUserId != null">loan_user_id,</if>
  54. <if test="loanFromId != null">loan_from_id,</if>
  55. <if test="loanTime != null">loan_time,</if>
  56. <if test="reminderTime != null">reminder_time,</if>
  57. <if test="restitutionUserId != null">restitution_user_id,</if>
  58. <if test="restitutionToId != null">restitution_to_id,</if>
  59. <if test="restitutionTime != null">restitution_time,</if>
  60. <if test="restitutionRequired != null">restitution_required,</if>
  61. <if test="remark != null">remark,</if>
  62. <if test="delFlag != null">del_flag,</if>
  63. <if test="createBy != null">create_by,</if>
  64. <if test="createTime != null">create_time,</if>
  65. <if test="updateTime != null">update_time,</if>
  66. <if test="updateBy != null">update_by,</if>
  67. <if test="actualRestitutionTime != null">actual_restitution_time,</if>
  68. <if test="timeoutAlarm != null">timeout_alarm,</if>
  69. </trim>
  70. <trim prefix="values (" suffix=")" suffixOverrides=",">
  71. <if test="materialsId != null">#{materialsId},</if>
  72. <if test="loanUserId != null">#{loanUserId},</if>
  73. <if test="loanFromId != null">#{loanFromId},</if>
  74. <if test="loanTime != null">#{loanTime},</if>
  75. <if test="reminderTime != null">#{reminderTime},</if>
  76. <if test="restitutionUserId != null">#{restitutionUserId},</if>
  77. <if test="restitutionToId != null">#{restitutionToId},</if>
  78. <if test="restitutionTime != null">#{restitutionTime},</if>
  79. <if test="restitutionRequired != null">#{restitutionRequired},</if>
  80. <if test="remark != null">#{remark},</if>
  81. <if test="delFlag != null">#{delFlag},</if>
  82. <if test="createBy != null">#{createBy},</if>
  83. <if test="createTime != null">#{createTime},</if>
  84. <if test="updateTime != null">#{updateTime},</if>
  85. <if test="updateBy != null">#{updateBy},</if>
  86. <if test="actualRestitutionTime != null">#{actualRestitutionTime},</if>
  87. <if test="timeoutAlarm != null">#{timeoutAlarm},</if>
  88. </trim>
  89. </insert>
  90. <update id="updateIsMaterialsLoan" parameterType="IsMaterialsLoan">
  91. update is_materials_loan
  92. <trim prefix="SET" suffixOverrides=",">
  93. <if test="materialsId != null">materials_id = #{materialsId},</if>
  94. <if test="loanUserId != null">loan_user_id = #{loanUserId},</if>
  95. <if test="loanFromId != null">loan_from_id = #{loanFromId},</if>
  96. <if test="loanTime != null">loan_time = #{loanTime},</if>
  97. <if test="reminderTime != null">reminder_time = #{reminderTime},</if>
  98. <if test="restitutionUserId != null">restitution_user_id = #{restitutionUserId},</if>
  99. <if test="restitutionToId != null">restitution_to_id = #{restitutionToId},</if>
  100. <if test="restitutionTime != null">restitution_time = #{restitutionTime},</if>
  101. <if test="restitutionRequired != null">restitution_required = #{restitutionRequired},</if>
  102. <if test="remark != null">remark = #{remark},</if>
  103. <if test="delFlag != null">del_flag = #{delFlag},</if>
  104. <if test="createBy != null">create_by = #{createBy},</if>
  105. <if test="createTime != null">create_time = #{createTime},</if>
  106. <if test="updateTime != null">update_time = #{updateTime},</if>
  107. <if test="updateBy != null">update_by = #{updateBy},</if>
  108. <if test="actualRestitutionTime != null">actual_restitution_time = #{actualRestitutionTime},</if>
  109. <if test="timeoutAlarm != null">timeout_alarm = #{timeoutAlarm},</if>
  110. </trim>
  111. where materials_loan_id = #{materialsLoanId}
  112. </update>
  113. <delete id="deleteIsMaterialsLoanByMaterialsLoanId" parameterType="Long">
  114. delete from is_materials_loan where materials_loan_id = #{materialsLoanId}
  115. </delete>
  116. <delete id="deleteIsMaterialsLoanByMaterialsLoanIds" parameterType="String">
  117. delete from is_materials_loan where materials_loan_id in
  118. <foreach item="materialsLoanId" collection="array" open="(" separator="," close=")">
  119. #{materialsLoanId}
  120. </foreach>
  121. </delete>
  122. <select id="getIsMaterialsLoanPage" resultType="com.ktg.iscs.domain.vo.materialsLoan.MaterialsLoanPageVO">
  123. SELECT
  124. l.*,
  125. m.materials_code,
  126. m.materials_name,
  127. c1.cabinet_name as loan_from_name,
  128. c2.cabinet_name as restitution_to_name,
  129. u.user_name as loan_user_name,
  130. u1.user_name as restitution_user_name,
  131. m.materials_type_id,
  132. mt.materials_type_name,
  133. mt.materials_type_icon,
  134. mt.materials_type_picture,
  135. CASE
  136. WHEN l.actual_restitution_time IS NOT NULL THEN
  137. CONCAT(
  138. FLOOR( DATEDIFF( SECOND, l.loan_time, l.actual_restitution_time ) / 3600 ),
  139. '小时 ',
  140. FLOOR( DATEDIFF( SECOND, l.loan_time, l.actual_restitution_time ) / 60 ) % 60,
  141. '分 ',
  142. DATEDIFF( SECOND, l.loan_time, l.actual_restitution_time ) % 60,
  143. '秒'
  144. ) ELSE null
  145. END AS loan_duration
  146. FROM
  147. is_materials_loan l
  148. LEFT JOIN is_materials m ON m.materials_id = l.materials_id
  149. LEFT JOIN is_materials_cabinet c1 ON c1.cabinet_id = l.loan_from_id
  150. LEFT JOIN is_materials_cabinet c2 ON c2.cabinet_id = l.restitution_to_id
  151. LEFT JOIN sys_user u ON u.user_id = l.loan_user_id
  152. LEFT JOIN sys_user u1 ON u1.user_id = l.restitution_user_id
  153. LEFT JOIN is_materials_type mt ON mt.materials_type_id = m.materials_type_id
  154. <where>
  155. <if test="dto.materialsName != null and dto.materialsName.trim != ''">
  156. and m.materials_name like concat('%',#{dto.materialsName},'%')
  157. </if>
  158. <if test="dto.restitutionRequired != null">
  159. and l.restitution_required = #{dto.restitutionRequired}
  160. </if>
  161. <if test="dto.loanFromId != null">
  162. and l.loan_from_id = #{dto.loanFromId}
  163. </if>
  164. <if test="dto.restitutionToId != null">
  165. and l.restitution_to_id = #{dto.restitutionToId}
  166. </if>
  167. <if test="dto.materialsTypeId != null">
  168. and m.materials_type_id = #{dto.materialsTypeId}
  169. </if>
  170. <if test="dto.loanUserName != null and dto.loanUserName.trim != ''">
  171. and u.user_name like concat('%',#{dto.loanUserName},'%')
  172. </if>
  173. <if test="dto.loanTimeStart != null and dto.loanTimeStart.trim != ''">
  174. and l.loan_time &gt;= #{dto.loanTimeStart}
  175. </if>
  176. <if test="dto.loanTimeEnd != null and dto.loanTimeEnd.trim != ''">
  177. and l.loan_time &lt;= #{dto.loanTimeEnd}
  178. </if>
  179. <if test="dto.restitutionUserName != null and dto.restitutionUserName.trim != ''">
  180. and u1.user_name like concat('%',#{dto.restitutionUserName},'%')
  181. </if>
  182. <if test="dto.restitutionTimeStart != null and dto.restitutionTimeStart.trim != ''">
  183. and l.actual_restitution_time &gt;= #{dto.restitutionTimeStart}
  184. </if>
  185. <if test="dto.restitutionTimeEnd != null and dto.restitutionTimeEnd.trim != ''">
  186. and l.actual_restitution_time &lt;= #{dto.restitutionTimeEnd}
  187. </if>
  188. <if test="dto.status != null and dto.status.trim != ''">
  189. and l.status = #{dto.status}
  190. </if>
  191. </where>
  192. ORDER BY l.materials_loan_id DESC
  193. </select>
  194. <select id="getReturnReminderPage" resultType="com.ktg.iscs.domain.vo.materialsLoan.ReminderPageVO">
  195. SELECT
  196. l.*,
  197. m.materials_code,
  198. m.materials_name,
  199. c1.cabinet_name as loan_from_name,
  200. c2.cabinet_name as restitution_to_name,
  201. u.user_name as loan_user_name
  202. FROM
  203. is_materials_loan l
  204. LEFT JOIN is_materials m ON m.materials_id = l.materials_id
  205. LEFT JOIN is_materials_cabinet c1 ON c1.cabinet_id = l.loan_from_id
  206. LEFT JOIN is_materials_cabinet c2 ON c2.cabinet_id = l.restitution_to_id
  207. LEFT JOIN sys_user u ON u.user_id = l.loan_user_id
  208. <where>
  209. l.reminder_time &lt; NOW()
  210. and NOW() &lt; l.timeout_alarm
  211. and actual_restitution_time is null
  212. <if test="dto.materialsCode != null and dto.materialsCode.trim != ''">
  213. and m.materials_code like concat('%',#{dto.materialsCode},'%')
  214. </if>
  215. <if test="dto.materialsName != null and dto.materialsName.trim != ''">
  216. and m.materials_name like concat('%',#{dto.materialsName},'%')
  217. </if>
  218. <if test="dto.loanUserName != null and dto.loanUserName.trim != ''">
  219. and u.user_name like concat('%',#{dto.loanUserName},'%')
  220. </if>
  221. <if test="dto.loanFromId != null">
  222. and l.loan_from_id = #{dto.loanFromId}
  223. </if>
  224. <if test="dto.loanFromName != null and dto.loanFromName.trim != ''">
  225. and c1.cabinet_name like concat('%',#{dto.loanFromName},'%')
  226. </if>
  227. <if test="dto.startTime != null and dto.startTime.trim != ''">
  228. and l.loan_time &gt;= #{dto.startTime}
  229. </if>
  230. <if test="dto.endTime != null and dto.endTime.trim != ''">
  231. and l.loan_time &lt;= #{dto.endTime}
  232. </if>
  233. </where>
  234. ORDER BY l.materials_loan_id DESC
  235. </select>
  236. <select id="getExpiredReminderPage" resultType="com.ktg.iscs.domain.vo.materialsLoan.ReminderPageVO">
  237. SELECT
  238. l.*,
  239. m.materials_code,
  240. m.materials_name,
  241. c1.cabinet_name as loan_from_name,
  242. c2.cabinet_name as restitution_to_name,
  243. u.user_name as loan_user_name
  244. FROM
  245. is_materials_loan l
  246. LEFT JOIN is_materials m ON m.materials_id = l.materials_id
  247. LEFT JOIN is_materials_cabinet c1 ON c1.cabinet_id = l.loan_from_id
  248. LEFT JOIN is_materials_cabinet c2 ON c2.cabinet_id = l.restitution_to_id
  249. LEFT JOIN sys_user u ON u.user_id = l.loan_user_id
  250. <where>
  251. l.timeout_alarm &lt; NOW()
  252. and actual_restitution_time is null
  253. <if test="dto.materialsCode != null and dto.materialsCode.trim != ''">
  254. and m.materials_code like concat('%',#{dto.materialsCode},'%')
  255. </if>
  256. <if test="dto.materialsName != null and dto.materialsName.trim != ''">
  257. and m.materials_name like concat('%',#{dto.materialsName},'%')
  258. </if>
  259. <if test="dto.loanUserName != null and dto.loanUserName.trim != ''">
  260. and u.user_name like concat('%',#{dto.loanUserName},'%')
  261. </if>
  262. <if test="dto.loanFromId != null">
  263. and l.loan_from_id = #{dto.loanFromId}
  264. </if>
  265. <if test="dto.loanFromName != null and dto.loanFromName.trim != ''">
  266. and c1.cabinet_name like concat('%',#{dto.loanFromName},'%')
  267. </if>
  268. <if test="dto.startTime != null and dto.startTime.trim != ''">
  269. and l.timeout_alarm &gt;= #{dto.startTime}
  270. </if>
  271. <if test="dto.endTime != null and dto.endTime.trim != ''">
  272. and l.timeout_alarm &lt;= #{dto.endTime}
  273. </if>
  274. </where>
  275. ORDER BY l.materials_loan_id DESC
  276. </select>
  277. <select id="getLastLoanRecord" resultType="java.lang.Long">
  278. SELECT
  279. max(materials_loan_id)
  280. FROM
  281. is_materials_loan ml
  282. WHERE
  283. ml.materials_id IN
  284. <foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
  285. #{item}
  286. </foreach>
  287. AND ml.status != 1
  288. GROUP BY ml.materials_id
  289. </select>
  290. </mapper>