|
@@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Authorization;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.AspNetCore.StaticFiles;
|
|
|
+using Microsoft.Data.SqlClient;
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
|
using Microsoft.Extensions.Hosting;
|
|
@@ -787,6 +788,84 @@ namespace wispro.sp.api.Controllers
|
|
|
return new List<string>();
|
|
|
}
|
|
|
|
|
|
+ public FileProcessTask GetStaticsReport(int Year,int Month)
|
|
|
+ {
|
|
|
+ CalMonth calMonth = Context.CalMonths.FirstOrDefault(c => c.Year == Year && c.Month == Month);
|
|
|
+ if (calMonth != null)
|
|
|
+ {
|
|
|
+ var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-{calMonth.Year}{calMonth.Month}代理人全部考评维度绩效点数加和.xlsx";
|
|
|
+ var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
|
|
|
+ var filePath = Path.Combine(attachfileSavePath, filename);
|
|
|
+
|
|
|
+ var fileTask = new FileProcessTask()
|
|
|
+ {
|
|
|
+ Id = Guid.NewGuid().ToString(),
|
|
|
+ FileName = filename,
|
|
|
+ FilePath = filePath,
|
|
|
+ Processed = 0
|
|
|
+ };
|
|
|
+
|
|
|
+ fileTaskService.Add(fileTask);
|
|
|
+
|
|
|
+ ExportDataResult result = new ExportDataResult()
|
|
|
+ {
|
|
|
+ fileTask = fileTask,
|
|
|
+ calMonth = calMonth
|
|
|
+ };
|
|
|
+
|
|
|
+ System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(ExportStaticReport));
|
|
|
+ t.Start(result);
|
|
|
+
|
|
|
+ return fileTask;
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void ExportStaticReport(object exportDataResult)
|
|
|
+ {
|
|
|
+ ExportDataResult result = (ExportDataResult)exportDataResult;
|
|
|
+ FileProcessTask file = result.fileTask;
|
|
|
+ CalMonth calMonth = result.calMonth;
|
|
|
+
|
|
|
+ //var StatisticsResults = _CalMyStatistics(calMonth);
|
|
|
+ string strSQL = @"SELECT Staff.Name as 代理人,StaffGrade.Grade as 代理人等级,
|
|
|
+ (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = '新申请处理' and CalMonthId = @CalMonthId ) as '新申请处理',
|
|
|
+ (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = '新申请审核' and CalMonthId = @CalMonthId) as '新申请审核',
|
|
|
+ (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = '专案处理' and CalMonthId = @CalMonthId) as '专案处理',
|
|
|
+ (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = '专案审核' and CalMonthId = @CalMonthId) as '专案审核',
|
|
|
+ (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = 'OA处理' and CalMonthId = @CalMonthId) as OA处理,
|
|
|
+ (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = 'OA审核' and CalMonthId = @CalMonthId) as OA审核,
|
|
|
+ (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = '其它处理' and CalMonthId = @CalMonthId) as 其它处理,
|
|
|
+ (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and b.jxType = '其它审核' and CalMonthId = @CalMonthId) as 其它审核,
|
|
|
+ (select sum([FinianlPoint]) from[StaffStatistics] B where B.StaffId = A.[StaffId] and CalMonthId = @CalMonthId) as 总计
|
|
|
+ FROM[spDB].[dbo].[StaffStatistics] as A
|
|
|
+ inner join Staff on Staff.Id = A.StaffId
|
|
|
+ Left join StaffGrade on Staff.StaffGradeId = StaffGrade.Id
|
|
|
+ where CalMonthId = @CalMonthId
|
|
|
+ group by A.StaffId, Staff.Name,StaffGrade.Grade";
|
|
|
+
|
|
|
+ DataTable dt = new DataTable();
|
|
|
+ spDbContext spDb = new spDbContext();
|
|
|
+ using (var conn = spDb.Database.GetDbConnection())
|
|
|
+ {
|
|
|
+ conn.Open();
|
|
|
+ var cmd = conn.CreateCommand();
|
|
|
+ cmd.CommandText = strSQL;
|
|
|
+ cmd.CommandType = CommandType.Text;
|
|
|
+
|
|
|
+ cmd.Parameters.Add(new SqlParameter("CalMonthId", calMonth.Id));
|
|
|
+ using (var reader = cmd.ExecuteReader())
|
|
|
+ {
|
|
|
+ dt.Load(reader);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ NPOIExcel.DataTableToExcel(dt, result.fileTask.FilePath);
|
|
|
+ result.fileTask.Finished = true;
|
|
|
+ }
|
|
|
+
|
|
|
private List<StaffStatistics> _CalMyStatistics(CalMonth calMonth, int? userid = null)
|
|
|
{
|
|
|
var retList = Context.StaffStatistics.Where(s => s.CalMonthId == calMonth.Id);
|
|
@@ -1057,9 +1136,11 @@ namespace wispro.sp.api.Controllers
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- public FileProcessTask CurrentData2Excel()
|
|
|
+
|
|
|
+
|
|
|
+ public FileProcessTask CurrentData2Excel(int Year,int Month)
|
|
|
{
|
|
|
- CalMonth calMonth = Context.CalMonths.FirstOrDefault(c => c.Status == 0);
|
|
|
+ CalMonth calMonth = Context.CalMonths.FirstOrDefault(c => c.Year == Year && c.Month == Month);
|
|
|
if (calMonth != null)
|
|
|
{
|
|
|
var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-{calMonth.Year}{calMonth.Month}线下绩效核算数据.xlsx";
|
|
@@ -1076,8 +1157,13 @@ namespace wispro.sp.api.Controllers
|
|
|
|
|
|
fileTaskService.Add(fileTask);
|
|
|
|
|
|
+ ExportDataResult result = new ExportDataResult() {
|
|
|
+ fileTask = fileTask,
|
|
|
+ calMonth = calMonth
|
|
|
+ };
|
|
|
+
|
|
|
System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(Export2ExcelThread));
|
|
|
- t.Start(fileTask);
|
|
|
+ t.Start(result);
|
|
|
|
|
|
return fileTask;
|
|
|
}
|
|
@@ -1086,9 +1172,16 @@ namespace wispro.sp.api.Controllers
|
|
|
|
|
|
}
|
|
|
|
|
|
+ internal class ExportDataResult
|
|
|
+ {
|
|
|
+ public FileProcessTask fileTask { get; set; }
|
|
|
+ public CalMonth calMonth { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
private void Export2ExcelThread(object attfile)
|
|
|
{
|
|
|
- FileProcessTask file = (FileProcessTask)attfile;
|
|
|
+ ExportDataResult result = (ExportDataResult)attfile;
|
|
|
+ FileProcessTask file = result.fileTask;
|
|
|
|
|
|
spDbContext spDb = new spDbContext();
|
|
|
List<PerformanceItem> items = spDb.PerformanceItems
|
|
@@ -1097,7 +1190,7 @@ namespace wispro.sp.api.Controllers
|
|
|
.Include(p => p.Customer)
|
|
|
.Include(p => p.CalMonth)
|
|
|
.Include(p => p.ItemStaffs).ThenInclude(s => s.DoPerson).ThenInclude(s => s.StaffGrade)
|
|
|
- .Where(p => p.CalMonth.Status == 0 && !p.CaseNo.StartsWith("J")).OrderBy(p => p.CaseNo).ThenBy(p => p.DoItem).ToList();
|
|
|
+ .Where(p => p.CalMonth.Id == result.calMonth.Id && !p.CaseNo.StartsWith("J")).OrderBy(p => p.CaseNo).ThenBy(p => p.DoItem).ToList();
|
|
|
|
|
|
DataTable dt = new DataTable();
|
|
|
#region 栏位名称
|
|
@@ -1792,7 +1885,7 @@ namespace wispro.sp.api.Controllers
|
|
|
{
|
|
|
if (jx.totalBasePoint == 0)
|
|
|
{
|
|
|
- return;
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
jx.ItemId = Item.Id;
|
|
@@ -2179,6 +2272,40 @@ namespace wispro.sp.api.Controllers
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public ProcessTask FinishedCalMonth(int year,int month)
|
|
|
+ {
|
|
|
+ CalMonth calMonth = Context.CalMonths.FirstOrDefault(c => c.Year == year && c.Month == month);
|
|
|
+ if (calMonth != null)
|
|
|
+ {
|
|
|
+ var filename = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}-{calMonth.Year}{calMonth.Month}线下绩效核算数据.xlsx";
|
|
|
+ var attachfileSavePath = utility.ConfigHelper.GetSectionValue("AttachFileSavePath");
|
|
|
+ var filePath = Path.Combine(attachfileSavePath, filename);
|
|
|
+
|
|
|
+ var fileTask = new FileProcessTask()
|
|
|
+ {
|
|
|
+ Id = Guid.NewGuid().ToString(),
|
|
|
+ FileName = filename,
|
|
|
+ FilePath = filePath,
|
|
|
+ Processed = 0
|
|
|
+ };
|
|
|
+
|
|
|
+ fileTaskService.Add(fileTask);
|
|
|
+
|
|
|
+ ExportDataResult result = new ExportDataResult()
|
|
|
+ {
|
|
|
+ fileTask = fileTask,
|
|
|
+ calMonth = calMonth
|
|
|
+ };
|
|
|
+
|
|
|
+ System.Threading.Thread t = new System.Threading.Thread(new ParameterizedThreadStart(_FinishedCalMonth));
|
|
|
+ t.Start(result);
|
|
|
+
|
|
|
+ return fileTask;
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
/// <summary>
|
|
|
/// 新申请/专案:
|
|
|
/// 调整点数 = 分配比例点数/分配比例点数之和*总点数
|
|
@@ -2196,56 +2323,49 @@ namespace wispro.sp.api.Controllers
|
|
|
/// <param name="year"></param>
|
|
|
/// <param name="month"></param>
|
|
|
/// <returns></returns>
|
|
|
- public ApiSaveResponse FinishedCalMonth(int year,int month)
|
|
|
+ private void _FinishedCalMonth(object proecssTask)
|
|
|
{
|
|
|
- CalMonth calMonth = Context.CalMonths.Where<CalMonth>(c => c.Month == month && c.Year == year).FirstOrDefault();
|
|
|
-
|
|
|
+ ExportDataResult result = (ExportDataResult)proecssTask;
|
|
|
+ CalMonth calMonth = result.calMonth;
|
|
|
+
|
|
|
if (calMonth != null || calMonth.Status !=4)
|
|
|
{
|
|
|
-
|
|
|
- using (var t = Context.Database.BeginTransaction())
|
|
|
+ spDbContext spDb = new spDbContext();
|
|
|
+ calMonth = spDb.CalMonths.FirstOrDefault(c=>c.Id == calMonth.Id);
|
|
|
+ using (var t = spDb.Database.BeginTransaction())
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- _RefreshBasePoint(calMonth,Context);
|
|
|
+ _RefreshBasePoint(calMonth, spDb);
|
|
|
//_CalJXPoint(calMonth, Context);
|
|
|
|
|
|
calMonth.Status = 4;
|
|
|
- Context.SaveChanges();
|
|
|
+ spDb.SaveChanges();
|
|
|
|
|
|
- StatisticsCount(calMonth.Id); //等级核算案件统计
|
|
|
+ StatisticsCount(calMonth.Id,spDb); //等级核算案件统计
|
|
|
|
|
|
#region 将待审核的申诉全部修改为已审核
|
|
|
- var aList = Context.AppealRecords.Where(a => a.State == 0).ToList();
|
|
|
+ var aList = spDb.AppealRecords.Where(a => a.State == 0).ToList();
|
|
|
aList.ForEach(a =>a.State = 1);
|
|
|
- Context.SaveChanges();
|
|
|
+ spDb.SaveChanges();
|
|
|
#endregion
|
|
|
|
|
|
t.Commit();
|
|
|
- return new ApiSaveResponse()
|
|
|
- {
|
|
|
- Success = true
|
|
|
- };
|
|
|
+ result.fileTask.Finished = true;
|
|
|
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
t.Rollback();
|
|
|
- return new ApiSaveResponse()
|
|
|
- {
|
|
|
- Success = false,
|
|
|
- ErrorMessage = ex.Message
|
|
|
- };
|
|
|
+ result.fileTask.ErrorMessage = ex.Message;
|
|
|
+ result.fileTask.Finished = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- return new ApiSaveResponse()
|
|
|
- {
|
|
|
- Success = false,
|
|
|
- ErrorMessage ="指定月份没有数据或者已归档!"
|
|
|
- };
|
|
|
+ result.fileTask.ErrorMessage = "指定月份没有数据或者已归档!";
|
|
|
+ result.fileTask.Finished = true;
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -2788,7 +2908,7 @@ namespace wispro.sp.api.Controllers
|
|
|
var retObj = Context.PerformanceItems.Include(p=>p.Customer).FirstOrDefault<PerformanceItem>(p => p.CaseNo == CaseNo.Trim()
|
|
|
&& p.DoItem == DoItem.Trim() && p.CaseStage == caseStage);
|
|
|
|
|
|
- if (retObj == null && UpdateFromIPEasy)
|
|
|
+ if (retObj == null || UpdateFromIPEasy)
|
|
|
{
|
|
|
var temObj = new Job.UpdateJXDataFromIPEasyJob().GetItemFromIPEasyDB(
|
|
|
new PerformanceItem() {CaseNo =CaseNo,DoItem =DoItem,CaseStage = caseStage },
|
|
@@ -2999,19 +3119,19 @@ namespace wispro.sp.api.Controllers
|
|
|
/// </summary>
|
|
|
/// <param name="calMonthId"></param>
|
|
|
/// <returns></returns>
|
|
|
- private List<StaffStatisticsforLevel> StatisticsCount(int calMonthId)
|
|
|
+ private List<StaffStatisticsforLevel> StatisticsCount(int calMonthId,spDbContext spDb )
|
|
|
{
|
|
|
var retlist = new List<StaffStatisticsforLevel>();
|
|
|
|
|
|
#region 新申请
|
|
|
- var newList = Context.PerformanceItems.Include(p => p.ItemStaffs)
|
|
|
+ var newList = spDb.PerformanceItems.Include(p => p.ItemStaffs)
|
|
|
.Where(p=>p.CalMonthId == calMonthId && p.BasePoint >0
|
|
|
&& (p.Type =="新申请" || p.Type =="专案" || (p.Type == "其它" && p.WordCount >0 && (p.DoItem =="新申请" || p.DoItem == "翻译")))
|
|
|
).ToList();
|
|
|
|
|
|
foreach(var p in newList)
|
|
|
{
|
|
|
- var pointList = Context.StaffStatistics.Include(i=>i.Staff).Where(i=>i.ItemId == p.Id).ToList();
|
|
|
+ var pointList = spDb.StaffStatistics.Include(i=>i.Staff).Where(i=>i.ItemId == p.Id).ToList();
|
|
|
|
|
|
#region 新申请处理
|
|
|
var doList = pointList.Where(i => i.jxType.Contains("处理"));
|
|
@@ -3138,13 +3258,13 @@ namespace wispro.sp.api.Controllers
|
|
|
#endregion
|
|
|
|
|
|
#region 国内OA
|
|
|
- var cnOA = Context.PerformanceItems.Include(x=>x.ItemStaffs)
|
|
|
+ var cnOA = spDb.PerformanceItems.Include(x=>x.ItemStaffs)
|
|
|
.Where(x => x.CalMonthId == calMonthId && x.Type == "OA" && x.CaseNo.Contains("CN") && x.BasePoint > 0
|
|
|
&& (x.CaseStage == "一通" || x.DoItemCoefficient.Contains("首次转入"))).ToList();
|
|
|
|
|
|
foreach(var p in cnOA)
|
|
|
{
|
|
|
- var pointList = Context.StaffStatistics.Include(i => i.Staff).Where(i=> i.ItemId == p.Id).ToList();
|
|
|
+ var pointList = spDb.StaffStatistics.Include(i => i.Staff).Where(i=> i.ItemId == p.Id).ToList();
|
|
|
|
|
|
#region 国内OA处理
|
|
|
var doList = pointList.Where(i => i.jxType.Contains("处理"));
|
|
@@ -3233,13 +3353,13 @@ namespace wispro.sp.api.Controllers
|
|
|
#endregion
|
|
|
|
|
|
#region 涉外OA
|
|
|
- var gwOA = Context.PerformanceItems.Include(x => x.ItemStaffs)
|
|
|
+ var gwOA = spDb.PerformanceItems.Include(x => x.ItemStaffs)
|
|
|
.Where(x => x.CalMonthId == calMonthId && x.Type == "OA" && !x.CaseNo.Contains("CN") && x.BasePoint>0
|
|
|
&& (x.DoItemCoefficient.Contains("实质"))).ToList();
|
|
|
|
|
|
foreach (var p in gwOA)
|
|
|
{
|
|
|
- var pointList = Context.StaffStatistics.Include(i => i.Staff).Where(i => i.ItemId == p.Id).ToList();
|
|
|
+ var pointList = spDb.StaffStatistics.Include(i => i.Staff).Where(i => i.ItemId == p.Id).ToList();
|
|
|
|
|
|
#region 涉外OA处理
|
|
|
var doList = pointList.Where(i => i.jxType.Contains("处理"));
|
|
@@ -3468,7 +3588,10 @@ namespace wispro.sp.api.Controllers
|
|
|
result.UpgradeBase = temResult.doAverage();
|
|
|
}
|
|
|
|
|
|
- var temAverage= result.pAverage(result.Statistics[0].StaffId);
|
|
|
+ if (result.Statistics.Count > 0)
|
|
|
+ {
|
|
|
+ var temAverage = result.pAverage(result.Statistics[0].StaffId);
|
|
|
+ }
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -3488,7 +3611,7 @@ namespace wispro.sp.api.Controllers
|
|
|
var temList = Context.StaffStatisticsforLevels.Where(l => l.CalMonthId == temObj.Id);
|
|
|
Context.StaffStatisticsforLevels.RemoveRange(temList);
|
|
|
|
|
|
- var NewList = StatisticsCount(temObj.Id);
|
|
|
+ var NewList = StatisticsCount(temObj.Id,Context);
|
|
|
|
|
|
Context.StaffStatisticsforLevels.AddRange(NewList);
|
|
|
Context.SaveChanges();
|