package cn.minestar.agriculture.controller;

import cn.minestar.agriculture.entity.WxMiniAttach;
import cn.minestar.agriculture.service.IWxMiniAttachService;
import cn.minestar.common.annotation.Log;
import cn.minestar.common.core.domain.AjaxResult;
import cn.minestar.common.enums.BusinessType;
import cn.minestar.common.utils.poi.ExcelUtil;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * Controller
 * 
 * @author www.minestar.cn/
 * @date 2021-08-10
 */
@RestController
@RequestMapping("/weixin/api/ma/agriculture/attach")
public class WxMiniAttachController
{
    @Autowired
    private IWxMiniAttachService wxMiniAttachService;

    @PostMapping("upload")
    public AjaxResult upload(@RequestParam("file") MultipartFile file){
        String fileName = "";
        if(null != file){
             fileName =  wxMiniAttachService.upload(file);
        }
        return AjaxResult.success(fileName);
    }

    /**
     * 查询【请填写功能名称】列表
     */
//    @PreAuthorize("@ss.hasPermi('system:attach:list')")
    @GetMapping("/list")
    public AjaxResult list(WxMiniAttach wxMiniAttach)
    {
        List<WxMiniAttach> list = wxMiniAttachService.selectWxMiniAttachList(wxMiniAttach);
        return AjaxResult.success(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
//    @PreAuthorize("@ss.hasPermi('agriculture:attach:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WxMiniAttach wxMiniAttach)
    {
        List<WxMiniAttach> list = wxMiniAttachService.selectWxMiniAttachList(wxMiniAttach);
        ExcelUtil<WxMiniAttach> util = new ExcelUtil<WxMiniAttach>(WxMiniAttach.class);
        return util.exportExcel(list, "attach");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
//    @PreAuthorize("@ss.hasPermi('agriculture:attach:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wxMiniAttachService.selectWxMiniAttachById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('agriculture:attach:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxMiniAttach wxMiniAttach)
    {
        return AjaxResult.success(wxMiniAttachService.insertWxMiniAttach(wxMiniAttach));
    }

    /**
     * 修改【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('agriculture:attach:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxMiniAttach wxMiniAttach)
    {
        return AjaxResult.success(wxMiniAttachService.updateWxMiniAttach(wxMiniAttach));
    }

    /**
     * 删除【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('agriculture:attach:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return AjaxResult.success(wxMiniAttachService.deleteWxMiniAttachByIds(ids));
    }
}
