package com.td.Dawa.game.comsetting.controller;

import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.td.Dawa.common.pojo.Result;
import com.td.Dawa.game.excelcharacterattri.vo.ExcelCharacterAttriSimpleVo;
import com.td.Dawa.game.excelcharacterattri.vo.ExcelCharacterAttriVo;
import com.td.Dawa.game.excelcharactercolor.service.ExcelCharacterColorService;
import com.td.Dawa.game.excelcharactercolor.vo.ExcelCharacterColorSimpleVo;
import com.td.Dawa.game.excelcharactercolor.vo.ExcelCharacterColorVo;
import com.td.Dawa.game.excelcharactercreate.service.ExcelCharacterCreateService;
import com.td.Dawa.game.excelcharactercreate.vo.ExcelCharacterCreateSimpleVo;
import com.td.Dawa.game.excelcharactercreate.vo.ExcelCharacterCreateVo;
import com.td.Dawa.game.excelcharacterlevel.service.ExcelCharacterLevelService;
import com.td.Dawa.game.excelcharacterlevel.vo.ExcelCharacterLevelSimpleVo;
import com.td.Dawa.game.excelcharacterlevel.vo.ExcelCharacterLevelVo;
import com.td.Dawa.game.exceldrop.service.ExcelDropService;
import com.td.Dawa.game.exceldrop.vo.ExcelDropVo;
import com.td.Dawa.game.excelparameter.service.ExcelParameterService;
import com.td.Dawa.game.excelparameter.vo.ExcelParameterSimpleVo;
import com.td.Dawa.game.excelparameter.vo.ExcelParameterVo;
import com.td.Dawa.game.excelprop.service.ExcelPropService;
import com.td.Dawa.game.excelprop.vo.ExcelPropSimpleVo;
import com.td.Dawa.game.excelprop.vo.ExcelPropVo;
import com.td.Dawa.game.excelresources.service.ExcelResourcesService;
import com.td.Dawa.game.excelresources.vo.ExcelResourcesSimpleVo;
import com.td.Dawa.game.excelresources.vo.ExcelResourcesVo;
import com.td.Dawa.game.excelscene.service.ExcelSceneService;
import com.td.Dawa.game.excelscene.vo.ExcelSceneSimpleVo;
import com.td.Dawa.game.excelscene.vo.ExcelSceneVo;
import com.td.Dawa.game.excelworkpro.service.ExcelWorkProService;
import com.td.Dawa.game.excelworkpro.vo.ExcelWorkProSimpleVo;
import com.td.Dawa.game.excelworkpro.vo.ExcelWorkProVo;
import com.td.Dawa.util.CopyUtil;
import com.td.Dawa.util.ExcelDataUtil;
import com.td.Dawa.game.excelcharacterattri.service.ExcelCharacterAttriService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.List;

@RestController
@RequestMapping("/game/comSetting/")
@Slf4j
public class ComSettingController{

    @Autowired
    private ExcelCharacterLevelService excelCharacterLevelService;

    @Autowired
    private ExcelCharacterCreateService excelCharacterCreateService;

    @Autowired
    private ExcelCharacterAttriService excelCharacterAttriService;

    @Autowired
    private ExcelCharacterColorService excelCharacterColorService;

    @Autowired
    private ExcelSceneService excelSceneService;

    @Autowired
    private ExcelPropService excelPropService;

    @Autowired
    private ExcelResourcesService excelResourcesService;

    @Autowired
    private ExcelDropService excelDropService;

    @Autowired
    private ExcelParameterService excelParameterService;

    @Autowired
    private ExcelWorkProService excelWorkProService;


    @ResponseBody
    @RequestMapping(value = "/excelImport")
    public Result<?> importExcel(@RequestParam("file") MultipartFile file) {
        int count = 0;
        if (file.isEmpty()) {
            System.out.println("文件为空！");
            Result.of(count);
        }
        // 获取上传文件输入流
        InputStream inputStream = null;
        try {
            inputStream = file.getInputStream();
        } catch (Exception e) {
            //return ResponseData.fail(ResponseCodeEnum.ERROR_PARAM_INVALID);
            e.printStackTrace();
        }
        log.info("file.getName():" + file.getOriginalFilename());
        ExcelReader excelReader = ExcelUtil.getReader(inputStream);
        //暂时按照名字区分

        switch (file.getOriginalFilename().replace(".xlsx", "")) {
            case "UI界面":

                return null;
            case "帮助":

                return null;
            case "参数":
                List<ExcelParameterVo> voList = ExcelDataUtil.setParameter(excelReader);
                for (ExcelParameterVo objects : voList) {
                    excelParameterService.save(objects);
                }
                return Result.of(CopyUtil.copyList(voList, ExcelParameterSimpleVo.class));
            case "产出表":

                return null;
            case "场景":
                List<ExcelSceneVo> excelSceneVoList = ExcelDataUtil.setScene(excelReader);
                for (ExcelSceneVo objects : excelSceneVoList) {
                    excelSceneService.save(objects);
                }
                return Result.of(CopyUtil.copyList(excelSceneVoList, ExcelSceneSimpleVo.class));
            case "道具":
                List<ExcelPropVo> excelPropVoList = ExcelDataUtil.setProp(excelReader);
                for (ExcelPropVo objects : excelPropVoList) {
                    excelPropService.save(objects);
                }
                return Result.of(CopyUtil.copyList(excelPropVoList, ExcelPropSimpleVo.class));
            case "掉落":
                List<ExcelDropVo> excelDropVoList = ExcelDataUtil.setDrop(excelReader);
                for (ExcelDropVo objects : excelDropVoList) {
                    excelDropService.save(objects);
                }
                return Result.of(CopyUtil.copyList(excelDropVoList, ExcelPropSimpleVo.class));
            case "多语言":

                return null;
            case "工作效率对应":
                List<ExcelWorkProVo> excelWorkPros = ExcelDataUtil.setWorkPro(excelReader);
                for (ExcelWorkProVo objects : excelWorkPros) {
                    excelWorkProService.save(objects);
                }
                return Result.of(CopyUtil.copyList(excelWorkPros, ExcelWorkProSimpleVo.class));
            case "挂机收益":

                return null;
            case "互动事件":

                return null;
            case "技能":

                return null;
            case "建筑升级":

                return null;
            case "角色等级":
                List<ExcelCharacterLevelVo> characterLevelVoList = ExcelDataUtil.setCharacterLevel(excelReader);
                for (ExcelCharacterLevelVo objects : characterLevelVoList) {
                    excelCharacterLevelService.save(objects);
                }
                return Result.of(CopyUtil.copyList(characterLevelVoList, ExcelCharacterLevelSimpleVo.class));
            case "角色生成":
                List<ExcelCharacterCreateVo> characterCreateReaderList = ExcelDataUtil.setCharacterCreate(excelReader);
                for (ExcelCharacterCreateVo objects : characterCreateReaderList) {
                    excelCharacterCreateService.save(objects);
                }
                return Result.of(CopyUtil.copyList(characterCreateReaderList, ExcelCharacterCreateSimpleVo.class));
            case "角色属性":
                List<ExcelCharacterAttriVo> characterReaderList = ExcelDataUtil.setCharacterAttributes(excelReader);
                for (ExcelCharacterAttriVo objects : characterReaderList) {
                    excelCharacterAttriService.save(objects);
                }
                return Result.of(CopyUtil.copyList(characterReaderList, ExcelCharacterAttriSimpleVo.class));
            case "角色颜色":
                List<ExcelCharacterColorVo> characterColorVoList = ExcelDataUtil.setCharacterColor(excelReader);
                for (ExcelCharacterColorVo objects : characterColorVoList) {
                    excelCharacterColorService.save(objects);
                }
                return Result.of(CopyUtil.copyList(characterColorVoList, ExcelCharacterColorSimpleVo.class));
            case "角色刷新":

                return null;
            case "路径":

                return null;
            case "模型":

                return null;
            case "文字":

                return null;
            case "引导":

                return null;
            case "资源":
                List<ExcelResourcesVo> resourcesVos = ExcelDataUtil.setResource(excelReader);
                for (ExcelResourcesVo objects : resourcesVos) {
                    excelResourcesService.save(objects);
                }
                return Result.of(CopyUtil.copyList(resourcesVos, ExcelResourcesSimpleVo.class));

        }
        return Result.of(null);
    }

}
