<?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.jeeplus.modules.sg.mapper.JkxlMapper">
	<select id="getValue" parameterType="String" resultType="com.jeeplus.modules.sg.entity.RuleRatio">
		select value from sg_rule_ratio
		<where>
			ratio_name = #{ratioName}
		</where>
	</select>

	<select id="getList" parameterType="String" resultType="com.jeeplus.modules.sg.entity.JkxlData">
        SELECT
         a.describe,
         a.short_id as wbsCode,
         a.parent_node as parentNode,
         a.state,
         b.id,
         b.original_total_cost as originalTotalCost,
         b.original_rg_cost as originalRgCost,
         b.original_cbr_cost as originalCbrCost,
         b.original_fbr_cost as originalFbrCost,
         b.original_jx_cost as originalJxCost,
         b.rg_cost as rgCost,
         b.cbr_cost as cbrCost,
         b.fbr_cost as fbrCost,
         b.jx_cost as jxCost,
         b.measures_fee1 as measuresFee1,
         b.measures_fee2 as measuresFee2,
         b.other_cost as otherCost,
         b.tex as tex,
         b.fees as fees,
         b.zjgc_fee as zjgcFee,
         b.total_fee as totalFee,
         b.original_rate as originalRate,
         b.bz_fee as bzFee,
         b.jk_fee as jkFee
         FROM sg_wbs_elements_data a LEFT JOIN sg_wbs_fee b on a.short_id = b.wbs_code
         and b.id = #{id}
	</select>


	<select id="findList" parameterType="String" resultType="com.jeeplus.modules.sg.entity.JkxlData">
		 SELECT
		 a.id as wbsId,
         a.project_id as projectId,
         a.describe,
         a.short_id as wbsCode,
         a.subject_allocate as subjectAllocate,
         a.mount_matter as mountMatter,
         a.mount_server as mountServer,
         b.total_fee as totalFee
         FROM sg_wbs_elements a LEFT JOIN sg_wbs_fee b on a.short_id = b.wbs_code
         and b.id = #{id}
         order by short_id
	</select>


	<insert id="save" parameterType="com.jeeplus.modules.sg.entity.JkxlData">
		insert into sg_wbs_fee
		(id,
		 wbs_code,
		 original_total_cost,
		 original_rate,
		 original_rg_cost,
		 original_cbr_cost,
		 original_fbr_cost,
		 original_jx_cost,
		 rg_cost,
		 cbr_cost,
		 fbr_cost,
		 jx_cost,
		 measures_fee1,
		 measures_fee2,
		 other_cost,
		 fees,
		 tex,
		 total_fee,
		 bz_fee,
		 jk_fee,
		 zjgc_fee
		) values (
		 #{id},
		 #{wbsCode},
		 #{originalTotalCost},
		 #{originalRate},
		 #{originalRgCost},
		 #{originalCbrCost},
		 #{originalFbrCost},
		 #{originalJxCost},
		 #{rgCost},
		 #{cbrCost},
		 #{fbrCost},
		 #{jxCost},
		 #{measuresFee1},
		 #{measuresFee2},
		 #{otherCost},
		 #{fees},
		 #{tex},
		 #{totalFee},
		 #{bzFee},
		 #{jkFee},
		 #{zjgcFee}
		)
	</insert>

	<insert id="saveProject" parameterType="com.jeeplus.modules.sg.entity.WbsProject">
		insert into sg_wbs_project
		(id,
		 project_name,
		 create_date
		) values (
		 #{id},
		 #{name},
		 #{createDate}
		)
	</insert>

    <!--<update id="updateData" parameterType="com.jeeplus.modules.sg.entity.WbsProject">-->
          <!--update sg_wbs_fee set-->

          <!--<where>-->
              <!--id = #{id} and wbs_code = #{wbsCode}-->
          <!--</where>-->
    <!--</update>-->

	<select id="getTzFee" parameterType="com.jeeplus.modules.sg.entity.TzData" resultType="com.jeeplus.modules.sg.entity.TzData">
		select id,type,fee from sg_wbs_fee_tz
		<where>
			<if test="type != null and type != ''">
				type = #{type} and
			</if>
			id = #{id}
		</where>
		order by type
	</select>

	<update id="updateTzFee" parameterType="com.jeeplus.modules.sg.entity.TzData">
		update sg_wbs_fee_tz set fee = #{fee}
		<where>
			<if test="type != null and type != ''">
				type = #{type} and
			</if>
			id = #{id}
		</where>
	</update>

	<insert id="saveTzFee" parameterType="com.jeeplus.modules.sg.entity.TzData">
		insert into sg_wbs_fee_tz
		(
		 id,
		 type,
		 fee
		)values (
		#{id},
		#{type},
		#{fee}
		)
	</insert>



	
</mapper>