package com.njzscloud.dispose.sys.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.dispose.sys.district.pojo.entity.DistrictEntity;
import com.njzscloud.dispose.sys.district.pojo.param.SearchDistrictParam;
import com.njzscloud.dispose.sys.district.service.DistrictService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 省市区表
 */
@Slf4j
@RestController
@RequestMapping("/district")
@RequiredArgsConstructor
public class DistrictController {
    private final DistrictService districtService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public R<?> add(@RequestBody DistrictEntity districtEntity) {
        districtService.add(districtEntity);
        return R.success();
    }

    /**
     * 修改
     */
    @PostMapping("/modify")
    public R<?> modify(@RequestBody DistrictEntity districtEntity) {
        districtService.modify(districtEntity);
        return R.success();
    }

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

    /**
     * 详情
     */
    @GetMapping("/detail")
    public R<DistrictEntity> detail(@RequestParam("id") Long id) {
        return R.success(districtService.detail(id));
    }

    /**
     * 分页查询
     */
    @GetMapping("/paging")
    public R<PageResult<DistrictEntity>> paging(PageParam pageParam, SearchDistrictParam searchDistrictParam) {
        return R.success(districtService.paging(pageParam, searchDistrictParam));
    }

    /**
     * 查询所有
     */
    @GetMapping("/list")
    public R<List<DistrictEntity>> list(SearchDistrictParam searchDistrictParam) {
        return R.success(districtService.list(searchDistrictParam));
    }

}
