package com.njzscloud.supervisory.district.controller;

import com.njzscloud.common.core.utils.R;
import com.njzscloud.common.mp.support.PageParam;
import com.njzscloud.common.mp.support.PageResult;
import com.njzscloud.supervisory.district.pojo.DistrictTreeResult;
import com.njzscloud.supervisory.district.pojo.SysDistrictEntity;
import com.njzscloud.supervisory.district.service.SysDistrictService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 省市区表
 */
@Slf4j
@RestController
@RequestMapping("/sys_district")
@RequiredArgsConstructor
public class SysDistrictController {

    private final SysDistrictService sysDistrictService;

    /**
     * 新增
     *
     * @param sysDistrictEntity 数据
     */
    @PostMapping("/add")
    public R<?> add(@RequestBody SysDistrictEntity sysDistrictEntity) {
        sysDistrictService.add(sysDistrictEntity);
        return R.success();
    }

    /**
     * 修改
     *
     * @param sysDistrictEntity 数据
     */
    @PostMapping("/modify")
    public R<?> modify(@RequestBody SysDistrictEntity sysDistrictEntity) {
        sysDistrictService.modify(sysDistrictEntity);
        return R.success();
    }

    /**
     * 删除
     *
     * @param ids Ids
     */
    @PostMapping("/del")
    public R<?> del(@RequestBody List<Long> ids) {
        sysDistrictService.del(ids);
        return R.success();
    }

    /**
     * 详情
     *
     * @param id Id
     * @return SysDistrictEntity 结果
     */
    @GetMapping("/detail")
    public R<SysDistrictEntity> detail(@RequestParam Long id) {
        return R.success(sysDistrictService.detail(id));
    }

    /**
     * 分页查询
     *
     * @param sysDistrictEntity 筛选条件
     * @param pageParam         分页参数
     * @return PageResult&lt;SysDistrictEntity&gt; 分页结果
     */
    @GetMapping("/paging")
    public R<PageResult<SysDistrictEntity>> paging(PageParam pageParam, SysDistrictEntity sysDistrictEntity) {
        return R.success(sysDistrictService.paging(pageParam, sysDistrictEntity));
    }

    @GetMapping("/tree")
    public R<List<DistrictTreeResult>> tree() {
        return R.success(sysDistrictService.tree());
    }

}
