郑永安
2023-06-19 7a6abd05683528032687c75e80e0bd2030a3e46c
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
package com.gkhy.safePlatform.account.rpc.test;
 
import com.gkhy.safePlatform.account.model.dto.req.CameraQuery;
import com.gkhy.safePlatform.account.model.dto.resp.CameraRespDTO;
import com.gkhy.safePlatform.account.rpc.apimodel.CameraService;
import com.gkhy.safePlatform.account.rpc.apimodel.model.req.query.CameraRpcQuery;
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.CameraRpcRespDTO;
import com.gkhy.safePlatform.account.service.CameraManageService;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.vo.SearchResultVO;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
 
import java.util.ArrayList;
import java.util.List;
 
@DubboService
public class CameraServiceProvider implements CameraService {
 
    @Autowired
    private CameraManageService cameraManageService;
 
    @Override
    public SearchResultVO<List<CameraRpcRespDTO>> listCamerasByDepId(CameraRpcQuery rpcQuery) {
        CameraQuery query = new CameraQuery();
        BeanUtils.copyProperties(rpcQuery,query);
        SearchResultVO<List<CameraRespDTO>> srs = cameraManageService.listCamerasByDepId(query);
        SearchResultVO<List<CameraRpcRespDTO>> resultVO = new SearchResultVO<>();
        BeanUtils.copyProperties(srs,resultVO);
        resultVO.setData(toRpcDtoList((List<CameraRespDTO>) srs.getData()));
        return resultVO;
    }
 
    @Override
    public SearchResultVO<List<CameraRpcRespDTO>> listCamerasByUserId(Long userId) {
        SearchResultVO<List<CameraRespDTO>> srs = cameraManageService.listAccessCamerasByUserId(userId);
        SearchResultVO<List<CameraRpcRespDTO>> resultVO = new SearchResultVO<>();
        BeanUtils.copyProperties(srs,resultVO);
        resultVO.setData(toRpcDtoList((List<CameraRespDTO>) srs.getData()));
        return resultVO;
    }
 
    @Override
    public SearchResultVO<CameraRpcRespDTO> findCameraById(Long cameraId) {
        SearchResultVO<CameraRespDTO> srs = cameraManageService.findByCameraId(cameraId);
        SearchResultVO<CameraRpcRespDTO> resultVO = new SearchResultVO<>();
        BeanUtils.copyProperties(srs,resultVO);
        resultVO.setData(toRpcDto((CameraRespDTO) srs.getData()));
        return resultVO;
    }
 
    @Override
    public SearchResultVO<List<CameraRpcRespDTO>> findCamerasByCondition(CameraRpcQuery rpcQuery) {
        CameraQuery query = new CameraQuery();
        BeanUtils.copyProperties(rpcQuery,query);
        SearchResultVO<List<CameraRespDTO>> srs = cameraManageService.listCamerasByCondition(query);
        SearchResultVO<List<CameraRpcRespDTO>> resultVO = new SearchResultVO<>();
        BeanUtils.copyProperties(srs,resultVO);
        resultVO.setData(toRpcDtoList((List<CameraRespDTO>) srs.getData()));
        return resultVO;
    }
 
    @Override
    public SearchResultVO<List<CameraRpcRespDTO>> listByCameraIdList(List<Long> cameraIdList) {
        SearchResultVO<List<CameraRpcRespDTO>> resultVO = new SearchResultVO<>();
        resultVO.setCode(ResultCodes.OK);
        List<CameraRespDTO> respDTOList = cameraManageService.listByCameraIdList(cameraIdList);
        List<CameraRpcRespDTO> rpcRespDTOS = toRpcDtoList(respDTOList);
        if(respDTOList != null)
            resultVO.setCount(rpcRespDTOS.size());
        else
            resultVO.setCount(0);
        resultVO.setData(rpcRespDTOS);
        return resultVO;
    }
 
    private List<CameraRpcRespDTO> toRpcDtoList(List<CameraRespDTO> respDTOList){
        if(respDTOList == null || respDTOList.isEmpty())
            return null;
        List<CameraRpcRespDTO> rpcRespDTOS = new ArrayList<>();
        for(int i=0;i<respDTOList.size();i++){
            rpcRespDTOS.add(toRpcDto(respDTOList.get(i)));
        }
        return rpcRespDTOS;
    }
 
    private CameraRpcRespDTO toRpcDto(CameraRespDTO respDTO){
        if(respDTO == null)
            return null;
        CameraRpcRespDTO rpcDto = new CameraRpcRespDTO();
        BeanUtils.copyProperties(respDTO,rpcDto);
        return rpcDto;
    }
}