ClientAction.java 5.19 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.user.AgentInfoDao;
import com.cjs.cms.dao.user.account.ClientDao;
import com.cjs.cms.dao.user.account.ClientInfoDao;
import com.cjs.cms.model.user.AgentInfo;
import com.cjs.cms.util.lang.DateUtil;
import com.cjs.cms.util.lang.JsonUtil;
import com.cjs.cms.util.lang.PageUtils;

/**
 * 会员
 * 
 * @author tongyufu
 *
 */
@RestController
@RequestMapping("/report/client")
public class ClientAction {

    Logger                log = LogManager.getLogger();
    @Autowired
    private ReportBiz     reportBiz;
    @Autowired
    private ClientDao     clientDao;
    @Autowired
    private AgentInfoDao  agentDao;
    @Autowired
    private ClientInfoDao clientInfoDao;

    /** 开户人数统计 */
    @RequestMapping("search")
    public String search(@RequestParam Map<String, Object> params) {
        PageUtils.processOralcePage(params);
        reportBiz.formatDate(params);
        //开户人数统计
        Map<String, Object> footer = new HashMap<String, Object>();
        footer.put("OPEN_DATE", "汇总");
        footer.put("USERS", clientDao.searchSum(params));
        return JsonUtil.toPageJson(clientDao.search(params), clientDao.searchTotal(params), footer);
    }

    /**
     * 会员导出
     * @param params
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("exportClient")
    public ResponseEntity<byte[]> exportClient(@RequestParam Map<String, Object> params,
                                               HttpServletRequest request) throws Exception {
        reportBiz.formatDate(params);
        params.put("rows", 999999);
        PageUtils.processOralcePage(params);
        File targetFile = reportBiz.exportClient(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);
    }

    /**会员等级*/
    @RequestMapping("searchLevel")
    public String searchLevel(@RequestParam Map<String, Object> params) {
        PageUtils.processOralcePage(params);
        return JsonUtil.toPageJson(clientDao.searchClient(params),
            clientDao.searchClientCount(params));
    }

    /**下属会员统计*/
    @RequestMapping("searchUnder")
    public String searchUnder(@RequestParam Map<String, Object> params) {
        PageUtils.processOralcePage(params);
        DateUtil.formatHundsunDate(params);
        //查询用户是否是代理商
        if (params.containsKey("clientId")) {
            AgentInfo agentInfo = agentDao.queryByFundAccount(params.get("clientId").toString());
            if (agentInfo != null) {
                params.put("clientId", agentInfo.getAgentNo());
            }
        }

        return JsonUtil.toPageJson(clientDao.queryUnderInfo(params),
            clientDao.queryUnderTotal(params));
    }

    /**下辖会员交易量统计*/
    @RequestMapping("searchUnderCount")
    public String searchUnderCount(@RequestParam Map<String, Object> params) {
        PageUtils.processOralcePage(params);
        DateUtil.formatHundsunDate(params);

        Map<String, Object> footer = clientInfoDao.querySumCountTatal(params);
        if (footer == null) {
            footer = new HashMap<String, Object>();
        }
        footer.put("CLIENTID", "汇总");
        return JsonUtil.toPageJson(clientInfoDao.queryclientUnderCount(params),
            clientInfoDao.queryclientUnderCountTotal(params), footer);
    }

    /**导出下辖会员统计*/
    @RequestMapping("exportUnderCount")
    public ResponseEntity<byte[]> exportUnderCount(@RequestParam Map<String, Object> params,
                                                   HttpServletRequest request) throws Exception {
        reportBiz.formatDate(params);
        params.put("rows", 999999);
        PageUtils.processOralcePage(params);
        File targetFile = reportBiz.exportClientUnder(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);
    }
}