package com.fdkankan.ucenter.controller;

import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.fdkankan.common.util.Base64Converter;
import com.fdkankan.common.util.FileUtils;
import com.fdkankan.common.util.JwtUtil;
import com.fdkankan.common.util.SecurityUtil;
import com.fdkankan.fyun.face.FYunFileServiceInterface;
import com.fdkankan.redis.constant.RedisKey;
import com.fdkankan.redis.util.RedisUtil;
import com.fdkankan.sign.RsaUtils;
import com.fdkankan.sms.SmsService;
import com.fdkankan.ucenter.common.*;
import com.fdkankan.ucenter.entity.*;
import com.fdkankan.ucenter.service.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.*;

@RestController
@Slf4j
@RequestMapping("/ucenter/test")
public class TestController extends BaseController {

    @Autowired
    IAppSecretService appSecretService;

    //@GetMapping("/createPublicKeyAndPrivate/{size}")
    public ResultData createPublicKeyAndPrivate(@PathVariable Integer size){
        for (int i = 0 ; i <size;i++){
            com.fdkankan.sign.RsaUtils.KeyPairInfo keyPair = com.fdkankan.sign.RsaUtils.getKeyPair();
            String publicKey = keyPair.getPublicKey();
            String privateKey = keyPair.getPrivateKey();

            AppSecret appSecret = new AppSecret();
            appSecret.setPublicKey(publicKey);
            appSecret.setPrivateKey(privateKey);
            appSecretService.save(appSecret);
        }
        return ResultData.ok();
    }


    @Autowired
    IFolderService folderService;
    @Autowired
    IFolderSceneService folderSceneService;
    @Autowired
    IScenePlusService scenePlusService;
    @Autowired
    ISceneProService sceneProService;


    @GetMapping("/updateFolder")
    public ResultData updateFolder(){
        LambdaQueryWrapper<Folder> wrapper = new LambdaQueryWrapper<>();
        wrapper.isNotNull(Folder::getLaserParentId);
        List<Folder> list = folderService.list(wrapper);

        HashMap<Long,Long> map = new HashMap<>();
        for (Folder folder : list) {
            map.put(folder.getLaserId(),folder.getId());
        }
        for (Folder folder : list) {
            Long newParentId = map.get(folder.getLaserParentId());
            if(newParentId == null){
                continue;
            }
            LambdaUpdateWrapper<Folder> updateWrapper = new LambdaUpdateWrapper<>();
            updateWrapper.eq(Folder::getId,folder.getId());
            updateWrapper.set(Folder::getParentId,newParentId);
            folderService.update(updateWrapper);
        }

        return ResultData.ok();
    }

    @GetMapping("/updateFolderScene")
    public ResultData updateFolderScene(){
//        List<FolderScene> list = folderSceneService.list();
//        for (FolderScene folderScene : list) {
//            String num = null;
//            ScenePro scenePro = sceneProService.getById(folderScene.getSceneId());
//            if(scenePro !=null){
//                num = scenePro.getNum();
//            }else {
//                ScenePlus scenePlus = scenePlusService.getById(folderScene.getSceneId());
//                if(scenePlus != null){
//                    num = scenePlus.getNum();
//                }
//            }
//
//            LambdaUpdateWrapper<FolderScene> wrapper = new LambdaUpdateWrapper<>();
//            wrapper.eq(FolderScene::getId,folderScene.getId());
//            wrapper.set(FolderScene::getNum,num);
//            folderSceneService.update(wrapper);
//        }

        return ResultData.ok();
    }


}
