package cc.smtweb.system.bpm.web.sys.base.dict;

import cc.smtweb.framework.core.annotation.SwBody;
import cc.smtweb.framework.core.annotation.SwService;
import cc.smtweb.framework.core.common.R;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.mvc.service.AbstractHandler;
import cc.smtweb.framework.core.session.UserSession;
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageLoadHandler;
import cc.smtweb.system.bpm.web.engine.dynPage.DynPageService;

import java.io.File;
import java.io.FileOutputStream;
import java.nio.charset.StandardCharsets;

/**
 * Created by 1 at 2022-07-28 09:23:54
 * 页面【[数据字典]的服务类
 */
@SwService
public class DictService extends DynPageService {

    @Override
    protected AbstractHandler createHandler(String type) {
        switch (type) {
            case TYPE_SAVE:
                return new DictHandler.DictSaveHandler();
        }
        return super.createHandler(type);
    }
    //新增
    public R exportExcel(@SwBody SwMap params, UserSession us) {
        try {
            File tempFile = File.createTempFile("xls_", ".txt", new File(System.getProperty("java.io.tmpdir")));
            FileOutputStream fs = new FileOutputStream(tempFile);
            fs.write("flypht-唐海鹏".getBytes(StandardCharsets.UTF_8));
            SwMap swMap = new SwMap();
            swMap.put("fileName",tempFile.getName());
            swMap.put("filePath",tempFile.getAbsolutePath());
            return R.success(swMap);
        }catch (Exception e){
            return R.error("导出失败！");
        }
    }
}
