<?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.financial.erpcredit.mapper.ErpCreditMapper">

	<sql id="erpColumns">
		a.id AS "id",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag",
		a.item_id As "itemId",
		a.item_name As "itemName",
		a.actual_investment As "actualInvestment",
		a.transfer_assets As "transferAssets",
		a.cons_building_fee As "consBuildingFee",
		a.cons_install_fee As "consInstallFee",
		a.cons_total_fee As "consTotalFee",
		a.other_supervisor_fee As "otherSupervisorFee",
		a.other_design_fee As "otherDesignFee",
		a.other_bework_fee As "otherBeWorkFee",
		a.other_build_loan As "otherBuildLoan",
		a.other_line_damages As "otherLineDamages",
		a.other_legal_manage As "otherLegalManage",
		a.other_total_fee As "otherTotalFee",
		a.tenkv_model As "tenKvModel",
		a.tenkv_unit As "tenKvUnit",
		a.tenkv_length As "tenKvLength",
		a.tenkv_line_length As "tenKvLineLength",
		a.tenkv_its_line As "tenKvItsLine",
		a.tenkv_ites_fhv_follow As "tenKvItesFhvFollow",
		a.the_input_tax As "theInputTax",
		a.ten_supplier_name As "supplierName",
	  	a.cable_tube As "cableTube",
 		a.status As "status"
	</sql>

	<select id="get" resultType="ErpCredit" >
		SELECT
		<include refid="erpColumns"/>
		FROM js_erp_credit a
		WHERE a.id = #{id}
	</select>

	<select id="findList" resultType="ErpCredit" >
		SELECT
		<include refid="erpColumns"/>
		FROM js_erp_credit a
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
			<if test="itemId != null and itemId != ''">
				AND a.item_id LIKE CONCAT(CONCAT('%',#{itemId},'%'))
			</if>
			<if test="status!=null and status !=''">
				AND a.status = #{status}
			</if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>

	<select id="findAllList" resultType="ErpCredit" >
		SELECT
		<include refid="erpColumns"/>
		FROM js_erp_credit a
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>

	<insert id="insert">
		INSERT INTO js_erp_credit(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			item_id,
			item_name,
			actual_investment,
			transfer_assets,
			cons_building_fee,
			cons_install_fee,
			cons_total_fee,
			other_supervisor_fee,
			other_design_fee,
			other_bework_fee,
			other_build_loan,
			other_line_damages,
			other_legal_manage,
			other_total_fee,
			tenkv_model,
			tenkv_unit,
			tenkv_length,
			tenkv_line_length,
			tenkv_its_line,
			tenkv_ites_fhv_follow,
			the_input_tax,
			ten_supplier_name,
			cable_tube,
			status
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{itemId},
			#{itemName},
			#{actualInvestment},
			#{transferAssets},
    		#{consBuildingFee},
    		#{consInstallFee},
    		#{consTotalFee},
    		#{otherSupervisorFee},
    		#{otherDesignFee},
    		#{otherBeWorkFee},
    		#{otherBuildLoan},
    		#{otherLineDamages},
    		#{otherLegalManage},
    		#{otherTotalFee},
    		#{tenKvModel},
    		#{tenKvUnit},
    		#{tenKvLength},
    		#{tenKvLineLength},
    		#{tenKvItsLine},
    		#{tenKvItesFhvFollow},
    		#{theInputTax},
    		#{supplierName},
    		#{cableTube},
    		#{status}
		)
	</insert>

	<update id="update">
		UPDATE js_erp_credit SET
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			del_flag = #{delFlag},
			item_id = #{itemId},
			item_name = #{itemName},
			actual_investment = #{actualInvestment},
			transfer_assets = #{transferAssets},
			cons_building_fee = #{consBuildingFee},
			cons_install_fee = #{consInstallFee},
			cons_total_fee = #{consInstallFee},
			other_supervisor_fee = #{otherSupervisorFee},
			other_design_fee = #{otherDesignFee},
			other_bework_fee = #{otherBeWorkFee},
			other_build_loan = #{otherBuildLoan},
			other_line_damages = #{otherLineDamages},
			other_legal_manage =#{otherLegalManage},
			other_total_fee = #{otherTotalFee},
			tenkv_model = #{tenKvModel},
			tenkv_unit = #{tenKvUnit},
			tenkv_length = #{tenKvLength},
			tenkv_line_length = #{tenKvLineLength},
			tenkv_its_line = #{tenKvItsLine},
			tenkv_ites_fhv_follow = #{tenKvItesFhvFollow},
			the_input_tax = #{theInputTax},
			ten_supplier_name=#{supplierName}
		WHERE id = #{id}
	</update>


	<!--物理删除-->
	<update id="delete">
		DELETE FROM js_erp_credit
		WHERE id = #{id}
	</update>

	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE js_erp_credit SET
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>


	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="ErpCredit" statementType="STATEMENT">
		select * FROM js_erp_credit where ${propertyName} = '${value}'
	</select>

	<select id="findErpCreditList" parameterType="java.util.List" resultType="erpCredit">
		select
		<include refid="erpColumns"/>
		FROM js_erp_credit a
		WHERE a.del_flag = '0'
		and a.item_id in
		<if test="list !=null">
			<foreach collection="list" index="index" item="item" open="("
					 separator="," close=")">
				#{item}
			</foreach>
		</if>
	</select>

	<delete id="deleteAll">
		delete from js_erp_credit
	</delete>

	<insert id="insertList">
		insert INTO js_erp_credit(
		id,
		create_by,
		create_date,
		update_by,
		update_date,
		remarks,
		del_flag,
		item_id,
		item_name,
		actual_investment,
		transfer_assets,
		cons_building_fee,
		cons_install_fee,
		cons_total_fee,
		other_supervisor_fee,
		other_design_fee,
		other_bework_fee,
		other_build_loan,
		other_line_damages,
		other_legal_manage,
		other_total_fee,
		tenkv_model,
		tenkv_unit,
		tenkv_length,
		tenkv_line_length,
		tenkv_its_line,
		tenkv_ites_fhv_follow,
		the_input_tax,
		ten_supplier_name,
		cable_tube,
		status
		) VALUES
		<foreach collection="list" item="item" index="index" separator="," >
			(
			#{item.id},
			#{item.createBy.id},
			#{item.createDate},
			#{item.updateBy.id},
			#{item.updateDate},
			#{item.remarks},
			#{item.delFlag},
			#{item.itemId},
			#{item.itemName},
			#{item.actualInvestment},
			#{item.transferAssets},
			#{item.consBuildingFee},
			#{item.consInstallFee},
			#{item.consTotalFee},
			#{item.otherSupervisorFee},
			#{item.otherDesignFee},
			#{item.otherBeWorkFee},
			#{item.otherBuildLoan},
			#{item.otherLineDamages},
			#{item.otherLegalManage},
			#{item.otherTotalFee},
			#{item.tenKvModel},
			#{item.tenKvUnit},
			#{item.tenKvLength},
			#{item.tenKvLineLength},
			#{item.tenKvItsLine},
			#{item.tenKvItesFhvFollow},
			#{item.theInputTax},
			#{item.supplierName},
			#{item.cableTube},
			#{item.status}
			)
		</foreach>
	</insert>
</mapper>