package com.dst.slms.workBench.service.sql;
/**
 * @description  费效工作台的SQL语句类 TABLE
 * @date  20/05/04 14:09
 * @author  wanghb
 */

public class CostEffectiveSQL {
    //public final static String SQL_LIST_02   = "SELECT \"\" FROM TABLE l1 left join TABLE l2 on l1.fid = l2.FparentId  WHERE 1 = 1";

    //取验收单数据
    public final static String SQL_LIST_01   = "SELECT SUM(l2.Flfcount) lfcount, SUM(l2.Fcjcount) cjcount,SUM(l2.FcjAmt) cjAmt,SUM(l2.FysAmt) ysAmt  FROM yc_cost_receipt l1 left join yc_cost_receiptE3 l2 on l1.fid = l2.FparentId  WHERE 1 = 1";
    //取销售金额
    public final static String SQL_LIST_02   = "SELECT SUM(l1.FsalesAmount) salesAmount  FROM yc_cost_salesTarget l1 WHERE 1 = 1";
    //取销售目标
    public final static String SQL_LIST_03   = "SELECT SUM(l1.FsalesTarget) salesTarget ,SUM(l1.FsalesAmount) salesAmount FROM yc_cost_salesTarget l1 WHERE 1 = 1";

    //付款申请单
    public final static String SQL_LIST_05   = "SELECT SUM(l1.FtaxReqAmt) taxReqAmt FROM yc_cost_paymentReq l1 WHERE 1 = 1 ";
    //费用计划
    public final static String SQL_LIST_06   = "SELECT SUM(l1.FtotalAMT) totalAMT  FROM yc_cost_MonMarkMange l1 WHERE 1 = 1";
    //取费率排行
    public final static String SQL_ECHARTS_01   = "SELECT distinct l1.Frate rate,l2.fname name  FROM yc_cost_CyclePaymentPlan l1 " +
            " LEFT JOIN yc_cost_marketProject l2 on  l1.FprojectID = l2.fid " +
            " WHERE 1 = 1 ";


    //取渠道占比比例
    public final static String SQL_ECHARTS_02   = " select md.fname ctname,sum(a.FysAmt)/10000 amount ,sum(a.Flfcount) lfcount,case when sum(a.Flfcount)<>0 then sum(a.FysAmt)/sum(a.Flfcount) else 0 end lrfx, " +
            " case when sum(ct.Flfcount)<>0 then sum(a.Flfcount)/sum(ct.Flfcount)*100 else 0 end lrzb, " +
            " sum(a.Fcjcount) cjcount,case when sum(cts.Fcjcount)<>0 then sum(a.Fcjcount)/sum(cts.Fcjcount)*100 else 0 end cjzb, " +
            " case when sum(ctsf.FysAmt)<>0 then sum(a.FysAmt)/sum(ctsf.FysAmt)*100 else 0 end cjfyzb, " +
            " sum(a.FcjAmt)/10000  cjAmt,case when sum(a.Flfcount)<>0 then sum(a.FcjAmt)/sum(a.Flfcount) else 0 end cjfx " +
            " from yc_cost_receiptE3 a " +
            " left join yc_cost_receipt b on b.fid =a.fparentid " +
            " left join yc_cost_marketAccount ac on ac.fid = a.FmarkAccountID " +
            " left join yc_cost_mediaInfo md on md.fid = ac.FmediaID " +
            " left join ( " +
            " select sum(b.Flfcount) Flfcount,a.FprojectID from yc_cost_receipt a " +
            " left join yc_cost_receiptE3 b on b.fparentid =a.fid " +
            " where  a.fstate='AUDIT' group by  a.fid " +
            " ) ct on ct.FprojectID=b.FprojectID " +
            " left join ( " +
            " select sum(b.Fcjcount) Fcjcount,a.FprojectID from yc_cost_receipt a " +
            " left join yc_cost_receiptE3 b on b.fparentid =a.fid " +
            " where  a.fstate='AUDIT' group by  a.fid " +
            " ) cts on cts.FprojectID=b.FprojectID " +
            " left join ( " +
            " select sum(b.FysAmt) FysAmt,a.FprojectID from yc_cost_receipt a " +
            " left join yc_cost_receiptE3 b on b.fparentid =a.fid " +
            " where a.fstate='AUDIT' group by a.fid " +
            " ) ctsf on ctsf.FprojectID=b.FprojectID where 1=1  ";
    //渠道费效分析
    public final static String SQL_ECHARTS_05   = " select uuid() id,md.fname ctname,ac.fname,sum(a.FysAmt)/10000 amount ,sum(a.Flfcount) lfcount,case when sum(a.Flfcount)<>0 then sum(a.FysAmt)/sum(a.Flfcount) else 0 end lrfx,\r\n" +
            " case when sum(ct.Flfcount)<>0 then sum(a.Flfcount)/sum(ct.Flfcount)*100 else 0 end lrzb,\r\n" +
            " sum(a.Fcjcount) cjcount,case when sum(cts.Fcjcount)<>0 then sum(a.Fcjcount)/sum(cts.Fcjcount)*100 else 0 end cjzb,\r\n" +
            " case when sum(ctsf.FysAmt)<>0 then sum(a.FysAmt)/sum(ctsf.FysAmt)*100 else 0 end cjfyzb,\r\n" +
            " sum(a.FcjAmt)/10000  cjAmt,case when sum(a.Flfcount)<>0 then sum(a.FcjAmt)/sum(a.Flfcount) else 0 end cjfx\r\n" +
            " from yc_cost_receiptE3 a\r\n" +
            " left join yc_cost_receipt b on b.fid =a.fparentid\r\n" +
            " left join yc_cost_marketAccount ac on ac.fid = a.FmarkAccountID\r\n" +
            " left join yc_cost_mediaInfo md on md.fid = ac.FmediaID\r\n" +
            " left join (\r\n" +
            " select sum(b.Flfcount) Flfcount,a.FprojectID from yc_cost_receipt a\r\n" +
            " left join yc_cost_receiptE3 b on b.fparentid =a.fid\r\n" +
            " where a.fstate='AUDIT' and  a.FprojectID in(:projectIds) GROUP BY a.FprojectID  \r\n" +
            " ) ct on ct.FprojectID=b.FprojectID\r\n" +
            " left join (\r\n" +
            " select sum(b.Fcjcount) Fcjcount,a.FprojectID from yc_cost_receipt a\r\n" +
            " left join yc_cost_receiptE3 b on b.fparentid =a.fid\r\n" +
            " where  a.fstate='AUDIT' and a.FprojectID in(:projectIds) GROUP BY a.FprojectID \r\n" +
            " ) cts on cts.FprojectID=b.FprojectID\r\n" +
            " left join (\r\n" +
            " select sum(b.FysAmt) FysAmt,a.FprojectID from yc_cost_receipt a\r\n" +
            " left join yc_cost_receiptE3 b on b.fparentid =a.fid\r\n" +
            " where a.fstate='AUDIT' and a.FprojectID in(:projectIds) GROUP BY a.FprojectID \r\n" +
            " ) ctsf on ctsf.FprojectID=b.FprojectID\r\n" +
            " where b.fstate='AUDIT' and b.FprojectID in(:projectIds) group by md.fname,ac.fname order by md.fname,ac.fname\r\n";
    //渠道费效分析
    public final static String SQL_ECHARTS_06   = " select uuid() id,md.fname ctname,ac.fname,sum(a.FysAmt)/10000 amount ,sum(a.Flfcount) lfcount,case when sum(a.Flfcount)<>0 then sum(a.FysAmt)/sum(a.Flfcount) else 0 end lrfx,\r\n" +
            " case when sum(ct.Flfcount)<>0 then sum(a.Flfcount)/sum(ct.Flfcount)*100 else 0 end lrzb,\r\n" +
            " sum(a.Fcjcount) cjcount,case when sum(cts.Fcjcount)<>0 then sum(a.Fcjcount)/sum(cts.Fcjcount)*100 else 0 end cjzb,\r\n" +
            " case when sum(ctsf.FysAmt)<>0 then sum(a.FysAmt)/sum(ctsf.FysAmt)*100 else 0 end cjfyzb,\r\n" +
            " sum(a.FcjAmt)/10000  cjAmt,case when sum(a.Flfcount)<>0 then sum(a.FcjAmt)/sum(a.Flfcount) else 0 end cjfx\r\n" +
            " from yc_cost_receiptE3 a\r\n" +
            " left join yc_cost_receipt b on b.fid =a.fparentid\r\n" +
            " left join yc_cost_marketAccount ac on ac.fid = a.FmarkAccountID\r\n" +
            " left join yc_cost_mediaInfo md on md.fid = ac.FmediaID\r\n" +
            " left join (\r\n" +
            " select sum(b.Flfcount) Flfcount,a.FprojectID from yc_cost_receipt a\r\n" +
            " left join yc_cost_receiptE3 b on b.fparentid =a.fid\r\n" +
            " where a.fstate='AUDIT'  GROUP BY a.FprojectID  \r\n" +
            " ) ct on ct.FprojectID=b.FprojectID\r\n" +
            " left join (\r\n" +
            " select sum(b.Fcjcount) Fcjcount,a.FprojectID from yc_cost_receipt a\r\n" +
            " left join yc_cost_receiptE3 b on b.fparentid =a.fid\r\n" +
            " where  a.fstate='AUDIT' GROUP BY a.FprojectID \r\n" +
            " ) cts on cts.FprojectID=b.FprojectID\r\n" +
            " left join (\r\n" +
            " select sum(b.FysAmt) FysAmt,a.FprojectID from yc_cost_receipt a\r\n" +
            " left join yc_cost_receiptE3 b on b.fparentid =a.fid\r\n" +
            " where a.fstate='AUDIT' GROUP BY a.FprojectID \r\n" +
            " ) ctsf on ctsf.FprojectID=b.FprojectID\r\n" +
            " where b.fstate='AUDIT'  group by md.fname,ac.fname order by md.fname,ac.fname\r\n";
    //取费率排行
    public final static String SQL_ECHARTS_07   = "SELECT l3.fname name,SUM(l2.Flfcount) lfcount, SUM(l2.Fcjcount) cjcount,SUM(l2.FcjAmt) cjAmt,SUM(l2.FysAmt) ysAmt " +
            " FROM yc_cost_receipt l1 " +
            " LEFT JOIN yc_cost_receiptE3 l2 on l1.fid = l2.FparentId  " +
            " LEFT JOIN yc_cost_marketProject l3 on l3.fid = l1.FprojectID  " +
            " WHERE 1 = 1 ";

    //取费效排行
    public final static String SQL_ECHARTS_03   = " select b.FprojectID ,mp.fname ,sum(a.FysAmt)/10000 amount ,sum(a.Flfcount) lfcount,case when sum(a.Flfcount)<>0 then sum(a.FysAmt)/sum(a.Flfcount) else 0 end lrfx, " +
            " case when sum(ct.Flfcount)<>0 then sum(a.Flfcount)/sum(ct.Flfcount)*100 else 0 end lrzb, " +
            " sum(a.Fcjcount) cjcount,case when sum(cts.Fcjcount)<>0 then sum(a.Fcjcount)/sum(cts.Fcjcount)*100 else 0 end cjzb, " +
            " case when sum(ctsf.FysAmt)<>0 then sum(a.FysAmt)/sum(ctsf.FysAmt)*100 else 0 end cjfyzb, " +
            " sum(a.FcjAmt)/10000  cjAmt,case when sum(a.Flfcount)<>0 then sum(a.FcjAmt)/sum(a.Flfcount) else 0 end cjfx " +
            " from yc_cost_receiptE3 a " +
            " left join yc_cost_receipt b on b.fid =a.fparentid " +
            " left join yc_cost_marketAccount ac on ac.fid = a.FmarkAccountID " +
            " left join yc_cost_mediaInfo md on md.fid = ac.FmediaID " +
            " left join yc_cost_marketProject mp on mp.fid = b.FprojectID " +
            " left join ( " +
            " select sum(b.Flfcount) Flfcount,a.FprojectID from yc_cost_receipt a " +
            " left join yc_cost_receiptE3 b on b.fparentid =a.fid " +
            " where  a.fstate='AUDIT' group by  a.fid " +
            " ) ct on ct.FprojectID=b.FprojectID " +
            " left join ( " +
            " select sum(b.Fcjcount) Fcjcount,a.FprojectID from yc_cost_receipt a " +
            " left join yc_cost_receiptE3 b on b.fparentid =a.fid " +
            " where  a.fstate='AUDIT' group by  a.fid " +
            " ) cts on cts.FprojectID=b.FprojectID " +
            " left join ( " +
            " select sum(b.FysAmt) FysAmt,a.FprojectID from yc_cost_receipt a " +
            " left join yc_cost_receiptE3 b on b.fparentid =a.fid " +
            " where a.fstate='AUDIT' group by a.fid " +
            " ) ctsf on ctsf.FprojectID=b.FprojectID  " +
            " where 1= 1 ";

    //取费效费率趋势
    public final static String SQL_ECHARTS_04   = " select date_format(b.FconDate,'%Y-%m') conDate,sum(a.FysAmt)/10000 amount ,sum(a.Flfcount) lfcount,case when sum(a.Flfcount)<>0 then sum(a.FysAmt)/sum(a.Flfcount) else 0 end lrfx, " +
            " case when sum(ct.Flfcount)<>0 then sum(a.Flfcount)/sum(ct.Flfcount)*100 else 0 end lrzb, " +
            " sum(a.Fcjcount) cjcount,case when sum(cts.Fcjcount)<>0 then sum(a.Fcjcount)/sum(cts.Fcjcount)*100 else 0 end cjzb, " +
            " case when sum(ctsf.FysAmt)<>0 then sum(a.FysAmt)/sum(ctsf.FysAmt)*100 else 0 end cjfyzb, " +
            " sum(a.FcjAmt)/10000  cjAmt,case when sum(a.Flfcount)<>0 then sum(a.FcjAmt)/sum(a.Flfcount) else 0 end cjfx " +
            " from yc_cost_receiptE3 a " +
            " left join yc_cost_receipt b on b.fid =a.fparentid " +
            " left join yc_cost_marketAccount ac on ac.fid = a.FmarkAccountID " +
            " left join yc_cost_mediaInfo md on md.fid = ac.FmediaID " +
            " left join yc_cost_marketProject mp on mp.fid = b.FprojectID " +
            " left join ( " +
            " select sum(b.Flfcount) Flfcount,a.FprojectID from yc_cost_receipt a " +
            " left join yc_cost_receiptE3 b on b.fparentid =a.fid " +
            " where  a.fstate='AUDIT' group by  a.fid " +
            " ) ct on ct.FprojectID=b.FprojectID " +
            " left join ( " +
            " select sum(b.Fcjcount) Fcjcount,a.FprojectID from yc_cost_receipt a " +
            " left join yc_cost_receiptE3 b on b.fparentid =a.fid " +
            " where  a.fstate='AUDIT' group by  a.fid " +
            " ) cts on cts.FprojectID=b.FprojectID " +
            " left join ( " +
            " select sum(b.FysAmt) FysAmt,a.FprojectID from yc_cost_receipt a " +
            " left join yc_cost_receiptE3 b on b.fparentid =a.fid " +
            " where a.fstate='AUDIT' group by a.fid " +
            " ) ctsf on ctsf.FprojectID=b.FprojectID  " +
            " where 1= 1  ";
}
