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

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.dto.property.PropertyEnterpriseAddressListQueryDto;
import com.yuchen.saas.park.api.dto.property.PropertyHouseEnterpriseDto;
import com.yuchen.saas.park.api.dto.property.PropertyHouseEnterpriseQueryDto;
import com.yuchen.saas.park.api.vo.property.*;
import com.yuchen.saas.park.service.service.property.IPropertyHouseEnterpriseService;
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("/propertyHouseEnterprise")
public class PropertyHouseEnterpriseController {

    @Resource
    private IPropertyHouseEnterpriseService baseService;

    /**
     * 添加入驻企业
     * @param enterpriseDto 入驻企业Dto
     * @return TRUE/FALSE
     */
    @PostMapping("/saveHouseEnterprise")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "添加入驻企业", notes = "添加入驻企业")
    public R<Boolean> saveorUpdateHouseEnterprise(@RequestBody @Validated PropertyHouseEnterpriseDto enterpriseDto) {
        return R.data(baseService.saveorUpdateHouseEnterprise(enterpriseDto));
    }

    /**
     * 编辑入驻企业
     * @param enterpriseDto 入驻企业Dto
     * @return TRUE/FALSE
     */
    @PostMapping("/updateHouseEnterprise")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "编辑入驻企业", notes = "编辑入驻企业")
    public R<Boolean> updateHouseEnterprise(@RequestBody @Validated PropertyHouseEnterpriseDto enterpriseDto) {
        return R.data(baseService.saveorUpdateHouseEnterprise(enterpriseDto));
    }

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

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

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

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

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

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

    /**
     * 小程序企业端->企业入驻园区列表(分页)
     * @param queryDto 企业入驻园区列表查询参数
     * @return 企业入驻园区列表Vo
     */
    @PostMapping("/getEnterpriseAddressList")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "小程序企业端->企业入驻园区列表(分页)", notes = "小程序企业端->企业入驻园区列表(分页)")
    public R<NestPage<PropertyEnterpriseAddressListVo>> getEnterpriseAddressList(@RequestBody PropertyEnterpriseAddressListQueryDto queryDto) {
        return R.data(baseService.getEnterpriseAddressList(queryDto));
    }


}
