<?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="cn.superdesk.uniorder.dao.mapper.unified.UnifiedProjectMapper">
	<resultMap id="BaseResultMap" type="cn.superdesk.uniorder.dao.entity.unified.UnifiedProject">
		<id column="project_id" property="projectId" jdbcType="BIGINT"/>
		<result column="project_name" property="projectName" jdbcType="VARCHAR"/>
		<result column="project_no" property="projectNo" jdbcType="VARCHAR"/>
		<result column="province_code" property="provinceCode" jdbcType="VARCHAR"/>
		<result column="province_name" property="provinceName" jdbcType="VARCHAR"/>
		<result column="city_code" property="cityCode" jdbcType="VARCHAR"/>
		<result column="city_name" property="cityName" jdbcType="VARCHAR"/>
		<result column="customer_user_id" property="customerUserId" jdbcType="BIGINT"/>
		<result column="purchase_user_id" property="purchaseUserId" jdbcType="BIGINT"/>
		<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
		<result column="create_user_id" property="createUserId" jdbcType="BIGINT"/>
		<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
		<result column="update_user_id" property="updateUserId" jdbcType="BIGINT"/>
	</resultMap>
	<resultMap id="DataResultMap" type="cn.superdesk.uniorder.dto.vo.unified.UnifiedProjectVo">
		<id column="project_id" property="projectId" jdbcType="BIGINT"/>
		<result column="project_name" property="projectName" jdbcType="VARCHAR"/>
		<result column="project_no" property="projectNo" jdbcType="VARCHAR"/>
		<result column="province_code" property="provinceCode" jdbcType="VARCHAR"/>
		<result column="province_name" property="provinceName" jdbcType="VARCHAR"/>
		<result column="city_code" property="cityCode" jdbcType="VARCHAR"/>
		<result column="city_name" property="cityName" jdbcType="VARCHAR"/>
		<result column="customer_user_id" property="customerUserId" jdbcType="BIGINT"/>
		<result column="purchase_user_id" property="purchaseUserId" jdbcType="BIGINT"/>
		<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
		<result column="create_user_id" property="createUserId" jdbcType="BIGINT"/>
		<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
		<result column="update_user_id" property="updateUserId" jdbcType="BIGINT"/>
		<result column="customer_user_name" property="customerUserName" jdbcType="VARCHAR"/>
		<result column="purchase_user_name" property="purchaseUserName" jdbcType="VARCHAR"/>
		<result column="okr_target" property="okrTarget" jdbcType="DECIMAL"/>
		<result column="kpi_target" property="kpiTarget" jdbcType="DECIMAL"/>
	</resultMap>
	<select id="getData" resultMap="DataResultMap">
		SELECT target.kpi_target,target.okr_target,cu.fullname as customer_user_name,pu.fullname as
		purchase_user_name,a.project_id,
		a.project_name,
		a.project_no,
		a.province_code,
		a.province_name,
		a.city_code,
		a.city_name,
		a.customer_user_id,
		a.purchase_user_id,
		a.create_time,
		a.create_user_id,
		a.update_time,
		a.update_user_id FROM unified_project a
		LEFT JOIN sys_user cu on cu.id=a.customer_user_id
		LEFT JOIN sys_user pu on pu.id = a.purchase_user_id
		LEFT JOIN (
		SELECT * from unified_project_target where yearly=YEAR(CURDATE()) and monthly = MONTH(CURDATE())

		) target on target.project_id = a.project_id
		where 1=1
		<if test="project != null and project != '' ">
			and (a.project_id = #{project} or
			a.project_name like CONCAT('%',#{project},'%')
			)
		</if>
		<if test="cususername != null and cususername != '' ">
			and cu.fullname like CONCAT('%',#{cususername},'%')
		</if>
		<if test="purusername != null and purusername != '' ">
			and pu.fullname like CONCAT('%',#{purusername},'%')
		</if>
		order by a.create_time desc
	</select>

	<sql id="Base_Column_List">
    project_id, project_name, project_no, province_code, province_name, city_code, city_name, 
    customer_user_id, purchase_user_id, create_time, create_user_id, update_time, update_user_id
  </sql>
	<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">
		select
		<include refid="Base_Column_List"/>
		from unified_project
		where project_id = #{projectId,jdbcType=BIGINT}
	</select>
	<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from unified_project
    where project_id = #{projectId,jdbcType=BIGINT}
  </delete>
	<insert id="insert" parameterType="cn.superdesk.uniorder.dao.entity.unified.UnifiedProject">
    insert into unified_project (project_id, project_name, project_no, 
      province_code, province_name, city_code, 
      city_name, customer_user_id, purchase_user_id, 
      create_time, create_user_id, update_time, 
      update_user_id)
    values (#{projectId,jdbcType=BIGINT}, #{projectName,jdbcType=VARCHAR}, #{projectNo,jdbcType=VARCHAR}, 
      #{provinceCode,jdbcType=VARCHAR}, #{provinceName,jdbcType=VARCHAR}, #{cityCode,jdbcType=VARCHAR}, 
      #{cityName,jdbcType=VARCHAR}, #{customerUserId,jdbcType=BIGINT}, #{purchaseUserId,jdbcType=BIGINT}, 
      #{createTime,jdbcType=TIMESTAMP}, #{createUserId,jdbcType=BIGINT}, #{updateTime,jdbcType=TIMESTAMP}, 
      #{updateUserId,jdbcType=BIGINT})
  </insert>
	<insert id="insertSelective" parameterType="cn.superdesk.uniorder.dao.entity.unified.UnifiedProject">
		insert into unified_project
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="projectId != null">
				project_id,
			</if>
			<if test="projectName != null">
				project_name,
			</if>
			<if test="projectNo != null">
				project_no,
			</if>
			<if test="provinceCode != null">
				province_code,
			</if>
			<if test="provinceName != null">
				province_name,
			</if>
			<if test="cityCode != null">
				city_code,
			</if>
			<if test="cityName != null">
				city_name,
			</if>
			<if test="customerUserId != null">
				customer_user_id,
			</if>
			<if test="purchaseUserId != null">
				purchase_user_id,
			</if>
			<if test="createTime != null">
				create_time,
			</if>
			<if test="createUserId != null">
				create_user_id,
			</if>
			<if test="updateTime != null">
				update_time,
			</if>
			<if test="updateUserId != null">
				update_user_id,
			</if>
		</trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="projectId != null">
				#{projectId,jdbcType=BIGINT},
			</if>
			<if test="projectName != null">
				#{projectName,jdbcType=VARCHAR},
			</if>
			<if test="projectNo != null">
				#{projectNo,jdbcType=VARCHAR},
			</if>
			<if test="provinceCode != null">
				#{provinceCode,jdbcType=VARCHAR},
			</if>
			<if test="provinceName != null">
				#{provinceName,jdbcType=VARCHAR},
			</if>
			<if test="cityCode != null">
				#{cityCode,jdbcType=VARCHAR},
			</if>
			<if test="cityName != null">
				#{cityName,jdbcType=VARCHAR},
			</if>
			<if test="customerUserId != null">
				#{customerUserId,jdbcType=BIGINT},
			</if>
			<if test="purchaseUserId != null">
				#{purchaseUserId,jdbcType=BIGINT},
			</if>
			<if test="createTime != null">
				#{createTime,jdbcType=TIMESTAMP},
			</if>
			<if test="createUserId != null">
				#{createUserId,jdbcType=BIGINT},
			</if>
			<if test="updateTime != null">
				#{updateTime,jdbcType=TIMESTAMP},
			</if>
			<if test="updateUserId != null">
				#{updateUserId,jdbcType=BIGINT},
			</if>
		</trim>
	</insert>
	<update id="updateByPrimaryKeySelective" parameterType="cn.superdesk.uniorder.dao.entity.unified.UnifiedProject">
		update unified_project
		<set>
			<if test="projectName != null">
				project_name = #{projectName,jdbcType=VARCHAR},
			</if>
			<if test="projectNo != null">
				project_no = #{projectNo,jdbcType=VARCHAR},
			</if>
			<if test="provinceCode != null">
				province_code = #{provinceCode,jdbcType=VARCHAR},
			</if>
			<if test="provinceName != null">
				province_name = #{provinceName,jdbcType=VARCHAR},
			</if>
			<if test="cityCode != null">
				city_code = #{cityCode,jdbcType=VARCHAR},
			</if>
			<if test="cityName != null">
				city_name = #{cityName,jdbcType=VARCHAR},
			</if>
			<if test="customerUserId != null">
				customer_user_id = #{customerUserId,jdbcType=BIGINT},
			</if>
			<if test="purchaseUserId != null">
				purchase_user_id = #{purchaseUserId,jdbcType=BIGINT},
			</if>
			<if test="createTime != null">
				create_time = #{createTime,jdbcType=TIMESTAMP},
			</if>
			<if test="createUserId != null">
				create_user_id = #{createUserId,jdbcType=BIGINT},
			</if>
			<if test="updateTime != null">
				update_time = #{updateTime,jdbcType=TIMESTAMP},
			</if>
			<if test="updateUserId != null">
				update_user_id = #{updateUserId,jdbcType=BIGINT},
			</if>
		</set>
		where project_id = #{projectId,jdbcType=BIGINT}
	</update>
	<update id="updateByPrimaryKey" parameterType="cn.superdesk.uniorder.dao.entity.unified.UnifiedProject">
    update unified_project
    set project_name = #{projectName,jdbcType=VARCHAR},
      project_no = #{projectNo,jdbcType=VARCHAR},
      province_code = #{provinceCode,jdbcType=VARCHAR},
      province_name = #{provinceName,jdbcType=VARCHAR},
      city_code = #{cityCode,jdbcType=VARCHAR},
      city_name = #{cityName,jdbcType=VARCHAR},
      customer_user_id = #{customerUserId,jdbcType=BIGINT},
      purchase_user_id = #{purchaseUserId,jdbcType=BIGINT},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      create_user_id = #{createUserId,jdbcType=BIGINT},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      update_user_id = #{updateUserId,jdbcType=BIGINT}
    where project_id = #{projectId,jdbcType=BIGINT}
  </update>
</mapper>