package com.palmnest.webapp.controller.lingling;

import com.alibaba.fastjson.JSONObject;
import com.palmnest.application.core.util.LingLingUtil;
import com.palmnest.service.lingling.manager.LingLingManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author HXT
 * @Description 令令日志回调控制器
 * @Date 2018/12/13 10:10
 **/
@Slf4j
@RequestMapping(value = "/api/lingling")
@Controller
public class ApiLingLingLogController {


	@Autowired
	private LingLingManager lingLingManager;

	@RequestMapping(value = "/uploadLogMsg", method = {RequestMethod.GET, RequestMethod.POST}, produces = "application/json;charset=UTF-8")
	@ResponseBody
	public String uploadLogMsg(HttpServletRequest request) {

		JSONObject result     = new JSONObject();
		JSONObject jsonObject = LingLingUtil.handleParam(request);
		if (jsonObject == null) {
			result.put("statusCode", "0");
			result.put("responseResult", "参数异常");
			return result.toJSONString();
		}

		try {
			lingLingManager.uploadLogMsg(jsonObject);
			result.put("statusCode", "1");
			result.put("responseResult", "保存成功");
		} catch (Exception e) {
			log.info("ApiLingLingLogController uploadLogMsg 令令日志回调异常=======>" + e.getMessage());
			result.put("statusCode", "0");
			result.put("responseResult", "方法异常");
		}

		return result.toJSONString();
	}
}
