Commit 51c5b9e7 authored by suhuiguang's avatar suhuiguang

1.分布式定时任务锁

parent 2d187912
......@@ -21,6 +21,14 @@
<artifactId>amos-boot-module-common-api</artifactId>
<version>${amos-biz-boot.version}</version>
</dependency>
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-spring</artifactId>
</dependency>
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-provider-redis-spring</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -2,6 +2,7 @@ package com.yeejoin.amos;
import com.yeejoin.amos.boot.biz.common.utils.oConvertUtils;
import com.yeejoin.amos.boot.module.elevator.biz.service.impl.StartPlatformTokenService;
import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -40,6 +41,7 @@ import java.net.UnknownHostException;
@EnableAsync
@EnableSwagger2WebMvc
@EnableEurekaClient
@EnableSchedulerLock(defaultLockAtMostFor = "10m")
//@EnableScheduling
@MapperScan({"org.typroject.tyboot.demo.face.orm.dao*", "org.typroject.tyboot.face.*.orm.dao*",
"org.typroject.tyboot.core.auth.face.orm.dao*", "org.typroject.tyboot.component.*.face.orm.dao*",
......
package com.yeejoin.amos.boot.module.elevator.biz.config;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.provider.redis.spring.RedisLockProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
/**
* @author Administrator
*/
@Configuration
public class ShedLockConfig {
@Bean
public LockProvider lockProvider(RedisConnectionFactory connectionFactory) {
return new RedisLockProvider(connectionFactory);
}
}
......@@ -13,6 +13,7 @@ import com.yeejoin.amos.boot.module.elevator.api.entity.VoiceRecordLog;
import com.yeejoin.amos.boot.module.elevator.api.mapper.VoiceRecordLogMapper;
import com.yeejoin.amos.boot.module.elevator.api.service.ICtiService;
import com.yeejoin.amos.boot.module.elevator.api.service.IVoiceRecordLogService;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.paho.client.mqttv3.MqttException;
......@@ -72,6 +73,7 @@ public class VoiceRecordLogServiceImpl extends BaseService<VoiceRecordLogDto,Voi
private TzsAuthServiceImpl tzsAuthServiceImpl;
@Scheduled(fixedDelay=ONE_Minute)
@SchedulerLock(name="voiceRecordLogTask",lockAtMostFor = "PT1H")
public void fixedDelayJob(){
// 设置token
tzsAuthServiceImpl.setRequestContext();
......@@ -93,7 +95,7 @@ public class VoiceRecordLogServiceImpl extends BaseService<VoiceRecordLogDto,Voi
this.updateById(l);
continue;
}
if(ctiInfos == null || ctiInfos.size() == 0) {
if(ctiInfos == null || ctiInfos.isEmpty()) {
this.updateById(l);
continue;
}
......@@ -160,7 +162,7 @@ public class VoiceRecordLogServiceImpl extends BaseService<VoiceRecordLogDto,Voi
}
l.setIsDeal(true);
this.updateById(l);
};
}
}
System.out.println("执行通话记录任务");
......
......@@ -22,6 +22,14 @@
<artifactId>amos-boot-module-common-api</artifactId>
<version>${amos-biz-boot.version}</version>
</dependency>
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-spring</artifactId>
</dependency>
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-provider-redis-spring</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -2,6 +2,7 @@ package com.yeejoin.amos;
import com.yeejoin.amos.boot.biz.common.utils.oConvertUtils;
import com.yeejoin.amos.boot.module.cylinder.biz.listener.FillingRecordSyncListener;
import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
......@@ -44,6 +45,7 @@ import java.net.UnknownHostException;
@EnableSwagger2WebMvc
@EnableEurekaClient
@EnableScheduling
@EnableSchedulerLock(defaultLockAtMostFor = "10m")
@MapperScan({ "org.typroject.tyboot.demo.face.orm.dao*", "org.typroject.tyboot.face.*.orm.dao*",
"org.typroject.tyboot.core.auth.face.orm.dao*", "org.typroject.tyboot.component.*.face.orm.dao*",
"com.yeejoin.amos.boot.module.**.api.mapper", "com.yeejoin.amos.boot.biz.common.dao.mapper" })
......
package com.yeejoin.amos.boot.module.cylinder.biz.config;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.provider.redis.spring.RedisLockProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
/**
* @author Administrator
*/
@Configuration
public class ShedLockConfig {
@Bean
public LockProvider lockProvider(RedisConnectionFactory connectionFactory) {
return new RedisLockProvider(connectionFactory);
}
}
......@@ -57,7 +57,7 @@ public class ESAlertCalledService {
public void init() throws Exception
{
//初始化ES,重建索引
initEs();
// initEs();
}
/**
......
package com.yeejoin.amos.boot.module.cylinder.flc.biz.quartz;
import com.yeejoin.amos.boot.module.cylinder.flc.biz.service.impl.ScheduleService;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
......@@ -20,6 +21,7 @@ public class CylinderSchedulerJob {
* 每天9点-日报生成
*/
@Scheduled(cron = "${cylinder-early-warning-cron:0 0 9 * * ?}")
@SchedulerLock(name="calEarlyWarningLevelTask",lockAtMostFor = "PT6H")
public void dayReport() {
scheduleService.calEarlyWarningLevel();
}
......
......@@ -10,6 +10,7 @@ import com.yeejoin.amos.boot.module.cylinder.flc.api.dto.CylinderTableDto;
import com.yeejoin.amos.boot.module.cylinder.flc.api.entity.*;
import com.yeejoin.amos.boot.module.cylinder.flc.api.mapper.CylinderDateInfoMapper;
import com.yeejoin.amos.boot.module.cylinder.flc.api.mapper.CylinderUnitMapper;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -160,10 +161,15 @@ public class CylinderDateInfoServiceImpl extends BaseService<CylinderDateInfoDto
return page;
}
@Scheduled(cron = "0 0 2 * * ?") //每天凌晨两点执行
/**
* 每天凌晨两点执行
*/
@Scheduled(cron = "0 0 2 * * ?")
@SchedulerLock(name="fixedDelayJobCylinderDataTask",lockAtMostFor = "PT6H")
public void fixedDelayJob() {
// 每天更新或者添加昨天的数据
Date date = new Date();//取时间
//取时间
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DATE, -1);
......
......@@ -10,6 +10,7 @@ import com.yeejoin.amos.boot.module.cylinder.flc.api.dto.CylinderFillingRecordDt
import com.yeejoin.amos.boot.module.cylinder.flc.api.entity.CylinderFillingRecord;
import com.yeejoin.amos.boot.module.cylinder.flc.api.mapper.CylinderFillingRecordMapper;
import com.yeejoin.amos.boot.module.cylinder.flc.api.service.ICylinderFillingRecordService;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
......@@ -127,6 +128,7 @@ public class CylinderFillingRecordServiceImpl extends BaseService<CylinderFillin
@Scheduled(cron = "${tzs.cylinder.fill.cron}")
@SchedulerLock(name="cylinderFillingRecord2ESTask",lockAtMostFor = "PT6H")
public void setTimeSaveCylinderInfoToES(){
Page<ESCylinderFillingRecordDto> cylinderFillingRecordPage = new Page<>();
Page<ESCylinderFillingRecordDto> cyinderInfoList = cylinderFillingRecordMapper.getCyinderFillingRecord(cylinderFillingRecordPage);
......
......@@ -24,6 +24,7 @@ import com.yeejoin.amos.component.rule.RuleTrigger;
import com.yeejoin.amos.feign.systemctl.Systemctl;
import com.yeejoin.amos.feign.systemctl.model.RegionModel;
import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
......@@ -214,8 +215,10 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind
/**
* 按单位统计
*/
@Override
@Transactional(rollbackFor = Exception.class)
@Scheduled(cron = "0 0 2 * * ?")
@SchedulerLock(name="synFillingUnloadDataTask",lockAtMostFor = "PT6H")
public void synFillingUnloadData() {
cylinderFillingUnloadDataServiceImpl.remove(new LambdaQueryWrapper<CylinderFillingUnloadData>());
countByRegion(regionModel -> {
......@@ -240,8 +243,10 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind
/**
* 按区域统计
*/
@Override
@Transactional(rollbackFor = Exception.class)
@Scheduled(cron = "0 0 2 * * ?")
@SchedulerLock(name="synAreaDataTask",lockAtMostFor = "PT60M")
public void synAreaData() {
cylinderAreaDataServiceImpl.remove(new LambdaQueryWrapper<CylinderAreaData>());
countByRegion(regionModel -> {
......@@ -275,6 +280,7 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind
*/
@Transactional(rollbackFor = Exception.class)
@Scheduled(cron = "* * 2 * * ?")
@SchedulerLock(name="addIntegrityDataTask",lockAtMostFor = "PT60M")
public void addIntegrityData() {
System.out.println("====================数据完整性开始============================");
cylinderIntegrityDataServiceImpl.remove(new LambdaQueryWrapper<CylinderIntegrityData>());
......@@ -337,8 +343,10 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind
/**
* 企业总量按区域统计
*/
@Override
@Transactional(rollbackFor = Exception.class)
@Scheduled(cron = "0 0 2 * * ?")
@SchedulerLock(name="cylinderUnitInfoTask",lockAtMostFor = "PT60M")
public void getCylinderUnitInfo() {
cylinderUnitDataServiceImpl.remove(new LambdaQueryWrapper<CylinderUnitData>());
countByRegion(regionModel -> {
......@@ -371,8 +379,10 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind
/**
* 气瓶总量按区域统计
*/
@Override
@Transactional(rollbackFor = Exception.class)
@Scheduled(cron = "0 0 2 * * ?")
@SchedulerLock(name="cylinderInfoTask",lockAtMostFor = "PT6H")
public void getCylinderInfo() {
cylinderInfoDataServiceImpl.remove(new LambdaQueryWrapper<>());
countByRegion(regionModel -> {
......@@ -404,8 +414,10 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind
/**
* 按单位统计
*/
@Override
@Transactional(rollbackFor = Exception.class)
@Scheduled(cron = "0 0 2 * * ?")
@SchedulerLock(name="synUnitCylinderInfoDataTask",lockAtMostFor = "PT6H")
public void synUnitCylinderInfoData() {
cylinderInfoDataUnitServiceImpl.remove(new LambdaQueryWrapper<CylinderInfoDataUnit>());
countByUnit(cylinderUnit -> {
......@@ -437,8 +449,10 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind
/**
* 充装量按单位和月统计
*/
@Override
@Transactional(rollbackFor = Exception.class)
@Scheduled(cron = "0 0 2 * * ?")
@SchedulerLock(name="synUnitCylinderFillingDataTask",lockAtMostFor = "PT6H")
public void synUnitCylinderFillingData() {
cylinderFillingDataUnitServiceImpl.remove(new LambdaQueryWrapper<CylinderFillingDataUnit>());
countByUnit(cylinderUnit -> {
......@@ -480,8 +494,10 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind
/**
* 按单位统计
*/
@Override
@Transactional(rollbackFor = Exception.class)
@Scheduled(cron = "0 0 2 * * ?")
@SchedulerLock(name="synUnitCylinderTagsDataTask",lockAtMostFor = "PT6H")
public void synUnitCylinderTagsData() {
cylinderTagsDataUnitServiceImpl.remove(new LambdaQueryWrapper<CylinderTagsDataUnit>());
countByUnit(cylinderUnit -> {
......@@ -511,8 +527,10 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind
/**
* 按单位统计
*/
@Override
@Transactional(rollbackFor = Exception.class)
@Scheduled(cron = "0 0 2 * * ?")
@SchedulerLock(name="synUnitIntegrityDataTask",lockAtMostFor = "PT6H")
public void synUnitIntegrityData() {
cylinderIntegrityDataUnitServiceImpl.remove(new LambdaQueryWrapper<CylinderIntegrityDataUnit>());
countByUnit(cylinderUnit -> {
......@@ -570,8 +588,10 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind
/**
* 充装详情按单位统计
*/
@Override
@Transactional(rollbackFor = Exception.class)
@Scheduled(cron = "0 0 2 * * ?")
@SchedulerLock(name="synUnitFillingCheckDataTask",lockAtMostFor = "PT6H")
public void synUnitFillingCheckData() {
// cylinderFillingCheckDataUnitServiceImpl.remove(new LambdaQueryWrapper<CylinderFillingCheckDataUnit>());
countByUnit(cylinderUnit -> {
......@@ -669,8 +689,10 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind
/**
* 充装量、卸液量按单位统计
*/
@Override
@Transactional(rollbackFor = Exception.class)
@Scheduled(cron = "0 0 2 * * ?")
@SchedulerLock(name="synFillingUnloadUnitDataTask",lockAtMostFor = "PT6H")
public void synFillingUnloadUnitData() {
cylinderFillingUnloadDataUnitServiceImpl.remove(new LambdaQueryWrapper<CylinderFillingUnloadDataUnit>());
countByUnit(cylinderUnit -> {
......@@ -693,6 +715,7 @@ public class CylinderInfoServiceImpl extends BaseService<CylinderInfoDto, Cylind
}
@Scheduled(cron = "${tzs.cylinder.info.cron}")
@SchedulerLock(name="cylinderInfoToESTask",lockAtMostFor = "PT6H")
public void setTimeSaveCylinderInfoToES(){
Page<CylinderInfoDto> cylinderInfoPage = new Page<>();
Page<CylinderInfoDto> cyinderInfoList = cylinderInfoMapper.getCyinderInfoList(cylinderInfoPage);
......
......@@ -57,7 +57,7 @@ public class ESAlertCalledService {
public void init() throws Exception
{
//初始化ES,重建索引
initEs();
// initEs();
}
/**
......
......@@ -21,6 +21,14 @@
<artifactId>amos-boot-module-common-api</artifactId>
<version>${amos-biz-boot.version}</version>
</dependency>
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-spring</artifactId>
</dependency>
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-provider-redis-spring</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -16,6 +16,7 @@ import com.yeejoin.amos.boot.module.tcm.flc.biz.service.impl.UnitInfoServiceImpl
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.RoleModel;
import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
......@@ -58,7 +59,7 @@ import java.util.List;
@EnableAsync
@EnableSwagger2WebMvc
@EnableEurekaClient
//@EnableScheduling
@EnableSchedulerLock(defaultLockAtMostFor = "10m")
@MapperScan({"org.typroject.tyboot.demo.face.orm.dao*", "org.typroject.tyboot.face.*.orm.dao*",
"org.typroject.tyboot.core.auth.face.orm.dao*", "org.typroject.tyboot.component.*.face.orm.dao*",
"com.yeejoin.amos.boot.module.**.api.mapper", "com.yeejoin.amos.boot.biz.common.dao.mapper"})
......
package com.yeejoin.amos.boot.module.tcm.biz.config;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.provider.redis.spring.RedisLockProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
/**
* @author Administrator
*/
@Configuration
public class ShedLockConfig {
@Bean
public LockProvider lockProvider(RedisConnectionFactory connectionFactory) {
return new RedisLockProvider(connectionFactory);
}
}
......@@ -67,7 +67,7 @@ public class PlatformUserTopicMessage extends EmqxListener {
try {
if (StringUtils.isNotEmpty(path)) {
if (path.contains("company") && !"company".equals(dataResult.get("level"))) {
equipmentCategoryService.creatTree();
// equipmentCategoryService.creatTree();
} else if (path.contains("agencyuser")) {
regUnitInfoService.updateAdminInfo(dataResult);
}
......
......@@ -57,7 +57,7 @@ public class ESAlertCalledService {
public void init() throws Exception
{
//初始化ES,重建索引
initEs();
// initEs();
}
/**
......
......@@ -41,6 +41,7 @@ import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import com.yeejoin.amos.feign.privilege.model.CompanyModel;
import com.yeejoin.amos.feign.privilege.model.RoleModel;
import com.yeejoin.amos.feign.systemctl.Systemctl;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.entity.ContentType;
......@@ -237,6 +238,7 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI
return model;
}
@SchedulerLock(name="asyncSetQrCodeTask",lockAtMostFor = "PT30M")
@Scheduled(cron = "${async.set.qr-code.cron:0 0/1 * * * ?}")
public void asyncSetQrCode() {
// 给所有新注册的企业创建二维码,每次处理1000个,不排序
......
......@@ -68,13 +68,10 @@ public class PlatformUserTopicMessage extends EmqxListener {
if (StringUtils.isNotEmpty(path)) {
if (path.contains("company") && !"company".equals(dataResult.get("level"))) {
equipmentCategoryService.creatTree();
} else if (path.contains("agencyuser")) {
regUnitInfoService.updateAdminInfo(dataResult);
}
}
} catch (Exception e) {
log.info("平台同步消息失败:{}", e.getMessage());
e.printStackTrace();
}
log.info("平台推送消息同步完成");
}
......
......@@ -57,7 +57,7 @@ public class ESAlertCalledService {
public void init() throws Exception
{
//初始化ES,重建索引
initEs();
// initEs();
}
/**
......
......@@ -67,7 +67,16 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-spring</artifactId>
<version>4.44.0</version>
</dependency>
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-provider-redis-spring</artifactId>
<version>4.44.0</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
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