123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- package com.yihu.wlyy.web.quota;
- import com.yihu.wlyy.job.FollowupPlanJob;
- import com.yihu.wlyy.job.QuartzHelper;
- import com.yihu.wlyy.job.consult.ConsultCleanerJob;
- import com.yihu.wlyy.job.consult.FamousConsultTimesJob;
- import com.yihu.wlyy.service.app.disease.PatientDiseaseService;
- import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
- import com.yihu.wlyy.service.app.statistics.StatisticsService;
- import com.yihu.wlyy.service.quota.JobService;
- import com.yihu.wlyy.web.BaseController;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.redis.core.StringRedisTemplate;
- import org.springframework.http.MediaType;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RestController;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.HashMap;
- import static com.yihu.wlyy.job.consult.ConsultCleanerJob.ConsultTerminatorJobKey;
- /**
- * 任务启动
- *
- * @author chenweida
- */
- @RestController
- @RequestMapping(value = "/job", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
- @Api(description = "后台-任务控制")
- public class JobController extends BaseController {
- private final JobService jobService;
- private final PatientDiseaseService diseaseService;
- private final StringRedisTemplate redisTemplate;
- private final QuartzHelper quartzHelper;
- private final DoctorWorkTimeService workTimeService;
- private final StatisticsService statisticsService;
- @Autowired
- public JobController(StatisticsService statisticsService, JobService jobService, StringRedisTemplate redisTemplate, DoctorWorkTimeService workTimeService, PatientDiseaseService diseaseService, QuartzHelper quartzHelper) {
- this.statisticsService = statisticsService;
- this.jobService = jobService;
- this.redisTemplate = redisTemplate;
- this.workTimeService = workTimeService;
- this.diseaseService = diseaseService;
- this.quartzHelper = quartzHelper;
- }
- /**
- * 启动任务
- *
- * @param id id
- * @return
- */
- @RequestMapping(value = "startNowById", method = RequestMethod.GET)
- public String startNowById(String id) {
- try {
- jobService.startNowById(id);
- return success("启动成功!");
- } catch (Exception e) {
- error(e);
- return invalidUserException(e, -1, "启动失败:" + e.getMessage());
- }
- }
- /**
- * 生成过去几天的数据
- *
- * @param day
- * @return
- */
- @RequestMapping(value = "productDataByDay", method = RequestMethod.GET)
- public String productDataByDay(Integer day) {
- try {
- jobService.productDataByDay(day);
- return success("启动成功!");
- } catch (Exception e) {
- error(e);
- return invalidUserException(e, -1, "启动失败:" + e.getMessage());
- }
- }
- /**
- * 生成过去某一天的全部的数据
- *
- * @param day
- * @return
- */
- @RequestMapping(value = "productDataByOneDay", method = RequestMethod.GET)
- public String productDataByOneDay(String day) {
- try {
- jobService.productDataByOneDay(day);
- return success("启动成功!");
- } catch (Exception e) {
- error(e);
- return invalidUserException(e, -1, "启动失败:" + e.getMessage());
- }
- }
- /**
- * 生成过去某一天的某一个指标的数据
- *
- * @param day
- * @return
- */
- @RequestMapping(value = "productDataByOneDayWithId", method = RequestMethod.GET)
- public String productDataByOneDayWithId(String day, String id) {
- try {
- jobService.productDataByOneDayWithId(day, id);
- return success("启动成功!");
- } catch (Exception e) {
- error(e);
- return invalidUserException(e, -1, "启动失败:" + e.getMessage());
- }
- }
- /**
- * 生成过去某几天的某一个指标的数据
- *
- * @param day
- * @return
- */
- @RequestMapping(value = "productDataByDayAndId", method = RequestMethod.GET)
- public String productDataByDayAndId(Integer day, String id) {
- try {
- jobService.productDataByDayAndId(day, id);
- return success("启动成功!");
- } catch (Exception e) {
- error(e);
- return invalidUserException(e, -1, "启动失败:" + e.getMessage());
- }
- }
- /**
- * 启动任务
- *
- * @param id id
- * @return
- */
- @RequestMapping(value = "startById", method = RequestMethod.GET)
- public String startById(String id) {
- try {
- jobService.startById(id);
- return success("启动成功!");
- } catch (Exception e) {
- error(e);
- return invalidUserException(e, -1, "启动失败:" + e.getMessage());
- }
- }
- /**
- * 停止任务
- *
- * @param id id
- * @return
- */
- @RequestMapping(value = "stopById", method = RequestMethod.GET)
- public String stopById(String id) {
- try {
- jobService.stopById(id);
- return success("停止成功!");
- } catch (Exception e) {
- error(e);
- return invalidUserException(e, -1, "启动失败:" + e.getMessage());
- }
- }
- /**
- * 停止所有任务
- *
- * @return
- */
- @RequestMapping(value = "stopAll", method = RequestMethod.GET)
- public String stopAll() {
- try {
- jobService.stopAll();
- return success("停止成功!");
- } catch (Exception e) {
- error(e);
- return invalidUserException(e, -1, "启动失败:" + e.getMessage());
- }
- }
- /**
- * 启动所有任务
- *
- * @return
- */
- @RequestMapping(value = "startAll", method = RequestMethod.GET)
- public String startAll() {
- try {
- jobService.startAll();
- return success("启动成功!");
- } catch (Exception e) {
- error(e);
- return invalidUserException(e, -1, "启动失败:" + e.getMessage());
- }
- }
- @RequestMapping(value = "startaaaa", method = RequestMethod.GET)
- public String startaaaa() {
- try {
- jobService.startaaaa();
- return success("启动成功!");
- } catch (Exception e) {
- error(e);
- return invalidUserException(e, -1, "启动失败:" + e.getMessage());
- }
- }
- /**
- * 将患者疾病推送到redis
- *
- * @return
- */
- @RequestMapping(value = "/disease/to_redis", method = RequestMethod.GET)
- public String updateToRedid() {
- try {
- diseaseService.updateToRedis();
- return write(200, "更新成功");
- } catch (Exception e) {
- return error(-1, "更新失败");
- }
- }
- /**
- * 将患者疾病到数据库
- *
- * @return
- */
- @RequestMapping(value = "/disease/to_disease", method = RequestMethod.GET)
- public String updateToDisease() {
- try {
- diseaseService.updateToDisease();
- return write(200, "更新成功");
- } catch (Exception e) {
- return error(-1, "更新失败");
- }
- }
- /**
- * 从Redis查询患者疾病
- *
- * @param patient
- * @return
- */
- @RequestMapping(value = "/disease/patient", method = RequestMethod.GET)
- public String getDiseaseFromRedis(String patient) {
- try {
- return write(200, "查询成功", "data", redisTemplate.opsForValue().get("disease:" + patient));
- } catch (Exception e) {
- e.printStackTrace();
- return error(-1, "查询失败");
- }
- }
- /**
- * 开始名医咨询剩余次数统计任务
- *
- * @return
- */
- @RequestMapping(value = "/famous_doctor/start_job", method = RequestMethod.GET)
- public String startConsultTimesJob() {
- try {
- if (!quartzHelper.isExistJob("famous-doctor-times")) {
- quartzHelper.addJob(FamousConsultTimesJob.class, "0 0 0 * * ?", "famous-doctor-times", new HashMap<String, Object>());
- return write(200, "启动成功");
- } else {
- return write(200, "任务已存在");
- }
- } catch (Exception e) {
- error(e);
- return error(-1, "启动失败");
- }
- }
- /**
- * 名医咨询剩余次数手动更新
- *
- * @return
- */
- @RequestMapping(value = "/famous_doctor/times_update", method = RequestMethod.GET)
- public String famousConsultTimeUpdate() {
- try {
- workTimeService.consultTimesRemain(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
- return write(200, "更新成功");
- } catch (Exception e) {
- error(e);
- return error(-1, "更新失败");
- }
- }
- /**
- * 更新人口数据到redis
- *
- * @return
- */
- public String peopleNumToRedis() {
- try {
- statisticsService.peopleNumToRedis();
- return write(200, "更新成功");
- } catch (Exception e) {
- error(e);
- return error(-1, "更新失败");
- }
- }
- /**
- * 添加患者咨询超时未响应关闭任务。
- */
- @RequestMapping(value = "/consult_auto_termination", method = RequestMethod.POST)
- @ApiOperation("添加超时咨询自动关闭任务")
- public String addConsultJob() {
- try {
- quartzHelper.startNow(ConsultCleanerJob.class, ConsultTerminatorJobKey, null);
- return write(200, "");
- } catch (Exception e) {
- error(e);
- return error(-1, e.getMessage());
- }
- }
- /******************************************** 随访计划任务 **********************************************************************/
- @RequestMapping(value = "/followup/planJob", method = RequestMethod.POST)
- @ApiOperation("随访计划消息发送任务")
- public String addFollowPlanJob() {
- try {
- String jobKey = "followup-plan";
- if (!quartzHelper.isExistJob(jobKey)) {
- quartzHelper.addJob(FollowupPlanJob.class, "0 0/5 0 * * ?", jobKey, new HashMap<String, Object>());
- return write(200, "启动成功");
- } else {
- return write(200, "任务已存在");
- }
- } catch (Exception e) {
- error(e);
- return error(-1, "启动失败");
- }
- }
- }
|