using EC.App.AutoWeight.MonthPlan; using EC.App.AutoWeight.Report; using EC.App.AutoWeight.TransportBill; using learun.util; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace EC.Web.Areas.AutoWeight.Controllers { [Area("AutoWeight")] public class ReportController : MvcControllerBase { private readonly ReportIBll _bll; public ReportController(ReportIBll bll) { _bll = bll; } #region 视图功能 public IActionResult StatisticsSheetByDay() { return View(); } public IActionResult StatisticsSheetByMonth() { return View(); } public IActionResult StatisticsSheetByYear() { return View(); } public IActionResult BillVolumeScatterChartByDay() { return View(); } public IActionResult BillVolumeLineChartByMonth() { return View(); } public IActionResult BillRateScatterChartByDay() { return View(); } public IActionResult BillRateScatterChartByMonth() { return View(); } public IActionResult TruckGradeSheetByMonth() { return View(); } #endregion 视图功能 #region 获取数据 /// /// CompanyId,SupplierId,StartTime,EndTime,State /// /// /// [HttpGet] [AjaxOnly] public async Task GetPlanInfoList(string queryJson) { var queryParam = queryJson.ToJObject(); var monthPlanList = (!queryParam["CompanyId"].IsEmpty()) ? (await _bll.GetMonthPlanList(queryParam)).ToList() : new List(); var planInfoList = new List(); foreach (var plan in monthPlanList) { queryParam["PlanSerialNumber"] = plan.SerialNumber; var planInfo = (!queryParam["CompanyId"].IsEmpty()) ? (await _bll.GetMonthPlanInfo(queryParam)) : new MonthPlanInfoDto(); if (plan?.PlanQty != null) planInfo.PlanQty = (decimal)plan?.PlanQty; if (plan?.ActQty != null) planInfo.ActQty = (decimal)plan?.ActQty; planInfo.CreateTime = plan.CreateTime; planInfoList.Add(planInfo); } var jsonData = new { planInfoList }; return Success(jsonData); } /// /// CompanyId,SupplierId,StartTime,EndTime,State /// /// /// [HttpGet] [AjaxOnly] public async Task GetStatisticsDataByDay(string queryJson) { var queryParam = queryJson.ToJObject(); var billList = (!queryParam["CompanyId"].IsEmpty()) && !queryParam["SupplierId"].IsEmpty() ? await _bll.GetStatisticsBillListByDay(queryParam) : new List(); var jsonData = new { billList }; return Success(jsonData); } /// /// CompanyId,SupplierId,StartTime,EndTime,State /// /// /// [HttpGet] [AjaxOnly] public async Task GetStatisticsDataByMonth(string queryJson) { var queryParam = queryJson.ToJObject(); var dayDtoList = (!queryParam["CompanyId"].IsEmpty()) && !queryParam["SupplierId"].IsEmpty() ? await _bll.GetStatisticsDataListByMonth(queryParam) : new List(); var jsonData = new { dayDtoList }; return Success(jsonData); } /// /// CompanyId,SupplierId,StartTime,EndTime,State /// /// /// [HttpGet] [AjaxOnly] public async Task GetStatisticsDataByYear(string queryJson) { var queryParam = queryJson.ToJObject(); var monthDtoList = (!queryParam["CompanyId"].IsEmpty()) && !queryParam["SupplierId"].IsEmpty() ? await _bll.GetStatisticsDataListByYear(queryParam) : new List(); var jsonData = new { monthDtoList }; return Success(jsonData); } /// /// CompanyId,StartTime,EndTime,State /// /// /// [HttpGet] [AjaxOnly] public async Task GetBillVolumeListByDay(string queryJson) { var queryParam = queryJson.ToJObject(); var billList = (!queryParam["CompanyId"].IsEmpty()) && !queryParam["SupplierId"].IsEmpty() ? await _bll.GetBillVolumeListByDay(queryParam) : new List(); var volumeList = new List>(); foreach (var bill in billList) { var time = bill.InStartTime; var volume = bill?.NetWeight; volumeList.Add(new List { time, volume }); } var jsonData = new { volumeList }; return Success(jsonData); } /// /// CompanyId,StartTime,EndTime,State /// /// /// [HttpGet] [AjaxOnly] public async Task GetBillVolumeListByMonth(string queryJson) { var queryParam = queryJson.ToJObject(); var dtoList = (!queryParam["CompanyId"].IsEmpty()) && !queryParam["SupplierId"].IsEmpty() ? await _bll.GetStatisticsDataListByMonth(queryParam) : new List(); var date = !queryParam["StartTime"].IsEmpty() ? queryParam["StartTime"].ToDate() : new DateTime(); var days = DateTime.DaysInMonth(date.Year, date.Month); var volumeList = new List>(); for (var day = 1; day <= days; day++) { var time = new DateTime(date.Year, date.Month, day).ToString("yyyy-MM-dd"); volumeList.Add(new List { time, 0 }); } foreach (var dto in dtoList) { //var time = new DateTime(dto.Year, dto.Month, dto.Day).ToString("yyyy-MM-dd"); var volume = dto.NetWeightSum; volumeList[dto.Day][1] = volume; } var jsonData = new { volumeList }; return Success(jsonData); } /// /// CompanyId,SupplierId,StartTime,EndTime,State /// /// /// [HttpGet] [AjaxOnly] public async Task GetBillRateListByMonth(string queryJson) { var queryParam = queryJson.ToJObject(); var billList = (!queryParam["CompanyId"].IsEmpty()) && !queryParam["SupplierId"].IsEmpty() ? await _bll.GetBillStandardRateListByMonth(queryParam) : new List(); var rateList = new List>(); foreach (var bill in billList) { var time = bill.InStartTime?.Day; var rate = bill?.StandardRate; rateList.Add(new List { time, rate }); } var jsonData = new { rateList }; return Success(jsonData); } /// /// CompanyId,SupplierId,StartTime,EndTime,State /// /// /// [HttpGet] [AjaxOnly] public async Task GetBillRateListByDay(string queryJson) { var queryParam = queryJson.ToJObject(); var billList = (!queryParam["CompanyId"].IsEmpty()) && !queryParam["SupplierId"].IsEmpty() ? await _bll.GetBillStandardRateListByDay(queryParam) : new List(); var rateList = new List>(); foreach (var bill in billList) { var time = bill.InStartTime; var rate = bill?.StandardRate; rateList.Add(new List { time, rate }); } var jsonData = new { rateList }; return Success(jsonData); } /// /// CompanyId,SupplierId,StartTime,EndTime,State /// /// /// [HttpGet] [AjaxOnly] public async Task GetTruckGradeByMonth(string queryJson) { var queryParam = queryJson.ToJObject(); var originBillList = (!queryParam["CompanyId"].IsEmpty()) && !queryParam["SupplierId"].IsEmpty() ? (await _bll.GetTruckGradeListByMonth(queryParam)).ToList() : new List(); List billList = new(); int count = originBillList.Count; if (count <= 0) return Success(new { billList }); string logPlate = string.Empty; int logStart = 0, logEnd = 0; decimal diffWeightStandard = 0.07m; int diffWeightLen = 3; for (int i = 0; i < count; i++) { var bill = originBillList[i]; var plateEqual = i != 0 ? bill.LicensePlate.Equals(logPlate) : true; var diffWeightOut = (decimal)(bill.BillWeight - bill.NetWeight) >= diffWeightStandard; if (diffWeightOut) { billList.Add(originBillList[i]); } //if (plateEqual) //{ // if (diffWeightOut) // { // logEnd = i; // } // else // { // if ((logEnd - logStart + 1) >= diffWeightLen) // { // //if (billList.Count > 0) // // billList.Add(new()); // for (int j = logStart; j <= logEnd; j++) // { // billList.Add(originBillList[j]); // } // } // logStart = i + 1; // logEnd = i + 1; // } //} //else //{ // if ((logEnd - logStart + 1) >= diffWeightLen) // { // //if (billList.Count > 0) // // billList.Add(new()); // for (int j = logStart; j <= logEnd; j++) // { // billList.Add(originBillList[j]); // } // } // logPlate = bill.LicensePlate; // logStart = i; // logEnd = i; //} } var jsonData = new { billList }; return Success(jsonData); } #endregion 获取数据 } }