ludc
2023-04-07 7df1d61319149a666e8b2801a3c89c1d80900d2e
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
package com.vci.ubcs.code.service.impl;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vci.ubcs.code.entity.CodeBasicSec;
import com.vci.ubcs.code.entity.CodeClassifyValue;
import com.vci.ubcs.code.entity.CodeFixedValue;
import com.vci.ubcs.code.enumpack.CodeSecTypeEnum;
import com.vci.ubcs.code.mapper.CodeBasicSecMapper;
import com.vci.ubcs.code.mapper.CodeClassifyValueMapper;
import com.vci.ubcs.code.mapper.CodeFixedValueMapper;
import com.vci.ubcs.code.service.ICodeBasicSecService;
import com.vci.ubcs.com.vci.starter.web.util.VciBaseUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
 
import javax.annotation.Resource;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
 
/**
 * 码段基础信息服务接口
 *
 * @author weidy
 * @date 2022-01-24
 */
@Service
public class CodeBasicSecServiceImpl extends ServiceImpl<CodeBasicSecMapper, CodeBasicSec> implements ICodeBasicSecService {
 
    @Resource
    private CodeBasicSecMapper codeBasicSecMapper;
 
    /**
     * 固定码段的码值数据操作层
     */
    @Resource
    private CodeFixedValueMapper fixedValueMapper;
 
    /**
     * 分类码段的码值数据操作层
     */
    @Resource
    private CodeClassifyValueMapper codeClassifyValueMapper;
 
    /**
     * 根据编码规则批量删除码段基本信息
     * @param codeRuleOid 编码规则主键
     * @return 执行结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean batchDeleteSecByCodeRuleOid(String codeRuleOid) {
        VciBaseUtil.alertNotNull(codeRuleOid,"编码规则主键");
        // 1、通过pkcoderule作为条件,先查询要删除基础码段
        List<CodeBasicSec> deleteList = this.codeBasicSecMapper.selectList(Wrappers.<CodeBasicSec>query().eq("pkcoderule", codeRuleOid));
        if (CollectionUtils.isEmpty(deleteList)){
            return true;
        }
        // 2、再删除基础码段
        boolean deletFlag = codeBasicSecMapper.deleteBatchIds(deleteList.stream().map(CodeBasicSec::getOid).collect(Collectors.toSet())) > 0;
        // 3、再根据删除固定码段,丛查询出来的基础码段中过滤出包含固定码段的记录
        List<CodeBasicSec> fixedSecList = deleteList.stream().filter(sec -> {
            return CodeSecTypeEnum.CODE_FIXED_SEC.getValue().equals(sec.getSecType());
        }).collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(fixedSecList)){
            // 将要作为删除条件的值放在一个集合里面
            Set<String> fixedSecOidSet = fixedSecList.stream().map(CodeBasicSec::getOid).collect(Collectors.toSet());
            // 通过外键进行查询
            List<CodeFixedValue> fixedValueS = fixedValueMapper.selectList(Wrappers.<CodeFixedValue>query().lambda().in(CodeFixedValue::getCodeFixedSecOid,fixedSecOidSet));
            // 根据查询出来的id执行固定码段执行删除
            deletFlag = fixedValueMapper.deleteBatchIds(fixedValueS.stream().map(CodeFixedValue::getOid).collect(Collectors.toSet()))>0;
        }
        // 4、再删除分类码段
        List<CodeBasicSec> classifySecList = deleteList.stream().filter(sec -> {
            return CodeSecTypeEnum.CODE_CLASSIFY_SEC.getValue().equals(sec.getSecType());
        }).collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(classifySecList)){
            // 将要作为删除条件的值放在一个集合里面
            Set<String> classifySecOidSet = classifySecList.stream().map(CodeBasicSec::getOid).collect(Collectors.toSet());
            // 通过外键进行查询
            List<CodeClassifyValue> fixedValueS = codeClassifyValueMapper.selectList(Wrappers.<CodeClassifyValue>query().lambda().in(CodeClassifyValue::getCodeClassifySecOid,classifySecOidSet));
            // 根据查询出来的主键id执行固定码段执行删除
            deletFlag = fixedValueMapper.deleteBatchIds(fixedValueS.stream().map(CodeClassifyValue::getOid).collect(Collectors.toSet()))>0;
        }
        return deletFlag;
    }
 
 
}