package com.ruoyi.sy.service.impl; import java.io.IOException; import java.util.*; import com.alibaba.fastjson.JSON; import com.github.pagehelper.PageHelper; import com.ruoyi.common.core.domain.entity.SysConfig; import com.ruoyi.common.utils.uuid.IdUtils; import com.ruoyi.sy.domain.ArdSyCar; import com.ruoyi.sy.domain.ArdSyUser; import com.ruoyi.sy.domain.ArdTankLockState; import com.ruoyi.sy.mapper.*; import com.ruoyi.system.mapper.SysConfigMapper; import com.ruoyi.utils.forest.SYClient; import com.ruoyi.utils.websocket.util.WebSocketUtils; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; import org.apache.commons.codec.digest.DigestUtils; import org.springframework.stereotype.Service; import java.util.stream.Collectors; import com.ruoyi.sy.domain.ArdTankLock; import com.ruoyi.sy.service.IArdTankLockService; import javax.annotation.Resource; import static com.ruoyi.utils.websocket.util.WebSocketUtils.ONLINE_USER_SESSIONS; /** * 电磁锁Service业务层处理 * * @author ard * @date 2024-07-01 */ @Service public class ArdTankLockServiceImpl implements IArdTankLockService { @Resource private ArdTankLockMapper ardTankLockMapper; @Resource private ArdTankWallLockMapper ardTankWallLockMapper; @Resource private ArdTankWallLockTemporaryMapper ardTankWallLockTemporaryMapper; @Resource private ArdSyUserMapper ardSyUserMapper; @Resource private SysConfigMapper sysConfigMapper; @Resource private ArdSyCarMapper ardSyCarMapper; @Resource private ArdTankLockStateMapper ardTankLockStateMapper; @Resource private SYClient sYClient; private Map alarmMap = new HashMap();//电磁锁历史报警线程容器 /** * 查询电磁锁 * * @param id 电磁锁主键 * @return 电磁锁 */ @Override public ArdTankLock selectArdTankLockById(String id) { return ardTankLockMapper.selectArdTankLockById(id); } /** * 查询电磁锁列表 * * @param ardTankLock 电磁锁 * @return 电磁锁 */ @Override public List selectArdTankLockList(ArdTankLock ardTankLock) { return ardTankLockMapper.selectArdTankLockList(ardTankLock); } /** * 新增电磁锁 * * @return 结果 */ @Override public int insertArdTankLock(Map para) { String carId = (String) para.get("carId"); List> lockList = (List>)para.get("lockList"); List ardTankLocks = new ArrayList(); for(Map map : lockList){ ArdTankLock ardTankLock = new ArdTankLock(); ardTankLock.setId(IdUtils.simpleUUID()); ardTankLock.setLockNum(map.get("lockNum")); ardTankLock.setLockName(map.get("lockName")); ardTankLock.setImgPositionTop(map.get("imgPositionTop")); ardTankLock.setImgPositionLeft(map.get("imgPositionLeft")); ardTankLock.setCarId(carId); ardTankLock.setEnable(map.get("enable")); ardTankLocks.add(ardTankLock); } return ardTankLockMapper.insertArdTankLocks(ardTankLocks); } /*@Override public int insertArdTankLock(ArdTankLock ardTankLock) { ardTankLock.setId(IdUtils.simpleUUID()); return ardTankLockMapper.insertArdTankLock(ardTankLock); }*/ /** * 修改电磁锁 * * @param ardTankLock 电磁锁 * @return 结果 */ @Override public int updateArdTankLock(ArdTankLock ardTankLock) { return ardTankLockMapper.updateArdTankLock(ardTankLock); } /** * 批量删除电磁锁 * * @param ids 需要删除的电磁锁主键 * @return 结果 */ @Override public int deleteArdTankLockByIds(String[] ids) { return ardTankLockMapper.deleteArdTankLockByIds(ids); } /** * 删除电磁锁信息 * * @param id 电磁锁主键 * @return 结果 */ @Override public int deleteArdTankLockById(String id) { try{ return ardTankLockMapper.deleteArdTankLockById(id); } finally { ardTankWallLockMapper.deleteArdTankWallLockByLockId(id);//删除永久电子围栏中间表 ardTankWallLockTemporaryMapper.deleteArdTankWallLockTemporaryByLockId(id);//删除临时电子围栏中间表 } } @Override //public Results List> getAll(String usersId) { public Map getAll(String usersId) { List ardTankLockList = ardTankLockMapper.getAll(); ArdSyUser ardSyUser = ardSyUserMapper.userById(usersId); if(ardSyUser == null){ return new HashMap(); } List syURLResult = sysConfigMapper.selectByType("syCarPT"); String syURL = ""; if(syURLResult.size() != 0){ syURL = syURLResult.get(0).getConfigValue(); }else{ return new HashMap(); } String passwordMd5 = DigestUtils.md5Hex(ardSyUser.getPassword()); Map LogInResult = sYClient.logIn(syURL, passwordMd5, ardSyUser.getUserId()); String sessionId = (String) LogInResult.get("sessionId"); //List ardTankLockList = ardTankLockMapper.getAll(); List> result = new ArrayList(); for(ArdTankLock ardTankLock : ardTankLockList){ Map map = new HashMap(); map.put("id",ardTankLock.getId()); map.put("lockNum",ardTankLock.getLockNum()); map.put("lockName",ardTankLock.getLockName()); map.put("imgPositionTop",ardTankLock.getImgPositionTop()); map.put("imgPositionLeft",ardTankLock.getImgPositionLeft()); map.put("carId",ardTankLock.getCarId()); map.put("enable",ardTankLock.getEnable()); if(ardTankLock.getRestartState() == null){ map.put("restartState",""); }else{ map.put("restartState",ardTankLock.getRestartState()); } if(ardTankLock.getOnlineTime() == null){ map.put("onlineTime",""); }else{ map.put("onlineTime",ardTankLock.getOnlineTime()); } Map syResult = sYClient.getCarNearPositionByCarId(syURL, ardTankLock.getCarId(), ardSyUser.getUserId(), sessionId); if(((String)syResult.get("rspCode")).equals("1")){ Map carMap = ((List>)syResult.get("list")).get(0); map.put("carPlate",carMap.get("carPlate")); } result.add(map); } List> result0 = new ArrayList();//拼接carId和carPlate Set carIdSet = new HashSet(); for(Map map : result){ if(!carIdSet.contains((String) map.get("carId"))){ Map mapr = new HashMap(); mapr.put("carId",map.get("carId")); mapr.put("carPlate",map.get("carPlate")); mapr.put("lockList",new ArrayList()); result0.add(mapr); } carIdSet.add((String) map.get("carId")); } for(Map map : result0){ for(Map map0 : result){ if(((String)map.get("carId")).equals((String)map0.get("carId"))){ ((List)map.get("lockList")).add(map0); } } } Long total = ardTankLockMapper.selectArdTankLockTotal(); Map resultMap = new HashMap(); resultMap.put("list",result0); resultMap.put("total",total); return resultMap; } @Override public Map getLockByCarId(String carId, String usersId) { ArdSyUser ardSyUser = ardSyUserMapper.userById(usersId); if(ardSyUser == null){ return new HashMap(); } List syURLResult = sysConfigMapper.selectByType("syCarPT"); String syURL = ""; if(syURLResult.size() != 0){ syURL = syURLResult.get(0).getConfigValue(); }else{ return new HashMap(); } String passwordMd5 = DigestUtils.md5Hex(ardSyUser.getPassword()); Map LogInResult = sYClient.logIn(syURL, passwordMd5, ardSyUser.getUserId()); String sessionId = (String) LogInResult.get("sessionId"); List ardTankLockList = ardTankLockMapper.getLockByCarId(carId); Map syResult = sYClient.getCarNearPositionByCarId(syURL, carId, ardSyUser.getUserId(), sessionId); Map resultMap = new HashMap(); if(ardTankLockList.size() != 0){ resultMap.put("carId",carId); if(((String)syResult.get("rspCode")).equals("1")){ Map carMap = ((List>)syResult.get("list")).get(0); resultMap.put("carPlate",carMap.get("carPlate")); } }else{ resultMap.put("carId",carId); if(((String)syResult.get("rspCode")).equals("1")){ Map carMap = ((List>)syResult.get("list")).get(0); resultMap.put("carPlate",carMap.get("carPlate")); } resultMap.put("lockList",new ArrayList()); } List> result = new ArrayList(); for(ArdTankLock ardTankLock : ardTankLockList){ Map map = new HashMap(); map.put("id",ardTankLock.getId()); map.put("lockNum",ardTankLock.getLockNum()); map.put("lockName",ardTankLock.getLockName()); map.put("imgPositionTop",ardTankLock.getImgPositionTop()); map.put("imgPositionLeft",ardTankLock.getImgPositionLeft()); map.put("carId",ardTankLock.getCarId()); map.put("enable",ardTankLock.getEnable()); if(ardTankLock.getRestartState() == null){ map.put("restartState",""); }else{ map.put("restartState",ardTankLock.getRestartState()); } if(ardTankLock.getOnlineTime() == null){ map.put("onlineTime",""); }else{ map.put("onlineTime",ardTankLock.getOnlineTime()); } if(ardTankLock.getArdTankLockState() != null){//电磁锁状态 map.put("ardTankLockState",ardTankLock.getArdTankLockState()); }else{ ArdTankLockState ardTankLockState = new ArdTankLockState(); ardTankLockState.setId(""); ardTankLockState.setLockId(""); ardTankLockState.setLockNum(""); ardTankLockState.setLockState(""); ardTankLockState.setLockPositionState(""); ardTankLockState.setLockShellState(""); ardTankLockState.setRestartState(""); ardTankLockState.setBatterVoltage(""); ardTankLockState.setPowerVoltage(""); ardTankLockState.setUploadTime(""); ardTankLockState.setUniqueMark(""); ardTankLockState.setLockStateMark(false); map.put("ardTankLockState",ardTankLockState); } Map carMap = ((List>)syResult.get("list")).get(0); map.put("carPlate",carMap.get("carPlate")); result.add(map); } resultMap.put("lockList",result); return resultMap; } @Override public int deleteLockByCarId(String carId) { int result = ardTankLockMapper.deleteLockByCarId(carId); return result; } @Override public int updateLockByCarId(Map para) { int result = 0; String carId = (String) para.get("carId"); List ardTankLockOldList = ardTankLockMapper.getLockByCarId(carId); Set idSet = new HashSet();//之前的主键 for(ArdTankLock ardTankLock : ardTankLockOldList){ idSet.add(ardTankLock.getId()); } //Set newIdSet = new HashSet();//传参的主键 List> lockList = (List>) para.get("lockList"); if(lockList.isEmpty()){//数组为空,做删除操作 if(ardTankLockOldList.isEmpty()){//若没有挂接,不做操作 return 1; } result = ardTankLockMapper.deleteLockByCarId(carId); return result; } List ardTankLocks = new ArrayList(); for(Map map : lockList){ if(map.get("id") != null){//有主键,做修改操作 //newIdSet.add((String) map.get("id")); idSet.remove((String) map.get("id")); ArdTankLock ardTankLock = new ArdTankLock(); ardTankLock.setId((String) map.get("id")); ardTankLock.setLockNum((String) map.get("lockNum")); ardTankLock.setLockName((String) map.get("lockName")); ardTankLock.setImgPositionTop((String) map.get("imgPositionTop")); ardTankLock.setImgPositionLeft((String) map.get("imgPositionLeft")); ardTankLock.setCarId((String) map.get("carId")); ardTankLock.setEnable((String) map.get("enable")); result = result + ardTankLockMapper.updateArdTankLock(ardTankLock); }else{//无主键,做新增操作 ArdTankLock ardTankLock = new ArdTankLock(); ardTankLock.setId(IdUtils.simpleUUID()); ardTankLock.setLockNum((String) map.get("lockNum")); ardTankLock.setLockName((String) map.get("lockName")); ardTankLock.setImgPositionTop((String) map.get("imgPositionTop")); ardTankLock.setImgPositionLeft((String) map.get("imgPositionLeft")); ardTankLock.setCarId(carId); ardTankLock.setEnable((String) map.get("enable")); ardTankLocks.add(ardTankLock); } } if(ardTankLocks.size() != 0){ result = result + ardTankLockMapper.insertArdTankLocks(ardTankLocks); } if(!idSet.isEmpty()){ result = result + ardTankLockMapper.deleteArdTankLockByIdSet(idSet); } return result; } @Override public Map getLockByCarPlate(String usersId, String carPlate, Integer pageNum, Integer pageSize) { ArdSyUser ardSyUser = ardSyUserMapper.userById(usersId); if(ardSyUser == null){ return new HashMap(); } List syURLResult = sysConfigMapper.selectByType("syCarPT"); String syURL = ""; if(syURLResult.size() != 0){ syURL = syURLResult.get(0).getConfigValue(); }else{ return new HashMap(); } String passwordMd5 = DigestUtils.md5Hex(ardSyUser.getPassword()); Map LogInResult = sYClient.logIn(syURL, passwordMd5, ardSyUser.getUserId()); String sessionId = (String) LogInResult.get("sessionId"); List ardTankLockList = new ArrayList(); List> result = new ArrayList(); List carIdList = new ArrayList();//记录三一车辆主键 if(!carPlate.equals("")){ Map carMap = sYClient.getCarListByPlate(syURL,carPlate,ardSyUser.getUserId(),sessionId);//车牌号模糊搜索车辆 List> carList = new ArrayList(); if(((String)carMap.get("rspCode")).equals("1")){ carList = (List>) carMap.get("list"); }else{ return new HashMap(); } //List carIdList = new ArrayList();//记录三一车辆主键 for(Map map : carList){ carIdList.add((String) map.get("carId")); } PageHelper.startPage(pageNum, pageSize);//分页 ardTankLockList = ardTankLockMapper.getLockByCarIdList(carIdList); for(ArdTankLock ardTankLock : ardTankLockList){ if(carIdList.contains(ardTankLock.getCarId())){//返回的车辆包含数据库录入的车辆 Map map = new HashMap(); map.put("id",ardTankLock.getId()); map.put("lockNum",ardTankLock.getLockNum()); map.put("lockName",ardTankLock.getLockName()); map.put("imgPositionTop",ardTankLock.getImgPositionTop()); map.put("imgPositionLeft",ardTankLock.getImgPositionLeft()); map.put("carId",ardTankLock.getCarId()); map.put("enable",ardTankLock.getEnable()); if(ardTankLock.getRestartState() == null){ map.put("restartState",""); }else{ map.put("restartState",ardTankLock.getRestartState()); } if(ardTankLock.getOnlineTime() == null){ map.put("onlineTime",""); }else{ map.put("onlineTime",ardTankLock.getOnlineTime()); } Map car = carList.stream().filter(mapCar -> ((String)mapCar.get("carId")).equals(ardTankLock.getCarId())).collect(Collectors.toList()).get(0); map.put("carPlate", (String) car.get("carPlate")); result.add(map); }else{ continue; } } }else{ PageHelper.startPage(pageNum, pageSize);//分页 ardTankLockList = ardTankLockMapper.getAll(); for(ArdTankLock ardTankLock : ardTankLockList){ Map map = new HashMap(); map.put("id",ardTankLock.getId()); map.put("lockNum",ardTankLock.getLockNum()); map.put("lockName",ardTankLock.getLockName()); map.put("imgPositionTop",ardTankLock.getImgPositionTop()); map.put("imgPositionLeft",ardTankLock.getImgPositionLeft()); map.put("carId",ardTankLock.getCarId()); map.put("enable",ardTankLock.getEnable()); if(ardTankLock.getRestartState() == null){ map.put("restartState",""); }else{ map.put("restartState",ardTankLock.getRestartState()); } if(ardTankLock.getOnlineTime() == null){ map.put("onlineTime",""); }else{ map.put("onlineTime",ardTankLock.getOnlineTime()); } Map syResult = sYClient.getCarNearPositionByCarId(syURL, ardTankLock.getCarId(), ardSyUser.getUserId(), sessionId); if(((String)syResult.get("rspCode")).equals("1")){ Map carMap = ((List>)syResult.get("list")).get(0); map.put("carPlate", (String) carMap.get("carPlate")); } result.add(map); } } Long total = Long.valueOf(0); if(!carPlate.equals("")){ total = ardTankLockMapper.selectArdTankLockTotalByCarIdList(carIdList); }else{ total = ardTankLockMapper.selectArdTankLockAllTotal(); } Map mapResult = new HashMap(); mapResult.put("list",result); mapResult.put("total",total); return mapResult; } @Override public List getArdTankLockAll() { List result = ardTankLockMapper.getAll(); return result; } @Override public void sendLockState(String userId, String syUserId, String syPassword) { List syURLResult = sysConfigMapper.selectByType("syCarPT"); String syURL = ""; if(syURLResult.size() != 0){ syURL = syURLResult.get(0).getConfigValue(); }else{ return; } String passwordMd5 = DigestUtils.md5Hex(syPassword); Map LogInResult = sYClient.logIn(syURL, passwordMd5, syUserId); String sessionId = (String) LogInResult.get("sessionId"); List lockBatteryVoltageResult = sysConfigMapper.selectByType("lockBatteryVoltage"); Integer lockBatteryVoltage = 9; if(!lockBatteryVoltageResult.isEmpty()){ lockBatteryVoltage = Integer.parseInt(lockBatteryVoltageResult.get(0).getConfigValue()); } List lockPowerVoltageResult = sysConfigMapper.selectByType("lockPowerVoltage"); Integer lockPowerVoltage = 5; if(!lockPowerVoltageResult.isEmpty()){ lockPowerVoltage = Integer.parseInt(lockPowerVoltageResult.get(0).getConfigValue()); } List> result = new ArrayList(); List ardSyCarResult = ardSyCarMapper.selectArdSyCarAndTankLockByUserId(userId.split("_")[0]); for(ArdSyCar ardSyCar : ardSyCarResult){ Map map = new HashMap(); map.put("id",ardSyCar.getId()); map.put("carId",ardSyCar.getCarId()); map.put("carModel",ardSyCar.getCarModel()); map.put("carType",ardSyCar.getCarType()); map.put("carBrand",ardSyCar.getCarBrand()); map.put("deptId",ardSyCar.getDeptId()); map.put("carPicture",ardSyCar.getCarPicture()); Map syResult = sYClient.getCarNearPositionByCarId(syURL, ardSyCar.getCarId(), syUserId, sessionId); if(((String)syResult.get("rspCode")).equals("1")){ Map carMap = ((List>)syResult.get("list")).get(0); map.put("carPlate", (String) carMap.get("carPlate")); } List> lockList = new ArrayList(); List ardTankLockList = ardSyCar.getArdTankLockList(); for(ArdTankLock ardTankLock : ardTankLockList){ Map lockMap = new HashMap(); lockMap.put("id",ardTankLock.getId()); lockMap.put("lockNum",ardTankLock.getLockNum()); lockMap.put("lockName",ardTankLock.getLockName()); lockMap.put("imgPositionTop",ardTankLock.getImgPositionTop()); lockMap.put("imgPositionLeft",ardTankLock.getImgPositionLeft()); lockMap.put("carId",ardTankLock.getCarId()); lockMap.put("enable",ardTankLock.getEnable()); if(ardTankLock.getRestartState() == null){ lockMap.put("restartState",""); }else{ lockMap.put("restartState",ardTankLock.getRestartState()); } if(ardTankLock.getOnlineTime() == null){ lockMap.put("onlineTime",""); }else{ lockMap.put("onlineTime",ardTankLock.getOnlineTime()); } //Map ardTankLockState = new HashMap(); ArdTankLockState ardTankLockStateResult = ardTankLockStateMapper.selectArdTankLockStateByLockIdLimitOne(ardTankLock.getId()); if(ardTankLockStateResult == null){ /*ardTankLockState.put("id",""); ardTankLockState.put("lockId",""); ardTankLockState.put("lockNum","");*/ /*ardTankLockState.put("lockState",""); ardTankLockState.put("lockPositionState",""); ardTankLockState.put("lockShellState",""); ardTankLockState.put("restartState",""); ardTankLockState.put("batterVoltage",""); ardTankLockState.put("batterVoltageAlarm",false); ardTankLockState.put("powerVoltage",""); ardTankLockState.put("powerVoltageAlarm",false); ardTankLockState.put("uploadTime",""); ardTankLockState.put("uniqueMark",""); ardTankLockState.put("lockStateMark",false); lockMap.put("ardTankLockState",ardTankLockState);*/ lockMap.put("lockState",""); lockMap.put("lockPositionState",""); lockMap.put("lockShellState",""); lockMap.put("restartState",""); lockMap.put("batterVoltage",""); lockMap.put("batterVoltageAlarm",false); lockMap.put("powerVoltage",""); lockMap.put("powerVoltageAlarm",false); lockMap.put("uploadTime",""); lockMap.put("uniqueMark",""); lockMap.put("lockStateMark",false); lockMap.put("alarmMark",false); lockMap.put("alarmInfo",""); }else{ /*ardTankLockState.put("id",ardTankLockStateResult.getId()); ardTankLockState.put("lockId",ardTankLockStateResult.getLockId()); ardTankLockState.put("lockNum",ardTankLockStateResult.getLockNum());*/ /*ardTankLockState.put("lockState",ardTankLockStateResult.getLockState()); ardTankLockState.put("lockPositionState",ardTankLockStateResult.getLockPositionState()); ardTankLockState.put("lockShellState",ardTankLockStateResult.getLockShellState()); ardTankLockState.put("restartState",ardTankLockStateResult.getRestartState()); ardTankLockState.put("batterVoltage",ardTankLockStateResult.getBatterVoltage()); if(Double.parseDouble(ardTankLockStateResult.getBatterVoltage()) <= lockBatteryVoltage){ ardTankLockState.put("batterVoltageAlarm",true); }else{ ardTankLockState.put("batterVoltageAlarm",false); } ardTankLockState.put("powerVoltage",ardTankLockStateResult.getPowerVoltage()); if(Double.parseDouble(ardTankLockStateResult.getPowerVoltage()) <= lockPowerVoltage){ ardTankLockState.put("powerVoltageAlarm",true); }else{ ardTankLockState.put("powerVoltageAlarm",false); } ardTankLockState.put("uploadTime",ardTankLockStateResult.getUploadTime()); ardTankLockState.put("uniqueMark",ardTankLockStateResult.getUniqueMark()); ardTankLockState.put("lockStateMark",ardTankLockStateResult.getLockStateMark()); lockMap.put("ardTankLockState",ardTankLockState);*/ String alarmInfo = ""; lockMap.put("lockState",ardTankLockStateResult.getLockState()); if(ardTankLockStateResult.getLockState().equals("异常状态")){ alarmInfo = alarmInfo + "锁芯异常;"; } lockMap.put("lockPositionState",ardTankLockStateResult.getLockPositionState()); if(ardTankLockStateResult.getLockPositionState().equals("异常")){ alarmInfo = alarmInfo + "位置异常;"; } lockMap.put("lockShellState",ardTankLockStateResult.getLockShellState()); if(ardTankLockStateResult.getLockShellState().equals("异常")){ alarmInfo = alarmInfo + "外壳异常;"; } lockMap.put("restartState",ardTankLockStateResult.getRestartState()); lockMap.put("batterVoltage",ardTankLockStateResult.getBatterVoltage()); if(Double.parseDouble(ardTankLockStateResult.getBatterVoltage()) <= lockBatteryVoltage){ lockMap.put("batterVoltageAlarm",true); alarmInfo = alarmInfo + "电池电压低于" + lockBatteryVoltage + ";"; }else{ lockMap.put("batterVoltageAlarm",false); } lockMap.put("powerVoltage",ardTankLockStateResult.getPowerVoltage()); if(Double.parseDouble(ardTankLockStateResult.getPowerVoltage()) <= lockPowerVoltage){ lockMap.put("powerVoltageAlarm",true); alarmInfo = alarmInfo + "电源电压低于" + lockBatteryVoltage + ";"; }else{ lockMap.put("powerVoltageAlarm",false); } lockMap.put("uploadTime",ardTankLockStateResult.getUploadTime()); lockMap.put("uniqueMark",ardTankLockStateResult.getUniqueMark()); lockMap.put("lockStateMark",ardTankLockStateResult.getLockStateMark()); if(alarmInfo.equals("")){ lockMap.put("alarmMark",false); }else{ lockMap.put("alarmMark",true); } lockMap.put("alarmInfo",alarmInfo); } lockList.add(lockMap); } map.put("lockList",lockList); result.add(map); Map data = new HashMap(); data.put("40002",result); WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(userId), JSON.toJSONString(data)); } } @Override public void getAlarm(String syUserId,String syPassword) { List syURLResult = sysConfigMapper.selectByType("syCarPT"); String syURL = ""; if(syURLResult.size() != 0){ syURL = syURLResult.get(0).getConfigValue(); }else{ return; } String finalSyURL = syURL; String passwordMd5 = DigestUtils.md5Hex(syPassword); Map LogInResult = sYClient.logIn(syURL, passwordMd5, syUserId); String sessionId = (String) LogInResult.get("sessionId"); List ardTankLockResult = ardTankLockMapper.getAll(); for(ArdTankLock ardTankLock : ardTankLockResult){ if(this.alarmMap.get(ardTankLock.getLockNum()) != null){ continue;//当前锁已在获取报警,不在创建线程 } Thread thread = new Thread(finalSyURL){ @Override public void run() { try{ String lockNum = ardTankLock.getLockNum(); String lockNumHead = lockNum.substring(0,2); String lockNumTail = lockNum.substring(2,4); String checkNum = Integer.toHexString(Integer.parseInt(lockNumHead, 16)//锁编号高8位 + Integer.parseInt(lockNumTail, 16)//锁编号低8位 + Integer.parseInt("06", 16));//设置锁芯状态功能码06 if(checkNum.length() == 1){ checkNum = "0" + checkNum; } if(checkNum.length() > 2){ checkNum = checkNum.substring(checkNum.length() - 2,checkNum.length()); } String paramsStr = lockNum + "06" + checkNum; paramsStr = "%7B%22type%22%3A%22ff%22%2C%22dataCnt%22%3A%22" + paramsStr + "%22%7D"; Map result = sendCmd(finalSyURL, syUserId, ardTankLock.getCarId(), 199, "DataDownTransfer", paramsStr, sessionId); alarmMap.remove(ardTankLock.getLockNum()); }catch(Exception e){ e.printStackTrace(); } } }; thread.start(); alarmMap.put(ardTankLock.getLockNum(),thread); } } public Map sendCmd(String syURL,String userId,String carId,Integer cmdId,String cmd,String paramsStr,String sessionId){ OkHttpClient okHttpClient = new OkHttpClient(); Request request = new Request.Builder() .url(syURL + "/gps-web/api/send_cmd.jsp?params="+paramsStr+"&userId="+userId+"&carId="+carId+"&cmdId="+cmdId+"&cmd="+cmd+"&sessionId="+sessionId) .build(); //System.out.println("url = " + syURL + "/gps-web/api/send_cmd.jsp?params="+paramsStr+"&userId="+userId+"&carId="+carId+"&cmdId="+cmdId+"&cmd="+cmd+"&sessionId="+sessionId); Response response = null; try { response = okHttpClient.newCall(request).execute(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } okhttp3.ResponseBody responseBody = response.body(); try { String message = responseBody.string();// 响应体 Map map = (Map) com.alibaba.fastjson2.JSON.parse(message); return map; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return new HashMap(); } } }