320 lines
		
	
	
		
			15 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			320 lines
		
	
	
		
			15 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using APT.BaseData.Domain.Entities;
 | 
						|
using APT.BaseData.Domain.Entities.FM;
 | 
						|
using APT.BaseData.Domain.Enums;
 | 
						|
using APT.BaseData.Domain.Enums.PF;
 | 
						|
using APT.BaseData.Domain.IServices;
 | 
						|
using APT.BaseData.Domain.IServices.FM;
 | 
						|
using APT.BaseData.Services.Services.FM;
 | 
						|
using APT.Infrastructure.Core;
 | 
						|
using APT.MS.Domain.Entities.DM;
 | 
						|
using APT.MS.Domain.Entities.SC.DM;
 | 
						|
using APT.MS.Domain.Enums;
 | 
						|
using APT.Utility;
 | 
						|
using Microsoft.AspNetCore.Mvc;
 | 
						|
using System;
 | 
						|
using System.Collections.Generic;
 | 
						|
using System.Linq;
 | 
						|
using System.Threading.Tasks;
 | 
						|
 | 
						|
namespace APT.SC.WebApi.Controllers.Api.DMController
 | 
						|
{
 | 
						|
    /// <summary>
 | 
						|
    ///  设备设施发放表
 | 
						|
    /// </summary>
 | 
						|
    [Route("api/DM/DMDeviceIssue")]
 | 
						|
    public partial class DeviceIssueController : AuthorizeApiController<T_DM_DEVICE_ISSUE>
 | 
						|
    {
 | 
						|
        IPFCodeRuleService CodeRuleService { get; set; }
 | 
						|
        IFMNotificationTaskService NotificationTaskService { get; set; }
 | 
						|
        IFMFlowPermitService MFlowPermitService { get; set; }
 | 
						|
        IPFApproveCallBackService ApproveCallBackService { get; set; }
 | 
						|
        /// <summary>
 | 
						|
        /// 设备设施发放表
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="notificationTaskService"></param>
 | 
						|
        public DeviceIssueController(IPFCodeRuleService codeRuleService, IFMNotificationTaskService notificationTaskService, IFMFlowPermitService mFlowPermitService, IPFApproveCallBackService approveCallBackService)
 | 
						|
        {
 | 
						|
            CodeRuleService = codeRuleService;
 | 
						|
            NotificationTaskService = notificationTaskService;
 | 
						|
            MFlowPermitService = mFlowPermitService;
 | 
						|
            ApproveCallBackService = approveCallBackService;
 | 
						|
        }
 | 
						|
        /// <summary>
 | 
						|
        /// 新增/编辑
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="entity"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        [HttpPost, Route("FullUpdate")]
 | 
						|
        public JsonActionResult<bool> FullUpdate([FromBody] T_DM_DEVICE_ISSUE entity)
 | 
						|
        {
 | 
						|
            return SafeExecute(() =>
 | 
						|
            {
 | 
						|
                entity.TIME = DateTime.Now;
 | 
						|
                entity.STATUS = PFStandardStatus.Draft;
 | 
						|
                var loginUserId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
 | 
						|
                if (entity.TaskID != Guid.Empty)
 | 
						|
                {
 | 
						|
                    var currTask = GetEntity<T_FM_NOTIFICATION_TASK>(t => t.ID == entity.TaskID);
 | 
						|
                    if (currTask != null)
 | 
						|
                    {
 | 
						|
                        loginUserId = currTask.USER_ID;
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                if (entity.USER_ID == null)
 | 
						|
                    entity.USER_ID = loginUserId;
 | 
						|
                if (entity.DEPARTMENT_ID == null)
 | 
						|
                    entity.DEPARTMENT_ID = this.GetEntity<T_FM_USER>(t => t.ENABLE_STATUS == 0 && t.ID == (Guid)loginUserId)?.DEPARTMENT_ID;
 | 
						|
                if (string.IsNullOrEmpty(entity.CODE))
 | 
						|
                    entity.CODE = DateTime.Now.Year.ToString().PadLeft(4, '0') + DateTime.Now.Month.ToString().PadLeft(2, '0') + DateTime.Now.Day.ToString().PadLeft(2, '0') + new Random().Next().ToString();
 | 
						|
                var details = entity.Nav_Details;
 | 
						|
                entity.Nav_Details = null;
 | 
						|
                if (details != null && details.Any())
 | 
						|
                {
 | 
						|
                    var departIds = details.Select(t => t.DEPARTMENT_ID).Distinct().ToList();
 | 
						|
                    var postIds = details.Select(t => t.USE_USER_POST_ID).Distinct().ToList();
 | 
						|
                    var users = this.GetEntities<T_FM_USER>(t => (departIds.Contains(t.DEPARTMENT_ID) || (t.Nav_Person != null && postIds.Contains(t.Nav_Person.POST_ID))) && t.ENABLE_STATUS == 0, new BaseFilter(entity.ORG_ID), "Nav_Person");
 | 
						|
                    details.ForEach(t =>
 | 
						|
                    {
 | 
						|
                        t.ORG_ID = entity.ORG_ID; t.DEVICE_ISSUE_ID = entity.ID;
 | 
						|
                        t.USER_ID = users.FirstOrDefault(m => m.DEPARTMENT_ID == t.DEPARTMENT_ID && m.Nav_Person.POST_ID == t.USE_USER_POST_ID)?.ID;
 | 
						|
                    });
 | 
						|
                }
 | 
						|
                List<T_FM_NOTIFICATION_TASK> notices = new List<T_FM_NOTIFICATION_TASK>();
 | 
						|
                T_FM_NOTIFICATION_TASK task = null;
 | 
						|
                if (entity.PUBLISH != null && entity.PUBLISH.Equals("SaveAndNotify"))
 | 
						|
                {
 | 
						|
                    //details.ForEach(t =>
 | 
						|
                    //{
 | 
						|
                    //    t.DEAL_STATUS = MS.Domain.Enums.FOUserShiftStatusEnum.已处理;
 | 
						|
                    //});
 | 
						|
                    //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], "DM016", "", entity.ID, "DM016_SHOWPRINT", entity.TaskID, true, () =>
 | 
						|
                    //{
 | 
						|
                    //    if (entity != null)
 | 
						|
                    //        this.UpdateEntityNoCommit(entity);
 | 
						|
                    //    if (details != null && details.Any())
 | 
						|
                    //        this.BantchSaveEntityNoCommit(details);
 | 
						|
                    //}, null, null, null, null, null, "DM016_SHOWPRINT", null);
 | 
						|
                    //return true;
 | 
						|
                    entity.STATUS = PFStandardStatus.Sign;
 | 
						|
                    //details.ForEach(t =>
 | 
						|
                    //{
 | 
						|
                    //    if (t.USER_ID == loginUserId)
 | 
						|
                    //        t.DEAL_STATUS = MS.Domain.Enums.FOUserShiftStatusEnum.已处理;
 | 
						|
                    //});
 | 
						|
                    var userIds = details.Select(t => t.USER_ID).Distinct().ToList();
 | 
						|
                    if (userIds != null && userIds.Any())
 | 
						|
                    {
 | 
						|
                        var users = this.GetEntities<T_FM_USER>(t => userIds.Contains(t.ID) && t.ENABLE_STATUS == 0, new BaseFilter(entity.ORG_ID));
 | 
						|
                        foreach (var item in userIds)
 | 
						|
                        {
 | 
						|
                            var userInfo = users.FirstOrDefault(t => t.ID == item.Value);
 | 
						|
                            if (userInfo != null)
 | 
						|
                            {
 | 
						|
                                notices.Add(NotificationTaskService.InsertUserNoticeTaskModel("设备设施领用发放确认", entity.ID, entity.ORG_ID, userInfo.ID, userInfo.NAME, DateTime.Now, DateTime.Now.AddDays(30), (int)FMNoticeTypeEnum.消息, "DM016_SHOWPRINT"));
 | 
						|
                            }
 | 
						|
                        }
 | 
						|
                    }
 | 
						|
                    if (entity.TaskID != Guid.Empty)
 | 
						|
                    {
 | 
						|
                        task = NotificationTaskService.GetTaskFinishModel(entity.TaskID);
 | 
						|
                        task.SOURCE_FORMCODE = "DM016_SHOWPRINT";
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                UnifiedCommit(() =>
 | 
						|
                {
 | 
						|
                    if (entity != null)
 | 
						|
                        this.UpdateEntityNoCommit(entity);
 | 
						|
                    if (details != null && details.Any())
 | 
						|
                        this.BantchSaveEntityNoCommit(details);
 | 
						|
                    if (notices != null && notices.Any())
 | 
						|
                        this.BantchSaveEntityNoCommit(notices);
 | 
						|
                    if (task != null)
 | 
						|
                        this.UpdateEntityNoCommit(task);
 | 
						|
                });
 | 
						|
                return true;
 | 
						|
            });
 | 
						|
        }
 | 
						|
        /// <summary>
 | 
						|
        /// 识别人确认
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="entity"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        [HttpPost, Route("IdentityUpdate")]
 | 
						|
        public JsonActionResult<bool> IdentityUpdate([FromBody] T_DM_DEVICE_ISSUE entity)
 | 
						|
        {
 | 
						|
            return SafeExecute(() =>
 | 
						|
            {
 | 
						|
                var issue = this.GetEntity<T_DM_DEVICE_ISSUE>(entity.ID, "Nav_Details");
 | 
						|
                var userId = APT.Infrastructure.Api.AppContext.CurrentSession.UserID;
 | 
						|
                if (entity.TaskID != Guid.Empty)
 | 
						|
                {
 | 
						|
                    var currTask = GetEntity<T_FM_NOTIFICATION_TASK>(t => t.ID == entity.TaskID);
 | 
						|
                    if (currTask != null)
 | 
						|
                    {
 | 
						|
                        userId = currTask.USER_ID;
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                var user = this.GetEntity<T_DM_DEVICE_ISSUE_DETAIL>(t => t.DEVICE_ISSUE_ID == issue.ID && t.USER_ID == userId, new BaseFilter(issue.ORG_ID));
 | 
						|
                user.DEAL_STATUS = FOUserShiftStatusEnum.已处理;
 | 
						|
                T_FM_NOTIFICATION_TASK task = null;
 | 
						|
                var todoCount = this.GetCount<T_DM_DEVICE_ISSUE_DETAIL>(t => t.DEVICE_ISSUE_ID == issue.ID && t.DEAL_STATUS == 0, new BaseFilter(issue.ORG_ID));
 | 
						|
                if (todoCount == 0 || todoCount == 1)
 | 
						|
                {
 | 
						|
                    //issue.STATUS = PFStandardStatus.Archived;
 | 
						|
                    issue.STATUS = PFStandardStatus.Approving;
 | 
						|
                    //取审批流水码
 | 
						|
                    var sysFilter = new SystemCodeFilter();
 | 
						|
                    sysFilter.CodeType = (int)PFCodeRuleType.审批流编码;
 | 
						|
                    sysFilter.Count = 1;
 | 
						|
                    sysFilter.OrgId = issue.ORG_ID;
 | 
						|
                    var codes = CodeRuleService.NewGenSerial(sysFilter);
 | 
						|
                    var serialCode = codes.Split(new char[] { ',' });
 | 
						|
                    MFlowPermitService.InsertApprove(serialCode[0], "DM016", "", entity.ID, "DM016_SHOWPRINT", entity.TaskID, true, () =>
 | 
						|
                    {
 | 
						|
                        if (issue != null)
 | 
						|
                            this.UpdateEntityNoCommit(issue);
 | 
						|
                        if (user != null)
 | 
						|
                            this.UpdateEntityNoCommit(user);
 | 
						|
                        if (task != null)
 | 
						|
                            this.UpdateEntityNoCommit(task);
 | 
						|
                    }, null, null, null, null, null, "DM016_SHOWPRINT", issue.USER_ID);
 | 
						|
                }
 | 
						|
                if (entity.TaskID != Guid.Empty)
 | 
						|
                {
 | 
						|
                    task = NotificationTaskService.GetTaskFinishModel(entity.TaskID);
 | 
						|
                    task.SOURCE_FORMCODE = "DM016_SHOWPRINT";
 | 
						|
                }
 | 
						|
                UnifiedCommit(() =>
 | 
						|
                {
 | 
						|
                    if (issue != null)
 | 
						|
                        this.UpdateEntityNoCommit(issue);
 | 
						|
                    if (user != null)
 | 
						|
                        this.UpdateEntityNoCommit(user);
 | 
						|
                    if (task != null)
 | 
						|
                        this.UpdateEntityNoCommit(task);
 | 
						|
                });
 | 
						|
                return true;
 | 
						|
            });
 | 
						|
        }
 | 
						|
        /// <summary>
 | 
						|
        /// 归还
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="entity"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        [HttpPost, Route("DetailUpdate")]
 | 
						|
        public JsonActionResult<bool> DetailUpdate([FromBody] T_DM_DEVICE_ISSUE_DETAIL entity)
 | 
						|
        {
 | 
						|
            return SafeExecute(() =>
 | 
						|
            {
 | 
						|
                T_FM_NOTIFICATION_TASK task = null;
 | 
						|
                if (entity.TaskID != Guid.Empty)
 | 
						|
                {
 | 
						|
                    task = NotificationTaskService.GetTaskFinishModel(entity.TaskID);
 | 
						|
                    task.SOURCE_FORMCODE = "DM026_SHOWPRINT";
 | 
						|
                }
 | 
						|
                UnifiedCommit(() =>
 | 
						|
                {
 | 
						|
                    if (entity != null)
 | 
						|
                        this.UpdateEntityNoCommit(entity);
 | 
						|
                    if (task != null)
 | 
						|
                        this.UpdateEntityNoCommit(task);
 | 
						|
                });
 | 
						|
                return true;
 | 
						|
            });
 | 
						|
        }
 | 
						|
        /// <summary>
 | 
						|
        /// 回调函数
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="id"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        [HttpGet, Route("BackUpdate")]
 | 
						|
        public JsonActionResult<bool> BackUpdate(string id)
 | 
						|
        {
 | 
						|
            return SafeExecute(() =>
 | 
						|
            {
 | 
						|
                return ApproveCallBackService.CallBack("DM/DMDeviceIssue/BackUpdate", id);
 | 
						|
            });
 | 
						|
        }
 | 
						|
 | 
						|
        /// <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_DM_DEVICE_ISSUE>(model.DATA_ID, new string[] { "Nav_User" });
 | 
						|
                entity.STATUS = PFStandardStatus.Rejected;
 | 
						|
                T_FM_NOTIFICATION_TASK notice = new T_FM_NOTIFICATION_TASK();
 | 
						|
                //驳回发消息
 | 
						|
                notice = NotificationTaskService.InsertUserNoticeTaskModel("设备设施发放表已被驳回", entity.ID, entity.ORG_ID, (Guid)entity.USER_ID, entity.Nav_User.NAME, DateTime.Now,
 | 
						|
           DateTime.Now.AddHours(24), (int)FMNoticeTypeEnum.消息, "DM016");
 | 
						|
 | 
						|
                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);
 | 
						|
            });
 | 
						|
        }
 | 
						|
 | 
						|
        /// <summary>
 | 
						|
        /// 获取
 | 
						|
        /// </summary>
 | 
						|
        /// <param name="filter"></param>
 | 
						|
        /// <returns></returns>
 | 
						|
        [HttpPost, Route("GetEdit")]
 | 
						|
        public JsonActionResult<T_DM_DEVICE_ISSUE> GetEdit([FromBody] KeywordFilter filter)
 | 
						|
        {
 | 
						|
            return SafeExecute(() => {
 | 
						|
                var id = filter.FilterGroup.Rules.FirstOrDefault(t => t.Field == "ID").Value.ToString();
 | 
						|
                if (string.IsNullOrEmpty(id))
 | 
						|
                    this.ThrowError("030017");
 | 
						|
                var result = this.GetEntity<T_DM_DEVICE_ISSUE>(id, new string[] { "Nav_User", "Nav_Department","Nav_Apply","Nav_UserPost","Nav_Details","Nav_Details.Nav_UseUserPost",
 | 
						|
            "Nav_Details.Nav_User","Nav_Details.Nav_Department","Nav_Details.Nav_DeviceBase"
 | 
						|
                });
 | 
						|
                if (result != null && result.Nav_Details.Any())
 | 
						|
                {
 | 
						|
                    if (result.STATUS == PFStandardStatus.Rejected)
 | 
						|
                    {
 | 
						|
                        result.CONTEXT = ApproveCallBackService.RejectContent(result.ID);
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                return result;
 | 
						|
            });
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |