fengxiang
2018-05-08 5f549c4d7bb36ff4dc012fed9ee1e049dbf899a8
运维app getEquInfoByMac api
5 files modified
67 ■■■■■ changed files
src/main/java/com/moral/controller/MobileController.java 16 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/entity/Device.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/DeviceService.java 4 ●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/DeviceServiceImpl.java 33 ●●●● patch | view | raw | blame | history
src/main/resources/mapper/DeviceMapper.xml 8 ●●●●● 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,7 +16,9 @@
    List<Device> getInstallDevicesByOperateUser(Integer uid, Integer pageIndex, Integer pageSize);
    Device getDeviceByMac(String mac);
    Device getDeviceByMac(String mac, boolean fromCache);
    Device getDeviceByMac(String mac);
    List<Device> query(Map<String,Object> map);
    PageResult query(Integer orgId, String deviceName,Integer pageSize,Integer pageNo);
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,17 +117,32 @@
        List<Device> devices = deviceMapper.select(device);
        return devices;
    }
    @Override
    public  Device getDeviceByMac (String mac ,boolean fromCache){
        if(fromCache){
            Device device = getDeviceFromRedis(mac);
            if(device==null) {
                device = deviceMapper.selectWithOrgIdsByMac(mac);
                if(device!=null){
                    setDeviceToRedis(mac,device);
                }
            }
            return  device;
        }else {
            return  deviceMapper.selectWithOrgIdsByMac(mac);
        }
    }
    /**
     * 默认会从缓存取
     * @param mac
     * @return
     */
    @Override
    public Device getDeviceByMac(String mac) {
        Device device = getDeviceFromRedis(mac);
        if(device==null) {
            device = deviceMapper.selectWithOrgIdsByMac(mac);
            if(device!=null){
                setDeviceToRedis(mac,device);
            }
        }
        return device;
        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">