jinpengyong
2021-12-22 9d91dc402f279630eaa100024fd3b1542fbeb41c
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
package com.moral.api.controller;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.moral.api.entity.Sensor;
import com.moral.api.entity.SysDictData;
import com.moral.api.entity.Test;
import com.moral.api.entity.UnitConversion;
import com.moral.api.mapper.SysDictDataMapper;
import com.moral.api.service.SensorService;
import com.moral.api.service.SysDictDataService;
import com.moral.api.service.TestService;
import com.moral.api.service.impl.SensorServiceImpl;
import com.moral.api.util.CacheUtils;
import com.moral.constant.Constants;
import com.moral.constant.KafkaConstants;
import com.moral.constant.RedisConstants;
import com.moral.constant.ResultMessage;
import com.moral.redis.RedisUtil;
import com.moral.util.PageResult;
import com.moral.util.TokenEncryptUtils;
import com.moral.util.TokenUtils;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
 
import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
 
 
@Slf4j
@Api(tags = {"大屏"})
@RestController
@RequestMapping("/api")
public class TestController {
 
    @Resource
    private KafkaTemplate kafkaTemplate;
 
    @Resource
    private TestService testService;
 
    @Autowired
    RedisTemplate redisTemplate;
 
 
    /**
     * name   姓名
     * email  郵箱
     * mobile 手機號
     */
    @ApiOperation(value = "测试插入", notes = "测试插入")
    @RequestMapping(value = "/saveTest", method = RequestMethod.POST)
    public ResultMessage save() {
 
        Test test = new Test();
        test.setEmail("test@qq.com");
        test.setName("name");
        test.setMobile("13965898745");
        testService.save(test);
        return ResultMessage.ok();
 
    }
 
    /**
     * page   當前頁
     * size   每頁大小
     */
    @ApiOperation(value = "分頁", notes = "分頁")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "當前頁數", required = true, paramType = "path", dataType = "Int"),
            @ApiImplicitParam(name = "size", value = "每頁大小", required = true, paramType = "path", dataType = "Int")
    })
    @RequestMapping(value = "search/{page}/{size}", method = RequestMethod.GET)
    public ResultMessage findBypage(@PathVariable("page") Integer page, @PathVariable("size") Integer size) {
 
        //log.info("page is:" + page + " size is:" + size);
        //根据条件分页查询
        Page<Test> userPage = testService.selectByPage(null, page, size);
        //封装分页返回对象
        PageResult<Test> pageResult = new PageResult<>(
                userPage.getTotal(), userPage.getPages(), userPage.getRecords()
        );
        //返回数据
        return ResultMessage.ok(pageResult);
    }
 
 
    /**
     * redis測試
     */
    @ApiOperation(value = "redis測試", notes = "redis測試")
    @RequestMapping(value = "redis", method = RequestMethod.GET)
    public ResultMessage testRedis() {
        RedisUtil.set("redistest", "test");
        return ResultMessage.ok(RedisUtil.get("redistest"));
 
    }
 
    /**
     * 事務
     */
    @ApiOperation(value = "事務測試", notes = "事務測試")
    @RequestMapping(value = "saveTest", method = RequestMethod.GET)
    public ResultMessage saveTest() throws Exception {
        testService.saveTest();
        return ResultMessage.ok();
 
    }
 
    /**
     * 分钟主题kafka測試
     */
    @ApiOperation(value = "kafka測試", notes = "kafka測試")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "data", value = "data", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "minuteKafkaTest", method = RequestMethod.GET)
    public void minuteKafkaTest(String data) {
        System.out.println(data);
        kafkaTemplate.send(KafkaConstants.TOPIC_MINUTE, data);
    }
 
    /**
     * 小时主题kafka測試
     */
    @ApiOperation(value = "kafka測試", notes = "kafka測試")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "data", value = "data", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "hourKafkaTest", method = RequestMethod.GET)
    public void hourKafkaTest(String data) {
        System.out.println(data);
        kafkaTemplate.send(KafkaConstants.TOPIC_HOUR, data);
    }
 
    @GetMapping("testToken")
    public void testToken() {
        String decoded = TokenEncryptUtils.decoded("5b53480d4e570b54565f555775");
        String decoded2 = TokenEncryptUtils.decoded("584f560a49510f5453515453");
        System.out.println(decoded);
        System.out.println(decoded2);
    }
 
    public static void main(String[] args) throws IOException {
        String path = "C:\\Users\\cdl\\Desktop\\province.txt";
        BufferedReader fis = new BufferedReader(new FileReader(path));
        BufferedWriter writer = new BufferedWriter(new FileWriter("C:\\Users\\cdl\\Desktop\\provin1ce.txt"));
        String line = "";
        while ((line = fis.readLine()) != null) {
            //获取code
            StringBuilder str = new StringBuilder(line);
            String code = str.substring(31, 37);
 
            //获取名称
            char[] chars = line.toCharArray();
            int i = 0;
            StringBuilder buffered = new StringBuilder();
            for (char aChar : chars) {
                if (aChar == '\'')
                    i++;
                if (i == 1) {
                    buffered.append(aChar);
                }
            }
            buffered.append('\'');
            String name = buffered.toString();
 
            //获取父级code
            line.trim();
            char[] chars1 = line.toCharArray();
            int j = 0;
            StringBuilder buffered2 = new StringBuilder();
            for (char c : chars1) {
                if (j == 6) {
                    buffered2.append(c);
                }
                if (c == ',')
                    j++;
            }
            StringBuilder parentCode = buffered2.deleteCharAt(buffered2.length() - 1);
            //写入
            writer.write("INSERT INTO `sys_area` VALUES (" + code + "," + name + "," + parentCode + ");");
            writer.newLine();
        }
 
        writer.close();
        fis.close();
    }
 
    @Autowired
    private SensorService sensorService;
    @Autowired
    SysDictDataMapper sysDictDataMapper;
 
    @ApiOperation(value = "因子测试", notes = "因子测试")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
    })
    @RequestMapping(value = "getSensor", method = RequestMethod.GET)
    public void getSensor() {
        QueryWrapper<Sensor> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("code").eq("is_delete", Constants.NOT_DELETE);
        List<Object> list = sensorService.listObjs(queryWrapper);
        for (Object o : list) {
            System.out.println(o);
        }
    }
 
}