<?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.contract.ContractDetailsMapper">

    <select id="getInPage" resultType="java.util.LinkedHashMap">
        select cd.apply_purchase_id,
               cd.apply_purchase_code,
               cd.id   contract_details_id,
               cd.code contract_details_code,
               m.code  material_code,
               m.name  material_name,
               cd.quantity,
               cd.arrival_quantity,
               cd.afloat_quantity,
               cd.complete_status
        from contract_details cd
                 left join material m on cd.material_id = m.id
            ${ew.customSqlSegment}
    </select>

    <select id="outStatistics" resultType="java.util.Map">
        select count(0)                    count,
               ifnull(sum(wd.quantity), 0) sum
        from water w
                 left join water_detail wd on w.id = wd.water_id
            ${ew.customSqlSegment}
    </select>

    <select id="getOutPage" resultType="java.util.LinkedHashMap">
        select m.id                        materialId,
               w.id                        waterId,
               m.name                      materialName,
               m.code                      materialCode,
               w.oper_user_id,
               w.type,
               w.create_time,
               count(0)                    count,
               ifnull(sum(wd.quantity), 0) sum,
               w.remark
        from water w
                 left join water_detail wd on w.id = wd.water_id
                 left join material m on wd.material_id = m.id
            ${ew.customSqlSegment}
    </select>

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

    <select id="warehousingPage" resultType="java.util.LinkedHashMap">
        select m.code                                                         materialCode,
               m.name                                                         materialName,
               m.spec                                                         materialSpec,
               cd.contract_code,
               s.name                                                         supplierName,
               m.unit                                                         materialUnit,
               cd.quantity,
               cd.price,
               cd.update_time                                                 updateTime,
               cd.arrival_quantity - cd.back_quantity                         arrivalQuantity,
               format(cd.price * (cd.arrival_quantity - cd.back_quantity), 2) amountMoney
        from contract_details cd
                 left join supplier s on cd.supplier_id = s.id
                 left join material m on cd.material_id = m.id
            ${ew.customSqlSegment}
    </select>


</mapper>
