package com.iformall.controller;

import com.iformall.common.Result;
import com.iformall.common.ResultData;
import com.iformall.domain.po.WxActivity;
import com.iformall.service.WxActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * @author gongbiao
 */
@RestController
@RequestMapping("/api/wxActivity")
@Api(description = "活动")
public class WxActivityController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private WxActivityService wxActivityService;


    @ApiOperation("查询活动状态")
    @GetMapping("/queryStatus")
    @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
    public ResultData queryStatus(Long id) {
        return new ResultData(wxActivityService.queryStatus(id, getUserId()));
    }

    @ApiOperation("根据id查询接口")
    @GetMapping("/findById")
    @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
    public ResultData findById(Long id) {
        WxActivity wxActivity = wxActivityService.getById(id);
        Integer status = wxActivityService.queryStatus(id, getUserId());
        Map<String, Object> data = new HashMap<>();
        data.put("activity", wxActivity);
        data.put("status", status);
        return new ResultData(Result.SUCCESS, "查询成功", data);
    }

    @ApiOperation("输出富文本内容")
    @GetMapping("/printHtmlById")
    @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
    public void printHtmlById(Long id, HttpServletResponse response) {
        wxActivityService.printHtmlById(id, response);
    }


}
