package com.fzzy.gateway.service; import com.bstek.dorado.annotation.DataResolver; import com.fzzy.api.utils.ContextUtil; import com.fzzy.gateway.GatewayUtils; import com.fzzy.gateway.entity.GatewayDevice; import com.fzzy.gateway.service.repository.GatewayDeviceRep; import org.springframework.beans.BeanUtils; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.List; @Component public class GatewayDeviceService2 { @Resource private GatewayDeviceRep gatewayDeviceRep; public List listAll() { Sort sort = new Sort(Sort.Direction.ASC, "deviceId"); return gatewayDeviceRep.findAll(sort); } /** * gatewayDeviceService2#updateSave * * @param data */ @DataResolver public void updateSave(GatewayDevice data) { GatewayDevice data2 = new GatewayDevice(); BeanUtils.copyProperties(data, data2); if (null == data2.getDeviceSn()) { if (null != data2.getIp()) { data.setDeviceSn(data2.getIp()); } else { data.setDeviceSn(data2.getDeviceId()); } } if (null == data2.getId()) { data2.setId(ContextUtil.getUUID()); gatewayDeviceRep.save(data2); } else { gatewayDeviceRep.save(data2); } flushCache(); } public void flushCache() { List list = listAll(); if (null == list || list.isEmpty()) return; for (GatewayDevice device : list) { GatewayUtils.add2Cache(device); } } }