提交 | 用户 | 时间
|
58d006
|
1 |
package com.mandi.fendan.service.impl; |
A |
2 |
|
|
3 |
import java.lang.reflect.InvocationTargetException; |
|
4 |
import java.util.*; |
|
5 |
|
|
6 |
import javax.annotation.Resource; |
|
7 |
import javax.transaction.Transactional; |
|
8 |
|
|
9 |
import com.mandi.fendan.mapper.FdMxWlgsMapper; |
|
10 |
import com.mandi.system.persist.Login; |
|
11 |
import com.mandi.system.persist.UserType; |
|
12 |
import org.springframework.stereotype.Service; |
|
13 |
|
|
14 |
import com.google.gson.JsonObject; |
|
15 |
import com.mandi.fendan.persist.Fd_Company; |
|
16 |
import com.mandi.fendan.persist.Fd_Vehicle; |
|
17 |
|
|
18 |
import org.apache.commons.beanutils.BeanUtils; |
|
19 |
import org.apache.commons.lang3.StringUtils; |
|
20 |
|
|
21 |
import com.mandi.basicconfig.mapper.NczsjMapper; |
|
22 |
import com.mandi.basicconfig.penum.PrefixEnum; |
|
23 |
import com.mandi.basicconfig.persist.Ncywdy; |
|
24 |
import com.mandi.common.JSONobj; |
|
25 |
import com.mandi.common.Wxhtmethod; |
|
26 |
import com.mandi.dao.common.Daomethod; |
|
27 |
import com.mandi.dao.common.ObjectResult; |
|
28 |
import com.mandi.dao.common.PageRequest; |
|
29 |
import com.mandi.dao.common.PageResult; |
|
30 |
import com.mandi.fendan.mapper.Fd_CompanyMapper; |
|
31 |
import com.mandi.fendan.mapper.Fd_VehicleMapper; |
|
32 |
import com.mandi.fendan.mapper.Fd_fhdqMapper; |
|
33 |
import com.mandi.fendan.service.Ifd_companyService; |
|
34 |
import com.mandi.fendan.util.Contants; |
|
35 |
import com.mandi.common.Pinyinmethod; |
|
36 |
@Service |
|
37 |
public class Fd_CompanyService implements Ifd_companyService { |
|
38 |
@Resource |
|
39 |
private Fd_CompanyMapper cmper; |
|
40 |
@Resource |
|
41 |
private Fd_fhdqMapper dqper; |
|
42 |
@Resource |
|
43 |
private Fd_VehicleMapper vhper; |
|
44 |
@Resource |
|
45 |
private NczsjMapper zsjper; |
|
46 |
|
|
47 |
@Resource |
|
48 |
private FdMxWlgsMapper fdMxWlgsMapper; |
|
49 |
|
|
50 |
@Override |
|
51 |
public ObjectResult<Fd_Company> get(String id) { |
|
52 |
ObjectResult<Fd_Company> prr = new ObjectResult<Fd_Company>(); |
|
53 |
if(!StringUtils.isBlank(id)){ |
|
54 |
Fd_Company fcy = cmper.get(id); |
|
55 |
prr.setCode(0); |
|
56 |
prr.setItem(fcy); |
|
57 |
}else{ |
|
58 |
prr.setCode(1); |
|
59 |
prr.setErrmsg("编号不能为空");; |
|
60 |
} |
|
61 |
|
|
62 |
return prr; |
|
63 |
} |
|
64 |
@Override |
|
65 |
public ObjectResult<Fd_Company> getByCompanyNo(String companyNo) { |
|
66 |
ObjectResult<Fd_Company> prr = new ObjectResult<Fd_Company>(); |
|
67 |
if(!StringUtils.isBlank(companyNo)){ |
|
68 |
Fd_Company fcy = cmper.getByCompanyNo(companyNo); |
|
69 |
prr.setCode(0); |
|
70 |
prr.setItem(fcy); |
|
71 |
}else{ |
|
72 |
prr.setCode(1); |
|
73 |
prr.setErrmsg("公司编号不能为空");; |
|
74 |
} |
|
75 |
|
|
76 |
return prr; |
|
77 |
} |
|
78 |
|
|
79 |
@Override |
|
80 |
public PageResult<Map<String, Object>> getlist(String name, PageRequest pr) { |
|
81 |
PageResult<Map<String, Object>> prr=new PageResult<Map<String, Object>>(); |
|
82 |
List<Map<String, Object>> rl=new ArrayList<Map<String,Object>>(); |
|
83 |
Map<String, Object> mp=new HashMap<String, Object>(); |
|
84 |
mp.put("pagesize", pr.getPageSize()); |
|
85 |
mp.put("page", pr.getStart()); |
|
86 |
mp.put("name", name); |
|
87 |
List<Fd_Company> list; |
|
88 |
if(pr.isNeedPages()) |
|
89 |
{ |
|
90 |
int pages=cmper.getPages(mp); |
|
91 |
pages=Daomethod.countpages(pages, pr.getPageSize()); |
|
92 |
prr.setPages(pages); |
|
93 |
list =cmper.getList(mp); |
|
94 |
}else{ |
|
95 |
list = cmper.getList1(mp); |
|
96 |
} |
|
97 |
|
|
98 |
if(list!=null){ |
|
99 |
for (Fd_Company fdc : list) { |
|
100 |
String comNo=fdc.getCompanyNo(); |
|
101 |
Map<String, Object> rm=new HashMap<String, Object>(); |
|
102 |
try { |
|
103 |
rm=BeanUtils.describe(fdc); |
|
104 |
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { |
|
105 |
} |
|
106 |
List<Ncywdy> cyl=this.cmper.getncYwdylist(comNo); |
|
107 |
rm.put("ywList", cyl); |
|
108 |
rl.add(rm); |
|
109 |
} |
|
110 |
} |
|
111 |
prr.setCode(0); |
|
112 |
prr.setList(rl); |
|
113 |
return prr; |
|
114 |
} |
|
115 |
|
|
116 |
@Override |
|
117 |
public List<Map<String, Object>> companytypehead(String search, int pagesize) { |
|
118 |
|
|
119 |
return null; |
|
120 |
} |
|
121 |
|
|
122 |
@Override |
|
123 |
public ObjectResult<Fd_Company> saveCompany(Fd_Company c,String ywdyNos) throws Exception { |
|
124 |
ObjectResult<Fd_Company> orr=new ObjectResult<Fd_Company>(); |
|
125 |
if(c==null){ |
|
126 |
orr.setCode(1); |
|
127 |
orr.setErrmsg("运输公司对象为空,不能保存"); |
|
128 |
return orr; |
|
129 |
} |
|
130 |
if(StringUtils.isEmpty(c.getName())){ |
|
131 |
orr.setCode(1); |
|
132 |
orr.setErrmsg("运输公司名字为空,不能保存"); |
|
133 |
return orr; |
|
134 |
} |
|
135 |
String hdpinyin=Pinyinmethod.pinyinhds(c.getName()); |
|
136 |
String pinyin=Pinyinmethod.pinyins(c.getName()); |
|
137 |
c.setPinyin(pinyin); |
|
138 |
c.setHdpinyin(hdpinyin); |
|
139 |
String id=c.getId(); |
|
140 |
try { |
|
141 |
Fd_Company c1= cmper.get(id); |
|
142 |
if(c1!=null){ |
|
143 |
Fd_Company fcd=cmper.getByCompanyNo(c.getCompanyNo()); |
|
144 |
if(fcd!=null&&!fcd.getId().equals(c1.getId())){ |
|
145 |
orr.setCode(1); |
|
146 |
orr.setErrmsg("运输公司编号已存在,不能保存,请修改!"); |
|
147 |
return orr; |
|
148 |
} |
|
149 |
|
|
150 |
c1.setCname(c.getCname()); |
|
151 |
c1.setHdpinyin(c.getHdpinyin()); |
|
152 |
c1.setPinyin(c.getPinyin()); |
|
153 |
c1.setNote(c.getNote()); |
|
154 |
c1.setCtime(new Date()); |
|
155 |
c1.setCompanyNo(c.getCompanyNo()); |
|
156 |
c1.setHasSPR(c.isHasSPR()); |
|
157 |
c1.setName(c.getName()); |
|
158 |
cmper.update(c1); |
|
159 |
this.cmper.delCYnexus(c.getCompanyNo()); |
|
160 |
orr.setItem(c1); |
|
161 |
}else{ |
|
162 |
if(StringUtils.isEmpty(c.getCompanyNo())){ |
|
163 |
JsonObject pfob=Wxhtmethod.postJsonStr(Contants.YKTgetPrefix_url,PrefixEnum.fd_Company.toString()); |
|
164 |
ObjectResult<String> pfor=new ObjectResult<String>(); |
|
165 |
String bsNo=JSONobj.getstring(pfob, "item"); |
|
166 |
int code=JSONobj.getint(pfob, "code"); |
|
167 |
String errmsg=JSONobj.getstring(pfob, "errmsg"); |
|
168 |
pfor.setCode(code); |
|
169 |
pfor.setErrmsg(errmsg); |
|
170 |
pfor.setItem(bsNo); |
|
171 |
if(pfor==null||pfor.getCode()!=0){ |
|
172 |
orr.setCode(1); |
|
173 |
orr.setErrmsg(pfor.getErrmsg()); |
|
174 |
return orr; |
|
175 |
} |
|
176 |
c.setCompanyNo(pfor.getItem()); |
|
177 |
}else{ |
|
178 |
Fd_Company fcd=cmper.getByCompanyNo(c.getCompanyNo()); |
|
179 |
if(fcd!=null){ |
|
180 |
orr.setCode(1); |
|
181 |
orr.setErrmsg("运输公司编号已存在,不能保存,请修改!"); |
|
182 |
return orr; |
|
183 |
} |
|
184 |
} |
|
185 |
c.setCtime(new Date()); |
|
186 |
c.setId(UUID.randomUUID()+""); |
|
187 |
cmper.insert(c); |
|
188 |
orr.setItem(c); |
|
189 |
} |
|
190 |
} catch (Exception e) { |
|
191 |
throw new Exception(StringUtils.isEmpty(e.getMessage())?"物流公司保存出错!":e.getMessage()); |
|
192 |
} |
|
193 |
//修改运输公司和业务单元关联表 |
|
194 |
if(!StringUtils.isEmpty(ywdyNos)){ |
|
195 |
for (String ywdyNo : ywdyNos.split(",")) { |
|
196 |
Ncywdy ywdy=this.zsjper.getNcywdybyCode(ywdyNo); |
|
197 |
if(ywdy==null) |
|
198 |
continue; |
|
199 |
this.cmper.insertCYnexus(c.getCompanyNo(), ywdyNo); |
|
200 |
} |
|
201 |
} |
|
202 |
|
|
203 |
orr.setCode(0); |
|
204 |
orr.setItem(c); |
|
205 |
return orr; |
|
206 |
} |
|
207 |
|
|
208 |
@Override |
|
209 |
public ObjectResult<Boolean> changeUsed(Fd_Company cp) { |
|
210 |
|
|
211 |
return null; |
|
212 |
} |
|
213 |
|
|
214 |
@Override |
|
215 |
@Transactional(rollbackOn=Exception.class) |
|
216 |
public ObjectResult<Boolean> delCompany(String companyNo) throws Exception{ |
|
217 |
ObjectResult<Boolean> prr = new ObjectResult<Boolean>(); |
|
218 |
if(!StringUtils.isBlank(companyNo)){ |
|
219 |
|
|
220 |
try { |
|
221 |
Fd_Vehicle fdv=this.vhper.selectbyCompanyNo(companyNo); |
|
222 |
if(fdv!=null){ |
|
223 |
prr.setCode(1); |
|
224 |
prr.setErrmsg("请先删除所属的该物流公司的车辆信息!"); |
|
225 |
return prr; |
|
226 |
} |
|
227 |
cmper.delByCompanyNo(companyNo); |
|
228 |
this.dqper.delbywlgsCode(companyNo); |
|
229 |
this.cmper.delCYnexus(companyNo); |
|
230 |
prr.setCode(0); |
|
231 |
prr.setItem(true); |
|
232 |
} catch (Exception e) { |
|
233 |
throw new Exception(StringUtils.isEmpty(e.getMessage())?"物流公司删除程序出错!":e.getMessage()); |
|
234 |
} |
|
235 |
prr.setCode(0); |
|
236 |
prr.setItem(true); |
|
237 |
}else{ |
|
238 |
prr.setCode(1); |
|
239 |
prr.setErrmsg("公司编号不能为空"); |
|
240 |
} |
|
241 |
return prr; |
|
242 |
|
|
243 |
} |
|
244 |
|
|
245 |
|
|
246 |
@Override |
|
247 |
public PageResult<Map<String, Object>> getcqList(String companyNo) { |
|
248 |
PageResult<Map<String, Object>> prr=new PageResult<Map<String,Object>>(); |
|
249 |
LinkedList<Map<String, Object>> rl=new LinkedList<>(); |
|
250 |
if(StringUtils.isNotBlank(companyNo)){ |
|
251 |
List<Ncywdy> l=this.cmper.getncYwdylist(companyNo); |
|
252 |
|
|
253 |
Map<String, Ncywdy> map = new HashMap<>(); |
|
254 |
for (Ncywdy ncy : l) { // 排重 |
|
255 |
if (map.get(ncy.getCode()) == null) |
|
256 |
map.put(ncy.getCode(), ncy); |
|
257 |
} |
|
258 |
int a = 0; |
|
259 |
for (Map.Entry<String, Ncywdy> entry : map.entrySet()) { |
|
260 |
String code = entry.getKey(); |
|
261 |
Map<String, Object> m = null; |
|
262 |
if(Contants.nc_ywdy_ZZ.equals(code)){ |
|
263 |
m = new HashMap<>(2); |
|
264 |
m.put("name","郑州厂区"); |
|
265 |
m.put("cqval",Contants.nc_ywdy_ZZ); |
|
266 |
}else if(Contants.nc_ywdy_MS.equals(code)){ |
|
267 |
m = new HashMap<>(2); |
|
268 |
m.put("name","明晟厂区"); |
|
269 |
m.put("cqval",Contants.nc_ywdy_MS); |
|
270 |
}else if(Contants.nc_ywdy_YR.equals(code)){ |
|
271 |
m = new HashMap<>(2); |
|
272 |
m.put("name","义瑞厂区"); |
|
273 |
m.put("cqval",Contants.nc_ywdy_YR); |
|
274 |
} else{ |
|
275 |
if(a==0){ // 防止出现多个科技厂区 |
|
276 |
m = new HashMap<>(2); |
|
277 |
m.put("name","科技厂区"); |
|
278 |
m.put("cqval",Contants.nc_ywdy_KJ); |
|
279 |
a=1; |
|
280 |
// 特殊需求 科技要放到第一个 |
|
281 |
rl.addFirst(m); |
|
282 |
} |
|
283 |
// 防止出现空行 |
|
284 |
continue; |
|
285 |
} |
|
286 |
rl.add(m); |
|
287 |
} |
|
288 |
prr.setList(rl); |
|
289 |
}else{ |
|
290 |
Map<String, Object> m2=new HashMap<String, Object>(); |
|
291 |
m2.put("name","全部厂区"); |
|
292 |
m2.put("cqval",""); |
|
293 |
rl.add(m2); |
|
294 |
Map<String, Object> m=new HashMap<String, Object>(); |
|
295 |
m.put("name","科技厂区"); |
|
296 |
m.put("cqval",Contants.nc_ywdy_KJ); |
|
297 |
rl.add(m); |
|
298 |
Map<String, Object> m1=new HashMap<String, Object>(); |
|
299 |
m1.put("name","郑州厂区"); |
|
300 |
m1.put("cqval",Contants.nc_ywdy_ZZ); |
|
301 |
rl.add(m1); |
|
302 |
Map<String, Object> m3=new HashMap<String, Object>(); |
|
303 |
m3.put("name","明晟厂区"); |
|
304 |
m3.put("cqval",Contants.nc_ywdy_MS); |
|
305 |
rl.add(m3); |
|
306 |
Map<String, Object> m4=new HashMap<String, Object>(); |
|
307 |
m4.put("name","义瑞厂区"); |
|
308 |
m4.put("cqval",Contants.nc_ywdy_YR); |
|
309 |
rl.add(m4); |
|
310 |
prr.setList(rl); |
|
311 |
} |
|
312 |
prr.setCode(0); |
|
313 |
return prr; |
|
314 |
} |
|
315 |
@Override |
|
316 |
public PageResult<Map<String, Object>> getFdCqList(String companyNo, Login login) { |
|
317 |
PageResult<Map<String, Object>> prr=new PageResult<Map<String,Object>>(); |
|
318 |
LinkedList<Map<String, Object>> rl=new LinkedList<>(); |
|
319 |
if (!UserType.admin.toString().equals(login.getWorkerno())) { |
|
320 |
List<Map> l= fdMxWlgsMapper.selectChangqu(login.getUsername()); |
|
321 |
|
|
322 |
Map<String,Map> map = new HashMap<>(); |
|
323 |
for (Map map1 : l) { // 排重 |
|
324 |
if (map1.get(map1.get("fd_cq")) == null) |
|
325 |
map.put(map1.get("fd_cq").toString(), map1); |
|
326 |
} |
|
327 |
int a = 0; |
|
328 |
for (Map.Entry<String, Map> entry : map.entrySet()) { |
|
329 |
String code = entry.getKey(); |
|
330 |
Map<String, Object> m = null; |
|
331 |
if(Contants.nc_ywdy_ZZ.equals(code)){ |
|
332 |
m = new HashMap<>(2); |
|
333 |
m.put("name","郑州厂区"); |
|
334 |
m.put("cqval",Contants.nc_ywdy_ZZ); |
|
335 |
}else if(Contants.nc_ywdy_MS.equals(code)){ |
|
336 |
m = new HashMap<>(2); |
|
337 |
m.put("name","明晟厂区"); |
|
338 |
m.put("cqval",Contants.nc_ywdy_MS); |
|
339 |
}else if(Contants.nc_ywdy_YR.equals(code)){ |
|
340 |
m = new HashMap<>(2); |
|
341 |
m.put("name","义瑞厂区"); |
|
342 |
m.put("cqval",Contants.nc_ywdy_YR); |
|
343 |
} else{ |
|
344 |
if(a==0){ // 防止出现多个科技厂区 |
|
345 |
m = new HashMap<>(2); |
|
346 |
m.put("name","科技厂区"); |
|
347 |
m.put("cqval",Contants.nc_ywdy_KJ); |
|
348 |
a=1; |
|
349 |
// 特殊需求 科技要放到第一个 |
|
350 |
rl.addFirst(m); |
|
351 |
} |
|
352 |
// 防止出现空行 |
|
353 |
continue; |
|
354 |
} |
|
355 |
rl.add(m); |
|
356 |
} |
|
357 |
prr.setList(rl); |
|
358 |
}else{ |
|
359 |
Map<String, Object> m2=new HashMap<String, Object>(); |
|
360 |
m2.put("name","全部厂区"); |
|
361 |
m2.put("cqval",""); |
|
362 |
rl.add(m2); |
|
363 |
Map<String, Object> m=new HashMap<String, Object>(); |
|
364 |
m.put("name","科技厂区"); |
|
365 |
m.put("cqval",Contants.nc_ywdy_KJ); |
|
366 |
rl.add(m); |
|
367 |
Map<String, Object> m1=new HashMap<String, Object>(); |
|
368 |
m1.put("name","郑州厂区"); |
|
369 |
m1.put("cqval",Contants.nc_ywdy_ZZ); |
|
370 |
rl.add(m1); |
|
371 |
Map<String, Object> m3=new HashMap<String, Object>(); |
|
372 |
m3.put("name","明晟厂区"); |
|
373 |
m3.put("cqval",Contants.nc_ywdy_MS); |
|
374 |
rl.add(m3); |
|
375 |
Map<String, Object> m4=new HashMap<String, Object>(); |
|
376 |
m4.put("name","义瑞厂区"); |
|
377 |
m4.put("cqval",Contants.nc_ywdy_YR); |
|
378 |
rl.add(m4); |
|
379 |
prr.setList(rl); |
|
380 |
} |
|
381 |
prr.setCode(0); |
|
382 |
return prr; |
|
383 |
} |
|
384 |
|
|
385 |
|
|
386 |
} |