package com.fs.hisStore.controller;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.ParseUtils;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.hisStore.domain.FsPrescribeScrm;
import com.fs.hisStore.param.FsPrescribeVOParam;
import com.fs.hisStore.service.IFsPrescribeScrmService;
import com.fs.hisStore.vo.FsPrescribeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 处方Controller
 *
 * @author fs
 * @date 2022-03-15
 */
@RestController
@RequestMapping("/store/store/prescribe")
public class FsPrescribeScrmController extends BaseController
{
    @Autowired
    private IFsPrescribeScrmService fsPrescribeService;

    /**
     * 查询处方列表
     */
    @PreAuthorize("@ss.hasPermi('store:prescribe:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsPrescribeVOParam fsPrescribe)
    {
        startPage();
        List<FsPrescribeVO> list = fsPrescribeService.selectFsPrescribeListVO(fsPrescribe);
        for (FsPrescribeVO vo : list){
            vo.setUserPhone(ParseUtils.parsePhone(vo.getUserPhone()));
        }
        return getDataTable(list);
    }

    /**
     * 导出处方列表
     */
    @PreAuthorize("@ss.hasPermi('store:prescribe:export')")
    @Log(title = "处方", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsPrescribeScrm fsPrescribe)
    {
        List<FsPrescribeScrm> list = fsPrescribeService.selectFsPrescribeList(fsPrescribe);
        ExcelUtil<FsPrescribeScrm> util = new ExcelUtil<FsPrescribeScrm>(FsPrescribeScrm.class);
        return util.exportExcel(list, "prescribe");
    }

    /**
     * 获取处方详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:prescribe:query')")
    @GetMapping(value = "/{prescribeId}")
    public AjaxResult getInfo(@PathVariable("prescribeId") Long prescribeId)
    {
        return AjaxResult.success(fsPrescribeService.selectFsPrescribeById(prescribeId));
    }

    /**
     * 新增处方
     */
    @PreAuthorize("@ss.hasPermi('store:prescribe:add')")
    @Log(title = "处方", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsPrescribeScrm fsPrescribe)
    {
        return toAjax(fsPrescribeService.insertFsPrescribe(fsPrescribe));
    }

    /**
     * 修改处方
     */
    @PreAuthorize("@ss.hasPermi('store:prescribe:edit')")
    @Log(title = "处方", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsPrescribeScrm fsPrescribe)
    {
        return toAjax(fsPrescribeService.updateFsPrescribe(fsPrescribe));
    }

    /**
     * 删除处方
     */
    @PreAuthorize("@ss.hasPermi('store:prescribe:remove')")
    @Log(title = "处方", businessType = BusinessType.DELETE)
	@DeleteMapping("/{prescribeIds}")
    public AjaxResult remove(@PathVariable Long[] prescribeIds)
    {
        return toAjax(fsPrescribeService.deleteFsPrescribeByIds(prescribeIds));
    }
}
