package com.fs.hospital.controller.hospital;

import java.util.List;

import com.fs.common.annotation.RepeatSubmit;
import com.fs.common.core.domain.R;
import com.fs.common.utils.ServletUtils;
import com.fs.framework.security.LoginUser;
import com.fs.framework.service.TokenService;
import com.fs.hospital.domain.HospitalExamItem;
import com.fs.hospital.domain.HospitalInspectItem;
import com.fs.hospital.domain.HospitalPayment;
import com.fs.hospital.param.HospitalOrderItemParam;
import com.fs.hospital.service.IHospitalExamItemService;
import com.fs.hospital.service.IHospitalInspectItemService;
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.hospital.domain.HospitalOrderItem;
import com.fs.hospital.service.IHospitalOrderItemService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 诊疗项目Controller
 *
 * @author fs
 * @date 2024-03-22
 */
@RestController
@RequestMapping("/hospital/hospitalOrderItem")
public class HospitalOrderItemController extends BaseController
{
    @Autowired
    private IHospitalOrderItemService hospitalOrderItemService;
    @Autowired
    private TokenService tokenService;
    @Autowired
    private IHospitalExamItemService hospitalExamItemService;
    @Autowired
    private IHospitalInspectItemService hospitalInspectItemService;

    /**
     * 查询诊疗项目列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalOrderItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalOrderItem hospitalOrderItem)
    {
        startPage();
        List<HospitalOrderItem> list = hospitalOrderItemService.selectHospitalOrderItemList(hospitalOrderItem);
        return getDataTable(list);
    }

    /**
     * 导出诊疗项目列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalOrderItem:export')")
    @Log(title = "诊疗项目", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HospitalOrderItem hospitalOrderItem)
    {
        List<HospitalOrderItem> list = hospitalOrderItemService.selectHospitalOrderItemList(hospitalOrderItem);
        ExcelUtil<HospitalOrderItem> util = new ExcelUtil<HospitalOrderItem>(HospitalOrderItem.class);
        return util.exportExcel(list, "诊疗项目数据");
    }

    /**
     * 获取诊疗项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalOrderItem:query')")
    @GetMapping(value = "/{itemId}")
    public AjaxResult getInfo(@PathVariable("itemId") Long itemId)
    {
        return AjaxResult.success(hospitalOrderItemService.selectHospitalOrderItemByItemId(itemId));
    }

    /**
     * 新增诊疗项目
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalOrderItem:add')")
    @Log(title = "诊疗项目", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody HospitalOrderItem hospitalOrderItem)
    {
        return toAjax(hospitalOrderItemService.insertHospitalOrderItem(hospitalOrderItem));
    }

    /**
     * 修改诊疗项目
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalOrderItem:edit')")
    @Log(title = "诊疗项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalOrderItem hospitalOrderItem)
    {
        return toAjax(hospitalOrderItemService.updateHospitalOrderItem(hospitalOrderItem));
    }

    /**
     * 删除诊疗项目
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalOrderItem:remove')")
    @Log(title = "诊疗项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{itemIds}")
    public AjaxResult remove(@PathVariable Long[] itemIds)
    {
        return toAjax(hospitalOrderItemService.deleteHospitalOrderItemByItemIds(itemIds));
    }

    /**
     *  商品查询
     */
    @GetMapping("/goodsSearch")
    public R goodsSearch(HospitalOrderItemParam param)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        param.setHospitalId(loginUser.getHospital().getHospitalId());
        return hospitalOrderItemService.selectHospitalOrderItemListHVO(param);
    }

    @Log(title = "完成挂号收费", businessType = BusinessType.UPDATE)
    @PostMapping("/finishRegistration")
    public R finishRegistration(@RequestBody HospitalOrderItem orderItem)
    {
        return hospitalOrderItemService.finishRegistration(orderItem);
    }
}
