hjg
2023-11-22 975c04c0181b3da82a79cb04abe6a2f1799eb363
提交 | 用户 | 时间
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());
975c04 158                 c1.setShortName(c.getShortName());
58d006 159                 cmper.update(c1);
A 160                 this.cmper.delCYnexus(c.getCompanyNo());
161                 orr.setItem(c1);
162             }else{
163                 if(StringUtils.isEmpty(c.getCompanyNo())){
164                     JsonObject pfob=Wxhtmethod.postJsonStr(Contants.YKTgetPrefix_url,PrefixEnum.fd_Company.toString());
165                     ObjectResult<String> pfor=new ObjectResult<String>();
166                     String bsNo=JSONobj.getstring(pfob, "item");
167                     int code=JSONobj.getint(pfob, "code");
168                     String errmsg=JSONobj.getstring(pfob, "errmsg");
169                     pfor.setCode(code);
170                     pfor.setErrmsg(errmsg);
171                     pfor.setItem(bsNo);
172                     if(pfor==null||pfor.getCode()!=0){
173                         orr.setCode(1);
174                         orr.setErrmsg(pfor.getErrmsg());
175                         return orr;
176                     }
177                     c.setCompanyNo(pfor.getItem());
178                 }else{
179                     Fd_Company fcd=cmper.getByCompanyNo(c.getCompanyNo());
180                     if(fcd!=null){
181                         orr.setCode(1);
182                         orr.setErrmsg("运输公司编号已存在,不能保存,请修改!");
183                         return orr;
184                     }
185                 }
186                 c.setCtime(new Date());
187                 c.setId(UUID.randomUUID()+"");
188                 cmper.insert(c);
189                 orr.setItem(c);
190             }
191         } catch (Exception e) {
192             throw new Exception(StringUtils.isEmpty(e.getMessage())?"物流公司保存出错!":e.getMessage());
193         }
194         //修改运输公司和业务单元关联表
195         if(!StringUtils.isEmpty(ywdyNos)){
196             for (String ywdyNo : ywdyNos.split(",")) {
197                 Ncywdy ywdy=this.zsjper.getNcywdybyCode(ywdyNo);
198                 if(ywdy==null)
199                     continue;
200                 this.cmper.insertCYnexus(c.getCompanyNo(), ywdyNo);
201             }
202         }
203
204         orr.setCode(0);
205         orr.setItem(c);
206         return orr;
207     }
208
209     @Override
210     public ObjectResult<Boolean> changeUsed(Fd_Company cp) {
211
212         return null;
213     }
214
215     @Override
216     @Transactional(rollbackOn=Exception.class)
217     public ObjectResult<Boolean> delCompany(String companyNo) throws Exception{
218         ObjectResult<Boolean> prr = new ObjectResult<Boolean>();
219         if(!StringUtils.isBlank(companyNo)){
220
221             try {
222                 Fd_Vehicle fdv=this.vhper.selectbyCompanyNo(companyNo);
223                 if(fdv!=null){
224                     prr.setCode(1);
225                     prr.setErrmsg("请先删除所属的该物流公司的车辆信息!");
226                     return prr;
227                 }
228                 cmper.delByCompanyNo(companyNo);
229                 this.dqper.delbywlgsCode(companyNo);
230                 this.cmper.delCYnexus(companyNo);
231                 prr.setCode(0);
232                 prr.setItem(true);
233             } catch (Exception e) {
234                 throw new Exception(StringUtils.isEmpty(e.getMessage())?"物流公司删除程序出错!":e.getMessage());
235             }
236             prr.setCode(0);
237             prr.setItem(true);
238         }else{
239             prr.setCode(1);
240             prr.setErrmsg("公司编号不能为空");
241         }
242         return prr;
243
244     }
245
246
247     @Override
248     public PageResult<Map<String, Object>> getcqList(String companyNo) {
249         PageResult<Map<String, Object>> prr=new PageResult<Map<String,Object>>();
250         LinkedList<Map<String, Object>> rl=new LinkedList<>();
251         if(StringUtils.isNotBlank(companyNo)){
252             List<Ncywdy> l=this.cmper.getncYwdylist(companyNo);
253
254             Map<String, Ncywdy> map = new HashMap<>();
255             for (Ncywdy ncy : l) { // 排重
256                 if (map.get(ncy.getCode()) == null)
257                     map.put(ncy.getCode(), ncy);
258             }
259             int a = 0;
260             for (Map.Entry<String, Ncywdy> entry : map.entrySet()) {
261                 String code = entry.getKey();
262                 Map<String, Object> m = null;
263                 if(Contants.nc_ywdy_ZZ.equals(code)){
264                     m = new HashMap<>(2);
265                     m.put("name","郑州厂区");
266                     m.put("cqval",Contants.nc_ywdy_ZZ);
267                 }else if(Contants.nc_ywdy_MS.equals(code)){
268                     m = new HashMap<>(2);
269                     m.put("name","明晟厂区");
270                     m.put("cqval",Contants.nc_ywdy_MS);
271                 }else if(Contants.nc_ywdy_YR.equals(code)){
272                     m = new HashMap<>(2);
273                     m.put("name","义瑞厂区");
274                     m.put("cqval",Contants.nc_ywdy_YR);
275                 } else{
276                     if(a==0){ // 防止出现多个科技厂区
277                         m = new HashMap<>(2);
278                         m.put("name","科技厂区");
279                         m.put("cqval",Contants.nc_ywdy_KJ);
280                         a=1;
281                         // 特殊需求 科技要放到第一个
282                         rl.addFirst(m);
283                     }
284                     // 防止出现空行
285                     continue;
286                 }
287                 rl.add(m);
288             }
289             prr.setList(rl);
290         }else{
291             Map<String, Object> m2=new HashMap<String, Object>();
292             m2.put("name","全部厂区");
293             m2.put("cqval","");
294             rl.add(m2);
295             Map<String, Object> m=new HashMap<String, Object>();
296             m.put("name","科技厂区");
297             m.put("cqval",Contants.nc_ywdy_KJ);
298             rl.add(m);
299             Map<String, Object> m1=new HashMap<String, Object>();
300             m1.put("name","郑州厂区");
301             m1.put("cqval",Contants.nc_ywdy_ZZ);
302             rl.add(m1);
303             Map<String, Object> m3=new HashMap<String, Object>();
304             m3.put("name","明晟厂区");
305             m3.put("cqval",Contants.nc_ywdy_MS);
306             rl.add(m3);
307             Map<String, Object> m4=new HashMap<String, Object>();
308             m4.put("name","义瑞厂区");
309             m4.put("cqval",Contants.nc_ywdy_YR);
310             rl.add(m4);
311             prr.setList(rl);
312         }
313         prr.setCode(0);
314         return prr;
315     }
316     @Override
317     public PageResult<Map<String, Object>> getFdCqList(String companyNo, Login login) {
318         PageResult<Map<String, Object>> prr=new PageResult<Map<String,Object>>();
319         LinkedList<Map<String, Object>> rl=new LinkedList<>();
320         if (!UserType.admin.toString().equals(login.getWorkerno())) {
321             List<Map> l= fdMxWlgsMapper.selectChangqu(login.getUsername());
322
323             Map<String,Map> map = new HashMap<>();
324             for (Map map1 : l) { // 排重
325                 if (map1.get(map1.get("fd_cq")) == null)
326                     map.put(map1.get("fd_cq").toString(), map1);
327             }
328             int a = 0;
329             for (Map.Entry<String, Map> entry : map.entrySet()) {
330                 String code = entry.getKey();
331                 Map<String, Object> m = null;
332                 if(Contants.nc_ywdy_ZZ.equals(code)){
333                     m = new HashMap<>(2);
334                     m.put("name","郑州厂区");
335                     m.put("cqval",Contants.nc_ywdy_ZZ);
336                 }else if(Contants.nc_ywdy_MS.equals(code)){
337                     m = new HashMap<>(2);
338                     m.put("name","明晟厂区");
339                     m.put("cqval",Contants.nc_ywdy_MS);
340                 }else if(Contants.nc_ywdy_YR.equals(code)){
341                     m = new HashMap<>(2);
342                     m.put("name","义瑞厂区");
343                     m.put("cqval",Contants.nc_ywdy_YR);
344                 } else{
345                     if(a==0){ // 防止出现多个科技厂区
346                         m = new HashMap<>(2);
347                         m.put("name","科技厂区");
348                         m.put("cqval",Contants.nc_ywdy_KJ);
349                         a=1;
350                         // 特殊需求 科技要放到第一个
351                         rl.addFirst(m);
352                     }
353                     // 防止出现空行
354                     continue;
355                 }
356                 rl.add(m);
357             }
358             prr.setList(rl);
359         }else{
360             Map<String, Object> m2=new HashMap<String, Object>();
361             m2.put("name","全部厂区");
362             m2.put("cqval","");
363             rl.add(m2);
364             Map<String, Object> m=new HashMap<String, Object>();
365             m.put("name","科技厂区");
366             m.put("cqval",Contants.nc_ywdy_KJ);
367             rl.add(m);
368             Map<String, Object> m1=new HashMap<String, Object>();
369             m1.put("name","郑州厂区");
370             m1.put("cqval",Contants.nc_ywdy_ZZ);
371             rl.add(m1);
372             Map<String, Object> m3=new HashMap<String, Object>();
373             m3.put("name","明晟厂区");
374             m3.put("cqval",Contants.nc_ywdy_MS);
375             rl.add(m3);
376             Map<String, Object> m4=new HashMap<String, Object>();
377             m4.put("name","义瑞厂区");
378             m4.put("cqval",Contants.nc_ywdy_YR);
379             rl.add(m4);
380             prr.setList(rl);
381         }
382         prr.setCode(0);
383         return prr;
384     }
385
386
387 }