fengxiang
2018-05-15 f600872a54da4b41ed137c3361f685604e47ee9d
编辑 设备 redis里组织id清空bug修复。
5 files modified
54 ■■■■ changed files
src/main/java/com/moral/controller/AreaController.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/controller/ScreenController.java 3 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/AreaService.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/AreaServiceImpl.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/DeviceServiceImpl.java 41 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/controller/AreaController.java
@@ -1,6 +1,5 @@
package com.moral.controller;
import com.moral.common.bean.Constants;
import com.moral.common.bean.ResultBean;
import com.moral.entity.Area;
import com.moral.entity.City;
@@ -20,7 +19,10 @@
public class AreaController {
     @Resource
     AreaService areaService;
   @GetMapping("getfullnames")
    public ResultBean<String> getFullNames(Integer code){
      return new ResultBean<>(areaService.queryFullNameByCode(code));
    }
    @GetMapping("get-provinces")
     public ResultBean<List<Province>> getProvinces(){
         ResultBean<List<Province>> resultBean = new ResultBean<>();
src/main/java/com/moral/controller/ScreenController.java
@@ -36,7 +36,6 @@
import org.springframework.web.servlet.ModelAndView;
import org.xml.sax.InputSource;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.moral.common.bean.Constants;
@@ -374,7 +373,7 @@
    @RequestMapping(value = "/map-page", method = RequestMethod.GET)
    public ModelAndView map(ModelAndView model, @RequestParam("areaCode")int code, @RequestParam("accountId")int accountId){
        Account account = accountService.getAccountById(accountId);
        String regionName = areaService.selectFullNameByCode(code);
        String regionName = areaService.queryFullNameByCode(code);
        if(account!=null&&regionName!=null){
            //去除空格
            regionName = regionName.replace(" ","");
src/main/java/com/moral/service/AreaService.java
@@ -11,5 +11,5 @@
    List<City> getCities(int provinceCode);
    List<Area> getAreas(int cityCode);
    String selectFullNameByCode(Integer code);
    String queryFullNameByCode(Integer code);
}
src/main/java/com/moral/service/impl/AreaServiceImpl.java
@@ -48,7 +48,7 @@
     * @return
     */
    @Override
    public String selectFullNameByCode(Integer code){
    public String queryFullNameByCode(Integer code){
        String codeStr = code.toString();
        String fullName = "";
        // 此时为地区code
src/main/java/com/moral/service/impl/DeviceServiceImpl.java
@@ -105,7 +105,7 @@
            deviceMapper.updateByPrimaryKeySelective(device);
        }
        //刷新redis里的信息
        refreshDeviceInRedis(device);
        refreshDeviceInRedis(device.getMac());
    }
    @Override
@@ -273,26 +273,27 @@
        }
        return device;
    }
    /*
      刷新 redis 设备的信息
    /**
     * 要在数据库更改后刷新
     * 刷新 redis 设备的信息
     * @param mac
     */
    private void refreshDeviceInRedis(Device device){
         if(!StringUtils.isBlank(device.getMac())){
//             Device simpleDevice = new Device();
//             simpleDevice.setId(device.getId());// id
//             simpleDevice.setName(device.getName());// name
//             simpleDevice.setAddress(device.getAddress());// address
//             simpleDevice.setDeviceVersionId(device.getDeviceVersionId());// version
//             simpleDevice.setMac(device.getMac()); // mac
//             simpleDevice.setMonitorPointId(device.getMonitorPointId());// 监控地id
//             simpleDevice.setOrganizationIds(device.getOrganizationIds());// 组织数组
             if(device.getMonitorPointId()!=null){
                 List<Integer> orgIds = monitorPointMapper.selectOrganizationIds(device.getMonitorPointId());
                 device.setOrganizationIds(orgIds);
             }
             String key = "device_"+device.getMac();
    private void refreshDeviceInRedis(String mac){
         if(!StringUtils.isBlank(mac)){
              Device devQuery = new Device();
              devQuery.setMac(mac);
              Device device = deviceMapper.selectOne(devQuery);
              if(device.getMonitorPointId()!=null){
                  List<Integer> orgIds = monitorPointMapper.selectOrganizationIds(device.getMonitorPointId());
                  device.setOrganizationIds(orgIds);
             }
             String key = "device_"+mac;
             redisUtils.set(key,device);
         }
         }else
         {
             log.warn("param mac is null in method [refreshDeviceInRedis]");
         }
    }
    @Override
    public int countByExample(PageBean pageBean){
@@ -358,7 +359,7 @@
                deviceMapper.updateByPrimaryKeySelective(device);
            }
            //刷新redis里设备信息
            refreshDeviceInRedis(device);
            refreshDeviceInRedis(device.getMac());
        }
        catch (Exception ex){
            throw  ex;