package com.xinelu.manage.controller.information;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.custominterface.Insert;
import com.xinelu.common.custominterface.Update;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.information.Information;
import com.xinelu.manage.service.information.IInformationService;
import com.xinelu.manage.vo.information.InformationVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 资讯信息管理Controller
 *
 * @author xinyilu
 * @date 2023-02-14
 */
@RestController
@RequestMapping("/system/informationInfo")
public class InformationController extends BaseController {
    @Resource
    private IInformationService informationService;

    /**
     * 查询资讯信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:informationInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(Information information) {
        startPage();
        List<InformationVO> list = informationService.selectInformationList(information);
        return getDataTable(list);
    }

    /**
     * 导出资讯信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:informationInfo:export')")
    @Log(title = "资讯信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Information information) {
        List<InformationVO> list = informationService.selectInformationList(information);
        ExcelUtil<InformationVO> util = new ExcelUtil<>(InformationVO.class);
        util.exportExcel(response, list, "资讯信息管理数据");
    }

    /**
     * 获取资讯信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:informationInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(informationService.selectInformationById(id));
    }

    /**
     * 新增资讯信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:informationInfo:add')")
    @Log(title = "资讯信息管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody @Validated(Insert.class) Information information) {
        return toAjax(informationService.insertInformation(information));
    }

    /**
     * 修改资讯信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:informationInfo:edit')")
    @Log(title = "资讯信息管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody @Validated(Update.class) Information information) {
        return informationService.updateInformation(information);
    }

    /**
     * 删除资讯信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:informationInfo:remove')")
    @Log(title = "资讯信息管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return informationService.deleteInformationByIds(ids);
    }
}
