<?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.StockTransferMapper">

    <select id="getPage" resultType="java.util.Map">
        select st.id,
               st.submit_num,
               st.submit_meters,
               st.submit_time,
               uu.RealName  receive_user,
               uu2.RealName submit_user
        from stock_transfer st
                 left join u_user uu on st.receive_user = uu.ID
                 left join acc_account aa on st.submit_user = aa.AccountNo
                 left join u_user uu2 on aa.ID = uu2.ID
            ${ew.customSqlSegment}
    </select>

    <select id="StockTransferVo" resultType="com.fjhx.params.stock.StockTransferVo">
        select st.id,
               st.material_id,
               st.submit_user,
               st.submit_time,
               st.submit_num,
               st.submit_meters,
               st.receive_user,
               st.check_user,
               st.check_time,
               st.status,
               m.Name material_name
        from stock_transfer st
                 left join material m on st.material_id = m.ID
        where st.id = #{id}
    </select>

    <select id="webStatistics" resultType="java.util.Map">
        select ifnull(count(0), 0)                                    count,
               ifnull(sum(std.quantity), 0)                           quantity,
               round(ifnull(sum(std.quantity * m.Width / 100), 0), 2) area,
               round(ifnull(sum(std.quantity * m.Price), 0), 2)       Price
        from stock_transfer st
                 left join stock_transfer_details std on st.id = std.stock_transfer_id
                 left join material m on std.material_id = m.id
                 left join u_user uu on st.receive_user = uu.ID
                 left join acc_account aa on st.submit_user = aa.AccountNo
                 left join u_user uu2 on aa.ID = uu2.ID
            ${ew.customSqlSegment}
    </select>


    <select id="webPage" resultType="java.util.Map">
        select st.submit_time,
               uu.RealName                              receiveUser,
               uu2.RealName                             submitUser,
               m.name                                   materialName,
               std.quantity,
               round((std.quantity * m.Width / 100), 2) area
        from stock_transfer st
                 left join stock_transfer_details std on st.id = std.stock_transfer_id
                 left join material m on std.material_id = m.id
                 left join u_user uu on st.receive_user = uu.ID
                 left join acc_account aa on st.submit_user = aa.AccountNo
                 left join u_user uu2 on aa.ID = uu2.ID
            ${ew.customSqlSegment}
    </select>

</mapper>
