package com.yihu.wlyy.logs;

import com.yihu.wlyy.util.DateUtil;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 业务日志输出
 * <p>
 * Created by lyr-pc on 2017/1/19.
 */
public class BusinessLogs {

    // 日志输出
    private static Logger logger = LoggerFactory.getLogger(BusinessLogs.class);

    /**
     * 业务类型
     */
    public enum BusinessType {
        // 咨询
        consult
        // 指导
        , guidance
        // 健康教育
        , article
        // 随访
        , followup
        // 预约
        , appointment
        // 标签
        , label
        // 注册
        , register
        // 健康档案
        , archive
        // 签约
        , sign
        // 指标
        , index
    }

    /**
     * 业务日志输出
     *
     * @param type 业务类别
     * @param info 日志信息
     */
    public static void info(BusinessType type, String caller,String user, JSONObject info) {
        try {
            JSONObject log = new JSONObject();

            log.put("time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS").format(new Date()));
            log.put("logType", 2);
            log.put("caller", caller);

            JSONObject data = new JSONObject();

            data.put("businessType", type.ordinal());
            data.put("patient", user);
            data.put("data", info);

            log.put("data", data);

            logger.info(log.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 业务日志输出
     *
     * @param type 业务类别
     * @param info 日志信息
     */
    public static void info(BusinessType type,String caller, String user, JSONArray info) {
        try {
            JSONObject log = new JSONObject();

            log.put("time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS").format(new Date()));
            log.put("logType", 2);
            log.put("caller", caller);

            JSONObject data = new JSONObject();

            data.put("businessType", type.ordinal());
            data.put("patient", user);
            data.put("data", info);

            log.put("data", data);

            logger.info(log.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
