package com.xinyilu.web.controller.motionprescriptioninfo;

import com.xinyilu.common.annotation.Log;
import com.xinyilu.common.core.controller.BaseController;
import com.xinyilu.common.core.domain.AjaxResult;
import com.xinyilu.common.core.page.TableDataInfo;
import com.xinyilu.common.custominterface.Insert;
import com.xinyilu.common.custominterface.Update;
import com.xinyilu.common.enums.BusinessType;
import com.xinyilu.common.utils.poi.ExcelUtil;
import com.xinyilu.system.domain.motionprescriptioninfo.MotionPrescriptionDict;
import com.xinyilu.system.service.motionprescriptioninfo.IMotionPrescriptionDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * 运动处方字典Controller
 *
 * @author xinyilu
 * @date 2022-08-01
 */
@RestController
@RequestMapping("/system/motionInfo")
public class MotionPrescriptionDictController extends BaseController {
    @Autowired
    private IMotionPrescriptionDictService motionPrescriptionDictService;

    /**
     * 查询运动处方字典列表
     */
    @PreAuthorize("@ss.hasPermi('system:motionInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(MotionPrescriptionDict motionPrescriptionDict) {
        startPage();
        List<MotionPrescriptionDict> list = motionPrescriptionDictService.selectMotionPrescriptionDictList(motionPrescriptionDict);
        return getDataTable(list);
    }

    /**
     * 导出运动处方字典列表
     */
    @PreAuthorize("@ss.hasPermi('system:motionInfo:export')")
    @Log(title = "运动处方字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MotionPrescriptionDict motionPrescriptionDict) {
        List<MotionPrescriptionDict> list = motionPrescriptionDictService.selectMotionPrescriptionDictList(motionPrescriptionDict);
        ExcelUtil<MotionPrescriptionDict> util = new ExcelUtil<MotionPrescriptionDict>(MotionPrescriptionDict.class);
        util.exportExcel(response, list, "运动处方字典数据");
    }

    /**
     * 获取运动处方字典详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:motionInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(motionPrescriptionDictService.selectMotionPrescriptionDictById(id));
    }

    /**
     * 新增运动处方字典
     */
    @PreAuthorize("@ss.hasPermi('system:motionInfo:add')")
    @Log(title = "运动处方字典", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated(Insert.class) @RequestBody MotionPrescriptionDict motionPrescriptionDict) {
        return toAjax(motionPrescriptionDictService.insertMotionPrescriptionDict(motionPrescriptionDict));
    }

    /**
     * 修改运动处方字典
     */
    @PreAuthorize("@ss.hasPermi('system:motionInfo:edit')")
    @Log(title = "运动处方字典", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@Validated(Update.class) @RequestBody MotionPrescriptionDict motionPrescriptionDict) {
        return toAjax(motionPrescriptionDictService.updateMotionPrescriptionDict(motionPrescriptionDict));
    }


    /**
     * 逻辑运动处方字典
     */
    @PreAuthorize("@ss.hasPermi('system:motionInfo:remove')")
    @Log(title = "运动处方字典", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(motionPrescriptionDictService.updateMotionPrescriptionDictById(ids));
    }
}
