<?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.pay.mapper.PayWorkOrderBaohuoMapper">

    <resultMap type="com.ruoyi.pay.domain.PayWorkOrderBaohuo" id="PayWorkOrderBaohuoResult">
        <result property="id" column="id"/>
        <result property="tenantId" column="tenant_id"/>
        <result property="archiveId" column="archive_id"/>
        <result property="productId" column="product_id"/>
        <result property="deptId" column="dept_id"/>
        <result property="workshop" column="workshop"/>
        <result property="name" column="name"/>
        <result property="content" column="content"/>
        <result property="productNum" column="product_num"/>
        <result property="price" column="price"/>
        <result property="unit" column="unit"/>
        <result property="amount" column="amount"/>
        <result property="beginTime" column="begin_time"/>
        <result property="endTime" column="end_time"/>
        <result property="qualityName" column="quality_name"/>
        <result property="qualityRemark" column="quality_remark"/>
        <result property="instorageTime" column="instorage_time"/>
        <result property="instorageName" column="instorage_name"/>
        <result property="instorageNum" column="instorage_num"/>
        <result property="managerName" column="manager_name"/>
        <result property="deleted" column="deleted"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <resultMap type="ExportBaohuoVo" id="ExportBaohuoVoResult">
        <result property="instorageTime"    column="instorage_time"    />
        <result property="woId"    column="wo_id"    />
        <result property="name"    column="name"    />
        <result property="productName"    column="product_name"    />
        <result property="content"    column="content"    />
        <result property="unit"    column="unit"    />
        <result property="productNum"    column="product_num"    />
        <result property="price"    column="price"    />
        <result property="amount"    column="amount"    />
        <result property="avgAmount"    column="avg_amount"    />
        <result property="workerNum"    column="worker_num"    />
        <result property="workTime"    column="work_time"    />
        <result property="worksName"    column="works_name"    />
    </resultMap>
    <select id="getWorkOrderListByDate" parameterType="date" resultMap="ExportBaohuoVoResult">
        SELECT b.instorage_time, b.`name`, a.product_name,b.content,a.unit,a.product_num,a.price,a.amount,a.wo_id,
               (SELECT count(*) FROM pay_baohuo_employee WHERE wo_id = b.id) as worker_num,
               (SELECT sum(valid_hours) FROM pay_baohuo_worktime WHERE wo_id = b.id) AS work_time,
               (SELECT GROUP_CONCAT(emp_name) FROM pay_baohuo_employee WHERE wo_id = b.id) AS works_name
        FROM pay_baohuo_product a
                 LEFT JOIN pay_work_order_baohuo b ON a.wo_id = b.id
        WHERE date_format(#{exportDate},'%y%m') = date_format(b.instorage_time,'%y%m')
        ORDER BY a.wo_id ASC
    </select>

    <select id="getWoIdSet" resultType="java.lang.Long">
        SELECT DISTINCT wo_id FROM pay_baohuo_worktime
        <where>
            <if test="empId != null">
                AND emp_id = #{empId}
            </if>
            <if test="workDate != null and workDate != ''">
                AND date = #{workDate}
            </if>

        </where>
    </select>
</mapper>
