EntrustOldApplyBiz.java 3.09 KB
package com.cjs.cms.biz.ration;

import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.cjs.cms.action.user.fund.UserBalanceAction;
import com.cjs.cms.dao.ration.RationOldConfigDao;
import com.cjs.cms.dao.ration.TrustApplyDao;
import com.cjs.cms.util.file.FileUtil;
import com.cjs.cms.util.lang.DateEnum;
import com.cjs.cms.util.lang.DateUtil;
import com.cjs.cms.util.poi.ExcelConfig;
import com.cjs.cms.util.poi.ExcelUtil;

/**
 * 申请在托管查询业务
 * 
 * @author xiangwei
 *
 */
@Service
public class EntrustOldApplyBiz {
    @Value("${download.export}")
    private String             exportPath;
    @Autowired
    private RationOldConfigDao rationOldConfigDao;
    @Autowired
    private TrustApplyDao      applyDao;

    /**申请在托管选择*/
    public List<Map<String, Object>> searchChoose(Map<String, Object> params) {
        List<String> otcCodes = rationOldConfigDao.queryAllCode(params);
        if (otcCodes.size() == 0) {
            return new ArrayList<Map<String, Object>>();
        }
        params.put("otcCodes", otcCodes);
        List<Map<String, Object>> resultMap = applyDao.queryAgree(params);
        return resultMap;
    }

    /**申请在托管总页数*/
    public int searchChooseTotal(Map<String, Object> params) {
        List<String> otcCodes = rationOldConfigDao.queryAllCode(params);
        if (otcCodes.size() == 0) {
            return 0;
        }
        params.put("otcCodes", otcCodes);
        return applyDao.queryAgreeTotal(params);
    }

    /**
     * 生成权益查询excel表
     */
    public File export(Map<String, Object> params) throws Exception {
        String filename = "申请在托管选择_" + DateUtil.getNow(DateEnum.UNSIGNED_DATE_TIME);
        filename = FileUtil.makeMonthDir(exportPath) + filename + ".xlsx";
        File targetFile = new File(filename);
        ExcelConfig config = new ExcelConfig();
        URI template = UserBalanceAction.class.getResource("/excel/ration_apply_choose.xlsx")
            .toURI();
        List<String> otcCodes = rationOldConfigDao.queryAllCode(params);
        if (otcCodes.size() == 0) {
            new ArrayList<Map<String, Object>>();
        }
        params.put("otcCodes", otcCodes);
        List<Map<String, Object>> resultMap = applyDao.queryAgree(params);
        for (Map<String, Object> map : resultMap) {
            String date = map.get("AGGREE_DATE") == null ? "" : map.get("AGGREE_DATE").toString();
            if (!"".equals(date)) {
                date = date.substring(0, 4) + "-" + date.substring(4, 6) + "-"
                       + date.substring(6, 8);
                map.put("AGGREE_DATE", date);
            }
        }
        // 先生成Excel文件
        config.setSourceTemplate(new File(template));
        config.setTargetFile(targetFile);
        config.setData(resultMap);
        new ExcelUtil(config).writeExcel();
        return targetFile;
    }
}