package com.ruoyi.web.controller.system;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.domain.dto.VillageProfile.VillageProfileAddRequest;
import com.ruoyi.web.domain.dto.VillageProfile.VillageProfileEditRequest;
import com.ruoyi.web.domain.dto.VillageProfile.VillageProfileQueryRequest;
import com.ruoyi.web.domain.vo.VillageProfileVO;
import com.ruoyi.web.service.VillageProfileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 村庄概况信息Controller
 */
@RestController
@RequestMapping("/system/village/profile")
@Api(tags ="村庄概况信息管理")
public class VillageProfileController extends BaseController {

    @Autowired
    private VillageProfileService villageProfileService;

    /**
     * 添加村庄
     *
     * @param villageProfileAddRequest
     * @return
     */
    @ApiOperation("添加村庄")
    @PostMapping("/add")
    public AjaxResult addVillageProfile(@RequestBody VillageProfileAddRequest villageProfileAddRequest) {
        if (villageProfileAddRequest == null) {
            return error("请求参数为空");
        }
        Integer id = villageProfileService.addVillageProfile(villageProfileAddRequest);
        return success(id);
    }

    /**
     * 删除村庄
     *
     * @param paramsMap
     * @return
     */
    @ApiOperation("删除村庄")
    @PostMapping("/delete")
    public AjaxResult deleteVillageProfile(@RequestBody Map<String, String> paramsMap) {
        String ids = paramsMap.get("ids");
        if (StrUtil.isBlank(ids)) {
            return error("请求参数为空");
        }
        boolean b = villageProfileService.deleteVillageProfile(ids);
        if (b) {
            return success("删除成功");
        }
        return error("删除失败");
    }


    /**
     * 编辑村庄
     *
     * @param villageProfileEditRequest
     * @return
     */
    @ApiOperation("编辑村庄")
    @PostMapping("/edit")
    public AjaxResult editVillageProfile(@RequestBody VillageProfileEditRequest villageProfileEditRequest) {
        if (villageProfileEditRequest == null) {
            return error("请求参数为空");
        }
        villageProfileService.editVillageProfile(villageProfileEditRequest);
        return AjaxResult.success();
    }


    /**
     * 根据id获取村庄
     *
     * @param id
     * @return
     */
    @ApiOperation("根据id获取村庄")
    @GetMapping("/get")
    public AjaxResult getVillageProfileById(@RequestParam int id) {
        if (ObjectUtil.isEmpty(id)) {
            return error("请求参数为空");
        }
        VillageProfileVO villageProfileById = villageProfileService.getVillageProfileById(id);
        return success(villageProfileById);
    }

    /**
     * 分页获取村庄列表
     *
     * @param villageProfileQueryRequest
     * @return
     */
    @ApiOperation("分页获取村庄列表")
    @PostMapping("/list/page")
    public AjaxResult listVillageProfileByPage(@RequestBody VillageProfileQueryRequest villageProfileQueryRequest) {
        if (villageProfileQueryRequest == null) {
            return error("请求参数为空");
        }
        Page<VillageProfileVO> listVillageProfileByPageVO = villageProfileService.getListVillageProfileByPage(villageProfileQueryRequest);
        return success(listVillageProfileByPageVO);
    }
} 