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
142
143
144
145
146
147
148
149
150
151
152
//
// GXFFunctionDBHelper.m
// XFFruit
//
// Created by freecui on 15/8/28.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "GXFFunctionDBHelper.h"
#import "GXFFunctionDB.h"
@interface GXFFunctionDBHelper ()
//@property (nonatomic, strong)GXFFunctionDB *functionDb;
@end
@implementation GXFFunctionDBHelper
+ (instancetype)sharedInstance{
static GXFFunctionDBHelper *dbHelper = nil;
static dispatch_once_t once;
dispatch_once(&once, ^{
dbHelper = [[GXFFunctionDBHelper alloc]init];
});
return dbHelper;
}
////开启一次就可以了
//- (void)openDb {
// self.functionDb = [GXFFunctionDB sharedInstance];
// [_functionDb functionTableCreate];
// [_functionDb displayFunctionTableCreate];
//}
- (void)insertAllOriginFunctions{
NSArray *functionsArr = [NSArray arrayWithArray:[self p_readJsonFile]];
for (int count = 0; count < functionsArr.count; count ++) {
GXFFunction *function = (GXFFunction *)functionsArr[count];
[[GXFFunctionDB sharedInstance] insertFunction:function];
}
}
//从读出的json文件返回GXFFunction数组
- (NSArray *)p_readJsonFile {
NSMutableArray *muArr = [NSMutableArray array];
//添加公告
GXFFunction *function = [[GXFFunction alloc]init];
function.Id = 000000;
function.name = @"announcement";
function.caption = @"公告";
function.hasPermission = YES;
function.isSelected = NO;
[muArr addObject:function];
NSString *path = [[NSBundle mainBundle] pathForResource:@"PermissionJson" ofType:nil];
NSData *jsonData = [NSData dataWithContentsOfFile:path options:NSDataReadingMappedIfSafe error:nil];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData options: NSJSONReadingMutableContainers error:nil];
NSArray *childrenArr = dict[@"children"];
for (int i = 0; i < childrenArr.count; i ++) {
NSArray *permissionsArr = [childrenArr[i] objectForKey:@"permissions"];
for (int j = 0; j < permissionsArr.count; j++) {
NSMutableDictionary *muDict = [NSMutableDictionary dictionaryWithObjects:@[@(0),@(0)] forKeys:@[@"hasPermission",@"isSelected"]];
[muDict addEntriesFromDictionary:permissionsArr[j]];
GXFFunction *function = [[GXFFunction alloc]initWithDictionary:muDict];
[muArr addObject:function];
}
}
return muArr;
}
- (void)insertAllOriginDisplayFunctions{
NSArray *arr = [self p_createAllDisplayFunctions];
for (int count = 0; count < arr.count; count ++) {
GXFDisplayFunction *displayFunction = (GXFDisplayFunction *)arr[count];
[[GXFFunctionDB sharedInstance] insertDisplayFunction:displayFunction];
}
}
- (NSArray *)p_createAllDisplayFunctions{
NSArray *functionsId = @[@(000000),
@(500101),@(500102),@(500103),
@(500201),
@(500301),@(500302),@(500303),//"采购通知",
@(500401),@(500402),@(500403),@(500404),//"采购单"
@(500501),@(500502),@(500503),//"发运单"
@(500601),@(500602),@(500603),//"转运单"
@(500701),@(500702),@(500703),//加工单
@(500802),@(500803),];//收货单
NSArray *functionsName = @[@"公告",
@"新建行情调研",@"查看行情调研", @"查看行情调研",
@"填写行情反馈",
@"新建采购通知",@"查看采购通知", @"查看采购通知",
@"新建采购单",@"查看采购单", @"查看采购单", @"供应商确认采购单",//【供应商】",
@"新建发运单",@"查看发运单", @"查看发运单",
@"新增加工单",@"查看加工单", @"查看加工单",
@"新建转运单", @"查看转运单", @"查看转运单",
@"查看收货单", @"查看收货单"];
NSArray *functionsImageName = @[@"notice",
@"create_surver",@"watch_surver", @"watch_surver",
@"create_surver_result",
@"create_needs",@"watch_needs", @"watch_needs",
@"create_purchase",@"watch_purchase", @"watch_purchase", @"review_purchase",
@"create_transport",@"watch_transort", @"watch_transort",
@"create_process",@"watch_process", @"watch_process",
@"create_transfer", @"create_transfer", @"create_transfer",
@"create_transfer", @"create_transfer" ];//收货单
//NSArray *functionsSmallImgName = @[];
NSArray *functionItemTag = @[@(0),
@(1),@(2),@(2),
@(3),
@(4),@(5),@(5),//"采购通知",
@(6),@(7),@(7),@(8),//"采购单"
@(9),@(10),@(10),//"发运单"
@(11),@(12),@(12),//"转运单"
@(13),@(14),@(14),//加工单
@(15),@(15),];//收货单
if ((functionsId.count != functionsName.count) ||(functionsId.count != functionsImageName.count)||(functionsName.count != functionsImageName.count)) {
NSLog(@"展现功能界面:插入的数据不是一一对应的");
return nil;
}
NSMutableArray *muarr = [NSMutableArray array];
for (int count = 0; count < functionsId.count; count ++) {
GXFDisplayFunction *displayFunction = [[GXFDisplayFunction alloc]init];
displayFunction.functionId = [functionsId[count] integerValue];
displayFunction.functionName = functionsName[count];
displayFunction.functionImgName = functionsImageName[count];
//displayFunction.functionSmallImgName = fu
displayFunction.functionItemTag = [functionItemTag[count] integerValue];
[muarr addObject:displayFunction];
}
return muarr;
}
- (BOOL)successInsertOriginFunctions{
return [[GXFFunctionDB sharedInstance] originFunctions].count > 0 ? YES : NO;
}
- (BOOL)sucessInsertOriginDisplayFunctions {
return [[GXFFunctionDB sharedInstance] originDisplayFunctions].count > 0 ? YES : NO;
}
@end