Blame view

src/main/java/com/huaheng/api/erp/controller/ErpController.java 41.1 KB
lihailong authored
1
2
3
package com.huaheng.api.erp.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
pengcheng authored
4
import com.huaheng.common.utils.Wrappers;
tongzhonghao authored
5
import com.huaheng.api.erp.domain.CapturePictureModule;
6
7
8
import com.huaheng.api.erp.service.DisConnect;
import com.huaheng.api.erp.service.HaveReConnect;
import com.huaheng.common.constant.QuantityConstant;
lihailong authored
9
import com.huaheng.common.utils.StringUtils;
tongzhonghao authored
10
import com.huaheng.common.utils.security.ShiroUtils;
lihailong authored
11
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
tongzhonghao authored
12
import com.huaheng.framework.shiro.session.OnlineSessionDAO;
lihailong authored
13
14
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
tongzhonghao authored
15
import com.huaheng.pc.config.camera.service.ICameraService;
lihailong authored
16
17
18
19
20
21
22
23
24
25
26
27
import com.huaheng.pc.config.company.domain.Company;
import com.huaheng.pc.config.company.service.CompanyService;
import com.huaheng.pc.config.customer.domain.Customer;
import com.huaheng.pc.config.customer.service.CustomerServiceImpl;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.config.materialType.domain.MaterialType;
import com.huaheng.pc.config.materialType.service.MaterialTypeService;
import com.huaheng.pc.config.supplier.domain.Supplier;
import com.huaheng.pc.config.supplier.service.SupplierService;
import com.huaheng.pc.config.warehouse.domain.Warehouse;
import com.huaheng.pc.config.warehouse.service.WarehouseService;
28
import com.huaheng.pc.monitor.job.task.RyTask;
tongzhonghao authored
29
import com.huaheng.pc.monitor.online.domain.OnlineSession;
lihailong authored
30
31
32
33
34
35
36
37
38
39
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
import com.huaheng.pc.system.dept.domain.Dept;
import com.huaheng.pc.system.dept.service.IDeptService;
import com.huaheng.pc.system.role.domain.Role;
import com.huaheng.pc.system.role.service.IRoleService;
import com.huaheng.pc.system.user.domain.User;
import com.huaheng.pc.system.user.service.IUserService;
import com.huaheng.pc.vehicle.vehicleReceipt.service.VehicleReceiptService;
import com.huaheng.pc.vehicle.vehicleShipment.service.VehicleShipmentService;
tongzhonghao authored
40
41
42
import com.netsdk.demo.module.LoginModule;
import com.netsdk.lib.NetSDKLib;
import com.sun.jna.Pointer;
lihailong authored
43
import io.swagger.annotations.ApiOperation;
tongzhonghao authored
44
45
import org.apache.shiro.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
lihailong authored
46
47
48
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
49
50
51
52
53
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
lihailong authored
54
import java.util.*;
55
import java.util.List;
lihailong authored
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

@RestController
@RequestMapping("/API/WMS/v2")
public class ErpController extends BaseController {

    @Resource
    private IUserService userService;
    @Resource
    private IDeptService deptService;
    @Resource
    private WarehouseService warehouseService;
    @Resource
    private CompanyService companyService;
    @Resource
    private IRoleService roleService;
    @Resource
    private MaterialTypeService materialTypeService;
    @Resource
    private ReceiptHeaderService receiptHeaderService;
    @Resource
    private MaterialService materialService;
    @Resource
    private VehicleReceiptService vehicleReceiptService;
    @Resource
    private VehicleShipmentService vehicleShipmentService;
    @Resource
    private CustomerServiceImpl customerService;
    @Resource
    private SupplierService supplierService;
tongzhonghao authored
85
86
    @Autowired
    private OnlineSessionDAO onlineSessionDAO;
tongzhonghao authored
87
88
    @Autowired
    private ICameraService cameraService;
89
90
91
92
93
94
    /**
     * 1.车辆入库
     * 2.车辆出库
     * 3.物料
     */
    public static String cameraFlag = null;
95
96

    @PostMapping("/cameraLogin")
tongzhonghao authored
97
    @ApiOperation("登录拍照")
tongzhonghao authored
98
    @ApiLogger(apiName = "登录拍照", from = "ERP")
99
    @ResponseBody
tongzhonghao authored
100
    public AjaxResult login(String cameraId) {
tongzhonghao authored
101
        if(cameraId == null || "".equals(cameraId)){
tongzhonghao authored
102
            return AjaxResult.error("没有选择摄像头,缺少 cameraId 信息");
103
        }
104
        cameraFlag = cameraId;
105
tongzhonghao authored
106
        switch(cameraId){
107
108
109
            case "3":
                if(RyTask.camera1 == null){
                    //登录
tongzhonghao authored
110
                    AjaxResult ajaxResult = cameraService.loginCamera("camera1");
111
112
113
                    if(ajaxResult.getCode()!=200){
                        return AjaxResult.error().setData(ajaxResult.getData());
                    }
114
                }
tongzhonghao authored
115
                CapturePictureModule.remoteCapturePicture(0,new NetSDKLib.LLong(Long.valueOf(RyTask.camera1)));
tongzhonghao authored
116
                break;
117
118
119
            case "1" :
            case "2" :
                if(RyTask.camera2 == null){
tongzhonghao authored
120
                    AjaxResult ajaxResult = cameraService.loginCamera("camera2");
121
122
123
                    if(ajaxResult.getCode()!=200){
                        return AjaxResult.error().setData(ajaxResult.getData());
                    }
124
                }
tongzhonghao authored
125
                CapturePictureModule.remoteCapturePicture(0,new NetSDKLib.LLong(Long.valueOf(RyTask.camera2)));
tongzhonghao authored
126
                break;
周鸿 authored
127
128
129
130
131
132
133
134
135
            case "4" :
                if(RyTask.camera3 == null){
                    AjaxResult ajaxResult = cameraService.loginCamera("camera3");
                    if(ajaxResult.getCode()!=200){
                        return AjaxResult.error().setData(ajaxResult.getData());
                    }
                }
                CapturePictureModule.remoteCapturePicture(0,new NetSDKLib.LLong(Long.valueOf(RyTask.camera3)));
                break;
136
        }
tongzhonghao authored
137
        return AjaxResult.success("成功");
138
139
    }
tongzhonghao authored
140
141
lihailong authored
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
    @PostMapping("/selectDept")
    @ApiOperation("查询部门")
    @ApiLogger(apiName = "查询部门", from = "ERP")
    @ResponseBody
    public AjaxResult selectDept() {
        List<Dept> deptList = deptService.selectDeptAll();
        return AjaxResult.success(deptList);
    }

    @PostMapping("/selectUser")
    @ApiOperation("查询用户")
    @ApiLogger(apiName = "查询用户", from = "ERP")
    @ResponseBody
    public AjaxResult selectUser() {
        List<User> selectUserList = userService.selectUserList(null);
        return AjaxResult.success(selectUserList);
    }

    @PostMapping("/selectCompany")
    @ApiOperation("查询货主")
    @ApiLogger(apiName = "查询货主", from = "ERP")
    @ResponseBody
    public AjaxResult selectCompany() {
        List<Company> companyList = companyService.list();
        return AjaxResult.success(companyList);
    }

    @PostMapping("/selectWarehouse")
    @ApiOperation("查询仓库")
    @ApiLogger(apiName = "查询仓库", from = "ERP")
    @ResponseBody
    public AjaxResult selectWarehouse() {
        List<Warehouse> warehouseList = warehouseService.list();
        return AjaxResult.success(warehouseList);
    }

    @PostMapping("/selectRole")
    @ApiOperation("查询角色")
    @ApiLogger(apiName = "查询角色", from = "ERP")
    @ResponseBody
    public AjaxResult selectRole() {
        List<Role> selectRoleAll = roleService.selectRoleAll();
        return AjaxResult.success(selectRoleAll);
    }

    @PostMapping("/selectMaterialType")
    @ApiOperation("查询原材料")
    @ApiLogger(apiName = "查询原材料", from = "ERP")
    @ResponseBody
    public AjaxResult selectMaterialType() {
        List<MaterialType> materialTypeList = materialTypeService.list();
        return AjaxResult.success(materialTypeList);
    }



    @PostMapping("/addUser")
    @ApiOperation("添加用户")
    @ApiLogger(apiName = "添加用户", from = "ERP")
    @ResponseBody
    public AjaxResult addUser(@RequestBody Map<String, String> map) {
        String loginName = map.get("loginName");
        String userName = map.get("userName");
        String passWord = map.get("passWord");
        String deptId = map.get("deptId");
        String warehouseCode = map.get("warehouseCode");
        String companyCode = map.get("companyCode");
        String companyName = map.get("companyName");
        String roleId = map.get("roleId");
        if(userName == null || userName.length()==0){
            return AjaxResult.error("没有 userName");
        }
        if(passWord == null || passWord.length()==0){
            return AjaxResult.error("没有 passWord");
        }
        if(warehouseCode == null || warehouseCode.length()==0){
            return AjaxResult.error("没有 warehouseCode");
        }
        if(companyCode == null || companyCode.length()==0 ){
            return AjaxResult.error("没有 companyCode");
        }
        if(companyName == null || companyName.length()==0){
            return AjaxResult.error("没有 companyName");
        }
        if(StringUtils.isEmpty(loginName)){
            loginName = userName;
        }
        if(roleId == null || roleId.length()==0){
            return AjaxResult.error("没有 roleId");
        }


        User user = new User();
        if(StringUtils.isNotEmpty(deptId)){
            user.setDeptId(Integer.parseInt(deptId));
        }
        user.setDeptId(155);
        user.setPassword(passWord);
        user.setLoginName(loginName);
        user.setUserName(userName);
        user.setCreateBy("ERP");
        List<Integer> roleIdsList = new ArrayList<>();
        roleIdsList.add(Integer.parseInt(roleId));
        user.setRoleIds(roleIdsList);
        List<String> stringList = new ArrayList<>();
        stringList.add(warehouseCode);
        user.setWarehouseCodeList(stringList);
        LambdaQueryWrapper<Company> companyLambdaQueryWrapper = Wrappers.lambdaQuery();
        companyLambdaQueryWrapper.eq(StringUtils.isNotEmpty(companyCode),Company::getCode,companyCode)
tongzhonghao authored
251
                .eq(StringUtils.isNotEmpty(companyName),Company::getName,companyName);
lihailong authored
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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
        Company companyServiceOne = companyService.getOne(companyLambdaQueryWrapper);
        Integer companyId = companyServiceOne.getId();
        List<Integer> companyIdList = new ArrayList<>();
        companyIdList.add(companyId);
        user.setCompanyIdList(companyIdList);
        int a = userService.insertUser(user);
        if(a==0){
            return AjaxResult.error("添加角色失败");
        }
        return AjaxResult.success();
    }



    //添加部门
    @PostMapping("/addDept")
    @ApiOperation("添加部门")
    @ApiLogger(apiName = "添加部门", from = "ERP")
    @ResponseBody
    public AjaxResult addDept(@RequestBody Map<String, String> map) {
        String parentId = map.get("parentId");
        String deptName = map.get("deptName");
        String ancestors = map.get("ancestors");
        if(deptName == null || deptName.length()==0){
            return AjaxResult.error("没有 deptName");
        }
        Dept dept = new Dept();
        dept.setDeptName(deptName);
        if(StringUtils.isEmpty(parentId)){
            dept.setParentId(0);
        }
        if(StringUtils.isEmpty(ancestors)){
            dept.setAncestors(ancestors);
        }
        dept.setCreateBy("ERP");

        int count = deptService.insertDept(dept);
        if(count<1){
            return AjaxResult.error("添加部门失败");
        }
        return AjaxResult.success();
    }

    //添加仓库
    @PostMapping("/addWarehourse")
    @ApiOperation("添加仓库")
    @ApiLogger(apiName = "添加仓库", from = "ERP")
    @ResponseBody
    public AjaxResult addWarehourse(@RequestBody Map<String, String> map) {
        String city = map.get("city");
        String state = map.get("state");
        String name = map.get("name");
        String code = map.get("code");
        Warehouse warehouse = new Warehouse();
        if(StringUtils.isEmpty(city)){
            warehouse.setCity("格林美");
        }
        if(StringUtils.isEmpty(state)){
            warehouse.setState("武汉");
        }
        if(name == "" || name.length()==0){
            return AjaxResult.error("没有 仓库名name");
        }
        if(code == "" || code.length()==0){
            return AjaxResult.error("没有 仓库code");
        }
        LambdaQueryWrapper<Warehouse> warehouseLambdaQueryWrapper2 = Wrappers.lambdaQuery();
        warehouseLambdaQueryWrapper2.eq(Warehouse::getCode,code);
        List<Warehouse> list2 = warehouseService.list(warehouseLambdaQueryWrapper2);
        if(list2.size()>0){
            return AjaxResult.error("仓库code重复");
        }

        warehouse.setCountry("中国");
        warehouse.setEnable(1);
        warehouse.setCreatedBy("ERP");
        warehouse.setCode(code);
        warehouse.setName(name);
        boolean isSuccess = warehouseService.save(warehouse);
        if(!isSuccess){
            return AjaxResult.error("添加仓库失败");
        }
        return AjaxResult.success();
    }



    //添加货主
    @PostMapping("/addCompany")
    @ApiOperation("添加货主")
    @ApiLogger(apiName = "添加货主", from = "ERP")
    @ResponseBody
    public AjaxResult addCompany(@RequestBody Map<String, String> map) {
        String warehouseCode = map.get("warehouseCode");
        String name = map.get("name");
        String code = map.get("code");
        if(name == null || name.length()==0){
            return AjaxResult.error("没有 货主名name");
        }
        if(code == null || code.length()==0){
            return AjaxResult.error("没有 货主code");
        }
        if(warehouseCode == null || warehouseCode.length()==0){
            return AjaxResult.error("没有 仓库编码warehouseCode");
        }

        LambdaQueryWrapper<Company> companyLambdaQueryWrapper = Wrappers.lambdaQuery();
        companyLambdaQueryWrapper.eq(StringUtils.isNotEmpty(code),Company::getCode,code);
        List<Company> companyList = companyService.list(companyLambdaQueryWrapper);
        if (companyList.size()>0){
            return AjaxResult.error("货主编码code重复");
        }

        LambdaQueryWrapper<Warehouse> warehouseLambdaQueryWrapper = Wrappers.lambdaQuery();
        warehouseLambdaQueryWrapper.eq(StringUtils.isNotEmpty(warehouseCode),Warehouse::getCode,warehouseCode);
        List<Warehouse> warehouseList = warehouseService.list(warehouseLambdaQueryWrapper);
        if (warehouseList.size()==0){
            return AjaxResult.error("没有找到仓库编码warehouseCode");
        }


        Company company = new Company();
        company.setWarehouseCode(warehouseCode);
        company.setCode(code);
        company.setName(name);
        company.setCreatedBy("ERP");
        boolean isSuccess = companyService.save(company);
        if(!isSuccess){
            return AjaxResult.error("添加货主失败");
        }
        return AjaxResult.success();
    }


    //添加原材料
    @PostMapping("/addMaterialType")
    @ApiOperation("添加原材料")
    @ApiLogger(apiName = "添加原材料", from = "ERP")
    @ResponseBody
    public AjaxResult addMaterialType(@RequestBody Map<String, String> map) {
        String name = map.get("name");
        String code = map.get("code");
        String companyCode = map.get("companyCode");
        String warehouseCode = map.get("warehouseCode");
        if(name == null || name.length()==0){
            return AjaxResult.error("没有 原材料name");
        }
        if(code == null || code.length()==0){
            return AjaxResult.error("没有 原材料code");
        }
        if(warehouseCode == null || warehouseCode.length()==0){
            return AjaxResult.error("没有 仓库编码warehouseCode");
        }
        if(companyCode == null || companyCode.length()==0){
            return AjaxResult.error("没有 货主编码companyCode");
        }

        List<String> list = new ArrayList<>();
        list.add(companyCode);
        list.add(warehouseCode);
        list.add(name);
        list.add(code);
        Map<String,String> map1 = new HashMap<>();
        map1.put("companyCode",companyCode);
        map1.put("warehouseCode",warehouseCode);
        map1.put("materialTypeName",name);
        map1.put("materialTypeCode",code);
        String repeat = isRepeat(map1);
        if (repeat.length()>1){
            return AjaxResult.error(repeat);
        };
        MaterialType materialType = new MaterialType();
        materialType.setWarehouseCode(warehouseCode);
        materialType.setName(name);
        materialType.setCode(code);
        materialType.setCompanyCode(companyCode);
        materialType.setEnable(1);
        materialType.setDaysToExpire(0);
        materialType.setTrackSerialNum(0);
        materialType.setAutoGenSerialNum(0);
        materialType.setMinShelfLifeDays(0);
        materialType.setCreatedBy("ERP");
        materialType.setVersion(0);
        boolean isSuccess = materialTypeService.save(materialType);
        if(!isSuccess){
            return AjaxResult.error("添加原材料失败");
        }
        return AjaxResult.success();
    }





    /**
     * 判断是否重复的方法
     */
    public String isRepeat(Map<String,String> map1){
        String companyCode = map1.get("companyCode");
        String warehouseCode = map1.get("warehouseCode");
        String materialTypeName = map1.get("materialTypeName");
        String materialTypeCode = map1.get("materialTypeCode");

        LambdaQueryWrapper<Company> companyLambdaQueryWrapper = Wrappers.lambdaQuery();
        companyLambdaQueryWrapper.eq(StringUtils.isNotEmpty(companyCode),Company::getCode,companyCode);
        List<Company> companyList = companyService.list(companyLambdaQueryWrapper);
        if (companyCode != null || companyList.size()==0){
            return "没有找到货主编码companyCode";
        }
        LambdaQueryWrapper<Warehouse> warehouseLambdaQueryWrapper = Wrappers.lambdaQuery();
        warehouseLambdaQueryWrapper.eq(StringUtils.isNotEmpty(warehouseCode),Warehouse::getCode,warehouseCode);
        List<Warehouse> warehouseList = warehouseService.list(warehouseLambdaQueryWrapper);
        if (warehouseList.size()==0){
            return "没有找到仓库编码warehouseCode";
        }
        LambdaQueryWrapper<MaterialType> materialTypeLambdaQueryWrapper = Wrappers.lambdaQuery();
        materialTypeLambdaQueryWrapper.eq(StringUtils.isNotEmpty(materialTypeName),MaterialType::getName,materialTypeName);
        List<MaterialType> materialTypeList = materialTypeService.list(materialTypeLambdaQueryWrapper);
        if (materialTypeList.size()>0){
            return "原材料名字重复 name";
        }
        LambdaQueryWrapper<MaterialType> materialTypeLambdaQueryWrapper2 = Wrappers.lambdaQuery();
        materialTypeLambdaQueryWrapper2.eq(StringUtils.isNotEmpty(materialTypeCode),MaterialType::getCode,materialTypeCode);
        List<MaterialType> materialTypeList2 = materialTypeService.list(materialTypeLambdaQueryWrapper2);
        if (materialTypeList2.size()>0){
            return "原材料编码重复 code";
        }
        return "1";
    }






    //添加采购单入库单
    @PostMapping("/addReceiptHeader")
    @ApiOperation("添加原材料")
    @ApiLogger(apiName = "添加原材料", from = "ERP")
    @ResponseBody
    public AjaxResult addReceiptHeader(@RequestBody Map<String, String> map) {
        String companyCode = map.get("companyCode");
        String warehouseCode = map.get("warehouseCode");
        String receiptType = map.get("receiptType");
        if(warehouseCode == null || warehouseCode.length()==0){
            return AjaxResult.error("没有 仓库编码warehouseCode");
        }
        if(companyCode == null || companyCode.length()==0){
            return AjaxResult.error("没有 货主编码companyCode");
        }
        LambdaQueryWrapper<Company> companyLambdaQueryWrapper = Wrappers.lambdaQuery();
        companyLambdaQueryWrapper.eq(StringUtils.isNotEmpty(companyCode),Company::getCode,companyCode);
        List<Company> companyList = companyService.list(companyLambdaQueryWrapper);
        if (companyList.size()==0){
            return AjaxResult.error("没有找到货主编码companyCode");
        }
        LambdaQueryWrapper<Warehouse> warehouseLambdaQueryWrapper = Wrappers.lambdaQuery();
        warehouseLambdaQueryWrapper.eq(StringUtils.isNotEmpty(warehouseCode),Warehouse::getCode,warehouseCode);
        List<Warehouse> warehouseList = warehouseService.list(warehouseLambdaQueryWrapper);
        if (warehouseList.size()==0){
            return AjaxResult.error("没有找到仓库编码warehouseCode");
        }
        LambdaQueryWrapper<Company> companyLambdaQueryWrapper2 = Wrappers.lambdaQuery();
        companyLambdaQueryWrapper2.eq(StringUtils.isNotEmpty(companyCode),Company::getCode,companyCode)
                .eq(StringUtils.isNotEmpty(warehouseCode),Company::getWarehouseCode,warehouseCode);
        List<Company> companyList2 = companyService.list(companyLambdaQueryWrapper2);
        if (companyList2.size()==0){
            return AjaxResult.error("货主编码companyCode和仓库编码warehouseCode不一致");
        }
        ReceiptHeader receiptHeader = new ReceiptHeader();
        if(StringUtils.isEmpty(receiptType)){
            receiptHeader.setReceiptType("CGD");
        }
        receiptHeader.setWarehouseCode(warehouseCode);
        receiptHeader.setCompanyCode(companyCode);
        receiptHeaderService.saveReceiptHeaders(receiptHeader);
        return AjaxResult.success();
    }




    //添加成品
    @PostMapping("/addMaterial")
    @ApiOperation("添加成品物料")
    @ApiLogger(apiName = "添加成品物料", from = "ERP")
    @ResponseBody
    public AjaxResult addMaterial(@RequestBody Map<String, String> map) {
        String code = map.get("code");
        String companyCode = map.get("companyCode");
        String warehouseCode = map.get("warehouseCode");
        String name = map.get("name");
        String type = map.get("type");
        if(warehouseCode == null || warehouseCode.length()==0){
            return AjaxResult.error("没有仓库编码 warehouseCode");
        }
        if(companyCode == null || companyCode.length()==0){
            return AjaxResult.error("没有货主编码 companyCode");
        }
        if(code == null || code.length()==0){
            return AjaxResult.error("没有成品物料编码 code");
        }
        if(name == null || name.length()==0){
            return AjaxResult.error("没有成品物料名字 name");
        }
        if(type == null || type.length()==0){
            return AjaxResult.error("没有成品物料原材料类型 type");
        }

        LambdaQueryWrapper<Material> materialLambdaQueryWrapper = Wrappers.lambdaQuery();
        materialLambdaQueryWrapper.eq(Material::getCode,code);
        List<Material> materialList = materialService.list(materialLambdaQueryWrapper);
        if(materialList.size()>0){
            return AjaxResult.error("成品物料编码重复 code");
        }
        LambdaQueryWrapper<Warehouse> warehouseLambdaQueryWrapper = Wrappers.lambdaQuery();
        warehouseLambdaQueryWrapper.eq(Warehouse::getCode,warehouseCode);
        List<Warehouse> warehouseList = warehouseService.list(warehouseLambdaQueryWrapper);
        if(warehouseList.size()==0){
            return AjaxResult.error("没有找到仓库编码 warehouseCode");
        }
        LambdaQueryWrapper<Company> companyLambdaQueryWrapper = Wrappers.lambdaQuery();
        companyLambdaQueryWrapper.eq(StringUtils.isNotEmpty(companyCode),Company::getCode,companyCode);
        List<Company> companyList = companyService.list(companyLambdaQueryWrapper);
        if (companyList.size()==0){
            return AjaxResult.error("没有找到货主编码 companyCode");
        }
        LambdaQueryWrapper<MaterialType> materialTypeLambdaQueryWrapper = Wrappers.lambdaQuery();
        materialTypeLambdaQueryWrapper.eq(MaterialType::getCode,type);
        List<MaterialType> materialTypeList = materialTypeService.list(materialTypeLambdaQueryWrapper);
        if(materialTypeList.size()==0){
            return AjaxResult.error("没有找到成品物料原材料类型 type");
        }

        LambdaQueryWrapper<MaterialType> materialTypeLambdaQueryWrapper2 = Wrappers.lambdaQuery();
        materialTypeLambdaQueryWrapper.eq(MaterialType::getCode,type)
tongzhonghao authored
588
589
                .eq(MaterialType::getWarehouseCode,warehouseCode)
                .eq(MaterialType::getCompanyCode,companyCode);
lihailong authored
590
591
592
593
594
595
596
597
598
599
600
601
        List<MaterialType> materialTypeList2 = materialTypeService.list(materialTypeLambdaQueryWrapper2);
        if(materialTypeList2.size()==0){
            return AjaxResult.error("原材料类型:"+type+"仓库编码:"+warehouseCode+"货主编码:"+companyCode+"对应不一致!");
        }
        Material material = new Material();
        AjaxResult ajaxResult = materialService.addSave(material);
        return ajaxResult;

    }
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
//    //添加车辆入库信息
//    @PostMapping("/addVehicleReceipt")
//    @ApiOperation("添加车辆入库信息")
//    @ApiLogger(apiName = "添加车辆入库信息", from = "ERP")
//    @ResponseBody
//    public AjaxResult addVehicleReceipt(@RequestBody Map<String, String> map) {
//        String companyCode = map.get("companyCode");
//        String warehouseCode = map.get("warehouseCode");
//        String materialBatch = map.get("materialBatch");
//        String vehicleType = map.get("vehicleType");
//        String meterialName = map.get("meterialName");
//        String grossWeight = map.get("grossWeight");
//        String tareWeight = map.get("tareWeight");
//        String carNumber = map.get("carNumber");
//        String vehicleName = map.get("vehicleName");
//        String driverNumber = map.get("driverNumber");
//        String cardNumber = map.get("cardNumber");
//        String incomingTime = map.get("incomingTime");
//        String remark = map.get("remark");
//        String type = map.get("type");
//
//        if(warehouseCode == null || warehouseCode.length()==0){
//            return AjaxResult.error("没有仓库编码 warehouseCode");
//        }
//        if(companyCode == null || companyCode.length()==0){
//            return AjaxResult.error("没有货主编码 companyCode");
//        }
//        if(materialBatch == null || materialBatch.length()==0){
//            return AjaxResult.error("没有原料批号 materialBatch");
//        }
//        if(vehicleType == null || vehicleType.length()==0){
//            return AjaxResult.error("没有单据类型 vehicleType");
//        }
//
//        if(meterialName == null || meterialName.length()==0){
//            return AjaxResult.error("没有物料名称 meterialName");
//        }
//        if(grossWeight == null || grossWeight.length()==0){
//            return AjaxResult.error("没有毛重 grossWeight");
//        }
//        if(tareWeight == null || tareWeight.length()==0){
//            return AjaxResult.error("没有皮重 tareWeight");
//        }
//        if(carNumber == null || carNumber.length()==0){
//            return AjaxResult.error("没有车牌号 carNumber");
//        }
//        if(vehicleName == null || vehicleName.length()==0){
//            return AjaxResult.error("没有司机名字 vehicleName");
//        }
//        if(driverNumber == null || driverNumber.length()==0){
//            return AjaxResult.error("没有驾驶证号 driverNumber");
//        }
//        if(cardNumber == null || cardNumber.length()==0){
//            return AjaxResult.error("没有身份证 cardNumber");
//        }
//        if(incomingTime == null || incomingTime.length()==0){
//            return AjaxResult.error("没有入厂时间 incomingTime");
//        }
//        if(type == null || type.length()==0){
//            return AjaxResult.error("没有车辆任务类型 type");
//        }
//        VehicleReceipt vehicelReceipt = new VehicleReceipt();
//        vehicelReceipt.setCompanyCode(companyCode);
//        vehicelReceipt.setWarehouseCode(warehouseCode);
//        vehicelReceipt.setMaterialBatch(materialBatch);
//        vehicelReceipt.setVehicleType(vehicleType);
//        vehicelReceipt.setMeterialName(meterialName);
//        vehicelReceipt.setGrossWeight(grossWeight);
//        vehicelReceipt.setTareWeight(tareWeight);
//        vehicelReceipt.setCarNumber(carNumber);
//        vehicelReceipt.setVehicleName(vehicleName);
//        vehicelReceipt.setDriverNumber(driverNumber);
//        vehicelReceipt.setCardNumber(cardNumber);
////        vehicelReceipt.setIncomingTime(new Date());
//        vehicelReceipt.setCreatedBy("ERP");
//        vehicelReceipt.setRemark(remark);
//        boolean save = vehicleReceiptService.save(vehicelReceipt);
//        if(!save){
//            return AjaxResult.error("新增车辆入厂信息失败");
//        }
//        return AjaxResult.success();
//    }
//
//
//
//    //添加车辆出库信息
//    @PostMapping("/addVehicleShipment")
//    @ApiOperation("添加车辆出库信息")
//    @ApiLogger(apiName = "添加车辆出库信息", from = "ERP")
//    @ResponseBody
//    public AjaxResult addVehicleShipment(@RequestBody Map<String, String> map) {
//        String poundNumber = map.get("poundNumber");
//        String vehicleStatus = map.get("vehicleStatus");
//        String seller = map.get("seller");
//        String companyCode = map.get("companyCode");
//        String warehouseCode = map.get("warehouseCode");
//        String meterialName = map.get("meterialName");
//        String grossWeight = map.get("grossWeight");
//        String tareWeight = map.get("tareWeight");
//        String carNumber = map.get("carNumber");
//        String vehicleName = map.get("vehicleName");
//        String driverNumber = map.get("driverNumber");
//        String cardNumber = map.get("cardNumber");
//        String incomingTime = map.get("incomingTime");
//        String remark = map.get("remark");
//        String type = map.get("type");
//
//        if(warehouseCode == null || warehouseCode.length()==0){
//            return AjaxResult.error("没有仓库编码 warehouseCode");
//        }
//        if(companyCode == null || companyCode.length()==0){
//            return AjaxResult.error("没有货主编码 companyCode");
//        }
//        if(poundNumber == null || poundNumber.length()==0){
//            return AjaxResult.error("没有磅单编号 poundNumber");
//        }
//        if(vehicleStatus == null || vehicleStatus.length()==0){
//            return AjaxResult.error("没有状态 vehicleStatus");
//        }
//        if(seller == null || seller.length()==0){
//            return AjaxResult.error("没有销售商 seller");
//        }
//        if(meterialName == null || meterialName.length()==0){
//            return AjaxResult.error("没有物料名称 meterialName");
//        }
//        if(grossWeight == null || grossWeight.length()==0){
//            return AjaxResult.error("没有毛重 grossWeight");
//        }
//        if(tareWeight == null || tareWeight.length()==0){
//            return AjaxResult.error("没有皮重 tareWeight");
//        }
//        if(carNumber == null || carNumber.length()==0){
//            return AjaxResult.error("没有车牌号 carNumber");
//        }
//        if(vehicleName == null || vehicleName.length()==0){
//            return AjaxResult.error("没有司机名字 vehicleName");
//        }
//        if(driverNumber == null || driverNumber.length()==0){
//            return AjaxResult.error("没有驾驶证号 driverNumber");
//        }
//        if(cardNumber == null || cardNumber.length()==0){
//            return AjaxResult.error("没有身份证 cardNumber");
//        }
//        if(incomingTime == null || incomingTime.length()==0){
//            return AjaxResult.error("没有入厂时间 incomingTime");
//        }
//        if(type == null || type.length()==0){
//            return AjaxResult.error("没有车辆任务类型 type");
//        }
//
//        VehicleShipment vehicleShipment = new VehicleShipment();
//        vehicleShipment.setPoundNumber(poundNumber);
//        vehicleShipment.setVehicleStatus(vehicleStatus);
//        vehicleShipment.setSeller(seller);
//        vehicleShipment.setCompanyCode(companyCode);
//        vehicleShipment.setWarehouseCode(warehouseCode);
//        vehicleShipment.setMeterialName(meterialName);
//        vehicleShipment.setGrossWeight(grossWeight);
//        vehicleShipment.setTareWeight(tareWeight);
//        vehicleShipment.setCarNumber(carNumber);
//        vehicleShipment.setVehicleName(vehicleName);
//        vehicleShipment.setDriverNumber(driverNumber);
//        vehicleShipment.setCardNumber(cardNumber);
////        vehicleShipment.setIncomingTime();
//        vehicleShipment.setRemark(remark);
//        vehicleShipment.setType(type);
//        boolean save = vehicleShipmentService.save(vehicleShipment);
//        if(!save){
//            return AjaxResult.error("新增车辆出厂信息失败");
//        }
//        return AjaxResult.success();
//    }
lihailong authored
774
775
776
    //添加客户
lihailong authored
777
    @PostMapping("/addCustomer")
778
779
    @ApiOperation("添加客户")
    @ApiLogger(apiName = "添加客户", from = "ERP")
lihailong authored
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
    @ResponseBody
    public AjaxResult addCustomer(@RequestBody Map<String, String> map) {
        String code = map.get("code");
        String shipToCode = map.get("shipToCode");
        String warehouseCode = map.get("warehouseCode");
        String companyCode = map.get("companyCode");
        String name = map.get("name");
        String address1 = map.get("address1");
        String address2 = map.get("address2");
        String city = map.get("city");
        String province = map.get("province");
        String country = map.get("country");
        String postalCode = map.get("postalCode");
        String parent = map.get("parent");
        String attentionTo = map.get("attentionTo");
        String phoneNum = map.get("phoneNum");
        String mobile = map.get("mobile");
        String faxNum = map.get("faxNum");
        String email = map.get("email");
        String enable = map.get("enable");
        String createdBy = map.get("createdBy");
        String processStamp = map.get("processStamp");
        String deleted = map.get("deleted");
803
        String endEnterpriseCode = map.get("endEnterpriseCode");
804
        String allCreditCode = map.get("allCreditCode");
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820

//        if(StringUtils.isEmpty(country)){
//            return AjaxResult.error("国家地址country 字段不能为空");
//        }
//        if(StringUtils.isEmpty(province)){
//            return AjaxResult.error("省地址province 字段不能为空");
//        }
//        if(StringUtils.isEmpty(city)){
//            return AjaxResult.error("市地址city 字段不能为空");
//        }
//        if(StringUtils.isEmpty(address1)){
//            return AjaxResult.error("县地址address1 字段不能为空");
//        }
//        if(StringUtils.isEmpty(address2)){
//            return AjaxResult.error("镇地址address2 字段不能为空");
//        }
lihailong authored
821
822
823

        Customer customer = new Customer();
824
        if(StringUtils.isEmpty(code)){
lihailong authored
825
826
827
828
829
830
831
832
833
834
835
            return AjaxResult.error("没有客户ID code");
        }
        if(StringUtils.isEmpty(shipToCode)){
            customer.setShipToCode("");
        }
        if(StringUtils.isEmpty(warehouseCode)){
            customer.setWarehouseCode("CS0001");
        }
        if(StringUtils.isEmpty(companyCode)){
            customer.setCompanyCode("BHF");
        }
836
837
        if(StringUtils.isEmpty(name)){
            return AjaxResult.error("没有名称");
lihailong authored
838
839
840
841
842
843
844
845
        }
        if(StringUtils.isEmpty(address1)){
            customer.setAddress1("");
        }
        if(StringUtils.isEmpty(city)){
            customer.setCity("武汉");
        }
        if(StringUtils.isEmpty(province)){
846
            customer.setProvince("湖北");
lihailong authored
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
        }
        if(StringUtils.isEmpty(country)){
            customer.setCountry("中国");
        }
        if(StringUtils.isEmpty(postalCode)){
            customer.setPostalCode("");
        }
        if(StringUtils.isEmpty(parent)){
            customer.setParent(0);
        }
        if(StringUtils.isEmpty(attentionTo)){
            customer.setAttentionTo("");
        }
        if(StringUtils.isEmpty(phoneNum)){
            customer.setPhoneNum("");
        }
        if(StringUtils.isEmpty(mobile)){
            customer.setMobile("");
        }
        if(StringUtils.isEmpty(faxNum)){
            customer.setFaxNum("");
        }
        if(StringUtils.isEmpty(email)){
            customer.setEmail("");
        }
872
873
//        if(StringUtils.isEmpty(enable)){
//            customer.setEnable(true);
lihailong authored
874
875
876
877
878
879
880
//        }
        if(StringUtils.isEmpty(createdBy)){
            customer.setCreatedBy("ERP");
        }
        if(StringUtils.isEmpty(processStamp)){
            customer.setProcessStamp("");
        }
881
        if(StringUtils.isEmpty(allCreditCode)){
882
883
            return AjaxResult.error("没有企业信用代码");
        }
lihailong authored
884
885
886
        if(StringUtils.isEmpty(deleted)){
            customer.setDeleted(false);
        }
887
        customer.setAllCreditCode(allCreditCode);
lihailong authored
888
889
        customer.setCode(code);
        customer.setName(name);
890
891
        customer.setCountry(country);
        customer.setProvince(province);
892
        customer.setCity(city);
893
894
        customer.setAddress1(address1);
        customer.setAddress2(address2);
895
896
897
898
        customer.setCreatedBy(createdBy);
        customer.setWarehouseCode("CS0001");
        customer.setCompanyCode("BHF");
        customer.setEnable(true);
899
900
901
902
        Customer one = customerService.getOne(new LambdaQueryWrapper<Customer>().eq(Customer::getCode, code));
        if (one==null) {
            customerService.save(customer);
        }else {
903
            customer.setId(one.getId());
904
905
906
907
            customerService.updateById(customer);
            return AjaxResult.success("客户更新成功");
        }
        return AjaxResult.success("客户同步成功");
lihailong authored
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
    }



    //添加供应商
    @PostMapping("/addSupplier")
    @ApiOperation("添加供应商")
    @ApiLogger(apiName = "添加供应商", from = "ERP")
    @ResponseBody
    public AjaxResult addSupplier(@RequestBody Map<String, String> map) {
        String code = map.get("code");
        String companyCode = map.get("companyCode");
        String name = map.get("name");
        String address1 = map.get("address1");
        String address2 = map.get("address2");
        String city = map.get("city");
        String state = map.get("state");
        String country = map.get("country");
        String postalCode = map.get("postalCode");
        String parent = map.get("parent");
        String attentionTo = map.get("attentionTo");
        String phoneNum = map.get("phoneNum");
        String faxNum = map.get("faxNum");
        String email = map.get("email");
        String enable = map.get("enable");
        String createdBy = map.get("createdBy");
        String carrier = map.get("carrier");
        String version = map.get("version");
        String processStamp = map.get("processStamp");
        String deleted = map.get("deleted");
938
        String allCreditCode = map.get("allCreditCode");
lihailong authored
939
940
941
942
943
944
945
946

        Supplier supplier = new Supplier();
        if(StringUtils.isEmpty(carrier)){
            supplier.setCarrier("");
        }
        if(StringUtils.isEmpty(version)){
            supplier.setVersion(0);
        }
947
948
        if(StringUtils.isEmpty(code)){
            supplier.setCompanyCode("没有供应商code");
lihailong authored
949
950
951
952
        }
        if(StringUtils.isEmpty(companyCode)){
            supplier.setCompanyCode("BHF");
        }
953
954
        if(StringUtils.isEmpty(name)){
            return AjaxResult.error("没有供应商名称");
lihailong authored
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
        }
        if(StringUtils.isEmpty(address1)){
            supplier.setAddress1("");
        }
        if(StringUtils.isEmpty(address2)){
            supplier.setAddress2("");
        }
        if(StringUtils.isEmpty(city)){
            supplier.setCity("武汉");
        }
        if(StringUtils.isEmpty(state)){
            supplier.setState("湖北");
        }
        if(StringUtils.isEmpty(country)){
            supplier.setCountry("中国");
        }
        if(StringUtils.isEmpty(postalCode)){
            supplier.setPostalCode("");
        }
        if(StringUtils.isEmpty(parent)){
            supplier.setParent(0);
        }
        if(StringUtils.isEmpty(attentionTo)){
            supplier.setAttentionTo("");
        }
        if(StringUtils.isEmpty(phoneNum)){
            supplier.setPhoneNum("");
        }
        if(StringUtils.isEmpty(faxNum)){
            supplier.setFaxNum("");
        }
        if(StringUtils.isEmpty(email)){
            supplier.setEmail("");
        }
        if(StringUtils.isEmpty(enable)){
            supplier.setEnable(true);
        }
        if(StringUtils.isEmpty(createdBy)){
            supplier.setCreatedBy("ERP");
        }
        if(StringUtils.isEmpty(processStamp)){
            supplier.setProcessStamp("");
        }
        if(StringUtils.isEmpty(deleted)){
            supplier.setDeleted(false);
        }
1001
1002
1003
        if(StringUtils.isEmpty(allCreditCode)){
            supplier.setAllCreditCode(allCreditCode);
        }
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
        supplier.setCode(code);
        supplier.setAllCreditCode(allCreditCode);
        supplier.setCreatedBy(carrier);
        supplier.setName(name);
        supplier.setCreatedBy(createdBy);
        supplier.setWarehouseCode("CS0001");
        supplier.setCompanyCode(companyCode);
        supplier.setAddress1(address1);
        supplier.setCity(city);
        supplier.setState(state);
        supplier.setCountry(country);
1015
1016
1017
1018
1019

        Supplier one = supplierService.getOne(new LambdaQueryWrapper<Supplier>().eq(Supplier::getCode, code));
        if (one==null) {
            supplierService.save(supplier);
        }else {
1020
            supplier.setId(one.getId());
1021
1022
1023
1024
            supplierService.updateById(supplier);
            return AjaxResult.success("供应商更新成功");
        }
        return AjaxResult.success("同步供应商成功");
lihailong authored
1025
1026
1027
    }

}