| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import com.aliyuncs.iot.model.v20180120.BatchGetDeviceStateResponse; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.service.impl.BaseServiceImpl; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.mainboard.MainBoardInvokeSyncService; |
| | | import com.sandu.ximon.admin.param.LampPostParam; |
| | | import com.sandu.ximon.admin.security.CountSet; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.dao.domain.LampCount; |
| | | import com.sandu.ximon.dao.domain.LampPost; |
| | | import com.sandu.ximon.dao.mapper.LampCountMapper; |
| | | import com.sandu.ximon.dao.mapper.ClientMapper; |
| | | import com.sandu.ximon.dao.mapper.LampPostMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | |
| | | public class LampPostService extends BaseServiceImpl<LampPostMapper, LampPost> { |
| | | private final CountSet countSet; |
| | | private final LampCountService lampCountService; |
| | | private final ClientMapper clientMapper; |
| | | private final LampPostMapper lampPostMapper; |
| | | |
| | | public void addLamp(LampPostParam lampPostParam){ |
| | | LampPost lampPost=new LampPost(); |
| | | public boolean addLamp(LampPostParam lampPostParam) { |
| | | LampPost lampPost = new LampPost(); |
| | | // lampPost.setId(snowflake.nextId()); |
| | | Long userId = SecurityUtils.getUserId(); |
| | | lampPost.setUserId(userId); |
| | | lampPost.setLampId(countSet.aVoid()); |
| | | lampPost.setName(lampPostParam.getName()); |
| | | lampPost.setMacCode("虚拟灯杆"); |
| | | lampPost.setGroup(null); |
| | | lampPost.setState("正常"); |
| | | lampPost.setBound(null); |
| | | lampPost.setBelongs(lampPostParam.getBelongs()); |
| | | lampPost.setAddress(lampPostParam.getAddress()); |
| | | if (lampPostParam.getBelongsClient() != null) { |
| | | Long clientId = clientMapper.findClientIdByName(lampPostParam.getBelongsClient()); |
| | | lampPost.setBelongsClient(lampPostParam.getBelongsClient()); |
| | | lampPost.setClientId(clientId); |
| | | } |
| | | if (lampPostParam.getMacCode() == null) { |
| | | lampPost.setMacCode("虚拟灯杆"); |
| | | } else { |
| | | lampPost.setMacCode(lampPostParam.getMacCode()); |
| | | } |
| | | lampPost.setState(1); |
| | | boolean save = save(lampPost); |
| | | |
| | | if(!save){ |
| | | if (!save) { |
| | | LampCount lampCount = lampCountService.list().get(0); |
| | | lampCount.setCount(lampCount.getCount()-1); |
| | | lampCount.setCount(lampCount.getCount() - 1); |
| | | lampCountService.updateById(lampCount); |
| | | } |
| | | |
| | | return save; |
| | | |
| | | } |
| | | |
| | | public void updateLamp(Long id,LampPostParam lampPostParam){ |
| | | |
| | | |
| | | public boolean updateLamp(Long id, LampPostParam lampPostParam) { |
| | | LampPost lampPost = new LampPost(); |
| | | LampPost byId = getById(id); |
| | | if (byId == null) { |
| | | throw new BusinessException("未找到该灯杆"); |
| | | } |
| | | lampPost.setId(id); |
| | | lampPost.setName(lampPostParam.getName()); |
| | | lampPost.setAddress(lampPostParam.getAddress()); |
| | | if (lampPostParam.getBelongsClient() != null) { |
| | | Long clientId = clientMapper.findClientIdByName(lampPostParam.getBelongsClient()); |
| | | lampPost.setBelongsClient(lampPostParam.getBelongsClient()); |
| | | lampPost.setClientId(clientId); |
| | | } |
| | | if (lampPostParam.getMacCode() == null) { |
| | | lampPost.setMacCode("虚拟灯杆"); |
| | | } else { |
| | | lampPost.setMacCode(lampPostParam.getMacCode()); |
| | | } |
| | | return updateById(lampPost); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * |
| | | * @param group |
| | | * @param lampPosts |
| | | *编辑分组--选择灯杆 |
| | | * @param Id 编辑分组--选择灯杆 |
| | | */ |
| | | |
| | | public void setGroup(String group, List<LampPost> lampPosts){ |
| | | for (LampPost lamp:lampPosts |
| | | ) { |
| | | lamp.setGroup(group); |
| | | updateById(lamp); |
| | | public void setGroup(String group, List<Long> Id) { |
| | | // List<LampPost> update=new ArrayList<>(); |
| | | for (Long id : Id |
| | | ) { |
| | | lampPostMapper.serGroup(group, id); |
| | | } |
| | | |
| | | // return updateBatchById(update); |
| | | } |
| | | |
| | | public List<LampPost> listLamp() { |
| | | List<LampPost> list = lampPostMapper.listLamp(); |
| | | // List<LampPost> list = list(Wrappers.lambdaQuery(LampPost.class)); |
| | | return list; |
| | | |
| | | } |
| | | |
| | | public List<LampPost> queryStates() { |
| | | // List<LampPost> list = list(Wrappers.lambdaQuery(LampPost.class).eq(LampPost::getClientId, SecurityUtils.getUserId())); |
| | | List<LampPost> list = list(Wrappers.lambdaQuery(LampPost.class)); |
| | | List<String> MacCodes = new ArrayList<>(); |
| | | |
| | | for (LampPost post : list) { |
| | | MacCodes.add(post.getMacCode()); |
| | | } |
| | | List<BatchGetDeviceStateResponse.DeviceStatus> deviceStatuses = MainBoardInvokeSyncService.getInstance().batchGetDeviceState(MacCodes); |
| | | for (LampPost post : list) { |
| | | for (BatchGetDeviceStateResponse.DeviceStatus deviceStatus : deviceStatuses) { |
| | | if(post.getMacCode().equals(deviceStatus.getDeviceName())){ |
| | | post.setOnLineState(deviceStatus.getStatus()); |
| | | } |
| | | } |
| | | MacCodes.add(post.getMacCode()); |
| | | } |
| | | |
| | | |
| | | return list; |
| | | } |
| | | |
| | | |