package com.pcloud.book.advertising.service.impl;

import com.pcloud.book.advertising.biz.AdvertisingSpaceBiz;
import com.pcloud.book.advertising.biz.GroupMasterTagBiz;
import com.pcloud.book.advertising.service.AdvertisingSpaceService;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.utils.ResponseHandleUtil;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
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.RestController;

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

import io.swagger.annotations.ApiOperation;

/**
 * Description 广告位内部接口实现类
 * Created by PENG on 2019/5/6.
 */
@RestController("advertisingSpaceService")
@RequestMapping("advertisingSpaceService")
public class AdvertisingSpaceServiceImpl implements AdvertisingSpaceService {

    private static final Logger LOGGER = LoggerFactory.getLogger(AdvertisingSpaceServiceImpl.class);

    @Autowired
    private AdvertisingSpaceBiz advertisingSpaceBiz;
    @Autowired
    private GroupMasterTagBiz groupMasterTagBiz;

    /**
     * 每日凌晨计算昨日广告位收益
     */
    @Override
    @RequestMapping(value = "calculateAdvertisingIncomeYesterday", method = RequestMethod.GET)
    public void calculateAdvertisingIncomeYesterday() throws BizException {
        advertisingSpaceBiz.calculateAdvertisingIncomeYesterday();
    }

    @ApiOperation("发送广告计划")
    @PostMapping("sendAdvertisingPlan")
    @Override
    public void sendAdvertisingPlan(@RequestBody Map<String, Object> map) throws BizException {
        LOGGER.info("内部接口群发广告被调用"+map.toString());
        advertisingSpaceBiz.sendAdvertisingPlan(new Long(map.get("advertisingPutId").toString()));
    }

    @Override
    @GetMapping("getTagWxGroupIdsByUserId")
    @ParamLog("根据登录用户获取标记的微信群列表")
    public ResponseEntity<ResponseDto<List<String>>> getTagWxGroupIdsByUserId(@RequestParam("userId") Long userId) {
        List<String> list = groupMasterTagBiz.getTagWxGroupIdsByUserId(userId);
        return ResponseHandleUtil.toResponse(list);
    }
}
