Commit 37fc7968 by chenzy

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

parent 9aef130e
......@@ -9,7 +9,6 @@ import com.keymobile.syncdata.util.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.bson.Document;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import java.io.IOException;
......@@ -39,7 +38,6 @@ public class DataSyncActor extends AbstractActor {
}
public void syncData(SyncDataMessage syncDataMessage) {
handleUserData();
// 抽取所有数据
......@@ -112,20 +110,25 @@ public class DataSyncActor extends AbstractActor {
Map<String, Object> map = null;
try {
map = objectMapper.readValue(rows.toString(), Map.class);
String deptid = (String)map.get("DEPTID");
String username = (String)map.get("NAME");
String hr_status = (String) map.getOrDefault("HR_STATUS", "I");
String eff_status = (String) map.getOrDefault("EFF_STATUS", "I");
if ("A".equals(hr_status) || "A".equals(eff_status)) {
String deptid = (String) map.get("DEPTID");
String username = (String) map.get("NAME");
String userId = String.valueOf(map.get("USER_ID"));
String deptName = orgMapIdAndName.get(deptid);
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) {
throw new RuntimeException(e);
}
});
}
}
// 处理用户数据,根据机构编号,查机构名称DEPT_NAME
private void handleUserData() {
Query query = new Query();
......@@ -137,7 +140,7 @@ public class DataSyncActor extends AbstractActor {
log.info("机构数据未同步,为空");
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 {
String deptId = (String) map.get("DEPT_ID");
String partDeptId = (String) map.get("PART_DEPT_ID");
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<>();
longTreeNode.setExtra(hashMap);
nodeList.add(longTreeNode);
......@@ -92,13 +93,16 @@ public class SyncDataController {
tree.setId((String) treeNode.getId());
tree.setParentId((String) treeNode.getParentId());
tree.setName(treeNode.getName());
Comparable weight = treeNode.getWeight();
tree.setWeight(weight);
tree.putAll(treeNode.getExtra());
});
return build;
}
@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及其子节点
Queue<String> queue = new LinkedList<>();
List<String> list = new ArrayList<>();
......@@ -114,7 +118,7 @@ public class SyncDataController {
query.fields().exclude("_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");
Pageable pageable = PageRequest.of(pageNumber, pageSize);
Pageable pageable = PageRequest.of(pageNum - 1, pageSize);
query.with(pageable);
List<Document> documents = mongoTemplate.find(query, Document.class, "sync_user_data");
......@@ -130,7 +134,7 @@ public class SyncDataController {
query.addCriteria(Criteria.where("search").regex(search));
}
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);
List<Document> documents = mongoTemplate.find(query, Document.class, "sync_user_data");
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