<?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.material.mapper.MaterialReceivingMapper">

    <insert id="insertFlowApplyCheck">
        insert into flow_applycheck(id, IsDelete, CreatedTime, UpdatedTime, FlowId, NodeId, PreNodeId, NextNodeId,
                                    CheckUserId, CheckState, Suggestions, LinkId, ApprovalItem)
        values (#{id},
                0,
                now(),
                now(),
                #{flowId},
                #{nodeId},
                #{preNodeId},
                #{nextNodeId},
                #{checkUserId},
                #{checkState},
                #{suggestions},
                #{linkId},
                #{approvalItem})
    </insert>

    <select id="getList" resultType="java.util.Map">
        select mrd.id,
               m.Name                  materialName,
               m.Code                  materialCode,
               mr.submit_time          submitTime,
               st.Quantity             quantity,
               mr.submit_user_account  submitUserAccount,
               mr.receive_user_account receiveUserAccount
        from material_receiving mr
                 inner join material_receiving_details mrd on mr.id = mrd.material_receiving_id
                 inner join stock_tag st on mrd.rfid = st.RfidCode
                 inner join material m on st.MaterialCode = m.Code
        where mr.receive_user_account = #{receiveUserAccount}
          and mrd.status = 2
    </select>

    <select id="getUserNameByAccount" resultType="java.util.Map">
        select aa.AccountNo account,
               uu.RealName  userName
        from acc_account aa
                 left join u_user uu on aa.ID = uu.ID
            ${ew.customSqlSegment}
    </select>

    <select id="flowDetails" resultType="java.util.Map">
        select m.Name                  materialName,
               m.Code                  materialCode,
               mr.submit_time          createTime,
               st.Quantity             changeNum,
               mr.Remark               remark,
               mr.submit_user_account  submitUserAccount,
               mr.receive_user_account receiveUserAccount,
               mr.id                   materialReceivingId,
               mr.FlowLinkId           flowLinkId
        from material_receiving mr
                 left join material_receiving_details mrd on mr.id = mrd.material_receiving_id
                 left join stock_tag st on mrd.rfid = mrd.rfid
                 left join material m on st.MaterialCode = m.Code
        where mr.FlowLinkId = #{linkId}
    </select>

    <select id="toBeReceivedList" resultType="java.util.Map">
        select mrd.id,
               m.Name                  materialName,
               m.Code                  materialCode,
               mr.submit_time          submitTime,
               st.Quantity             quantity,
               mr.submit_user_account  submitUserAccount,
               mr.receive_user_account receiveUserAccount,
               mrd.status              status
        from material_receiving mr
                 inner join material_receiving_details mrd on mr.id = mrd.material_receiving_id
                 inner join stock_tag st on mrd.rfid = st.RfidCode
                 inner join material m on st.MaterialCode = m.Code
        where mr.submit_user_account = #{submitUserAccount}
          and (mrd.status = 2 or mrd.status = 4)
    </select>

</mapper>
