DeptDataSeed.cs
4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Yi.Framework.Rbac.Domain.Entities;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
{
public class DeptDataSeed : IDataSeedContributor, ITransientDependency
{
private ISqlSugarRepository<DeptAggregateRoot> _repository;
private IGuidGenerator _guidGenerator;
public DeptDataSeed(ISqlSugarRepository<DeptAggregateRoot> repository, IGuidGenerator guidGenerator)
{
_repository = repository;
_guidGenerator = guidGenerator;
}
public async Task SeedAsync(DataSeedContext context)
{
if (!await _repository.IsAnyAsync(x => true))
{
await _repository.InsertManyAsync(GetSeedData());
}
}
public List<DeptAggregateRoot> GetSeedData()
{
var entities = new List<DeptAggregateRoot>();
DeptAggregateRoot chengziDept = new DeptAggregateRoot(_guidGenerator.Create())
{
DeptName = "橙子科技",
DeptCode = "Yi",
OrderNum = 100,
IsDeleted = false,
Leader = "橙子",
Remark = "如名所指"
};
entities.Add(chengziDept);
DeptAggregateRoot shenzhenDept = new DeptAggregateRoot(_guidGenerator.Create())
{
DeptCode = "SZ",
DeptName = "深圳总公司",
OrderNum = 100,
IsDeleted = false,
ParentId = chengziDept.Id
};
entities.Add(shenzhenDept);
DeptAggregateRoot jiangxiDept = new DeptAggregateRoot(_guidGenerator.Create())
{
DeptCode = "JX",
DeptName = "江西总公司",
OrderNum = 100,
IsDeleted = false,
ParentId = chengziDept.Id
};
entities.Add(jiangxiDept);
DeptAggregateRoot szDept1 = new DeptAggregateRoot(_guidGenerator.Create())
{
DeptCode = "YF",
DeptName = "研发部门",
OrderNum = 100,
IsDeleted = false,
ParentId = shenzhenDept.Id
};
entities.Add(szDept1);
DeptAggregateRoot szDept2 = new DeptAggregateRoot(_guidGenerator.Create())
{
DeptCode = "SC",
DeptName = "市场部门",
OrderNum = 100,
IsDeleted = false,
ParentId = shenzhenDept.Id
};
entities.Add(szDept2);
DeptAggregateRoot szDept3 = new DeptAggregateRoot(_guidGenerator.Create())
{
DeptCode = "CS",
DeptName = "测试部门",
OrderNum = 100,
IsDeleted = false,
ParentId = shenzhenDept.Id
};
entities.Add(szDept3);
DeptAggregateRoot szDept4 = new DeptAggregateRoot(_guidGenerator.Create())
{
DeptCode = "CW",
DeptName = "财务部门",
OrderNum = 100,
IsDeleted = false,
ParentId = shenzhenDept.Id
};
entities.Add(szDept4);
DeptAggregateRoot szDept5 = new DeptAggregateRoot(_guidGenerator.Create())
{
DeptCode = "YW",
DeptName = "运维部门",
OrderNum = 100,
IsDeleted = false,
ParentId = shenzhenDept.Id
};
entities.Add(szDept5);
DeptAggregateRoot jxDept1 = new DeptAggregateRoot(_guidGenerator.Create())
{
DeptCode = "SC",
DeptName = "市场部门",
OrderNum = 100,
IsDeleted = false,
ParentId = jiangxiDept.Id
};
entities.Add(jxDept1);
DeptAggregateRoot jxDept2 = new DeptAggregateRoot(_guidGenerator.Create())
{
DeptCode = "CW2",
DeptName = "财务部门",
OrderNum = 100,
IsDeleted = false,
ParentId = jiangxiDept.Id
};
entities.Add(jxDept2);
return entities;
}
}
}