package cn.com.countrygarden.bi.main.controller.phoenix;

import cn.com.countrygarden.bi.main.core.Response;
import cn.com.countrygarden.bi.main.model.PageData;
import cn.com.countrygarden.bi.main.model.phoenix.PhoenixSalesProject;
import cn.com.countrygarden.bi.main.service.phoenix.PhoenixSalesProjectService;
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 java.util.List;

@Controller("datavPhoenixSalesProjectController")
@RequestMapping("/api/phoenix/project")
public class PhoenixSalesProjectController {

    @Autowired
    private PhoenixSalesProjectService projectService;


    /**
     * 同步项目
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/sync", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    public Object sync() {
        List<PhoenixSalesProject> onSaleProjects = projectService.persistence();

        return Response.response(onSaleProjects);
    }

    /**
     * 同步项目
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/search", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    public Object search(@RequestParam(name = "page", defaultValue = "1") int page,
                         @RequestParam(name = "pageSize", defaultValue = "15") int pageSize) {
        PageData pageData = projectService.search(page, pageSize);

        return Response.response(pageData);
    }
}
