SampleController.java 1.48 KB
package com.bsth.controller.forecast;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bsth.common.ResponseCode;
import com.bsth.controller.BaseController;
import com.bsth.controller.forecast.dto.CreateSampleParam;
import com.bsth.entity.forecast.Sample;
import com.bsth.service.forecast.SampleService;

@RestController
@RequestMapping("sample")
public class SampleController extends BaseController<Sample, Long>{

	@Autowired
	SampleService sampleService;
	
	Logger loger = LoggerFactory.getLogger(this.getClass());
	
	@RequestMapping("/create/gps")
	public Map<String, Object> createDataByGps(@RequestParam String data){
		Map<String, Object> rs = new HashMap<>();
		try {
			data = URLDecoder.decode(data, "utf-8");
			CreateSampleParam param = JSONObject.toJavaObject(JSON.parseObject(data), CreateSampleParam.class);
			
			rs = sampleService.createDataByGps(param);
		} catch (UnsupportedEncodingException e) {
			loger.info("", e);
			rs.put("status", ResponseCode.ERROR);
		}
		return rs;
	}
}