853 lines
36 KiB
C#
853 lines
36 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Diagnostics;
|
||
using System.Linq;
|
||
using System.Net.Mail;
|
||
using System.Reflection.Metadata;
|
||
using System.Text;
|
||
using System.Threading.Channels;
|
||
using System.Threading.Tasks;
|
||
using System.Xml.Linq;
|
||
using DG.Core;
|
||
using Hg.Core.Domain.Dto.CmsNews;
|
||
using Hg.Core.Domain.Dto.News;
|
||
using Hg.Core.Domain.Dto.Stocks;
|
||
using Hg.Core.Entity;
|
||
using Hg.Core.Entity.Dncmsbase;
|
||
using Newtonsoft.Json;
|
||
using Serilog.Events;
|
||
using Zxd.Core.Shared.Dto;
|
||
|
||
namespace Hg.Core.Domain
|
||
{
|
||
internal class CmsNewsDomain : ICmsNewsDomain
|
||
{
|
||
private readonly IBaseRepository<ZxdDbContext> _repository;
|
||
private readonly IHttpClient _httpClient;
|
||
private readonly IMapper _mapper;
|
||
private readonly ICacheDomain _cacheDomain;
|
||
private readonly IConfiguration _configuration;
|
||
private readonly SystemConfig _systemConfig;
|
||
private readonly IDepartmentDomain _departmentDomain;
|
||
private readonly ICsvrMessageDomain _csvrMessageDomain;
|
||
|
||
public CmsNewsDomain(IConfiguration configuration,
|
||
IBaseRepository<ZxdDbContext> repository,
|
||
IHttpClient httpClient,
|
||
IMapper mapper,
|
||
ICacheDomain cacheDomain,
|
||
IDepartmentDomain departmentDomain,
|
||
ICsvrMessageDomain csvrMessageDomain
|
||
)
|
||
{
|
||
_systemConfig = configuration.GetSection("SystemConfig").Get<SystemConfig>();
|
||
_configuration = configuration;
|
||
_repository = repository;
|
||
_httpClient = httpClient;
|
||
_mapper = mapper;
|
||
_cacheDomain = cacheDomain;
|
||
_departmentDomain = departmentDomain;
|
||
_csvrMessageDomain = csvrMessageDomain;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据CreateCmsNewsDto类创建CmsNews类。
|
||
/// </summary>
|
||
/// <param name="dto"></param>
|
||
/// <returns></returns>
|
||
public async Task<int> CreateOrUpdateCmsNews(CreateOrUpdateCmsNewsDto dto)
|
||
{
|
||
var entity = _mapper.Map<CreateOrUpdateCmsNewsDto, CmsNews>(dto);
|
||
|
||
var companys = await _cacheDomain.GetCompanyVirtualList();
|
||
var departments = await _departmentDomain.GetDeptments();
|
||
entity.Id = (int)dto.Id;
|
||
if (await _repository.GetRepository<CmsNews>().Query().AnyAsync(x => x.Id == entity.Id))
|
||
{
|
||
entity = await _repository.GetRepository<CmsNews>().Query().FirstAsync(x => x.Id == entity.Id);
|
||
}
|
||
if (dto.DepartmentId == null)
|
||
{
|
||
entity.Channel = (int?)dto.Channel;
|
||
foreach (var deptment in departments)
|
||
{
|
||
foreach (var deptmentCampain in deptment?.DeptmentCampains ?? new List<DeptmentCampainDto>())
|
||
{
|
||
if (entity.Channel >= deptmentCampain.StartCampainId && entity.Channel <= deptmentCampain.EndCampainId)
|
||
{
|
||
entity.DepartmentId = deptment?.DepartmentId;
|
||
}
|
||
}
|
||
}
|
||
if (dto.Channel != null)
|
||
{
|
||
foreach (var company in companys)
|
||
{
|
||
var channels = company.Channel.Split('|');
|
||
foreach (var subchannel in channels)
|
||
{
|
||
var subch = subchannel.Split(',');
|
||
var min = int.Parse(subch[0].ToString());
|
||
var max = int.Parse(subch[1].ToString());
|
||
|
||
if (entity.Channel != null && (entity.Channel.Value >= min && entity.Channel.Value <= max))
|
||
{
|
||
entity.Deptcode = company.CompanyCode;
|
||
entity.Companycode = company.CompanyCode;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
entity.Companycode = dto.Companycode ?? dto.Deptcode;
|
||
}
|
||
string[] ss = { "DNG1", "DNG2", "DNG3", "DNG8" };
|
||
if (ss.Contains(entity.Companycode))
|
||
{
|
||
entity.Companycode = "DNG8";
|
||
entity.Deptcode = "DNG8";
|
||
}
|
||
string[] ss2 = { "DNZZ05", "DNZZ06", "DNRW06", "DNRW07", "DNRW08", "DNRW09", "DNRW10" };
|
||
if (ss2.Contains(entity.Companycode) || ss2.Contains(entity.Deptcode))
|
||
{
|
||
entity.Companycode = "DNZZ";
|
||
entity.Deptcode = "DNZZ";
|
||
}
|
||
|
||
string[] ss3 = { "DNBB01", "DNCC01" };
|
||
if (ss3.Contains(entity.Companycode) || ss3.Contains(entity.Deptcode))
|
||
{
|
||
entity.Companycode = "DNBB";
|
||
entity.Deptcode = "DNBB";
|
||
}
|
||
|
||
string[] ss4 = { "DNYY02" };
|
||
if (ss4.Contains(entity.Companycode) || ss4.Contains(entity.Deptcode))
|
||
{
|
||
entity.Companycode = "DNYY";
|
||
entity.Deptcode = "DNYY";
|
||
}
|
||
}
|
||
else
|
||
{
|
||
var department = departments.FirstOrDefault(x => x.DepartmentId == dto.DepartmentId);
|
||
if (department != null)
|
||
{
|
||
entity.Deptcode = department.Code;
|
||
entity.Companycode = department.CompanyCode;
|
||
entity.Channel = department.DeptmentCampains?.FirstOrDefault()?.StartCampainId;
|
||
}
|
||
}
|
||
if (entity.DepartmentId == 45) entity.DepartmentId = 49;
|
||
var transaction = await _repository.BeginTransactionAsync();
|
||
try
|
||
{
|
||
var cmsNewsLog = new CmsNewsLog
|
||
{
|
||
CTime = DateTime.Now,
|
||
Att = entity.Att,
|
||
Content = entity.Content,
|
||
Deptcode = entity.Deptcode,
|
||
Newid = entity.Id,
|
||
NewsType = entity.NewsType,
|
||
OpName = dto.OperateUserName,
|
||
OpUser = (int)dto.OperateUser,
|
||
Remark = entity.Remark,
|
||
Status = entity.Status,
|
||
Title = entity.Title,
|
||
Channel = entity.Channel,
|
||
Author = entity.Author,
|
||
Channels = entity.Channels,
|
||
Attachment = entity.Attachment,
|
||
DepartmentId = entity.DepartmentId,
|
||
};
|
||
if (await _repository.GetRepository<CmsNews>().Query().AnyAsync(x => x.Id == entity.Id))
|
||
{
|
||
if (entity.IsUpload.HasValue && entity.IsUpload.Value && (entity.Status == CmsNewStatus.未审核 || entity.Status == CmsNewStatus.通过))
|
||
{
|
||
throw new ApiException("文案已上传,请勿修改!");
|
||
}
|
||
cmsNewsLog.OpEvent = "修改";
|
||
entity.Updator = dto.OperateUserName;
|
||
entity.UpdateTime = DateTime.Now;
|
||
entity.Att = dto.Att;
|
||
entity.Content = dto.Content;
|
||
entity.NewsType = dto.NewsType;
|
||
entity.Remark = dto.Remark;
|
||
entity.Title = dto.Title;
|
||
entity.Author = dto.Author;
|
||
entity.Channels = dto.Channels;
|
||
await _repository.GetRepository<CmsNewsLog>().InsertAsync(cmsNewsLog);
|
||
entity = await _repository.GetRepository<CmsNews>().UpdateAsync(entity, x => new
|
||
{
|
||
x.DepartmentId,
|
||
x.Channel,
|
||
x.Title,
|
||
x.UpdateTime,
|
||
x.Updator,
|
||
x.Content,
|
||
x.NewsType,
|
||
x.Author,
|
||
x.Channels,
|
||
x.Remark,
|
||
x.IsUpload,
|
||
x.Att,
|
||
});
|
||
await transaction.CommitAsync();
|
||
return entity.Id;
|
||
}
|
||
|
||
cmsNewsLog.OpEvent = "新增";
|
||
entity.IsUpload = false;
|
||
entity.CreateUser = (int)dto.OperateUser;
|
||
entity.CreateUserName = dto.OperateUserName;
|
||
entity.CTime = DateTime.Now;
|
||
entity.Status = CmsNewStatus.未审核;
|
||
entity = await _repository.GetRepository<CmsNews>().InsertAsync(entity);
|
||
await _repository.GetRepository<CmsNewsLog>().InsertAsync(cmsNewsLog);
|
||
await transaction.CommitAsync();
|
||
|
||
return entity.Id;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
await transaction.RollbackAsync();
|
||
await transaction.DisposeAsync();
|
||
Log.Error(ex, "添加文案审核报错!");
|
||
throw new ApiException(ex.Message);
|
||
}
|
||
}
|
||
|
||
public async Task<bool> JustStock(CmsNews news)
|
||
{
|
||
try
|
||
{
|
||
var errList = await CollectStock(news.Remark);
|
||
if (errList.Count > 0)
|
||
{
|
||
AuditCmsNewsDto dto = new AuditCmsNewsDto
|
||
{
|
||
Id = news.Id,
|
||
SelectReason = "16384",
|
||
Status = CmsNewStatus.未通过,
|
||
Auditer = 10000,
|
||
AuditerName = "系统管理员",
|
||
AuditRemark = $"{string.Join(",", errList)}未在股票池报备",
|
||
};
|
||
await Audit(dto);
|
||
return false;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Log.Error($"文案审核自动驳回失败");
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public async Task<List<string>> CollectStock(string context)
|
||
{
|
||
var errMsg = new List<string>();
|
||
if (!string.IsNullOrEmpty(context))
|
||
{
|
||
var stockUrl = $"{_systemConfig.StockUrl.Trim('/')}/stockpool/api/stock/pool/page";
|
||
var authorization = _systemConfig.StockPoolAuthorization;
|
||
//Dictionary<string, string> myDictionary = new Dictionary<string, string>();
|
||
var crulist = new List<DictStockMid>();
|
||
var path = string.Concat(AppDomain.CurrentDomain.BaseDirectory, "/stocks.txt");
|
||
Log.Information($"stock path:{path}");
|
||
string str = "";
|
||
if (File.Exists(path))
|
||
{
|
||
StreamReader fs = new StreamReader(path, System.Text.Encoding.UTF8);
|
||
String input = fs.ReadToEnd();
|
||
fs.Close();
|
||
str = input;
|
||
}
|
||
Log.Information($"stock:{str}");
|
||
string illegalWords = str;
|
||
if (!string.IsNullOrEmpty(illegalWords))
|
||
{
|
||
var list = JsonHelper.FromJson<List<DictStockMid>>(illegalWords);
|
||
for (var i = 0; i < list.Count; i++)
|
||
{
|
||
if (context.Contains(list[i].n))
|
||
crulist.Add(list[i]);
|
||
}
|
||
}
|
||
foreach (var item in crulist)
|
||
{
|
||
if (string.IsNullOrWhiteSpace(item.c))
|
||
{
|
||
continue;
|
||
}
|
||
var dto = new StockPoolDto
|
||
{
|
||
CheckStatus = 99,
|
||
PageNum = 1,
|
||
PageSize = 100,
|
||
StockCode = item.c,
|
||
Status = 0
|
||
};
|
||
var json = JsonConvert.SerializeObject(dto, Formatting.Indented, new JsonSerializerSettings
|
||
{
|
||
NullValueHandling = NullValueHandling.Ignore,
|
||
ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver()
|
||
});
|
||
var response = StockHttpHelper.PostAjaxData($"{stockUrl}", json, authorization, true);
|
||
Log.Information($"stock {response}");
|
||
var data = JsonConvert.DeserializeObject<StockPoolResult<StockPoolResultRow>>(response);
|
||
if (data.Total <= 0)
|
||
{
|
||
errMsg.Add(item.n);
|
||
}
|
||
}
|
||
}
|
||
return errMsg;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据id更新CmsNews类中的是否上传,上传时间字段。
|
||
/// </summary>
|
||
/// <param name="dto"></param>
|
||
/// <returns></returns>
|
||
/// <exception cref="ApiException"></exception>
|
||
public async Task<bool> Upload(UploadCmsNewDto dto)
|
||
{
|
||
var departments = await _departmentDomain.GetDeptments();
|
||
var entity = await _repository.GetRepository<CmsNews>().Query().FirstOrDefaultAsync(x => x.Id == dto.Id);
|
||
if (entity == null) throw new ApiException("文案不存在");
|
||
if (entity.IsUpload.HasValue && entity.IsUpload.Value && (entity.Status == CmsNewStatus.未审核 || entity.Status == CmsNewStatus.通过))
|
||
{
|
||
throw new ApiException("文案已上传,请勿重复上传!");
|
||
}
|
||
var cmsNewsLog = new CmsNewsLog
|
||
{
|
||
CTime = DateTime.Now,
|
||
Att = entity.Att,
|
||
Content = entity.Content,
|
||
Deptcode = entity.Deptcode,
|
||
Newid = entity.Id,
|
||
NewsType = entity.NewsType,
|
||
OpName = dto.Uploader,
|
||
OpUser = dto.UploaderId,
|
||
Remark = entity.Remark,
|
||
Status = entity.Status,
|
||
Title = entity.Title,
|
||
Channel = entity.Channel,
|
||
Author = entity.Author,
|
||
Channels = entity.Channels,
|
||
DepartmentId = entity.DepartmentId,
|
||
Attachment = entity.Status == CmsNewStatus.未审核 ? entity.Attachment : null,
|
||
Reason = entity.Status == CmsNewStatus.未审核 ? entity.Reason : null,
|
||
UploadName = entity.UploadName,
|
||
};
|
||
if (entity.Status == CmsNewStatus.未审核)
|
||
{
|
||
cmsNewsLog.OpEvent = "提交";
|
||
}
|
||
else
|
||
{
|
||
cmsNewsLog.OpEvent = "重提交";
|
||
}
|
||
entity.UploadName = dto.Uploader;
|
||
entity.UploaderId = dto.UploaderId;
|
||
entity.IsUpload = true;
|
||
entity.UploadTime = DateTime.Now;
|
||
entity.UpdateTime = DateTime.Now;
|
||
entity.Updator = dto.Uploader;
|
||
entity.Status = CmsNewStatus.未审核;
|
||
var transaction = await _repository.BeginTransactionAsync();
|
||
try
|
||
{
|
||
entity = await _repository.GetRepository<CmsNews>().UpdateAsync(entity, x => new
|
||
{
|
||
x.IsUpload,
|
||
x.UploadTime,
|
||
x.UploadName,
|
||
x.UploaderId,
|
||
x.UpdateTime,
|
||
x.Updator
|
||
});
|
||
await _repository.GetRepository<CmsNewsLog>().InsertAsync(cmsNewsLog);
|
||
await transaction.CommitAsync();
|
||
var fromer = entity.CreateUserName;
|
||
foreach (var deptment in departments)
|
||
{
|
||
foreach (var deptmentCampain in deptment?.DeptmentCampains ?? new List<DeptmentCampainDto>())
|
||
{
|
||
if (entity.Channel >= deptmentCampain.StartCampainId && entity.Channel <= deptmentCampain.EndCampainId)
|
||
{
|
||
fromer = deptment?.Title;
|
||
}
|
||
}
|
||
}
|
||
var pass = await JustStock(entity);
|
||
if (pass)
|
||
{
|
||
await _csvrMessageDomain.PushNewsMsg(new PushNewsMsgDto
|
||
{
|
||
Companycode = entity.Deptcode,
|
||
Fromer = fromer,
|
||
Msgcode = "WASH",
|
||
Title = $"文案【{entity.Title}】已经【提交】,请您审核!",
|
||
Param = null
|
||
});
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
await transaction.RollbackAsync();
|
||
await transaction.DisposeAsync();
|
||
Log.Error(ex, "提交文案审核报错!");
|
||
throw new ApiException(ex.Message);
|
||
}
|
||
return entity != null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据AuditCmsNewsDto更新CmsNews类。
|
||
/// </summary>
|
||
/// <param name="dto"></param>
|
||
/// <returns></returns>
|
||
/// <exception cref="ApiException"></exception>
|
||
public async Task<bool> Audit(AuditCmsNewsDto dto)
|
||
{
|
||
var entity = await _repository.GetRepository<CmsNews>().Query().FirstOrDefaultAsync(x => x.Id == dto.Id);
|
||
if (entity == null) throw new ApiException("文案不存在");
|
||
entity.Reason = dto.Status == CmsNewStatus.通过 ? null : dto.Reason;
|
||
entity.Status = dto.Status;
|
||
entity.Auditer = dto.Auditer;
|
||
entity.AuditerName = dto.AuditerName;
|
||
entity.AuditRemark = dto.AuditRemark;
|
||
entity.StatusTime = DateTime.Now;
|
||
entity.Attachment = dto.Attachment;
|
||
var cmsNewsLog = new CmsNewsLog
|
||
{
|
||
CTime = DateTime.Now,
|
||
Att = entity.Att,
|
||
Content = entity.Content,
|
||
Deptcode = entity.Deptcode,
|
||
Newid = entity.Id,
|
||
NewsType = entity.NewsType,
|
||
OpName = dto.AuditerName,
|
||
OpUser = dto.Auditer,
|
||
Remark = entity.Remark,
|
||
Status = entity.Status,
|
||
CheckRemark = entity.AuditRemark,
|
||
Title = entity.Title,
|
||
Channel = entity.Channel,
|
||
Author = entity.Author,
|
||
Channels = entity.Channels,
|
||
DepartmentId = entity.DepartmentId,
|
||
Attachment = entity.Attachment,
|
||
Reason = entity.Reason,
|
||
OpEvent = dto.Status == CmsNewStatus.通过 ? "通过审核" : "驳回"
|
||
};
|
||
var transaction = await _repository.BeginTransactionAsync();
|
||
try
|
||
{
|
||
entity = await _repository.GetRepository<CmsNews>().UpdateAsync(entity, x => new
|
||
{
|
||
x.Reason,
|
||
x.Status,
|
||
x.Auditer,
|
||
x.AuditerName,
|
||
x.AuditRemark,
|
||
x.StatusTime,
|
||
x.Attachment
|
||
});
|
||
await _repository.GetRepository<CmsNewsLog>().InsertAsync(cmsNewsLog);
|
||
await transaction.CommitAsync();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
await transaction.RollbackAsync();
|
||
await transaction.DisposeAsync();
|
||
Log.Error(ex, "提交文案审核报错!");
|
||
throw new ApiException(ex.Message);
|
||
}
|
||
return entity != null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 删除文案审核
|
||
/// </summary>
|
||
/// <param name="dto"></param>
|
||
/// <returns></returns>
|
||
/// <exception cref="ApiException"></exception>
|
||
public async Task<bool> Delete(DelCmsNewsDto dto)
|
||
{
|
||
var entity = await _repository.GetRepository<CmsNews>().Query().FirstOrDefaultAsync(x => x.Id == dto.Id);
|
||
if (entity == null) throw new ApiException("文案不存在");
|
||
entity.Isdelete =1;
|
||
entity.DeleteUser = dto.DelUsername;
|
||
entity.DeleteTime = DateTime.Now;
|
||
var transaction = await _repository.BeginTransactionAsync();
|
||
try
|
||
{
|
||
entity = await _repository.GetRepository<CmsNews>().UpdateAsync(entity, x => new
|
||
{
|
||
x.Isdelete,
|
||
x.DeleteUser,
|
||
x.DeleteTime
|
||
});
|
||
await transaction.CommitAsync();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
await transaction.RollbackAsync();
|
||
await transaction.DisposeAsync();
|
||
Log.Error(ex, "文案删除失败!");
|
||
throw new ApiException(ex.Message);
|
||
}
|
||
return entity != null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据id获取CmsNews类。
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
/// <exception cref="ApiException"></exception>
|
||
public async Task<CmsNewsDto> GetCmsNews(int id)
|
||
{
|
||
var entity = await _repository.GetRepository<CmsNews>().Query().FirstOrDefaultAsync(x => x.Id == id);
|
||
if (entity == null) throw new ApiException("文案不存在");
|
||
var dto = _mapper.Map<CmsNews, CmsNewsDto>(entity);
|
||
var departments = await _departmentDomain.GetDeptments();
|
||
var dept = departments.FirstOrDefault(x => x.DepartmentId == dto.DepartmentId);
|
||
if (dept != null)
|
||
{
|
||
dto.DeptName = dept.Title;
|
||
}
|
||
return dto;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 搜索CmsNews类分页。
|
||
/// </summary>
|
||
/// <param name="dto"></param>
|
||
/// <returns></returns>
|
||
public async Task<PageResult<CmsNewsDto>> SearchCmsNews(SearchCmsNewsDto dto)
|
||
{
|
||
var departments = await _departmentDomain.GetDeptments();
|
||
var companys = await _cacheDomain.GetCompanyVirtualList();
|
||
var reasons = GetReasonForRejectionNew();
|
||
var companyCode = "";
|
||
if (!string.IsNullOrEmpty(dto.Appid))
|
||
{
|
||
var department = departments.FirstOrDefault(x => x.Appid == dto.Appid);
|
||
if (department != null)
|
||
{
|
||
companyCode = department.CompanyCode;
|
||
}
|
||
}
|
||
|
||
var query = _repository.GetRepository<CmsNews>().Query().Where(m=>m.Isdelete==0)
|
||
.If(!string.IsNullOrEmpty(companyCode), x => x.Where(x => x.Companycode == companyCode))
|
||
.If(dto.Status != null, x => x.Where(x => x.Status == dto.Status))
|
||
.If(dto.IsUpload != null, x => x.Where(x => x.IsUpload == dto.IsUpload))
|
||
.If(!string.IsNullOrEmpty(dto.Deptcode), x => x.Where(x => x.Deptcode == dto.Deptcode))
|
||
.If(!string.IsNullOrEmpty(dto.NewsType), x => x.Where(x => x.NewsType == dto.NewsType))
|
||
.If(!string.IsNullOrEmpty(dto.Title), x => x.Where(x => x.Title.Contains(dto.Title)))
|
||
.If(!string.IsNullOrEmpty(dto.Context), x => x.Where(x => x.Remark.Contains(dto.Context)))
|
||
.If(dto.Reason != null, x => x.Where(x => (dto.Reason & x.Reason) > 0))
|
||
.If(!string.IsNullOrEmpty(dto.Uploader), x => x.Where(x => x.UploadName.Contains(dto.Uploader)))
|
||
.If(!string.IsNullOrEmpty(dto.Updator), x => x.Where(x => x.Updator.Contains(dto.Uploader)))
|
||
.If(!string.IsNullOrEmpty(dto.Title), x => x.Where(x => x.Title.Contains(dto.Title)))
|
||
.If(!string.IsNullOrEmpty(dto.Remark), x => x.Where(x => x.Remark.Contains(dto.Remark)))
|
||
.If(!string.IsNullOrEmpty(dto.CreateUserName), x => x.Where(x => x.CreateUserName.Contains(dto.CreateUserName)))
|
||
.If(!string.IsNullOrEmpty(dto.AuditerName), x => x.Where(x => x.AuditerName.Contains(dto.AuditerName)))
|
||
.If(dto.AuditTimeFrom != null, x => x.Where(x => x.StatusTime > dto.AuditTimeFrom))
|
||
.If(dto.AuditTimeTo != null, x => x.Where(x => x.StatusTime <= dto.AuditTimeTo.Value.AddDays(1).AddMilliseconds(-1)))
|
||
.If(dto.UpdateTimeFrom != null, x => x.Where(x => x.UpdateTime > dto.UpdateTimeFrom))
|
||
.If(dto.UpdateTimeTo != null, x => x.Where(x => x.UpdateTime <= dto.UpdateTimeTo.Value.AddDays(1).AddMilliseconds(-1)))
|
||
.If(dto.NewsStartTime != null, x => x.Where(x => x.UploadTime > dto.NewsStartTime))
|
||
.If(dto.NewsEndTime != null, x => x.Where(x => x.UploadTime <= dto.NewsEndTime.Value.AddDays(1).AddMilliseconds(-1)))
|
||
.If(dto.AuditStartTime != null, x => x.Where(x => x.StatusTime > dto.AuditStartTime))
|
||
.If(dto.AuditEndTime != null, x => x.Where(x => x.StatusTime <= dto.AuditEndTime.Value.AddDays(1).AddMilliseconds(-1)));
|
||
var where = PredicateExtensionses.True<CmsNews>();
|
||
if (!string.IsNullOrWhiteSpace(dto.DepartmentId))
|
||
{
|
||
var deptids = dto.DepartmentId.Split(",").Select(n => Convert.ToInt32(n)).ToList();
|
||
query = query.Where(n => n.DepartmentId.HasValue && deptids.Contains(n.DepartmentId.Value));
|
||
}
|
||
if (!string.IsNullOrEmpty(dto.Channel))
|
||
{
|
||
var arr0 = dto.Channel.Split('|');
|
||
if (arr0.Length > 1)
|
||
{
|
||
var whereOr = PredicateExtensionses.False<CmsNews>();
|
||
foreach (var item in arr0)
|
||
{
|
||
var a = item.Split(',');
|
||
var min = Convert.ToInt32(a[0]);
|
||
var max = Convert.ToInt32(a[1]);
|
||
whereOr = whereOr.Or(m => m.Channel >= min && m.Channel <= max);
|
||
}
|
||
where = where.And(whereOr);
|
||
}
|
||
else
|
||
{
|
||
var arr = dto.Channel.Split(',');
|
||
var min = Convert.ToInt32(arr[0]);
|
||
var max = Convert.ToInt32(arr[1]);
|
||
where = where.And(m => m.Channel >= min && m.Channel <= max);
|
||
}
|
||
}
|
||
query = query.Where(where);
|
||
var total = await query.CountAsync();
|
||
var list = await query.OrderByDescending(x => x.CTime)
|
||
.Skip((dto.PageIndex - 1) * dto.PageSize)
|
||
.Take(dto.PageSize)
|
||
.ToListAsync();
|
||
var data = _mapper.Map<CmsNews, CmsNewsDto>(list);
|
||
foreach (var item in data)
|
||
{
|
||
var dept = departments.FirstOrDefault(x => x.DepartmentId == item.DepartmentId);
|
||
if (dept != null)
|
||
{
|
||
item.DeptName = dept.Title;
|
||
}
|
||
var reasonList = new List<string>();
|
||
foreach (var reason in reasons)
|
||
{
|
||
if ((reason.Key & item.Reason) > 0)
|
||
{
|
||
reasonList.Add(reason.Value);
|
||
}
|
||
}
|
||
item.ReasonStr = string.Join(",", reasonList);
|
||
}
|
||
var result = new PageResult<CmsNewsDto>(dto.PageIndex, dto.PageSize, total, data);
|
||
return result;
|
||
}
|
||
|
||
public async Task<List<CmsNewsLogDto>> GetCmsNewsLogs(int id)
|
||
{
|
||
var logs = await _repository.GetRepository<CmsNewsLog>().Query().Where(x => x.Newid == id).ToListAsync();
|
||
var data = _mapper.Map<CmsNewsLog, CmsNewsLogDto>(logs);
|
||
var departments = await _departmentDomain.GetDeptments();
|
||
var reasons = GetReasonForRejectionNew();
|
||
foreach (var item in data)
|
||
{
|
||
var dept = departments.FirstOrDefault(x => x.DepartmentId == item.DepartmentId);
|
||
if (dept != null)
|
||
{
|
||
item.DeptName = dept.Title;
|
||
}
|
||
var reasonList = new List<string>();
|
||
foreach (var reason in reasons)
|
||
{
|
||
if ((reason.Key & item.Reason) > 0)
|
||
{
|
||
reasonList.Add(reason.Value);
|
||
}
|
||
}
|
||
item.ReasonStr = string.Join(",", reasonList);
|
||
}
|
||
return data;
|
||
}
|
||
|
||
public async Task SyncCmsNews()
|
||
{
|
||
var now = DateTime.Now.AddYears(-7);
|
||
var departments = await _departmentDomain.GetDeptmentAll();
|
||
var data = await _repository.GetRepository<CmsNews>().Query()
|
||
.Where(x => x.DepartmentId == null && x.Channel != null)
|
||
.ToListAsync();
|
||
var updateData = new List<CmsNews>();
|
||
var logs = await _repository.GetRepository<CmsNewsLog>().Query()
|
||
.Where(x => x.DepartmentId == null && x.Channel != null && x.CTime > now)
|
||
.ToListAsync();
|
||
var updateLogs = new List<CmsNewsLog>();
|
||
foreach (var item in data)
|
||
{
|
||
foreach (var deptment in departments)
|
||
{
|
||
foreach (var deptmentCampain in deptment?.DeptmentCampains ?? new List<DeptmentCampainDto>())
|
||
{
|
||
if (item.Channel >= deptmentCampain.StartCampainId && item.Channel <= deptmentCampain.EndCampainId)
|
||
{
|
||
item.DepartmentId = deptment?.DepartmentId;
|
||
if (item.DepartmentId == 45) item.DepartmentId = 49;
|
||
updateData.Add(item);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
foreach (var item in logs)
|
||
{
|
||
foreach (var deptment in departments)
|
||
{
|
||
foreach (var deptmentCampain in deptment?.DeptmentCampains ?? new List<DeptmentCampainDto>())
|
||
{
|
||
if (item.Channel >= deptmentCampain.StartCampainId && item.Channel <= deptmentCampain.EndCampainId)
|
||
{
|
||
item.DepartmentId = deptment?.DepartmentId;
|
||
if (item.DepartmentId == 45) item.DepartmentId = 49;
|
||
updateLogs.Add(item);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (data.Any())
|
||
{
|
||
await _repository.GetRepository<CmsNews>().BatchUpdateAsync(updateData, x => new
|
||
{
|
||
x.DepartmentId
|
||
});
|
||
}
|
||
if (logs.Any())
|
||
{
|
||
await _repository.GetRepository<CmsNewsLog>().BatchUpdateAsync(updateLogs, x => new
|
||
{
|
||
x.DepartmentId
|
||
});
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新未审核状态
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public async Task SyncCmsNews2()
|
||
{
|
||
var now = DateTime.Now.AddDays(-7);
|
||
var data = await _repository.GetRepository<CmsNews>().Query()
|
||
.Where(x => x.Status == 0 && x.CTime < now)
|
||
.ToListAsync();
|
||
var updateData = new List<CmsNews>();
|
||
var logs = new List<CmsNewsLog>();
|
||
foreach (var item in data)
|
||
{
|
||
item.Status = CmsNewStatus.通过;
|
||
item.AuditerName = await _repository.GetRepository<CmsNews>().Query()
|
||
.Where(x => x.DepartmentId == item.DepartmentId && !string.IsNullOrEmpty(x.AuditerName))
|
||
.Select(x => x.AuditerName)
|
||
.FirstOrDefaultAsync();
|
||
item.StatusTime = item.CTime.AddHours(2);
|
||
logs.Add(new CmsNewsLog
|
||
{
|
||
DepartmentId = item.DepartmentId,
|
||
Deptcode = item.Deptcode,
|
||
Att = item.Att,
|
||
Attachment = item.Attachment,
|
||
Author = item.Author,
|
||
Channel = item.Channel,
|
||
CTime = item.StatusTime.Value,
|
||
Newid = item.Id,
|
||
OpName = item.AuditerName,
|
||
Status = item.Status,
|
||
Title = item.Title,
|
||
NewsType = item.NewsType,
|
||
Channels = item.Channels,
|
||
Content = item.Content
|
||
});
|
||
}
|
||
|
||
if (data.Any())
|
||
{
|
||
await _repository.GetRepository<CmsNews>().BatchUpdateAsync(updateData, x => new
|
||
{
|
||
x.Status,
|
||
x.AuditerName,
|
||
x.StatusTime
|
||
});
|
||
}
|
||
if (logs.Any())
|
||
{
|
||
await _repository.GetRepository<CmsNewsLog>().BatchInsertAsync(logs);
|
||
}
|
||
}
|
||
|
||
public async Task SyncNews()
|
||
{
|
||
var data = await _repository.GetRepository<CmsNews>().Query()
|
||
.Where(x => x.Status == CmsNewStatus.未通过 && x.Reason != null).ToListAsync();
|
||
var reasons = GetReasonForRejection().ToList();
|
||
foreach (var item in data)
|
||
{
|
||
var reason = 0;
|
||
if ((reasons[0].Key & item.Reason) > 0 ||
|
||
(reasons[1].Key & item.Reason) > 0)
|
||
reason += 1 << 0;
|
||
if ((reasons[2].Key & item.Reason) > 0 ||
|
||
(reasons[6].Key & item.Reason) > 0)
|
||
reason += 1 << 2;
|
||
if ((reasons[5].Key & item.Reason) > 0 ||
|
||
(reasons[10].Key & item.Reason) > 0 ||
|
||
(reasons[11].Key & item.Reason) > 0)
|
||
reason += 1 << 12;
|
||
item.Reason = reason;
|
||
}
|
||
var logData = await _repository.GetRepository<CmsNewsLog>().Query()
|
||
.Where(x => x.Status == CmsNewStatus.未通过 && x.Reason != null).ToListAsync();
|
||
foreach (var item in logData)
|
||
{
|
||
var reason = 0;
|
||
if ((reasons[0].Key & item.Reason) > 0 ||
|
||
(reasons[1].Key & item.Reason) > 0)
|
||
reason += 1 << 0;
|
||
if ((reasons[2].Key & item.Reason) > 0 ||
|
||
(reasons[6].Key & item.Reason) > 0)
|
||
reason += 1 << 2;
|
||
if ((reasons[5].Key & item.Reason) > 0 ||
|
||
(reasons[10].Key & item.Reason) > 0 ||
|
||
(reasons[11].Key & item.Reason) > 0)
|
||
reason += 1 << 12;
|
||
item.Reason = reason;
|
||
}
|
||
await _repository.GetRepository<CmsNews>().BatchUpdateAsync(data, x => new { x.Reason });
|
||
await _repository.GetRepository<CmsNewsLog>().BatchUpdateAsync(logData, x => new { x.Reason });
|
||
}
|
||
|
||
private static Dictionary<int, string> GetReasonForRejection()
|
||
{
|
||
Dictionary<int, string> reason = new()
|
||
{
|
||
{ 1 << 0, "无风险提示" },
|
||
{ 1 << 1, "无投顾信息" },
|
||
{ 1 << 2, "缺失证明材料、理由依据" },
|
||
{ 1 << 3, "投顾人员未报备" },
|
||
{ 1 << 4, "统计数据错误" },
|
||
{ 1 << 5, "图文不一致" },
|
||
{ 1 << 6, "使用敏感词" },
|
||
{ 1 << 7, "涉嫌指导操作" },
|
||
{ 1 << 8, "涉嫌保证收益" },
|
||
{ 1 << 9, "涉嫌夸大虚假宣传" },
|
||
{ 1 << 10, "内容重复提交" },
|
||
{ 1 << 11, "提交内容空白" },
|
||
{ 1 << 13, "无投顾资质展业" },
|
||
{ 1 << 12, "其他" }
|
||
};
|
||
return reason;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 需求:合规文案驳回理由替换
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public Dictionary<int, string> GetReasonForRejectionNew()
|
||
{
|
||
Dictionary<int, string> reason = new()
|
||
{
|
||
{ 1 << 0, "营销宣传不规范" },
|
||
{ 1 << 2, "营销宣传违规用语" },
|
||
{ 1 << 3, "未事前报备" },
|
||
{ 1 << 4, "误导性宣传" },
|
||
{ 1 << 7, "代客理财" },
|
||
{ 1 << 8, "保收担损" },
|
||
{ 1 << 9, "虚假宣传" },
|
||
{ 1 << 13, "违规展业" },
|
||
{ 1 << 14, "违规荐股" },
|
||
{ 1 << 15, "贬低同事或同行" },
|
||
{ 1 << 12, "其他" },
|
||
};
|
||
return reason;
|
||
}
|
||
}
|
||
} |