-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatilhos.sql
234 lines (204 loc) · 6.46 KB
/
gatilhos.sql
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
-- CREATE TABLE IF NOT EXISTS `gantt_tasks` (
-- `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
-- `text` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
-- `start_date` datetime NOT NULL,
-- `duration` int(11) NOT NULL,
-- `parent` int(11) NOT NULL,
-- `atividade` int(11) NOT NULL
-- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE IF NOT EXISTS `gantt_tasks` (
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`text` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`start_date` datetime NOT NULL,
`duration` int(11) NOT NULL,
`progress` float NOT NULL DEFAULT 0,
`parent` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
DELIMITER $
CREATE TRIGGER trg_insert_atividade AFTER INSERT ON quxmr_jem_events
FOR EACH ROW
BEGIN
INSERT INTO gantt_tasks
(text,
start_date, duration,
parent, atividade)
VALUES
(NEW.title, NEW.dates,
datediff(NEW.enddates, NEW.dates),
0, NEW.id);
END $
DELIMITER ;
INSERT INTO `quxmr_jem_events`
(`id`, `locid`, `dates`, `enddates`,
`times`, `endtimes`, `title`, `alias`,
`created_by`, `modified`, `modified_by`,
`version`, `author_ip`, `created`,
`introtext`, `meta_keywords`, `meta_description`,
`recurrence_first_id`, `recurrence_number`,
`recurrence_type`, `recurrence_counter`,
`recurrence_limit`, `recurrence_limit_date`,
`recurrence_byday`, `datimage`, `checked_out`,
`checked_out_time`, `registra`, `unregistra`,
`unregistra_until`, `maxplaces`, `waitinglist`,
`hits`, `published`, `contactid`, `custom1`,
`custom2`, `custom3`, `custom4`, `custom5`,
`custom6`, `custom7`, `custom8`, `custom9`,
`custom10`, `fulltext`, `created_by_alias`,
`access`, `metadata`, `featured`, `attribs`,
`language`)
VALUES (NULL, '1', '2017-11-01', '2017-11-02',
'03:09:13', '06:18:00', 'Atividade adicionada por gatilho',
'1', '665', '2017-11-07 00:00:00', '665', '2', '',
'2017-11-01 00:00:00', '', '', '', '0', '0', '0',
'0', '0', NULL, NULL, '', '0', '2017-11-01 05:15:16',
'0', '0', '0', '0', '0', '0', '0', '5', '', 'concepcao', '', '',
'', '', '', '', '', '', '', '', '0', '', '0', '', '');
DELIMITER $
CREATE TRIGGER trg_update AFTER UPDATE ON quxmr_jem_events
FOR EACH ROW
BEGIN
UPDATE gantt_tasks
SET text = NEW.title,
start_date = NEW.dates,
duration = datediff(NEW.enddates, NEW.dates),
parent = 1
WHERE
atividade = OLD.id;
END $
DELIMITER ;
SELECT min(dates), max(DATEDIFF(enddates, dates)) FROM `quxmr_jem_events`;
/*Funções*/
DELIMITER $
CREATE FUNCTION get_duracao_concepcao() RETURNS INT
BEGIN
DECLARE duracao INT;
SELECT duracao = max(DATEDIFF(enddates, dates))
FROM `quxmr_jem_events`;
RETURN duracao;
END $
DELIMITER ;
/*INserção projeto*/
INSERT INTO gantt_tasks
(id, text, start_date, duration, progress, parent)
VALUES
(1, 'Solar', now(), 0, 0, 0);
/*Inserção das fases*/
INSERT INTO gantt_tasks
(id, text, start_date, duration, progress, parent)
VALUES
(2, 'Concepção', now(), 0, 1, 1);
INSERT INTO gantt_tasks
(id, text, start_date, duration, progress, parent)
VALUES
(3, 'Documentação', now(), 0, 1, 1);
INSERT INTO gantt_tasks
(id, text, start_date, duration, progress, parent)
VALUES
(4, 'Desenvolvimento', now(), 0, 1, 1);
INSERT INTO gantt_tasks
(id, text, start_date, duration, progress, parent)
VALUES
(5, 'Teste', now(), 0, 1, 1);
INSERT INTO gantt_tasks
(id, text, start_date, duration, progress, parent)
VALUES
(6, 'Homologação', now(), 0, 1, 1);
INSERT INTO gantt_tasks
(id, text, start_date, duration, progress, parent)
VALUES
(7, 'Implantação', now(), 0, 1, 1);
INSERT INTO gantt_tasks
(id, text, start_date, duration, progress, parent)
VALUES
(8, 'Treinamento', now(), 0, 1, 1);
INSERT INTO gantt_tasks
(id, text, start_date, duration, progress, parent)
VALUES
(9, 'Produção', now(), 0, 1, 1);
/*Nova versão do gatilho de insert*/
DELIMITER $
CREATE TRIGGER trg_insert_atividade AFTER INSERT ON quxmr_jem_events
FOR EACH ROW
BEGIN
IF (NEW.custom2 = 'concepcao') THEN
INSERT INTO gantt_tasks
(text,
start_date, duration,
parent, atividade)
VALUES
(NEW.title, NEW.dates,
datediff(NEW.enddates, NEW.dates),
2, NEW.id);
END IF;
IF (NEW.custom2 = 'documentacao') THEN
INSERT INTO gantt_tasks
(text,
start_date, duration,
parent, atividade)
VALUES
(NEW.title, NEW.dates,
datediff(NEW.enddates, NEW.dates),
3, NEW.id);
END IF;
IF (NEW.custom2 = 'desenvolvimento') THEN
INSERT INTO gantt_tasks
(text,
start_date, duration,
parent, atividade)
VALUES
(NEW.title, NEW.dates,
datediff(NEW.enddates, NEW.dates),
4, NEW.id);
END IF;
IF (NEW.custom2 = 'teste') THEN
INSERT INTO gantt_tasks
(text,
start_date, duration,
parent, atividade)
VALUES
(NEW.title, NEW.dates,
datediff(NEW.enddates, NEW.dates),
5, NEW.id);
END IF;
IF (NEW.custom2 = 'homologacao') THEN
INSERT INTO gantt_tasks
(text,
start_date, duration,
parent, atividade)
VALUES
(NEW.title, NEW.dates,
datediff(NEW.enddates, NEW.dates),
6, NEW.id);
END IF;
IF (NEW.custom2 = 'implantacao') THEN
INSERT INTO gantt_tasks
(text,
start_date, duration,
parent, atividade)
VALUES
(NEW.title, NEW.dates,
datediff(NEW.enddates, NEW.dates),
7, NEW.id);
END IF;
IF (NEW.custom2 = 'treinamento') THEN
INSERT INTO gantt_tasks
(text,
start_date, duration,
parent, atividade)
VALUES
(NEW.title, NEW.dates,
datediff(NEW.enddates, NEW.dates),
8, NEW.id);
END IF;
IF (NEW.custom2 = 'producao') THEN
INSERT INTO gantt_tasks
(text,
start_date, duration,
parent, atividade)
VALUES
(NEW.title, NEW.dates,
datediff(NEW.enddates, NEW.dates),
9, NEW.id);
END IF;
END $
DELIMITER ;