package com.op.mes.controller;

import com.op.common.core.utils.poi.ExcelUtil;
import com.op.common.core.web.controller.BaseController;
import com.op.common.core.web.domain.AjaxResult;
import com.op.common.core.web.page.TableDataInfo;
import com.op.common.log.annotation.Log;
import com.op.common.log.enums.BusinessType;
import com.op.mes.domain.ProRecipeContent;
import com.op.mes.service.IProRecipeContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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


/**
 * 配药配方管理内容Controller
 *
 * @author yinjinlu
 * @date 2022-05-12
 */
@RestController
@RequestMapping("/pro/recipecontent")
public class ProRecipeContentController extends BaseController {
    @Autowired
    private IProRecipeContentService proRecipeContentService;

    /**
     * 查询配药配方管理内容列表
     */
    //@RequiresPermissions("mes:pro:recipecontent:list")
    @GetMapping("/list")
    public TableDataInfo list(ProRecipeContent proRecipeContent) {
        startPage();
        List<ProRecipeContent> list = proRecipeContentService.selectProRecipeContentList(proRecipeContent);
        return getDataTable(list);
    }

    /**
     * 导出配药配方管理内容列表
     */
    //@RequiresPermissions("mes:pro:recipecontent:export")
    @Log(title = "配药配方管理内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProRecipeContent proRecipeContent) {
        List<ProRecipeContent> list = proRecipeContentService.selectProRecipeContentList(proRecipeContent);
        ExcelUtil<ProRecipeContent> util = new ExcelUtil<ProRecipeContent>(ProRecipeContent.class);
        util.exportExcel(response, list, "配药配方管理内容数据");
    }

    /**
     * 获取配药配方管理内容详细信息
     */
    //@RequiresPermissions("mes:pro:recipecontent:query")
    @GetMapping(value = "/{contentId}")
    public AjaxResult getInfo(@PathVariable("contentId") String contentId) {
        return AjaxResult.success(proRecipeContentService.selectProRecipeContentByContentId(contentId));
    }

    /**
     * 新增配药配方管理内容
     */
    //@RequiresPermissions("mes:pro:recipecontent:add")
    @Log(title = "配药配方管理内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProRecipeContent proRecipeContent) {
        return toAjax(proRecipeContentService.insertProRecipeContent(proRecipeContent));
    }

    /**
     * 修改配药配方管理内容
     */
    //@RequiresPermissions("mes:pro:recipecontent:edit")
    @Log(title = "配药配方管理内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProRecipeContent proRecipeContent) {
        return toAjax(proRecipeContentService.updateProRecipeContent(proRecipeContent));
    }

    /**
     * 删除配药配方管理内容
     */
    //@RequiresPermissions("mes:pro:recipecontent:remove")
    @Log(title = "配药配方管理内容", businessType = BusinessType.DELETE)
    @DeleteMapping("/{contentIds}")
    public AjaxResult remove(@PathVariable String[] contentIds) {
        return toAjax(proRecipeContentService.deleteProRecipeContentByContentIds(contentIds));
    }
}
