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.entity.property.PropertyFeeStandard;
import com.yuchen.saas.park.api.vo.property.*;
import com.yuchen.saas.park.service.service.property.IPropertyHouseBindFeeService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.NonNull;
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;
import java.util.Map;

/**
 * @Author 蔡文强
 * @Date 2023/11/28 10:56
 * @Description 房源绑定收费标准 前端控制器
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/propertyHouseBindFee")
public class PropertyHouseBindFeeController {

    @Resource
    private IPropertyHouseBindFeeService baseService;

    /**
     * 查询已绑定/未绑定收费标准房源树形结构
     * @param queryDto 房源树列表查询参数
     * @return TRUE/FALSE
     */
    @PostMapping("/getBindHouseTree")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "查询已绑定/未绑定收费标准房源树形结构", notes = "查询已绑定/未绑定收费标准房源树形结构")
    public R<PropertyHousesTreeVo> getBindHouseTree(@RequestBody PropertyBindHouseTreeQueryDto queryDto) {
        return R.data(baseService.getBindHouseTree(queryDto));
    }

    /**
     * 确认添加列表
     * @param confirmQueryDto 确认添加列表查询参数
     * @return TRUE/FALSE
     */
    @PostMapping("/getConfirmList")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "确认添加列表", notes = "确认添加列表")
    public R<Map<String, List<PropertyHouseBindFeeConfirmListVo>>> getConfirmList(@RequestBody @Validated PropertyHouseBindFeeConfirmQueryDto confirmQueryDto) {
        return R.data(baseService.getConfirmList(confirmQueryDto));
    }

    /**
     * 批量绑定收费标准
     * @param propertyHouseBindFeeDtoList 批量绑定收费标准DTO
     * @return TRUE/FALSE
     */
    @PostMapping("/bindBatch")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "批量绑定收费标准", notes = "批量绑定收费标准")
    public R<Boolean> bindBatch(@RequestBody @Validated List<PropertyHouseBindFeeDto> propertyHouseBindFeeDtoList) {
        return R.data(baseService.bindBatch(propertyHouseBindFeeDtoList));
    }

    /**
     * 查询收费标准列表
     * @param mapParam 查询收费标准列表查询参数
     * @return TRUE/FALSE
     */
    @PostMapping("/getFeeStandardList")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "查询收费项目收费标准列表", notes = "查询收费项目收费标准列表")
    public R<List<PropertyFeeStandardVo>> getFeeStandardList(@RequestBody Map<String, List<Long>> mapParam) {
        return R.data(baseService.getFeeStandardList(mapParam.get("houseIds")));
    }

    /**
     * 批量修改
     * @param updateDto 批量修改DTO
     * @return TRUE/FALSE
     */
    @PostMapping("/updateBatch")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "批量修改", notes = "批量修改")
    public R<Boolean> updateBatch(@RequestBody @Validated PropertyHouseBindFeeUpdateDto updateDto) {
        return R.data(baseService.updateBatch(updateDto));
    }

    /**
     * 批量解除列表
     * @param mapParam 批量解除列表查询参数
     * @return TRUE/FALSE
     */
    @PostMapping("/getRemoveList")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "批量解除列表", notes = "批量解除列表")
    public R<Map<String, List<PropertyHouseBindFeeListVo>>> getRemoveList(@RequestBody Map<String, List<Long>> mapParam) {
        return R.data(baseService.getRemoveList(mapParam.get("houseIds")));
    }

    /**
     * 批量解除
     * @param ids 主键集合
     * @return TRUE/FALSE
     */
    @DeleteMapping("/removeBatch")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "批量解除", notes = "批量解除")
    public R<PropertyRemoveBatchResVo> removeBatch(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.data(baseService.removeBatch(ids));
    }

    /**
     * 绑定详情
     * @param feeStandardId 收费标准ID
     * @return TRUE/FALSE
     */
    @GetMapping("/getBindDetail/{feeStandardId}")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "绑定详情", notes = "绑定详情")
    public R<PropertyHouseBindFeeBindDetailVo> getBindDetail(@ApiParam(name = "feeStandardId", value = "收费标准ID", required = true) @PathVariable("feeStandardId") Long feeStandardId) {
        return R.data(baseService.getBindDetail(feeStandardId));
    }

    /**
     * 绑定收费标准按收费项目汇总列表
     * @param queryDto 按收费项目汇总列表查询参数
     * @return TRUE/FALSE
     */
    @PostMapping("/getBindFeeSummaryList")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "绑定收费标准按收费项目汇总列表", notes = "绑定收费标准按收费项目汇总列表")
    public R<NestPage<PropertyHouseBindFeeSummaryListVo>> getBindFeeSummaryList(@RequestBody PropertyHouseBindFeeSummaryListQueryDto queryDto) {
        return R.data(baseService.getBindFeeSummaryList(queryDto));
    }

    /**
     * 导入房源绑定收费标准
     * @return page 分页数据
     */
    @PostMapping("/importHouseBindFee")
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "导入房源绑定收费标准", notes = "导入房源绑定收费标准")
    public void importHouseBindFee(@RequestParam("file") MultipartFile file) {
        baseService.importHouseBindFee(file);
    }

    /**
     * 导出房源绑定收费标准模版
     * @return page 分页数据
     */
    @GetMapping("/exportTemplate")
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "导出房源绑定收费标准模版", notes = "导出房源绑定收费标准模版")
    public void exportTemplate(HttpServletResponse response) {
        List<PropertyHouseBindFeeImportExcelVo> list = new ArrayList<>();
        ExcelUtil.export(response, "房源绑定收费标准模版", "房源绑定收费标准模版", list, PropertyHouseBindFeeImportExcelVo.class);
    }

    /**
     * 导出房源绑定收费标准
     * @return page 分页数据
     */
    @PostMapping("/exportHouseBindFee")
    @ApiOperationSupport(order = 9)
    @ApiOperation(value = "导出房源绑定收费标准", notes = "导出房源绑定收费标准")
    public void exportHouseBindFee(HttpServletResponse response, @RequestBody PropertyHouseBindFeeQueryDto queryDto) {
        baseService.exportHouseBindFee(response, queryDto);
    }

    /**
     * 房源绑定收费标准明细列表
     * @param queryDto 房源绑定收费标准明细列表查询参数
     * @return TRUE/FALSE
     */
    @PostMapping("/getHouseBindFeeList")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "房源绑定收费标准明细列表", notes = "房源绑定收费标准明细列表")
    public R<NestPage<PropertyHouseBindFeeListVo>> getHouseBindFeeList(@RequestBody PropertyHouseBindFeeQueryDto queryDto) {
        return R.data(baseService.getHouseBindFeeList(queryDto));
    }

    /**
     * 修改房源绑定收费标准
     * @param itemList 批量修改DTO
     * @return TRUE/FALSE
     */
    @PostMapping("/updateItem")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "修改房源绑定收费标准", notes = "修改房源绑定收费标准")
    public R<Boolean> updateItem(@RequestBody List<PropertyHouseBindFeeItemDto> itemList) {
        return R.data(baseService.updateItem(itemList));
    }

    @GetMapping("listByHouseId")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "获取房源绑定的收费标准", notes = "获取房源绑定的收费标准")
    public R<List<PropertyFeeStandard>> listByHouseId(@ApiParam(name = "houseId", value = "房源id", required = true) @NonNull @RequestParam Long houseId,
                                                      @ApiParam(name = "feeMark", value = "费用标识;费用标识：1-周期性收费，2-用量收费，3-数量收费，4-固定金额收费，5-指定金额收费", required = false)  @RequestParam Integer feeMark) {
        List<PropertyFeeStandard> list = baseService.listByHouseId(houseId,feeMark);
        return R.data(list);
    }

}
