package cn.tsy.idsse.dsds.control.sample;

import java.io.File;
import java.util.List;

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

import cn.hme.framework.helper.file.FileHelper;
import cn.hme.framework.web.control.Ajax;
import cn.hme.framework.web.control.AjaxControl;
import cn.tsy.data.idsse.dsds.model.sample.SampleLineTrack;
import cn.tsy.idsse.dsds.service.sample.SampleLineTrackService;

@RestController
@RequestMapping("sample/line/track")
@CrossOrigin
public class SampleLineTrackControl extends AjaxControl {


	@Autowired
	private SampleLineTrackService sTrack;



	@CrossOrigin
	@RequestMapping("upload.htm")
	public Ajax upload(int dataset_id, MultipartFile file) {
		// DSDSWebHelper.getFrameOptr(true);
		File f = FileHelper.fromUpload(file);
		List<String> array = FileHelper.readFileAsArray(f);
		f.delete();
		List<SampleLineTrack> list = this.sTrack.uploadTrack(dataset_id, array,file.getOriginalFilename());
//		if (list.size() == 0)
//			throw new BusinessException("未找到有效的轨迹文件(已忽略相同的记录)！");
		return new Ajax(file.getOriginalFilename());
	}

	

}
