<?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.dsk.cscec.mapper.CbCostMeasureMapper">
  <resultMap id="BaseResultMap" type="com.dsk.cscec.domain.CbCostMeasure">
    <!--@mbg.generated-->
    <!--@Table cb_cost_measure-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="project_id" jdbcType="BIGINT" property="projectId" />
    <result column="cb_stage" jdbcType="INTEGER" property="projectFileId" />
    <result column="parent_id" jdbcType="BIGINT" property="parentId" />
    <result column="level" jdbcType="INTEGER" property="level" />
    <result column="number" jdbcType="VARCHAR" property="number" />
    <result column="no" jdbcType="VARCHAR" property="no" />
    <result column="item_content" jdbcType="VARCHAR" property="itemContent" />
    <result column="work_content" jdbcType="VARCHAR" property="workContent" />
    <result column="unit" jdbcType="VARCHAR" property="unit" />
    <result column="quantity" jdbcType="DECIMAL" property="quantity" />
    <result column="unit_price_excluding_tax" jdbcType="VARCHAR" property="unitPriceExcludingTax" />
    <result column="usage_time" jdbcType="VARCHAR" property="usageTime" />
    <result column="amount_excluding_tax" jdbcType="VARCHAR" property="amountExcludingTax" />
    <result column="tax_rate" jdbcType="VARCHAR" property="taxRate" />
    <result column="amount_including_tax" jdbcType="VARCHAR" property="amountIncludingTax" />
    <result column="amortization_ratio" jdbcType="VARCHAR" property="amortizationRatio" />
    <result column="amount_exclude_tax_amortized" jdbcType="VARCHAR" property="amountExcludeTaxAmortized" />
    <result column="amount_include_tax_amortized" jdbcType="VARCHAR" property="amountIncludeTaxAmortized" />
    <result column="tax_amount" jdbcType="VARCHAR" property="taxAmount" />
    <result column="remarks" jdbcType="VARCHAR" property="remarks" />
    <result column="cost_subject" jdbcType="VARCHAR" property="costSubject" />
    <result column="tax_type" jdbcType="VARCHAR" property="taxType" />
    <result column="data_source" jdbcType="INTEGER" property="dataSource" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, project_id, cb_stage, parent_id, `level`, `number`, `no`,item_content, work_content,
    unit, quantity, unit_price_excluding_tax, usage_time, amount_excluding_tax, tax_rate, 
    amount_including_tax, amortization_ratio, amount_exclude_tax_amortized, amount_include_tax_amortized, 
    tax_amount, remarks, cost_subject, tax_type,data_source, create_time, update_time
  </sql>


  <select id="selectListByProjectAndNo" resultType="com.dsk.cscec.domain.vo.CbCostMeasureActualVo">
    SELECT t.*,t1.actualId,t1.plan_measure_id,t1.month_cost_rate, t1.cost_effective,  t1.project_volume,t1.current_project_volume,t1.submit_project_volume,t1.`month`,t1.push_time FROM cb_cost_measure t
    left JOIN (
        SELECT t.id actualId,t1.plan_measure_id,t1.month_cost_rate, t1.cost_effective,t1.project_volume, t1.current_project_volume,t1.submit_project_volume,t1.`month`,t1.push_time FROM cb_cost_measure t
        inner JOIN cb_cost_measure_actual t1 ON t1.plan_measure_id=t.id
        WHERE
            t.project_id=#{projectId}
        AND t1.`month`=#{month}) t1 ON t1.plan_measure_id=t.id
    WHERE
      t.project_id=#{projectId}
      AND t.`level`!=0
      AND t.`no` like concat(#{id},'.%')
    ORDER BY id ASC
  </select>

  <select id="actualMonthList" resultType="java.lang.String">
    SELECT
      t1.`month`
    FROM cb_cost_measure t
    inner JOIN cb_cost_measure_actual t1 ON t1.plan_measure_id=t.id
    WHERE
      t.project_id=#{projectId}
      and t1.del_flag=0
    GROUP  BY  t1.`month` ORDER BY t1.`month` desc
  </select>
</mapper>