package com.tofly.feesapi.common;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.tofly.feesapi.common.core.ResultRespone;
import com.tofly.feesapi.common.enums.UserRoleEnum;
import com.tofly.feesapi.common.mapper.CommonMapper;
import com.tofly.feesapi.common.model.CollectionData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * 用户控制处理类
 */
@RestController
@AllArgsConstructor
@RequestMapping("/api/common/user")
@Api(tags = "公共-操作员信息")
public class UserController extends BaseController {

    private CommonMapper commonMapper;

    /**
     * 获取所有抄表员数据
     */
    @PostMapping("/getAllMeterReader")
    @ApiOperation(value = "获取所有抄表员数据")
    @DS("udb")
    public ResultRespone<CollectionData<List<HashMap<String, Object>>>> getAllMeterReaderList() {
        return getListResult(UserRoleEnum.MeterReader);
    }

    /**
     * 获取所有抄表员数据
     */
    @PostMapping("/getAllUsers")
    @ApiOperation(value = "获取所有人员")
    @DS("udb")
    public ResultRespone<CollectionData<List<HashMap<String, Object>>>> getAllUsers() {
        return getListResult(null);
    }


    /**
     * 获取所有收费人员数据
     */
    @PostMapping("/getAllTollCollector")
    @ApiOperation(value = "获取所有收费人员数据")
    @DS("udb")
    public ResultRespone<CollectionData<List<HashMap<String, Object>>>> getAllTollCollectorList() {
        return getListResult(UserRoleEnum.TollCollector);
    }

    /**
     * 获取所有第三方收费人员数据
     */
    @DS("udb")
    @PostMapping("/getAllThirdPartyTollCollector")
    @ApiOperation(value = "获取第三方收费人员数据")
    public ResultRespone<CollectionData<List<HashMap<String, Object>>>> getAllThirdPartyTollCollectorList() {
        return getListResult(UserRoleEnum.ThirdPartyTollCollector);
    }

    @DS("udb")
    @PostMapping("/getAllRegionalPersonInCharge")
    @ApiOperation(value = "获取区域负责人数据")
    public ResultRespone<CollectionData<List<HashMap<String, Object>>>> getAllRegionalPersonInChargeList() {
        return getListResult(UserRoleEnum.RegionalPersonInCharge);
    }

    /**
     * 公用提取枚举方法
     *
     * @param userRoleEnum 用户角色枚举
     * @return 结果相应集
     */
    @DS("udb")
    private ResultRespone<CollectionData<List<HashMap<String, Object>>>> getListResult(UserRoleEnum userRoleEnum) {
        List<HashMap<String, Object>> rs = commonMapper.getUserListByRoleId(userRoleEnum);
        return ResultRespone.success(new CollectionData(rs, rs.size()));
    }

    @DS("udb")
    @PostMapping("/getAllOperater")
    @ApiOperation(value = "获取操作人员数据")
    public ResultRespone<CollectionData<List<HashMap<String, Object>>>> getAllOperater() {
        List<HashMap<String, Object>> rs = commonMapper.getAllOperater();
        return ResultRespone.success(new CollectionData(rs, rs.size()));
    }
}
