| | |
| | | import java.util.function.Predicate; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.uuid.IdUtils; |
| | | import com.ruoyi.common.websocket.util.WebSocketUtils; |
| | | import com.ruoyi.device.hiksdk.config.MinioClientSingleton; |
| | | import com.ruoyi.device.hiksdk.util.minio.MinioUtils; |
| | | import com.ruoyi.sy.domain.ArdSyUser; |
| | | import com.ruoyi.sy.gps31.PositionContainer; |
| | | 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 com.ruoyi.utils.forest.SYClient; |
| | | import com.ruoyi.utils.result.Results; |
| | | import io.minio.GetPresignedObjectUrlArgs; |
| | | import io.minio.ListObjectsArgs; |
| | | import io.minio.PutObjectArgs; |
| | | import io.minio.Result; |
| | | import io.minio.http.Method; |
| | | import io.minio.messages.Item; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import com.ruoyi.sy.mapper.ArdSyCarMapper; |
| | | import com.ruoyi.sy.domain.ArdSyCar; |
| | |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import static com.ruoyi.common.websocket.util.WebSocketUtils.ONLINE_USER_SESSIONS; |
| | | |
| | | /** |
| | | * 三一车辆Service业务层处理 |
| | |
| | | |
| | | @Resource |
| | | private ArdSyUserMapper ardSyUserMapper; |
| | | |
| | | @Resource |
| | | private SysUserMapper userMapper; |
| | | |
| | | @Resource |
| | | private SYClient sYClient; |
| | | |
| | | private Map<Integer,Map<String,String>> logInMap = new HashMap(); |
| | | |
| | | /** |
| | | * 查询三一车辆 |
| | |
| | | return result; |
| | | }else{ |
| | | ArdSyUser ardSyUser = ardSyUserList.get(0); |
| | | Map<String,Object> LogInResult = SYCarClient.logIn(syURL,ardSyUser.getUserId(), ardSyUser.getPassword()); |
| | | //Map<String,Object> LogInResult = SYCarClient.logIn(syURL,ardSyUser.getUserId(), ardSyUser.getPassword()); |
| | | String passwordMd5 = DigestUtils.md5Hex(ardSyUser.getPassword()); |
| | | Map<String,Object> LogInResult = sYClient.logIn(syURL,passwordMd5,ardSyUser.getUserId()); |
| | | String sessionId = (String) LogInResult.get("sessionId"); |
| | | Map<String,Object> carListMap = SYCarClient.getCarList(syURL,sessionId); |
| | | //Map<String,Object> carListMap = SYCarClient.getCarList(syURL,sessionId); |
| | | Map<String,Object> carListMap = sYClient.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(); |
| | |
| | | } |
| | | }).collect(Collectors.toList()); |
| | | result.put("data",carList); |
| | | result.put("code","200"); |
| | | return result; |
| | | }else{ |
| | | result.put("data","三一车辆平台出错"); |
| | | result.put("code","500"); |
| | | return result; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getArdSyCarAll(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 passwordMd5 = DigestUtils.md5Hex(ardSyUser.getPassword()); |
| | | Map<String,Object> LogInResult = sYClient.logIn(syURL,passwordMd5,ardSyUser.getUserId()); |
| | | String sessionId = (String) LogInResult.get("sessionId"); |
| | | //Map<String,Object> carListMap = SYCarClient.getCarList(syURL,sessionId); |
| | | Map<String,Object> carListMap = sYClient.getCarList(syURL,sessionId); |
| | | if(((String)carListMap.get("rspCode")).equals("1")){ |
| | | List<Map<String,Object>> list = (List<Map<String,Object>>) carListMap.get("list"); |
| | | result.put("data",list); |
| | | result.put("code","200"); |
| | | return result; |
| | | }else{ |
| | |
| | | |
| | | @Override |
| | | public String uploadCarPicture(String id, MultipartFile carPicture) { |
| | | //String url = MinioUtils.putObjectAndGetUrl("sycar",carPicture); |
| | | if(id != null && !id.equals("")){//id为非必要 |
| | | ArdSyCar ardSyCarr = ardSyCarMapper.selectArdSyCarById(id); |
| | | List<String> objectNames = new ArrayList(); |
| | | if(ardSyCarr.getCarPicture() != null || !ardSyCarr.getCarPicture().equals("")){ |
| | | String objectName = ardSyCarr.getCarPicture().split("/sycar/")[1]; |
| | | objectNames.add(objectName); |
| | | MinioUtils.removeObjects("sycar", objectNames); |
| | | } |
| | | } |
| | | //判断文件是否为空 |
| | | if (null == carPicture || 0 == carPicture.getSize()) { |
| | | return ""; |
| | |
| | | .build(); |
| | | String presignedObjectUrl = MinioClientSingleton.getMinioClient().getPresignedObjectUrl(getPresignedObjectUrlArgs); |
| | | String ObjectUrl = presignedObjectUrl.substring(0, presignedObjectUrl.indexOf("?")); |
| | | ArdSyCar ardSyCar = new ArdSyCar(); |
| | | ardSyCar.setId(id); |
| | | ardSyCar.setCarPicture(ObjectUrl); |
| | | ardSyCarMapper.updateArdSyCar(ardSyCar); |
| | | if(id != null && !id.equals("")){//id为非必要 |
| | | ArdSyCar ardSyCar = new ArdSyCar(); |
| | | ardSyCar.setId(id); |
| | | ardSyCar.setCarPicture(ObjectUrl); |
| | | ardSyCarMapper.updateArdSyCar(ardSyCar); |
| | | } |
| | | return ObjectUrl; |
| | | } catch (Exception ex) { |
| | | return ""; |
| | | } |
| | | } |
| | | |
| | | // @Override |
| | | // public List<ArdSyCar> getArdSyCarWithRightByCarIdList(List<String> carIdList) { |
| | | // List<ArdSyCar> result = ardSyCarMapper.getArdSyCarWithRightByCarIdList(carIdList); |
| | | // return result; |
| | | // } |
| | | |
| | | |
| | | @Override |
| | | public Results carListById(String id) { |
| | | try { |
| | | List<ArdSyCar> list = ardSyCarMapper.carListById(id); |
| | | if(list.size()>0){ |
| | | ArdSyCar ardSyCar = list.get(0); |
| | | return Results.succeed(ardSyCar); |
| | | }else { |
| | | return Results.succeed(); |
| | | } |
| | | } catch (Exception e) { |
| | | return Results.error(e.toString()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getArdSyCarAndDeptByCarId(String carId) { |
| | | Map<String, Object> result = ardSyCarMapper.getArdSyCarAndDeptByCarId(carId); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public void sendArdSyCarPosition() { |
| | | for(String key : ONLINE_USER_SESSIONS.keySet()){ |
| | | SysUser sysUser = userMapper.selectUserById(key); |
| | | String deptId = String.valueOf(sysUser.getDeptId()); |
| | | Map<String,Map<String,Object>> map = PositionContainer.getDeptPositionMap().get(deptId); |
| | | if(map != null){ |
| | | Map<String,Object> data = new HashMap(); |
| | | data.put("30000", map.values()); |
| | | WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(key), JSON.toJSONString(data)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void sendArdSyCarAlarmByCarId(String carId, Map<String,Object> data) { |
| | | List<SysUser> result = userMapper.getSysUserByCarId(carId); |
| | | for(SysUser sysUser : result){ |
| | | WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(sysUser.getUserId()), JSON.toJSONString(data)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据用户获取三一列表 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Map<String,Object> allListByUser(ArdSyUser ardSyUser,String syURL,String usersId){ |
| | | Map<String,Object> result0 = new HashMap(); |
| | | //判断关联表是否有数据 |
| | | if(ardSyUser!=null){ |
| | | Map<String, String> result = logInMap.get(Integer.parseInt(usersId)); |
| | | //31用户名密码 |
| | | String username31 = ardSyUser.getUserId(); |
| | | String password31 = ardSyUser.getPassword(); |
| | | String passwordMd5 = DigestUtils.md5Hex(password31); |
| | | Map<String, Object> result1 = sYClient.logIn(syURL,passwordMd5, username31); |
| | | result = new HashMap(); |
| | | result.put("userId", username31); |
| | | result.put("sessionId", (String) result1.get("sessionId")); |
| | | try { |
| | | result0 = sYClient.getTeamList(syURL,result.get("userId"),result.get("sessionId")); |
| | | } catch (Exception e) { |
| | | Map<String,Object> map = new HashMap(); |
| | | map.put("rspCode", 0); |
| | | map.put("list", new ArrayList()); |
| | | return map; |
| | | } |
| | | int online = 0; |
| | | for(Map<String,Object> map : (List<Map<String,Object>>) result0.get("list")){ |
| | | Map<String,Object> resultMap = sYClient.getTeamCarList(syURL,(String)map.get("teamId"),result.get("sessionId")); |
| | | List<Map<String,Object>> carList = (List<Map<String, Object>>) resultMap.get("carList"); |
| | | for(Map<String,Object> m : carList){ |
| | | if(((String) m.get("stateCn")).contains("在线")){ |
| | | online = online + 1; |
| | | }else{ |
| | | continue; |
| | | } |
| | | } |
| | | for(Map<String,Object> m : (List<Map<String,Object>>) result0.get("list")){ |
| | | if(((String) m.get("teamId")).equals(((String) map.get("teamId")))){ |
| | | map.put("count", Integer.parseInt((String) m.get("carNum"))); |
| | | } |
| | | } |
| | | map.put("online", online); |
| | | online = 0; |
| | | } |
| | | }else { |
| | | result0.put("列表为空!","无关联账号!"); |
| | | } |
| | | return result0; |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String,String>> getCarList(ArdSyUser ardSyUser, String syURL, String usersId,String teamId){ |
| | | List<Map<String,String>> list = new ArrayList<>(); |
| | | Map<String, String> result = logInMap.get(Integer.parseInt(usersId)); |
| | | //31用户名密码 |
| | | String username31 = ardSyUser.getUserId(); |
| | | String password31 = ardSyUser.getPassword(); |
| | | String passwordMd5 = DigestUtils.md5Hex(password31); |
| | | Map<String, Object> result1 = sYClient.logIn(syURL,passwordMd5, username31); |
| | | result = new HashMap(); |
| | | result.put("userId", username31); |
| | | result.put("sessionId", (String) result1.get("sessionId")); |
| | | //查询该teamId下的车辆数据 |
| | | Map<String,Object> carList31 = new HashMap(); |
| | | carList31 = sYClient.getCarList1(syURL,teamId, result.get("userId"),result.get("sessionId")); |
| | | //拿到车辆数据 |
| | | list= (List) carList31.get("list"); |
| | | List<String> carIdList = new ArrayList(); |
| | | //所有carId |
| | | for(Map<String,String> m : list){ |
| | | carIdList.add(m.get("carId")); |
| | | } |
| | | if(carIdList.size() == 0){ |
| | | Map<String,String> map0 = new HashMap(); |
| | | map0.put("list", "{}"); |
| | | map0.put("rspCode", "1"); |
| | | list.add(map0); |
| | | return list; |
| | | } |
| | | //添加车辆属性 |
| | | for(Map<String,String> m : list){ |
| | | switch (m.get("state")) { |
| | | case "1": |
| | | m.put("carState", "离线-从未报定位");break; |
| | | case "2": |
| | | m.put("carState", "离线-欠费");break; |
| | | case "3": |
| | | m.put("carState", "离线");break; |
| | | case "4": |
| | | m.put("carState", "离线-报警");break; |
| | | case "5": |
| | | m.put("carState", "在线-从未报定位");break; |
| | | case "6": |
| | | m.put("carState", "在线-欠费");break; |
| | | case "7": |
| | | m.put("carState", "在线-行驶");break; |
| | | case "8": |
| | | m.put("carState", "在线-行驶-报警");break; |
| | | case "9": |
| | | m.put("carState", "在线-停车-ACC关");break; |
| | | case "10": |
| | | m.put("carState", "在线-停车-ACC开");break; |
| | | case "11": |
| | | m.put("carState", "在线-停车-ACC关-报警");break; |
| | | case "12": |
| | | m.put("carState", "在线-停车-ACC开-报警");break; |
| | | case "13": |
| | | m.put("carState", "在线-无效定位");break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 根据dept集合查询出所有对应的carId |
| | | * @param deptList |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<Map<String,String>> carIdByDeptList(List<Long> deptList,List<Map<String,String>> list){ |
| | | QueryWrapper<ArdSyCar> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.in("dept_id",deptList); |
| | | List<ArdSyCar> carList = ardSyCarMapper.selectList(queryWrapper); |
| | | //对比把匹配到的数据添加到list中 |
| | | for(Map<String,String> m : list){ |
| | | String carId = m.get("carId"); |
| | | for (int i = 0; i < carList.size(); i++) { |
| | | ArdSyCar ardSyCar = carList.get(i); |
| | | if(carId.equals(ardSyCar.getCarId())){ |
| | | m.put("carModel",ardSyCar.getCarModel()); |
| | | m.put("carTypeArd",ardSyCar.getCarType()); |
| | | m.put("carBrand",ardSyCar.getCarBrand()); |
| | | m.put("carPicture",ardSyCar.getCarPicture()); |
| | | } |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | } |