package com.fs.store.controller;

import java.util.List;

import com.fs.common.utils.ParseUtils;
import com.fs.store.param.FsPrescribeVOParam;
import com.fs.store.vo.FsPrescribeVO;
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.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.store.domain.FsPrescribe;
import com.fs.store.service.IFsPrescribeService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 处方Controller
 *
 * @author fs
 * @date 2022-03-15
 */
@RestController
@RequestMapping("/store/prescribe")
public class FsPrescribeController extends BaseController
{
    @Autowired
    private IFsPrescribeService 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(FsPrescribe fsPrescribe)
    {
        List<FsPrescribe> list = fsPrescribeService.selectFsPrescribeList(fsPrescribe);
        ExcelUtil<FsPrescribe> util = new ExcelUtil<FsPrescribe>(FsPrescribe.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 FsPrescribe fsPrescribe)
    {
        return toAjax(fsPrescribeService.insertFsPrescribe(fsPrescribe));
    }

    /**
     * 修改处方
     */
    @PreAuthorize("@ss.hasPermi('store:prescribe:edit')")
    @Log(title = "处方", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsPrescribe 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));
    }
}
