package com.philisense.www.controller.web;

import com.philisense.www.common.config.CommonConst;
import com.philisense.www.service.ProTenantService;
import com.philisense.www.pojos.entity.ProTenant;
import com.philisense.www.annotation.log.OperateLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.philisense.www.controller.BaseUtilController;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import cn.hutool.core.io.IoUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;

import java.util.*;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.math.BigDecimal;

@RestController
@RequestMapping(CommonConst.WEB_REST_SERVICE_PREFICX + "protenant")
@Api(tags = "ProTenantControllerForWeb|一个用来操作-{租户表}-业务模块的控制器")
public class ProTenantControllerForWeb extends BaseUtilController {

    @Autowired
    private ProTenantService proTenantService;


    @GetMapping("/delete")
    @ApiOperation(value = "根据-{租户表}-主键删除记录", notes = "成功返回:{\"success\":true,\"message\",\"数据删除成功\"},失败返回:{\"success\":false,\"message\",\"数据删除失败\"}")
    @ApiImplicitParam(paramType = "query", name = "recordid", value = "记录主键", required = true, dataTypeClass = String.class)
    @OperateLog(name = "根据-{租户表}-主键删除记录", value = "delete", type = "PC")
    public Map<String, Object> deleteByPrimaryKeyForProTenantForWeb(HttpServletRequest request, HttpServletResponse response, @RequestParam String recordid) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            int flag = proTenantService.deleteByPrimaryKey(recordid);
            if (1 <= flag) {
                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, DELETE_SUCCESS_MSG);
            } else {
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, DELETE_FAIL_MSG);
            }

        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, DELETE_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @GetMapping("/get")
    @ApiOperation(value = "根据-{租户表}-主键查询记录", notes = "成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"datarecord\":\"{}\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
    @ApiImplicitParam(paramType = "query", name = "recordid", value = "记录主键", required = true, dataTypeClass = String.class)
    @OperateLog(name = "根据-{租户表}-主键查询记录", value = "query", type = "PC")
    public Map<String, Object> selectByPrimaryKeyForProTenantForWeb(HttpServletRequest request, HttpServletResponse response, @RequestParam String recordid) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {

            result.put(DATASUCCESS, SUCCESSFLAG);
            result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
            result.put(DATARECORD, proTenantService.selectByPrimaryKey(recordid));
        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, QUERY_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @PostMapping("/insert")
    @ApiOperation(value = "根据-{租户表}-对象插入记录", notes = "成功返回:{\"success\":true,\"message\",\"数据插入成功\"},失败返回:{\"success\":false,\"message\",\"数据插入失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = ProTenant.ID_KEY, value = "id", required = true, dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_CODE_KEY, value = "租户代码", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_NAME_KEY, value = "租户名", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.MENOS_KEY, value = "备注", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_ID_KEY, value = "create_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATOR_KEY, value = "创建人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_TIME_KEY, value = "创建时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATER_KEY, value = "更新人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_ID_KEY, value = "update_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_TIME_KEY, value = "更新时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.STATUS_KEY, value = "0正常 9-冻结", required = true, dataTypeClass = String.class)
    })
    @OperateLog(name = "根据-{租户表}-对象插入记录", value = "insert", type = "PC")
    public Map<String, Object> insertForProTenantForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            // map.put("id", UUID.randomUUID().toString().replaceAll("-", ""));
            if (!proTenantService.checkTenantCodeUnique(map)) {
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, INSERT_FAIL_MSG + "租户代码不能重复");
                return result;
            }
            proTenantService.insert(map);
            result.put(DATASUCCESS, SUCCESSFLAG);
            result.put(DATAMESSAGE, INSERT_SUCCESS_MSG);
        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, INSERT_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @PostMapping("/update")
    @ApiOperation(value = "根据-{租户表}-对象更新记录", notes = "成功返回:{\"success\":true,\"message\",\"数据更新成功\"},失败返回:{\"success\":false,\"message\",\"数据更新失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = ProTenant.ID_KEY, value = "id", required = true, dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_CODE_KEY, value = "租户代码", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_NAME_KEY, value = "租户名", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.MENOS_KEY, value = "备注", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_ID_KEY, value = "create_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATOR_KEY, value = "创建人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_TIME_KEY, value = "创建时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATER_KEY, value = "更新人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_ID_KEY, value = "update_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_TIME_KEY, value = "更新时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.STATUS_KEY, value = "0正常 9-冻结", required = true, dataTypeClass = String.class)
    })
    @OperateLog(name = "根据-{租户表}-对象更新记录", value = "update", type = "PC")
    public Map<String, Object> updateForProTenantForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {

            if (!proTenantService.checkTenantCodeUnique(map)) {
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, UPDATE_FAIL_MSG + "租户代码不能重复");
                return result;
            }

            Map<String, Object> paramsmap = proTenantService.selectByPrimaryKey(map.get("id") + "");

            int flag = 0;

            if (null != paramsmap && paramsmap.size() > 0) {
                paramsmap.putAll(map);
                flag = proTenantService.update(paramsmap);
            }

            if (1 <= flag) {
                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, UPDATE_SUCCESS_MSG);
            } else {
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, UPDATE_FAIL_MSG);
            }

        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, UPDATE_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @PostMapping("/deleteByMap")
    @ApiOperation(value = "根据-{租户表}-对象Map删除记录", notes = "成功返回:{\"success\":true,\"message\",\"数据删除成功\"},失败返回:{\"success\":false,\"message\",\"数据删除失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = ProTenant.ID_KEY, value = "id", required = true, dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_CODE_KEY, value = "租户代码", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_NAME_KEY, value = "租户名", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.MENOS_KEY, value = "备注", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_ID_KEY, value = "create_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATOR_KEY, value = "创建人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_TIME_KEY, value = "创建时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATER_KEY, value = "更新人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_ID_KEY, value = "update_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_TIME_KEY, value = "更新时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.STATUS_KEY, value = "0正常 9-冻结", required = true, dataTypeClass = String.class)
    })
    @OperateLog(name = "根据-{租户表}-对象Map删除记录", value = "delete", type = "PC")
    public Map<String, Object> deleteByMapForProTenantForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            int flag = proTenantService.deleteByMap(map);
            if (1 <= flag) {
                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, DELETE_SUCCESS_MSG);
            } else {
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, DELETE_FAIL_MSG);
            }

        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, DELETE_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @PostMapping("/updateByMap")
    @ApiOperation(value = "根据-{租户表}-对象Map更新记录", notes = "成功返回:{\"success\":true,\"message\",\"数据更新成功\"},失败返回:{\"success\":false,\"message\",\"数据更新失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = ProTenant.ID_KEY, value = "id", required = true, dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_CODE_KEY, value = "租户代码", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_NAME_KEY, value = "租户名", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.MENOS_KEY, value = "备注", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_ID_KEY, value = "create_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATOR_KEY, value = "创建人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_TIME_KEY, value = "创建时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATER_KEY, value = "更新人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_ID_KEY, value = "update_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_TIME_KEY, value = "更新时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.STATUS_KEY, value = "0正常 9-冻结", required = true, dataTypeClass = String.class)
    })
    @OperateLog(name = "根据-{租户表}-对象Map更新记录", value = "update", type = "PC")
    public Map<String, Object> updateByMapForProTenantForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {


            int flag = proTenantService.updateByMap(map);
            if (1 <= flag) {
                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, UPDATE_SUCCESS_MSG);
            } else {
                result.put(DATASUCCESS, ERRORFLAG);
                result.put(DATAMESSAGE, UPDATE_FAIL_MSG);
            }

        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, UPDATE_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @PostMapping("/getOne")
    @ApiOperation(value = "根据-{租户表}-对象Map查询记录", notes = "成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"datarecord\":\"{}\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = ProTenant.ID_KEY, value = "id", required = true, dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_CODE_KEY, value = "租户代码", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_NAME_KEY, value = "租户名", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.MENOS_KEY, value = "备注", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_ID_KEY, value = "create_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATOR_KEY, value = "创建人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_TIME_KEY, value = "创建时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATER_KEY, value = "更新人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_ID_KEY, value = "update_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_TIME_KEY, value = "更新时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.STATUS_KEY, value = "0正常 9-冻结", required = true, dataTypeClass = String.class)
    })
    @OperateLog(name = "根据-{租户表}-对象Map查询记录", value = "query", type = "PC")
    public Map<String, Object> getOneForProTenantForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {

            result.put(DATASUCCESS, SUCCESSFLAG);
            result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
            result.put(DATARECORD, proTenantService.getOne(map));
        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, QUERY_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @PostMapping("/getAll")
    @ApiOperation(value = "根据-{租户表}-对象Map查询所有记录", notes = "成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"data\":\"[]\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = ProTenant.ID_KEY, value = "id", required = true, dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_CODE_KEY, value = "租户代码", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_NAME_KEY, value = "租户名", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.MENOS_KEY, value = "备注", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_ID_KEY, value = "create_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATOR_KEY, value = "创建人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_TIME_KEY, value = "创建时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATER_KEY, value = "更新人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_ID_KEY, value = "update_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_TIME_KEY, value = "更新时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.STATUS_KEY, value = "0正常 9-冻结", required = true, dataTypeClass = String.class)
    })
    @OperateLog(name = "根据-{租户表}-对象Map查询所有记录", value = "query", type = "PC")
    public Map<String, Object> getAllForProTenantForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {

            result.put(DATASUCCESS, SUCCESSFLAG);
            result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
            result.put(DATALIST, proTenantService.getAll(map));
        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, QUERY_FAIL_MSG + e.getMessage());
        }
        return result;
    }


    @PostMapping("/queryPage")
    @ApiOperation(value = "根据-{租户表}-对象Map分页记录", notes = "成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"data\":\"[]\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = ProTenant.ID_KEY, value = "id", required = true, dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_CODE_KEY, value = "租户代码", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_NAME_KEY, value = "租户名", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.MENOS_KEY, value = "备注", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_ID_KEY, value = "create_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATOR_KEY, value = "创建人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_TIME_KEY, value = "创建时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATER_KEY, value = "更新人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_ID_KEY, value = "update_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_TIME_KEY, value = "更新时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.STATUS_KEY, value = "0正常 9-冻结", required = true, dataTypeClass = String.class)
    })
    @OperateLog(name = "根据-{租户表}-对象Map分页记录", value = "query", type = "PC")
    public Map<String, Object> queryPageForProTenantForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {

            int currentPage = map.get(DATACURRENT) != null ? Integer.parseInt(map.get(DATACURRENT) + "") - 1 : 0;
            int pageSize = map.get(PAGESIZE) != null ? Integer.parseInt(map.get(PAGESIZE) + "") : 10;
            int pageStart = currentPage * pageSize;


            map.put(PAGESIZE, pageSize);
            map.put(PAGESTART, pageStart);

            int total = proTenantService.count(map);
            List<Map<String, Object>> datalist = new ArrayList<Map<String, Object>>();
            if (total > 0) {
                datalist = proTenantService.queryPage(map);
            }
            result.put(DATASUCCESS, SUCCESSFLAG);
            result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
            result.put(DATALIST, datalist);
            Map<String, Object> pagemode = new HashMap<String, Object>();
            pagemode.put(DATATOTAL, total);
            pagemode.put(PAGESIZE, map.get(PAGESIZE) != null ? map.get(PAGESIZE) : 10);
            pagemode.put(DATACURRENT, map.get(DATACURRENT) != null ? map.get(DATACURRENT) : 0);
            result.put(PAGINATION, pagemode);
        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, QUERY_FAIL_MSG + e.getMessage());
        }
        return result;
    }


    @PostMapping("/queryPageVue")
    @ApiOperation(value = "根据-{租户表}-对象Map分页记录", notes = "成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"data\":\"[]\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = ProTenant.ID_KEY, value = "id", required = true, dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_CODE_KEY, value = "租户代码", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_NAME_KEY, value = "租户名", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.MENOS_KEY, value = "备注", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_ID_KEY, value = "create_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATOR_KEY, value = "创建人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_TIME_KEY, value = "创建时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATER_KEY, value = "更新人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_ID_KEY, value = "update_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_TIME_KEY, value = "更新时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.STATUS_KEY, value = "0正常 9-冻结", required = true, dataTypeClass = String.class)
    })
    @OperateLog(name = "根据-{租户表}-对象Map分页记录", value = "query", type = "PC")
    public Map<String, Object> queryPageVueForProTenantForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {

            int currentPage = map.get(DATACURRENT_VUE) != null ? Integer.parseInt(map.get(DATACURRENT_VUE) + "") - 1 : 0;
            int pageSize = map.get(PAGESIZE_VUE) != null ? Integer.parseInt(map.get(PAGESIZE_VUE) + "") : 10;
            int pageStart = currentPage * pageSize;


            map.put(PAGESIZE_VUE, pageSize);
            map.put(PAGESTART, pageStart);

            int total = proTenantService.count(map);
            List<Map<String, Object>> datalist = new ArrayList<Map<String, Object>>();
            if (total > 0) {
                datalist = proTenantService.queryPage(map);
            }
            Map<String, Object> tempresult = new HashMap<String, Object>();
            tempresult.put(DATASUCCESS, SUCCESSFLAG);
            tempresult.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
            tempresult.put(DATALIST_VUE, datalist);
            tempresult.put(DATATOTAL_VUE, total);
            tempresult.put(PAGESIZE_VUE, map.get(PAGESIZE_VUE) != null ? map.get(PAGESIZE_VUE) : 10);
            tempresult.put(DATACURRENT_VUE, map.get(DATACURRENT_VUE) != null ? map.get(DATACURRENT_VUE) : 0);
            result.put(DATARESULT, tempresult);
        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, QUERY_FAIL_MSG + e.getMessage());
        }
        return result;
    }


    @PostMapping("/queryPageOracle")
    @ApiOperation(value = "根据-{租户表}-对象Map分页记录", notes = "成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"data\":\"[]\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = ProTenant.ID_KEY, value = "id", required = true, dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_CODE_KEY, value = "租户代码", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_NAME_KEY, value = "租户名", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.MENOS_KEY, value = "备注", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_ID_KEY, value = "create_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATOR_KEY, value = "创建人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_TIME_KEY, value = "创建时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATER_KEY, value = "更新人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_ID_KEY, value = "update_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_TIME_KEY, value = "更新时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.STATUS_KEY, value = "0正常 9-冻结", required = true, dataTypeClass = String.class)
    })
    @OperateLog(name = "根据-{租户表}-对象Map分页记录", value = "query", type = "PC")
    public Map<String, Object> queryPageOracleForProTenantForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {

            int currentPage = map.get(DATACURRENT) != null ? Integer.parseInt(map.get(DATACURRENT) + "") : 1;
            int pageSize = map.get(PAGESIZE) != null ? Integer.parseInt(map.get(PAGESIZE) + "") : 10;
            int pageStart = currentPage * pageSize;


            map.put(PAGESTART, (currentPage - 1) * pageSize);
            map.put(PAGEEND, currentPage * pageSize);

            int total = proTenantService.count(map);
            List<Map<String, Object>> datalist = new ArrayList<Map<String, Object>>();
            if (total > 0) {
                datalist = proTenantService.queryPage(map);
            }
            result.put(DATASUCCESS, SUCCESSFLAG);
            result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
            result.put(DATALIST, datalist);
            Map<String, Object> pagemode = new HashMap<String, Object>();
            pagemode.put(DATATOTAL, total);
            pagemode.put(PAGESIZE, map.get(PAGESIZE) != null ? map.get(PAGESIZE) : 10);
            pagemode.put(DATACURRENT, map.get(DATACURRENT) != null ? map.get(DATACURRENT) : 0);
            result.put(PAGINATION, pagemode);
        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, QUERY_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @PostMapping("/count")
    @ApiOperation(value = "根据-{租户表}-对象Map统计查询总数记录", notes = "成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"data\":\"[]\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = ProTenant.ID_KEY, value = "id", required = true, dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_CODE_KEY, value = "租户代码", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_NAME_KEY, value = "租户名", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.MENOS_KEY, value = "备注", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_ID_KEY, value = "create_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATOR_KEY, value = "创建人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_TIME_KEY, value = "创建时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATER_KEY, value = "更新人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_ID_KEY, value = "update_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_TIME_KEY, value = "更新时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.STATUS_KEY, value = "0正常 9-冻结", required = true, dataTypeClass = String.class)
    })
    @OperateLog(name = "根据-{租户表}-对象Map统计查询总数记录", value = "query", type = "PC")
    public Map<String, Object> countForProTenantForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {

            result.put(DATASUCCESS, SUCCESSFLAG);
            result.put(DATAMESSAGE, QUERY_SUCCESS_MSG);
            result.put(DATATOTAL, proTenantService.count(map));
        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, QUERY_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @PostMapping("/insertBatch")
    @ApiOperation(value = "根据-{租户表}-对象Map批量插入记录", notes = "成功返回:{\"success\":true,\"message\",\"数据插入成功\"},失败返回:{\"success\":false,\"message\",\"数据插入失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = ProTenant.ID_KEY, value = "id", required = true, dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_CODE_KEY, value = "租户代码", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_NAME_KEY, value = "租户名", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.MENOS_KEY, value = "备注", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_ID_KEY, value = "create_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATOR_KEY, value = "创建人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_TIME_KEY, value = "创建时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATER_KEY, value = "更新人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_ID_KEY, value = "update_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_TIME_KEY, value = "更新时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.STATUS_KEY, value = "0正常 9-冻结", required = true, dataTypeClass = String.class)
    })
    @OperateLog(name = "根据-{租户表}-对象Map批量插入记录", value = "insert", type = "PC")
    public Map<String, Object> insertBatchForProTenantForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody List<Map<String, Object>> list) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {

            for (Map<String, Object> map : list) {
                map.put("id", UUID.randomUUID().toString().replaceAll("-", ""));
            }

            proTenantService.insertBatch(list);
            result.put(DATASUCCESS, SUCCESSFLAG);
            result.put(DATAMESSAGE, INSERT_SUCCESS_MSG);
        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, INSERT_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @PostMapping("/deleteBatch")
    @ApiOperation(value = "根据-{租户表}-对象Map批量删除记录", notes = "成功返回:{\"success\":true,\"message\",\"数据删除成功\"},失败返回:{\"success\":false,\"message\",\"数据删除失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = ProTenant.ID_KEY, value = "id", required = true, dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_CODE_KEY, value = "租户代码", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_NAME_KEY, value = "租户名", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.MENOS_KEY, value = "备注", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_ID_KEY, value = "create_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATOR_KEY, value = "创建人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_TIME_KEY, value = "创建时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATER_KEY, value = "更新人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_ID_KEY, value = "update_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_TIME_KEY, value = "更新时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.STATUS_KEY, value = "0正常 9-冻结", required = true, dataTypeClass = String.class)
    })
    @OperateLog(name = "根据-{租户表}-对象Map批量删除记录", value = "delete", type = "PC")
    public Map<String, Object> deleteBatchForProTenantForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody List<Map<String, Object>> list) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            proTenantService.deleteBatch(list);
            result.put(DATASUCCESS, SUCCESSFLAG);
            result.put(DATAMESSAGE, DELETE_SUCCESS_MSG);

        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, DELETE_FAIL_MSG + e.getMessage());
        }
        return result;
    }

    @PostMapping("/updateBatch")
    @ApiOperation(value = "根据-{租户表}-对象Map批量更新记录", notes = "成功返回:{\"success\":true,\"message\",\"数据更新成功\"},失败返回:{\"success\":false,\"message\",\"数据更新失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = ProTenant.ID_KEY, value = "id", required = true, dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_CODE_KEY, value = "租户代码", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_NAME_KEY, value = "租户名", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.MENOS_KEY, value = "备注", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_ID_KEY, value = "create_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATOR_KEY, value = "创建人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_TIME_KEY, value = "创建时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATER_KEY, value = "更新人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_ID_KEY, value = "update_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_TIME_KEY, value = "更新时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.STATUS_KEY, value = "0正常 9-冻结", required = true, dataTypeClass = String.class)
    })
    @OperateLog(name = "根据-{租户表}-对象Map批量更新记录", value = "update", type = "PC")
    public Map<String, Object> updateBatchForProTenantForWeb(HttpServletRequest request, HttpServletResponse response, @RequestBody List<Map<String, Object>> list) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {


            proTenantService.updateBatch(list);
            result.put(DATASUCCESS, SUCCESSFLAG);
            result.put(DATAMESSAGE, UPDATE_SUCCESS_MSG);

        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, UPDATE_FAIL_MSG + e.getMessage());
        }
        return result;
    }


    @GetMapping("/export")
    @ApiOperation(value = "根据-{{租户表}}-对象Map导出所有记录", notes = "成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"data\":\"[]\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = ProTenant.ID_KEY, value = "id", required = true, dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_CODE_KEY, value = "租户代码", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_NAME_KEY, value = "租户名", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.MENOS_KEY, value = "备注", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_ID_KEY, value = "create_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATOR_KEY, value = "创建人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_TIME_KEY, value = "创建时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATER_KEY, value = "更新人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_ID_KEY, value = "update_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_TIME_KEY, value = "更新时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.STATUS_KEY, value = "0正常 9-冻结", required = true, dataTypeClass = String.class)
    })
    @OperateLog(name = "根据-{{租户表}}-对象Map导出所有记录", value = "query", type = "PC")
    public void exportForProTenantForWeb(HttpServletRequest request, HttpServletResponse response, @RequestParam Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {

            List<Map<String, Object>> rows = proTenantService.getAll(map);
            // 通过工具类创建writer
            //创建xlsx格式的
            ExcelWriter writer = ExcelUtil.getWriter(true);
            String filename = "租户表";
            getWriter(writer, filename);
            writer.setHeaderAlias(getKVAliasMap());


            writer.setOnlyAlias(true);

            // 一次性写出内容，使用默认样式，强制输出标题
            writer.write(rows, true);

            //response为HttpServletResponse对象
            response.setContentType("application/vnd.ms-excel;charset=utf-8");
            //test.xls是弹出下载对话框的文件名，不能为中文，中文请自行编码
            response.setHeader("Content-Disposition", "attachment;filename=" + filename + "_ProTenant.xlsx");
            ServletOutputStream out = response.getOutputStream();
            writer.flush(out, true);
            // 关闭writer，释放内存
            writer.close();
            //此处记得关闭输出Servlet流
            IoUtil.close(out);

        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, QUERY_FAIL_MSG + e.getMessage());
        }
    }


    @GetMapping("/exportTemplate")
    @ApiOperation(value = "根据-{{租户表}}-下载导出模板", notes = "成功返回:{\"success\":true,\"message\",\"数据查询成功\",\"data\":\"[]\"},失败返回:{\"success\":false,\"message\",\"数据查询失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = ProTenant.ID_KEY, value = "id", required = true, dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_CODE_KEY, value = "租户代码", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_NAME_KEY, value = "租户名", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.MENOS_KEY, value = "备注", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_ID_KEY, value = "create_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATOR_KEY, value = "创建人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_TIME_KEY, value = "创建时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATER_KEY, value = "更新人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_ID_KEY, value = "update_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_TIME_KEY, value = "更新时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.STATUS_KEY, value = "0正常 9-冻结", required = true, dataTypeClass = String.class)
    })
    @OperateLog(name = "根据-{{租户表}}-下载导出模板", value = "query", type = "PC")
    public void exportTemplateForProTenantForWeb(HttpServletRequest request, HttpServletResponse response, @RequestParam Map<String, Object> map) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            String filename = "租户表";
            InputStream resource = getClass().getClassLoader().getResourceAsStream("excelTemplate/protenant" + "/" + filename + "_ProTenant.xlsx");
            //response为HttpServletResponse对象
            response.setContentType("application/vnd.ms-excel;charset=utf-8");
            //test.xls是弹出下载对话框的文件名，不能为中文，中文请自行编码
            response.setHeader("Content-Disposition", "attachment;filename=" + filename + "_ProTenant.xlsx");
            ServletOutputStream out = response.getOutputStream();
            IoUtil.copy(resource, out);
            //此处记得关闭输出Servlet流
            IoUtil.close(out);
            IoUtil.close(resource);
        } catch (Exception e) {
            result.put(DATASUCCESS, ERRORFLAG);
            result.put(DATAMESSAGE, QUERY_FAIL_MSG + e.getMessage());
        }
    }


    @PostMapping("/importExcel")
    @ApiOperation(value = "根据-{{租户表}}-对象Map批量导入记录", notes = "成功返回:{\"success\":true,\"message\",\"数据更新成功\"},失败返回:{\"success\":false,\"message\",\"数据更新失败\"}")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = ProTenant.ID_KEY, value = "id", required = true, dataTypeClass = int.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_CODE_KEY, value = "租户代码", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.TENANT_NAME_KEY, value = "租户名", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.MENOS_KEY, value = "备注", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_ID_KEY, value = "create_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATOR_KEY, value = "创建人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.CREATE_TIME_KEY, value = "创建时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATER_KEY, value = "更新人", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_ID_KEY, value = "update_id", required = true, dataTypeClass = String.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.UPDATE_TIME_KEY, value = "更新时间", required = true, dataTypeClass = Date.class),
            @ApiImplicitParam(paramType = "body", name = ProTenant.STATUS_KEY, value = "0正常 9-冻结", required = true, dataTypeClass = String.class)
    })
    @OperateLog(name = "根据-{{租户表}}-对象Map批量导入记录", value = "update", type = "PC")
    public Map<String, Object> importExcelForProTenantForWeb(String baseDir, MultipartFile file) {
        Map<String, Object> result = new HashMap<String, Object>();

        if (!file.isEmpty()) {
            try {
                ExcelReader reader = ExcelUtil.getReader(file.getInputStream());

                reader.setHeaderAlias(getVKAliasMap());


                List<Map<String, Object>> list = new ArrayList<>();
                List<Map<String, Object>> read = reader.read(1, 2, Integer.MAX_VALUE);

                for (Map<String, Object> map : read) {


                    if ("".equals(map.get(ProTenant.ID_KEY))) {
                        map.put(ProTenant.ID_KEY, null);
                    }

                    if ("".equals(map.get(ProTenant.TENANT_CODE_KEY))) {
                        map.put(ProTenant.TENANT_CODE_KEY, null);
                    }

                    if ("".equals(map.get(ProTenant.TENANT_NAME_KEY))) {
                        map.put(ProTenant.TENANT_NAME_KEY, null);
                    }

                    if ("".equals(map.get(ProTenant.MENOS_KEY))) {
                        map.put(ProTenant.MENOS_KEY, null);
                    }

                    if ("".equals(map.get(ProTenant.CREATE_ID_KEY))) {
                        map.put(ProTenant.CREATE_ID_KEY, null);
                    }

                    if ("".equals(map.get(ProTenant.CREATOR_KEY))) {
                        map.put(ProTenant.CREATOR_KEY, null);
                    }

                    if ("".equals(map.get(ProTenant.CREATE_TIME_KEY))) {
                        map.put(ProTenant.CREATE_TIME_KEY, null);
                    }

                    if ("".equals(map.get(ProTenant.UPDATER_KEY))) {
                        map.put(ProTenant.UPDATER_KEY, null);
                    }

                    if ("".equals(map.get(ProTenant.UPDATE_ID_KEY))) {
                        map.put(ProTenant.UPDATE_ID_KEY, null);
                    }

                    if ("".equals(map.get(ProTenant.UPDATE_TIME_KEY))) {
                        map.put(ProTenant.UPDATE_TIME_KEY, null);
                    }

                    if ("".equals(map.get(ProTenant.STATUS_KEY))) {
                        map.put(ProTenant.STATUS_KEY, null);
                    }


                    list.add(map);

                }
                proTenantService.insertBatch(list);

                result.put(DATASUCCESS, SUCCESSFLAG);
                result.put(DATAMESSAGE, INSERT_SUCCESS_MSG);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        result.put(DATASUCCESS, ERRORFLAG);
        result.put(DATAMESSAGE, INSERT_FAIL_MSG);
        return result;
    }


    protected void getWriter(ExcelWriter writer, String filename) {
        // 通过工具类创建writer
        //创建xlsx格式的
        writer.setColumnWidth(0, 25);
        writer.setColumnWidth(1, 25);
        writer.setColumnWidth(2, 25);
        writer.setColumnWidth(3, 25);
        writer.setColumnWidth(4, 25);
        writer.setColumnWidth(5, 25);
        writer.setColumnWidth(6, 25);
        writer.setColumnWidth(7, 25);
        writer.setColumnWidth(8, 25);
        writer.setColumnWidth(9, 25);
        writer.setColumnWidth(10, 25);
        // 合并单元格后的标题行，使用默认标题样式
        writer.merge(11, filename);

    }


    protected Map<String, String> getKVAliasMap() {

        Map<String, String> aliasMap = new LinkedHashMap<>();

        aliasMap.put(ProTenant.ID_KEY, "id");
        aliasMap.put(ProTenant.TENANT_CODE_KEY, "租户代码");
        aliasMap.put(ProTenant.TENANT_NAME_KEY, "租户名");
        aliasMap.put(ProTenant.MENOS_KEY, "备注");
        aliasMap.put(ProTenant.CREATE_ID_KEY, "create_id");
        aliasMap.put(ProTenant.CREATOR_KEY, "创建人");
        aliasMap.put(ProTenant.CREATE_TIME_KEY, "创建时间");
        aliasMap.put(ProTenant.UPDATER_KEY, "更新人");
        aliasMap.put(ProTenant.UPDATE_ID_KEY, "update_id");
        aliasMap.put(ProTenant.UPDATE_TIME_KEY, "更新时间");
        aliasMap.put(ProTenant.STATUS_KEY, "0正常 9-冻结");

        return aliasMap;

    }

    protected Map<String, String> getVKAliasMap() {
        Map<String, String> aliasMap = new LinkedHashMap<>();

        aliasMap.put("id", ProTenant.ID_KEY);
        aliasMap.put("租户代码", ProTenant.TENANT_CODE_KEY);
        aliasMap.put("租户名", ProTenant.TENANT_NAME_KEY);
        aliasMap.put("备注", ProTenant.MENOS_KEY);
        aliasMap.put("create_id", ProTenant.CREATE_ID_KEY);
        aliasMap.put("创建人", ProTenant.CREATOR_KEY);
        aliasMap.put("创建时间", ProTenant.CREATE_TIME_KEY);
        aliasMap.put("更新人", ProTenant.UPDATER_KEY);
        aliasMap.put("update_id", ProTenant.UPDATE_ID_KEY);
        aliasMap.put("更新时间", ProTenant.UPDATE_TIME_KEY);
        aliasMap.put("0正常 9-冻结", ProTenant.STATUS_KEY);

        return aliasMap;
    }


}
