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

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

    @Resource
    private IPropertyHouseResidentService baseService;

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

    /**
     * 编辑房产住户
     * @param houseResidentDto 房产住户Dto
     * @return TRUE/FALSE
     */
    @PostMapping("/updateHouseResident")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "编辑房产住户", notes = "编辑房产住户")
    public R<Boolean> updateHouseResident(@RequestBody @Validated PropertyHouseResidentDto houseResidentDto) {
        return R.data(baseService.saveOrUpdateHouseResident(houseResidentDto));
    }

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

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

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

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

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

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

}
