JqlController.java 1.68 KB
package com.bsth.controller.oil;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.bsth.controller.BaseController;
import com.bsth.entity.oil.Jql;
import com.bsth.service.oil.JqlService;
import com.google.common.io.Files;

@RestController
@RequestMapping("jql")
public class JqlController extends BaseController<Jql, Integer> {

	@Autowired
	JqlService jqlService;

	public String getDataImportClasspath(){
		return this.getClass().getResource("/").getPath() + "/static/pages/hydrogen/jql";
	}
	
	@RequestMapping(value = "/uploadFile",method = RequestMethod.POST)
	public String uploadFile(MultipartFile file, String gsbm_, String gsName,
											String fgsbm_, String fgsName) throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
        File newFile = new File(
        		getDataImportClasspath() + File.separator +
                        file.getOriginalFilename());
        Files.write(file.getBytes(), newFile);
		String result = jqlService.importExcel(newFile, gsbm_, gsName, fgsbm_, fgsName);
		return "{\"result\":" + "\""+result+"\"}";
	}
	
	@RequestMapping(value = "/query",method = RequestMethod.GET)
	public Map<String, Object> query(@RequestParam Map<String, Object> map) throws Exception{
		return jqlService.query(map);
	}
	
}