cuijian
2023-08-19 bdd0875d4b13a3f1ef472f64d4b6a95e0ef64b22
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
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
588
589
590
591
592
593
594
595
596
597
598
599
600
601
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
package org.jeecg.modules.base.controller;
 
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.jeecg.common.system.query.QueryGenerator;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.base.entity.*;
import org.jeecg.modules.base.service.IEnterpriseService;
import org.jeecg.modules.base.service.IFactoryModelService;
import org.jeecg.modules.quartz.entity.QuartzJob;
import org.jeecg.modules.quartz.service.IQuartzJobService;
import org.jeecg.common.system.base.entity.DataVersion;
import org.jeecg.modules.system.service.IDataVersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
 
import java.text.ParseException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
 
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.base.service.IProductionLineWarehouseService;
import org.jeecg.modules.base.service.IProductionLineWarehouseClientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import java.io.IOException;
import java.util.stream.Collectors;
 
 /**
 * @Description: 线边库管理
 * @Author: jeecg-boot
 * @Date:   2023-01-28
 * @Version: V1.0
 */
@Api(tags="线边库管理")
@RestController
@RequestMapping("/base/productionLineWarehouse")
@Slf4j
public class ProductionLineWarehouseController extends JeecgController<ProductionLineWarehouse, IProductionLineWarehouseService> {
 
    @Autowired
    private IProductionLineWarehouseService productionLineWarehouseService;
 
    @Autowired
    private IProductionLineWarehouseClientService productionLineWarehouseClientService;
 
    @Autowired
    private IDataVersionService dataVersionService;
 
    @Autowired
    private IQuartzJobService quartzJobService;
 
    @Autowired
    private IFactoryModelService factoryModelService;
 
    @Autowired
    private IEnterpriseService enterpriseService;
    /*---------------------------------主表处理-begin-------------------------------------*/
     /**
      * 获取维护升版允许权限
      *
      *
      */
     @GetMapping("/getNewVersionPermission")
    public Result<?> getNewVersionPermission(){
         List<FactoryModel> usableFactoryList = factoryModelService
                .list(new QueryWrapper<FactoryModel>()
                        .eq("del_flag",0)
                        .in("enterprise_id",enterpriseService.getUsableIdList()));
         if(CollectionUtils.isEmpty(usableFactoryList)){
             return Result.OK(false);
        }else {
            List<ProductionLineWarehouse> list = productionLineWarehouseService
                    .list(new QueryWrapper<ProductionLineWarehouse>()
                            .in("workshop_id",usableFactoryList.stream().map(FactoryModel::getId).collect(Collectors.toList()))
                            .eq("del_flag",0));
             if(CollectionUtils.isNotEmpty(list)){
                 return Result.OK(false);
            }
             else {
                 return Result.OK(true);
            }
        }
    }
     /**
      *
      * 查该版本是否为历史版本
      *
      */
     @GetMapping(value = "/getUpdateVersionPermission")
     public Result<?> getUpdatePermission(@RequestParam("version") Integer version){
         List<FactoryModel> usableFactoryList = factoryModelService
                 .list(new QueryWrapper<FactoryModel>()
                         .eq("del_flag",0)
                         .in("enterprise_id",enterpriseService.getUsableIdList()));
         if(CollectionUtils.isNotEmpty(usableFactoryList)){
             return Result.OK(productionLineWarehouseService
                     .list(new QueryWrapper<ProductionLineWarehouse>()
                             .in("workshop_id",usableFactoryList.stream().map(FactoryModel::getId).collect(Collectors.toList()))
                             .eq("version",version)
                             .eq("del_flag",0)));
         }
         return Result.OK();
     }
     /**
      * 获取初始信息
      *
      *
      */
     @GetMapping("/getWarehouseInfo")
     public Result<?> getFactoryInfo(){
         Map<String,Object> infoMap = new HashMap<>(2);
         LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
         infoMap.put("enterpriseId",loginUser.getEnterpriseId());
         infoMap.put("version",productionLineWarehouseService.getInitVersion());
         return Result.OK(infoMap);
     }
    /**
     * 分页列表查询
     * @param map
     * @param pageNo
     * @param pageSize
     * @param workshopId
     * @param version
     * @return
     */
    @ApiOperation(value="线边库管理-分页列表查询", notes="线边库管理-分页列表查询")
    @GetMapping(value = "/list")
    @Transactional
    public Result<?> list(Map map,
                          @RequestParam(name ="pageNo", defaultValue="1") Integer pageNo,
                          @RequestParam(name ="pageSize", defaultValue="10") Integer pageSize,
                          @RequestParam(name = "workshopId",required = false) String workshopId,
                          @RequestParam(name="version",required = false) Integer version){
        Page<Map<String,Object>> page = new Page(pageNo, pageSize);
        IPage<Map<String,Object>> pageList = productionLineWarehouseService.getWarehouseList(page,version,workshopId);
        return Result.OK(pageList);
    }
     /**
      * 获取当前生效版本和上一次生效版本的版本号
      *
      * @return
      */
     @GetMapping("/getNowAndLastUsableVersion")
     public Result<?> getNowAndLastUsableVersion(){
         return Result.OK(productionLineWarehouseService.getNowAndLastUsableVersion());
     }
     /**
      * 获取所有版本号
      *
      *
      */
     @GetMapping("/getVersionList")
     public Result<?> getAllVersion(){
         return Result.OK(productionLineWarehouseService.getVersionList());
     }
     /**
      * 根据版本获取版本号
      * @param version
      * @return
      *
      */
     @GetMapping("/getVersionStatusByVersion")
     public Result<?> getVersionStatusByVersion(@RequestParam(value = "version",required = false) Integer version){
         return Result.OK(productionLineWarehouseService.getVersionStatusByVersion(version));
     }
    /**
     *   添加
     * @param map
     * @return
     */
    @AutoLog(value = "线边库管理-添加")
    @ApiOperation(value="线边库管理-添加", notes="线边库管理-添加")
    //@RequiresPermissions("org.jeecg.modules.demo:mom_base_production_line_warehouse:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody Map<String,Object> map) {
        ProductionLineWarehouse productionLineWarehouse = new ProductionLineWarehouse();
        productionLineWarehouse.setCode(String.valueOf(map.get("code")))
                .setName(String.valueOf(map.get("name")))
                .setVersion(Integer.parseInt(String.valueOf(map.get("version"))))
                .setWorkshopId(String.valueOf(map.get("workshopId")))
                .setRemark(String.valueOf(map.get("remark")))
                .setStatus(String.valueOf(map.get("status")))
                .setDelFlag(0);
        productionLineWarehouseService.save(productionLineWarehouse);
        QueryWrapper<ProductionLineWarehouse> queryWrapper = new QueryWrapper<ProductionLineWarehouse>()
                .eq("code",productionLineWarehouse.getCode())
                .eq("version",productionLineWarehouse.getVersion())
                .eq("del_flag",0);
        ProductionLineWarehouse selectWarehouse = productionLineWarehouseService.getOne(queryWrapper,true);
        DataVersion dataVersion = new DataVersion();
        dataVersion.setBusinessId(selectWarehouse.getId())
                .setBusinessType("线边库管理")
                .setVersion(selectWarehouse.getVersion())
                .setVersionStatus(String.valueOf(map.get("versionStatus")))
                .setDelFlag(0)
                .setEffectiveType("0")
                .setIsLastUsable("0");
        dataVersionService.save(dataVersion);
        QueryWrapper<DataVersion> queryWrapper1 = new QueryWrapper<DataVersion>()
                .eq("business_id",selectWarehouse.getId()).eq("del_flag",0);
        DataVersion selectDataVersion = dataVersionService.getOne(queryWrapper1,true);
        selectWarehouse.setDataVersionId(selectDataVersion.getId());
        productionLineWarehouseService.saveOrUpdate(selectWarehouse);
        return Result.OK("添加成功!");
    }
     /**
      * 表单校验
      */
     @GetMapping("/check")
     public Result<?> check(@RequestParam(name="name",required = false) String name,
                            @RequestParam(name="workshopId",required = false) String workshopId,
                            @RequestParam(name="version",required = false) Integer version
     ){
         QueryWrapper<ProductionLineWarehouse> queryWrapper = new QueryWrapper<>();
         if(!StringUtils.isBlank(name)){
             queryWrapper.eq("name",name);
         }
         if(!StringUtils.isBlank(workshopId)){
             queryWrapper.eq("workshop_id",workshopId);
         }
         if(version!=null){
             queryWrapper.eq("version",version);
         }
         queryWrapper.eq("del_flag","0");
         return Result.OK(productionLineWarehouseService.list(queryWrapper));
     }
     /**
      * 升版
      * 需要一次完成
      * @param map
      * @param
      * @return
      */
     @PostMapping("/updateVersion")
     @Transactional
     public  Result<?> updateVersion(@RequestBody Map<String,Object> map){
         Integer version = Integer.parseInt((String)map.get("version"));
         //获取升版数据
         List<ProductionLineWarehouse> list = productionLineWarehouseService.list(new QueryWrapper<ProductionLineWarehouse>()
                 .eq("version",version)
                 .eq("del_flag",0));
         //获取升版数据的版本信息
         QueryWrapper<DataVersion> queryWrapper = new QueryWrapper<DataVersion>()
                 .in("business_id", list.stream().map(ProductionLineWarehouse::getId).collect(Collectors.toList()))
                 .eq("del_flag",0);
         List<DataVersion> dataVersionList = dataVersionService.list(queryWrapper);
         Set<Integer> set = productionLineWarehouseService.getVersionList();
         Optional<Integer> maxVersion = set.stream().findFirst();
         list.stream().forEach(warehouse -> {
             warehouse.setId("");
             warehouse.setVersion(maxVersion.get()+1);
         });
         productionLineWarehouseService.saveBatch(list);
         List<ProductionLineWarehouse> newList = productionLineWarehouseService
                 .list(new QueryWrapper<ProductionLineWarehouse>()
                         .eq("version",maxVersion.get()+1));
         List<DataVersion> newDataVersionList = new ArrayList<>();
         for(int i=0;i<newList.size();i++){
             DataVersion dataVersion = new DataVersion();
             for(int j=0;j<list.size();j++){
                 for(int k=0;k<dataVersionList.size();k++){
                     if(list.get(j).getCode().equals(newList.get(i).getCode())
                             &&list.get(j).getDataVersionId().equals(dataVersionList.get(k).getId())) {
                         dataVersion
                                 .setVersion(maxVersion.get() + 1)
                                 .setVersionStatus("1")
                                 .setBusinessId(newList.get(i).getId())
                                 .setDelFlag(0)
                                 .setSourceVersionId(dataVersionList.get(k).getId())
                                 .setBusinessType("线边库管理")
                                 .setIsLastUsable("0");
                     }
                 }
             }
             newDataVersionList.add(dataVersion);
         }
         dataVersionService.saveBatch(newDataVersionList);
         List<String> dataVersionBusinessIdList = newDataVersionList.stream().map(DataVersion::getBusinessId).collect(Collectors.toList());
         QueryWrapper<DataVersion> queryWrapper1 = new QueryWrapper<DataVersion>().in("business_id",dataVersionBusinessIdList).eq("del_flag",0);
         List<DataVersion> selectDataVersionList = dataVersionService.list(queryWrapper1);
         for(int i=0;i<newList.size();i++){
             for(int j=0;j<selectDataVersionList.size();j++){
                 if(newList.get(i).getId().equals(selectDataVersionList.get(j).getBusinessId())){
                     newList.get(i).setDataVersionId(selectDataVersionList.get(j).getId());
                 }
             }
         }
         productionLineWarehouseService.updateBatchById(newList);
         return Result.OK(maxVersion.get()+1);
     }
     /**
      * 维护升版
      * 需要一次完成
      * @param
      * @return
      */
     @PostMapping("/updateVersionForChange")
     @Transactional
     public  Result<?> updateVersionForChange(){
         Set<Integer> set =  productionLineWarehouseService.getVersionList();
         return Result.OK(set.stream().findFirst().get()+1);
     }
     /**
      * 生效
      * 需要一次性完成
      * @param
      * @param map
      * @return
      */
     @PostMapping("/updateVersionStatusToUsable")
     @Transactional
     public Result<?> updateVersionStatusToUsable(@RequestBody Map<String,Object> map){
         Date date = new Date(System.currentTimeMillis());
         QuartzJob quartzJob = quartzJobService.getOne(new QueryWrapper<QuartzJob>()
                 .eq("job_class_name","org.jeecg.modules.quartz.job.ProductionLineWarehouseSetUsableJob"),true);
         if(ObjectUtils.isNotNull(quartzJob)){
             quartzJobService.deleteAndStopJob(quartzJob);
         }
         Integer version = Integer.parseInt((String)map.get("version"));
         //获取上次生效版本并将其是否上次生效位置置为否
         List<ProductionLineWarehouse> lastUsableList = productionLineWarehouseService.getLastUsableList();
         if(CollectionUtils.isNotEmpty(lastUsableList)){
             QueryWrapper<DataVersion> queryWrapper2 = new QueryWrapper<DataVersion>()
                     .in("business_id",lastUsableList.stream()
                             .map(ProductionLineWarehouse::getId)
                             .collect(Collectors.toList()));
             List<DataVersion> lastUsableVersionList = dataVersionService.list(queryWrapper2);
             lastUsableVersionList.stream().forEach(dataVersion -> {
                 dataVersion
                         .setIsLastUsable("0");
             });
             dataVersionService.updateBatchById(lastUsableVersionList);
         }
         //获取生效版本及版本信息并将其置为失效
         List<ProductionLineWarehouse> usableList = productionLineWarehouseService.getUsableList();
         if(CollectionUtils.isNotEmpty(usableList)){
             QueryWrapper<DataVersion> queryWrapper = new QueryWrapper<DataVersion>()
                     .in("business_id",usableList.stream()
                             .map(ProductionLineWarehouse::getId)
                             .collect(Collectors.toList()));
             List<DataVersion> usableDataVersionList = dataVersionService.list(queryWrapper);
             usableDataVersionList.stream().forEach(dataVersion -> {
                 dataVersion
                         .setVersionStatus("3")
                         .setIsLastUsable("1")
                         .setExpiredTime(date);
             });
             dataVersionService.updateBatchById(usableDataVersionList);
         }
         //获取待生效版本及版本信息并将其置为生效
         QueryWrapper<DataVersion> queryWrapper1 = new QueryWrapper<DataVersion>()
                 .in("business_id",productionLineWarehouseService.list(new QueryWrapper<ProductionLineWarehouse>()
                         .eq("version",version)
                         .eq("del_flag",0))
                         .stream().map(ProductionLineWarehouse::getId)
                         .collect(Collectors.toList()));
         List<DataVersion> dataVersionList = dataVersionService.list(queryWrapper1);
         dataVersionList.stream().forEach(dataVersion -> {
             dataVersion.setVersionStatus("2")
                     .setEffectiveType("2")
                     .setEffectiveTime(date)
                     .setIsLastUsable("0");
         });
         //存入数据库
         dataVersionService.updateBatchById(dataVersionList);
         return  Result.OK("生效成功");
     }
     /**
      * 定时生效
      * 需要一次性完成
      * @param quartzJob
      * @param
      * @return
      */
     @PostMapping("/updateVersionStatusToUsableBySetTime")
     @Transactional
     public Result<?> updateVersionStatusToUsableBySetTime(@RequestBody QuartzJob quartzJob) throws ParseException {
         DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("ss mm HH dd MM ? yyyy");
         String jobClassName = quartzJob.getJobClassName();
         String time = quartzJob.getCronExpression();
         System.out.println(time);
         LocalDateTime localDateTime = LocalDateTime.parse(time,dateTimeFormatter);
         String cronStr=dateTimeFormatter1.format(localDateTime);
         quartzJob.setCronExpression(cronStr);
         QueryWrapper<QuartzJob> queryWrapper = new QueryWrapper();
         queryWrapper.eq("JOB_CLASS_NAME",jobClassName);
         List<QuartzJob> quartzJobs = quartzJobService.list(queryWrapper);
         if(CollectionUtils.isEmpty(quartzJobs)){
             quartzJobService.saveAndScheduleJob(quartzJob);
             quartzJobs = quartzJobService.list(queryWrapper);
             quartzJob.setId(quartzJobs.get(0).getId());
             quartzJobService.resumeJob(quartzJob);
             return  Result.OK(quartzJob);
         }else{
             quartzJob.setId(quartzJobs.get(0).getId());
             quartzJobService.resumeJob(quartzJob);
             return Result.OK(quartzJob);
         }
 
     }
 
    /**
     *  编辑
     * @param productionLineWarehouse
     * @return
     */
    @AutoLog(value = "线边库管理-编辑")
    @ApiOperation(value="线边库管理-编辑", notes="线边库管理-编辑")
    //@RequiresPermissions("org.jeecg.modules.demo:mom_base_production_line_warehouse:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
    public Result<String> edit(@RequestBody ProductionLineWarehouse productionLineWarehouse) {
        productionLineWarehouseService.updateById(productionLineWarehouse);
        return Result.OK("编辑成功!");
    }
 
    /**
     * 通过id删除
     * @param id
     * @return
     */
    @Transactional
    @AutoLog(value = "线边库管理-通过id删除")
    @ApiOperation(value="线边库管理-通过id删除", notes="线边库管理-通过id删除")
    //@RequiresPermissions("org.jeecg.modules.demo:mom_base_production_line_warehouse:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name="id",required=true) String id) {
        dataVersionService.update(new UpdateWrapper<DataVersion>()
                .set("del_flag",1)
                .eq("business_id",id));
        productionLineWarehouseService.update(new UpdateWrapper<ProductionLineWarehouse>().set("del_flag",1).eq("id",id));
        return Result.OK("删除成功!");
    }
 
    /**
     * 批量删除
     * @param ids
     * @return
     */
    @Transactional
    @AutoLog(value = "线边库管理-批量删除")
    @ApiOperation(value="线边库管理-批量删除", notes="线边库管理-批量删除")
    //@RequiresPermissions("org.jeecg.modules.demo:mom_base_production_line_warehouse:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
        dataVersionService.update(new UpdateWrapper<DataVersion>()
                .set("del_flag",1)
                .in("business_id",Arrays.asList(ids.split(","))));
        productionLineWarehouseService
                .update(new UpdateWrapper<ProductionLineWarehouse>()
                        .in("id",Arrays.asList(ids.split(","))).set("del_flag",1));
        return Result.OK("批量删除成功!");
    }
 
    /**
     * 导出
     * @return
     */
    //@RequiresPermissions("org.jeecg.modules.demo:mom_base_production_line_warehouse:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, ProductionLineWarehouse productionLineWarehouse) {
        return super.exportXls(request, productionLineWarehouse, ProductionLineWarehouse.class, "线边库管理");
    }
 
    /**
     * 导入
     * @return
     */
    //@RequiresPermissions("org.jeecg.modules.demo:mom_base_production_line_warehouse:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, ProductionLineWarehouse.class);
    }
    /*---------------------------------主表处理-end-------------------------------------*/
 
 
    /*--------------------------------子表处理-线边库服务对象-begin----------------------------------------------*/
    /**
     * 通过主表ID查询
     * @return
     */
    //@AutoLog(value = "线边库服务对象-通过主表ID查询")
    @ApiOperation(value="线边库服务对象-通过主表ID查询", notes="线边库服务对象-通过主表ID查询")
    @GetMapping(value = "/listProductionLineWarehouseClientByMainId")
    public Result<IPage<ProductionLineWarehouseClient>> listProductionLineWarehouseClientByMainId(ProductionLineWarehouseClient productionLineWarehouseClient,
                                                    @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                    @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                    HttpServletRequest req) {
        QueryWrapper<ProductionLineWarehouseClient> queryWrapper = QueryGenerator.initQueryWrapper(productionLineWarehouseClient, req.getParameterMap());
        Page<ProductionLineWarehouseClient> page = new Page<ProductionLineWarehouseClient>(pageNo, pageSize);
        IPage<ProductionLineWarehouseClient> pageList = productionLineWarehouseClientService.page(page, queryWrapper);
        return Result.OK(pageList);
    }
 
    /**
     * 添加
     * @param map
     * @return
     */
    @AutoLog(value = "线边库服务对象-添加")
    @ApiOperation(value="线边库服务对象-添加", notes="线边库服务对象-添加")
    @PostMapping(value = "/addProductionLineWarehouseClient")
    public Result<String> addProductionLineWarehouseClient(@RequestBody Map map) {
        List<Map<String,Object>> addFactoryIds = (List<Map<String, Object>>) map.get("addFactoryIds");
        String warehouseId = (String) map.get("warehouseId");
        if(CollectionUtils.isNotEmpty(addFactoryIds)){
            List<ProductionLineWarehouseClient> warehouseClients=new ArrayList<>();
            addFactoryIds.forEach(factoryMap->{
                ProductionLineWarehouseClient warehouseClient = new ProductionLineWarehouseClient();
                warehouseClient.setClientId((String) factoryMap.get("id"))
                        .setWarehouseId(warehouseId)
                        .setCode((String) factoryMap.get("code"))
                        .setName((String) factoryMap.get("name"))
                        .setDelFlag(0);
                warehouseClients.add(warehouseClient);
            });
            productionLineWarehouseClientService.saveBatch(warehouseClients);
        }
        return Result.OK("添加成功!");
    }
 
    /**
     * 编辑
     * @param map
     * @return
     */
    @AutoLog(value = "线边库服务对象-编辑")
    @ApiOperation(value="线边库服务对象-编辑", notes="线边库服务对象-编辑")
    @RequestMapping(value = "/editProductionLineWarehouseClient", method = {RequestMethod.PUT,RequestMethod.POST})
    public Result<String> editProductionLineWarehouseClient(@RequestBody Map map) {
        List<Map<String,Object>> addFactoryIds = (List<Map<String, Object>>) map.get("addFactoryIds");
        String id = (String) map.get("id");
        if(CollectionUtils.isNotEmpty(addFactoryIds)){
            UpdateWrapper<ProductionLineWarehouseClient> updateWrapper = new UpdateWrapper<ProductionLineWarehouseClient>()
                    .eq("id",id)
                    .set("code",(String)addFactoryIds.get(0).get("code"))
                    .set("name",(String)addFactoryIds.get(0).get("name"));
            productionLineWarehouseClientService.update(updateWrapper);
        }
        return Result.OK("编辑成功!");
    }
 
    /**
     * 通过id删除
     * @param id
     * @return
     */
    @AutoLog(value = "线边库服务对象-通过id删除")
    @ApiOperation(value="线边库服务对象-通过id删除", notes="线边库服务对象-通过id删除")
    @DeleteMapping(value = "/deleteProductionLineWarehouseClient")
    public Result<String> deleteProductionLineWarehouseClient(@RequestParam(name="id",required=true) String id) {
        dataVersionService.update(new UpdateWrapper<DataVersion>()
                .set("del_flag",1)
                .eq("business_id",id));
        productionLineWarehouseClientService.update( new UpdateWrapper<ProductionLineWarehouseClient>()
                .set("del_flag",1)
                .eq("id",id));
        return Result.OK("删除成功!");
    }
 
    /**
     * 批量删除
     * @param ids
     * @return
     */
    @AutoLog(value = "线边库服务对象-批量删除")
    @ApiOperation(value="线边库服务对象-批量删除", notes="线边库服务对象-批量删除")
    @DeleteMapping(value = "/deleteBatchProductionLineWarehouseClient")
    public Result<String> deleteBatchProductionLineWarehouseClient(@RequestParam(name="ids",required=true) String ids) {
        dataVersionService.update(new UpdateWrapper<DataVersion>()
                .set("del_flag",1)
                .in("business_id",Arrays.asList(ids.split(","))));
        productionLineWarehouseClientService.update(new UpdateWrapper<ProductionLineWarehouseClient>()
                .in("id",Arrays.asList(ids.split(",")))
                .set("del_flag",1));
        return Result.OK("删除成功");
    }
 
    /**
     * 导出
     * @return
     */
    @RequestMapping(value = "/exportProductionLineWarehouseClient")
    public ModelAndView exportProductionLineWarehouseClient(HttpServletRequest request, ProductionLineWarehouseClient productionLineWarehouseClient) {
         // Step.1 组装查询条件
         QueryWrapper<ProductionLineWarehouseClient> queryWrapper = QueryGenerator.initQueryWrapper(productionLineWarehouseClient, request.getParameterMap());
         LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
 
         // Step.2 获取导出数据
         List<ProductionLineWarehouseClient> pageList = productionLineWarehouseClientService.list(queryWrapper);
         List<ProductionLineWarehouseClient> exportList = null;
 
         // 过滤选中数据
         String selections = request.getParameter("selections");
         if (oConvertUtils.isNotEmpty(selections)) {
             List<String> selectionList = Arrays.asList(selections.split(","));
             exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
         } else {
             exportList = pageList;
         }
 
         // Step.3 AutoPoi 导出Excel
         ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
         //此处设置的filename无效,前端会重更新设置一下
         mv.addObject(NormalExcelConstants.FILE_NAME, "线边库服务对象");
         mv.addObject(NormalExcelConstants.CLASS, ProductionLineWarehouseClient.class);
         mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("线边库服务对象报表", "导出人:" + sysUser.getRealname(), "线边库服务对象"));
         mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
         return mv;
    }
 
    /**
     * 导入
     * @return
     */
    @RequestMapping(value = "/importProductionLineWarehouseClient/{mainId}")
    public Result<?> importProductionLineWarehouseClient(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
         MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
         Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
         for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
       // 获取上传文件对象
             MultipartFile file = entity.getValue();
             ImportParams params = new ImportParams();
             params.setTitleRows(2);
             params.setHeadRows(1);
             params.setNeedSave(true);
             try {
                 List<ProductionLineWarehouseClient> list = ExcelImportUtil.importExcel(file.getInputStream(), ProductionLineWarehouseClient.class, params);
                 for (ProductionLineWarehouseClient temp : list) {
                    temp.setWarehouseId(mainId);
                 }
                 long start = System.currentTimeMillis();
                 productionLineWarehouseClientService.saveBatch(list);
                 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
                 return Result.OK("文件导入成功!数据行数:" + list.size());
             } catch (Exception e) {
                 log.error(e.getMessage(), e);
                 return Result.error("文件导入失败:" + e.getMessage());
             } finally {
                 try {
                     file.getInputStream().close();
                 } catch (IOException e) {
                     e.printStackTrace();
                 }
             }
         }
         return Result.error("文件导入失败!");
    }
 
    /*--------------------------------子表处理-线边库服务对象-end----------------------------------------------*/
     /**
      * //根据工厂id查所有子工厂及车间
      *
      * @param pageNo
      * @param pageSize
      * @param parentId
      * @param version
      * @return
      */
     @GetMapping("/factorylist")//根据工厂id查所有子工厂及车间
     public Result<?> list(Map map,
                           @RequestParam(name ="pageNo", defaultValue="1") Integer pageNo,
                           @RequestParam(name ="pageSize", defaultValue="10") Integer pageSize,
                           @RequestParam(name = "parentId",required = false) String parentId,
                           @RequestParam(name="version",required = false) Integer version,
                           @RequestParam(name="selected",required = false) String selected
     ){
         List<String> ids =  new ArrayList<>();
         if(selected!=null){
             ids = Arrays.asList(selected.split(","));
         }
         Page<Map<String,Object>> page = new Page(pageNo, pageSize);
         IPage<Map<String,Object>> pageList = productionLineWarehouseClientService.getFactoryList(page,version,parentId,ids);
         return Result.OK(pageList);
     }
 
 
 
}