Administrator
2023-06-19 49588f5a462ae7425e7eb030438a35fd80c246fa
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
package com.gk.firework.Controller;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gk.firework.Controller.Base.BaseController;
import com.gk.firework.Domain.*;
import com.gk.firework.Domain.Enum.ErrorCode;
import com.gk.firework.Domain.Enum.LicenseStatus;
import com.gk.firework.Domain.Enum.ProvinceCode;
import com.gk.firework.Domain.Exception.BusinessException;
import com.gk.firework.Domain.Utils.Base64Encrypt;
import com.gk.firework.Domain.Utils.Msg;
import com.gk.firework.Domain.Utils.PageInfo;
import com.gk.firework.Domain.Utils.StringUtils;
import com.gk.firework.Domain.Vo.LicenseVo;
import com.gk.firework.Service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @author : jingjy
 * @date : 2021/5/11 16:48
 */
@Api(tags = "许可证")
@RequestMapping("/license")
@RestController
public class LicenseController extends BaseController {
 
    private static final Byte ADD_OPTION = 1;
    private static final Byte EDIT_OPTION = 2;
    private static final Byte DEL_OPTION = 3;
 
    private static final Byte LICENSE_PF = 2;
    private static final Byte LICENSE_LS = 3;
 
    private static final int LICENSE_CODE_LENGTH = 16;
 
    /**
     * 未审核:0;等待审核:1;已审核:2;拒绝审核:3;
     **/
    private static final Byte STATUS_NOT_REVIEW = 0;
    private static final Byte STATUS_WAIT_REVIEW = 1;
    private static final Byte STATUS_REVIEWED = 2;
    private static final Byte STATUS_REJECT_REVIEW = 3;
 
 
    @Autowired
    private LicenseService licenseService;
    @Autowired
    private UserService userService;
    @Autowired
    private LicenseStorageService licenseStorageService;
    @Autowired
    private EnterpriseService enterpriseService;
    @Autowired
    private EnterpriseLicenseService enterpriseLicenseService;
 
 
    @ApiOperation(value = "许可证信息", notes = "分页查询", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex", value = "当前页面索引", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页面个数", required = true),
            @ApiImplicitParam(name = "sort", value = "排序字段", required = true),
            @ApiImplicitParam(name = "order", value = "排序方法(ASC/DESC)", required = true),
            @ApiImplicitParam(name = "name", value = "单位名称"),
            @ApiImplicitParam(name = "type", value = "1.生产;2.批发;3.零售 (传String类型的数字)"),
            @ApiImplicitParam(name = "effectdate", value = "生效日期(传String类型日期)"),
            @ApiImplicitParam(name = "noeffectdate", value = "失效日期(传String类型日期)"),
            @ApiImplicitParam(name = "status", value = "状态(1.有效;2.注销)(传String类型的数字)"),
            @ApiImplicitParam(name = "issuingunit", value = "发证机关"),
            @ApiImplicitParam(name = "reviewer", value = "发证人"),
            @ApiImplicitParam(name = "province", value = "省"),
            @ApiImplicitParam(name = "city", value = "市"),
            @ApiImplicitParam(name = "district", value = "区"),
 
    })
    @GetMapping("/info")
    public Msg getLicenseInfo(@RequestParam(value = "name", required = false) String name,
                              @RequestParam(value = "type", required = false) String type,
                              @RequestParam(value = "effectdate", required = false) String effectdate,
                              @RequestParam(value = "noeffectdate", required = false) String noeffectdate,
                              @RequestParam(value = "status", required = false) String status,
                              @RequestParam(value = "issuingunit", required = false) String issuingunit,
                              @RequestParam(value = "reviewer", required = false) String reviewer,
                              @RequestParam(value = "province", required = false) String province,
                              @RequestParam(value = "city", required = false) String city,
                              @RequestParam(value = "district", required = false) String district,
                              @RequestParam(value = "starttime1", required = false)String starttime1,
                              @RequestParam(value = "endtime1", required = false) String  endtime1,
                              @RequestParam(value = "starttime2", required = false)String starttime2,
                              @RequestParam(value = "endtime2", required = false)String endtime2,
                              @RequestParam(value = "reviewstatus", required = false)Integer reviewstatus,
                              @RequestParam(value = "validstatus", required = false)Byte validstatus,
                              @RequestParam(value = "licensecode", required = false)String licensecode,
                              @RequestParam(defaultValue = "0") Integer pageIndex,
                              @RequestParam(defaultValue = "10") Integer pageSize,
                              String sort, String order) {
        Msg msg = new Msg(true);
        PageInfo pageInfo = new PageInfo(pageIndex, pageSize, sort, order);
        Map<String, Object> condition = new HashMap<>(16);
 
        if (StringUtils.isNotBlank(type)) {
            condition.put("type", type);
        }
        if (StringUtils.isNotBlank(effectdate)) {
            condition.put("effectdate", effectdate);
        }
        if (StringUtils.isNotBlank(noeffectdate)) {
            condition.put("noeffectdate", noeffectdate);
        }
        if (StringUtils.isNotBlank(status)) {
            condition.put("status", status);
        }
        if (StringUtils.isNotBlank(issuingunit)) {
            condition.put("issuingunit", issuingunit);
        }
        if (StringUtils.isNotBlank(reviewer)) {
            condition.put("reviewer", reviewer);
        }
        condition.put("filterProvince", province);
        condition.put("filterCity", city);
        condition.put("filterDistrict", district);
        condition.put("starttime1", starttime1);
        condition.put("endtime1", endtime1);
        condition.put("starttime2", starttime2);
        condition.put("endtime2", endtime2);
        condition.put("licensestatus", LicenseStatus.parse(licensecode));
        condition.put("validstatus", validstatus);
        condition.put("reviewstatus", reviewstatus);
        UserInfo userInfo = userService.getById(getUser().getId());
        if (userInfo.getCompanyid() != null) {
            condition.put("name", userInfo.getCompany());
        } else if (userInfo.getType() == 3) {
            if (StringUtils.isNotBlank(name)) {
                condition.put("name", name);
            }
            if (StringUtils.isNotBlank(userInfo.getProvince())) {
                condition.put("province", userInfo.getProvince());
            }
            if (StringUtils.isNotBlank(userInfo.getCity())) {
                condition.put("city", userInfo.getCity());
            }
            if (StringUtils.isNotBlank(userInfo.getArea())) {
                condition.put("district", userInfo.getArea());
            }
        }else {
            if (StringUtils.isNotBlank(name)) {
                condition.put("name", name);
            }
        }
 
        pageInfo.setCondition(condition);
        licenseService.selectDataGrid(pageInfo);
        msg.setResult(pageInfo);
        return msg;
    }
 
    @GetMapping("/export")
    Msg exportLicense(@RequestParam(value = "name", required = false) String name,
                      @RequestParam(value = "type", required = false) String type,
                      @RequestParam(value = "status", required = false) String status,
                      @RequestParam(value = "issuingunit", required = false) String issuingunit,
                      @RequestParam(value = "reviewer", required = false) String reviewer,
                      @RequestParam(value = "province", required = false) String province,
                      @RequestParam(value = "city", required = false) String city,
                      @RequestParam(value = "district", required = false) String district,
                      @RequestParam(value = "starttime1", required = false) String starttime1,
                      @RequestParam(value = "endtime1", required = false) String endtime1,
                      @RequestParam(value = "starttime2", required = false) String starttime2,
                      @RequestParam(value = "endtime2", required = false) String endtime2,
                      @RequestParam(value = "reviewstatus", required = false) Integer reviewstatus,
                      String sort, String order) {
        Map<String,Object> condition = new HashMap<>();
        condition.put("type", type);
       condition.put("status", status);
       condition.put("issuingunit", issuingunit);
        condition.put("reviewer", reviewer);
        condition.put("filterProvince", province);
        condition.put("filterCity", city);
        condition.put("filterDistrict", district);
        condition.put("starttime1", starttime1);
        condition.put("endtime1", endtime1);
        condition.put("starttime2", starttime2);
        condition.put("endtime2", endtime2);
        condition.put("reviewstatus", reviewstatus);
        UserInfo userInfo = userService.getById(getUser().getId());
        if (userInfo.getCompanyid() != null) {
            condition.put("name", userInfo.getCompany());
        } else if (userInfo.getType() == 3) {
            if (StringUtils.isNotBlank(name)) {
                condition.put("name", name);
            }
            if (StringUtils.isNotBlank(userInfo.getProvince())) {
                condition.put("province", userInfo.getProvince());
            }
            if (StringUtils.isNotBlank(userInfo.getCity())) {
                condition.put("city", userInfo.getCity());
            }
            if (StringUtils.isNotBlank(userInfo.getArea())) {
                condition.put("district", userInfo.getArea());
            }
        }else {
            if (StringUtils.isNotBlank(name)) {
                condition.put("name", name);
            }
        }
 
        List<LicenseVo> licenseVos = licenseService.exportLicense(condition);
        return success(licenseVos);
    }
 
    @PostMapping("/addLicense")
    public Msg addLicense(@Validated @RequestBody LicenseVo licenseVo, BindingResult bindingResult) {
        Msg msg = new Msg(true);
        if (bindingResult.hasErrors()) {
            StringBuilder stringBuilder = new StringBuilder();
            for (String s : bindingResult.getFieldErrors().stream()
                    .map(FieldError::getDefaultMessage).collect(Collectors.toList())) {
                stringBuilder.append(s);
                stringBuilder.append(",");
            }
            msg.setCode("999");
            msg.setMessage(stringBuilder.toString());
            return msg;
        }
        Msg checkMsg = checkLicense(licenseVo, ADD_OPTION);
        if (!checkMsg.getCode().equals(ErrorCode.SUCCESS.getCode())) {
            return checkMsg;
        }
        LicenseInfo licenseInfo1 = licenseService.getLastOne();
        Integer sn = licenseInfo1.getSn();
        sn++;
        licenseVo.setSn(sn);
        String abbr = "";
        String typeCode = "";
        for (ProvinceCode code : ProvinceCode.values()) {
            if (licenseVo.getProvince().equals(code.getName())) {
                abbr = code.getAbbr();
            }
        }
        if (StringUtils.isBlank(abbr)) {
            msg.setCode("200");
            msg.setMessage("省份对应错误,生成许可证编号失败!");
            return msg;
        }
        if (licenseVo.getType().equals(LICENSE_PF)) {
            typeCode = "PF";
        } else if (licenseVo.getType().equals(LICENSE_LS)) {
            typeCode = "LS";
        }
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
 
        String licenseCode = "(" + abbr + ")" + typeCode + "〔" + year + "〕" + String.format("%05d", sn);
        if (licenseCode.length() != LICENSE_CODE_LENGTH) {
            msg.setCode("999");
            msg.setMessage("错误,生成许可证编号失败!");
            return msg;
        }
        licenseVo.setLicensecode(licenseCode);
        JSONArray jsonArray = JSONArray.parseArray(licenseVo.getLicenseStorage());
        List<LicenseStorage> licenseStorageList = jsonArray.toJavaList(LicenseStorage.class);
        for (LicenseStorage licenseStorage : licenseStorageList) {
            licenseStorage.setLicensecode(licenseCode);
        }
        licenseStorageService.saveBatch(licenseStorageList);
        licenseVo.setCreatedat(new Date());
        licenseVo.setCreatedby(getUser().getUsername());
        licenseVo.setLicensestatus(LicenseStatus.NEW);
        licenseVo.setValidstatus((byte) 1);
        licenseService.save(licenseVo);
        return msg;
    }
 
    @PostMapping("/editLicense")
    public Msg editLicense(@Validated @RequestBody LicenseVo licenseVo, BindingResult bindingResult) {
        Msg msg = new Msg(true);
        if (bindingResult.hasErrors()) {
            StringBuilder stringBuilder = new StringBuilder();
            for (String s : bindingResult.getFieldErrors().stream()
                    .map(FieldError::getDefaultMessage).collect(Collectors.toList())) {
                stringBuilder.append(s);
                stringBuilder.append(",");
            }
            msg.setCode("999");
            msg.setMessage(stringBuilder.toString());
            return msg;
        }
        Msg checkMsg = checkLicense(licenseVo, EDIT_OPTION);
        //控制许可证相关信息是否更新在企业信息中
        boolean flag = false;
        if (!checkMsg.getCode().equals(ErrorCode.SUCCESS.getCode())) {
            return checkMsg;
        }
        UserInfo userInfo = userService.getById(getUser().getId());
        JSONArray jsonArray = JSONArray.parseArray(licenseVo.getLicenseStorage());
        List<LicenseStorage> licenseStorages = jsonArray.toJavaList(LicenseStorage.class);
        for (LicenseStorage licenseStorage : licenseStorages) {
            licenseStorage.setLicensecode(licenseVo.getLicensecode());
        }
 
        LicenseInfo licenseInfo = licenseService.getLicenseById(licenseVo.getId());
        Byte reviewStatus = licenseVo.getReviewstatus();
        if (licenseInfo == null) {
            msg.setCode(ErrorCode.ERROR_999.getMsg());
            msg.setMessage("未找到对应的许可证信息,审核失败!");
            return msg;
        }
        if (licenseInfo.getReviewstatus().equals(STATUS_REVIEWED)){
            msg.setCode(ErrorCode.ERROR_999.getMsg());
            msg.setMessage("许可证信息已审核,无法修改!");
            return msg;
        }
 
        if (userInfo.getCompanyid() == null) {
            // 审核需要判断用户角色权限
            if (!reviewStatus.equals(STATUS_REVIEWED) && !reviewStatus.equals(STATUS_REJECT_REVIEW)) {
                msg.setCode(ErrorCode.ERROR_999.getMsg());
                msg.setMessage("权限错误,审核失败!");
                return msg;
            }
 
            if (licenseInfo.getReviewstatus().equals(STATUS_NOT_REVIEW) && !reviewStatus.equals(STATUS_WAIT_REVIEW)) {
                msg.setCode(ErrorCode.ERROR_999.getMsg());
                msg.setMessage("当前许可证未提交审核,操作失败!");
                return msg;
            }
 
            if (licenseInfo.getReviewstatus().equals(STATUS_WAIT_REVIEW)) {
                if (!reviewStatus.equals(STATUS_REVIEWED) && !reviewStatus.equals(STATUS_REJECT_REVIEW)) {
                    msg.setCode(ErrorCode.ERROR_999.getMsg());
                    msg.setMessage("当前许可证为待审核,操作失败!");
                    return msg;
                }
            }
 
            if (licenseInfo.getReviewstatus().equals(STATUS_REVIEWED)) {
                msg.setCode(ErrorCode.ERROR_999.getMsg());
                msg.setMessage("当前许可证已审核完毕,操作失败!");
                return msg;
            }
 
            //判断是否能够审核
            if (reviewStatus.equals(STATUS_REVIEWED)){
                if (!reviewStatus.equals(licenseInfo.getReviewstatus())) {
                    if (licenseVo.getEffectdate() == null || licenseVo.getNoeffectdate() == null) {
                        msg.setCode(ErrorCode.ERROR_999.getMsg());
                        msg.setMessage("有效期不能为空");
                        return msg;
                    }
 
                    if (StringUtils.isBlank(licenseVo.getIssuingunit()) || licenseVo.getIssuingdate() == null) {
                        msg.setCode(ErrorCode.ERROR_999.getMsg());
                        msg.setMessage("发证机关和发证日期不能为空");
                        return msg;
                    }
                }
                licenseVo.setReviewer(getUser().getUsername());
                licenseVo.setReviewat(new Date());
                flag = true;
            }
        }else{
            if (licenseInfo.getReviewstatus().equals(STATUS_WAIT_REVIEW)){
                msg.setCode(ErrorCode.ERROR_999.getMsg());
                msg.setMessage("许可证信息等待审核中,无法修改!");
                return msg;
            }
        }
 
 
        licenseStorageService.updateBatchById(licenseStorages);
        licenseVo.setModifiedat(new Date());
        licenseVo.setModifiedby(getUser().getUsername());
        licenseService.updateById(licenseVo);
        if (flag){
            Enterprise enterprise = enterpriseService.selectEnterpriseByName(licenseInfo.getName());
            enterprise.setValidstarttime(licenseVo.getEffectdate());
            enterprise.setValidendtime(licenseVo.getNoeffectdate());
            enterpriseService.updateById(enterprise);
            EnterpriseLicense enterpriseLicense = new EnterpriseLicense();
            if (licenseVo.getType().equals(LICENSE_PF)){
                enterpriseLicense.setLicensename("烟花爆竹经营(批发)许可证");
            }else if (licenseVo.getType().equals(LICENSE_LS)){
                enterpriseLicense.setLicensename("烟花爆竹经营(零售)许可证");
            }
            enterpriseLicense.setLicensenumber(licenseVo.getLicensecode());
            enterpriseLicense.setEnterpriseid(enterprise.getId());
            enterpriseLicense.setAuthority(licenseVo.getIssuingunit());
            enterpriseLicense.setRanges(licenseService.dealDealingRange(licenseVo.getDealingrange()).toString());
            enterpriseLicense.setValidendtime(licenseVo.getReviewat());
            enterpriseLicense.setValidstarttime(licenseVo.getEffectdate());
            enterpriseLicense.setValidflag(true);
            enterpriseLicense.setCreatetime(new Date());
            enterpriseLicense.setCreateby(getUser().getId());
            enterpriseLicense.setCreatebyname(getUser().getUsername());
            enterpriseLicenseService.save(enterpriseLicense);
            //issale = 1 修改 截止有效期
            List<UserInfo> userList = userService.selectByCompanyId(enterprise.getId(),0);
            if (userList.size() != 2) {
                throw new BusinessException("发生错误,请联系管理员");
            }
            for (UserInfo info : userList) {
                //修改许可证 同时修改issale=1的用户有效期
                if (info.getIssale() == (byte) 1) {
                    Date validendtime = enterprise.getValidendtime();
                    Calendar instance = Calendar.getInstance();
                    instance.setTime(validendtime);
                    instance.set(Calendar.HOUR_OF_DAY, 23);
                    instance.set(Calendar.MINUTE, 59);
                    instance.set(Calendar.SECOND, 59);
                    info.setExpiredate(instance.getTime());
                    userService.updateById(info);
                }
            }
        }
        return msg;
    }
 
    @ApiOperation(value = "许可证审核", httpMethod = "PUT")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "审核许可证ID", required = true),
            @ApiImplicitParam(name = "reviewstatus", value = "审核状态(0.未审核;1.等待审核;2.已审核;3.审核驳回) 数字类型", required = true),})
    @PostMapping("/review")
    private Msg reviewLicense(@RequestParam(value = "id") Long id,
                              @RequestParam(value = "reviewstatus") Byte reviewstatus) {
        Msg msg = new Msg(true);
 
        LicenseInfo licenseInfo = licenseService.getLicenseById(id);
        if (licenseInfo == null) {
            msg.setCode(ErrorCode.ERROR_999.getMsg());
            msg.setMessage("未找到对应的许可证信息,审核失败!");
            return msg;
        }
 
        UserInfo userInfo = userService.getById(getUser().getId());
        if (userInfo.getCompanyid() == null) {
            if (!reviewstatus.equals(STATUS_NOT_REVIEW) || !reviewstatus.equals(STATUS_WAIT_REVIEW)) {
                msg.setCode(ErrorCode.ERROR_999.getMsg());
                msg.setMessage("权限错误,审核失败!");
                return msg;
            }
        }
 
 
        if (licenseInfo.getReviewstatus().equals(STATUS_NOT_REVIEW) && !reviewstatus.equals(STATUS_WAIT_REVIEW)) {
            msg.setCode(ErrorCode.ERROR_999.getMsg());
            msg.setMessage("当前许可证未提交审核,操作失败!");
            return msg;
        }
 
        if (licenseInfo.getReviewstatus().equals(STATUS_WAIT_REVIEW)) {
            if (!reviewstatus.equals(STATUS_REVIEWED) && !reviewstatus.equals(STATUS_REJECT_REVIEW)) {
                msg.setCode(ErrorCode.ERROR_999.getMsg());
                msg.setMessage("当前许可证为待审核,操作失败!");
                return msg;
            }
        }
        if (licenseInfo.getReviewstatus().equals(STATUS_REVIEWED)) {
            msg.setCode(ErrorCode.ERROR_999.getMsg());
            msg.setMessage("当前许可证已审核完毕,操作失败!");
            return msg;
        }
        licenseInfo.setReviewstatus(reviewstatus);
        licenseService.updateById(licenseInfo);
 
        return msg;
    }
 
 
    @ApiOperation(value = "许可证删除", httpMethod = "PUT")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "许可证ID", required = true)})
    @PostMapping("/delete")
    private Msg delLicense(@RequestParam(value = "id") Long id) {
        Msg msg = new Msg(true);
 
        LicenseInfo licenseInfo = licenseService.getLicenseById(id);
        if (licenseInfo == null) {
            msg.setCode(ErrorCode.ERROR_999.getMsg());
            msg.setMessage("未找到对应的许可证信息,审核失败!");
            return msg;
        }
 
        if (licenseInfo.getReviewstatus().equals(STATUS_REVIEWED)) {
            msg.setCode(ErrorCode.ERROR_999.getCode());
            msg.setMessage("当前许可证已审核完毕,无法删除!");
            return msg;
        }
 
        licenseInfo.setFlag((byte) 1);
        licenseService.updateById(licenseInfo);
 
        return msg;
    }
 
 
    @ApiOperation(value = "许可证驳回", httpMethod = "PUT")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "许可证ID", required = true)})
    @PostMapping("/reject")
    private Msg rejectLicense(@RequestBody JSONObject data) {
        licenseService.rejectLicense(data,getUser());
        return success();
    }
 
    private Msg checkLicense(LicenseVo licenseVo, Byte option) {
        Msg msg = new Msg(false);
        if (licenseVo == null) {
            msg.setMessage("操作失败:未找到对应的许可证信息");
            return msg;
        }
        if (option.equals(EDIT_OPTION)) {
            if (licenseVo.getId() == null) {
                msg.setMessage("操作失败:未找到对应的许可证信息");
                return msg;
            }
        }
        if (licenseVo.getType() == null) {
            msg.setMessage("类型不能为空");
            return msg;
        }
 
        if (licenseVo.getName() == null) {
            msg.setMessage("类别名称不能为空");
            return msg;
        }
        if (licenseVo.getCode() == null) {
            msg.setMessage("统一社会信用代码不能为空");
            return msg;
        }
        if (StringUtils.isBlank(licenseVo.getMainpersonname())
                || StringUtils.isBlank(licenseVo.getMainpersonidcardnum())
                || StringUtils.isBlank(licenseVo.getMainpersontel())) {
            msg.setMessage("主要负责人信息不能为空");
            return msg;
        }
        if (StringUtils.isBlank(licenseVo.getSafetypersonname())
                || StringUtils.isBlank(licenseVo.getSafetypersonidcardnum())
                || StringUtils.isBlank(licenseVo.getSafetypersontel())) {
            msg.setMessage("安全负责人信息不能为空");
            return msg;
        }
        if (StringUtils.isBlank(licenseVo.getProvince()) || StringUtils.isBlank(licenseVo.getCity())
                || StringUtils.isBlank(licenseVo.getDistrict()) || StringUtils.isBlank(licenseVo.getAddress())) {
            msg.setMessage("单位地址/注册地址不能为空");
            return msg;
        }
 
        if (licenseVo.getType().equals(LICENSE_PF) || licenseVo.getType().equals(LICENSE_LS)) {
            if (StringUtils.isBlank(licenseVo.getLicenseStorage())) {
                msg.setMessage("批发企业和生产企业仓库信息不能为空");
                return msg;
            }
        }
        msg.setCode("200");
        return msg;
    }
 
 
    @PostMapping("/delay")
    public Msg delay(@RequestBody JSONObject jso) {
        Long id = jso.getLong("id");
        String issuingunit = jso.getString("issuingunit");
        Date issuingdate = jso.getDate("issuingdate");
        Date validstarttime = jso.getDate("validstarttime");
        Date validendtime = jso.getDate("validendtime");
        licenseService.delayLicense(id, issuingunit, issuingdate, validstarttime, validendtime,getUser());
        return success();
    }
 
    @PostMapping("/mod")
    public Msg mod(@Validated @RequestBody LicenseVo licenseVo, BindingResult bindingResult) {
        //判断
        Msg msg = new Msg(true);
        if (bindingResult.hasErrors()) {
            StringBuilder stringBuilder = new StringBuilder();
            for (String s : bindingResult.getFieldErrors().stream()
                    .map(FieldError::getDefaultMessage).collect(Collectors.toList())) {
                stringBuilder.append(s);
                stringBuilder.append(",");
            }
            msg.setCode("999");
            msg.setMessage(stringBuilder.toString());
        }
        Msg checkMsg = checkLicense(licenseVo, EDIT_OPTION);
        if (!checkMsg.getCode().equals(ErrorCode.SUCCESS.getCode())) {
            return checkMsg;
        }
 
        licenseService.generateLicenseDetail(licenseVo);
        JSONArray jsonArray = JSONArray.parseArray(licenseVo.getLicenseStorage());
        List<LicenseStorage> licenseStorageList = jsonArray.toJavaList(LicenseStorage.class);
        for (LicenseStorage licenseStorage : licenseStorageList) {
            licenseStorage.setLicensecode(licenseVo.getLicensecode());
        }
        licenseService.modLicense(licenseVo, licenseStorageList, getUser());
        return success();
    }
 
}