hjg
2023-11-17 3780c5e65b05bf23020810798babc6d20311fa79
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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
package com.mandi.fendan.service.impl;
 
import java.lang.reflect.InvocationTargetException;
import java.util.*;
 
import javax.annotation.Resource;
import javax.transaction.Transactional;
 
import com.mandi.fendan.mapper.FdMxWlgsMapper;
import com.mandi.system.persist.Login;
import com.mandi.system.persist.UserType;
import org.springframework.stereotype.Service;
 
import com.google.gson.JsonObject;
import com.mandi.fendan.persist.Fd_Company;
import com.mandi.fendan.persist.Fd_Vehicle;
 
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
 
import com.mandi.basicconfig.mapper.NczsjMapper;
import com.mandi.basicconfig.penum.PrefixEnum;
import com.mandi.basicconfig.persist.Ncywdy;
import com.mandi.common.JSONobj;
import com.mandi.common.Wxhtmethod;
import com.mandi.dao.common.Daomethod;
import com.mandi.dao.common.ObjectResult;
import com.mandi.dao.common.PageRequest;
import com.mandi.dao.common.PageResult;
import com.mandi.fendan.mapper.Fd_CompanyMapper;
import com.mandi.fendan.mapper.Fd_VehicleMapper;
import com.mandi.fendan.mapper.Fd_fhdqMapper;
import com.mandi.fendan.service.Ifd_companyService;
import com.mandi.fendan.util.Contants;
import com.mandi.common.Pinyinmethod;
@Service
public class Fd_CompanyService implements Ifd_companyService {
    @Resource
    private Fd_CompanyMapper cmper;
    @Resource
    private Fd_fhdqMapper dqper;
    @Resource
    private Fd_VehicleMapper vhper;
    @Resource
    private NczsjMapper zsjper;
 
    @Resource
    private FdMxWlgsMapper fdMxWlgsMapper;
 
    @Override
    public ObjectResult<Fd_Company> get(String id) {
        ObjectResult<Fd_Company> prr = new ObjectResult<Fd_Company>();
        if(!StringUtils.isBlank(id)){
            Fd_Company fcy = cmper.get(id);
            prr.setCode(0);
            prr.setItem(fcy);
        }else{
            prr.setCode(1);
            prr.setErrmsg("编号不能为空");;
        }
 
        return prr;
    }
    @Override
    public ObjectResult<Fd_Company> getByCompanyNo(String companyNo) {
        ObjectResult<Fd_Company> prr = new ObjectResult<Fd_Company>();
        if(!StringUtils.isBlank(companyNo)){
            Fd_Company fcy = cmper.getByCompanyNo(companyNo);
            prr.setCode(0);
            prr.setItem(fcy);
        }else{
            prr.setCode(1);
            prr.setErrmsg("公司编号不能为空");;
        }
 
        return prr;
    }
 
    @Override
    public PageResult<Map<String, Object>> getlist(String name, PageRequest pr) {
        PageResult<Map<String, Object>> prr=new PageResult<Map<String, Object>>();
        List<Map<String, Object>> rl=new ArrayList<Map<String,Object>>();
        Map<String, Object> mp=new HashMap<String, Object>();
        mp.put("pagesize", pr.getPageSize());
        mp.put("page", pr.getStart());
        mp.put("name", name);
        List<Fd_Company> list;
        if(pr.isNeedPages())
        {
            int pages=cmper.getPages(mp);
            pages=Daomethod.countpages(pages, pr.getPageSize());
            prr.setPages(pages);
            list =cmper.getList(mp);
        }else{
            list = cmper.getList1(mp);
        }
 
        if(list!=null){
            for (Fd_Company fdc : list) {
                String comNo=fdc.getCompanyNo();
                Map<String, Object> rm=new HashMap<String, Object>();
                try {
                    rm=BeanUtils.describe(fdc);
                } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
                }
                List<Ncywdy> cyl=this.cmper.getncYwdylist(comNo);
                rm.put("ywList", cyl);
                rl.add(rm);
            }
        }
        prr.setCode(0);
        prr.setList(rl);
        return prr;
    }
 
    @Override
    public List<Map<String, Object>> companytypehead(String search, int pagesize) {
 
        return null;
    }
 
    @Override
    public ObjectResult<Fd_Company> saveCompany(Fd_Company c,String ywdyNos) throws Exception {
        ObjectResult<Fd_Company> orr=new ObjectResult<Fd_Company>();
        if(c==null){
            orr.setCode(1);
            orr.setErrmsg("运输公司对象为空,不能保存");
            return orr;
        }
        if(StringUtils.isEmpty(c.getName())){
            orr.setCode(1);
            orr.setErrmsg("运输公司名字为空,不能保存");
            return orr;
        }
        String hdpinyin=Pinyinmethod.pinyinhds(c.getName());
        String pinyin=Pinyinmethod.pinyins(c.getName());
        c.setPinyin(pinyin);
        c.setHdpinyin(hdpinyin);
        String id=c.getId();
        try {
            Fd_Company c1= cmper.get(id);
            if(c1!=null){
                Fd_Company fcd=cmper.getByCompanyNo(c.getCompanyNo());
                if(fcd!=null&&!fcd.getId().equals(c1.getId())){
                    orr.setCode(1);
                    orr.setErrmsg("运输公司编号已存在,不能保存,请修改!");
                    return orr;
                }
 
                c1.setCname(c.getCname());
                c1.setHdpinyin(c.getHdpinyin());
                c1.setPinyin(c.getPinyin());
                c1.setNote(c.getNote());
                c1.setCtime(new Date());
                c1.setCompanyNo(c.getCompanyNo());
                c1.setHasSPR(c.isHasSPR());
                c1.setName(c.getName());
                cmper.update(c1);
                this.cmper.delCYnexus(c.getCompanyNo());
                orr.setItem(c1);
            }else{
                if(StringUtils.isEmpty(c.getCompanyNo())){
                    JsonObject pfob=Wxhtmethod.postJsonStr(Contants.YKTgetPrefix_url,PrefixEnum.fd_Company.toString());
                    ObjectResult<String> pfor=new ObjectResult<String>();
                    String bsNo=JSONobj.getstring(pfob, "item");
                    int code=JSONobj.getint(pfob, "code");
                    String errmsg=JSONobj.getstring(pfob, "errmsg");
                    pfor.setCode(code);
                    pfor.setErrmsg(errmsg);
                    pfor.setItem(bsNo);
                    if(pfor==null||pfor.getCode()!=0){
                        orr.setCode(1);
                        orr.setErrmsg(pfor.getErrmsg());
                        return orr;
                    }
                    c.setCompanyNo(pfor.getItem());
                }else{
                    Fd_Company fcd=cmper.getByCompanyNo(c.getCompanyNo());
                    if(fcd!=null){
                        orr.setCode(1);
                        orr.setErrmsg("运输公司编号已存在,不能保存,请修改!");
                        return orr;
                    }
                }
                c.setCtime(new Date());
                c.setId(UUID.randomUUID()+"");
                cmper.insert(c);
                orr.setItem(c);
            }
        } catch (Exception e) {
            throw new Exception(StringUtils.isEmpty(e.getMessage())?"物流公司保存出错!":e.getMessage());
        }
        //修改运输公司和业务单元关联表
        if(!StringUtils.isEmpty(ywdyNos)){
            for (String ywdyNo : ywdyNos.split(",")) {
                Ncywdy ywdy=this.zsjper.getNcywdybyCode(ywdyNo);
                if(ywdy==null)
                    continue;
                this.cmper.insertCYnexus(c.getCompanyNo(), ywdyNo);
            }
        }
 
        orr.setCode(0);
        orr.setItem(c);
        return orr;
    }
 
    @Override
    public ObjectResult<Boolean> changeUsed(Fd_Company cp) {
 
        return null;
    }
 
    @Override
    @Transactional(rollbackOn=Exception.class)
    public ObjectResult<Boolean> delCompany(String companyNo) throws Exception{
        ObjectResult<Boolean> prr = new ObjectResult<Boolean>();
        if(!StringUtils.isBlank(companyNo)){
 
            try {
                Fd_Vehicle fdv=this.vhper.selectbyCompanyNo(companyNo);
                if(fdv!=null){
                    prr.setCode(1);
                    prr.setErrmsg("请先删除所属的该物流公司的车辆信息!");
                    return prr;
                }
                cmper.delByCompanyNo(companyNo);
                this.dqper.delbywlgsCode(companyNo);
                this.cmper.delCYnexus(companyNo);
                prr.setCode(0);
                prr.setItem(true);
            } catch (Exception e) {
                throw new Exception(StringUtils.isEmpty(e.getMessage())?"物流公司删除程序出错!":e.getMessage());
            }
            prr.setCode(0);
            prr.setItem(true);
        }else{
            prr.setCode(1);
            prr.setErrmsg("公司编号不能为空");
        }
        return prr;
 
    }
 
 
    @Override
    public PageResult<Map<String, Object>> getcqList(String companyNo) {
        PageResult<Map<String, Object>> prr=new PageResult<Map<String,Object>>();
        LinkedList<Map<String, Object>> rl=new LinkedList<>();
        if(StringUtils.isNotBlank(companyNo)){
            List<Ncywdy> l=this.cmper.getncYwdylist(companyNo);
 
            Map<String, Ncywdy> map = new HashMap<>();
            for (Ncywdy ncy : l) { // 排重
                if (map.get(ncy.getCode()) == null)
                    map.put(ncy.getCode(), ncy);
            }
            int a = 0;
            for (Map.Entry<String, Ncywdy> entry : map.entrySet()) {
                String code = entry.getKey();
                Map<String, Object> m = null;
                if(Contants.nc_ywdy_ZZ.equals(code)){
                    m = new HashMap<>(2);
                    m.put("name","郑州厂区");
                    m.put("cqval",Contants.nc_ywdy_ZZ);
                }else if(Contants.nc_ywdy_MS.equals(code)){
                    m = new HashMap<>(2);
                    m.put("name","明晟厂区");
                    m.put("cqval",Contants.nc_ywdy_MS);
                }else if(Contants.nc_ywdy_YR.equals(code)){
                    m = new HashMap<>(2);
                    m.put("name","义瑞厂区");
                    m.put("cqval",Contants.nc_ywdy_YR);
                } else{
                    if(a==0){ // 防止出现多个科技厂区
                        m = new HashMap<>(2);
                        m.put("name","科技厂区");
                        m.put("cqval",Contants.nc_ywdy_KJ);
                        a=1;
                        // 特殊需求 科技要放到第一个
                        rl.addFirst(m);
                    }
                    // 防止出现空行
                    continue;
                }
                rl.add(m);
            }
            prr.setList(rl);
        }else{
            Map<String, Object> m2=new HashMap<String, Object>();
            m2.put("name","全部厂区");
            m2.put("cqval","");
            rl.add(m2);
            Map<String, Object> m=new HashMap<String, Object>();
            m.put("name","科技厂区");
            m.put("cqval",Contants.nc_ywdy_KJ);
            rl.add(m);
            Map<String, Object> m1=new HashMap<String, Object>();
            m1.put("name","郑州厂区");
            m1.put("cqval",Contants.nc_ywdy_ZZ);
            rl.add(m1);
            Map<String, Object> m3=new HashMap<String, Object>();
            m3.put("name","明晟厂区");
            m3.put("cqval",Contants.nc_ywdy_MS);
            rl.add(m3);
            Map<String, Object> m4=new HashMap<String, Object>();
            m4.put("name","义瑞厂区");
            m4.put("cqval",Contants.nc_ywdy_YR);
            rl.add(m4);
            prr.setList(rl);
        }
        prr.setCode(0);
        return prr;
    }
    @Override
    public PageResult<Map<String, Object>> getFdCqList(String companyNo, Login login) {
        PageResult<Map<String, Object>> prr=new PageResult<Map<String,Object>>();
        LinkedList<Map<String, Object>> rl=new LinkedList<>();
        if (!UserType.admin.toString().equals(login.getWorkerno())) {
            List<Map> l= fdMxWlgsMapper.selectChangqu(login.getUsername());
 
            Map<String,Map> map = new HashMap<>();
            for (Map map1 : l) { // 排重
                if (map1.get(map1.get("fd_cq")) == null)
                    map.put(map1.get("fd_cq").toString(), map1);
            }
            int a = 0;
            for (Map.Entry<String, Map> entry : map.entrySet()) {
                String code = entry.getKey();
                Map<String, Object> m = null;
                if(Contants.nc_ywdy_ZZ.equals(code)){
                    m = new HashMap<>(2);
                    m.put("name","郑州厂区");
                    m.put("cqval",Contants.nc_ywdy_ZZ);
                }else if(Contants.nc_ywdy_MS.equals(code)){
                    m = new HashMap<>(2);
                    m.put("name","明晟厂区");
                    m.put("cqval",Contants.nc_ywdy_MS);
                }else if(Contants.nc_ywdy_YR.equals(code)){
                    m = new HashMap<>(2);
                    m.put("name","义瑞厂区");
                    m.put("cqval",Contants.nc_ywdy_YR);
                } else{
                    if(a==0){ // 防止出现多个科技厂区
                        m = new HashMap<>(2);
                        m.put("name","科技厂区");
                        m.put("cqval",Contants.nc_ywdy_KJ);
                        a=1;
                        // 特殊需求 科技要放到第一个
                        rl.addFirst(m);
                    }
                    // 防止出现空行
                    continue;
                }
                rl.add(m);
            }
            prr.setList(rl);
        }else{
            Map<String, Object> m2=new HashMap<String, Object>();
            m2.put("name","全部厂区");
            m2.put("cqval","");
            rl.add(m2);
            Map<String, Object> m=new HashMap<String, Object>();
            m.put("name","科技厂区");
            m.put("cqval",Contants.nc_ywdy_KJ);
            rl.add(m);
            Map<String, Object> m1=new HashMap<String, Object>();
            m1.put("name","郑州厂区");
            m1.put("cqval",Contants.nc_ywdy_ZZ);
            rl.add(m1);
            Map<String, Object> m3=new HashMap<String, Object>();
            m3.put("name","明晟厂区");
            m3.put("cqval",Contants.nc_ywdy_MS);
            rl.add(m3);
            Map<String, Object> m4=new HashMap<String, Object>();
            m4.put("name","义瑞厂区");
            m4.put("cqval",Contants.nc_ywdy_YR);
            rl.add(m4);
            prr.setList(rl);
        }
        prr.setCode(0);
        return prr;
    }
 
 
}