package com.ruoyi.os.controller;


// IHealthcareOsConventionalValueService
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.beust.ah.A;
import com.ruoyi.common.enums.healthcare.HealthcareOsDictionaryName;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.os.domain.HealthcareOsConventionalValue;
import com.ruoyi.os.service.IHealthcareOsConventionalValueService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 字典Controller
 *
 * @author 何顺
 * @date 2024-09-29
 */
@RestController
@RequestMapping("/outpatientService/healthcareOsConventionalValue")
public class HealthcareOsConventionalValueController extends BaseController
{
    @Autowired
    private IHealthcareOsConventionalValueService iHealthcareOsConventionalValueService;



    /**
     *   查询详细字典
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:getInfo')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(iHealthcareOsConventionalValueService.selectHealthcareOsConventionalValueById(id));
    }

    /**
     *  删除字典
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:remove')")
    @Log(title = "删除字典数值", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(iHealthcareOsConventionalValueService.deleteHealthcareOsConventionalValueByIds(ids));
    }


    /**
     *    查询  字典  目录
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:queryDictionary')")
    @GetMapping("/queryDictionary")
    public TableDataInfo queryDictionary() {
        HealthcareOsConventionalValue healthcareOsConventionalValue = new HealthcareOsConventionalValue();
        healthcareOsConventionalValue.setParentId(0L);
        return getDataTable(iHealthcareOsConventionalValueService.selectHealthcareOsConventionalValueList(healthcareOsConventionalValue));
    }

    /**
     *    查询  字典  数值 列表
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:queryDictionaryValueList')")
    @GetMapping("/queryDictionaryValueList/{id}")
    public TableDataInfo queryDictionaryValueList(@PathVariable("id") Long id) {
        HealthcareOsConventionalValue healthcareOsConventionalValue = new HealthcareOsConventionalValue();
        healthcareOsConventionalValue.setParentId(id);
        return getDataTable(iHealthcareOsConventionalValueService.selectHealthcareOsConventionalValueList(healthcareOsConventionalValue));
    }

    /**
     *   添加 字典
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:AddDictionary')")
    @PostMapping("/addDictionary")
    public AjaxResult addDictionary(@RequestBody HealthcareOsConventionalValue healthcareOsConventionalValue) {
        healthcareOsConventionalValue.setParentId(0L);
        return toAjax(iHealthcareOsConventionalValueService.insertHealthcareOsConventionalValue(healthcareOsConventionalValue));
    }

    /**
     *   修改 字典
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:updateDictionary')")
    @PostMapping("/updateDictionary")
    public AjaxResult updateDictionary(@RequestBody HealthcareOsConventionalValue healthcareOsConventionalValue) {
        healthcareOsConventionalValue.setParentId(0L);
        return toAjax(iHealthcareOsConventionalValueService.updateHealthcareOsConventionalValue(healthcareOsConventionalValue));
    }

    /**
     *   查询 字典 id
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:id')")
    @GetMapping ("/queryDictionaryId")
    public TableDataInfo queryDictionaryId(String dictName) {
        // os_usage
        HealthcareOsConventionalValue healthcareOsConventionalValue = new HealthcareOsConventionalValue();
        healthcareOsConventionalValue.setDictName(dictName);
        healthcareOsConventionalValue.setParentId(0L);
        return getDataTable(iHealthcareOsConventionalValueService.selectHealthcareOsConventionalValueList(healthcareOsConventionalValue));
    }

    /**
     *    查询  用法  表单
     *    用法 ==> usage
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:queryUsageList')")
    @GetMapping("/queryUsageList")
    public TableDataInfo queryUsageList(HealthcareOsConventionalValue conventionalValue) {
        // os_usage
        Long id = iHealthcareOsConventionalValueService.queryDictionaryId(HealthcareOsDictionaryName.OS_USAGE);
        if(id == null) {
            throw new RuntimeException("用法字典不存在("+HealthcareOsDictionaryName.OS_USAGE+")");
        }
        conventionalValue.setParentId(id);
        // 可以 查询
        return getDataTable(iHealthcareOsConventionalValueService.selectHealthcareOsConventionalValueList(conventionalValue));
    }

    /**
     *   添加 用法
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:addUsage')")
    @PostMapping("/addUsage")
    public AjaxResult addUsage(@RequestBody HealthcareOsConventionalValue healthcareOsConventionalValue) {
        //
        Long id = iHealthcareOsConventionalValueService.queryDictionaryId(HealthcareOsDictionaryName.OS_USAGE);
        if(id == null) {
            throw new RuntimeException("用法字典不存在("+HealthcareOsDictionaryName.OS_USAGE+")");
        }
        return toAjax(iHealthcareOsConventionalValueService.addDictionaryValue(id , healthcareOsConventionalValue.getValue()));
    }

    /**
     *   修改 用法
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:addUsage')")
    @PostMapping("/updateUsage")
    public AjaxResult updateUsage(@RequestBody HealthcareOsConventionalValue healthcareOsConventionalValue) {
        //
        return toAjax(iHealthcareOsConventionalValueService.updateDictionaryValue(healthcareOsConventionalValue.getId(), healthcareOsConventionalValue.getValue()));
    }

    /**
     *    查询详细用法
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:getInfoUsage')")
    @GetMapping(value = "/getInfoUsage/{id}")
    public AjaxResult getInfoUsage(@PathVariable("id") Long id)
    {
        return success(iHealthcareOsConventionalValueService.selectHealthcareOsConventionalValueById(id));
    }

    /**
     *  删除用法
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:removeUsage')")
    @Log(title = "删除用法", businessType = BusinessType.DELETE)
    @DeleteMapping("/removeUsage/{ids}")
    public AjaxResult removeUsage(@PathVariable Long[] ids)
    {
        return toAjax(iHealthcareOsConventionalValueService.deleteHealthcareOsConventionalValueByIds(ids));
    }

    /**
     *    查询 用量  表单  Dosage
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:queryDoseList')")
    @GetMapping("/queryDoseList")
    public TableDataInfo queryDoseList(HealthcareOsConventionalValue conventionalValue) {
        //
        Long id = iHealthcareOsConventionalValueService.queryDictionaryId(HealthcareOsDictionaryName.OS_DOSE);
        if(id == null) {
            throw new RuntimeException("用量字典不存在("+HealthcareOsDictionaryName.OS_DOSE+")");
        }
        conventionalValue.setParentId(id);
        return getDataTable(iHealthcareOsConventionalValueService.selectHealthcareOsConventionalValueList(conventionalValue));
    }
    /**
     *    添加  用量
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:addDose')")
    @PostMapping("/addDose")
    public AjaxResult addDose(@RequestBody HealthcareOsConventionalValue healthcareOsConventionalValue) {
        //
        Long id = iHealthcareOsConventionalValueService.queryDictionaryId(HealthcareOsDictionaryName.OS_DOSE);
        if(id == null) {
            throw new RuntimeException("用量字典不存在("+HealthcareOsDictionaryName.OS_DOSE+")");
        }
        return toAjax(iHealthcareOsConventionalValueService.addDictionaryValue(id , healthcareOsConventionalValue.getName() , healthcareOsConventionalValue.getValue()));
    }

    /**
     *   修改  用量
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:updateDose')")
    @PostMapping("/updateDose")
    public AjaxResult updateDose(@RequestBody HealthcareOsConventionalValue healthcareOsConventionalValue) {
        //
        return toAjax(iHealthcareOsConventionalValueService.updateDictionaryValue(healthcareOsConventionalValue.getId(), healthcareOsConventionalValue.getName() , healthcareOsConventionalValue.getValue()));
    }

    /**
     *    查询详细 用量
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:getInfoDose')")
    @GetMapping(value = "/getInfoDose/{id}")
    public AjaxResult getInfoDose(@PathVariable("id") Long id)
    {
        return success(iHealthcareOsConventionalValueService.selectHealthcareOsConventionalValueById(id));
    }

    /**
     *  删除用量
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:removeDose')")
    @Log(title = "删除用量", businessType = BusinessType.DELETE)
    @DeleteMapping("/removeDose/{ids}")
    public AjaxResult removeDose(@PathVariable Long[] ids)
    {
        return toAjax(iHealthcareOsConventionalValueService.deleteHealthcareOsConventionalValueByIds(ids));
    }

    /**
     *    查询 食用时间 表单  commonEatingTime
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:queryEatingTimeList')")
    @GetMapping("/queryEatingTimeList")
    public TableDataInfo queryEatingTimeList(HealthcareOsConventionalValue conventionalValue) {
        //
        Long id = iHealthcareOsConventionalValueService.queryDictionaryId(HealthcareOsDictionaryName.OS_EATING_TIME);
        if(id == null) {
            throw new RuntimeException("食用时间字典不存在("+HealthcareOsDictionaryName.OS_EATING_TIME+")");
        }
        conventionalValue.setParentId(id);
        return getDataTable(iHealthcareOsConventionalValueService.selectHealthcareOsConventionalValueList(conventionalValue));
    }

    /**
     *    添加  食用时间
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:addEatingTime')")
    @PostMapping("/addEatingTime")
    public AjaxResult addEatingTime(@RequestBody HealthcareOsConventionalValue healthcareOsConventionalValue) {
        //
        Long id = iHealthcareOsConventionalValueService.queryDictionaryId(HealthcareOsDictionaryName.OS_EATING_TIME);
        if(id == null) {
            throw new RuntimeException("食用时间字典不存在("+HealthcareOsDictionaryName.OS_EATING_TIME+")");
        }
        return toAjax(iHealthcareOsConventionalValueService.addDictionaryValue(id , healthcareOsConventionalValue.getValue()));
    }

    /**
     *   修改  食用时间
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:updateEatingTime')")
    @PostMapping("/updateEatingTime")
    public AjaxResult updateEatingTime(@RequestBody HealthcareOsConventionalValue healthcareOsConventionalValue) {
        //
        return toAjax(iHealthcareOsConventionalValueService.updateDictionaryValue(healthcareOsConventionalValue.getId(), healthcareOsConventionalValue.getValue()));
    }

    /**
     *    查询详细 食用时间
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:getInfoEatingTime')")
    @GetMapping(value = "/getInfoEatingTime/{id}")
    public AjaxResult getInfoEatingTime(@PathVariable("id") Long id)
    {
        return success(iHealthcareOsConventionalValueService.selectHealthcareOsConventionalValueById(id));
    }

    /**
     *  删除食用时间
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:removeEatingTime')")
    @Log(title = "删除食用时间", businessType = BusinessType.DELETE)
    @DeleteMapping("/removeEatingTime/{ids}")
    public AjaxResult removeEatingTime(@PathVariable Long[] ids)
    {
        return toAjax(iHealthcareOsConventionalValueService.deleteHealthcareOsConventionalValueByIds(ids));
    }


    /**
     *    查询 次数 表单  commonFrequency
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:queryFrequencyList')")
    @GetMapping("/queryFrequencyList")
    public TableDataInfo queryFrequencyList(HealthcareOsConventionalValue conventionalValue) {
        //
        Long id = iHealthcareOsConventionalValueService.queryDictionaryId(HealthcareOsDictionaryName.OS_FREQUENCY);
        if(id == null) {
            throw new RuntimeException("次数字典不存在("+HealthcareOsDictionaryName.OS_FREQUENCY+")");
        }
        conventionalValue.setParentId(id);
        return getDataTable(iHealthcareOsConventionalValueService.selectHealthcareOsConventionalValueList(conventionalValue));
    }

    /**
     *    添加  次数
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:addFrequency')")
    @PostMapping("/addFrequency")
    public AjaxResult addFrequency(@RequestBody HealthcareOsConventionalValue healthcareOsConventionalValue) {
        //
        Long id = iHealthcareOsConventionalValueService.queryDictionaryId(HealthcareOsDictionaryName.OS_FREQUENCY);
        //
        if(id == null) {
            throw new RuntimeException("次数字典不存在("+HealthcareOsDictionaryName.OS_FREQUENCY+")");
        }
        return toAjax(iHealthcareOsConventionalValueService.addDictionaryValue(id , healthcareOsConventionalValue.getName() , healthcareOsConventionalValue.getValue()));
    }

    /**
     *   修改  次数
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:updateFrequency')")
    @PostMapping("/updateFrequency")
    public AjaxResult updateFrequency(@RequestBody HealthcareOsConventionalValue healthcareOsConventionalValue) {
        //
        return toAjax(iHealthcareOsConventionalValueService.updateDictionaryValue(healthcareOsConventionalValue.getId(), healthcareOsConventionalValue.getName() , healthcareOsConventionalValue.getValue()));
    }

    /**
     *    查询详细 次数
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:getInfoFrequency')")
    @GetMapping(value = "/getInfoFrequency/{id}")
    public AjaxResult getInfoFrequency(@PathVariable("id") Long id)
    {
        return success(iHealthcareOsConventionalValueService.selectHealthcareOsConventionalValueById(id));
    }

    /**
     *  删除次数
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:removeFrequency')")
    @Log(title = "删除次数", businessType = BusinessType.DELETE)
    @DeleteMapping("/removeFrequency/{ids}")
    public AjaxResult removeFrequency(@PathVariable Long[] ids)
    {
        return toAjax(iHealthcareOsConventionalValueService.deleteHealthcareOsConventionalValueByIds(ids));
    }

    /* ------------------------------------ */
    /**
     *    查询 症状 表单  symptom
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:querySymptomList')")
    @GetMapping("/querySymptomList")
    public TableDataInfo querySymptomList(HealthcareOsConventionalValue conventionalValue) {
        //
        Long id = iHealthcareOsConventionalValueService.queryDictionaryId(HealthcareOsDictionaryName.OS_SYMPTOM);
        if(id == null) {
            throw new RuntimeException("症状字典不存在("+HealthcareOsDictionaryName.OS_SYMPTOM+")");
        }
        conventionalValue.setParentId(id);
        return getDataTable(iHealthcareOsConventionalValueService.selectHealthcareOsConventionalValueList(conventionalValue));
    }

    /**
     *    添加  症状  symptom
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:addSymptom')")
    @PostMapping("/addSymptom")
    public AjaxResult addSymptom(@RequestBody HealthcareOsConventionalValue healthcareOsConventionalValue) {
        //
        Long id = iHealthcareOsConventionalValueService.queryDictionaryId(HealthcareOsDictionaryName.OS_SYMPTOM);
        //
        if(id == null) {
            throw new RuntimeException("症状字典不存在("+HealthcareOsDictionaryName.OS_SYMPTOM+")");
        }
        return toAjax(iHealthcareOsConventionalValueService.addDictionaryValue(id , healthcareOsConventionalValue.getName() , healthcareOsConventionalValue.getValue()));
    }

    /**
     *   修改  症状  symptom
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:updateSymptom')")
    @PostMapping("/updateSymptom")
    public AjaxResult updateSymptom(@RequestBody HealthcareOsConventionalValue healthcareOsConventionalValue) {
        //
        return toAjax(iHealthcareOsConventionalValueService.updateDictionaryValue(healthcareOsConventionalValue.getId(), healthcareOsConventionalValue.getName() , healthcareOsConventionalValue.getValue()));
    }

    /**
     *    查询详细 症状  symptom
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:getInfoSymptom')")
    @GetMapping(value = "/getInfoSymptom/{id}")
    public AjaxResult getInfoSymptom(@PathVariable("id") Long id)
    {
        return success(iHealthcareOsConventionalValueService.selectHealthcareOsConventionalValueById(id));
    }

    /**
     *  删除 症状   symptom
     */
    @PreAuthorize("@ss.hasPermi('os:healthcareOsConventionalValue:removeSymptom')")
    @Log(title = "删除次数", businessType = BusinessType.DELETE)
    @DeleteMapping("/removeSymptom/{ids}")
    public AjaxResult removeSymptom(@PathVariable Long[] ids)
    {
        return toAjax(iHealthcareOsConventionalValueService.deleteHealthcareOsConventionalValueByIds(ids));
    }


}
