diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java index b9795ef8dc..99dca942df 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java @@ -778,6 +778,18 @@ public class RedisKeys { return rootPrefix.concat("lock:").concat(methodName); } + /** + * desc:获取分布式锁key + * @param customerId + * @return + */ + public static String getXiaoquEditLock(String customerId) { + if (StringUtils.isBlank(customerId)){ + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"参数错误"); + } + return rootPrefix.concat("lock:xiaoquedit").concat(customerId); + } + /** * desc:获取更新 房屋内有居民数量的key * @param customerId diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/NeighborHoodController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/NeighborHoodController.java index 743254c2d4..e6ad2250fb 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/NeighborHoodController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/NeighborHoodController.java @@ -21,6 +21,8 @@ import cn.afterturn.easypoi.excel.entity.TemplateExportParams; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.aop.NoRepeatSubmit; +import com.epmet.commons.tools.distributedlock.DistributedLock; +import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.validator.ValidatorUtils; @@ -33,6 +35,7 @@ import com.epmet.entity.IcBuildingEntity; import com.epmet.service.NeighborHoodService; import com.epmet.util.ExcelPoiUtils; import lombok.extern.slf4j.Slf4j; +import org.redisson.api.RLock; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.PostMapping; @@ -44,6 +47,7 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.util.HashMap; import java.util.List; +import java.util.concurrent.TimeUnit; /** @@ -61,6 +65,8 @@ public class NeighborHoodController { private NeighborHoodService neighborHoodService; @Resource private IcBuildingDao icBuildingDao; + @Autowired + private DistributedLock distributedLock; @PostMapping("neighborhoodlist") @@ -88,7 +94,15 @@ public class NeighborHoodController { ValidatorUtils.validateEntity(formDTO, IcNeighborHoodAddFormDTO.UpdateShowGroup.class); String customerId = tokenDTO.getCustomerId(); // String customerId = "123123"; - neighborHoodService.updateNeighborhood(customerId,formDTO); + RLock lock = null; + try { + lock = distributedLock.getLock(RedisKeys.getXiaoquEditLock(tokenDTO.getCustomerId()), 120L, 3L, TimeUnit.SECONDS); + neighborHoodService.updateNeighborhood(customerId,formDTO); + } finally { + if (lock != null) { + lock.unlock(); + } + } return new Result(); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java index 161be43e92..378718c836 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java @@ -30,6 +30,7 @@ import com.epmet.commons.tools.constant.AppClientConstant; import com.epmet.commons.tools.constant.Constant; import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.constant.StrConstant; +import com.epmet.commons.tools.distributedlock.DistributedLock; import com.epmet.commons.tools.dto.form.mq.MqBaseFormDTO; import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; import com.epmet.commons.tools.dto.result.OptionDataResultDTO; @@ -76,6 +77,7 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.poi.poifs.filesystem.OfficeXmlFileException; import org.jetbrains.annotations.NotNull; +import org.redisson.api.RLock; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -90,6 +92,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.*; import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @@ -139,6 +142,8 @@ public class IcResiUserController implements ResultDataResolver { private RequestInterceptor requestInterceptor; @Autowired private ExecutorService executorService; + @Autowired + private DistributedLock distributedLock; /** * 模板枚举 @@ -247,11 +252,19 @@ public class IcResiUserController implements ResultDataResolver { @NoRepeatSubmit @PostMapping("edit") public Result edit(@LoginUser TokenDto tokenDto, @RequestBody List formDTO) { - String resiUserId = icResiUserService.edit(tokenDto, formDTO); - //推送MQ事件 - editResiMq(tokenDto.getCustomerId(), resiUserId); + RLock lock = null; + try { + lock = distributedLock.getLock(RedisKeys.getXiaoquEditLock(tokenDto.getCustomerId()), 120L, 3L, TimeUnit.SECONDS); + String resiUserId = icResiUserService.edit(tokenDto, formDTO); + //推送MQ事件 + editResiMq(tokenDto.getCustomerId(), resiUserId); - this.sendVolunteerMsg(tokenDto.getCustomerId(), resiUserId); + this.sendVolunteerMsg(tokenDto.getCustomerId(), resiUserId); + } finally { + if (lock != null) { + lock.unlock(); + } + } return new Result(); } @@ -599,7 +612,9 @@ public class IcResiUserController implements ResultDataResolver { // 三.异步执行导入 executorService.execute(() -> { boolean isAllSuccess = false; + RLock lock = null; try { + lock = distributedLock.getLock(RedisKeys.getXiaoquEditLock(customerId), 120L, 3L, TimeUnit.SECONDS); List formItemList = icResiUserService.listFormItems(customerId, IcFormCodeEnum.RESI_BASE_INFO.getCode()); isAllSuccess = icResiUserImportService.importIcResiInfoFromExcel(importTaskId, formItemList, importTempFileSavePath.toString(), response, IC_RESI_UPLOAD_DIR); } catch (Throwable e) { @@ -638,6 +653,11 @@ public class IcResiUserController implements ResultDataResolver { form.setMessageType(SystemMessageType.IC_RESI_USER_ADD); form.setContent(mqMsg); epmetMessageOpenFeignClient.sendSystemMsgByMQ(form); + + //解锁 + if (lock != null) { + lock.unlock(); + } } }); diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java index 0616392e8e..d685b9c0f7 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java @@ -26,6 +26,7 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.epmet.bean.ResiExportBaseInfoData; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; import com.epmet.commons.tools.constant.*; +import com.epmet.commons.tools.distributedlock.DistributedLock; import com.epmet.commons.tools.dto.form.DictListFormDTO; import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; import com.epmet.commons.tools.dto.result.DictListResultDTO; @@ -78,6 +79,7 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.compress.utils.Lists; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; +import org.redisson.api.RLock; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; @@ -153,6 +155,8 @@ public class IcResiUserServiceImpl extends BaseServiceImpl changeIcResiUserBelongTo(TokenDto tokenDto, IcUserBelongToChangedFormDTO formDTO) { List resiUserIdList = baseDao.listUserIds(formDTO.getCustomerId(), formDTO.getSourceGridId());