perryhsu
2020-10-14 f803c2a9296bcf3d2dba97b32f40276aa8b83d56
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 java.io.File;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
 
import javax.servlet.http.HttpSession;
 
import com.fgkj.mapper.BaseDAO;
import com.fgkj.mapper.impl.BattInfMapper;
import com.fgkj.mapper.impl.Battresdata_infMapper;
import com.fgkj.dto.BattInf;
import com.fgkj.dto.Battresdata_inf;
import com.fgkj.dto.DLG_Progress;
import com.fgkj.dto.ServiceModel;
import com.fgkj.dto.User_inf;
import com.fgkj.fbo.CsvData;
import com.fgkj.mapper.impl.ResDataUploadMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
@Service
public class ResDataUploadService extends Thread{
 
    /*private ServiceModel model;
    private User_inf uinf;
    private int bg_id;
    private String[][] tableRowData;
    private File[] file;
    // private HttpSession session;
    // private DLG_Progress progress;
    
    
    public ResDataUploadService(
            User_inf uinf,
            int bg_id,
            String[][] tableRowData,
            File[] file,
            HttpSession session) {
        this.model = new ServiceModel();
        this.uinf = uinf;
        this.bg_id = bg_id;
        this.tableRowData=tableRowData;
        this.file=file;
        this.session=session;
        progress=new DLG_Progress(true,false);
        progress.setTableData(tableRowData);
        progress.setTotal(file.length);
        session.setAttribute("Resprogress", progress);
    }*/
 
    @Autowired
    private ResDataUploadMapper mapper;
    @Autowired
    private BattInfMapper battInfMapper;
    @Autowired
    private Battresdata_infMapper battResDataInfMapper;
 
    public void uploadResFile(User_inf uinf, int bg_id, String[][] tableRowData, File[] file, HttpSession session) {
        DLG_Progress progress=new DLG_Progress(true,false);
        progress.setTableData(tableRowData);
        progress.setTotal(file.length);
        session.setAttribute("Resprogress", progress);
 
        Thread thread = new Thread() {
            @Override
            public void run() {
                for (int n = 0; n < tableRowData.length; n++) {
                    if (false == progress.isJudge()) {
                        break;
                    }
 
                    if ("false".equals(tableRowData[n][2]))    //是否能上传
                    {
                        continue;
                    }
                    if ("true".equals(tableRowData[n][4]))        //是否已上传
                    {
                        continue;
                    }
                    //m_UploadCount++;
                    CsvData res_data = new CsvData();
                    File f = file[n];
                    if (tableRowData[n][1].toUpperCase().endsWith(".CSV")) {
                        res_data.checkCsvFile(f);
                    } else if (tableRowData[n][1].toUpperCase().endsWith(".FGXLS")) {
                        res_data.checkFgxlsFile(f);
                    } else if (tableRowData[n][1].toUpperCase().endsWith(".XML")) {
                        res_data.checkXmlFile(f);
                    }
                    int bg_id = Integer.parseInt((String) tableRowData[n][0]);
//            if(!FileisUpload(bg_id,res_data)){
//                continue;
//            }
                    //System.out.println("正在上传");
                    boolean res = mapper.uploadResData(uinf, bg_id, res_data,
                            tableRowData[n], progress.isJudge());
 
                    if (true == res) {
                        System.out.println(f.getName());
                        tableRowData[n][4] = "true";
                        tableRowData[n][5] = "100";
                        progress.setUploadOkcount(progress.getUploadOkcount() + 1);
 
                    }
 
                }
                for (File fl : file) {
                    if (fl.exists()) {
                        fl.delete();
                    }
                }
 
                progress.setCompleteed(true);
                progress.setJudge(false);
            }
        };
        thread.start();
    }
    
    /*public void run(){
        for(int n=0; n<tableRowData.length; n++)
        {    
            if(false == progress.isJudge())
            {
                break;
            }
            
            if("false".equals(tableRowData[n][2]))    //是否能上传
            {
                continue;
            }
            if("true".equals(tableRowData[n][4]))        //是否已上传
            {
                continue;
            }
            //m_UploadCount++;
            CsvData res_data = new CsvData();
            File f = file[n];
            if (tableRowData[n][1].toUpperCase().endsWith(".CSV")) {
                res_data.checkCsvFile(f);
            } else if (tableRowData[n][1].toUpperCase().endsWith(".FGXLS")) {
                res_data.checkFgxlsFile(f);
            }else if(tableRowData[n][1].toUpperCase().endsWith(".XML")){
                res_data.checkXmlFile(f);
            }
            int bg_id = Integer.parseInt((String)tableRowData[n][0]);
//            if(!FileisUpload(bg_id,res_data)){
//                continue;
//            }
            //System.out.println("正在上传");
            boolean res = new ResDataUploadImpl().uploadResData(uinf, bg_id, res_data, 
                                                                tableRowData[n], progress.isJudge());
            
            if(true==res){
                System.out.println(f.getName());
                tableRowData[n][4]="true";
                tableRowData[n][5]="100";
                progress.setUploadOkcount(progress.getUploadOkcount()+1);
                
            }
                
        }
        for(File fl:file){
            if(fl.exists()){
                fl.delete();
            }
        }
        
        progress.setCompleteed(true);
        progress.setJudge(false);
    }*/
    
    //判断当前文件能否上传
    
    /**
     * 
     * @param bg_id   电池组名
     * @param  csv_data    上传数据
     * @return    true :能上传                 false:不能上传
     */
    public boolean FileisUpload(int bg_id,CsvData csv_data) {
 
        Calendar mcld = Calendar.getInstance();
        mcld.setTime(csv_data.m_TestTime);
        
        Date test_starttime=mcld.getTime();
        
        boolean data_ok = true;
        int data_reason_type = 0;
        
        if(false == csv_data.m_DataOk) {
            data_reason_type = 7;
        }
        BattInf binf=new BattInf();
        Battresdata_inf rinf=new Battresdata_inf();
        binf.setBattGroupId(bg_id);
        rinf.setBattGroupId(bg_id);
        rinf.setTest_starttime(test_starttime);
        float batt_cap=0f;
        int mon_count=0;
        float mon_vol=0f;
        if(0 == data_reason_type) {
            List<BattInf> listB=battInfMapper.serchByCondition(binf);
            if(listB!=null&&listB.size()>0){
                batt_cap = listB.get(0).getMonCapStd();
                mon_count = listB.get(0).getMonCount();
                mon_vol = listB.get(0).getMonVolStd();
            }
            List<Battresdata_inf> listR=battResDataInfMapper.serchTest_record_count(rinf);
            if(listR!=null&&listR.size()>0){
                int test_record_count = listR.get(0).getTest_record_count();
                data_reason_type = 1;
            }
            //******************************************************************//
            if(bg_id < 1) {
                data_reason_type = 6;
            } else if(mon_count != csv_data.m_BattSum) {
                data_reason_type = 3;
            } else if(mon_vol != csv_data.m_MonomerVol) {
                data_reason_type = 4;
            } 
        }
        
        if(data_reason_type > 0) {
            data_ok = false;
        }
        return data_ok;
    }
}