| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE mapper
- PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.ktg.iscs.mapper.IsJobTicketMapper">
- <!--<cache/>-->
- <resultMap type="IsJobTicket" id="IsJobTicketResult">
- <result property="ticketId" column="ticket_id" />
- <result property="ticketCode" column="ticket_code" />
- <result property="ticketName" column="ticket_name" />
- <result property="workshopId" column="workshop_id" />
- <result property="workareaId" column="workarea_id" />
- <result property="sopId" column="sop_id" />
- <result property="ticketType" column="ticket_type" />
- <result property="ticketContent" column="ticket_content" />
- <result property="ticketStatus" column="ticket_status" />
- <result property="ticketStartTime" column="ticket_start_time" />
- <result property="ticketEndTime" column="ticket_end_time" />
- <result property="delFlag" column="del_flag" />
- <result property="createBy" column="create_by" />
- <result property="createTime" column="create_time" />
- <result property="updateTime" column="update_time" />
- <result property="updateBy" column="update_by" />
- <result property="workstationId" column="workstation_id" />
- <result property="machineryId" column="machinery_id" />
- </resultMap>
- <sql id="selectIsJobTicketVo">
- select * from is_job_ticket
- </sql>
- <select id="selectIsJobTicketList" parameterType="IsJobTicket" resultMap="IsJobTicketResult">
- <include refid="selectIsJobTicketVo"/>
- <where>
- <if test="ticketCode != null and ticketCode != ''"> and ticket_code = #{ticketCode}</if>
- <if test="ticketName != null and ticketName != ''"> and ticket_name like concat('%', #{ticketName}, '%')</if>
- <if test="workshopId != null "> and workshop_id = #{workshopId}</if>
- <if test="workareaId != null "> and workarea_id = #{workareaId}</if>
- <if test="sopId != null "> and sop_id = #{sopId}</if>
- <if test="ticketType != null and ticketType != ''"> and ticket_type = #{ticketType}</if>
- <if test="ticketContent != null and ticketContent != ''"> and ticket_content = #{ticketContent}</if>
- <if test="ticketStatus != null and ticketStatus != ''"> and ticket_status = #{ticketStatus}</if>
- <if test="ticketStartTime != null "> and ticket_start_time = #{ticketStartTime}</if>
- <if test="ticketEndTime != null "> and ticket_end_time = #{ticketEndTime}</if>
- </where>
- </select>
- <select id="selectIsJobTicketByTicketId" parameterType="Long" resultMap="IsJobTicketResult">
- <!--<include refid="selectIsJobTicketVo"/>-->
- SELECT
- t.*,
- ws.workshop_name,
- wa.workarea_name,
- s.sop_name
- FROM
- is_job_ticket t
- LEFT JOIN md_workshop ws ON ws.workshop_id = t.workshop_id
- LEFT JOIN is_workarea wa ON wa.workarea_id = t.workarea_id
- LEFT JOIN is_sop s ON s.sop_id = t.sop_id
- WHERE ticket_id = #{ticketId}
- </select>
- <insert id="insertIsJobTicket" parameterType="IsJobTicket" useGeneratedKeys="true" keyProperty="ticketId">
- insert into is_job_ticket
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="ticketCode != null and ticketCode != ''">ticket_code,</if>
- <if test="ticketName != null and ticketName != ''">ticket_name,</if>
- <if test="workshopId != null">workshop_id,</if>
- <if test="workareaId != null">workarea_id,</if>
- <if test="sopId != null">sop_id,</if>
- <if test="ticketType != null">ticket_type,</if>
- <if test="ticketContent != null">ticket_content,</if>
- <if test="ticketStatus != null">ticket_status,</if>
- <if test="ticketStartTime != null">ticket_start_time,</if>
- <if test="ticketEndTime != null">ticket_end_time,</if>
- <if test="delFlag != null">del_flag,</if>
- <if test="createBy != null">create_by,</if>
- <if test="createTime != null">create_time,</if>
- <if test="updateTime != null">update_time,</if>
- <if test="updateBy != null">update_by,</if>
- <if test="workstationId != null">workstation_id,</if>
- <if test="machineryId != null">machinery_id,</if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="ticketCode != null and ticketCode != ''">#{ticketCode},</if>
- <if test="ticketName != null and ticketName != ''">#{ticketName},</if>
- <if test="workshopId != null">#{workshopId},</if>
- <if test="workareaId != null">#{workareaId},</if>
- <if test="sopId != null">#{sopId},</if>
- <if test="ticketType != null">#{ticketType},</if>
- <if test="ticketContent != null">#{ticketContent},</if>
- <if test="ticketStatus != null">#{ticketStatus},</if>
- <if test="ticketStartTime != null">#{ticketStartTime},</if>
- <if test="ticketEndTime != null">#{ticketEndTime},</if>
- <if test="delFlag != null">#{delFlag},</if>
- <if test="createBy != null">#{createBy},</if>
- <if test="createTime != null">#{createTime},</if>
- <if test="updateTime != null">#{updateTime},</if>
- <if test="updateBy != null">#{updateBy},</if>
- <if test="workstationId != null">#{workstationId},</if>
- <if test="machineryId != null">#{machineryId},</if>
- </trim>
- </insert>
- <update id="updateIsJobTicket" parameterType="IsJobTicket">
- update is_job_ticket
- <trim prefix="SET" suffixOverrides=",">
- <if test="ticketCode != null and ticketCode != ''">ticket_code = #{ticketCode},</if>
- <if test="ticketName != null and ticketName != ''">ticket_name = #{ticketName},</if>
- <if test="workshopId != null">workshop_id = #{workshopId},</if>
- <if test="workareaId != null">workarea_id = #{workareaId},</if>
- <if test="sopId != null">sop_id = #{sopId},</if>
- <if test="ticketType != null">ticket_type = #{ticketType},</if>
- <if test="ticketContent != null">ticket_content = #{ticketContent},</if>
- <if test="ticketStatus != null">ticket_status = #{ticketStatus},</if>
- <if test="ticketStartTime != null">ticket_start_time = #{ticketStartTime},</if>
- <if test="ticketEndTime != null">ticket_end_time = #{ticketEndTime},</if>
- <if test="delFlag != null">del_flag = #{delFlag},</if>
- <if test="createBy != null">create_by = #{createBy},</if>
- <if test="createTime != null">create_time = #{createTime},</if>
- <if test="updateTime != null">update_time = #{updateTime},</if>
- <if test="updateBy != null">update_by = #{updateBy},</if>
- <if test="workstationId != null">workstation_id = #{workstationId},</if>
- <if test="machineryId != null">machinery_id = #{machineryId},</if>
- </trim>
- where ticket_id = #{ticketId}
- </update>
- <delete id="deleteIsJobTicketByTicketId" parameterType="Long">
- delete from is_job_ticket where ticket_id = #{ticketId}
- </delete>
- <delete id="deleteIsJobTicketByTicketIds" parameterType="String">
- delete from is_job_ticket where ticket_id in
- <foreach item="ticketId" collection="array" open="(" separator="," close=")">
- #{ticketId}
- </foreach>
- </delete>
- <!-- 如果LEFT JOIN is_job_ticket_user需要正确的pointCount,需要改写成子查询,现在用不到正确的pointCount,效率优先 -->
- <select id="getIsJobTicketPage" resultType="com.ktg.iscs.domain.vo.ticket.PageTicketVO">
- select t.* from (
- SELECT
- j.ticket_id,
- j.ticket_code,
- j.ticket_name,
- j.workshop_id,
- j.workarea_id,
- j.sop_id,
- j.ticket_type,
- j.ticket_content,
- j.ticket_status,
- j.ticket_start_time,
- j.ticket_end_time,
- j.del_flag,
- j.create_by,
- j.create_time,
- j.update_time,
- j.update_by,
- j.workstation_id,
- j.machinery_id,
- max(ws.workstation_name) as workstation_name,
- max(m.machinery_name) as machinery_name,
- COUNT( p.record_id ) AS pointCount
- FROM
- is_job_ticket j
- LEFT JOIN is_workstation ws ON ws.workstation_id = j.workstation_id
- LEFT JOIN is_machinery m ON m.machinery_id = j.machinery_id
- LEFT JOIN is_job_ticket_points p ON p.ticket_id = j.ticket_id
- <if test="dto.userId != null and dto.userId.trim != ''">
- LEFT JOIN is_job_ticket_user u ON u.ticket_id = j.ticket_id
- </if>
- <where>
- <if test="dto.ticketCode != null and dto.ticketCode.trim != ''">
- and j.ticket_code like concat('%',#{dto.ticketCode},'%')
- </if>
- <if test="dto.ticketName != null and dto.ticketName.trim != ''">
- and j.ticket_name like concat('%',#{dto.ticketName},'%')
- </if>
- <if test="dto.ticketStatus != null and dto.ticketStatus.trim != ''">
- and j.ticket_status = #{dto.ticketStatus}
- </if>
- <if test="dto.workstationId != null">
- and j.workstation_id = #{dto.workstationId}
- </if>
- <if test="dto.machineryId != null">
- and j.machinery_id = #{dto.machineryId}
- </if>
- <if test="dto.ticketType != null and dto.ticketType.trim != ''">
- and j.ticket_type = #{dto.ticketType}
- </if>
- <if test="dto.startTime != null and dto.startTime.trim != ''">
- and j.create_time >= #{dto.startTime}
- </if>
- <if test="dto.endTime != null and dto.endTime.trim != ''">
- and j.create_time <= #{dto.endTime}
- </if>
- <if test="dto.userId != null and dto.userId.trim != ''">
- and u.user_id = #{dto.userId}
- </if>
- </where>
- GROUP BY j.ticket_id,
- j.ticket_code,
- j.ticket_name,
- j.workshop_id,
- j.workarea_id,
- j.sop_id,
- j.ticket_type,
- j.ticket_content,
- j.ticket_status,
- j.ticket_start_time,
- j.ticket_end_time,
- j.del_flag,
- j.create_by,
- j.create_time,
- j.update_time,
- j.update_by,
- j.workstation_id,
- j.machinery_id) t
- ORDER BY j.ticket_id DESC
- </select>
- <select id="getMonitorJobTicketPage" resultType="com.ktg.iscs.domain.vo.ticket.MonitorTicketPageVO">
- SELECT
- j.*, w.workstation_name, m.machinery_name
- FROM
- is_job_ticket j
- left join is_workstation w on w.workstation_id = j.workstation_id
- left join is_machinery m ON m.machinery_id = j.machinery_id
- <where>
- <!-- (j.ticket_status != 4 OR ( j.ticket_end_time > CURDATE() AND j.ticket_status = 4 )) -->
- (j.ticket_status < 5 OR ( j.ticket_end_time > GETDATE() AND j.ticket_status = 5 ))
- <if test="dto.ticketCode != null and dto.ticketCode.trim != ''">
- and j.ticket_code like concat('%',#{dto.ticketCode},'%')
- </if>
- <if test="dto.ticketName != null and dto.ticketName.trim != ''">
- and j.ticket_name like concat('%',#{dto.ticketName},'%')
- </if>
- <if test="dto.ticketStatus != null and dto.ticketStatus.trim != ''">
- and j.ticket_status = #{dto.ticketStatus}
- </if>
- <if test="dto.workstationId != null">
- and j.workstation_id = #{dto.workstationId}
- </if>
- <if test="dto.machineryId != null">
- and j.machinery_id = #{dto.machineryId}
- </if>
- <if test="dto.ticketType != null and dto.ticketType.trim != ''">
- and j.ticket_type = #{dto.ticketType}
- </if>
- <if test="dto.startTime != null and dto.startTime.trim != ''">
- and j.create_time >= #{dto.startTime}
- </if>
- <if test="dto.endTime != null and dto.endTime.trim != ''">
- and j.create_time <= #{dto.endTime}
- </if>
- <if test="dto.ticketId != null">
- and j.ticket_id = #{dto.ticketId}
- </if>
- </where>
- order by j.ticket_id desc
- </select>
- <select id="getTicketListByAttrValue" resultType="com.ktg.iscs.domain.IsJobTicket">
- SELECT
- j.*
- FROM
- is_job_ticket j
- LEFT JOIN is_job_ticket_user u ON u.ticket_id = j.ticket_id and u.user_role = "jtlocker"
- where (j.create_by = #{userId} or u.user_id = #{userId}) and j.ticket_status < 5
- </select>
- <select id="selectConflictTicket1" resultType="com.ktg.iscs.domain.vo.ticket.JobTicketDetailVO">
- SELECT
- j.*
- FROM
- `is_job_ticket` j
- LEFT JOIN is_job_ticket_points p ON p.ticket_id = j.ticket_id
- LEFT JOIN is_job_ticket_key k ON k.ticket_id = j.ticket_id
- WHERE
- j.ticket_status < 5
- AND p.point_id IN
- <foreach collection="pointIds" index="index" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- AND k.collect_time is not null
- and k.give_back_time is null
- and k.ticket_type = 0
- and j.ticket_id != #{ticketId}
- GROUP BY
- j.ticket_id
- </select>
- <select id="selectConflictTicket2" resultType="com.ktg.iscs.domain.vo.ticket.JobTicketDetailVO">
- SELECT
- j.*
- FROM
- `is_job_ticket` j
- LEFT JOIN is_job_ticket_points p ON p.ticket_id = j.ticket_id
- LEFT JOIN is_job_ticket_key k1 ON k1.ticket_id = j.ticket_id and k1.ticket_type = 0
- LEFT JOIN is_job_ticket_key k2 ON k2.ticket_id = j.ticket_id and k2.ticket_type = 1
- WHERE
- j.ticket_status < 5
- AND p.point_id IN
- <foreach collection="pointIds" index="index" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- AND k1.collect_time is not null
- and k1.give_back_time is not null
- AND k2.collect_time is null
- and k2.give_back_time is null
- and j.ticket_id != #{ticketId}
- and p.point_status = 1
- GROUP BY
- j.ticket_id
- </select>
- </mapper>
|