XlybtzController.java 2 KB
package com.bsth.controller.report;


import com.bsth.service.report.XlybtzService;
import com.google.common.io.Files;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.util.*;

@RestController
@RequestMapping("xlybtz")
public class XlybtzController {

    @Autowired
    XlybtzService xlybtzService;

    public String getDataImportClasspath(){
        return this.getClass().getResource("/").getPath() + "/static/pages/electricity/jdl";
    }
    @RequestMapping(value = "/uploadFile",method = RequestMethod.POST)
    public String uploadFile(MultipartFile file,@RequestParam int reportType,@RequestParam String date) throws Exception{
        File newFile = new File(getDataImportClasspath() + File.separator + file.getOriginalFilename());
        Files.write(file.getBytes(), newFile);
        String type=null;
        String result=null;
        if(reportType==1){
            type="票务";
            result = xlybtzService.imporPWExcel(newFile,date);
        }else if(reportType==2){
            type="二维码";
            result = xlybtzService.importQRCordExcel(newFile,date);
        }
        else if(reportType==3){
            type="申城通";
            result = xlybtzService.importCardExcel(newFile,date,type);
        }
        else if(reportType==4){
            type="实体卡";
            result = xlybtzService.importCardExcel(newFile,date,type);
        }
        else if(reportType==5){
            type="保通卡";
            result = xlybtzService.importCardExcel(newFile,date,type);
        }
        else{
            result="请选择导入类型";
        }

        return "{\"result\":" + "\""+result+"\"}";
    }

    @RequestMapping(value = "/query",method = RequestMethod.GET)
    public Map<String, Object> query(@RequestParam Map<String, Object> map) throws Exception{
        Map<String, Object> m= xlybtzService.query(map);
        return m;
    }

}