IsJobTicketMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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.IsJobTicketMapper">
  6. <!--<cache/>-->
  7. <resultMap type="IsJobTicket" id="IsJobTicketResult">
  8. <result property="ticketId" column="ticket_id" />
  9. <result property="ticketCode" column="ticket_code" />
  10. <result property="ticketName" column="ticket_name" />
  11. <result property="workshopId" column="workshop_id" />
  12. <result property="workareaId" column="workarea_id" />
  13. <result property="sopId" column="sop_id" />
  14. <result property="ticketType" column="ticket_type" />
  15. <result property="ticketContent" column="ticket_content" />
  16. <result property="ticketStatus" column="ticket_status" />
  17. <result property="ticketStartTime" column="ticket_start_time" />
  18. <result property="ticketEndTime" column="ticket_end_time" />
  19. <result property="delFlag" column="del_flag" />
  20. <result property="createBy" column="create_by" />
  21. <result property="createTime" column="create_time" />
  22. <result property="updateTime" column="update_time" />
  23. <result property="updateBy" column="update_by" />
  24. <result property="workstationId" column="workstation_id" />
  25. <result property="machineryId" column="machinery_id" />
  26. </resultMap>
  27. <sql id="selectIsJobTicketVo">
  28. select * from is_job_ticket
  29. </sql>
  30. <select id="selectIsJobTicketList" parameterType="IsJobTicket" resultMap="IsJobTicketResult">
  31. <include refid="selectIsJobTicketVo"/>
  32. <where>
  33. <if test="ticketCode != null and ticketCode != ''"> and ticket_code = #{ticketCode}</if>
  34. <if test="ticketName != null and ticketName != ''"> and ticket_name like concat('%', #{ticketName}, '%')</if>
  35. <if test="workshopId != null "> and workshop_id = #{workshopId}</if>
  36. <if test="workareaId != null "> and workarea_id = #{workareaId}</if>
  37. <if test="sopId != null "> and sop_id = #{sopId}</if>
  38. <if test="ticketType != null and ticketType != ''"> and ticket_type = #{ticketType}</if>
  39. <if test="ticketContent != null and ticketContent != ''"> and ticket_content = #{ticketContent}</if>
  40. <if test="ticketStatus != null and ticketStatus != ''"> and ticket_status = #{ticketStatus}</if>
  41. <if test="ticketStartTime != null "> and ticket_start_time = #{ticketStartTime}</if>
  42. <if test="ticketEndTime != null "> and ticket_end_time = #{ticketEndTime}</if>
  43. </where>
  44. </select>
  45. <select id="selectIsJobTicketByTicketId" parameterType="Long" resultMap="IsJobTicketResult">
  46. <!--<include refid="selectIsJobTicketVo"/>-->
  47. SELECT
  48. t.*,
  49. ws.workshop_name,
  50. wa.workarea_name,
  51. s.sop_name
  52. FROM
  53. is_job_ticket t
  54. LEFT JOIN md_workshop ws ON ws.workshop_id = t.workshop_id
  55. LEFT JOIN is_workarea wa ON wa.workarea_id = t.workarea_id
  56. LEFT JOIN is_sop s ON s.sop_id = t.sop_id
  57. WHERE ticket_id = #{ticketId}
  58. </select>
  59. <insert id="insertIsJobTicket" parameterType="IsJobTicket" useGeneratedKeys="true" keyProperty="ticketId">
  60. insert into is_job_ticket
  61. <trim prefix="(" suffix=")" suffixOverrides=",">
  62. <if test="ticketCode != null and ticketCode != ''">ticket_code,</if>
  63. <if test="ticketName != null and ticketName != ''">ticket_name,</if>
  64. <if test="workshopId != null">workshop_id,</if>
  65. <if test="workareaId != null">workarea_id,</if>
  66. <if test="sopId != null">sop_id,</if>
  67. <if test="ticketType != null">ticket_type,</if>
  68. <if test="ticketContent != null">ticket_content,</if>
  69. <if test="ticketStatus != null">ticket_status,</if>
  70. <if test="ticketStartTime != null">ticket_start_time,</if>
  71. <if test="ticketEndTime != null">ticket_end_time,</if>
  72. <if test="delFlag != null">del_flag,</if>
  73. <if test="createBy != null">create_by,</if>
  74. <if test="createTime != null">create_time,</if>
  75. <if test="updateTime != null">update_time,</if>
  76. <if test="updateBy != null">update_by,</if>
  77. <if test="workstationId != null">workstation_id,</if>
  78. <if test="machineryId != null">machinery_id,</if>
  79. </trim>
  80. <trim prefix="values (" suffix=")" suffixOverrides=",">
  81. <if test="ticketCode != null and ticketCode != ''">#{ticketCode},</if>
  82. <if test="ticketName != null and ticketName != ''">#{ticketName},</if>
  83. <if test="workshopId != null">#{workshopId},</if>
  84. <if test="workareaId != null">#{workareaId},</if>
  85. <if test="sopId != null">#{sopId},</if>
  86. <if test="ticketType != null">#{ticketType},</if>
  87. <if test="ticketContent != null">#{ticketContent},</if>
  88. <if test="ticketStatus != null">#{ticketStatus},</if>
  89. <if test="ticketStartTime != null">#{ticketStartTime},</if>
  90. <if test="ticketEndTime != null">#{ticketEndTime},</if>
  91. <if test="delFlag != null">#{delFlag},</if>
  92. <if test="createBy != null">#{createBy},</if>
  93. <if test="createTime != null">#{createTime},</if>
  94. <if test="updateTime != null">#{updateTime},</if>
  95. <if test="updateBy != null">#{updateBy},</if>
  96. <if test="workstationId != null">#{workstationId},</if>
  97. <if test="machineryId != null">#{machineryId},</if>
  98. </trim>
  99. </insert>
  100. <update id="updateIsJobTicket" parameterType="IsJobTicket">
  101. update is_job_ticket
  102. <trim prefix="SET" suffixOverrides=",">
  103. <if test="ticketCode != null and ticketCode != ''">ticket_code = #{ticketCode},</if>
  104. <if test="ticketName != null and ticketName != ''">ticket_name = #{ticketName},</if>
  105. <if test="workshopId != null">workshop_id = #{workshopId},</if>
  106. <if test="workareaId != null">workarea_id = #{workareaId},</if>
  107. <if test="sopId != null">sop_id = #{sopId},</if>
  108. <if test="ticketType != null">ticket_type = #{ticketType},</if>
  109. <if test="ticketContent != null">ticket_content = #{ticketContent},</if>
  110. <if test="ticketStatus != null">ticket_status = #{ticketStatus},</if>
  111. <if test="ticketStartTime != null">ticket_start_time = #{ticketStartTime},</if>
  112. <if test="ticketEndTime != null">ticket_end_time = #{ticketEndTime},</if>
  113. <if test="delFlag != null">del_flag = #{delFlag},</if>
  114. <if test="createBy != null">create_by = #{createBy},</if>
  115. <if test="createTime != null">create_time = #{createTime},</if>
  116. <if test="updateTime != null">update_time = #{updateTime},</if>
  117. <if test="updateBy != null">update_by = #{updateBy},</if>
  118. <if test="workstationId != null">workstation_id = #{workstationId},</if>
  119. <if test="machineryId != null">machinery_id = #{machineryId},</if>
  120. </trim>
  121. where ticket_id = #{ticketId}
  122. </update>
  123. <delete id="deleteIsJobTicketByTicketId" parameterType="Long">
  124. delete from is_job_ticket where ticket_id = #{ticketId}
  125. </delete>
  126. <delete id="deleteIsJobTicketByTicketIds" parameterType="String">
  127. delete from is_job_ticket where ticket_id in
  128. <foreach item="ticketId" collection="array" open="(" separator="," close=")">
  129. #{ticketId}
  130. </foreach>
  131. </delete>
  132. <!-- 如果LEFT JOIN is_job_ticket_user需要正确的pointCount,需要改写成子查询,现在用不到正确的pointCount,效率优先 -->
  133. <select id="getIsJobTicketPage" resultType="com.ktg.iscs.domain.vo.ticket.PageTicketVO">
  134. select t.* from (
  135. SELECT
  136. j.ticket_id,
  137. j.ticket_code,
  138. j.ticket_name,
  139. j.workshop_id,
  140. j.workarea_id,
  141. j.sop_id,
  142. j.ticket_type,
  143. j.ticket_content,
  144. j.ticket_status,
  145. j.ticket_start_time,
  146. j.ticket_end_time,
  147. j.del_flag,
  148. j.create_by,
  149. j.create_time,
  150. j.update_time,
  151. j.update_by,
  152. j.workstation_id,
  153. j.machinery_id,
  154. max(ws.workstation_name) as workstation_name,
  155. max(m.machinery_name) as machinery_name,
  156. COUNT( p.record_id ) AS pointCount
  157. FROM
  158. is_job_ticket j
  159. LEFT JOIN is_workstation ws ON ws.workstation_id = j.workstation_id
  160. LEFT JOIN is_machinery m ON m.machinery_id = j.machinery_id
  161. LEFT JOIN is_job_ticket_points p ON p.ticket_id = j.ticket_id
  162. <if test="dto.userId != null and dto.userId.trim != ''">
  163. LEFT JOIN is_job_ticket_user u ON u.ticket_id = j.ticket_id
  164. </if>
  165. <where>
  166. <if test="dto.ticketCode != null and dto.ticketCode.trim != ''">
  167. and j.ticket_code like concat('%',#{dto.ticketCode},'%')
  168. </if>
  169. <if test="dto.ticketName != null and dto.ticketName.trim != ''">
  170. and j.ticket_name like concat('%',#{dto.ticketName},'%')
  171. </if>
  172. <if test="dto.ticketStatus != null and dto.ticketStatus.trim != ''">
  173. and j.ticket_status = #{dto.ticketStatus}
  174. </if>
  175. <if test="dto.workstationId != null">
  176. and j.workstation_id = #{dto.workstationId}
  177. </if>
  178. <if test="dto.machineryId != null">
  179. and j.machinery_id = #{dto.machineryId}
  180. </if>
  181. <if test="dto.ticketType != null and dto.ticketType.trim != ''">
  182. and j.ticket_type = #{dto.ticketType}
  183. </if>
  184. <if test="dto.startTime != null and dto.startTime.trim != ''">
  185. and j.create_time &gt;= #{dto.startTime}
  186. </if>
  187. <if test="dto.endTime != null and dto.endTime.trim != ''">
  188. and j.create_time &lt;= #{dto.endTime}
  189. </if>
  190. <if test="dto.userId != null and dto.userId.trim != ''">
  191. and u.user_id = #{dto.userId}
  192. </if>
  193. </where>
  194. GROUP BY j.ticket_id,
  195. j.ticket_code,
  196. j.ticket_name,
  197. j.workshop_id,
  198. j.workarea_id,
  199. j.sop_id,
  200. j.ticket_type,
  201. j.ticket_content,
  202. j.ticket_status,
  203. j.ticket_start_time,
  204. j.ticket_end_time,
  205. j.del_flag,
  206. j.create_by,
  207. j.create_time,
  208. j.update_time,
  209. j.update_by,
  210. j.workstation_id,
  211. j.machinery_id) t
  212. ORDER BY j.ticket_id DESC
  213. </select>
  214. <select id="getMonitorJobTicketPage" resultType="com.ktg.iscs.domain.vo.ticket.MonitorTicketPageVO">
  215. SELECT
  216. j.*, w.workstation_name, m.machinery_name
  217. FROM
  218. is_job_ticket j
  219. left join is_workstation w on w.workstation_id = j.workstation_id
  220. left join is_machinery m ON m.machinery_id = j.machinery_id
  221. <where>
  222. <!-- (j.ticket_status != 4 OR ( j.ticket_end_time > CURDATE() AND j.ticket_status = 4 )) -->
  223. (j.ticket_status &lt; 5 OR ( j.ticket_end_time > GETDATE() AND j.ticket_status = 5 ))
  224. <if test="dto.ticketCode != null and dto.ticketCode.trim != ''">
  225. and j.ticket_code like concat('%',#{dto.ticketCode},'%')
  226. </if>
  227. <if test="dto.ticketName != null and dto.ticketName.trim != ''">
  228. and j.ticket_name like concat('%',#{dto.ticketName},'%')
  229. </if>
  230. <if test="dto.ticketStatus != null and dto.ticketStatus.trim != ''">
  231. and j.ticket_status = #{dto.ticketStatus}
  232. </if>
  233. <if test="dto.workstationId != null">
  234. and j.workstation_id = #{dto.workstationId}
  235. </if>
  236. <if test="dto.machineryId != null">
  237. and j.machinery_id = #{dto.machineryId}
  238. </if>
  239. <if test="dto.ticketType != null and dto.ticketType.trim != ''">
  240. and j.ticket_type = #{dto.ticketType}
  241. </if>
  242. <if test="dto.startTime != null and dto.startTime.trim != ''">
  243. and j.create_time &gt;= #{dto.startTime}
  244. </if>
  245. <if test="dto.endTime != null and dto.endTime.trim != ''">
  246. and j.create_time &lt;= #{dto.endTime}
  247. </if>
  248. <if test="dto.ticketId != null">
  249. and j.ticket_id = #{dto.ticketId}
  250. </if>
  251. </where>
  252. order by j.ticket_id desc
  253. </select>
  254. <select id="getTicketListByAttrValue" resultType="com.ktg.iscs.domain.IsJobTicket">
  255. SELECT
  256. j.*
  257. FROM
  258. is_job_ticket j
  259. LEFT JOIN is_job_ticket_user u ON u.ticket_id = j.ticket_id and u.user_role = "jtlocker"
  260. where (j.create_by = #{userId} or u.user_id = #{userId}) and j.ticket_status &lt; 5
  261. </select>
  262. <select id="selectConflictTicket1" resultType="com.ktg.iscs.domain.vo.ticket.JobTicketDetailVO">
  263. SELECT
  264. j.*
  265. FROM
  266. `is_job_ticket` j
  267. LEFT JOIN is_job_ticket_points p ON p.ticket_id = j.ticket_id
  268. LEFT JOIN is_job_ticket_key k ON k.ticket_id = j.ticket_id
  269. WHERE
  270. j.ticket_status &lt; 5
  271. AND p.point_id IN
  272. <foreach collection="pointIds" index="index" item="item" open="(" separator="," close=")">
  273. #{item}
  274. </foreach>
  275. AND k.collect_time is not null
  276. and k.give_back_time is null
  277. and k.ticket_type = 0
  278. and j.ticket_id != #{ticketId}
  279. GROUP BY
  280. j.ticket_id
  281. </select>
  282. <select id="selectConflictTicket2" resultType="com.ktg.iscs.domain.vo.ticket.JobTicketDetailVO">
  283. SELECT
  284. j.*
  285. FROM
  286. `is_job_ticket` j
  287. LEFT JOIN is_job_ticket_points p ON p.ticket_id = j.ticket_id
  288. LEFT JOIN is_job_ticket_key k1 ON k1.ticket_id = j.ticket_id and k1.ticket_type = 0
  289. LEFT JOIN is_job_ticket_key k2 ON k2.ticket_id = j.ticket_id and k2.ticket_type = 1
  290. WHERE
  291. j.ticket_status &lt; 5
  292. AND p.point_id IN
  293. <foreach collection="pointIds" index="index" item="item" open="(" separator="," close=")">
  294. #{item}
  295. </foreach>
  296. AND k1.collect_time is not null
  297. and k1.give_back_time is not null
  298. AND k2.collect_time is null
  299. and k2.give_back_time is null
  300. and j.ticket_id != #{ticketId}
  301. and p.point_status = 1
  302. GROUP BY
  303. j.ticket_id
  304. </select>
  305. </mapper>