| | |
| | | |
| | | import java.util.*; |
| | | |
| | | import com.dtflys.forest.annotation.Var; |
| | | 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.mapper.ArdSyUserMapper; |
| | | import com.ruoyi.sy.mapper.ArdTankWallLockMapper; |
| | | import com.ruoyi.sy.mapper.ArdTankWallLockTemporaryMapper; |
| | | 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.result.Results; |
| | | import com.ruoyi.utils.websocket.util.WebSocketUtils; |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.stream.Collectors; |
| | | |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.sy.mapper.ArdTankLockMapper; |
| | | 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业务层处理 |
| | |
| | | |
| | | @Resource |
| | | private SysConfigMapper sysConfigMapper; |
| | | |
| | | @Resource |
| | | private ArdSyCarMapper ardSyCarMapper; |
| | | |
| | | @Resource |
| | | private ArdTankLockStateMapper ardTankLockStateMapper; |
| | | |
| | | @Resource |
| | | private SYClient sYClient; |
| | |
| | | /** |
| | | * 新增电磁锁 |
| | | * |
| | | * @param ardTankLock 电磁锁 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | //public Results List<Map<String,Object>> getAll(String usersId) { |
| | | public List<Map<String,Object>> getAll(String usersId) { |
| | | public Map<String,Object> getAll(String usersId) { |
| | | List<ArdTankLock> ardTankLockList = ardTankLockMapper.getAll(); |
| | | ArdSyUser ardSyUser = ardSyUserMapper.userById(usersId); |
| | | /*if(ardSyUser == null){ |
| | | return Results.error("没有挂接三一车辆用户"); |
| | | }*/ |
| | | if(ardSyUser == null){ |
| | | return new HashMap(); |
| | | } |
| | | List<SysConfig> syURLResult = sysConfigMapper.selectByType("syCarPT"); |
| | | String syURL = ""; |
| | | if(syURLResult.size() != 0){ |
| | | syURL = syURLResult.get(0).getConfigValue(); |
| | | }/*else{ |
| | | return Results.error("三一车辆地址未录入"); |
| | | }*/ |
| | | }else{ |
| | | return new HashMap(); |
| | | } |
| | | String passwordMd5 = DigestUtils.md5Hex(ardSyUser.getPassword()); |
| | | Map<String, Object> LogInResult = sYClient.logIn(syURL, passwordMd5, ardSyUser.getUserId()); |
| | | String sessionId = (String) LogInResult.get("sessionId"); |
| | | List<ArdTankLock> ardTankLockList = ardTankLockMapper.getAll(); |
| | | //List<ArdTankLock> ardTankLockList = ardTankLockMapper.getAll(); |
| | | List<Map<String,Object>> result = new ArrayList(); |
| | | for(ArdTankLock ardTankLock : ardTankLockList){ |
| | | Map<String,Object> map = new HashMap(); |
| | |
| | | } |
| | | } |
| | | } |
| | | //return Results.succeed(result0); |
| | | return result0; |
| | | Long total = ardTankLockMapper.selectArdTankLockTotal(); |
| | | Map<String,Object> resultMap = new HashMap(); |
| | | resultMap.put("list",result0); |
| | | resultMap.put("total",total); |
| | | return resultMap; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getLockByCarId(String carId, String usersId) { |
| | | ArdSyUser ardSyUser = ardSyUserMapper.userById(usersId); |
| | | /*if(ardSyUser == null){ |
| | | return Results.error("没有挂接三一车辆用户"); |
| | | }*/ |
| | | if(ardSyUser == null){ |
| | | return new HashMap(); |
| | | } |
| | | List<SysConfig> syURLResult = sysConfigMapper.selectByType("syCarPT"); |
| | | String syURL = ""; |
| | | if(syURLResult.size() != 0){ |
| | | syURL = syURLResult.get(0).getConfigValue(); |
| | | }/*else{ |
| | | return Results.error("三一车辆地址未录入"); |
| | | }*/ |
| | | }else{ |
| | | return new HashMap(); |
| | | } |
| | | String passwordMd5 = DigestUtils.md5Hex(ardSyUser.getPassword()); |
| | | Map<String, Object> LogInResult = sYClient.logIn(syURL, passwordMd5, ardSyUser.getUserId()); |
| | | String sessionId = (String) LogInResult.get("sessionId"); |
| | |
| | | }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<String,Object> carMap = ((List<Map<String,Object>>)syResult.get("list")).get(0); |
| | | map.put("carPlate",carMap.get("carPlate")); |
| | | result.add(map); |
| | |
| | | } |
| | | //Set<String> newIdSet = new HashSet();//传参的主键 |
| | | List<Map<String,Object>> lockList = (List<Map<String, Object>>) para.get("lockList"); |
| | | if(lockList.isEmpty()){//数组为空,做删除操作 |
| | | if(ardTankLockOldList.isEmpty()){//若没有挂接,不做操作 |
| | | return 1; |
| | | } |
| | | result = ardTankLockMapper.deleteLockByCarId(carId); |
| | | return result; |
| | | } |
| | | |
| | | List<ArdTankLock> ardTankLocks = new ArrayList(); |
| | | for(Map<String,Object> map : lockList){ |
| | | if(map.get("id") != null){//有主键,做修改操作 |
| | |
| | | ardTankLock.setCarId((String) map.get("carId")); |
| | | ardTankLock.setEnable((String) map.get("enable")); |
| | | result = result + ardTankLockMapper.updateArdTankLock(ardTankLock); |
| | | }else{//无主键,做修改操作 |
| | | }else{//无主键,做新增操作 |
| | | ArdTankLock ardTankLock = new ArdTankLock(); |
| | | ardTankLock.setId(IdUtils.simpleUUID()); |
| | | ardTankLock.setLockNum((String) map.get("lockNum")); |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String,Object> getLockByCarPlate(String usersId, String carPlate, Integer pageNum, Integer pageSize) { |
| | | ArdSyUser ardSyUser = ardSyUserMapper.userById(usersId); |
| | | if(ardSyUser == null){ |
| | | return new HashMap(); |
| | | } |
| | | List<SysConfig> 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<String, Object> LogInResult = sYClient.logIn(syURL, passwordMd5, ardSyUser.getUserId()); |
| | | String sessionId = (String) LogInResult.get("sessionId"); |
| | | List<ArdTankLock> ardTankLockList = new ArrayList(); |
| | | List<Map<String,Object>> result = new ArrayList(); |
| | | List<String> carIdList = new ArrayList();//记录三一车辆主键 |
| | | if(!carPlate.equals("")){ |
| | | Map<String,Object> carMap = sYClient.getCarListByPlate(syURL,carPlate,ardSyUser.getUserId(),sessionId);//车牌号模糊搜索车辆 |
| | | List<Map<String,Object>> carList = new ArrayList(); |
| | | if(((String)carMap.get("rspCode")).equals("1")){ |
| | | carList = (List<Map<String, Object>>) carMap.get("list"); |
| | | }else{ |
| | | return new HashMap(); |
| | | } |
| | | //List<String> carIdList = new ArrayList();//记录三一车辆主键 |
| | | for(Map<String,Object> 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<String,Object> 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<String,Object> 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<String,Object> 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<String,Object> syResult = sYClient.getCarNearPositionByCarId(syURL, ardTankLock.getCarId(), ardSyUser.getUserId(), sessionId); |
| | | if(((String)syResult.get("rspCode")).equals("1")){ |
| | | Map<String,Object> carMap = ((List<Map<String,Object>>)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<String,Object> mapResult = new HashMap(); |
| | | mapResult.put("list",result); |
| | | mapResult.put("total",total); |
| | | return mapResult; |
| | | } |
| | | |
| | | @Override |
| | | public List<ArdTankLock> getArdTankLockAll() { |
| | | List<ArdTankLock> result = ardTankLockMapper.getAll(); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public void sendLockState(String userId, String syUserId, String syPassword) { |
| | | List<SysConfig> syURLResult = sysConfigMapper.selectByType("syCarPT"); |
| | | String syURL = ""; |
| | | if(syURLResult.size() != 0){ |
| | | syURL = syURLResult.get(0).getConfigValue(); |
| | | }else{ |
| | | return; |
| | | } |
| | | String passwordMd5 = DigestUtils.md5Hex(syPassword); |
| | | Map<String, Object> LogInResult = sYClient.logIn(syURL, passwordMd5, syUserId); |
| | | String sessionId = (String) LogInResult.get("sessionId"); |
| | | |
| | | List<SysConfig> lockBatteryVoltageResult = sysConfigMapper.selectByType("lockBatteryVoltage"); |
| | | Integer lockBatteryVoltage = 9; |
| | | if(!lockBatteryVoltageResult.isEmpty()){ |
| | | lockBatteryVoltage = Integer.parseInt(lockBatteryVoltageResult.get(0).getConfigValue()); |
| | | } |
| | | |
| | | List<SysConfig> lockPowerVoltageResult = sysConfigMapper.selectByType("lockPowerVoltage"); |
| | | Integer lockPowerVoltage = 5; |
| | | if(!lockPowerVoltageResult.isEmpty()){ |
| | | lockPowerVoltage = Integer.parseInt(lockPowerVoltageResult.get(0).getConfigValue()); |
| | | } |
| | | |
| | | List<Map<String,Object>> result = new ArrayList(); |
| | | List<ArdSyCar> ardSyCarResult = ardSyCarMapper.selectArdSyCarAndTankLockByUserId(userId.split("_")[0]); |
| | | for(ArdSyCar ardSyCar : ardSyCarResult){ |
| | | Map<String,Object> 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<String,Object> syResult = sYClient.getCarNearPositionByCarId(syURL, ardSyCar.getCarId(), syUserId, sessionId); |
| | | if(((String)syResult.get("rspCode")).equals("1")){ |
| | | Map<String,Object> carMap = ((List<Map<String,Object>>)syResult.get("list")).get(0); |
| | | map.put("carPlate", (String) carMap.get("carPlate")); |
| | | } |
| | | List<Map<String,Object>> lockList = new ArrayList(); |
| | | List<ArdTankLock> ardTankLockList = ardSyCar.getArdTankLockList(); |
| | | for(ArdTankLock ardTankLock : ardTankLockList){ |
| | | Map<String,Object> 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<String,Object> 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); |
| | | }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); |
| | | } |
| | | lockList.add(lockMap); |
| | | } |
| | | map.put("lockList",lockList); |
| | | result.add(map); |
| | | Map<String,Object> data = new HashMap(); |
| | | data.put("40002",result); |
| | | WebSocketUtils.sendMessage(ONLINE_USER_SESSIONS.get(userId), JSON.toJSONString(data)); |
| | | } |
| | | } |
| | | } |