From b8ab6d74a7f5f8454e0ec8cf35fd008f8096fcb5 Mon Sep 17 00:00:00 2001 From: linbangquan <1437892690@qq.com> Date: Sat, 11 Nov 2023 13:17:55 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BF=AE=E5=A4=8D]=20=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE-=E4=B8=AA=E6=80=A7=E5=8C=96=E5=BC=B9?= =?UTF-8?q?=E7=AA=97=E6=8F=90=E9=86=92=E7=9A=84=E6=96=87=E6=A1=88=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1020779955716096]个人设置-个性化弹窗提醒的文案错误 http://192.168.0.96:8090/demo/rdm.html#/bug-detail/939050947543040/939050947543057/1020779955716096 --- .../tenant/api/user/UserProfileListApi.java | 114 +++++++------- .../tenant/api/user/UserProfileSaveApi.java | 143 ++++++++++-------- 2 files changed, 145 insertions(+), 112 deletions(-) diff --git a/src/main/java/neatlogic/module/tenant/api/user/UserProfileListApi.java b/src/main/java/neatlogic/module/tenant/api/user/UserProfileListApi.java index bd872984..a7b865d5 100644 --- a/src/main/java/neatlogic/module/tenant/api/user/UserProfileListApi.java +++ b/src/main/java/neatlogic/module/tenant/api/user/UserProfileListApi.java @@ -16,32 +16,27 @@ package neatlogic.module.tenant.api.user; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import neatlogic.framework.auth.core.AuthAction; -import neatlogic.framework.restful.constvalue.OperationTypeEnum; -import neatlogic.framework.restful.annotation.*; -import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; - -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; - +import neatlogic.framework.asynchronization.threadlocal.TenantContext; import neatlogic.framework.asynchronization.threadlocal.UserContext; import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.common.constvalue.IUserProfile; +import neatlogic.framework.common.constvalue.IUserProfileOperate; +import neatlogic.framework.common.util.ModuleUtil; import neatlogic.framework.dao.mapper.UserMapper; import neatlogic.framework.dto.UserProfileVo; +import neatlogic.framework.dto.module.ModuleVo; +import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; import neatlogic.framework.userprofile.UserProfileFactory; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.*; @Service @@ -57,7 +52,7 @@ public class UserProfileListApi extends PrivateApiComponentBase { @Override public String getName() { - return "用户个性化查询列表接口"; + return "nmtau.userprofilelistapi.getname"; } @Override @@ -66,11 +61,11 @@ public class UserProfileListApi extends PrivateApiComponentBase { } @Input({ - @Param( name="moduleId" , type=ApiParamType.STRING , desc="模块Id"), - @Param(name="name",type=ApiParamType.STRING,desc="操作个性化选项名") + @Param( name="moduleId" , type=ApiParamType.STRING , desc="common.moduleid"), + @Param(name="name",type=ApiParamType.STRING,desc="common.name") }) - @Output({@Param( explode = UserProfileVo.class , desc = "用户个性化查询接口")}) - @Description(desc = "用户个性化查询列表接口") + @Output({@Param( explode = UserProfileVo.class , desc = "common.tbodylist")}) + @Description(desc = "nmtau.userprofilelistapi.getname") @Override public Object myDoService(JSONObject jsonObj) throws Exception { String moduleId = jsonObj.getString("moduleId"); @@ -93,40 +88,57 @@ public class UserProfileListApi extends PrivateApiComponentBase { } } - List userProfileList = new ArrayList(); - Map userProfileMap = UserProfileFactory.getUserProfileMap(); - Set> entrySet = userProfileMap.entrySet(); - for(Entry entry:entrySet) { - UserProfileVo usrProfileVo = (UserProfileVo) entry.getValue().clone(); - if(StringUtils.isNotBlank(moduleId)&&!moduleId.equals(usrProfileVo.getModuleId())) { + List userProfileList = new ArrayList<>(); + List activeModuleIdList = new ArrayList<>(); + if (moduleId != null) { + activeModuleIdList.add(moduleId); + } else { + List activeModuleList = TenantContext.get().getActiveModuleList(); + for (ModuleVo moduleVo : activeModuleList) { + activeModuleIdList.add(moduleVo.getId()); + } + } + for (String activeModuleId : activeModuleIdList) { + List userProfiles = UserProfileFactory.getUserProfileListByModuleId(activeModuleId); + if (CollectionUtils.isEmpty(userProfiles)) { continue; } - String config = usrProfileVo.getConfig(); - JSONArray configObjArray = JSONArray.parseArray(config); - ListIterator configIterator = configObjArray.listIterator(); - while(configIterator.hasNext()) { - JSONObject configJson = (JSONObject)configIterator.next(); - if(StringUtils.isNotBlank(name)&&!name.equals(configJson.getString("value"))) { - configIterator.remove(); + UserProfileVo userProfileVo = new UserProfileVo(); + userProfileVo.setModuleId(activeModuleId); + userProfileVo.setModuleName(ModuleUtil.getModuleById(activeModuleId).getName()); + JSONArray userProfileArray = new JSONArray(); + for (IUserProfile userProfile : userProfiles) { + if (StringUtils.isNotBlank(name) && !Objects.equals(name, userProfile.getValue())) { continue; } - configJson.put("checked", 1); - JSONArray operateArray = configJson.getJSONArray("userProfileOperateList"); - if(CollectionUtils.isNotEmpty(operateArray)) { - for(Object operateObj:operateArray) { - JSONObject operateJson = (JSONObject)operateObj; - if(myUserProfileOperateMap.containsKey(usrProfileVo.getModuleId()+configJson.getString("value")+operateJson.getString("value"))) { - operateJson.put("checked", 1); - configJson.put("checked", 0); - }else { - operateJson.put("checked", 0); - } + List profileOperateList = userProfile.getProfileOperateList(); + if (CollectionUtils.isEmpty(profileOperateList)) { + continue; + } + JSONObject userProfileObj = new JSONObject(); + userProfileObj.put("value", userProfile.getValue()); + userProfileObj.put("text", userProfile.getText()); + userProfileObj.put("checked", 1); + JSONArray userProfileOperateArray = new JSONArray(); + for (IUserProfileOperate userProfileOperate : profileOperateList) { + JSONObject userProfileOperateObj = new JSONObject(); + userProfileOperateObj.put("value", userProfileOperate.getValue()); + userProfileOperateObj.put("text", userProfileOperate.getText()); + String key = activeModuleId + userProfile.getValue() + userProfileOperate.getValue(); + if (myUserProfileOperateMap.containsKey(key)) { + userProfileOperateObj.put("checked", 1); + userProfileObj.put("checked", 0); + } else { + userProfileOperateObj.put("checked", 0); } + userProfileOperateArray.add(userProfileOperateObj); } + userProfileObj.put("userProfileOperateList", userProfileOperateArray); + userProfileArray.add(userProfileObj); } - usrProfileVo.setConfig(configObjArray.toJSONString()); - userProfileList.add(usrProfileVo); + userProfileVo.setConfig(userProfileArray.toJSONString()); + userProfileList.add(userProfileVo); } - return userProfileList; + return userProfileList; } } diff --git a/src/main/java/neatlogic/module/tenant/api/user/UserProfileSaveApi.java b/src/main/java/neatlogic/module/tenant/api/user/UserProfileSaveApi.java index 92fc383f..5af44070 100644 --- a/src/main/java/neatlogic/module/tenant/api/user/UserProfileSaveApi.java +++ b/src/main/java/neatlogic/module/tenant/api/user/UserProfileSaveApi.java @@ -16,9 +16,12 @@ package neatlogic.module.tenant.api.user; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import neatlogic.framework.asynchronization.threadlocal.UserContext; -import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.common.constvalue.IUserProfile; +import neatlogic.framework.common.constvalue.IUserProfileOperate; import neatlogic.framework.dao.mapper.UserMapper; import neatlogic.framework.dto.UserProfileVo; import neatlogic.framework.exception.type.ParamIrregularException; @@ -27,8 +30,6 @@ import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; import neatlogic.framework.userprofile.UserProfileFactory; import neatlogic.module.tenant.exception.user.UserProfileModuleNotFoundException; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -36,7 +37,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; -import java.util.stream.Collectors; +import java.util.Objects; @Service @Transactional @@ -53,7 +54,7 @@ public class UserProfileSaveApi extends PrivateApiComponentBase { @Override public String getName() { - return "用户个性化保存接口"; + return "nmtau.userprofilesaveapi.getname"; } @Override @@ -62,13 +63,13 @@ public class UserProfileSaveApi extends PrivateApiComponentBase { } @Input({ - @Param(name="moduleId",type=ApiParamType.STRING,isRequired=true,desc="模块id"), - @Param(name="checked",type=ApiParamType.INTEGER,isRequired=true,desc="操作个性化选项勾选,1:勾选,0:不勾选"), - @Param(name="name",type=ApiParamType.STRING,isRequired=true,desc="操作个性化选项名"), - @Param(name="operate",type=ApiParamType.STRING,desc="具体操作个性化选项名,checked = 0时,必填。") + @Param(name="moduleId",type=ApiParamType.STRING,isRequired=true,desc="common.moduleid"), + @Param(name="checked",type=ApiParamType.INTEGER,isRequired=true,desc="nmtau.userprofilesaveapi.input.param.checked.desc", help = "1:勾选,0:不勾选"), + @Param(name="name",type=ApiParamType.STRING,isRequired=true,desc="nmtau.userprofilesaveapi.input.param.name.desc"), + @Param(name="operate",type=ApiParamType.STRING,desc="nmtau.userprofilesaveapi.input.param.operate.desc", help = "checked = 0时,必填。") }) @Output({}) - @Description(desc = "用户个性化保存接口") + @Description(desc = "nmtau.userprofilesaveapi.getname") @Override public Object myDoService(JSONObject jsonObj) throws Exception { String moduleId = jsonObj.getString("moduleId"); @@ -76,67 +77,87 @@ public class UserProfileSaveApi extends PrivateApiComponentBase { String operate = jsonObj.getString("operate"); String userUuid =UserContext.get().getUserUuid(true); Integer checked = jsonObj.getInteger("checked"); - if(!UserProfileFactory.getUserProfileMap().containsKey(moduleId)) { + List userProfileList = UserProfileFactory.getUserProfileListByModuleId(moduleId); + if(CollectionUtils.isEmpty(userProfileList)) { throw new UserProfileModuleNotFoundException(moduleId); } if(checked == 0&&StringUtils.isBlank(operate)) { throw new ParamIrregularException("operate"); } //找出对用的json - String config = UserProfileFactory.getUserProfileMap().get(moduleId).getConfig(); - JSONArray configArray = JSONObject.parseArray(config); - List list = configArray.stream().filter(o->((JSONObject)o).containsValue(name)).collect(Collectors.toList()); - if(CollectionUtils.isNotEmpty(list)) { - JSONObject profileJson = (JSONObject)list.get(0); - JSONArray operateList = profileJson.getJSONArray("userProfileOperateList"); - List operateTmpList = operateList.stream().filter(o->((JSONObject)o).containsValue(operate)).collect(Collectors.toList()); - profileJson.put("userProfileOperateList", operateTmpList); - List myUserProfileList = userMapper.getUserProfileByUserUuidAndModuleId(userUuid, moduleId); - if(CollectionUtils.isNotEmpty(myUserProfileList)) {//存在用户记录 update - UserProfileVo userProfileVo = myUserProfileList.get(0); - String myConfig = userProfileVo.getConfig(); - if(StringUtils.isNotBlank(myConfig)) { - JSONArray myConfigArray = JSONArray.parseArray(myConfig); - java.util.ListIterator myConfigIterator = myConfigArray.listIterator(); - Boolean isExist = false; - while(myConfigIterator.hasNext()) { - JSONObject myConfigJson = (JSONObject)myConfigIterator.next(); - if(myConfigJson.getString("value").equals(name)) { - isExist = true; - if(checked == 0) { - myConfigJson.put("userProfileOperateList", operateTmpList); - }else { - myConfigIterator.remove(); - } - } - } - if(!isExist) { - if(checked == 1) { - //do nothing - }else { - myConfigArray.add(list.get(0)); - } + JSONObject userProfileObj = null; + JSONObject userProfileOperateObj = null; + for (IUserProfile userProfile : userProfileList) { + if (!Objects.equals(name, userProfile.getValue())) { + continue; + } + userProfileObj = new JSONObject(); + userProfileObj.put("value", userProfile.getValue()); + userProfileObj.put("text", userProfile.getText()); + if (checked == 1) { + userProfileObj.put("checked", 1); + } else { + userProfileObj.put("checked", 0); + List profileOperateList = userProfile.getProfileOperateList(); + if (CollectionUtils.isEmpty(profileOperateList)) { + continue; + } + for (IUserProfileOperate userProfileOperate : profileOperateList) { + if (!Objects.equals(operate, userProfileOperate.getValue())) { + continue; } - if(CollectionUtils.isNotEmpty(myConfigArray)) { - userMapper.updateUserProfileByUserUuidAndModuleId(userUuid, moduleId, myConfigArray.toJSONString()); - }else {//config 为空,则删除用户记录 - userMapper.deleteUserProfileByUserUuidAndModuleId(userUuid, moduleId); + userProfileOperateObj = new JSONObject(); + userProfileOperateObj.put("value", userProfileOperate.getValue()); + userProfileOperateObj.put("text", userProfileOperate.getText()); + userProfileOperateObj.put("checked", 1); + } + } + } + if (userProfileObj == null) { + // 参数name无效 + throw new UserProfileModuleNotFoundException(name); + } + if (checked == 0) { + if (userProfileOperateObj == null) { + // 参数operate无效 + throw new UserProfileModuleNotFoundException(operate); + } + JSONArray userProfileOperateArray = new JSONArray(); + userProfileOperateArray.add(userProfileOperateObj); + userProfileObj.put("userProfileOperateList", userProfileOperateArray); + } + + List myUserProfileList = userMapper.getUserProfileByUserUuidAndModuleId(userUuid, moduleId); + if(CollectionUtils.isNotEmpty(myUserProfileList)) {//存在用户记录 update + UserProfileVo userProfileVo = myUserProfileList.get(0); + String myConfig = userProfileVo.getConfig(); + if(StringUtils.isNotBlank(myConfig)) { + JSONArray newUserProfileArray = new JSONArray(); + JSONArray oldUserProfileArray = JSONArray.parseArray(myConfig); + for (int i = 0; i < oldUserProfileArray.size(); i++) { + JSONObject oldUserProfileObj = oldUserProfileArray.getJSONObject(i); + if(!Objects.equals(oldUserProfileObj.getString("value"), name)) { + newUserProfileArray.add(oldUserProfileObj); } - }else { - //do nothing } - }else {//不存在用户记录 insert - if(checked == 0) { - UserProfileVo userProfileVo = new UserProfileVo(); - JSONArray myConfigArray = new JSONArray(); - myConfigArray.add(list.get(0)); - userProfileVo.setModuleId(moduleId); - userProfileVo.setUserUuid(userUuid); - userProfileVo.setConfig(myConfigArray.toJSONString()); - userMapper.insertUserProfile(userProfileVo); - }else { - // do nothing + if (checked == 0) { + newUserProfileArray.add(userProfileObj); } + if(CollectionUtils.isNotEmpty(newUserProfileArray)) { + userMapper.updateUserProfileByUserUuidAndModuleId(userUuid, moduleId, newUserProfileArray.toJSONString()); + }else {//config 为空,则删除用户记录 + userMapper.deleteUserProfileByUserUuidAndModuleId(userUuid, moduleId); + } + } + }else {//不存在用户记录 insert + if(checked == 0) { + UserProfileVo userProfileVo = new UserProfileVo(); + JSONArray userProfileArray = new JSONArray(); + userProfileArray.add(userProfileObj); + userProfileVo.setModuleId(moduleId); + userProfileVo.setUserUuid(userUuid); + userProfileVo.setConfig(userProfileArray.toJSONString()); + userMapper.insertUserProfile(userProfileVo); } } return null; -- Gitee