using APT.BaseData.Domain.Entities; using APT.BaseData.Domain.Entities.FM; using APT.BaseData.Domain.IServices.FM; using APT.Infrastructure.Core; using APT.MS.Domain.Entities.LR; using APT.MS.Domain.Enums; using APT.Utility; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace APT.LR.WebApi.Controllers.Api { [Route("api/LR/LRDemandDistinguishReport")] public class DemandDistinguishReportController : AuthorizeApiController { IFMNotificationTaskService NotificationTaskService { get; set; } public DemandDistinguishReportController(IFMNotificationTaskService notificationTaskService) { NotificationTaskService = notificationTaskService; } /// /// 保存 /// /// /// [HttpPost, Route("FullUpdate")] public JsonActionResult FullUpdate([FromBody] T_LR_DEMAND_DISTINGUISH_REPORT entity) { return SafeExecute(() => { var demandReportDetail = entity.Nav_DemandReportDetail; entity.Nav_DemandReportDetail = null; T_FM_NOTIFICATION_TASK finishNotice = null; if (entity.PUBLISH != null && entity.PUBLISH.Equals("SaveAndNotify")) { if (entity.TaskID != Guid.Empty) { finishNotice = NotificationTaskService.GetTaskFinishModel(entity.TaskID); } } UnifiedCommit(() => { UpdateEntityNoCommit(entity); if (demandReportDetail != null && demandReportDetail.Any()) BantchSaveEntityNoCommit(demandReportDetail); if (finishNotice != null) UpdateEntityNoCommit(finishNotice); }); return true; }); } /// /// 由“安全生产法律法规需求识别“形成部门、公司级分析表 /// /// /// [HttpGet, Route("DistinguishReport")] public JsonActionResult DistinguishReport() { return SafeExecute(() => { List demandReportDetails = new List(); List demandReports = new List(); DateTime dateTimeNow = DateTime.Now; List demandDistinguish = GetEntities(t => t.DISTINGUISH_TYPE == LRDistinguishEnum.未识别 && t.YEARS == dateTimeNow.Year, new BaseFilter(), new string[] { "Nav_DemandLaw.Nav_Law", "Nav_DemandOther.Nav_OtherDistinguish.Nav_DemandUser.Nav_User", "Nav_Department" }).ToList(); var department = GetEntities(null, new BaseFilter()).ToList(); var user = GetEntities(null, new BaseFilter()).ToList(); var allDistinguish = GetEntities(c => c.YEARS == dateTimeNow.Year, new BaseFilter()).ToList(); var config = GetEntity(null, new BaseFilter()); if (config != null && config.DEMAND_END_TIME != null) { if (config.DEMAND_END_TIME.Date == dateTimeNow.Date)//日期相同则 { if (department != null && department.Count() > 0) { department.ForEach(t => { if (t.PARENT_ID == null)//公司 { var distinguishCompany = allDistinguish.Where(c => c.DEPARTMENT_ID == t.ID).ToList(); if (distinguishCompany == null || distinguishCompany.Count() == 0) { T_LR_DEMAND_DISTINGUISH_REPORT distinguishReportCompany = new T_LR_DEMAND_DISTINGUISH_REPORT(); distinguishReportCompany.ID = Guid.NewGuid(); distinguishReportCompany.DEPARTMENT_ID = t.ID; distinguishReportCompany.YEARS = dateTimeNow.Year; distinguishReportCompany.REPORT_TIME = dateTimeNow; distinguishReportCompany.INVESTIGATE_TIMES = user.Count(); distinguishReportCompany.FEEDBACK_TIMES = demandDistinguish.Count(); if (user.Count() >= 0 && demandDistinguish.Count() >= 0) { double demandDistinguishCount = demandDistinguish.Count(); double userCount = user.Count(); distinguishReportCompany.FEEDBACK_RATE = ((demandDistinguishCount / userCount) * 100).ToString("#0.00"); } else { distinguishReportCompany.FEEDBACK_RATE = "0"; } distinguishReportCompany.ORG_ID = t.ORG_ID; demandReports.Add(distinguishReportCompany); demandDistinguish.ForEach(d => { if (d.Nav_DemandLaw != null && d.Nav_DemandLaw.Count() > 0)//法律法规 { d.Nav_DemandLaw.ForEach(l => { if (l.Nav_DemandDistinguish != null && l.Nav_DemandDistinguish.NAME != null) { if (demandReportDetails.Any(r => r.DEMAND_NAME.Contains(l.Nav_DemandDistinguish.NAME) && r.IS_OTHER == 0))//已经存在则加人数和部门 { demandReportDetails.ForEach(s => { if (s.DEMAND_NAME == l.Nav_DemandDistinguish.NAME && s.IS_OTHER == 0) { s.DEMAND_TIMES += 1; if (d.Nav_Department != null && d.Nav_Department.NAME != null) { if (string.IsNullOrEmpty(s.DEMAND_DEPARTMENT)) { s.DEMAND_DEPARTMENT = d.Nav_Department.NAME; } else { s.DEMAND_DEPARTMENT += "|" + d.Nav_Department.NAME; } } } }); } else { if (d.Nav_Department != null && d.Nav_Department.NAME != null) { T_LR_DEMAND_DISTINGUISH_REPORT_DETAIL newDemandReportDetail = new T_LR_DEMAND_DISTINGUISH_REPORT_DETAIL(); newDemandReportDetail.DEMAND_DEPARTMENT = d.Nav_Department.NAME; newDemandReportDetail.DEMAND_NAME = l.Nav_DemandDistinguish.NAME; newDemandReportDetail.DEMAND_PERSON = "无"; newDemandReportDetail.DEMAND_TIMES = 1; newDemandReportDetail.IS_OTHER = 0; newDemandReportDetail.ORG_ID = d.ORG_ID; newDemandReportDetail.REPORT_ID = distinguishReportCompany.ID; demandReportDetails.Add(newDemandReportDetail); } } } }); } if (d.Nav_DemandOther != null && d.Nav_DemandOther.Count() > 0)//其他 { d.Nav_DemandOther.ForEach(o => { if (o.Nav_OtherDistinguish != null && o.Nav_OtherDistinguish.NAME != null) { if (demandReportDetails.Any(r => r.DEMAND_NAME.Contains(o.Nav_OtherDistinguish.NAME) && r.IS_OTHER == 1))//已经存在则加人数和部门 { demandReportDetails.ForEach(s => { if (s.DEMAND_NAME == o.Nav_OtherDistinguish.NAME && s.IS_OTHER == 1) { s.DEMAND_TIMES += 1; if (d.Nav_Department != null && d.Nav_Department.NAME != null) { if (string.IsNullOrEmpty(s.DEMAND_DEPARTMENT)) { s.DEMAND_DEPARTMENT = d.Nav_Department.NAME; } else { s.DEMAND_DEPARTMENT += "|" + d.Nav_Department.NAME; } } } }); } else { if (d.Nav_Department != null && d.Nav_Department.NAME != null) { T_LR_DEMAND_DISTINGUISH_REPORT_DETAIL newDemandReportDetail = new T_LR_DEMAND_DISTINGUISH_REPORT_DETAIL(); newDemandReportDetail.DEMAND_DEPARTMENT = d.Nav_Department.NAME; newDemandReportDetail.DEMAND_NAME = o.Nav_OtherDistinguish.NAME; string DEMAND_PERSON = string.Empty; if (o.Nav_OtherDistinguish.Nav_DemandUser != null && o.Nav_OtherDistinguish.Nav_DemandUser.Count() > 0) { o.Nav_OtherDistinguish.Nav_DemandUser.ForEach(od => { if (od.Nav_User != null && od.Nav_User.NAME != null) { if (string.IsNullOrEmpty(DEMAND_PERSON)) { DEMAND_PERSON = od.Nav_User.NAME; } else { DEMAND_PERSON += "|" + od.Nav_User.NAME; } } }); } newDemandReportDetail.DEMAND_PERSON = DEMAND_PERSON; newDemandReportDetail.DEMAND_TIMES = 1; newDemandReportDetail.IS_OTHER = 1; newDemandReportDetail.ORG_ID = d.ORG_ID; newDemandReportDetail.REPORT_ID = distinguishReportCompany.ID; demandReportDetails.Add(newDemandReportDetail); } } } }); } }); } } else { var distinguishDepartment = allDistinguish.Where(c => c.DEPARTMENT_ID == t.ID).ToList(); if (distinguishDepartment == null || distinguishDepartment.Count() == 0) { var demandDistinguishDepartment = demandDistinguish.Where(d => d.DEPARTMENT_ID == t.ID).ToList(); T_LR_DEMAND_DISTINGUISH_REPORT distinguishReportDepartment = new T_LR_DEMAND_DISTINGUISH_REPORT(); distinguishReportDepartment.ID = Guid.NewGuid(); distinguishReportDepartment.DEPARTMENT_ID = t.ID; distinguishReportDepartment.YEARS = dateTimeNow.Year; distinguishReportDepartment.REPORT_TIME = dateTimeNow; distinguishReportDepartment.INVESTIGATE_TIMES = user.Count(); distinguishReportDepartment.FEEDBACK_TIMES = demandDistinguishDepartment.Count(); if (user.Count() >= 0 && demandDistinguishDepartment.Count() >= 0) { double demandDistinguishDepartmentCount = demandDistinguishDepartment.Count(); double userCount = user.Count(); distinguishReportDepartment.FEEDBACK_RATE = ((demandDistinguishDepartmentCount / userCount) * 100).ToString("#0.00"); } else { distinguishReportDepartment.FEEDBACK_RATE = "0"; } distinguishReportDepartment.ORG_ID = t.ORG_ID; demandReports.Add(distinguishReportDepartment); demandDistinguishDepartment.ForEach(d => { if (d.Nav_DemandLaw != null && d.Nav_DemandLaw.Count() > 0)//法律法规 { d.Nav_DemandLaw.ForEach(l => { if (l.Nav_DemandDistinguish != null && l.Nav_DemandDistinguish.NAME != null) { if (demandReportDetails.Any(r => r.DEMAND_NAME.Contains(l.Nav_DemandDistinguish.NAME) && r.IS_OTHER == 0))//已经存在则加人数和部门 { demandReportDetails.ForEach(s => { if (s.DEMAND_NAME == l.Nav_DemandDistinguish.NAME && s.IS_OTHER == 0) { s.DEMAND_TIMES += 1; if (d.Nav_Department != null && d.Nav_Department.NAME != null) { if (string.IsNullOrEmpty(s.DEMAND_DEPARTMENT)) { s.DEMAND_DEPARTMENT = d.Nav_Department.NAME; } else { s.DEMAND_DEPARTMENT += "|" + d.Nav_Department.NAME; } } } }); } else { if (d.Nav_Department != null && d.Nav_Department.NAME != null) { T_LR_DEMAND_DISTINGUISH_REPORT_DETAIL newDemandReportDetail = new T_LR_DEMAND_DISTINGUISH_REPORT_DETAIL(); newDemandReportDetail.DEMAND_DEPARTMENT = d.Nav_Department.NAME; newDemandReportDetail.DEMAND_NAME = l.Nav_DemandDistinguish.NAME; newDemandReportDetail.DEMAND_PERSON = "无"; newDemandReportDetail.DEMAND_TIMES = 1; newDemandReportDetail.IS_OTHER = 0; newDemandReportDetail.ORG_ID = d.ORG_ID; newDemandReportDetail.REPORT_ID = distinguishReportDepartment.ID; demandReportDetails.Add(newDemandReportDetail); } } } }); } if (d.Nav_DemandOther != null && d.Nav_DemandOther.Count() > 0)//其他 { d.Nav_DemandOther.ForEach(o => { if (o.Nav_OtherDistinguish != null && o.Nav_OtherDistinguish.NAME != null) { if (demandReportDetails.Any(r => r.DEMAND_NAME.Contains(o.Nav_OtherDistinguish.NAME) && r.IS_OTHER == 1))//已经存在则加人数和部门 { demandReportDetails.ForEach(s => { if (s.DEMAND_NAME == o.Nav_OtherDistinguish.NAME && s.IS_OTHER == 1) { s.DEMAND_TIMES += 1; if (d.Nav_Department != null && d.Nav_Department.NAME != null) { if (string.IsNullOrEmpty(s.DEMAND_DEPARTMENT)) { s.DEMAND_DEPARTMENT = d.Nav_Department.NAME; } else { s.DEMAND_DEPARTMENT += "|" + d.Nav_Department.NAME; } } } }); } else { if (d.Nav_Department != null && d.Nav_Department.NAME != null) { T_LR_DEMAND_DISTINGUISH_REPORT_DETAIL newDemandReportDetail = new T_LR_DEMAND_DISTINGUISH_REPORT_DETAIL(); newDemandReportDetail.DEMAND_DEPARTMENT = d.Nav_Department.NAME; newDemandReportDetail.DEMAND_NAME = o.Nav_OtherDistinguish.NAME; string DEMAND_PERSON = string.Empty; if (o.Nav_OtherDistinguish.Nav_DemandUser != null && o.Nav_OtherDistinguish.Nav_DemandUser.Count() > 0) { o.Nav_OtherDistinguish.Nav_DemandUser.ForEach(od => { if (od.Nav_User != null && od.Nav_User.NAME != null) { if (string.IsNullOrEmpty(DEMAND_PERSON)) { DEMAND_PERSON = od.Nav_User.NAME; } else { DEMAND_PERSON += "|" + od.Nav_User.NAME; } } }); } newDemandReportDetail.DEMAND_PERSON = DEMAND_PERSON; newDemandReportDetail.DEMAND_TIMES = 1; newDemandReportDetail.IS_OTHER = 1; newDemandReportDetail.ORG_ID = d.ORG_ID; newDemandReportDetail.REPORT_ID = distinguishReportDepartment.ID; demandReportDetails.Add(newDemandReportDetail); } } } }); } }); } } }); } UnifiedCommit(() => { if (demandReportDetails.Any()) BantchAddEntity(demandReportDetails); if (demandReports.Any()) BantchAddEntity(demandReports); }); } } return true; }); } } }