k94314517
2025-05-28 a43f9d75a9e0ba2720b3c438a0c5ece7be0eb110
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
package com.doumee.service.business.impl;
 
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.*;
import com.doumee.dao.business.join.SolutionWorktypeJoinMapper;
import com.doumee.dao.business.join.SolutionsBaseJoinMapper;
import com.doumee.dao.business.model.*;
import com.doumee.service.business.SolutionsBaseService;
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.github.yulichang.wrapper.MPJLambdaWrapper;
import io.swagger.models.auth.In;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
 
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 保险方案信息表Service实现
 * @author 江蹄蹄
 * @date 2024/10/28 19:16
 */
@Service
public class SolutionsBaseServiceImpl implements SolutionsBaseService {
 
    @Autowired
    private SolutionsBaseMapper solutionsBaseMapper;
 
    @Autowired
    private SolutionsBaseJoinMapper solutionsBaseJoinMapper;
 
    @Autowired
    private InsuranceMapper insuranceMapper;
 
    @Autowired
    private SolutionWorktypeJoinMapper solutionWorktypeJoinMapper;
 
    @Autowired
    private WorktypeMapper worktypeMapper;
 
    @Autowired
    private CompanySolutionMapper companySolutionMapper;
 
    @Autowired
    private DuSolutionMapper duSolutionMapper;
 
    @Autowired
    private SolutionsMapper solutionsMapper;
 
    @Autowired
    private InsuranceApplyMapper insuranceApplyMapper;
 
    @Override
    @Transactional(rollbackFor = {BusinessException.class,Exception.class})
    public Integer create(SolutionsBase solutionsBase) {
        LoginUserInfo user= (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        initCreateParam(solutionsBase);
        if(solutionsBaseMapper.selectCount(new QueryWrapper<SolutionsBase>().lambda()
                .eq(SolutionsBase::getName,solutionsBase.getName())
                .eq(SolutionsBase::getIsdeleted,Constants.ZERO)
                .eq(SolutionsBase::getDataType,Constants.ZERO)
        )>Constants.ZERO){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"保险主方案名称已存在");
        }
 
 
        solutionsBase.setCreateDate(new Date());
        solutionsBase.setCreator(user.getId());
        solutionsBase.setEditDate(new Date());
        solutionsBase.setEditor(user.getId());
        solutionsBase.setIsdeleted(Constants.ZERO);
        solutionsBase.setStatus(Constants.ZERO);
        solutionsBase.setVersion(UUID.randomUUID().toString());//版本号
        solutionsBase.setDataType(Constants.ZERO);
 
        //2024年6月17日15:56:18 仅支持替换模式下,批增配置日期 等于 批减配置日期
        if(Constants.equalsInteger(solutionsBase.getDelOnlyReplace(),Constants.ONE)){
            solutionsBase.setAddValidDays(solutionsBase.getDelValidDays());
        }
        solutionsBaseMapper.insert(solutionsBase); //基础版本
 
        //如果有工种,则产生一个新的有效历史版本 ~
        SolutionsBase newModel = new SolutionsBase();
        BeanUtils.copyProperties(solutionsBase,newModel);
        newModel.setId(null);
        newModel.setBaseId(solutionsBase.getId());
        newModel.setDataType(Constants.TWO);
        solutionsBaseMapper.insert(newModel);
 
        dealWorkTypeInsurance(solutionsBase,newModel,solutionsBase.getWorktypeIdList());
 
        return solutionsBase.getId();
    }
 
 
 
 
 
    private void dealWorkTypeInsurance(SolutionsBase solutionsBase, SolutionsBase newModel, List<Integer> worktypeIdList) {
        Insurance  model = insuranceMapper.selectById(solutionsBase.getInsuranceId());
        if(model == null  || !Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)
                || !Constants.equalsInteger(model.getDataType(),Constants.TWO)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,该保险公司信息不存在,请尝试刷新页面重试~" );
        }
        if( !Constants.equalsInteger(model.getStatus(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,该保险公司已被禁用,请尝试刷新页面重试~" );
        }
        List<Worktype> worktypeList = worktypeMapper.selectList(new QueryWrapper<Worktype>().lambda()
                .eq(Worktype::getInsuranceId,solutionsBase.getInsuranceId())
                .eq(Worktype::getIsdeleted,Constants.ZERO)
                .in(Worktype::getId,worktypeIdList));
        if(worktypeList==null ||worktypeIdList.size()==0){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,工种信息选择有误,请尝试刷新页面重试~" );
        }
        int num =0;
        for(Worktype type : worktypeList) {
            //基础版本
            SolutionWorktype w = new SolutionWorktype();
            w.setSolutionId(solutionsBase.getId());
            w.setIsdeleted(Constants.ZERO);
            w.setCreator(newModel.getCreator());
            w.setCreateDate(solutionsBase.getCreateDate());
            w.setWorktypeId(type.getId());
            w.setStatus(Constants.ZERO);
            w.setSortnum(num++);
            w.setType(Constants.ONE);
            solutionWorktypeJoinMapper.insert(w);
 
            //历史版本的工种信息
            SolutionWorktype newType = new SolutionWorktype();
            BeanUtils.copyProperties(w, newType);
            newType.setId(null);
            newType.setSolutionId(newModel.getId());
            solutionWorktypeJoinMapper.insert(newType);
        }
 
    }
 
 
    private void initCreateParam(SolutionsBase solutionsBase) {
        if(StringUtils.isBlank(solutionsBase.getName())||
            StringUtils.isBlank(solutionsBase.getCompanyName())
                || Objects.isNull(solutionsBase.getValidType())
                || Objects.isNull(solutionsBase.getCanAdd())
                || Objects.isNull(solutionsBase.getCanReduce())
                || Objects.isNull(solutionsBase.getCanChangeUnit())
                || Objects.isNull(solutionsBase.getDelOnlyReplace())
                || Objects.isNull(solutionsBase.getAddValidDays())
                || Objects.isNull(solutionsBase.getDelValidDays())
                || Objects.isNull(solutionsBase.getInsuranceId())
//                || Objects.isNull(solutionsBase.getRiskDelayStatus())
//                || Objects.isNull(solutionsBase.getRiskDelayTime())
//                || Objects.isNull(solutionsBase.getRiskDelayUnit())
//                || Objects.isNull(solutionsBase.getRiskNewUserStatus())
//                || Objects.isNull(solutionsBase.getRiskNewUserTime())
//                || Objects.isNull(solutionsBase.getRiskNewUserUnit())
 
                ||solutionsBase.getInsuranceId()==null
                || Constants.formatIntegerNum(solutionsBase.getMaxAge()) < 0
                ||Constants.formatIntegerNum(solutionsBase.getMinAge()) < 0
                ||Constants.formatIntegerNum( solutionsBase.getMinAge()) >Constants.formatIntegerNum(solutionsBase.getMaxAge())
                || com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(solutionsBase.getWorktypeIdList())
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        if(Constants.equalsInteger(solutionsBase.getValidType(),Constants.ZERO) && Objects.isNull(solutionsBase.getValidTypeNum())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
    }
 
 
    @Override
    public void saveSolutionsRisk(SolutionsBase solutionsBase){
        if( Objects.isNull(solutionsBase)
                || Objects.isNull(solutionsBase.getId())
                ||Objects.isNull(solutionsBase.getRiskDelayStatus())
                || Objects.isNull(solutionsBase.getRiskDelayTime())
                || Objects.isNull(solutionsBase.getRiskDelayUnit())
                || Objects.isNull(solutionsBase.getRiskNewUserStatus())
                || Objects.isNull(solutionsBase.getRiskNewUserTime())
                || Objects.isNull(solutionsBase.getRiskNewUserUnit())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        SolutionsBase model = solutionsBaseMapper.selectById(solutionsBase.getId());
        if(Objects.isNull(model)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        solutionsBaseMapper.update(new UpdateWrapper<SolutionsBase>().lambda()
                .set(SolutionsBase::getEditDate,new Date())
                .set(SolutionsBase::getRiskDelayStatus,solutionsBase.getRiskDelayStatus())
                .set(SolutionsBase::getRiskDelayTime,solutionsBase.getRiskDelayTime())
                .set(SolutionsBase::getRiskDelayUnit,solutionsBase.getRiskDelayUnit())
                .set(SolutionsBase::getRiskNewUserStatus,solutionsBase.getRiskNewUserStatus())
                .set(SolutionsBase::getRiskNewUserTime,solutionsBase.getRiskNewUserTime())
                .set(SolutionsBase::getRiskNewUserUnit,solutionsBase.getRiskNewUserUnit())
                .eq(SolutionsBase::getId,solutionsBase.getId())
        );
    }
 
    @Override
    public void deleteById(Integer id) {
        SolutionsBase solutionsBase = solutionsBaseMapper.selectById(id);
        if (!Objects.isNull(solutionsBase)){
            //查询主方案下所有启用版本数据中 是否存在 子方案
            if(solutionsMapper.selectCount(new QueryWrapper<Solutions>()
                    .lambda()
                    .eq(Solutions::getDataType,Constants.ZERO)
                    .eq(Solutions::getIsdeleted,Constants.ZERO)
                            .eq(Solutions::getParentId,id)
            )>Constants.ZERO){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"["+solutionsBase.getName()+"]下存在子方案,无法进行删除");
            };
        }
        solutionsBaseMapper.deleteById(id);
    }
 
    @Override
    public void delete(SolutionsBase solutionsBase) {
        UpdateWrapper<SolutionsBase> deleteWrapper = new UpdateWrapper<>(solutionsBase);
        solutionsBaseMapper.delete(deleteWrapper);
    }
 
    @Override
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        for (Integer id:ids) {
            this.deleteById(id);
        }
        solutionsBaseMapper.deleteBatchIds(ids);
    }
 
 
 
 
    @Override
    @Transactional(rollbackFor = {BusinessException.class,Exception.class})
    public void updateById(SolutionsBase solutionsBase) {
        LoginUserInfo user= (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
        SolutionsBase model = findById(solutionsBase.getId());
        if(model == null  || !Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)
                || !Constants.equalsInteger(model.getDataType(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY );
        }
        //数据有效性校验
        initCreateParam(solutionsBase);
        //查询是否已存在使用中的保单
        if(insuranceApplyMapper.selectCount(new QueryWrapper<InsuranceApply>().lambda()
                .apply(" solution_id in (  select s.ID from solutions s where s.PARENT_ID in ( select id from solutions_base where BASE_ID =  "+solutionsBase.getId()+"  or id = "+solutionsBase.getId()+" ) )" )
                .notIn(InsuranceApply::getStatus
                        ,Constants.InsuranceApplyStatus.PLATFORM_RETURN
                        ,Constants.InsuranceApplyStatus.CLOSE
                        ,Constants.InsuranceApplyStatus.WTB_CLOSED
                )
        )>Constants.ZERO){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"存在已投保的保单数据,无法进行修改");
        };
 
        if(solutionsBaseMapper.selectCount(new QueryWrapper<SolutionsBase>().lambda()
                .eq(SolutionsBase::getName,solutionsBase.getName())
                .eq(SolutionsBase::getIsdeleted,Constants.ZERO)
                .eq(SolutionsBase::getDataType,Constants.ZERO)
                .ne(SolutionsBase::getId,solutionsBase.getId())
        )>Constants.ZERO){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"保险主方案名称已存在");
        }
 
        solutionsBase.setEditor(user.getId());
        solutionsBase.setVersion(UUID.randomUUID().toString());
        solutionsBase.setEditDate(new Date());
 
        //2024年6月17日15:56:18 仅支持替换模式下,批增日期 等于 批减日期
        if(Constants.equalsInteger(solutionsBase.getDelOnlyReplace(),Constants.ONE)){
            solutionsBase.setAddValidDays(solutionsBase.getDelValidDays());
        }
        solutionsBaseMapper.updateById(solutionsBase);
 
        SolutionsBase oldVersion = solutionsBaseMapper.selectOne(new QueryWrapper<SolutionsBase>()
                .lambda()
                .eq(SolutionsBase::getBaseId,solutionsBase.getId())
                .eq(SolutionsBase::getDataType,Constants.TWO)
                .last("limit 1")
        );
 
        if(Objects.isNull(oldVersion)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到历史版本数据");
        }
 
        //如果修改,则产生一个新的历史版本 ~
        SolutionsBase newModel = new SolutionsBase();
        BeanUtils.copyProperties( findById(solutionsBase.getId()),newModel);
        newModel.setId(null);
        newModel.setVersion(solutionsBase.getVersion());
        newModel.setCreateDate(new Date());
        newModel.setBaseId(solutionsBase.getId());
        newModel.setDataType(Constants.TWO);
        solutionsBaseMapper.insert(newModel);
 
        //删除父方案下所有工种数据
        solutionWorktypeJoinMapper.delete(new UpdateWrapper<SolutionWorktype>()
                .lambda()
                .eq(SolutionWorktype::getSolutionId,solutionsBase.getId())
                .eq(SolutionWorktype::getType,Constants.ONE)
        );
        //删除父方案下所有子方案的工种数据
        solutionWorktypeJoinMapper.delete(new UpdateWrapper<SolutionWorktype>()
                .lambda()
                .eq(SolutionWorktype::getType,Constants.ZERO)
                .apply(" SOLUTION_ID in ( select s.id  from solutions s where s.PARENT_ID = "+solutionsBase.getId()+" ) ")
        );
 
        dealWorkTypeInsurance(solutionsBase,newModel,solutionsBase.getWorktypeIdList());
 
        solutionsBaseMapper.update(null,new UpdateWrapper<SolutionsBase>()
                .lambda()
                .ne(SolutionsBase::getId,newModel.getId())
                .eq(SolutionsBase::getBaseId,solutionsBase.getId())
                .eq(SolutionsBase::getDataType,Constants.TWO)
                .set(SolutionsBase::getDataType,Constants.ONE)
        );
 
        //更新company_solution 使用新版本的数据
        companySolutionMapper.update(null,
                new UpdateWrapper<CompanySolution>()
                        .lambda()
                        .eq(CompanySolution::getStatus,Constants.ZERO)
                        .set(CompanySolution::getSolutionId,newModel.getId())
                        .eq(CompanySolution::getSolutionBaseId,solutionsBase.getId())
        );
 
        //更新 du_solution 使用新版本的数据
        duSolutionMapper.update(null,
                new UpdateWrapper<DuSolution>()
                        .lambda()
                        .eq(DuSolution::getIsdeleted, Constants.ZERO)
                        .eq(DuSolution::getStatus, Constants.ONE)
                        .set(DuSolution::getSolutionId,newModel.getId())
                        .eq(DuSolution::getSolutionId,oldVersion.getId()));
 
    }
 
 
 
    @Override
    public void updateByIdInBatch(List<SolutionsBase> solutionsBases) {
        if (CollectionUtils.isEmpty(solutionsBases)) {
            return;
        }
        for (SolutionsBase solutionsBase: solutionsBases) {
            this.updateById(solutionsBase);
        }
    }
 
 
    @Override
    public void updateStatus(SolutionsBase solutionsBase){
        if(solutionsBase.getId() == null || solutionsBase.getStatus()==null || solutionsBase.getStatus()<0||solutionsBase.getStatus()>1){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST );
        }
        SolutionsBase model = findById(solutionsBase.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(),solutionsBase.getStatus())){
            //如果状态不发生改变,直接返回
            return;
        }
        LoginUserInfo user= (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        //同时更新基表和历史版本所有数据状态
        solutionsBaseMapper.update(null,new UpdateWrapper<SolutionsBase>()
                .lambda()
                .and(m -> m.eq(SolutionsBase::getId,model.getId()).or().eq(SolutionsBase::getBaseId,model.getId()))
                .eq(SolutionsBase::getIsdeleted,Constants.ZERO)
                .set(SolutionsBase::getEditDate,new Date())
                .set(SolutionsBase::getEditor,user.getId())
                .set(SolutionsBase::getStatus,solutionsBase.getStatus())
        );
 
        //如果是禁用,则修改方案子表的全部数据为禁用
        if(Constants.equalsInteger(solutionsBase.getStatus(),Constants.ONE)){
            solutionsMapper.update(null,new UpdateWrapper<Solutions>()
                    .lambda()
                    .set(Solutions::getStatus,solutionsBase.getStatus())
                    .set(Solutions::getEditDate,new Date())
                    .set(Solutions::getEditor,user.getId())
                    .eq(Solutions::getParentId,solutionsBase.getId())
            );
        }
 
    }
 
 
    @Override
    public SolutionsBase findById(Integer id) {
        MPJLambdaWrapper<SolutionsBase> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(SolutionsBase.class);
        queryWrapper.selectAs(Insurance::getName,SolutionsBase::getInsuranceName);
        queryWrapper.selectAs(Company::getName,SolutionsBase::getShopName);
        queryWrapper.leftJoin(Insurance.class,Insurance::getId,SolutionsBase::getInsuranceId);
        queryWrapper.leftJoin(Company.class,Company::getId,SolutionsBase::getShopId);
        queryWrapper.eq(SolutionsBase::getId,id);
        SolutionsBase model = solutionsBaseJoinMapper.selectJoinOne(SolutionsBase.class,queryWrapper);
        if(model == null  || !Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY );
        }
        MPJLambdaWrapper<SolutionWorktype> wrapper = new MPJLambdaWrapper<>();
        wrapper.selectAll(SolutionWorktype.class);
        wrapper.selectAs(Worktype::getName,SolutionWorktype::getWorktypeName);
        wrapper.leftJoin(Worktype.class,Worktype::getId,SolutionWorktype::getWorktypeId);
        wrapper.eq(SolutionWorktype::getSolutionId,id);
        wrapper.eq(SolutionWorktype::getType,Constants.ONE);
        wrapper.eq(SolutionWorktype::getIsdeleted,Constants.ZERO);
        wrapper.orderByAsc(SolutionWorktype::getSortnum);
        List<SolutionWorktype> worktypeList = solutionWorktypeJoinMapper.selectJoinList(SolutionWorktype.class,wrapper);
        model.setWorktypeList(worktypeList);
        return model;
    }
 
    @Override
    public SolutionsBase findOne(SolutionsBase solutionsBase) {
        QueryWrapper<SolutionsBase> wrapper = new QueryWrapper<>(solutionsBase);
        return solutionsBaseMapper.selectOne(wrapper);
    }
 
    @Override
    public List<SolutionsBase> findList(SolutionsBase solutionsBase) {
        QueryWrapper<SolutionsBase> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(SolutionsBase::getDataType,Constants.ZERO);
        wrapper.lambda().eq(SolutionsBase::getIsdeleted,Constants.ZERO);
        return solutionsBaseMapper.selectList(wrapper);
    }
 
    @Override
    public PageData<SolutionsBase> findPage(PageWrap<SolutionsBase> pageWrap) {
        IPage<SolutionsBase> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<SolutionsBase> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        queryWrapper.selectAll(SolutionsBase.class);
        queryWrapper.selectAs(Insurance::getName,SolutionsBase::getInsuranceName);
        queryWrapper.selectAs(Company::getName,SolutionsBase::getShopName);
        queryWrapper.leftJoin(Insurance.class,Insurance::getId,SolutionsBase::getInsuranceId);
        queryWrapper.leftJoin(Company.class,Company::getId,SolutionsBase::getShopId);
        //只查询未删除的数据
        queryWrapper.eq(SolutionsBase::getIsdeleted,Constants.ZERO);
        //只查询基础版本数据
        queryWrapper.eq(SolutionsBase::getDataType,Constants.ZERO);
        if (pageWrap.getModel().getName() != null) {
            queryWrapper.like(SolutionsBase::getName, pageWrap.getModel().getName());
        }
 
        for(PageWrap.SortData sortData: pageWrap.getSorts()) {
            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
                queryWrapper.orderByDesc(sortData.getProperty());
            } else {
                queryWrapper.orderByAsc(sortData.getProperty());
            }
        }
        IPage<SolutionsBase> iPageData = solutionsBaseJoinMapper.selectJoinPage(page,SolutionsBase.class,queryWrapper);
        return PageData.from(iPageData);
    }
 
    @Override
    public long count(SolutionsBase solutionsBase) {
        QueryWrapper<SolutionsBase> wrapper = new QueryWrapper<>(solutionsBase);
        return solutionsBaseMapper.selectCount(wrapper);
    }
 
 
    @Override
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
    public void createSolutionBase(Integer solutionId){
        List<Solutions> solutionsList = solutionsMapper.selectList(new QueryWrapper<Solutions>().lambda()
                    .eq(Objects.nonNull(solutionId),Solutions::getId,solutionId)
                .isNull(Solutions::getParentId).eq(Solutions::getDataType,Constants.ZERO).eq(Solutions::getIsdeleted,Constants.ZERO));
        for (Solutions solutions: solutionsList) {
            SolutionsBase solutionsBase = new SolutionsBase();
            solutionsBase.setCreator(solutions.getCreator());
            solutionsBase.setCreateDate(new Date());
            solutionsBase.setIsdeleted(Constants.ZERO);
            solutionsBase.setName(solutions.getName());
            solutionsBase.setStatus(solutions.getStatus());
            solutionsBase.setSortnum(Constants.ZERO);
            solutionsBase.setInsuranceId(solutions.getInsuranceId());
            solutionsBase.setValidType(solutions.getValidType());
            solutionsBase.setMinAge(solutions.getMinAge());
            solutionsBase.setMaxAge(solutions.getMaxAge());
            solutionsBase.setSingleWorktype(solutions.getSingleWorktype());
            solutionsBase.setSpecialInfo(solutions.getSpecialInfo());
            solutionsBase.setSpecialAgreement(solutions.getSpecialAgreement());
            solutionsBase.setOrtherInfo(solutions.getOrtherInfo());
            solutionsBase.setDataType(Constants.ZERO);
            solutionsBase.setValidTypeNum(solutions.getValidTypeNum());
            solutionsBase.setShopId(solutions.getShopId());
            solutionsBase.setAddValidDays(solutions.getAddValidDays());
            solutionsBase.setDelValidDays(solutions.getDelValidDays());
            solutionsBase.setCanAdd(solutions.getCanAdd());
            solutionsBase.setCanReduce(solutions.getCanReduce());
            solutionsBase.setCanChangeUnit(solutions.getCanChangeUnit());
            solutionsBase.setDelOnlyReplace(solutions.getDelOnlyReplace());
            solutionsBase.setCompanyName(solutions.getCompanyName());
            solutionsBase.setCompanyName(solutions.getCompanyName());
            solutionsBase.setCorrectWarnTime("18:30");
            solutionsBaseMapper.insert(solutionsBase);
 
 
            //如果有工种,则产生一个新的有效历史版本 ~
            SolutionsBase newModel = new SolutionsBase();
            BeanUtils.copyProperties(solutionsBase,newModel);
            newModel.setId(null);
            newModel.setBaseId(solutionsBase.getId());
            newModel.setDataType(Constants.TWO);
            solutionsBaseMapper.insert(newModel);
 
            List<SolutionWorktype> solutionWorktypeList = solutionWorktypeJoinMapper.selectList(new QueryWrapper<SolutionWorktype>().lambda().eq(SolutionWorktype::getType,Constants.ZERO).eq(SolutionWorktype::getSolutionId,solutions.getId()));
 
            Integer num = 1;
            for(SolutionWorktype solutionWorktype : solutionWorktypeList) {
                //基础版本
                SolutionWorktype w = new SolutionWorktype();
                w.setSolutionId(solutionsBase.getId());
                w.setIsdeleted(Constants.ZERO);
                w.setCreator(newModel.getCreator());
                w.setCreateDate(solutionsBase.getCreateDate());
                w.setStatus(Constants.ZERO);
                w.setSortnum(num++);
                w.setWorktypeId(solutionWorktype.getWorktypeId());
                w.setType(Constants.ONE);
                solutionWorktypeJoinMapper.insert(w);
 
                //历史版本的工种信息
                SolutionWorktype newType = new SolutionWorktype();
                BeanUtils.copyProperties(w, newType);
                newType.setSolutionId(newModel.getId());
                solutionWorktypeJoinMapper.insert(newType);
            }
 
            solutionsMapper.update(null,new UpdateWrapper<Solutions>().lambda().set(Solutions::getParentId,solutionsBase.getId())
                    .and(i->i.eq(Solutions::getId,solutions.getId()).or().eq(Solutions::getBaseId,solutions.getId()))
            );
        }
    }
 
 
 
}