272 lines
		
	
	
		
			14 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			272 lines
		
	
	
		
			14 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using APT.BaseData.Domain.Entities.FM;
 | 
						|
using APT.BaseData.Domain.Entities;
 | 
						|
using APT.BaseData.Domain.Enums.PF;
 | 
						|
using APT.BaseData.Domain.Enums;
 | 
						|
using APT.BaseData.Domain.IServices.FM;
 | 
						|
using APT.BaseData.Domain.IServices;
 | 
						|
using APT.Infrastructure.Core;
 | 
						|
using APT.MS.Domain.Entities.SK;
 | 
						|
using APT.MS.Domain.Enums;
 | 
						|
using APT.Utility;
 | 
						|
using Microsoft.AspNetCore.Mvc;
 | 
						|
using log4net.Core;
 | 
						|
using APT.MS.Domain.Enums.SK;
 | 
						|
using APT.MS.Domain.Entities.FO;
 | 
						|
using System;
 | 
						|
using System.Collections.Generic;
 | 
						|
using System.Linq;
 | 
						|
 | 
						|
namespace APT.SK.WebApi.Controllers.Api
 | 
						|
{
 | 
						|
    /// <summary>
 | 
						|
    ///  辨识评估计划
 | 
						|
    /// </summary>
 | 
						|
    [Route("api/SK/SKIdentifyEvaluationPlan")]
 | 
						|
    public partial class IdentifyEvaluationPlanController : AuthorizeApiController<T_SK_IDENTIFY_EVALUATION_PLAN>
 | 
						|
    {
 | 
						|
        IPFApproveCallBackService ApproveCallBackService { get; set; }
 | 
						|
        IFMNotificationTaskService NotificationTaskService { get; set; }
 | 
						|
        IPFCodeRuleService CodeRuleService { get; set; }
 | 
						|
        IFMFlowPermitService MFlowPermitService { get; set; }
 | 
						|
        public IdentifyEvaluationPlanController(IFMNotificationTaskService notificationTaskService, IFMFlowPermitService mFlowPermitService, IPFCodeRuleService codeRuleService, IPFApproveCallBackService approveCallBackService)
 | 
						|
        {
 | 
						|
            NotificationTaskService = notificationTaskService;
 | 
						|
            MFlowPermitService = mFlowPermitService;
 | 
						|
            CodeRuleService = codeRuleService;
 | 
						|
            ApproveCallBackService = approveCallBackService;
 | 
						|
        }
 | 
						|
        [HttpPost, Route("FullUpdate")]
 | 
						|
        public JsonActionResult<bool> FullUpdate([FromBody] T_SK_IDENTIFY_EVALUATION_PLAN entity)
 | 
						|
        {
 | 
						|
            return SafeExecute<bool>(() =>
 | 
						|
            {
 | 
						|
                var userId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
 | 
						|
                var departId = APT.Infrastructure.Api.AppContext.CurrentSession.DepartmentID;
 | 
						|
                if (entity.APPLY_USER_ID == null)
 | 
						|
                    entity.APPLY_USER_ID = userId;
 | 
						|
                if (entity.APPLY_DEPARTMENT_ID == null)
 | 
						|
                    entity.APPLY_DEPARTMENT_ID = departId;
 | 
						|
                var details = entity.Nav_Details;
 | 
						|
                entity.Nav_Details = null;
 | 
						|
                var files = entity.Nav_Files;
 | 
						|
                entity.Nav_Files = null;
 | 
						|
                var requires = entity.Nav_Requires;
 | 
						|
                entity.Nav_Requires = null;
 | 
						|
                entity.ApplyDepartmentName = this.GetEntity<T_FM_DEPARTMENT>(t => t.ID == departId).NAME;
 | 
						|
                entity.ApplyPostName = this.GetEntity<T_FM_USER>(t => t.ID == userId, "Nav_Person.Nav_Post")?.Nav_Person?.Nav_Post?.NAME;
 | 
						|
                if (entity.START_DATE.Value.Date < DateTime.Now.Date)
 | 
						|
                {
 | 
						|
                    throw new Exception("辨识开始时间必须大于今天");
 | 
						|
                }
 | 
						|
                List<Guid> deleteUserIds = new List<Guid>();
 | 
						|
                List<Guid> deleteIds = new List<Guid>();
 | 
						|
                List<T_SK_IDENTIFY_EVALUATION_PLAN_DETAIL_USER> userList = new List<T_SK_IDENTIFY_EVALUATION_PLAN_DETAIL_USER>();
 | 
						|
                var error1 = details.FirstOrDefault(t => t.DEPARTMENT_ID == null && !t.IS_DELETED);
 | 
						|
                if (error1 != null)
 | 
						|
                {
 | 
						|
                    throw new Exception("辨识部门不能为空");
 | 
						|
                }
 | 
						|
                var error2 = details.FirstOrDefault(t => t.Nav_DetailUsers == null && !t.IS_DELETED);
 | 
						|
                if (error2 != null)
 | 
						|
                {
 | 
						|
                    throw new Exception("辨识人员不能为空");
 | 
						|
                }
 | 
						|
                deleteIds = this.GetEntities<T_SK_IDENTIFY_EVALUATION_PLAN_DETAIL>(t => t.IDENTIFY_EVALUATION_PLAN_ID == entity.ID, new BaseFilter(entity.ORG_ID)).Select(t => t.ID).ToList();
 | 
						|
                deleteUserIds = this.GetEntities<T_SK_IDENTIFY_EVALUATION_PLAN_DETAIL_USER>(t => deleteIds.Contains(t.IDENTIFY_EVALUATION_PLAN_DETAIL_ID), new BaseFilter(entity.ORG_ID)).Select(t => t.ID).ToList();
 | 
						|
                if (details != null && details.Where(t => !t.IS_DELETED).Any())
 | 
						|
                {
 | 
						|
                    foreach (var item in details.Where(t => !t.IS_DELETED).ToList())
 | 
						|
                    {
 | 
						|
                        item.ORG_ID = entity.ORG_ID;
 | 
						|
                        item.IDENTIFY_EVALUATION_PLAN_ID = entity.ID;
 | 
						|
                        if (item.Nav_DetailUsers != null && item.Nav_DetailUsers.Where(t => !t.IS_DELETED).Any())
 | 
						|
                        {
 | 
						|
                            foreach (var item2 in item.Nav_DetailUsers.Where(t => !t.IS_DELETED).ToList())
 | 
						|
                            {
 | 
						|
                                item2.ORG_ID = entity.ORG_ID;
 | 
						|
                                item2.IDENTIFY_EVALUATION_PLAN_DETAIL_ID = item.ID;
 | 
						|
                                item2.Nav_User = null;
 | 
						|
                                userList.Add(item2);
 | 
						|
                            }
 | 
						|
                        }
 | 
						|
                        item.Nav_DetailUsers = null;
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                if (files != null && files.Any())
 | 
						|
                {
 | 
						|
                    foreach (var item in files)
 | 
						|
                    {
 | 
						|
                        item.ORG_ID = entity.ORG_ID;
 | 
						|
                        item.IDENTIFY_EVALUATION_PLAN_ID = entity.ID;
 | 
						|
                        item.Nav_ImgFile = null;
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                if (requires != null && requires.Any())
 | 
						|
                {
 | 
						|
                    foreach (var item in requires)
 | 
						|
                    {
 | 
						|
                        item.ORG_ID = entity.ORG_ID;
 | 
						|
                        item.IDENTIFY_EVALUATION_PLAN_ID = entity.ID;
 | 
						|
                        item.Nav_Require = null;
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                List<T_FM_NOTIFICATION_TASK> notices = new List<T_FM_NOTIFICATION_TASK>();
 | 
						|
                if (entity.PUBLISH != null && entity.PUBLISH.Equals("SaveAndNotify"))
 | 
						|
                {
 | 
						|
                    var param = "其他";
 | 
						|
                    var department = this.GetEntity<T_FM_DEPARTMENT>(t => t.ID == entity.APPLY_DEPARTMENT_ID && t.ENABLE_STATUS == 0);
 | 
						|
                    if (department != null)
 | 
						|
                    {
 | 
						|
                        if (department.DEPARTMENT_TYPE == 5 || (department.NAME.Contains("安全环保") && department.DEPARTMENT_TYPE == 10))
 | 
						|
                        { param = "公司"; }
 | 
						|
                    }
 | 
						|
                    entity.STATUS = PFStandardStatus.Approving;
 | 
						|
                    //取审批流水码
 | 
						|
                    var sysFilter = new SystemCodeFilter();
 | 
						|
                    sysFilter.CodeType = (int)PFCodeRuleType.审批流编码;
 | 
						|
                    sysFilter.Count = 1;
 | 
						|
                    sysFilter.OrgId = entity.ORG_ID;
 | 
						|
                    var codes = CodeRuleService.NewGenSerial(sysFilter);
 | 
						|
                    var serialCode = codes.Split(new char[] { ',' });
 | 
						|
                    MFlowPermitService.InsertApprove(serialCode[0], "SK031", param, entity.ID, "SK031_SHOWPRINT", entity.TaskID, true, () =>
 | 
						|
                    {
 | 
						|
                        if (deleteUserIds != null && deleteUserIds.Any())
 | 
						|
                            this.BantchDeleteEntityNoCommit<T_SK_IDENTIFY_EVALUATION_PLAN_DETAIL_USER>(deleteUserIds);
 | 
						|
                        if (deleteIds != null && deleteIds.Any())
 | 
						|
                            this.BantchDeleteEntityNoCommit<T_SK_IDENTIFY_EVALUATION_PLAN_DETAIL>(deleteIds);
 | 
						|
                        if (entity != null)
 | 
						|
                            UpdateEntityNoCommit(entity);
 | 
						|
                        if (details != null && details.Any())
 | 
						|
                            BantchSaveEntityNoCommit(details);
 | 
						|
                        if (files != null && files.Any())
 | 
						|
                            BantchSaveEntityNoCommit(files);
 | 
						|
                        if (requires != null && requires.Any())
 | 
						|
                            BantchSaveEntityNoCommit(requires);
 | 
						|
                        if (userList != null && userList.Any())
 | 
						|
                            BantchSaveEntityNoCommit(userList);
 | 
						|
                    }, null, null, null, null, null, "SK031_SHOWPRINT", null, "安全风险辨识与评估计划审批");
 | 
						|
                    return true;
 | 
						|
                }
 | 
						|
 | 
						|
                this.UnifiedCommit(() =>
 | 
						|
                {
 | 
						|
                    if (deleteUserIds != null && deleteUserIds.Any())
 | 
						|
                        this.BantchDeleteEntityNoCommit<T_SK_IDENTIFY_EVALUATION_PLAN_DETAIL_USER>(deleteUserIds);
 | 
						|
                    if (deleteIds != null && deleteIds.Any())
 | 
						|
                        this.BantchDeleteEntityNoCommit<T_SK_IDENTIFY_EVALUATION_PLAN_DETAIL>(deleteIds);
 | 
						|
                    if (entity != null)
 | 
						|
                        UpdateEntityNoCommit(entity);
 | 
						|
                    if (details != null && details.Any())
 | 
						|
                        BantchSaveEntityNoCommit(details);
 | 
						|
                    if (files != null && files.Any())
 | 
						|
                        BantchSaveEntityNoCommit(files);
 | 
						|
                    if (requires != null && requires.Any())
 | 
						|
                        BantchSaveEntityNoCommit(requires);
 | 
						|
                    if (userList != null && userList.Any())
 | 
						|
                        BantchSaveEntityNoCommit(userList);
 | 
						|
                });
 | 
						|
                return true;
 | 
						|
            });
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 获得单条实体数据
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="filter">过滤实体</param>
 | 
						|
        /// <returns></returns>
 | 
						|
        [HttpPost, Route("SKGet")]
 | 
						|
        public JsonActionResult<T_SK_IDENTIFY_EVALUATION_PLAN> SKGet([FromBody] KeywordFilter filter)
 | 
						|
        {
 | 
						|
            return SafeExecute(() =>
 | 
						|
            {
 | 
						|
                var id = filter.FilterGroup.Rules.FirstOrDefault(t => t.Field == "ID").Value.ToString();
 | 
						|
                if (string.IsNullOrEmpty(id))
 | 
						|
                    this.ThrowError("060010");
 | 
						|
                filter.IgnoreDataRule = true;
 | 
						|
                var result = this.GetEntity<T_SK_IDENTIFY_EVALUATION_PLAN>(id, new string[] { "Nav_ApplyUser", "Nav_ApplyDepartment",
 | 
						|
           "Nav_Files.Nav_ImgFile","Nav_Requires.Nav_Require"});
 | 
						|
                if (result != null)
 | 
						|
                {
 | 
						|
                    var details = this.GetEntities<T_SK_IDENTIFY_EVALUATION_PLAN_DETAIL>(t => t.IDENTIFY_EVALUATION_PLAN_ID == result.ID, new BaseFilter(filter.OrgId), "Nav_Department");
 | 
						|
                    if (details.Any())
 | 
						|
                    {
 | 
						|
                        var detailIds = details.Select(t => t.ID).ToList();
 | 
						|
                        var users = this.GetEntities<T_SK_IDENTIFY_EVALUATION_PLAN_DETAIL_USER>(t => detailIds.Contains(t.IDENTIFY_EVALUATION_PLAN_DETAIL_ID), new BaseFilter(filter.OrgId), "Nav_User");
 | 
						|
                        foreach (var detail in details)
 | 
						|
                        {
 | 
						|
                            var userTemps = users.Where(t => t.IDENTIFY_EVALUATION_PLAN_DETAIL_ID == detail.ID).ToList();
 | 
						|
                            detail.Nav_DetailUsers = userTemps;
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                    result.Nav_Details = details.OrderBy(m => m.NUM).ToList();
 | 
						|
                    if (result.STATUS == PFStandardStatus.Rejected)
 | 
						|
                    {
 | 
						|
                        result.CONTEXT = ApproveCallBackService.RejectContent(result.ID);
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                return result;
 | 
						|
            });
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 回调函数
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="id"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        [HttpPost, Route("BackUpdateNew")]
 | 
						|
        public JsonActionResult<bool> BackUpdateNew([FromBody] T_PF_APPROVE entity)
 | 
						|
        {
 | 
						|
            return SafeExecute(() =>
 | 
						|
            {
 | 
						|
                return ApproveCallBackService.CallBackNew("SK/SKIdentifyEvaluationPlan/BackUpdateNew", entity);
 | 
						|
            });
 | 
						|
        }
 | 
						|
        /// <summary>
 | 
						|
        /// 驳回
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="id"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        [HttpPost, Route("RejectUpdate")]
 | 
						|
        public JsonActionResult<bool> RejectUpdate([FromBody] T_PF_APPROVE model)
 | 
						|
        {
 | 
						|
            return SafeExecute(() =>
 | 
						|
            {
 | 
						|
                //公共 获取审批流信息
 | 
						|
                T_PF_APPROVE modelApp = null;
 | 
						|
                List<T_PF_APPROVE_DETAIL> listAppDetail = null;
 | 
						|
                T_FM_NOTIFICATION_TASK taskFinish = null;
 | 
						|
                string Msg = string.Empty;
 | 
						|
                bool ResultGetInfo = ApproveCallBackService.GetApproject(model, ref modelApp, ref listAppDetail, ref taskFinish, ref Msg);
 | 
						|
                if (!ResultGetInfo)
 | 
						|
                    throw new Exception("驳回失败!");
 | 
						|
                if (modelApp == null || listAppDetail == null)
 | 
						|
                    throw new Exception("获取驳回信息失败!");
 | 
						|
                var entity = this.GetEntity<T_SK_IDENTIFY_EVALUATION_PLAN>(model.DATA_ID, new string[] { "Nav_ApplyUser" });
 | 
						|
                entity.STATUS = PFStandardStatus.Rejected;
 | 
						|
                T_FM_NOTIFICATION_TASK notice = new T_FM_NOTIFICATION_TASK();
 | 
						|
                if (entity.APPLY_USER_ID != null)
 | 
						|
                {
 | 
						|
                    //发消息
 | 
						|
                    notice = NotificationTaskService.InsertUserNoticeTaskModel("安全风险辨识与评估计划被驳回", entity.ID, entity.ORG_ID, (Guid)entity.APPLY_USER_ID, entity.Nav_ApplyUser?.NAME, DateTime.Now,
 | 
						|
               DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum.消息, "SK031");
 | 
						|
                }
 | 
						|
                UnifiedCommit(() =>
 | 
						|
                {
 | 
						|
                    if (entity != null)
 | 
						|
                        this.UpdateEntityNoCommit(entity);
 | 
						|
                    if (notice != null)
 | 
						|
                        this.UpdateEntityNoCommit(notice);
 | 
						|
                    if (modelApp != null)
 | 
						|
                        UpdateEntityNoCommit(modelApp);
 | 
						|
                    if (listAppDetail != null && listAppDetail.Count > 0)
 | 
						|
                        BantchUpdateEntityNoCommit(listAppDetail);
 | 
						|
                    if (taskFinish != null)
 | 
						|
                        UpdateEntityNoCommit(taskFinish);
 | 
						|
                });
 | 
						|
                return true;
 | 
						|
                //return ApproveCallBackService.CallReject("HM/HMLicenseAnalysis/RejectUpdate", id);
 | 
						|
            });
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |