package com.ruoyi.web.controller.system;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.LcdInfo;
import com.ruoyi.system.domain.vo.LcdInfoVo;
import com.ruoyi.system.service.ILcdInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 消息Controller
 *
 * @author ruoyi
 * @date 2023-01-14
 */
@Api(tags = "LcdInfoController",description = "消息")
@RestController
@RequestMapping("/system/infos")
public class LcdInfoController extends BaseController
{
    @Autowired
    private ILcdInfoService lcdInfoService;

    /**
     * 查询消息列表
     */
    @ApiOperation("查询消息列表")
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(LcdInfo lcdInfo)
    {
        startPage();
        List<LcdInfo> list = lcdInfoService.selectLcdInfoList(lcdInfo);
        return getDataTable(list);
    }

    /**
     * 导出消息列表
     */
    @ApiOperation("导出消息列表")
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "消息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LcdInfo lcdInfo)
    {
        List<LcdInfo> list = lcdInfoService.selectLcdInfoList(lcdInfo);
        ExcelUtil<LcdInfo> util = new ExcelUtil<LcdInfo>(LcdInfo.class);
        util.exportExcel(response, list, "消息数据");
    }


    /**
     * 获取消息详细信息
     */
    @ApiOperation("获取消息详细信息")
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(lcdInfoService.selectLcdInfoById(id));
    }

    /**
     * 新增消息
     */
    @ApiOperation("新增消息")
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "消息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LcdInfoVo lcdInfoVo)
    {
        lcdInfoVo.setCreateBy(getUsername());
        lcdInfoVo.setCreateTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getTime()));
        lcdInfoVo.setUpdateBy(getUsername());
        lcdInfoVo.setUpdateTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getTime()));
        return lcdInfoService.insertLcdInfo(lcdInfoVo);
    }

    /**
     * 修改消息
     */
    @ApiOperation("修改消息")
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "消息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LcdInfo lcdInfo)
    {
        return toAjax(lcdInfoService.updateLcdInfo(lcdInfo));
    }

    /**
     * 删除消息
     */
    @ApiOperation("删除消息")
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "消息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long ids)
    {
        return toAjax(lcdInfoService.deleteLcdInfoById(ids));
    }
    /**
     * 搜索消息列表.
     * @param title
     * @param lcdTimeLeft
     * @param lcdTimeRight
     * @return
     */
    @ApiOperation("搜索消息列表")
    @PreAuthorize("@ss.hasPermi('system:lcd:querylcd')")
    @GetMapping("/queryLcd")
    public AjaxResult list(@RequestParam(value="title",required = false)String title,
                              @RequestParam(value="lcdTimeLeft",required = false) Date lcdTimeLeft,
                              @RequestParam(value="lcdTimeRight",required = false) Date lcdTimeRight)
    {
        List<LcdInfo> list= lcdInfoService.selectList(title,lcdTimeLeft,lcdTimeRight);
        return success(list);
    }
}
