TrustApplyAction.java 5.94 KB
package com.cjs.cms.action.report;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cjs.cms.biz.report.ReportBiz;
import com.cjs.cms.dao.ration.TrustApplyDao;
import com.cjs.cms.util.lang.JsonUtil;
import com.cjs.cms.util.lang.PageUtils;

/**
 * 托管
 * 
 * @author tongyufu
 *
 */
@RestController
@RequestMapping("/report/trustApply")
public class TrustApplyAction {

    Logger                log = LogManager.getLogger();
    @Autowired
    private ReportBiz     reportBiz;
    @Autowired
    private TrustApplyDao trustApplyDao;

    /** 托管数量统计 */
    @RequestMapping("querySum")
    public String querySum(@RequestParam Map<String, Object> params) {
        reportBiz.formatDate(params);
        PageUtils.processOralcePage(params);
        return JsonUtil.toPageJson(trustApplyDao.querySum(params),
            trustApplyDao.querySumTotal(params));
    }

    /** 查询 */
    @RequestMapping("search")
    public String search(@RequestParam Map<String, Object> params) {
        reportBiz.formatDate(params);
        PageUtils.processOralcePage(params);
        return JsonUtil.toPageJson(trustApplyDao.search(params), trustApplyDao.searchTotal(params));
    }

    @RequestMapping("export")
    public ResponseEntity<byte[]> export(@RequestParam Map<String, Object> params,
                                         HttpServletRequest request) throws Exception {
        reportBiz.formatDate(params);
        params.put("rows", 999999);
        PageUtils.processOralcePage(params);
        File targetFile = reportBiz.exportTrustApplyDetail(params);
        HttpHeaders head = new HttpHeaders();
        head.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        // 下载的文件名
        head.setContentDispositionFormData("attachment",
            new String(targetFile.getName().getBytes("UTF-8"), "ISO8859-1"));
        return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(targetFile), head,
            HttpStatus.CREATED);
    }

    /**
     * 托管申请查询
     * @param params
     * @return
     */
    @RequestMapping("searchApply")
    public String getTrustApply(@RequestParam Map<String, Object> params) {
        reportBiz.formatDate(params);
        PageUtils.processOralcePage(params);
        Map<String, Object> footer = trustApplyDao.selectApplySumTotal(params);
        if (footer == null) {
            footer = new HashMap<String, Object>();
        }
        footer.put("APPLY_DATE", "汇总");
        return JsonUtil.toPageJson(trustApplyDao.selectApply(params),
            trustApplyDao.selectApplyTotal(params), footer);
    }

    /**
     * 托管申请查询导出
     * @param params
     * @param request
     * @return
     * @throws Exception
     */

    @RequestMapping("exportApply")
    public ResponseEntity<byte[]> exportApply(@RequestParam Map<String, Object> params,
                                              HttpServletRequest request) throws Exception {
        reportBiz.formatDate(params);
        params.put("rows", 999999);
        PageUtils.processOralcePage(params);
        File targetFile = reportBiz.exportTrustApplyList(params);
        HttpHeaders head = new HttpHeaders();
        head.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        // 下载的文件名
        head.setContentDispositionFormData("attachment",
            new String(targetFile.getName().getBytes("UTF-8"), "ISO8859-1"));
        return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(targetFile), head,
            HttpStatus.CREATED);
    }

    /**
     * 托管转赵涌在线
     * @param params
     * @return
     */
    @RequestMapping("online")
    public String searchApplyOnline(@RequestParam Map<String, Object> params) {
        reportBiz.formatDate(params);
        PageUtils.processOralcePage(params);
        return JsonUtil.toPageJson(trustApplyDao.selectToOnline(params),
            trustApplyDao.selectToOnlineTotal(params));
    }

    /**
     * 托管转赵涌在线导出
     * @param params
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("exportOnline")
    public ResponseEntity<byte[]> exportOnline(@RequestParam Map<String, Object> params,
                                               HttpServletRequest request) throws Exception {
        reportBiz.formatDate(params);
        params.put("rows", 999999);
        PageUtils.processOralcePage(params);
        File targetFile = reportBiz.exportTrustApplyOnline(params);
        HttpHeaders head = new HttpHeaders();
        head.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        // 下载的文件名
        head.setContentDispositionFormData("attachment",
            new String(targetFile.getName().getBytes("UTF-8"), "ISO8859-1"));
        return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(targetFile), head,
            HttpStatus.CREATED);
    }

    /**
     * 转赵涌在线
     * @return
     *  
     */
    @RequestMapping("/changeOnline")
    public String changeOnline(@RequestParam Map<String, Object> params) {
        return reportBiz.changeOnline(params);
    }

    /**
     * 转赵涌在心
     * 根据内部流转号查询托管信息
     * @param innercirculatNo 内部流转号
     * @return  托管信息
     */
    @RequestMapping("/queryTrustApply")
    public String queryTrustApply(String innerNo) {
        return reportBiz.queryTrustApply(innerNo);
    }
}