package com.yunfeiyun.agmp.fms.controller;

import com.yunfeiyun.agmp.common.annotation.Log;
import com.yunfeiyun.agmp.common.core.controller.BaseController;
import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
import com.yunfeiyun.agmp.common.enums.BusinessType;
import com.yunfeiyun.agmp.common.utils.poi.ExcelUtil;
import com.yunfeiyun.agmp.fms.domain.FmsSolar;
import com.yunfeiyun.agmp.fms.service.IFmsSolarService;
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.List;

/**
 * 节气时令Controller
 * 
 * @author 杨晓辉
 * @date 2023-06-01
 */
@RestController
@RequestMapping("/fms/solar")
public class FmsSolarController extends BaseController
{



    @Autowired
    private IFmsSolarService fmsSolarService;

    /**
     * 查询节气时令列表
     */
    @PreAuthorize("@ss.hasPermi('fms:solar:list')")
    @GetMapping("/list")
    public TableDataInfo list(FmsSolar fmsSolar)
    {
        startPage();
        List<FmsSolar> list = fmsSolarService.selectFmsSolarList(fmsSolar);
        return getDataTable(list);
    }

    /**
     * 导出节气时令列表
     */
    @PreAuthorize("@ss.hasPermi('fms:solar:export')")
    @Log(title = "节气时令", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmsSolar fmsSolar)
    {
        List<FmsSolar> list = fmsSolarService.selectFmsSolarList(fmsSolar);
        ExcelUtil<FmsSolar> util = new ExcelUtil<FmsSolar>(FmsSolar.class);
        util.exportExcel(response, list, "节气时令数据");
    }

    /**
     * 获取节气时令详细信息
     */
    @PreAuthorize("@ss.hasPermi('fms:solar:info')")
    @GetMapping(value = "/info")
    public AjaxResult getInfo(@RequestParam("solarId") String solarId)
    {
        return success(fmsSolarService.selectFmsSolarBySolarId(solarId));
    }

    /**
     * 获取节气时令详细信息
     */
    @PreAuthorize("@ss.hasPermi('fms:solar:byname:info')")
    @GetMapping(value = "/byname/info")
    public AjaxResult getInfoByName(@RequestParam("solarName") String solarName)
    {
        return success(fmsSolarService.selectFmsSolarBySolarName(solarName));
    }

    /**
     * 新增节气时令
     */
    @PreAuthorize("@ss.hasPermi('fms:solar:add')")
    @Log(title = "节气时令", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FmsSolar fmsSolar)
    {
        return toAjax(fmsSolarService.insertFmsSolar(fmsSolar));
    }

    /**
     * 修改节气时令
     */
    @PreAuthorize("@ss.hasPermi('fms:solar:edit')")
    @Log(title = "节气时令", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody FmsSolar fmsSolar)
    {
        return toAjax(fmsSolarService.updateFmsSolar(fmsSolar));
    }

    /**
     * 删除节气时令
     */
    @PreAuthorize("@ss.hasPermi('fms:solar:delete')")
    @Log(title = "节气时令", businessType = BusinessType.DELETE)
	@DeleteMapping("/delete/{solarIds}")
    public AjaxResult remove(@PathVariable String[] solarIds)
    {
        return toAjax(fmsSolarService.deleteFmsSolarBySolarIds(solarIds));
    }

    @PreAuthorize("@ss.hasPermi('fms:solar:update')")
    @PostMapping("/date/update")
    public AjaxResult dateUpdate() throws Exception{
        return toAjax(fmsSolarService.updateFmsSolarAll());
    }
}
