182d317424bd72a4b3540118e02d63b59e621b72.svn-base 5.44 KB
package com.thinkgem.jeesite.modules.reg.web.httprest.utils;

import java.io.InputStreamReader;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

import org.json.JSONObject;
import org.json.XML;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.Lists;
import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.utils.DateUtils;
import com.thinkgem.jeesite.common.utils.JsonUtil;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.restQydm.restQydmInterfaceService;
import com.thinkgem.jeesite.modules.sys.utils.DictUtils;

public class DatatypeUtil {
	private static Logger logger = LoggerFactory.getLogger(DatatypeUtil.class);
	public static Boolean isInteger(String str) {
		Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
		return pattern.matcher(str).matches();
	}

	/**
	 * 请求接受 2018-11-11
	 */
	public static String reqReceive(HttpServletRequest request) {
		// 接收请求
		String reqjson = "";
		try {
			InputStreamReader reader = new InputStreamReader(request.getInputStream(), "utf-8");
			char[] buff = new char[20480];
			int length = 0;
			while ((length = reader.read(buff)) != -1) {
				String str =  new String(buff, 0, length);
				logger.info("接收到{}的字符串信息:{}",length,str);
				reqjson += str;
				
			}
			
			// base64 解码
			// reqjson = Base64.decodeStr(reqjson,"utf-8");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return reqjson;
	}

	public static Map readXml(String xml_str) {
		List<Map> rows = Lists.newArrayList();
		JSONObject xml = XML.toJSONObject(xml_str);
		Map xml_map = JsonUtil.jsonToMap(xml.toString());
		Map root = xml_map.get("Root") == null ? null : (Map) xml_map.get("Root");
		return root;
	}

	public static List<Map> getRows(Map root) {
		List<Map> rows = Lists.newArrayList();
		Map recordSet = root.get("RecordSet") == null ? null : (Map) root.get("RecordSet");
		Object row_obj = recordSet.get("Row");

		if (row_obj instanceof Map) {
			Map row = (Map) row_obj;
			rows.add(row);
		} else if (row_obj instanceof List) {
			rows = (List) row_obj;
		}
		return rows;
	}

	public static Map getHead(Map root) {
		return root.get("Head") == null ? null : (Map) root.get("Head");
	}

	public static Boolean validateSxh(List<Integer> lst) {
		Collections.sort(lst);
		Integer i = 1;
		for (Integer sxh : lst) {
			if (!i.equals(sxh)) {
				return false;
			}
			i++;
		}
		return true;
	}

	public static Boolean validateGyqk(String gyfs, String gyqk) {
		String c_gyqk = DictUtils.getDictLabel(gyfs, "reg_bus_gyfs", "");

		System.out.println(c_gyqk + " ***  " + gyqk);

		return c_gyqk.equals(gyqk);
	}

	public static Boolean isDate(String str) {

		try {
			DateUtils.parseDate(str);
		} catch (Exception e) {
			return false;
		}
		return true;
	}

	public static String getYwztMc(String taskey) {
		String areaCode = Global.getAreaCode();
		String audit = "";
		switch (taskey) { 
		case "reg_start":
			audit = "受理";
			break;
		case "reg_audit":
			if ("610702".equals(areaCode) || "610725".equals(areaCode) || "610721".equals(areaCode)
					|| "610727".equals(areaCode) || "610728".equals(areaCode)) {
				audit = "审核";
			} else {
				audit = "初审";
			}
			break;
		case "reg_audit2":
			if (!"610702".equals(areaCode) && !"610725".equals(areaCode) && !"610721".equals(areaCode)
					&& !"610727".equals(areaCode) || "610728".equals(areaCode)) {
				audit = "复审";
			}
			break;
		case "reg_audit3":
			audit = "核定";
			break;
		case "reg_audit4":
			audit = "登簿";
			break;
		case "reg_audit5":
			audit = "缮证";
			break;
		case "reg_audit56":
			audit = "收费";
			break;
		case "reg_audit6":
			audit = "发证";
			break;
		case "reg_end":
			audit = "归档";
			break;
		default:
			break;
		}
		return audit;
	}

	public static String getValueByMap(Map map, String key, String value) {
		return map.get(key) == null ? value : map.get(key).toString();
	}

	public static Boolean isYcslBuss(String djlx) {
		switch (djlx) {
		case "207":
		case "302":
		case "402":
		case "403":
		case "404":
		case "416":
		case "428":
		case "431":
		case "213":
		case "214":
		case "215":
		case "316":
		case "317":
		case "318":
		case "433":
		case "509":
		case "515":
		case "606":
		case "608":
		case "818":
		case "505":
		case "506":
		case "510":
		case "511":
		case "512":
		case "513":
		case "607":
		case "609":
		case "803":
		case "804":
		case "806":
		case "807":
		case "809":
		case "810":
		case "811":
		case "812":
		case "819":
		case "604":
		case "1003":
		case "1004":
		case "703":
		case "704":
		case "902":
		case "903":
		case "905":
		case "906":
		case "907":
		case "908":
		case "910":
		case "912":
		case "427":
		case "422":
		case "432":
			return true;
		default:
			return false;
		}

	}

	public static String randomName(String hz) {
		Random r = new Random(99);
		String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
		int ran1 = r.nextInt(10000);
	    return uuid+ran1+"."+hz;
	}
	/**
	 * 输出异常信息
	 * 
	 * @param e
	 * @return
	 */
	public static String errorTrackSpace(Exception e) {
		StringBuffer sb = new StringBuffer();
		if (e != null) {
			for (StackTraceElement element : e.getStackTrace()) {
				sb.append("\r\n\t").append(element);
			}
		}
		return sb.length() == 0 ? null : sb.toString();
	}
}