123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
-
- using AutoMapper;
- using OASystem.Domain;
- using OASystem.Domain.Dtos.System;
- using OASystem.Domain.Dtos.UserDto;
- using OASystem.Domain.Entities.Financial;
- using OASystem.Domain.Entities.Resource;
- using OASystem.Domain.Entities.System;
- using OASystem.Domain.ViewModels.Groups;
- using OASystem.Domain.ViewModels.System;
- using OASystem.Infrastructure.Tools;
- namespace OASystem.Infrastructure.Repositories.System
- {
- public class SetDataRepository : BaseRepository<Sys_SetData, SetDataView>
- {
- private readonly IMapper _mapper;
- public SetDataRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
- {
- _mapper = mapper;
- }
- /// <summary>
- /// 获取所有系统模块
- /// </summary>
- /// <param name="_SetData"></param>
- /// <returns></returns>
- public async Task<Result> GetSySDefultModule()
- {
- Result result = new Result();
- string sql = "select * from Sys_SetData where STid = 5 and isdel = 0";
- var DBdata = await GetListBySqlWithNolockAsync(sql);
- if (DBdata == null || DBdata.Count == 0)
- {
- return result;
- }
- result.Data = DBdata.Select(x=> new SetDataView
- {
- Name = x.Name,
- STid = x.STid,
- Id = x.Id,
- });
- result.Code = 0;
- result.Msg = "成功!";
- return result;
- }
- /// <summary>
- /// 获取类型Data By STId
- /// </summary>
- /// <param name="_SetData"></param>
- /// <returns></returns>
- public async Task<Result> GetSetDataBySTId(SetDataRepository _SetData,int stId)
- {
- Result result = new Result();
- string sql = string.Format(@"select * from Sys_SetData where STid = {0} and isdel = 0",stId);
- var DBdata = await _SetData.GetListBySqlWithNolockAsync(sql);
- if (DBdata == null || DBdata.Count == 0)
- {
- return result;
- }
- result.Data = DBdata.Select(x => new SetDataInfoView
- {
- Name = x.Name,
- Id = x.Id,
- Remark = x.Remark,
- });
- result.Code = 0;
- result.Msg = "成功!";
- return result;
- }
- public async Task<Result> GetSetDataAndPageInfoBySTId(int stId = 5)
- {
- Result result = new Result();
- List<SetDataAndPageInfoView> ViewList = _sqlSugar.SqlQueryable<SetDataAndPageInfoView>($@"
- select a.id as modulid,a.Name as modulName,a.STid,a.Remark as modulRemark,
- b.Id as pageid, b.Name as pageName, b.IsEnable as PageIsEnable ,b.phoneIsEnable as PagePhoneIsEnable,b.SystemMenuCode,b.webUrl,b.androidUrl,
- b.iosUrl,b.icon ,b.Remark as PageRemark
- from Sys_SetData a , Sys_SystemMenuPermission b where STid = {stId}
- and a.isdel = 0 and b.Mid = a.Id and b.IsDel = 0
- ").ToList();
- result.Data = ViewList;
- result.Code = 0;
- result.Msg = "成功!";
- if (ViewList == null || ViewList.Count == 0)
- {
- result.Msg = "无数据!";
- result.Code = -1;
- }
- return result;
- }
- public async Task<Result> QuerySetData(SetDataIDto dto)
- {
- Result result = new Result() { Code = -2, Msg = "未知错误" };
- try
- {
- string sqlWhere = string.Empty;
- if (dto.STid!=0)
- {
- sqlWhere += string.Format(@" And s2.STid ={0}=", dto.STid);
- }
- sqlWhere += string.Format(@" And s1.IsDel={0} And s2.IsDel={0}", 0);
- if (!string.IsNullOrEmpty(sqlWhere.Trim()))
- {
- Regex r = new Regex("And");
- sqlWhere = r.Replace(sqlWhere, "Where", 1);
- }
- if (dto.PortType == 1)
- {
- string sql = string.Format(@"select s2.*,s1.Name as 'StName',u.CnName from Sys_setDataType s1 left join Sys_SetData s2 on s1.Id=s2.STid left join Sys_Users u on s2.CreateUserId=u.Id {0}", sqlWhere);
- List<SetDataIView> SetData = await _sqlSugar.SqlQueryable<SetDataIView>(sql).ToListAsync();
- if (SetData.Count == 0)
- {
- return result = new Result() { Code = -1, Msg = "暂无数据" };
- }
- SetData = SetData.OrderByDescending(x => x.CreateTime).ToList();
- if (dto.PageSize == 0 && dto.PageIndex == 0)
- {
- return result = new Result()
- {
- Code = 0,
- Msg = "查询成功",
- Data = SetData,
- };
- }
- else
- {
- int count = SetData.Count;
- float totalPage = (float)count / dto.PageSize;//总页数
- if (totalPage == 0) totalPage = 1;
- else totalPage = (int)Math.Ceiling((double)totalPage);
- List<SetDataIView> _SetData = new List<SetDataIView>();
- for (int i = 0; i < dto.PageSize; i++)
- {
- var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
- if (RowIndex < SetData.Count)
- {
- _SetData.Add(SetData[RowIndex]);
- }
- else
- {
- break;
- }
- }
- return result = new Result()
- {
- Code = 0,
- Msg = "查询成功",
- Data = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = _SetData },
- };
- }
- }
- else if (dto.PortType == 2)
- {
- string sql = string.Format(@"select s2.*,s1.Name as 'StName' from Sys_setDataType s1 left join Sys_SetData s2 on s1.Id=s2.STid {0}", sqlWhere);
- List<SetDataIView> SetData = await _sqlSugar.SqlQueryable<SetDataIView>(sql).ToListAsync();
- if (SetData.Count == 0)
- {
- return result = new Result() { Code = -1, Msg = "暂无数据" };
- }
- SetData = SetData.OrderByDescending(x => x.CreateTime).ToList();
- if (dto.PageSize == 0 && dto.PageIndex == 0)
- {
- return result = new Result()
- {
- Code = 0,
- Msg = "查询成功",
- Data = SetData,
- };
- }
- else
- {
- int count = SetData.Count;
- float totalPage = (float)count / dto.PageSize;//总页数
- if (totalPage == 0) totalPage = 1;
- else totalPage = (int)Math.Ceiling((double)totalPage);
- List<SetDataIView> _SetData = new List<SetDataIView>();
- for (int i = 0; i < dto.PageSize; i++)
- {
- var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
- if (RowIndex < SetData.Count)
- {
- _SetData.Add(SetData[RowIndex]);
- }
- else
- {
- break;
- }
- }
- return result = new Result()
- {
- Code = 0,
- Msg = "查询成功",
- Data = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = _SetData },
- };
- }
- }
- else
- {
- return result = new Result() { Code = -2, Msg = "请传入PortType参数!1:Web,2:Android,3:IOS" };
- }
- }
- catch (Exception)
- {
- return result;
- throw;
- }
- }
- public async Task<Result> OperationSetData(OperationSetDataDto dto)
- {
- Result result = new Result() { Code = -2, Msg = "未知错误" };
- try
- {
- if (dto.Status == 1)//添加
- {
- string selectSql = string.Format(@"select * from Sys_SetData where Name='{0}' and IsDel='{1}'"
- , dto.Name, 0);
- var SetData = await _sqlSugar.SqlQueryable<Sys_SetData>(selectSql).FirstAsync();//查询是否存在
- if (SetData != null)
- {
- return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
- }
- else//不存在,可添加
- {
- Sys_SetData _SetData = _mapper.Map<Sys_SetData>(dto);
- int id = await AddAsyncReturnId(_SetData);
- if (id == 0)
- {
- return result = new Result() { Code = -1, Msg = "添加失败!" };
- }
- result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
- }
- }
- else if (dto.Status == 2)//修改
- {
- bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Sys_SetData
- {
- Name = dto.Name,
- STid = dto.STid,
- Remark = dto.Remark,
- });
- if (!res)
- {
- return result = new Result() { Code = -1, Msg = "修改失败!" };
- }
- result = new Result() { Code = 0, Msg = "修改成功!" };
- }
- else
- {
- return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
- }
- }
- catch (Exception ex)
- {
- return result = new Result() { Code = -2, Msg = "程序错误!" };
- }
- return result;
- }
- public async Task<Result> PostCurrencyByDiid(int diId,int CId, int currencyId)
- {
- if (diId==0)
- {
- return new Result() { Code = -1, Msg = "请传入团组Id!" };
- }
- if (CId == 0)
- {
- return new Result() { Code = -1, Msg = "请传入类型Id!" };
- }
- if (currencyId == 0)
- {
- return new Result() { Code = -1, Msg = "请传入币种Id!" };
- }
- Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == diId && a.IsDel == 0 && a.CTable == CId);
- List<CurrencyInfo> currencyInfos = new List<CurrencyInfo>();
- CurrencyInfo CurrencyRate = new CurrencyInfo();
- try
- {
- if (_TeamRate != null)
- {
- Sys_SetData _SetData = _sqlSugar.Queryable<Sys_SetData>().First(a => a.IsDel == 0 && a.Id == currencyId);
- if (_SetData != null)
- {
- currencyInfos = CommonFun.GetCurrencyChinaToList(_TeamRate.Remark);
- CurrencyRate = currencyInfos.FirstOrDefault(a => a.CurrencyCode == _SetData.Name);
- if (CurrencyRate!=null)
- {
- return new Result() { Code = 0, Msg = "查询成功!", Data = CurrencyRate };
- }
- else
- {
- return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
- }
-
- }
- else
- {
- return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
- }
-
- }
- else
- {
- return new Result() { Code = -1, Msg = "暂无团组汇率,请前往设置!", Data = CurrencyRate };
- }
- }
- catch (Exception)
- {
- return new Result() { Code = -1, Msg = "查询异常!", Data = CurrencyRate };
- }
-
- }
-
- }
- }
|