1
ydj
2024-06-11 14b46ebd008c9f9fbaa0dd43a49783d2f54536a3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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);
    }
 
}