package com.landray.kmss.fs.expense.service.spring;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import net.sf.json.JSONObject;
/**
*
* 通过接收年月参数统计个人对应时间发生的报销费用
*
* @param context
*
* @return String
*/
@WebServlet(displayName = "FsExpensePersonServlet",name = "FsExpensePersonServlet",urlPatterns = { "/sys/webservice/fsExpensePerson" })
public class FsExpensePersonServletServiceImp extends HttpServlet {
private static final long serialVersionUID = 1L;
private Log logger = LogFactory.getLog(getClass());
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
logger.info("调用费控接口返回个人报销结果开始...");
String rtn = "";
try {
rtn = getPersonExpenseData(req, resp);
} catch (Exception e) {
e.printStackTrace();
}
resp.setContentType("text/html;charset=utf-8");
resp.setCharacterEncoding("utf-8");
resp.getWriter().write(rtn);
logger.info("调用费控接口返回个人报销结果结束...");
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
logger.info("调用费控接口返回个人报销结果开始...");
String rtn = "";
try {
rtn = getPersonExpenseData(req, resp);
} catch (Exception e) {
e.printStackTrace();
}
resp.setContentType("text/html;charset=utf-8");
resp.setCharacterEncoding("utf-8");
resp.getWriter().write(rtn);
logger.info("调用费控接口返回个人报销结果结束...");
}
protected String getPersonExpenseData(HttpServletRequest req,
HttpServletResponse resp) throws Exception {
JSONObject rtn = new JSONObject();
try {
ServletContext servletContext = this.getServletContext();
WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(
servletContext);
FsExpensePersonResponseService service = (FsExpensePersonResponseService) context.getBean(
"fsExpensePersonResponseService");
String result = service.getPersonExpenseData(req);
rtn.put("success", true);
rtn.put("message", result);
} catch (Exception e) {
logger.error("获取个人报销结果发生错误", e);
rtn.put("success", false);
rtn.put("message", e.getMessage());
}
return rtn.toString();
}
}
urlPatterns = { "/sys/webservice/fsExpensePerson" }即为接口访问地址,直接展现接口返回结果