package com.ruoyi.project.production.controller;

import java.util.List;

import com.ruoyi.project.production.controller.vo.MonthlyUpdateVO;
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.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.production.domain.TMonthlyProductionPrice;
import com.ruoyi.project.production.service.ITMonthlyProductionPriceService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 生产月报单价维护Controller
 *
 * @author ruoyi
 * @date 2022-11-18
 */
@RestController
@RequestMapping("/production/price")
public class TMonthlyProductionPriceController extends BaseController
{
    @Autowired
    private ITMonthlyProductionPriceService tMonthlyProductionPriceService;

    /**
     * 修改单价列表
     */
    @PreAuthorize("@ss.hasPermi('production:price:edit')")
    @PutMapping(value = "/updatePriceList")
    public AjaxResult updatePriceList(@RequestBody MonthlyUpdateVO monthlyUpdateVO)
    {
        return toAjax(tMonthlyProductionPriceService.updatePriceList(monthlyUpdateVO));
    }

    /**
     * 按年份查询单价
     */
    @PreAuthorize("@ss.hasPermi('production:price:query')")
    @GetMapping(value = "/getByYear/{year}")
    public AjaxResult getPriceByYear(@PathVariable("year") Long year)
    {
        return AjaxResult.success(tMonthlyProductionPriceService.selectPriceByYear(year));
    }

    /**
     * 查询生产月报单价维护列表
     */
    @PreAuthorize("@ss.hasPermi('production:price:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMonthlyProductionPrice tMonthlyProductionPrice)
    {
        startPage();
        List<TMonthlyProductionPrice> list = tMonthlyProductionPriceService.selectTMonthlyProductionPriceList(tMonthlyProductionPrice);
        return getDataTable(list);
    }

    /**
     * 导出生产月报单价维护列表
     */
    @PreAuthorize("@ss.hasPermi('production:price:export')")
    @Log(title = "生产月报单价维护", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TMonthlyProductionPrice tMonthlyProductionPrice)
    {
        List<TMonthlyProductionPrice> list = tMonthlyProductionPriceService.selectTMonthlyProductionPriceList(tMonthlyProductionPrice);
        ExcelUtil<TMonthlyProductionPrice> util = new ExcelUtil<TMonthlyProductionPrice>(TMonthlyProductionPrice.class);
        return util.exportExcel(list, "price");
    }

    /**
     * 获取生产月报单价维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:price:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tMonthlyProductionPriceService.selectTMonthlyProductionPriceById(id));
    }

    /**
     * 新增生产月报单价维护
     */
    @PreAuthorize("@ss.hasPermi('production:price:add')")
    @Log(title = "生产月报单价维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMonthlyProductionPrice tMonthlyProductionPrice)
    {
        return toAjax(tMonthlyProductionPriceService.insertTMonthlyProductionPrice(tMonthlyProductionPrice));
    }

    /**
     * 修改生产月报单价维护
     */
    @PreAuthorize("@ss.hasPermi('production:price:edit')")
    @Log(title = "生产月报单价维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMonthlyProductionPrice tMonthlyProductionPrice)
    {
        return toAjax(tMonthlyProductionPriceService.updateTMonthlyProductionPrice(tMonthlyProductionPrice));
    }

    /**
     * 删除生产月报单价维护
     */
    @PreAuthorize("@ss.hasPermi('production:price:remove')")
    @Log(title = "生产月报单价维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tMonthlyProductionPriceService.deleteTMonthlyProductionPriceByIds(ids));
    }
}
