354 lines
16 KiB
C#
354 lines
16 KiB
C#
|
|
using APT.BaseData.Domain.Entities.FM;
|
|||
|
|
using APT.Infrastructure.Core;
|
|||
|
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
using APT.Infrastructure.Api;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq.Expressions;
|
|||
|
|
using System;
|
|||
|
|
using System.Linq;
|
|||
|
|
using APT.BaseData.Domain.ApiModel;
|
|||
|
|
using Ubiety.Dns.Core;
|
|||
|
|
using System.Security.AccessControl;
|
|||
|
|
using APT.MS.Domain.Entities.FO;
|
|||
|
|
using APT.BaseData.Domain.Entities;
|
|||
|
|
using APT.MS.Domain.Enums;
|
|||
|
|
using APT.MS.Domain.Entities.BI;
|
|||
|
|
using static APT.MS.Domain.Enums.BI.BIEnums;
|
|||
|
|
using APT.Utility;
|
|||
|
|
using APT.BaseData.Services.Services.FM;
|
|||
|
|
using APT.BaseData.Domain.IServices.FM;
|
|||
|
|
using static APT.SC.WebApi.Controllers.Api.BI.BIController;
|
|||
|
|
using MySqlX.XDevAPI.Common;
|
|||
|
|
using System.ComponentModel;
|
|||
|
|
using NPOI.SS.Formula.Functions;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.IO;
|
|||
|
|
|
|||
|
|
namespace APT.SC.WebApi.Controllers.Api.BI
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 年度监测汇总
|
|||
|
|
/// </summary>
|
|||
|
|
[Route("api/BI/BITask")]
|
|||
|
|
public class BITaskController : AuthorizeApiController<T_BI_BSSAFECHECK>
|
|||
|
|
{
|
|||
|
|
IFMNotificationTaskService NotificationTaskService { get; set; }
|
|||
|
|
|
|||
|
|
public BITaskController(IFMNotificationTaskService notificationTaskService)
|
|||
|
|
{
|
|||
|
|
NotificationTaskService = notificationTaskService;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 关闭待办申请
|
|||
|
|
/// <returns></returns>
|
|||
|
|
/// </summary>
|
|||
|
|
[HttpPost, Route("CloseTask")]
|
|||
|
|
public JsonActionResult<bool> CloseTask([FromBody] KeywordFilter filter)
|
|||
|
|
{
|
|||
|
|
return SafeExecute(() =>
|
|||
|
|
{
|
|||
|
|
if ( filter!=null&& filter.Parameter1 != "" && filter.Parameter2 != "")
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
var currUserid = APT.Infrastructure.Api.AppContext.CurrentSession.UserId;
|
|||
|
|
var currUser = GetEntity<T_FM_USER>(currUserid, "Nav_Department.Nav_User");
|
|||
|
|
T_BI_CLOSE_TASKS task = new T_BI_CLOSE_TASKS();
|
|||
|
|
task.ID = Guid.NewGuid();
|
|||
|
|
task.DEPARTMENT_NAME = currUser.Nav_Department.NAME;
|
|||
|
|
task.USER_NAME = currUser.NAME;
|
|||
|
|
task.TASK_IDS = filter.Parameter1;
|
|||
|
|
task.TASK_NAMES = filter.Parameter2;
|
|||
|
|
task.AUDIT_USER_ID = (Guid)currUser.Nav_Department.USER_ID;
|
|||
|
|
task.AUDIT_USER_NAME = currUser.Nav_Department.Nav_User.NAME;
|
|||
|
|
task.ORG_ID = filter.GetOrgId();
|
|||
|
|
var sendNotice = NotificationTaskService.InsertUserNoticeTaskModel("待办关闭申请", task.ID, filter.GetOrgId(), task.AUDIT_USER_ID, task.AUDIT_USER_NAME, DateTime.Now, DateTime.Now.AddDays(30), (int)FMNoticeTypeEnum.消息, "CLOSETASKS");
|
|||
|
|
UnifiedCommit(() =>
|
|||
|
|
{
|
|||
|
|
if (sendNotice != null)
|
|||
|
|
AddEntityNoCommit(sendNotice);
|
|||
|
|
if (task != null)
|
|||
|
|
AddEntityNoCommit(task);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
return true;
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 确认关闭待办
|
|||
|
|
/// <returns></returns>
|
|||
|
|
/// </summary>
|
|||
|
|
[HttpPost, Route("ConfirmCloseTask")]
|
|||
|
|
public JsonActionResult<bool> ConfirmCloseTask([FromBody] KeywordFilter filter)
|
|||
|
|
{
|
|||
|
|
return SafeExecute(() =>
|
|||
|
|
{
|
|||
|
|
List<Guid> closeTasks = new List<Guid>();
|
|||
|
|
var closeTaskIds = filter.Parameter1.Split(',');
|
|||
|
|
foreach (var closeId in closeTaskIds)
|
|||
|
|
{
|
|||
|
|
closeTasks.Add(Guid.Parse(closeId));
|
|||
|
|
}
|
|||
|
|
var allTasks = GetEntities<T_FM_NOTIFICATION_TASK>(t => closeTasks.Contains(t.ID), new BaseFilter(filter.GetOrgId()));
|
|||
|
|
foreach (var task in allTasks)
|
|||
|
|
{
|
|||
|
|
task.NOTICE_STATUS = (int)FMNoticeStatusEnum.关闭;
|
|||
|
|
}
|
|||
|
|
var finishNotice = NotificationTaskService.GetTaskFinishModel(Guid.Parse(filter.Parameter2));
|
|||
|
|
UnifiedCommit(() =>
|
|||
|
|
{
|
|||
|
|
if (allTasks != null && allTasks.Any())
|
|||
|
|
BantchUpdateEntityNoCommit(allTasks, "NOTICE_STATUS");
|
|||
|
|
if (finishNotice != null)
|
|||
|
|
UpdateEntityNoCommit(finishNotice);
|
|||
|
|
});
|
|||
|
|
return true;
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
public class samePostUserData
|
|||
|
|
{
|
|||
|
|
public List<postUsers> users { get; set; }
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
public class postUsers
|
|||
|
|
{
|
|||
|
|
public string userName { get; set; }
|
|||
|
|
public Guid userID { get; set; }
|
|||
|
|
public int todoCount { get; set; }
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 确认关闭待办
|
|||
|
|
/// <returns></returns>
|
|||
|
|
/// </summary>
|
|||
|
|
[HttpPost, Route("searchSamePost")]
|
|||
|
|
public JsonActionResult<samePostUserData> searchSamePost([FromBody] KeywordFilter filter)
|
|||
|
|
{
|
|||
|
|
return SafeExecute<samePostUserData>(() =>
|
|||
|
|
{
|
|||
|
|
var currUserId = Guid.Parse(filter.Parameter1);
|
|||
|
|
var currUser = GetEntity<T_FM_USER>(t => t.ID == currUserId, "Nav_Person");
|
|||
|
|
var currPost = currUser.Nav_Person.POST_ID;
|
|||
|
|
var currDep = currUser.DEPARTMENT_ID;
|
|||
|
|
BaseFilter baseFilter = new BaseFilter();
|
|||
|
|
baseFilter.Include = new string[] { "Nav_Person" };
|
|||
|
|
baseFilter.IgnoreOrgRule = true;
|
|||
|
|
var allSameUsers = GetEntities<T_FM_USER>(t => t.DEPARTMENT_ID == currDep &&t.Nav_Person.POST_ID==currPost && t.ENABLE_STATUS == 0&&t.ID!=currUserId, baseFilter);
|
|||
|
|
var allSameUserIds = allSameUsers.Select(t => t.ID);
|
|||
|
|
BaseFilter baseFilter1 = new BaseFilter();
|
|||
|
|
|
|||
|
|
var todoTasks = GetEntities<T_FM_NOTIFICATION_TASK>(t => allSameUserIds.Contains(t.USER_ID) && t.NOTICE_STATUS == 0 && t.NOTICE_TYPE != 2 && t.NOTICE_TYPE != 7 && t.TASK_ENDDT >= DateTime.Now.AddMonths(-3), baseFilter1);
|
|||
|
|
samePostUserData Data = new samePostUserData();
|
|||
|
|
List<postUsers> postUsers = new List<postUsers>();
|
|||
|
|
foreach (var user in allSameUsers)
|
|||
|
|
{
|
|||
|
|
postUsers item = new postUsers();
|
|||
|
|
item.userName = user.NAME;
|
|||
|
|
item.userID=user.ID;
|
|||
|
|
item.todoCount = todoTasks.Count(t=>t.USER_ID==user.ID);
|
|||
|
|
postUsers.Add(item);
|
|||
|
|
}
|
|||
|
|
Data.users = postUsers;
|
|||
|
|
return Data;
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
public class todoList
|
|||
|
|
{
|
|||
|
|
[Description("ID")]
|
|||
|
|
public Guid? ID { get; set; }
|
|||
|
|
[Description("消息类型")]
|
|||
|
|
public int NOTICE_TYPE { get; set; }
|
|||
|
|
[Description("消息标题")]
|
|||
|
|
public String NOTICE_TITLE { get; set; }
|
|||
|
|
[Description("消息状态")]
|
|||
|
|
public int NOTICE_STATUS { get; set; }
|
|||
|
|
[Description("办结时间")]
|
|||
|
|
public DateTime TASK_DT { get; set; }
|
|||
|
|
[Description("接收人编号")]
|
|||
|
|
public Guid USER_ID { get; set; }
|
|||
|
|
[Description("接收人姓名")]
|
|||
|
|
public String USER_NAME { get; set; }
|
|||
|
|
[Description("来源表单编号")]
|
|||
|
|
public String SOURCE_FORMCODE { get; set; }
|
|||
|
|
[Description("来源数据ID")]
|
|||
|
|
public Guid? SOURCE_DATA_ID { get; set; }
|
|||
|
|
[Description("任务开始时间")]
|
|||
|
|
public DateTime TASK_STARTDT { get; set; }
|
|||
|
|
[Description("任务结束时间")]
|
|||
|
|
public DateTime TASK_ENDDT { get; set; }
|
|||
|
|
[Description("单据类型")]
|
|||
|
|
public int FORM_TYPE { get; set; }
|
|||
|
|
[Description("是否超时")]
|
|||
|
|
[DataFieldIngore]
|
|||
|
|
public string OVER_TIME { get; set; }
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 确认关闭待办
|
|||
|
|
/// <returns></returns>
|
|||
|
|
/// </summary>
|
|||
|
|
[HttpPost, Route("userToDo")]
|
|||
|
|
public JsonActionResult<dynamic> userToDo([FromBody] KeywordFilter filter)
|
|||
|
|
{
|
|||
|
|
return SafeExecute<dynamic>(() =>
|
|||
|
|
{
|
|||
|
|
var currUserId = Guid.Parse(filter.Parameter1);
|
|||
|
|
KeywordPageFilter baseFilter = new KeywordPageFilter();
|
|||
|
|
DataOrder order1 = new DataOrder();
|
|||
|
|
order1.Field = "NOTICE_STATUS";
|
|||
|
|
order1.Order = DbOrder.ASC;
|
|||
|
|
baseFilter.Orders.Add(order1);
|
|||
|
|
DataOrder order2 = new DataOrder();
|
|||
|
|
order2.Field = "TASK_STARTDT";
|
|||
|
|
order2.Order = DbOrder.DESC;
|
|||
|
|
baseFilter.Orders.Add(order2);
|
|||
|
|
baseFilter.IgnoreOrgRule = true;
|
|||
|
|
var result = new PagedActionResult<T_FM_NOTIFICATION_TASK>();
|
|||
|
|
result = GetOrderPageEntities<T_FM_NOTIFICATION_TASK>(s => s.USER_ID == currUserId && s.NOTICE_STATUS == 0 && s.NOTICE_TYPE != 2 && s.NOTICE_TYPE != 7 && s.TASK_ENDDT >= DateTime.Now.AddMonths(-3), baseFilter);
|
|||
|
|
List<todoList> todoLists = new List<todoList>();
|
|||
|
|
foreach(var item in result.Data)
|
|||
|
|
{
|
|||
|
|
todoList todo = new todoList();
|
|||
|
|
todo.ID = item.ID;
|
|||
|
|
todo.NOTICE_TYPE=item.NOTICE_TYPE;
|
|||
|
|
todo.NOTICE_TITLE = item.NOTICE_TITLE;
|
|||
|
|
todo.NOTICE_STATUS = item.NOTICE_STATUS;
|
|||
|
|
todo.TASK_DT = item.TASK_DT;
|
|||
|
|
todo.USER_ID = item.USER_ID;
|
|||
|
|
todo.USER_NAME = item.USER_NAME;
|
|||
|
|
todo.SOURCE_FORMCODE = item.SOURCE_FORMCODE;
|
|||
|
|
todo.SOURCE_DATA_ID = item.SOURCE_DATA_ID;
|
|||
|
|
todo.TASK_STARTDT = item.TASK_STARTDT;
|
|||
|
|
todo.TASK_ENDDT = item.TASK_ENDDT;
|
|||
|
|
todo.FORM_TYPE = item.FORM_TYPE;
|
|||
|
|
todo.OVER_TIME = (item.TASK_ENDDT < DateTime.Now && item.NOTICE_STATUS == 0) ? "超期" : "正常";
|
|||
|
|
todoLists.Add(todo);
|
|||
|
|
}
|
|||
|
|
return todoLists;
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 获取导入数据
|
|||
|
|
/// 参考 [Route("api/PF/Import")]
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
[HttpPost, Route("GetImportData")]
|
|||
|
|
public JsonActionResult<ImportDataModel> GetImportDataUser()
|
|||
|
|
{
|
|||
|
|
return SafeExecute<ImportDataModel>(() =>
|
|||
|
|
{
|
|||
|
|
var orgId = APT.Infrastructure.Api.AppContext.CurrentSession.OrgId;
|
|||
|
|
var httpRequest = this.HttpContext.Request;
|
|||
|
|
string orgIdStr = httpRequest.Form["OrgId"];// 获取 组织
|
|||
|
|
ImportDataModel result = new ImportDataModel();
|
|||
|
|
var dic = Path.Combine(System.AppContext.BaseDirectory, "tempImportFiles");
|
|||
|
|
if (!Directory.Exists(dic))
|
|||
|
|
Directory.CreateDirectory(dic);
|
|||
|
|
foreach (var key in httpRequest.Form.Files) // 文件键
|
|||
|
|
{
|
|||
|
|
var postedFile = key; // 获取文件键对应的文件对象
|
|||
|
|
string filePath = Path.Combine(dic, DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + "_" + postedFile.FileName);
|
|||
|
|
Byte[] fileData = new Byte[postedFile.Length];
|
|||
|
|
Stream sr = postedFile.OpenReadStream();//创建数据流对象
|
|||
|
|
sr.Read(fileData, 0, (int)postedFile.Length);
|
|||
|
|
using (FileStream fs = new FileStream(filePath, FileMode.CreateNew))
|
|||
|
|
{
|
|||
|
|
fs.Write(fileData, 0, fileData.Length);
|
|||
|
|
fs.Flush();
|
|||
|
|
fs.Close();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//获取数据
|
|||
|
|
Dictionary<int, int> startRowIndexs = new Dictionary<int, int>();
|
|||
|
|
startRowIndexs.Add(0, 1);//根据Excel格式数据赋值
|
|||
|
|
var dataTables = FileUtils.ReadExcelByOledb(filePath, startRowIndexs);
|
|||
|
|
string Msg = string.Empty;
|
|||
|
|
|
|||
|
|
bool isOK = InsertModelUser(dataTables.Tables[0], orgId, ref Msg);
|
|||
|
|
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
System.IO.File.Delete(filePath);
|
|||
|
|
}
|
|||
|
|
catch { }
|
|||
|
|
|
|||
|
|
result.Data = Msg;
|
|||
|
|
result.MessageList = new List<string> { Msg };
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return result;
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 数据插入
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="dtSource"></param>
|
|||
|
|
/// <param name="OrgID"></param>
|
|||
|
|
/// <param name="Msg"></param>
|
|||
|
|
/// <param name="rowIndex"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
/// <exception cref="Exception"></exception>
|
|||
|
|
public bool InsertModelUser(DataTable dtSource, Guid? orgId, ref string Msg, int rowIndex = 1)
|
|||
|
|
{
|
|||
|
|
if (dtSource == null || dtSource.Rows.Count < rowIndex)
|
|||
|
|
{
|
|||
|
|
Msg = "未获取到导入数据";
|
|||
|
|
throw new Exception(Msg);
|
|||
|
|
}
|
|||
|
|
int rowAll = dtSource.Rows.Count;
|
|||
|
|
if (!string.IsNullOrEmpty(Msg))
|
|||
|
|
{
|
|||
|
|
throw new Exception(Msg);
|
|||
|
|
}
|
|||
|
|
List<T_FM_DEPARTMENT_SCHEDULING> items = new List<T_FM_DEPARTMENT_SCHEDULING>();
|
|||
|
|
List<T_FM_DEPARTMENT_SCHEDULING_DETAIL> itemDetails = new List<T_FM_DEPARTMENT_SCHEDULING_DETAIL>();
|
|||
|
|
|
|||
|
|
var teams = GetEntities<T_FM_TEAM>(t => t.IS_DELETED == false, new BaseFilter(orgId));
|
|||
|
|
for (int i = 0; i < rowAll; i++)
|
|||
|
|
{
|
|||
|
|
T_FM_DEPARTMENT_SCHEDULING item = new T_FM_DEPARTMENT_SCHEDULING();
|
|||
|
|
item.ID = Guid.NewGuid();
|
|||
|
|
var teamName = dtSource.Rows[i][0].ToString().Trim();
|
|||
|
|
var team = teams.FirstOrDefault(t => t.NAME == teamName);
|
|||
|
|
if (team == null)
|
|||
|
|
{
|
|||
|
|
Msg = "未能找到对应班组";
|
|||
|
|
throw new Exception(Msg);
|
|||
|
|
}
|
|||
|
|
item.CLASS_ID = GetEntity<T_FM_CLASS>(t => t.NAME == "手动导入").ID;
|
|||
|
|
item.TEAM_ID = team.ID;
|
|||
|
|
item.DATE_TIME = DateTime.Parse(dtSource.Rows[i][1].ToString().Trim());
|
|||
|
|
item.START_TIME = DateTime.Parse(dtSource.Rows[i][2].ToString().Trim());
|
|||
|
|
item.END_TIME = DateTime.Parse(dtSource.Rows[i][3].ToString().Trim());
|
|||
|
|
item.DEPARTMENT_ID = (Guid)team.DEPARTMENT_ID;
|
|||
|
|
var users = dtSource.Rows[i][4].ToString().Trim();
|
|||
|
|
var userdt = users.Split(",");
|
|||
|
|
var persons = GetEntities<T_FM_PERSON>(t => userdt.Contains(t.NAME), new BaseFilter(orgId));
|
|||
|
|
foreach (var user in userdt)
|
|||
|
|
{
|
|||
|
|
var person = persons.FirstOrDefault(t => t.NAME == user);
|
|||
|
|
if (person == null)
|
|||
|
|
{
|
|||
|
|
Msg = "未找到人员"+ user;
|
|||
|
|
throw new Exception(Msg);
|
|||
|
|
}
|
|||
|
|
T_FM_DEPARTMENT_SCHEDULING_DETAIL sd = new T_FM_DEPARTMENT_SCHEDULING_DETAIL()
|
|||
|
|
{
|
|||
|
|
DEPARTMENT_SCHEDULING_ID=item.ID,
|
|||
|
|
PERSON_ID = person.ID,
|
|||
|
|
ORG_ID = orgId
|
|||
|
|
};
|
|||
|
|
itemDetails.Add(sd);
|
|||
|
|
}
|
|||
|
|
item.ORG_ID = orgId;
|
|||
|
|
items.Add(item);
|
|||
|
|
}
|
|||
|
|
UnifiedCommit(() =>
|
|||
|
|
{
|
|||
|
|
if (items != null && items.Any())
|
|||
|
|
BantchAddEntityNoCommit(items);
|
|||
|
|
if (itemDetails != null && itemDetails.Any())
|
|||
|
|
BantchAddEntityNoCommit(itemDetails);
|
|||
|
|
});
|
|||
|
|
Msg = "导入成功!";
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|