package com.ruoyi.web.controller.system;

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

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.domain.entity.ImageDatas;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IImageDataService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 附件信息Controller
 * 
 * @author boman
 * @date 2021-12-24
 */
@RestController
@RequestMapping("/system/image")
public class ImageDataController extends BaseController
{
    @Autowired
    private IImageDataService imageDataService;

    /**
     * 查询附件信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:image:list')")
    @GetMapping("/list")
    public TableDataInfo list(ImageDatas imageDatas)
    {
        startPage();
        List<ImageDatas> list = imageDataService.selectImageDatasList(imageDatas);
        return getDataTable(list);
    }

    /**
     * 导出附件信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:image:export')")
    @Log(title = "附件信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ImageDatas imageDatas)
    {
        List<ImageDatas> list = imageDataService.selectImageDatasList(imageDatas);
        ExcelUtil<ImageDatas> util = new ExcelUtil<ImageDatas>(ImageDatas.class);
        util.exportExcel(response, list, "附件信息数据");
    }

    /**
     * 获取附件信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:image:query')")
    @GetMapping(value = "/{imageId}")
    public AjaxResult getInfo(@PathVariable("imageId") Long imageId)
    {
        return AjaxResult.success(imageDataService.selectImageDataByImageId(imageId));
    }

    /**
     * 新增附件信息
     */
    @PreAuthorize("@ss.hasPermi('system:image:add')")
    @Log(title = "附件信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ImageDatas imageDatas)
    {
        imageDatas.setCreateBy(getUsername());
        return toAjax(imageDataService.insertImageData(imageDatas));
    }

    /**
     * 修改附件信息
     */
    @PreAuthorize("@ss.hasPermi('system:image:edit')")
    @Log(title = "附件信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ImageDatas imageDatas)
    {
        imageDatas.setUpdateBy(getUsername());
        return toAjax(imageDataService.updateImageData(imageDatas));
    }

    /**
     * 删除附件信息
     */
    @PreAuthorize("@ss.hasPermi('system:image:remove')")
    @Log(title = "附件信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{imageIds}")
    public AjaxResult remove(@PathVariable Long[] imageIds)
    {
        return toAjax(imageDataService.deleteImageDataByImageIds(imageIds));
    }
}
