ludc
2024-12-04 787eeb2b2880490bcf2705dc8d35c9dd230dba35
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
package com.vci.web.service.impl;
 
import com.vci.corba.omd.data.BusinessObject;
import com.vci.omd.utils.ObjectTool;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.pagemodel.SmOperationVO;
import com.vci.web.service.SmOperationServiceI;
import com.vci.web.service.WebBoServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * 操作的服务
 * @author weidy
 * @date 2022-2-23
 */
@Service
public class SmOperationServiceImpl implements SmOperationServiceI {
 
    /**
     * 业务数据的服务
     */
    @Autowired
    private WebBoServiceI boService;
    /**
     * 使用菜单的编号获取按钮的内容
     *
     * @param functionId 功能的编号
     * @return 操作的信息
     */
    @Override
    public List<SmOperationVO> listButtonByFunctionId(String functionId) {
        VciBaseUtil.alertNotNull(functionId,"功能菜单");
        //我们需要先获取到授权的值
        String sql = "select f.ploid from plfunction f where  lower(f.plmoduleno) = :functionId";
        Map<String,String> conditionMap = new HashMap<>();
        conditionMap.put("functionId",functionId.toLowerCase(Locale.ROOT).trim());
        List<BusinessObject> functionCbos = boService.queryBySql(sql, conditionMap);
        if(CollectionUtils.isEmpty(functionCbos)){
            //都没有这个功能
            return new ArrayList<>();
        }
        String functionOid = ObjectTool.getBOAttributeValue(functionCbos.get(0), "ploid");
        conditionMap.clear();
        conditionMap.put("functionOid",functionOid);
        sql = "select rf.plrightvalue from PLROLERIGHT rf left join pluserrole ur on rf.plroleoid = ur.plroleuid " +
                " where ur.pluseruid =:useroid and rf.plfuncoid = :functionOid";
        conditionMap.put("useroid",VciBaseUtil.getCurrentUserOid());
        List<BusinessObject> cbos = boService.queryBySql(sql, conditionMap);
        if(CollectionUtils.isEmpty(cbos)){
            //没有授权
            return new ArrayList<>();
        }
        long rightValue = VciBaseUtil.getLong(ObjectTool.getBOAttributeValue(cbos.get(0), "plrightvalue"));
        //获取具体包含哪些按钮
        sql = "select o.ploperoid,o.plno from PLFUNCOPERATION o where o.plfuncoid = :functionOid ";
        conditionMap.remove("useroid");
        List<BusinessObject> operationLinkCbos = boService.queryBySql(sql, conditionMap);
        if(CollectionUtils.isEmpty(operationLinkCbos)){
            //根本没有按钮
            return new ArrayList<>();
        }
        //需要判断有权限的内容
        List<String> hasRightOids = new ArrayList<>();
        Map<String,Integer> oidOrderMap = new HashMap<>();
        operationLinkCbos.stream().forEach(cbo->{
            String operationOid = ObjectTool.getBOAttributeValue(cbo,"ploperoid");
            int orderNo = VciBaseUtil.getInt(ObjectTool.getBOAttributeValue(cbo,"plno"));
            if(hasRight(rightValue,orderNo)){
                hasRightOids.add(operationOid);
                oidOrderMap.put(operationOid,orderNo);
            }
        });
        if(CollectionUtils.isEmpty(hasRightOids)){
            //没有权限
            return new ArrayList<>();
        }
        sql = "select ploid as oid,plname,pluniqueflag,pldesc,plalias,plsequence from ploperation where ploid in (" + VciBaseUtil.toInSql(hasRightOids.toArray(new String[0])) + ")";
        List<BusinessObject> opertionCBOs = boService.queryBySql(sql, new HashMap<>());
        List<SmOperationVO> operationVOS = new ArrayList<>();
        Optional.ofNullable(opertionCBOs).orElseGet(()->new ArrayList<>()).stream().forEach(cbo->{
            SmOperationVO operationVO = new SmOperationVO();
            operationVO.setFunctionOid(functionOid);
            operationVO.setOid(cbo.oid);
            operationVO.setUniqueFlag(ObjectTool.getBOAttributeValue(cbo,"pluniqueflag"));
            operationVO.setName(ObjectTool.getBOAttributeValue(cbo,"plname"));
            operationVO.setAlias(ObjectTool.getBOAttributeValue(cbo,"plalias"));
            operationVO.setOrderNo(String.valueOf(oidOrderMap.get(operationVO.getOid())));
            operationVO.setDescription(ObjectTool.getBOAttributeValue(cbo,"pldesc"));
            operationVO.setModuleNo(functionId);
            operationVOS.add(operationVO);
        });
        List<SmOperationVO> operationVOList = operationVOS.stream().sorted(((o1, o2) -> o1.getOrderNo().compareTo(o2.getOrderNo()))).collect(Collectors.toList());
        return operationVOList;
    }
 
    /**
     * 是否有权限
     * @param rightValue 权限的值
     * @param operNum 操作的位置号
     * @return true表示有权限,false表示没有
     */
    private boolean hasRight(long rightValue, int operNum) {
        boolean res = false;
        long preValue = (long) Math.pow(2, operNum);
        if (preValue == (rightValue & preValue)) {
            res = true;
        }
        return res;
    }
 
}