DlbServiceImpl.java
9.21 KB
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
package com.bsth.service.oil.impl;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.transaction.Transactional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import com.bsth.common.ResponseCode;
import com.bsth.entity.Cars;
import com.bsth.entity.oil.Cdl;
import com.bsth.entity.oil.Cyl;
import com.bsth.entity.oil.Dlb;
import com.bsth.entity.oil.Jdl;
import com.bsth.entity.oil.Ylb;
import com.bsth.entity.oil.Ylxxb;
import com.bsth.entity.search.CustomerSpecs;
import com.bsth.repository.CarsRepository;
import com.bsth.repository.oil.CdlRepository;
import com.bsth.repository.oil.CylRepository;
import com.bsth.repository.oil.DlbRepository;
import com.bsth.repository.oil.JdlRepository;
import com.bsth.repository.oil.YlbRepository;
import com.bsth.repository.oil.YlxxbRepository;
import com.bsth.service.impl.BaseServiceImpl;
import com.bsth.service.oil.DlbService;
import com.bsth.service.realcontrol.ScheduleRealInfoService;
@Service
public class DlbServiceImpl extends BaseServiceImpl<Dlb,Integer> implements DlbService{
@Autowired
DlbRepository repository;
@Autowired
YlxxbRepository ylxxbRepository;
@Autowired
CdlRepository cdlRepository;
@Autowired
JdlRepository jdlRepository;
@Autowired
CarsRepository carsRepository;
@Autowired
ScheduleRealInfoService scheduleRealInfoService;
@Autowired
JdbcTemplate jdbcTemplate;
Logger logger = LoggerFactory.getLogger(this.getClass());
/**
* 获取进存油信息
* @Transactional 回滚事物
*/
@Transactional
@Override
public Map<String, Object> obtain(Map<String, Object> map2) {
List<Cars> carsList=carsRepository.findCars();
Map<String, Boolean> carsMap=new HashMap<String, Boolean>();
for (int i = 0; i < carsList.size(); i++) {
Cars c=carsList.get(i);
carsMap.put(c.getInsideCode(), c.getSfdc());
}
String rq=map2.get("rq").toString();
String line="";
if(map2.get("xlbm_eq")!=null){
line=map2.get("xlbm_eq").toString();
}
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
//保留两位小数
DecimalFormat df = new DecimalFormat("#.00");
// TODO Auto-generated method stub
Map<String, Object> newMap=new HashMap<String,Object>();
//当天DLB信息
List<Dlb> dlList=repository.obtainDl(rq);
//当天YLXXB信息
List<Ylxxb> ylxxList=ylxxbRepository.obtainYlxx(rq,1);
//当天加电信息表
List<Jdl> jdlList=jdlRepository.JdlList(rq);
//前一天所有车辆最后进场班次信息
List<Dlb> dlListBe=repository.obtainYlbefore(rq);
List<Cdl> cdyList=cdlRepository.obtainCdl();
//从排班表中计算出行驶的总里程
List<Map<String,Object>> listpb=scheduleRealInfoService.yesterdayDataList(line,rq);
List<Ylb> addList=new ArrayList<Ylb>();
List<Ylb> updateList=new ArrayList<Ylb>();
for(int x=0;x<listpb.size();x++){
String type="add";
boolean sfdc=false;
Map<String, Object> map=listpb.get(x);
if (carsMap.get(map.get("clZbh").toString())!=null) {
sfdc= carsMap.get(map.get("clZbh").toString());
}else{
sfdc=false;
}
if(sfdc){
//判断驾驶员驾驶的该车辆是否已经存入了(查出的结果集中日期是相同的,根据驾驶员、内部编号、线路编码判断)
Dlb t=new Dlb();
for(int k=0;k<dlList.size();k++){
Dlb t1=dlList.get(k);
if(t1.getNbbm().equals(map.get("clZbh").toString())
&&t1.getJsy().equals(map.get("jGh").toString())
&&t1.getXlbm().equals(map.get("xlBm").toString()))
{
t=t1;
type="update";
}
}
try {
//当日的第一个班次,出场油量等于前一天的最后一个班次的进场油量
if(map.get("seqNumber").toString().equals("1")){
boolean fage=true;
for (int i = 0; i < dlListBe.size(); i++) {
Dlb dlb=dlListBe.get(i);
if(map.get("clZbh").toString().equals(dlb.getNbbm())){
t.setCzcd(dlb.getJzcd());
fage=false;
break;
}
}
if(fage){
for (int y = 0; y < cdyList.size(); y++) {
Cdl cdl=cdyList.get(y);
if(map.get("clZbh").toString().equals(cdl.getNbbm())){
t.setCzcd(cdl.getClcd());
fage=false;
break;
}
}
}
if(fage){
t.setCzcd(0.0);
}
}
Double jzl=0.0;
//把当天的YLXXB的加注量设置为当天YLB的加注量(根据车号,驾驶员判断)
for(int j=0;j<ylxxList.size();j++){
Ylxxb ylxxb= ylxxList.get(j);
if(map.get("clZbh").toString().equals(ylxxb.getNbbm()) &&map.get("jGh").toString().equals(ylxxb.getJsy())){
jzl+=ylxxb.getJzl();
}
}
//手动导入没有驾驶员工号
for (int i = 0; i < jdlList.size(); i++) {
Jdl jdl=jdlList.get(i);
if(map.get("clZbh").toString().equals(jdl.getNbbm()) ){
jzl+=jdl.getJdl();
}
}
t.setCdl(jzl);
t.setJzcd(t.getCzcd());
t.setNbbm(map.get("clZbh").toString());
t.setJsy(map.get("jGh")==null?"":map.get("jGh").toString());
t.setZlc(map.get("totalKilometers")==null?0.0:Double.parseDouble(df.format(Double.parseDouble(map.get("totalKilometers").toString()))));
t.setXlbm(map.get("xlBm")==null?"":map.get("xlBm").toString());
t.setHd(jzl);
t.setJcsx(Integer.parseInt(map.get("seqNumber").toString()));
t.setSsgsdm(map.get("company")==null?"":map.get("company").toString());
t.setFgsdm(map.get("bCompany")==null?"":map.get("bCompany").toString());
t.setRq(sdf.parse(rq));
/*if(type.equals("add")){
addList.add(t);
}else{
updateList.add(t);
}*/
repository.save(t);
newMap.put("status", ResponseCode.SUCCESS);
} catch (ParseException e) {
// TODO Auto-generated catch block
newMap.put("status", ResponseCode.ERROR);
e.printStackTrace();
}
}
}
/* try {
if(addList.size()>0){
new BatchSaveUtils<Ylb>().saveList(addList, Ylb.class);
}
if(updateList.size()>0){
}
newMap.put("status", ResponseCode.SUCCESS);
}
catch (Exception e) {
// TODO: handle exception
newMap.put("status", ResponseCode.ERROR);
}*/
return newMap;
}
/**
* 拆分
*/
@Transactional
@Override
public Map<String, Object> sort(Map<String, Object> map) {
// TODO Auto-generated method stub
Map<String, Object> newMap = new HashMap<String, Object>();
try{
int id=Integer.parseInt(map.get("id").toString());
//最后存油量
Double jzdl=Double.parseDouble(map.get("jzdl").toString());
Double hdl=Double.parseDouble(map.get("hdl").toString());
Dlb dlb=repository.findOne(id);
dlb.setJzcd(jzdl);
dlb.setHd(hdl);
repository.save(dlb);
newMap.put("status", ResponseCode.SUCCESS);
}catch(Exception e){
newMap.put("status", ResponseCode.ERROR);
logger.error("save erro.", e);
}
return newMap;
}
/**
* 核对,有加注没里程
* @param map
* @return
*/
@Transactional
@Override
public Map<String, Object> checkDl(Map<String, Object> map) {
Map<String, Object> newMap=new HashMap<String,Object>();
String xlbm=map.get("xlbm_eq").toString();
// TODO Auto-generated method stub
try{
//获取车辆存油信息
// List<Cyl> cylList=cylRepository.findAll(new CustomerSpecs<Cyl>(newMap));
String rq=map.get("rq").toString();
List<Dlb> dlbList=repository.obtainDl(rq);
List<Ylxxb> ylxxbList=ylxxbRepository.obtainYlxx(rq,1);
//当天加电信息表
List<Jdl> jdlList=jdlRepository.JdlList(rq);
for (int i = 0; i < ylxxbList.size(); i++) {
Boolean fage=true;
Ylxxb y1=ylxxbList.get(i);
for(int y=0;y<dlbList.size();y++){
Dlb y2=dlbList.get(y);
if(y1.getNbbm().equals(y2.getNbbm())){
fage=false;
break;
}
}
if(fage){
Dlb t=new Dlb();
t.setNbbm(y1.getNbbm());
t.setRq(y1.getYyrq());
t.setJsy(y1.getJsy());
t.setCdl(y1.getJzl());
t.setSsgsdm(y1.getGsdm());
t.setXlbm(xlbm);
repository.save(t);
}
}
for (int i = 0; i < jdlList.size(); i++) {
Boolean fage=true;
Jdl y1=jdlList.get(i);
for(int y=0;y<dlbList.size();y++){
Dlb y2=dlbList.get(y);
if(y1.getNbbm().equals(y2.getNbbm())){
fage=false;
break;
}
}
if(fage){
Dlb t=new Dlb();
t.setNbbm(y1.getNbbm());
t.setRq(y1.getRq());
// t.setJsy(y1.getJsy());
t.setCdl(y1.getJdl());
t.setSsgsdm(y1.getGsBm());
t.setXlbm(xlbm);
repository.save(t);
}
}
newMap.put("status", ResponseCode.SUCCESS);
}catch(Exception e){
newMap.put("status", ResponseCode.ERROR);
logger.error("save erro.", e);
}
return newMap;
}
}