企微前后台联调。
This commit is contained in:
@@ -73,8 +73,9 @@ public class QweiDepartmentController {
|
|||||||
|
|
||||||
@PostMapping("/sync")
|
@PostMapping("/sync")
|
||||||
@Operation(summary = "同步企微部门并入库")
|
@Operation(summary = "同步企微部门并入库")
|
||||||
public ResponseEntity<Map<String, Object>> sync() {
|
public ResponseEntity<Map<String, Object>> sync(
|
||||||
Map<String, Object> result = qweiDepartmentService.syncFromQiWei();
|
@RequestParam(required = false) String tenantId) {
|
||||||
|
Map<String, Object> result = qweiDepartmentService.syncFromQiWei(tenantId);
|
||||||
Boolean success = (Boolean) result.get("success");
|
Boolean success = (Boolean) result.get("success");
|
||||||
if (success != null && success) {
|
if (success != null && success) {
|
||||||
return ResponseEntity.ok(result);
|
return ResponseEntity.ok(result);
|
||||||
|
|||||||
@@ -74,8 +74,9 @@ public class QweiUserController {
|
|||||||
|
|
||||||
@PostMapping("/sync")
|
@PostMapping("/sync")
|
||||||
@Operation(summary = "同步企微用户并入库")
|
@Operation(summary = "同步企微用户并入库")
|
||||||
public ResponseEntity<Map<String, Object>> sync() {
|
public ResponseEntity<Map<String, Object>> sync(
|
||||||
Map<String, Object> result = qweiUserService.syncFromQiWei();
|
@RequestParam(required = false) String tenantId) {
|
||||||
|
Map<String, Object> result = qweiUserService.syncFromQiWei(tenantId);
|
||||||
Boolean success = (Boolean) result.get("success");
|
Boolean success = (Boolean) result.get("success");
|
||||||
if (success != null && success) {
|
if (success != null && success) {
|
||||||
return ResponseEntity.ok(result);
|
return ResponseEntity.ok(result);
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ public interface IQweiDepartmentService extends IService<QweiDepartment> {
|
|||||||
String deptName,
|
String deptName,
|
||||||
Long parentDeptId);
|
Long parentDeptId);
|
||||||
|
|
||||||
Map<String, Object> syncFromQiWei();
|
default Map<String, Object> syncFromQiWei() {
|
||||||
|
return syncFromQiWei(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Object> syncFromQiWei(String tenantId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ public interface IQweiUserService extends IService<QweiUser> {
|
|||||||
Long mainDepartmentId,
|
Long mainDepartmentId,
|
||||||
Integer status);
|
Integer status);
|
||||||
|
|
||||||
Map<String, Object> syncFromQiWei();
|
default Map<String, Object> syncFromQiWei() {
|
||||||
|
return syncFromQiWei(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Object> syncFromQiWei(String tenantId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -167,11 +167,11 @@ public class QweiDepartmentServiceImpl extends ServiceImpl<QweiDepartmentMapper,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Map<String, Object> syncFromQiWei() {
|
public Map<String, Object> syncFromQiWei(String tenantIdParam) {
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
QiWeiConfig cfg = loadQiWeiConfig();
|
QiWeiConfig cfg = loadQiWeiConfig();
|
||||||
String tenantId = resolveTenantId(null);
|
String tenantId = resolveTenantId(tenantIdParam);
|
||||||
// 确保后续对 qwei_department 的查询/写入都带 tenant_id 条件
|
// 确保后续对 qwei_department 的查询/写入都带 tenant_id 条件
|
||||||
TenantContextHolder.setTenantId(tenantId);
|
TenantContextHolder.setTenantId(tenantId);
|
||||||
String corpId = requireNonBlank(cfg.getCorpid(), "qiwei_config.corpid不能为空");
|
String corpId = requireNonBlank(cfg.getCorpid(), "qiwei_config.corpid不能为空");
|
||||||
|
|||||||
@@ -173,11 +173,11 @@ public class QweiUserServiceImpl extends ServiceImpl<QweiUserMapper, QweiUser> i
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Map<String, Object> syncFromQiWei() {
|
public Map<String, Object> syncFromQiWei(String tenantIdParam) {
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
String tenantId = null;
|
String tenantId = null;
|
||||||
try {
|
try {
|
||||||
tenantId = resolveTenantId(null);
|
tenantId = resolveTenantId(tenantIdParam);
|
||||||
TenantContextHolder.setTenantId(tenantId);
|
TenantContextHolder.setTenantId(tenantId);
|
||||||
|
|
||||||
QiWeiConfig cfg = loadQiWeiConfig();
|
QiWeiConfig cfg = loadQiWeiConfig();
|
||||||
|
|||||||
@@ -49,9 +49,10 @@ public class QweiDepartmentControllerTest {
|
|||||||
serviceResult.put("inserted", 3);
|
serviceResult.put("inserted", 3);
|
||||||
serviceResult.put("updated", 5);
|
serviceResult.put("updated", 5);
|
||||||
serviceResult.put("total", 8);
|
serviceResult.put("total", 8);
|
||||||
when(qweiDepartmentService.syncFromQiWei()).thenReturn(serviceResult);
|
when(qweiDepartmentService.syncFromQiWei("TENANT_TEST")).thenReturn(serviceResult);
|
||||||
|
|
||||||
mockMvc.perform(post("/api/qweiDepartment/sync")
|
mockMvc.perform(post("/api/qweiDepartment/sync")
|
||||||
|
.param("tenantId", "TENANT_TEST")
|
||||||
.contentType(MediaType.APPLICATION_JSON))
|
.contentType(MediaType.APPLICATION_JSON))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(jsonPath("$.success").value(true))
|
.andExpect(jsonPath("$.success").value(true))
|
||||||
@@ -59,7 +60,7 @@ public class QweiDepartmentControllerTest {
|
|||||||
.andExpect(jsonPath("$.updated").value(5))
|
.andExpect(jsonPath("$.updated").value(5))
|
||||||
.andExpect(jsonPath("$.total").value(8));
|
.andExpect(jsonPath("$.total").value(8));
|
||||||
|
|
||||||
verify(qweiDepartmentService, times(1)).syncFromQiWei();
|
verify(qweiDepartmentService, times(1)).syncFromQiWei("TENANT_TEST");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -67,14 +68,15 @@ public class QweiDepartmentControllerTest {
|
|||||||
Map<String, Object> serviceResult = new HashMap<>();
|
Map<String, Object> serviceResult = new HashMap<>();
|
||||||
serviceResult.put("success", false);
|
serviceResult.put("success", false);
|
||||||
serviceResult.put("message", "同步异常:测试错误");
|
serviceResult.put("message", "同步异常:测试错误");
|
||||||
when(qweiDepartmentService.syncFromQiWei()).thenReturn(serviceResult);
|
when(qweiDepartmentService.syncFromQiWei("TENANT_TEST")).thenReturn(serviceResult);
|
||||||
|
|
||||||
mockMvc.perform(post("/api/qweiDepartment/sync")
|
mockMvc.perform(post("/api/qweiDepartment/sync")
|
||||||
|
.param("tenantId", "TENANT_TEST")
|
||||||
.contentType(MediaType.APPLICATION_JSON))
|
.contentType(MediaType.APPLICATION_JSON))
|
||||||
.andExpect(status().isBadRequest())
|
.andExpect(status().isBadRequest())
|
||||||
.andExpect(jsonPath("$.success").value(false));
|
.andExpect(jsonPath("$.success").value(false));
|
||||||
|
|
||||||
verify(qweiDepartmentService, times(1)).syncFromQiWei();
|
verify(qweiDepartmentService, times(1)).syncFromQiWei("TENANT_TEST");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user