diff --git a/src/main/java/com/xkrs/common/StaticScheduleTask.java b/src/main/java/com/xkrs/common/StaticScheduleTask.java index 397510b..3c8dbaf 100644 --- a/src/main/java/com/xkrs/common/StaticScheduleTask.java +++ b/src/main/java/com/xkrs/common/StaticScheduleTask.java @@ -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 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 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); } } \ No newline at end of file diff --git a/src/main/java/com/xkrs/controller/SettingController.java b/src/main/java/com/xkrs/controller/SettingController.java index 3da73d5..8dd2a85 100644 --- a/src/main/java/com/xkrs/controller/SettingController.java +++ b/src/main/java/com/xkrs/controller/SettingController.java @@ -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 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 settingEntityList = settingDao.findAll(); - if (settingEntityList.isEmpty()) { - return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有状态信息", locale); - } - SettingEntity settingEntity = settingEntityList.get(0); - return outputEncapsulationObject(PromptMessageEnum.SUCCESS, settingEntity.getSwitchState(), locale); + return settingService.querySwitchState(); } - } diff --git a/src/main/java/com/xkrs/service/SettingService.java b/src/main/java/com/xkrs/service/SettingService.java new file mode 100644 index 0000000..b1b9ac3 --- /dev/null +++ b/src/main/java/com/xkrs/service/SettingService.java @@ -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(); + +} diff --git a/src/main/java/com/xkrs/service/impl/SettingServiceImpl.java b/src/main/java/com/xkrs/service/impl/SettingServiceImpl.java new file mode 100644 index 0000000..f2d4396 --- /dev/null +++ b/src/main/java/com/xkrs/service/impl/SettingServiceImpl.java @@ -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 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 settingEntityList = settingDao.findAll(); + if (settingEntityList.isEmpty()) { + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有状态信息", locale); + } + SettingEntity settingEntity = settingEntityList.get(0); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, settingEntity.getSwitchState(), locale); + } +}