付延余
2022-12-16 f0f8ee8c4a945adbc742d9bab69382b28ad311fb
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
package com.wgcloud.service;
 
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wgcloud.entity.DbInfo;
import com.wgcloud.mapper.DbInfoMapper;
import com.wgcloud.util.DateUtil;
import com.wgcloud.util.HostUtil;
import com.wgcloud.util.UUIDUtil;
import com.wgcloud.util.jdbc.RDSConnection;
import com.wgcloud.util.staticvar.StaticKeys;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
 
/**
 * @version v3.3
 * @ClassName:DbInfoService.java
 * @author: http://www.wgstart.com
 * @date: 2021年1月16日
 * @Description: DbInfoService.java
 * @Copyright: 2019-2021 wgcloud. All rights reserved.
 */
@Service
public class DbInfoService {
 
    public PageInfo selectByParams(Map<String, Object> params, int currPage, int pageSize) throws Exception {
        PageHelper.startPage(currPage, pageSize);
        List<DbInfo> list = dbInfoMapper.selectByParams(params);
        PageInfo<DbInfo> pageInfo = new PageInfo<DbInfo>(list);
        return pageInfo;
    }
 
    public void save(DbInfo DbInfo) throws Exception {
        DbInfo.setId(UUIDUtil.getUUID());
        DbInfo.setCreateTime(DateUtil.getNowTime());
        DbInfo.setDbState(StaticKeys.ON_STATE);
        dbInfoMapper.save(DbInfo);
    }
 
    public int countByParams(Map<String, Object> params) throws Exception {
        return dbInfoMapper.countByParams(params);
    }
 
    @Transactional
    public int deleteById(String[] id) throws Exception {
        return dbInfoMapper.deleteById(id);
    }
 
    public int updateById(DbInfo DbInfo)
            throws Exception {
        return dbInfoMapper.updateById(DbInfo);
    }
 
    public DbInfo selectById(String id) throws Exception {
        return dbInfoMapper.selectById(id);
    }
 
    public List<DbInfo> selectAllByParams(Map<String, Object> params) throws Exception {
        return dbInfoMapper.selectAllByParams(params);
    }
 
    /**
     * 保存操作日志
     *
     * @param request 获取当前登录用户
     * @param action  操作标识
     */
    public void saveLog(HttpServletRequest request, String action, DbInfo dbInfo) {
        if (null == dbInfo) {
            return;
        }
        logInfoService.save(HostUtil.getAccountByRequest(request).getAccount() + action + "数据源监测信息:" + dbInfo.getAliasName(),
                "数据库类型:" + dbInfo.getDbType(), StaticKeys.LOG_XTCZ);
    }
 
    /**
     * 设置数据库logo
     *
     * @param list
     */
    public void dbAddLogo(List<DbInfo> list) throws Exception {
        for (DbInfo dbInfo : list) {
            if (!StringUtils.isEmpty(dbInfo.getDbType())) {
                if (RDSConnection.KEY_MYSQL.equals(dbInfo.getDbType())) {
                    dbInfo.setImage("/tssw/static/images/mysql.png");
                } else if (RDSConnection.KEY_MARIADB.equals(dbInfo.getDbType())) {
                    dbInfo.setImage("/tssw/static/images/mariadb.png");
                } else if (RDSConnection.KEY_POSTGRESQL.equals(dbInfo.getDbType())) {
                    dbInfo.setImage("/tssw/static/images/postgresql.png");
                } else if (RDSConnection.KEY_SQLSERVER.equals(dbInfo.getDbType())) {
                    dbInfo.setImage("/tssw/static/images/windows.png");
                } else if (RDSConnection.KEY_DB2.equals(dbInfo.getDbType())) {
                    dbInfo.setImage("/tssw/static/images/db2.png");
                } else {
                    dbInfo.setImage("/tssw/static/images/oracle.png");
                }
            } else {
                dbInfo.setImage("/tssw/static/images/mysql.png");
            }
        }
    }
 
 
    @Autowired
    private DbInfoMapper dbInfoMapper;
    @Autowired
    private LogInfoService logInfoService;
 
 
}