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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package com.fgkj.services;
 
import com.fgkj.dto.*;
import com.fgkj.mapper.impl.BattInfMapper;
import com.fgkj.mapper.impl.User_battmaint_checkMapper;
import com.fgkj.mapper.impl.User_battmaint_check_processMapper;
import com.fgkj.mapper.impl.User_infMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
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 java.util.ArrayList;
import java.util.List;
 
import javax.annotation.Resource;
@Service
public class User_battmaint_checkService {
 
    @Autowired
    DataSourceTransactionManager dataSourceTransactionManager;
    @Autowired
    TransactionDefinition transactionDefinition;
    @Resource
    private User_battmaint_checkMapper mapper;
    @Resource
    private User_battmaint_check_processMapper processMapper;
    @Resource
    private User_infMapper userInfMapper;
    @Resource
    private BattInfMapper battInfMapper;
    
    //4.10作业抽查管理(新建)
    public ServiceModel add(User_battmaint_check obj) {
        ServiceModel model=new ServiceModel();
        Boolean bl=mapper.add(obj)>0;
        if(bl){
            model.setCode(1);
            model.setMsg("添加成功!");
        }
        else{
            model.setMsg("添加失败!");
        }
        return model;
        
    }
    //4.10作业抽查管理(编辑记录)
    public ServiceModel update(User_battmaint_check obj) {
        ServiceModel model=new ServiceModel();
        Boolean bl=mapper.update(obj)>0;
        if(bl){
            model.setCode(1);
            model.setMsg("修改成功!");
        }
        else{
            model.setMsg("修改失败!");
        }
        return model;    
    }    
   //4.10作业抽查管理(编辑记录)(user_battmaint_check表修改时User_battmaint_check_process表就新增一条记录)
    public ServiceModel updatePro(User_battmaint_check ucheck,List<User_battmaint_check_process> list) {
        ServiceModel model = new ServiceModel();
        //TODO perry待查
        boolean bl = true;
        TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
//        ArrayList<String> str_sql = new ArrayList<String>();//存放所有的sql语句
        //修改User_battmaint_check表
        if (!(mapper.updatePro(ucheck) > 0)) {
            bl = false;
        }
        if (list != null && list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                if (!(processMapper.addPro(list.get(i)) > 0)) {
                    bl = false;
                }
            }
        }
        //System.out.println(str_sql);
        //Boolean bl=DateUtil.makeManualCommit(DBUtil.getConn(), str_sql);
        if (bl) {
            dataSourceTransactionManager.commit(transactionStatus);     //手动提交
            model.setCode(1);
            model.setMsg("修改成功!");
        } else {
            dataSourceTransactionManager.rollback(transactionStatus);       //事务回滚
            model.setMsg("修改失败!");
        }
        return model;
    }
    //4.10作业抽查管理(删除记录)
    public ServiceModel delete(User_battmaint_check obj) {
        ServiceModel model=new ServiceModel();
        Boolean bl=mapper.del(obj)>0;
        if(bl){
            model.setCode(1);
            model.setMsg("删除成功!");
        }
        else{
            model.setMsg("删除失败!");
        }
        return model;    
    }
    //4.10作业抽查管理(删除记录)
    public ServiceModel deletePro(User_battmaint_check ucheck) {
        ServiceModel model = new ServiceModel();
        TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
        boolean bl = true;
        //删除对应的User_battmaint_check_process
        User_battmaint_check_process uprocess = new User_battmaint_check_process();
        uprocess.setTask_rec_id(ucheck.getNum());
        //删除User_battmaint_check表
        bl = mapper.delPro(ucheck) > 0;
        //删除User_battmaint_check_process表中task_rec_id对应的记录
        if (bl) {
            bl = processMapper.delPro(uprocess) > 0;
        }
        if (bl) {
            dataSourceTransactionManager.commit(transactionStatus);     //手动提交
            model.setCode(1);
            model.setMsg("修改成功!");
        } else {
            dataSourceTransactionManager.rollback(transactionStatus);       //事务回滚
            model.setMsg("修改失败!");
        }
        return model;
    }
    //TODO  数据不足待测试
    //4.10作业抽查管理
    public ServiceModel serchByCondition(Task_Batt_Test tbt){
        System.out.println("tbt = " + tbt);
        ServiceModel model=new ServiceModel();
        //分页
        PageBean pageBean = tbt.getPageBean();
        PageHelper.startPage(pageBean.getPageNum(),pageBean.getPageSize(),true);
        List<Task_Batt_Test> list=mapper.serchByCondition(tbt);
        User_inf uinf=new User_inf();
        int usr_id=0;//责任人
        String usr_name="";
        int master_id=0;//创建人
        String master_name="";
        int appoint_uid=0;//指派人
        String appoint_name="";
        String copy_ids="";//抄送人
        int copy_id=0;
        String copy_name="";
        String[] copy_names;
        System.out.println(" list.size = " + list.size());
        for(int i=0;i<list.size();i++){
            System.out.println("list.get("+i+") = " + list.get(i));
            BattInf binf=new BattInf();
            //电池组组数
            binf.setStationName(list.get(i).getMcheck().getRemark());
//            binf.setStationName("湖北省-武汉市-东西湖区-我的测试机房-BTS");
            binf.setStationName1("");
            List listbinf=battInfMapper.serchByBattGroupName(binf);
            list.get(i).getMcheck().setStationId(listbinf.size());
            //责任人/创建人/指派人/抄送人
            usr_id=list.get(i).getMcheck().getUsr_id();
            uinf.setuId(usr_id);
//            System.out.println("usr_id = " + usr_id);
            List<User_inf> listuser_inf = userInfMapper.serchUname(uinf);
            if (listuser_inf.size() > 0) {
                usr_name = listuser_inf.get(0).getuName();
            }
            binf.setStationName6(usr_name);
 
            master_id=list.get(i).getMcheck().getMaster_id();
            uinf.setuId(master_id);
            List<User_inf> user_infs = userInfMapper.serchUname(uinf);
            if (user_infs.size() > 0) {
                master_name = user_infs.get(0).getuName();
            }
            binf.setStationName7(master_name);
 
            appoint_uid=list.get(i).getMcheck().getAppoint_uid();
            uinf.setuId(appoint_uid);
            List<User_inf> user_infs1 = userInfMapper.serchUname(uinf);
            if (user_infs1.size() > 0) {
                appoint_name = user_infs1.get(0).getuName();
            }
            binf.setStationName8(appoint_name);
            //System.out.println(usr_name+"  "+master_name+"  "+appoint_name);
            copy_ids=list.get(i).getMcheck().getCopy_uids();
            System.out.println("copy_ids = " + copy_ids);        //1001,1002,1003,1004,1008
            copy_names=copy_ids.split(",");
            if (copy_names.length>0) {
                System.out.println("copy_names = " + copy_names.toString());
                for (int j = 0; j < copy_names.length; j++) {
                    String copy_name1 = copy_names[j];
                    if (copy_name1.length() > 0) {
                        copy_id = Integer.parseInt(copy_name1);
                        uinf.setuId(copy_id);
                    }
                    copy_name += ",";
                    List<User_inf> user_infs2 = userInfMapper.serchUname(uinf);
                    if (user_infs2.size() > 0) {
                        copy_name += user_infs2.get(0).getuName();
                    }
                }
            }
            binf.setStationName9(copy_name.substring(1, copy_name.length()));
            //System.out.println(binf.getStationName9());
            list.get(i).setBinf(binf);
            copy_name="";
        }
        if(list!=null && list.size()>0){
            model.setCode(1);
            PageInfo<Task_Batt_Test> pageInfo = new PageInfo<>(list);
            model.setData(pageInfo);
        }
 
        return model;
    }
 
 
    public ServiceModel searchAll() {
        ServiceModel model=new ServiceModel();
        List<User_battmaint_check> list = mapper.searchAll();
        //System.out.println(list.size());
 
        if (list != null && list.size() > 0) {
            model.setCode(1);
            model.setData(list);
        }
        return model;
    } 
 
}