ludc
2025-01-16 5203081b68e3a8dc139d1807b2f8774e4a00a82a
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
package com.vci.web.service.impl;
 
import com.vci.corba.common.PLException;
import com.vci.corba.common.data.UserEntityInfo;
import com.vci.corba.framework.data.PasswordStrategyInfo;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.dto.SmPasswordStrategyDTO;
import com.vci.model.SmPasswordStrategyDO;
import com.vci.model.SmPasswordStrategyForPlatform1;
import com.vci.omd.utils.ObjectTool;
import com.vci.pagemodel.SmPasswordStrategyVO;
import com.vci.starter.web.enumpck.VciFieldTypeEnum;
import com.vci.starter.web.util.BeanUtilForVCI;
import com.vci.web.service.SmUserQueryServiceI;
import com.vci.starter.web.constant.QueryOptionConstant;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.pagemodel.DataGrid;
import com.vci.starter.web.pagemodel.PageHelper;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.starter.web.util.WebThreadLocalUtil;
import com.vci.starter.web.wrapper.VciQueryWrapperForDO;
import com.vci.web.enumpck.CombinationEnum;
import com.vci.web.service.SmPwdStrategyQueryServiceI;
import com.vci.web.service.WebBoServiceI;
import com.vci.starter.web.util.Lcm.Func;
import com.vci.web.util.PlatformClientUtil;
import com.vci.web.util.WebUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
 
import static com.vci.constant.FrameWorkBusLangCodeConstant.DATA_OID_NOT_EXIST;
 
/**
 * 密码策略查询服务
 * @author ludc
 * @date 2024/6/24 16:33
 */
@Service
public class SmPwdStrategyQueryServiceImpl implements SmPwdStrategyQueryServiceI {
 
    /**
     * 业务数据服务
     */
    @Autowired
    private WebBoServiceI boService;
 
    /**
     * 用户查询服务
     */
    @Autowired
    private SmUserQueryServiceI smUserQueryService;
 
    /**
     * 平台调用客户端
     */
    @Autowired
    private PlatformClientUtil platformClientUtil;
 
    /**
     * 日志
     */
    private Logger logger = LoggerFactory.getLogger(getClass());
 
    /**
     * 获取默认密码策略
     * @return
     */
    public SmPasswordStrategyVO getPasswordStrategyVOByDefault(){
        //获取默认的
        VciQueryWrapperForDO queryWrapperForDO = new VciQueryWrapperForDO(null, SmPasswordStrategyDO.class);
        queryWrapperForDO.eq("plisdefault","1");
        List<BusinessObject> cboList = boService.queryBySql(queryWrapperForDO.getSelectFieldSql() + " from plpasswordstrategy " +
                queryWrapperForDO.getTableNick() + queryWrapperForDO.getLinkTableSql() +
                (StringUtils.isBlank(queryWrapperForDO.getWhereSql()) ? "" : (" where " + queryWrapperForDO.getWhereSql())), null);
        if(!CollectionUtils.isEmpty(cboList)){
            SmPasswordStrategyDO passwordStrategyDO = new SmPasswordStrategyDO();
            WebUtil.copyValueToObjectFromCbos(cboList.get(0),passwordStrategyDO);
            return pwdStrategyDO2VO(passwordStrategyDO);
        }
        return null;
    }
 
    /**
     * 密码策略分页查询
     * @param conditionMap
     * @param pageHelper
     * @return
     */
    @Override
    public DataGrid<SmPasswordStrategyVO> refDataGrid(Map<String, String> conditionMap, PageHelper pageHelper) throws Exception {
        if(pageHelper == null){
            pageHelper = new PageHelper(-1);
        }
        pageHelper.addDefaultAsc("pname");
        VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(conditionMap, SmPasswordStrategyForPlatform1.class,pageHelper);
        //platformClientUtil.getFrameworkService().fetchAllPasswordStrategy();
        List<SmPasswordStrategyForPlatform1> smPasswordStrategyForPlatform1s = boService.selectByQueryWrapper(queryWrapper, SmPasswordStrategyForPlatform1.class);
        DataGrid<SmPasswordStrategyVO> dataGrid = new DataGrid<>();
        if(!CollectionUtils.isEmpty(smPasswordStrategyForPlatform1s)){
            dataGrid.setData(pltPwdStrategy2SmPwdStrategyVOs(smPasswordStrategyForPlatform1s));
            dataGrid.setTotal(boService.countByQueryWrapper(queryWrapper,SmPasswordStrategyForPlatform1.class));
        }
        return dataGrid;
    }
 
    /**
     * 查询密码安全策略,下拉使用的接口
     * @param conditionMap
     * @return key为密码策略name,value为密码策略的oid
     * @throws VciBaseException
     */
    @Override
    public List<Map<String,String>> selectPwdStrategyMap(Map<String, String> conditionMap) throws PLException {
        PageHelper pageHelper = new PageHelper(-1);
        pageHelper.addDefaultAsc("plname");
        PasswordStrategyInfo[] passwordStrategyInfos = platformClientUtil.getFrameworkService().fetchAllPasswordStrategy();
        List<Map<String,String>> mapArrayList = new ArrayList<>();
        if(Func.isEmpty(passwordStrategyInfos)){
            return mapArrayList;
        }
        Arrays.stream(passwordStrategyInfos).forEach(item->{
            Map<String, String> map = new HashMap<>();
            map.put("name",item.name);
            map.put("id",item.id);
            mapArrayList.add(map);
        });
        return mapArrayList;
    }
 
    /**
     * 原平台密码策略转SmPasswordStrategyVOS对象
     * @param smPasswordStrategyForPlatform1s 原平台的密码策略
     * @return
     */
    private List<SmPasswordStrategyVO> pltPwdStrategy2SmPwdStrategyVOs(List<SmPasswordStrategyForPlatform1> smPasswordStrategyForPlatform1s) throws Exception{
        List<SmPasswordStrategyVO> smPasswordStrategyVOList = new ArrayList<>();
        if(!CollectionUtils.isEmpty(smPasswordStrategyForPlatform1s)){
            smPasswordStrategyForPlatform1s.stream().forEach(s -> {
                try {
                    smPasswordStrategyVOList.add(pltPwdStrategy2SmPwdStrategyVO(s));
                } catch (Exception e) {
                    e.printStackTrace();
                    String exceptionMessage = "Platform1对象转VO对象时出现错误,原因:"+VciBaseUtil.getExceptionMessage(e);
                    logger.error(exceptionMessage);
                    throw new VciBaseException(exceptionMessage);
                }
            });
        }
        return smPasswordStrategyVOList;
    }
 
    /**
     * 原平台密码策略转SmPasswordStrategyVO对象
     * @param strategyForPlatform1 原平台的密码策略
     * @return 新的密码策略对象
     */
    private SmPasswordStrategyVO pltPwdStrategy2SmPwdStrategyVO(SmPasswordStrategyForPlatform1 strategyForPlatform1) throws PLException, ParseException {
        SmPasswordStrategyVO strategyVO = new SmPasswordStrategyVO();
        strategyVO.setOid(strategyForPlatform1.getPluid());
        strategyVO.setId("");
        strategyVO.setName(strategyForPlatform1.getPname());
        strategyVO.setMaxLength(strategyForPlatform1.getPlmaxlength());
        strategyVO.setMinLength(strategyForPlatform1.getPlength());
        strategyVO.setValidDay(strategyForPlatform1.getPoverdueday());
        strategyVO.setRemindDay(strategyForPlatform1.getPremindday());
        strategyVO.setRetryTime(strategyForPlatform1.getPretrytime());
        strategyVO.setLockTime(strategyForPlatform1.getPlocktime());
        strategyVO.setDefaultFlag(strategyForPlatform1.getPlisdefault() == 1);
        strategyVO.setDescription(strategyForPlatform1.getPldesc());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        if(Func.isNotEmpty(strategyForPlatform1.getPlcreatetime())){
            strategyVO.setCreateTime(sdf.parse(strategyForPlatform1.getPlcreatetime()));
        }
        strategyVO.setCreator(strategyForPlatform1.getPlcreateuser());
        if(Func.isNotEmpty(strategyForPlatform1.getPlupdatetime())){
            strategyVO.setLastModifyTime(sdf.parse(strategyForPlatform1.getPlupdatetime()));
        }
        strategyVO.setLastModifier(strategyForPlatform1.getPlupdateuser());
        strategyVO.setLicensors(strategyForPlatform1.getPllicensors());
        strategyVO.setRequireCharCount(strategyForPlatform1.getPlrequiredtype());
        //处理密码策略的组合方式
        Integer plchartypes = strategyForPlatform1.getPlchartypes();
        if(Func.isNotEmpty(plchartypes)){
            String combinations = plchartypes2Combinations(plchartypes);
            strategyVO.setRequireCharType(combinations);
            strategyVO.setRequireCharTypeText(CombinationEnum.getCombinationText(combinations));
        }
        return strategyVO;
    }
 
    /**
     *  plchartypes转换为Combinations(英文)
     * @param plchartypes
     * @return 进制数转换为组合方式的因为枚举多个之间用都好间隔
     */
    private String plchartypes2Combinations(Integer plchartypes){
        StringBuilder sb = new StringBuilder();
        if ((plchartypes & 0x01) == 0x01)
            sb.append("number,");
        if ((plchartypes & 0x02) == 0x02)
            sb.append("lower,");
        if ((plchartypes & 0x04) == 0x04)
            sb.append("upper,");
        if ((plchartypes & 0x08) == 0x08)
            sb.append("symbol,");
        return sb.deleteCharAt(sb.length() - 1).toString();
    }
 
    /**
     *  plchartypes转换为Combinations(英文)
     * @param combinations
     * @return 组合方式转换为实际要存储的整形数
     */
    private short combinations2Plchartypes(String combinations) {
        short plchartypes = 0;
        String[] combinationsArray = combinations.split(",");
        for (String type : combinationsArray) {
            switch (type) {
                case "number":
                    plchartypes |= 0x01;
                    break;
                case "lower":
                    plchartypes |= 0x02;
                    break;
                case "upper":
                    plchartypes |= 0x04;
                    break;
                case "symbol":
                    plchartypes |= 0x08;
                    break;
            }
        }
 
        return plchartypes;
    }
 
    /**
     * 保存用户关联密码策略
     * @param userIds
     * @param passwordStrategId
     * @return
     */
    @Override
    public boolean saveUserPasswordStrateg(String[] userIds, String passwordStrategId) throws PLException {
        VciBaseUtil.alertNotNull(userIds,"用户主键",passwordStrategId,"密码安全策略主键");
        return platformClientUtil.getFrameworkService().saveUserPasswordStrateg(
                userIds,
                passwordStrategId,
                new UserEntityInfo(WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId(),null)
        );
    }
 
    /**
     * 密码策略校验:是否合规校验
     * @param strategy
     */
    private void checkPwdStrategy(SmPasswordStrategyDTO strategy){
        if(strategy.getRequireCharCount() > strategy.getCombinations().split(",").length){
            throw new VciBaseException("必填种类不能大于所选择的密码组合方式的个数!");
        }
        if(strategy.getRequireCharCount() <= 0){
            throw new VciBaseException("必填种类不能小于等于0!");
        }
        if(strategy.getMaxLength() < strategy.getMinLength()){
            throw new VciBaseException("密码最大长度不能小于最小长度!");
        }
        if(Func.isNotEmpty(strategy.getRequireCharCount()) &&
                (strategy.getMinLength() < strategy.getRequireCharCount() ||
                strategy.getMaxLength() < strategy.getRequireCharCount())
        ){
            throw new VciBaseException("密码最小长度不能小于必填种类的值!");
        }
        if(strategy.getValidDay() <= strategy.getRemindDay()){
            throw new VciBaseException("过期时间不能小于提醒时间!");
        }
        //判断前端是否未提交,是否默认字段
        if(Func.isEmpty(strategy.getDefaultFlag())){
            strategy.setDefaultFlag("false");
        }
    }
 
    /**
     * dto对象转换为info对象
     * @param dto
     * @return
     */
    private PasswordStrategyInfo changePasswordStrategyDTO2Info(SmPasswordStrategyDTO dto){
        PasswordStrategyInfo info = new PasswordStrategyInfo();
        info.id = dto.getOid() == null ? "" : dto.getOid();
        info.name = dto.getName();
        info.passwordLen = dto.getMinLength();
        info.passwordMaxLen = dto.getMaxLength();
        info.charTypes = dto.getRequireCharType();
        info.requiredType = dto.getRequireCharCount();
        //逾期日=有效天数
        info.overdueDay = dto.getValidDay();
        info.remideDay = dto.getRemindDay();
        info.retryTime = dto.getRetryTime();
        info.lockTime = dto.getLockTime();
        if(dto.getDefaultFlag().equals("1") || dto.getDefaultFlag().equals("true")){
            info.isDefault = true;
        }else {
            info.isDefault = false;
        }
        info.desc = dto.getDescription() == null ? "" : dto.getDescription();
        info.createTime = dto.getCreateTime() == null ? System.currentTimeMillis() : dto.getCreateTime().getTime();
        info.createUser = dto.getCreator() == null ? "" : dto.getCreator();
        info.updateTime = System.currentTimeMillis();
        info.updateUser = dto.getLastModifier() == null ? "" : dto.getLastModifier();
        return info;
    }
 
    /**
     * 根据map条件查询密码策略
     * @param conditionMap
     * @return
     */
    private List<SmPasswordStrategyVO> getPwdStrategyByCondition(Map<String,String> conditionMap) throws Exception {
        if(Func.isEmpty(conditionMap)){
            conditionMap = new HashMap();
        }
        VciQueryWrapperForDO queryWrapper = new VciQueryWrapperForDO(conditionMap, SmPasswordStrategyForPlatform1.class);
        List<SmPasswordStrategyForPlatform1> roleForPlatform1s = boService.selectByQueryWrapper(queryWrapper, SmPasswordStrategyForPlatform1.class);
        if(Func.isEmpty(roleForPlatform1s)){
            return null;
        }
        return pltPwdStrategy2SmPwdStrategyVOs(roleForPlatform1s);
    }
 
    /**
     * 新增密码策略
     * @param spsDto
     * @return
     */
    @Override
    public boolean addPasswordStrateg(SmPasswordStrategyDTO spsDto) throws Exception {
        VciBaseUtil.alertNotNull(
                spsDto,"新增的密码策略对象",
                spsDto.getName(),"策略名称",
                spsDto.getMinLength(),"密码最小长度",
                spsDto.getMaxLength(),"密码最大长度",
                spsDto.getCombinations(),"组合方式种类",
                spsDto.getRequireCharCount(),"必填种类",
                spsDto.getValidDay(),"过期时间",
                spsDto.getRemindDay(),"提醒时间",
                spsDto.getRetryTime(),"重试次数",
                spsDto.getLockTime(),"锁定时间"
        );
        //密码策略合规校验,不合规会抛出错误
        this.checkPwdStrategy(spsDto);
        //根据策略名称查重
        Map<String, String> conditionMap = new HashMap<>();
        conditionMap.put("pname",spsDto.getName());
        List<SmPasswordStrategyVO> dbVoList = this.getPwdStrategyByCondition(conditionMap);
        if(Func.isNotEmpty(dbVoList)){
            throw new VciBaseException("策略名称已经存在,请进行修改!");
        }
        //获取当前用户账号信息:平台保存方法中会将userEntityInfo中的用户信息用作当前策略的创建人和修改人
        String userId = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId();
        UserEntityInfo userEntityInfo = new UserEntityInfo(userId,null);
        //组合方式转换为存储值
        spsDto.setRequireCharType(combinations2Plchartypes(spsDto.getCombinations()));
        spsDto.setOid(VciBaseUtil.getPk().toUpperCase(Locale.ROOT));
        spsDto.setCreator(userId);
        spsDto.setLastModifier(userId);
        //转换为存储用对象
        PasswordStrategyInfo passwordStrategyInfo = changePasswordStrategyDTO2Info(spsDto);
        //当设置为默认策略时,平台保存方法会自动处理掉已存在的默认策略,以保证只有一条默认策略
        return platformClientUtil.getFrameworkService().savePasswordStrategy(passwordStrategyInfo, userEntityInfo);
    }
 
    /**
     * 修改密码策略
     * @param spsDto
     * @return
     */
    @Override
    public boolean updatePasswordStrateg(SmPasswordStrategyDTO spsDto) throws Exception {
        VciBaseUtil.alertNotNull(
                spsDto,"新增的密码策略对象",
                spsDto.getOid(),"策略主键",
                spsDto.getName(),"策略名称",
                spsDto.getMinLength(),"密码最小长度",
                spsDto.getMaxLength(),"密码最大长度",
                spsDto.getCombinations(),"组合方式种类",
                spsDto.getRequireCharCount(),"必填种类",
                spsDto.getValidDay(),"过期时间",
                spsDto.getRemindDay(),"提醒时间",
                spsDto.getRetryTime(),"重试次数",
                spsDto.getLockTime(),"锁定时间"
        );
        //密码策略合规校验,不合规会抛出错误
        this.checkPwdStrategy(spsDto);
        //查询修改的策略是否存在
        Map<String, String> conditionMap = new HashMap<>();
        conditionMap.put("pluid",spsDto.getOid());
        List<SmPasswordStrategyVO> dbVoList = this.getPwdStrategyByCondition(conditionMap);
        if(Func.isEmpty(dbVoList)){
            throw new VciBaseException("当前修改的密码策略在系统中不存在,请刷新后重试!");
        }
        //获取当前用户账号信息
        String userId = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId();
        UserEntityInfo userEntityInfo = new UserEntityInfo(userId,null);
        //根据策略名称查重
        conditionMap.clear();
        conditionMap.put("pname",spsDto.getName());
        conditionMap.put("pluid", QueryOptionConstant.NOTEQUAL + spsDto.getOid());
        List<SmPasswordStrategyVO> repeatVoList = this.getPwdStrategyByCondition(conditionMap);
        if(Func.isNotEmpty(repeatVoList)){
            throw new VciBaseException("策略名称已经存在,请进行修改!");
        }
        SmPasswordStrategyVO smPasswordStrategyVO = dbVoList.get(0);
        spsDto.setCreateTime(smPasswordStrategyVO.getCreateTime());
        spsDto.setCreator(smPasswordStrategyVO.getCreator());
        spsDto.setLastModifier(userId);
        //组合方式转换为存储值
        spsDto.setRequireCharType(combinations2Plchartypes(spsDto.getCombinations()));
        PasswordStrategyInfo passwordStrategyInfo = changePasswordStrategyDTO2Info(spsDto);
 
        return platformClientUtil.getFrameworkService().editPasswordStrategy(passwordStrategyInfo,userEntityInfo);
    }
 
    /**
     *  删除密码策略
     * @param pwdIds
     * @return
     */
    @Override
    public boolean delPasswordStrateg(String[] pwdIds) throws PLException {
        VciBaseUtil.alertNotNull(pwdIds,"要删除的密码策略主键");
        //TODO: 应该是不具备连带删除的功能,策略删除后用户关联的无用策略信息还在,考虑后期是否需要做,数据量不大可以不做连带删除
        return platformClientUtil.getFrameworkService().deletePasswordStrategy(
                pwdIds,
                new UserEntityInfo("developer"/*WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId()*/, null)
        );
    }
 
    /**
     * 根据主键查询密码策略map对象
     * @param oidList
     * @return key为密码策略主键 value为密码策略
     */
    @Override
    public Map<String, SmPasswordStrategyVO> mapPasswordStrategyVOMapByOid(Collection<String> oidList) {
        VciQueryWrapperForDO queryWrapperForDO = new VciQueryWrapperForDO(null, SmPasswordStrategyDO.class);
        queryWrapperForDO.in("oid",oidList.stream().collect(Collectors.joining(",")));
        List<BusinessObject> cboList = boService.queryBySql(queryWrapperForDO.getSelectFieldSql() + " from plpasswordstrategy " +
                queryWrapperForDO.getTableNick() + queryWrapperForDO.getLinkTableSql() +
                (StringUtils.isBlank(queryWrapperForDO.getWhereSql()) ? "" : (" where " + queryWrapperForDO.getWhereSql())), null);
        Map<String,SmPasswordStrategyVO> smPasswordStrategyVOMap = new HashMap<>();
        if(Func.isEmpty(cboList)){
            return new HashMap<>();
        }
        cboList.stream().forEach(item->{
            SmPasswordStrategyDO passwordStrategyDO = new SmPasswordStrategyDO();
            WebUtil.copyValueToObjectFromCbos(item,passwordStrategyDO);
            SmPasswordStrategyVO passwordStrategyVO = new SmPasswordStrategyVO();
            BeanUtilForVCI.convert(passwordStrategyDO,passwordStrategyVO);
            smPasswordStrategyVOMap.put(passwordStrategyVO.getOid(),passwordStrategyVO);
        });
        return smPasswordStrategyVOMap;
    }
 
    /**
     * 使用主键获取密码策略
     * @param oid 主键
     * @return 密码策略显示对象
     */
    public SmPasswordStrategyVO getPasswordStrategyVOByOid(String oid){
        VciQueryWrapperForDO queryWrapperForDO = new VciQueryWrapperForDO(null, SmPasswordStrategyDO.class);
        queryWrapperForDO.eq("oid",oid.trim());
        List<BusinessObject> cboList = boService.queryBySql(queryWrapperForDO.getSelectFieldSql() + " from plpasswordstrategy " +
                queryWrapperForDO.getTableNick() + queryWrapperForDO.getLinkTableSql() +
                (StringUtils.isBlank(queryWrapperForDO.getWhereSql()) ? "" : (" where " + queryWrapperForDO.getWhereSql())), null);
        if(!CollectionUtils.isEmpty(cboList)){
            SmPasswordStrategyDO passwordStrategyDO = new SmPasswordStrategyDO();
            WebUtil.copyValueToObjectFromCbos(cboList.get(0),passwordStrategyDO);
            SmPasswordStrategyVO passwordStrategyVO = new SmPasswordStrategyVO();
            BeanUtilForVCI.convert(passwordStrategyDO,passwordStrategyVO);
            return passwordStrategyVO;
        }else{
            //获取默认的
            queryWrapperForDO = new VciQueryWrapperForDO(null, SmPasswordStrategyDO.class);
            queryWrapperForDO.eq("plisdefault","1");
            cboList = boService.queryBySql(queryWrapperForDO.getSelectFieldSql() + " from plpasswordstrategy " +
                    queryWrapperForDO.getTableNick() + queryWrapperForDO.getLinkTableSql() +
                    (StringUtils.isBlank(queryWrapperForDO.getWhereSql()) ? "" : (" where " + queryWrapperForDO.getWhereSql())), null);
            if(!CollectionUtils.isEmpty(cboList)){
                SmPasswordStrategyDO passwordStrategyDO = new SmPasswordStrategyDO();
                WebUtil.copyValueToObjectFromCbos(cboList.get(0),passwordStrategyDO);
                return pwdStrategyDO2VO(passwordStrategyDO);
            }
        }
        return null;
    }
 
    /**
     * 多条密码策略do对象转vo对象
     * @param smPasswordStrategyDOList
     * @return
     */
    private List<SmPasswordStrategyVO> pwdStrategyDO2VOS(List<SmPasswordStrategyDO> smPasswordStrategyDOList){
        List<SmPasswordStrategyVO> smPasswordStrategyVOList = new ArrayList<>();
        if(Func.isEmpty(smPasswordStrategyDOList)) {
            return smPasswordStrategyVOList;
        }
        smPasswordStrategyDOList.stream().forEach(item->{
            smPasswordStrategyVOList.add(pwdStrategyDO2VO(item));
        });
        return smPasswordStrategyVOList;
    }
 
    /**
     * 密码策略do对象转vo对象
     * @param smPasswordStrategyDO
     * @return
     */
    private SmPasswordStrategyVO pwdStrategyDO2VO(SmPasswordStrategyDO smPasswordStrategyDO){
        SmPasswordStrategyVO passwordStrategyVO = new SmPasswordStrategyVO();
        BeanUtilForVCI.convert(smPasswordStrategyDO,passwordStrategyVO);
        return passwordStrategyVO;
    }
 
    /**
     * 根据用户的主键,获取用户的密码安全策略
     * @param userOid 用户的主键
     * @return 密码安全策略的显示对象,如果不存在则会返回Null
     * @throws VciBaseException 参数为空或者数据库查询出错的时候会抛出异常
     */
    @Override
    public SmPasswordStrategyVO getPasswordStrategyVOByUserOid(String userOid) throws PLException {
        WebUtil.alertNotNull(userOid,"用户的主键");
        if(!smUserQueryService.checkUserExist(null,userOid)){
            throw new VciBaseException(DATA_OID_NOT_EXIST);
        }
        String sql = "select plpasswordstrategyuid,pluseruid from pluserpasswordstrategy where pluseruid = '"+ userOid +"'";
        List<BusinessObject> cbos = boService.queryBySql(sql, null);
        if(Func.isNotEmpty(cbos)){
            return getPasswordStrategyVOByOid(ObjectTool.getNewBOAttributeValue(cbos.get(0), "plpasswordstrategyuid"));
        }
        return null;
    }
 
    /**
     * 根据多条用户主键,获取用户的密码安全策略
     * @param userOids
     * @return
     * @throws PLException
     */
    @Override
    public List<SmPasswordStrategyVO> listSmPasswordStrategyVOByUserOids(Collection<String> userOids) {
        WebUtil.alertNotNull(userOids,"用户的主键");
        //先查关联表
        List<String> userPwdStrategyList = new ArrayList<>();
        WebUtil.switchCollectionForOracleIn(userOids).stream().forEach(userOidSplit->{
            //查关联表sql
            String sql = "select plpasswordstrategyuid,pluseruid from pluserpasswordstrategy where pluseruid in (" + WebUtil.toInSql(userOidSplit.toArray(new String[0])) + ")";
            List<BusinessObject> cbos = boService.queryBySql(sql, null);
            cbos.stream().forEach(cbo->{
                userPwdStrategyList.add(ObjectTool.getNewBOAttributeValue(cbo,"plpasswordstrategyuid"));
            });
        });
        return listSmPasswordStrategyVOByOids(userPwdStrategyList);
    }
 
    /**
     * 根据用户主键查询密码策略关联表中的密码策略主键
     * @param userOids
     * @return key为用户oid:value为密码策略oid
     */
    private Map<String,String> mapUserPwdStrategy(Collection<String> userOids){
        Map<String,String> userPwdStrategyMap = new HashMap<>();
        WebUtil.switchCollectionForOracleIn(userOids).stream().forEach(userOidSplit->{
            //查关联表sql
            String sql = "select plpasswordstrategyuid,pluseruid from pluserpasswordstrategy where pluseruid in (" + WebUtil.toInSql(userOidSplit.toArray(new String[0])) + ")";
            List<BusinessObject> cbos = boService.queryBySql(sql, null);
            cbos.stream().forEach(cbo->{
                String pluseruid = ObjectTool.getNewBOAttributeValue(cbo, "pluseruid");
                String plpasswordstrategyuid = ObjectTool.getNewBOAttributeValue(cbo, "plpasswordstrategyuid");
                userPwdStrategyMap.put(pluseruid,plpasswordstrategyuid);
            });
        });
        return userPwdStrategyMap;
    }
 
    /**
     * 根据主键,批量获取密码安全策略主键
     * @param oids
     * @return
     * @throws PLException
     */
    @Override
    public List<SmPasswordStrategyVO> listSmPasswordStrategyVOByOids(Collection<String> oids) {
        VciQueryWrapperForDO queryWrapperForDO = new VciQueryWrapperForDO(null, SmPasswordStrategyDO.class);
        queryWrapperForDO.in("oid",oids.stream().collect(Collectors.joining(",")));
        List<BusinessObject> cboList = boService.queryBySql(queryWrapperForDO.getSelectFieldSql() + " from plpasswordstrategy " +
                queryWrapperForDO.getTableNick() + queryWrapperForDO.getLinkTableSql() +
                (StringUtils.isBlank(queryWrapperForDO.getWhereSql()) ? "" : (" where " + queryWrapperForDO.getWhereSql())), null);
        List<SmPasswordStrategyVO> smPasswordStrategyVOList = new ArrayList<>();
        if(Func.isEmpty(cboList)){
            return smPasswordStrategyVOList;
        }
        cboList.stream().forEach(item->{
            SmPasswordStrategyDO passwordStrategyDO = new SmPasswordStrategyDO();
            WebUtil.copyValueToObjectFromCbos(item,passwordStrategyDO);
            SmPasswordStrategyVO passwordStrategyVO = new SmPasswordStrategyVO();
            BeanUtilForVCI.convert(passwordStrategyDO,passwordStrategyVO);
            smPasswordStrategyVOList.add(passwordStrategyVO);
        });
        return smPasswordStrategyVOList;
    }
 
    /**
     * 批量根据用户的主键来获取密码策略
     * @param userOidCollection 用户主键集合
     * @return 密码策略的显示对象,key是用户主键,value是这个用户关联的密码策略
     */
    @Override
    public Map<String, SmPasswordStrategyVO> batchSmPwdStrategyByUserOids(Collection<String> userOidCollection) {
        if(CollectionUtils.isEmpty(userOidCollection)){
            return new HashMap<>();
        }
        Map<String,SmPasswordStrategyVO> smPasswordStrategyVOMap = new HashMap<>();
        Map<String,String> userPasswordStrategyVOMap = new HashMap<>();
 
        Map<String/*用户id*/, SmPasswordStrategyVO/*密码策略*/> returnMap = new HashMap<>();
        WebUtil.switchCollectionForOracleIn(userOidCollection).stream().forEach(userOids->{
            //查询密码策略关联信息,key为用户oid:value为密码策略oid
            Map<String, String> userPwdStrategyMap = mapUserPwdStrategy(userOids);
            userPasswordStrategyVOMap.putAll(userPwdStrategyMap);
            //查询密码策略,key为密码策略主键:value为密码策略
            smPasswordStrategyVOMap.putAll(mapPasswordStrategyVOMapByOid(userPwdStrategyMap.values()));
        });
        //查询默认的密码策略
        SmPasswordStrategyVO passwordStrategyVOByDefault = getPasswordStrategyVOByDefault();
        //循环用户id,查询是否有符合条件的oid
        userOidCollection.stream().forEach(oid->{
            SmPasswordStrategyVO smPasswordStrategyVO;
            //通过用户oid没获取到密码策略oid,说明没有给当前用户设置策略,直接返默认的密码策略
            String pwdStrategyId = userPasswordStrategyVOMap.get(oid);
            if(Func.isNotBlank(pwdStrategyId)){
                //通过密码策略oid去map中取密码策略
                smPasswordStrategyVO = smPasswordStrategyVOMap.get(pwdStrategyId);
            }else {
                smPasswordStrategyVO = passwordStrategyVOByDefault;
            }
            returnMap.put(oid,smPasswordStrategyVO);
        });
        return returnMap;
    }
 
}