123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934 |
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.EntityFrameworkCore;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text.Json.Serialization;
- using System.Text.Json;
- using System.Threading.Tasks;
- using wispro.sp.api.Job;
- using wispro.sp.entity;
- using wispro.sp.share;
- using Fizzler;
- using static wispro.sp.api.Controllers.PerformanceItemController;
- using System.Threading;
- using wispro.sp.api.Services;
- using Microsoft.Data.SqlClient;
- using System.Data;
- using wispro.sp.utility;
- using OpenQA.Selenium.DevTools.V85.CSS;
- namespace wispro.sp.api.Controllers
- {
- [Route("api/[controller]/[action]")]
- [ApiController]
- //[Authorize]
- public class AppealController : ControllerBase
- {
- spDbContext Context;
- IFileTaskService fileTaskService;
- public AppealController(spDbContext context, IFileTaskService _fileTaskService)
- {
- Context = context;
- fileTaskService = _fileTaskService;
- }
- public List<AppealType> GetAppealTypes()
- {
- return Context.AppealTypes.ToList();
- }
- /// <summary>
- /// 统计指定客户、指定月份新申请案件各案件系数的案件数量
- /// </summary>
- /// <param name="CustomerId">指定客户Id</param>
- /// <param name="CalmonthId">指定月份Id</param>
- /// <returns></returns>
- public CaseCoefficientStatistics GetCCSRecord(int? CustomerId,int CalmonthId)
- {
- CaseCoefficientStatistics retObject = new CaseCoefficientStatistics();
- if(CustomerId != null)
- {
- retObject.customer = Context.Customers.FirstOrDefault(c => c.Id == CustomerId);
- }
-
- var myGroups = Context.PerformanceItems
- .Where(p=>
- p.Type=="新申请"
- && (p.AgentFeedbackMemo != "已算绩效" || string.IsNullOrEmpty(p.AgentFeedbackMemo))
- && p.CalMonthId == CalmonthId
- && p.CustomerId == CustomerId)
- .GroupBy(p => p.CaseCoefficient)
- .Select(g => new { CaseCoefficient = g.Key, Count = g.Count() });
- if(CustomerId == null)
- {
- myGroups = Context.PerformanceItems
- .Where(p =>
- p.Type == "新申请"
- && (p.AgentFeedbackMemo != "已算绩效" || string.IsNullOrEmpty(p.AgentFeedbackMemo))
- && p.CalMonthId == CalmonthId)
- .GroupBy(p => p.CaseCoefficient)
- .Select(g => new { CaseCoefficient = g.Key, Count = g.Count() });
- }
- foreach (var g in myGroups)
- {
- string strKey = ( string.IsNullOrEmpty(g.CaseCoefficient)) ? "B" : g.CaseCoefficient;
- switch (strKey)
- {
- case "A":
- retObject.ACount += g.Count;
- retObject.Totals += g.Count;
- break;
- case "S":
- retObject.SCount += g.Count;
- retObject.Totals += g.Count;
- break;
- default:
- retObject.Totals += g.Count;
- break;
- }
- }
- return retObject;
- #region SQL
- //string strSQL = $"SELECT CaseCoefficient,count(*) as CaseCoefficientCount " +
- // "FROM PerformanceItem " +
- // $"where CalMonthId = {CalmonthId} and CustomerId = {CustomerId} and Type = '新申请' and(AgentFeedbackMemo <> '已算绩效' or AgentFeedbackMemo is null) " +
- // "group by CaseCoefficient";
- //var conn= Context.Database.GetDbConnection();
- //if(conn.State != System.Data.ConnectionState.Open)
- //{
- // conn.Open();
- //}
-
-
- //try
- //{
- // var cmd = conn.CreateCommand();
- // cmd.CommandText = strSQL;
- // var reader = cmd.ExecuteReader();
-
- // while (reader.Read())
- // {
- // string strKey = (reader.IsDBNull(0) || string.IsNullOrEmpty(reader.GetString(0))) ? "B" : reader.GetString(0);
- // switch (strKey)
- // {
- // case "A":
- // retObject.ACount += reader.GetInt32(1);
- // retObject.Totals += reader.GetInt32(1);
- // break;
- // case "S":
- // retObject.SCount += reader.GetInt32(1);
- // retObject.Totals += reader.GetInt32(1);
- // break;
- // default:
- // retObject.Totals += reader.GetInt32(1);
- // break;
- // }
-
- // }
- // cmd.Dispose();
- // return retObject;
- //}
- //catch (Exception ex)
- //{
- // throw ex;
- //}
- //finally
- //{
-
- // conn.Close();
- //}
- #endregion
- }
- public FileProcessTask GetStaticsReport(int CalMonthId)
- {
- CalMonth calMonth = Context.CalMonths.FirstOrDefault(c => c.Id == CalMonthId);
- 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
- };
- ExportStaticReport(result);
- //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 retList = GetCCSRecords(calMonth.Id);
- DataTable dt = new DataTable();
- dt.Columns.Add("客户名称");
- dt.Columns.Add("S案件阈值");
- dt.Columns.Add("A案件阈值");
- dt.Columns.Add("案件总数",typeof(int));
- dt.Columns.Add("S案件数", typeof(int));
- dt.Columns.Add("A案件数", typeof(int));
- foreach(var ccsObj in retList)
- {
- var row = dt.NewRow();
- row["客户名称"] = ccsObj.customer.Name;
- row["S案件阈值"] =$"{((ccsObj.customer.SRate == null) ? 5: ccsObj.customer.SRate)}%" ;
- row["A案件阈值"] = $"{((ccsObj.customer.ARate == null) ? 30: ccsObj.customer.ARate)}%";
- row["案件总数"] = ccsObj.Totals;
- row["S案件数"] = ccsObj.SCount;
- row["A案件数"] = ccsObj.ACount;
- dt.Rows.Add(row);
- }
- NPOIExcel.DataTableToExcel(dt, result.fileTask.FilePath);
- result.fileTask.Finished = true;
- }
- public List<CaseCoefficientStatistics> GetCCSRecords(int CalmonthId)
- {
- var AllCustomers = Context.Customers.ToList();
- var myGroups = Context.PerformanceItems
- .Where(p =>
- p.Type == "新申请"
- && (p.AgentFeedbackMemo != "已算绩效" || string.IsNullOrEmpty(p.AgentFeedbackMemo))
- && p.CalMonthId == CalmonthId)
- .GroupBy(p => new { CustomerId = p.CustomerId, CaseCeoffcient = p.CaseCoefficient })
- .Select(g => new { CaseCoefficient = g.Key.CaseCeoffcient,CustomerId=g.Key.CustomerId, Count = g.Count() });
- List<CaseCoefficientStatistics> retList= new List<CaseCoefficientStatistics>();
- foreach (var g in myGroups)
- {
- CaseCoefficientStatistics temObject = retList.Where(p=>p.customer.Id == g.CustomerId).FirstOrDefault();
- if(temObject == null)
- {
- temObject = new CaseCoefficientStatistics() {
- customer = AllCustomers.FirstOrDefault(c => c.Id == g.CustomerId)
- };
- retList.Add(temObject);
- }
- string strKey = g.CaseCoefficient;
- switch (strKey)
- {
- case "A":
- temObject.ACount += g.Count;
- temObject.Totals += g.Count;
- break;
- case "S":
- temObject.SCount += g.Count;
- temObject.Totals += g.Count;
- break;
- default:
- temObject.Totals += g.Count;
- break;
- }
- }
- return retList;
- }
- public List<InputField> GetInputField(int appealTypeId, int state)
- {
- var retList = Context.InputFields
- .Where<InputField>(ip => ip.AppealTypeId == appealTypeId && ip.AppealState == state)
- .Include(p => p.SelectValues)
- .ToList();
- string str = System.Text.Json.JsonSerializer.Serialize(retList, new JsonSerializerOptions()
- {
- ReferenceHandler = ReferenceHandler.Preserve
- });
- Log(str);
- foreach (var inputField in retList)
- {
- if (inputField.SelectValues != null)
- {
- foreach(var ifValue in inputField.SelectValues)
- {
- ifValue.InputField = null;
- }
- }
- }
- return retList;
- }
- /// <summary>
- /// 创建申诉流程
- /// </summary>
- /// <param name="ItemId"></param>
- /// <param name="typeid"></param>
- /// <param name="reviewerId"></param>
- /// <param name="appealObject"></param>
- /// <returns></returns>
- public ApiSaveResponse CreateAppeal(int ItemId, int typeid, int reviewerId, AppealObject appealObject)
- {
- ApiSaveResponse response = new ApiSaveResponse();
- response.Success = true;
-
- AppealRecord appealRecord = new AppealRecord();
- if(ItemId > 0)
- {
- appealRecord.ItemId = ItemId;
- }
- else
- {
- appealRecord.ItemId = null;
- }
-
- appealRecord.TypeId = typeid;
- appealRecord.ReviewerId = reviewerId;
- appealRecord.CreaterId = Context.Staffs.Where<Staff>(s => s.Name == User.Identity.Name).FirstOrDefault().Id;
- appealRecord.CreateTime = DateTime.Now;
- var t = Context.Database.BeginTransaction();
- try
- {
- Context.AppealRecords.Add(appealRecord);
- Context.SaveChanges();
- foreach (var fieldValue in appealObject.inputFieldValues)
- {
- fieldValue.InputField = null;
- fieldValue.AppealRecordId = appealRecord.Id;
- }
- Context.InputFieldValues.AddRange(appealObject.inputFieldValues);
- foreach (var file in appealObject.attachFiles)
- {
- var temFile = Context.AttachFiles.Where<AttachFile>(f => f.Id == file.Id).FirstOrDefault();
- temFile.AppealRecordId = appealRecord.Id;
- temFile.UploadUserId = appealRecord.CreaterId;
- }
- Context.SaveChanges();
- var temType = Context.AppealTypes.FirstOrDefault(c=>c.Id == appealRecord.TypeId);
- if (!string.IsNullOrEmpty(temType.ApplealObject))
- {
- IDoAppealObject doAppeal = (IDoAppealObject)Activator.CreateInstance(Type.GetType(appealRecord.Type.ApplealObject));
- doAppeal.DoAppeal(appealObject, appealRecord.Id, Context);
- }
- t.Commit();
- var Reviewer = Context.Staffs.Where<Staff>(s => s.Id == appealRecord.ReviewerId).FirstOrDefault();
- if(appealRecord.Type == null)
- {
- appealRecord.Type = Context.AppealTypes.FirstOrDefault(p=>p.Id == appealRecord.TypeId);
- }
- string strSubject = appealRecord.Type.Name;
- string strBody = $"<div style=\"position:absolute;width:800;height:300;margin-top:50px;margin-left:200px;margin-right:200px;box-shadow:0px 0px 3px 3px #ccc \"><div style= \"margin-top: 20px; margin-left:20px;;font-size:14px; \">{Reviewer.Name},您好!</div><div style= \"margin-top: 25px; margin-left:20px;font-size:14px; \"><div>{User.Identity.Name} 向您提交了{appealRecord.Type.Name}申诉,请使用<a href= \"http://1.116.113.26\">绩效系统</a>在<B>{utility.ConfigHelper.GetSectionValue("Lastest_feedback_date")}日</B>前完成审核!</div><div style= \"margin-top: 100px;margin-right:15px; padding-bottom: 20px; font-size:14px;color:#888888;float:right; \">小美集团绩效管理系统</div></div>";
- string strTo = Reviewer.Mail;
- if (!string.IsNullOrEmpty(strTo))
- {
- _ = QuartzUtil.AddMailJob(strSubject, strBody, Reviewer.Name, strTo);
- }
- strBody = $"<div style=\"position:absolute;width:800;height:300;margin-top:50px;margin-left:200px;margin-right:200px;box-shadow:0px 0px 3px 3px #ccc \"><div style= \"margin-top: 20px; margin-left:20px;;font-size:14px; \">{Reviewer.Name},您好!</div><div style= \"margin-top: 25px; margin-left:20px;font-size:14px; \"><div>{User.Identity.Name} 向您提交了{appealRecord.Type.Name}申诉,请使用<a href= \"http://1.116.113.26\">绩效系统</a>查看详情!</div><div style= \"margin-top: 100px;margin-right:15px; padding-bottom: 20px; font-size:14px;color:#888888;float:right; \">小美集团绩效管理系统</div></div>";
- _ = QuartzUtil.AddMailJob(strSubject, strBody, "钟子敏", "zhongzimin@china-wispro.com");
- //_ = QuartzUtil.AddMailJob(strSubject, strBody, "夏敏", "xiamin@china-wispro.com");
- _ = QuartzUtil.AddMailJob(strSubject, strBody, "吴芳", "wufang@china-wispro.com");
- return response;
- }
- catch (Exception ex)
- {
- t.Rollback();
- response.Success = false;
- response.ErrorMessage = "申诉时发生错误!";
- return response;
- }
- }
- public ApiSaveResponse ReviewerAppeal(int appealRecordId,AppealObject appealObject)
- {
- ApiSaveResponse response = new ApiSaveResponse();
- response.Success = true;
- var appealRecord = Context.AppealRecords.Where<AppealRecord>(p => p.Id == appealRecordId).FirstOrDefault();
-
- if(appealRecord != null)
- {
- if (appealRecord.ItemId.HasValue)
- {
- var item = Context.PerformanceItems.Include(p=>p.CalMonth).FirstOrDefault(p => p.Id == appealRecord.ItemId.Value);
- if(item == null)
- {
- response.Success = false;
- response.ErrorMessage = "无效的ItemId!";
- return response;
- }
- else
- {
- if(item.CalMonth.Status != 0)
- {
- response.Success = false;
- response.ErrorMessage = "指定的绩效已经归档!";
- return response;
- }
- }
- }
- var t = Context.Database.BeginTransaction();
- try
- {
- appealRecord.ReviewerId = Context.Staffs.Where<Staff>(s => s.Name == User.Identity.Name).FirstOrDefault().Id;
- appealRecord.State = 1;
- appealRecord.ReviewTime = DateTime.Now;
- Context.SaveChanges();
- foreach (var fieldValue in appealObject.inputFieldValues)
- {
- fieldValue.InputField = null;
- fieldValue.AppealRecordId = appealRecord.Id;
- }
- Context.InputFieldValues.AddRange(appealObject.inputFieldValues);
- Context.SaveChanges();
- if (appealObject.attachFiles != null)
- {
- foreach (var file in appealObject.attachFiles)
- {
- var temFile = Context.AttachFiles.Where<AttachFile>(f => f.Id == file.Id).FirstOrDefault();
- temFile.AppealRecordId = appealRecord.Id;
- temFile.UploadUserId = appealRecord.ReviewerId;
- }
- }
- List<InputFieldValue> inputFieldValues = Context.InputFieldValues
- .Where<InputFieldValue>(p => p.AppealRecordId == appealRecordId
- && p.InputField.MapObjectField != null)
- .Include(i=>i.InputField)
- .ToList();
- foreach(InputFieldValue inputFieldValue in inputFieldValues)
- {
-
- SaveValueToMapObject(appealRecord, inputFieldValue);
-
- }
- Context.SaveChanges();
- if(appealRecord.Type == null)
- {
- appealRecord.Type = Context.AppealTypes.FirstOrDefault(s=>s.Id == appealRecord.TypeId);
- }
- if (!string.IsNullOrEmpty(appealRecord.Type.ReviewObject))
- {
- IDoAppealObject doAppeal = (IDoAppealObject)Activator.CreateInstance(Type.GetType(appealRecord.Type.ReviewObject));
- doAppeal.DoAppeal(appealObject, appealRecord.Id,Context);
- }
- Context.SaveChanges();
- if(appealRecord.ItemId.HasValue)
- {
- var item = Context.PerformanceItems
- .Include(p => p.ItemStaffs)
- .Include(p => p.Customer)
- .Include(p=>p.Reviewer)
- .FirstOrDefault(p=>p.Id == appealRecord.ItemId);
- new PerformanceItemController(Context, new Services.FileTaskCacheService()).RefreshPoint(item);
- }
-
- t.Commit();
- return response;
- }
- catch (Exception ex)
- {
- t.Rollback();
- response.Success = false;
- response.ErrorMessage = ex.Message;
- return response;
- }
- }
- else
- {
- response.Success = true;
- response.ErrorMessage = "申诉不存在!";
- return response;
- }
-
- }
- private object ConvertSimpleType(object value, Type destinationType)
- {
- object returnValue;
- if ((value == null) || destinationType.IsInstanceOfType(value))
- {
- return value;
- }
- string str = value as string;
- if ((str != null) && (str.Length == 0))
- {
- return null;
- }
- TypeConverter converter = TypeDescriptor.GetConverter(destinationType);
- bool flag = converter.CanConvertFrom(value.GetType());
- if (!flag)
- {
- converter = TypeDescriptor.GetConverter(value.GetType());
- }
- if (!flag && !converter.CanConvertTo(destinationType))
- {
- throw new InvalidOperationException("无法转换成类型:" + value.ToString() + "==>" + destinationType);
- }
- try
- {
- returnValue = flag ? converter.ConvertFrom(null, null, value) : converter.ConvertTo(null, null, value, destinationType);
- }
- catch (Exception e)
- {
- throw new InvalidOperationException("类型转换出错:" + value.ToString() + "==>" + destinationType, e);
- }
- return returnValue;
- }
- private void SaveValueToMapObject(AppealRecord appealRecord, InputFieldValue inputFieldValue)
- {
- if (!string.IsNullOrEmpty(inputFieldValue.InputField.MapObjectField))
- {
- bool isSave = false;
- if (!string.IsNullOrEmpty(inputFieldValue.InputField.MapSaveCondition))
- {
- string[] conditions = inputFieldValue.InputField.MapSaveCondition.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
- if (conditions.Length == 1)
- {
- if (appealRecord.State == int.Parse(conditions[0]))
- {
- isSave = true;
- }
- }
- else
- {
- if (appealRecord.State == int.Parse(conditions[0]))
- {
- InputFieldValue temValue =
- Context.InputFieldValues.Where<InputFieldValue>(v =>
- v.AppealRecordId == appealRecord.Id &&
- v.InputField.Id == int.Parse(conditions[1]))
- .FirstOrDefault();
- if (temValue != null)
- {
- if(temValue.Value == conditions[2])
- {
- isSave = true;
- }
- else
- {
- if (string.IsNullOrEmpty(temValue.Value))
- {
- throw (new ApplicationException(string.Format("请选择或输入栏位【{0}】的值!",temValue.InputField.FieldName)));
- }
- else
- {
- isSave = false;
- }
-
- }
-
- }
- }
- }
- }
- else
- {
- isSave = true;
- }
- if (isSave)
- {
- InputField field = inputFieldValue.InputField;
- PerformanceItem Item = Context.PerformanceItems.Where<PerformanceItem>(p =>
- p.Id == appealRecord.ItemId)
- .Include(p => p.ItemStaffs).ThenInclude(it=>it.DoPerson)
- .Include(p => p.Reviewer)
- .FirstOrDefault();
- bool ItemIsNull = false;
- if(Item == null)
- {
- ItemIsNull = true;
- Item = new PerformanceItem();
- }
- if (!string.IsNullOrEmpty(field.MapObjectField) && !string.IsNullOrEmpty(field.MapObjectFieldLabel))
- {
- List<InputFieldValue> temValues = new List<InputFieldValue>();
- string[] pList = field.MapObjectField.Split(new char[] { '.' });
- string[] plList = field.MapObjectFieldLabel.Split(new char[] { '.' });
- var pInfo = Item.GetType().GetProperty(pList[0]);
- var o = pInfo.GetValue(Item);
- if (Array.IndexOf(o.GetType().GetInterfaces(), typeof(IEnumerable)) > -1)
- {
- List<string> Values = new List<string>();
- List<string> Labels = new List<string>();
- var objList = o as IEnumerable;
- foreach (var obj in objList)
- {
- var objLabel = obj;
- for (int i = 1; i < plList.Length; i++)
- {
- objLabel = objLabel.GetType().GetProperty(plList[i]).GetValue(objLabel);
- }
- if (objLabel.ToString() == inputFieldValue.Label)
- {
- var objValue = obj;
- for (int i = 1; i < pList.Length - 1; i++)
- {
- objValue = objValue.GetType().GetProperty(pList[i]).GetValue(objValue);
- }
- objValue.GetType().GetProperty(pList[pList.Length - 1])
- .SetValue(objValue, ConvertSimpleType(inputFieldValue.Value,Type.GetType(inputFieldValue.InputField.FieldType)));
- }
- }
- }
-
- }
- else
- {
- Item.GetType().GetProperty(field.MapObjectField).SetValue(Item, ConvertSimpleType(inputFieldValue.Value, Type.GetType(inputFieldValue.InputField.FieldType)));
- }
- }
- }
- }
- public List<AppealRecord> GetAppealRecords(int userId)
- {
- try
- {
- var data = Context.AppealRecords.Where<AppealRecord>(p => p.Id > 0);
- if (userId > 0)
- {
- data = Context.AppealRecords.Where<AppealRecord>(ar => (ar.CreaterId == userId || (ar.ReviewerId == userId && ar.State != 1)) && ar.Type.NeedReview == true);
- }
- var retList = data
- .Include(p => p.Reviewer)
- .Include(p => p.Creater)
- .Include(p => p.Item)
- .Include(p => p.Type)
- .OrderBy(p => p.State)
- .ToList();
-
- foreach (var record in retList)
- {
- replaceDataForSerialize(record);
- }
- //string str = System.Text.Json.JsonSerializer.Serialize(retList);
- //System.Diagnostics.Debug.WriteLine(str);
- //Log(str);
- return retList;
- }
- catch (Exception ex)
- {
- Log(ex.ToString());
- return new List<AppealRecord>();
- }
-
- }
- private void replaceDataForSerialize(AppealRecord record)
- {
- if(record.Creater !=null)
- {
- Staff temStaff = new Staff()
- {
- Name = record.Creater.Name,
- Id = record.Creater.Id,
- ItemStaffs = null,
- ReviewerItems = null,
- Customers = null,
- Positions = null,
- StaffGrade = null,
- };
- record.Creater = temStaff;
- //record.Creater.ItemStaffs = null;
- //record.Creater.ReviewerItems = null;
- //record.Creater.Customers = null;
- //record.Creater.Positions = null;
- //record.Creater.StaffGrade = null;
- }
- if (record.Reviewer != null)
- {
- Staff temStaff = new Staff() {
- Name = record.Reviewer.Name,
- Id = record.Creater.Id,
- ItemStaffs = null,
- ReviewerItems = null,
- Customers = null,
- Positions = null,
- StaffGrade = null,
- };
- record.Reviewer = temStaff;
- //record.Reviewer.ItemStaffs = null;
- //record.Reviewer.Customers = null;
- //record.Reviewer.ReviewerItems = null;
- //record.Reviewer.Positions = null;
- //record.Reviewer.StaffGrade = null;
- }
- if (record.Item != null)
- {
- PerformanceItem temItem = new PerformanceItem()
- {
- Id = record.Item.Id,
- CaseNo = record.Item.CaseNo,
- DoItem = record.Item.DoItem,
- CaseName = record.Item.CaseName,
- CalMonthId = record.Item.CalMonthId
-
- };
- record.Item = temItem;
- //record.Item.ItemStaffs = null;
- //record.Item.PreOastaff = null;
- //record.Item.Reviewer = null;
- //record.Item.WorkflowUser = null;
- //record.Item.Customer = null;
- //record.Item.CalMonth = null;
- }
- if(record.Type != null)
- {
- record.Type.ReviewerExpress = null;
- record.Type.CanDoExpress = null;
- record.Type.ApplealObject = null;
- record.Type.CanDoExpress = null;
- record.Type.ReviewerExpress = null;
- }
- //record.Type.ReviewerExpress = null;
- }
- [HttpPost]
- public List<AppealRecord> QueryByFilter(AppealRecordFilter filter)
- {
- var data = Context.AppealRecords.Where<AppealRecord>(s => true);
- if(filter.AppealTypeId > 0)
- {
- data = Context.AppealRecords.Where(f=>f.TypeId == filter.AppealTypeId);
- }
- if(!string.IsNullOrEmpty(filter.CaseNo))
- {
- data = data.Where(s=>s.Item.CaseNo.Contains(filter.CaseNo));
- }
- if (!string.IsNullOrEmpty(filter.CreateUser))
- {
- data = data.Where(s => s.Creater.Name.Contains(filter.CreateUser));
- }
- if (!string.IsNullOrEmpty(filter.Reviewer))
- {
- data = data.Where(s => s.Reviewer.Name.Contains(filter.Reviewer));
- }
- if (filter.beginCreateTime.HasValue)
- {
- data = data.Where(s => s.CreateTime>=filter.beginCreateTime.Value );
- }
- if (filter.endCreateTime.HasValue)
- {
- data = data.Where(s => s.CreateTime <= filter.endCreateTime.Value);
- }
- if (filter.beginReviewTime.HasValue)
- {
- data = data.Where(s => s.ReviewTime >= filter.beginReviewTime.Value);
- }
- if (filter.endReviewTime.HasValue)
- {
- data = data.Where(s => s.ReviewTime <= filter.endReviewTime.Value);
- }
- var retList = data
- .Include(p => p.Reviewer)
- .Include(p => p.Creater)
- .Include(p => p.Item)
- .Include(p => p.Type)
- .OrderBy(p => p.State)
- .ToList();
- foreach (var record in retList)
- {
- replaceDataForSerialize(record);
- }
- return retList;
- }
- public AppealRecord GetAppealRecord(int Id)
- {
- var data = Context.AppealRecords.Where<AppealRecord>(ar => ar.Id == Id);
- return data.Include(p => p.Reviewer)
- .Include(p => p.Creater)
- .Include(p => p.Item)
- .Include(p => p.Type).FirstOrDefault();
- }
- public List<InputFieldValue> GetInputFieldValues(int id, int state)
- {
- var result = Context.InputFieldValues.Where<InputFieldValue>(f => f.AppealRecordId == id && f.InputField.AppealState == state);
- return result.Include(i => i.InputField).ToList();
- }
- public List<InputFieldValue> GetAllInputFieldValue(int id)
- {
- var result = Context.InputFieldValues.Where<InputFieldValue>(f => f.AppealRecordId == id);
- return result.Include(i => i.InputField).ToList();
- }
- public List<AttachFile> GetAppealRecordAttachFiles(int appealRecordId)
- {
- var result = Context.AttachFiles.Where<AttachFile>(at => at.AppealRecordId == appealRecordId).Include(f => f.UploadUser);
- return result.ToList();
- }
- public ApiSaveResponse ChangeRecordReviewer(int RecordId,int ReviewerId)
- {
- var data = Context.AppealRecords.FirstOrDefault<AppealRecord>(ar => ar.Id == RecordId);
- if(data != null)
- {
- var reviewer = Context.Staffs.FirstOrDefault(s => s.Id == ReviewerId);
- var CurrentUser = Context.Staffs.FirstOrDefault(s=>s.Name == User.Identity.Name);
- if ((CurrentUser.Id == data.CreaterId || CurrentUser.Id == data.ReviewerId) && data.State ==0)
- {
- if (reviewer != null)
- {
- data.ReviewerId = ReviewerId;
- Context.SaveChanges();
- return new ApiSaveResponse()
- {
- Success = true
- };
- }
- else
- {
- return new ApiSaveResponse()
- {
- Success = false,
- ErrorMessage = "指定的审核人不存在"
- };
- }
- }
- else
- {
- return new ApiSaveResponse()
- {
- Success = false,
- ErrorMessage = "只有申诉人和审核人在未审核状态时才能变更审核人"
- };
- }
- }
- else
- {
- return new ApiSaveResponse()
- {
- Success = false,
- ErrorMessage = "指定的申诉记录不存在"
- };
- }
- }
- private void Log(string strMessage)
- {
- StreamWriter sw = System.IO.File.AppendText("c:\\temp\\log.txt");
- sw.WriteLine($"{strMessage}");
- sw.Flush();
- sw.Close();
- sw.Dispose();
- }
- }
- }
|