Переглянути джерело

Merge branch 'dev' of lyr/patient-co-management into dev

chenweida 8 роки тому
батько
коміт
35ace255f8

+ 8 - 0
src/main/java/com/yihu/wlyy/job/QuartzHelper.java

@ -65,6 +65,14 @@ public class QuartzHelper {
        scheduler.deleteJob(jobName);// 删除任务
    }
    public boolean isExistJob(String jobKey) throws SchedulerException {
        JobKey jk = new JobKey("job-id:" + jobKey,"job-group:" + jobKey);
        if(scheduler.checkExists(jk)){
            return true;
        }else{
            return false;
        }
    }
    public void startNow(Class jobClass,  String id, Map<String, Object> params) throws Exception {
        JobDetail job = JobBuilder.newJob(jobClass).

+ 37 - 0
src/main/java/com/yihu/wlyy/job/consult/FamousConsultTimesJob.java

@ -0,0 +1,37 @@
package com.yihu.wlyy.job.consult;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.doctor.schedule.DoctorFamousConsultTimesRemain;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.doctor.FamousDoctorTimesRemainDao;
import com.yihu.wlyy.service.app.account.DoctorInfoService;
import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
import org.json.JSONObject;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
 * Created by lyr on 2016/9/21.
 */
@Component
public class FamousConsultTimesJob implements Job {
    @Autowired
    DoctorWorkTimeService workTimeService;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        workTimeService.consultTimesRemain(df.format(new Date()));
    }
}

+ 1 - 0
src/main/java/com/yihu/wlyy/repository/doctor/DoctorDao.java

@ -118,4 +118,5 @@ public interface DoctorDao extends PagingAndSortingRepository<Doctor, Long>, Jpa
    @Query("update Doctor set idcard = ?2 where code = ?1")
    int updateIdcard(String doctor, String idcard);
    List<Doctor> findByIsFamous(Integer isFamous);
}

+ 85 - 10
src/main/java/com/yihu/wlyy/service/app/scheduling/DoctorWorkTimeService.java

@ -92,16 +92,6 @@ public class DoctorWorkTimeService extends BaseService {
        map.put("workTime", workTime);
        map.put("workWeek", workWeek);
        if (doc.getIsFamous() == 1) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            DoctorFamousConsultTimesRemain timesRemain = timesRemainDao.findByDoctorAndConsultDate(doctor, df.format(new Date()));
            if (timesRemain == null) {
                map.put("famousDoctorTimesRemain",workTime.getFamousConsultTimes());
            } else {
                map.put("famousDoctorTimesRemain",timesRemain.getTimesRemain());
            }
        }
        return map;
    }
@ -317,6 +307,70 @@ public class DoctorWorkTimeService extends BaseService {
        return json;
    }
    /**
     * 查询名医当天是否接受咨询
     *
     * @param doctor
     * @return
     * @throws Exception
     */
    public JSONObject isDoctorWorkingToday(String doctor) throws Exception {
        JSONObject json = new JSONObject();
        Calendar calendar = Calendar.getInstance();
        int week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        if (week == 0) {
            week = 7;
        }
        // 医生工作时间设置
        Map<String, Object> result = findDoctorWeekWork(doctor, String.valueOf(week));
        if (result.get("workTime") == null) {
            // 医生未设置时,默认7*24小时工作
            json.put("status", "1");
            json.put("times", 0);
        } else {
            WlyyDoctorWorkTime doctorWorkTime = (WlyyDoctorWorkTime) result.get("workTime");
            if (doctorWorkTime.getReceiveConsult().equals("0")) {
                json.put("status", "0");
                json.put("times", 0);
            } else {
                if (result.get("workWeek") != null) {
                    WlyyDoctorWorkWeek workWeek = (WlyyDoctorWorkWeek)result.get("workWeek");
                    boolean flag = false;
                    if(StringUtils.isNotEmpty(workWeek.getMorning()) && workWeek.getMorning().equals("1")){
                        json.put("status", "1");
                        json.put("times", doctorWorkTime.getFamousConsultTimes());
                        flag = true;
                    }
                    if(StringUtils.isNotEmpty(workWeek.getMorning()) && workWeek.getMorning().equals("1")){
                        json.put("status", "1");
                        json.put("times", doctorWorkTime.getFamousConsultTimes());
                        flag = true;
                    }
                    if(StringUtils.isNotEmpty(workWeek.getMorning()) && workWeek.getMorning().equals("1")){
                        json.put("status", "1");
                        json.put("times", doctorWorkTime.getFamousConsultTimes());
                        flag = true;
                    }
                    if(!flag){
                        json.put("status", "0");
                        json.put("times", 0);
                    }
                } else {
                    json.put("status", "0");
                    json.put("times", doctorWorkTime.getFamousConsultTimes());
                }
            }
        }
        return json;
    }
    /**
     * 设置名医咨询次数
     *
@ -416,4 +470,25 @@ public class DoctorWorkTimeService extends BaseService {
            return false;
        }
    }
    @Transactional
    public void consultTimesRemain(String date) {
        try {
            List<Doctor> doctors = doctorDao.findByIsFamous(1);
            for (Doctor doc : doctors) {
                JSONObject json = isDoctorWorkingToday(doc.getCode());
                if (json.getString("status").equals("1")) {
                    DoctorFamousConsultTimesRemain timesRemain = new DoctorFamousConsultTimesRemain();
                    timesRemain.setDoctor(doc.getCode());
                    timesRemain.setConsultDate(date);
                    timesRemain.setTimesRemain(json.getInt("times"));
                    timesRemainDao.save(timesRemain);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

+ 13 - 5
src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsService.java

@ -126,15 +126,19 @@ public class StatisticsService extends BaseService {
     * @param level   级别
     * @return
     */
    public String getSignRate(String endDate, String area, int level) throws Exception {
    public JSONObject getSignRate(String endDate, String area, int level) throws Exception {
        JSONObject json =  new JSONObject();
        long signAmount = getTotalAmount(endDate, area, level, SIGN);
        PopulationBase peopleNum = peopleNumDao.findByCodeAndYear(area, Calendar.getInstance().get(Calendar.YEAR));
        DecimalFormat df = new DecimalFormat("0.0000");
        if (peopleNum != null && peopleNum.getNum() > 0) {
            return df.format((signAmount * 1.0000) / peopleNum.getNum() * 100);
            json.put("rate",df.format((signAmount * 1.0000) / peopleNum.getNum() * 100));
            json.put("sign",signAmount);
            json.put("people", peopleNum.getNum());
            return json;
        } else {
            throw new Exception("户籍人口为0");
            throw new Exception("户籍任务人口数为0");
        }
    }
@ -146,13 +150,17 @@ public class StatisticsService extends BaseService {
     * @param level   级别
     * @return
     */
    public String getSignTaskRate(String endDate, String area, int level) throws Exception {
    public JSONObject getSignTaskRate(String endDate, String area, int level) throws Exception {
        JSONObject json =  new JSONObject();
        long signAmount = getTotalAmount(endDate, area, level, SIGN);
        PopulationBase peopleNum = peopleNumDao.findByCodeAndYear(area, Calendar.getInstance().get(Calendar.YEAR));
        DecimalFormat df = new DecimalFormat("0.0000");
        if (peopleNum != null && peopleNum.getTaskNum() > 0) {
            return df.format((signAmount * 1.0000) / peopleNum.getTaskNum() * 100);
            json.put("rate",df.format((signAmount * 1.0000) / peopleNum.getTaskNum() * 100));
            json.put("sign",signAmount);
            json.put("people", peopleNum.getTaskNum());
            return json;
        } else {
            throw new Exception("户籍人口任务数为0");
        }

+ 22 - 0
src/main/java/com/yihu/wlyy/web/common/util/ManagerUtilController.java

@ -1,12 +1,17 @@
package com.yihu.wlyy.web.common.util;
import com.yihu.wlyy.job.QuartzHelper;
import com.yihu.wlyy.job.consult.FamousConsultTimesJob;
import com.yihu.wlyy.service.app.disease.PatientDiseaseService;
import com.yihu.wlyy.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.hash.HashMapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
/**
 * Created by lyr on 2016/09/13.
 */
@ -18,6 +23,8 @@ public class ManagerUtilController extends BaseController{
    PatientDiseaseService diseaseService;
    @Autowired
    StringRedisTemplate redisTemplate;
    @Autowired
    QuartzHelper quartzHelper;
    /**
     * 更新到redis
@ -59,4 +66,19 @@ public class ManagerUtilController extends BaseController{
            return error(-1,"查询失败");
        }
    }
    @RequestMapping(value = "/famous_doctor/start_job")
    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){
            e.printStackTrace();
            return error(-1,"启动失败");
        }
    }
}

+ 1 - 1
src/main/java/com/yihu/wlyy/web/statistic/StatisticsController.java

@ -203,7 +203,7 @@ public class StatisticsController extends BaseController {
    @ResponseBody
    public String getAreaRate(String endDate, String area, int level, String type) {
        try {
            String result = "0.00";
            JSONObject result = null;
            if (type.equals("1")) {
                result = statisticsService.getSignRate(endDate,area,level);