| | |
| | | import com.bstek.dorado.annotation.DataProvider; |
| | | import com.bstek.dorado.annotation.DataResolver; |
| | | import com.bstek.dorado.annotation.Expose; |
| | | import com.fzzy.api.Constant; |
| | | import com.fzzy.api.data.ApiCommonDevice; |
| | | import com.fzzy.api.utils.ContextUtil; |
| | | import com.fzzy.api.utils.RedisConst; |
| | | import com.fzzy.api.utils.RedisUtil; |
| | | import com.fzzy.async.fzzy40.Fzzy40CommonService; |
| | | import com.fzzy.gateway.GatewayUtils; |
| | | import com.fzzy.gateway.api.GatewayRemoteManager; |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.gateway.service.repository.GatewayDeviceRep; |
| | | import com.fzzy.mqtt.MqttProviderConfig; |
| | | import com.fzzy.mqtt.MqttPublishService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.HashMap; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class GatewayDeviceService { |
| | | |
| | |
| | | */ |
| | | @DataProvider |
| | | public List<GatewayDevice> listAll() { |
| | | return gatewayDeviceRep.findAll(); |
| | | Sort sort = new Sort(Sort.Direction.ASC, "deviceId"); |
| | | |
| | | |
| | | List<GatewayDevice> list = gatewayDeviceRep.findAll(sort); |
| | | |
| | | if (null == list || list.isEmpty()) return list; |
| | | |
| | | List<GatewayDevice> result = new ArrayList<>(); |
| | | |
| | | ApiCommonDevice apiCommonDevice; |
| | | for (GatewayDevice device : list) { |
| | | |
| | | apiCommonDevice = Constant.getCommonDeviceCache(device.getDeviceSn()); |
| | | if (null != apiCommonDevice) { |
| | | device.setIp(apiCommonDevice.getIp()); |
| | | device.setPort(apiCommonDevice.getPort()); |
| | | device.setStatus(apiCommonDevice.getStatus()); |
| | | device.setOnlineTime(apiCommonDevice.getOnlineTime()); |
| | | } |
| | | result.add(device); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | // /** |
| | | // * gatewayDeviceService#getQuery |
| | | // * |
| | | // * @return |
| | | // */ |
| | | // @DataProvider |
| | | // public GateWayTestParam getQuery() { |
| | | // GateWayTestParam param = new GateWayTestParam(); |
| | | // param.setDayTime(new Date()); |
| | | // param.setCarNumber("川A12345"); |
| | | // param.setEnd(new Date()); |
| | | // param.setStart(new Date()); |
| | | // param.setWeight(25000.00); |
| | | // return param; |
| | | // } |
| | | |
| | | /** |
| | | * gatewayDeviceService#updateSave |
| | | * |
| | | * @param entity |
| | | * @param data |
| | | */ |
| | | @DataResolver |
| | | public void updateSave(GatewayDevice entity) { |
| | | GatewayDevice data = new GatewayDevice(); |
| | | BeanUtils.copyProperties(entity, data); |
| | | public void updateSave(GatewayDevice data) { |
| | | GatewayDevice data2 = new GatewayDevice(); |
| | | BeanUtils.copyProperties(data, data2); |
| | | |
| | | if (null == data.getId()) { |
| | | data.setId(ContextUtil.getUUID()); |
| | | } |
| | | |
| | | |
| | | if (null == data.getDeviceSn()) { |
| | | if (null != entity.getIp()) { |
| | | data.setDeviceSn(entity.getIp()); |
| | | if (null == data2.getDeviceSn()) { |
| | | if (null != data2.getIp()) { |
| | | data.setDeviceSn(data2.getIp()); |
| | | } else { |
| | | data.setDeviceSn(data.getDeviceId()); |
| | | data.setDeviceSn(data2.getDeviceId()); |
| | | } |
| | | } |
| | | |
| | | gatewayDeviceRep.save(data); |
| | | |
| | | if (null == data2.getId()) { |
| | | data2.setId(ContextUtil.getUUID()); |
| | | gatewayDeviceRep.save(data2); |
| | | } else { |
| | | gatewayDeviceRep.save(data2); |
| | | } |
| | | flushCache(); |
| | | } |
| | | |
| | |
| | | return null; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * gatewayDeviceService#flushCache |
| | | */ |
| | | @Expose |
| | | public void flushCache() { |
| | | List<GatewayDevice> list = listAll(); |
| | | if (null == list || list.isEmpty()) return; |
| | |
| | | GatewayUtils.add2Cache(device); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Expose |
| | | public String test() { |
| | | log.info("-----------test-------------------"); |
| | | return "SUCCESS"; |
| | | } |
| | | } |