⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 relationuuinfo.java

📁 java阿里巴巴代码
💻 JAVA
字号:
package com.saas.biz.relationUuMgr;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;


import com.saas.biz.commen.commMethodMgr;
import com.saas.biz.dao.relationuuDAO.RelationuuDAO;
import com.saas.biz.dao.relationuuDAO.RelationuuExt;
import com.saas.biz.dao.userDAO.UserExt;
import com.saas.sys.buffer.Buffers;
import com.saas.sys.dbm.Dbtable;
import com.saas.sys.exp.SaasApplicationException;
import com.saas.sys.log.Logger;

/**
 * @author liuy
 */
public class RelationUUInfo {
	
	
	Dbtable tradeQuery;
	
	
	commMethodMgr comm;
	
	
	Logger log;
	
	
	Buffers inBuffer;
	
	
	Buffers outBuffer;
	
	
	ArrayList queryResult = new ArrayList();
	
	
	
	public RelationUUInfo() {

		log = new Logger(this);
		tradeQuery = new Dbtable();
		comm = new commMethodMgr();
	}
	
	
	public void setTradeQuery(Dbtable tradeQuery) {

		this.tradeQuery = tradeQuery;
	}
	
	
	public Dbtable getTradeQuery() {

		return this.tradeQuery;
	}
	
	
	public void setOutBuffer(Buffers outBuffer) {

		this.outBuffer = outBuffer;
	}
	
	
	public Buffers getOutBuffer() {

		return this.outBuffer;
	}
	
	
	public ArrayList getQueryResult() {

		return this.queryResult;
	}
	
	
	public void setQueryResult(ArrayList queryResult) {

		this.queryResult = queryResult;
	}
	
	
	
	// 用户与用户之间的联系
	public void addRelationUU(Buffers inbuffer) {

		log.LOG_INFO("进入addRelationUU方法...");
		this.outBuffer = inbuffer;
		this.inBuffer = inbuffer;
		int iResult = -1;
		try {
			RelationuuDAO relation = new RelationuuDAO();
			String relation_type_code = inbuffer.getString("RELATION_UU_CODE");
			String user_id_a = inbuffer.getString("USER_ID");
			String user_id_b = inbuffer.getString("SESSION_USER_ID");
			String end_date = inbuffer.getString("END_DATE");
			relation.setEnd_date(end_date);
			relation.setRelation_type_code(relation_type_code);
			relation.setUser_id_a(user_id_a);
			relation.setUser_id_b(user_id_b);
			iResult = addRelationUU(relation);
		}
		catch (SaasApplicationException e) {
			log.LOG_INFO(e.getMessage());
		}
		if (iResult != 0) {
			this.outBuffer.setInt("RESULT_CODE", -1);
			this.outBuffer.setString("RESULT_INFO", "业务处理失败!");
		}
		else {
			this.outBuffer.setInt("RESULT_CODE", 0);
			this.outBuffer.setString("RESULT_INFO", "业务处理成功!");
		}
		log.LOG_INFO("退出addRelationUU方法...");
	}
	
	
	public int addRelationUU(RelationuuDAO relation) throws SaasApplicationException {

		String relation_code = relation.getRelation_type_code();
		String user_id = relation.getUser_id_b();
		String user_id_a = relation.getUser_id_a();
		String role_code = "0";
		boolean result = checkUserRelation(relation_code, user_id, role_code);
		if (result) {
			relation.setRole_code_b("1");
			saveRelationUU(relation);
		}
		else {
			relation.setRole_code_b("0");
			relation.setUser_id_a(comm.GenTradeId());
			saveRelationUU(relation);
			RelationuuDAO relations = new RelationuuDAO();
			relations.setRole_code_b("1");
			relations.setEnd_date(relation.getEnd_date());
			relations.setRelation_type_code(relation.getRelation_type_code());
			relations.setUser_id_a(user_id_a);
			relations.setUser_id_b(relation.getUser_id_b());
			saveRelationUU(relations);
		}
		return 0;
	}
	
	
	public int saveRelationUU(RelationuuDAO relation) throws SaasApplicationException {

		boolean isExe = checkExistRelation(relation.getRelation_type_code(), relation.getUser_id_a(), relation.getRole_code_b());
		if (isExe) {
			RelationuuExt relaExt = new RelationuuExt();
			relaExt.setParam(":VUSER_ID_A", relation.getUser_id_a());
			relaExt.setParam(":VUSER_ID_B", relation.getUser_id_b());
			relaExt.setParam(":VRELATION_TYPE_CODE", relation.getRelation_type_code());
			relaExt.setParam(":VROLE_CODE_B", relation.getRole_code_b());
			relaExt.setParam(":VEND_DATE", relation.getEnd_date());
			tradeQuery.executeBy(relaExt.insBy("UPDATE_BY_ALL"));
		}
		else {
			RelationuuExt relaExt = new RelationuuExt();
			relaExt.setParam(":VUSER_ID_A", relation.getUser_id_a());
			relaExt.setParam(":VUSER_ID_B", relation.getUser_id_b());
			relaExt.setParam(":VRELATION_TYPE_CODE", relation.getRelation_type_code());
			relaExt.setParam(":VROLE_CODE_B", relation.getRole_code_b());
			relaExt.setParam(":VEND_DATE", relation.getEnd_date());
			tradeQuery.executeBy(relaExt.insBy("INS_BY_ALL"));
		}
		return 0;
	}
	
	
	
	// 初次判断用户是否已建立关系
	public boolean checkUserRelation(String relation_code, String user_id, String role_code) throws SaasApplicationException {

		log.LOG_INFO("进入检测建立关系开始..." + relation_code + "|" + user_id + "|" + role_code);
		boolean result = false;
		RelationuuExt relaExt = new RelationuuExt();
		relaExt.setParam(":VUSER_ID_B", user_id);
		relaExt.setParam(":VRELATION_TYPE_CODE", relation_code);
		relaExt.setParam(":VROLE_CODE_B", role_code);
		ArrayList list = relaExt.selByList("SEL_BY_CHECK");
		if (list != null && list.size() > 0) {
			result = true;
		}
		log.LOG_INFO("退出检测建立关系开始..." + user_id + relation_code);
		return result;
	}
	
	
	
	// 初次判断联系人是否存在
	public boolean checkExistRelation(String relation_code, String user_id_a, String role_code) throws SaasApplicationException {

		log.LOG_INFO("进入checkExistRelation开始...");
		boolean result = false;
		RelationuuExt relaExt = new RelationuuExt();
		relaExt.setParam(":VUSER_ID_A", user_id_a);
		relaExt.setParam(":VRELATION_TYPE_CODE", relation_code);
		relaExt.setParam(":VROLE_CODE_B", role_code);
		ArrayList list = relaExt.selByList("SEL_BY_CHECK_CON");
		if (list != null && list.size() > 0) {
			result = true;
		}
		log.LOG_INFO("退出checkExistRelation...");
		return result;
	}
	
	
	
	// 取出联系人列表
	public ArrayList getContactList(int iStart, String user_id, String role_code) throws SaasApplicationException {

		ArrayList list = new ArrayList();
		if (iStart == 0) {
			iStart = 0;
		}
		else {
			iStart = (iStart - 1) * 20;
		}
		RelationuuExt relaExt = new RelationuuExt();
		relaExt.setParam(":VUSER_ID", user_id);
		relaExt.setParam(":VROLE_CODE_B", role_code);
		relaExt.setParam(":VRELATION_TYPE_CODE", "0");
		list = relaExt.selByList("SEL_BY_USER", iStart, 20);
		return list;
	}
	
	
	public int getContactSum(String user_id, String role_code) throws SaasApplicationException {

		int size = 0;
		ArrayList list = new ArrayList();
		RelationuuExt relaExt = new RelationuuExt();
		relaExt.setParam(":VUSER_ID", user_id);
		relaExt.setParam(":VROLE_CODE_B", role_code);
		list = relaExt.selByList("SEL_BY_USER_CT");
		if (list != null && list.size() > 0) {
			HashMap map = (HashMap) list.get(0);
			size = Integer.parseInt(map.get("ct").toString());
		}
		return size;
	}
	
	
	public String getJsonStore(String user_id, String role_code, int pageSize, int iStart) throws SaasApplicationException {

		String jsonData = "";
		ArrayList list = new ArrayList();
		RelationuuExt relaExt = new RelationuuExt();
		relaExt.setParam(":VUSER_ID", user_id);
		relaExt.setParam(":VROLE_CODE_B", role_code);
		relaExt.setParam(":VRELATION_TYPE_CODE", "0");
		list = relaExt.selByList("SEL_BY_USER", iStart, pageSize);
		JSONObject jsob = new JSONObject();
		JSONArray array = new JSONArray();
		int pageCount = getContactSum(user_id, role_code);
		jsob.put("totalCount", pageCount);
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				HashMap map = (HashMap) list.get(i);
				String id = map.get("cust_id").toString();
				String name = map.get("cust_name").toString();
				String phone = "";
				if (map.get("phone") != null) {
					phone = map.get("phone").toString();
				}
				String home_addr="";
				if(map.get("home_addr")!=null){
				  home_addr=map.get("home_addr").toString();
				}
				String email="";
				if(map.get("email")!=null){
					email=map.get("email").toString();
				}
				JSONObject obj = new JSONObject();
				obj.put("id", id);
				obj.put("name", name);
				obj.put("phone", phone);
				obj.put("addr", home_addr);
				obj.put("email", email);
				array.add(obj);
			}
		}
		jsob.put("root", array);
		jsonData = jsob.toString();
		return jsonData;
	}
	
	
	public Map getUserByCustId(String cust_id) throws SaasApplicationException {

		log.LOG_INFO("cust_id=====" + cust_id);
		HashMap map = new HashMap();
		UserExt userExt = new UserExt();
		userExt.setParam(":VCUST_ID", cust_id);
		userExt.setParam(":VUSER_STATE", "0");
		ArrayList list = userExt.selByList("SEL_CUST_BY_IDX");
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				HashMap maps = (HashMap) list.get(i);
				String user_id = maps.get("user_id").toString();
				String user_name = maps.get("user_name").toString();
				map.put(user_id, user_name);
			}
		}
		log.LOG_INFO("======" + map);
		return map;
	}
	
	
	public Map getContactUserByCustId(String cust_id, String user_idx) throws SaasApplicationException {

		log.LOG_INFO("cust_id=====" + cust_id + "user_id==" + user_idx);
		HashMap<String, String> map = new HashMap<String, String>();
		UserExt userExt = new UserExt();
		userExt.setParam(":VCUST_ID", cust_id);
		userExt.setParam(":VUSER_STATE", "0");
		ArrayList list = userExt.selByList("SEL_CUST_BY_IDX");
		List conList = getContactByList(user_idx, "1");
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				HashMap maps = (HashMap) list.get(i);
				String user_id = maps.get("user_id").toString();
				String user_name = maps.get("user_name").toString();
				if (!conList.contains(user_id)) {
					map.put(user_id, user_name);
				}
			}
		}
		log.LOG_INFO("======" + map);
		return map;
	}
	
	
	
	// 取出联系人ID
	public List<String> getContactByList(String user_id, String role_code) throws SaasApplicationException {

		List<String> list = new ArrayList<String>();
		ArrayList conList = getContactList(user_id, role_code);
		if (conList != null && conList.size() > 0) {
			for (int i = 0; i < conList.size(); i++) {
				HashMap map = (HashMap) conList.get(i);
				String u_user_id = map.get("user_id").toString();
				list.add(u_user_id);
			}
		}
		return list;
	}
	
	
	
	// 取出联系人列表[RELATION_TYPE_CODE:0 联系人 1 合作伙伴 2 竞争对手]
	public ArrayList getContactList(String user_id, String role_code) throws SaasApplicationException {

		ArrayList list = new ArrayList();
		RelationuuExt relaExt = new RelationuuExt();
		relaExt.setParam(":VUSER_ID", user_id);
		relaExt.setParam(":VROLE_CODE_B", role_code);
		relaExt.setParam(":VRELATION_TYPE_CODE", "0");
		list = relaExt.selByList("SEL_BY_USER");
		return list;
	}
	
	/*
	 * 08-7-14:10:08
	 * lill2
	 * 取出最近新增的五条联系人记录 
	 */
	public ArrayList getNewContactList(String user_id, String role_code) throws SaasApplicationException {
		ArrayList list = new ArrayList();
		RelationuuExt relaExt = new RelationuuExt();
		relaExt.setParam(":VUSER_ID", user_id);
		relaExt.setParam(":VROLE_CODE_B", role_code);
		relaExt.setParam(":VRELATION_TYPE_CODE", "0");
		list = relaExt.selByList("SEL_NEW_CONTACT_BY_FIVE");
		return list;
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -