<?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.fuxi.ws.data.dao.WDeptmonthaimMapper" >
  <resultMap id="BaseResultMap" type="com.fuxi.ws.data.entity.WDeptmonthaim" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue May 15 12:39:49 CST 2018.
    -->
    <id column="DepartmentID" property="departmentid" jdbcType="VARCHAR" />
    <id column="AimYear" property="aimyear" jdbcType="INTEGER" />
    <id column="AimMonth" property="aimmonth" jdbcType="INTEGER" />
    <result column="SellAim" property="sellaim" jdbcType="DECIMAL" />
    <result column="VipAim" property="vipaim" jdbcType="INTEGER" />
  </resultMap>
  <sql id="Example_Where_Clause" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue May 15 12:39:49 CST 2018.
    -->
    <where >
      <foreach collection="oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue May 15 12:39:49 CST 2018.
    -->
    DepartmentID, AimYear, AimMonth, SellAim, VipAim
  </sql>
  <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.fuxi.ws.data.entity.WDeptmonthaimExample" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue May 15 12:39:49 CST 2018.
    -->
    select
    <if test="distinct" >
      distinct
    </if>
    'false' as QUERYID,
    <include refid="Base_Column_List" />
    from W_DeptMonthAim
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null" >
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="com.fuxi.ws.data.entity.WDeptmonthaimKey" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue May 15 12:39:49 CST 2018.
    -->
    select 
    <include refid="Base_Column_List" />
    from W_DeptMonthAim
    where DepartmentID = #{departmentid,jdbcType=VARCHAR}
      and AimYear = #{aimyear,jdbcType=INTEGER}
      and AimMonth = #{aimmonth,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WDeptmonthaimKey" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue May 15 12:39:49 CST 2018.
    -->
    delete from W_DeptMonthAim
    where DepartmentID = #{departmentid,jdbcType=VARCHAR}
      and AimYear = #{aimyear,jdbcType=INTEGER}
      and AimMonth = #{aimmonth,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.fuxi.ws.data.entity.WDeptmonthaim" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue May 15 12:39:49 CST 2018.
    -->
    insert into W_DeptMonthAim (DepartmentID, AimYear, AimMonth, 
      SellAim, VipAim)
    values (#{departmentid,jdbcType=VARCHAR}, #{aimyear,jdbcType=INTEGER}, #{aimmonth,jdbcType=INTEGER}, 
      #{sellaim,jdbcType=DECIMAL}, #{vipaim,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.fuxi.ws.data.entity.WDeptmonthaim" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue May 15 12:39:49 CST 2018.
    -->
    insert into W_DeptMonthAim
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="departmentid != null" >
        DepartmentID,
      </if>
      <if test="aimyear != null" >
        AimYear,
      </if>
      <if test="aimmonth != null" >
        AimMonth,
      </if>
      <if test="sellaim != null" >
        SellAim,
      </if>
      <if test="vipaim != null" >
        VipAim,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="departmentid != null" >
        #{departmentid,jdbcType=VARCHAR},
      </if>
      <if test="aimyear != null" >
        #{aimyear,jdbcType=INTEGER},
      </if>
      <if test="aimmonth != null" >
        #{aimmonth,jdbcType=INTEGER},
      </if>
      <if test="sellaim != null" >
        #{sellaim,jdbcType=DECIMAL},
      </if>
      <if test="vipaim != null" >
        #{vipaim,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.fuxi.ws.data.entity.WDeptmonthaimExample" resultType="java.lang.Integer" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue May 15 12:39:49 CST 2018.
    -->
    select count(*) from W_DeptMonthAim
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByPrimaryKeySelective" parameterType="com.fuxi.ws.data.entity.WDeptmonthaim" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue May 15 12:39:49 CST 2018.
    -->
    update W_DeptMonthAim
    <set >
      <if test="sellaim != null" >
        SellAim = #{sellaim,jdbcType=DECIMAL},
      </if>
      <if test="vipaim != null" >
        VipAim = #{vipaim,jdbcType=INTEGER},
      </if>
    </set>
    where DepartmentID = #{departmentid,jdbcType=VARCHAR}
      and AimYear = #{aimyear,jdbcType=INTEGER}
      and AimMonth = #{aimmonth,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WDeptmonthaim" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue May 15 12:39:49 CST 2018.
    -->
    update W_DeptMonthAim
    set SellAim = #{sellaim,jdbcType=DECIMAL},
      VipAim = #{vipaim,jdbcType=INTEGER}
    where DepartmentID = #{departmentid,jdbcType=VARCHAR}
      and AimYear = #{aimyear,jdbcType=INTEGER}
      and AimMonth = #{aimmonth,jdbcType=INTEGER}
  </update>
  
   <delete id="deleteByWDeptmonthaim" parameterType="com.fuxi.ws.data.entity.WDeptmonthaim" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue May 15 12:39:49 CST 2018.
    -->
    delete from W_DeptMonthAim
    where DepartmentID = #{departmentid,jdbcType=VARCHAR}
      and AimYear = #{aimyear,jdbcType=INTEGER}
  </delete>
  
  	<!-- 门店目标销售额列表 -->
	<select id="selectWDeptmonthaimlist" resultType="java.util.LinkedHashMap">
		select d.Code,d.Department,
		sum(case a.AimMonth when 1 then a.SellAim else 0 end) as Month1Aim,
		sum(case a.AimMonth when 2 then a.SellAim else 0 end) as Month2Aim,
		sum(case a.AimMonth when 3 then a.SellAim else 0 end) as Month3Aim,
		sum(case a.AimMonth when 4 then a.SellAim else 0 end) as Month4Aim,
		sum(case a.AimMonth when 5 then a.SellAim else 0 end) as Month5Aim,
		sum(case a.AimMonth when 6 then a.SellAim else 0 end) as Month6Aim,
		sum(case a.AimMonth when 7 then a.SellAim else 0 end) as Month7Aim,
		sum(case a.AimMonth when 8 then a.SellAim else 0 end) as Month8Aim,
		sum(case a.AimMonth when 9 then a.SellAim else 0 end) as Month9Aim,
		sum(case a.AimMonth when 10 then a.SellAim else 0 end) as Month10Aim,
		sum(case a.AimMonth when 11 then a.SellAim else 0 end) as Month11Aim,
		sum(case a.AimMonth when 12 then a.SellAim else 0 end) as Month12Aim
		from W_DeptMonthAim a join Department d on a.DepartmentID=d.DepartmentID
		<if test="conditions != null and conditions != ''">
			 where ${conditions}
		</if>
		group by d.Code,d.Department 
	</select>
	
		<!-- 门店目标新增会员列表 -->
	<select id="selectWDeptmonthaimviplist" resultType="java.util.LinkedHashMap">
		select d.Code,d.Department,
		sum(case a.AimMonth when 1 then a.VipAim else 0 end) as Month1Aim,
		sum(case a.AimMonth when 2 then a.VipAim else 0 end) as Month2Aim,
		sum(case a.AimMonth when 3 then a.VipAim else 0 end) as Month3Aim,
		sum(case a.AimMonth when 4 then a.VipAim else 0 end) as Month4Aim,
		sum(case a.AimMonth when 5 then a.VipAim else 0 end) as Month5Aim,
		sum(case a.AimMonth when 6 then a.VipAim else 0 end) as Month6Aim,
		sum(case a.AimMonth when 7 then a.VipAim else 0 end) as Month7Aim,
		sum(case a.AimMonth when 8 then a.VipAim else 0 end) as Month8Aim,
		sum(case a.AimMonth when 9 then a.VipAim else 0 end) as Month9Aim,
		sum(case a.AimMonth when 10 then a.VipAim else 0 end) as Month10Aim,
		sum(case a.AimMonth when 11 then a.VipAim else 0 end) as Month11Aim,
		sum(case a.AimMonth when 12 then a.VipAim else 0 end) as Month12Aim
		from W_DeptMonthAim a join Department d on a.DepartmentID=d.DepartmentID
		<if test="conditions != null and conditions != ''">
			 where ${conditions}
		</if>
		group by d.Code,d.Department 
	</select>
	
	 <select id="selectByWDeptmonthaim" resultMap="BaseResultMap" parameterType="com.fuxi.ws.data.entity.WDeptmonthaim" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue May 15 12:39:49 CST 2018.
    -->
    select 
    <include refid="Base_Column_List" />
    from W_DeptMonthAim
    where DepartmentID = #{departmentid,jdbcType=VARCHAR}
      and AimYear = #{aimyear,jdbcType=INTEGER}
      and AimMonth = #{aimmonth,jdbcType=INTEGER}
  </select>
</mapper>