123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using AutoMapper;
- using GxPress.Common.AppOptions;
- using GxPress.Common.Tools;
- using GxPress.Entity;
- using GxPress.Repository.Interface;
- using Microsoft.Extensions.Options;
- using Datory;
- using System;
- using Dapper;
- namespace GxPress.Repository.Implement
- {
- public class CcRepository : ICcRepository
- {
- private readonly Repository<Cc> _repository;
- private readonly IMapper _mapper;
- private readonly string _connectionString;
- private readonly string _databaseTypeStr;
- public CcRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper)
- {
- _databaseTypeStr = dbOptionsAccessor.CurrentValue.DatabaseType;
- _connectionString = dbOptionsAccessor.CurrentValue.ConnectionString;
- var databaseType = StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
- var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
- _repository = new Repository<Cc>(database);
- _mapper = mapper;
- }
- public IDatabase Database => _repository.Database;
- public string TableName => _repository.TableName;
- public List<TableColumn> TableColumns => _repository.TableColumns;
- /// <summary>
- /// 根据通知ID获取抄送人
- /// </summary>
- /// <param name="noticeId"></param>
- /// <returns></returns>
- public async Task<IEnumerable<Cc>> GetNoticeCcByNoticeIdAsync(int noticeId, int sourceType)
- {
- return await _repository.GetAllAsync(Q.Where(nameof(Cc.SourceId), noticeId).Where(nameof(Cc.SourceType), sourceType));
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="sourceId"></param>
- /// <param name="sourceType"></param>
- /// <returns></returns>
- public async Task<bool> DeleteAsync(int sourceId, int sourceType)
- {
- return await _repository.DeleteAsync(Q.Where(nameof(Cc.SourceId), sourceId).Where(nameof(Cc.SourceType), sourceType)) > 0;
- }
- public async Task<int> InsertAsync(Cc cc)
- {
- return await _repository.InsertAsync(cc);
- }
- /// <summary>
- /// 添加通知抄送人
- /// </summary>
- /// <param name="noticeCcs"></param>
- /// <returns></returns>
- public async Task<bool> InsertAsync(List<Cc> noticeCcs)
- {
- if (noticeCcs.Count == 0)
- return false;
- var sql = "INSERT INTO `tede_cc`(`Guid`,`CreatedDate`,`LastModifiedDate`,`SourceId`,`SourceType`,`UserId`,`UserName`,`IsRead`)VALUES";
- foreach (var item in noticeCcs)
- {
- var guId = Guid.NewGuid().ToString();
- var createdDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- var isRead = item.IsRead == true ? 1 : 0;
- sql += $"('{guId}','{createdDate}','{createdDate}',{item.SourceId},{item.SourceType},{item.UserId},'',{isRead}),";
- }
- sql = sql.Remove(sql.Length - 1, 1);
- var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
- var database = new Database(databaseType, _connectionString);
- var connection = database.GetConnection();
- var items = await connection.ExecuteAsync(sql);
- return items > 0;
- }
- }
- }
|