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

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.dto.property.*;
import com.yuchen.saas.park.api.vo.property.*;
import com.yuchen.saas.park.service.service.property.IPropertyHouseOwnerService;
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("/propertyHouseOwner")
public class PropertyHouseOwnerController {

    @Resource
    private IPropertyHouseOwnerService baseService;

    /**
     * 添加房产业主
     * @param houseOwnerDto 房产业主Dto
     * @return TRUE/FALSE
     */
    @PostMapping("/saveHouseOwner")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "添加房产业主", notes = "添加房产业主")
    public R<Boolean> saveHouseOwner(@RequestBody @Validated PropertyHouseOwnerDto houseOwnerDto) {
        return R.data(baseService.saveHouseOwner(houseOwnerDto));
    }

    /**
     * 编辑房产业主
     * @param houseOwnerDto 房产业主Dto
     * @return TRUE/FALSE
     */
    @PostMapping("/updateHouseOwner")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "编辑房产业主", notes = "编辑房产业主")
    public R<Boolean> updateHouseOwner(@RequestBody @Validated PropertyHouseOwnerDto houseOwnerDto) {
        return R.data(baseService.updateHouseOwner(houseOwnerDto));
    }

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

    /**
     * 房产业主详情
     * @param id 房产业主ID
     * @return 房产业主详情Vo
     */
    @GetMapping("/getHouseOwnerById/{id}")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "房产业主详情", notes = "房产业主详情")
    public R<PropertyHouseOwnerVo> getHouseOwnerById(@ApiParam(name = "id", value = "主键ID", required = true) @PathVariable("id") Long id) {
        return R.data(baseService.getHouseOwnerById(id));
    }

    /**
     * 房产业主列表(分页)
     * @param queryDto 房产业主列表查询参数
     * @return 房产业主列表Vo
     */
    @PostMapping("/getHouseOwnerPageList")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "房产业主列表(分页)", notes = "房产业主列表(分页)")
    public R<NestPage<PropertyHouseOwnerListVo>> getHouseOwnerPageList(@RequestBody PropertyHouseOwnerQueryDto queryDto) {
        return R.data(baseService.getHouseOwnerPageList(queryDto));
    }

    /**
     * 导入房产业主
     * @return page 分页数据
     */
    @PostMapping("/importHouseOwner")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "导入房产业主", notes = "导入房产业主")
    public R<PropertyHouseOwnerImportResVo> importHouseOwner(@RequestParam("file") MultipartFile file) {
        return R.data(baseService.importHouseOwner(file));
    }

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

    /**
     * 导出房产业主
     * @return page 分页数据
     */
    @PostMapping("/exportHouseOwner")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "导出房产业主", notes = "导出房产业主")
    public void exportHouseOwner(@RequestBody PropertyHouseOwnerQueryDto queryDto, HttpServletResponse response) {
        baseService.exportHouseOwner(queryDto, response);
    }

}
