Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mall.oytour.com
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄奎
mall.oytour.com
Commits
998561c8
Commit
998561c8
authored
Jun 16, 2020
by
吴春
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交代码
parent
8f344ff1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
231 additions
and
10 deletions
+231
-10
LogHelper.cs
Mall.WindowsService/Helper/LogHelper.cs
+99
-0
PathHelper.cs
Mall.WindowsService/Helper/PathHelper.cs
+94
-0
TimersHelper.cs
Mall.WindowsService/Helper/TimersHelper.cs
+2
-2
CommandModel.cs
Mall.WindowsService/Model/CommandModel.cs
+27
-0
FinanceModule.cs
Mall.WindowsService/Module/FinanceModule.cs
+6
-5
WindowsService.cs
Mall.WindowsService/WindowsService.cs
+3
-3
No files found.
Mall.WindowsService/Helper/LogHelper.cs
0 → 100644
View file @
998561c8
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Text
;
namespace
Mall.WindowsService.Helper
{
/// <summary>
/// 日志帮助类
/// </summary>
public
class
LogHelper
{
/// <summary>
/// 防止多线程
/// </summary>
private
static
object
objlock
=
new
object
();
public
static
string
filepath
=
string
.
Format
(
@"{0}\Log"
,
PathHelper
.
RootPath
);
/// <summary>
/// 创建文件夹
/// </summary>
/// <param name="path"></param>
private
static
void
CreateDirectory
(
string
path
)
{
//创建文件夹
if
(!
Directory
.
Exists
(
path
))
{
Directory
.
CreateDirectory
(
path
);
}
}
/// <summary>
/// 写日志
/// </summary>
/// <param name="message">日志信息</param>
/// <returns></returns>
public
static
void
Write
(
string
message
)
{
CreateDirectory
(
filepath
);
string
FileName
=
string
.
Format
(
@"{0}\{1}.txt"
,
filepath
,
DateTime
.
Now
.
ToString
(
"yyyyMMdd"
));
lock
(
objlock
)
{
using
(
StreamWriter
sw
=
File
.
AppendText
(
FileName
))
{
sw
.
WriteLine
(
string
.
Format
(
@"DateTime:{0} "
,
DateTime
.
Now
.
ToString
()));
sw
.
WriteLine
(
string
.
Format
(
@"Message:{0}"
,
message
));
}
}
}
/// <summary>
/// 写日志
/// </summary>
/// <param name="exception">异常信息</param>
/// <param name="otherMsg">其他信息</param>
public
static
void
WriteLog
(
Exception
exception
,
string
otherMsg
=
""
)
{
CreateDirectory
(
filepath
);
string
str
=
""
;
try
{
str
+=
string
.
Format
(
@"
DateTime:{0}"
,
DateTime
.
Now
.
ToString
());
if
(
exception
!=
null
)
{
if
(
exception
.
InnerException
!=
null
)
{
exception
=
exception
.
InnerException
;
}
str
+=
string
.
Format
(
@"
Message:{0}
StackTrace:
{1}
Source:{2}
"
,
exception
.
Message
,
exception
.
StackTrace
,
exception
.
Source
);
}
str
+=
string
.
Format
(
@"
ExtMessage:{0}"
,
otherMsg
);
string
FileName
=
string
.
Format
(
@"{0}\{1}.txt"
,
filepath
,
DateTime
.
Now
.
ToString
(
"yyyyMMdd"
));
lock
(
objlock
)
{
StreamWriter
sw
=
new
StreamWriter
(
FileName
,
true
);
sw
.
WriteLine
(
str
);
sw
.
Close
();
}
}
catch
{
}
}
}
}
Mall.WindowsService/Helper/PathHelper.cs
0 → 100644
View file @
998561c8
using
Mall.WindowsService.Model
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json.Converters
;
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Reflection
;
using
System.Text
;
namespace
Mall.WindowsService.Helper
{
/// <summary>
/// 地址帮助类
/// </summary>
public
class
PathHelper
{
/// <summary>
/// 应用程序Bin目录
/// </summary>
public
static
string
RootPath
{
get
{
return
AppDomain
.
CurrentDomain
.
BaseDirectory
;
}
}
}
/// <summary>
/// 配置文件帮助类
/// </summary>
public
class
ConfigHelper
{
/// <summary>
/// 获取任务配置文件
/// </summary>
/// <returns></returns>
public
static
IList
<
CommandModel
>
GetTaskConfig
()
{
IList
<
CommandModel
>
list
=
new
List
<
CommandModel
>();
//加载接口配置文件
string
settingPath
=
PathHelper
.
RootPath
+
@"\task.json"
;
using
(
StreamReader
sr
=
new
StreamReader
(
settingPath
))
{
try
{
JsonSerializer
serializer
=
new
JsonSerializer
();
serializer
.
Converters
.
Add
(
new
JavaScriptDateTimeConverter
());
serializer
.
NullValueHandling
=
NullValueHandling
.
Ignore
;
//构建Json.net的读取流
JsonReader
reader
=
new
JsonTextReader
(
sr
);
//对读取出的Json.net的reader流进行反序列化,并装载到模型中
list
=
serializer
.
Deserialize
<
IList
<
CommandModel
>>(
reader
);
}
catch
(
Exception
ex
)
{
LogHelper
.
Write
(
"加载配置文件"
+
ex
.
Message
.
ToString
());
}
}
return
list
;
}
/// <summary>
/// 加载DLL文件
/// </summary>
/// <returns></returns>
public
static
Dictionary
<
string
,
object
>
LoadAssembly
()
{
Dictionary
<
string
,
object
>
assemblyDic
=
new
Dictionary
<
string
,
object
>();
string
path
=
PathHelper
.
RootPath
;
DirectoryInfo
directoryInfo
=
new
DirectoryInfo
(
path
);
if
(
directoryInfo
.
Exists
)
{
//搜索dll文件
FileInfo
[]
dllList
=
directoryInfo
.
GetFiles
(
"*.dll"
);
if
(!
object
.
Equals
(
dllList
,
null
)
&&
dllList
.
Length
>
0
)
{
foreach
(
var
item
in
dllList
)
{
AssemblyName
assemblyName
=
AssemblyName
.
GetAssemblyName
(
item
.
FullName
);
Assembly
ass
=
Assembly
.
Load
(
assemblyName
);
foreach
(
var
type
in
ass
.
ExportedTypes
)
{
string
fullName
=
type
.
FullName
;
assemblyDic
.
Add
(
fullName
,
type
);
}
}
}
}
return
assemblyDic
;
}
}
}
Mall.WindowsService/Helper/TimersHelper.cs
View file @
998561c8
...
...
@@ -19,12 +19,12 @@ namespace Mall.WindowsService.Helper
{
if
(
Interlocked
.
Exchange
(
ref
inTimer
,
1
)
==
0
)
{
LogHelper
.
Write
(
"
ClearOrder
=====Start"
);
LogHelper
.
Write
(
"
RevenueFinance
=====Start"
);
Module
.
FinanceModule
.
OrderIncomeFinanceModule
();
LogHelper
.
Write
(
"
ClearOrder
=====End"
);
LogHelper
.
Write
(
"
RevenueFinance
=====End"
);
Interlocked
.
Exchange
(
ref
inTimer
,
0
);
}
}
...
...
Mall.WindowsService/Model/CommandModel.cs
0 → 100644
View file @
998561c8
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
namespace
Mall.WindowsService.Model
{
/// <summary>
/// 任务命令实体类
/// </summary>
public
class
CommandModel
{
/// <summary>
/// 对应方法名称
/// </summary>
public
string
Method
{
get
;
set
;
}
/// <summary>
/// 执行方式(1-每天,2-间隔多少小时,3-间隔多少分钟)
/// </summary>
public
int
ActionType
{
get
;
set
;
}
/// <summary>
/// 执行时间(01:00)
/// </summary>
public
string
ActionTime
{
get
;
set
;
}
}
}
Mall.WindowsService/Module/FinanceModule.cs
View file @
998561c8
...
...
@@ -5,6 +5,7 @@ using Mall.Model.Extend.Finance;
using
Mall.Model.Extend.Product
;
using
Mall.Repository.Finance
;
using
Mall.Repository.Product
;
using
Mall.WindowsService.Helper
;
using
Newtonsoft.Json.Linq
;
using
System
;
using
System.Collections.Generic
;
...
...
@@ -46,7 +47,7 @@ namespace Mall.WindowsService.Module
try
{
//先查询规则
var
financeConfigurineList
=
financeConfigurineRepository
.
GetList
(
new
Model
.
Extend
.
Finance
.
RB_Finance_Configurine_Extend
{
Type
=
1
});
var
financeConfigurineList
=
financeConfigurineRepository
.
GetList
(
new
RB_Finance_Configurine_Extend
{
Type
=
1
});
//根据规则中的小程序,查询订单详情信息
if
(
financeConfigurineList
!=
null
&&
financeConfigurineList
.
Any
())
...
...
@@ -59,7 +60,7 @@ namespace Mall.WindowsService.Module
var
addFinance
=
false
;
DateTime
startDate
=
System
.
DateTime
.
Now
.
AddDays
(-
1
);
var
recordModel
=
financeRecordRepository
.
GetList
(
new
Model
.
Extend
.
Finance
.
RB_Finance_Record_Extend
{
TenantId
=
item
.
TenantId
,
MallBaseId
=
item
.
MallBaseId
}).
OrderByDescending
(
x
=>
x
.
CreateDate
).
FirstOrDefault
();
var
recordModel
=
financeRecordRepository
.
GetList
(
new
RB_Finance_Record_Extend
{
TenantId
=
item
.
TenantId
,
MallBaseId
=
item
.
MallBaseId
}).
OrderByDescending
(
x
=>
x
.
CreateDate
).
FirstOrDefault
();
if
(
recordModel
==
null
)
//今天没生成单据
{
if
(
Convert
.
ToDateTime
(
item
.
StartTime
.
Value
.
AddDays
(
item
.
IntervalDay
??
0
).
ToString
(
"yyyy-MM-dd 00:00:00"
))
<=
Convert
.
ToDateTime
(
System
.
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd 00:00:00"
)))
//判断开始时间加上执行周期是否等于当前日期
...
...
@@ -173,13 +174,13 @@ and DATE_FORMAT(b.CreateDate,'%y-%m-%d')<DATE_FORMAT('{endDate}','%y-%m-%d') an
{
record
.
FinanceId
=
frid
;
int
recordId
=
financeRecordRepository
.
Insert
(
record
);
LogHelper
.
Write
(
"财务单据ID:"
+
recordId
+
"订单数量:"
+
record
.
RecordDetailList
.
Count
());
Helper
.
LogHelper
.
Write
(
"财务单据ID:"
+
frid
+
",记录id:"
+
recordId
+
"订单数量:"
+
record
.
RecordDetailList
.
Count
());
record
.
RecordDetailList
.
ForEach
(
x
=>
x
.
RecordId
=
recordId
);
record
.
RecordDetailList
.
ForEach
(
x
=>
x
.
FinanceId
=
frid
);
flag
=
financeRecordDetailRepository
.
InsertBatch
(
record
.
RecordDetailList
);
}
LogHelper
.
Write
(
apiResult
);
Helper
.
LogHelper
.
Write
(
apiResult
);
}
}
}
...
...
@@ -188,7 +189,7 @@ and DATE_FORMAT(b.CreateDate,'%y-%m-%d')<DATE_FORMAT('{endDate}','%y-%m-%d') an
catch
(
Exception
ex
)
{
LogHelper
.
Write
(
ex
);
Helper
.
LogHelper
.
Write
(
ex
.
Message
);
}
return
flag
;
...
...
Mall.WindowsService/WindowsService.cs
View file @
998561c8
...
...
@@ -21,10 +21,10 @@ namespace Mall.WindowsService
protected
override
void
OnStart
(
string
[]
args
)
{
// TODO: 在此处添加代码以启动服务。
LogHelper
.
Write
(
"主服务开始运行......"
);
Helper
.
LogHelper
.
Write
(
"主服务开始运行......"
);
TimersHelper
helper
=
new
TimersHelper
();
timer1
=
new
System
.
Timers
.
Timer
();
timer1
.
Interval
=
1000
*
(
60
*
0.5
);
//60分钟
timer1
.
Interval
=
1000
*
(
60
*
60
);
//60分钟
timer1
.
Elapsed
+=
new
System
.
Timers
.
ElapsedEventHandler
(
helper
.
RevenueFinance
);
timer1
.
Enabled
=
true
;
}
...
...
@@ -32,7 +32,7 @@ namespace Mall.WindowsService
protected
override
void
OnStop
()
{
// TODO: 在此处添加代码以执行停止服务所需的关闭操作。
LogHelper
.
Write
(
"主服务停止运行......"
);
Helper
.
LogHelper
.
Write
(
"主服务停止运行......"
);
this
.
timer1
.
Enabled
=
false
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment