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

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.dto.property.PropertyEnterpriseMemberDto;
import com.yuchen.saas.park.api.dto.property.PropertyEnterpriseMemberQueryDto;
import com.yuchen.saas.park.api.dto.property.PropertyEnterpriseMemberSyncDto;
import com.yuchen.saas.park.api.vo.property.*;
import com.yuchen.saas.park.service.service.property.IPropertyEnterpriseMemberService;
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("/propertyEnterpriseMember")
public class PropertyEnterpriseMemberController {

    @Resource
    private IPropertyEnterpriseMemberService baseService;

    /**
     * 添加入驻企业成员
     * @param enterpriseMemberDto 入驻企业成员Dto
     * @return TRUE/FALSE
     */
    @PostMapping("/saveEnterpriseMember")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "添加入驻企业成员", notes = "添加入驻企业成员")
    public R<Boolean> saveEnterpriseMember(@RequestBody @Validated PropertyEnterpriseMemberDto enterpriseMemberDto) {
        return R.data(baseService.saveOrUpdateEnterpriseMember(enterpriseMemberDto));
    }

    /**
     * 编辑入驻企业成员
     * @param enterpriseMemberDto 入驻企业成员Dto
     * @return TRUE/FALSE
     */
    @PostMapping("/updateEnterpriseMember")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "编辑入驻企业成员", notes = "编辑入驻企业成员")
    public R<Boolean> updateEnterpriseMember(@RequestBody @Validated PropertyEnterpriseMemberDto enterpriseMemberDto) {
        return R.data(baseService.saveOrUpdateEnterpriseMember(enterpriseMemberDto));
    }

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

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

    /**
     * 入驻企业成员列表(分页)
     * @param queryDto 入驻企业成员列表查询参数
     * @return 入驻企业成员列表Vo
     */
    @PostMapping("/getEnterpriseMemberPageList")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "入驻企业成员列表(分页)", notes = "入驻企业成员列表(分页)")
    public R<NestPage<PropertyEnterpriseMemberListVo>> getEnterpriseMemberPageList(@RequestBody PropertyEnterpriseMemberQueryDto queryDto) {
        return R.data(baseService.getEnterpriseMemberPageList(queryDto));
    }

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

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

    /**
     * 导出入驻企业成员
     * @return page 分页数据
     */
    @PostMapping("/exportEnterpriseMember")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "导出入驻企业成员", notes = "导出入驻企业成员")
    public void exportEnterpriseMember(@RequestBody PropertyEnterpriseMemberQueryDto queryDto, HttpServletResponse response) {
        baseService.exportEnterpriseMember(queryDto, response);
    }

    /**
     * 同步组织成员
     * @param syncDto 同步组织成员Dto
     * @return TRUE/FALSE
     */
    @PostMapping("/syncEnterpriseMember")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "同步组织成员", notes = "同步组织成员")
    public R<Long> syncEnterpriseMember(@RequestBody @Validated PropertyEnterpriseMemberSyncDto syncDto) {
        return R.data(baseService.syncEnterpriseMember(syncDto));
    }

}
