<?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.goafanti.common.dao.OrgActivityMapper" >
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.OrgActivity" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="uid" property="uid" jdbcType="VARCHAR" />
    <result column="activity_number" property="activityNumber" jdbcType="VARCHAR" />
    <result column="activity_name" property="activityName" jdbcType="VARCHAR" />
    <result column="start_date" property="startDate" jdbcType="TIMESTAMP" />
    <result column="end_date" property="endDate" jdbcType="TIMESTAMP" />
    <result column="participant" property="participant" jdbcType="VARCHAR" />
    <result column="project_mode" property="projectMode" jdbcType="INTEGER" />
    <result column="technical_field1" property="technicalField1" jdbcType="VARCHAR" />
    <result column="technical_field2" property="technicalField2" jdbcType="VARCHAR" />
    <result column="technical_field3" property="technicalField3" jdbcType="VARCHAR" />
    <result column="technical_source" property="technicalSource" jdbcType="INTEGER" />
    <result column="intellectual_property_number" property="intellectualPropertyNumber" jdbcType="VARCHAR" />
    <result column="budget" property="budget" jdbcType="DECIMAL" />
    <result column="first_year_expenditure" property="firstYearExpenditure" jdbcType="DECIMAL" />
    <result column="second_year_expenditure" property="secondYearExpenditure" jdbcType="DECIMAL" />
    <result column="third_year_expenditure" property="thirdYearExpenditure" jdbcType="DECIMAL" />
    <result column="implement" property="implement" jdbcType="VARCHAR" />
    <result column="technology_innovation" property="technologyInnovation" jdbcType="VARCHAR" />
    <result column="achievement" property="achievement" jdbcType="VARCHAR" />
    <result column="proof_url" property="proofUrl" jdbcType="VARCHAR" />
    <result column="deleted_sign" property="deletedSign" jdbcType="INTEGER" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, uid, activity_number, activity_name, start_date, end_date, participant, project_mode,
    technical_field1,  technical_field2, technical_field3, technical_source, intellectual_property_number, 
    budget, first_year_expenditure, second_year_expenditure, third_year_expenditure, 
    implement, technology_innovation, achievement, proof_url, deleted_sign
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from org_activity
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from org_activity
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.OrgActivity" >
    insert into org_activity (id, uid, activity_number, 
      activity_name, start_date, end_date, participant, project_mode,
      technical_field1, technical_field2, technical_field3, 
      technical_source, intellectual_property_number, 
      budget, first_year_expenditure, second_year_expenditure, 
      third_year_expenditure, implement, technology_innovation, 
      achievement, proof_url, deleted_sign
      )
    values (#{id,jdbcType=VARCHAR}, #{uid,jdbcType=VARCHAR}, #{activityNumber,jdbcType=VARCHAR}, 
      #{activityName,jdbcType=VARCHAR}, #{startDate,jdbcType=TIMESTAMP}, #{endDate,jdbcType=TIMESTAMP}, #{participant,jdbcType=VARCHAR},
      #{projectMode,jdbcType=INTEGER}, #{technicalField1,jdbcType=VARCHAR}, #{technicalField2,jdbcType=VARCHAR}, #{technicalField3,jdbcType=VARCHAR}, 
      #{technicalSource,jdbcType=INTEGER}, #{intellectualPropertyNumber,jdbcType=VARCHAR}, 
      #{budget,jdbcType=DECIMAL}, #{firstYearExpenditure,jdbcType=DECIMAL}, #{secondYearExpenditure,jdbcType=DECIMAL}, 
      #{thirdYearExpenditure,jdbcType=DECIMAL}, #{implement,jdbcType=VARCHAR}, #{technologyInnovation,jdbcType=VARCHAR}, 
      #{achievement,jdbcType=VARCHAR}, #{proofUrl,jdbcType=VARCHAR}, #{deletedSign,jdbcType=INTEGER}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.OrgActivity" >
    insert into org_activity
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="uid != null" >
        uid,
      </if>
      <if test="activityNumber != null" >
        activity_number,
      </if>
      <if test="activityName != null" >
        activity_name,
      </if>
      <if test="startDate != null" >
        start_date,
      </if>
      <if test="endDate != null" >
        end_date,
      </if>
      <if test="participant != null" >
        participant,
      </if>
       <if test="projectMode != null" >
        project_mode,
      </if>
      <if test="technicalField1 != null" >
        technical_field1,
      </if>
      <if test="technicalField2 != null" >
        technical_field2,
      </if>
      <if test="technicalField3 != null" >
        technical_field3,
      </if>
      <if test="technicalSource != null" >
        technical_source,
      </if>
      <if test="intellectualPropertyNumber != null" >
        intellectual_property_number,
      </if>
      <if test="budget != null" >
        budget,
      </if>
      <if test="firstYearExpenditure != null" >
        first_year_expenditure,
      </if>
      <if test="secondYearExpenditure != null" >
        second_year_expenditure,
      </if>
      <if test="thirdYearExpenditure != null" >
        third_year_expenditure,
      </if>
      <if test="implement != null" >
        implement,
      </if>
      <if test="technologyInnovation != null" >
        technology_innovation,
      </if>
      <if test="achievement != null" >
        achievement,
      </if>
      <if test="proofUrl != null" >
        proof_url,
      </if>
      <if test="deletedSign != null" >
        deleted_sign,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="uid != null" >
        #{uid,jdbcType=VARCHAR},
      </if>
      <if test="activityNumber != null" >
        #{activityNumber,jdbcType=VARCHAR},
      </if>
      <if test="activityName != null" >
        #{activityName,jdbcType=VARCHAR},
      </if>
      <if test="startDate != null" >
        #{startDate,jdbcType=TIMESTAMP},
      </if>
      <if test="endDate != null" >
        #{endDate,jdbcType=TIMESTAMP},
      </if>
       <if test="participant != null" >
        #{participant,jdbcType=VARCHAR},
      </if>
       <if test="projectMode != null" >
        #{projectMode,jdbcType=INTEGER},
      </if>
      <if test="technicalField1 != null" >
        #{technicalField1,jdbcType=VARCHAR},
      </if>
      <if test="technicalField2 != null" >
        #{technicalField2,jdbcType=VARCHAR},
      </if>
      <if test="technicalField3 != null" >
        #{technicalField3,jdbcType=VARCHAR},
      </if>
      <if test="technicalSource != null" >
        #{technicalSource,jdbcType=INTEGER},
      </if>
      <if test="intellectualPropertyNumber != null" >
        #{intellectualPropertyNumber,jdbcType=VARCHAR},
      </if>
      <if test="budget != null" >
        #{budget,jdbcType=DECIMAL},
      </if>
      <if test="firstYearExpenditure != null" >
        #{firstYearExpenditure,jdbcType=DECIMAL},
      </if>
      <if test="secondYearExpenditure != null" >
        #{secondYearExpenditure,jdbcType=DECIMAL},
      </if>
      <if test="thirdYearExpenditure != null" >
        #{thirdYearExpenditure,jdbcType=DECIMAL},
      </if>
      <if test="implement != null" >
        #{implement,jdbcType=VARCHAR},
      </if>
      <if test="technologyInnovation != null" >
        #{technologyInnovation,jdbcType=VARCHAR},
      </if>
      <if test="achievement != null" >
        #{achievement,jdbcType=VARCHAR},
      </if>
       <if test="proofUrl != null" >
        #{proofUrl,jdbcType=VARCHAR},
      </if>
       <if test="deletedSign != null" >
        #{deletedSign,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.OrgActivity" >
    update org_activity
    <set >
      <if test="uid != null" >
        uid = #{uid,jdbcType=VARCHAR},
      </if>
      <if test="activityNumber != null" >
        activity_number = #{activityNumber,jdbcType=VARCHAR},
      </if>
      <if test="activityName != null" >
        activity_name = #{activityName,jdbcType=VARCHAR},
      </if>
      <if test="startDate != null" >
        start_date = #{startDate,jdbcType=TIMESTAMP},
      </if>
      <if test="endDate != null" >
        end_date = #{endDate,jdbcType=TIMESTAMP},
      </if>
      <if test="participant != null" >
        participant = #{participant,jdbcType=VARCHAR},
      </if>
      <if test="projectMode != null" >
        project_mode = #{projectMode,jdbcType=INTEGER},
      </if>
      <if test="technicalField1 != null" >
        technical_field1 = #{technicalField1,jdbcType=VARCHAR},
      </if>
      <if test="technicalField2 != null" >
        technical_field2 = #{technicalField2,jdbcType=VARCHAR},
      </if>
      <if test="technicalField3 != null" >
        technical_field3 = #{technicalField3,jdbcType=VARCHAR},
      </if>
      <if test="technicalSource != null" >
        technical_source = #{technicalSource,jdbcType=INTEGER},
      </if>
      <if test="intellectualPropertyNumber != null" >
        intellectual_property_number = #{intellectualPropertyNumber,jdbcType=VARCHAR},
      </if>
      <if test="budget != null" >
        budget = #{budget,jdbcType=DECIMAL},
      </if>
      <if test="firstYearExpenditure != null" >
        first_year_expenditure = #{firstYearExpenditure,jdbcType=DECIMAL},
      </if>
      <if test="secondYearExpenditure != null" >
        second_year_expenditure = #{secondYearExpenditure,jdbcType=DECIMAL},
      </if>
      <if test="thirdYearExpenditure != null" >
        third_year_expenditure = #{thirdYearExpenditure,jdbcType=DECIMAL},
      </if>
      <if test="implement != null" >
        implement = #{implement,jdbcType=VARCHAR},
      </if>
      <if test="technologyInnovation != null" >
        technology_innovation = #{technologyInnovation,jdbcType=VARCHAR},
      </if>
      <if test="achievement != null" >
        achievement = #{achievement,jdbcType=VARCHAR},
      </if>
       <if test="proofUrl != null" >
        proof_url = #{proofUrl,jdbcType=VARCHAR},
      </if>
      <if test="deletedSign != null" >
        deleted_sign = #{deletedSign,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.OrgActivity" >
    update org_activity
    set uid = #{uid,jdbcType=VARCHAR},
      activity_number = #{activityNumber,jdbcType=VARCHAR},
      activity_name = #{activityName,jdbcType=VARCHAR},
      start_date = #{startDate,jdbcType=TIMESTAMP},
      end_date = #{endDate,jdbcType=TIMESTAMP},
      participant = #{participant,jdbcType=VARCHAR},
      project_mode = #{projectMode,jdbcType=INTEGER},
      technical_field1 = #{technicalField1,jdbcType=VARCHAR},
      technical_field2 = #{technicalField2,jdbcType=VARCHAR},
      technical_field3 = #{technicalField3,jdbcType=VARCHAR},
      technical_source = #{technicalSource,jdbcType=INTEGER},
      intellectual_property_number = #{intellectualPropertyNumber,jdbcType=VARCHAR},
      budget = #{budget,jdbcType=DECIMAL},
      first_year_expenditure = #{firstYearExpenditure,jdbcType=DECIMAL},
      second_year_expenditure = #{secondYearExpenditure,jdbcType=DECIMAL},
      third_year_expenditure = #{thirdYearExpenditure,jdbcType=DECIMAL},
      implement = #{implement,jdbcType=VARCHAR},
      technology_innovation = #{technologyInnovation,jdbcType=VARCHAR},
      achievement = #{achievement,jdbcType=VARCHAR},
      internal_labor_cost = #{internalLaborCost,jdbcType=INTEGER},
      internal_direct_cost = #{internalDirectCost,jdbcType=INTEGER},
      internal_depreciation_cost = #{internalDepreciationCost,jdbcType=INTEGER},
      internal_amortization_cost = #{internalAmortizationCost,jdbcType=INTEGER},
      internal_design_cost = #{internalDesignCost,jdbcType=INTEGER},
      internal_equipment_cost = #{internalEquipmentCost,jdbcType=INTEGER},
      internal_other_cost = #{internalOtherCost,jdbcType=INTEGER},
      external_total_cost = #{externalTotalCost,jdbcType=INTEGER},
      external_abroad_cost = #{externalAbroadCost,jdbcType=INTEGER},
      enterprise_filler = #{enterpriseFiller,jdbcType=VARCHAR},
      sign_date = #{signDate,jdbcType=TIMESTAMP},
      sort_number = #{sortNumber,jdbcType=VARCHAR},
      proof_url = #{proofUrl,jdbcType=VARCHAR},
      deleted_sign = #{deletedSign,jdbcType=INTEGER}
    where id = #{id,jdbcType=VARCHAR}
  </update>
  
  <select id="findOrgActivityListByPage" parameterType="java.lang.String" resultMap="BaseResultMap">
  	 select 
    id, uid, activity_number as activityNumber, activity_name as activityName, 
    technical_field1 as technicalField1, technical_field2 as technicalField2, technical_field3 as technicalField3,
    technical_source as technicalSource, intellectual_property_number as intellectualPropertyNumber,
    start_date as startDate, end_date as endDate
    from org_activity
    where deleted_sign = 0
    <if test="uid != null">
	    and  uid = #{uid,jdbcType=VARCHAR}
	</if>
    <if test="activityNumber != null">
    	and  activity_number = #{activityNumber,jdbcType=VARCHAR}
    </if>
    <if test="activityName != null">
    	and  activity_name= #{activityName,jdbcType=VARCHAR}
    </if>
    <if test="startDate != null">
    	and  start_date <![CDATA[ >= ]]> #{startDate,jdbcType=TIMESTAMP}
    </if>
    <if test="endDate != null">
    	and  end_date <![CDATA[ < ]]> #{endDate,jdbcType=TIMESTAMP}
    </if>
    order by start_date desc
    <if test="page_sql != null">
    	${page_sql}
    </if>
  </select>
  
   <select id="findOrgActivityCount" resultType="java.lang.Integer" parameterType="String">
  	 select count(1) 
    from org_activity
    where deleted_sign = 0
    <if test="uid != null">
	    and  uid = #{uid,jdbcType=VARCHAR}
	</if>
    <if test="activityNumber != null">
    	and  activity_number = #{activityNumber,jdbcType=VARCHAR}
    </if>
    <if test="activityName != null">
    	and  activity_name= #{activityName,jdbcType=VARCHAR}
    </if>
    <if test="startDate != null">
    	and  start_date <![CDATA[ >= ]]> #{startDate,jdbcType=TIMESTAMP}
    </if>
    <if test="endDate != null">
    	and  end_date <![CDATA[ < ]]> #{endDate,jdbcType=TIMESTAMP}
    </if>
  </select>
  
  <update id="batchDeleteByPrimaryKey" parameterType="java.util.List">
  	update org_activity set deleted_sign = 1
  	where  id in 
	<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
		#{item}
	</foreach>
  </update>
  
  
  
  <select id="selectAcivityList" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from org_activity
    where uid = #{1} and (start_date <![CDATA[ <> ]]> null and
    start_date 
		 >= (select  str_to_date(CONCAT(#{0}-2,'-01-01'), '%Y-%m-%d %H'))
				or  start_date   <![CDATA[ < ]]> (select  str_to_date(CONCAT(#{0}+1,'-01-01'), '%Y-%m-%d %H'))
	or end_date <![CDATA[ <> ]]> null and 
	end_date 
		 >= (select  str_to_date(CONCAT(#{0}-2,'-01-01'), '%Y-%m-%d %H'))
				or  end_date   <![CDATA[ < ]]> (select  str_to_date(CONCAT(#{0}+1,'-01-01'), '%Y-%m-%d %H'))
	)
	and deleted_sign = 0 order by start_date 
  </select>
 <!--  <select id="selectDetailById" parameterType="java.lang.String" resultMap="BaseResultMap">
  	
  </select> -->
</mapper>