Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
EduSpider
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
viitto
EduSpider
Commits
c2eae54e
Commit
c2eae54e
authored
May 25, 2022
by
liudong1993
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
2c01b41d
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
333 additions
and
4 deletions
+333
-4
IAccountRepository.cs
EduSpider.IRepository/IAccountRepository.cs
+29
-0
RB_Account.cs
EduSpider.Model/Entity/RB_Account.cs
+55
-0
RB_Account_Extend.cs
EduSpider.Model/Extend/RB_Account_Extend.cs
+20
-0
AccountRepository.cs
EduSpider.Repository/AccountRepository.cs
+84
-0
DES.cs
EduSpider.Utility/Encrypt/DES.cs
+80
-0
ClassInFlow.cs
EduSpider/Spiders/ClassInRule/ClassInFlow.cs
+3
-3
StudentManager.cs
EduSpider/Spiders/ClassInRule/StudentManager.cs
+35
-0
TeacherManager.cs
EduSpider/Spiders/ClassInRule/TeacherManager.cs
+27
-1
No files found.
EduSpider.IRepository/IAccountRepository.cs
0 → 100644
View file @
c2eae54e
using
EduSpider.Model.Entity
;
using
EduSpider.Model.Extend
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
VTX.FW.Config
;
using
VTX.FW.DB
;
namespace
EduSpider.Repository
{
/// <summary>
/// 账号仓储接口
/// </summary>
public
interface
IAccountRepository
:
IDBRepository
<
RB_Account
>,
IDependency
{
/// <summary>
/// 批量新增
/// </summary>
/// <param name="accounts"></param>
/// <returns></returns>
public
bool
BatchSetAccount
(
List
<
RB_Account
>
accounts
);
int
GetMaxStuTeaId
(
int
type
);
public
List
<
RB_Account_Extend
>
GetAccountList
(
RB_Account_Extend
demodel
);
}
}
EduSpider.Model/Entity/RB_Account.cs
0 → 100644
View file @
c2eae54e
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
VTX.FW.Attr
;
namespace
EduSpider.Model.Entity
{
[
Serializable
]
[
DB
(
ConnectionName
=
"DefaultConnection"
)]
public
class
RB_Account
{
/// <summary>
/// 对应Uid
/// </summary>
public
int
Id
{
get
;
set
;
}
/// <summary>
/// 登录账号
/// </summary>
public
string
Account
{
get
;
set
;
}
/// <summary>
/// 密码
/// </summary>
public
string
Password
{
get
;
set
;
}
/// <summary>
/// 类型 1老师 2学生
/// </summary>
public
int
AccountType
{
get
;
set
;
}
/// <summary>
/// 对应 老师/学生ID
/// </summary>
public
int
AccountId
{
get
;
set
;
}
/// <summary>
/// 删除状态
/// </summary>
public
int
Status
{
get
;
set
;
}
/// <summary>
/// 微信唯一识别码
/// </summary>
public
string
OpenId
{
get
;
set
;
}
/// <summary>
/// 微信UnionId
/// </summary>
public
string
UnionId
{
get
;
set
;
}
}
}
EduSpider.Model/Extend/RB_Account_Extend.cs
0 → 100644
View file @
c2eae54e
using
EduSpider.Model.Entity
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
VTX.FW.Attr
;
namespace
EduSpider.Model.Extend
{
[
Serializable
]
[
DB
(
ConnectionName
=
"DefaultConnection"
)]
public
class
RB_Account_Extend
:
RB_Account
{
/// <summary>
/// 帐号名称
/// </summary>
public
string
AccountName
{
get
;
set
;
}
}
}
EduSpider.Repository/AccountRepository.cs
0 → 100644
View file @
c2eae54e
using
EduSpider.Model.Entity
;
using
EduSpider.Model.Extend
;
using
EduSpider.Repository.Base
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
EduSpider.Repository
{
/// <summary>
/// 账号仓储层
/// </summary>
public
class
AccountRepository
:
BaseRepository
<
RB_Account
>,
IAccountRepository
{
/// <summary>
/// 批量新增账号
/// </summary>
/// <param name="accounts"></param>
/// <returns></returns>
public
bool
BatchSetAccount
(
List
<
RB_Account
>
accounts
)
{
return
base
.
BatchInsert
(
accounts
,
isReplace
:
true
);
}
/// <summary>
/// 获取账户列表
/// </summary>
/// <param name="demodel"></param>
/// <returns></returns>
public
List
<
RB_Account_Extend
>
GetAccountList
(
RB_Account_Extend
demodel
)
{
string
where
=
" 1=1 "
;
if
(
demodel
.
Id
>
0
)
{
where
+=
$" and t.
{
nameof
(
RB_Account_Extend
.
Id
)}
=
{
demodel
.
Id
}
"
;
}
if
(
demodel
.
AccountType
>
0
)
{
where
+=
$" and t.
{
nameof
(
RB_Account_Extend
.
AccountType
)}
=
{
demodel
.
AccountType
}
"
;
}
if
(
demodel
.
AccountId
>
0
)
{
where
+=
$" and t.
{
nameof
(
RB_Account_Extend
.
AccountId
)}
=
{
demodel
.
AccountId
}
"
;
}
if
(
demodel
.
Status
>
-
1
)
{
where
+=
$" and t.
{
nameof
(
RB_Account_Extend
.
Status
)}
=
{
demodel
.
Status
}
"
;
}
if
(!
string
.
IsNullOrEmpty
(
demodel
.
Account
))
{
where
+=
$" and t.
{
nameof
(
RB_Account_Extend
.
Account
)}
='
{
demodel
.
Account
}
'"
;
}
if
(!
string
.
IsNullOrEmpty
(
demodel
.
Password
))
{
where
+=
$" and t.
{
nameof
(
RB_Account_Extend
.
Password
)}
='
{
demodel
.
Password
}
'"
;
}
string
sql
=
$@"
select * from(
SELECT a.Id,a.Account,a.`Password`,a.AccountType,a.AccountId,t.TeacherName AS AccountName,a.Status FROM rb_account a
INNER JOIN rb_teacher t on a.AccountId =t.TeacherId and a.AccountType =1
UNION
SELECT a.Id,a.Account,a.`Password`,a.AccountType,a.AccountId,s.StudentName AS AccountName,a.Status FROM rb_account a
INNER JOIN rb_student s on a.AccountId =s.StudId and a.AccountType =2
) t where
{
where
}
"
;
return
Get
<
RB_Account_Extend
>(
sql
).
ToList
();
}
/// <summary>
/// 获取最大ID
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public
int
GetMaxStuTeaId
(
int
type
)
{
string
sql
=
$" select max(AccountId) from RB_Account where AccountType =
{
type
}
"
;
var
obj
=
ExecuteScalar
(
sql
);
return
obj
==
null
?
0
:
Convert
.
ToInt32
(
obj
);
}
}
}
EduSpider.Utility/Encrypt/DES.cs
0 → 100644
View file @
c2eae54e
using
System
;
using
System.IO
;
using
System.Security.Cryptography
;
using
System.Text
;
namespace
EduSpider.Utility
{
/// <summary>
/// DES 加解密
/// </summary>
public
class
DES
{
private
static
readonly
byte
[]
_webapikey
=
{
0xF1
,
0x12
,
0xA3
,
0xD1
,
0xBA
,
0x54
,
0x2A
,
0x88
};
private
static
readonly
byte
[]
_webapiiv
=
{
0x04
,
0xAE
,
0x57
,
0x83
,
0x56
,
0x28
,
0x66
,
0xA7
};
/// <summary>
/// DES加密(单向,只能C#用)
/// </summary>
/// <param name="EncryptString">加密字符串</param>
/// <returns></returns>
public
static
string
Encrypt
(
string
EncryptString
)
{
return
Encrypt
(
EncryptString
,
_webapikey
,
_webapiiv
);
}
/// <summary>
/// DES加密(单向,只能C#用)
/// </summary>
/// <param name="EncryptString">待加密的字符串</param>
/// <param name="Key">加密密钥</param>
/// <param name="IV">初始化加密函数的变量</param>
/// <returns></returns>
private
static
string
Encrypt
(
string
EncryptString
,
byte
[]
Key
,
byte
[]
IV
)
{
byte
[]
inputByteArray
=
Encoding
.
UTF8
.
GetBytes
(
EncryptString
);
DESCryptoServiceProvider
des
=
new
DESCryptoServiceProvider
();
MemoryStream
mStream
=
new
MemoryStream
();
CryptoStream
cStream
=
new
CryptoStream
(
mStream
,
des
.
CreateEncryptor
(
Key
,
IV
),
CryptoStreamMode
.
Write
);
cStream
.
Write
(
inputByteArray
,
0
,
inputByteArray
.
Length
);
cStream
.
FlushFinalBlock
();
return
Convert
.
ToBase64String
(
mStream
.
ToArray
());
}
/// <summary>
/// DES解密
/// </summary>
/// <param name="DecryptString">待解密的字符串</param>
/// <returns>解密成功返回解密后的字符串,失败返源串</returns>
public
static
string
Decrypt
(
string
DecryptString
)
{
return
Decrypt
(
DecryptString
,
_webapikey
,
_webapiiv
);
}
/// <summary>
/// DES解密
/// </summary>
/// <param name="DecryptString">待解密的字符串</param>
/// <param name="Key">解密密钥,要求为8位,和加密密钥相同</param>
/// <param name="IV">初始化加密函数的变量</param>
/// <returns>解密成功返回解密后的字符串,失败返源串</returns>
private
static
string
Decrypt
(
string
DecryptString
,
byte
[]
Key
,
byte
[]
IV
)
{
try
{
byte
[]
inputByteArray
=
Convert
.
FromBase64String
(
DecryptString
);
DESCryptoServiceProvider
des
=
new
DESCryptoServiceProvider
();
MemoryStream
mStream
=
new
MemoryStream
();
CryptoStream
cStream
=
new
CryptoStream
(
mStream
,
des
.
CreateDecryptor
(
Key
,
IV
),
CryptoStreamMode
.
Write
);
cStream
.
Write
(
inputByteArray
,
0
,
inputByteArray
.
Length
);
cStream
.
FlushFinalBlock
();
return
Encoding
.
UTF8
.
GetString
(
mStream
.
ToArray
());
}
catch
{
return
""
;
}
}
}
}
\ No newline at end of file
EduSpider/Spiders/ClassInRule/ClassInFlow.cs
View file @
c2eae54e
...
...
@@ -24,9 +24,9 @@ namespace TicketSpider.Spiders.ClassInRule
Console
.
WriteLine
(
"开始获取学员信息"
);
//
new StudentManager().RunAsync(loginCookies);
new
CourseManager
().
RunCourse
(
loginCookies
);
new
StudentManager
().
RunAsync
(
loginCookies
);
//
new CourseManager().RunCourse(loginCookies);
//new TeacherManager().RunTeacher(loginCookies);
}
}
}
EduSpider/Spiders/ClassInRule/StudentManager.cs
View file @
c2eae54e
...
...
@@ -6,6 +6,7 @@ using Newtonsoft.Json;
using
Newtonsoft.Json.Linq
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Net.Http
;
using
System.Text
;
using
VTX.FW.Helper
;
...
...
@@ -22,6 +23,14 @@ namespace EduSpider.Spiders.ClassInRule
var
request
=
Utility
.
HttpHelper
.
GenerateHttp
(
cookie
);
int
pageIndex
=
1
,
pageCount
=
1
,
pageSize
=
500
;
#
region
获取最大学生
ID
//更新账户
IAccountRepository
accountRepository
=
new
AccountRepository
();
//获取账户表 最大的TeacherId
int
MaxStuId
=
accountRepository
.
GetMaxStuTeaId
(
type
:
2
);
List
<
RB_Account
>
accountList
=
new
();
#
endregion
while
(
pageIndex
<=
pageCount
)
{
Console
.
WriteLine
(
$"正在查询第
{
pageIndex
}
-
{
pageSize
}
页学员信息"
);
...
...
@@ -69,11 +78,37 @@ namespace EduSpider.Spiders.ClassInRule
courseRepository
.
BatchSetStudent
(
stus
);
Console
.
WriteLine
(
$"已导入第
{
pageIndex
}
-
{
pageSize
}
页学员信息"
);
#
endregion
#
region
写入账号
if
(
stus
.
Any
(
x
=>
x
.
StudId
>
MaxStuId
))
{
foreach
(
var
item
in
stus
.
Where
(
x
=>
x
.
StudId
>
MaxStuId
))
{
accountList
.
Add
(
new
RB_Account
()
{
Id
=
item
.
StudentUid
,
Account
=
item
.
StudentAccount
,
AccountId
=
item
.
StudId
,
AccountType
=
2
,
OpenId
=
""
,
Password
=
Utility
.
DES
.
Encrypt
(
item
.
StudentAccount
[^
6.
.]),
Status
=
0
,
UnionId
=
""
});
}
}
#
endregion
}
}
pageIndex
++;
}
#
region
插入账号
if
(
accountList
.
Any
())
{
accountRepository
.
BatchSetAccount
(
accountList
);
}
#
endregion
Console
.
WriteLine
(
"学员同步完成"
);
}
...
...
EduSpider/Spiders/ClassInRule/TeacherManager.cs
View file @
c2eae54e
...
...
@@ -69,7 +69,33 @@ namespace EduSpider.Spiders.ClassInRule
}
ITeacherRepository
teacherRepository
=
new
TeacherRepository
();
teacherRepository
.
BatchSetTeache
(
list
.
OrderBy
(
x
=>
x
.
TeacherId
).
ToList
());
bool
flag
=
teacherRepository
.
BatchSetTeache
(
list
.
OrderBy
(
x
=>
x
.
TeacherId
).
ToList
());
if
(
flag
)
{
//更新账户
IAccountRepository
accountRepository
=
new
AccountRepository
();
//获取账户表 最大的TeacherId
int
MaxTeacherId
=
accountRepository
.
GetMaxStuTeaId
(
type
:
1
);
if
(
list
.
Any
(
x
=>
x
.
TeacherId
>
MaxTeacherId
))
{
List
<
RB_Account
>
accountList
=
new
();
foreach
(
var
item
in
list
.
Where
(
x
=>
x
.
TeacherId
>
MaxTeacherId
))
{
accountList
.
Add
(
new
RB_Account
()
{
Id
=
item
.
TeacherUid
,
Account
=
item
.
TeacherAccount
,
AccountId
=
item
.
TeacherId
,
AccountType
=
1
,
OpenId
=
""
,
Password
=
Utility
.
DES
.
Encrypt
(
item
.
TeacherAccount
[^
6.
.]),
Status
=
0
,
UnionId
=
""
});
}
accountRepository
.
BatchSetAccount
(
accountList
);
}
}
}
/// <summary>
...
...
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