From 479b6cfc60113f692f6f9146bcd7b9231a32b0e8 Mon Sep 17 00:00:00 2001
From: 移动系统liao <liaoxujun@qq.com>
Date: 星期六, 08 二月 2025 09:07:57 +0800
Subject: [PATCH] Merge branch 'cyronghe'

---
 cylsg/cylsg.Application/CyOS/CyOSBaoXiaoZHuGuanController.cs |  255 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 255 insertions(+), 0 deletions(-)

diff --git a/cylsg/cylsg.Application/CyOS/CyOSBaoXiaoZHuGuanController.cs b/cylsg/cylsg.Application/CyOS/CyOSBaoXiaoZHuGuanController.cs
new file mode 100644
index 0000000..39e60fe
--- /dev/null
+++ b/cylsg/cylsg.Application/CyOS/CyOSBaoXiaoZHuGuanController.cs
@@ -0,0 +1,255 @@
+锘縰sing cylsg.Model.ECTEModel;
+using cylsg.Model.utilityViewModel;
+using ECTESTOA;
+using Furion.LinqBuilder;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace cylsg.Application.CyOS
+{
+    /// <summary>
+    /// 鎶ラ攢涓荤鐩稿叧鎺у埗鍣�
+    /// </summary>
+    [Authorize]
+    public class CyOSBaoXiaoZHuGuanController: IDynamicApiController
+    {
+        private readonly IOAServices _OAServices;
+        private readonly ISqlSugarClient _SugarClient;
+        private ECTESTOAPermissions Permissions;
+        public CyOSBaoXiaoZHuGuanController(IOAServices oaservices, ISqlSugarClient sugarClient)
+        {
+            _OAServices = oaservices;
+            _SugarClient = sugarClient.AsTenant().GetConnection("ECTESTOADB");
+        }
+
+
+        /// <summary>
+        ///  鏌ヨ
+        /// </summary>
+        [HttpPost]
+        public async Task<WorekPlandto> getplanelist(SearchOaWorekPlan param)
+        {
+            if (!await CheckRols())
+            {
+                throw Oops.Oh("娌℃湁鏉冮檺");
+            }
+            
+            Expression<Func<OaWorkPlan, bool>> SearchList = (x) => true;
+
+            //宸濆嵃宸ヤ綔鍗�
+            SearchList = SearchList.And(x => x.ApprovalStatus != PlanStatusType.Uncommitted);
+            SearchList = SearchList.And(x => x.MemberId == _OAServices.firmId);
+            SearchList = SearchList.And(x => x.PlanType == 3);
+            SearchList = SearchList.And(x => x.PlanDataType == 17);
+            //SearchList = SearchList.And(x =>  x.ApprovalStatus == PlanStatusType.unApproval);
+            //SearchList = SearchList.And(x =>  x.OaWorkPlanShenpis.Where(y => y.Buzhou == 1 && y.ApprovalStaffId == Permissions.MemberId).Count()<=0);
+            //SearchList = SearchList.And(x => x.DepartId == Permissions.DepartId); 閮ㄩ棬绛涢��
+            if (!string.IsNullOrEmpty(param.StaffName))
+            {
+                SearchList = SearchList.And(x => x.SentStaff.Name.Contains(param.StaffName));
+            }
+            if (param.StaffMemberIdId != null)
+            {
+                SearchList = SearchList.And(x => x.MemberId == param.StaffMemberIdId);
+            }
+            if (param.PlanDataType > 0)
+            {
+                SearchList = SearchList.And(x => x.PlanDataType == param.PlanDataType);
+            }
+            if (param.PlanStartTimeStart != null)
+            {
+                SearchList = SearchList.And(x => x.PlanStartTime > param.PlanStartTimeStart);
+            }
+            if (param.PlanStartTimeEnd != null)
+            {
+                SearchList = SearchList.And(x => x.PlanStartTime <= param.PlanStartTimeEnd.Value.AddDays(1));
+            }
+            //瀹℃壒鐘舵��
+            if (param.ApprovalStatus != null)
+            {
+                if (param.ApprovalStatus == PlanStatusType.Yes)
+                    SearchList = SearchList.And(x => x.ApprovalStatus == param.ApprovalStatus || ((x.OaWorkPlanShenpis.Count(y => y.ApprovalStatus == PlanStatusType.Yes&&y.ApprovalStaffId==Permissions.MemberId && y.Buzhou == 1) >0)));
+                else  if(param.ApprovalStatus == PlanStatusType.No)
+                {
+                    SearchList = SearchList.And(x => x.ApprovalStatus == param.ApprovalStatus );
+                }
+                else
+                {
+                    SearchList= SearchList.And(x=>x.ApprovalStatus== PlanStatusType.unApproval&&(x.OaWorkPlanShenpis.Count(y => y.Buzhou == 1&& y.ApprovalStaffId == Permissions.MemberId) <=0));
+                }
+
+            }
+            //鎶ラ攢鐘舵��
+            if (param.EvaluationStatus != null)
+            {
+                SearchList = SearchList.And(x => x.EvaluationStatus == param.EvaluationStatus);
+            }
+            RefAsync<int> totle = 0;
+
+            //寮哄埗澧炲姞鍛樺伐杩囨护
+
+            var data = await _SugarClient.Queryable<OaWorkPlan>().Includes(x=>x.Depart)
+                    .Includes(x=>x.OaWorkPlanShenpis.Where(y=>y.ApprovalStaffId==Permissions.MemberId&&y.Buzhou==1).ToList())
+                    .Where(SearchList).OrderByDescending(x => x.PlanStartTime).Mapper(
+                    x =>
+                    {
+                        if (x.ApprovalStatus == PlanStatusType.unApproval)
+                        {
+                            var oashenpi = x.OaWorkPlanShenpis?.FirstOrDefault();
+                            if (oashenpi != null)
+                                x.ApprovalStatus = oashenpi.ApprovalStatus;
+                            
+
+                        }
+                            ;
+                    }
+                    ).ToPageListAsync(param.page.PageIndex, param.page.PageSize, totle);
+
+
+            param.page.TotalCount = totle;
+            var sum = await _SugarClient.Queryable<OaWorkPlan>()
+             .Where(SearchList).SumAsync(x => x.PlanMoney);
+            return new WorekPlandto
+
+                {
+                    list = data,
+                    page = param.page,
+                TotalMoney = sum ?? 0
+            };
+           
+
+        }
+
+        /// <summary>
+        ///  鑾峰彇鎶ラ攢鍗曡鎯�
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        [HttpGet]
+        public async Task<OaWorkPlan> GetPlanInfo(int id)
+        {
+            if (!await CheckRols())
+            {
+                throw Oops.Oh("娌℃湁鏉冮檺");
+            }
+            return await _SugarClient.Queryable<OaWorkPlan>().Includes(x => x.OaWorkPlanShenpis.Where(y => y.Buzhou == 1).ToList(), y => y.ApprovalStaff).Includes(x => x.SentStaff).Includes(x => x.Depart).Includes(x => x.WorkPlanAttachments).Where(x=>x.Keyid==id).Mapper(x=>
+            {
+                if (x.ApprovalStatus == PlanStatusType.unApproval)
+                {
+                    var oashenpi = x.OaWorkPlanShenpis?.Where(x=>x.ApprovalStaffId==Permissions.MemberId).FirstOrDefault();
+                    if (oashenpi != null)
+                        x.ApprovalStatus = oashenpi.ApprovalStatus;
+
+
+                }
+                            ;
+            }).FirstAsync();
+        }
+
+        /// <summary>
+        /// 瀹℃壒鏉冮檺
+        /// </summary>       
+        /// <returns></returns>
+         [HttpPost]
+        public async Task<bool> ApprovalPlan(OaWorkPlanShenpi param)
+        {
+            if (param.ApprovalStatus == PlanStatusType.unApproval)
+                throw Oops.Oh("涓嶅彲璁剧疆涓烘湭瀹℃壒鐘舵��");
+
+            if (!await CheckRols())
+            {
+                throw Oops.Oh("娌℃湁鏉冮檺");
+            }
+            var data = await _SugarClient.Queryable<OaWorkPlan>().Includes(x=>x.OaWorkPlanShenpis).Where(x => x.Keyid == param.OA_WorkPlanId).FirstAsync();
+            if (data == null)
+                throw Oops.Oh("娌℃湁鎵惧埌鎶ラ攢鍗�");
+            if (data.ApprovalStatus != null && data.ApprovalStatus != PlanStatusType.unApproval)
+                throw Oops.Oh("鎶ラ攢鍗曞凡缁忔壒澶嶅畬姣�");
+            if(data.ApprovalStatus== PlanStatusType.Uncommitted)
+            {
+                throw Oops.Oh("鎶ラ攢鍗曟湭鎻愪氦涓嶅彲瀹℃壒");
+            }
+            OaWorkPlanShenpi shenpi = data.OaWorkPlanShenpis.Where(x => x.ApprovalStaffId == Permissions.MemberId&&x.Buzhou==1).FirstOrDefault();
+             if (shenpi!=null)
+            {
+                //鑷繁宸茬粡鎵瑰锛屼笉鍙洿鏀�
+                throw Oops.Oh("鎶ラ攢鍗曞凡缁忔壒澶�");
+                //shenpi.ApprovalStatus = PlanStatusType.Yes;
+                //await _SugarClient.Updateable(shenpi).ExecuteCommandAsync();
+            }
+             else
+            {
+    
+
+                data.RewardResult = param.RewardResult;
+                data.PlanContent = param.PlanContent;
+                if (param.PlanMoney > 0 && param.PlanMoney <= data.PlanMoney)
+                    data.PlanMoney = param.PlanMoney;
+
+                await   _SugarClient.AsTenant().BeginTranAsync();
+                try
+                {
+                    if (param.ApprovalStatus == PlanStatusType.No)
+                    {
+                        //褰撴湁浜哄鎵规嫆缁濆悗鐩存帴灏嗙敵璇峰崟璁剧疆涓烘嫆缁濓紝涓嶅湪杩涜鍏朵粬瀹℃牳
+                        data.ApprovalStatus = PlanStatusType.No;
+                        data.ApprovalTime = DateTime.Now;
+                        data.LastUpdateTime = DateTime.Now;
+                        data.Operator = Permissions.Name;
+                       await  _SugarClient.Updateable(data).ExecuteCommandAsync();
+
+                    }
+
+                    shenpi = new OaWorkPlanShenpi()
+                    {
+                        ApprovalStaffId = Permissions.MemberId,
+                        ApprovalContent = param.ApprovalContent,
+                        ApprovalStatus = param.ApprovalStatus,
+                        ApprovalTime = DateTime.Now,
+                        Buzhou = 1,
+                        CreateTime = DateTime.Now,
+                        Operator = Permissions.Name,
+                        OA_WorkPlanId = param.OA_WorkPlanId,
+
+                    };
+                    await _SugarClient.Insertable(shenpi).ExecuteCommandAsync();
+
+                    await _SugarClient.AsTenant().CommitTranAsync();
+                }
+                catch (Exception)
+                {
+                    await _SugarClient.AsTenant().RollbackTranAsync();
+                    throw;
+                }
+             
+            }
+            return true;
+        }
+
+        /// <summary>
+        /// 鍒ゆ柇鏄惁鍏锋湁鏉冮檺
+        /// </summary>
+        /// <returns></returns>
+        private async Task<bool> CheckRols()
+        {
+            var pr = await _OAServices.GetOAPermissions();
+            Permissions = pr;
+            if (pr != null && pr.MemberId != null)
+            {
+
+                if ( pr.BF_IsBaoxiaozhuguan)
+                    return true;
+                else return false;
+
+            }
+            else
+                return false;
+        }
+    }
+
+   
+}

--
Gitblit v1.9.1