package com.bohuikeji.delivery.backstage.controller.api.system;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bohuikeji.delivery.backstage.service.ITCourierService;
import com.bohuikeji.delivery.backstage.service.ITCustomerAddressService;
import com.bohuikeji.delivery.backstage.service.ITOrderService;
import com.bohuikeji.frame.module.admin.base.ApiController;
import com.bohuikeji.frame.module.admin.entity.back.APIEntity;
import com.bohuikeji.frame.module.admin.entity.sys.SysConfig;
import com.bohuikeji.frame.module.admin.service.ISysConfigService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Random;

/**
 * 数据字典
 */
@Slf4j
@Api(tags = {"数据字典接口"})
@RestController
@RequestMapping("/api/sysconfig")
public class SysConfigApi extends ApiController {

    @Autowired
    ITOrderService orderService;
    @Autowired
    ITCourierService courierService;
    @Autowired
    ISysConfigService sysConfigService;
    @Autowired
    ITCustomerAddressService itCustomerAddressService;


    /**
     * 查询服务/货物/价值类型
     * @return
     */
    @ApiOperation("查询服务/货物/车辆类型/价值类型")
    @GetMapping("/sysconfig/serviceType")
    //配置忽略参数
    @ApiOperationSupport(ignoreParameters = {"records","total","searchCount"})
    @ApiImplicitParams({
            @ApiImplicitParam(name="configKey",value="configKey",dataType="String", paramType = "query")})
    public APIEntity<List<SysConfig>> serviceTypeList(String configKey){
        QueryWrapper<SysConfig> queryWrapper=new QueryWrapper<SysConfig>().eq("config_group",configKey);
        if("car_type".equals(configKey)){
            queryWrapper.orderByDesc("config_id");
        }
        List<SysConfig> sysConfigs = sysConfigService.list(queryWrapper);
        return APIEntity.success(sysConfigs);
    }
    /**
     * 根据id查询字典类型
     * @return
     */
    @ApiOperation("根据id查询字典类型")
    @GetMapping("/sysconfig/getSysConfig")
    //配置忽略参数
    @ApiOperationSupport(ignoreParameters = {"records","total","searchCount"})
    @ApiImplicitParams({
            @ApiImplicitParam(name="configId",value="字典id",dataType="Integer", paramType = "query")})
    public APIEntity<SysConfig> serviceById(Integer configId){
        SysConfig sysConfig = sysConfigService.getById(configId);
        return APIEntity.success(sysConfig);
    }



    @ApiOperation("根据配置key查询配置项")
    @GetMapping("/get/key")
    @ApiImplicitParams({
            @ApiImplicitParam(name="configKey",value="数据字典key",dataType="String", paramType = "query")})
    public APIEntity<SysConfig> getKey(String configKey){
        SysConfig sysConfig = sysConfigService.getOneByKey(configKey);
        if(sysConfig==null){
            return APIEntity.fail("未找到配置项信息！");
        }
        return APIEntity.success(sysConfig);
    }

    @ApiOperation("根据配置组key查询配置项")
    @GetMapping("/get/group")
    @ApiImplicitParams({
            @ApiImplicitParam(name="configGroup",value="数据字典组",dataType="String", paramType = "query")})
    public APIEntity<List<SysConfig>> getGroup(String configGroup){
        List<SysConfig> sysConfigList = sysConfigService.getListByGroup(configGroup);
        return APIEntity.success(sysConfigList);
    }


    /**
     * 查询车辆能源类型
     * @return
     */
   /* @ApiOperation("查询车辆能源类型")
    @GetMapping("/sysconfig/energyType")
    //配置忽略参数
    @ApiOperationSupport(ignoreParameters = {"records","total","searchCount"})
    @ApiImplicitParams({
            @ApiImplicitParam(name="configName",value="车辆类型名称",dataType="String", paramType = "query")})
    public APIEntity<SysConfig> energyTypeList(String configName){
        SysConfig sysConfig = sysConfigService.getOne(new QueryWrapper<SysConfig>().eq("config_name",configName));
        return APIEntity.success(sysConfigService.list(new QueryWrapper<SysConfig>().eq("cinfig_super",sysConfig.getConfigId())));
    }
*/

}
