123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626 |
- using Microsoft.AspNetCore.Mvc;
- using NPOI.SS.Formula.Functions;
- using OASystem.API.OAMethodLib.ALiYun;
- using OASystem.API.OAMethodLib.ExcelOutput;
- using OASystem.Domain.Common;
- using OASystem.Domain.Dtos.Business;
- using OASystem.Domain.Dtos.Financial;
- using OASystem.Domain.Dtos.Groups;
- using OASystem.Domain.Entities.Business;
- using OASystem.Domain.Entities.Financial;
- using OASystem.Domain.Entities.Groups;
- using OASystem.Domain.Entities.Resource;
- using OASystem.Domain.ViewModels.Business;
- using OASystem.Domain.ViewModels.Financial;
- using OASystem.Domain.ViewModels.Groups;
- using OASystem.Infrastructure.Repositories.Business;
- using OASystem.Infrastructure.Repositories.Groups;
- using OASystem.Infrastructure.Repositories.System;
- using Org.BouncyCastle.Asn1.Mozilla;
- using StackExchange.Redis;
- namespace OASystem.API.Controllers
- {
- /// <summary>
- /// 通用业务操作
- /// </summary>
- [Route("api/[controller]/[action]")]
- public class BusinessController : ControllerBase
- {
- private readonly IMapper _mapper;
- private readonly CommonBusRepository _busRep;
- private readonly SetDataRepository _setDataRep;
- private readonly DelegationInfoRepository _groupRep;
- private readonly TeamRateRepository _teamRateRep;
- public BusinessController( IMapper mapper, CommonBusRepository busRep, SetDataRepository setDataRep, DelegationInfoRepository groupRep, TeamRateRepository teamRateRep)
- {
- _mapper = mapper;
- _busRep = busRep;
- _setDataRep = setDataRep;
- _groupRep = groupRep;
- _teamRateRep = teamRateRep;
- }
- #region 团组信息
- /// <summary>
- /// 团组信息
- /// 团组简略详情
- /// </summary>
- /// <param name="dto">团组info请求dto</param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostShareGroupInfo(ShareGroupInfoDto dto)
- {
- try
- {
- var groupData = await _groupRep.PostShareGroupInfo(dto);
- if (groupData.Code != 0)
- {
- return Ok(JsonView(false, groupData.Msg));
- }
- return Ok(JsonView(groupData.Data));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
-
- }
- /// <summary>
- /// 团组信息 团组名称 List
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GetGroupNameList(GroupNameDto dto)
- {
- var groupData = await _groupRep.GetGroupNameList(dto);
- if (groupData.Code != 0)
- {
- return Ok(JsonView(false, groupData.Msg));
- }
- return Ok(JsonView(groupData.Data, groupData.Data.Count));
- }
- /// <summary>
- /// 获取团组指向分类
- /// </summary>
- /// <param name="_dto">参数Json字符串</param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostGroupDirectionalClassificationInit()
- {
- Result result = new Result();
- result = await _setDataRep.GetSetDataBySTId(_setDataRep, 16); //团组指向分类
- if (result.Code != 0)
- {
- return Ok(JsonView(false, "获取失败!"));
- }
- List<SetDataInfoView> _view1 = JsonConvert.DeserializeObject<List<SetDataInfoView>>(JsonConvert.SerializeObject(result.Data));
- SetDataInfoView xc_view = new SetDataInfoView();//77 行程 //移除行程
- xc_view = _view1.Where(it => it.Id == 77).FirstOrDefault();
- if (xc_view != null) { _view1.Remove(xc_view); };
- List<SetDataInfoView> _view = new List<SetDataInfoView>();
- //_view.Insert(0, new SetDataInfoView { Id = -1, Name = "所有模块" });
- SetDataInfoView qz_view = new SetDataInfoView();//80 签证
- qz_view = _view1.Where(it => it.Id == 80).FirstOrDefault();
- if (qz_view != null) { _view.Insert(0, qz_view); _view1.Remove(qz_view); };
- SetDataInfoView jpyd_view = new SetDataInfoView();//85 机票预订
- jpyd_view = _view1.Where(it => it.Id == 85).FirstOrDefault();
- if (jpyd_view != null) { _view.Insert(1, jpyd_view); _view1.Remove(jpyd_view); };
- SetDataInfoView jdyd_view = new SetDataInfoView();//76 酒店预订
- jdyd_view = _view1.Where(it => it.Id == 76).FirstOrDefault();
- if (jdyd_view != null) { _view.Insert(2, jdyd_view); _view1.Remove(jdyd_view); };
- SetDataInfoView jdzc_view = new SetDataInfoView();//751 酒店早餐
- jdzc_view = _view1.Where(it => it.Id == 751).FirstOrDefault();
- if (jdzc_view != null) { _view.Insert(3, jdzc_view); _view1.Remove(jdzc_view); };
- SetDataInfoView cdy_view = new SetDataInfoView();//79 车/导游地接
- cdy_view = _view1.Where(it => it.Id == 79).FirstOrDefault();
- if (cdy_view != null) { _view.Insert(4, cdy_view); _view1.Remove(cdy_view); };
- SetDataInfoView yqgw_view = new SetDataInfoView();//81 邀请/公务活动
- yqgw_view = _view1.Where(it => it.Id == 81).FirstOrDefault();
- if (yqgw_view != null) { _view.Insert(5, yqgw_view); _view1.Remove(yqgw_view); };
- SetDataInfoView bx_view = new SetDataInfoView();//82 团组客户保险
- bx_view = _view1.Where(it => it.Id == 82).FirstOrDefault();
- if (bx_view != null) { _view.Insert(6, bx_view); _view1.Remove(bx_view); };
- SetDataInfoView qtkx_view = new SetDataInfoView();//98 其他款项
- qtkx_view = _view1.Where(it => it.Id == 98).FirstOrDefault();
- if (qtkx_view != null) { _view.Insert(7, qtkx_view); _view1.Remove(qtkx_view); };
- SetDataInfoView skth_view = new SetDataInfoView();//285 收款退还与其他款项
- skth_view = _view1.Where(it => it.Id == 285).FirstOrDefault();
- if (skth_view != null) { _view.Insert(8, skth_view); _view1.Remove(skth_view); };
- if (_view1.Count > 0)
- {
- _view.AddRange(_view1);
- }
- return Ok(JsonView(_view));
- }
- /// <summary>
- /// 查询团组简略详情列表
- /// Page 根据Ctable And User 返回可操作的团
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostGroupListByCTableAndUserId(GroupListByCTableAndUserIdDto dto)
- {
- if (dto.CTable < 1) Ok(JsonView(false, @"请输入正确的员工给Id!"));
- if (dto.CTable < 1)
- return Ok(JsonView(false, @"请输入正确的CTable Id !76 酒店预订 77 行程 79 车/导游地接<br/>80 签证 81 邀请/公务活动 82 团组客户保险<br\>85 机票预订 98 其他款项 751 酒店早餐"));
- if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3)
- {
- string sql = string.Format(@"Select row_number() over(order by di.VisitStartDate Desc) as Row_Number,
- di.Id,di.TeamName,di.TourCode,di.ClientName,di.VisitCountry,di.VisitStartDate,
- di.VisitEndDate,di.VisitDays,di.VisitPNumber
- From Grp_GroupsTaskAssignment gta
- Inner Join Grp_DelegationInfo di On gta.DIId = di.Id
- Where gta.IsDel = 0 And di.IsDel = 0 And gta.IsEnable = 1
- And gta.CTId = {0} And gta.UId = {1}", dto.CTable, dto.UserId);
- RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
- var data = await _groupRep._sqlSugar.SqlQueryable<GroupListByCTableAndUserIdView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, total); //ToPageAsync
- foreach (var item in data)
- {
- item.VisitStartDate = item.VisitStartDate == "" ? "" : Convert.ToDateTime(item.VisitStartDate).ToString("yyyy-MM-dd");
- item.VisitEndDate = item.VisitEndDate == "" ? "" : Convert.ToDateTime(item.VisitEndDate).ToString("yyyy-MM-dd");
- }
- return Ok(JsonView(true, "操作成功!", data, total));
- }
- else
- {
- return Ok(JsonView(false, @"请输入正确的PortType 1 Web 2 Android 3 IOS "));
- }
- }
- #endregion
- #region 币种 List
- /// <summary>
- /// 币种 List
- /// </summary>
- /// <returns></returns>
- [HttpGet,HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostCurrencyList()
- {
- try
- {
- Result setData = await _setDataRep.GetSetDataBySTId(_setDataRep, 66); //币种类型
- if (setData.Code == 0)
- {
- return Ok(JsonView(true, "查询成功", setData.Data));
- }
- else
- {
- return Ok(JsonView(false, setData.Msg));
- }
- }
- catch (Exception)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- }
- /// <summary>
- /// 团组汇率 币种 Item (来源:团组汇率)
- /// 根据 团组Id And 业务类型(CTable)Id
- /// api处理CTable = 285,默认返回CNY
- /// </summary>
- /// <param name="dto"> 请求参数Dto </param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostGroupTeamRateByDiIdAndCTableId(GeneralTeamRateInfoDto dto)
- {
- try
- {
- if (dto == null)
- {
- return Ok(JsonView(false, "请输入参数!"));
- }
- if (dto.DiId == 0)
- {
- return Ok(JsonView(false, "请输入正确的团组Id!"));
- }
- if (dto.CTable == 0)
- {
- return Ok(JsonView(false, "请输入正确的业务类型(CTable)Id!"));
- }
- if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3 )
- {
- string teamRateInfoSql = string.Format(@"Select sd.Name,tr.* From Grp_TeamRate tr
- Left Join Sys_SetData sd On sd.IsDel=0 And sd.STid=16 And tr.CTable = sd.Id
- Where tr.IsDel = 0 And tr.DiId = {0} And tr.CTable = {1}", dto.DiId,dto.CTable);
- var teamRateInfo = await _teamRateRep._sqlSugar.SqlQueryable<TeamRateInfoView>(teamRateInfoSql).ToListAsync();
- #region 团组汇率
- TeamRateModelGeneralView teamRateModels = new TeamRateModelGeneralView();
- #region 单独处理Ctable 币种汇率 默认 为CNY
- if (dto.CTable == 285)
- {
- teamRateModels = new TeamRateModelGeneralView()
- {
- Id = 0,
- CTableId = 285,
- CTableName = "其他款项与收款退还",
- TeamRates = new List<TeamRateDescAddCurrencyIdView>() {
- new TeamRateDescAddCurrencyIdView()
- {
- CurrencyId = 836,
- CurrencyCode = "CNY",
- CurrencyName = "人民币",
- Rate = 1.0000M,
- }
- }
- };
- return Ok(JsonView(true, "操作成功!", teamRateModels));
- }
- #endregion
- List<SetDataInfoView> currencyDatas = new List<SetDataInfoView>();
- #region 获取所有币种
- string sql = string.Format(@"select * from Sys_SetData where STid = {0} and isdel = 0", 66);
- var DBdata = await _setDataRep.GetListBySqlWithNolockAsync(sql);
- if (DBdata == null || DBdata.Count == 0)
- {
- return Ok(JsonView(false, "所有币种获取失败!"));
- }
- currencyDatas = DBdata.Select(x => new SetDataInfoView
- {
- Name = x.Name,
- Id = x.Id,
- Remark = x.Remark,
- }).ToList();
- #endregion
- foreach (TeamRateInfoView item in teamRateInfo)
- {
- TeamRateModelGeneralView teamRateModelInfo = new TeamRateModelGeneralView();
- teamRateModelInfo.Id = item.Id;
- teamRateModelInfo.CTableId = item.CTable;
- teamRateModelInfo.CTableName = item.Name;
- List<TeamRateDescAddCurrencyIdView> teamRateDescViews = new List<TeamRateDescAddCurrencyIdView>();
- #region 拆分remark里的汇率
- if (item.Remark.Contains("|"))
- {
- string[] currencyArr = item.Remark.Split("|");
- foreach (string currency in currencyArr)
- {
- string[] currency1 = currency.Split(":");
- string[] currency2 = currency1[0].Split("(");
- string currencyCode = currency2[1].Replace(")", "").TrimEnd();
- SetDataInfoView dataInfoView = new SetDataInfoView();
- dataInfoView = currencyDatas.Where(it => it.Name == currencyCode).FirstOrDefault();
- int currencyId = currencyDatas.Where(it => it.Name == currencyCode).FirstOrDefault().Id;
- TeamRateDescAddCurrencyIdView rateDescView = new TeamRateDescAddCurrencyIdView()
- {
- CurrencyId = dataInfoView.Id,
- CurrencyCode = currencyCode,
- CurrencyName = currency2[0],
- Rate = decimal.Parse(currency1[1]),
- };
- teamRateDescViews.Add(rateDescView);
- }
- }
- #endregion
- if (teamRateDescViews.Count > 0)
- {
- teamRateDescViews = teamRateDescViews.OrderBy(it => it.CurrencyId).ToList();
- }
- teamRateModelInfo.TeamRates = teamRateDescViews;
- teamRateModels = teamRateModelInfo;
- }
- #endregion
- return Ok(JsonView(true, "操作成功!", teamRateModels));
- }
- else
- {
- return Ok(JsonView(false, "请输入正确的端口号! 1 Web 2 Android 3 Ios;"));
- }
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
- }
- /// <summary>
- /// 根据团组Id币种Id及类型Id查询团组汇率
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpGet, HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostCurrencyByDiid(int DiId,int CId,int CurrencyId)
- {
- try
- {
- Result setData = await _setDataRep.PostCurrencyByDiid( DiId, CId, CurrencyId); //币种类型
- if (setData.Code == 0)
- {
- return Ok(JsonView(true, "查询成功", setData.Data));
- }
- else
- {
- return Ok(JsonView(false, setData.Msg));
- }
- }
- catch (Exception)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- }
- #endregion
- #region 查询页面关联Ctable
- /// <summary>
- /// 页面关联Ctable
- /// 根据PageId 返回 CTable Id
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostPageLinkCTable(PageLinkCTableDto dto)
- {
- try
- {
- if (dto == null)
- {
- return Ok(JsonView(false, "请求参数不能为空!"));
- }
- if (dto.PageId == 0)
- {
- return Ok(JsonView(false, "页面Id不能为0!"));
- }
- List<CTableCorrelationPageDatas> data = AppSettingsHelper.Get<CTableCorrelationPageDatas>("CTableCorrelationPageDatas");
- CTableCorrelationPageDatas correlationPageDatas = new CTableCorrelationPageDatas();
- foreach (var item in data)
- {
- if (item.PageIdDatas != null)
- {
- var pageId = item.PageIdDatas.Where(it => it == dto.PageId).FirstOrDefault();
- if (pageId != 0)
- {
- correlationPageDatas = item;
- break;
- }
- }
- }
- if (correlationPageDatas.CTableId == 0)
- {
- return Ok(JsonView(false, "您查询的页面Id,未配置AppSettings,请前往配置!"));
- }
- return Ok(JsonView(true, "操作成功",new { CTable = correlationPageDatas.CTableId }));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
- }
- #endregion
- #region 会务物料单
- /// <summary>
- /// 获取会务活动列表
- /// </summary>
- /// <param name="paras"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostConferenceList()
- {
- List<Grp_DelegationInfo> listSource = _busRep.Query<Grp_DelegationInfo>(s => s.TeamDid == 691 && s.IsDel == 0).ToList();
- List<GroupNameView> viewList = new List<GroupNameView>();
- foreach (var group in listSource)
- {
- GroupNameView _view = new GroupNameView();
- _view.Id = group.Id;
- _view.GroupName = group.TeamName;
- }
- return Ok(JsonView(viewList));
- }
- /// <summary>
- /// 获取会务的采购物品计划清单
- /// </summary>
- /// <param name="ConfId">会务活动Id</param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostConfItemList(int ConfId)
- {
- Bus_ConfItemListView view = new Bus_ConfItemListView();
- Bus_ConfItemListInfo _confListInfo = await _busRep.Query<Bus_ConfItemListInfo>(s => s.Diid == ConfId).FirstAsync();
- if (_confListInfo != null)
- {
- view.TotalCost = _confListInfo.TotalCost;
- string sqlItem = string.Format(@" Select c.Id,c.ItemId,d.ItemName,c.[Count],c.CurrCost,c.OpRemark
- From Bus_ConfItem as c With(Nolock)
- Inner Join Res_ItemDetail as d with(Nolock) On c.ItemId=d.Id
- Where c.ConfListId = {0}", ConfId);
- List<Bus_ConfItemView> confItemList = await _busRep._sqlSugar.SqlQueryable<Bus_ConfItemView>(sqlItem).ToListAsync();
- view.ItemList = new List<Bus_ConfItemView>(confItemList);
- }
- else
- {
- view.ItemList = new List<Bus_ConfItemView>();
- view.TotalCost = 0;
- }
- return Ok(JsonView(view));
- }
- /// <summary>
- /// 获取会务可采购的物料集合
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostOptionalItemList()
- {
- List<OptionalBusRangeView> result = await _busRep.GetViewList_OptionalItem();
- return Ok(JsonView(result));
- }
- /// <summary>
- /// 编辑物料采购清单
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostEditOptionalItemList(JsonDtoBase jsonDto)
- {
- if (string.IsNullOrEmpty(jsonDto.Paras))
- {
- return Ok(JsonView(false, "参数为空"));
- }
- Edit_OptionalItemListDto _dto = JsonConvert.DeserializeObject<Edit_OptionalItemListDto>(jsonDto.Paras);
- //Edit_OptionalItemListDto _dto = System.Text.Json.JsonSerializer.Deserialize<Edit_OptionalItemListDto>(jsonDto.Paras);
- if (_dto.DiId < 1)
- {
- return Ok(JsonView(false, "团组Id为空"));
- }
- if (_dto.ConfItemListId < 1)
- {
- //新增
- int rstInsert = await _busRep.Insert_ConfItemList(_dto);
- return Ok(JsonView(rstInsert == 0));
- }
- else
- {
- //修改
- int rstUpdate = await _busRep.Edit_ConfItemList(_dto);
- return Ok(JsonView(rstUpdate == 0));
- }
- return Ok(JsonView(false));
- }
- /// <summary>
- /// 获取会务采购物料清单Excel
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> Excel_ConfItemList(JsonDtoBase jsonDto)
- {
- if (string.IsNullOrEmpty(jsonDto.Paras))
- {
- return Ok(JsonView(false, "参数为空"));
- }
- dynamic confList = JsonConvert.DeserializeObject<dynamic>(jsonDto.Paras);
- int confListId = confList.ConfListId;
- Bus_ConfItemListInfo _entityConfList = await _busRep.Query<Bus_ConfItemListInfo>(s => s.Id == confListId).FirstAsync();
- if (_entityConfList != null)
- {
- string result = new Excel_BusConfItemList().Excel(_entityConfList);
- }
- else
- {
- return Ok(JsonView(false, "请先保存数据"));
- }
- return Ok(JsonView(false));
- }
- #endregion
- #region 阿里云短信测试
- /// <summary>
- /// 编辑物料采购清单
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> AliMessageTest(string mobile)
- {
- string add2dayZH = DateTime.Now.AddDays(2).ToString("yyyy年MM月dd日");
- string templateParam = JsonConvert.SerializeObject(new { teams = "测试团组", date = add2dayZH });
- AliMessagePost.PostMessage(mobile, "泛美国际团组", "SMS_461575447", templateParam);
- return Ok(JsonView(true));
- }
- #endregion
- }
- }
|