| | |
| | | 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 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 |
| | |
| | | |
| | | @Resource |
| | | private TestService testService; |
| | | |
| | | @Autowired |
| | | RedisTemplate redisTemplate; |
| | | |
| | | |
| | | /** |
| | | * name 姓名 |
| | |
| | | @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); |
| | | //log.info("page is:" + page + " size is:" + size); |
| | | //根据条件分页查询 |
| | | Page<Test> userPage = testService.selectByPage(null, page, size); |
| | | //封装分页返回对象 |
| | |
| | | } |
| | | |
| | | /** |
| | | * kafka測試 |
| | | * 分钟主题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 = "kafkaTest", method = RequestMethod.GET) |
| | | public void kafkaTest() { |
| | | kafkaTemplate.send("test_topic", "{'mac': 'p5dnd1234567','DataTime':1623058244104,'e1':10,'e2':20,'ver':2}"); |
| | | @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") |
| | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | @GetMapping("test") |
| | | public void test() throws IOException { |
| | | BufferedReader br = new BufferedReader(new FileReader(new File("C:\\Users\\cdl\\Desktop\\alarmLevels.json"))); |
| | | StringBuilder sb = new StringBuilder(); |
| | | String line = br.readLine(); |
| | | while (line != null) { |
| | | sb.append(line + "\r\n"); |
| | | line = br.readLine(); |
| | | } |
| | | |
| | | Map map = JSON.parseObject(sb.toString(), Map.class); |
| | | System.out.println(map); |
| | | |
| | | Map<String,Object> sensorMap = (Map<String, Object>) map.get("alarmLevels"); |
| | | |
| | | Set<String> sets = sensorMap.keySet(); |
| | | |
| | | Map<String,String> alarmLevels = new HashMap<>(); |
| | | for (String set : sets) { |
| | | Map<String,Object> map2 = (Map<String, Object>) sensorMap.get(set); |
| | | String increment = map2.get("increment").toString(); |
| | | alarmLevels.put(set,increment); |
| | | } |
| | | alarmLevels.remove("AQI"); |
| | | Map<String,Object> resultMap = new HashMap<>(); |
| | | Map<String, String> ecodeMap = testService.getMap(); |
| | | |
| | | alarmLevels.forEach((key,value)->{ |
| | | resultMap.put(ecodeMap.get(key),value); |
| | | }); |
| | | |
| | | resultMap.forEach((key,value)->{ |
| | | SysDictData sysDictData = new SysDictData(); |
| | | sysDictData.setDataKey(key); |
| | | sysDictData.setDataValue(value.toString()); |
| | | sysDictData.setDictTypeId(25); |
| | | sysDictDataMapper.insert(sysDictData); |
| | | }); |
| | | |
| | | } |
| | | |
| | | } |