package com.ruoyi.web.controller.api;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.ApiResult;
import com.ruoyi.mall.domain.BusinessBulletin;
import com.ruoyi.mall.domain.OfflineServices;
import com.ruoyi.mall.domain.OfflineServicesRegister;
import com.ruoyi.mall.domain.Vo.BusinessBulletinResponse;
import com.ruoyi.mall.domain.Vo.BusinessBulletinVo;
import com.ruoyi.mall.domain.Vo.OfflineServicesRegisterVo;
import com.ruoyi.mall.domain.Vo.OfflineServicesVo;
import com.ruoyi.mall.service.IBusinessBulletinService;
import com.ruoyi.mall.service.IOfflineServicesRegisterService;
import com.ruoyi.mall.service.IOfflineServicesService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

/**公告
 **/
@RestController
@RequestMapping("/api/Bulletin")
public class ApiBulletinController extends BaseController {

    @Resource
    private IBusinessBulletinService businessBulletinService;
    /**
     * 公告列表
     */
    @GetMapping("/getBulletinList")
    public AjaxResult getBulletinList(@RequestParam(defaultValue = "1") Integer pageNum,
                                            @RequestParam(defaultValue = "10") Integer pageSize) {
        try{
            PageHelper.startPage(pageNum, pageSize);
            BusinessBulletin businessBulletin = new BusinessBulletin();
            List<BusinessBulletinResponse> list = businessBulletinService.getHotList(businessBulletin);
            PageInfo<BusinessBulletinResponse> pageInfo = new PageInfo<>(list);
            return AjaxResult.success().put("data",pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("公告列表查询异常");
        }
    }

    /**公告详情
     *
     * @param bulletinId
     * @return
     */
    @GetMapping("/getBulletinDetail")
    public AjaxResult getOfflineServiceDetail(Long bulletinId) {
        try{


            //获取线下服务详情
            BusinessBulletin businessBulletin = businessBulletinService.selectBusinessBulletinByBulletinId(bulletinId);
            // 公告浏览量+1
            BusinessBulletin update = new BusinessBulletin();
            update.setBulletinId(businessBulletin.getBulletinId());
            update.setHot(businessBulletin.getHot()+1);
            businessBulletinService.updateBusinessBulletin(update);
            return AjaxResult.success().put("data",businessBulletin);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("获取公告详情异常");
        }

    }



}
