package com.ruoyi.web.controller.system;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.domain.dto.villageCommitteeRole.VillageCommitteeRoleUserAddRequest;
import com.ruoyi.web.domain.dto.villageCommitteeRole.VillageCommitteeRoleUserEditRequest;
import com.ruoyi.web.domain.dto.villageCommitteeRole.VillageCommitteeRoleUserQueryRequest;
import com.ruoyi.web.domain.vo.VillageCommitteeRoleUserVO;
import com.ruoyi.web.service.VillageCommitteeRoleUserService;
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.List;
import java.util.Map;

import static com.ruoyi.common.core.domain.AjaxResult.error;
import static com.ruoyi.common.core.domain.AjaxResult.success;

@Api(tags = "村委管理")
@RestController
@RequestMapping("/system/village/committee/role/user")
public class VillageCommitteeRoleUserController {

    @Autowired
    private VillageCommitteeRoleUserService villageCommitteeRoleUserService;

    /**
     * 添加村委
     *
     * @param villageCommitteeRoleUserAddRequest
     * @return
     */
    @ApiOperation("添加村委")
    @PostMapping("/add")
    public AjaxResult addVillageCommitteeRoleUser(@RequestBody VillageCommitteeRoleUserAddRequest villageCommitteeRoleUserAddRequest) {
        if (villageCommitteeRoleUserAddRequest == null) {
            return error("请求参数为空");
        }
        Integer id = villageCommitteeRoleUserService.addVillageCommitteeRoleUser(villageCommitteeRoleUserAddRequest);
        return success(id);
    }

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


    /**
     * 编辑村委
     *
     * @param villageCommitteeRoleUserEditRequest
     * @return
     */
    @ApiOperation("编辑村委")
    @PostMapping("/edit")
    public AjaxResult editVillageCommitteeRoleUser(@RequestBody VillageCommitteeRoleUserEditRequest villageCommitteeRoleUserEditRequest) {
        if (villageCommitteeRoleUserEditRequest == null) {
            return error("请求参数为空");
        }
        villageCommitteeRoleUserService.editVillageCommitteeRoleUser(villageCommitteeRoleUserEditRequest);
        return AjaxResult.success();
    }


    /**
     * 根据id获取村委
     *
     * @param id
     * @return
     */
    @ApiOperation("根据id获取村委")
    @GetMapping("/get")
    public AjaxResult getVillageCommitteeRoleUserById(@RequestParam int id) {
        if (ObjectUtil.isEmpty(id)) {
            return error("请求参数为空");
        }
        VillageCommitteeRoleUserVO villageCommitteeRoleUserVO = villageCommitteeRoleUserService.getVillageCommitteeRoleUserVOById(id);
        return success(villageCommitteeRoleUserVO);
    }

    /**
     * 获取村委列表
     *
     * @param villageCommitteeRoleUserQueryRequest
     * @return
     */
    @ApiOperation("获取村委列表")
    @PostMapping("/list")
    public AjaxResult getListVillageCommitteeRoleUser(@RequestBody VillageCommitteeRoleUserQueryRequest villageCommitteeRoleUserQueryRequest) {
        if (villageCommitteeRoleUserQueryRequest == null) {
            return error("请求参数为空");
        }
        List<VillageCommitteeRoleUserVO> listVillageCommitteeRoleUserVO = villageCommitteeRoleUserService.getListVillageCommitteeRoleUserVO(villageCommitteeRoleUserQueryRequest);
        return success(listVillageCommitteeRoleUserVO);
    }

}
