package com.ruoyi.web.controller.common;

import com.google.common.collect.Lists;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.AccessFromType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.syzy.service.IBBusiWishUniversitySubmitMarjorsService;
import com.ruoyi.voluntary.domain.BusiCards;
import com.ruoyi.voluntary.domain.BusiSchools;
import com.ruoyi.voluntary.domain.SysLocations;
import com.ruoyi.voluntary.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 位置编码Controller
 *
 * @author mingxue
 * @date 2021-06-12
 */
@Api(tags = "前端 位置编码")
@RestController
@RequestMapping("/mingxue/SysLocations")
public class SysLocationsController extends BaseController
{
    @Autowired
    private ISysLocationsService sysLocationsService;
    @Autowired
    private IBusiCardsService cardsService;
    @Autowired
    private IBusiSchoolsService schoolsService;
    @Autowired
    private ISysConfigService configService;

    /**
     * 查询位置编码列表
     */
    @ApiOperation("查询位置编码")
    @GetMapping("/getLocationsList")
    public AjaxResult getLocationsList(SysLocations sysLocations)
    {
        boolean provLevel = null != sysLocations.getParentId() && sysLocations.getParentId() == 1 ||
                null != sysLocations.getLevel() && sysLocations.getLevel() == 1;
        List<SysLocations> list = sysLocationsService.selectSysLocationsList(sysLocations);
        if (provLevel) {
            String[] strArray = configService.selectConfigByKey("system.open.province").split(",");
            List<String> locations = Arrays.asList(strArray);
            list = list.stream().filter(l -> locations.contains(l.getSname())).collect(Collectors.toList());
        }
        return AjaxResult.success(list);
    }
}
