//package com.sckw.example.controller;
//
//import cn.hutool.core.lang.UUID;
//import com.alibaba.csp.sentinel.annotation.SentinelResource;
//import com.alibaba.fastjson2.JSON;
//import com.sckw.core.model.page.PageResult;
//import com.sckw.core.web.exceptionHandler.CustomBlockExceptionHandler;
//import com.sckw.core.web.response.HttpResult;
//import com.sckw.example.model.SysUser;
//import com.sckw.example.model.TestSensitive;
//import com.sckw.example.service.SysUserService;
//import com.sckw.stream.enums.SmsCodeEnum;
//import com.sckw.stream.model.SckwMessage;
//import com.sckw.stream.model.SckwSms;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.redisson.api.RBucket;
//import org.redisson.api.RedissonClient;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.cloud.stream.function.StreamBridge;
//import org.springframework.web.bind.annotation.*;
//
//import javax.annotation.Resource;
//import java.util.Date;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//@Slf4j
//@AllArgsConstructor
//@RestController
//@RequestMapping("/")
//public class SysUserController {
//
//    @Autowired
//    SysUserService sysUserService;
//
//    @Autowired
//    RedissonClient redissonClient;
//
//    /*@Autowired
//    RedisService redisService;*/
//
//    @GetMapping("index")
//    public Object test(){
//        Map result = new HashMap();
//        result.put("user", System.currentTimeMillis());
//        result.put("datatime", System.currentTimeMillis());
//        result.put("database", "redis");
//
//        RBucket<Object> mytest = redissonClient.getBucket("mytest");
//        mytest.set("value");
//        System.out.println(mytest.get());//value
//        mytest.set("value2");
//        System.out.println(mytest.get());//value2
//        boolean b = mytest.compareAndSet("value2", result); //true
//        System.out.println(mytest.get());//value3
//        Object resultObj = mytest.get();
//
//        /*result.put("type", "spring boot");
//        redisService.setCacheMap("value2", result);
//        resultObj = redisService.getCacheMap("value2");*/
//
//        return String.valueOf(resultObj);
//    }
//
//    //@Override
//    public String getUserInfo(String account) {
//        return account + String.valueOf(new Date());
//    }
//
//    @PostMapping("findByAccount")
//    public HttpResult findByAccount(HashMap params) {
//        List<SysUser> data = sysUserService.findByAccount(params);
//        return HttpResult.ok(data);
//    }
//
//    @PostMapping("findPage")
//    public HttpResult findPage(Map<String, Object> params) {
//        PageResult pageResult = sysUserService.findPage(params);
//        return HttpResult.ok(pageResult);
//    }
//
//
//    /**
//     * 限流测试示例
//     * @return
//     */
//    //value将该方法定义为sentinel的资源，blockHandlerClass指明流控处理的类，blockHandler是流控时调用的方法。
//    //这里需要注意处理异常的方法必须是静态方法添加static, 并需要添加sentinel的异常参数BlockException。
//    @RequestMapping(value = "sentinelFlowDemo", method = RequestMethod.GET)
//    @SentinelResource(value = "sentinelFlowDemo", blockHandlerClass = CustomBlockExceptionHandler.class, blockHandler = "sentinelFlowBlock")
//    public HttpResult sentinelFlowDemo() {
//        return HttpResult.ok("sentinelFlowDemo正常返回");
//    }
//
//    /**
//     * 熔断测试示例
//     * @param id
//     * @return
//     */
//    @RequestMapping(value = "sentinelDegradeDemo", method = RequestMethod.GET)
//    @SentinelResource(value = "sentinelDegradeDemo", blockHandlerClass = SysUserController.class, blockHandler = "sentinelDegradeBlock")
//    public HttpResult sentinelDegradeDemo(@RequestParam("id") String id) {
//        if ("2".equals(id)){
//            try {
//                Thread.sleep(5000);
//            } catch (InterruptedException e) {
//                throw new RuntimeException(e);
//            }
//        }
//        return HttpResult.ok("sentinelDegradeDemo正常返回");
//    }
//
////    /**
////     * 分布式事务示例
////     * @return
////     */
////    @GlobalTransactional
////    @RequestMapping(value = "/globalTransactionalDemo", method = RequestMethod.GET)
////    public HttpResult globalTransactionalDemo() {
////        return HttpResult.ok("globalTransactionalDemo");
////    }
//
//
//
//
//
//
//    @GetMapping("/testSensitive")
//    public HttpResult testSensitive() {
//        TestSensitive testSensitive = new TestSensitive();
//        testSensitive.setIdCard("210397198608215431");
//        testSensitive.setPhone("17640125371");
//        testSensitive.setAddress("北京市朝阳区某某四合院1203室");
//        testSensitive.setEmail("17640125371@163.com");
//        testSensitive.setBankCard("6226456952351452853");
//        return HttpResult.ok(testSensitive);
//    }
//
//    @Resource
//    private StreamBridge streamBridge;
//
//    @GetMapping("/pushMesg")
//    public HttpResult pushMesg() {
//        String uuid = UUID.fastUUID().toString();
//        SckwSms sckwSms = new SckwSms();
//        sckwSms.setPhone("17358629955");
//        sckwSms.setSignName("矿拉拉");
//        sckwSms.setTemplateCode(SmsCodeEnum.VERIFICATION_CODE);
//        sckwSms.setParams(new HashMap(){{put("code", "123456");}});
//        streamBridge.send("sckw-sms", JSON.toJSONString(sckwSms));
//
//
//        SckwMessage message = new SckwMessage();
//        //person.setName(String.valueOf(System.currentTimeMillis()));
//        message.setMsgUrl("---");
//        message.setPushType("====");
//        message.setClientId("111111111111111");
//        streamBridge.send("sckw-message", JSON.toJSONString(message));
//
//        return HttpResult.ok(uuid);
//    }
//
//    @GetMapping("/pushSms")
//    public HttpResult pushSms() {
//        TestSensitive testSensitive = new TestSensitive();
//        testSensitive.setIdCard("210397198608215431");
//        testSensitive.setPhone("17640125371");
//        testSensitive.setAddress("北京市朝阳区某某四合院1203室");
//        testSensitive.setEmail("17640125371@163.com");
//        testSensitive.setBankCard("6226456952351452853");
//        return HttpResult.ok(testSensitive);
//    }
//}
