whycrzg
2021-02-23 351b9a53cb9ecebdf8f79db0117f540d9c42c2a4
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package com.fgkj.services;
 
import com.fgkj.dto.ServiceModel;
import com.fgkj.dto.User_battgroup_baojigroup;
import com.fgkj.dto.User_log;
import com.fgkj.mapper.UinfDaoFactory;
import com.fgkj.mapper.impl.User_battgroup_baojigroupMapper;
import com.fgkj.mapper.impl.User_battgroup_baojigroup_battgroupMapper;
import com.fgkj.mapper.impl.User_battgroup_baojigroup_usrMapper;
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.ArrayList;
import java.util.List;
 
import javax.annotation.Resource;
@Service
public class User_battgroup_baojigroupService {
    @Autowired
    DataSourceTransactionManager dataSourceTransactionManager;
    @Autowired
    TransactionDefinition transactionDefinition;
    @Resource
    private User_battgroup_baojigroupMapper mapper;
    @Resource
    private User_battgroup_baojigroup_usrMapper baojiGroupUserMapper;
    @Resource
    private User_battgroup_baojigroup_battgroupMapper baojiGroupBattGroupMapper;
    @Resource
    private User_logService uservice;
 
    // 5.3添加新包机组
    public ServiceModel add(User_battgroup_baojigroup obj) {
        ServiceModel model= new ServiceModel();
        Boolean bl = mapper.add(obj)>0;
        if (bl) {
            model.setCode(1);
            model.setMsg("添加包机组成功!");
        } else {
            model.setMsg("添加包机组失败!");
        }
        return model;
 
    }
 
    // 5.3修改包机组名
    public ServiceModel update(User_battgroup_baojigroup obj) {
        ServiceModel model= new ServiceModel();
        Boolean bl = mapper.update(obj)>0;
        if (bl) {
            model.setCode(1);
            model.setMsg("修改成功!");
        } else {
            model.setMsg("修改失败!");
        }
        return model;
    }
 
    //5.3删除包机组
//    @Transactional
    public ServiceModel delete(User_battgroup_baojigroup obj) {
        TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
        ServiceModel model = new ServiceModel();
        boolean bl = true;
        try {
            bl = mapper.delPro(obj) > 0;
            if (bl) {
                bl = baojiGroupUserMapper.delAll(obj) > 0;
            }
            if (bl) {
                bl = baojiGroupBattGroupMapper.delAll(obj) > 0;
            }
        } catch (Exception e) {
            e.printStackTrace();
            dataSourceTransactionManager.rollback(transactionStatus);       //事务回滚
            model.setMsg("删除失败!");
            return model;
        }
 
        if (bl) {
            dataSourceTransactionManager.commit(transactionStatus);     //手动提交
            model.setCode(1);
            model.setMsg("删除成功!");
            {
                String msg = "删除" + obj.getBaoji_group_name() + "包机组";
                User_log ulog = UinfDaoFactory.CreateULog(UinfDaoFactory.Delete, msg);
                uservice.add(ulog);//将用户的操作记录下来
            }
        } else {
            dataSourceTransactionManager.rollback(transactionStatus);       //事务回滚
            model.setMsg("删除失败!");
        }
        //System.out.println(model);
        return model;
    }
 
 
 
    // 5.3根据包机组id查对应的机房和电池组
    public ServiceModel serchByInfo(User_battgroup_baojigroup obj) {
        ServiceModel model= new ServiceModel();
        List list = mapper.serchByInfo(obj);
        // for (Object object : list) {
        // System.out.println(object);
        // }
        // System.out.println(list);
        if (list != null && list.size() > 0) {
            model.setCode(1);
            model.setData(list);
        }
        return model;
    }
 
    // 5.3根据包机组id查包机组对应的用户
    public ServiceModel serchByCondition(User_battgroup_baojigroup obj) {
        ServiceModel model= new ServiceModel();
        List list = mapper.serchByCondition(obj);
        // for (Object object : list) {
        // System.out.println(object);
        // }
        // System.out.println(list);
        if (list != null && list.size() > 0) {
            model.setCode(1);
            model.setData(list);
        }
        return model;
    }
 
    // 5.3查所有包机组
    public ServiceModel searchAll() {
        ServiceModel model= new ServiceModel();
        List<User_battgroup_baojigroup> list = mapper.searchAll();
        // for (User_battgroup_baojigroup u : list) {
        // System.out.println(u);
        // }
        if (list != null && list.size() > 0) {
            model.setCode(1);
            model.setData(list);
        }
        return model;
    }
 
}