package fcb.project.manager.core.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import fcb.project.manager.base.entity.*;
import fcb.project.manager.base.enums.*;
import fcb.project.manager.base.param.house.QueryHouseParam;
import fcb.project.manager.base.service.ITmApiRoomIdLogService;
import fcb.project.manager.base.service.custom.PanoService;
import fcb.project.manager.base.service.impl.*;
import fcb.project.manager.base.utils.DataUtils;
import fcb.project.manager.base.utils.DateUtil;
import fcb.project.manager.base.utils.ExcelUtil;
import fcb.project.manager.base.vo.house.HouseVO;
import fcb.project.manager.core.feignInterfaces.SceneFeign;
import fdage.back.sdk.base.entity.Result;
import fdage.back.sdk.base.entity.ViewResult;
import fdage.back.sdk.base.enums.ResultCodeEnum;
import fdage.back.sdk.base.exception.CommonBaseException;
import fdage.back.sdk.base.uuid.SnowFlakeUUidUtils;
import fdage.back.sdk.core.alibabaUtils.AlibabaOssHelper;
import io.swagger.annotations.*;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * 2 * @Author: Abner
 * 3 * @Date: 2021/1/7 17:38
 * 4
 */
@Api(tags = "房源相关接口")
@RestController
@RequestMapping("fcb/project/roomid")
@Log4j2
@Validated
public class RoomIdController extends BaseController{

    @Autowired
    private ITmApiRoomIdLogService iTmApiRoomIdLogService;

    @GetMapping("/save")
    @ApiOperation("获取20位随机数")
    public Result save() {

        TmApiRoomIdLog tmApiRoomIdLog = new TmApiRoomIdLog();
        tmApiRoomIdLog.setLogId(SnowFlakeUUidUtils.generaUUid(null , null ,  UuidPreEnum.API_ROOM_ID_PRE.getPre()));
        tmApiRoomIdLog.setCommunicateRoomId(DateUtil.randonNum());
        tmApiRoomIdLog.setEnable(1);
        tmApiRoomIdLog.setCreateTime(LocalDateTime.now());
        tmApiRoomIdLog.setUpdateTime(LocalDateTime.now());

        boolean bool = iTmApiRoomIdLogService.save(tmApiRoomIdLog);

        if(bool){
            return Result.success(tmApiRoomIdLog);
        }else{
            return Result.failure("保存失败");
        }
    }




    @PostMapping("/update")
    @ApiOperation("改")
    public Result update(@RequestBody TmApiRoomIdLog tmApiRoomIdLog) {

        if (null == tmApiRoomIdLog) {
            return Result.failure("信息不能为空");
        }
        if (null == tmApiRoomIdLog.getCommunicateRoomId()) {
            log.info("房间ID不能为空，无法更新房间信息");
            return Result.failure("房间ID不能为空，无法更新房间信息");
        }

        LambdaQueryWrapper<TmApiRoomIdLog> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(TmApiRoomIdLog::getCommunicateRoomId,tmApiRoomIdLog.getCommunicateRoomId());
        tmApiRoomIdLog.setEnable(0);
        iTmApiRoomIdLogService.update(tmApiRoomIdLog,lambdaQueryWrapper);

        return Result.success();
    }

    @PostMapping("/select")
    @ApiOperation("查")
    public Result select(@RequestBody TmApiRoomIdLog tmApiRoomIdLog) {

        LambdaQueryWrapper<TmApiRoomIdLog> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(TmApiRoomIdLog::getCommunicateRoomId,tmApiRoomIdLog.getCommunicateRoomId());
        lambdaQueryWrapper.last("limit 1");
        tmApiRoomIdLog.setUpdateTime(LocalDateTime.now());

        return Result.success(iTmApiRoomIdLogService.getBaseMapper().selectList(lambdaQueryWrapper));
    }



}
