<?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="org.springblade.modules.project.mapper.WorkFocusMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="workfocusResultMap" type="org.springblade.modules.project.pojo.entity.WorkFocusEntity">
        <result column="id" property="id"/>
        <result column="work_focus_stage" property="workFocusStage"/>
        <result column="target_plan" property="targetPlan"/>
        <result column="start_year" property="startYear"/>
        <result column="end_year" property="endYear"/>
        <result column="work_plan" property="workPlan"/>
        <result column="duty_unit" property="dutyUnit"/>
        <result column="create_time" property="createTime"/>
        <result column="create_user" property="createUser"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="status" property="status"/>
        <result column="create_dept" property="createDept"/>
    </resultMap>

    <!-- 通用查询映射结果 -->
    <resultMap id="workFocusVOResultMap" type="org.springblade.modules.project.pojo.vo.WorkFocusVO">
        <result column="id" property="id"/>
        <result column="work_focus_stage" property="workFocusStage"/>
        <result column="target_plan" property="targetPlan"/>
        <result column="start_year" property="startYear"/>
        <result column="end_year" property="endYear"/>
        <result column="work_plan" property="workPlan"/>
        <result column="duty_unit" property="dutyUnit"/>
        <result column="create_time" property="createTime"/>
        <result column="create_user" property="createUser"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="status" property="status"/>
        <result column="create_dept" property="createDept"/>
        <result column="workFocusStageName" property="workFocusStageName"/>
        <result column="comRate" property="comRate"/>
    </resultMap>

    <select id="selectWorkFocusPage" resultMap="workFocusVOResultMap">
        select * ,(SELECT dict_value from blade_dict_biz where code='workFocusStage' and is_deleted=0 and dict_key=b.work_focus_stage) as workFocusStageName,
        FLOOR((SELECT sum(a.schedule is not null and schedule!='' and month &lt;=12) + sum(a.progress is not null and progress!='') from d_work_focus_progress a where work_focus_id=b.id and is_deleted=0)/
        ((end_year-start_year+1)*28)*100) as comRate
        from d_work_focus b where is_deleted = 0
        <if test="param2.startYear!=null and param2.startYear != ''">
            and start_year &lt;= #{param2.startYear}
        </if>
        <if test="param2.endYear!=null and param2.endYear != '' ">
            and end_year &gt;= #{param2.endYear}
        </if>

        <if test="param2.targetPlan!=null and param2.targetPlan != '' ">
            and (target_plan like  concat(concat('%', #{param2.targetPlan}), '%') or work_plan like  concat(concat('%', #{param2.targetPlan}), '%') )
        </if>
        <if test="param2.workFocusStage!=null and param2.workFocusStage != '' ">
            and work_focus_stage = #{param2.workFocusStage}
        </if>
         order by target_plan
    </select>


    <select id="exportWorkFocus" resultType="org.springblade.modules.project.pojo.excel.WorkFocusExcel">
        SELECT * FROM d_work_focus ${ew.customSqlSegment}
    </select>

    <select id="queryWorkFocusDataInfo" resultType="org.springblade.modules.project.pojo.vo.WorkFocusProgressDataInfoVO">
        SELECT DISTINCT id,
               (SELECT dict_value from blade_dict_biz where code='workFocusStage' and is_deleted=0 and dict_key=b.work_focus_stage) as workFocusStageName,
               target_plan,work_plan,duty_unit,
               a.month1,a.month2,a.month3,a.month4,a.month5,a.month6,a.month7,a.month8,a.month9,a.month10,a.month11,a.month12
        from d_work_focus b,d_work_focus_view a where is_deleted=0 and b.id=a.work_focus_id
        <if test="workfocus.year!=null and workfocus.year != '' ">
            and a.year = #{workfocus.year}
        </if>
    </select>
</mapper>
