java two map left join

2020-12-24 21:27

阅读:448

标签:source   flat   oracle   jeecg   link   对象   esper   ons   dma   

java two map left join - 国际版 Bing
https://cn.bing.com/search?FORM=U227DF&PC=U227&q=java+two+map+left+join

两个不同的Java对象的“左连接”-代码日志
https://stackoverflow.com/questions/25593733/left-join-of-two-different-java-objects

10 ways to Join two Lists in Java - Techie Delight
https://www.techiedelight.com/join-two-lists-java/

Map-side Join Vs. Join | Edureka Blog
https://www.edureka.co/blog/map-side-join-vs-join/

Using JoinRowSet Objects (The Java? Tutorials > JDBC(TM) Database Access > JDBC Basics)
https://docs.oracle.com/javase/tutorial/jdbc/basics/joinrowset.html

JPA Join Types | Baeldung
https://www.baeldung.com/jpa-join-types

package org.jeecgframework.test.crm;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.jeecgframework.minidao.spring.map.MiniDaoLinkedMap;

public class Java8StreamTest {

private static String[] REPORT_SALES_WORKLOAD_KEYS = new String[] { "departname", "rolename", "realname",
		"resourcecount", "resourcecountinvalid", "resourcecountclosedeals", "mobilephone" };

private static String[] REPORT_SALES_PERFORMANCE_KEYS = new String[] { "username", "phone", "effective_case_number",
		"old_customer_performance", "new_customer_performance", "total_customer_performance" };

public String ObjectToString(Object obj) {
	String str = "";
	if (obj != null) {
		str = obj.toString();
	}
	return str;
}

public void test() {

// {departname=专部, rolename=总监, realname=张, mobilephone=10041268773, resourcecount=0, resourcecountinvalid=0, resourcecountclosedeals=0}
// {departname=专部, rolename=总监, realname=潘, mobilephone=10011806256, resourcecount=0, resourcecountinvalid=0, resourcecountclosedeals=0}
// {departname=专部, rolename=顾问, realname=专3, mobilephone=, resourcecount=0, resourcecountinvalid=0, resourcecountclosedeals=0}
// {departname=专部, rolename=顾问, realname=专4, mobilephone=, resourcecount=0, resourcecountinvalid=0, resourcecountclosedeals=0}
// {departname=专部, rolename=顾问, realname=张, mobilephone=, resourcecount=0, resourcecountinvalid=0, resourcecountclosedeals=0}
List salesWorkLoadList = new ArrayList();
MiniDaoLinkedMap miniDaoLinkedMap11 = new MiniDaoLinkedMap();
miniDaoLinkedMap11.put("departname", "专部");
miniDaoLinkedMap11.put("rolename", "总监");
miniDaoLinkedMap11.put("realname", "张");
miniDaoLinkedMap11.put("mobilephone", "10041268773");
miniDaoLinkedMap11.put("resourcecount", "0");
miniDaoLinkedMap11.put("resourcecountinvalid", "0");
miniDaoLinkedMap11.put("resourcecountclosedeals", "0");
MiniDaoLinkedMap miniDaoLinkedMap12 = new MiniDaoLinkedMap();
miniDaoLinkedMap12.put("departname", "专部");
miniDaoLinkedMap12.put("rolename", "总监");
miniDaoLinkedMap12.put("realname", "潘");
miniDaoLinkedMap12.put("mobilephone", "10011806256");
miniDaoLinkedMap12.put("resourcecount", "0");
miniDaoLinkedMap12.put("resourcecountinvalid", "0");
miniDaoLinkedMap12.put("resourcecountclosedeals", "0");
MiniDaoLinkedMap miniDaoLinkedMap13 = new MiniDaoLinkedMap();
miniDaoLinkedMap13.put("departname", "专部");
miniDaoLinkedMap13.put("rolename", "顾问");
miniDaoLinkedMap13.put("realname", "专3");
miniDaoLinkedMap13.put("mobilephone", null);
miniDaoLinkedMap13.put("resourcecount", "0");
miniDaoLinkedMap13.put("resourcecountinvalid", "0");
miniDaoLinkedMap13.put("resourcecountclosedeals", "0");
MiniDaoLinkedMap miniDaoLinkedMap14 = new MiniDaoLinkedMap();
miniDaoLinkedMap14.put("departname", "专部");
miniDaoLinkedMap14.put("rolename", "顾问");
miniDaoLinkedMap14.put("realname", "专4");
miniDaoLinkedMap14.put("mobilephone", "");
miniDaoLinkedMap14.put("resourcecount", "0");
miniDaoLinkedMap14.put("resourcecountinvalid", "0");
miniDaoLinkedMap14.put("resourcecountclosedeals", "0");
MiniDaoLinkedMap miniDaoLinkedMap15 = new MiniDaoLinkedMap();
miniDaoLinkedMap15.put("departname", "专部");
miniDaoLinkedMap15.put("rolename", "顾问");
miniDaoLinkedMap15.put("realname", "张");
miniDaoLinkedMap15.put("mobilephone", " ");
miniDaoLinkedMap15.put("resourcecount", "0");
miniDaoLinkedMap15.put("resourcecountinvalid", "0");
miniDaoLinkedMap15.put("resourcecountclosedeals", "0");
salesWorkLoadList.add(miniDaoLinkedMap11);
salesWorkLoadList.add(miniDaoLinkedMap12);
salesWorkLoadList.add(miniDaoLinkedMap13);
salesWorkLoadList.add(miniDaoLinkedMap14);
salesWorkLoadList.add(miniDaoLinkedMap15);

// {username=王, phone=10069715637, effective_case_number=0, old_customer_performance=0.0, new_customer_performance=0.0, total_customer_performance=0.0}
// {username=贾, phone=10001047098, effective_case_number=0, old_customer_performance=0.0, new_customer_performance=0.0, total_customer_performance=0.0}
// {username=张, phone=10041268773, effective_case_number=0, old_customer_performance=0.0, new_customer_performance=0.0, total_customer_performance=0.0}
// {username=田, phone=10022826166, effective_case_number=0, old_customer_performance=0.0, new_customer_performance=0.0, total_customer_performance=0.0}
// {username=蒙, phone=10010387081, effective_case_number=0, old_customer_performance=0.0, new_customer_performance=0.0, total_customer_performance=0.0}
List salesPerformanceList = new ArrayList();
MiniDaoLinkedMap miniDaoLinkedMap21 = new MiniDaoLinkedMap();
miniDaoLinkedMap21.put("username", "王");
miniDaoLinkedMap21.put("phone", "10069715637");
miniDaoLinkedMap21.put("effective_case_number", "0");
miniDaoLinkedMap21.put("old_customer_performance", "0.0");
miniDaoLinkedMap21.put("new_customer_performance", "0.0");
miniDaoLinkedMap21.put("total_customer_performance", "0.0");
MiniDaoLinkedMap miniDaoLinkedMap22 = new MiniDaoLinkedMap();
miniDaoLinkedMap22.put("username", "贾");
miniDaoLinkedMap22.put("phone", "10001047098");
miniDaoLinkedMap22.put("effective_case_number", "0");
miniDaoLinkedMap22.put("old_customer_performance", "0.0");
miniDaoLinkedMap22.put("new_customer_performance", "0.0");
miniDaoLinkedMap22.put("total_customer_performance", "0.0");
MiniDaoLinkedMap miniDaoLinkedMap23 = new MiniDaoLinkedMap();
miniDaoLinkedMap23.put("username", "张");
miniDaoLinkedMap23.put("phone", "10041268773");
miniDaoLinkedMap23.put("effective_case_number", "0");
miniDaoLinkedMap23.put("old_customer_performance", "0.0");
miniDaoLinkedMap23.put("new_customer_performance", "0.0");
miniDaoLinkedMap23.put("total_customer_performance", "0.0");
MiniDaoLinkedMap miniDaoLinkedMap24 = new MiniDaoLinkedMap();
miniDaoLinkedMap24.put("username", "田");
miniDaoLinkedMap24.put("phone", "10022826166");
miniDaoLinkedMap24.put("effective_case_number", "0");
miniDaoLinkedMap24.put("old_customer_performance", "0.0");
miniDaoLinkedMap24.put("new_customer_performance", "0.0");
miniDaoLinkedMap24.put("total_customer_performance", "0.0");
MiniDaoLinkedMap miniDaoLinkedMap25 = new MiniDaoLinkedMap();
miniDaoLinkedMap25.put("username", "蒙");
miniDaoLinkedMap25.put("phone", "10010387081");
miniDaoLinkedMap25.put("effective_case_number", "0");
miniDaoLinkedMap25.put("old_customer_performance", "0.0");
miniDaoLinkedMap25.put("new_customer_performance", "0.0");
miniDaoLinkedMap25.put("total_customer_performance", "0.0");
salesPerformanceList.add(miniDaoLinkedMap21);
salesPerformanceList.add(miniDaoLinkedMap22);
salesPerformanceList.add(miniDaoLinkedMap23);
salesPerformanceList.add(miniDaoLinkedMap24);
//salesPerformanceList.add(miniDaoLinkedMap25);

	List result = new ArrayList();
	for (MiniDaoLinkedMap salesWorkLoad : salesWorkLoadList) {
		OutputData data = null;

		for (MiniDaoLinkedMap salesPerformance : salesPerformanceList) {

			Object salesWorkLoadMobilePhone = salesWorkLoad.get(REPORT_SALES_WORKLOAD_KEYS[6]);
			Object salesPerformanceMobilePhone = salesPerformance.get(REPORT_SALES_PERFORMANCE_KEYS[1]);

			if (salesWorkLoadMobilePhone != null && salesPerformanceMobilePhone != null
					&& salesWorkLoadMobilePhone.equals(salesPerformanceMobilePhone)) {
				data = new OutputData(ObjectToString(salesWorkLoad.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[0], "")),
						ObjectToString(salesWorkLoad.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[1], "")),
						ObjectToString(salesWorkLoad.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[2], "")),
						ObjectToString(salesWorkLoad.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[3], "")),
						ObjectToString(salesWorkLoad.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[4], "")),
						ObjectToString(salesWorkLoad.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[5], "")),
						ObjectToString(salesWorkLoad.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[6], "")),
						ObjectToString(salesPerformance.getOrDefault(REPORT_SALES_PERFORMANCE_KEYS[2], "")),
						ObjectToString(salesPerformance.getOrDefault(REPORT_SALES_PERFORMANCE_KEYS[3], "")),
						ObjectToString(salesPerformance.getOrDefault(REPORT_SALES_PERFORMANCE_KEYS[4], "")),
						ObjectToString(salesPerformance.getOrDefault(REPORT_SALES_PERFORMANCE_KEYS[5], "")));
			} else {

			}
		}
		if (data == null) {
			data = new OutputData(ObjectToString(salesWorkLoad.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[0], "")),
					ObjectToString(salesWorkLoad.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[1], "")),
					ObjectToString(salesWorkLoad.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[2], "")),
					ObjectToString(salesWorkLoad.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[3], "")),
					ObjectToString(salesWorkLoad.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[4], "")),
					ObjectToString(salesWorkLoad.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[5], "")),
					ObjectToString(salesWorkLoad.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[6], "")), "", "", "", "");
		}

		result.add(data);
	}

// List result = salesPerformanceList.stream()
// .flatMap(x -> salesWorkLoadList.stream()
// .filter(y -> y.get(REPORT_SALES_PERFORMANCE_KEYS[1]).equals(x.get(REPORT_SALES_WORKLOAD_KEYS[6])))
// .map(y -> new OutputData(
// ObjectToString(x.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[0], "")),
// ObjectToString(x.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[1], "")),
// ObjectToString(x.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[2], "")),
// ObjectToString(x.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[3], "")),
// ObjectToString(x.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[4], "")),
// ObjectToString(x.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[5], "")),
// ObjectToString(x.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[6], "")),
// ObjectToString(y.getOrDefault(REPORT_SALES_PERFORMANCE_KEYS[2], "")),
// ObjectToString(y.getOrDefault(REPORT_SALES_PERFORMANCE_KEYS[3], "")),
// ObjectToString(y.getOrDefault(REPORT_SALES_PERFORMANCE_KEYS[4], "")),
// ObjectToString(y.getOrDefault(REPORT_SALES_PERFORMANCE_KEYS[5], "")))))
// .collect(Collectors.toList());

// List result = salesWorkLoadList.stream()
// .flatMap(x -> salesPerformanceList.stream()
// .filter(y -> x.get(REPORT_SALES_PERFORMANCE_KEYS[1]).equals(y.get(REPORT_SALES_WORKLOAD_KEYS[6])))
// .map(y -> new OutputData(
// ObjectToString(x.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[0], "")),
// ObjectToString(x.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[1], "")),
// ObjectToString(x.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[2], "")),
// ObjectToString(x.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[3], "")),
// ObjectToString(x.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[4], "")),
// ObjectToString(x.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[5], "")),
// ObjectToString(x.getOrDefault(REPORT_SALES_WORKLOAD_KEYS[6], "")),
// ObjectToString(y.getOrDefault(REPORT_SALES_PERFORMANCE_KEYS[2], "")),
// ObjectToString(y.getOrDefault(REPORT_SALES_PERFORMANCE_KEYS[3], "")),
// ObjectToString(y.getOrDefault(REPORT_SALES_PERFORMANCE_KEYS[4], "")),
// ObjectToString(y.getOrDefault(REPORT_SALES_PERFORMANCE_KEYS[5], "")))))
// .collect(Collectors.toList());
}

public static void main(String[] args) {
	Java8StreamTest java8StreamTest = new Java8StreamTest();

	java8StreamTest.test();
}

public class OutputData {
	private String departname;
	private String rolename;
	private String realname;
	private String resourcecount;
	private String resourcecountinvalid;
	private String resourcecountclosedeals;
	private String mobilephone;
	private String effective_case_number;
	private String old_customer_performance;
	private String new_customer_performance;
	private String total_customer_performance;
	
	public OutputData(){
	}

	public OutputData(String departname, String rolename, String realname, String resourcecount,
			String resourcecountinvalid, String resourcecountclosedeals, String mobilephone,
			String effective_case_number, String old_customer_performance, String new_customer_performance,
			String total_customer_performance) {
		this.departname = departname;
		this.rolename = rolename;
		this.realname = realname;
		this.resourcecount = resourcecount;
		this.resourcecountinvalid = resourcecountinvalid;
		this.resourcecountclosedeals = resourcecountclosedeals;
		this.mobilephone = mobilephone;
		this.effective_case_number = effective_case_number;
		this.old_customer_performance = old_customer_performance;
		this.new_customer_performance = new_customer_performance;
		this.total_customer_performance = total_customer_performance;
	}

	public String getDepartname() {
		return departname;
	}

	public void setDepartname(String departname) {
		this.departname = departname;
	}

	public String getRolename() {
		return rolename;
	}

	public void setRolename(String rolename) {
		this.rolename = rolename;
	}

	public String getRealname() {
		return realname;
	}

	public void setRealname(String realname) {
		this.realname = realname;
	}

	public String getResourcecount() {
		return resourcecount;
	}

	public void setResourcecount(String resourcecount) {
		this.resourcecount = resourcecount;
	}

	public String getResourcecountinvalid() {
		return resourcecountinvalid;
	}

	public void setResourcecountinvalid(String resourcecountinvalid) {
		this.resourcecountinvalid = resourcecountinvalid;
	}

	public String getResourcecountclosedeals() {
		return resourcecountclosedeals;
	}

	public void setResourcecountclosedeals(String resourcecountclosedeals) {
		this.resourcecountclosedeals = resourcecountclosedeals;
	}

	public String getMobilephone() {
		return mobilephone;
	}

	public void setMobilephone(String mobilephone) {
		this.mobilephone = mobilephone;
	}

	public String getEffective_case_number() {
		return effective_case_number;
	}

	public void setEffective_case_number(String effective_case_number) {
		this.effective_case_number = effective_case_number;
	}

	public String getOld_customer_performance() {
		return old_customer_performance;
	}

	public void setOld_customer_performance(String old_customer_performance) {
		this.old_customer_performance = old_customer_performance;
	}

	public String getNew_customer_performance() {
		return new_customer_performance;
	}

	public void setNew_customer_performance(String new_customer_performance) {
		this.new_customer_performance = new_customer_performance;
	}

	public String getTotal_customer_performance() {
		return total_customer_performance;
	}

	public void setTotal_customer_performance(String total_customer_performance) {
		this.total_customer_performance = total_customer_performance;
	}
}

}

java two map left join

标签:source   flat   oracle   jeecg   link   对象   esper   ons   dma   

原文地址:https://www.cnblogs.com/rgqancy/p/13209823.html


评论


亲,登录后才可以留言!