|  |  |  | 
|---|
|  |  |  | 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.pojo.dto.account.AccountDTO; | 
|---|
|  |  |  | import com.moral.api.pojo.dto.accountRole.AccountRoleDTO; | 
|---|
|  |  |  | import com.moral.api.pojo.dto.adjust.AdjustDTO; | 
|---|
|  |  |  | import com.moral.api.service.DeviceService; | 
|---|
|  |  |  | 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.web.bind.annotation.PathVariable; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMethod; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  | 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   姓名 | 
|---|
|  |  |  | * email  郵箱 | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @ApiOperation(value = "测试插入", notes = "测试插入") | 
|---|
|  |  |  | @RequestMapping(value = "/saveTest", method = RequestMethod.POST) | 
|---|
|  |  |  | public ResultMessage save()  { | 
|---|
|  |  |  | public ResultMessage save() { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Test test=new Test(); | 
|---|
|  |  |  | Test test = new Test(); | 
|---|
|  |  |  | test.setEmail("test@qq.com"); | 
|---|
|  |  |  | test.setName("name"); | 
|---|
|  |  |  | test.setMobile("13965898745"); | 
|---|
|  |  |  | 
|---|
|  |  |  | 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") | 
|---|
|  |  |  | @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); | 
|---|
|  |  |  | //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() | 
|---|
|  |  |  | userPage.getTotal(), userPage.getPages(), userPage.getRecords() | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | //返回数据 | 
|---|
|  |  |  | return  ResultMessage.ok(pageResult); | 
|---|
|  |  |  | return ResultMessage.ok(pageResult); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "redis測試", notes = "redis測試") | 
|---|
|  |  |  | @RequestMapping(value = "redis", method = RequestMethod.GET) | 
|---|
|  |  |  | public ResultMessage testRedis() { | 
|---|
|  |  |  | RedisUtil.set("redistest","test"); | 
|---|
|  |  |  | RedisUtil.set("redistest", "test"); | 
|---|
|  |  |  | return ResultMessage.ok(RedisUtil.get("redistest")); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @ApiOperation(value = "事務測試", notes = "事務測試") | 
|---|
|  |  |  | @RequestMapping(value = "saveTest", method = RequestMethod.GET) | 
|---|
|  |  |  | public ResultMessage saveTest() throws Exception{ | 
|---|
|  |  |  | public ResultMessage saveTest() throws Exception { | 
|---|
|  |  |  | testService.saveTest(); | 
|---|
|  |  |  | return ResultMessage.ok(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * kafka測試 | 
|---|
|  |  |  | * 分钟主题kafka測試 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @ApiOperation(value = "kafka測試", notes = "kafka測試") | 
|---|
|  |  |  | @RequestMapping(value = "kafkaTest", method = RequestMethod.GET) | 
|---|
|  |  |  | public void kafkaTest() { | 
|---|
|  |  |  | kafkaTemplate.send("test_topic","test111111111111111"); | 
|---|
|  |  |  | @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; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private DeviceService deviceService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "因子测试", notes = "因子测试") | 
|---|
|  |  |  | @ApiImplicitParams({ | 
|---|
|  |  |  | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @RequestMapping(value = "getSensor", method = RequestMethod.GET) | 
|---|
|  |  |  | public void getSensor() { | 
|---|
|  |  |  | HashMap<String, Object> deviceData = new HashMap<>(); | 
|---|
|  |  |  | deviceData.put("time","1691996716839"); | 
|---|
|  |  |  | deviceData.put("DataTime","20230814150000"); | 
|---|
|  |  |  | deviceData.put("mac","p5dnd7a0245362"); | 
|---|
|  |  |  | deviceData.put("a00e12","11479.2"); | 
|---|
|  |  |  | deviceData.put("a00e13","44.0"); | 
|---|
|  |  |  | deviceData.put("a21005","0.0264"); | 
|---|
|  |  |  | deviceData.put("a21004","20.0"); | 
|---|
|  |  |  | deviceData.put("a21026","30.5"); | 
|---|
|  |  |  | deviceData.put("a01001","38.1"); | 
|---|
|  |  |  | deviceData.put("a05024","279.6"); | 
|---|
|  |  |  | deviceData.put("a01002","54.2"); | 
|---|
|  |  |  | deviceData.put("a01007","2.45"); | 
|---|
|  |  |  | deviceData.put("a01006","805.834"); | 
|---|
|  |  |  | deviceData.put("a01008","102.0"); | 
|---|
|  |  |  | deviceData.put("a34002","4.9"); | 
|---|
|  |  |  | deviceData.put("a34004","4.9"); | 
|---|
|  |  |  | deviceData.put("a00e03","798.5"); | 
|---|
|  |  |  | deviceData.put("a00e04","2.9"); | 
|---|
|  |  |  | deviceData.put("a99054","0.0348"); | 
|---|
|  |  |  | deviceData.put("a31001","0.1"); | 
|---|
|  |  |  | Map<String, Object> map = deviceService.adjustDeviceData(deviceData, "2"); | 
|---|
|  |  |  | //        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); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|