whycrzg
2021-02-02 028d5568c2e8c8f649b1f395d76826944cd5f1a9
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
package com.fgkj.services;
 
import com.fgkj.dto.Database_backup;
import com.fgkj.dto.ServiceModel;
import com.fgkj.dto.ServiceModelOnce;
import com.fgkj.mapper.impl.Database_backupMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
 
import javax.annotation.Resource;
@Service
public class Database_backupService {
 
    ServiceModel model = new ServiceModel();
 
    @Resource
    private Database_backupMapper mapper;;
    @Autowired
    DataSourceTransactionManager dataSourceTransactionManager;
    @Autowired
    TransactionDefinition transactionDefinition;
    
    //根据数据库名和表名修改备份数据库的使能(多笔记录)
    public ServiceModel updatePro(List<Database_backup> obj) {
        ServiceModel model = new ServiceModel();
        TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
        boolean bl = true;
        try {
            bl = mapper.updatePro(obj) > 0;
        } catch (Exception e) {
            e.printStackTrace();
            dataSourceTransactionManager.rollback(transactionStatus);
            model.setCode(0);
            model.setMsg("修改失败!");
            return model;
        }
        if (bl) {
            dataSourceTransactionManager.commit(transactionStatus);
            model.setCode(1);
            model.setMsg("修改成功!");
        } else {
            dataSourceTransactionManager.rollback(transactionStatus);
            model.setCode(0);
            model.setMsg("修改失败!");
        }
        return model;
    }
    //根据数据库名和表名修改备份数据库的使能(一键修改)
    public ServiceModel updateProAll() {
        ServiceModel model = new ServiceModel();
        boolean bl = mapper.updateProAll() > 0;
        if (bl) {
            model.setCode(1);
            model.setMsg("修改成功!");
        } else {
            model.setCode(0);
            model.setMsg("修改失败!");
        }
        return model;
    }
        
    
    
    //查询所有数据库备份信息
    public ServiceModel searchAll() {
        ServiceModel model = new ServiceModel();
        List list=mapper.searchAll();
        if(list!=null&&list.size()>0){
            model.setData(list);
            model.setCode(1);
            model.setMsg("查询成功!");
        }else{
            model.setCode(0);
            model.setMsg("查询失败!");
        }
        return model;
    }
    
    //查询数据库备份表中所有的数据库
    public ServiceModel searchAllDatabase() {
        ServiceModel model = new ServiceModel();
        List list=mapper.searchAllDatabase();
        if(list!=null&&list.size()>0){
            model.setData(list);
            model.setCode(1);
            model.setMsg("查询成功!");
        }else{
            model.setCode(0);
            model.setMsg("查询失败!");
        }
        return model;
    }
 
    //根据数据库名查询所有的表
    public ServiceModel searchAllTable(Database_backup obj) {
        ServiceModel model = new ServiceModel();
        List list=mapper.searchAllTable(obj);
        if(list!=null&&list.size()>0){
            model.setData(list);
            model.setCode(1);
            model.setMsg("查询成功!");
        }else{
            model.setCode(0);
            model.setMsg("查询失败!");
        }
        return model;
    }
    //查询个数
    public ServiceModelOnce searchNum() {
        ServiceModelOnce model = new ServiceModelOnce();
        Database_backup baseup = new Database_backup();
        //总数
        baseup.setNum(0);
        int sum = mapper.searchNum(baseup);
        //处于备份的数目
        baseup.setNum(1);
        int baseup_num = mapper.searchNum(baseup);
        model.setSum(sum);
        model.setNewsum(baseup_num);
        model.setCode(1);
        return model;
    }
}