123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- using Microsoft.EntityFrameworkCore;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using wispro.sp.api.Controllers;
- using wispro.sp.entity;
- using wispro.sp.share;
- namespace wispro.sp.api.AppealHandler
- {
- public class ChangeDoPersonReviewer : IDoAppealObject
- {
- public void DoAppeal(AppealObject appeal, int appealRecordId, DbContext spContext)
- {
- bool isAggree = false;
- foreach (var iv in appeal.inputFieldValues)
- {
- if (iv.InputField == null)
- {
- iv.InputField = ((spDbContext)spContext).InputFields.FirstOrDefault(s => s.Id == iv.InputFieldId);
- }
- if (iv.InputField.FieldName == "审核意见" && iv.Value == "确认变更")
- {
- isAggree = true;
- break;
- }
- }
- if (isAggree)
- {
- var result = ((spDbContext)spContext).InputFieldValues.Where<InputFieldValue>(f => f.AppealRecordId == appealRecordId && f.InputField.AppealState == 0).ToList();
- string strOldPerson = "";
- string strNewPerson = "";
-
- foreach (var iv in result)
- {
- if (iv.InputField == null)
- {
- iv.InputField = ((spDbContext)spContext).InputFields.FirstOrDefault(s => s.Id == iv.InputFieldId);
- }
- if (iv.InputField.FieldName == "变更前处理人")
- {
- strOldPerson = iv.Value;
- continue;
- }
- if (iv.InputField.FieldName == "变更后处理人")
- {
- strNewPerson = iv.Value;
- continue;
- }
- }
- var appRecord = ((spDbContext)spContext).AppealRecords.FirstOrDefault(f => f.Id == appealRecordId);
- if(appRecord != null)
- {
- var itemStaffs = ((spDbContext)spContext).ItemStaffs.Include(p=>p.DoPerson).Where(s => s.ItemId == appRecord.ItemId.Value);
- var oldPersons = strOldPerson.Split(new char[] { ' ', ',', ',' },StringSplitOptions.RemoveEmptyEntries);
- var newPersons = strNewPerson.Split(new char[] { ' ', ',', ',' }, StringSplitOptions.RemoveEmptyEntries);
-
- bool oldPersonExist = true;
- List<ItemStaff> waitingRemoveObj = new List<ItemStaff>();
- foreach(var temName in oldPersons)
- {
- var temItemStaff = itemStaffs.Where(s => s.DoPerson.Name == temName).FirstOrDefault();
- if(temItemStaff == null)
- {
- oldPersonExist = false;
- break;
- }
- else
- {
- waitingRemoveObj.Add(temItemStaff);
- }
- }
- //foreach (ItemStaff staff in itemStaffs)
- //{
- // if (oldPersons.Contains(staff.DoPerson.Name))
- // {
- // waitingRemoveObj.Add(staff);
-
- // oldPersonExist = true;
-
- // }
- // else
- // {
- // oldPersonExist = false;
- // break;
- // }
- //}
-
- if (oldPersonExist)
- {
- ((spDbContext)spContext).ItemStaffs.RemoveRange(waitingRemoveObj);
- foreach (var temName in newPersons)
- {
- var newStaff = ((spDbContext)spContext).Staffs.FirstOrDefault(s => s.Name == temName.Trim());
-
- if (newStaff != null )
- {
- var temItemStaff = ((spDbContext)spContext).ItemStaffs.Where(s => s.ItemId == appRecord.ItemId.Value && s.DoPersonId == newStaff.Id).FirstOrDefault();
- if (temItemStaff == null)
- {
- ((spDbContext)spContext).ItemStaffs.Add(new ItemStaff()
- {
- ItemId = appRecord.ItemId.Value,
- DoPersonId = newStaff.Id
- });
- }
- }
- else
- {
- throw new ApplicationException("变更后处理人不存在!");
- }
- }
- }
- else
- {
- throw new ApplicationException("变更前处理人不存在!");
- }
- }
- }
- }
- }
- }
|