|
@@ -19,6 +19,7 @@ import com.yonge.cooleshow.common.constant.SysConfigConstant;
|
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
|
import com.yonge.toolset.payment.util.DistributedLock;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.redisson.api.RLock;
|
|
|
import org.redisson.api.RedissonClient;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -28,6 +29,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -70,31 +72,44 @@ public class CbsMusicSheetServiceImpl implements CbsMusicSheetService {
|
|
|
CbsMusicSheetApiWrapper.MusicSheetUpdate musicSheetUpdate = extend.getMusicSheetUpdate();
|
|
|
|
|
|
Long finalUserId = userId;
|
|
|
- DistributedLock.of(redissonClient).runIfLockCanGet("musicSheetUpdate:" + musicSheetUpdate.getId(), () -> {
|
|
|
- updateMusicDataFormat(musicSheetUpdate, finalUserId);
|
|
|
-
|
|
|
- //需要修改的曲目
|
|
|
- List<MusicSheet> musicSheets = musicSheetService.lambdaQuery()
|
|
|
- .in(MusicSheet::getCbsMusicSheetId, extend.getMusicSheetId())
|
|
|
- .list();
|
|
|
- if (com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isNotEmpty(musicSheets)){
|
|
|
- // 判断是改机构数据,还是平台数据
|
|
|
- if (extend.getApplicationId() !=null && cbsTenantAppId.equals(extend.getApplicationId().toString())) {
|
|
|
-
|
|
|
- musicSheetService.getDao().updateTenantByCbsId(extend);
|
|
|
+ RLock lock = redissonClient.getLock("musicSheetUpdate:" + musicSheetUpdate.getId());
|
|
|
+ try {
|
|
|
+ if (lock.tryLock(10, 10, TimeUnit.SECONDS)) {
|
|
|
+ updateMusicDataFormat(musicSheetUpdate, finalUserId);
|
|
|
+
|
|
|
+ //需要修改的曲目
|
|
|
+ List<MusicSheet> musicSheets = musicSheetService.lambdaQuery()
|
|
|
+ .in(MusicSheet::getCbsMusicSheetId, extend.getMusicSheetId())
|
|
|
+ .list();
|
|
|
+ if (com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isNotEmpty(musicSheets)) {
|
|
|
+ // 判断是改机构数据,还是平台数据
|
|
|
+ if (extend.getApplicationId() != null && cbsTenantAppId.equals(extend.getApplicationId().toString())) {
|
|
|
+
|
|
|
+ musicSheetService.getDao().updateTenantByCbsId(extend);
|
|
|
+ } else {
|
|
|
+ musicSheetService.getDao().updatePlatformByCbsId(extend);
|
|
|
+ }
|
|
|
} else {
|
|
|
- musicSheetService.getDao().updatePlatformByCbsId(extend);
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (extend.getApplicationId() !=null && cbsTenantAppId.equals(extend.getApplicationId().toString())) {
|
|
|
+ if (extend.getApplicationId() != null && cbsTenantAppId.equals(extend.getApplicationId().toString())) {
|
|
|
|
|
|
- musicSheetService.getDao().tenantInsert(extend);
|
|
|
- } else {
|
|
|
- musicSheetService.getDao().platformInsert(extend);
|
|
|
+ musicSheetService.getDao().tenantInsert(extend);
|
|
|
+ } else {
|
|
|
+ musicSheetService.getDao().platformInsert(extend);
|
|
|
+ }
|
|
|
}
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
}
|
|
|
- },5L, TimeUnit.MINUTES);
|
|
|
-
|
|
|
+ } catch (BizException e) {
|
|
|
+ log.error("BizException error lockName : musicSheetUpdate:" + musicSheetUpdate.getId(), e);
|
|
|
+ throw e;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("saveApplicationExtend error lockName : musicSheetUpdate:" + musicSheetUpdate.getId(), e);
|
|
|
+ } finally {
|
|
|
+ if (lock.getHoldCount() != 0 && lock.isHeldByCurrentThread()) {
|
|
|
+ lock.unlock();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return true;
|