You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
316 lines
12 KiB
C#
316 lines
12 KiB
C#
using Common.DJYModel;
|
|
using Common.Extensions;
|
|
using Common.Utilities;
|
|
using djy.IService.Report;
|
|
using djy.Model.Report;
|
|
using djy.Model.ReportDto;
|
|
|
|
using djy.Service.DjyService;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace djy.Service.Report
|
|
{
|
|
public class ReportService : ServBase, IReportService
|
|
{
|
|
//#region 获取模板
|
|
//public List<DS_ReportTemplate> GetTemplate()
|
|
//{
|
|
// try
|
|
// {
|
|
// var List = DbBus.Get(DbList.DSDB).Select<DS_ReportTemplate>().ToList();
|
|
// return List;
|
|
// }
|
|
// catch (Exception e)
|
|
// {
|
|
// throw;
|
|
// }
|
|
//}
|
|
//#endregion
|
|
|
|
#region 列表
|
|
public TableData Load(User user)
|
|
{
|
|
var result = new TableData();
|
|
|
|
var templist = DbBus.Get(DbList.DSDB).Select<DS_ReportTemplate>().ToList();
|
|
if (user.CompId != null) {
|
|
List<ReportDto> query = DbBus.Get(DbList.DSDB).Select<DS_ReportTemplate, DS_Report>().LeftJoin((temp, main) => main.TemplateID == temp.GID).
|
|
Where(x => x.t2.CompID == user.CompId).ToList((temp, main) => new ReportDto
|
|
{
|
|
GID = main.GID,
|
|
UserID = main.UserID,
|
|
UserName = main.UserName,
|
|
CompID = main.CompID,
|
|
CompName = main.CompName,
|
|
TemplateID = main.TemplateID,
|
|
TemplateName = temp.TemplateName,
|
|
TemplateDescribe = temp.TemplateDescribe,
|
|
IsBook = main.IsBook,
|
|
IsWechat = main.IsWechat,
|
|
IsEmail = main.IsEmail,
|
|
DJson = main.DJson,
|
|
EndTime = main.EndTime,
|
|
CreateTime = main.CreateTime,
|
|
TemplateType = temp.TemplateType
|
|
}).ToList();
|
|
|
|
foreach (var item in templist)
|
|
{
|
|
var it = query.Where(x => x.TemplateID == item.GID).FirstOrDefault();
|
|
if (it == null)
|
|
{
|
|
query.Add(new ReportDto
|
|
{
|
|
GID = null,
|
|
UserID = user.GID,
|
|
UserName = user.SHOWNAME,
|
|
CompID = user.CompId,
|
|
CompName = user.COMNAME,
|
|
TemplateID = item.GID,
|
|
TemplateName = item.TemplateName,
|
|
TemplateDescribe = item.TemplateDescribe,
|
|
IsBook = null,
|
|
IsWechat = null,
|
|
IsEmail = null,
|
|
DJson = null,
|
|
EndTime = null,
|
|
CreateTime = DateTime.Now,
|
|
TemplateType = item.TemplateType
|
|
});
|
|
}
|
|
}
|
|
|
|
result.data = query;
|
|
result.count = (int)query.Count();
|
|
}
|
|
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
#region 新增编辑
|
|
public string SaveInfo(DS_Report dto, User user)
|
|
{
|
|
string guid = dto.GID;
|
|
var list = DbBus.Get(DbList.DSDB).Select<DS_Report>().WhereIf(dto.GID != null, x => x.GID != dto.GID).
|
|
Where(x => x.IsDel != true && x.TemplateID == dto.TemplateID && x.CompID == user.Comid).ToOne();
|
|
if (list != null)
|
|
{
|
|
return "-1";
|
|
}
|
|
if (dto.GID.IsNull())
|
|
{
|
|
DS_Report report = dto.MapTo<DS_Report>();
|
|
report.GID = Guid.NewGuid().ToString("N");
|
|
report.UserID = user.GID;
|
|
report.UserName = user.SHOWNAME;
|
|
report.CompID = user.CompId;
|
|
report.CompName = user.COMNAME;
|
|
report.IsBook = false;
|
|
report.IsEmail = false;
|
|
report.IsDel = false;
|
|
report.CreateTime = DateTime.Now;
|
|
report.LastUpdate = DateTime.Now;
|
|
DbBus.Get(DbList.DSDB).Insert(report).ExecuteAffrows();
|
|
guid = report.GID;
|
|
}
|
|
else
|
|
{
|
|
DbBus.Get(DbList.DSDB).Update<DS_Report>().Set(w => new DS_Report
|
|
{
|
|
TemplateID = dto.TemplateID,
|
|
IsBook = dto.IsBook,
|
|
IsEmail=dto.IsEmail,
|
|
DJson=dto.DJson,
|
|
LastUpdate = DateTime.Now,
|
|
LastUserId=user.GID
|
|
}).Where(w => w.GID == dto.GID).ExecuteAffrows();
|
|
}
|
|
return guid;
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 取消订阅/订阅
|
|
|
|
public Response IsBook(string Gid,string TemplateId, bool isbook,string DJson, User user) {
|
|
var result = new Response();
|
|
if (isbook) {
|
|
if (Gid.IsNull())
|
|
{
|
|
DS_Report report = new DS_Report();
|
|
report.GID = Guid.NewGuid().ToString("N");
|
|
report.UserID = user.GID;
|
|
report.UserName = user.SHOWNAME;
|
|
report.CompID = user.CompId;
|
|
report.CompName = user.COMNAME;
|
|
report.IsDel = false;
|
|
report.TemplateID = TemplateId;
|
|
report.CreateTime = DateTime.Now;
|
|
report.LastUpdate = DateTime.Now;
|
|
DbBus.Get(DbList.DSDB).Insert(report).ExecuteAffrows();
|
|
Gid = report.GID;
|
|
}
|
|
|
|
if (DbBus.Get(DbList.DSDB).Select<DS_Report>().Where(x => x.GID==Gid).ToOne().IsBook==true) {
|
|
result.Code = 201;
|
|
result.Message = "该模板已经订阅过了";
|
|
return result;
|
|
}
|
|
var endtime = DbBus.Get(DbList.DSDB).Select<DS_Report>().Where(x => x.GID == Gid).ToOne().EndTime;
|
|
if (endtime != null&& endtime>DateTime.Now) {
|
|
|
|
DbBus.Get(DbList.DSDB).Update<DS_Report>().Set(w => new DS_Report
|
|
{
|
|
IsBook = true,
|
|
IsEmail = true,
|
|
DJson = DJson,
|
|
LastUpdate = DateTime.Now,
|
|
LastUserId = user.GID
|
|
}).Where(w => w.GID == Gid).ExecuteAffrows();
|
|
|
|
result.Code = 200;
|
|
result.Message = "订阅成功!";
|
|
return result;
|
|
}
|
|
////订阅
|
|
var fin = new FinanceService();
|
|
var templist = DbBus.Get(DbList.DSDB).Select<DS_ReportTemplate>().
|
|
Where(x => x.GID==TemplateId).ToOne();
|
|
var getfinrs = fin.Expend(new CustFee
|
|
{
|
|
SENDUSERID = user.GID,
|
|
LURURENID = user.GID,
|
|
MBLNO= "1",
|
|
CtnrCount = 1,
|
|
CtnrInfo = string.Empty,
|
|
BSTYPE = 17,
|
|
SENDTYPE = templist.SendType,
|
|
BSNO = Gid,
|
|
}, 0);
|
|
if (!getfinrs.Status)
|
|
{
|
|
result.Code = 201;
|
|
result.Message = getfinrs.Message;
|
|
return result;
|
|
|
|
}
|
|
DbBus.Get(DbList.DSDB).Update<DS_Report>().Set(w => new DS_Report
|
|
{
|
|
IsBook = true,
|
|
IsEmail=true,
|
|
DJson=DJson,
|
|
EndTime=DateTime.Now.AddMonths(1),
|
|
LastUpdate = DateTime.Now,
|
|
LastUserId = user.GID
|
|
}).Where(w => w.GID ==Gid).ExecuteAffrows();
|
|
fin.Expend(new CustFee
|
|
{
|
|
SENDUSERID = user.GID,
|
|
LURURENID = user.GID,
|
|
MBLNO = "1",
|
|
CtnrCount = 1,
|
|
CtnrInfo = string.Empty,
|
|
BSTYPE = 17,
|
|
SENDTYPE = templist.SendType,
|
|
BSNO = Gid,
|
|
}, 1);
|
|
result.Code = 200;
|
|
result.Message = "订阅成功!";
|
|
return result;
|
|
}
|
|
else {
|
|
DbBus.Get(DbList.DSDB).Update<DS_Report>().Set(w => new DS_Report
|
|
{
|
|
IsBook = false,
|
|
LastUpdate = DateTime.Now,
|
|
LastUserId = user.GID
|
|
}).Where(w => w.GID == Gid).ExecuteAffrows();
|
|
result.Code = 200;
|
|
result.Message = "取消成功!";
|
|
return result;
|
|
}
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
#region 定时任务
|
|
public void TemplateTask() {
|
|
try
|
|
{
|
|
_LogsAdd("TemplateTask", "post", $"报表定时任务开始");
|
|
///获取所有订阅过的用户
|
|
var datetime = DateTime.Now.AddDays(-1);
|
|
var list = DbBus.Get(DbList.DSDB).Select<DS_Report>().Where(x => x.IsBook == true && x.EndTime < datetime).ToList();
|
|
var templist = DbBus.Get(DbList.DSDB).Select<DS_ReportTemplate>().ToList();
|
|
var fin = new FinanceService();
|
|
foreach (var item in list)
|
|
{
|
|
var getfinrs = fin.Expend(new CustFee
|
|
{
|
|
SENDUSERID = item.UserID,
|
|
LURURENID = item.UserID,
|
|
MBLNO = "1",
|
|
CtnrCount = 1,
|
|
CtnrInfo = string.Empty,
|
|
BSTYPE = 17,
|
|
SENDTYPE = templist.Where(x => x.GID == item.TemplateID).Select(x => x.SendType).FirstOrDefault(), ////templist.SendType,
|
|
BSNO = item.GID,
|
|
}, 0);
|
|
if (!getfinrs.Status)
|
|
{
|
|
///扣费失败 ,更改状态
|
|
var date = DateTime.Now;
|
|
if (item.EndTime<date) {
|
|
DbBus.Get(DbList.DSDB).Update<DS_Report>().Set(w => new DS_Report
|
|
{
|
|
IsBook = false,
|
|
}).Where(w => w.GID == item.GID).ExecuteAffrows();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
////余额充足 ,执行扣费,
|
|
fin.Expend(new CustFee
|
|
{
|
|
SENDUSERID = item.UserID,
|
|
LURURENID = item.UserID,
|
|
MBLNO = "1",
|
|
CtnrCount = 1,
|
|
CtnrInfo = string.Empty,
|
|
BSTYPE = 17,
|
|
SENDTYPE = templist.Where(x => x.GID == item.TemplateID).Select(x => x.SendType).FirstOrDefault(), ////templist.SendType,
|
|
BSNO = item.GID,
|
|
}, 1);
|
|
|
|
DbBus.Get(DbList.DSDB).Update<DS_Report>().Set(w => new DS_Report
|
|
{
|
|
EndTime = Convert.ToDateTime(w.EndTime).AddMonths(1),///修改截止日期
|
|
LastUpdate = DateTime.Now,
|
|
LastUserId = item.GID
|
|
}).Where(w => w.GID == item.GID).ExecuteAffrows();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex) {
|
|
|
|
Exception excep = ex;
|
|
while (excep != null)
|
|
{
|
|
_LogsAdd("TemplateTask", "post", $"报表定时任务:{excep.Message}{excep.StackTrace}");
|
|
excep = excep.InnerException;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
}
|
|
}
|