lxw
2020-07-11 9db52f2f2dd3665fe9da1ae5657e0167c3a34d40
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
package com.fgkj.services;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
 
import com.fgkj.actions.ActionUtil;
import com.fgkj.dao.BaseDAO;
import com.fgkj.dao.BaseDAOFactory;
import com.fgkj.dao.DAOHelper;
import com.fgkj.dao.impl.BattInfImpl;
import com.fgkj.dao.impl.User_battmaint_checkImpl;
import com.fgkj.dao.impl.User_battmaint_check_processImpl;
import com.fgkj.dao.impl.User_infImpl;
import com.fgkj.db.DBUtil;
import com.fgkj.db.IDatabaseName;
import com.fgkj.dto.BattInf;
import com.fgkj.dto.Page;
import com.fgkj.dto.ServiceModel;
import com.fgkj.dto.Task_Batt_Test;
import com.fgkj.dto.User_battmaint_check_process;
import com.fgkj.dto.User_inf;
 
import com.fgkj.dto.User_battmaint_check;
 
public class User_battmaint_checkService {
    private ServiceModel model;
    private BaseDAO dao;
    public User_battmaint_checkService() {
        model=new ServiceModel();
        dao=BaseDAOFactory.getBaseDAO(BaseDAO.USER_BATTMAINT_CHECK);
    }
    
    //4.10作业抽查管理(新建)
    public ServiceModel add(Object obj) {
        Boolean bl=dao.add(obj);
        if(bl){
            model.setCode(1);
            model.setMsg("添加成功!");
        }
        else{
            model.setMsg("添加失败!");
        }
        return model;
        
    }
    //4.10作业抽查管理(编辑记录)
    public ServiceModel update(Object obj) {
        Boolean bl=dao.update(obj);
        if(bl){
            model.setCode(1);
            model.setMsg("修改成功!");
        }
        else{
            model.setMsg("修改失败!");
        }
        return model;    
    }    
   //4.10作业抽查管理(编辑记录)(user_battmaint_check表修改时User_battmaint_check_process表就新增一条记录)
    public ServiceModel updatePro(Object obj1,Object obj2) {
        User_battmaint_check ucheck=(User_battmaint_check) obj1;
        List<User_battmaint_check_process> list=(List<User_battmaint_check_process>) obj2;
        ArrayList<String> str_sql=new ArrayList<String>();//存放所有的sql语句
        //修改User_battmaint_check表
        String sqlCheck=(new User_battmaint_checkImpl()).updatePro(ucheck);
        str_sql.add(sqlCheck);
        if(list!=null && list.size()>0){
            for (int i = 0; i < list.size(); i++) {
                //Date caption_time=new Date();
                //System.out.println("caption_time:"+caption_time);
                //list.get(i).setWork_caption_time(caption_time);
                //新增User_battmaint_check_process表
                String sqlProcess=(new User_battmaint_check_processImpl()).addPro(list.get(i));
                str_sql.add(sqlProcess);
            }
        }
        //System.out.println(str_sql);
        Boolean bl=DAOHelper.makeManualCommit(DBUtil.getConn(), str_sql);
        if(bl){
            model.setCode(1);
            model.setMsg("修改成功!");
        }
        else{
            model.setMsg("修改失败!");
        }
        return model;
    }
    //4.10作业抽查管理(删除记录)
    public ServiceModel delete(Object obj) {
        Boolean bl=dao.del(obj);
        if(bl){
            model.setCode(1);
            model.setMsg("删除成功!");
        }
        else{
            model.setMsg("删除失败!");
        }
        return model;    
    }
    //4.10作业抽查管理(删除记录)
    public ServiceModel deletePro(Object obj) {
        User_battmaint_check ucheck=(User_battmaint_check) obj;
        //删除对应的User_battmaint_check_process
        User_battmaint_check_process uprocess=new User_battmaint_check_process();
        uprocess.setTask_rec_id(ucheck.getNum());
        ArrayList<String> str_sql=new ArrayList<String>();//存放所有的sql语句
        //删除User_battmaint_check表
        String sqlCheck=(new User_battmaint_checkImpl()).delPro(ucheck);
        str_sql.add(sqlCheck);
        //删除User_battmaint_check_process表中task_rec_id对应的记录
        String sqlProcess=(new User_battmaint_check_processImpl()).delPro(uprocess);
        str_sql.add(sqlProcess);
        Boolean bl=DAOHelper.makeManualCommit(DBUtil.getConn(), str_sql);
        if(bl){
            model.setCode(1);
            model.setMsg("修改成功!");
        }
        else{
            model.setMsg("修改失败!");
        }
        return model;
    }
 
    //4.10作业抽查管理
    public ServiceModel serchByCondition(Object obj){
        List<Task_Batt_Test> list=dao.serchByCondition(obj);
        
        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;
        for(int i=0;i<list.size();i++){
            BattInf binf=new BattInf();
            //电池组组数
            binf.setStationName(list.get(i).getMcheck().getRemark());
            binf.setStationName1("");
            List listbinf=(new BattInfImpl()).serchByBattGroupName(binf);
            list.get(i).getMcheck().setStationId(listbinf.size());
            //责任人/创建人/指派人/抄送人
            usr_id=list.get(i).getMcheck().getUsr_id();
            uinf.setUId(usr_id);
            usr_name=((User_inf)(new User_infImpl()).serchUname(uinf).get(0)).getUName();
            binf.setStationName6(usr_name);
            
            master_id=list.get(i).getMcheck().getMaster_id();
            uinf.setUId(master_id);
            master_name=((User_inf)(new User_infImpl()).serchUname(uinf).get(0)).getUName();
            binf.setStationName7(master_name);
            
            appoint_uid=list.get(i).getMcheck().getAppoint_uid();
            uinf.setUId(appoint_uid);
            appoint_name=((User_inf)(new User_infImpl()).serchUname(uinf).get(0)).getUName();
            binf.setStationName8(appoint_name);
            //System.out.println(usr_name+"  "+master_name+"  "+appoint_name);
            copy_ids=list.get(i).getMcheck().getCopy_uids();
            copy_names=copy_ids.split(",");
            for(int j=0;j<copy_names.length;j++){
                copy_id=Integer.parseInt(copy_names[j]);
                uinf.setUId(copy_id);
                copy_name+=",";
                copy_name+=((User_inf)(new User_infImpl()).serchUname(uinf).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);
            model.setData(list);
        }
        List<Task_Batt_Test> listt=(List<Task_Batt_Test>)model.getData();    
    //    for (Task_Batt_Test t : listt) {
    //        System.out.println(t.getBinf().getStationName9()+"  "+t.getMcheck().getCopy_uids());
    //    }
        return model;
    }
 
 
    public ServiceModel searchAll() {
        List<User_battmaint_check> list = dao.searchAll();
        //System.out.println(list.size());
 
        if (list != null && list.size() > 0) {
            model.setCode(1);
            model.setData(list);
        }
        return model;
    } 
    public static void main(String[] args) throws ParseException {
        User_battmaint_checkService us=new User_battmaint_checkService();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = sdf.parse("2000-01-01");
        Date date2 = sdf.parse("2020-01-01");
        
        BattInf binf = new BattInf();
        binf.setStationName("");
        binf.setStationName1("");
        binf.setBattGroupId(0);
        
        User_battmaint_check mcheck=new User_battmaint_check();
        mcheck.setUsr_id(0);
        mcheck.setOrigin_usr_work_mark(0);
        mcheck.setOrigin_usr_work_mark1(100);
        mcheck.setTask_done(100);
        mcheck.setTask_done_confirm(100);
        mcheck.setTask_time_start(ActionUtil.getSimpDate(date1));
        mcheck.setTask_time_end(ActionUtil.getSimpDate(date2));
        Page p = new Page();
        p.setPageCurr(1);
        p.setPageSize(10);
        Task_Batt_Test tbt=new Task_Batt_Test();
        tbt.setBinf(binf);
        tbt.setMcheck(mcheck);
        tbt.setPage(p);
        us.serchByCondition(tbt);
        //us.searchAll();
    }
 
}