package com.dayou.controller;

import com.dayou.vo.DistrictsTreeVO;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.RestController;
import com.dayou.controller.BaseController;
import com.dayou.service.IDistrictsService;
import com.dayou.entity.Districts;
import com.dayou.common.RestResponse;
import org.springframework.web.bind.annotation.*;
import com.dayou.common.PullDownModel;
import com.dayou.utils.ConvertUtil;
import com.dayou.utils.HttpKit;
import com.dayou.exception.ErrorCode;
import java.util.Date;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.http.MediaType;
import org.springframework.web.multipart.MultipartFile;
/**
 * 地区
 *
 * @author wucl
 * @since 2023-01-10
 */
@RestController
@RequestMapping("districts")
@Slf4j
public class DistrictsController extends BaseController {
    @Autowired
    private IDistrictsService districtsService;

    /**
    * 地区列表
    */
    @GetMapping("")
    public RestResponse<Page<Districts>> page(Districts districts, Page page){
        Page<Districts> pages=districtsService.selectPage(page,districts);
        return RestResponse.data(pages);
    }

    /**
     * 地区详情
     */
    @GetMapping("/{id}")
    public RestResponse<Districts> detail(@PathVariable Long id){
        Districts xDistricts =districtsService.detail(id);
        return RestResponse.data(xDistricts);
     }


    /**
     * 地区下拉列表
     */
    @GetMapping("/simpleAll")
    public RestResponse<List<PullDownModel>> simpleAll(){
        LambdaQueryWrapper<Districts> lambdaQueryWrapper = new LambdaQueryWrapper<Districts>()
        .select(Districts::getId,Districts::getName);
        List<Districts> list= districtsService.list(lambdaQueryWrapper);
        List<PullDownModel> ret=ConvertUtil.copyList(list, PullDownModel.class);
        return RestResponse.data(ret);
    }

    @GetMapping("/tree")
    public RestResponse<List<DistrictsTreeVO>> getDistrictsTree(){
        List<DistrictsTreeVO> result = districtsService.getDistrictsTree();
        return RestResponse.data(result);
    }
}

