diff --git a/coolstore-partner-common/src/main/java/com/cool/store/constants/RedisConstant.java b/coolstore-partner-common/src/main/java/com/cool/store/constants/RedisConstant.java index e72023d47..a6949233d 100644 --- a/coolstore-partner-common/src/main/java/com/cool/store/constants/RedisConstant.java +++ b/coolstore-partner-common/src/main/java/com/cool/store/constants/RedisConstant.java @@ -277,4 +277,6 @@ public class RedisConstant { * 招商经理轮询key */ public static final String YUN_XUE_TANG_ACCESS_TOKEN = "yun_xue_tang_access_token_"; + + public static final String SUBMIT_BUILD_KEY = "submit_build_key_"; } diff --git a/coolstore-partner-common/src/main/java/com/cool/store/utils/RedisConstantUtil.java b/coolstore-partner-common/src/main/java/com/cool/store/utils/RedisConstantUtil.java index cafac3462..3136ff26d 100644 --- a/coolstore-partner-common/src/main/java/com/cool/store/utils/RedisConstantUtil.java +++ b/coolstore-partner-common/src/main/java/com/cool/store/utils/RedisConstantUtil.java @@ -106,5 +106,8 @@ public class RedisConstantUtil { public String getInvestmentManagerKey(Long wantShopAreaId, Long roleId) { return active + "_" + RedisConstant.INVESTMENT_MANAGER_CACHE + eid + ":" + wantShopAreaId + ":" + roleId ; } + public String submitBuildKey(Long shopId){ + return active + "_" + RedisConstant.SUBMIT_BUILD_KEY + eid + ":" + shopId ; + } } diff --git a/coolstore-partner-service/src/main/java/com/cool/store/service/impl/BuildInformationServiceImpl.java b/coolstore-partner-service/src/main/java/com/cool/store/service/impl/BuildInformationServiceImpl.java index fae418f59..c667529b2 100644 --- a/coolstore-partner-service/src/main/java/com/cool/store/service/impl/BuildInformationServiceImpl.java +++ b/coolstore-partner-service/src/main/java/com/cool/store/service/impl/BuildInformationServiceImpl.java @@ -18,6 +18,8 @@ import com.cool.store.service.BuildInformationService; import com.cool.store.mapper.BuildInformationMapper; import com.cool.store.service.PreparationService; import com.cool.store.service.UserAuthMappingService; +import com.cool.store.utils.RedisConstantUtil; +import com.cool.store.utils.RedisUtilPool; import com.cool.store.utils.poi.StringUtils; import io.lettuce.core.ZAddArgs; import org.jetbrains.annotations.NotNull; @@ -37,6 +39,10 @@ import java.util.stream.Collectors; @Service public class BuildInformationServiceImpl implements BuildInformationService { + @Resource + private RedisConstantUtil redisConstantUtil; + @Resource + private RedisUtilPool redisUtilPool; @Resource private WarehouseInfoMapper warehouseInfoMapper; @Resource @@ -176,51 +182,66 @@ public class BuildInformationServiceImpl implements BuildInformationService { @Override @Transactional(rollbackFor = Exception.class) public Integer submitOrUpdate(BuildInformationRequest request) { - BuildInformationDO informationDO = buildInformationDAO.selectOneByShopId(request.getShopId()); - BuildInformationDO buildInformationDO = request.toDO(); - OrderSysInfoDO orderSysInfoDO = getOrderSysInfoDO(request); - OrderSysInfoDO orderSysInfoDO1 = orderSysInfoDAO.selectByShopId(request.getShopId()); - if (Objects.nonNull(orderSysInfoDO1)) { - orderSysInfoDAO.updateByShopId(orderSysInfoDO); - } else { - orderSysInfoDAO.insertSelective(orderSysInfoDO); - } - ShopInfoDO shopInfoDO = shopInfoDAO.getShopInfo(request.getShopId()); - LineInfoDO lineInfoDO = lineInfoDAO.getLineInfo(shopInfoDO.getLineId()); - QualificationsInfoDO qualificationsInfoDO = qualificationsInfoDAO.getByLineId(lineInfoDO.getId()); - if (request.getJuridicalIsSamePartner()) { - buildInformationDO.setJuridicalIdCardNo(qualificationsInfoDO.getIdCardNo()); - buildInformationDO.setJuridicalIdCardFront(qualificationsInfoDO.getFrontOfIdCard()); - buildInformationDO.setJuridicalIdCardReverse(qualificationsInfoDO.getBackOfIdCard()); - } - if (request.getSettlerIsSamePartner()) { - buildInformationDO.setSettlerIdCardNo(qualificationsInfoDO.getIdCardNo()); - buildInformationDO.setSettlerName(lineInfoDO.getUsername()); - buildInformationDO.setSettlerIdCardFront(qualificationsInfoDO.getFrontOfIdCard()); - buildInformationDO.setSettlerIdCardReverse(qualificationsInfoDO.getBackOfIdCard()); - } - if (Objects.isNull(informationDO)) { - buildInformationDO.setCreateTime(new Date()); - buildInformationDO.setUpdateTime(new Date()); - shopStageInfoDAO.updateShopStageInfo(request.getShopId(), ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_151); - HashMap map = new HashMap<>(); - map.put("partnerUsername", lineInfoDO.getUsername()); - map.put("partnerMobile", lineInfoDO.getMobile()); - map.put("storeName", shopInfoDO.getShopName()); - List logisticsList = userAuthMappingService.getAllUserByRoleEnumAndRegionId(UserRoleEnum.LOGISTICS, shopInfoDO.getRegionId()); - List logistics = new ArrayList<>(); - if (Objects.nonNull(logisticsList)) { - logistics.addAll(logisticsList.stream().map(EnterpriseUserDO::getUserId).collect(Collectors.toList())); + String lockKey = redisConstantUtil.submitBuildKey(request.getShopId()); + String lockValue = UUID.randomUUID().toString(); + boolean acquired = false; + try { + acquired = redisUtilPool.setNxExpire(lockKey, lockValue, CommonConstants.TEN_SECONDS); + if (Boolean.TRUE.equals(acquired)) { + BuildInformationDO informationDO = buildInformationDAO.selectOneByShopId(request.getShopId()); + BuildInformationDO buildInformationDO = request.toDO(); + OrderSysInfoDO orderSysInfoDO = getOrderSysInfoDO(request); + OrderSysInfoDO orderSysInfoDO1 = orderSysInfoDAO.selectByShopId(request.getShopId()); + if (Objects.nonNull(orderSysInfoDO1)) { + orderSysInfoDAO.updateByShopId(orderSysInfoDO); + } else { + orderSysInfoDAO.insertSelective(orderSysInfoDO); + } + ShopInfoDO shopInfoDO = shopInfoDAO.getShopInfo(request.getShopId()); + LineInfoDO lineInfoDO = lineInfoDAO.getLineInfo(shopInfoDO.getLineId()); + QualificationsInfoDO qualificationsInfoDO = qualificationsInfoDAO.getByLineId(lineInfoDO.getId()); + if (request.getJuridicalIsSamePartner()) { + buildInformationDO.setJuridicalIdCardNo(qualificationsInfoDO.getIdCardNo()); + buildInformationDO.setJuridicalIdCardFront(qualificationsInfoDO.getFrontOfIdCard()); + buildInformationDO.setJuridicalIdCardReverse(qualificationsInfoDO.getBackOfIdCard()); + } + if (request.getSettlerIsSamePartner()) { + buildInformationDO.setSettlerIdCardNo(qualificationsInfoDO.getIdCardNo()); + buildInformationDO.setSettlerName(lineInfoDO.getUsername()); + buildInformationDO.setSettlerIdCardFront(qualificationsInfoDO.getFrontOfIdCard()); + buildInformationDO.setSettlerIdCardReverse(qualificationsInfoDO.getBackOfIdCard()); + } + if (Objects.isNull(informationDO)) { + buildInformationDO.setCreateTime(new Date()); + buildInformationDO.setUpdateTime(new Date()); + shopStageInfoDAO.updateShopStageInfo(request.getShopId(), ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_151); + HashMap map = new HashMap<>(); + map.put("partnerUsername", lineInfoDO.getUsername()); + map.put("partnerMobile", lineInfoDO.getMobile()); + map.put("storeName", shopInfoDO.getShopName()); + List logisticsList = userAuthMappingService.getAllUserByRoleEnumAndRegionId(UserRoleEnum.LOGISTICS, shopInfoDO.getRegionId()); + List logistics = new ArrayList<>(); + if (Objects.nonNull(logisticsList)) { + logistics.addAll(logisticsList.stream().map(EnterpriseUserDO::getUserId).collect(Collectors.toList())); + } + commonService.sendQWMessage(logistics, + MessageEnum.MESSAGE_52, + map); + return buildInformationDAO.insertSelective(buildInformationDO); + } else { + buildInformationDO.setUpdateTime(new Date()); + return buildInformationDAO.updateByShopIdSelective(buildInformationDO); + } + } + } finally { + if (Boolean.TRUE.equals(acquired)) { + String currentValue = redisUtilPool.getString(lockKey); + if (lockValue.equals(currentValue)) { + redisUtilPool.delKey(lockKey); + } } - commonService.sendQWMessage(logistics, - MessageEnum.MESSAGE_52, - map); - return buildInformationDAO.insertSelective(buildInformationDO); - } else { - buildInformationDO.setUpdateTime(new Date()); - return buildInformationDAO.updateByShopIdSelective(buildInformationDO); } - + return 0; } private static @NotNull OrderSysInfoDO getOrderSysInfoDO(BuildInformationRequest request) {