src/main/java/com/moral/controller/MobileController.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/entity/Device.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/service/DeviceService.java | ●●●●● patch | view | raw | blame | history | |
src/main/java/com/moral/service/impl/DeviceServiceImpl.java | ●●●●● patch | view | raw | blame | history | |
src/main/resources/mapper/DeviceMapper.xml | ●●●●● patch | view | raw | blame | history |
src/main/java/com/moral/controller/MobileController.java
@@ -2,6 +2,7 @@ import static com.moral.common.util.WebUtils.getParametersStartingWith; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -12,6 +13,7 @@ import com.moral.util.MessageUtils; import com.taobao.api.ApiException; import org.apache.commons.lang3.StringUtils; import org.springframework.cglib.beans.BeanMap; import org.springframework.web.bind.annotation.*; import com.moral.common.bean.AppData; @@ -109,9 +111,12 @@ * @return the device by mac */ @GetMapping("getEquInfoByMac") public AppData<Device> getDeviceByMac(@RequestParam(value="mac", required=true)String mac) { Device device = deviceService.getDeviceByMac(mac); return new AppData<Device>(device); public AppData<Map> getDeviceByMac(@RequestParam(value="mac", required=true)String mac) { Device device = deviceService.getDeviceByMac(mac,false);//不从缓存取 Map<String,Object> deviceMap = new HashMap<>(BeanMap.create(device)); deviceMap.put("monitorpointDetail",deviceMap.get("monitorPoint")); deviceMap.remove("monitorPoint"); return new AppData<Map>(deviceMap); } /** @@ -190,9 +195,10 @@ } /** * Send SMS * * @param mobile * @param username * @param password * @param code * @return */ @PostMapping("password") src/main/java/com/moral/entity/Device.java
@@ -117,11 +117,9 @@ private OperateUser operateUser; @Transient private DeviceVersion deviceVersion; //@Transient //private MonitorPoint monitorPoint; @Transient private MonitorPoint monitorPoint; @Transient private List<Integer> organizationIds; @Transient private MonitorPoint monitorpointDetail; } src/main/java/com/moral/service/DeviceService.java
@@ -16,6 +16,8 @@ List<Device> getInstallDevicesByOperateUser(Integer uid, Integer pageIndex, Integer pageSize); Device getDeviceByMac(String mac, boolean fromCache); Device getDeviceByMac(String mac); List<Device> query(Map<String,Object> map); src/main/java/com/moral/service/impl/DeviceServiceImpl.java
@@ -104,6 +104,8 @@ device.setId(queryDevice.getId()); deviceMapper.updateByPrimaryKeySelective(device); } //刷新redis里的信息 refreshDeviceInRedis(device); } @Override @@ -115,9 +117,9 @@ List<Device> devices = deviceMapper.select(device); return devices; } @Override public Device getDeviceByMac(String mac) { public Device getDeviceByMac (String mac ,boolean fromCache){ if(fromCache){ Device device = getDeviceFromRedis(mac); if(device==null) { device = deviceMapper.selectWithOrgIdsByMac(mac); @@ -126,6 +128,21 @@ } } return device; }else { return deviceMapper.selectWithOrgIdsByMac(mac); } } /** * 默认会从缓存取 * @param mac * @return */ @Override public Device getDeviceByMac(String mac) { return getDeviceByMac(mac,true); } /* * 获取报警阀值在redis里的key src/main/resources/mapper/DeviceMapper.xml
@@ -210,9 +210,11 @@ </select> <select id="selectWithOrgIdsByMac" parameterType="java.lang.String" resultMap="BaseResultWithOrgIdsMap"> select id,device_version_id,mac,monitor_point_id from device where mac = #{mac,jdbcType=VARCHAR} dev.*, mpt.name as monitor_point_name from device dev left join monitor_point mpt on dev.monitor_point_id = mpt.id where dev.mac = #{mac,jdbcType=VARCHAR} </select> <select id="getDeviceCountByRegion" resultType="java.lang.Integer">