diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java index 056b1adf..a51c25e4 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java @@ -194,24 +194,57 @@ public class DcWarningServiceImpl implements IDcWarningService otherConfig = map.get("otherConfig").toString(); //取出原id的配置信息 } String otherConfigString = dcWarning.getOtherConfig();//新增的配置信息 + if (StringUtils.isBlank(otherConfig)&&StringUtils.isBlank(otherConfigString)){//数据为空不新增,直接走规则 + redisCache.setCacheObject(WARNINGDATA+key,dataId,Integer.parseInt(strategyTime),TimeUnit.MINUTES);//重新设置延迟时间 + return 1;//修改数据库配置 + } JSONObject jsonObjectOne = new JSONObject(otherConfig);//原始数据库数据 JSONObject jsonObjectTwo = new JSONObject(otherConfigString); - int picturesLength = jsonObjectOne.getJSONArray("pictures").length();//已经存在数据库的图片的长度 - if (picturesLength>=UniversalEnum.TEN.getNumber()&&jsonObjectTwo.get("pictures")!=null){//如果数据长度大于等于10,对第十位进行替换 - JSONArray pictures = jsonObjectOne.getJSONArray("pictures");//获取图片数组 - pictures.put(picturesLength-UniversalEnum.ONE.getNumber(),jsonObjectTwo.getJSONArray("pictures").getString(UniversalEnum.ZERO.getNumber())); //替换第十个元素 - jsonObjectOne.put("pictures", pictures);//更新 jsonObjectOne中的pictures 数组 - int videoListLength = jsonObjectOne.getJSONArray("pictures").length();//已经存在数据库的视频的长度 - if (videoListLength>=UniversalEnum.TEN.getNumber()&&jsonObjectTwo.get("videoList")!=null){ - JSONArray videoList = jsonObjectOne.getJSONArray("videoList"); - videoList.put(videoListLength-UniversalEnum.ONE.getNumber(),jsonObjectTwo.getJSONArray("videoList").getString(UniversalEnum.ZERO.getNumber())); - jsonObjectOne.put("videoList",videoList); + JSONArray picturesArrayPic = null; + if (jsonObjectOne != null && jsonObjectOne.has("pictures")) {//验证图片是否存在 + picturesArrayPic = jsonObjectOne.getJSONArray("pictures"); + } + JSONArray picturesArrayVideo = null; + if (jsonObjectOne != null && jsonObjectOne.has("videoList")) {//验证视频是否存在 + picturesArrayVideo = jsonObjectOne.getJSONArray("videoList"); + } + if (picturesArrayVideo!=null||picturesArrayPic!=null) { + boolean a =false; + if (picturesArrayVideo != null) { + int videoListLength = jsonObjectOne.getJSONArray("pictures").length();//已经存在数据库的视频的长度 + if (videoListLength >= UniversalEnum.TEN.getNumber() && jsonObjectTwo.get("videoList") != null) { + JSONArray videoList = jsonObjectOne.getJSONArray("videoList"); + videoList.put(videoListLength - UniversalEnum.ONE.getNumber(), jsonObjectTwo.getJSONArray("videoList").getString(UniversalEnum.ZERO.getNumber())); + jsonObjectOne.put("videoList", videoList); + a=true; + } + } + if (picturesArrayPic != null) { + int picturesLength = jsonObjectOne.getJSONArray("pictures").length();//已经存在数据库的图片的长度 + if (picturesLength >= UniversalEnum.TEN.getNumber() && jsonObjectTwo.get("pictures") != null) {//如果数据长度大于等于10,对第十位进行替换 + JSONArray pictures = jsonObjectOne.getJSONArray("pictures");//获取图片数组 + pictures.put(picturesLength - UniversalEnum.ONE.getNumber(), jsonObjectTwo.getJSONArray("pictures").getString(UniversalEnum.ZERO.getNumber())); //替换第十个元素 + jsonObjectOne.put("pictures", pictures);//更新 jsonObjectOne中的pictures 数组 + a=true; + } + } + if (a==true){ + redisCache.setCacheObject(WARNINGDATA + key, dataId, Integer.parseInt(strategyTime), TimeUnit.MINUTES);//重新设置延迟时间 + return dcWarningMapper.updateOtherConfig(dataId, jsonObjectOne.toString(), dcWarning.getEndTime());//修改数据库配置 } - redisCache.setCacheObject(WARNINGDATA+key,dataId,Integer.parseInt(strategyTime),TimeUnit.MINUTES);//重新设置延迟时间 - return dcWarningMapper.updateOtherConfig(dataId,jsonObjectOne.toString(),dcWarning.getEndTime());//修改数据库配置 } DcWarningServiceImpl dcWarningService = new DcWarningServiceImpl();//合成工具类 JSONObject jsonObject = dcWarningService.mergeJsonObjects(jsonObjectOne, jsonObjectTwo); + if (jsonObject==null){ //没有进行合成或则合成后的数据为null + redisCache.setCacheObject(WARNINGDATA+key,dataId,Integer.parseInt(strategyTime),TimeUnit.MINUTES);//重新设置延迟时间 + if (jsonObjectOne!=null) { + return dcWarningMapper.updateOtherConfig(dataId, jsonObjectOne.toString(), dcWarning.getEndTime());//修改数据库配置 + }else if (jsonObjectTwo!=null){ + return dcWarningMapper.updateOtherConfig(dataId, jsonObjectTwo.toString(), dcWarning.getEndTime());//修改数据库配置 + }else { + return dcWarningMapper.updateOtherConfig(dataId, "", dcWarning.getEndTime());//修改数据库配置 + } + } redisCache.setCacheObject(WARNINGDATA+key,dataId,Integer.parseInt(strategyTime),TimeUnit.MINUTES);//重新设置延迟时间 return dcWarningMapper.updateOtherConfig(dataId, jsonObject.toString(),dcWarning.getEndTime());//修改数据库配置 }