package com.yihu.hos.rest.controllers;

import com.yihu.hos.rest.services.crawler.DatacollectService;
import com.yihu.hos.web.framework.model.Result;
import com.yihu.hos.web.framework.util.controller.BaseController;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
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.ResponseBody;

import javax.annotation.Resource;
import javax.annotation.Resources;

/**
 * 数据采集配置页面
 * Created by hzp on 2015/8/12.
 */
@RequestMapping("/crawler")
@Controller("dataCollectController")
public class DataCollectController extends BaseController {

    @Resource(name = "DatacollectService")
    DatacollectService datacollectService;

    @RequestMapping(value = "collect", method = RequestMethod.POST)
    @ApiOperation(value = "采集医院数据", produces = "application/json", notes = "采集医院数据")
    @ResponseBody
    public Result collect(
            @ApiParam(name = "jobId", value = "任务jobId", required = true)
            @RequestParam(value = "jobId") String jobId) {
        try {
            if (datacollectService.collectByJobId(jobId)) {
                return Result.success("采集成功");
            } else {
                return Result.error("采集失败");
            }
        } catch (Exception e) {
            return Result.error("采集失败");
        }
    }
}
