<?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.mapper.water.WaterDetailMapper">

    <select id="getInQuantityByApplyPurchaseDetailsId" resultType="java.util.Map">
        select sum(wd.quantity)    quantity,
               min(wd.create_time) createTime,
               wd.oper_user_id     operUserId
        from water_batch wb
                 inner join water_detail wd on wb.id = wd.water_batch_id and wd.type = 10
        where wb.apply_purchase_details_id = #{applyPurchaseDetailsId}
        group by wb.id
    </select>
    <select id="getPickingList" resultType="java.util.Map">
        select if(wd.type = 15, -wd.quantity, wd.quantity) changeNum,
               ifnull(wd.price, 0)                         materialPrice,
               m.technology_type                           materialType,
               m.Width                                     materialWidth,
               wd.oper_user_id                             userId
        from water_detail wd
                 inner join material m on wd.material_id = m.id
            ${ew.customSqlSegment}
    </select>

    <select id="pickingTypeStatistics" resultType="java.util.Map">
        select sum(if(wd.type = 15, 1, 0)) cancellingStocks,
               sum(if(wd.type = 20, 1, 0)) exWarehouse,
               sum(if(wd.type = 23, 1, 0)) supplementaryDelivery
        from water_detail wd
                 inner join material m on wd.material_id = m.id
            ${ew.customSqlSegment}
    </select>

    <select id="pickingPage" resultType="java.util.Map">
        select wd.create_time                    createdTime,
               m.technology_type                 materialType,
               m.code                            materialCode,
               m.name                            materialName,
               m.spec                            materialSpec,
               m.unit                            materialUnit,
               wd.quantity                       changeNum,
               wd.Price                          materialPrice,
               format(wd.price * wd.quantity, 2) money,
               wd.oper_user_id                   operUserId
        from water_detail wd
                 inner join material m on wd.material_id = m.id
            ${ew.customSqlSegment}
    </select>

    <select id="getPickingToday" resultType="java.util.Map">
        select distinct m.id, m.name
        from water_detail wd
                 left join material m on m.id = wd.material_id
            ${ew.customSqlSegment}
    </select>

</mapper>
