DHTMLX Gantt集成源码

DHTMLX Gantt集成源码

1.安装dhtmlx gantt

1
npm install --save dhtmlx-gantt

2.前端vue — GanttChart.vue

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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
<template>
<div ref="cont" style="width: 100%; height: calc(100vh - 100px)"></div>
</template>

<script>
import gantt from 'dhtmlx-gantt';
import 'dhtmlx-gantt/codebase/dhtmlxgantt.css';
import {
addGanttData,
delGanttData,
listAllGanttData,
updateGanttData,
updateGanttTaskOpen, updateGanttTaskOrder
} from '@/api/system/ganttData'
import { addGanttLinks, delGanttLinks, listAllGanttLinks, updateGanttLinks } from '@/api/system/ganttLinks'
import { checkRole } from '@/utils/permission'

export default {
name: 'GanttChart',
props:{
tasks:null,
},
data() {
return {
// ganttInstance: null,
};
},
methods:{
initGantt() {
gantt.plugins({
multiselect: true,
auto_scheduling: true,
keyboard_navigation: true,
tooltip: true,
drag_timeline: true,
});

gantt.config.keyboard_navigation_cells = true;
gantt.config.auto_scheduling = true;
gantt.config.auto_scheduling_strict = true;
gantt.config.row_height = 35; //单元格行高
gantt.config.fit_tasks = true;
gantt.config.show_unscheduled = true;
gantt.config.placeholder_task = true;
gantt.config.auto_types = true;
gantt.config.order_branch = "marker";
gantt.config.order_branch_free = true;
// gantt.config.scale_height = 30*2; //首行高度
// gantt.config.min_column_width = 50;

gantt.serverList("priority", [
{key: "1", label: "Low"},
{key: "2", label: "Normal"},
{key: "3", label: "High"}
]);

gantt.serverList("category", [
{key: "1", label: "BUG"},
{key: "2", label: "新需求"}
]);

var formatter = gantt.ext.formatters.durationFormatter({
enter: "day",
store: "day",
format: "auto"
});
var linksFormatter = gantt.ext.formatters.linkFormatter({durationFormatter: formatter});

var editors = {
text: {type: "text", map_to: "text"},
start_date: {type: "date", map_to: "start_date", min: new Date(2023, 0, 1), max: new Date(2026, 0, 1)},
end_date: {type: "date", map_to: "end_date", min: new Date(2023, 0, 1), max: new Date(2026, 0, 1)},
duration: {type: "duration", map_to: "duration", min:0, max: 100, formatter: formatter},
priority: {type: "select", map_to: "priority", options:gantt.serverList("priority")},
category: {type: "select", map_to: "category", options:gantt.serverList("category")},
predecessors: {type: "predecessor", map_to: "auto", formatter: linksFormatter},
assigned: {type: "text", map_to: "assigned"},
};

function priorityLabel(task){
var value = task.priority;
var list = gantt.serverList("priority");
for(var i = 0; i < list.length; i++){
if(list[i].key == value){
return list[i].label;
}
}
return "";
}

function categoryLabel(task){
var value = task.category;
var list = gantt.serverList("category");
for(var i = 0; i < list.length; i++){
if(list[i].key == value){
return list[i].label;
}
}
return "";
}

gantt.config.columns = [
{name: "wbs", label: "#", width: 60, align: "center", template: gantt.getWBSCode},
{name: "text", label: "任务名称", tree: true, width: 300, editor: editors.text},
{name: "category", label: "类别", width:80, align: "center", editor: editors.category, template: categoryLabel},
{name: "start_date", label: "开始日期", width:80, align: "center", editor: editors.start_date},
{name: "duration", label: "天数",width:60, align: "center", editor: editors.duration, template: function(task){
return formatter.format(task.duration);
}},
// {name: "end_date", label: "Finish", width:80, align: "center", editor: editors.end_date, resize: true},
// {name: "priority", label: "优先级", width:80, align: "center", editor: editors.priority, template: priorityLabel},
// {name: "predecessors", label: "Predecessors",width:80, align: "left", editor: editors.predecessors, resize: true, template: function(task){
// var links = task.$target;
// var labels = [];
// for(var i = 0; i < links.length; i++){
// var link = gantt.getLink(links[i]);
// labels.push(linksFormatter.format(link));
// }
// return labels.join(", ")
// }},
// {
// name: "progress", label: "Progress", width: 80, align: "center",
// template: function (item) {
// if (item.progress >= 1)
// return "Complete";
// if (item.progress == 0)
// return "Not started";
// return Math.round(item.progress * 100) + "%";
// }
// },
{
name: "progress", label: "进度", width: 100, align: "center",
template: function (item) {
// if (item.progress >= 1)
// return "已完成";
if (item.progress == 0)
return "未开始";
// return Math.round(item.progress * 100) + "%";
// return Math.round(item.progress * 100) + "%" + "<progress value=\"50\" max=\"100\" style=\"\n" +
// " width: 50px;\n" +
// "\" />";
// return "<el-progress :text-inside=\"true\" :stroke-width=\"26\" :percentage=\"70\"></el-progress>";
if (item.progress >= 1)
return "<div class=\"progress-container\"> \n" +
" <div class=\"progress-complete-bar\" id=\"myProgressBar\" style=\"width: "+ Math.round(item.progress * 100) + "%"+";\"><span id=\"progressNumber\">"+ Math.round(item.progress * 100) + "%"+"</span></div> \n" +
"</div>";
return "<div class=\"progress-container\"> \n" +
" <div class=\"progress-bar\" id=\"myProgressBar\" style=\"width: "+ Math.round(item.progress * 100) + "%"+";\"><span id=\"progressNumber\">"+ Math.round(item.progress * 100) + "%"+"</span></div> \n" +
"</div>";

}
},

{
name: "assigned", label: "分配人", align: "center", width: 100,editor: editors.assigned,hide:true,
},
// {
// name: "progress", label: "进度", width: 80, align: "center",
// template: function (item) {
// if (item.progress >= 1)
// return "完成";
// if (item.progress == 0)
// return "未开始";
// return Math.round(item.progress * 100) + "%";
// }
// },
{name:"add"}
];

gantt.config.lightbox.sections = [
{ name: 'description', height: 38, map_to: 'text', type: 'textarea', focus: true },
{name: "type", type: "typeselect", map_to: "type"},
{
name: 'category', height: 22, map_to: 'category', type: 'select', options: [
{ key: 1, label: 'BUG' },
{ key: 2, label: '新需求' }
]
},
{ name: 'time', type: 'duration', map_to: 'auto' },
{
name: 'progress', height: 22, map_to: 'progress', type: 'select', options: [
{ key: '0', label: 'Not started' },
{ key: '0.1', label: '10%' },
{ key: '0.2', label: '20%' },
{ key: '0.3', label: '30%' },
{ key: '0.4', label: '40%' },
{ key: '0.5', label: '50%' },
{ key: '0.6', label: '60%' },
{ key: '0.7', label: '70%' },
{ key: '0.8', label: '80%' },
{ key: '0.9', label: '90%' },
{ key: '1', label: 'Complete' }
]
},
{ name: 'assigned', height: 38, map_to: 'assigned', type: 'textarea', focus: true }
];

gantt.config.lightbox.project_sections = [
{ name: 'description', height: 38, map_to: 'text', type: 'textarea', focus: true },
{name: "type", type: "typeselect", map_to: "type"},
{ name: 'time', type: 'duration', map_to: 'auto' },
{
name: 'progress', height: 22, map_to: 'progress', type: 'select', options: [
{ key: '0', label: 'Not started' },
{ key: '0.1', label: '10%' },
{ key: '0.2', label: '20%' },
{ key: '0.3', label: '30%' },
{ key: '0.4', label: '40%' },
{ key: '0.5', label: '50%' },
{ key: '0.6', label: '60%' },
{ key: '0.7', label: '70%' },
{ key: '0.8', label: '80%' },
{ key: '0.9', label: '90%' },
{ key: '1', label: 'Complete' }
]
},
];


gantt.attachEvent("onTaskCreated", function(task){
task.priority = "1";
// task.category = "2";
if(task.type == gantt.config.types.placeholder){
task.text = "新建任务";
}
task.assigned = "";
return true;
});

gantt.ext.inlineEditors.attachEvent("onSave", function(state){
var col = state.columnName;
if(gantt.autoSchedule && (col == "start_date" || col == "end_date" || col == "duration")){
gantt.autoSchedule();
}
});

// 暂不显示进度文本
// gantt.templates.progress_text = function (start, end, task) {
// return "<span style='text-align:left;'>" + Math.round(task.progress * 100) + "% </span>";
// };

// === 列选中效果 begin === //
var selected_column = null;
gantt.attachEvent("onScaleClick", function (e, date) {
selected_column = date;
var pos = gantt.getScrollState();
gantt.render();
gantt.scrollTo(pos.x, pos.y);
});
function is_selected_column(column_date) {
if (selected_column && column_date.valueOf() == selected_column.valueOf()) {
return true;
}
return false;
}
gantt.templates.scale_cell_class = function (date) {
if (is_selected_column(date))
return "highlighted-column";
};
gantt.templates.timeline_cell_class = function (item, date) {
if (is_selected_column(date))
return "highlighted-column";
};
gantt.templates.leftside_text = function (start, end, task) {
return Math.round(task.progress * 100) + "%";
};
gantt.templates.task_text = function (start, end, task) {
return "Task #" + task.$wbs;
};
// === 列选中效果 end === //

// === 缩放效果 begin === //
gantt.config.scale_height = 50;
gantt.config.scales = [
{unit: "month", step: 1, format: "%F, %Y"},
{unit: "day", step: 1, format: "%j, %D"},
];
// gantt.config.min_column_width = 80;
// var zoomConfig = {
// minColumnWidth: 80,
// maxColumnWidth: 170,
// levels: [
// [
// { unit: "month", format: "%M %Y", step: 1},
// { unit: "day", format: "%d %M", step: 7}
// ],
// [
// { unit: "month", format: "%M %Y", step: 1},
// { unit: "day", format: "%d %M", step: 3}
// ],
// [
// { unit: "month", format: "%M %Y", step: 1},
// { unit: "day", format: "%d %M", step: 1}
// ],
// ],
// startDate: new Date(2023, 2, 27),
// endDate: new Date(2023, 5, 20),
// useKey: "ctrlKey",
// trigger: "wheel",
// element: function(){
// return gantt.$root.querySelector(".gantt_task");
// }
// }
// gantt.ext.zoom.init(zoomConfig);
// === 缩放效果 end === //

gantt.config.date_format = "%Y-%m-%d";
gantt.config.open_split_tasks = true;
gantt.config.drag_resize = false; // 禁止调整任务bar
gantt.config.drag_move = false; // 禁止移动任务bar

gantt.i18n.setLocale("cn");
gantt.locale.labels.section_progress = "进度";
gantt.locale.labels.section_category = "类别";
gantt.locale.labels.section_assigned = "分配人";
gantt.locale.labels.category = "类别";

// gantt.ext.tooltips.tooltipFor({
// selector: ".gantt_row",
// html: function(event, domElement){
// return ""
// }
// });

gantt.init(this.$refs.cont);
// gantt.init("ganttContainer");
// gantt.parse(this.tasks);

// gantt.createDataProcessor((entity, action, data, id) => {
// console.dir(entity);
// console.dir(action);
// console.dir(data);
// console.dir(id);
// this.$emit(`${entity}-updated`, id, action, data);
// });


gantt.attachEvent("onTaskOpened", function(id) {
updateGanttTaskOpen({'id':id,open:1})
});
gantt.attachEvent("onTaskClosed", function(id) {
updateGanttTaskOpen({'id':id,open:0})
});
let that = this;
gantt.attachEvent("onAfterTaskMove", function(id, parent, tindex){
console.dir(id);
console.dir(parent);
console.dir(tindex);
console.dir(gantt.getWBSCode(gantt.getTask(id)));
// 获取所有任务
var tasksStore = gantt.getDatastore("task");
// console.dir(tasksStore);
let tasks = gantt.getTaskByTime();
console.dir(tasks);
that.$nextTick(() =>{
tasks.forEach(item => {
item.order = item.$index;
});
updateGanttTaskOrder(tasks).then(res => {
console.dir(res);
});
})

// 遍历任务并获取 wbscode
tasks.forEach(function(task){
// 假设 wbscode 是任务数据的一个字段
let wbscode = task.$wbs;
console.log("Task ID:", task.id, "WBSCode:", wbscode,task.text,"序号",task.$index,"wbs",task.$wbs);
});

});

gantt.createDataProcessor({
task: {
create: function(data) {
addGanttData(data)
},
update: function(data, id) {
updateGanttData(data).then(res => {
});
},
delete: function(id) {
delGanttData(id);
}
},
link: {
create: function(data) {
addGanttLinks(data);
},
update: function(data, id) {
updateGanttLinks(data);
},
delete: function(id) {
delGanttLinks(id);
}
}
});

},

getTasks(){
let promiseData = listAllGanttData();
let promiseLink = listAllGanttLinks();
Promise.all([promiseData,promiseLink]).then((res) => {
if(!checkRole(['admin'])){
gantt.config.readonly = true; //只读模式
}
gantt.parse({"data":res[0].rows,"links":res[1].rows});

gantt.event(window, 'mousemove', function(e){
if(!gantt.$container) {
return;
}
var position = gantt.utils.dom.getRelativeEventPosition(e, gantt.$container);
var ganttWidth = gantt.$container.offsetWidth;
var ganttHeight = gantt.$container.offsetHeight;

if(position.x < 0 ||
position.y < 0 ||
position.x > ganttWidth ||
position.y > ganttHeight ) {
gantt.ext.tooltips.tooltip.hide();
}

});

// gantt.sort("order",false); // 排序后wbs会变
})
// listAllGanttData().then(res => {
// gantt.parse({"data":res.rows});
// gantt.sort("start_date", false);
// })
},

},

mounted() {
this.initGantt();
this.getTasks();
},
unmounted() {
this.gantt.destructor();
this.$refs.cont.innerHTML = "";
},

watch: {
// tasks: {
// deep: true,
// handler(val) {
// gantt.parse(val);
// }
// }
},

}
</script>

<style lang="scss">
.gantt_task_progress {
text-align: left;
padding-left: 10px;
box-sizing: border-box;
color: white;
font-weight: bold;
}

.highlighted-column {
background-color: #fff3a1;
}

.gantt_task_scale .gantt_scale_cell {
cursor: default;
}

.gantt_task_scale .gantt_scale_cell.highlighted-column {
color: #454545;
font-weight: bold;
}

.progress-container {
width: 100%;
background-color: #f3f3f3;
border-radius: 5px;
margin-bottom: 5px;
overflow: hidden;
margin-top:5px;
}

.progress-bar {
height: 27px;
width: 0;
background-color: #299cb4;
text-align: center;
line-height: 27px;
color: white;
border-radius: 5px;
transition: width 0.4s ease;
}

.progress-complete-bar {
height: 27px;
width: 0;
background-color: #4caf50;
text-align: center;
line-height: 27px;
color: white;
border-radius: 5px;
transition: width 0.4s ease;
}
</style>

3.数据结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
CREATE TABLE `gantt_data` (
`id` varchar(32) NOT NULL COMMENT '主键',
`text` varchar(255) DEFAULT NULL COMMENT '项目名称',
`start_date` date DEFAULT NULL COMMENT '开始日期',
`end_date` date DEFAULT NULL COMMENT '结束日期',
`duration` int(11) DEFAULT NULL COMMENT '持续天数',
`progress` decimal(10,2) DEFAULT NULL COMMENT '进度',
`open` tinyint(1) DEFAULT '1' COMMENT '打开状态',
`parent` varchar(32) DEFAULT NULL COMMENT '父级id',
`order` int(11) DEFAULT NULL COMMENT '排序',
`priority` varchar(32) DEFAULT NULL COMMENT '优先级',
`category` varchar(32) DEFAULT NULL COMMENT '分类',
`assigned` varchar(255) DEFAULT NULL COMMENT '分配人',
`type` varchar(32) DEFAULT NULL COMMENT '任务类型',
`del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0代表存在 2代表删除)',
`create_by` varchar(64) DEFAULT NULL COMMENT '创建者',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(64) DEFAULT NULL COMMENT '更新者',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='任务数据'
1
2
3
4
5
6
7
CREATE TABLE `gantt_links` (
`id` varchar(32) NOT NULL COMMENT '主键',
`source` varchar(32) DEFAULT NULL COMMENT '源头ID',
`target` varchar(32) DEFAULT NULL COMMENT '目标ID',
`type` varchar(6) DEFAULT NULL COMMENT '类型',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='任务链接'

4.实体类

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
@Data
public class GanttData extends BaseEntity
{
private static final long serialVersionUID = 1L;

/** 主键 */
private String id;

/** 项目名称 */
@Excel(name = "项目名称")
private String text;

/** 开始日期 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "开始日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date startDate;

/** 开始日期 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "开始日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date start_date;

/** 结束日期 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "结束日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date endDate;

/** 结束日期 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "结束日期", width = 30, dateFormat = "yyyy-MM-dd")
private Date end_date;

/** 持续天数 */
@Excel(name = "持续天数")
private Long duration;

/** 进度 */
@Excel(name = "进度")
private BigDecimal progress;

/** 打开状态 */
@Excel(name = "打开状态")
private Integer open;

/** 父级id */
@Excel(name = "父级id")
private String parent;

/** 排序 */
@Excel(name = "排序")
private Long order;

/** 优先级 */
@Excel(name = "优先级")
private String priority;

/** 分类 */
@Excel(name = "分类")
private String category;

/** 删除标志(0代表存在 2代表删除) */
private String delFlag;

/** 分配人 */
@Excel(name = "分配人")
private String assigned;

/** 分类 */
@Excel(name = "任务类型")
private String type;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
@Data
public class GanttLinks extends BaseEntity
{
private static final long serialVersionUID = 1L;

/** 主键 */
private String id;

/** 源头ID */
@Excel(name = "源头ID")
private String source;

/** 目标ID */
@Excel(name = "目标ID")
private String target;

/** 类型 */
@Excel(name = "类型")
private String type;
}

5.Mapper

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
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.GanttDataMapper">

<resultMap type="GanttData" id="GanttDataResult">
<result property="id" column="id" />
<result property="text" column="text" />
<!-- <result property="startDate" column="start_date" />-->
<!-- <result property="endDate" column="end_date" />-->
<result property="start_date" column="start_date" />
<result property="end_date" column="end_date" />
<result property="duration" column="duration" />
<result property="progress" column="progress" />
<result property="open" column="open" />
<result property="parent" column="parent" />
<result property="order" column="order" />
<result property="priority" column="priority" />
<result property="category" column="category" />
<result property="type" column="type" />
<result property="assigned" column="assigned" />
<result property="delFlag" column="del_flag" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>

<sql id="selectGanttDataVo">
select id, text, start_date, end_date, duration, progress, open, parent, `order`, priority, category,type,assigned, del_flag, create_by, create_time, update_by, update_time from gantt_data
</sql>

<select id="selectGanttDataList" parameterType="GanttData" resultMap="GanttDataResult">
<include refid="selectGanttDataVo"/>
<where>
<if test="text != null and text != ''"> and text = #{text}</if>
<!-- <if test="startDate != null "> and start_date = #{startDate}</if>-->
<!-- <if test="endDate != null "> and end_date = #{endDate}</if>-->
<if test="start_date != null "> and start_date = #{start_date}</if>
<if test="end_date != null "> and end_date = #{end_date}</if>
<if test="duration != null "> and duration = #{duration}</if>
<if test="progress != null "> and progress = #{progress}</if>
<if test="open != null "> and open = #{open}</if>
<if test="parent != null and parent != ''"> and parent = #{parent}</if>
<if test="order != null "> and `order` = #{order}</if>
<if test="priority != null and priority != ''"> and priority = #{priority}</if>
<if test="category != null and category != ''"> and category = #{category}</if>
<if test="type != null and type != ''"> and type = #{type}</if>
<if test="assigned != null and assigned != ''"> and assigned like concat('%', #{assigned}, '%')</if>
</where>
</select>

<select id="selectGanttDataById" parameterType="String" resultMap="GanttDataResult">
<include refid="selectGanttDataVo"/>
where id = #{id}
</select>

<insert id="insertGanttData" parameterType="GanttData">
insert into gantt_data
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null and id != ''">id,</if>
<if test="text != null">text,</if>
<!-- <if test="startDate != null">start_date,</if>-->
<!-- <if test="endDate != null">end_date,</if>-->
<if test="start_date != null">start_date,</if>
<if test="end_date != null">end_date,</if>
<if test="duration != null">duration,</if>
<if test="progress != null">progress,</if>
<if test="open != null">open,</if>
<if test="parent != null">parent,</if>
<if test="order != null">`order`,</if>
<if test="priority != null">priority,</if>
<if test="category != null">category,</if>
<if test="type != null">type,</if>
<if test="assigned != null">assigned,</if>
<if test="delFlag != null">del_flag,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null and id != ''">#{id},</if>
<if test="text != null">#{text},</if>
<!-- <if test="startDate != null">#{startDate},</if>-->
<!-- <if test="endDate != null">#{endDate},</if>-->
<if test="start_date != null">#{start_date},</if>
<if test="end_date != null">#{end_date},</if>
<if test="duration != null">#{duration},</if>
<if test="progress != null">#{progress},</if>
<if test="open != null">#{open},</if>
<if test="parent != null">#{parent},</if>
<if test="order != null">#{order},</if>
<if test="priority != null">#{priority},</if>
<if test="category != null">#{category},</if>
<if test="type != null">#{type},</if>
<if test="assigned != null">#{assigned},</if>
<if test="delFlag != null">#{delFlag},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>

<update id="updateGanttData" parameterType="GanttData">
update gantt_data
<trim prefix="SET" suffixOverrides=",">
<if test="text != null">text = #{text},</if>
<!-- <if test="startDate != null">start_date = #{startDate},</if>-->
<!-- <if test="endDate != null">end_date = #{endDate},</if>-->
<if test="start_date != null">start_date = #{start_date},</if>
<if test="end_date != null">end_date = #{end_date},</if>
<if test="duration != null">duration = #{duration},</if>
<if test="progress != null">progress = #{progress},</if>
<if test="open != null">open = #{open},</if>
<if test="parent != null">parent = #{parent},</if>
<if test="order != null">`order` = #{order},</if>
<if test="priority != null">priority = #{priority},</if>
<if test="category != null">category = #{category},</if>
<if test="type != null">type = #{type},</if>
<if test="assigned != null">assigned = #{assigned},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where id = #{id}
</update>

<delete id="deleteGanttDataById" parameterType="String">
delete from gantt_data where id = #{id}
</delete>

<delete id="deleteGanttDataByIds" parameterType="String">
delete from gantt_data where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>

<!-- 插入或更新用户 -->
<insert id="insertOrUpdateGanttData" parameterType="GanttData">
insert into gantt_data (id, text, start_date,end_date,duration,progress,open,parent,`order`,priority
,category,type,assigned,del_flag,create_by,create_time,update_by,update_time)
VALUES (#{id},#{text},#{start_date},#{end_date},#{duration},#{progress},#{open},#{parent},#{order}
,#{priority},#{category},#{type},#{assigned},#{delFlag},#{createBy},#{createTime},#{updateBy},#{updateTime})
ON DUPLICATE KEY UPDATE
text = VALUES(text),
start_date = VALUES(start_date),
end_date = VALUES(end_date),
duration = VALUES(duration),
progress = VALUES(progress),
open = VALUES(open),
parent = VALUES(parent),
`order` = VALUES(`order`),
priority = VALUES(priority),
category = VALUES(category),
type = VALUES(type),
assigned = VALUES(assigned),
update_by = VALUES(update_by),
update_time = VALUES(update_time)
</insert>

<update id="updateGanttTaskOpenById" parameterType="GanttData">
update gantt_data set open = #{open}
where id = #{id}
</update>
</mapper>
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
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.GanttLinksMapper">

<resultMap type="GanttLinks" id="GanttLinksResult">
<result property="id" column="id" />
<result property="source" column="source" />
<result property="target" column="target" />
<result property="type" column="type" />
</resultMap>

<sql id="selectGanttLinksVo">
select id, source, target, type from gantt_links
</sql>

<select id="selectGanttLinksList" parameterType="GanttLinks" resultMap="GanttLinksResult">
<include refid="selectGanttLinksVo"/>
<where>
<if test="source != null and source != ''"> and source = #{source}</if>
<if test="target != null and target != ''"> and target = #{target}</if>
<if test="type != null and type != ''"> and type = #{type}</if>
</where>
</select>

<select id="selectGanttLinksById" parameterType="String" resultMap="GanttLinksResult">
<include refid="selectGanttLinksVo"/>
where id = #{id}
</select>

<insert id="insertGanttLinks" parameterType="GanttLinks">
insert into gantt_links
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null and id != ''">id,</if>
<if test="source != null">source,</if>
<if test="target != null">target,</if>
<if test="type != null">type,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null and id != ''">#{id},</if>
<if test="source != null">#{source},</if>
<if test="target != null">#{target},</if>
<if test="type != null">#{type},</if>
</trim>
</insert>

<update id="updateGanttLinks" parameterType="GanttLinks">
update gantt_links
<trim prefix="SET" suffixOverrides=",">
<if test="source != null">source = #{source},</if>
<if test="target != null">target = #{target},</if>
<if test="type != null">type = #{type},</if>
</trim>
where id = #{id}
</update>

<delete id="deleteGanttLinksById" parameterType="String">
delete from gantt_links where id = #{id}
</delete>

<delete id="deleteGanttLinksByIds" parameterType="String">
delete from gantt_links where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

DHTMLX Gantt集成源码
http://eevann.cn/2024/07/17/DhtmlxGantt-springboot/
作者
月下独白
发布于
2024年7月18日
许可协议