Commit 7f3f2707 authored by suhuiguang's avatar suhuiguang

1.定时任务后端处理生成二维码

parent 179baeee
...@@ -50,6 +50,8 @@ import org.springframework.beans.factory.annotation.Value; ...@@ -50,6 +50,8 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.mock.web.MockMultipartFile; import org.springframework.mock.web.MockMultipartFile;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronization; import org.springframework.transaction.support.TransactionSynchronization;
...@@ -82,6 +84,7 @@ import java.util.stream.Stream; ...@@ -82,6 +84,7 @@ import java.util.stream.Stream;
* @date 2022-08-09 * @date 2022-08-09
*/ */
@Service @Service
@EnableScheduling
public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitInfo, RegUnitInfoMapper> public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitInfo, RegUnitInfoMapper>
implements IRegUnitInfoService { implements IRegUnitInfoService {
...@@ -209,14 +212,6 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI ...@@ -209,14 +212,6 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI
if(log.isDebugEnabled()){ if(log.isDebugEnabled()){
log.debug("注册总耗时:==》" + watch.getTotalTimeSeconds()); log.debug("注册总耗时:==》" + watch.getTotalTimeSeconds());
} }
//9.事务提交后,异步创建企业的二维码
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
@Override
public void afterCommit(){
RegUnitInfoServiceImpl proxy = applicationContext.getBean(RegUnitInfoServiceImpl.class);
proxy.asyncSetQrCode(model);
}
});
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
// 失败后回滚:删除已经创建的企业信息 // 失败后回滚:删除已经创建的企业信息
...@@ -240,15 +235,15 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI ...@@ -240,15 +235,15 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI
return model; return model;
} }
@Async @Scheduled(cron = "* 0/1 * * * ?")
public void asyncSetQrCode(RegUnitInfoDto regUnitInfoDto){ public void asyncSetQrCode(){
TzBaseEnterpriseInfo useCodeResult = tzBaseEnterpriseInfoMapper.selectOne(new QueryWrapper<TzBaseEnterpriseInfo>().eq("use_code", regUnitInfoDto.getUnitCode())); //给所有新注册的企业创建二维码,每次处理100个,不排序
if (ObjectUtils.isEmpty(useCodeResult)) { LambdaQueryWrapper<TzBaseEnterpriseInfo> wrapper = new LambdaQueryWrapper<>();
useCodeResult.setQrCode(createQRCode(regUnitInfoDto.getUnitCode())); wrapper.notLike(TzBaseEnterpriseInfo::getQrCode,"upload");
} else { wrapper.last("limit 100");
useCodeResult.setQrCode(ObjectUtils.isEmpty(useCodeResult.getQrCode()) ? createQRCode(regUnitInfoDto.getUnitCode()) : useCodeResult.getQrCode()); List<TzBaseEnterpriseInfo> noQrCodeList = tzBaseEnterpriseInfoMapper.selectList(wrapper);
} noQrCodeList.forEach(e-> e.setQrCode(createQRCode(e.getUseCode())));
tzBaseEnterpriseInfoService.saveOrUpdate(useCodeResult); tzBaseEnterpriseInfoService.saveOrUpdateBatch(noQrCodeList);
} }
private FutureTask<ResponseModel<Boolean>> getResponseModelFutureTask(RegUnitInfoDto model) { private FutureTask<ResponseModel<Boolean>> getResponseModelFutureTask(RegUnitInfoDto model) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment