package com.jpsoft.shinestar.modules.mobile.controller;

import com.jpsoft.shinestar.modules.base.entity.MobileBannerInfo;
import com.jpsoft.shinestar.modules.base.service.MobileBannerInfoService;
import com.jpsoft.shinestar.modules.common.dto.MessageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/mobile/bannerInfo")
@Api(description = "移动端广告栏接口")
public class BannerInfoApiController {

    @Autowired
    private MobileBannerInfoService mobileBannerInfoService;

    @PostMapping("getBannerInfo")
    @ApiOperation(value = "获取移动端广告栏")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "1 园区 ，2 小区 , 3 养老院", required = true, paramType = "form"),
            @ApiImplicitParam(name = "token", value = "令牌", required = true, paramType = "form"),
            @ApiImplicitParam(name = "subject", value = "目标(不传)", paramType = "form")
    })
    public MessageResult<List> getBannerInfo(String type, String token, @RequestAttribute String subject) {

        MessageResult<List> messageResult = new MessageResult<>();
        //    Map<String, Object> map = new HashMap<>();

        try {
            List<MobileBannerInfo> list = mobileBannerInfoService.getBannerInfo(type);

            //         map.put("list",list);
            messageResult.setData(list);
            messageResult.setCode(200);
            messageResult.setMessage("查询成功");
            messageResult.setResult(true);

        } catch (Exception ex) {
            messageResult.setCode(400);
            messageResult.setMessage(ex.getMessage());
            messageResult.setResult(false);
        }

        return messageResult;
    }

}
