Package com.sfpay.histran.web

Source Code of com.sfpay.histran.web.IndexController

package com.sfpay.histran.web;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sfpay.histran.base.Page;
import com.sfpay.histran.domain.Histran;
import com.sfpay.histran.domain.User;
import com.sfpay.histran.service.IHistranService;
import com.sfpay.histran.service.IUserService;

@Controller
@RequestMapping(value = "/histran")
public class IndexController {
  Logger logger = LoggerFactory.getLogger(IndexController.class);
  @Resource
  private IHistranService histranService;
  @Resource
  private IUserService userService;

  @RequestMapping(value = "/login")
  public String login(HttpServletRequest request, HttpServletResponse response) throws NoSuchAlgorithmException,
      IOException {
    request.setCharacterEncoding("UTF-8");
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    User user = new User();
    user.setUsername(username);
    user.setPassword(password);
    if (userService.login(user)) {
      request.getSession().setAttribute("user", user);
      response.sendRedirect("/portal/histran/index");
      return null;
    }
    return "histran/login";
  }

  @RequestMapping(value = "/logout")
  public String logout(HttpServletRequest request) {
    request.getSession().setAttribute("user", null);
    return "histran/login";
  }

  @RequestMapping(value = "/index")
  public String index(HttpServletRequest request) {

    try {
      request.setCharacterEncoding("UTF-8");
    } catch (UnsupportedEncodingException e1) {
      e1.printStackTrace();
    }

    User u0 = (User) request.getSession().getAttribute("user");
    if (null == u0) {
      return "histran/login";
    }

    String area = request.getParameter("area");
    String txnDate = request.getParameter("txnDate");
    String sCurrentPage = request.getParameter("currentPage");
    String sTxnAmt1 = request.getParameter("txnAmt1");
    String sTxnAmt2 = request.getParameter("txnAmt2");
    String sAccType = request.getParameter("accType");
    String trace1 = request.getParameter("trace1");
    String settleDate = request.getParameter("settleDate");
    String cname = request.getParameter("cname");
    String tid = request.getParameter("tid");
    String spMid = request.getParameter("spMid");
    String spTid = request.getParameter("spTid");
    String pan = request.getParameter("pan");

    int currentPage = 1;
    int accType = 0;
    float txnAmt1 = 0f;
    float txnAmt2 = 0f;
    if (null != sAccType) {
      try {
        accType = Integer.valueOf(sAccType);
      } catch (Exception e) {
      }
    }
    if (null != sCurrentPage) {
      try {
        currentPage = Integer.valueOf(sCurrentPage);
        // currentPage = currentPage == 0 ? 1 : currentPage;
      } catch (Exception e) {
      }
    }

    if (null != sTxnAmt1) {
      try {
        txnAmt1 = Float.valueOf(sTxnAmt1);
      } catch (Exception e) {
      }
    }
    if (null != sTxnAmt2) {
      try {
        txnAmt2 = Float.valueOf(sTxnAmt2);
      } catch (Exception e) {
      }
    }

    Histran histran = new Histran();
    histran.setArea(area);
    if (null != txnDate) {
      histran.setTxnDate(txnDate.replaceAll("-", "").trim());
    }
    histran.setAccType(accType);
    if (null != settleDate) {
      histran.setSettleDate(settleDate.replaceAll("-", "").trim());
    }
    histran.setCname(cname);
    histran.setTid(tid);
    histran.setSpMid(spMid);
    histran.setSpTid(spTid);
    histran.setPan(pan);
    histran.setTrace1(trace1);
    if (txnAmt1 + txnAmt2 != 0) {
      histran.setTxnAmt(1);
    } else {
      histran.setTxnAmt(0);
    }

    Page page = histranService.query(histran, currentPage, txnAmt1, txnAmt2);
    if (logger.isDebugEnabled()) {
      // 获取参数的方式,通过增加方法的参数来自动将数据封装到对象中。
      logger.debug(histran.toString());
      logger.debug(page.toString());
    }

    histran.setTxnDate(txnDate);
    histran.setSettleDate(settleDate);

    request.setAttribute("page", page);
    request.setAttribute("histran", histran);
    if (txnAmt1 != 0) {
      request.setAttribute("txnAmt1", txnAmt1);
    }
    if (txnAmt2 != 0) {
      request.setAttribute("txnAmt2", txnAmt2);
    }
    request.setAttribute("currentPage", currentPage);
    request.setAttribute("totalSize", page.getTotalSize());
    request.setAttribute("pageSize", page.getPageSize());
    request.setAttribute("totalPageCount", page.getTotalPageCount());
    return "histran/index";
  }
}
TOP

Related Classes of com.sfpay.histran.web.IndexController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.