642 lines
32 KiB
C#
642 lines
32 KiB
C#
using BLL;
|
||
using Model;
|
||
using Newtonsoft.Json;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data.SqlClient;
|
||
using System.Linq;
|
||
using System.Web;
|
||
using System.Web.Script.Serialization;
|
||
using System.Web.SessionState;
|
||
|
||
namespace FineUIPro.Web.common
|
||
{
|
||
/// <summary>
|
||
/// main1 的摘要说明
|
||
/// </summary>
|
||
public class main1 : IHttpHandler, IRequiresSessionState
|
||
{
|
||
public static Model.FCLDB db = Funs.DB;
|
||
JavaScriptSerializer j = new JavaScriptSerializer();
|
||
private void ResponseError(HttpContext context)
|
||
{
|
||
// 出错了
|
||
context.Response.StatusCode = 500;
|
||
context.Response.Write("Error occurred!");
|
||
}
|
||
|
||
public void ProcessRequest(HttpContext context)
|
||
{
|
||
string strJson = string.Empty;
|
||
string action = context.Request.Form["action"];
|
||
string Contractor = context.Request.Form["Contractor"] != null ? context.Request.Form["Contractor"].Trim() : "";
|
||
string FO_NO = context.Request.Form["FO_NO"] != null ? context.Request.Form["FO_NO"].Trim() : "";
|
||
if (action == "mainkpi")
|
||
{
|
||
string start = string.IsNullOrEmpty(context.Request.Form["startTime"]) ? DateTime.Now.AddYears(-1).ToString("yyyy-MM") + "-1" : context.Request.Form["startTime"].Replace("/", "-") + "-1";
|
||
string end = string.IsNullOrEmpty(context.Request.Form["endTime"]) ? DateTime.Now.ToString("yyyy-MM") + "-1" : context.Request.Form["endTime"].Replace("/", "-") + "-1";
|
||
MainKpi mKpi = new MainKpi();
|
||
//kpi1
|
||
string kpi1xAxis = string.Empty;
|
||
string kpi1serieshze = string.Empty;
|
||
string kpi1serieshzl = string.Empty;
|
||
string kpi1DateEnd = "100";
|
||
//kpi2
|
||
string kpi2serieshze = string.Empty;
|
||
string kpi2serieshzl = string.Empty;
|
||
string kpi2series = string.Empty;
|
||
//kpi3
|
||
string kpi3xAxis = string.Empty;//名称
|
||
string kpi3seriesSsr = string.Empty;//金额
|
||
string kpi3serieshzl = string.Empty;//利率
|
||
string kpi3DateEnd = "100";//显示占比
|
||
|
||
int sYear = int.Parse(start.Split('-')[0]);
|
||
int sMonth = int.Parse(start.Split('-')[1]);
|
||
int eYear = int.Parse(end.Split('-')[0]);
|
||
int eMonth = int.Parse(end.Split('-')[1]);
|
||
DateTime stDate = DateTime.Parse(start);
|
||
DateTime enDate = LastDayOfMonth(DateTime.Parse(end));
|
||
int sumMonth = (eYear - sYear) * 12 + (eMonth - sMonth);
|
||
if (sumMonth > 10)
|
||
{
|
||
kpi1DateEnd = (sumMonth > 10 && sumMonth < 20) ? "60" : (sumMonth > 20 && sumMonth < 30) ? "40" : sumMonth > 30 ? "30" : "20";
|
||
}
|
||
//根据FoNo计算
|
||
var ContractFoNoList = Funs.DB.ContractorKpiView.Where(p => p.Contract_No == FO_NO).ToList();
|
||
//KPI2根据SES计算(因为DateMonth是string类型,lambda里面string类型无法进行>=和<=)
|
||
var ContractSesDt = SQLHelper.GetDataTableRunText("SELECT Quotation as Hze,(case when Deduction>0 then Deduction/Quotation*100 else 0 end) as Hzl,SES from ContractorKpi0View where Contract_No='" + FO_NO + "' and DateMonth>='" + stDate.ToString("yyyy-MM") + "' and DateMonth<='" + enDate.ToString("yyyy-MM") + "'", new SqlParameter[0]);
|
||
var ContractSesList = JsonConvert.DeserializeObject<List<KpiSesNo>>(JsonConvert.SerializeObject(ContractSesDt));
|
||
//KPI3获取数据
|
||
var ConractDepDt = SQLHelper.GetDataTableRunText("SELECT Section,SUM(Net_Value) as NumVal,(case when SUM(Deduction)>0 then (SUM(Deduction)/SUM(Quotation)*100) else 0 end) as Rate from ContractorKpi0View as a where a.Contract_No='" + FO_NO + "' and a.DateMonth>='" + stDate.ToString("yyyy-MM") + "' and a.DateMonth<='" + enDate.ToString("yyyy-MM") + "' and isnull(Section,'')!='' group by a.Section ORDER BY Section asc", new SqlParameter[0]);
|
||
var ContractDepList = JsonConvert.DeserializeObject<List<KPIConDep>>(JsonConvert.SerializeObject(ConractDepDt));
|
||
|
||
#region kpi1
|
||
for (DateTime dt = DateTime.Parse(start); dt <= DateTime.Parse(end); dt = dt.AddMonths(1))
|
||
{
|
||
kpi1xAxis += string.IsNullOrEmpty(kpi1xAxis) ? dt.ToString("yyyy-MM") : "," + dt.ToString("yyyy-MM");
|
||
if (ContractFoNoList.Count > 0)
|
||
{
|
||
var kpiContractModel = ContractFoNoList.FirstOrDefault(p => p.DateMonth == dt.ToString("yyyy-MM"));
|
||
if (kpiContractModel != null)
|
||
{
|
||
if (kpiContractModel.Deduction.Value < 0)
|
||
{
|
||
kpiContractModel.Deduction = 0;
|
||
}
|
||
if (decimal.Parse(kpiContractModel.Rate) < 0) kpiContractModel.Rate = "0";
|
||
|
||
kpi1serieshze += string.IsNullOrEmpty(kpi1serieshze) ? string.Format("{0:N}", kpiContractModel.Deduction.Value) : "," + string.Format("{0:N}", kpiContractModel.Deduction.Value);
|
||
kpi1serieshzl += string.IsNullOrEmpty(kpi1serieshzl) ? decimal.Parse(kpiContractModel.Rate).ToString("0.##") : "," + decimal.Parse(kpiContractModel.Rate).ToString("0.##");
|
||
}
|
||
else
|
||
{
|
||
kpi1serieshze += string.IsNullOrEmpty(kpi1serieshze) ? "0" : ",0";
|
||
kpi1serieshzl += string.IsNullOrEmpty(kpi1serieshzl) ? "0" : ",0";
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
kpi1serieshze += string.IsNullOrEmpty(kpi1serieshze) ? "0" : ",0";
|
||
kpi1serieshzl += string.IsNullOrEmpty(kpi1serieshzl) ? "0" : ",0";
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region kpi2
|
||
if (ContractSesList.Count > 0)
|
||
{
|
||
kpi2serieshze = string.Join(",", ContractSesList.Select(p => p.Hze).ToList());
|
||
kpi2serieshzl = string.Join(",", ContractSesList.Select(p => decimal.Parse(p.Hzl).ToString("0.##")).ToList());
|
||
kpi2series = string.Join(",", ContractSesList.Select(p => p.SES).ToList());
|
||
}
|
||
#endregion
|
||
|
||
#region KPI3
|
||
if (ContractDepList.Count > 0)
|
||
{
|
||
//名称
|
||
kpi3xAxis = string.Join(",", ContractDepList.Select(p => p.Section).ToList());
|
||
//金额
|
||
kpi3seriesSsr = string.Join(",", ContractDepList.Select(p => p.NumVal.ToString("0.##")).ToList());
|
||
//利率
|
||
kpi3serieshzl = string.Join(",", ContractDepList.Select(p => p.Rate.ToString("0.##")).ToList());
|
||
//显示占比
|
||
if (ContractDepList.Count > 10)
|
||
{
|
||
kpi3DateEnd = (ContractDepList.Count > 10 && ContractDepList.Count < 20) ? "60" : (ContractDepList.Count > 20 && ContractDepList.Count < 30) ? "40" : (ContractDepList.Count > 30 && ContractDepList.Count < 35) ? "30" : "20";
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
mKpi.Kpi1json = kpi1xAxis + "||" + kpi1serieshze + "||" + kpi1serieshzl + "||" + kpi1DateEnd;
|
||
mKpi.Kpi2json = kpi2serieshze + "||" + kpi2serieshzl + "||" + kpi2series;
|
||
mKpi.Kpi3json = kpi3xAxis + "||" + kpi3seriesSsr + "||" + kpi3serieshzl + "||" + kpi3DateEnd;
|
||
strJson = j.Serialize(mKpi);
|
||
}
|
||
if (action == "kpir")
|
||
{
|
||
string rStart = string.IsNullOrEmpty(context.Request.Form["startTime"]) ? DateTime.Now.AddMonths(-11).ToString("yyyy-MM") + "-01" : DateTime.Parse(context.Request.Form["startTime"].Replace("/", "-")).ToString("yyyy-MM") + "-01";
|
||
string rEnd = string.IsNullOrEmpty(context.Request.Form["endTime"]) ? DateTime.Now.ToString("yyyy-MM") + "-01" : DateTime.Parse(context.Request.Form["endTime"].Replace("/", "-")).ToString("yyyy-MM") + "-01";
|
||
LKPR kpir = new LKPR();
|
||
string kpirlegend = string.Empty;
|
||
string kpirxAxis = string.Empty;
|
||
string kpirUser = string.Empty;
|
||
string kpirDep = string.Empty;
|
||
string kpirAll = string.Empty;
|
||
var kpi1DateEnd = "100";
|
||
int sYear = int.Parse(rStart.Split('-')[0]);
|
||
int sMonth = int.Parse(rStart.Split('-')[1]);
|
||
int eYear = int.Parse(rEnd.Split('-')[0]);
|
||
int eMonth = int.Parse(rEnd.Split('-')[1]);
|
||
DateTime stDate = DateTime.Parse(rStart);
|
||
DateTime enDate = LastDayOfMonth(DateTime.Parse(rEnd));
|
||
int sumMonth = (eYear - sYear) * 12 + (eMonth - sMonth);
|
||
if (sumMonth > 10)
|
||
{
|
||
kpi1DateEnd = (sumMonth > 10 && sumMonth < 20) ? "60" : (sumMonth > 20 && sumMonth < 30) ? "40" : sumMonth > 30 ? "30" : "20";
|
||
kpi1DateEnd = sumMonth <= 12 ? "100": (sumMonth > 12 && sumMonth < 20) ? "70" : (sumMonth > 20 && sumMonth < 30) ? "50" : sumMonth > 30 ? "30" : "20";
|
||
}
|
||
var kpirDt = SQLHelper.RunSqlString("exec FN_SumScore '" + rStart + "','" + rEnd + "','" + FO_NO + "'", "KPIR");
|
||
var KpiRList = JsonConvert.DeserializeObject<List<KPIRScore>>(JsonConvert.SerializeObject(kpirDt.Tables[0]));
|
||
if (KpiRList.Count > 0)
|
||
{
|
||
for (DateTime dt = DateTime.Parse(rStart); dt <= DateTime.Parse(rEnd); dt = dt.AddMonths(1))
|
||
{
|
||
var userScore = KpiRList.FirstOrDefault(p => p.DataMonth == dt.ToString("yyyy-MM"));
|
||
kpirxAxis += string.IsNullOrEmpty(kpirxAxis) ? dt.ToString("yyyy-MM") : "," + dt.ToString("yyyy-MM");
|
||
|
||
kpirUser += string.IsNullOrEmpty(kpirUser) ? (userScore != null ? userScore.UserScore.ToString("0.##") : "0") : (userScore != null ? "," + userScore.UserScore.ToString("0.##") : ",0");
|
||
|
||
kpirDep += string.IsNullOrEmpty(kpirDep) ? (userScore != null ? userScore.DepScore.ToString("0.##") : "0") : (userScore != null ? "," + userScore.DepScore.ToString("0.##") : ",0");
|
||
|
||
kpirAll += string.IsNullOrEmpty(kpirAll) ? (userScore != null ? userScore.AllScore.ToString("0.##") : "0") : (userScore != null ? "," + userScore.AllScore.ToString("0.##") : ",0");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
for (DateTime dt = DateTime.Parse(rStart); dt <= DateTime.Parse(rEnd); dt = dt.AddMonths(1))
|
||
{
|
||
kpirUser += string.IsNullOrEmpty(kpirUser) ? "0" : ",0";
|
||
kpirDep += string.IsNullOrEmpty(kpirDep) ? "0" : ",0";
|
||
kpirAll += string.IsNullOrEmpty(kpirAll) ? "0" : ",0";
|
||
}
|
||
}
|
||
kpir.kpirJson = kpirlegend + "||" + kpirxAxis + "||" + kpi1DateEnd + "||" + kpirUser + "||" + kpirDep + "||" + kpirAll;
|
||
strJson = j.Serialize(kpir);
|
||
}
|
||
if (action == "kpi")
|
||
{
|
||
string start = string.IsNullOrEmpty(context.Request.Form["startTime"]) ? DateTime.Now.AddYears(-1).ToString("yyyy-MM") + "-1" : context.Request.Form["startTime"].Replace("/", "-") + "-1";
|
||
string end = string.IsNullOrEmpty(context.Request.Form["endTime"]) ? DateTime.Now.ToString("yyyy-MM") + "-1" : context.Request.Form["endTime"].Replace("/", "-") + "-1";
|
||
KPI kpiModel = new KPI();
|
||
//kpi4
|
||
string kpi4xAxis = string.Empty;
|
||
string kpi4serieshze = string.Empty;
|
||
string kpi4serieshzl = string.Empty;
|
||
string kpi4DateEnd = "100";
|
||
//kpi5
|
||
string kpi5serieshze = string.Empty;
|
||
string kpi5serieshzl = string.Empty;
|
||
string kpi5series = string.Empty;
|
||
string titleName = string.Empty;
|
||
//kpi6
|
||
string kpi6xAxis = string.Empty;
|
||
string kpi6seriesSsr = string.Empty;
|
||
string kpi6serieshzl = string.Empty;
|
||
string kpi6DateEnd = "100";
|
||
//kpi7
|
||
string kpi7xAxis = string.Empty;
|
||
string kpi7seriesSsr = string.Empty;
|
||
string kpi7Count = string.Empty;
|
||
string kpi7DateEnd = "100";
|
||
string kpi7titleName = string.Empty;
|
||
//kpi8
|
||
string kpi8xAxis = string.Empty;
|
||
string kpi8ssrCost = string.Empty;
|
||
string kpi8DateEnd = "100";
|
||
string kpi8titleName = string.Empty;
|
||
//KPI9
|
||
string kpi9legendDate = string.Empty;
|
||
string kpi9xAxis = string.Empty;
|
||
string kpi9DateEnd = "100";
|
||
//KPIOther
|
||
string kpioxAxis = string.Empty;
|
||
string kpioserieshze = string.Empty;
|
||
string kpioserieshzl = string.Empty;
|
||
string kpioDateEnd = "100";
|
||
|
||
int sYear = int.Parse(start.Split('-')[0]);
|
||
int sMonth = int.Parse(start.Split('-')[1]);
|
||
int eYear = int.Parse(end.Split('-')[0]);
|
||
int eMonth = int.Parse(end.Split('-')[1]);
|
||
DateTime stDate = DateTime.Parse(start);
|
||
DateTime enDate = LastDayOfMonth(DateTime.Parse(end));
|
||
//kpi获取数据sql
|
||
var kpiDt = SQLHelper.RunSqlString("exec FN_Kpi '" + stDate.ToString("yyyy-MM") + "','" + enDate.ToString("yyyy-MM") + "','0'", "KPI");
|
||
|
||
#region kpi4
|
||
var Kpi4List = JsonConvert.DeserializeObject<List<KpiMonth>>(JsonConvert.SerializeObject(kpiDt.Tables[0]));
|
||
if (Kpi4List.Count > 0)
|
||
{
|
||
var kpi4Order = Kpi4List.OrderBy(x => x.DateMonth);
|
||
kpi4xAxis = string.Join(",", kpi4Order.Select(p => p.DateMonth).ToList());
|
||
kpi4serieshze = string.Join(",", kpi4Order.Select(p => p.NumVal.ToString("0.#")).ToList());
|
||
kpi4serieshzl = string.Join(",", kpi4Order.Select(p => p.Rate.ToString("0.#")).ToList());
|
||
//if (Kpi4List.Count > 10)
|
||
//{
|
||
// kpi4DateEnd = (Kpi4List.Count > 10 && Kpi4List.Count < 20) ? "60" : (Kpi4List.Count > 20 && Kpi4List.Count < 30) ? "40" : (Kpi4List.Count > 30 && Kpi4List.Count < 40) ? "30" : "20";
|
||
//}
|
||
}
|
||
#endregion
|
||
|
||
#region kpi5
|
||
var Kpi5List = JsonConvert.DeserializeObject<List<KPI5Contract>>(JsonConvert.SerializeObject(kpiDt.Tables[2]));
|
||
if (Kpi5List.Count > 0)
|
||
{
|
||
kpi5serieshze = string.Join(",", Kpi5List.Select(p => p.NumVal.ToString("0.##")).ToList());
|
||
kpi5serieshzl = string.Join(",", Kpi5List.Select(p => p.Rate.ToString("0.##")).ToList());
|
||
kpi5series = string.Join(",", Kpi5List.Select(p => p.Contract_No + "(" + p.Contractor + ")").ToList());
|
||
titleName = "Overall Dedcution Cost:" + kpiDt.Tables[1].Rows[0]["dSumDeduction"] + ",Overall Deduction Rate:" + (100.0 * float.Parse(kpiDt.Tables[1].Rows[0]["dSumDeduction"].ToString()) / float.Parse(kpiDt.Tables[1].Rows[0]["dSumQuotation"].ToString())).ToString("#.##") + "%,Average Deduction Rate:" + decimal.Parse(kpiDt.Tables[1].Rows[0]["dAverageDeductionRate"].ToString()).ToString("0.##") + "%";
|
||
}
|
||
#endregion
|
||
|
||
#region KPI6,KPI7
|
||
var Kpi6List = JsonConvert.DeserializeObject<List<KPIConDep>>(JsonConvert.SerializeObject(kpiDt.Tables[3]));
|
||
if (Kpi6List.Count > 0)
|
||
{
|
||
kpi6xAxis = string.Join(",", Kpi6List.Select(p => p.Section).ToList());
|
||
kpi6seriesSsr = string.Join(",", Kpi6List.Select(p => p.NumVal.ToString("0.#")).ToList());
|
||
kpi6serieshzl = string.Join(",", Kpi6List.Select(p => p.Rate.ToString("0.#")).ToList());
|
||
|
||
kpi7xAxis = string.Join(",", Kpi6List.Select(p => p.Section).ToList());
|
||
kpi7seriesSsr = string.Join(",", Kpi6List.Select(p => p.NetVal.ToString("0.#")).ToList());
|
||
kpi7Count = string.Join(",", Kpi6List.Select(p => p.SesNum).ToList());
|
||
kpi7titleName = "User Sample Analyse \n SSR Cost: " + Kpi6List.Sum(p => p.NetVal) + " RMB/SSR Count: " + Kpi6List.Sum(p => p.SesNum) + "";
|
||
|
||
//kpi6DateEnd = kpi7DateEnd = Kpi6List.Count > 20 && Kpi6List.Count < 30 ? "60" : Kpi6List.Count > 30 && Kpi6List.Count < 40 ? "40" : Kpi6List.Count > 40 && Kpi6List.Count < 50 ? "30" : "20";
|
||
}
|
||
#endregion
|
||
|
||
#region KPI8
|
||
var Kpi8List = JsonConvert.DeserializeObject<List<KPI8Contract>>(JsonConvert.SerializeObject(kpiDt.Tables[4]));
|
||
var Kpi8Top20List = JsonConvert.DeserializeObject<List<KPI8Contract>>(JsonConvert.SerializeObject(kpiDt.Tables[5]));
|
||
if (Kpi8List.Count > 0)
|
||
{
|
||
kpi8xAxis = string.Join(",", Kpi8List.Select(p => p.Contractor).ToList());
|
||
kpi8ssrCost = string.Join(",", Kpi8List.Select(p => (p.NetVal / 1000).ToString("0.##")).ToList());
|
||
kpi8DateEnd = Kpi8List.Count > 5 && Kpi8List.Count < 10 ? "60" : Kpi8List.Count > 10 && Kpi8List.Count < 15 ? "40" : Kpi8List.Count > 15 && Kpi8List.Count < 20 ? "30" : Kpi8List.Count > 20 && Kpi8List.Count < 25 ? "20" : Kpi8List.Count > 25 && Kpi8List.Count < 30 ? "10" : "5";
|
||
|
||
var topVal = Kpi8Top20List.Count > 0 ? Kpi8Top20List.Sum(p => p.NetVal).ToString("0.##") : "0";
|
||
kpi8titleName = "Contractor Cost \n All Contractor Cost: " + Kpi8List.Sum(p => p.NetVal).ToString("0.##") + " RMB/The TOP 20 Contractor Cost: " + topVal + " RMB";
|
||
}
|
||
#endregion
|
||
|
||
#region KPI9
|
||
var Kpi9List = JsonConvert.DeserializeObject<List<KPI9Dep>>(JsonConvert.SerializeObject(kpiDt.Tables[6]));
|
||
var kpiDis = Kpi9List.Select(p => p.Dis).Distinct().ToList();
|
||
var KpiDepCount = Kpi9List.GroupBy(p => p.Section).Count();
|
||
List<ZBKPI> zbList = new List<ZBKPI>();
|
||
if (Kpi9List.Count > 0)
|
||
{
|
||
foreach (var itemDis in kpiDis)
|
||
{
|
||
ZBKPI zbModel = new ZBKPI();
|
||
zbModel.name = itemDis;
|
||
foreach (var item in Kpi9List.Select(p => p.Section).Distinct().ToList())
|
||
{
|
||
var DepNetVal = Kpi9List.Where(p => p.Section == item).Sum(p => p.NetVal);
|
||
var DisNetVal = Kpi9List.Where(p => p.Section == item && p.Dis.Contains(itemDis)).Sum(p => p.NetVal);
|
||
var disVal = DisNetVal > 0 ? Round((float)(DisNetVal / DepNetVal) * 100, 2) : 0;
|
||
zbModel.data.Add(disVal);
|
||
}
|
||
zbList.Add(zbModel);
|
||
}
|
||
kpi9legendDate = string.Join(",", kpiDis);
|
||
kpi9xAxis = string.Join(",", Kpi9List.Select(p => p.Section).Distinct().ToList());
|
||
//kpi9DateEnd = KpiDepCount > 10 && KpiDepCount < 20 ? "60" : KpiDepCount > 20 && KpiDepCount < 30 ? "40" : KpiDepCount > 30 && KpiDepCount < 40 ? "30" : "20";
|
||
}
|
||
#endregion
|
||
|
||
#region KPIOther
|
||
var KpiOtherList = JsonConvert.DeserializeObject<List<KPIOther>>(JsonConvert.SerializeObject(kpiDt.Tables[7]));
|
||
if (KpiOtherList.Count > 0)
|
||
{
|
||
kpioxAxis = string.Join(",", KpiOtherList.Select(p => p.Dis).ToList());
|
||
kpioserieshze = string.Join(",", KpiOtherList.Select(p => (p.NumVal < 0 ? 0 : p.NumVal).ToString("0.#")).ToList());
|
||
kpioserieshzl = string.Join(",", KpiOtherList.Select(p => (p.Rate < 0 ? 0 : p.Rate).ToString("0.#")).ToList());
|
||
//kpioDateEnd = KpiOtherList.Count > 10 && KpiOtherList.Count < 20 ? "60" : KpiOtherList.Count > 20 && KpiOtherList.Count < 30 ? "40" : KpiOtherList.Count > 30 && KpiOtherList.Count < 40 ? "30" : "20";
|
||
}
|
||
#endregion
|
||
|
||
kpiModel.Kpi4json = kpi4xAxis + "||" + kpi4serieshze + "||" + kpi4serieshzl + "||" + kpi4DateEnd;
|
||
kpiModel.Kpi5json = kpi5serieshze + "||" + kpi5serieshzl + "||" + kpi5series + "||" + titleName;
|
||
kpiModel.Kpi6json = kpi6xAxis + "||" + kpi6seriesSsr + "||" + kpi6serieshzl + "||" + kpi6DateEnd;
|
||
kpiModel.Kpi7json = kpi7xAxis + "||" + kpi7seriesSsr + "||" + kpi7Count + "||" + kpi7DateEnd + "||" + kpi7titleName;
|
||
kpiModel.Kpi8json = kpi8xAxis + "||" + kpi8ssrCost + "||" + kpi8DateEnd + "||" + kpi8titleName;
|
||
kpiModel.Kpi9json = kpi9legendDate + "||" + kpi9xAxis + "||" + kpi9DateEnd;
|
||
kpiModel.kpi9series = zbList;
|
||
kpiModel.Kpiojson = kpioxAxis + "||" + kpioserieshze + "||" + kpioserieshzl + "||" + kpioDateEnd;
|
||
strJson = j.Serialize(kpiModel);
|
||
}
|
||
if (action == "kpisearchdep")
|
||
{
|
||
string start = string.IsNullOrEmpty(context.Request.Form["startTime"]) ? DateTime.Now.AddYears(-1).ToString("yyyy-MM") + "-1" : context.Request.Form["startTime"].Replace("/", "-") + "-1";
|
||
string end = string.IsNullOrEmpty(context.Request.Form["endTime"]) ? DateTime.Now.ToString("yyyy-MM") + "-1" : context.Request.Form["endTime"].Replace("/", "-") + "-1";
|
||
string kpitype = context.Request.Form["kpitype"];
|
||
KPI kpiModel = new KPI();
|
||
//KPI9
|
||
string kpi9legendDate = string.Empty;
|
||
string kpi9xAxis = string.Empty;
|
||
string kpi9DateEnd = "100";
|
||
int sYear = int.Parse(start.Split('-')[0]);
|
||
int sMonth = int.Parse(start.Split('-')[1]);
|
||
int eYear = int.Parse(end.Split('-')[0]);
|
||
int eMonth = int.Parse(end.Split('-')[1]);
|
||
DateTime stDate = DateTime.Parse(start);
|
||
DateTime enDate = LastDayOfMonth(DateTime.Parse(end));
|
||
//kpi获取数据sql
|
||
var kpiDt = SQLHelper.RunSqlString("exec FN_Kpi '" + stDate.ToString("yyyy-MM") + "','" + enDate.ToString("yyyy-MM") + "','" + kpitype + "'", "KPI");
|
||
|
||
#region KPI9
|
||
var Kpi9List = JsonConvert.DeserializeObject<List<KPI9Dep>>(JsonConvert.SerializeObject(kpiDt.Tables[0]));
|
||
var kpiDis = Kpi9List.Select(p => p.Dis).Distinct().ToList();
|
||
var KpiDepCount = Kpi9List.GroupBy(p => p.Section).Count();
|
||
List<ZBKPI> zbList = new List<ZBKPI>();
|
||
if (Kpi9List.Count > 0)
|
||
{
|
||
foreach (var itemDis in kpiDis)
|
||
{
|
||
ZBKPI zbModel = new ZBKPI();
|
||
zbModel.name = itemDis;
|
||
foreach (var item in Kpi9List.Select(p => p.Section).Distinct().ToList())
|
||
{
|
||
var DepNetVal = Kpi9List.Where(p => p.Section == item).Sum(p => p.NetVal);
|
||
var DisNetVal = Kpi9List.Where(p => p.Section == item && p.Dis.Contains(itemDis)).Sum(p => p.NetVal);
|
||
var disVal = DisNetVal > 0 ? Round((float)(DisNetVal / DepNetVal) * 100, 2) : 0;
|
||
zbModel.data.Add(disVal);
|
||
}
|
||
zbList.Add(zbModel);
|
||
}
|
||
kpi9legendDate = string.Join(",", kpiDis);
|
||
kpi9xAxis = string.Join(",", Kpi9List.Select(p => p.Section).Distinct().ToList());
|
||
//kpi9DateEnd = KpiDepCount > 10 && KpiDepCount < 20 ? "60" : KpiDepCount > 20 && KpiDepCount < 30 ? "40" : KpiDepCount > 30 && KpiDepCount < 40 ? "30" : "100";
|
||
}
|
||
#endregion
|
||
|
||
kpiModel.Kpi9json = kpi9legendDate + "||" + kpi9xAxis + "||" + kpi9DateEnd;
|
||
kpiModel.kpi9series = zbList;
|
||
strJson = j.Serialize(kpiModel);
|
||
}
|
||
|
||
context.Response.Write(strJson);
|
||
}
|
||
|
||
#region KPI图Model
|
||
/// <summary>
|
||
/// MainKpi
|
||
/// </summary>
|
||
public class MainKpi
|
||
{
|
||
public string Kpi1json { get; set; } = string.Empty;
|
||
public string Kpi2json { get; set; } = string.Empty;
|
||
public string Kpi3json { get; set; } = string.Empty;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 右边的KPI
|
||
/// </summary>
|
||
public class LKPR
|
||
{
|
||
public string kpirJson { get; set; } = string.Empty;
|
||
}
|
||
|
||
/// <summary>
|
||
/// KPI
|
||
/// </summary>
|
||
public class KPI
|
||
{
|
||
public string Kpi4json { get; set; } = string.Empty;
|
||
public string Kpi5json { get; set; } = string.Empty;
|
||
public string Kpi6json { get; set; } = string.Empty;
|
||
public string Kpi7json { get; set; } = string.Empty;
|
||
public string Kpi8json { get; set; } = string.Empty;
|
||
public string Kpi9json { get; set; } = string.Empty;
|
||
public List<ZBKPI> kpi9series { get; set; } = new List<ZBKPI>();
|
||
public string Kpiojson { get; set; } = string.Empty;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 占比柱状图
|
||
/// </summary>
|
||
public class ZBKPI
|
||
{
|
||
public string name { get; set; } = string.Empty;
|
||
public string type { get; set; } = "bar";
|
||
public string stack { get; set; } = "tb";
|
||
public string barWidth { get; set; } = "30";
|
||
public List<float> data { get; set; } = new List<float>();
|
||
}
|
||
#endregion
|
||
|
||
#region KPI数据Model
|
||
/// <summary>
|
||
/// kpi2中,datatable转换list
|
||
/// </summary>
|
||
public class KpiSesNo
|
||
{
|
||
/// <summary>
|
||
/// 核准率
|
||
/// </summary>
|
||
public string Hzl { get; set; }
|
||
/// <summary>
|
||
/// 核准额
|
||
/// </summary>
|
||
public string Hze { get; set; }
|
||
/// <summary>
|
||
/// ses
|
||
/// </summary>
|
||
public string SES { get; set; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// KPI3,KPI6,KPI7中 承包商部门分布
|
||
/// </summary>
|
||
public class KPIConDep
|
||
{
|
||
/// <summary>
|
||
/// 部门名称
|
||
/// </summary>
|
||
public string Section { get; set; } = string.Empty;
|
||
/// <summary>
|
||
/// 核减率
|
||
/// </summary>
|
||
public decimal Rate { get; set; }
|
||
/// <summary>
|
||
/// 核减额
|
||
/// </summary>
|
||
public decimal NumVal { get; set; }
|
||
/// <summary>
|
||
/// 合同SES数量
|
||
/// </summary>
|
||
public int SesNum { get; set; } = 0;
|
||
/// <summary>
|
||
/// Net_Value
|
||
/// </summary>
|
||
public decimal NetVal { get; set; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// KPI4中按月实体
|
||
/// </summary>
|
||
public class KpiMonth
|
||
{
|
||
/// <summary>
|
||
/// 数值
|
||
/// </summary>
|
||
public decimal NumVal { get; set; }
|
||
/// <summary>
|
||
/// 利率
|
||
/// </summary>
|
||
public decimal Rate { get; set; }
|
||
/// <summary>
|
||
/// 月份
|
||
/// </summary>
|
||
public string DateMonth { get; set; }
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// KPI5实体
|
||
/// </summary>
|
||
public class KPI5Contract
|
||
{
|
||
/// <summary>
|
||
/// 利率
|
||
/// </summary>
|
||
public decimal Rate { get; set; }
|
||
/// <summary>
|
||
/// 额度
|
||
/// </summary>
|
||
public decimal NumVal { get; set; }
|
||
/// <summary>
|
||
/// 合同号
|
||
/// </summary>
|
||
public string Contract_No { get; set; } = string.Empty;
|
||
/// <summary>
|
||
/// 承包商名称
|
||
/// </summary>
|
||
public string Contractor { get; set; } = string.Empty;
|
||
}
|
||
|
||
/// <summary>
|
||
/// KPI8实体
|
||
/// </summary>
|
||
public class KPI8Contract
|
||
{
|
||
/// <summary>
|
||
/// 承包商名称
|
||
/// </summary>
|
||
public string Contractor { get; set; }
|
||
/// <summary>
|
||
/// 承包商数值
|
||
/// </summary>
|
||
public decimal NetVal { get; set; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// KPI9实体
|
||
/// </summary>
|
||
public class KPI9Dep
|
||
{
|
||
/// <summary>
|
||
/// 部门
|
||
/// </summary>
|
||
public string Section { get; set; }
|
||
/// <summary>
|
||
/// 类型
|
||
/// </summary>
|
||
public string Dis { get; set; }
|
||
/// <summary>
|
||
/// 数值
|
||
/// </summary>
|
||
public decimal NetVal { get; set; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// KPIOther实体
|
||
/// </summary>
|
||
public class KPIOther
|
||
{
|
||
/// <summary>
|
||
/// 部门
|
||
/// </summary>
|
||
public string Dis { get; set; }
|
||
/// <summary>
|
||
/// 数值
|
||
/// </summary>
|
||
public decimal NumVal { get; set; }
|
||
/// <summary>
|
||
/// 利率
|
||
/// </summary>
|
||
public decimal Rate { get; set; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 右边的KPI实体
|
||
/// </summary>
|
||
public class KPIRScore
|
||
{
|
||
public string NewGuid { get; set; }
|
||
public string Contract_No { get; set; }
|
||
public string DataMonth { get; set; }
|
||
public decimal UserScore { get; set; }
|
||
public decimal DepScore { get; set; }
|
||
public decimal AllScore { get; set; }
|
||
}
|
||
|
||
#endregion
|
||
|
||
|
||
public bool IsReusable
|
||
{
|
||
get
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 取得某月的第一天
|
||
/// </summary>
|
||
/// <param name="datetime">要取得月份第一天的时间</param>
|
||
/// <returns></returns>
|
||
private DateTime FirstDayOfMonth(DateTime datetime)
|
||
{
|
||
return datetime.AddDays(1 - datetime.Day);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 取得某月的最后一天
|
||
/// </summary>
|
||
/// <param name="datetime">要取得月份最后一天的时间</param>
|
||
/// <returns></returns>
|
||
private DateTime LastDayOfMonth(DateTime datetime)
|
||
{
|
||
return datetime.AddDays(1 - datetime.Day).AddMonths(1).AddDays(-1);
|
||
}
|
||
|
||
public static float Round(float score, int pointCount)
|
||
{
|
||
try
|
||
{
|
||
return Convert.ToSingle(Math.Round(Convert.ToDecimal(score), pointCount, MidpointRounding.AwayFromZero));
|
||
}
|
||
catch
|
||
{
|
||
return Convert.ToSingle(Math.Round(score, pointCount));
|
||
}
|
||
}
|
||
}
|
||
} |