提交建店资料加锁防止重复提交

This commit is contained in:
shuo.wang
2025-05-13 15:02:55 +08:00
parent f5e6194272
commit 2bf1ddea47
3 changed files with 69 additions and 43 deletions

View File

@@ -277,4 +277,6 @@ public class RedisConstant {
* 招商经理轮询key * 招商经理轮询key
*/ */
public static final String YUN_XUE_TANG_ACCESS_TOKEN = "yun_xue_tang_access_token_"; public static final String YUN_XUE_TANG_ACCESS_TOKEN = "yun_xue_tang_access_token_";
public static final String SUBMIT_BUILD_KEY = "submit_build_key_";
} }

View File

@@ -106,5 +106,8 @@ public class RedisConstantUtil {
public String getInvestmentManagerKey(Long wantShopAreaId, Long roleId) { public String getInvestmentManagerKey(Long wantShopAreaId, Long roleId) {
return active + "_" + RedisConstant.INVESTMENT_MANAGER_CACHE + eid + ":" + wantShopAreaId + ":" + roleId ; return active + "_" + RedisConstant.INVESTMENT_MANAGER_CACHE + eid + ":" + wantShopAreaId + ":" + roleId ;
} }
public String submitBuildKey(Long shopId){
return active + "_" + RedisConstant.SUBMIT_BUILD_KEY + eid + ":" + shopId ;
}
} }

View File

@@ -18,6 +18,8 @@ import com.cool.store.service.BuildInformationService;
import com.cool.store.mapper.BuildInformationMapper; import com.cool.store.mapper.BuildInformationMapper;
import com.cool.store.service.PreparationService; import com.cool.store.service.PreparationService;
import com.cool.store.service.UserAuthMappingService; 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 com.cool.store.utils.poi.StringUtils;
import io.lettuce.core.ZAddArgs; import io.lettuce.core.ZAddArgs;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -37,6 +39,10 @@ import java.util.stream.Collectors;
@Service @Service
public class BuildInformationServiceImpl implements BuildInformationService { public class BuildInformationServiceImpl implements BuildInformationService {
@Resource
private RedisConstantUtil redisConstantUtil;
@Resource
private RedisUtilPool redisUtilPool;
@Resource @Resource
private WarehouseInfoMapper warehouseInfoMapper; private WarehouseInfoMapper warehouseInfoMapper;
@Resource @Resource
@@ -176,51 +182,66 @@ public class BuildInformationServiceImpl implements BuildInformationService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Integer submitOrUpdate(BuildInformationRequest request) { public Integer submitOrUpdate(BuildInformationRequest request) {
BuildInformationDO informationDO = buildInformationDAO.selectOneByShopId(request.getShopId()); String lockKey = redisConstantUtil.submitBuildKey(request.getShopId());
BuildInformationDO buildInformationDO = request.toDO(); String lockValue = UUID.randomUUID().toString();
OrderSysInfoDO orderSysInfoDO = getOrderSysInfoDO(request); boolean acquired = false;
OrderSysInfoDO orderSysInfoDO1 = orderSysInfoDAO.selectByShopId(request.getShopId()); try {
if (Objects.nonNull(orderSysInfoDO1)) { acquired = redisUtilPool.setNxExpire(lockKey, lockValue, CommonConstants.TEN_SECONDS);
orderSysInfoDAO.updateByShopId(orderSysInfoDO); if (Boolean.TRUE.equals(acquired)) {
} else { BuildInformationDO informationDO = buildInformationDAO.selectOneByShopId(request.getShopId());
orderSysInfoDAO.insertSelective(orderSysInfoDO); BuildInformationDO buildInformationDO = request.toDO();
} OrderSysInfoDO orderSysInfoDO = getOrderSysInfoDO(request);
ShopInfoDO shopInfoDO = shopInfoDAO.getShopInfo(request.getShopId()); OrderSysInfoDO orderSysInfoDO1 = orderSysInfoDAO.selectByShopId(request.getShopId());
LineInfoDO lineInfoDO = lineInfoDAO.getLineInfo(shopInfoDO.getLineId()); if (Objects.nonNull(orderSysInfoDO1)) {
QualificationsInfoDO qualificationsInfoDO = qualificationsInfoDAO.getByLineId(lineInfoDO.getId()); orderSysInfoDAO.updateByShopId(orderSysInfoDO);
if (request.getJuridicalIsSamePartner()) { } else {
buildInformationDO.setJuridicalIdCardNo(qualificationsInfoDO.getIdCardNo()); orderSysInfoDAO.insertSelective(orderSysInfoDO);
buildInformationDO.setJuridicalIdCardFront(qualificationsInfoDO.getFrontOfIdCard()); }
buildInformationDO.setJuridicalIdCardReverse(qualificationsInfoDO.getBackOfIdCard()); ShopInfoDO shopInfoDO = shopInfoDAO.getShopInfo(request.getShopId());
} LineInfoDO lineInfoDO = lineInfoDAO.getLineInfo(shopInfoDO.getLineId());
if (request.getSettlerIsSamePartner()) { QualificationsInfoDO qualificationsInfoDO = qualificationsInfoDAO.getByLineId(lineInfoDO.getId());
buildInformationDO.setSettlerIdCardNo(qualificationsInfoDO.getIdCardNo()); if (request.getJuridicalIsSamePartner()) {
buildInformationDO.setSettlerName(lineInfoDO.getUsername()); buildInformationDO.setJuridicalIdCardNo(qualificationsInfoDO.getIdCardNo());
buildInformationDO.setSettlerIdCardFront(qualificationsInfoDO.getFrontOfIdCard()); buildInformationDO.setJuridicalIdCardFront(qualificationsInfoDO.getFrontOfIdCard());
buildInformationDO.setSettlerIdCardReverse(qualificationsInfoDO.getBackOfIdCard()); buildInformationDO.setJuridicalIdCardReverse(qualificationsInfoDO.getBackOfIdCard());
} }
if (Objects.isNull(informationDO)) { if (request.getSettlerIsSamePartner()) {
buildInformationDO.setCreateTime(new Date()); buildInformationDO.setSettlerIdCardNo(qualificationsInfoDO.getIdCardNo());
buildInformationDO.setUpdateTime(new Date()); buildInformationDO.setSettlerName(lineInfoDO.getUsername());
shopStageInfoDAO.updateShopStageInfo(request.getShopId(), ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_151); buildInformationDO.setSettlerIdCardFront(qualificationsInfoDO.getFrontOfIdCard());
HashMap<String, String> map = new HashMap<>(); buildInformationDO.setSettlerIdCardReverse(qualificationsInfoDO.getBackOfIdCard());
map.put("partnerUsername", lineInfoDO.getUsername()); }
map.put("partnerMobile", lineInfoDO.getMobile()); if (Objects.isNull(informationDO)) {
map.put("storeName", shopInfoDO.getShopName()); buildInformationDO.setCreateTime(new Date());
List<EnterpriseUserDO> logisticsList = userAuthMappingService.getAllUserByRoleEnumAndRegionId(UserRoleEnum.LOGISTICS, shopInfoDO.getRegionId()); buildInformationDO.setUpdateTime(new Date());
List<String> logistics = new ArrayList<>(); shopStageInfoDAO.updateShopStageInfo(request.getShopId(), ShopSubStageStatusEnum.SHOP_SUB_STAGE_STATUS_151);
if (Objects.nonNull(logisticsList)) { HashMap<String, String> map = new HashMap<>();
logistics.addAll(logisticsList.stream().map(EnterpriseUserDO::getUserId).collect(Collectors.toList())); map.put("partnerUsername", lineInfoDO.getUsername());
map.put("partnerMobile", lineInfoDO.getMobile());
map.put("storeName", shopInfoDO.getShopName());
List<EnterpriseUserDO> logisticsList = userAuthMappingService.getAllUserByRoleEnumAndRegionId(UserRoleEnum.LOGISTICS, shopInfoDO.getRegionId());
List<String> 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) { private static @NotNull OrderSysInfoDO getOrderSysInfoDO(BuildInformationRequest request) {