package com.engine.organization.transmethod;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.engine.organization.enums.OperateTypeEnum;
import org.apache.commons.lang.StringUtils;

/**
 * @author:dxfeng
 * @createTime: 2022/07/05
 * @version: 1.0
 */
public class LogViewTransMethod {

    public String getOperateType(String operateType) {
        if (StringUtils.isNotBlank(operateType)) {
            switch (operateType) {
                case "1":
                    operateType = OperateTypeEnum.ADD.getLabel();
                    break;
                case "2":
                    operateType = OperateTypeEnum.UPDATE.getLabel();
                    break;
                case "4":
                    operateType = OperateTypeEnum.DELETE.getLabel();
                    break;
                case "5":
                    operateType = OperateTypeEnum.MOVE.getLabel();
                    break;
                case "6":
                    operateType = OperateTypeEnum.MERGE.getLabel();
                    break;
                case "7":
                    operateType = OperateTypeEnum.COPY.getLabel();
                    break;
                default:
                    break;
            }
            return operateType;
        }
        return "";
    }

    public String getDateTimeFormat(String dateTime) {
        if (StringUtils.isNotBlank(dateTime)) {
            dateTime = dateTime.substring(0,19);
        }
        return dateTime;
    }

    public static String getFormatJson(String jsonStr) {
        if (StringUtils.isNotBlank(jsonStr)) {
            try {
                JSONObject object = JSONObject.parseObject(jsonStr);
                jsonStr = JSON.toJSONString(object, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue,
                        SerializerFeature.WriteDateUseDateFormat);
                jsonStr= jsonStr.replace("\n","<br/>").replace("\t","&nbsp&nbsp&nbsp&nbsp");
            } catch (Exception e) {
                return jsonStr;
            }
        }
        return jsonStr;
    }
}
