Commit 37fc7968 by chenzy

【修改】抽取数据过滤,分页处理

parent 9aef130e
...@@ -9,7 +9,6 @@ import com.keymobile.syncdata.util.SpringUtil; ...@@ -9,7 +9,6 @@ import com.keymobile.syncdata.util.SpringUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.bson.Document; import org.bson.Document;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import java.io.IOException; import java.io.IOException;
...@@ -39,7 +38,6 @@ public class DataSyncActor extends AbstractActor { ...@@ -39,7 +38,6 @@ public class DataSyncActor extends AbstractActor {
} }
public void syncData(SyncDataMessage syncDataMessage) { public void syncData(SyncDataMessage syncDataMessage) {
handleUserData(); handleUserData();
// 抽取所有数据 // 抽取所有数据
...@@ -112,20 +110,25 @@ public class DataSyncActor extends AbstractActor { ...@@ -112,20 +110,25 @@ public class DataSyncActor extends AbstractActor {
Map<String, Object> map = null; Map<String, Object> map = null;
try { try {
map = objectMapper.readValue(rows.toString(), Map.class); map = objectMapper.readValue(rows.toString(), Map.class);
String deptid = (String)map.get("DEPTID"); String hr_status = (String) map.getOrDefault("HR_STATUS", "I");
String username = (String)map.get("NAME"); String eff_status = (String) map.getOrDefault("EFF_STATUS", "I");
String userId = String.valueOf(map.get("USER_ID")); if ("A".equals(hr_status) || "A".equals(eff_status)) {
String deptName = orgMapIdAndName.get(deptid); String deptid = (String) map.get("DEPTID");
String oaAccount = (String) map.get("OA_ACCOUNT"); String username = (String) map.get("NAME");
map.put("DEPT_NAME", deptName); String userId = String.valueOf(map.get("USER_ID"));
map.put("search", oaAccount + ":" + userId + ":" + username + ":" + ":" + deptName + ":" + deptid); String deptName = orgMapIdAndName.get(deptid);
urlList.add(map); String oaAccount = (String) map.get("OA_ACCOUNT");
map.put("DEPT_NAME", deptName);
map.put("search", oaAccount + ":" + userId + ":" + username + ":" + ":" + deptName + ":" + deptid);
urlList.add(map);
}
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
}); });
} }
} }
// 处理用户数据,根据机构编号,查机构名称DEPT_NAME // 处理用户数据,根据机构编号,查机构名称DEPT_NAME
private void handleUserData() { private void handleUserData() {
Query query = new Query(); Query query = new Query();
...@@ -137,7 +140,7 @@ public class DataSyncActor extends AbstractActor { ...@@ -137,7 +140,7 @@ public class DataSyncActor extends AbstractActor {
log.info("机构数据未同步,为空"); log.info("机构数据未同步,为空");
return; return;
} }
orgMapIdAndName = documentList.stream().collect(Collectors.toMap(each->(String)each.get("DEPT_ID"), each->(String)each.get("DEPT_DESC"),(key1, key2)->key1)); orgMapIdAndName = documentList.stream().collect(Collectors.toMap(each -> (String) each.get("DEPT_ID"), each -> (String) each.get("DEPT_DESC"), (key1, key2) -> key1));
} }
} }
...@@ -75,8 +75,9 @@ public class SyncDataController { ...@@ -75,8 +75,9 @@ public class SyncDataController {
String deptId = (String) map.get("DEPT_ID"); String deptId = (String) map.get("DEPT_ID");
String partDeptId = (String) map.get("PART_DEPT_ID"); String partDeptId = (String) map.get("PART_DEPT_ID");
String deptDesc = (String) map.get("DEPT_DESC"); String deptDesc = (String) map.get("DEPT_DESC");
String order_num = String.valueOf(map.get("ORDER_NUM"));
TreeNode<String> longTreeNode = new TreeNode<>(deptId, partDeptId, deptDesc, 0); TreeNode<String> longTreeNode = new TreeNode<>(deptId, partDeptId, deptDesc, order_num);
HashMap<String, Object> hashMap = new HashMap<>(); HashMap<String, Object> hashMap = new HashMap<>();
longTreeNode.setExtra(hashMap); longTreeNode.setExtra(hashMap);
nodeList.add(longTreeNode); nodeList.add(longTreeNode);
...@@ -92,13 +93,16 @@ public class SyncDataController { ...@@ -92,13 +93,16 @@ public class SyncDataController {
tree.setId((String) treeNode.getId()); tree.setId((String) treeNode.getId());
tree.setParentId((String) treeNode.getParentId()); tree.setParentId((String) treeNode.getParentId());
tree.setName(treeNode.getName()); tree.setName(treeNode.getName());
Comparable weight = treeNode.getWeight();
tree.setWeight(weight);
tree.putAll(treeNode.getExtra()); tree.putAll(treeNode.getExtra());
}); });
return build; return build;
} }
@GetMapping("/getUserByOrgId") @GetMapping("/getUserByOrgId")
public Page<Document> getUserByOrgId(@RequestParam String orgId, @RequestParam(defaultValue = "0") Integer pageNumber, @RequestParam(defaultValue = "10") Integer pageSize) { public Page<Document> getUserByOrgId(@RequestParam String orgId, @RequestParam(defaultValue = "0") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) {
// 查询orgID及其子节点 // 查询orgID及其子节点
Queue<String> queue = new LinkedList<>(); Queue<String> queue = new LinkedList<>();
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
...@@ -114,7 +118,7 @@ public class SyncDataController { ...@@ -114,7 +118,7 @@ public class SyncDataController {
query.fields().exclude("_id"); query.fields().exclude("_id");
query.with(org.springframework.data.domain.Sort.by(org.springframework.data.domain.Sort.Direction.ASC, "DEPT_ID")); query.with(org.springframework.data.domain.Sort.by(org.springframework.data.domain.Sort.Direction.ASC, "DEPT_ID"));
Long total = mongoTemplate.count(query, Document.class, "sync_user_data"); Long total = mongoTemplate.count(query, Document.class, "sync_user_data");
Pageable pageable = PageRequest.of(pageNumber, pageSize); Pageable pageable = PageRequest.of(pageNum - 1, pageSize);
query.with(pageable); query.with(pageable);
List<Document> documents = mongoTemplate.find(query, Document.class, "sync_user_data"); List<Document> documents = mongoTemplate.find(query, Document.class, "sync_user_data");
...@@ -123,14 +127,14 @@ public class SyncDataController { ...@@ -123,14 +127,14 @@ public class SyncDataController {
} }
@GetMapping("/getAllSyncUser") @GetMapping("/getAllSyncUser")
public Page<Document> getAllSyncUser(@RequestParam(required = false) String search, @RequestParam(defaultValue = "0") Integer pageNumber, @RequestParam(defaultValue = "10") Integer pageSize) { public Page<Document> getAllSyncUser(@RequestParam(required = false) String search, @RequestParam(defaultValue = "0") Integer pageNumber, @RequestParam(defaultValue = "10") Integer pageSize) {
Query query = new Query(); Query query = new Query();
query.fields().exclude("_id"); query.fields().exclude("_id");
if (search != null && !search.isEmpty()) { if (search != null && !search.isEmpty()) {
query.addCriteria(Criteria.where("search").regex(search)); query.addCriteria(Criteria.where("search").regex(search));
} }
Long total = mongoTemplate.count(query, Document.class, "sync_user_data"); Long total = mongoTemplate.count(query, Document.class, "sync_user_data");
Pageable pageable = PageRequest.of(pageNumber, pageSize); Pageable pageable = PageRequest.of(pageNumber - 1, pageSize);
query.with(pageable); query.with(pageable);
List<Document> documents = mongoTemplate.find(query, Document.class, "sync_user_data"); List<Document> documents = mongoTemplate.find(query, Document.class, "sync_user_data");
return PageableExecutionUtils.getPage(documents, pageable, () -> total); return PageableExecutionUtils.getPage(documents, pageable, () -> total);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment