|
@@ -0,0 +1,292 @@
|
|
|
|
+using DocumentFormat.OpenXml.InkML;
|
|
|
|
+using DynamicExpresso;
|
|
|
|
+using Microsoft.AspNetCore.Authorization;
|
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
|
+using Microsoft.EntityFrameworkCore;
|
|
|
|
+using System;
|
|
|
|
+using System.Collections.Generic;
|
|
|
|
+using System.Linq;
|
|
|
|
+using System.Linq.Expressions;
|
|
|
|
+using wispro.sp.api.Services;
|
|
|
|
+using wispro.sp.entity;
|
|
|
|
+using wispro.sp.entity.CompareCase;
|
|
|
|
+using wispro.sp.share;
|
|
|
|
+
|
|
|
|
+namespace wispro.sp.api.Controllers
|
|
|
|
+{
|
|
|
|
+ [Route("api/[controller]/[action]")]
|
|
|
|
+ [ApiController]
|
|
|
|
+ public class CaseFileCompareController : ControllerBase
|
|
|
|
+ {
|
|
|
|
+ spDbContext Context;
|
|
|
|
+ IFileTaskService fileTaskService;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public CaseFileCompareController(spDbContext context, IFileTaskService _fileTaskService)
|
|
|
|
+ {
|
|
|
|
+ Context = context;
|
|
|
|
+ fileTaskService = _fileTaskService;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ [Authorize]
|
|
|
|
+ public ApiSaveResponse Save(CaseInfo caseInfo)
|
|
|
|
+ {
|
|
|
|
+ ApiSaveResponse ret = new ApiSaveResponse();
|
|
|
|
+ ret.Success = true;
|
|
|
|
+
|
|
|
|
+ using (Context.Database.BeginTransaction())
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ #region 客户处理
|
|
|
|
+ if (caseInfo.Customer != null && !string.IsNullOrEmpty(caseInfo.Customer.Name))
|
|
|
|
+ {
|
|
|
|
+ var temCustomer = Context.Customers.Where<Customer>(c => c.Name == caseInfo.Customer.Name).FirstOrDefault();
|
|
|
|
+
|
|
|
|
+ if (temCustomer == null)
|
|
|
|
+ {
|
|
|
|
+ temCustomer = new Customer() { Name = caseInfo.Customer.Name };
|
|
|
|
+ //item.Customer.Id = 0;
|
|
|
|
+
|
|
|
|
+ Context.Customers.Add(temCustomer);
|
|
|
|
+ Context.SaveChanges();
|
|
|
|
+ caseInfo.Customer = temCustomer;
|
|
|
|
+ //item.CustomerId = item.Customer.Id;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ caseInfo.Customer = temCustomer;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ caseInfo.CustomerId = caseInfo.Customer.Id;
|
|
|
|
+ caseInfo.Customer = null;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ caseInfo.Customer = null;
|
|
|
|
+ }
|
|
|
|
+ #endregion
|
|
|
|
+
|
|
|
|
+ #region 审核人
|
|
|
|
+ if (caseInfo.Reviewer != null && !string.IsNullOrEmpty(caseInfo.Reviewer.Name))
|
|
|
|
+ {
|
|
|
|
+ var temReviewer = Context.Staffs.Where<Staff>(c => c.Name == caseInfo.Reviewer.Name).FirstOrDefault();
|
|
|
|
+
|
|
|
|
+ if (temReviewer == null)
|
|
|
|
+ {
|
|
|
|
+ temReviewer = new Staff() { Name = caseInfo.Reviewer.Name };
|
|
|
|
+ //item.Customer.Id = 0;
|
|
|
|
+
|
|
|
|
+ Context.Staffs.Add(temReviewer);
|
|
|
|
+ Context.SaveChanges();
|
|
|
|
+ caseInfo.Reviewer = temReviewer;
|
|
|
|
+ //item.CustomerId = item.Customer.Id;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ caseInfo.Reviewer = temReviewer;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ caseInfo.ReviewerId = caseInfo.Reviewer.Id;
|
|
|
|
+ caseInfo.Reviewer = null;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ caseInfo.Reviewer = null;
|
|
|
|
+ }
|
|
|
|
+ #endregion
|
|
|
|
+
|
|
|
|
+ if (caseInfo.DRRAbstract != null) {
|
|
|
|
+ Context.CaseCompareResults.Add(caseInfo.DRRAbstract);
|
|
|
|
+ Context.SaveChanges();
|
|
|
|
+ caseInfo.DRRAbstractId = caseInfo.DRRAbstract.Id;
|
|
|
|
+ caseInfo.DRRAbstract = null;
|
|
|
|
+ }
|
|
|
|
+ if (caseInfo.DRRCalim != null)
|
|
|
|
+ {
|
|
|
|
+ Context.CaseCompareResults.Add(caseInfo.DRRCalim);
|
|
|
|
+ Context.SaveChanges();
|
|
|
|
+ caseInfo.DRRCalimId = caseInfo.DRRCalim.Id;
|
|
|
|
+ caseInfo.DRRCalim = null;
|
|
|
|
+ }
|
|
|
|
+ if (caseInfo.DRRFulltext != null)
|
|
|
|
+ {
|
|
|
|
+ Context.CaseCompareResults.Add(caseInfo.DRRFulltext);
|
|
|
|
+ Context.SaveChanges();
|
|
|
|
+ caseInfo.DRRFulltextId = caseInfo.DRRFulltext.Id;
|
|
|
|
+ caseInfo.DRRFulltext = null;
|
|
|
|
+ }
|
|
|
|
+ if (caseInfo.DRRAll != null)
|
|
|
|
+ {
|
|
|
|
+ Context.CaseCompareResults.Add(caseInfo.DRRAll);
|
|
|
|
+ Context.SaveChanges();
|
|
|
|
+ caseInfo.DRRAllId = caseInfo.DRRAll.Id;
|
|
|
|
+ caseInfo.DRRAll = null;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ if (caseInfo.RFRAbstract != null)
|
|
|
|
+ {
|
|
|
|
+ Context.CaseCompareResults.Add(caseInfo.RFRAbstract);
|
|
|
|
+ Context.SaveChanges();
|
|
|
|
+ caseInfo.RFRAbstractId = caseInfo.RFRAbstract.Id;
|
|
|
|
+ caseInfo.RFRAbstract = null;
|
|
|
|
+ }
|
|
|
|
+ if (caseInfo.RFRCalim != null)
|
|
|
|
+ {
|
|
|
|
+ Context.CaseCompareResults.Add(caseInfo.RFRCalim);
|
|
|
|
+ Context.SaveChanges();
|
|
|
|
+ caseInfo.RFRCalimId = caseInfo.RFRCalim.Id;
|
|
|
|
+ caseInfo.RFRCalim = null;
|
|
|
|
+ }
|
|
|
|
+ if (caseInfo.RFRFulltext != null)
|
|
|
|
+ {
|
|
|
|
+ Context.CaseCompareResults.Add(caseInfo.RFRFulltext);
|
|
|
|
+ Context.SaveChanges();
|
|
|
|
+ caseInfo.RFRFulltextId = caseInfo.RFRFulltext.Id;
|
|
|
|
+ caseInfo.RFRFulltext = null;
|
|
|
|
+ }
|
|
|
|
+ if (caseInfo.RFRAll != null)
|
|
|
|
+ {
|
|
|
|
+ Context.CaseCompareResults.Add(caseInfo.RFRAll);
|
|
|
|
+ Context.SaveChanges();
|
|
|
|
+ caseInfo.RFRAllId = caseInfo.RFRAll.Id;
|
|
|
|
+ caseInfo.RFRAll = null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Context.CaseInfos.Add(caseInfo);
|
|
|
|
+ Context.SaveChanges();
|
|
|
|
+ Context.Database.CommitTransaction();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ catch (Exception ex)
|
|
|
|
+ {
|
|
|
|
+ ret.Success = false;
|
|
|
|
+ ret.ErrorMessage = ex.Message;
|
|
|
|
+ Context.Database.RollbackTransaction();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public ListApiResponse<CaseInfo> QueryFilter(QueryFilter queryFilter)
|
|
|
|
+ {
|
|
|
|
+ ListApiResponse<CaseInfo> ret = new ListApiResponse<CaseInfo>();
|
|
|
|
+
|
|
|
|
+ IQueryable<CaseInfo> response = NewMethod(queryFilter);
|
|
|
|
+
|
|
|
|
+ int totals = response.Count();
|
|
|
|
+
|
|
|
|
+ if (totals > 0 && totals < (queryFilter.PageIndex) * queryFilter.PageSize)
|
|
|
|
+ {
|
|
|
|
+ response = response
|
|
|
|
+ .Include(pi => pi.DRRCalim)
|
|
|
|
+ .Include(pi => pi.DRRAbstract)
|
|
|
|
+ .Include(pi => pi.DRRFulltext)
|
|
|
|
+ .Include(pi => pi.DRRAll)
|
|
|
|
+ .Include(pi => pi.RFRCalim)
|
|
|
|
+ .Include(pi => pi.RFRAbstract)
|
|
|
|
+ .Include(pi => pi.RFRFulltext)
|
|
|
|
+ .Include(pi => pi.RFRAll)
|
|
|
|
+ .Include(pi => pi.Customer)
|
|
|
|
+ .Include(pi => pi.Reviewer)
|
|
|
|
+ .OrderConditions<CaseInfo>(queryFilter.Sorts)
|
|
|
|
+ .Skip((queryFilter.PageIndex - 1) * queryFilter.PageSize)
|
|
|
|
+ .Take(totals - (queryFilter.PageIndex - 1) * queryFilter.PageSize);
|
|
|
|
+ //.Pager<PerformanceItem>(1, queryFilter.PageSize, out totals);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ response = response
|
|
|
|
+ .Include(pi => pi.DRRCalim)
|
|
|
|
+ .Include(pi => pi.DRRAbstract)
|
|
|
|
+ .Include(pi => pi.DRRFulltext)
|
|
|
|
+ .Include(pi=>pi.DRRAll)
|
|
|
|
+ .Include(pi => pi.RFRCalim)
|
|
|
|
+ .Include(pi => pi.RFRAbstract)
|
|
|
|
+ .Include(pi => pi.RFRFulltext)
|
|
|
|
+ .Include(pi => pi.RFRAll)
|
|
|
|
+ .Include(pi => pi.Customer)
|
|
|
|
+ .Include(pi => pi.Reviewer)
|
|
|
|
+ .OrderConditions<CaseInfo>(queryFilter.Sorts)
|
|
|
|
+ .Skip((queryFilter.PageIndex - 1) * queryFilter.PageSize)
|
|
|
|
+ .Take(queryFilter.PageSize);
|
|
|
|
+ }
|
|
|
|
+ ret.TotalCount = totals;
|
|
|
|
+
|
|
|
|
+ var retList = response.ToList<CaseInfo>();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ #region 将某些属性设为null,避免循环取值造成返回json过大
|
|
|
|
+ foreach (CaseInfo item in retList)
|
|
|
|
+ {
|
|
|
|
+ item.Customer.PerformanceItems = null;
|
|
|
|
+ item.Customer.ResponseMan = null;
|
|
|
|
+ item.Reviewer.Customers = null;
|
|
|
|
+ item.Reviewer.ExternalHandlerItems = null;
|
|
|
|
+ item.Reviewer.ItemStaffs = null;
|
|
|
|
+ item.Reviewer.AllocationRatios = null;
|
|
|
|
+ item.Reviewer.ReviewerItems = null;
|
|
|
|
+ }
|
|
|
|
+ #endregion
|
|
|
|
+
|
|
|
|
+ ret.Results = retList.ToList();
|
|
|
|
+
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private string GetExpress(IList<FieldCondition> conditions)
|
|
|
|
+ {
|
|
|
|
+ string str = "";
|
|
|
|
+
|
|
|
|
+ foreach (var c in conditions)
|
|
|
|
+ {
|
|
|
|
+ if (string.IsNullOrEmpty(str))
|
|
|
|
+ {
|
|
|
|
+ str = c.ToExpressString("s");
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ if (c.LogicOperate == LogicEnum.And)
|
|
|
|
+ {
|
|
|
|
+ str = $"({str}) && {c.ToExpressString("s")}";
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ str = $"({str}) || {c.ToExpressString("s")}";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return str;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private IQueryable<CaseInfo> NewMethod(QueryFilter queryFilter)
|
|
|
|
+ {
|
|
|
|
+ string strExpress = "";
|
|
|
|
+
|
|
|
|
+ if (queryFilter.ConditionTree != null)
|
|
|
|
+ {
|
|
|
|
+ strExpress = GetExpress(queryFilter.ConditionTree);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var interpreter = new Interpreter();
|
|
|
|
+ if (string.IsNullOrEmpty(strExpress))
|
|
|
|
+ {
|
|
|
|
+ return new spDbContext().CaseInfos.Where<CaseInfo>(p=>(p.Id>0));
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ Expression<Func<CaseInfo, bool>> dynamicWhere = interpreter.ParseAsExpression<Func<CaseInfo, bool>>(strExpress, "s");
|
|
|
|
+
|
|
|
|
+ IQueryable<CaseInfo> response = new spDbContext().CaseInfos.Where<CaseInfo>(dynamicWhere);
|
|
|
|
+ return response;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|