添加火点审核开关计划任务

1、早上八点打开火点审核开关
2、晚上十点关闭火点审核开关
This commit is contained in:
liuchengqian 2022-06-07 09:24:30 +08:00
parent fac3ab9d2f
commit 3aa2747e18
4 changed files with 101 additions and 60 deletions

View File

@ -1,14 +1,12 @@
package com.xkrs.common;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xkrs.model.qo.SettingQo;
import com.xkrs.service.SettingService;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.HashMap;
import java.util.Map;
import static com.xkrs.utils.WDHttpClientUtils.sendHttpPost;
import javax.annotation.Resource;
/**
* 火点审核开关计划任务
@ -17,29 +15,22 @@ import static com.xkrs.utils.WDHttpClientUtils.sendHttpPost;
@EnableScheduling
public class StaticScheduleTask {
@Resource
private SettingService settingService;
//早上八点打开火点审核开关
@Scheduled(cron = "0 0 8 * * ?")
private void openVerifySwitch() {
try {
String url = "http://118.24.27.47:6801/updateswitchstate";
Map<String, Object> map = new HashMap<>();
map.put("switchState", "1");
sendHttpPost(url, new ObjectMapper().writeValueAsString(map));
} catch (Exception e) {
e.printStackTrace();
}
SettingQo settingQo = new SettingQo();
settingQo.setSwitchState("1");
settingService.updateSwitchState(settingQo);
}
//晚上十点关闭火点审核开关
@Scheduled(cron = "0 0 22 * * ?")
private void closeVerifySwitch() {
try {
String url = "http://118.24.27.47:6801/updateswitchstate";
Map<String, Object> map = new HashMap<>();
map.put("switchState", "0");
sendHttpPost(url, new ObjectMapper().writeValueAsString(map));
} catch (Exception e) {
e.printStackTrace();
}
SettingQo settingQo = new SettingQo();
settingQo.setSwitchState("0");
settingService.updateSwitchState(settingQo);
}
}

View File

@ -1,23 +1,13 @@
package com.xkrs.controller;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.dao.CountyCodeWeiXinDao;
import com.xkrs.dao.SettingDao;
import com.xkrs.model.entity.SettingEntity;
import com.xkrs.model.qo.SettingQo;
import org.apache.http.util.TextUtils;
import org.springframework.context.i18n.LocaleContextHolder;
import com.xkrs.service.SettingService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.List;
import java.util.Locale;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
/**
* 设置审核开关状态
@ -26,41 +16,22 @@ import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulat
public class SettingController {
@Resource
private SettingDao settingDao;
private SettingService settingService;
@Resource
private CountyCodeWeiXinDao countyCodeWeiXinDao;
@Transactional(rollbackOn = Exception.class)
/**
* 更新审核开关状态
*/
@PostMapping("/updateswitchstate")
public String updateSwitchState(@RequestBody SettingQo settingQo) {
Locale locale = LocaleContextHolder.getLocale();
if (TextUtils.isEmpty(settingQo.getSwitchState())) {
return outputEncapsulationObject(PromptMessageEnum.PARAM_NULL, "switchState参数不能为空", locale);
}
List<SettingEntity> settingEntityList = settingDao.findAll();
if (settingEntityList.isEmpty()) {
SettingEntity settingEntity = new SettingEntity();
settingEntity.setSwitchState(settingQo.getSwitchState());
settingDao.save(settingEntity);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale);
}
for (SettingEntity settingEntity : settingEntityList) {
settingDao.updateSwitchStateById(settingEntity.getId(), settingQo.getSwitchState());
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale);
return settingService.updateSwitchState(settingQo);
}
/**
* 查询审核开关状态
*/
@GetMapping("/queryswitchstate")
public String querySwitchState() {
Locale locale = LocaleContextHolder.getLocale();
List<SettingEntity> settingEntityList = settingDao.findAll();
if (settingEntityList.isEmpty()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有状态信息", locale);
return settingService.querySwitchState();
}
SettingEntity settingEntity = settingEntityList.get(0);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, settingEntity.getSwitchState(), locale);
}
}

View File

@ -0,0 +1,18 @@
package com.xkrs.service;
import com.xkrs.model.qo.SettingQo;
import org.springframework.web.bind.annotation.RequestBody;
public interface SettingService {
/**
* 更新审核开关状态
*/
String updateSwitchState(@RequestBody SettingQo settingQo);
/**
* 查询审核开关状态
*/
String querySwitchState();
}

View File

@ -0,0 +1,61 @@
package com.xkrs.service.impl;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.dao.SettingDao;
import com.xkrs.model.entity.SettingEntity;
import com.xkrs.model.qo.SettingQo;
import com.xkrs.service.SettingService;
import org.apache.http.util.TextUtils;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.List;
import java.util.Locale;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
@Service
public class SettingServiceImpl implements SettingService {
@Resource
private SettingDao settingDao;
/**
* 更新审核开关状态
*/
@Transactional(rollbackOn = Exception.class)
@Override
public String updateSwitchState(SettingQo settingQo) {
Locale locale = LocaleContextHolder.getLocale();
if (TextUtils.isEmpty(settingQo.getSwitchState())) {
return outputEncapsulationObject(PromptMessageEnum.PARAM_NULL, "switchState参数不能为空", locale);
}
List<SettingEntity> settingEntityList = settingDao.findAll();
if (settingEntityList.isEmpty()) {
SettingEntity settingEntity = new SettingEntity();
settingEntity.setSwitchState(settingQo.getSwitchState());
settingDao.save(settingEntity);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale);
}
for (SettingEntity settingEntity : settingEntityList) {
settingDao.updateSwitchStateById(settingEntity.getId(), settingQo.getSwitchState());
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功", locale);
}
/**
* 查询审核开关状态
*/
@Override
public String querySwitchState() {
Locale locale = LocaleContextHolder.getLocale();
List<SettingEntity> settingEntityList = settingDao.findAll();
if (settingEntityList.isEmpty()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有状态信息", locale);
}
SettingEntity settingEntity = settingEntityList.get(0);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, settingEntity.getSwitchState(), locale);
}
}