‘liusuyi’
2023-07-18 9f0d9e8358442d5d156a4e8aa1e8d6bd4960a6f9
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package com.ruoyi.sy.service.impl;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.Collectors;
 
import com.ruoyi.sy.domain.ArdSyUser;
import com.ruoyi.sy.mapper.ArdSyUserMapper;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.mapper.SysConfigMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.utils.httpclient.SYCarClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.sy.mapper.ArdSyCarMapper;
import com.ruoyi.sy.domain.ArdSyCar;
import com.ruoyi.sy.service.IArdSyCarService;
 
import javax.annotation.Resource;
 
/**
 * 三一车辆Service业务层处理
 *
 * @author ard
 * @date 2023-06-26
 */
@Service
public class ArdSyCarServiceImpl implements IArdSyCarService {
    @Resource
    private ArdSyCarMapper ardSyCarMapper;
 
    @Resource
    private SysConfigMapper sysConfigMapper;
 
    @Resource
    private ArdSyUserMapper ardSyUserMapper;
 
    /**
     * 查询三一车辆
     *
     * @param id 三一车辆主键
     * @return 三一车辆
     */
    @Override
    public ArdSyCar selectArdSyCarById(String id) {
        return ardSyCarMapper.selectArdSyCarById(id);
    }
 
    /**
     * 查询三一车辆列表
     *
     * @param ardSyCar 三一车辆
     * @return 三一车辆
     */
    @Override
    public List<ArdSyCar> selectArdSyCarList(ArdSyCar ardSyCar) {
        return ardSyCarMapper.selectArdSyCarList(ardSyCar);
    }
 
    /**
     * 新增三一车辆
     *
     * @param ardSyCar 三一车辆
     * @return 结果
     */
    @Override
    public int insertArdSyCar(ArdSyCar ardSyCar) {
            return ardSyCarMapper.insertArdSyCar(ardSyCar);
    }
 
    /**
     * 修改三一车辆
     *
     * @param ardSyCar 三一车辆
     * @return 结果
     */
    @Override
    public int updateArdSyCar(ArdSyCar ardSyCar) {
        return ardSyCarMapper.updateArdSyCar(ardSyCar);
    }
 
    /**
     * 批量删除三一车辆
     *
     * @param ids 需要删除的三一车辆主键
     * @return 结果
     */
    @Override
    public int deleteArdSyCarByIds(String[] ids) {
        return ardSyCarMapper.deleteArdSyCarByIds(ids);
    }
 
    /**
     * 删除三一车辆信息
     *
     * @param id 三一车辆主键
     * @return 结果
     */
    @Override
    public int deleteArdSyCarById(String id) {
        return ardSyCarMapper.deleteArdSyCarById(id);
    }
 
    /**
     * 获取未挂接权限的三一车辆
     */
    @Override
    public Map<String,Object> getArdSyCarNoRight(String userId) {
        SysConfig config = new SysConfig();
        config.setConfigKey("syCarPT");
        List<SysConfig> sysConfigResult = sysConfigMapper.selectConfigList(config);
        String syURL = "";
        Map<String,Object> result = new HashMap();
        if(sysConfigResult.size() == 0){
            result.put("data","三一车辆url没有录入");
            result.put("code","500");
            return result;
        }else{
            syURL = sysConfigResult.get(0).getConfigValue();
            ArdSyUser ardSyUserPara = new ArdSyUser();
            ardSyUserPara.setSysUserId(userId);
            List<ArdSyUser> ardSyUserList = ardSyUserMapper.selectArdSyUserList(ardSyUserPara);
            if(ardSyUserList.size() == 0){
                result.put("data","用户未挂接三一车辆");
                result.put("code","500");
                return result;
            }else{
                ArdSyUser ardSyUser = ardSyUserList.get(0);
                Map<String,Object> LogInResult = SYCarClient.logIn(syURL,ardSyUser.getUserId(), ardSyUser.getPassword());
                String sessionId = (String) LogInResult.get("sessionId");
                Map<String,Object> carListMap = SYCarClient.getCarList(syURL,sessionId);
                if(((String)carListMap.get("rspCode")).equals("1")){
                    List<Map<String,Object>> list = (List<Map<String,Object>>) carListMap.get("list");
                    ArdSyCar ardSyCar = new ArdSyCar();
                    List<ArdSyCar> ardSyCarList = ardSyCarMapper.selectArdSyCarList(ardSyCar);
                    List<String> carIdList = new ArrayList();
                    for(ArdSyCar innerArdSyCar : ardSyCarList){
                        carIdList.add(innerArdSyCar.getCarId());
                    }
 
                    List<Map<String,Object>> carList = list.stream().filter(new Predicate<Map<String,Object>>(){
                        @Override
                        public boolean test(Map<String,Object> map) {
                            return !carIdList.contains((String)map.get("carId"));
                        }
                    }).collect(Collectors.toList());
                    result.put("data",carList);
                    result.put("code","200");
                    return result;
                }else{
                    result.put("data","三一车辆平台出错");
                    result.put("code","500");
                    return result;
                }
            }
        }
    }
}