| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766 | using AutoMapper;using Microsoft.Extensions.Logging;using Serilog;using Newtonsoft.Json;using OASystem.Domain;using OASystem.Domain.Dtos;using OASystem.Domain.Dtos.Financial;using OASystem.Domain.Dtos.PersonnelModule;using OASystem.Domain.Entities.Financial;using OASystem.Domain.Entities.PersonnelModule;using OASystem.Domain.ViewModels.Financial;using OASystem.Infrastructure.Repositories.PersonnelModule;using OASystem.Infrastructure.Repositories.System;namespace OASystem.Infrastructure.Repositories.Financial{    /// <summary>    /// 财务 - 日付申请    /// </summary>    public class DailyFeePaymentRepository : BaseRepository<Fin_DailyFeePayment, Fin_DailyFeePaymentView>    {        private readonly IMapper _mapper;        private readonly SetDataTypeRepository _setDataTypeRep;        private readonly UsersRepository _UsersRep;        private readonly CompanyRepository _CompanyRep;        private readonly GoodsRepository _goodsRep;        private readonly ILogger<DailyFeePaymentRepository> _logger;        /// <summary>        ///         /// </summary>        /// <param name="sqlSugar"></param>        /// <param name="mapper"></param>        /// <param name="setDataTypeRep"></param>        /// <param name="usersRep"></param>        /// <param name="companyRep"></param>        /// <param name="goodsRep"></param>        /// <param name="logger"></param>        public DailyFeePaymentRepository(SqlSugarClient sqlSugar,            IMapper mapper,            SetDataTypeRepository setDataTypeRep,            UsersRepository usersRep,            CompanyRepository companyRep,            GoodsRepository goodsRep,            ILogger<DailyFeePaymentRepository> logger)            : base(sqlSugar)        {            _mapper = mapper;            _setDataTypeRep = setDataTypeRep;            _UsersRep = usersRep;            _CompanyRep = companyRep;            _goodsRep = goodsRep;            _logger = logger;        }        /// <summary>        /// 日付申请查询 使用的数据源        /// </summary>        /// <param name="dto"></param>        /// <returns></returns>        public async Task<Result> GetPagePriceTypeData(PortDtoBase dto, int currUserId = 0)        {            Result result = new Result() { Code = -2 };            dynamic? DailyFeePaymentList = null;            var setTypeData = _setDataTypeRep.QueryDto<Sys_SetDataType, Fin_DailyFeePaymentPagePriceTypeView>().ToList();            var setData = _setDataTypeRep.QueryDto<Sys_SetData, Fin_DailyFeePaymentPagePriceSubTypeView>().ToList();            //48人员费用  49办公费用 50 销售费用 51 其他费用 55 大运会            var typeIds = new List<int>() {                48, //人员费用                49, //办公费用                50, //销售费用                51, //其他费用                55, //大运会                90, //各部门基础固定费用明细                104, //团组费用                116, //物资采购            };            var priceTypeData = setTypeData.Where(s => typeIds.Contains(s.Id)).ToList();            var priceSubTypeData = setData.Where(s => typeIds.Contains(s.STid)).ToList();            //var isEnable = false;            //员工姓名列表            var userData = _sqlSugar.Queryable<Sys_Users>()                .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)                .LeftJoin<Sys_JobPost>((u, d, jp) => u.JobPostId == jp.Id)                .Where((u, d, jp) => u.IsDel == 0)                .Select((u, d, jp) => new                {                    u.Id,                    u.CnName,                    u.DepId,                    d.DepName,                    u.JobPostId,                    jp.JobName                })                .ToList();            //1 经理职位 查看该部门下所有人员            if (currUserId > 0)            {                //42                var auditUserIds = _sqlSugar.Queryable<Sys_UserAuthority>().Where(x => x.IsDel == 0 && x.SmId == 42 && x.FId == 12).Select(x => x.UId).ToList();                if (!auditUserIds.Contains(currUserId))                {                    var screenWheres = new List<string>() { "经理", "主管" };                    var userInfo = userData.Find(x => x.Id == currUserId && screenWheres.Contains(x.JobName));                    if (userInfo != null)                    {                        userData = userData.Where(x => x.DepName.Equals(userInfo.DepName)).ToList();                    }                    else                    {                        userData = userData.Where(x => x.Id == currUserId).ToList();                    }                }                else                {                    userData.Insert(0, new { Id = -1, CnName = "全部", DepId = 0, DepName = "", JobPostId = 0, JobName = "" });                }            }            var userData1 = userData.Select(x => new { x.Id, x.CnName }).ToList();            //62 公转 63 私转                    var feeMarkTypeData = setTypeData.Where(s => s.Id == 62 || s.Id == 63).ToList();            var feeMarkSubTypeData = setData.Where(s => s.STid == 62 || s.STid == 63).ToList();            var companyNameData = await _CompanyRep.GetCompanyNameData();            //审核状态            var auditStatusData = new List<dynamic>()            {                new { Id = -1, Name = "全部" },                new { Id = 0, Name = "未审核" },                new { Id = 1, Name = "已审核" },                new { Id = 2, Name = "审核未通过" },                new { Id = 3, Name = "自动审核" }            };            if (dto.PortType == 1) //web            {                DailyFeePaymentList = new                {                    FeeTypeData = priceTypeData,                    FeeSubTypeData = priceSubTypeData,                    UserNameData = userData1,                    FeeMarkTypeData = feeMarkTypeData,                    FeeMarkSubTypeData = feeMarkSubTypeData,                    CompanyNameData = companyNameData.Data,                    AuditStatusData = auditStatusData                };            }            else if (dto.PortType == 2) //安卓            {                DailyFeePaymentList = new                {                    UserNameData = userData1,                    FeeTypeData = priceTypeData,                    FeeTypeSubData = priceSubTypeData                };            }            result.Code = 0;            result.Msg = "查询成功!";            result.Data = DailyFeePaymentList;            return result;        }        /// <summary>        /// 总经理自动审核通过类型         /// 90 Parent 各部门基础固定费用明细          /// 104 Parent 团组费用        /// 672 Sub 办公费用-信息部申请费用        /// 1433 Sub 团组/会务储备物资采购        /// 1451 Sub 会务部报销费用        /// </summary>        /// <param name="typeId"></param>        /// <returns></returns>        public async Task<bool> GMAutoApprovalType(int typeId)        {            if (typeId < 1) return false;            var parentIds = new List<int>()                {                    90,  // 各部门基础固定费用明细                    104, // 团组费用                };            var subIds = new List<int>()                {                    672,  //办公费用-信息部申请费用                    1433, //团组/会务储备物资采购                    1451, //会务部报销费用                };            var parentTypeDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && parentIds.Contains(x.STid)).ToListAsync();            var subTypeDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && subIds.Contains(x.Id)).ToListAsync();            var typeDatas = new List<Sys_SetData>();            if (parentTypeDatas.Any()) typeDatas.AddRange(parentTypeDatas);            if (subTypeDatas.Any()) typeDatas.AddRange(subTypeDatas);            if (typeDatas.Any(x => x.Id == typeId)) return true;            return false;        }        /// <summary>        /// 日付申请查询 使用的数据源        /// </summary>        /// <param name="dto"></param>        /// <returns></returns>        public async Task<Result> GetPriceTypeAddData(PortDtoBase dto)        {            Result result = new() { Code = -2 };            dynamic? DailyFeePaymentList = null;            var setTypeData = _setDataTypeRep.QueryDto<Sys_SetDataType, Fin_DailyFeePaymentPagePriceTypeView>().ToList();            var setData = _setDataTypeRep.QueryDto<Sys_SetData, Fin_DailyFeePaymentPagePriceSubTypeView>().ToList();            //48人员费用  49办公费用 50 销售费用 51 其他费用 55 大运会            var priceTypeData = setTypeData.Where(s => s.Id == 48 || s.Id == 49 || s.Id == 50 || s.Id == 51 || s.Id == 55).ToList();            var priceSubTypeData = setData.Where(s => s.STid == 48 || s.STid == 49 || s.STid == 50 || s.STid == 51 || s.STid == 55).ToList();            //员工姓名列表            var userNameData = await _UsersRep.GetUserNameList(dto.PortType);            //62 公转 63 私转            var feeMarkTypeData = setTypeData.Where(s => s.Id == 62 || s.Id == 63).ToList();            var feeMarkSubTypeData = setData.Where(s => s.STid == 62 || s.STid == 63).ToList();            var companyNameData = await _CompanyRep.GetCompanyNameData();            if (dto.PortType == 1) //web            {                DailyFeePaymentList = new Fin_DailyFeePaymentPagePriceTypeDataView                {                    FeeTypeData = priceTypeData,                    FeeSubTypeData = priceSubTypeData,                    UserNameData = userNameData.Data,                    FeeMarkTypeData = feeMarkTypeData,                    FeeMarkSubTypeData = feeMarkSubTypeData,                    CompanyNameData = companyNameData.Data                };            }            else if (dto.PortType == 2) //安卓            {                DailyFeePaymentList = new                {                    CompanyNameData = companyNameData.Data,                    FeeTypeData = feeMarkTypeData,                    FeeTypeSubData = feeMarkSubTypeData                };            }            result.Code = 0;            result.Msg = "查询成功!";            result.Data = DailyFeePaymentList;            return result;        }        /// <summary>        /// 日付申请 page 查询        /// </summary>        /// <param name="dto"></param>        /// <returns></returns>        public async Task<Result> GetPageSearchAll(PageDailyFeePaymentDto dto)        {            Result result = new Result() { Code = -2 };            ListViewBase<Fin_DailyFeePaymentPageListView> dailyFeePaymentPageList = new ListViewBase<Fin_DailyFeePaymentPageListView>()            {                ReceiveDt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")            };            #region sql条件处理            string sqlWhere = "";            if (dto.CompanyId != -1)  //公司                sqlWhere += string.Format(" And dfp.CompanyId = {0}", dto.CompanyId);            if (dto.FinancialAuditStatus != -1) //财务审核                sqlWhere += string.Format(" And dfp.FAudit = {0}", dto.FinancialAuditStatus);            if (dto.ManagerAuditStatus != -1)   //总经理审核                sqlWhere += string.Format(" And dfp.MAudit = {0}", dto.ManagerAuditStatus);            if (dto.IsPaySign != -1) //付款状态            {                sqlWhere += string.Format(" And dfp.IsPay = {0}", dto.IsPaySign);            }            if (dto.FeeTypeId != -1)   //费用类型            {                if (dto.FeeSubTypeId != -1) //子类处理                {                    sqlWhere += string.Format(" And dfp.PriceTypeId = {0}", dto.FeeSubTypeId);                }                else                {                    var setData = _setDataTypeRep.QueryDto<Sys_SetData, SetDataView>(s => s.STid == dto.FeeTypeId).ToList();                    if (setData.Count > 0)                    {                        string setDataIds = string.Join(",", setData.Select(x => x.Id).ToList());                        sqlWhere += string.Format(" And dfp.PriceTypeId In ({0})", setDataIds);                    }                }            }            if (!string.IsNullOrEmpty(dto.FeeDesc))                sqlWhere += string.Format(" And dfp.Instructions Like '%{0}%'", dto.FeeDesc);            if (dto.CreateUserId != -1)                sqlWhere += string.Format(" And dfp.CreateUserId = {0}", dto.CreateUserId);            int startIndex = (dto.PageIndex - 1) * dto.PageSize + 1;            int endIndex = startIndex + dto.PageSize - 1;            string sqlPage = string.Format(@"Select * From (	                                                Select row_number() over (order by dfp.Id Desc) as RowNumber,                                                    dfp.Id,dfp.CompanyId,c.CompanyName,dfp.Instructions,dfp.SumPrice,                                                    dfp.CreateUserId,u.CnName CreateUser,dfp.CreateTime,dfp.FAudit,dfp.MAudit,                                                    dfp.PriceTypeId,dfp.IsPay                                                From Fin_DailyFeePayment dfp                                                Inner Join Sys_Company c On dfp.CompanyId = c.Id                                                Left Join Sys_Users u On dfp.CreateUserId = u.Id                                                Where dfp.IsDel=0 {0}                                                 ) temp Where RowNumber Between {1} and {2}", sqlWhere, startIndex, endIndex);            string sqlCount = string.Format(@"Select COUNT(1) as Count From (	                                                Select dfp.Id,dfp.CompanyId,c.CompanyName,dfp.Instructions,dfp.SumPrice,                                                       dfp.CreateUserId,u.CnName CreateUser,dfp.CreateTime,dfp.FAudit,dfp.MAudit,                                                       dfp.PriceTypeId                                                From Fin_DailyFeePayment dfp                                                Inner Join Sys_Company c On dfp.CompanyId = c.Id                                                Left Join Sys_Users u On dfp.CreateUserId = u.Id                                                Where dfp.IsDel=0 {0}                                                 ) temp ", sqlWhere);            #endregion            if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //web            {                //Fin_DailyFeePaymentPageCount                var dailyFeePaymentCount = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentPageCount>(sqlCount).FirstAsync();                var DailyFeePaymentData = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentPageListView>(sqlPage).ToListAsync();                int totalCount = dailyFeePaymentCount.Count;                dailyFeePaymentPageList = new ListViewBase<Fin_DailyFeePaymentPageListView>                {                    CurrPageIndex = dto.PageIndex,                    CurrPageSize = dto.PageSize,                    DataCount = totalCount,                    DataList = DailyFeePaymentData                };            }            result.Code = 0;            result.Msg = "查询成功!";            result.Data = dailyFeePaymentPageList;            return result;        }        /// <summary>        /// 日付申请 single 查询 By Id        /// </summary>        /// <param name="dto"></param>        /// <returns></returns>        public async Task<Result> GetSearchById(SearchDailyFeePaymentDto dto)        {            Result result = new Result() { Code = -2 };            if (dto.PortType == 1) //web            {                Fin_DailyFeePaymentInfolView feeData = new Fin_DailyFeePaymentInfolView();                string feeSql = string.Format(@"Select * From Fin_DailyFeePayment                                                 Where IsDel=0 And Id = {0} ", dto.Id);                feeData = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentInfolView>(feeSql).FirstAsync();                string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent                                                         Where IsDel=0 And DFPId = {0} ", dto.Id);                feeData.FeeContents = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToListAsync();                result.Code = 0;                result.Msg = "查询成功!";                result.Data = feeData;            }            else if (dto.PortType == 2 || dto.PortType == 3)  //android And ios            {                Fin_DailyFeePaymentInfoAndroidlView feeData = new Fin_DailyFeePaymentInfoAndroidlView();                string feeSql = string.Format(@"Select * From Fin_DailyFeePayment                                                 Where IsDel=0 And Id = {0} ", dto.Id);                feeData = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentInfoAndroidlView>(feeSql).FirstAsync();                //feeData.TransferTypeId = feeData.TransferTypeId == 0 ? 62 : feeData.TransferTypeId == 1 ? 63 : 0;                string feeContentSql = string.Format(@"Select * From Fin_DailyFeePaymentContent                                                         Where IsDel=0 And DFPId = {0} ", dto.Id);                feeData.FeeContents = await _sqlSugar.SqlQueryable<Fin_DailyFeePaymentContentInfolView>(feeContentSql).ToListAsync();                result.Code = 0;                result.Msg = "查询成功!";                result.Data = feeData;            }            return result;        }        /// <summary>        /// 日付申请 添加        /// </summary>        /// <param name="dto"></param>        /// <returns></returns>        public async Task<Result> Add(AddDailyFeePaymentDto dto)        {            Result result = new Result() { Code = -2 };            _sqlSugar.BeginTran();            var _fee = _mapper.Map<Fin_DailyFeePayment>(dto);            _fee.CreateUserId = dto.UserId;            _fee.GroupId = dto.GroupId;            //自动审核验证            var auditPer = await GMAutoApprovalType(dto.PriceTypeId);            var priceTypeInfo = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync(x => x.IsDel == 0 && x.Id == dto.PriceTypeId);            if (auditPer)            {                _fee.MAudit = 3;                _fee.MAuditDate = DateTime.Now;            }            int? feeId = await _sqlSugar.Insertable(_fee).ExecuteReturnIdentityAsync();            if (dto.FeeContents.Any())            {                var _feeContents = _mapper.Map<List<Fin_DailyFeePaymentContent>>(dto.FeeContents);                foreach (var item in _feeContents)                {                    item.DFPId = feeId == null ? -1 : Convert.ToInt32(feeId);                    item.CreateUserId = dto.UserId;                }                await _sqlSugar.Insertable(_feeContents).ExecuteCommandAsync();            }            _sqlSugar.CommitTran();            result.Code = 0;            var data = new { dailyId = feeId, sign = 1 };            result.Data = data;            return result;        }        /// <summary>        /// 日付申请 编辑        /// </summary>        /// <param name="dto"></param>        /// <returns></returns>        public async Task<Result> Edit(EditDailyFeePaymentDto dto)        {            Result result = new Result() { Code = -2 };            //自动审核验证            var auditPer = await GMAutoApprovalType(dto.PriceTypeId);            #region 已审核的数据不可编辑            var dailyFeeInfo = await _sqlSugar.Queryable<Fin_DailyFeePayment>().Where(it => it.Id == dto.Id && it.IsDel == 0).FirstAsync();            if (dailyFeeInfo != null)            {                var auditIds = new List<int>() { 1, 3 };                if (auditIds.Contains(dailyFeeInfo.FAudit) || auditIds.Contains(dailyFeeInfo.MAudit))                {                    if (auditPer)                    {                        if (dailyFeeInfo.IsPay == 1)                        {                            result.Msg = "该笔费用已付款,不可修改!";                            return result;                        }                    }                    else                    {                        result.Msg = "审核已通过,不可修改!";                        return result;                    }                }            }            #endregion            _sqlSugar.BeginTran();            try            {                Fin_DailyFeePayment _fee = _mapper.Map<Fin_DailyFeePayment>(dto);                _fee.CreateUserId = dto.UserId;                int? editFeeStatus = await _sqlSugar.Updateable<Fin_DailyFeePayment>()                    .SetColumns(a => new Fin_DailyFeePayment                    {                        Instructions = dto.Instructions,                        SumPrice = dto.SumPrice,                        TransferTypeId = dto.TransferTypeId,                        PriceTypeId = dto.PriceTypeId,                        CompanyId = dto.CompanyId,                        GroupId = dto.GroupId,                    })                    .SetColumnsIF(auditPer, a => a.MAudit == 3)                    .SetColumnsIF(auditPer, a => a.MAuditDate == DateTime.Now)                    .Where(a => a.Id == dto.Id)                    .ExecuteCommandAsync();                var _feeContents = _mapper.Map<List<Fin_DailyFeePaymentContent>>(dto.FeeContents);                await _sqlSugar.Updateable<Fin_DailyFeePaymentContent>()                    .Where(a => a.DFPId == _fee.Id)                    .SetColumns(a => new Fin_DailyFeePaymentContent                    {                        IsDel = 1,                        DeleteUserId = _fee.CreateUserId,                        DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),                    })                    .ExecuteCommandAsync();                if (_feeContents.Any())                {                    foreach (var item in _feeContents)                    {                        item.DFPId = _fee.Id;                        item.CreateUserId = dto.UserId;                    }                    await _sqlSugar.Insertable(_feeContents).ExecuteCommandAsync();                }                _sqlSugar.CommitTran();                result.Code = 0;                var data = new { dailyId = dto.Id, sign = 2 };                result.Data = data;            }            catch (Exception ex)            {                _sqlSugar.RollbackTran();                result.Msg = ex.Message;            }            return result;        }        /// <summary>        /// 日付申请 删除        /// </summary>        /// <param name="dto"></param>        /// <returns></returns>        public async Task<Result> Del(DelDailyFeePaymentDto dto)        {            Result result = new Result() { Code = -2 };            int? delFeeStatus = await _sqlSugar.Updateable<Fin_DailyFeePayment>()                .Where(a => a.Id == dto.Id)                .SetColumns(a => new Fin_DailyFeePayment                {                    IsDel = 1,                    DeleteUserId = dto.UserId,                    DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),                }).ExecuteCommandAsync();            result.Code = 0;            return result;        }        /// <summary>        /// 日付申请 审核        /// </summary>        /// <param name="dto"></param>        /// <returns></returns>        public async Task<Result> DailyPaymentAudit(DP_AuditStatusDto dto)        {            Result result = new Result() { Code = -2 };            if (dto.AuditType == 1) //财务审核            {                int auditStatus = await _sqlSugar.Updateable<Fin_DailyFeePayment>()                    .Where(a => a.Id == dto.Id)                    .SetColumns(a => new Fin_DailyFeePayment                    {                        FAudit = dto.AuditStatus,                        FAuditDate = DateTime.Now,                    }).ExecuteCommandAsync();                if (auditStatus > 0) result.Code = 0;                else result.Msg = "财务审核操作失败";            }            else if (dto.AuditType == 2) //总经理            {                int auditStatus = await _sqlSugar.Updateable<Fin_DailyFeePayment>()                    .Where(a => a.Id == dto.Id)                    .SetColumns(a => new Fin_DailyFeePayment                    {                        MAudit = dto.AuditStatus,                        MAuditDate = DateTime.Now,                    }).ExecuteCommandAsync();                if (auditStatus > 0) result.Code = 0;                else result.Msg = "总经理审核操作失败";            }            #region 审核完全通过 指定类型 向物资添加信息            //费用类型            var feeTypeIds = new List<int>() {                1433,    //团组/会务储备物资采购                1435,    //公司固定物资采购            };            //审核状态集合            var auditStatuses = new List<int>() {                1,  //审核通过                3,  //自动审核             };            var dailyInfo = await _sqlSugar.Queryable<Fin_DailyFeePayment>()                .FirstAsync(x => x.Id == dto.Id && x.IsDel == 0 &&                                 auditStatuses.Contains(x.MAudit) &&                                 auditStatuses.Contains(x.FAudit) &&                                 feeTypeIds.Contains(x.PriceTypeId));            if (dailyInfo != null)            {                //执行物资添加、入库、关联信息操作                var linkOpRes = await ApplicationLinkGoodsAddAsync(dailyInfo.Id);                // Updated the logging statement to ensure consistent message templates                _logger.LogInformation("【日付申请单关联物品】请求参数:{DailyInfoId}\r\n返回参数:{LinkOpResData}\r\n返回消息:{LinkOpResMsg}",                    dailyInfo.Id,                    JsonConvert.SerializeObject(linkOpRes.Data),                    linkOpRes.Msg);            }            #endregion            return result;        }        /// <summary>        /// 购买申请单关联物品        /// </summary>        /// <param name="applicatId">日付申请Id</param>        /// <returns></returns>        public async Task<JsonView> ApplicationLinkGoodsAddAsync(int applicatId)        {            if (applicatId < 1) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = $"日付申请单ID不正确!" };            //if (currUserId < 1) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = $"当前登陆人ID不正确!" };            var dailyInfoRes = await GetSearchById(new Domain.Dtos.Financial.SearchDailyFeePaymentDto() { PortType = 1, Id = applicatId });            if (dailyInfoRes.Code != 0) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = dailyInfoRes?.Msg ?? "日付申请单信息不存在!" };            string dynamicJson = JsonConvert.SerializeObject(dailyInfoRes.Data);            Fin_DailyFeePaymentInfolView dailyInfo = JsonConvert.DeserializeObject<Fin_DailyFeePaymentInfolView>(dynamicJson);            if (dailyInfo == null || !dailyInfo.FeeContents.Any())            {                return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = $"付申请单信息不存在!!" };            }            //审核验证 总经理 && 财务 审核通过 才可进行 物品添加、入库、关联信息 操作            if (dailyInfo.MAudit == 0 || dailyInfo.MAudit == 2 || dailyInfo.FAudit == 0 || dailyInfo.FAudit == 2)            {                return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = $"审核未通过,不可进行物资关联信息!" };            }            _sqlSugar.BeginTran();            //1.验证物品信息            var currGoodsTypeId = dailyInfo.PriceTypeId switch            {                1433 => 1424, //团组物资                1435 => 1426, //固定资产                _ => 0            };            var paras = new List<dynamic>();            foreach (var item in dailyInfo.FeeContents)            {                var goodsInfo = await _sqlSugar.Queryable<Pm_GoodsInfo>().FirstAsync(x => x.Name.Equals(item.PriceName) && x.IsDel == 0)                    ?? new Pm_GoodsInfo()                    {                        Id = 0,                        Name = item.PriceName,                        Type = currGoodsTypeId,                        Unit = "-",                        CreateUserId = dailyInfo.CreateUserId,                        Remark = $"日付申请模块新增物品信息(需自行更改单位):\n{item.Remark}",                    };                //物品不存在执行添加                if (goodsInfo.Id == 0)                {                    goodsInfo.Id = await _sqlSugar.Insertable(goodsInfo).ExecuteReturnIdentityAsync();                    if (goodsInfo.Id < 1)                    {                        _sqlSugar.RollbackTran();                        return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = $"物品添加失败!" };                    }                }                //执行入库信息添加                var storageRes = await _goodsRep.GoodsStorageOp(new GoodsStorageOpDto()                {                    GoodsId = goodsInfo.Id,                    Quantity = item.Quantity,                    UnitPrice = item.Price,                    TotalPrice = item.ItemTotal,                    SupplierName = "-",                    SupplierTel = "-",                    SupplierAddress = "-",                    SupplierSource = "-",                    StorageUserId = 374, //固定前台ID为入库人                    StorageTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),                    Remark = $"日付申请模块新增物品入库信息:{item.Remark}",                }, 374);                if (storageRes.Code != StatusCodes.Status200OK)                {                    _sqlSugar.RollbackTran();                    return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = $"物品入库信息添加失败!" };                }                var storageId = Convert.ToInt32(storageRes.Data.GetType().GetProperty("sign").GetValue(storageRes.Data, null) ?? 0);                //执行关联表添加                var addStatus = await _sqlSugar.Insertable(new Fin_ApplicationLinkGoods(                    id: 0,                    dailyId: dailyInfo.Id,                    goodsId: goodsInfo.Id,                    goodsStorageId: storageId,                    remark: "",                    userId: dailyInfo.CreateUserId                    )).ExecuteCommandAsync();                if (addStatus < 1)                {                    _sqlSugar.RollbackTran();                    return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = $"日付、物品入库信息关联信息添加失败!" };                }                paras.Add(new                {                    dailyId = dailyInfo.Id,                    goodsId = goodsInfo.Id,                    GoodsStorageId = storageId,                    LinkTableId = addStatus                });            }            _sqlSugar.CommitTran();            return new JsonView() { Code = StatusCodes.Status200OK, Data = paras, Msg = $"操作成功!" };        }    }}
 |