<?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="cn.com.ty.lift.business.project.dao.mapper.ProjectLiftRelevanceMapper" >
	<resultMap id="BaseResultMap" type="cn.com.ty.lift.business.project.dao.entity.ProjectLiftRelevance" >
		<id column="id" property="id" jdbcType="BIGINT" />
		<result column="project_id" property="projectId" jdbcType="BIGINT" />
		<result column="lift_id" property="liftId" jdbcType="BIGINT" />
		<result column="relevance_id" property="relevanceId" jdbcType="BIGINT" />
		<result column="worker_id" property="workerId" jdbcType="BIGINT" />
		<result column="lift_locked" property="liftLocked" jdbcType="BIT" />
		<result column="mt_companyId" property="mtCompanyId" jdbcType="BIGINT" />
		<result column="first_time" property="firstTime" jdbcType="DATE" />
		<result column="out_service_date" property="outServiceDate" jdbcType="DATE" />
		<result column="stop_date" property="stopDate" jdbcType="DATE" />
		<result column="plan_interval" property="planInterval" jdbcType="INTEGER" />
		<result column="creator_id" property="creatorId" jdbcType="BIGINT" />
		<result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
		<result column="update_id" property="updateId" jdbcType="BIGINT" />
		<result column="update_date" property="updateDate" jdbcType="TIMESTAMP" />
	</resultMap>

	<sql id="Base_Column_List" >
		id, project_id, lift_id, relevance_id, worker_id, lift_locked, delete_flag, company_id,
		first_time, out_service_date, stop_date, plan_interval, creator_id, create_date,
		update_id, update_date
	</sql>

	<select id="selectListByUserId" resultType="cn.com.ty.lift.business.project.dao.entity.model.response.ProjectRelevanceResponse"
			parameterType="cn.com.ty.lift.business.project.dao.entity.model.request.ProjectRequest" >
		SELECT
		   plr.id              AS id,
		   plr.worker_id       AS workerId,
		   p.project_code      AS projectCode,
  		   p.project_name      AS projectName,
           l.lift_code         AS liftCode,
           l.registration_code AS registrationCode,
           l.device_position   AS devicePosition
		FROM project_lift_relevance plr
		  LEFT JOIN project p ON plr.project_id = p.id
		  LEFT JOIN lift l ON plr.lift_id = l.id
		WHERE plr.worker_id = #{request.workerId,jdbcType=BIGINT}
	</select>

	<select id="count" resultType="java.lang.Integer">
		SELECT count(1)
		FROM project_lift_relevance plr
				 LEFT JOIN project p ON plr.project_id = p.id
		WHERE plr.mt_company_id = #{mtCompanyId}
		  AND p.project_status = #{projectStatus}
	</select>
</mapper>
