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.Groups;
using OASystem.Domain.Entities.Business;
using OASystem.Domain.Entities.Groups;
using OASystem.Domain.Entities.Resource;
using OASystem.Domain.ViewModels.Business;
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;
namespace OASystem.API.Controllers
{
///
/// 通用业务操作
///
[Route("api/[controller]/[action]")]
public class BusinessController : ControllerBase
{
private readonly IMapper _mapper;
private readonly CommonBusRepository _busRep;
private readonly SetDataRepository _setDataRep;
private readonly DelegationInfoRepository _groupRep;
public BusinessController(IMapper mapper, CommonBusRepository busRep, SetDataRepository setDataRep, DelegationInfoRepository groupRep)
{
_mapper = mapper;
_busRep = busRep;
_setDataRep = setDataRep;
_groupRep = groupRep;
}
#region 团组信息 团组详情
///
/// 团组信息 团组详情
///
/// 团组info请求dto
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task PostShareGroupInfo(ShareGroupInfoDto dto)
{
var groupData = await _groupRep.PostShareGroupInfo(dto);
if (groupData.Code != 0)
{
return Ok(JsonView(false, groupData.Msg));
}
return Ok(JsonView(groupData.Data));
}
///
/// 团组信息 团组名称 List
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task 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));
}
#endregion
#region 币种 List
///
/// 币种 List
///
///
///
[HttpGet,HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task 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;
}
}
///
/// 根据团组Id币种Id及类型Id查询团组汇率
///
///
///
[HttpGet, HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task 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 会务物料单
///
/// 获取会务活动列表
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task PostConferenceList()
{
List listSource = _busRep.Query(s => s.TeamDid == 691 && s.IsDel == 0).ToList();
List viewList = new List();
foreach (var group in listSource)
{
GroupNameView _view = new GroupNameView();
_view.Id = group.Id;
_view.GroupName = group.TeamName;
}
return Ok(JsonView(viewList));
}
///
/// 获取会务的采购物品计划清单
///
/// 会务活动Id
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task PostConfItemList(int ConfId)
{
Bus_ConfItemListView view = new Bus_ConfItemListView();
Bus_ConfItemListInfo _confListInfo = await _busRep.Query(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 confItemList = await _busRep._sqlSugar.SqlQueryable(sqlItem).ToListAsync();
view.ItemList = new List(confItemList);
}
else
{
view.ItemList = new List();
view.TotalCost = 0;
}
return Ok(JsonView(view));
}
///
/// 获取会务可采购的物料集合
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task PostOptionalItemList()
{
List result = await _busRep.GetViewList_OptionalItem();
return Ok(JsonView(result));
}
///
/// 编辑物料采购清单
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task PostEditOptionalItemList(JsonDtoBase jsonDto)
{
if (string.IsNullOrEmpty(jsonDto.Paras))
{
return Ok(JsonView(false, "参数为空"));
}
Edit_OptionalItemListDto _dto = JsonConvert.DeserializeObject(jsonDto.Paras);
//Edit_OptionalItemListDto _dto = System.Text.Json.JsonSerializer.Deserialize(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));
}
///
/// 获取会务采购物料清单Excel
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task Excel_ConfItemList(JsonDtoBase jsonDto)
{
if (string.IsNullOrEmpty(jsonDto.Paras))
{
return Ok(JsonView(false, "参数为空"));
}
dynamic confList = JsonConvert.DeserializeObject(jsonDto.Paras);
int confListId = confList.ConfListId;
Bus_ConfItemListInfo _entityConfList = await _busRep.Query(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 阿里云短信测试
///
/// 编辑物料采购清单
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task 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
}
}