package com.eitc.patient.controller;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.eitc.common.annotation.Log;
import com.eitc.common.core.controller.BaseController;
import com.eitc.common.core.domain.AjaxResult;
import com.eitc.common.enums.BusinessType;
import com.eitc.patient.service.IDiagnosisTypeOrderDoctorService;
import com.eitc.patient.service.IDiagnosisTypeService;
import com.eitc.patient.tree.DiagnosisTypeTree;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * DiagnosisTypeOrderDoctorController
 *
 * @author mtx
 * @date: 2024/05/17 15:51
 */
@Api(tags = "诊断分类排序与医生的关联表")
@RestController
@RequestMapping("/diagnosis-type-order-doctor")
public class DiagnosisTypeOrderDoctorController extends BaseController {

    @Resource
    private IDiagnosisTypeOrderDoctorService diagnosisTypeOrderDoctorService;
    @Resource
    private IDiagnosisTypeService diagnosisTypeService;

    @Log(title = "保存分类排序", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("保存分类排序")
    public AjaxResult add(@Valid @RequestBody List<DiagnosisTypeTree> treeList) {
        if (CollectionUtils.isEmpty(treeList)) {
            return AjaxResult.warn("请选择");
        }
        return diagnosisTypeOrderDoctorService.saveTree(treeList);
    }

    @GetMapping("/tree")
    @ApiOperation("查询诊断分类")
    public AjaxResult tree() {
        return success(diagnosisTypeService.findTreeList());
    }

}
