<?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="cn.superdesk.uniorder.dao.mapper.unified.UnifiedSupplierCostConfigMapperEx">

	<update id="updateOrderCost" parameterType="cn.superdesk.uniorder.dto.vo.unified.OrderCostUpdateParam">
	    update
	    	unified_order
	    set
	    	cost_amount = amount * (1-#{returnPoint})
	    <where>
	    	and service_no = #{serviceNo}
		    and sale_id = #{saleId}
		    and year(create_time) = #{syear}
		    and month(create_time) = #{smonth}
		</where>
 	</update>

	<update id="updateOrderGoodsCost" parameterType="cn.superdesk.uniorder.dto.vo.unified.OrderCostUpdateParam">
    update
    	unified_order_goods
    set
    	cost_price = price * (1-#{returnPoint})
    <where>
		and order_sn in (
			SELECT
				order_sn
			from
				unified_order
			<where>
				and service_no = #{serviceNo}
				and sale_id = #{saleId}
				and year(create_time) = #{syear}
				and month(create_time) = #{smonth}
			</where>
		)
	</where>
 	</update>

	<select id="findAll" resultMap="cn.superdesk.uniorder.dao.mapper.unified.UnifiedSupplierCostConfigMapper.BaseResultMap">
		select
		<include refid="cn.superdesk.uniorder.dao.mapper.unified.UnifiedSupplierCostConfigMapper.Base_Column_List"/>
		from
			unified_supplier_cost_config
		<where>
			<if test="saleId != null and saleId != '' ">
				and sale_id = #{saleId}
			</if>
			<if test="saleName != null and saleName != '' ">
				and sale_name like CONCAT('%',#{saleName},'%')
			</if>
			<if test="enabled != null and enabled != ''">
				and enabled = #{enabled}
			</if>
		</where>
	</select>

	<select id="findBySaleId" resultMap="cn.superdesk.uniorder.dao.mapper.unified.UnifiedSupplierCostConfigMapper.BaseResultMap" parameterType="java.lang.Long">
		select
		<include refid="cn.superdesk.uniorder.dao.mapper.unified.UnifiedSupplierCostConfigMapper.Base_Column_List"/>
		from
			unified_supplier_cost_config
		<where>
			and sale_id = #{saleId}
		</where>
	</select>

</mapper>