Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
74734544
Commit
74734544
authored
Mar 21, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
判断是否登录
parent
d738a26b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
232 additions
and
0 deletions
+232
-0
BaseService.java
.../main/java/com/yanzuoguang/db/db/service/BaseService.java
+44
-0
BaseServiceImpl.java
...a/com/yanzuoguang/db/db/service/Impl/BaseServiceImpl.java
+188
-0
readme.txt
...db/src/main/java/com/yanzuoguang/db/db/service/readme.txt
+0
-0
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/db/db/service/BaseService.java
0 → 100644
View file @
74734544
package
com
.
yanzuoguang
.
db
.
db
.
service
;
import
java.util.List
;
/**
* 基本服务接口
* created by yanzu on 2017/5/29.
*/
public
interface
BaseService
<
T
>
{
/**
* 创建数据
*
* @param models 需要创建的数据
*/
List
<
String
>
create
(
T
...
models
);
/**
* 修改数据
*
* @param models 需要修改的数据
*/
List
<
String
>
update
(
T
...
models
);
/**
* 保存数据
*
* @param models 需要保存的数据
*/
List
<
String
>
save
(
T
...
models
);
/**
* 删除数据
*
* @param models 需要删除的数据
*/
List
<
String
>
remove
(
T
...
models
);
/**
* 加载数据
*
* @param models 需要删除的数据
*/
List
<
T
>
load
(
T
...
models
);
}
yzg-util-db/src/main/java/com/yanzuoguang/db/db/service/Impl/BaseServiceImpl.java
0 → 100644
View file @
74734544
package
com
.
yanzuoguang
.
db
.
db
.
service
.
Impl
;
import
com.yanzuoguang.db.db.dao.BaseDao
;
import
com.yanzuoguang.db.db.service.BaseService
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* 基本服务实现
* created by yanzu on 2017/5/31.
*/
public
abstract
class
BaseServiceImpl
<
T
>
implements
BaseService
<
T
>
{
/**
* 数据类的类型
*/
protected
Class
<
T
>
dataClass
;
/**
* 标识
*/
protected
String
tag
;
/**
* 构造函数
*
* @param cls
*/
public
BaseServiceImpl
(
Class
<
T
>
cls
,
String
tag
)
{
this
.
dataClass
=
cls
;
this
.
tag
=
tag
;
}
/**
* @param
* @return
* @description 获取Dao类来处理
*/
protected
abstract
BaseDao
getDao
();
/**
* 创建数据
*
* @param models 需要创建的数据
*/
public
List
<
String
>
create
(
T
...
models
)
{
List
<
String
>
ids
=
new
ArrayList
<
String
>();
for
(
T
t
:
models
)
{
String
id
=
createItem
(
t
);
ids
.
add
(
id
);
}
return
ids
;
}
/**
* 创建一项
*
* @param item
* @return
*/
protected
String
createItem
(
T
item
)
{
String
id
=
this
.
getDao
().
create
(
item
);
check
(
"创建"
,
this
.
tag
,
id
);
return
id
;
}
/**
* 修改数据
*
* @param models 需要修改的数据
*/
public
List
<
String
>
update
(
T
...
models
)
{
List
<
String
>
ids
=
new
ArrayList
<
String
>();
for
(
T
t
:
models
)
{
String
id
=
updateItem
(
t
);
ids
.
add
(
id
);
}
return
ids
;
}
/**
* 修改一项数据
*
* @param item
* @return
*/
protected
String
updateItem
(
T
item
)
{
String
id
=
this
.
getDao
().
update
(
item
);
check
(
"修改"
,
this
.
tag
,
id
);
return
id
;
}
/**
* 保存数据
*
* @param models 需要保存的数据
*/
public
List
<
String
>
save
(
T
...
models
)
{
List
<
String
>
ids
=
new
ArrayList
<
String
>();
for
(
T
item
:
models
)
{
String
id
=
saveItem
(
item
);
ids
.
add
(
id
);
}
return
ids
;
}
/**
* 保存其中一项
*
* @param item
* @return
*/
protected
String
saveItem
(
T
item
)
{
String
id
=
this
.
getDao
().
save
(
item
);
check
(
"保存"
,
this
.
tag
,
id
);
return
id
;
}
/**
* 删除数据
*
* @param models 需要删除的数据
*/
public
List
<
String
>
remove
(
T
...
models
)
{
List
<
String
>
ids
=
new
ArrayList
<
String
>();
for
(
T
item
:
models
)
{
String
id
=
removeItem
(
item
);
ids
.
add
(
id
);
}
return
ids
;
}
/**
* 删除其中一项
*
* @param item
* @return
*/
protected
String
removeItem
(
T
item
)
{
String
id
=
this
.
getDao
().
remove
(
item
);
check
(
"删除"
,
this
.
tag
,
id
);
return
id
;
}
/**
* 加载数据
*
* @param models 需要删除的数据
*/
public
List
<
T
>
load
(
T
...
models
)
{
List
<
T
>
tos
=
new
ArrayList
<
T
>();
for
(
T
item
:
models
)
{
T
to
=
loadItem
(
item
);
tos
.
add
(
to
);
}
return
tos
;
}
/**
* 加载单个数据
*
* @param item
* @return
*/
protected
T
loadItem
(
T
item
)
{
T
to
=
this
.
getDao
().
load
(
item
,
dataClass
);
check
(
"加载"
,
this
.
tag
,
to
);
return
to
;
}
/**
* 检测编号
*
* @param opTag 操作标识
* @param serviceTag 服务标识
* @param id ID编号
*/
private
void
check
(
String
opTag
,
String
serviceTag
,
Object
id
)
{
if
(
StringHelper
.
isEmpty
(
id
))
{
throw
new
CodeException
(
opTag
+
serviceTag
+
"失败,该数据可能已被修改"
);
}
}
}
yzg-util-db/src/main/java/com/yanzuoguang/db/db/service/readme.txt
0 → 100644
View file @
74734544
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment