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

import cn.com.countrygarden.bi.main.core.Response;
import cn.com.countrygarden.bi.main.model.phoenix.PhoenixSalesRoom;
import cn.com.countrygarden.bi.main.service.phoenix.PhoenixSalesRoomService;
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("datavPhoenixSalesRoomController")
@RequestMapping("/api/phoenix/room")
public class PhoenixSalesRoomController {

    @Autowired
    private PhoenixSalesRoomService service;


    /**
     * 同步
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/sync/batch", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    public Object syncBatch(@RequestParam(name = "projectPage", defaultValue = "1") int projectPage,
                            @RequestParam(name = "projectPageSize", defaultValue = "100") int projectPageSize) {
        service.persistenceBatch(projectPage, projectPageSize);

        return Response.response();
    }

    /**
     * 同步
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/sync/batch/build", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    public Object syncBatchByBuild(@RequestParam(name = "page", defaultValue = "1") int page,
                            @RequestParam(name = "pageSize", defaultValue = "100") int pageSize,
                            @RequestParam(name = "projectPage", defaultValue = "1") int projectPage,
                            @RequestParam(name = "projectPageSize", defaultValue = "100") int projectPageSize) {
        service.persistenceBatchByBuild(pageSize, projectPage, projectPageSize);

        return Response.response();
    }

    /**
     * 同步
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/sync", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    public Object sync(@RequestParam(name = "areaId") String areaId) {
        List<PhoenixSalesRoom> items = service.persistence(areaId);

        return Response.response(items);
    }
}
