<?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.TechProjectMapper">
	<resultMap id="BaseResultMap" type="com.goafanti.common.model.TechProject">
		<id column="id" property="id" jdbcType="VARCHAR" />
		<result column="uid" property="uid" jdbcType="VARCHAR" />
		<result column="serial_number" property="serialNumber"
			jdbcType="INTEGER" />
		<result column="contacts" property="contacts" jdbcType="INTEGER" />
		<result column="department" property="department" jdbcType="VARCHAR" />
		<result column="dispatch_info" property="dispatchInfo"
			jdbcType="VARCHAR" />
		<result column="project_name" property="projectName" jdbcType="VARCHAR" />
		<result column="project_catagory" property="projectCatagory"
			jdbcType="VARCHAR" />
		<result column="tech_field" property="techField" jdbcType="VARCHAR" />
		<result column="project_des" property="projectDes" jdbcType="VARCHAR" />
		<result column="project_mode" property="projectMode" jdbcType="INTEGER" />
		<result column="project_approval" property="projectApproval"
			jdbcType="DECIMAL" />
		<result column="subsidy" property="subsidy" jdbcType="INTEGER" />
		<result column="consultant" property="consultant" jdbcType="VARCHAR" />
		<result column="approval_url" property="approvalUrl" jdbcType="VARCHAR" />
		<result column="state" property="state" jdbcType="INTEGER" />
		<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
		<result column="accept_date" property="acceptDate" jdbcType="TIMESTAMP" />
		<result column="approved_date" property="approvedDate"
			jdbcType="TIMESTAMP" />
		<result column="record_time" property="recordTime" jdbcType="TIMESTAMP" />
		<result column="deleted_sign" property="deletedSign" jdbcType="INTEGER" />
		<result column="founder" property="founder" jdbcType="VARCHAR" />
		<result column="contract_id" property="contractId" jdbcType="VARCHAR" />
		<result column="principal" property="principal" jdbcType="VARCHAR" />
	</resultMap>
	<sql id="Base_Column_List">
		id, uid, serial_number, contacts, department, dispatch_info,
		project_name, project_catagory,
		tech_field, project_des, project_mode, project_approval, subsidy, consultant,
		approval_url,
		state, create_time, accept_date, approved_date, record_time, deleted_sign,
		founder, contract_id, principal
	</sql>
	<select id="selectByPrimaryKey" resultMap="BaseResultMap"
		parameterType="java.lang.String">
		select
		<include refid="Base_Column_List" />
		from tech_project
		where id = #{id,jdbcType=VARCHAR}
	</select>
	<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
		delete from tech_project
		where id = #{id,jdbcType=VARCHAR}
	</delete>
	<insert id="insert" parameterType="com.goafanti.common.model.TechProject">
		insert into tech_project (id, uid, serial_number,
		contacts, department, dispatch_info,
		project_name, project_catagory, tech_field,
		project_des, project_mode, project_approval,
		subsidy, consultant, approval_url,
		state, create_time, accept_date,
		approved_date, record_time, deleted_sign, founder, contract_id, principal
		)
		values (#{id,jdbcType=VARCHAR}, #{uid,jdbcType=VARCHAR},
		#{serialNumber,jdbcType=INTEGER},
		#{contacts,jdbcType=INTEGER}, #{department,jdbcType=VARCHAR}, #{dispatchInfo,jdbcType=VARCHAR},
		#{projectName,jdbcType=VARCHAR}, #{projectCatagory,jdbcType=VARCHAR},
		#{techField,jdbcType=VARCHAR},
		#{projectDes,jdbcType=VARCHAR}, #{projectMode,jdbcType=INTEGER}, #{projectApproval,jdbcType=DECIMAL},
		#{subsidy,jdbcType=INTEGER}, #{consultant,jdbcType=VARCHAR},
		#{approvalUrl,jdbcType=VARCHAR},
		#{state,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{acceptDate,jdbcType=TIMESTAMP},
		#{approvedDate,jdbcType=TIMESTAMP}, #{recordTime,jdbcType=TIMESTAMP},
		#{deletedSign,jdbcType=INTEGER}, #{founder,jdbcType=VARCHAR}, #{contractId,jdbcType=VARCHAR},
		#{principal,jdbcType=VARCHAR}
		)
	</insert>
	<insert id="insertSelective" parameterType="com.goafanti.common.model.TechProject">
		insert into tech_project
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="id != null">
				id,
			</if>
			<if test="uid != null">
				uid,
			</if>
			<if test="serialNumber != null">
				serial_number,
			</if>
			<if test="contacts != null">
				contacts,
			</if>
			<if test="department != null">
				department,
			</if>
			<if test="dispatchInfo != null">
				dispatch_info,
			</if>
			<if test="projectName != null">
				project_name,
			</if>
			<if test="projectCatagory != null">
				project_catagory,
			</if>
			<if test="techField != null">
				tech_field,
			</if>
			<if test="projectDes != null">
				project_des,
			</if>
			<if test="projectMode != null">
				project_mode,
			</if>
			<if test="projectApproval != null">
				project_approval,
			</if>
			<if test="subsidy != null">
				subsidy,
			</if>
			<if test="consultant != null">
				consultant,
			</if>
			<if test="approvalUrl != null">
				approval_url,
			</if>
			<if test="state != null">
				state,
			</if>
			<if test="createTime != null">
				create_time,
			</if>
			<if test="acceptDate != null">
				accept_date,
			</if>
			<if test="approvedDate != null">
				approved_date,
			</if>
			<if test="recordTime != null">
				record_time,
			</if>
			<if test="deletedSign != null">
				deleted_sign,
			</if>
			<if test="founder != null">
				founder,
			</if>
			<if test="contractId != null">
				contract_id,
			</if>
			<if test="principal != null">
				principal,
			</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="serialNumber != null">
				#{serialNumber,jdbcType=INTEGER},
			</if>
			<if test="contacts != null">
				#{contacts,jdbcType=INTEGER},
			</if>
			<if test="department != null">
				#{department,jdbcType=VARCHAR},
			</if>
			<if test="dispatchInfo != null">
				#{dispatchInfo,jdbcType=VARCHAR},
			</if>
			<if test="projectName != null">
				#{projectName,jdbcType=VARCHAR},
			</if>
			<if test="projectCatagory != null">
				#{projectCatagory,jdbcType=VARCHAR},
			</if>
			<if test="techField != null">
				#{techField,jdbcType=VARCHAR},
			</if>
			<if test="projectDes != null">
				#{projectDes,jdbcType=VARCHAR},
			</if>
			<if test="projectMode != null">
				#{projectMode,jdbcType=INTEGER},
			</if>
			<if test="projectApproval != null">
				#{projectApproval,jdbcType=DECIMAL},
			</if>
			<if test="subsidy != null">
				#{subsidy,jdbcType=INTEGER},
			</if>
			<if test="consultant != null">
				#{consultant,jdbcType=VARCHAR},
			</if>
			<if test="approvalUrl != null">
				#{approvalUrl,jdbcType=VARCHAR},
			</if>
			<if test="state != null">
				#{state,jdbcType=INTEGER},
			</if>
			<if test="createTime != null">
				#{createTime,jdbcType=TIMESTAMP},
			</if>
			<if test="acceptDate != null">
				#{acceptDate,jdbcType=TIMESTAMP},
			</if>
			<if test="approvedDate != null">
				#{approvedDate,jdbcType=TIMESTAMP},
			</if>
			<if test="recordTime != null">
				#{recordTime,jdbcType=TIMESTAMP},
			</if>
			<if test="deletedSign != null">
				#{deletedSign,jdbcType=INTEGER},
			</if>
			<if test="founder != null">
				#{founder,jdbcType=VARCHAR},
			</if>
			<if test="contractId != null">
				#{contractId,jdbcType=VARCHAR},
			</if>
			<if test="principal != null">
				#{principal,jdbcType=VARCHAR},
			</if>
		</trim>
	</insert>
	<update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.TechProject">
		update tech_project
		<set>
			<if test="uid != null">
				uid = #{uid,jdbcType=VARCHAR},
			</if>
			<if test="serialNumber != null">
				serial_number = #{serialNumber,jdbcType=INTEGER},
			</if>
			<if test="contacts != null">
				contacts = #{contacts,jdbcType=INTEGER},
			</if>
			<if test="department != null">
				department = #{department,jdbcType=VARCHAR},
			</if>
			<if test="dispatchInfo != null">
				dispatch_info = #{dispatchInfo,jdbcType=VARCHAR},
			</if>
			<if test="projectName != null">
				project_name = #{projectName,jdbcType=VARCHAR},
			</if>
			<if test="projectCatagory != null">
				project_catagory = #{projectCatagory,jdbcType=VARCHAR},
			</if>
			<if test="techField != null">
				tech_field = #{techField,jdbcType=VARCHAR},
			</if>
			<if test="projectDes != null">
				project_des = #{projectDes,jdbcType=VARCHAR},
			</if>
			<if test="projectMode != null">
				project_mode = #{projectMode,jdbcType=INTEGER},
			</if>
			<if test="projectApproval != null">
				project_approval = #{projectApproval,jdbcType=DECIMAL},
			</if>
			<if test="subsidy != null">
				subsidy = #{subsidy,jdbcType=INTEGER},
			</if>
			<if test="consultant != null">
				consultant = #{consultant,jdbcType=VARCHAR},
			</if>
			<if test="approvalUrl != null">
				approval_url = #{approvalUrl,jdbcType=VARCHAR},
			</if>
			<if test="state != null">
				state = #{state,jdbcType=INTEGER},
			</if>
			<if test="createTime != null">
				create_time = #{createTime,jdbcType=TIMESTAMP},
			</if>
			<if test="acceptDate != null">
				accept_date = #{acceptDate,jdbcType=TIMESTAMP},
			</if>
			<if test="approvedDate != null">
				approved_date = #{approvedDate,jdbcType=TIMESTAMP},
			</if>
			<if test="recordTime != null">
				record_time = #{recordTime,jdbcType=TIMESTAMP},
			</if>
			<if test="deletedSign != null">
				deleted_sign = #{deletedSign,jdbcType=INTEGER},
			</if>
			<if test="founder != null">
				founder = #{founder,jdbcType=VARCHAR},
			</if>
			<if test="contractId != null">
				contract_id = #{contractId,jdbcType=VARCHAR},
			</if>
			<if test="principal != null">
				principal = #{principal,jdbcType=VARCHAR},
			</if>
		</set>
		where id = #{id,jdbcType=VARCHAR}
	</update>
	<update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.TechProject">
		update tech_project
		set uid = #{uid,jdbcType=VARCHAR},
		serial_number = #{serialNumber,jdbcType=INTEGER},
		contacts = #{contacts,jdbcType=INTEGER},
		department = #{department,jdbcType=VARCHAR},
		dispatch_info = #{dispatchInfo,jdbcType=VARCHAR},
		project_name = #{projectName,jdbcType=VARCHAR},
		project_catagory = #{projectCatagory,jdbcType=VARCHAR},
		tech_field = #{techField,jdbcType=VARCHAR},
		project_des = #{projectDes,jdbcType=VARCHAR},
		project_mode = #{projectMode,jdbcType=INTEGER},
		project_approval = #{projectApproval,jdbcType=DECIMAL},
		subsidy = #{subsidy,jdbcType=INTEGER},
		consultant = #{consultant,jdbcType=VARCHAR},
		approval_url = #{approvalUrl,jdbcType=VARCHAR},
		state = #{state,jdbcType=INTEGER},
		create_time = #{createTime,jdbcType=TIMESTAMP},
		accept_date = #{acceptDate,jdbcType=TIMESTAMP},
		approved_date = #{approvedDate,jdbcType=TIMESTAMP},
		record_time = #{recordTime,jdbcType=TIMESTAMP},
		deleted_sign = #{deletedSign,jdbcType=INTEGER},
		founder = #{founder,jdbcType=VARCHAR},
		contract_id = #{contractId,jdbcType=VARCHAR},
		principal = #{principal,jdbcType=VARCHAR}
		where id = #{id,jdbcType=VARCHAR}
	</update>

	<select id="findTechProjectClientListByPage" parameterType="java.lang.String"
		resultType="com.goafanti.techproject.bo.TechProjectClientListBo">
	    select p.id, p.uid, i.location_province as province, 
	        i.unit_name as unitName,  
		    p.serial_number as serialNumber, p.create_time as createTime, p.approved_date as approvedDate, 
		    p.accept_date as acceptDate, a.name as consultant, p.contacts,
		    p.project_name as projectName, p.project_catagory as projectCatagory, p.tech_field as techField, p.state
	    FROM  tech_project p
		LEFT JOIN organization_identity i on i.uid = p.uid
		LEFT JOIN admin a on p.consultant = a.id 
		where p.deleted_sign = 0 
		<if test ="uid != null">
	        and p.uid = #{uid,jdbcType=VARCHAR}
	    </if>
	    order by p.serial_number desc
	    <if test="page_sql!=null">
			${page_sql}
		</if>
	</select>
	
	<select id="findTechProjectClientCount" resultType="java.lang.Integer" parameterType="String">
 	select count(1)
    FROM  tech_project p
		LEFT JOIN organization_identity i on i.uid = p.uid
		LEFT JOIN admin a on p.consultant = a.id 
		where p.deleted_sign = 0 
    <if test ="uid != null">
        and p.uid = #{uid,jdbcType=VARCHAR}
    </if>
  </select>
  
  <select id ="findTechProjectManageListByPage" parameterType="java.lang.String" 
     resultType="com.goafanti.techproject.bo.TechProjectManageListBo">
  	 select p.id, p.uid, i.licence_province as province, p.contract_id as contractId,
	        i.unit_name as unitName,  
		    p.serial_number as serialNumber, p.create_time as createTime, p.approved_date as approvedDate, 
		    p.accept_date as acceptDate, a.name as consultant, p.contacts, ad.name as founder,
		    p.project_name as projectName, p.project_catagory as projectCatagory, p.tech_field as techField, p.state, 
        w.id as wid, w.website, w.account_number as accountNumber, w.department, 
        w.password, c.serial_number as contractNumber
	  FROM  tech_project p
		LEFT JOIN organization_identity i on i.uid = p.uid
		LEFT JOIN admin a on p.consultant = a.id 
		LEFT JOIN admin ad on p.founder = ad.id 
   	LEFT JOIN tech_website w on p.department = w.id 
    LEFT JOIN contract c on c.id = p.contract_id
    <if test="principal != null">
		left join contract_log l on p.contract_id=l.cid
	</if>
	where p.deleted_sign = 0 and (w.deleted_sign is  null or w.deleted_sign = 0) 
	<if test="principal != null">
		and l.principal = #{principal,jdbcType=VARCHAR}
	</if>
    <if test="contractId != null">
    	and p.contract_id = #{contractId,jdbcType=VARCHAR}
    </if>
      <if test="province != null">
    	and i.licence_province = #{province,jdbcType=INTEGER}
    </if>
     <if test="uid != null">
    	and p.uid = #{uid,jdbcType=VARCHAR}
    </if>
    <if test="unitName != null" >
    	and i.unit_name like CONCAT('%', #{unitName,jdbcType=VARCHAR}, '%')  
    </if>
     <if test="principal != null">
		group by p.id,i.id
	</if>
    order by p.serial_number desc
   <if test="page_sql!=null">
		${page_sql}
	</if>
  </select>
  
  <select id="findTechProjectManageCount" resultType="java.lang.Integer" parameterType="String">
 	select count(distinct(p.id))  
	 	FROM  tech_project p
		LEFT JOIN organization_identity i on i.uid = p.uid
		LEFT JOIN tech_website w on p.department = w.id 
     <if test="principal != null">
		left join contract_log l on p.contract_id=l.cid
	</if>
	where p.deleted_sign = 0 and (w.deleted_sign is  null or w.deleted_sign = 0) 
	<if test="principal != null">
		and l.principal = #{principal,jdbcType=VARCHAR}
	</if>
    <if test="contractId != null">
    	and p.contract_id = #{contractId,jdbcType=VARCHAR}
    </if>
      <if test="province != null">
    	and i.licence_province = #{province,jdbcType=INTEGER}
    </if>
     <if test="uid != null">
    	and p.uid = #{uid,jdbcType=VARCHAR}
    </if>
    <if test="unitName != null" >
    	and i.unit_name like CONCAT('%', #{unitName,jdbcType=VARCHAR}, '%')  
    </if>
  </select>
  
  <select id="selectProjectDetail" resultType="com.goafanti.techproject.bo.TechProjectDetailBo" parameterType="java.lang.String">
  	select 
  		 p.id, p.uid, i.licence_province as province, 
  		 i.licence_city as city, i.licence_area as area, i.postal_address as postalAddress,
	     i.unit_name as unitName,  i.org_code as orgCode, p.serial_number as serialNumber,  
		 a.name as consultant, p.contacts, p.project_des as projectDes, 
		 p.subsidy, p.dispatch_info as dispatchInfo, p.project_mode as projectMode, 
		 p.project_approval as projectApproval, p.approval_url as approvalUrl , p.department,
		 p.project_name as projectName, p.project_catagory as projectCatagory, p.tech_field as techField, 
		 p.state       
	FROM  tech_project p
		LEFT JOIN organization_identity i on i.uid = p.uid
		LEFT JOIN admin a on p.consultant = a.id 
	where p.deleted_sign = 0  and p.id = #{uid,jdbcType=VARCHAR}
  </select>
  
   <update id="batchDeleteByPrimaryKey" parameterType="java.util.List">
  	update tech_project set deleted_sign = 1
  	where  id in 
	<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
		#{item}
	</foreach>
  </update>
  
  <select id="countTechProjectDone"  resultType="java.lang.Integer">
	   select 
	   		count(1) 
	   from tech_project 
	   where uid = #{uid,jdbcType=VARCHAR}
	   and 
	   deleted_sign = 0 
	   and state in (6,8) 
	   and approved_date >= 
						(
							select  
								str_to_date(CONCAT(#{year,jdbcType=INTEGER}-3,'-01-01'), '%Y-%m-%d %H')
						)
   	   and approved_date  <![CDATA[ < ]]> 
						(
							select  
								str_to_date(CONCAT(#{year,jdbcType=INTEGER},'-01-01'), '%Y-%m-%d %H')
						)
  </select>
  
  <select id="countTechProjectUndone"  resultType="java.lang.Integer">
	   select 
	   		count(1) 
	   from tech_project 
	   where uid = #{uid,jdbcType=VARCHAR}
	   and deleted_sign = 0 
	   and state in (1,2,3,4,5,7)
	   and approved_date >= 
						(
							select  
								str_to_date(CONCAT(#{year,jdbcType=INTEGER}-3,'-01-01'), '%Y-%m-%d %H')
						)
   	   and approved_date  <![CDATA[ < ]]> 
						(
							select  
								str_to_date(CONCAT(#{year,jdbcType=INTEGER},'-01-01'), '%Y-%m-%d %H')
						) 
  </select>
  
  <select id="selectWebsiteUnitNames" parameterType="java.lang.String" resultType="com.goafanti.user.bo.OrgUnitNames">
  	select distinct(oi.uid), oi.unit_name as unitName 
		from tech_project tp 
		LEFT JOIN organization_identity oi on oi.uid = tp.uid
	 <if test="_parameter != null">
		LEFT JOIN tech_project_log tpl on tp.id = tpl.pid
	</if>
		where tp.deleted_sign = 0 
	<if test="_parameter != null">
		and tpl.principal = #{principal,jdbcType=VARCHAR}
	</if>
	 <if test="_parameter != null">
		group by tp.id,oi.id
	</if> 
  </select>
  
  <select id="listContractTechProjectByContractId" parameterType="java.lang.String" resultType="com.goafanti.techproject.bo.TechProjectContractListBo">
		select 
			tp.id, tp.uid, tp.contract_id as contractId, 
			tp.project_name as projectName, tp.project_catagory as projectCatagory, tp.state, 
			tp.tech_field as techField, a.name as principle
		from tech_project tp 
		left join admin a on a.id = tp.principal
		where tp.contract_id = #{contractId,jdbcType=VARCHAR} 
	</select>
	
  <insert id="batchInsert" parameterType="com.goafanti.common.model.TechProject">
   insert into tech_project (id, uid, serial_number,
		contacts, department, dispatch_info,
		project_name, project_catagory, tech_field,
		project_des, project_mode, project_approval,
		subsidy, consultant, approval_url,
		state, create_time, accept_date,
		approved_date, record_time, deleted_sign, founder, contract_id, principal
		)
    values 
    <foreach item="item" index="index" collection="list" separator=",">
      (
      	#{item.id,jdbcType=VARCHAR}, #{item.uid,jdbcType=VARCHAR},
		#{item.serialNumber,jdbcType=INTEGER},
		#{item.contacts,jdbcType=INTEGER}, #{item.department,jdbcType=VARCHAR}, #{item.dispatchInfo,jdbcType=VARCHAR},
		#{item.projectName,jdbcType=VARCHAR}, #{item.projectCatagory,jdbcType=VARCHAR},
		#{item.techField,jdbcType=VARCHAR},
		#{item.projectDes,jdbcType=VARCHAR}, #{item.projectMode,jdbcType=INTEGER}, #{item.projectApproval,jdbcType=DECIMAL},
		#{item.subsidy,jdbcType=INTEGER}, #{item.consultant,jdbcType=VARCHAR},
		#{item.approvalUrl,jdbcType=VARCHAR},
		#{item.state,jdbcType=INTEGER}, #{item.createTime,jdbcType=TIMESTAMP}, #{item.acceptDate,jdbcType=TIMESTAMP},
		#{item.approvedDate,jdbcType=TIMESTAMP}, #{item.recordTime,jdbcType=TIMESTAMP},
		#{item.deletedSign,jdbcType=INTEGER}, #{item.founder,jdbcType=VARCHAR}, #{item.contractId,jdbcType=VARCHAR},
		#{item.principal,jdbcType=VARCHAR}
	 )
  </foreach>
  </insert>
  
  <select id="findTechProjectNumByUid" parameterType="java.lang.String" resultType="java.lang.Integer">
  	select 
  		count(1)
  	from tech_project
  	where 
  		deleted_sign = 0
  	and uid = #{uid,jdbcType=VARCHAR}
  </select>

  <update id="batchDeleteByContractId" parameterType="java.util.List">
		update tech_project set deleted_sign = 1
		where contract_id in
		<foreach item="item" index="index" collection="list" open="("
			separator="," close=")">
			#{item}
		</foreach>
  </update>
	
  <select id="listProjectByPage" resultType="com.goafanti.techproject.bo.ProjectListBo">
	select
		a.id,
		a.serial_number as serialNumber,
		date_format(a.sign_date,'%Y-%m-%d %H:%i:%S') as signDate,
		date_format(a.create_time,'%Y-%m-%d %H:%i:%S') as projectTime,
		a.uid,
		a.status as projectStatus,
		a.task_distribution as taskDistribution,
		a.deleted_sign as deletedSign,
		a.order_no as orderNo,
		b.nickname as buyerName,
		b.type as buyerType,
		f.cname as projectType,
		c.create_time as orderTime,
		c.order_status as orderStatus,
		c.liquidation_status as liquidationStatus,
		c.approval,
		d.name as salesmanName,
		e.name as departmentName,
		g.name as principalName
	from
		contract a left join user b on
		a.uid = b.id left join t_order c on
		a.order_no = c.order_no left join admin d on
		c.salesman_id = d.id left join department e on
		d.department_id = e.id left join business_category f on
		a.type = f.id left join admin g on
		a.principal = g.id
	where 1=1
	<if test="deletedSign != null">
		and a.deleted_sign = #{deletedSign,jdbcType=INTEGER}
	</if>
	<if test="orderNo != null and orderNo != ''">
		and a.order_no = #{orderNo,jdbcType=VARCHAR}
	</if>
	<if test="serialNumber != null and serialNumber != ''">
		and a.serial_number = #{serialNumber,jdbcType=VARCHAR}
	</if>
	<if test="setUpStartDate != null and setUpStartDate != ''">
		and a.create_time &gt; #{setUpStartDate,jdbcType=TIMESTAMP}
	</if>
	<if test="setUpEndDate != null and setUpEndDate != ''">
		and a.create_time &lt; #{setUpEndDate,jdbcType=TIMESTAMP}
	</if>
	<if test="taskDistribution != null">
		and a.task_distribution = #{taskDistribution,jdbcType=INTEGER}
	</if>
	<if test="buyerName != null and buyerName != ''">
		and b.nickname like concat('%',#{buyerName,jdbcType=VARCHAR},'%')
	</if>
	<if test="salesmanName != null and salesmanName !=''">
		and d.name = #{salesmanName,jdbcType=VARCHAR}
	</if>
	<if test="depId != null and depId != ''">
		and d.department_id = #{depId,jdbcType=VARCHAR}
	</if>
	<if test="orderStartDate != null and orderStartDate != ''">
		and c.create_time &gt; #{orderStartDate,jdbcType=TIMESTAMP}
	</if>
	<if test="orderEndDate != null and orderEndDate != ''">
		and c.create_time &lt; #{orderEndDate,jdbcType=TIMESTAMP}
	</if>
	<if test="principalName != null and principalName != ''">
		and g.name = #{principalName,jdbcType=VARCHAR}
	</if>
		order by a.create_time desc
	<if test="page_sql != null">
		${page_sql}
	</if>
  </select>
  <select id="listProjectCount" resultType="java.lang.Integer">
  	select
		count(0)
	from
		contract a left join user b on
		a.uid = b.id left join t_order c on
		a.order_no = c.order_no left join admin d on
		c.salesman_id = d.id left join department e on
		d.department_id = e.id left join business_category f on
		a.type = f.id left join admin g on
		a.principal = g.id
	where 1=1
	<if test="deletedSign != null">
		and a.deleted_sign = #{deletedSign,jdbcType=INTEGER}
	</if>
	<if test="orderNo != null and orderNo != ''">
		and a.order_no = #{orderNo,jdbcType=VARCHAR}
	</if>
	<if test="serialNumber != null and serialNumber != ''">
		and a.serial_number = #{serialNumber,jdbcType=VARCHAR}
	</if>
	<if test="setUpStartDate != null and setUpStartDate != ''">
		and a.create_time &gt; #{setUpStartDate,jdbcType=TIMESTAMP}
	</if>
	<if test="setUpEndDate != null and setUpEndDate != ''">
		and a.create_time &lt; #{setUpEndDate,jdbcType=TIMESTAMP}
	</if>
	<if test="taskDistribution != null">
		and a.task_distribution = #{taskDistribution,jdbcType=INTEGER}
	</if>
	<if test="buyerName != null and buyerName != ''">
		and b.nickname like concat('%',#{buyerName,jdbcType=VARCHAR},'%')
	</if>
	<if test="salesmanName != null and salesmanName !=''">
		and d.name = #{salesmanName,jdbcType=VARCHAR}
	</if>
	<if test="depId != null and depId != ''">
		and d.department_id = #{depId,jdbcType=VARCHAR}
	</if>
	<if test="orderStartDate != null and orderStartDate != ''">
		and c.create_time &gt; #{orderStartDate,jdbcType=TIMESTAMP}
	</if>
	<if test="orderEndDate != null and orderEndDate != ''">
		and c.create_time &lt; #{orderEndDate,jdbcType=TIMESTAMP}
	</if>
	<if test="principalName != null and principalName != ''">
		and g.name = #{principalName,jdbcType=VARCHAR}
	</if>
  </select>
  
  <select id="selectTechProjectDetail" resultType="com.goafanti.techproject.bo.ProjectDetailBo">
	  <choose>
	  	<when test="buyerType == 0">
	  	  		  select
	a.id,
	a.serial_number as serialNumber,
	date_format( a.sign_date, '%Y-%m-%d %H:%i:%S' ) as signDate,
	a.sign_comment as signComment,
	date_format( a.complete_date, '%Y-%m-%d %H:%i:%S' ) as completeDate,
	a.complete_comment as completeComment,
	a.uid,
	a.status as projectStatus,
	a.deleted_sign as deletedSign,
	a.order_no as orderNo,
	b.nickname as buyerName,
	d.name as principalName,
	f.name as buyerProvince,
	g.cname as projectType,
	t.contract_no as contractNo,
	h.name as salesmanName
from
	contract a left join user b on
	a.uid = b.id left join admin d on
	a.principal = d.id left join user_identity e on
	a.uid = e.uid left join district_glossory f on
	e.province = f.id left join business_category g on
	a.type = g.id left join t_order t on
	a.order_no=t.order_no left join admin h on 
	t.salesman_id=h.id
			where a.id = #{contractId,jdbcType=VARCHAR}
	  	</when>
	  		<when test="buyerType == 1">
	  			select
				a.id,
				a.serial_number as serialNumber,
				date_format(a.sign_date,'%Y-%m-%d %H:%i:%S') as signDate,
				a.sign_comment as signComment,
				date_format(a.complete_date,'%Y-%m-%d %H:%i:%S') as completeDate,
				a.complete_comment as completeComment,
				a.uid,
				a.status as projectStatus,
				a.deleted_sign as deletedSign,
				a.order_no as orderNo,
				b.nickname as buyerName,
				d.name as principalName,
				f.name as buyerProvince,
				g.cname as projectType,
				t.contract_no as contractNo,
				h.name as salesmanName
			from
				contract a left join user b on
				a.uid = b.id left join admin d on
				a.principal = d.id left join organization_identity e on
				a.uid = e.uid left join district_glossory f on
				e.location_province  = f.id left join business_category g on
				a.type = g.id  left join t_order t on
				a.order_no=t.order_no left join admin h on 
				t.salesman_id=h.id
			where a.id = #{contractId,jdbcType=VARCHAR}
	  	</when>
	  </choose>
  </select>
  
  <select id="selectProjectTask" resultType="com.goafanti.techproject.bo.TaskListBo">
	select
		a.id as taskId,
		a.commodity_name as commodityName,
		a.commodity_quantity as commodityQuantity,
		a.task_status as taskStatus,
		a.deleted_sign as deletedSign,
		a.task_comment as taskComment,
		a.publish_status as publishStatus,
		ifnull(b.name,'暂无') as technicianName,
		ifnull(b.contact_mobile,'暂无') as technicianMobile
	from
		contract_task a left join admin b on
		a.task_receiver = b.id
	where a.contract_id = #{contractId,jdbcType=VARCHAR}
  </select>
  <select id="selectMyProjectTaskByPage" resultType="com.goafanti.techproject.bo.TaskListBo">
			select
			a.id as taskId,
			a.commodity_id as commodityId,
			a.serial_number as taskNo,
			a.task_status as taskStatus,
			a.deleted_sign as deleteSign,
			date_format(a.task_distribution_time,'%Y-%m-%d %H:%i:%S') as taskDistributionTimes,
			a.task_comment as taskComment,
			a.publish_status as publishStatus,
			b.bname as commodityName ,
			c.cname as categoryName,
			c.id as categoryId,
			d.serial_number as projectNo,
			d.status,
			d.deleted_sign as deletedSign,
			e.nickname as buyerName,
			f.name as taskReceiverName
		from
			contract_task a left join business_project b on
			a.commodity_id = b.id left join business_category c on
			b.cid = c.id left join contract d on
			a.contract_id = d.id left join user e on
			d.uid = e.id left join admin f on 
			a.task_receiver = f.id
		where 1=1
		<if test="taskReceiverId != null and taskReceiverId != ''">
			and a.task_receiver = #{taskReceiverId,jdbcType=VARCHAR}
		</if>
		<if test="deleteSign != null">
			and a.deleted_sign = #{deleteSign,jdbcType=VARCHAR}
		</if>
		<if test="publishStatus != null">
			and a.publish_status = #{publishStatus,jdbcType=VARCHAR}
		</if>
		<if test="taskStatus != null">
			and a.task_status = #{taskStatus,jdbcType=VARCHAR}
		</if>
		<if test="startDate != null">
			and a.task_distribution_time &gt; #{startDate,jdbcType=TIMESTAMP}
		</if>
		<if test="endDate != null">
			and a.task_distribution_time &lt; #{endDate,jdbcType=TIMESTAMP}
		</if>
		<if test="projectNo != null and projectNo != ''">
			and d.serial_number = #{projectNo,jdbcType=VARCHAR}
		</if>
		<if test="buyerName != null and buyerName != ''">
			and e.nickname like concat('%',#{buyerName,jdbcType=VARCHAR},'%')
		</if>
		<if test="taskReceiverName != null and taskReceiverName != ''">
			and f.name = #{taskReceiverName,jdbcType=VARCHAR}
		</if>
		<if test="categoryId != null and categoryId != ''">
			and c.id = #{categoryId,jdbcType=VARCHAR}
		</if>
			order by a.task_distribution_time desc
		<if test="page_sql != null">
			${page_sql}
		</if>
  </select>
  
  <select id="selectMyProjectTaskCount" resultType="java.lang.Integer">
  		select
			count(0)
		from
			contract_task a left join business_project b on
			a.commodity_id = b.id left join business_category c on
			b.cid = c.id left join contract d on
			a.contract_id = d.id left join user e on
			d.uid = e.id left join admin f on 
			a.task_receiver = f.id
		where 1=1
		<if test="taskReceiverId != null and taskReceiverId != ''">
			and a.task_receiver = #{taskReceiverId,jdbcType=VARCHAR}
		</if>
		<if test="deleteSign != null">
			and a.deleted_sign = #{deleteSign,jdbcType=VARCHAR}
		</if>
		<if test="publishStatus != null">
			and a.publish_status = #{publishStatus,jdbcType=VARCHAR}
		</if>
		<if test="taskStatus != null">
			and a.task_status = #{taskStatus,jdbcType=VARCHAR}
		</if>
		<if test="startDate != null">
			and a.task_distribution_time &gt; #{startDate,jdbcType=TIMESTAMP}
		</if>
		<if test="endDate != null">
			and a.task_distribution_time &lt; #{endDate,jdbcType=TIMESTAMP}
		</if>
		<if test="projectNo != null and projectNo != ''">
			and d.serial_number = #{projectNo,jdbcType=VARCHAR}
		</if>
		<if test="buyerName != null and buyerName != ''">
			and e.nickname like concat('%',#{buyerName,jdbcType=VARCHAR},'%')
		</if>
		<if test="taskReceiverName != null and taskReceiverName != ''">
			and f.name = #{taskReceiverName,jdbcType=VARCHAR}
		</if>
		<if test="categoryId != null and categoryId != ''">
			and c.id = #{categoryId,jdbcType=VARCHAR}
		</if>
		
		<if test="taskReceiverId != null and taskReceiverId != ''">
			and a.task_receiver = #{taskReceiverId,jdbcType=VARCHAR}
		</if>
		<if test="deleteSign != null">
			and a.deleted_sign = #{deleteSign,jdbcType=VARCHAR}
		</if>
		<if test="publishStatus != null">
			and a.publish_status = #{publishStatus,jdbcType=VARCHAR}
		</if>
		<if test="taskStatus != null">
			and a.task_status = #{taskStatus,jdbcType=VARCHAR}
		</if>
		<if test="startDate != null">
			and a.task_distribution_time &gt; #{startDate,jdbcType=TIMESTAMP}
		</if>
		<if test="endDate != null">
			and a.task_distribution_time &lt; #{endDate,jdbcType=TIMESTAMP}
		</if>
		<if test="projectNo != null and projectNo != ''">
			and d.serial_number = #{projectNo,jdbcType=VARCHAR}
		</if>
		<if test="buyerName != null and buyerName != ''">
			and e.nickname like concat('%',#{buyerName,jdbcType=VARCHAR},'%')
		</if>
		<if test="taskReceiverName != null and taskReceiverName != ''">
			and f.name = #{taskReceiverName,jdbcType=VARCHAR}
		</if>
		<if test="categoryId != null and categoryId != ''">
			and c.id = #{categoryId,jdbcType=VARCHAR}
		</if>
			order by a.task_distribution_time desc
		<if test="page_sql != null">
			${page_sql}
		</if>
  </select>
  
  
   <select id="salesmanListProjectByPage" resultType="com.goafanti.techproject.bo.ProjectListBo">
	select
		a.id,
		a.serial_number as serialNumber,
		date_format(a.sign_date,'%Y-%m-%d %H:%i:%S') as signDate,
		date_format(a.create_time,'%Y-%m-%d %H:%i:%S') as projectTime,
		a.uid,
		a.status as projectStatus,
		a.task_distribution as taskDistribution,
		a.deleted_sign as deletedSign,
		a.order_no as orderNo,
		b.nickname as buyerName,
		b.type as buyerType,
		f.cname as projectType,
		c.create_time as orderTime,
		c.order_status as orderStatus,
		c.liquidation_status as liquidationStatus,
		c.approval,
		d.name as salesmanName,
		e.name as departmentName,
		g.name as principalName
	from
		contract a left join user b on
		a.uid = b.id left join t_order c on
		a.order_no = c.order_no left join admin d on
		c.salesman_id = d.id left join department e on
		d.department_id = e.id left join business_category f on
		a.type = f.id left join admin g on
		a.principal = g.id
	where 1=1
	and c.salesman_id= #{salesmanId,jdbcType=VARCHAR}
	<if test="deletedSign != null">
		and a.deleted_sign = #{deletedSign,jdbcType=INTEGER}
	</if>
	<if test="orderNo != null and orderNo != ''">
		and a.order_no = #{orderNo,jdbcType=VARCHAR}
	</if>
	<if test="serialNumber != null and serialNumber != ''">
		and a.serial_number = #{serialNumber,jdbcType=VARCHAR}
	</if>
	<if test="setUpStartDate != null and setUpStartDate != ''">
		and a.create_time &gt; #{setUpStartDate,jdbcType=TIMESTAMP}
	</if>
	<if test="setUpEndDate != null and setUpEndDate != ''">
		and a.create_time &lt; #{setUpEndDate,jdbcType=TIMESTAMP}
	</if>
	<if test="taskDistribution != null">
		and a.task_distribution = #{taskDistribution,jdbcType=INTEGER}
	</if>
	<if test="buyerName != null and buyerName != ''">
		and b.nickname like concat('%',#{buyerName,jdbcType=VARCHAR},'%')
	</if>
	<if test="salesmanName != null and salesmanName !=''">
		and d.name = #{salesmanName,jdbcType=VARCHAR}
	</if>
	<if test="depId != null and depId != ''">
		and d.department_id = #{depId,jdbcType=VARCHAR}
	</if>
	<if test="orderStartDate != null and orderStartDate != ''">
		and c.create_time &gt; #{orderStartDate,jdbcType=TIMESTAMP}
	</if>
	<if test="orderEndDate != null and orderEndDate != ''">
		and c.create_time &lt; #{orderEndDate,jdbcType=TIMESTAMP}
	</if>
	<if test="principalName != null and principalName != ''">
		and g.name = #{principalName,jdbcType=VARCHAR}
	</if>
		order by a.create_time desc
	<if test="page_sql != null">
		${page_sql}
	</if>
  </select>
  <select id="salesmanListProjectCount" resultType="java.lang.Integer">
  	select
		count(0)
	from
		contract a left join user b on
		a.uid = b.id left join t_order c on
		a.order_no = c.order_no left join admin d on
		c.salesman_id = d.id left join department e on
		d.department_id = e.id left join business_category f on
		a.type = f.id left join admin g on
		a.principal = g.id
	where 1=1
	and c.salesman_id= #{salesmanId,jdbcType=VARCHAR}
	<if test="deletedSign != null">
		and a.deleted_sign = #{deletedSign,jdbcType=INTEGER}
	</if>
	<if test="orderNo != null and orderNo != ''">
		and a.order_no = #{orderNo,jdbcType=VARCHAR}
	</if>
	<if test="serialNumber != null and serialNumber != ''">
		and a.serial_number = #{serialNumber,jdbcType=VARCHAR}
	</if>
	<if test="setUpStartDate != null and setUpStartDate != ''">
		and a.create_time &gt; #{setUpStartDate,jdbcType=TIMESTAMP}
	</if>
	<if test="setUpEndDate != null and setUpEndDate != ''">
		and a.create_time &lt; #{setUpEndDate,jdbcType=TIMESTAMP}
	</if>
	<if test="taskDistribution != null">
		and a.task_distribution = #{taskDistribution,jdbcType=INTEGER}
	</if>
	<if test="buyerName != null and buyerName != ''">
		and b.nickname like concat('%',#{buyerName,jdbcType=VARCHAR},'%')
	</if>
	<if test="salesmanName != null and salesmanName !=''">
		and d.name = #{salesmanName,jdbcType=VARCHAR}
	</if>
	<if test="depId != null and depId != ''">
		and d.department_id = #{depId,jdbcType=VARCHAR}
	</if>
	<if test="orderStartDate != null and orderStartDate != ''">
		and c.create_time &gt; #{orderStartDate,jdbcType=TIMESTAMP}
	</if>
	<if test="orderEndDate != null and orderEndDate != ''">
		and c.create_time &lt; #{orderEndDate,jdbcType=TIMESTAMP}
	</if>
	<if test="principalName != null and principalName != ''">
		and g.name = #{principalName,jdbcType=VARCHAR}
	</if>
  </select>
  
  <select id="selectProjectTaskByPage" resultType="com.goafanti.techproject.bo.TaskListBo">
			select
			a.id as taskId,
			a.commodity_id as commodityId,
			a.serial_number as taskNo,
			a.task_status as taskStatus,
			a.deleted_sign as deleteSign,
			date_format(a.task_distribution_time,'%Y-%m-%d %H:%i:%S') as taskDistributionTimes,
			a.task_comment as taskComment,
			a.publish_status as publishStatus,
			b.bname as commodityName ,
			c.cname as categoryName,
			c.id as categoryId,
			d.serial_number as projectNo,
			d.status,
			d.deleted_sign as deletedSign,
			e.nickname as buyerName,
			f.name as taskReceiverName,
			ifnull(g.sign_total_amount,0) as signTotalAmount
		from
			(select *
		from contract_task_log
		where task_receiver=#{taskReceiver,jdbcType=VARCHAR}) x left join contract_task a on 
			x.contract_task_id=a.id	left join business_project b on
			a.commodity_id = b.id left join business_category c on
			b.cid = c.id left join contract d on
			a.contract_id = d.id left join user e on
			d.uid = e.id left join admin f on 
			a.task_receiver = f.id left join t_order g on 
			d.order_no=g.order_no
		where 1=1
		<if test="taskReceiverId != null and taskReceiverId != ''">
			and a.task_receiver = #{taskReceiverId,jdbcType=VARCHAR}
		</if>
		<if test="deleteSign != null">
			and a.deleted_sign = #{deleteSign,jdbcType=VARCHAR}
		</if>
		<if test="publishStatus != null">
			and a.publish_status = #{publishStatus,jdbcType=VARCHAR}
		</if>
		<if test="taskStatus != null">
			and a.task_status = #{taskStatus,jdbcType=VARCHAR}
		</if>
		<if test="startDate != null">
			and a.task_distribution_time &gt; #{startDate,jdbcType=TIMESTAMP}
		</if>
		<if test="endDate != null">
			and a.task_distribution_time &lt; #{endDate,jdbcType=TIMESTAMP}
		</if>
		<if test="projectNo != null and projectNo != ''">
			and d.serial_number = #{projectNo,jdbcType=VARCHAR}
		</if>
		<if test="buyerName != null and buyerName != ''">
			and e.nickname like concat('%',#{buyerName,jdbcType=VARCHAR},'%')
		</if>
		<if test="taskReceiverName != null and taskReceiverName != ''">
			and f.name = #{taskReceiverName,jdbcType=VARCHAR}
		</if>
		<if test="categoryId != null and categoryId != ''">
			and c.id = #{categoryId,jdbcType=VARCHAR}
		</if>
			order by a.task_distribution_time desc
		<if test="page_sql != null">
			${page_sql}
		</if>
  </select>
  
  <select id="selectProjectTaskCount" resultType="java.lang.Integer">
  		select
			count(0)
		from
			(select *
		from contract_task_log
		where task_receiver=#{taskReceiver,jdbcType=VARCHAR}) x left join contract_task a on 
			x.contract_task_id=a.id	left join business_project b on
			a.commodity_id = b.id left join business_category c on
			b.cid = c.id left join contract d on
			a.contract_id = d.id left join user e on
			d.uid = e.id left join admin f on 
			a.task_receiver = f.id left join t_order g on 
			d.order_no=g.order_no
		where 1=1
		<if test="taskReceiverId != null and taskReceiverId != ''">
			and a.task_receiver = #{taskReceiverId,jdbcType=VARCHAR}
		</if>
		<if test="deleteSign != null">
			and a.deleted_sign = #{deleteSign,jdbcType=VARCHAR}
		</if>
		<if test="publishStatus != null">
			and a.publish_status = #{publishStatus,jdbcType=VARCHAR}
		</if>
		<if test="taskStatus != null">
			and a.task_status = #{taskStatus,jdbcType=VARCHAR}
		</if>
		<if test="startDate != null">
			and a.task_distribution_time &gt; #{startDate,jdbcType=TIMESTAMP}
		</if>
		<if test="endDate != null">
			and a.task_distribution_time &lt; #{endDate,jdbcType=TIMESTAMP}
		</if>
		<if test="projectNo != null and projectNo != ''">
			and d.serial_number = #{projectNo,jdbcType=VARCHAR}
		</if>
		<if test="buyerName != null and buyerName != ''">
			and e.nickname like concat('%',#{buyerName,jdbcType=VARCHAR},'%')
		</if>
		<if test="taskReceiverName != null and taskReceiverName != ''">
			and f.name = #{taskReceiverName,jdbcType=VARCHAR}
		</if>
		<if test="categoryId != null and categoryId != ''">
			and c.id = #{categoryId,jdbcType=VARCHAR}
		</if>
		
		<if test="taskReceiverId != null and taskReceiverId != ''">
			and a.task_receiver = #{taskReceiverId,jdbcType=VARCHAR}
		</if>
		<if test="deleteSign != null">
			and a.deleted_sign = #{deleteSign,jdbcType=VARCHAR}
		</if>
		<if test="publishStatus != null">
			and a.publish_status = #{publishStatus,jdbcType=VARCHAR}
		</if>
		<if test="taskStatus != null">
			and a.task_status = #{taskStatus,jdbcType=VARCHAR}
		</if>
		<if test="startDate != null">
			and a.task_distribution_time &gt; #{startDate,jdbcType=TIMESTAMP}
		</if>
		<if test="endDate != null">
			and a.task_distribution_time &lt; #{endDate,jdbcType=TIMESTAMP}
		</if>
		<if test="projectNo != null and projectNo != ''">
			and d.serial_number = #{projectNo,jdbcType=VARCHAR}
		</if>
		<if test="buyerName != null and buyerName != ''">
			and e.nickname like concat('%',#{buyerName,jdbcType=VARCHAR},'%')
		</if>
		<if test="taskReceiverName != null and taskReceiverName != ''">
			and f.name = #{taskReceiverName,jdbcType=VARCHAR}
		</if>
		<if test="categoryId != null and categoryId != ''">
			and c.id = #{categoryId,jdbcType=VARCHAR}
		</if>
	 </select>
</mapper>