package com.boman.web.core.controller;

import com.boman.common.core.utils.SecurityUtils;
import com.boman.common.datascope.annotation.DataScope;
import com.boman.domain.SysDept;
import com.boman.domain.dto.AjaxResult;
import com.boman.web.core.domain.AdministrativeInfo;
import com.boman.web.core.service.vaccineInfo.AdministrativeInfoService;
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 javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author tjf
 * @Date: 2021/09/05/13:21
 */
@RestController
@RequestMapping("/administrativeInfo")
public class AdministrativeInfoController {

    @Resource
    private AdministrativeInfoService administrativeInfoService;
    /**
     * 获取乡镇列表,其实就是部门列表
     */
    @GetMapping("/treeSelect")
    public AjaxResult treeSelect(AdministrativeInfo administrativeInfo)
    {
        List<AdministrativeInfo> administrativeInfos = administrativeInfoService.selectAdministrativeInfoList(administrativeInfo);
        return AjaxResult.success(administrativeInfoService.buildAdministrativeInfoTreeSelect(administrativeInfos));
    }


    /**
     * 获取乡镇列表,其实就是部门列表,只到村
     */
    @GetMapping("/treeSelectVillage")
    public AjaxResult treeSelectVillage(AdministrativeInfo administrativeInfo)
    {
        List<AdministrativeInfo> administrativeInfos = administrativeInfoService.selectAdministrativeInfoList(administrativeInfo);
        List<AdministrativeInfo> collect = administrativeInfos.stream().filter(e -> e.getAncestors().split(",").length < 3).collect(Collectors.toList());
        return AjaxResult.success(administrativeInfoService.buildAdministrativeInfoTreeSelect(collect));
    }
}
