QueryHelperqueryHelper=newQueryHelper("SELECT p.*, FORMAT(p.contract_amount,2) as contractRound, FORMAT(p.huazhi_product_amount,2) as huazhiRound, FORMAT(p.huizhi_product_amount,2) as huizhiRound, FORMAT(p.huasan_product_amount,2) as huasanRound, FORMAT(p.ziguang_other_amount,2) as ziguangRound"+
", FORMAT(p.gross_profit,2) as grossProfitRound, FORMAT(p.gross_profit_margin,2) as grossProfitMarginRound, FORMAT(p.advance_interest_amount,2) as advanceInterestAmountRound, FORMAT(p.advance_peak_amount,2) as advancePeakAmountRound, pe.is_budget as isBudget"+
", FORMAT(pe.contract_amount,2) as contractRound2, FORMAT(pe.huazhi_product_amount,2) as huazhiRound2, FORMAT(pe.huizhi_product_amount,2) as huizhiRound2, FORMAT(pe.huasan_product_amount,2) as huasanRound2, FORMAT(pe.ziguang_other_amount,2) as ziguangRound2"+
", FORMAT(pe.gross_profit,2) as grossProfitRound2, FORMAT(pe.gross_profit_margin,2) as grossProfitMarginRound2, FORMAT(pe.advance_interest_amount,2) as advanceInterestAmountRound2, FORMAT(pe.advance_peak_amount,2) as advancePeakAmountRound2","project","p");
queryHelper.leftJoin("project_extend pe","p.id = pe.project_id and pe.is_budget = 1");
queryHelper.addCondition(StrUtil.isNotEmpty(searchInfo.get("name")),"p.name LIKE ?","%"+searchInfo.get("name")+"%");
queryHelper.addCondition(StrUtil.isNotEmpty(searchInfo.get("customer")),"p.customer LIKE ?","%"+searchInfo.get("customer")+"%");
queryHelper.addCondition(StrUtil.isNotEmpty(searchInfo.get("terminalCustomer")),"p.terminal_customer LIKE ?","%"+searchInfo.get("terminalCustomer")+"%");
queryHelper.addCondition(StrUtil.isNotEmpty(searchInfo.get("principal")),"p.principal LIKE ?","%"+searchInfo.get("principal")+"%");
queryHelper.addCondition("((p.status=? AND p.approve_status_estimate=?) OR (p.status=? AND p.approve_status_budget=?) OR (p.status=? AND p.approve_status_settle=?) OR (p.status=? AND p.approve_status_final=?))",
queryHelper.addCondition("(p.creator_id=? OR p.approve_id=? OR p.id in (SELECT pv1.project_id FROM project_visible pv1 WHERE pv1.type=1 AND pv1.tid=? UNION SELECT pv2.project_id FROM project_visible pv2 WHERE pv2.type=2 AND pv2.tid=?))",adminId,adminId,roleId,adminId);
Stringsql="SELECT count(id) as sum, certainty, certainty_str as name FROM project WHERE certainty >= 1 and approve_status_estimate >= 1 and approve_status_estimate <= 2 and dept_name = '销售管理部' GROUP BY certainty";
Stringsql2="SELECT sum(IFNULL(IF(pe.is_budget = 1, pe.contract_amount, p.contract_amount),0)) AS sum, avg(IFNULL(IF(pe.is_budget = 1, pe.gross_profit_margin, p.gross_profit_margin),0)) AS average, p.certainty, p.certainty_str as name, pe.is_budget FROM project p LEFT JOIN project_extend pe ON p.id = pe.project_id WHERE p.certainty >= 1 and p.approve_status_estimate >= 1 AND p.approve_status_estimate <= 2 AND p.dept_name = '销售管理部' GROUP BY p.certainty";