package com.eitc.patient.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.eitc.common.core.controller.BaseController;
import com.eitc.common.core.domain.AjaxResult;
import com.eitc.common.core.domain.entity.SysDictData;
import com.eitc.common.utils.StringUtils;
import com.eitc.patient.domain.BusinessDictData;
import com.eitc.patient.service.IBusinessDictDataService;
import com.eitc.system.service.ISysDictTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * AppSystemController
 *
 * @author mtx
 * @date: 2024/07/30 10:17
 */
@RestController
@RequestMapping("/app/system/")
@Api(tags = "APP系统字典数据")
public class AppSystemController extends BaseController {

    @Resource
    private ISysDictTypeService dictTypeService;
    @Resource
    private IBusinessDictDataService businessDictDataService;


    /**
     * 根据字典类型查询字典数据信息
     */
    @GetMapping(value = "/type/{dictType}")
    public AjaxResult dictType(@PathVariable String dictType) {
        List<SysDictData> data = dictTypeService.selectDictDataByType(dictType);
        if (StringUtils.isNull(data)) {
            data = new ArrayList<SysDictData>();
        }
        return success(data);
    }

    @GetMapping("/dropdownList")
    @ApiOperation("根据字典类型查询字典下拉数据项")
    public AjaxResult dropdownList(@ApiParam(name = "dictType", value = "字典类型", required = true) @RequestParam("dictType") String dictType) {
        List<BusinessDictData> list = businessDictDataService.list(Wrappers.<BusinessDictData>lambdaQuery()
                .eq(BusinessDictData::getDictStatus, 1)
                .eq(BusinessDictData::getDictType, dictType)
                .orderByAsc(BusinessDictData::getDictSort));

        return success(list);
    }
}
