<?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.orderplatform.mapper.PlatformQueryOtherMapper">

    <select id="queryAllDesignLeader" resultType="com.alibaba.fastjson.JSONObject">
        SELECT
            t1.realname,
            t1.id as userId
        FROM
            sys_user t1
                LEFT JOIN sys_user_role t2 ON t1.id = t2.user_id
                LEFT JOIN sys_role t3 ON t2.role_id = t3.id
        where t3.role_code='designTeamLeader'
        and t1.status=1
    </select>

    <select id="queryIdentity" resultType="com.alibaba.fastjson.JSONObject">
        SELECT
            t.realname,
            t2.role_name as roleName,
            t4.depart_name as departName,
            t6.area as area
        FROM
            sys_user t
                LEFT JOIN sys_user_role t1 ON t.id = t1.user_id
                LEFT JOIN sys_role t2 on t1.role_id=t2.id
                LEFT JOIN sys_user_depart t3 on t.id = t3.user_id
                LEFT JOIN sys_depart t4 on t3.dep_id=t4.id
                LEFT JOIN user_company t5 on t.id=t5.user_id
                LEFT JOIN sys_company t6 on t5.company_id=t6.company_id
        where t.id=#{currentLogon}
    </select>

    <select id="queryMaterialCountByDesignUserId" resultType="java.lang.Integer">
        SELECT
        count(id)
        FROM
        ctop_platform_material
        WHERE
        material_status in
        <foreach item="item" index="index" collection="materialStatus"
                 open="(" separator="," close=")">
            #{item}
        </foreach>
        And (plan = #{userId}
        OR clip = #{userId}
        OR shot = #{userId})
    </select>

    <select id="queryMaterialCountByOperatorUserId" resultType="java.lang.Integer">
        SELECT
            count(id)
        FROM
            ctop_platform_material
        WHERE
            material_status in(2,5)
          and project_id in(SELECT DISTINCT project_id from ctop_project_member WHERE user_id=#{operatorUserId})
    </select>

    <select id="queryMaterialCountByDesign" resultType="java.lang.Integer">
        SELECT
            count(t1.id)
        FROM
            ctop_platform_material t1
                LEFT JOIN ctop_platform_order t2 ON t1.order_code = t2.order_code
        WHERE
            t2.design =#{userId}
          AND t1.material_status = 0
    </select>

    <select id="queryOrderCountByDesign" resultType="java.lang.Integer">
        SELECT
            count(id)
        FROM
            ctop_platform_order
        WHERE
            design =#{userId}
        and order_status=0
    </select>

    <select id="queryNewOrderCountByOperator" resultType="java.lang.Integer">
        SELECT
            count(id)
        FROM
            ctop_platform_order
        WHERE
            create_by =#{userId}
    </select>

    <select id="queryRejectOrderCountByOperator" resultType="java.lang.Integer">
        SELECT
            count(id)
        FROM
            ctop_platform_order
        WHERE
            create_by =#{userId}
        and order_status=2
    </select>

    <select id="queryFinishOrderCountByOperator" resultType="java.lang.Integer">
        SELECT
            count(id)
        FROM
            ctop_platform_order
        WHERE
            create_by =#{userId}
        and order_status=3
    </select>

    <select id="queryFinishOrderCountByDesign" resultType="java.lang.Integer">
        SELECT
            count(id)
        FROM
            ctop_platform_order
        WHERE
            design =#{userId}
          and order_status=3
    </select>

    <select id="queryAllOrderByDesign" resultType="java.lang.Integer">
        SELECT
            count(id)
        FROM
            ctop_platform_order
        WHERE
            design =#{userId}
    </select>
</mapper>