package com.yuchen.saas.park.service.controller.property;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.dto.property.PropertyCommitteeMemberDto;
import com.yuchen.saas.park.api.dto.property.PropertyCommitteeMemberQueryDto;
import com.yuchen.saas.park.api.vo.property.*;
import com.yuchen.saas.park.service.service.property.IPropertyCommitteeMemberService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nest.springwrap.core.excel.util.ExcelUtil;
import org.nest.springwrap.core.mp.support.NestPage;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author 蔡文强
 * @Date 2023/11/28 10:56
 * @Description 委员会成员表 前端控制器
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/propertyCommitteeMember")
public class PropertyCommitteeMemberController {

    @Resource
    private IPropertyCommitteeMemberService baseService;

    /**
     * 添加委员会成员
     * @param committeeMemberDto 委员会成员Dto
     * @return TRUE/FALSE
     */
    @PostMapping("/saveCommitteeMember")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "添加委员会成员", notes = "添加委员会成员")
    public R<Boolean> saveCommitteeMember(@RequestBody @Validated PropertyCommitteeMemberDto committeeMemberDto) {
        return R.data(baseService.saveOrUpdateCommitteeMember(committeeMemberDto));
    }

    /**
     * 编辑委员会成员
     * @param committeeMemberDto 委员会成员Dto
     * @return TRUE/FALSE
     */
    @PostMapping("/updateCommitteeMember")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "编辑委员会成员", notes = "编辑委员会成员")
    public R<Boolean> updateCommitteeMember(@RequestBody @Validated PropertyCommitteeMemberDto committeeMemberDto) {
        return R.data(baseService.saveOrUpdateCommitteeMember(committeeMemberDto));
    }

    /**
     * 删除委员会成员
     * @param id 委员会成员ID
     * @return TRUE/FALSE
     */
    @DeleteMapping("/deleteCommitteeMember/{id}")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "删除委员会成员", notes = "删除委员会成员")
    public R<Boolean> deleteCommitteeMember(@ApiParam(name = "id", value = "主键ID", required = true) @PathVariable("id") Long id) {
        return R.data(baseService.deleteCommitteeMember(id));
    }

    /**
     * 委员会成员详情
     * @param id 委员会成员ID
     * @return 委员会成员详情Vo
     */
    @GetMapping("/getCommitteeMemberById/{id}")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "委员会成员详情", notes = "委员会成员详情")
    public R<PropertyCommitteeMemberVo> getCommitteeMemberById(@ApiParam(name = "id", value = "主键ID", required = true) @PathVariable("id") Long id) {
        return R.data(baseService.getCommitteeMemberById(id));
    }

    /**
     * 委员会成员列表(分页)
     * @param queryDto 委员会成员列表查询参数
     * @return 委员会成员列表Vo
     */
    @PostMapping("/getCommitteeMemberPageList")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "委员会成员列表(分页)", notes = "委员会成员列表(分页)")
    public R<NestPage<PropertyCommitteeMemberListVo>> getCommitteeMemberPageList(@RequestBody PropertyCommitteeMemberQueryDto queryDto) {
        return R.data(baseService.getCommitteeMemberPageList(queryDto));
    }

    /**
     * 导入委员会成员
     * @return page 分页数据
     */
    @PostMapping("/importCommitteeMember")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "导入委员会成员", notes = "导入委员会成员")
    public R<PropertyCommitteeMemberImportResVo> importCommitteeMember(@RequestParam("file") MultipartFile file) {
        return R.data(baseService.importCommitteeMember(file));
    }

    /**
     * 导出委员会成员模板
     * @return page 分页数据
     */
    @GetMapping("/exportTemplate")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "导出委员会成员模板", notes = "导出委员会成员模板")
    public void exportTemplate(HttpServletResponse response) {
        List<PropertyCommitteeMemberImportExcelVo> list = new ArrayList<>();
        ExcelUtil.export(response, "委员会成员模板", "委员会成员模板", list, PropertyCommitteeMemberImportExcelVo.class);
    }

    /**
     * 导出委员会成员
     * @return page 分页数据
     */
    @PostMapping("/exportCommitteeMember")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "导出委员会成员", notes = "导出委员会成员")
    public void exportCommitteeMember(@RequestBody PropertyCommitteeMemberQueryDto queryDto, HttpServletResponse response) {
        baseService.exportCommitteeMember(queryDto, response);
    }

}
