PersonnelServiceImpl.java
11.9 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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
package com.bsth.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bsth.entity.Business;
import com.bsth.entity.Personnel;
import com.bsth.entity.PersonnelCopy;
import com.bsth.repository.PersonnelRepository;
import com.bsth.service.PersonnelService;
import com.bsth.util.XmlToJson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Transient;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* Created by xu on 16/6/15.
*/
@Service
public class PersonnelServiceImpl implements PersonnelService {
// TODO 以后过滤退休人员
@Autowired
PersonnelRepository repository;
@Autowired
JdbcTemplate jdbcTemplate;
Logger logger = LoggerFactory.getLogger(this.getClass());
@Transient
@Override
public List<PersonnelCopy> matchPersonnel(JSONArray retiredInfor,String _getEmployee__return,int index,Map<String, Personnel> personnelMap) {
Map<String,String> gzDictionaryMap = new HashMap<>();
gzDictionaryMap.put("路线驾驶员","1");
gzDictionaryMap.put("团客车驾驶员","1");
gzDictionaryMap.put("后方驾驶员","1");
gzDictionaryMap.put("实习驾驶员","1");
gzDictionaryMap.put("调度员","2");
gzDictionaryMap.put("售票员","3");
gzDictionaryMap.put("公共汽电车售票员","3");
gzDictionaryMap.put("管理员","3");
gzDictionaryMap.put("站员","4");
gzDictionaryMap.put("安检员","6");
gzDictionaryMap.put("机务","7");
gzDictionaryMap.put("机务员/质检员","7");
gzDictionaryMap.put("引导员","8");
gzDictionaryMap.put("乘务员","9");
gzDictionaryMap.put("线长(正职)","10");
gzDictionaryMap.put("线长(副职)","10");
gzDictionaryMap.put("见习管理人员","11");
gzDictionaryMap.put("公司部门管理人员","11");
gzDictionaryMap.put("机务员/警消人员","12");
gzDictionaryMap.put("线长(副职)","13");
gzDictionaryMap.put("见习管理人员","11");
gzDictionaryMap.put("公司部门管理人员","11");
gzDictionaryMap.put("机务员/警消人员","12");
gzDictionaryMap.put("票务人员","13");
gzDictionaryMap.put("其他服务人员","14");
String sql="select * from bsth_c_business ";
List<Business> businessList=jdbcTemplate.query(sql, new BeanPropertyRowMapper(Business.class));
Map<String,Map<String,Business>> businessMap = new HashMap<>();
for (Business bu:businessList) {
Map<String,Business> buMap = new HashMap<>();
if (businessMap.get(bu.getUpCode()) != null)
buMap = businessMap.get(bu.getUpCode());
/*if(bu.getUpCode().equals("55"))
buMap.put(bu.getBusinessName().substring(2),bu);
else*/
buMap.put(bu.getBusinessName(),bu);
businessMap.put(bu.getUpCode(),buMap);
}
List<Personnel> newPersonnel = new ArrayList<>();
// Map<String, Object> retiredInforMap = new HashMap<>();
try{
// if(retiredInfor.size() > 0){
// for(int i=0;i<retiredInfor.size()-1; i++){
// JSONObject pjson = retiredInfor.getJSONObject(i);
// String codeArr[] = pjson.getString("Code").split("-");
// String code = "",
// companyCode="";
//
// if(codeArr.length > 1){
// if (index == 0) {
// // 上南
// code = 55+"-"+codeArr[1];
// companyCode = "55";
// } else if (index == 1) {
// // 金高
// code = 22+"-"+codeArr[1];
// companyCode = "22";
// } else if (index == 2) {
// // 南汇
// code = 26+"-"+codeArr[1];
// companyCode = "26";
// } else if(index == 3){
// // 杨高
// code = "05"+"-"+codeArr[1];
// companyCode = "05";
// }
//// retiredInforMap.put(code,pjson);
// }
// }
// }
// 金蝶人员数据转为json,然后遍历匹配
JSONObject jsonInfor = XmlToJson.xml2Json(_getEmployee__return);
System.out.println("getEmployee.result=" + _getEmployee__return);
JSONArray jsonArr = JSONArray.parseArray(jsonInfor.get("Emp").toString());
for(int i=0;i<jsonArr.size()-1; i++){
JSONObject pjson = jsonArr.getJSONObject(i);
String codeArr[] = pjson.getString("Code").split("-");
String JobCodeori = codeArr[1];
while (JobCodeori.length() < 6){
JobCodeori = "0"+JobCodeori;
}
// Personnel p = new Personnel();
// p.setJdCodeori(pjson.getString("Code"));
// p.setJobCodeori(JobCodeori);
// p.setPersonnelName(pjson.getString("EmployeeName"));
// p.setCompany(pjson.getString("CompanyName"));
//
// newPersonnel.add(p);
String code = "",
companyCode="",
company="";
Business business = new Business();
String companyName = pjson.getString("CompanyName");
// 人员数据匹配公司
if (index == 0) {
// 上南
code = 55+"-"+JobCodeori;
companyCode = "55";
company = "上南公司";
if (companyName.indexOf("一分") > -1) {
business = businessMap.get(companyCode).get("上南一分公司");
} else if (companyName.indexOf("二分") > -1) {
business = businessMap.get(companyCode).get("上南二分公司");
} else if (companyName.indexOf("三分") > -1) {
business = businessMap.get(companyCode).get("上南三分公司");
} else if (companyName.indexOf("六分") > -1) {
business = businessMap.get(companyCode).get("上南六分公司");
} else if (companyName.indexOf("山南") > -1) {
business = businessMap.get(companyCode).get("山南培训部");
} else {
business = businessMap.get(companyCode).get("其它分公司");
}
} else if (index == 1) {
// 金高
code = 22+"-"+JobCodeori;
companyCode = "22";
company = "金高公司";
if (companyName.indexOf("一分") > -1) {
business = businessMap.get(companyCode).get("一分公司");
} else if (companyName.indexOf("二分") > -1) {
business = businessMap.get(companyCode).get("二分公司");
} else if (companyName.indexOf("三分") > -1) {
business = businessMap.get(companyCode).get("三分公司");
} else if (companyName.indexOf("四分") > -1) {
business = businessMap.get(companyCode).get("四分公司");
} else {
business = businessMap.get(companyCode).get("其它分公司");
}
} else if (index == 2) {
// 南汇
code = 26+"-"+JobCodeori;
companyCode = "26";
company = "南汇公司";
if (companyName.indexOf("一分") > -1) {
business = businessMap.get(companyCode).get("南汇一分");
} else if (companyName.indexOf("二分") > -1) {
business = businessMap.get(companyCode).get("南汇二分");
} else if (companyName.indexOf("三分") > -1) {
business = businessMap.get(companyCode).get("南汇三分");
} else if (companyName.indexOf("维修") > -1) {
business = businessMap.get(companyCode).get("南汇维修公司");
} else if (companyName.indexOf("南汇公司") > -1) {
business = businessMap.get(companyCode).get("南汇公司");
} else if (companyName.indexOf("航头") > -1) {
business = businessMap.get(companyCode).get("航头枢纽站");
} else {
business = businessMap.get(companyCode).get("其它分公司");
}
} else if(index == 3){
code = "05"+"-"+JobCodeori;
companyCode = "05";
company = "杨高公司";
if (companyName.indexOf("川沙") > -1) {
business = businessMap.get(companyCode).get("川沙分公司");
} else if (companyName.indexOf("金桥") > -1) {
business = businessMap.get(companyCode).get("金桥分公司");
} else if (companyName.indexOf("杨高") > -1) {
business = businessMap.get(companyCode).get("杨高分公司");
} else if (companyName.indexOf("周浦") > -1) {
business = businessMap.get(companyCode).get("周浦分公司");
} else if (companyName.indexOf("芦潮港") > -1) {
business = businessMap.get(companyCode).get("芦潮港分公司");
} else {
business = businessMap.get(companyCode).get("其它分公司");
}
}
//
// if(pjson.getString("Code").equals("03-S07265") ||pjson.getString("Code").equals("03-S07273") ||pjson.getString("Code").equals("03-S07264")
// ||pjson.getString("Code").equals("03-S07269") ||pjson.getString("Code").equals("03-S07274") ||pjson.getString("Code").equals("03-S07275")
// ||pjson.getString("Code").equals("03-S07267") ||pjson.getString("Code").equals("03-S07268") ||pjson.getString("Code").equals("05-006008")
// ||pjson.getString("Code").equals("02-017122")){
// System.out.print(pjson);
// }
// if(pjson.getString("EmployeeName").equals("吴燕辉") || pjson.getString("EmployeeName").equals("顾振军")|| pjson.getString("EmployeeName").equals("宋荣甲")){
// System.out.print(pjson);
// }
/*if(codeArr[0].equals("02")){
code = "05"+"-"+JobCodeori;
companyCode = "05";
company = "杨高公司";
} else if(codeArr[0].equals("03")){
code = 55+"-"+JobCodeori;
companyCode = "55";
company = "上南公司";
} else if(codeArr[0].equals("04")){
code = 22+"-"+JobCodeori;
companyCode = "22";
company = "金高公司";
} else if(codeArr[0].equals("05")){
code = 26+"-"+JobCodeori;
companyCode = "26";
company = "南汇公司";
}*/
Personnel p = personnelMap.get(code);
// Object isRetiredInfor = retiredInforMap.get(code);
// p不为空这表示调度数据和金蝶数据能匹配、则更新数据,不能匹配这新增数据
if(p != null ){
// p.setCard(pjson.getString("IDCardID"));// 第一次需要添加身份证,后面则不需要了
if(pjson.getString("IDCardID").equals(p.getCard())){
p.setBrancheCompanyCode(business.getBusinessCode());
p.setBrancheCompany(business.getBusinessName());
p.setPersonnelName(pjson.getString("EmployeeName"));
p.setDescriptions(pjson.getString("UnitFullName"));
p.setJdCodeori(pjson.getString("Code")); // 金蝶工号
p.setUpdateDate(new Date());
// 设置人员为在职状态
p.setDestroy(0);
newPersonnel.add(p);
}
} else {
p = new Personnel();
p.setJobCode(code);
p.setJobCodeori(JobCodeori);
p.setCard(pjson.getString("IDCardID"));
// String companyName = pjson.getString("CompanyName");
// // 搜索分公司
// Business business = businessMap.get(companyCode).get(companyName);
// if(business != null){
// } else {
// p.setBrancheCompanyCode("");
// p.setBrancheCompany("");
// }
p.setBrancheCompanyCode(business.getBusinessCode());
p.setBrancheCompany(business.getBusinessName());
p.setCompanyCode(companyCode);
p.setCompany(company);
p.setJdCodeori(pjson.getString("Code")); // 金蝶工号
p.setPersonnelName(pjson.getString("EmployeeName"));
p.setPersonnelType(pjson.getString("SexType").indexOf("男") > -1 ?"1":"2");
p.setPosts(gzDictionaryMap.get(pjson.getString("PositName")) == null?"14":gzDictionaryMap.get(pjson.getString("PositName")));
p.setDescriptions(pjson.getString("UnitFullName"));
p.setTelphone(pjson.getString("Telphone"));
p.setUpdateDate(new Date());
p.setRemark("新增");
// 设置人员为在职状态
p.setDestroy(0);
// if(isRetiredInfor != null && isRetiredInfor != ""){
// p.setRemark("退休");
// }
newPersonnel.add(p);
}
}
// 批量保存
repository.save(newPersonnel);
} catch (Exception e) {
logger.error("", e);
}
return null;
}
/*public Map<String, Personnel> loadPersonnel(){
Map<String, Personnel> personnelMap= new HashMap<>();
Iterator<Personnel> perIterator=repository.findAll().iterator();
Personnel per;
while(perIterator.hasNext()){
per=perIterator.next();
personnelMap.put(per.getJobCode(),per);
}
return personnelMap;
}*/
}