开缓存、增加异步请求

This commit is contained in:
wanggeng888 2021-05-23 21:11:44 +08:00
parent 0ea9db59bf
commit ceac706e09
3 changed files with 40 additions and 32 deletions

View File

@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
/**
* When you feel like quitting. Think about why you started
@ -44,10 +45,12 @@ public class DepartmentResourceController extends BaseController {
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PostMapping("listdepartments/{departmentParentId}")
public List<ZTreeDTO> listDepartments(@PathVariable("departmentParentId") String departmentParentId) throws SearchException {
public Callable<List<ZTreeDTO>> listDepartments(@PathVariable("departmentParentId") String departmentParentId) throws SearchException {
return () -> {
Map<String, Object> params = new HashMap<>(0);
params.put("departmentParentId", departmentParentId);
return departmentService.listZTreeDepartment(params);
};
}
@ApiOperation(value = "组织部门全部列表", notes = "组织部门全部列表接口")
@ -57,10 +60,12 @@ public class DepartmentResourceController extends BaseController {
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PostMapping("listalldepartments/{departmentParentId}")
public List<DepartmentDTO> listAllDepartments(@PathVariable("departmentParentId") String departmentParentId) throws SearchException {
public Callable<List<DepartmentDTO>> listAllDepartments(@PathVariable("departmentParentId") String departmentParentId) throws SearchException {
return () -> {
Map<String, Object> params = new HashMap<>(0);
params.put("departmentParentId", departmentParentId);
return departmentService.listDepartmentsAll(params);
};
}
@ApiOperation(value = "zTree列表包括人员", notes = "zTree列表包括人员接口")
@ -69,12 +74,14 @@ public class DepartmentResourceController extends BaseController {
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listztreedepartmentwithuser")
public List<ZTreeDTO> listZTreeDepartmentWithUser(@RequestParam(required = false) String id) throws SearchException {
public Callable<List<ZTreeDTO>> listZTreeDepartmentWithUser(@RequestParam(required = false) String id) throws SearchException {
return () -> {
String departmentParentId = "0";
if (!StringUtils.isBlank(id)) {
departmentParentId = id;
}
return departmentService.listZTreeDepartmentWithUser(departmentParentId);
};
}
@ApiOperation(value = "zTree列表", notes = "zTree列表接口")
@ -101,8 +108,8 @@ public class DepartmentResourceController extends BaseController {
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listdepartmentsimplebyparentid/{departmentParentId}")
public List<DepartmentSimpleDTO> listDepartmentSimpleByParentId(@PathVariable("departmentParentId") String departmentParentId) throws SearchException {
return departmentService.listDepartmentSimpleByParentId(departmentParentId);
public Callable<List<DepartmentSimpleDTO>> listDepartmentSimpleByParentId(@PathVariable("departmentParentId") String departmentParentId) throws SearchException {
return () -> departmentService.listDepartmentSimpleByParentId(departmentParentId);
}
@ApiOperation(value = "通过上级ID和添加获取组织部门全部增量列表简单格式", notes = "通过上级ID和添加获取组织部门全部增量列表简单格式接口")
@ -113,11 +120,11 @@ public class DepartmentResourceController extends BaseController {
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listdepartmentsimplebyparentidandadddate/{departmentParentId}/{addDate}")
public List<DepartmentSimpleDTO> listDepartmentSimpleByParentIdAndAddDate(@PathVariable("departmentParentId") String departmentParentId, @PathVariable("addDate") String addDate) throws SearchException {
public Callable<List<DepartmentSimpleDTO>> listDepartmentSimpleByParentIdAndAddDate(@PathVariable("departmentParentId") String departmentParentId, @PathVariable("addDate") String addDate) throws SearchException {
if (!RegexUtil.isDate(addDate)) {
throw new ParamsException("日期格式错误");
}
return departmentService.listDepartmentSimpleByParentIdAndAddDate(departmentParentId, addDate);
return () -> departmentService.listDepartmentSimpleByParentIdAndAddDate(departmentParentId, addDate);
}
@ApiOperation(value = "通过上级ID和更新获取组织部门全部新增和修改的列表简单格式", notes = "通过上级ID和更新获取组织部门全部新增和修改的列表简单格式接口")
@ -128,11 +135,11 @@ public class DepartmentResourceController extends BaseController {
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listdepartmentsimplebyparentidandupdatedate/{departmentParentId}/{updateDate}")
public List<DepartmentSimpleDTO> listDepartmentSimpleByParentIdAndUpdateDate(@PathVariable("departmentParentId") String departmentParentId, @PathVariable("updateDate") String updateDate) throws SearchException {
public Callable<List<DepartmentSimpleDTO>> listDepartmentSimpleByParentIdAndUpdateDate(@PathVariable("departmentParentId") String departmentParentId, @PathVariable("updateDate") String updateDate) throws SearchException {
if (!RegexUtil.isDate(updateDate)) {
throw new ParamsException("日期格式错误");
}
return departmentService.listDepartmentSimpleByParentIdAndUpdateDate(departmentParentId, updateDate);
return () -> departmentService.listDepartmentSimpleByParentIdAndUpdateDate(departmentParentId, updateDate);
}
@ApiOperation(value = "通过部门ID获取组织部门详情简单格式", notes = "通过部门ID获取组织部门详情简单格式接口")
@ -153,8 +160,8 @@ public class DepartmentResourceController extends BaseController {
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listdepartmentsimplebyparentid/{departmentParentIntId}")
public List<DepartmentSimpleDTO> listDepartmentSimpleByParentId(@PathVariable("departmentParentIntId") Long departmentParentIntId) throws SearchException {
return departmentService.listDepartmentSimpleByParentIntId(departmentParentIntId);
public Callable<List<DepartmentSimpleDTO>> listDepartmentSimpleByParentId(@PathVariable("departmentParentIntId") Long departmentParentIntId) throws SearchException {
return () -> departmentService.listDepartmentSimpleByParentIntId(departmentParentIntId);
}
@ApiOperation(value = "通过上级ID和添加获取组织部门全部增量列表简单格式", notes = "通过上级ID和添加获取组织部门全部增量列表简单格式接口")
@ -165,11 +172,11 @@ public class DepartmentResourceController extends BaseController {
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listdepartmentsimplebyparentidandadddate/{departmentParentIntId}/{addDate}")
public List<DepartmentSimpleDTO> listDepartmentSimpleByParentIdAndAddDate(@PathVariable("departmentParentIntId") Long departmentParentIntId, @PathVariable("addDate") String addDate) throws SearchException {
public Callable<List<DepartmentSimpleDTO>> listDepartmentSimpleByParentIdAndAddDate(@PathVariable("departmentParentIntId") Long departmentParentIntId, @PathVariable("addDate") String addDate) throws SearchException {
if (!RegexUtil.isDate(addDate)) {
throw new ParamsException("日期格式错误");
}
return departmentService.listDepartmentSimpleByParentIntIdAndAddDate(departmentParentIntId, addDate);
return () -> departmentService.listDepartmentSimpleByParentIntIdAndAddDate(departmentParentIntId, addDate);
}
@ApiOperation(value = "通过上级ID和更新获取组织部门全部新增和修改的列表简单格式", notes = "通过上级ID和更新获取组织部门全部新增和修改的列表简单格式接口")
@ -180,11 +187,11 @@ public class DepartmentResourceController extends BaseController {
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listdepartmentsimplebyparentidandupdatedate/{departmentParentIntId}/{updateDate}")
public List<DepartmentSimpleDTO> listDepartmentSimpleByParentIdAndUpdateDate(@PathVariable("departmentParentIntId") Long departmentParentIntId, @PathVariable("updateDate") String updateDate) throws SearchException {
public Callable<List<DepartmentSimpleDTO>> listDepartmentSimpleByParentIdAndUpdateDate(@PathVariable("departmentParentIntId") Long departmentParentIntId, @PathVariable("updateDate") String updateDate) throws SearchException {
if (!RegexUtil.isDate(updateDate)) {
throw new ParamsException("日期格式错误");
}
return departmentService.listDepartmentSimpleByParentIntIdAndUpdateDate(departmentParentIntId, updateDate);
return () -> departmentService.listDepartmentSimpleByParentIntIdAndUpdateDate(departmentParentIntId, updateDate);
}
@ApiOperation(value = "通过部门ID获取组织部门详情简单格式", notes = "通过部门ID获取组织部门详情简单格式接口")

View File

@ -228,7 +228,7 @@ public class DepartmentServiceImpl extends BaseService implements IDepartmentSer
@Override
public List<DepartmentDTO> listDepartmentsAll(Map<String, Object> params) throws SearchException {
List<DepartmentDTO> departmentDTOs = departmentDao.listDepartments(params);
List<DepartmentDTO> departmentDTOs = listDepartments(params);
listSubDepartments(departmentDTOs, params);
return departmentDTOs;
}
@ -267,7 +267,7 @@ public class DepartmentServiceImpl extends BaseService implements IDepartmentSer
@Override
public SuccessResultList<List<DepartmentDTO>> listPageDepartment(ListPage page) throws SearchException {
PageHelper.startPage(page.getPage(), page.getRows());
List<DepartmentDTO> departmentDTOs = departmentDao.listDepartments(page.getParams());
List<DepartmentDTO> departmentDTOs = listDepartments(page.getParams());
PageInfo<DepartmentDTO> pageInfo = new PageInfo<>(departmentDTOs);
return new SuccessResultList<>(departmentDTOs, pageInfo.getPageNum(), pageInfo.getTotal());
}
@ -294,7 +294,8 @@ public class DepartmentServiceImpl extends BaseService implements IDepartmentSer
@Override
public List<DepartmentDTO> listDepartments(Map<String, Object> params) throws SearchException {
return departmentDao.listDepartments(params);
List<DepartmentDTO> departmentDTOs = departmentDao.listDepartments(params);
return ArrayListUtil.deepClone(departmentDTOs, DepartmentDTO.class);
}
@Override
@ -338,7 +339,7 @@ public class DepartmentServiceImpl extends BaseService implements IDepartmentSer
@Override
public List<String> listDepartmentId(Map<String, Object> params) throws SearchException {
List<String> departmentIds = new ArrayList<>();
List<DepartmentDTO> departmentDTOs = departmentDao.listDepartments(params);
List<DepartmentDTO> departmentDTOs = listDepartments(params);
for (DepartmentDTO departmentDTO : departmentDTOs) {
departmentIds.add(departmentDTO.getDepartmentId());
}
@ -779,7 +780,7 @@ public class DepartmentServiceImpl extends BaseService implements IDepartmentSer
private void listSubDepartments(List<DepartmentDTO> departmentDTOs, Map<String, Object> params) throws SearchException {
for (DepartmentDTO departmentDTO : departmentDTOs) {
params.put("departmentParentId", departmentDTO.getDepartmentId());
List<DepartmentDTO> subDepartmentDTOs = departmentDao.listDepartments(params);
List<DepartmentDTO> subDepartmentDTOs = listDepartments(params);
departmentDTO.setSubDepartments(subDepartmentDTOs);
listSubDepartments(subDepartmentDTOs, params);
}

View File

@ -424,7 +424,7 @@
</select>
<!-- 组织部门列表 -->
<select id="listDepartments" parameterType="map" resultMap="departmentDTO" useCache="false">
<select id="listDepartments" parameterType="map" resultMap="departmentDTO" useCache="true">
SELECT
department_id,
department_parent_id,