123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- using AutoMapper;
- using Newtonsoft.Json;
- using OASystem.Domain;
- using OASystem.Domain.Dtos.Groups;
- using OASystem.Domain.Dtos.Resource;
- using OASystem.Domain.Entities.Customer;
- using OASystem.Domain.Entities.Groups;
- using OASystem.Domain.Entities.Resource;
- using OASystem.Domain.ViewModels;
- using OASystem.Domain.ViewModels.Groups;
- using OASystem.Domain.ViewModels.Resource;
- using OASystem.Infrastructure.Tools;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Security.Cryptography;
- using System.Text;
- using System.Threading.Tasks;
- namespace OASystem.Infrastructure.Repositories.Resource
- {
- public class InvitationOfficialActivityDataRepository : BaseRepository<Res_InvitationOfficialActivityData, InvitationOfficialActivitiesByIdDto>
- {
- private readonly IMapper _mapper;
- public InvitationOfficialActivityDataRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
- {
- _mapper = mapper;
- }
-
-
-
-
-
- public async Task<JsonView> QueryInvitationOfficialActivityData(QueryInvitationOfficialActivityDataDto dto)
- {
- var result = new JsonView() { Msg = "操作失败!" };
-
- DateTime _beginDt, _endDt;
- var _beginDtBool = DateTime.TryParse(dto.StartCreateTime+" 00:00:00", out _beginDt);
- var _endDtBool = DateTime.TryParse(dto.EndCreateTime + " 23:59:59", out _endDt);
- RefAsync<int> total = 0;
-
- var _view = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>()
- .LeftJoin<Sys_Users>((ioa, u) => ioa.CreateUserId == u.Id)
- .Where((ioa,u) => ioa.IsDel == 0)
- .WhereIF(!string.IsNullOrEmpty(dto.Country), (ioa, u) => ioa.Country.Contains(dto.Country))
- .WhereIF(!string.IsNullOrEmpty(dto.UnitName), (ioa, u) => ioa.UnitName.Contains(dto.UnitName))
- .WhereIF(!string.IsNullOrEmpty(dto.Contact), (ioa, u) => ioa.Contact.Contains(dto.Contact))
- .WhereIF(!string.IsNullOrEmpty(dto.Delegation), (ioa, u) => ioa.Delegation.Contains(dto.Delegation))
- .WhereIF(!string.IsNullOrEmpty(dto.Field), (ioa, u) => ioa.Field.Contains(dto.Field))
- .WhereIF(_beginDtBool && _endDtBool, (ioa, u) => ioa.CreateTime >= _beginDt && ioa.CreateTime <= _endDt)
- .WhereIF(dto.CreateUserId > 0, (ioa, u) => ioa.CreateUserId == dto.CreateUserId)
- .Select((ioa, u) => new {
- Row_Number = ioa.RowIndex,
- ioa.Id,
- ioa.Country,
- ioa.City,
- ioa.UnitName,
- ioa.Field,
- ioa.Contact,
- ioa.Job,
- ioa.Tel,
- ioa.CreateTime,
- CreateUserName = u.CnName,
- DelegationStr = ioa.Delegation
- })
- .OrderByDescending((ioa) => ioa.CreateTime)
- .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
- foreach (var item in _view)
- {
- string groupNameStr = "";
- int[] groupIds = item.DelegationStr.Split(',').Select(x =>
- {
- int id;
- if (int.TryParse(x, out id)) return id;
- else return id;
- }).ToArray();
- var _DelegationInfos = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => groupIds.Contains(x.Id)).ToList();
- foreach (var group in _DelegationInfos)
- {
- groupNameStr += $"{group.TeamName},";
- }
- if (groupNameStr.Length > 1)
- {
- groupNameStr= groupNameStr.Substring(0, groupNameStr.Length - 1);
- }
- }
- result.Code = StatusCodes.Status200OK;
- result.Msg = $"操作成功!";
- result.Data = _view;
- result.Count = _view.Count;
- return result;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
-
-
-
-
-
- public async Task<JsonView> Info(int id)
- {
- var res = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>()
- .Where(x => x.Id == id && x.IsDel == 0)
- .FirstAsync();
-
- var _view = _mapper.Map<IOAInfoView>(res);
- return new JsonView() { Code = StatusCodes.Status200OK, Msg = "操作成功", Data = _view };
- }
- public async Task<JsonView> IOA_OP(OpInvitationOfficialActivityDto dto)
- {
- JsonView result = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
- var _info = _mapper.Map<Res_InvitationOfficialActivityData>(dto);
- 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)
- {
- result.Msg = $"该信息已存在,请勿重复添加!";
- return result;
- }
- #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);
- }
- }
- }
- fileNameJsonStr = JsonConvert.SerializeObject(fileNames);
- }
- 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,
- SndFileName = fileNameJsonStr,
- Fax = dto.Fax,
-
- Remark = dto.Remark
- });
- if (!res) return result;
-
- Crm_TableOperationRecord operationRecord = new Crm_TableOperationRecord
- {
- CreateTime = DateTime.Now,
- CreateUserId = dto.CreateUserId,
- DataId = dto.Id,
- IsDel = 0,
- OperationItem = OperationEnum.Edit,
- PortType = 1,
- TableName = "Res_InvitationOfficialActivityData",
- };
- await _sqlSugar.Insertable(operationRecord).ExecuteCommandAsync();
- }
- 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);
- }
- foreach (var file in formFiles)
- {
-
- var path = Path.Combine(filePath, file.FileName);
- using (var stream = new FileStream(path, FileMode.Create))
- {
- await file.CopyToAsync(stream);
- }
- fileNames.Add(file.FileName);
- }
- }
- return fileNames;
- }
- }
- }
|