<?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.hzya.frame.u9c.saledeliver.dao.impl.VU9cSaledeliverEntityDaoImpl">

    <resultMap id="get-VU9cSaledeliverEntity-result" type="com.hzya.frame.u9c.saledeliver.entity.VU9cSaledeliverEntity" >
        <result property="billType" column="bill_type" jdbcType="VARCHAR"/>
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="operateOrgName" column="operate_org_name" jdbcType="VARCHAR"/>
        <result property="orgId" column="org_id" jdbcType="VARCHAR"/>
        <result property="billCode" column="bill_code" jdbcType="VARCHAR"/>
        <result property="custName" column="cust_name" jdbcType="VARCHAR"/>
        <result property="custCode" column="cust_code" jdbcType="VARCHAR"/>
        <result property="orgCode" column="org_code" jdbcType="VARCHAR"/>
        <result property="billDate" column="bill_date" jdbcType="VARCHAR"/>
        <result property="deptCode" column="dept_code" jdbcType="VARCHAR"/>
        <result property="deptName" column="dept_name" jdbcType="VARCHAR"/>
        <result property="salesmanCode" column="salesman_code" jdbcType="VARCHAR"/>
        <result property="salesmanName" column="salesman_name" jdbcType="VARCHAR"/>
        <result property="curCode" column="cur_code" jdbcType="VARCHAR"/>
        <result property="curName" column="cur_name" jdbcType="VARCHAR"/>
        <result property="shipmentTime" column="shipment_time" jdbcType="VARCHAR"/>
        <result property="isTax" column="is_tax" jdbcType="VARCHAR"/>
        <result property="isDirect" column="is_direct" jdbcType="VARCHAR"/>
        <result property="updatetime" column="updateTime" jdbcType="VARCHAR"/>
        <result property="crmId" column="crm_id" jdbcType="VARCHAR"/>
        <result property="operatorsId" column="operators_id" jdbcType="VARCHAR"/>
        <result property="salesOrderId" column="sales_order_id" jdbcType="VARCHAR"/>
        <result property="SrcDocTransType" column="SrcDocTransType" jdbcType="VARCHAR"/>
        <result property="soOrder" column="soOrder" jdbcType="VARCHAR"/>
        <result property="TotalNetMoneyTC" column="TotalNetMoneyTC" jdbcType="VARCHAR"/>
        <result property="TotalMoneyTC" column="TotalMoneyTC" jdbcType="VARCHAR"/>
        <result property="address" column="address" jdbcType="VARCHAR"/>
        <result property="phone" column="phone" jdbcType="VARCHAR"/>
        <result property="linkman" column="linkman" jdbcType="VARCHAR"/>
        <result property="state" column="state" jdbcType="VARCHAR"/>
        <result property="RcvQtyTU" column="RcvQtyTU" jdbcType="VARCHAR"/>
    </resultMap>
    <!-- 查询的字段-->
    <sql id = "VU9cSaledeliverEntity_Base_Column_List">
        bill_type
       ,id

       ,TotalMoneyTC
       ,linkman
       ,phone
       ,address
       ,TotalNetMoneyTC
       ,soOrder
        ,operate_org_name
        ,org_id 
        ,sales_order_id
        ,bill_code
        ,cust_name 
        ,cust_code 
        ,org_code 
        ,bill_date 
        ,dept_code
        ,dept_name 
        ,salesman_code 
        ,salesman_name 
        ,cur_code 
        ,cur_name 
        ,shipment_time 
        ,is_tax 
        ,is_direct 
        ,updateTime 
        ,crm_id 
        ,operators_id 
     </sql>
 <!-- 查询 采用==查询 -->
 <select id="VU9cSaledeliverEntity_list_base" resultMap="get-VU9cSaledeliverEntity-result" parameterType = "com.hzya.frame.u9c.saledeliver.entity.VU9cSaledeliverEntity">
    select

    <include refid="VU9cSaledeliverEntity_Base_Column_List" />
    from v_u9c_saledeliver where (crm_id ='' or crm_id is null  or  updateTime > #{updatetime} )
    <!--or  updateTime > #{updatetime}-->

</select>
   <!--通过主键修改方法-->
    <update id="entity_update" parameterType = "com.hzya.frame.u9c.itemmaster.entity.VU9cItemmasterEntity" >
        update SM_Ship  set
        <trim suffix="" suffixOverrides=",">
            <if test="dataId != null and dataId != ''"> DescFlexField_PrivateDescSeg1 = #{dataId},</if>
        </trim>
        where  id = #{id}
    </update>
    <!-- 查询 采用==查询 -->
    <select id="VU9cSaledeliverEntity_list_base_for_delete" resultMap="get-VU9cSaledeliverEntity-result" parameterType = "com.hzya.frame.u9c.saledeliver.entity.VU9cSaledeliverEntity">
        select
        *
        from SM_Ship_for_delete where (state is null or state ='')  and crm_id !=''

    </select>
    <!--通过主键修改方法-->
    <update id="entity_update_for_delete" parameterType = "com.hzya.frame.u9c.itemmaster.entity.VU9cItemmasterEntity" >
       update SM_Ship_for_delete set state = #{state}
        where  id = #{id}
    </update>

    <!-- 查询 采用==查询 -->
    <select id="VU9cSaledeliverEntity_list_base_for_update" resultMap="get-VU9cSaledeliverEntity-result" parameterType = "com.hzya.frame.u9c.saledeliver.entity.VU9cSaledeliverEntity">
        select
--         Receivement.id as id,
        rma.DescFlexField_PrivateDescSeg1 as crm_id
        from PM_Receivement Receivement
        left join PM_RcvLine RcvLine on Receivement.id = RcvLine.Receivement
        left join SM_RMA rma on rma.id = RcvLine.srcdoc_srcdoc_entityid
        where 1=1
        and rma.DescFlexField_PrivateDescSeg1 != ''
        and rma.DescFlexField_PrivateDescSeg1 is not null
        and Receivement.Status = '5'
--         and rma.DescFlexField_PrivateDescSeg1 = '65dee663fe5e1f000159fd79'
        and Receivement.ModifiedOn > #{updatetime}
        GROUP BY rma.DescFlexField_PrivateDescSeg1
    </select>

    <!-- 查询 采用==查询 -->
    <select id="VU9cSaledeliverEntity_list_base_for_update_details" resultMap="get-VU9cSaledeliverEntity-result" parameterType = "com.hzya.frame.u9c.saledeliver.entity.VU9cSaledeliverEntity">
      select RcvQtyTU,crm_id from (
      select
        CAST(RcvLine.RcvQtyTU AS DECIMAL(20,4)) as RcvQtyTU,
         rmaline.DescFlexField_PrivateDescSeg1 as crm_id,
         RcvLine.Receivement,
		rmaline.DescFlexField_PrivateDescSeg6
        from PM_RcvLine RcvLine
        left join SM_RMALine rmaline on RcvLine.srcdoc_srcdocline_entityid = rmaline.id
      )m1
    where DescFlexField_PrivateDescSeg6 = #{id}
    </select>
</mapper>

