package com.ssm.controller;


import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.github.pagehelper.PageInfo;
import com.ssm.core.utils.AESUtils;
import com.ssm.core.utils.SnowflakeUtil;
import com.ssm.filter.LoginInterceptor;
import com.ssm.manage.dao.SsmBaseStaffDao;
import com.ssm.manage.dao.StaffTemporaryDao;
import com.ssm.manage.dto.BlackListDto;
import com.ssm.manage.dto.StaffTemporaryDto;
import com.ssm.manage.entity.BlackList;
import com.ssm.manage.entity.RegionThreeLevel;
import com.ssm.manage.entity.StaffTemporary;
import com.ssm.manage.excelEntity.ExcelBlackList;
import com.ssm.manage.excelEntity.ExcelJobContentList;
import com.ssm.manage.mapper.BlackListMapper;
import com.ssm.manage.mapper.RegionListMapper;
import com.ssm.manage.response.*;
import com.ssm.manage.service.BlackListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import tk.mybatis.mapper.entity.Example;

import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.SQLIntegrityConstraintViolationException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * (BlackList)表控制层
 *
 * @author makejava
 * @since 2023-12-20 11:41:44
 */
@RestController
@RequestMapping("/blackList")
@Slf4j
@Api(tags = "临时工")
public class BlackListController {
    /**
     * 服务对象
     */
    @Autowired
    private BlackListService blackListService;
    @Autowired
    private SsmBaseStaffDao ssmBaseStaffDao;
    @Autowired
    private StaffTemporaryDao staffTemporaryDao;
    @Autowired
    private RegionListMapper regionListMapper;
    @Autowired
    private BlackListMapper blackListMapper;


/**
 * 通过主键查询单条数据
 *
 * @param id 主键
 * @return
 @GetMapping("{id}")
 @ApiOperation("通过主键查询单条数据")
 //@RequiresPermissions("system:blackList:query")
 public ResultVo get(@PathVariable Serializable id) {
 return this.blackListService.queryById(id);
 }
 */


    /**
     * 分页查询
     *
     * @param dto
     * @return
     */
//    @GetMapping
    @PostMapping
    @ApiOperation("分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "1", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", defaultValue = "10", required = true)
    })
//@RequiresPermissions("system:blackList:query")
    public PageResponse<BlackListVo> listPage(@RequestBody BlackListDto dto) {
        long start = System.currentTimeMillis();

        PageResponse<BlackListVo> pageResponse = new PageResponse<>();
        PageInfo<BlackListVo> pageInfo = new PageInfo<>();
        try {
            pageInfo = blackListService.selectPage(dto);
        } catch (Exception e) {
            log.error("SsmCollectionTypeController.selectPage", e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }

        // 三级部门
        List<BlackListVo> list = pageInfo.getList();

        if (!CollectionUtils.isEmpty(list)) {
            List<Integer> zhongkongDeptIds = list.stream().map(BlackListVo::getZhongkongDeptId).collect(Collectors.toList());
            Map<Integer, RegionThreeLevel> regionThreeLevelMap = regionListMapper.selectParentByIds(zhongkongDeptIds);

            list.forEach(blackListVo -> {
                // 三级部门以中控的为准
                Integer zhongkongDeptId = blackListVo.getZhongkongDeptId();
                if (zhongkongDeptId != null) {
                    RegionThreeLevel regionThreeLevel = regionThreeLevelMap.get(zhongkongDeptId);
                    String secondDeptName = regionThreeLevel.getSecondDeptName();
                    if (StringUtils.isBlank(secondDeptName)) {  // 二级为空, 说明当前部门只有一级
                        // 将三级提到一级
                        blackListVo.setFirstDeptName(blackListVo.getZhongkongDeptName());
                        // 设置三级为空
                        blackListVo.setZhongkongDeptName("");    // 除了中控部门名称, 其它没有改
                    } else {    // 二级不为空, 说明当前部门有可能有 一二两个级别
                        String firstDeptName = regionThreeLevel.getFirstDeptName();
                        if (StringUtils.isBlank(firstDeptName)) {   // 一级为空, 说明当前部门只有前两级
                            // 将二级提到一级
                            blackListVo.setFirstDeptName(secondDeptName);
                            // 将三级提到二级
                            blackListVo.setSecondDeptName(blackListVo.getZhongkongDeptName());
                            // 设置三级为空
                            blackListVo.setZhongkongDeptName("");
                        } else {    // 一级不为空, 说明当前部门有完整的三个级别
                            // 设置一二级别, 三级本身已经存在, 无需设置
                            blackListVo.setFirstDeptName(firstDeptName);
                            blackListVo.setSecondDeptName(secondDeptName);
                        }
                    }
                }
                //TODO 根据前端传递的结束时间实时判断是否离职，离职时间为空表示在职（zhongkongDimission  isZhongkong）
                if(Objects.nonNull(dto.getLastTime()) && Objects.nonNull(blackListVo.getEndTime()) &&
                        !Objects.nonNull(dto.getStartTime()) && Objects.nonNull(dto.getIsZhongkong())){
                    if(dto.getIsZhongkong() == 1){
                        blackListVo.setZhongkongDimission(1);
                    }else{
                        blackListVo.setZhongkongDimission(0);
                    }
                }
            });
        }


        pageResponse.setPageInfo(pageInfo);
        pageResponse.setCodeAndMsg(ResponseCode.OK);

        log.info("com.ssm.controller.BlackListController.listPage(BlackListDto) - Execution time: {}ms", System.currentTimeMillis() - start);
        return pageResponse;
    }

    /**
     * 分页查询临时工扫码记录
     *
     * @param dto
     * @return
     */
    @GetMapping("/getStaffTemporary")
    @ApiOperation("分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "1", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", defaultValue = "10", required = true)
    })
//@RequiresPermissions("system:blackList:query")
    public PageResponse<StaffTemporary> getStaffTemporary(BlackListDto dto) {
        PageResponse<StaffTemporary> pageResponse = new PageResponse<>();
        PageInfo<StaffTemporary> pageInfo = new PageInfo<>();
        try {
            pageInfo = this.blackListService.getStaffTemporary(dto);
        } catch (Exception e) {
            log.error("SsmCollectionTypeController.selectPage", e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setPageInfo(pageInfo);
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        return pageResponse;
    }

    /**
     * 分页查询临时工考勤记录
     *
     * @param dto
     * @return
     */
//    @GetMapping("/getJonContent")
    @PostMapping("/getJonContent")
    @ApiOperation("分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "1", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", defaultValue = "10", required = true)
    })
//@RequiresPermissions("system:blackList:query")
    public PageResponse<JobContentListVo> getJonContent(@RequestBody BlackListDto dto) {
        PageResponse<JobContentListVo> pageResponse = new PageResponse<>();
        PageInfo<JobContentListVo> pageInfo = new PageInfo<>();
        try {
            pageInfo = this.blackListService.getJonContent(dto);
        } catch (Exception e) {
            log.error("SsmCollectionTypeController.selectPage", e);
            pageResponse.setCodeAndMsg(ResponseCode.FAILED);
            return pageResponse;
        }
        pageResponse.setPageInfo(pageInfo);
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        return pageResponse;
    }

    /**
     * 新增
     *
     * @param blackList
     * @return
     */
//    @PostMapping
//    @ApiOperation("新增")
//@RequiresPermissions("system:blackList:add")
    public GenericResponse add(@RequestBody BlackList blackList) {
        GenericResponse genericResponse = new GenericResponse();
        int i = 0;
        try {
            StaffResponse userInfo = LoginInterceptor.getCurrentUserInfo();
            LoginInterceptor.clearThreadLocal();
            blackList.setInputId(userInfo.getId());
            blackList.setInputName(userInfo.getStaffName());
            blackList.setInputDate(new Date());
            blackList.setId(new SnowflakeUtil(new Random().nextInt(1023)).nextId());

            i = this.blackListService.save(blackList);
            //根据身份证与手机号
            if(blackList.getType()==1) {
                ssmBaseStaffDao.updateStaffState(5,blackList.getIdentityCard(), blackList.getStaffName(), AESUtils.encrypt(blackList.getMobilePhone()), blackList.getStoreId());
            }else {
                ssmBaseStaffDao.updateStaffState(1,blackList.getIdentityCard(), blackList.getStaffName(), AESUtils.encrypt(blackList.getMobilePhone()), blackList.getStoreId());
            }
        } catch (Exception e) {
            if(e instanceof SQLIntegrityConstraintViolationException){
                log.error("SsmCollectionTypeController.add:", e);
                genericResponse.setCodeAndMsg(ResponseCode.MSG,"数据已存在，无需重复添加");
                return genericResponse;
            }
        }
        if (i > 0) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        } else {
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
        }
        return genericResponse;
    }
    /**
     * 编辑
     *
     * @param blackList
     * @return
     */
    @PutMapping("/updateType")
    @ApiOperation("黑名单修改")
//@RequiresPermissions("system:blackList:edit")
    public GenericResponse updateType(@RequestBody BlackList blackList) {
        GenericResponse genericResponse = new GenericResponse();
        int i = 0;
        try {
//            i = this.blackListService.updateNotNull(blackList);
            //TODO 修改了这里
            i = blackListMapper.updateByIdentityCard(blackList.getIdentityCard(),blackList.getType(),blackList.getBlacklistReasons());
            //根据身份证与手机号
            if(blackList.getType()==1) {
                ssmBaseStaffDao.updateStaffState(5,blackList.getIdentityCard(), blackList.getStaffName(), AESUtils.encrypt(blackList.getMobilePhone()), blackList.getStoreId());
            }else {
                ssmBaseStaffDao.updateStaffState(1,blackList.getIdentityCard(), blackList.getStaffName(), AESUtils.encrypt(blackList.getMobilePhone()), blackList.getStoreId());
            }
        } catch (Exception e) {
            log.error("SsmCollectionTypeController.add:", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        } else {
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
        }
        return genericResponse;
    }
    /**
     * 编辑
     *
     * @param blackList
     * @return
     */
    @PutMapping
    @ApiOperation("编辑")
//@RequiresPermissions("system:blackList:edit")
    public GenericResponse edit(@RequestBody BlackList blackList) {
        GenericResponse genericResponse = new GenericResponse();
        int i = 0;
        try {
            i = this.blackListService.updateNotNull(blackList);
        } catch (Exception e) {
            log.error("SsmCollectionTypeController.add:", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        } else {
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
        }
        return genericResponse;
    }

    /**
     * 根据主键删除
     *
     * @param id 主键
     * @return
     */
    @DeleteMapping("{id}")
    @ApiOperation("根据主键删除")
//@RequiresPermissions("system:blackList:delete")
    public GenericResponse delete(@PathVariable Long id) {
        GenericResponse genericResponse = new GenericResponse();
        int i = 0;
        try {
            BlackList blackList = this.blackListService.selectByPrimaryKey(id);
            Example example = new Example(StaffTemporary.class);
            example.createCriteria().andEqualTo(StaffTemporaryDto.Fields.identityCard,blackList.getIdentityCard());
            List<StaffTemporary> staffTemporaryList = staffTemporaryDao.selectByExample(example);
            if (!CollectionUtils.isEmpty(staffTemporaryList)){
                staffTemporaryDao.deleteByExample(example);
            }
            i = this.blackListService.deleteByPrimaryKey(id);
        } catch (Exception e) {
            log.error("SsmCollectionTypeController.add:", e);
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
            return genericResponse;
        }
        if (i > 0) {
            genericResponse.setCodeAndMsg(ResponseCode.OK);
        } else {
            genericResponse.setCodeAndMsg(ResponseCode.FAILED);
        }
        return genericResponse;
    }

    /**
     * 分页查询
     *
     * @param dto
     * @return
     */
    @PostMapping("/export")
    @ApiOperation("分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "1", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", defaultValue = "10", required = true)
    })
//@RequiresPermissions("system:blackList:query")
    public void export(@RequestBody BlackListDto dto) {
        PageInfo<BlackListVo> pageInfo = new PageInfo<>();
        try {
            pageInfo = blackListService.selectPage(dto);
        } catch (Exception e) {
        }
        // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
        // {} 代表普通变量 {.} 代表是list的变量 {前缀.} 前缀可以区分不同的list
        ExcelWriter excelWriter = null;
        OutputStream out = null;
        List<BlackListVo> list = pageInfo.getList();
        //判断离职类型0 - 自离  1 - 辞退  2 - 辞职

//        courseListRequest.setStoreId(SessionHelp.getStoreId(session));
        try {
            String fileName = "projectType";
            HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
            response.setContentType("application/vnd.ms-excel;charset=utf-8");
            response.setHeader("Content-Disposition",
                    "attachment;filename=" + new String(fileName.getBytes("utf-8"), "ISO8859-1") + ".xlsx");
            out = response.getOutputStream();
            InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("config/blackList.xlsx");
            List<ExcelBlackList> excelBaseProjectTypeList = new ArrayList<>();
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

            // 批量查询三级部门, 使用Map加快查询, MapKey为部门ID (如果部门层级发送变动, 需要更改相应的 SQL)
            List<Integer> blackListIds = list.stream().map(BlackListVo::getZhongkongDeptId).collect(Collectors.toList());
            Map<Integer, RegionThreeLevel> regionThreeLevelMap = regionListMapper.selectParentByIds(blackListIds);

            log.debug("Size of blackList:{}", list.size());
            list.forEach(blackListVo -> {
                ExcelBlackList excelBlackList = new ExcelBlackList();
                BeanUtils.copyProperties(blackListVo, excelBlackList);
                /*
                    未完全枚举的状态, 默认值为右值
                 */
                // 性别：男0女1
                Integer sex = blackListVo.getSex();
                excelBlackList.setSex(sex == 1 ? "女" : "男");
                // 黑名单: 是1否0
                Integer type = blackListVo.getType();
                excelBlackList.setType(type == 1 ? "是": "否");
                // 中控推送: 已1未0
                Integer isZhongkong = blackListVo.getIsZhongkong();
                excelBlackList.setIsZhongkong(isZhongkong == 1 ? "已推送" : "未推送");
                // 中控离职: 已1未0
                Integer zhongkongDimission = blackListVo.getZhongkongDimission();
                excelBlackList.setZhongkongDimission(zhongkongDimission == 1 ? "已离职" : "未离职");
                // 判断离职类型0 - 自离  1 - 辞退  2 - 辞职
                Integer leavetype = blackListVo.getLeavetype();
                if(Objects.nonNull(leavetype)){
                 if(leavetype == 0){
                     excelBlackList.setLeavetype("自离");
                 } else if (leavetype == 1) {
                     excelBlackList.setLeavetype("辞退");
                 }else{
                     excelBlackList.setLeavetype("辞职");
                 }
                }
                // 北森暂无需使用
                /*// 北森推送: 已1未0
                Integer isBeisen = blackListVo.getIsBeisen();
                excelBlackList.setIsBeisen(isBeisen == 1 ? "已推送" : "未推送");
                // 北森离职: 已1未0
                Integer beisenDimission = blackListVo.getBeisenDimission();
                excelBlackList.setBeisenDimission(beisenDimission == 1 ? "已离职" : "未离职");*/
                // 入职时间
                excelBlackList.setRuzhiTime(format.format(blackListVo.getRuzhiTime()));
                // 离职时间
                if (Objects.nonNull(blackListVo.getEndTime())) {
                    excelBlackList.setEndTime(format.format(blackListVo.getEndTime()));
                }
                // 服务类型: 日结0月结1, 默认空
                Integer job = blackListVo.getJob();
                if (Objects.nonNull(job)) {
                    excelBlackList.setJobType(job == 0 ? "日结" : job == 1 ? "月结" : "");
                }

                // 三级部门以中控的为准
                Integer zhongkongDeptId = blackListVo.getZhongkongDeptId();
                if (zhongkongDeptId != null) {
                    RegionThreeLevel regionThreeLevel = regionThreeLevelMap.get(zhongkongDeptId);
                    String secondDeptName = regionThreeLevel.getSecondDeptName();
                    if (StringUtils.isBlank(secondDeptName)) {  // 二级为空, 说明当前部门只有一级
                        // 将三级提到一级
                        excelBlackList.setFirstDeptName(excelBlackList.getZhongkongDeptName());
                        // 设置三级为空
                        excelBlackList.setZhongkongDeptName("");    // 除了中控部门名称, 其它没有改
                    } else {    // 二级不为空, 说明当前部门有可能有 一二两个级别
                        String firstDeptName = regionThreeLevel.getFirstDeptName();
                        if (StringUtils.isBlank(firstDeptName)) {   // 一级为空, 说明当前部门只有前两级
                            // 将二级提到一级
                            excelBlackList.setFirstDeptName(secondDeptName);
                            // 将三级提到二级
                            excelBlackList.setSecondDeptName(excelBlackList.getZhongkongDeptName());
                            // 设置三级为空
                            excelBlackList.setZhongkongDeptName("");
                        } else {    // 一级不为空, 说明当前部门有完整的三个级别
                            // 设置一二级别, 三级本身已经存在, 无需设置
                            excelBlackList.setFirstDeptName(firstDeptName);
                            excelBlackList.setSecondDeptName(secondDeptName);
                        }
                    }
                }
                /*
                    NOTE:
                    如果 regionThreeLevel 不是完整的三级结构, excelBlackList.zhongkongDeptName 会被设置为空.
                    但是 excelBlackList 中其它的与中控有关的字段暂未进行设置, 因为在 Excel 中还暂时用不到.
                    如果需要通过 excelBlackList 获取中控信息, 需要注意以上几点!
                */
                excelBaseProjectTypeList.add(excelBlackList);

                log.debug("Added excelBlackList:{}", excelBlackList);
            });

//            WriteCellStyle headWriteCellStyle = new WriteCellStyle();
            // 这里 需要指定写用哪个class去写，然后写到第一个sheet，名字为模板 然后文件流会自动关闭
            //EasyExcel.write(out, LiveRoomData.class).sheet("模板").doWrite(list);
            excelWriter = EasyExcel.write(out).withTemplate(inputStream).build();
            //FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
            WriteSheet writeSheet = EasyExcel.writerSheet().build();
            excelWriter.fill(excelBaseProjectTypeList, writeSheet);
            out.flush();
        } catch (Exception e) {
            log.error("SsmProjectTypeController.export:",e);
        } finally {
            //destFile.delete();
            // 别忘记关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
    }


    /**
     * 分页查询
     *
     * @param dto
     * @return
     */
    @PostMapping("/jobContext/export")
    @ApiOperation("分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "1", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", defaultValue = "10", required = true)
    })
//@RequiresPermissions("system:blackList:query")
    public void jobContextExport(@RequestBody BlackListDto dto) {
        PageInfo<JobContentListVo> pageInfo = new PageInfo<>();
        try {
            pageInfo = this.blackListService.getJonContent(dto);
        } catch (Exception e) {
        }
        // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
        // {} 代表普通变量 {.} 代表是list的变量 {前缀.} 前缀可以区分不同的list
        ExcelWriter excelWriter = null;
        OutputStream out = null;
        List<JobContentListVo> list = pageInfo.getList();
//        courseListRequest.setStoreId(SessionHelp.getStoreId(session));
        try {
            String fileName = "projectType";
            HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
            response.setContentType("application/vnd.ms-excel;charset=utf-8");
            response.setHeader("Content-Disposition",
                    "attachment;filename=" + new String(fileName.getBytes("utf-8"), "ISO8859-1") + ".xlsx");
            out = response.getOutputStream();
            InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("config/jobContentList.xlsx");
            List<ExcelJobContentList> excelBaseProjectTypeList = new ArrayList<>();
//            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            if(list!=null && list.size()>0) {
                for (JobContentListVo jobContentListVo : list) {
                    ExcelJobContentList excelJobContentList = new ExcelJobContentList();
                    BeanUtils.copyProperties(jobContentListVo, excelJobContentList);
                    Date ruzhiTime = jobContentListVo.getRuzhiTime();
                    Date endTime = jobContentListVo.getEndTime();
//                    excelJobContentList.setRuzhiTime(ruzhiTime);
//                    excelJobContentList.setEndTime(endTime);
                    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                    excelJobContentList.setOnDutyTimeStr(ruzhiTime != null ? format.format(ruzhiTime) : "");
                    excelJobContentList.setOffDutyTimeStr(endTime != null ? format.format(endTime) : "");
                    Integer type = jobContentListVo.getType();
                    if (type == 0) {
                        excelJobContentList.setTypeName("日结");
                    } else if (type == 1) {
                        excelJobContentList.setTypeName("月结");
                    }

                    excelBaseProjectTypeList.add(excelJobContentList);
                }
            }
//            WriteCellStyle headWriteCellStyle = new WriteCellStyle();
            // 这里 需要指定写用哪个class去写，然后写到第一个sheet，名字为模板 然后文件流会自动关闭
            //EasyExcel.write(out, LiveRoomData.class).sheet("模板").doWrite(list);
            excelWriter = EasyExcel.write(out).withTemplate(inputStream).build();
            //FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
            WriteSheet writeSheet = EasyExcel.writerSheet().build();
            excelWriter.fill(excelBaseProjectTypeList, writeSheet);
            out.flush();
        } catch (Exception e) {
            log.error("SsmProjectTypeController.export:",e);
        } finally {
            //destFile.delete();
            // 别忘记关闭流
            excelWriter.finish();
        }
    }

}
