|
@@ -1,4 +1,5 @@
|
|
|
using AutoMapper;
|
|
|
+using Newtonsoft.Json;
|
|
|
using OASystem.Domain;
|
|
|
using OASystem.Domain.Dtos.Groups;
|
|
|
using OASystem.Domain.Dtos.Resource;
|
|
@@ -130,7 +131,6 @@ namespace OASystem.Infrastructure.Repositories.Resource
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
public async Task<JsonView> Info(int id)
|
|
|
{
|
|
|
-
|
|
|
var res = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>()
|
|
|
.Where(x => x.Id == id && x.IsDel == 0)
|
|
|
.FirstAsync();
|
|
@@ -139,72 +139,126 @@ namespace OASystem.Infrastructure.Repositories.Resource
|
|
|
return new JsonView() { Code = StatusCodes.Status200OK, Msg = "操作成功", Data = _view };
|
|
|
}
|
|
|
|
|
|
- public async Task<Result> OpInvitationOfficialActivity(OpInvitationOfficialActivityDto dto)
|
|
|
+ public async Task<JsonView> IOA_OP(OpInvitationOfficialActivityDto dto)
|
|
|
{
|
|
|
- Result result = new Result() { Code = -2, Msg = "未知错误" };
|
|
|
- try
|
|
|
+ JsonView result = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败1" };
|
|
|
+
|
|
|
+ var _info = _mapper.Map<Res_InvitationOfficialActivityData>(dto);
|
|
|
+
|
|
|
+ if (dto.Status == 1)//添加
|
|
|
{
|
|
|
- if (dto.Status == 1)//添加
|
|
|
+ string selectSql = string.Format(@"select * from Res_InvitationOfficialActivityData where UnitName='{0}' and IsDel='{1}'", dto.UnitName, 0);
|
|
|
+ var res_InvitationOfficial = await _sqlSugar.SqlQueryable<Res_InvitationOfficialActivityData>(selectSql).FirstAsync();//查询是否存在
|
|
|
+ if (res_InvitationOfficial != null)
|
|
|
{
|
|
|
- string selectSql = string.Format(@"select * from Res_InvitationOfficialActivityData where UnitName='{0}' and IsDel='{1}'", dto.UnitName, 0);
|
|
|
- var res_InvitationOfficial = await _sqlSugar.SqlQueryable<Res_InvitationOfficialActivityData>(selectSql).FirstAsync();//查询是否存在
|
|
|
- if (res_InvitationOfficial != null)
|
|
|
- {
|
|
|
- return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
|
|
|
+ result.Msg = $"该信息已存在,请勿重复添加!";
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
- else//不存在,可添加
|
|
|
- {
|
|
|
- Res_InvitationOfficialActivityData _InvitationOfficialActivityData = _mapper.Map<Res_InvitationOfficialActivityData>(dto);
|
|
|
- int id = await _sqlSugar.Insertable(_InvitationOfficialActivityData).ExecuteReturnIdentityAsync();
|
|
|
- if (id == 0)
|
|
|
- {
|
|
|
- return result = new Result() { Code = -1, Msg = "添加失败!" };
|
|
|
+ #region 处理上传文件
|
|
|
+ var fileNames = await Upload(dto.Files);
|
|
|
+ if (fileNames.Count > 0)
|
|
|
+ {
|
|
|
+ _info.SndFileName = JsonConvert.SerializeObject(fileNames);
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
|
|
|
+ var id = await _sqlSugar.Insertable(_info).ExecuteReturnIdentityAsync();
|
|
|
+ if (id < 1) return result;
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (dto.Status == 2)//修改
|
|
|
+ {
|
|
|
+ var fileNameJsonStr = string.Empty;
|
|
|
+ var fileNames = await Upload(dto.Files);
|
|
|
+ if (fileNames.Count > 0)
|
|
|
+ {
|
|
|
+ var ioaInfo = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>().FirstAsync(x => x.IsDel == 0 && x.Id == dto.Id);
|
|
|
+ if (ioaInfo != null) {
|
|
|
+ var fileName = ioaInfo.SndFileName;
|
|
|
+ if (!string.IsNullOrEmpty(fileName))
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var ioaFiles = JsonConvert.DeserializeObject<List<string>>(fileName);
|
|
|
+ fileNames.AddRange(ioaFiles);
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+ fileNames.Add(fileName);
|
|
|
+ }
|
|
|
}
|
|
|
- return result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
|
|
|
}
|
|
|
+
|
|
|
+ fileNameJsonStr = JsonConvert.SerializeObject(fileNames);
|
|
|
}
|
|
|
- else if (dto.Status == 2)//修改
|
|
|
+
|
|
|
+ bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Res_InvitationOfficialActivityData
|
|
|
{
|
|
|
- bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Res_InvitationOfficialActivityData
|
|
|
- {
|
|
|
- Country = dto.Country,
|
|
|
- City = dto.City,
|
|
|
- UnitName = dto.UnitName,
|
|
|
- UnitWeb = dto.UnitWeb,
|
|
|
- Field = dto.Field,
|
|
|
- Address = dto.Address,
|
|
|
- UnitInfo = dto.UnitInfo,
|
|
|
- Contact = dto.Contact,
|
|
|
- Job = dto.Job,
|
|
|
- Tel = dto.Tel,
|
|
|
- Email = dto.Email,
|
|
|
- WeChat = dto.WeChat,
|
|
|
- FaceBook = dto.FaceBook,
|
|
|
- Ins = dto.Ins,
|
|
|
- Delegation = dto.Delegation,
|
|
|
- FilePath = dto.FilePath,
|
|
|
- SndFilePath = dto.SndFilePath,
|
|
|
- Fax = dto.Fax,
|
|
|
- CreateUserId = dto.CreateUserId,
|
|
|
- Remark = dto.Remark
|
|
|
- });
|
|
|
- if (!res)
|
|
|
- {
|
|
|
- return result = new Result() { Code = -1, Msg = "修改失败!" };
|
|
|
- }
|
|
|
- return result = new Result() { Code = 0, Msg = "修改成功!" };
|
|
|
+ Country = dto.Country,
|
|
|
+ City = dto.City,
|
|
|
+ UnitName = dto.UnitName,
|
|
|
+ UnitWeb = dto.UnitWeb,
|
|
|
+ Field = dto.Field,
|
|
|
+ Address = dto.Address,
|
|
|
+ UnitInfo = dto.UnitInfo,
|
|
|
+ Contact = dto.Contact,
|
|
|
+ Job = dto.Job,
|
|
|
+ Tel = dto.Tel,
|
|
|
+ Email = dto.Email,
|
|
|
+ WeChat = dto.WeChat,
|
|
|
+ FaceBook = dto.FaceBook,
|
|
|
+ Ins = dto.Ins,
|
|
|
+ Delegation = dto.Delegation,
|
|
|
+ FilePath = dto.FilePath,
|
|
|
+ SndFileName = fileNameJsonStr,
|
|
|
+ Fax = dto.Fax,
|
|
|
+ CreateUserId = dto.CreateUserId,
|
|
|
+ Remark = dto.Remark
|
|
|
+ });
|
|
|
+ if (!res) return result;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ result.Msg = $"请传入Status参数,1添加 2修改!";
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ result.Msg = $"操作成功!";
|
|
|
+ result.Code = StatusCodes.Status200OK;
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public async Task< List<string>> Upload(IFormFile[] formFiles)
|
|
|
+ {
|
|
|
+ var fileNames = new List<string>();
|
|
|
+
|
|
|
+ if (formFiles != null && formFiles.Length > 0)
|
|
|
+ {
|
|
|
+ var filePath = $@"{AppSettingsHelper.Get("GrpFileBasePath")}/商邀相关文件";
|
|
|
+ if (!Directory.Exists(filePath))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(filePath);
|
|
|
}
|
|
|
- else
|
|
|
+
|
|
|
+ foreach (var file in formFiles)
|
|
|
{
|
|
|
- return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
|
|
|
+ //filePath = @$"{filePath}/{file.FileName}";
|
|
|
+
|
|
|
+ var path = Path.Combine(filePath, file.FileName);
|
|
|
+
|
|
|
+ using (var stream = new FileStream(path, FileMode.Create))
|
|
|
+ {
|
|
|
+ await file.CopyToAsync(stream);
|
|
|
+ }
|
|
|
+
|
|
|
+ fileNames.Add(file.FileName);
|
|
|
}
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- return result = new Result() { Code = -2, Msg = "程序错误!" };
|
|
|
- }
|
|
|
+
|
|
|
+ return fileNames;
|
|
|
}
|
|
|
}
|
|
|
}
|