songhuangfeng123
2022-08-05 d887d1db33d88948c71c5af670033382079bb250
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
package com.gkhy.safePlatform.targetDuty.service.impl;
 
import com.gkhy.safePlatform.account.rpc.apimodel.AccountDepartmentService;
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.DepInfoRPCRespDTO;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.vo.ResultVO;
import com.gkhy.safePlatform.targetDuty.service.CommonService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
 
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
 
/**
 * 公共服务实现类
 *
 * @author xurui
 * @since 2022-07-20 11:49:22
 */
@Service("commonServiceImpl")
public class CommonServiceImpl implements CommonService {
 
    @DubboReference(check = false)
    private AccountDepartmentService accountDepartmentService;
 
    @Override
    public String getDepName(Long depId) {
        return this.getDepInfo(depId).getDepName();
    }
 
    @Override
    public DepInfoRPCRespDTO getDepInfo(Long depId) {
        // 设置部门名称
        ResultVO<DepInfoRPCRespDTO> rpcResult = accountDepartmentService.getDepInfoByDepId(depId);
        if (rpcResult != null && rpcResult.getCode().equals(ResultCodes.OK.getCode())) {
            if (rpcResult.getData() != null) {
                DepInfoRPCRespDTO dep = (DepInfoRPCRespDTO) rpcResult.getData();
                return dep;
            }
        }
        return new DepInfoRPCRespDTO();
    }
 
 
    @Override
    public Map<Long,String> getDepName(Set<Long> collectDepIdSet) {
        Map<Long, String> depPool = new HashMap<>();
        collectDepIdSet.forEach(depId ->{
            // 设置部门名称
            if (!depPool.containsKey(depId)) {
                try {
                    ResultVO<DepInfoRPCRespDTO> rpcResult = accountDepartmentService.getDepInfoByDepId(depId);
                    if (rpcResult != null && rpcResult.getCode().equals(ResultCodes.OK.getCode())) {
                        if (rpcResult.getData() != null) {
                            DepInfoRPCRespDTO dep = (DepInfoRPCRespDTO) rpcResult.getData();
                            depPool.put(dep.getDepId(), dep.getDepName());
                        }
                    }
                } catch (Exception e) {
                    System.out.println("exception::"+e);
                }
            }
        });
        return depPool;
    }
}