package com.ozs.web.controller.home;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ozs.common.annotation.Log;
import com.ozs.common.constant.ModularConstans;
import com.ozs.common.core.controller.BaseController;
import com.ozs.common.core.domain.AjaxResult;
import com.ozs.common.enums.BusinessType;
import com.ozs.common.utils.StringUtils;
import com.ozs.home.domain.HomeNotice;
import com.ozs.home.domain.vo.HomeNoticeVo;
import com.ozs.home.service.HomeNoticeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.ObjectUtils;
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.RestController;

import javax.annotation.Resource;

/**
 * 首页公告控制层
 *
 * @author buzhanyi
 */
@RestController
@RequestMapping("/home/homeNotice")
public class HomeNoticeController extends BaseController {
    
    @Resource
    private  HomeNoticeService homeNoticeService;

    @ApiOperation(value = "查询首页公告")
    @PostMapping("/selectHomeNotice")
//    @PreAuthorize("@ss.hasPermi('home:homeNotice:selecthomeNotice')")
    @Log(title = ModularConstans.notice, businessType = BusinessType.QUERY)
    public AjaxResult selectHomeNotice(@RequestBody HomeNoticeVo homeNoticeVo) {
        LambdaQueryWrapper<HomeNotice> lw = new LambdaQueryWrapper<HomeNotice>();
        if (!StringUtils.isBlank(homeNoticeVo.getNoticeName())) {
            lw.like(HomeNotice::getNoticeName, "%" + homeNoticeVo.getNoticeName() + "%");
        }
        if (!StringUtils.isBlank(homeNoticeVo.getAnnouncementClassification())) {
            lw.eq(HomeNotice::getAnnouncementClassification, homeNoticeVo.getAnnouncementClassification());
        }
        if (!StringUtils.isBlank(homeNoticeVo.getHomepageClassification())) {
            lw.eq(HomeNotice::getHomepageClassification, homeNoticeVo.getHomepageClassification());
        }
        if(!ObjectUtils.isEmpty(homeNoticeVo.getNoticeTime())){
            lw.ge(HomeNotice::getNoticeTime,homeNoticeVo.getNoticeTime());
        }
        if(!ObjectUtils.isEmpty(homeNoticeVo.getNoticeTime())){
            lw.le(HomeNotice::getNoticeTime,homeNoticeVo.getNoticeTime());
        }
        IPage<HomeNotice> page = homeNoticeService.page(new Page<HomeNotice>(homeNoticeVo.getPageNum(), homeNoticeVo.getPageSize()), lw);
        return success(page);
    }
}
