package com.fs.hospital.controller.hospital;

import java.util.List;

import com.fs.common.annotation.RepeatSubmit;
import com.fs.common.utils.ServletUtils;
import com.fs.framework.security.LoginUser;
import com.fs.framework.service.TokenService;
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.HospitalTreatItem;
import com.fs.hospital.service.IHospitalTreatItemService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 治疗Controller
 *
 * @author fs
 * @date 2024-03-26
 */
@RestController
@RequestMapping("/hospital/hospitalTreatItem")
public class HospitalTreatItemController extends BaseController
{
    @Autowired
    private IHospitalTreatItemService hospitalTreatItemService;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询治疗列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalTreatItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalTreatItem hospitalTreatItem)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        hospitalTreatItem.setHospitalId(loginUser.getHospital().getHospitalId());
        List<HospitalTreatItem> list = hospitalTreatItemService.selectHospitalTreatItemList(hospitalTreatItem);
        return getDataTable(list);
    }

    /**
     * 导出治疗列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalTreatItem:export')")
    @Log(title = "治疗", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HospitalTreatItem hospitalTreatItem)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        hospitalTreatItem.setHospitalId(loginUser.getHospital().getHospitalId());
        List<HospitalTreatItem> list = hospitalTreatItemService.selectHospitalTreatItemList(hospitalTreatItem);
        ExcelUtil<HospitalTreatItem> util = new ExcelUtil<HospitalTreatItem>(HospitalTreatItem.class);
        return util.exportExcel(list, "治疗数据");
    }

    /**
     * 获取治疗详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalTreatItem:query')")
    @GetMapping(value = "/{treatId}")
    public AjaxResult getInfo(@PathVariable("treatId") Long treatId)
    {
        return AjaxResult.success(hospitalTreatItemService.selectHospitalTreatItemByTreatId(treatId));
    }

    /**
     * 新增治疗
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalTreatItem:add')")
    @Log(title = "治疗", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody HospitalTreatItem hospitalTreatItem)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        hospitalTreatItem.setHospitalId(loginUser.getHospital().getHospitalId());
        return toAjax(hospitalTreatItemService.insertHospitalTreatItem(hospitalTreatItem));
    }

    /**
     * 修改治疗
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalTreatItem:edit')")
    @Log(title = "治疗", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalTreatItem hospitalTreatItem)
    {
        return toAjax(hospitalTreatItemService.updateHospitalTreatItem(hospitalTreatItem));
    }

    /**
     * 删除治疗
     */
    @PreAuthorize("@ss.hasPermi('hospital:hospitalTreatItem:remove')")
    @Log(title = "治疗", businessType = BusinessType.DELETE)
	@DeleteMapping("/{treatIds}")
    public AjaxResult remove(@PathVariable Long[] treatIds)
    {
        return toAjax(hospitalTreatItemService.deleteHospitalTreatItemByTreatIds(treatIds));
    }
}
