package com.engine.kq.web;

import com.alibaba.fastjson.JSONObject;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.kq.service.ImportLogService;
import com.engine.kq.service.impl.ImportLogServiceImpl;
import weaver.general.BaseBean;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;

/**
 * Excel导入记录
 *
 */
public class ImportLogAction extends BaseBean {

	private ImportLogService getService(User user) {
		return (ImportLogServiceImpl) ServiceUtil.getService(ImportLogServiceImpl.class, user);
	}

	/**
	 * 获取导入进行明细
	 */
	@GET
	@Path("/getImportProcessLog")
	@Produces(MediaType.TEXT_PLAIN)
	public String getImportProcessLog(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).getImportProcessLog(ParamUtil.request2Map(request), request, user);
		} catch (Exception e) {
			apidatas.put("status", "-1");
			writeLog(e);
		}
		return JSONObject.toJSONString(apidatas);
	}

	/**
	 * 获取历史导入记录
	 */
	@GET
	@Path("/getImportHistory")
	@Produces(MediaType.TEXT_PLAIN)
	public String getImportHistory(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).getImportHistory(ParamUtil.request2Map(request), user);
		} catch (Exception e) {
			apidatas.put("status", "-1");
			writeLog(e);
		}
		return JSONObject.toJSONString(apidatas);
	}

	/**
	 * 获取导入结果明细
	 */
	@GET
	@Path("/getImportResult")
	@Produces(MediaType.TEXT_PLAIN)
	public String getImportResult(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).getImportResult(ParamUtil.request2Map(request), request, user);
		} catch (Exception e) {
			apidatas.put("status", "-1");
			writeLog(e);
		}
		return JSONObject.toJSONString(apidatas);
	}

	/**
	 *  获取导入日志
	 */
	@GET
	@Path("/getImportColResultLog")
	@Produces(MediaType.TEXT_PLAIN)
	public String getImportColResultLog(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).getImportColResultLog(ParamUtil.request2Map(request), user);
		} catch (Exception e) {
			apidatas.put("status", "-1");
			writeLog(e);
		}
		return JSONObject.toJSONString(apidatas);
	}


	/**
	 * 查询高级条件
	 * @param request
	 * @param response
	 * @return
	 */
	@GET
	@Path("/getHistorySearchCondition")
	@Produces(MediaType.TEXT_PLAIN)
	public String getHistorySearchCondition(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		Map<String, Object> apidatas = new HashMap<String, Object>();
		try {
			User user = HrmUserVarify.getUser(request, response);
			apidatas = getService(user).getHistorySearchCondition(ParamUtil.request2Map(request), user);
		} catch (Exception e) {
			apidatas.put("status", "-1");
			writeLog(e);
		}
		return JSONObject.toJSONString(apidatas);
	}

}
