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

    <select id="getPickingList" resultType="java.util.Map">
        select
            <if test="tech neq null and tech neq ''">DISTINCT</if>
            swd.CreatedTime createTime,
            uu.RealName realName,
            m.CODE materialCode,
            m.NAME materialName,
            swd.RfidCode rfidCode,
            swd.ChangeNum changeNum,
            (m.width * swd.ChangeNum / 100) area
        from stock_waterdetial swd
            left join material m on swd.MaterialCode = m.code
            left join u_user uu on uu.ID = swd.OperUserId
        <include refid="selectTech"/>
        ${ew.customSqlSegment}
    </select>

    <select id="getReturnMaterialList" resultType="java.util.Map">
        select
            <if test="tech neq null and tech neq ''">DISTINCT</if>
            sb.operation_time createTime,
            uu.RealName realName,
            m.CODE materialCode,
            m.NAME materialName,
            sbd.rfid rfidCode,
            sbd.material_meters changeNum,
            (m.width * sbd.material_meters / 100) area
        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
        <include refid="selectTech"/>
        ${ew.customSqlSegment}
    </select>
    <select id="getCorrectList" resultType="java.util.Map">
        SELECT
            <if test="tech neq null and tech neq ''">DISTINCT</if>
            sc.correct_date createTime,
            uu.RealName realName,
            m.CODE materialCode,
            m.NAME materialName,
            sc.correct_area area
        FROM stock_correct sc
            LEFT JOIN material m ON sc.material_id = m.ID
            LEFT JOIN u_user uu ON sc.correct_user = uu.ID
        <include refid="selectTech"/>
        ${ew.customSqlSegment}
    </select>

    <sql id="selectTech">
        <if test="tech neq null and tech neq ''">
            inner join (select distinct plan_material from stock_back_plan
            where tech=#{tech} and create_time between #{beginTime} and #{endTime}) sbp
            on (sbp.plan_material = m.`Name` or m.`Name` like (concat(sbp.plan_material,'-%')))
        </if>
    </sql>

</mapper>
