SELECT pk ,order_code -- 订单号 ,src_order_code -- 来源订单号 ,order_time -- 订单时间 ,order_type -- 订单类型 ,city_unit_code -- 城市单元编码 ,city_unit_name -- 城市单元 ,office_code -- 办事处编码 ,office_name -- 办事处 ,region_code -- 大区编码 ,region_name -- 大区名称 ,bu_code -- 事业部编码 ,bu_name -- 事业部 ,province_name -- 省份 ,city_name -- 市区 ,deal_code -- 主经销商编码 ,deal_name -- 主经销商名称 ,src_deal_code -- 子经销商编码 ,src_deal_name -- 子经销商名称 ,deal_type -- 经销商类型 ,yys_code -- 运营商编码 ,yys_name -- 运营商名称 ,product_code -- 产品编码 ,product_name -- 产品名称 ,aroma_type -- 香型 ,pi_name -- 品项 ,pr_name -- 产品系列 ,report_pi_name -- 报表品项 ,plan_pi_name -- 计划品项 ,plan_type -- 计划类型 ,pl_name -- 产品线 ,p_bu_code -- 产品所属事业部编码 ,p_bu_name -- 产品所属事业部名称 ,price_item -- 价格项 ,spec -- 规格 ,is_jxzx -- 酱酒执行 ,price -- 单价 ,discount_price -- 折后价 ,order_num -- 订单数量 ,pack_base_num -- 转换率 ,ton_num -- 订单吨数 ,x_amt -- x类金额 ,adj_amt -- 调整金额 ,e_amt -- E类费用 ,f_amt -- F类费用 ,q_amt -- Q类费用 ,d_amt -- D类金额 ,fz_amt -- FZ类金额 ,other_amt -- 其他费用 ,amt_bu -- 计事业部金额 ,amt_region -- 计大区金额 ,amt_office -- 计办事处金额 ,amt_city_unit -- 计城市单元金额 ,amt_dealer -- 计经销商金额 FROM dm.v_ag_sal_order a -- 订单时间 WHERE order_time >= '${CONCATENATE(sOrder_start_date," 00:00:00")}' AND order_time <= '${CONCATENATE(sOrder_end_date," 00:00:00")}' -- 事业部 ${if(len(sBu) == 0,"","and a.bu_code IN ('"+sBu+"')")} -- 大区 ${if(len(sRegion) == 0,"","and region_code IN ('"+ sRegion+"')")} -- 办事处 ${if(len(sOffice) == 0,"","and office_code IN ('"+ sOffice+"')")} -- 城市单元 ${if(len(sCu) == 0,"","and city_unit_code IN ('"+sCu+"')")} -- 产品 ${if(len(sProduct) == 0,"","and product_code IN ('"+ sProduct +"')")} -- 子主经销商 ${if(sSub_main == '主经销商',if(len(sDeal) == 0,"","and deal_code IN ('"+ sDeal+"')"),if(len(sDeal) == 0,"","and src_deal_code IN ('"+ sDeal +"')"))} -- 单据号 ${if(len(sBill) == 0,"","and order_code in ('" + sBill + "')")} -- 酱酒执行计划 ${if(len(sBill) == 0,"","and order_code in ('" + sBill + "')")} -- 权限控制 AND exists ( select 1 from dm.dm_bi_user_permisson where bi_user = '${fine_username}' and per_model IN ('all','sal') and ( is_all = 1 OR per_code = a.bu_code -- 事业部 OR per_code = a.region_code -- 大区 OR per_code = a.office_code -- 城市单元 OR per_code = a.city_unit_code -- 城市单元 ) )