ludc
2024-04-18 1c79f9cb22aa8663192bef0fcaeeec5606aa467f
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
package com.vci.ubcs.code.applyjtcodeservice.service.impl;
 
import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vci.ubcs.code.applyjtcodeservice.mapper.DockingPreClassifyMapper;
import com.vci.ubcs.code.applyjtcodeservice.service.IDockingPreAttrMappingService;
import com.vci.ubcs.code.applyjtcodeservice.service.IDockingPreClassifyService;
import com.vci.ubcs.code.applyjtcodeservice.service.IDockingPreViewModelService;
import com.vci.ubcs.code.applyjtcodeservice.wrapper.DockingPreClassifyWrapper;
import com.vci.ubcs.starter.revision.model.TreeQueryObject;
import com.vci.ubcs.starter.revision.model.TreeWrapperOptions;
import com.vci.ubcs.starter.revision.service.RevisionModelUtil;
import com.vci.ubcs.starter.util.MdmBtmTypeConstant;
import com.vci.ubcs.starter.web.pagemodel.Tree;
import com.vci.ubcs.code.applyjtcodeservice.entity.DockingPreClassify;
import com.vci.ubcs.code.applyjtcodeservice.vo.DockingPreClassifyVO;
import com.vci.ubcs.code.applyjtcodeservice.vo.DockingPreViewModelVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.*;
 
 
/**
 * 集团分类业务服务
 * @author xiejun
 * @date 2023-05-23
 */
@Service
@Slf4j
public class DockingPreClassifyServiceImpl extends ServiceImpl<DockingPreClassifyMapper, DockingPreClassify> implements IDockingPreClassifyService {
    /**
     * 上级节点的属性名称
     */
    public static  final String PARENT_FIELD_NAME = "pid";
    /***
     * 集团分类属性
     */
    @Resource
    private DockingPreClassifyMapper dockingPreClassifyMapper;
 
    /***
     * 集团分类属性
     */
    @Resource
    private IDockingPreViewModelService dockingPreViewModelService;
 
 
    /***
     *集团集成配置服务
     */
    @Resource
    private IDockingPreAttrMappingService dockingPreAttrMappingService;
 
 
    /**
     * 对象的操作
     */
    @Resource
    private RevisionModelUtil revisionModelUtil;
 
    /***
     * 集团分类树对象查
     *@param treeQueryObject 集团分类查询对象
     *@return 返回分类树对象
     */
    @Override
    public List<Tree> treeCompanyGroupClassify(TreeQueryObject treeQueryObject) {
        log.info("获取集团分类树start...");
 
        Map<String,String> conditionMap= treeQueryObject.getConditionMap();
        if(conditionMap==null){
            conditionMap=new HashMap<>();
        }
        TreeWrapperOptions treeWrapperOptions = new TreeWrapperOptions(PARENT_FIELD_NAME.toLowerCase(Locale.ROOT));
        treeWrapperOptions.copyFromTreeQuery(treeQueryObject);
        List<DockingPreClassifyVO> dockingPreClassifyVOS= getCompanyGourpClassByParentId(treeQueryObject.getParentOid(),false);
        List<Tree> tree= revisionModelUtil.doList2Trees(dockingPreClassifyVOS,treeWrapperOptions,(DockingPreClassifyVO s) ->{
            //可以在这里处理树节点的显示
            return s.getId() + " " + s.getName();//(FrameworkDataLCStatus.DISABLED.getValue().equalsIgnoreCase(s.getLcStatus()) ? (" 【停用】 ") : "");
        });
 
        setTreeConig(tree,conditionMap);
        log.info("获取集团分类树end...");
        return tree;
    }
    private void setTreeConig(List<Tree> tree,Map<String,String >conditionMap){
        boolean checkHasChild=false;
        Iterator var6 =  tree.listIterator();
        while(var6.hasNext()){
            Tree trees = (Tree) var6.next();
            List<Tree> childrenList=trees.getChildren();
            if(childrenList.size()>0){
                checkHasChild=true;
            }
            boolean checkHas=false;
            //如果与条件传过来的值匹配的上则设置为选中
            if(conditionMap.containsKey(MdmBtmTypeConstant.CODE_CLASSIFY_OID_FIELD)){
                String codeClassifyId=conditionMap.get(MdmBtmTypeConstant.CODE_CLASSIFY_OID_FIELD);
                checkHas = dockingPreAttrMappingService.checkHasConfigByTragetCodeclassifyId(codeClassifyId, trees.getOid());
            }
            if (checkHas) {
                trees.setChecked(true);
            }
            if(checkHasChild){
                trees.setLeaf(false);
            }else{
                trees.setLeaf(true);
            }
            if(checkHasChild) {
                setTreeConig(childrenList,conditionMap);
            }
        }
 
    }
 
    /***
     * 根据父分类id查询层级树数据对象集合
     * @param pid 集团分类的oid
     * @return 返回层级树数据对象集合
     */
    private List<DockingPreClassifyVO> getCompanyGourpClassByParentId(String pid,boolean isContainView){
        log.info("根据父分类pid->"+pid+"查询层级树数据对象集合start...");
        if(StringUtils.isBlank(pid)){
            pid=null;
        }
        List<DockingPreClassify> doList =dockingPreClassifyMapper.selectCompanyGroupClassifyVOByTree(pid);
        List<DockingPreClassifyVO>dockingPreClassifyVOS= DockingPreClassifyWrapper.build().entityVOs(doList);
        if(isContainView){
            dockingPreClassifyVOS.stream().forEach(dockingPreClassifyVO -> {
            List<DockingPreViewModelVO> dockingViewVOS=    dockingPreViewModelService.selectDockingPreViewModelByClassId(dockingPreClassifyVO.getOid(),isContainView);
                dockingPreClassifyVO.setDockingPreViewModelVOList(dockingViewVOS);
            });
        }
        log.info("根据父分类pid->"+pid+"查询层级树数据对象集合end...");
        return dockingPreClassifyVOS;
    }
}