<?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.ruoyi.project.mapper.ProjectStaffRecordMapper">
  <resultMap id="BaseResultMap" type="com.ruoyi.project.domain.ProjectStaffRecord">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="pid" jdbcType="BIGINT" property="pid" />
    <result column="aid" jdbcType="BIGINT" property="aid" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="project_status" jdbcType="INTEGER" property="projectStatus" />
    <result column="content" jdbcType="VARCHAR" property="content" />
    <result column="annex_url" jdbcType="VARCHAR" property="annexUrl" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="process_status" jdbcType="INTEGER" property="processStatus" />
    <result column="duration" jdbcType="DOUBLE" property="duration" />
    <result column="examine_id" jdbcType="BIGINT" property="examineId" />
    <result column="examine_time" jdbcType="TIMESTAMP" property="examineTime" />
    <result column="examine_name" jdbcType="VARCHAR" property="examineName" />
    <result column="record_time" jdbcType="TIMESTAMP" property="recordTime" />
  </resultMap>
  <sql id="Base_Column_List">
    id, pid, aid, `name`, project_status, content, annex_url, create_time, process_status,
    duration, examine_id, examine_time, examine_name, record_time
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from project_staff_record
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from project_staff_record
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ruoyi.project.domain.ProjectStaffRecord" useGeneratedKeys="true">
    insert into project_staff_record (pid, aid, `name`,
      project_status, content, annex_url,
      create_time, process_status, duration,
      examine_id, examine_time, examine_name,
      record_time)
    values (#{pid,jdbcType=BIGINT}, #{aid,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR},
      #{projectStatus,jdbcType=INTEGER}, #{content,jdbcType=VARCHAR}, #{annexUrl,jdbcType=VARCHAR},
      #{createTime,jdbcType=TIMESTAMP}, #{processStatus,jdbcType=INTEGER}, #{duration,jdbcType=DOUBLE},
      #{examineId,jdbcType=BIGINT}, #{examineTime,jdbcType=TIMESTAMP}, #{examineName,jdbcType=VARCHAR},
      #{recordTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.ruoyi.project.domain.ProjectStaffRecord" useGeneratedKeys="true">
    insert into project_staff_record
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="pid != null">
        pid,
      </if>
      <if test="aid != null">
        aid,
      </if>
      <if test="name != null">
        `name`,
      </if>
      <if test="projectStatus != null">
        project_status,
      </if>
      <if test="content != null">
        content,
      </if>
      <if test="annexUrl != null">
        annex_url,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="processStatus != null">
        process_status,
      </if>
      <if test="duration != null">
        duration,
      </if>
      <if test="examineId != null">
        examine_id,
      </if>
      <if test="examineTime != null">
        examine_time,
      </if>
      <if test="examineName != null">
        examine_name,
      </if>
      <if test="recordTime != null">
        record_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="pid != null">
        #{pid,jdbcType=BIGINT},
      </if>
      <if test="aid != null">
        #{aid,jdbcType=BIGINT},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="projectStatus != null">
        #{projectStatus,jdbcType=INTEGER},
      </if>
      <if test="content != null">
        #{content,jdbcType=VARCHAR},
      </if>
      <if test="annexUrl != null">
        #{annexUrl,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="processStatus != null">
        #{processStatus,jdbcType=INTEGER},
      </if>
      <if test="duration != null">
        #{duration,jdbcType=DOUBLE},
      </if>
      <if test="examineId != null">
        #{examineId,jdbcType=BIGINT},
      </if>
      <if test="examineTime != null">
        #{examineTime,jdbcType=TIMESTAMP},
      </if>
      <if test="examineName != null">
        #{examineName,jdbcType=VARCHAR},
      </if>
      <if test="recordTime != null">
        #{recordTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.ruoyi.project.domain.ProjectStaffRecord">
    update project_staff_record
    <set>
      <if test="pid != null">
        pid = #{pid,jdbcType=BIGINT},
      </if>
      <if test="aid != null">
        aid = #{aid,jdbcType=BIGINT},
      </if>
      <if test="name != null">
        `name` = #{name,jdbcType=VARCHAR},
      </if>
      <if test="projectStatus != null">
        project_status = #{projectStatus,jdbcType=INTEGER},
      </if>
      <if test="content != null">
        content = #{content,jdbcType=VARCHAR},
      </if>
      <if test="annexUrl != null">
        annex_url = #{annexUrl,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="processStatus != null">
        process_status = #{processStatus,jdbcType=INTEGER},
      </if>
      <if test="duration != null">
        duration = #{duration,jdbcType=DOUBLE},
      </if>
      <if test="examineId != null">
        examine_id = #{examineId,jdbcType=BIGINT},
      </if>
      <if test="examineTime != null">
        examine_time = #{examineTime,jdbcType=TIMESTAMP},
      </if>
      <if test="examineName != null">
        examine_name = #{examineName,jdbcType=VARCHAR},
      </if>
      <if test="recordTime != null">
        record_time = #{recordTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.ruoyi.project.domain.ProjectStaffRecord">
    update project_staff_record
    set pid = #{pid,jdbcType=BIGINT},
      aid = #{aid,jdbcType=BIGINT},
      `name` = #{name,jdbcType=VARCHAR},
      project_status = #{projectStatus,jdbcType=INTEGER},
      content = #{content,jdbcType=VARCHAR},
      annex_url = #{annexUrl,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      process_status = #{processStatus,jdbcType=INTEGER},
      duration = #{duration,jdbcType=DOUBLE},
      examine_id = #{examineId,jdbcType=BIGINT},
      examine_time = #{examineTime,jdbcType=TIMESTAMP},
      examine_name = #{examineName,jdbcType=VARCHAR},
      record_time = #{recordTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <select id="selectList" resultType="com.ruoyi.project.bo.ProjectStaffRecordOut">
    select a.id,c.job_number jobNumber,a.name   ,d.dept_id deptId ,d.dept_name deptName ,c.create_time createMonth,
    b.name projectName,b.admin_name adminName ,a.project_status projectStatus,a.content ,
    a.pid ,a.aid ,a.examine_id examineId ,a.examine_name examineName ,a.examine_time examineTime,
    a.annex_url annexUrl,a.create_time createTime,a.process_status processStatus , a.duration
    from project_staff_record a left join project_task b on a.pid=b.id
    left join sys_user c on a.aid=c.user_id left join sys_dept d on c.dept_id =d.dept_id
    where 1=1
    <if test="roleType==0">
      and a.aid =#{aid}
    </if>
    <if test="roleType==1">
      and a.aid in (select user_id from sys_user_role where role_id=2)
    </if>
    <if test="roleType==2">
      and a.aid in (select user_id from sys_user_role where role_id=3)
    </if>
    <if test="processStatus  !=null">
      and a.process_status= #{processStatus}
    </if>
    <if test="companyId !=null">
      and (d.dept_id= #{companyId} or find_in_set(#{companyId},d.ancestors))
    </if>
  </select>
    <select id="selectById" resultType="java.lang.Integer">
      select count(*)
      from project_staff_record a left join project_staff ps on a.aid = ps.aid
      where a.pid=ps.pid
      and ps.id = #{id}
    </select>
  <select id="selectByPidAndAid"  resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from project_staff_record
    where 1=1
    <if test="pid !=null">
      and pid= #{pid}
    </if>
    <if test="aid != null">
      and aid = #{aid}
    </if>

  </select>
    <select id="myDurationMonth" resultType="com.ruoyi.project.bo.MyMonthDays">
      select  x.dates dates,sum(x.duration)duration
      from (select a.duration ,date_format(a.record_time,'%Y-%m-%d')dates
            from project_staff_record a
            where a.pid = #{param1} and a.aid =#{param2}
              and a.record_time between #{param3} and #{param4}
           )x group by x.dates
    </select>
  <select id="selectDetailsById" resultType="com.ruoyi.project.bo.ProjectStaffRecordOut">
    select a.id,c.job_number jobNumber,a.name   ,d.dept_id deptId ,d.dept_name deptName ,c.create_time createMonth,
           b.id projectId,b.name projectName,b.admin_name adminName ,a.project_status projectStatus,a.content ,
           a.pid ,a.aid ,a.examine_id examineId ,a.examine_name examineName ,a.examine_time examineTime,
           a.annex_url annexUrl,a.create_time createTime,a.process_status processStatus , a.duration
    from project_staff_record a left join project_task b on a.pid=b.id
    left join sys_user c on a.aid=c.user_id left join sys_dept d on c.dept_id =d.dept_id
    where 1=1
    and a.id =#{id}
  </select>

</mapper>
