package com.gic.haoban.manage.web.controller.data;

import com.alibaba.fastjson.JSONObject;
import com.gic.commons.util.DataApiUtils;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.haoban.manage.web.qo.canvas.CanvasConversionDataQO;
import com.gic.haoban.manage.web.vo.canvas.CanvasConversionDataVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 画布数据
 */
@Slf4j
@RestController
@RequestMapping("/canvas-data")
public class CanvasDataController {

    /**
     * 活动转化数据
     * @param qo
     * @return
     */
    @RequestMapping("get-canvas-conversion-data")
    public RestResponse<CanvasConversionDataVO> getCanvasConversionData(@RequestBody CanvasConversionDataQO qo) {
        JSONObject jsonObject = (JSONObject) JSONObject.toJSON(qo);
        jsonObject.put("pageNum", 1);
        jsonObject.put("pageSize", 10);
        Map<String, Object> res = DataApiUtils.http(jsonObject.toJSONString(), "data_mkt_canvas_haoban_list");
        List<CanvasConversionDataVO> list = DataApiUtils.parsePageDataList(res, CanvasConversionDataVO.class);
        return RestResponse.successResult(list.size() > 0 ? list.get(0) : new CanvasConversionDataVO());
    }

}
