<?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.jeecg.modules.performance.mapper.DesignDetailMapper">

    <select id="queryMaterialDetailByDate" resultType="com.alibaba.fastjson.JSONObject">
        SELECT
        res.*,
        (
        SELECT
        USER.id
        FROM
        sys_user USER
        LEFT JOIN sys_user_role userRole ON USER .id = userRole.user_id
        LEFT JOIN sys_role role ON userRole.role_id = role.id
        WHERE
        USER .org_code = (
        SELECT
        user1.org_code
        FROM
        sys_user user1
        WHERE
        user1.id = res.clipId
        LIMIT 1
        )
        AND role.role_code = 'designTeamLeader'
        ) AS 'leaderId'
        FROM
        (
        SELECT
        report.code,
        sum(report.cost) AS cost,
        ascription.clip_id as clipId,
        ascription.plane_id as planeId,
        ascription.plan_id as planId,
        ascription.shot_id as shotId,
        ascription.material_id as materialId
        FROM
        ctop_material_report_total_result report
        LEFT JOIN ctop_material_info info on report.code=info.code
        LEFT JOIN ctop_material_ascription ascription ON info. CODE = ascription.material_id
        WHERE
        report.media_type = #{mediaType}
        AND report.stat_date &gt;= #{startDate}
        AND report.stat_date &lt;= #{endDate}
        GROUP BY
        report.CODE
        ) res
        WHERE
        res.cost > 0
    </select>

    <select id="queryDesignDetailBy" resultType="com.alibaba.fastjson.JSONObject">
        SELECT
            t1.media_type AS mediaType,
            (select realname from sys_user where id=t1.leader_id) AS leaderName,
            t3.project_name AS projectName,
            t2.material_name AS materialName,
            t2.url,
            t1.material_cost AS materialCost,
            t1.person_cost AS personCost,
            t1.percent
        FROM
            ctop_performance_design_detail t1
                LEFT JOIN ctop_material_info t2 ON t1.material_code = t2. CODE
                LEFT JOIN ctop_project t3 ON t2.project_id = t3.id
        WHERE
            t1.user_id = #{userId}
          AND t1.start_date = #{startDate}
          AND t1.media_type = #{mediaType}
        GROUP BY
            t1.material_code
        ORDER BY person_cost desc
    </select>
</mapper>