whycrzg
2021-02-20 aa885eba07f4b84390922b4b146d1806676293c0
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
package com.fgkj.controller;
 
import com.fgkj.config.DatasourceConfig;
import com.fgkj.dto.App_Param;
import com.fgkj.dto.ServiceModel;
import com.fgkj.services.App_ParamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.List;
 
@RequestMapping("appParam")
@RestController
@Api(tags = "appParam接口")
public class App_ParamController{
    @Resource
    private App_ParamService service;
    @Autowired
    private DatasourceConfig datasourceConfig;
 
    //根据discharge/charge/poweroff查询
    @PostMapping("byInfo")
    @ApiOperation(notes = "",value="byInfo")
    public ServiceModel serchByInfo(@RequestParam String param_name) {
        App_Param param = new App_Param();
        param.setParam_name(param_name);
        ServiceModel model = service.serchByInfo(param);
        return model;
    }
    //修改参数
    @PutMapping("/")
    @ApiOperation(notes = "[{ \"num\": 1, \"param_value\": 11 }]",value="修改参数")
    public ServiceModel update(@RequestBody List<App_Param> params) {
        // List<App_Param> params = getGson().fromJson(json, new TypeToken<List<App_Param>>(){}.getType());
        ServiceModel model = service.update(params);
        return model;
    }
    
    /**
     * 获取连接数据库的ip地址
     * @return
     */
    @GetMapping("ip")
    @ApiOperation(notes = "",value="获取连接数据库的ip地址")
    public ServiceModel searchIP(){
        //jdbc:mysql://localhost:3360/db_user?characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowMultiQueries=true
        String url = datasourceConfig.getUrl();
        String ip = url.split("/")[2].split(":")[0];
        ServiceModel model = new ServiceModel();
        if(ip != null && ip.length() > 0){
            model.setCode(1);
            model.setMsg(ip);
        }else{
            model.setMsg("获取失败");
        }
 
        return model;
    }
    
    /**
     * 设置服务器ip地址,TODO
     * @return
     */
    @PutMapping("ip")
    @ApiOperation(notes = "设置服务器ip地址,TODO",value="设置服务器ip地址")
    public ServiceModel updataIp(@RequestParam String json){
 
        // ServiceModel model = DBUtil1.setIp(json);
        ServiceModel model = new ServiceModel();
 
        return model;
    }
 
}