k94314517
2025-06-16 15286a9ab39823ddbbf682e1049f39dfc5dd024f
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
package com.doumee.service.business.impl;
 
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.InsuranceMapper;
import com.doumee.dao.business.MultifileMapper;
import com.doumee.dao.business.WorktypeMapper;
import com.doumee.dao.business.join.DuWorkTypeJoinMapper;
import com.doumee.dao.business.join.WorktypeJoinMapper;
import com.doumee.dao.business.model.Insurance;
import com.doumee.dao.business.model.Multifile;
import com.doumee.dao.business.model.Solutions;
import com.doumee.dao.business.model.Worktype;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.service.business.InsuranceService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sun.corba.se.spi.orbutil.threadpool.Work;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
 
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 保险公司信息表Service实现
 * @author 江蹄蹄
 * @date 2024/01/16 10:03
 */
@Service
public class InsuranceServiceImpl implements InsuranceService {
 
    @Autowired
    private InsuranceMapper insuranceMapper;
    @Autowired
    private WorktypeMapper worktypeMapper;
    @Autowired
    private WorktypeJoinMapper worktypeJoinMapper;
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    @Autowired
    private MultifileMapper multifileMapper;
 
    @Override
    @Transactional
    public Integer create(Insurance insurance) {
 
        LoginUserInfo user= (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
        initCreateParam(insurance);//工种数据有效性检验,去除空白行数据
 
        if(insuranceMapper.selectCount(new QueryWrapper<Insurance>().lambda().eq(Insurance::getName,insurance.getName())
                .eq(Insurance::getIsdeleted,Constants.ZERO)
                .eq(Insurance::getDataType,Constants.ZERO)
        )>Constants.ZERO){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"保险公司名称已存在");
        }
 
        insurance.setIsdeleted(Constants.ZERO);
        insurance.setCreator(user.getId());
        insurance.setCreateDate(new Date());
        insurance.setVersion(UUID.randomUUID().toString());//版本号
        insurance.setDataType(Constants.ZERO);
        insurance.setStatus(Constants.ZERO);
        insuranceMapper.insert(insurance);//基础版本
 
        //如果有工种,则产生一个新的有效历史版本 ~
        Insurance newModel = new Insurance();
        BeanUtils.copyProperties(insurance,newModel);
        newModel.setId(null);
        newModel.setBaseId(insurance.getId());
        newModel.setDataType(Constants.TWO);
        insuranceMapper.insert(newModel);
 
        dealWorkTypeData(insurance,newModel,insurance.getWorktypeList(),true);
 
        return insurance.getId();
    }
    private void dealWorkTypeData(Insurance insurance, Insurance newModel, List<Worktype> worktypeList,boolean isNew) {
       int num=0;
        List<String> workTypeName = worktypeList.stream().map(m->m.getName()).collect(Collectors.toList());
        Set<String> set = new HashSet<>(workTypeName);
        if(workTypeName.size() != set.size()){
            throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"对不起,工种录入数据存在相同数据!");
        }
        List<Worktype> saveList = new ArrayList<>();
 
        for(Worktype w : worktypeList) {
            if(!isNew){
                //查询保险公司下是否已存在该工种
                if(worktypeMapper.selectCount(new QueryWrapper<Worktype>().lambda().eq(Worktype::getInsuranceId,insurance.getId())
                        .eq(Worktype::getIsdeleted,Constants.ZERO)
                        .eq(Worktype::getDataType,Constants.ZERO)
                        .eq(Worktype::getName,w.getName())
                )>Constants.ZERO){
                    throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"当前保险公司下存在【"+w.getName()+"】该工种信息");
                }
            }
            //基础版本
            w.setInsuranceId(insurance.getId());
            w.setIsdeleted(Constants.ZERO);
            w.setCreator(newModel.getCreator());
            w.setCreateDate(new Date());
            w.setDataType(insurance.getDataType());
            w.setStatus(Constants.ZERO);
            w.setVersion(insurance.getVersion());
            w.setSortnum(num++);
            saveList.add(w);
//            worktypeMapper.insert(w);
 
 
            //历史版本的工种信息
            Worktype newType = new Worktype();
            BeanUtils.copyProperties(w, newType);
            newType.setInsuranceId(newModel.getId());
            newType.setBaseId(w.getId());
            newType.setDataType(Constants.TWO);
            newType.setVersion(newModel.getVersion());
            w.setSortnum(num++);
            saveList.add(newType);
//            worktypeMapper.insert(newType);
        }
 
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(saveList)){
            worktypeJoinMapper.insert(saveList);
        }
        
 
    }
 
    private void initCreateParam(Insurance insurance) {
        if(StringUtils.isBlank(insurance.getName())){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,请输入保险公司名称!");
        }
        List<Worktype> worktypeList = new ArrayList<>();
        if(insurance.getWorktypeList()!=null && insurance.getWorktypeList().size()>0){
            for(Worktype w : insurance.getWorktypeList()){
                if(StringUtils.isNotBlank(w.getName())){
                    worktypeList.add(w);
                }
            }
        }
        if(worktypeList.size()==0){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,工种不能为空!");
        }
        if(StringUtils.isNotBlank(insurance.getEnglishName()) && insurance.getEnglishName().length()>100){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,英文名超长!");
        }
        if(StringUtils.isNotBlank(insurance.getLinkName()) && insurance.getLinkName().length()>10){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,联系人名称超长!");
        }
        if(StringUtils.isNotBlank(insurance.getLinkPhone()) && insurance.getLinkPhone().length()!=11){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,请输入正确的手机号!");
        }
        insurance.setWorktypeList(worktypeList);
    }
 
    @Override
    public void deleteById(Integer id) {
        LoginUserInfo user= (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
        Insurance model = findById(id);
        if(model == null || !Constants.equalsInteger(model.getDataType(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY );
        }
        Insurance update = new Insurance();
        update.setIsdeleted(Constants.ZERO);
        update.setEditDate(new Date());
        update.setEditor(user.getId());
        update.setId(id);
        insuranceMapper.updateById(update);
 
        //逻辑删除所有工种数据
        worktypeMapper.update(null,new UpdateWrapper<Worktype>()
                .lambda()
                .eq(Worktype::getInsuranceId,id)
                .eq(Worktype::getIsdeleted,Constants.ZERO)
                .set(Worktype::getIsdeleted,Constants.ONE)
         );
    }
 
    @Override
    public void delete(Insurance insurance) {
        LoginUserInfo user= (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
        Insurance model = findById(insurance.getId());
        if(model == null || !Constants.equalsInteger(model.getDataType(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY );
        }
        Insurance update = new Insurance();
        update.setIsdeleted(Constants.ZERO);
        update.setEditDate(new Date());
        update.setId(insurance.getId());
        update.setEditor(user.getId());
        insuranceMapper.updateById(update);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        insuranceMapper.deleteBatchIds(ids);
    }
 
    /*@Override
    public void updateById(Insurance insurance) {
        Insurance model = findById(insurance.getId());
        if(model == null  || !Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)
                || !Constants.equalsInteger(model.getDataType(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY );
        }
        //数据有效性校验
        initCreateParam(insurance);
        if(insuranceMapper.selectCount(new QueryWrapper<Insurance>().lambda().eq(Insurance::getName,insurance.getName())
                .eq(Insurance::getIsdeleted,Constants.ZERO)
                .eq(Insurance::getDataType,Constants.ZERO)
                .ne(Insurance::getId,insurance.getId())
        )>Constants.ZERO){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"保险公司名称已存在");
        }
 
        LoginUserInfo user= (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
        Insurance updateModel = new Insurance();
        updateModel.setEditor(user.getId());
        updateModel.setName(insurance.getName());
        updateModel.setId(model.getId());
        updateModel.setVersion(UUID.randomUUID().toString());
        updateModel.setEditDate(new Date());
        updateModel.setRemark(insurance.getRemark());
        updateModel.setSortnum(insurance.getSortnum());
        updateModel.setLogo(insurance.getLogo());
        updateModel.setEnglishName(insurance.getEnglishName());
        updateModel.setLinkName(insurance.getLinkName());
        updateModel.setLinkPhone(insurance.getLinkPhone());
        updateModel.setPolicy(insurance.getPolicy());
        updateModel.setAgreement(insurance.getAgreement());
        updateModel.setClaimsInformation(insurance.getClaimsInformation());
        insuranceMapper.updateById(updateModel);
 
        //如果修改,则产生一个新的历史版本 ~
//        Insurance newModel = new Insurance();
//        BeanUtils.copyProperties(model,newModel);
//        newModel.setId(null);
//        newModel.setVersion(updateModel.getVersion());
//        newModel.setCreateDate(new Date());
//        newModel.setName(updateModel.getName());
//        newModel.setBaseId(insurance.getId());
//        newModel.setDataType(Constants.TWO);
//        newModel.setLogo(insurance.getLogo());
//        newModel.setEnglishName(insurance.getEnglishName());
//        newModel.setLinkName(insurance.getLinkName());
//        newModel.setLinkPhone(insurance.getLinkPhone());
//        newModel.setPolicy(insurance.getPolicy());
//        newModel.setAgreement(insurance.getAgreement());
//        newModel.setClaimsInformation(insurance.getClaimsInformation());
//        insuranceMapper.insert(newModel);
 
        Insurance useVersion = insuranceMapper.selectOne(new QueryWrapper<Insurance>().lambda()
                .eq(Insurance::getBaseId,insurance.getId())
                .eq(Insurance::getDataType,Constants.TWO)
                .last(" limit 1")
        );
 
        Insurance updateUsrModel = new Insurance();
        updateUsrModel.setEditor(user.getId());
        updateUsrModel.setName(insurance.getName());
        updateUsrModel.setId(useVersion.getId());
        updateUsrModel.setVersion(UUID.randomUUID().toString());
        updateUsrModel.setEditDate(new Date());
        updateUsrModel.setRemark(insurance.getRemark());
        updateUsrModel.setSortnum(insurance.getSortnum());
        updateUsrModel.setLogo(insurance.getLogo());
        updateUsrModel.setEnglishName(insurance.getEnglishName());
        updateUsrModel.setLinkName(insurance.getLinkName());
        updateUsrModel.setLinkPhone(insurance.getLinkPhone());
        updateUsrModel.setPolicy(insurance.getPolicy());
        updateUsrModel.setAgreement(insurance.getAgreement());
        updateUsrModel.setClaimsInformation(insurance.getClaimsInformation());
 
        //删除所有工种数据
        worktypeMapper.delete(new UpdateWrapper<Worktype>()
                .lambda()
                .in(Worktype::getInsuranceId,insurance.getId())
        );
//        insuranceMapper.update(null,new UpdateWrapper<Insurance>()
//                .lambda()
//                .eq(Insurance::getBaseId,insurance.getId())
//                .eq(Insurance::getDataType,Constants.TWO)
//                .ne(Insurance::getId,newModel.getId())
//                .set(Insurance::getDataType,Constants.ONE)
//        );
        worktypeMapper.update(null,new UpdateWrapper<Worktype>()
                .lambda()
                .eq(Worktype::getInsuranceId,useVersion.getId())
                .eq(Worktype::getDataType,Constants.TWO)
                .set(Worktype::getDataType,Constants.ONE)
        );
 
        //处理工作信息,新增最新的,同时产生历史版本
        dealWorkTypeData(updateModel,useVersion,insurance.getWorktypeList(),false);
    }*/
 
 
    @Override
    public void updateById(Insurance insurance) {
        Insurance model = findById(insurance.getId());
        if(model == null  || !Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)
                || !Constants.equalsInteger(model.getDataType(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY );
        }
        //数据有效性校验
        initCreateParam(insurance);
        if(insuranceMapper.selectCount(new QueryWrapper<Insurance>().lambda().eq(Insurance::getName,insurance.getName())
                .eq(Insurance::getIsdeleted,Constants.ZERO)
                .eq(Insurance::getDataType,Constants.ZERO)
                .ne(Insurance::getId,insurance.getId())
        )>Constants.ZERO){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"保险公司名称已存在");
        }
 
        LoginUserInfo user= (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
        Insurance updateModel = new Insurance();
        updateModel.setEditor(user.getId());
        updateModel.setName(insurance.getName());
        updateModel.setId(model.getId());
        updateModel.setVersion(UUID.randomUUID().toString());
        updateModel.setEditDate(new Date());
        updateModel.setRemark(insurance.getRemark());
        updateModel.setSortnum(insurance.getSortnum());
        updateModel.setLogo(insurance.getLogo());
        updateModel.setEnglishName(insurance.getEnglishName());
        updateModel.setLinkName(insurance.getLinkName());
        updateModel.setLinkPhone(insurance.getLinkPhone());
        updateModel.setPolicy(insurance.getPolicy());
        updateModel.setAgreement(insurance.getAgreement());
        updateModel.setClaimsInformation(insurance.getClaimsInformation());
        insuranceMapper.updateById(updateModel);
 
        //如果修改,则产生一个新的历史版本 ~
        Insurance newModel = new Insurance();
        BeanUtils.copyProperties(model,newModel);
        newModel.setId(null);
        newModel.setVersion(updateModel.getVersion());
        newModel.setCreateDate(new Date());
        newModel.setName(updateModel.getName());
        newModel.setBaseId(insurance.getId());
        newModel.setDataType(Constants.TWO);
        newModel.setLogo(insurance.getLogo());
        newModel.setEnglishName(insurance.getEnglishName());
        newModel.setLinkName(insurance.getLinkName());
        newModel.setLinkPhone(insurance.getLinkPhone());
        newModel.setPolicy(insurance.getPolicy());
        newModel.setAgreement(insurance.getAgreement());
        newModel.setClaimsInformation(insurance.getClaimsInformation());
        insuranceMapper.insert(newModel);
 
        //删除所有工种数据
        worktypeMapper.delete(new UpdateWrapper<Worktype>()
                .lambda()
                .eq(Worktype::getInsuranceId,insurance.getId())
        );
        insuranceMapper.update(null,new UpdateWrapper<Insurance>()
                .lambda()
                .eq(Insurance::getBaseId,insurance.getId())
                .eq(Insurance::getDataType,Constants.TWO)
                .ne(Insurance::getId,newModel.getId())
                .set(Insurance::getDataType,Constants.ONE)
        );
        worktypeMapper.update(null,new UpdateWrapper<Worktype>()
                .lambda()
                .eq(Worktype::getBaseId,insurance.getId())
                .eq(Worktype::getDataType,Constants.TWO)
                .set(Worktype::getDataType,Constants.ONE)
        );
 
        //处理工作信息,新增最新的,同时产生历史版本
        dealWorkTypeData(updateModel,newModel,insurance.getWorktypeList(),false);
    }
 
    @Override
    public void updateStatus(Insurance insurance){
        if(insurance.getId() == null || insurance.getStatus()==null || insurance.getStatus()<0||insurance.getStatus()>1){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST );
        }
        Insurance model = findById(insurance.getId());
        if(model == null  || !Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)
                || !Constants.equalsInteger(model.getDataType(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY );
        }
        if(Constants.equalsInteger(model.getStatus(),insurance.getStatus())){
            //如果状态不发生改变,直接返回
            return;
        }
        LoginUserInfo user= (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
        //同时更新基表和历史版本所有数据状态
        insuranceMapper.update(null,new UpdateWrapper<Insurance>()
                .lambda()
                 .and(m -> m.eq(Insurance::getId,model.getId()).or().eq(Insurance::getBaseId,model.getId()))
                .eq(Insurance::getIsdeleted,Constants.ZERO)
                .set(Insurance::getEditDate,new Date())
                .set(Insurance::getEditor,user.getId())
                .set(Insurance::getStatus,insurance.getStatus())
        );
    }
 
    @Override
    public void updateByIdInBatch(List<Insurance> insurances) {
        if (CollectionUtils.isEmpty(insurances)) {
            return;
        }
        for (Insurance insurance: insurances) {
            this.updateById(insurance);
        }
    }
 
    @Override
    public Insurance findByIdAndType(Integer id,Integer type) {
        Insurance model = insuranceMapper.selectById(id);
        if(model == null  || !Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY );
        }
        String path = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+
                systemDictDataBiz.queryByCode(Constants.OSS,Constants.INSURANCE).getCode();
        //附件信息
        Multifile lpStampTempFile = multifileMapper.selectOne(new QueryWrapper<Multifile>().lambda().eq(Multifile::getIsdeleted,Constants.ZERO)
                .eq(Multifile::getObjId,id).eq(Multifile::getObjType,Constants.MultiFile.LP_STAMP_FILE.getKey()).last("limit 1"));
        if(Objects.nonNull(lpStampTempFile)){
            lpStampTempFile.setFileurlFull(path + lpStampTempFile.getFileurl());
            model.setLpStampTempFile(lpStampTempFile);
        }
 
        Multifile lpFile = multifileMapper.selectOne(new QueryWrapper<Multifile>().lambda().eq(Multifile::getIsdeleted,Constants.ZERO)
                .eq(Multifile::getObjId,id).eq(Multifile::getObjType,Constants.MultiFile.LP_FILE.getKey()).last("limit 1"));
        if(Objects.nonNull(lpFile)){
            lpFile.setFileurlFull(path + lpFile.getFileurl());
            model.setLpFile(lpFile);
        }
        if(Objects.nonNull(type)&&Constants.equalsInteger(type,Constants.ONE)){
            return  model;
        }
        List<Worktype> worktypeList = worktypeMapper.selectList(new QueryWrapper<Worktype>().lambda()
                .eq(Worktype::getInsuranceId,id)
                .eq(Worktype::getIsdeleted,Constants.ZERO)
                .orderByAsc(Worktype::getSortnum));
        model.setWorktypeList(worktypeList);
        return model;
    }
 
    @Override
    public Insurance findById(Integer id) {
        return this.findByIdAndType(id,null);
//        Insurance model = insuranceMapper.selectById(id);
//        if(model == null  || !Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){
//            throw  new BusinessException(ResponseStatus.DATA_EMPTY );
//        }
//        List<Worktype> worktypeList = worktypeMapper.selectList(new QueryWrapper<Worktype>().lambda()
//                .eq(Worktype::getInsuranceId,id)
//                .eq(Worktype::getIsdeleted,Constants.ZERO)
//                .orderByAsc(Worktype::getSortnum));
//        model.setWorktypeList(worktypeList);
//        String path = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+
//                systemDictDataBiz.queryByCode(Constants.OSS,Constants.INSURANCE).getCode();
//        //附件信息
//        Multifile lpStampTempFile = multifileMapper.selectOne(new QueryWrapper<Multifile>().lambda().eq(Multifile::getIsdeleted,Constants.ZERO)
//                .eq(Multifile::getObjId,id).eq(Multifile::getObjType,Constants.MultiFile.LP_STAMP_FILE.getKey()).last("limit 1"));
//        if(Objects.nonNull(lpStampTempFile)){
//            lpStampTempFile.setFileurlFull(path + lpStampTempFile.getFileurl());
//            model.setLpStampTempFile(lpStampTempFile);
//        }
//
//        Multifile lpFile = multifileMapper.selectOne(new QueryWrapper<Multifile>().lambda().eq(Multifile::getIsdeleted,Constants.ZERO)
//                .eq(Multifile::getObjId,id).eq(Multifile::getObjType,Constants.MultiFile.LP_FILE.getKey()).last("limit 1"));
//        if(Objects.nonNull(lpFile)){
//            lpFile.setFileurlFull(path + lpFile.getFileurl());
//            model.setLpFile(lpFile);
//        }
 
    }
 
    @Override
    public Insurance findOne(Insurance insurance) {
        QueryWrapper<Insurance> wrapper = new QueryWrapper<>(insurance);
        return insuranceMapper.selectOne(wrapper);
    }
 
    @Override
    public List<Insurance> findList(Insurance insurance) {
        insurance.setIsdeleted(Constants.ZERO);
        QueryWrapper<Insurance> wrapper = new QueryWrapper<>(insurance);
        return insuranceMapper.selectList(wrapper);
    }
  
    @Override
    public PageData<Insurance> findPage(PageWrap<Insurance> pageWrap) {
        IPage<Insurance> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        QueryWrapper<Insurance> queryWrapper = new QueryWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        pageWrap.getModel().setDataType(Constants.ZERO);//只选择基表数据
        pageWrap.getModel().setIsdeleted(Constants.ZERO);
        if (pageWrap.getModel().getId() != null) {
            queryWrapper.lambda().eq(Insurance::getId, pageWrap.getModel().getId());
        }
        if (pageWrap.getModel().getCreator() != null) {
            queryWrapper.lambda().eq(Insurance::getCreator, pageWrap.getModel().getCreator());
        }
        if (pageWrap.getModel().getCreateDate() != null) {
            queryWrapper.lambda().ge(Insurance::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate()));
            queryWrapper.lambda().le(Insurance::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate()));
        }
        if (pageWrap.getModel().getEditor() != null) {
            queryWrapper.lambda().eq(Insurance::getEditor, pageWrap.getModel().getEditor());
        }
        if (pageWrap.getModel().getEditDate() != null) {
            queryWrapper.lambda().ge(Insurance::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate()));
            queryWrapper.lambda().le(Insurance::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate()));
        }
        if (pageWrap.getModel().getIsdeleted() != null) {
            queryWrapper.lambda().eq(Insurance::getIsdeleted, pageWrap.getModel().getIsdeleted());
        }
        if (pageWrap.getModel().getName() != null) {
            queryWrapper.lambda().like(Insurance::getName, pageWrap.getModel().getName());
        }
        if (pageWrap.getModel().getRemark() != null) {
            queryWrapper.lambda().eq(Insurance::getRemark, pageWrap.getModel().getRemark());
        }
        if (pageWrap.getModel().getStatus() != null) {
            queryWrapper.lambda().eq(Insurance::getStatus, pageWrap.getModel().getStatus());
        }
        if (pageWrap.getModel().getSortnum() != null) {
            queryWrapper.lambda().eq(Insurance::getSortnum, pageWrap.getModel().getSortnum());
        }
        if (pageWrap.getModel().getVersion() != null) {
            queryWrapper.lambda().eq(Insurance::getVersion, pageWrap.getModel().getVersion());
        }
        if (pageWrap.getModel().getDataType() != null) {
            queryWrapper.lambda().eq(Insurance::getDataType, pageWrap.getModel().getDataType());
        }
        if (pageWrap.getModel().getBaseId() != null) {
            queryWrapper.lambda().eq(Insurance::getBaseId, pageWrap.getModel().getBaseId());
        }
        queryWrapper.lambda().orderByAsc(Insurance::getSortnum);
        PageData<Insurance> pageData = PageData.from(insuranceMapper.selectPage(page, queryWrapper));
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(pageData.getRecords())){
            String path = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()
                    +systemDictDataBiz.queryByCode(Constants.OSS,Constants.INSURANCE).getCode();
            for (Insurance insurance:pageData.getRecords()) {
                if (StringUtils.isNotBlank(insurance.getLogo())) {
                    insurance.setLogoFullUrl(path + insurance.getLogo() );
                }
            }
        }
 
        return pageData;
    }
 
    @Override
    public long count(Insurance insurance) {
        QueryWrapper<Insurance> wrapper = new QueryWrapper<>(insurance);
        return insuranceMapper.selectCount(wrapper);
    }
 
 
 
    @Override
    public void saveLpInfo(Insurance insurance){
        LoginUserInfo user= (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
        if(Objects.isNull(insurance)
                || Objects.isNull(insurance.getId())
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        multifileMapper.delete(new QueryWrapper<Multifile>().lambda()
                .eq(Multifile::getObjId,insurance.getId())
                .in(Multifile::getObjType,Constants.MultiFile.LP_STAMP_FILE.getKey(),Constants.MultiFile.LP_FILE.getKey())
        );
 
        Insurance model = new Insurance();
        model.setEditDate(new Date());
        model.setEditor(user.getId());
        if(Objects.nonNull(insurance.getLpStampTempFile())){
            Multifile multifile = insurance.getLpStampTempFile();
            multifile.setCreateDate(model.getEditDate());
            multifile.setCreator(model.getEditor());
            multifile.setIsdeleted(Constants.ZERO);
            multifile.setObjType(Constants.MultiFile.LP_STAMP_FILE.getKey());
            multifile.setObjId(insurance.getId());
            multifileMapper.insert(multifile);
        }
        if(Objects.nonNull(insurance.getLpFile())){
            Multifile multifile = insurance.getLpFile();
            multifile.setCreateDate(model.getEditDate());
            multifile.setCreator(model.getEditor());
            multifile.setIsdeleted(Constants.ZERO);
            multifile.setObjType(Constants.MultiFile.LP_FILE.getKey());
            multifile.setObjId(insurance.getId());
            multifileMapper.insert(multifile);
        }
        model.setId(insurance.getId());
        model.setLpYggxFileInfo(insurance.getLpYggxFileInfo());
        model.setLpMzFileInfo(insurance.getLpMzFileInfo());
        model.setLpZyFileInfo(insurance.getLpZyFileInfo());
        model.setLpScFileInfo(insurance.getLpScFileInfo());
        model.setLpOtherFileInfo(insurance.getLpOtherFileInfo());
        model.setLpFileStatus(Constants.ONE);
        insuranceMapper.updateById(model);
    }
 
 
}