package com.fs.hisStore.controller.store;

import com.fs.common.BeanCopyUtils;
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.his.param.FsPrescribeParam;
import com.fs.his.vo.FsPrescribeExcelListStoreVO;
import com.fs.his.vo.FsPrescribeExcelListVO;
import com.fs.his.vo.FsPrescribeListVO;
import com.fs.his.vo.FsPrescribeVO;
import com.fs.hisStore.service.IFsPrescribeScrmStoreService;
import com.fs.hisStore.utils.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 处方Controller
 *
 * @author fs
 * @date 2023-06-13
 */
@RestController
@RequestMapping("/store/store/prescribe")
public class FsPrescribeScrmController extends BaseController
{   @Lazy
    @Autowired
    private IFsPrescribeScrmStoreService fsPrescribeService;

    /**
     * 查询处方列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FsPrescribeParam fsPrescribe)
    {
        fsPrescribe.setStoreId(UserUtil.getLoginUserStoreID());
        startPage();
        List<FsPrescribeListVO> list = fsPrescribeService.selectFsPrescribeListVO(fsPrescribe);
        for (FsPrescribeListVO fsPrescribeListVO : list) {
            fsPrescribeListVO.setPatientTel(ParseUtils.parsePhone(fsPrescribeListVO.getPatientTel()));
        }
        return getDataTable(list);
    }

    /**
     * 导出处方列表
     */

    @Log(title = "处方", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsPrescribeParam fsPrescribe)
    {
        fsPrescribe.setStoreId(UserUtil.getLoginUserStoreID());
        List<FsPrescribeExcelListVO> list = fsPrescribeService.selectFsPrescribeExcelListVO(fsPrescribe);
        List<FsPrescribeExcelListStoreVO> fsPrescribeExcelListStoreVOS = BeanCopyUtils.copyList(list, FsPrescribeExcelListStoreVO.class);
        ExcelUtil<FsPrescribeExcelListStoreVO> util = new ExcelUtil<FsPrescribeExcelListStoreVO>(FsPrescribeExcelListStoreVO.class);
        return util.exportExcel(fsPrescribeExcelListStoreVOS, "处方数据");
    }

    /**
     * 获取处方详细信息
     */

    @GetMapping(value = "/{prescribeId}")
    public AjaxResult getInfo(@PathVariable("prescribeId") Long prescribeId)
    {
        FsPrescribeVO fsPrescribeVO = fsPrescribeService.selectFsPrescribeByPrescribeIdVO(prescribeId);
        fsPrescribeVO.setPatientTel(ParseUtils.parsePhone(fsPrescribeVO.getPatientTel()));
        return AjaxResult.success(fsPrescribeVO);
    }
    /**
     * 获取处方详细信息
     */

    @GetMapping("/Drug/{prescribeId}")
    public AjaxResult getDrugInfo(@PathVariable("prescribeId") Long prescribeId)
    {
        return AjaxResult.success(fsPrescribeService.selectFsPrescribeDrugByPrescribeIdVO(prescribeId));
    }






}
