郑永安
2023-09-19 69185134fcfaf913ea45f1255677225a2cc311a4
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
package com.gk.hotwork.Service.ServiceImpl;
 
import com.gk.hotwork.Domain.DepartmentInfo;
import com.gk.hotwork.Domain.Enum.ResultCodes;
import com.gk.hotwork.Domain.Exception.BusinessException;
import com.gk.hotwork.Domain.Vo.DepartmentVo;
import com.gk.hotwork.Domain.Vo.ResultVO;
import com.gk.hotwork.Domain.dto.DepInfoRPCRespDTO;
import com.gk.hotwork.Service.DepartmentService;
import com.gk.hotwork.Service.Middle.AccountDepartmentService;
import com.gk.hotwork.specialWork.model.dto.resp.DepRPCRespDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
 
@Service("accountDepartmentService")
public class AccountDepartmentServiceImpl implements AccountDepartmentService {
 
    @Autowired
    private DepartmentService departmentService;
 
    @Override
    public ResultVO<DepInfoRPCRespDTO> getDepInfoByDepId(Long uid,Long depId) {
 
        if (depId == null) {
            throw new BusinessException("部门id为空");
        }
        DepInfoRPCRespDTO depInfoDep = null;
        DepartmentInfo department = departmentService.getById(depId);
        if (department != null) {
            depInfoDep = new DepInfoRPCRespDTO();
            depInfoDep.setDepId(department.getId());
            depInfoDep.setDepName(department.getDepartment());
        }
 
        return new ResultVO<>(ResultCodes.OK,depInfoDep);
    }
 
    @Override
    public ResultVO<List<DepInfoRPCRespDTO>> listDepByDepIds(List<Long> depIds) {
        List<DepInfoRPCRespDTO> result;
        if (depIds != null && depIds.size() > 0) {
            List<DepartmentInfo> deps = departmentService.listDepByDepIds(depIds);
            result = new ArrayList<>(depIds.size());
            for (DepartmentInfo dep : deps) {
                DepInfoRPCRespDTO respDTO = new DepInfoRPCRespDTO();
                respDTO.setDepId(dep.getId());
                respDTO.setDepName(dep.getDepartment());
                respDTO.setStatus(dep.getIsdel());
                result.add(respDTO);
            }
        }else{
            result = Collections.emptyList();
        }
 
        return new ResultVO<>(ResultCodes.OK,result);
    }
 
    @Override
    public ResultVO<List<DepRPCRespDTO>> depList() {
        List<DepartmentVo> depDos = departmentService.selectByAll();
        List<DepRPCRespDTO> result = new ArrayList<>(depDos.size());
        if (depDos.size() > 0) {
            for (DepartmentVo depDo : depDos) {
                DepRPCRespDTO respDTO = new DepRPCRespDTO();
                respDTO.setDepId(depDo.getId());
                respDTO.setDepName(depDo.getDepartment());
                respDTO.setStatus(depDo.getIsdel());
                respDTO.setChildren(Collections.emptyList());
                result.add(respDTO);
            }
        }
        return new ResultVO<>(ResultCodes.OK,result);
    }
}