Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
commit
420361456c
|
@ -1,5 +1,16 @@
|
|||
apply plugin: 'org.springframework.boot'
|
||||
|
||||
dependencies {
|
||||
compile("org.springframework.boot:spring-boot-configuration-processor")
|
||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||
}
|
||||
|
||||
jar.enabled = true
|
||||
|
||||
jar{
|
||||
manifest {
|
||||
attributes('Implementation-Title': 'Diboot core',
|
||||
'Implementation-Version': '2.0.3'
|
||||
)
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package com.diboot.core.binding.manager;
|
||||
|
||||
import com.diboot.core.binding.RelationsBinder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 绑定管理器 (已废弃,请调用RelationsBinder)
|
||||
* @author Mazhicheng
|
||||
* @version v2.0
|
||||
* @date 2019/3/30
|
||||
* @see RelationsBinder
|
||||
*/
|
||||
@Deprecated
|
||||
public class AnnotationBindingManager {
|
||||
private static final Logger log = LoggerFactory.getLogger(AnnotationBindingManager.class);
|
||||
|
||||
/**
|
||||
* 自动转换和绑定VO中的注解关联
|
||||
* @param entityList
|
||||
* @param voClass
|
||||
* @param <E>
|
||||
* @param <VO>
|
||||
* @return
|
||||
*/
|
||||
public static <E, VO> List<VO> autoConvertAndBind(List<E> entityList, Class<VO> voClass){
|
||||
return RelationsBinder.convertAndBind(entityList, voClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动绑定关联对象
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static <VO> void autoBind(List<VO> voList){
|
||||
RelationsBinder.bind(voList);
|
||||
}
|
||||
|
||||
}
|
|
@ -90,7 +90,7 @@ public interface BaseService<T> {
|
|||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
boolean deleteEntities(Wrapper queryWrapper) throws Exception;
|
||||
boolean deleteEntities(Wrapper queryWrapper);
|
||||
|
||||
/**
|
||||
* 获取符合条件的entity记录总数
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.diboot.core.service;
|
|||
import com.diboot.core.entity.Dictionary;
|
||||
import com.diboot.core.util.IGetter;
|
||||
import com.diboot.core.util.ISetter;
|
||||
import com.diboot.core.vo.DictionaryVO;
|
||||
import com.diboot.core.vo.KeyValue;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -41,4 +42,11 @@ public interface DictionaryService extends BaseService<Dictionary>{
|
|||
* @param getFieldName
|
||||
*/
|
||||
void bindItemLabel(List voList, String setFieldName, String getFieldName, String type);
|
||||
|
||||
/***
|
||||
* 添加多层级数据字典
|
||||
* @param dictionaryVO
|
||||
* @return
|
||||
*/
|
||||
boolean addDictTree(DictionaryVO dictionaryVO);
|
||||
}
|
||||
|
|
|
@ -110,10 +110,9 @@ public class BaseServiceImpl<M extends BaseCrudMapper<T>, T> extends ServiceImpl
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteEntities(Wrapper queryWrapper) throws Exception{
|
||||
public boolean deleteEntities(Wrapper queryWrapper){
|
||||
// 执行
|
||||
boolean success = super.remove(queryWrapper);
|
||||
return success;
|
||||
return super.remove(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,10 +6,12 @@ import com.diboot.core.entity.Dictionary;
|
|||
import com.diboot.core.mapper.DictionaryMapper;
|
||||
import com.diboot.core.service.DictionaryService;
|
||||
import com.diboot.core.util.*;
|
||||
import com.diboot.core.vo.DictionaryVO;
|
||||
import com.diboot.core.vo.KeyValue;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -19,7 +21,7 @@ import java.util.List;
|
|||
* @version 2.0
|
||||
* @date 2019/01/01
|
||||
*/
|
||||
@Service
|
||||
@Service("dictionaryService")
|
||||
public class DictionaryServiceImpl extends BaseServiceImpl<DictionaryMapper, Dictionary> implements DictionaryService {
|
||||
private static final Logger log = LoggerFactory.getLogger(DictionaryServiceImpl.class);
|
||||
|
||||
|
@ -66,4 +68,34 @@ public class DictionaryServiceImpl extends BaseServiceImpl<DictionaryMapper, Dic
|
|||
.andGT(FIELD_NAME_PARENT_ID, 0)
|
||||
.bind();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean addDictTree(DictionaryVO dictVO) {
|
||||
//将DictionaryVO转化为Dictionary
|
||||
Dictionary dictionary = new Dictionary();
|
||||
dictionary = (Dictionary) BeanUtils.copyProperties(dictVO, dictionary);
|
||||
if(!super.createEntity(dictionary)){
|
||||
log.warn("新建父数据字典失败,type="+dictVO.getType());
|
||||
return false;
|
||||
}
|
||||
List<Dictionary> children = dictVO.getChildren();
|
||||
if(V.notEmpty(children)){
|
||||
try {
|
||||
for(Dictionary dict : children){
|
||||
dict.setParentId(dictionary.getId());
|
||||
dict.setType(dictionary.getType());
|
||||
}
|
||||
if(!super.createEntities(children)){
|
||||
log.warn("新建子数据字典失败,type="+dictVO.getType());
|
||||
throw new RuntimeException();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("新建子数据字典失败,type="+dictVO.getType());
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.springframework.context.ApplicationContextAware;
|
|||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.ArrayList;
|
||||
|
@ -50,6 +51,9 @@ public class ContextHelper implements ApplicationContextAware {
|
|||
* 获取ApplicationContext上下文
|
||||
*/
|
||||
public static ApplicationContext getApplicationContext() {
|
||||
if (APPLICATION_CONTEXT == null){
|
||||
return ContextLoader.getCurrentWebApplicationContext();
|
||||
}
|
||||
return APPLICATION_CONTEXT;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package com.diboot.core.vo;
|
||||
|
||||
import com.diboot.core.binding.annotation.BindEntityList;
|
||||
import com.diboot.core.entity.Dictionary;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DictionaryVO extends Dictionary {
|
||||
|
||||
@BindEntityList(entity= Dictionary.class, condition="this.type=type AND parent_id>0 AND is_deleted=0")
|
||||
private List<Dictionary> children; //KEEP
|
||||
|
||||
public List<Dictionary> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<Dictionary> children) {
|
||||
this.children = children;
|
||||
}
|
||||
}
|
|
@ -40,9 +40,9 @@ public class Pagination implements Serializable {
|
|||
*/
|
||||
private List<String> ascList = null;
|
||||
/***
|
||||
* 降序排列的字段(默认以ID降序排列,当指定了其他排列方式时以用户指定为准)
|
||||
* 降序排列的字段(默认以create_time降序排列,当指定了其他排列方式时以用户指定为准)
|
||||
*/
|
||||
private List<String> descList = new ArrayList<>(Arrays.asList(Cons.FieldName.id.name()));
|
||||
private List<String> descList = new ArrayList<>(Arrays.asList("create_time"));
|
||||
|
||||
public Pagination(){
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package diboot.core.test.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.diboot.core.config.BaseConfig;
|
||||
import com.diboot.core.entity.Dictionary;
|
||||
import com.diboot.core.service.DictionaryService;
|
||||
import com.diboot.core.util.BeanUtils;
|
||||
import com.diboot.core.util.SqlExecutor;
|
||||
import com.diboot.core.util.V;
|
||||
import com.diboot.core.vo.Pagination;
|
||||
import diboot.core.test.StartupApplication;
|
||||
|
@ -13,6 +15,7 @@ import org.junit.Assert;
|
|||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
@ -32,6 +35,7 @@ import java.util.List;
|
|||
public class BaseServiceTest {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("dictionaryService")
|
||||
DictionaryService dictionaryService;
|
||||
|
||||
@Test
|
||||
|
@ -74,7 +78,7 @@ public class BaseServiceTest {
|
|||
String TYPE = "ID_TYPE";
|
||||
Dictionary dictionary = new Dictionary();
|
||||
dictionary.setType(TYPE);
|
||||
dictionary.setItemName("证件品类");
|
||||
dictionary.setItemName("证件类型");
|
||||
dictionary.setParentId(0L);
|
||||
dictionaryService.createEntity(dictionary);
|
||||
|
||||
|
@ -85,15 +89,62 @@ public class BaseServiceTest {
|
|||
Assert.assertTrue(V.notEmpty(dictionaryList));
|
||||
|
||||
// 更新
|
||||
dictionary.setItemName("证件类型");
|
||||
dictionary.setItemName("证件类型定义");
|
||||
dictionaryService.updateEntity(dictionary);
|
||||
Dictionary dictionary2 = dictionaryService.getEntity(dictionary.getId());
|
||||
Assert.assertTrue(dictionary2.getItemName().equals(dictionary.getItemName()));
|
||||
|
||||
// 删除
|
||||
dictionaryService.deleteEntity(dictionary.getId());
|
||||
clearTestData(TYPE);
|
||||
dictionary2 = dictionaryService.getEntity(dictionary.getId());
|
||||
Assert.assertTrue(dictionary2 == null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBatchCreate(){
|
||||
// 创建
|
||||
String TYPE = "ID_TYPE";
|
||||
// 定义
|
||||
Dictionary dictionary = new Dictionary();
|
||||
dictionary.setType(TYPE);
|
||||
dictionary.setItemName("证件类型");
|
||||
dictionary.setParentId(0L);
|
||||
boolean success = dictionaryService.createEntity(dictionary);
|
||||
Assert.assertTrue(success);
|
||||
|
||||
// 子项
|
||||
List<Dictionary> dictionaryList = new ArrayList<>();
|
||||
String[] itemNames = {"身份证", "驾照", "护照"}, itemValues = {"SFZ","JZ","HZ"};
|
||||
for(int i=0; i<itemNames.length; i++){
|
||||
Dictionary dict = new Dictionary();
|
||||
dict.setType(TYPE);
|
||||
dict.setItemName(itemNames[i]);
|
||||
dict.setItemValue(itemValues[i]);
|
||||
dict.setParentId(dictionary.getId());
|
||||
dictionaryList.add(dict);
|
||||
}
|
||||
success = dictionaryService.createEntities(dictionaryList);
|
||||
Assert.assertTrue(success);
|
||||
|
||||
success = clearTestData(TYPE);
|
||||
Assert.assertTrue(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空测试数据
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
private boolean clearTestData(String type){
|
||||
List params = new ArrayList();
|
||||
params.add(type);
|
||||
try{
|
||||
SqlExecutor.executeUpdate("DELETE FROM dictionary WHERE type=?", params);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,2 +1,3 @@
|
|||
## diboot-example: 各组件/模块的使用样例
|
||||
本地运行test单元测试需先执行/test/resources/init-{db}.sql到你的数据库(暂提供Mysql脚本)。
|
||||
样例项目已迁移至: : [diboot-v2-example](https://github.com/dibo-software/diboot-v2-example "示例代码").
|
||||
|
||||
|
|
|
@ -8,27 +8,26 @@ create table department
|
|||
org_id bigint not null comment '单位ID',
|
||||
name varchar(50) not null comment '名称',
|
||||
extdata varchar(100) null comment '扩展字段',
|
||||
deleted tinyint(1) default 0 not null comment '已删除',
|
||||
is_deleted tinyint(1) default 0 not null comment '已删除',
|
||||
create_time timestamp default CURRENT_TIMESTAMP not null comment '创建时间'
|
||||
)
|
||||
comment '组织单位' charset=utf8mb4;
|
||||
|
||||
create table dictionary
|
||||
(
|
||||
id int unsigned auto_increment comment 'ID'
|
||||
primary key,
|
||||
parent_id int unsigned not null comment '父ID',
|
||||
type varchar(50) not null comment '字典类型',
|
||||
item_name varchar(100) not null comment '字典项显示名',
|
||||
item_value varchar(100) null comment '字典项存储值',
|
||||
comment varchar(200) null comment '备注',
|
||||
extdata varchar(200) null comment '扩展属性',
|
||||
sort_id smallint(6) default 99 not null comment '排序号',
|
||||
`system` tinyint(1) default 0 not null comment '是否系统预置',
|
||||
editable tinyint(1) default 1 not null comment '是否可编辑',
|
||||
deleted tinyint(1) default 0 not null comment '已删除',
|
||||
create_time timestamp default CURRENT_TIMESTAMP not null comment '创建时间'
|
||||
);
|
||||
CREATE TABLE `dictionary` (
|
||||
`id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
|
||||
`parent_id` int unsigned NOT NULL COMMENT '父ID',
|
||||
`type` varchar(50) NOT NULL COMMENT '字典类型',
|
||||
`item_name` varchar(100) NOT NULL COMMENT '显示名',
|
||||
`item_value` varchar(100) DEFAULT NULL COMMENT '存储值',
|
||||
`description` varchar(100) DEFAULT NULL COMMENT '描述说明',
|
||||
`extdata` varchar(200) DEFAULT NULL COMMENT '扩展JSON',
|
||||
`sort_id` smallint NOT NULL DEFAULT '99' COMMENT '排序号',
|
||||
`is_editable` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否可改',
|
||||
`is_deletable` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否可删',
|
||||
`is_deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '删除标记',
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COMMENT '数据字典';
|
||||
|
||||
create table organization
|
||||
(
|
||||
|
@ -37,7 +36,7 @@ create table organization
|
|||
parent_id int default 0 not null comment '上级单位ID',
|
||||
name varchar(100) not null comment '名称',
|
||||
telphone varchar(20) null comment '电话',
|
||||
deleted tinyint(1) default 0 not null comment '是否有效',
|
||||
is_deleted tinyint(1) default 0 not null comment '是否有效',
|
||||
create_time timestamp default CURRENT_TIMESTAMP not null comment '创建时间'
|
||||
)
|
||||
comment '组织单位' charset=utf8mb4;
|
||||
|
@ -48,7 +47,7 @@ create table role
|
|||
primary key,
|
||||
name varchar(20) null,
|
||||
code varchar(20) null,
|
||||
deleted tinyint(1) default 0 null,
|
||||
is_deleted tinyint(1) default 0 null,
|
||||
create_time timestamp default CURRENT_TIMESTAMP null comment '创建时间'
|
||||
);
|
||||
|
||||
|
@ -59,7 +58,7 @@ create table user
|
|||
department_id int default 0 not null,
|
||||
username varchar(20) null,
|
||||
gender varchar(20) null,
|
||||
deleted tinyint(1) default 0 null,
|
||||
is_deleted tinyint(1) default 0 null,
|
||||
create_time timestamp default CURRENT_TIMESTAMP null comment '创建时间'
|
||||
);
|
||||
|
||||
|
@ -74,8 +73,8 @@ create table user_role
|
|||
INSERT INTO department (id, parent_id, org_id, name)
|
||||
VALUES (10001, 0, 100001, '产品部'), (10002, 10001, 100001, '研发组'), (10003, 10001, 100001, '测试组');
|
||||
|
||||
INSERT INTO dictionary (id, parent_id, type, item_name, item_value, comment, extdata, sort_id, `system`, editable)
|
||||
VALUES (1, 0, 'GENDER', '性别', null, '', null, 99, 1, 1), (2, 1, 'GENDER', '男', 'M', null, null, 99, 1, 0), (3, 1, 'GENDER', '女', 'F', null, null, 99, 1, 0);
|
||||
INSERT INTO dictionary (id, parent_id, type, item_name, item_value, description, extdata, sort_id, `is_deletable`, is_editable)
|
||||
VALUES (1, 0, 'GENDER', '性别', null, '', null, 99, 0, 1), (2, 1, 'GENDER', '男', 'M', null, null, 99, 0, 1), (3, 1, 'GENDER', '女', 'F', null, null, 99, 0, 1);
|
||||
|
||||
INSERT INTO organization (id, parent_id, name, telphone) VALUES (100001, 0, '苏州帝博', '0512-62988949');
|
||||
|
||||
|
|
Loading…
Reference in New Issue