<?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.fjhx.stock.mapper.StockBackPlanMapper">

    <select id="getList" resultType="java.util.Map">
        select t.jobNo,
               (t.quantity * m.Width / 100) quantity,
               t.planDate,
               m.Name                       materialName
        from (
                 (
                     select ss.printer           jobNo,
                            ss.material_code     materialCode,
                            ss.material_quantity quantity,
                            ss.plan_date         planDate
                     from stock_scheduling ss
                         ${ew.customSqlSegment}
                 )
                 union all
                 (
                     select ss.paper_man      jobNo,
                            ss.paper_code     materialCode,
                            ss.paper_quantity quantity,
                            ss.plan_date      planDate
                     from stock_scheduling ss
                         ${ew.customSqlSegment}
                 )
             ) t
                 inner join material m on m.code = t.materialCode
    </select>

    <select id="getWater" resultType="java.util.Map">
        select swd.ChangeNum   changeNum,
               swd.CreatedTime createTime,
               m.Name          materialName,
               m.Price         price,
               m.Width         width,
               uu.JobNo        jobNo
        from stock_waterdetial swd
                 left join material m on swd.MaterialCode = m.code
                 left join u_user uu on uu.ID = swd.OperUserId
            ${ew.customSqlSegment}
    </select>

    <select id="getCorrect" resultType="java.util.Map">
        select sbc.correct_area correctArea,
               m.Name           materialName,
               sbc.correct_time createTime,
               uu.JobNo         jobNo
        from stock_back_correct sbc
                 left join material m on sbc.material_id = m.ID
                 left join u_user uu on uu.ID = sbc.user_id
            ${ew.customSqlSegment}
    </select>

    <select id="getTransferBackList" resultType="java.util.Map">
        select std.quantity   changeNum,
               st.submit_time createTime,
               m.Name         materialName,
               m.Price        price,
               m.Width        width,
               uu.JobNo       jobNo
        from stock_transfer st
                 left join stock_transfer_details std on st.id = std.stock_transfer_id
                 left join material m on st.material_id = m.id
                 left join acc_account aa on aa.AccountNo = st.submit_user
                 left join u_user uu on uu.ID = aa.ID
            ${ew.customSqlSegment}
    </select>

    <select id="getTransferPickingList" resultType="java.util.Map">
        select std.quantity   changeNum,
               st.submit_time createTime,
               m.Name         materialName,
               m.Price        price,
               m.Width        width,
               uu.JobNo       jobNo
        from stock_transfer st
                 left join stock_transfer_details std on st.id = std.stock_transfer_id
                 left join material m on st.material_id = m.id
                 left join u_user uu on uu.ID = st.receive_user
            ${ew.customSqlSegment}
    </select>

    <select id="getReturnWarehouse" resultType="java.util.Map">
        select sbd.material_meters changeNum,
               sb.operation_time   createTime,
               m.Name              materialName,
               m.Price             price,
               m.Width             width,
               uu.JobNo            jobNo
        from stock_back sb
                 left join stock_back_details sbd on sb.id = sbd.stock_back_id
                 left join material m on sbd.material_id = m.id
                 left join acc_account aa on sb.operator_id = aa.AccountNo
                 left join u_user uu on uu.ID = aa.ID
            ${ew.customSqlSegment}
    </select>

</mapper>
