AgentTradeAction.java 3.86 KB
package com.cjs.cms.action.agent;

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

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.io.FileUtils;
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.agent.AgentTradeBiz;
import com.cjs.cms.biz.report.ReportBiz;
import com.cjs.cms.dao.user.AgentInfoDao;
import com.cjs.cms.model.user.AgentInfo;
import com.cjs.cms.util.lang.JsonUtil;
import com.cjs.cms.util.lang.PageUtils;
import com.cjs.cms.util.lang.StringUtil;
import com.cjs.cms.util.web.TimeInterval;

/**
 * 代理商
 * 
 * @author tongxiaochuan
 *
 */
@RestController
@RequestMapping("/agent")
public class AgentTradeAction {

    @Autowired
    private AgentTradeBiz agentBiz;
    @Autowired
    private ReportBiz     reportBiz;
    @Autowired
    private AgentInfoDao  agentInfoDao;

    //    @RequestMapping("check")
    //    public Map<String, Object> checkLevel(@RequestParam Map<String, Object> params) {
    //        return agentBiz.checkMember(params);
    //    }

    /**
     * 查询一级会员交易明细
     * @param params
     * @return
     */
    @RequestMapping("/trade/member")
    public String queryMemberTrade(@RequestParam Map<String, Object> params) {
        PageUtils.processOralcePage(params);
        reportBiz.formatDate(params);
        if (!StringUtil.isBlank(params.get("developer"))) {
            Map<String, Object> search = new HashMap<String, Object>();
            search.put("developer", params.get("developer"));
            List<AgentInfo> list = agentInfoDao.searchAgent(search);
            if (list.size() > 0) {
                params.put("agentNo", list.get(0).getAgentNo());
            }
        }
        return JsonUtil.toPageJson(agentBiz.queryTradeMember(params),
            agentBiz.queryTradeMemberTotal(params), agentBiz.queryTradeMemberSum(params));
    }

    @TimeInterval("10")
    @RequestMapping("/trade/member/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 = agentBiz.export(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("/trade/agent")
    //    public String queryAgentTrade(@RequestParam Map<String, Object> params) {
    //        PageUtils.processOralcePage(params);
    //        reportBiz.formatDate(params);
    //        if (!StringUtil.isBlank(params.get("developer"))) {
    //            Map<String, Object> search = new HashMap<String, Object>();
    //            search.put("fundAccount", params.get("developer"));
    //            List<AgentInfo> list = agentInfoDao.searchAgent(search);
    //            if (list.size() > 0) {
    //                params.put("agentNo", list.get(0).getAgentNo());
    //            }
    //        }
    //        return JsonUtil.toPageJson(agentBiz.queryTradeAgent(params),
    //            agentBiz.queryTradeAgentTotal(params), agentBiz.queryTradeAgentSum(params));
    //    }
}