New file |
| | |
| | | using 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; |
| | | } |
| | | } |
| | | |
| | | |
| | | } |