line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Vue::Crud; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
52744
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use Exporter; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
7
|
1
|
|
|
1
|
|
375
|
use parent 'Exporter'; |
|
1
|
|
|
|
|
231
|
|
|
1
|
|
|
|
|
4
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
10
|
|
|
|
|
|
|
# Mojo DBI 版本信息 |
11
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
12
|
|
|
|
|
|
|
our $VERSION = '0.0.2'; |
13
|
|
|
|
|
|
|
our @EXPORT = qw "vue_crud_get"; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
16
|
|
|
|
|
|
|
# 导出函数到外部,用来适配 VUE CRUD 数据结构 |
17
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
18
|
|
|
|
|
|
|
sub vue_crud_get { |
19
|
|
|
|
|
|
|
# 接收外部入参 - 前端查询变量 和 查询对象 |
20
|
0
|
|
|
0
|
0
|
|
my $params = shift; |
21
|
0
|
|
|
|
|
|
my $table = shift; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# 截取前端哈希长度 |
24
|
0
|
|
|
|
|
|
my $count = scalar( keys %{$params} ); |
|
0
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# 获取前端入参 |
27
|
0
|
|
0
|
|
|
|
my $page = $params->{"page"} || 0; |
28
|
0
|
|
0
|
|
|
|
my $size = $params->{"size"} || 10; |
29
|
0
|
|
0
|
|
|
|
my $sort = $params->{"sort"} || "id desc"; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# 提取 query 字段变量 |
32
|
0
|
|
|
|
|
|
my $time = $params->{"createTime"}; |
33
|
0
|
|
|
|
|
|
my $query = grep { !/page|size|sort|createTime/ } ( keys %{$params} ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
my $query_str = $params->{$query} if defined $query; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# 处理排序规则 |
37
|
0
|
0
|
|
|
|
|
$sort = join( " ", split( /,/, $sort ) ) if ( $sort =~ /,/ ); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# 计算数据偏移量 |
40
|
0
|
|
|
|
|
|
my $offset = $page * $size; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# 初始化 SQL 语句变量 |
43
|
0
|
|
|
|
|
|
my $sql_str = "SELECT * FROM $table"; |
44
|
0
|
|
|
|
|
|
my $order_str = " ORDER BY $sort LIMIT $offset, $size"; |
45
|
0
|
0
|
|
|
|
|
my $name_str = " WHERE $query LIKE \'%$query_str%\'" if defined $query_str; |
46
|
0
|
0
|
|
|
|
|
my $time_str = " create_time BETWEEN \'$time->[0]\' AND \'$time->[1]\'" if $time; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# 对数据进行判断 |
49
|
0
|
0
|
|
|
|
|
if ( $count == 3 ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
return $sql_str . $order_str; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
elsif ( $count == 4 ) { |
53
|
0
|
0
|
|
|
|
|
if ($name_str) { |
|
|
0
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
return $sql_str . $name_str . $order_str; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
elsif ($time_str) { |
57
|
0
|
|
|
|
|
|
return $sql_str . " WHERE" . $time_str . $order_str; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
elsif ( $count == 5 ) { |
61
|
0
|
|
|
|
|
|
return $sql_str . $name_str . " AND" . $time_str . $order_str; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |