同步客商数据BUG修改
This commit is contained in:
+49
-9
@@ -21,7 +21,6 @@ import com.mhd.user.interfaces.vo.ShipperMasterDataSyncTimeVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
@@ -35,6 +34,7 @@ public class UserShipperMasterDataSyncService {
|
||||
|
||||
private static final String LOCK_PREFIX = "shipper:mdm:sync:";
|
||||
private static final int PAGE_SIZE = 500;
|
||||
private static final long SYNC_LOCK_MINUTES = 30;
|
||||
|
||||
@Resource
|
||||
private ThirdPartyServiceFeign thirdPartyServiceFeign;
|
||||
@@ -46,6 +46,8 @@ public class UserShipperMasterDataSyncService {
|
||||
private UserShipperMdmSyncMapper userShipperMdmSyncMapper;
|
||||
@Resource
|
||||
private RedisLock redisLock;
|
||||
@Resource
|
||||
private AsyncUserShipperMasterDataSyncService asyncUserShipperMasterDataSyncService;
|
||||
|
||||
public ShipperMasterDataSyncTimeVo getLastSyncTime() {
|
||||
LoginUser loginUser = requireLoginUser();
|
||||
@@ -55,27 +57,65 @@ public class UserShipperMasterDataSyncService {
|
||||
if (syncEntity != null) {
|
||||
vo.setLastSyncTime(syncEntity.getLastSyncTime());
|
||||
vo.setLastModifyRecordTime(syncEntity.getLastModifyRecordTime());
|
||||
vo.setSyncStatus(syncEntity.getSyncStatus());
|
||||
vo.setSyncMessage(syncEntity.getSyncMessage());
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
public ShipperMasterDataSyncResultVo syncMasterData() {
|
||||
public void syncMasterData() {
|
||||
LoginUser loginUser = requireLoginUser();
|
||||
Long organizationId = loginUser.getUserPo().getOrganizationId();
|
||||
String lockKey = LOCK_PREFIX + organizationId;
|
||||
boolean locked = redisLock.tryLock(lockKey, 30, TimeUnit.SECONDS);
|
||||
boolean locked = redisLock.tryLock(lockKey, SYNC_LOCK_MINUTES, TimeUnit.MINUTES);
|
||||
if (!locked) {
|
||||
throw new ServiceException("当前组织正在同步主数据,请稍后再试");
|
||||
}
|
||||
try {
|
||||
return doSync(loginUser);
|
||||
} finally {
|
||||
redisLock.unlock(lockKey);
|
||||
markSyncInProgress(organizationId);
|
||||
asyncUserShipperMasterDataSyncService.syncMasterDataAsync(loginUser, lockKey);
|
||||
}
|
||||
|
||||
public ShipperMasterDataSyncResultVo executeSync(LoginUser loginUser) {
|
||||
return doSync(loginUser);
|
||||
}
|
||||
|
||||
public void markSyncFailed(Long organizationId, String errorMessage) {
|
||||
UserShipperMdmSyncEntity entity = userShipperMdmSyncMapper.selectByOrganizationId(organizationId);
|
||||
Date now = new Date();
|
||||
if (entity == null) {
|
||||
entity = new UserShipperMdmSyncEntity();
|
||||
entity.setOrganizationId(organizationId);
|
||||
entity.setCreateTime(now);
|
||||
}
|
||||
entity.setSyncStatus(2);
|
||||
entity.setSyncMessage("同步失败:" + errorMessage);
|
||||
entity.setUpdateTime(now);
|
||||
if (entity.getId() == null) {
|
||||
userShipperMdmSyncMapper.insert(entity);
|
||||
} else {
|
||||
userShipperMdmSyncMapper.updateById(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
protected ShipperMasterDataSyncResultVo doSync(LoginUser loginUser) {
|
||||
private void markSyncInProgress(Long organizationId) {
|
||||
UserShipperMdmSyncEntity entity = userShipperMdmSyncMapper.selectByOrganizationId(organizationId);
|
||||
Date now = new Date();
|
||||
if (entity == null) {
|
||||
entity = new UserShipperMdmSyncEntity();
|
||||
entity.setOrganizationId(organizationId);
|
||||
entity.setCreateTime(now);
|
||||
}
|
||||
entity.setSyncStatus(0);
|
||||
entity.setSyncMessage("同步中...");
|
||||
entity.setUpdateTime(now);
|
||||
if (entity.getId() == null) {
|
||||
userShipperMdmSyncMapper.insert(entity);
|
||||
} else {
|
||||
userShipperMdmSyncMapper.updateById(entity);
|
||||
}
|
||||
}
|
||||
|
||||
private ShipperMasterDataSyncResultVo doSync(LoginUser loginUser) {
|
||||
Long organizationId = loginUser.getUserPo().getOrganizationId();
|
||||
String orgNcCode = resolveOrgNcCode(organizationId);
|
||||
if (StringUtils.isEmpty(orgNcCode)) {
|
||||
|
||||
Reference in New Issue
Block a user