Skip to content

Commit 043b7de

Browse files
committed
优化命名
1 parent 0198fd2 commit 043b7de

File tree

25 files changed

+113
-114
lines changed

25 files changed

+113
-114
lines changed

hsweb-commons/hsweb-commons-controller/src/main/java/org/hswebframework/web/controller/GenericEntityController.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@
2020

2121
import org.hswebframework.web.commons.entity.Entity;
2222
import org.hswebframework.web.commons.entity.GenericEntity;
23-
import org.hswebframework.web.controller.message.ResponseMessage;
2423
import org.hswebframework.web.service.CrudService;
25-
import org.springframework.web.bind.annotation.PathVariable;
26-
import org.springframework.web.bind.annotation.RequestBody;
27-
28-
import static org.hswebframework.web.controller.message.ResponseMessage.ok;
2924

3025
/**
3126
* 通用实体的增删改查控制器
@@ -39,11 +34,4 @@ public interface GenericEntityController<E extends GenericEntity<PK>, PK, Q exte
3934
extends CrudController<E, PK, Q> {
4035

4136
CrudService<E, PK> getService();
42-
43-
@Override
44-
default ResponseMessage updateByPrimaryKey(@PathVariable PK id, @RequestBody E data) {
45-
// 设置id属性
46-
data.setId(id);
47-
return ok(getService().updateByPk(data));
48-
}
4937
}

hsweb-commons/hsweb-commons-controller/src/main/java/org/hswebframework/web/controller/GenericEntityUpdateController.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

hsweb-commons/hsweb-commons-controller/src/main/java/org/hswebframework/web/controller/QueryController.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.hswebframework.web.controller;
1919

20+
import org.hswebframework.web.NotFoundException;
2021
import org.hswebframework.web.authorization.Permission;
2122
import org.hswebframework.web.authorization.annotation.Authorize;
2223
import org.hswebframework.web.commons.entity.Entity;
@@ -71,7 +72,12 @@ default ResponseMessage list(Q param) {
7172
@GetMapping(path = "/{id}")
7273
@AccessLogger("{get_by_id}")
7374
default ResponseMessage getByPrimaryKey(@PathVariable PK id) {
74-
return ok(getService().selectByPk(id));
75+
return ok(assertNotNull(getService().selectByPk(id)));
76+
}
77+
78+
static Object assertNotNull(Object obj) {
79+
if (null == obj) throw new NotFoundException("{data_not_exist}");
80+
return obj;
7581
}
7682

7783
}

hsweb-commons/hsweb-commons-controller/src/main/java/org/hswebframework/web/controller/UpdateController.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717

1818
package org.hswebframework.web.controller;
1919

20+
2021
import org.hswebframework.web.authorization.Permission;
2122
import org.hswebframework.web.authorization.annotation.Authorize;
2223
import org.hswebframework.web.controller.message.ResponseMessage;
2324
import org.hswebframework.web.logging.AccessLogger;
25+
import org.hswebframework.web.service.UpdateService;
2426
import org.springframework.web.bind.annotation.PathVariable;
2527
import org.springframework.web.bind.annotation.PutMapping;
2628
import org.springframework.web.bind.annotation.RequestBody;
@@ -31,8 +33,12 @@
3133
* @author zhouhao
3234
*/
3335
public interface UpdateController<E, PK> {
36+
UpdateService<E, PK> getService();
37+
3438
@Authorize(action = Permission.ACTION_UPDATE)
3539
@PutMapping(path = "/{id}")
3640
@AccessLogger("{update_by_primary_key}")
37-
ResponseMessage updateByPrimaryKey(@PathVariable PK id, @RequestBody E data);
41+
default ResponseMessage updateByPrimaryKey(@PathVariable PK id, @RequestBody E data) {
42+
return ResponseMessage.ok(getService().updateByPk(id, data));
43+
}
3844
}

hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/CrudDao.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,26 @@
1919
package org.hswebframework.web.dao;
2020

2121
import org.hswebframework.web.dao.dynamic.UpdateByEntityDao;
22-
import org.hswebframework.web.dao.dynamic.DeleteByBeanDao;
23-
import org.hswebframework.web.dao.dynamic.QueryByBeanDao;
22+
import org.hswebframework.web.dao.dynamic.DeleteByEntityDao;
23+
import org.hswebframework.web.dao.dynamic.QueryByEntityDao;
2424

2525
/**
26-
* TODO 完成注释
26+
* 通用增删改查DAO接口,定义了增删改查.以及动态条件查询,修改,删除。
2727
*
28+
* @param <E> PO类型
29+
* @param <PK> 主键类型
2830
* @author zhouhao
31+
* @see InsertDao
32+
* @see DeleteDao
33+
* @see DeleteByEntityDao
34+
* @see UpdateByEntityDao
35+
* @see QueryByEntityDao
36+
* @since 3.0
2937
*/
30-
public interface CrudDao<PO, PK> extends
31-
InsertDao<PO>,
38+
public interface CrudDao<E, PK> extends
39+
InsertDao<E>,
3240
DeleteDao<PK>,
33-
DeleteByBeanDao,
41+
DeleteByEntityDao,
3442
UpdateByEntityDao,
35-
QueryByBeanDao<PO> {
43+
QueryByEntityDao<E> {
3644
}

hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/Dao.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
package org.hswebframework.web.dao;
2020

2121
/**
22-
* TODO 完成注释
22+
* Dao的总接口,用于标识类为Dao
2323
*
2424
* @author zhouhao
25+
* @since 3.0
2526
*/
2627
public interface Dao {
2728
}

hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/DeleteDao.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,18 @@
1919
package org.hswebframework.web.dao;
2020

2121
/**
22-
* TODO 完成注释
22+
* 通用删除dao
2323
*
24+
* @param <PK> 主键类型
2425
* @author zhouhao
2526
* @since 3.0
2627
*/
27-
public interface DeleteDao<PK> extends Dao{
28+
public interface DeleteDao<PK> extends Dao {
29+
/**
30+
* 根据主键删除数据,并返回被删除数据的数量
31+
*
32+
* @param pk 主键
33+
* @return 删除的数据数量, 理论上此返回值应该为0或者1.
34+
*/
2835
int deleteByPk(PK pk);
2936
}

hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/InsertDao.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
package org.hswebframework.web.dao;
2020

2121
/**
22-
* TODO 完成注释
22+
* 通用数据插入DAO接口
2323
*
2424
* @author zhouhao
2525
* @since 3.0
2626
*/
27-
public interface InsertDao<PO> extends Dao {
28-
void insert(PO po);
27+
public interface InsertDao<E> extends Dao {
28+
void insert(E e);
2929
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
import org.hswebframework.web.commons.entity.Entity;
2222

2323
/**
24-
* TODO 完成注释
24+
* 根据实体类条件进行删除,删除条件根据实体类进行解析。解析方式和{@link QueryByEntityDao#query}一致
2525
*
2626
* @author zhouhao
2727
* @since 3.0
2828
*/
29-
public interface DeleteByBeanDao {
29+
public interface DeleteByEntityDao {
3030
int delete(Entity entity);
3131
}

hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/dynamic/QueryByEntityDao.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import java.util.List;
2424

2525
/**
26-
* TODO 完成注释
27-
*
26+
* 根据实体类动态查询,可传入特定的实体类进行查询。
27+
* 目前支持{@link org.hswebframework.web.commons.entity.param.QueryParamEntity} 动态查询
2828
* @author zhouhao
2929
* @since 3.0
3030
*/

hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-api/src/main/java/org/hswebframework/web/dao/dynamic/UpdateByEntityDao.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
import org.hswebframework.web.commons.entity.Entity;
2222

2323
/**
24-
* TODO 完成注释
24+
* 根据实体类进行更新,实体类支持动态条件或者普通实体类。
25+
* 动态条件和{@link QueryByEntityDao#query(Entity)} 一致。
2526
*
2627
* @author zhouhao
2728
* @since 3.0

hsweb-commons/hsweb-commons-dao/hsweb-commons-dao-mybatis/src/main/java/org/hswebframework/web/dao/mybatis/builder/EasyOrmSqlBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ public String buildUpdateFields(String resultMapId, String tableName, UpdatePara
179179
"}");
180180
});
181181
if (!appender.isEmpty()) appender.removeFirst();
182+
else throw new UnsupportedOperationException("{no_columns_will_be_update}");
182183
return appender.toString();
183184
}
184185

hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/RecordCreationEntity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
* @since 3.0
99
*/
1010
public interface RecordCreationEntity extends Entity {
11+
12+
String creatorId = "creatorId";
13+
String createTime = "createTime";
14+
1115
String getCreatorId();
1216

1317
void setCreatorId(String creatorId);

hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/SimpleTreeSortSupportEntity.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
package org.hswebframework.web.commons.entity;
2020

21-
import org.hswebframework.web.Describe;
2221

2322
/**
2423
* 支持树形结构,排序的实体类,要使用树形结构,排序功能的实体类直接继承该类
@@ -28,21 +27,20 @@ public abstract class SimpleTreeSortSupportEntity<PK> extends SimpleGenericEntit
2827
/**
2928
* 父级类别
3029
*/
31-
@Describe("父级类别ID")
3230
private PK parentId;
3331

3432
/**
3533
* 树结构编码,用于快速查找, 每一层由4位字符组成,用-分割
3634
* 如第一层:0001 第二层:0001-0001 第三层:0001-0001-0001
3735
*/
38-
@Describe("树识别码")
3936
private String treeCode;
4037

4138
/**
4239
* 排序索引
4340
*/
44-
@Describe("排序索引")
45-
private long sortIndex;
41+
private Long sortIndex;
42+
43+
private Integer level;
4644

4745
@Override
4846
public String getTreeCode() {
@@ -65,12 +63,22 @@ public void setParentId(PK parentId) {
6563
}
6664

6765
@Override
68-
public long getSortIndex() {
66+
public Long getSortIndex() {
6967
return sortIndex;
7068
}
7169

7270
@Override
73-
public void setSortIndex(long sortIndex) {
71+
public Integer getLevel() {
72+
return level;
73+
}
74+
75+
@Override
76+
public void setLevel(Integer level) {
77+
this.level = level;
78+
}
79+
80+
@Override
81+
public void setSortIndex(Long sortIndex) {
7482
this.sortIndex = sortIndex;
7583
}
7684

hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/SortSupportEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
public interface SortSupportEntity extends Comparable<SortSupportEntity>, Entity {
2222

23-
long getSortIndex();
23+
Long getSortIndex();
2424

25-
void setSortIndex(long sortIndex);
25+
void setSortIndex(Long sortIndex);
2626

2727
default int compareTo(SortSupportEntity support) {
2828
if (support == null) return -1;

hsweb-commons/hsweb-commons-entity/src/main/java/org/hswebframework/web/commons/entity/TreeSupportEntity.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ public interface TreeSupportEntity<PK> extends GenericEntity<PK> {
4646

4747
void setParentId(PK parentId);
4848

49+
Integer getLevel();
50+
51+
void setLevel(Integer level);
52+
53+
default void setLevelFromTreeCode() {
54+
if (getTreeCode() != null)
55+
setLevel(getTreeCode().split("-").length);
56+
}
57+
4958
<T extends TreeSupportEntity<PK>> List<T> getChildren();
5059

5160
/**
@@ -74,6 +83,7 @@ static <T extends TreeSupportEntity<PK>, PK> void expandTree2List(TreeSupportEnt
7483
List<T> children = parent.getChildren();
7584
if (parent.getTreeCode() == null) {
7685
parent.setTreeCode(RandomUtil.randomChar(4));
86+
parent.setLevelFromTreeCode();
7787
}
7888
if (children != null) {
7989
PK pid = parent.getId();
@@ -88,6 +98,7 @@ static <T extends TreeSupportEntity<PK>, PK> void expandTree2List(TreeSupportEnt
8898
}
8999
child.setParentId(pid);
90100
child.setTreeCode(parent.getTreeCode() + "-" + RandomUtil.randomChar(4));
101+
child.setLevelFromTreeCode();
91102
target.add(child);
92103
expandTree2List(child, target, idGenerator);
93104
}

hsweb-commons/hsweb-commons-service/hsweb-commons-service-api/src/main/java/org/hswebframework/web/service/CrudService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
public interface CrudService<E, PK> extends
2828
QueryByEntityService<E>,
29-
UpdateService<E>,
29+
UpdateService<E,PK>,
3030
InsertService<E, PK>,
3131
DeleteService<PK>,
3232
CreateEntityService<E>,

0 commit comments

Comments
 (0)