<?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.settlement.mapper.DataMaintenanceMapper">
    
	<sql id="infoColumns">
		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.project_id AS "projectId",
		a.design_units AS "designUnits",
		a.construction_units AS "constructionUnits",
		a.address,
		a.property,
		a.investment,
		a.start_date AS "startDate",
		a.end_date AS "endDate",
		a.approval_number AS "approvalNumber",
		a.building_fee AS "buildingFee",
		a.install_fee AS "installFee",
		a.equipment_fee AS "equipmentFee",
		a.material_fee AS "materialFee",
		a.design_fee AS "designFee",
		a.supervision_fee AS "supervisionFee",
		a.preliminaryWork_fee AS "preliminaryWorkFee",
		a.damages AS "damages",
		a.management_fee AS "managementFee",
		a.total_fee AS "totalFee"
	</sql>

    
	<select id="get" resultType="MaintainData" >
		SELECT 
			<include refid="infoColumns"/>
		FROM js_maintain_data a
		WHERE a.project_id = #{id}
	</select>
	
	<select id="findList" resultType="MaintainData" >
		SELECT 
			<include refid="infoColumns"/>
		FROM js_maintain_data a
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			${dataScope}
			<if test="projectIds != null ">
				AND a.project_id in
                <foreach collection="projectIds" index="index" item="item" open="(" separator="," close=")">
                #{item}
                </foreach>
			</if>
			<if test="projectId != null and projectId != ''">
				AND a.project_id LIKE CONCAT(CONCAT('%',#{projectId},'%'))
			</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="MaintainData" >
		SELECT 
			<include refid="infoColumns"/>
		FROM js_maintain_data 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_maintain_data(
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			project_id,
			design_units,
		    construction_units,
		    address,
		    property,
		    investment,
			start_date,
			end_date,
			approval_number,
			building_fee,
			install_fee,
			equipment_fee,
			material_fee,
			design_fee,
			supervision_fee,
			preliminaryWork_fee,
			damages,
			management_fee,
			total_fee
		) VALUES (
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{projectId},
			#{designUnits},
			#{constructionUnits},
			#{address},
			#{property},
			#{investment},
			#{startDate},
			#{endDate},
			#{approvalNumber},
			#{buildingFee},
			#{installFee},
			#{equipmentFee},
			#{materialFee},
			#{designFee},
			#{supervisionFee},
			#{preliminaryWorkFee},
			#{damages},
			#{managementFee},
			#{totalFee}
		)
	</insert>

    <insert id="insertList">
        replace INTO js_maintain_data(
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			project_id,
		    design_units,
		    construction_units,
		    address,
		    property,
		    investment,
			start_date,
			end_date,
			approval_number,
			building_fee,
			install_fee,
			equipment_fee,
			material_fee,
			design_fee,
			supervision_fee,
			preliminaryWork_fee,
			damages,
			management_fee,
			total_fee
		) VALUES
        <foreach collection="list" item="item" index="index" separator="," >
		(

			#{item.createBy.id},
			#{item.createDate},
			#{item.updateBy.id},
			#{item.updateDate},
			#{item.remarks},
			#{item.delFlag},
			#{item.projectId},
			#{item.designUnits},
			#{item.constructionUnits},
			#{item.address},
			#{item.property},
			#{item.investment},
			#{item.startDate},
			#{item.endDate},
			#{item.approvalNumber},
			#{item.buildingFee},
			#{item.installFee},
			#{item.equipmentFee},
			#{item.materialFee},
			#{item.designFee},
			#{item.supervisionFee},
			#{item.preliminaryWorkFee},
			#{item.damages},
			#{item.managementFee},
			#{item.totalFee}
		)
        </foreach>
	</insert>
	
	<update id="update">
		UPDATE js_maintain_data SET
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			design_units = #{designUnits},
			construction_units = #{constructionUnits},
			address = #{address},
			property = #{property},
			investment = #{investment},
			start_date = #{startDate},
			end_date = #{endDate},
			approval_number = #{approvalNumber},
			building_fee = #{buildingFee},
			install_fee = #{installFee},
			equipment_fee = #{equipmentFee},
			material_fee = #{materialFee},
			design_fee = #{designFee},
			supervision_fee = #{supervisionFee},
			preliminaryWork_fee = #{preliminaryWorkFee},
			damages = #{damages},
			management_fee = #{managementFee},
			total_fee = #{totalFee}
		WHERE project_id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM js_maintain_data
		WHERE project_id = #{id}
	</update>

	<update id="deleteData">
		DELETE FROM js_maintain_data
		WHERE project_id = #{projectId}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE js_maintain_data SET
			del_flag = #{DEL_FLAG_DELETE}
		WHERE project_id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="TestNote" statementType="STATEMENT">
		select * FROM js_maintain_data  where ${propertyName} = '${value}'
	</select>

	<select id="findListMain" parameterType="java.util.List" resultType="MaintainData">
		select
		<include refid="infoColumns"/>
		FROM js_maintain_data a
		WHERE a.del_flag = '0'
		and a.project_id in
		<if test="list != null">
			<foreach collection="list" index="index" item="item" open="("
					 separator="," close=")">
				#{item}
			</foreach>
		</if>
	</select>
</mapper>