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.PhoenixSalesBuild;
import cn.com.countrygarden.bi.main.service.phoenix.PhoenixSalesBuildService;
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("datavPhoenixSalesBuildController")
@RequestMapping("/api/phoenix/build")
public class PhoenixSalesBuildController {

    @Autowired
    private PhoenixSalesBuildService service;


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

        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<PhoenixSalesBuild> items = service.persistence(areaId);

        return Response.response(items);
    }

    @ResponseBody
    @RequestMapping(value = "/search", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    public Object search(@RequestParam(name = "areaId", defaultValue = "") String areaId,
                         @RequestParam(name = "page", defaultValue = "1") int page,
                         @RequestParam(name = "pageSize", defaultValue = "15") int pageSize) {
        PageData pageData = service.search(areaId, page, pageSize);

        return Response.response(pageData);
    }
}
