package org.example.websocket.controller;
|
|
import cn.hutool.core.date.DateUtil;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import org.example.common.ServerResponse;
|
import org.example.dao.DataServiceKeyMapper;
|
import org.example.pojo.DataServiceKey;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import java.util.Date;
|
import java.util.UUID;
|
|
|
/**
|
* @program: webSocketProject
|
* @description: 生成key
|
* @create: 2024-03-27 19:38
|
**/
|
@RestController
|
@RequestMapping("/api")
|
public class GenerateKey {
|
|
@Autowired
|
DataServiceKeyMapper dataServiceKeyMapper;
|
|
@PostMapping("/creationKey")
|
public ServerResponse sendNotification(@RequestParam("time") Date time) {
|
String randomKey = UUID.randomUUID().toString();
|
try {
|
Long count = dataServiceKeyMapper.selectCount(new LambdaQueryWrapper<DataServiceKey>().eq(DataServiceKey::getTokenKey, randomKey));
|
if(count > 0){
|
return ServerResponse.createByErrorMsg("请重新生成");
|
}
|
System.out.println(randomKey);
|
DataServiceKey dataServiceKey = new DataServiceKey();
|
dataServiceKey.setTokenKey(randomKey);
|
dataServiceKey.setExpirationTime(time);
|
dataServiceKey.setStartTime(DateUtil.date());
|
dataServiceKeyMapper.insert(dataServiceKey);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return ServerResponse.createBySuccessMsg(randomKey);
|
}
|
|
}
|