|
|
@@ -27,47 +27,10 @@ public interface BaseSaveController<E,K extends Serializable> extends
|
|
|
BaseService<? extends Mapper<E>,E,K> getService();
|
|
|
|
|
|
|
|
|
-
|
|
|
- default E applyCreationEntity(E entity) {
|
|
|
- RecordCreationEntity creationEntity = ((RecordCreationEntity) entity);
|
|
|
- creationEntity.setCreateTimeNow();
|
|
|
- try {
|
|
|
- creationEntity.setCreateBy(StpUtil.getLoginIdAsString());
|
|
|
- }catch (Exception e){
|
|
|
- creationEntity.setCreateBy("-1");
|
|
|
- }
|
|
|
- return entity;
|
|
|
- }
|
|
|
-
|
|
|
- default E applyModifierEntity( E entity) {
|
|
|
- RecordModifierEntity modifierEntity = ((RecordModifierEntity) entity);
|
|
|
- modifierEntity.setModifyTimeNow();
|
|
|
- try {
|
|
|
- modifierEntity.setUpdateBy(StpUtil.getLoginIdAsString());
|
|
|
- }catch (Exception e){
|
|
|
- modifierEntity.setUpdateBy("-1");
|
|
|
- }
|
|
|
-
|
|
|
- return entity;
|
|
|
- }
|
|
|
-
|
|
|
- default E applyAuthentication(E entity) {
|
|
|
- if (entity instanceof RecordCreationEntity) {
|
|
|
- entity = applyCreationEntity(entity);
|
|
|
- }
|
|
|
- if (entity instanceof RecordModifierEntity) {
|
|
|
- entity = applyModifierEntity(entity);
|
|
|
- }
|
|
|
- return entity;
|
|
|
- }
|
|
|
-
|
|
|
@PostMapping("/_batch")
|
|
|
@Operation(summary = "批量新增数据")
|
|
|
default R add(@RequestBody List<E> payload) {
|
|
|
saveAuth();
|
|
|
- payload.forEach(s->{
|
|
|
- applyCreationEntity(s);
|
|
|
- });
|
|
|
return getService().saveBatch(payload)?R.success():R.fail("数据新增失败");
|
|
|
}
|
|
|
|
|
|
@@ -75,7 +38,6 @@ public interface BaseSaveController<E,K extends Serializable> extends
|
|
|
@Operation(summary = "新增单个数据,并返回新增后的数据.")
|
|
|
default R add(@RequestBody E payload) {
|
|
|
saveAuth();
|
|
|
- applyCreationEntity(payload);
|
|
|
return getService().save(payload)?R.success(payload):R.fail("数据新增失败");
|
|
|
}
|
|
|
|
|
|
@@ -84,7 +46,6 @@ public interface BaseSaveController<E,K extends Serializable> extends
|
|
|
@Operation(summary = "根据ID修改数据")
|
|
|
default R update(@RequestBody E payload) {
|
|
|
editAuth();
|
|
|
- applyModifierEntity(payload);
|
|
|
return getService().updateById(payload)?R.success():R.fail("更新失败");
|
|
|
}
|
|
|
}
|