package com.zcloud.util;

import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

@Component
public class ResultCodeConstant {
	/**
	 * code规则
	 * 1.数字
	 * 2.每两位代表不同的意义， 使用后 写入文档
	 * 		10**** 代表自己问题，如两个接口调用出现的问题，就是公司内部问题
	 * 	    90**** 系统问题，如空指针，越界等
	 * 		80**** 对接问题，
	 *
	 *      00**** 用户问题，如没有填入必填项，
	 *      0002** 隐患相关信息
	 */
	public static Map<Integer, String> rescodemap = new LinkedHashMap<Integer, String>();
	static {
		rescodemap.put(-1, "系统繁忙，此时请开发者稍候再试");
		rescodemap.put(0, "请求成功");
		rescodemap.put(000000, "请求成功");
		rescodemap.put(100001, "缺少必填参数");
		rescodemap.put(000201, "所在部门未维护部门负责人"); //隐患
		rescodemap.put(000202, "安全环保检查暂时不允许删除"); //隐患
		rescodemap.put(000204, "隐患已经进入下一个阶段!请刷新后查看"); //隐患 隐患状态和要修改的状态不一致

		rescodemap.put(000210, "未找到隐患确认人"); //隐患
		rescodemap.put(000211, "隐患确认人部门没有维护对接编码"); //隐患
		rescodemap.put(000212, "隐患确认人没有维护对接编码"); //隐患
		rescodemap.put(000213, "隐患区域等级维护错误"); //隐患
		rescodemap.put(000214, "隐患区域等级维护错误"); //隐患
		rescodemap.put(000215, "emis对接错误!请联系管理员"); //隐患
		rescodemap.put(000216, "特殊处置审核申请错误!请联系管理员"); //隐患


		rescodemap.put(000220, "未找到隐患验收人"); //隐患

		rescodemap.put(000301, "没有维护公告模板"); //通知公告
		rescodemap.put(000302, "使用公告模板错误");//通知公告

	}
	public static Map<Integer, String> resWarningcodemap = new LinkedHashMap<Integer, String>();
	static {
		rescodemap.put(000203, "此次检查还有未合格项，不能验收"); // 隐患 还有没有验收的人员

	}
	/**
	 * warning 警告
	 * fail 失败
	 * 错误返回
	 * @param resCode
	 * @return
	 */
	public static Map<String,Object> resMap (int resCode){
		Map<String,Object> map = new HashMap<>();

		if(resCode == 000000){
			map.put("result", "success");
			map.put("code", resCode);
			map.put("codeMsg", ResultCodeConstant.rescodemap.get(resCode));
		}else {
			if (rescodemap.containsKey(resCode)) {
				System.out.println("系统错误，错误代码:" + resCode + ",错误信息:" + ResultCodeConstant.rescodemap.get(resCode));
				map.put("result", "fail");
				map.put("code", resCode);
				map.put("codeMsg", ResultCodeConstant.rescodemap.get(resCode));
			} else if (resWarningcodemap.containsKey(resCode)) {
				System.out.println("业务警告，警告代码:" + resCode + ",警告信息:" + ResultCodeConstant.rescodemap.get(resCode));
				map.put("result", "warning");
				map.put("code", resCode);
				map.put("codeMsg", ResultCodeConstant.resWarningcodemap.get(resCode));
			} else {
				System.out.println("未知警告代码:" + resCode + ",未知警告代码:" + ResultCodeConstant.rescodemap.get(resCode));
				map.put("result", "fail");
				map.put("code", -1);
				map.put("codeMsg", ResultCodeConstant.rescodemap.get(-2));
			}
		}
		return map;
	}

	/**
	 * 可以携带其他参数
	 * @param resCode
	 * @param map
	 * @return
	 */
	public static Map<String,Object> resMap (int resCode,Map<String,Object> map){
		if(resCode == 000000){
			map.put("result", "success");
			map.put("code", resCode);
			map.put("codeMsg", ResultCodeConstant.rescodemap.get(resCode));
		}else {
			if (rescodemap.containsKey(resCode)) {
				System.out.println("系统错误，错误代码:" + resCode + ",错误信息:" + ResultCodeConstant.rescodemap.get(resCode));
				map.put("result", "fail");
				map.put("code", resCode);
				map.put("codeMsg", ResultCodeConstant.rescodemap.get(resCode));
			} else if (resWarningcodemap.containsKey(resCode)) {
				System.out.println("业务警告，警告代码:" + resCode + ",警告信息:" + ResultCodeConstant.rescodemap.get(resCode));
				map.put("result", "warning");
				map.put("code", resCode);
				map.put("codeMsg", ResultCodeConstant.resWarningcodemap.get(resCode));
			} else {
				System.out.println("未知警告代码:" + resCode + ",未知警告代码:" + ResultCodeConstant.rescodemap.get(resCode));
				map.put("result", "fail");
				map.put("code", -1);
				map.put("codeMsg", ResultCodeConstant.rescodemap.get(-2));
			}
		}
		return map;
	}
	public static void main(String[] args) {
		System.out.println();
		String a = ResultCodeConstant.rescodemap.get(0);
		System.out.println(a);
	}

}
