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

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

    @Autowired
    private PhoenixSalesOnSalesRoomService service;


    /**
     * 同步
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/sync/batch", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    public Object syncBatch(@RequestParam(name = "start") String start,
                            @RequestParam(name = "end") String end,
                            @RequestParam(name = "page", defaultValue = "1") int page,
                            @RequestParam(name = "pageSize", defaultValue = "10000") int pageSize,
                            @RequestParam(name = "projectPage", defaultValue = "1") int projectPage,
                            @RequestParam(name = "projectPageSize", defaultValue = "15") int projectPageSize) {
        service.persistenceBatch(start, end, page, 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,
                       @RequestParam(name = "start") String start,
                       @RequestParam(name = "end") String end,
                       @RequestParam(name = "page", defaultValue = "1") int page,
                       @RequestParam(name = "pageSize", defaultValue = "15") int pageSize) {
        List<PhoenixSalesOnSaleRoom> items = service.persistence(areaId, start, end, page, pageSize);

        return Response.response(items);
    }
}
