Browse Source

Merge branches 'dev_bugfix_ljj' and 'master' of http://git.elinkit.com.cn:7070/r/epmet-cloud

dev
wangxianzhang 3 years ago
parent
commit
a99e1e8703
  1. 12
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java
  2. 16
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/NeighborHoodController.java
  3. 28
      epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java
  4. 5
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java

12
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); 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 * desc:获取更新 房屋内有居民数量的key
* @param customerId * @param customerId

16
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.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.annotation.LoginUser;
import com.epmet.commons.tools.aop.NoRepeatSubmit; 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.security.dto.TokenDto;
import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.commons.tools.validator.ValidatorUtils;
@ -33,6 +35,7 @@ import com.epmet.entity.IcBuildingEntity;
import com.epmet.service.NeighborHoodService; import com.epmet.service.NeighborHoodService;
import com.epmet.util.ExcelPoiUtils; import com.epmet.util.ExcelPoiUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@ -44,6 +47,7 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
/** /**
@ -61,6 +65,8 @@ public class NeighborHoodController {
private NeighborHoodService neighborHoodService; private NeighborHoodService neighborHoodService;
@Resource @Resource
private IcBuildingDao icBuildingDao; private IcBuildingDao icBuildingDao;
@Autowired
private DistributedLock distributedLock;
@PostMapping("neighborhoodlist") @PostMapping("neighborhoodlist")
@ -88,7 +94,15 @@ public class NeighborHoodController {
ValidatorUtils.validateEntity(formDTO, IcNeighborHoodAddFormDTO.UpdateShowGroup.class); ValidatorUtils.validateEntity(formDTO, IcNeighborHoodAddFormDTO.UpdateShowGroup.class);
String customerId = tokenDTO.getCustomerId(); String customerId = tokenDTO.getCustomerId();
// String customerId = "123123"; // 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(); return new Result();
} }

28
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.Constant;
import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant; 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.form.mq.MqBaseFormDTO;
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult;
import com.epmet.commons.tools.dto.result.OptionDataResultDTO; 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.commons.lang3.StringUtils;
import org.apache.poi.poifs.filesystem.OfficeXmlFileException; import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.redisson.api.RLock;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -90,6 +92,7 @@ import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.*; import java.util.*;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -139,6 +142,8 @@ public class IcResiUserController implements ResultDataResolver {
private RequestInterceptor requestInterceptor; private RequestInterceptor requestInterceptor;
@Autowired @Autowired
private ExecutorService executorService; private ExecutorService executorService;
@Autowired
private DistributedLock distributedLock;
/** /**
* 模板枚举 * 模板枚举
@ -247,11 +252,19 @@ public class IcResiUserController implements ResultDataResolver {
@NoRepeatSubmit @NoRepeatSubmit
@PostMapping("edit") @PostMapping("edit")
public Result edit(@LoginUser TokenDto tokenDto, @RequestBody List<IcResiUserFormDTO> formDTO) { public Result edit(@LoginUser TokenDto tokenDto, @RequestBody List<IcResiUserFormDTO> formDTO) {
String resiUserId = icResiUserService.edit(tokenDto, formDTO); RLock lock = null;
//推送MQ事件 try {
editResiMq(tokenDto.getCustomerId(), resiUserId); 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(); return new Result();
} }
@ -599,7 +612,9 @@ public class IcResiUserController implements ResultDataResolver {
// 三.异步执行导入 // 三.异步执行导入
executorService.execute(() -> { executorService.execute(() -> {
boolean isAllSuccess = false; boolean isAllSuccess = false;
RLock lock = null;
try { try {
lock = distributedLock.getLock(RedisKeys.getXiaoquEditLock(customerId), 120L, 3L, TimeUnit.SECONDS);
List<FormItemResult> formItemList = icResiUserService.listFormItems(customerId, IcFormCodeEnum.RESI_BASE_INFO.getCode()); List<FormItemResult> formItemList = icResiUserService.listFormItems(customerId, IcFormCodeEnum.RESI_BASE_INFO.getCode());
isAllSuccess = icResiUserImportService.importIcResiInfoFromExcel(importTaskId, formItemList, importTempFileSavePath.toString(), response, IC_RESI_UPLOAD_DIR); isAllSuccess = icResiUserImportService.importIcResiInfoFromExcel(importTaskId, formItemList, importTempFileSavePath.toString(), response, IC_RESI_UPLOAD_DIR);
} catch (Throwable e) { } catch (Throwable e) {
@ -638,6 +653,11 @@ public class IcResiUserController implements ResultDataResolver {
form.setMessageType(SystemMessageType.IC_RESI_USER_ADD); form.setMessageType(SystemMessageType.IC_RESI_USER_ADD);
form.setContent(mqMsg); form.setContent(mqMsg);
epmetMessageOpenFeignClient.sendSystemMsgByMQ(form); epmetMessageOpenFeignClient.sendSystemMsgByMQ(form);
//解锁
if (lock != null) {
lock.unlock();
}
} }
}); });

5
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.bean.ResiExportBaseInfoData;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.*; 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.form.DictListFormDTO;
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult;
import com.epmet.commons.tools.dto.result.DictListResultDTO; 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.compress.utils.Lists;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.redisson.api.RLock;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -153,6 +155,8 @@ public class IcResiUserServiceImpl extends BaseServiceImpl<IcResiUserDao, IcResi
private UserBaseInfoDao userBaseInfoDao; private UserBaseInfoDao userBaseInfoDao;
@Autowired @Autowired
private EpmetUserOpenFeignClient epmetUserOpenFeignClient; private EpmetUserOpenFeignClient epmetUserOpenFeignClient;
@Autowired
private DistributedLock distributedLock;
@ -2210,7 +2214,6 @@ public class IcResiUserServiceImpl extends BaseServiceImpl<IcResiUserDao, IcResi
return listPage.getResult(); return listPage.getResult();
} }
@Transactional(rollbackFor = Exception.class)
@Override @Override
public List<String> changeIcResiUserBelongTo(TokenDto tokenDto, IcUserBelongToChangedFormDTO formDTO) { public List<String> changeIcResiUserBelongTo(TokenDto tokenDto, IcUserBelongToChangedFormDTO formDTO) {
List<String> resiUserIdList = baseDao.listUserIds(formDTO.getCustomerId(), formDTO.getSourceGridId()); List<String> resiUserIdList = baseDao.listUserIds(formDTO.getCustomerId(), formDTO.getSourceGridId());

Loading…
Cancel
Save