فهرست منبع

检查检验收据抽取

huangzhiyong 6 سال پیش
والد
کامیت
a3b5062ed8

+ 8 - 0
pom.xml

@ -77,6 +77,14 @@
			<artifactId>commons-data-query</artifactId>
			<scope>compile</scope>
		</dependency>
		<dependency>
			<groupId>com.yihu.ehr</groupId>
			<artifactId>commons-data-redis</artifactId>
		</dependency>
		<dependency>
			<groupId>org.quartz-scheduler</groupId>
			<artifactId>quartz</artifactId>
		</dependency>
	</dependencies>
	<build>

+ 2 - 0
src/main/java/com/yihu/ehr/SvrInspectionApplication.java

@ -8,11 +8,13 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.data.web.config.EnableSpringDataWebSupport;
import org.springframework.scheduling.annotation.EnableScheduling;
@EnableEurekaClient
@EnableDiscoveryClient
@EnableFeignClients
@SpringBootApplication
@EnableScheduling
public class SvrInspectionApplication extends SpringBootServletInitializer {
	public static void main(String[] args) {

+ 54 - 0
src/main/java/com/yihu/ehr/svrinspection/commons/config/SchedulerConfig.java

@ -0,0 +1,54 @@
package com.yihu.ehr.svrinspection.commons.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.util.Assert;
/***
 * @author HZY
 * @created 2018/11/27 14:47
 */
@ConfigurationProperties(prefix = "extract.job")
@Configuration
public class SchedulerConfig {
    private int initSize;
    private int maxSize;
    private String cronExp;
    public int getInitSize() {
        return initSize;
    }
    public void setInitSize(int initSize) {
        this.initSize = initSize;
    }
    public int getMaxSize() {
        return maxSize;
    }
    public void setMaxSize(int maxSize) {
        this.maxSize = maxSize;
    }
    public String getCronExp() {
        return cronExp;
    }
    public void setCronExp(String cronExp) {
        this.cronExp = cronExp;
    }
    @Bean
    SchedulerFactoryBean schedulerFactoryBean(){
        Assert.notNull(cronExp, "Can not found extract job config");
        SchedulerFactoryBean bean = new SchedulerFactoryBean();
        bean.setAutoStartup(true);
        bean.setSchedulerName("InspectionExtractScheduler");
        return bean;
    }
}

+ 1 - 3
src/main/java/com/yihu/ehr/svrinspection/controller/AssistanceApplyController.java

@ -18,8 +18,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@ -173,7 +171,7 @@ public class AssistanceApplyController extends EnvelopRestEndPoint {
        AssistanceApplyModel save = null;
        try {
            save = assistanceApplyService.saveApply(apply);
            save = assistanceApplyService.saveOrUpdateApply(apply);
        } catch (ManageException e) {
            return failed(e.getMessage());
        }

+ 54 - 0
src/main/java/com/yihu/ehr/svrinspection/job/InspectionExtractJob.java

@ -0,0 +1,54 @@
package com.yihu.ehr.svrinspection.job;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.lang.SpringContext;
import com.yihu.ehr.profile.queue.RedisCollection;
import com.yihu.ehr.svrinspection.commons.exception.ManageException;
import com.yihu.ehr.svrinspection.model.AssistanceApplyModel;
import com.yihu.ehr.svrinspection.service.AssistanceApplyService;
import org.quartz.*;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.io.Serializable;
/**
 * 检验记录抽取任务
 *
 * @author HZY
 * @created 2018/11/27 14:47
 */
@Component
@DisallowConcurrentExecution
public class InspectionExtractJob implements InterruptableJob {
    @Override
    public void interrupt() throws UnableToInterruptJobException {
    }
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //该对象要采用名称的方式获取,否则:expected single matching bean but found 3: redisTemplate,sessionRedisTemplate,stringRedisTemplate
        RedisTemplate<String, Serializable> redisTemplate = SpringContext.getService("redisTemplate");
        ObjectMapper objectMapper = SpringContext.getService(ObjectMapper.class);
        AssistanceApplyService assistanceApplyService =  SpringContext.getService(AssistanceApplyService.class);
        Serializable serializable = redisTemplate.opsForList().rightPop(RedisCollection.INSPECTION_EXTRACT_QUEUE);
        AssistanceApplyModel applyModel = null;
        try {
            if (serializable != null) {
                String packStr = serializable.toString();
                applyModel = objectMapper.readValue(packStr, AssistanceApplyModel.class);
                if (applyModel !=null) {
                    assistanceApplyService.addApply(applyModel);
                }
            }
        }catch (IOException e) {
            e.printStackTrace();
        } catch (ManageException e) {
            e.printStackTrace();
        }
    }
}

+ 105 - 0
src/main/java/com/yihu/ehr/svrinspection/job/SchedulerManager.java

@ -0,0 +1,105 @@
package com.yihu.ehr.svrinspection.job;
import com.yihu.ehr.svrinspection.commons.config.SchedulerConfig;
import org.quartz.*;
import org.quartz.impl.matchers.GroupMatcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.Set;
import java.util.UUID;
import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;
/**
 * 抽取任务管理
 *
 * @author HZY
 * @created 2018/11/27 14:47
 */
@Component
public class SchedulerManager {
    private int jobSetSize;
    @Autowired
    private Scheduler scheduler;
    @Autowired
    private SchedulerConfig schedulerConfig;
    @PostConstruct
    private void init() throws Exception {
        try {
            for (int i = 0; i < schedulerConfig.getInitSize(); i++) {
                String suffix = UUID.randomUUID().toString().substring(0, 8);
                JobDetail jobDetail = newJob(InspectionExtractJob.class)
                        .withIdentity("PackResolveJob-" + suffix, "inspectionTract")
                        .build();
                CronTrigger trigger = newTrigger()
                        .withIdentity("inspectionTractTrigger-" + suffix, "inspectionTract")
                        .withSchedule(CronScheduleBuilder.cronSchedule(schedulerConfig.getCronExp()))
                        .startNow()
                        .build();
                scheduler.scheduleJob(jobDetail, trigger);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        this.jobSetSize = schedulerConfig.getInitSize();
    }
    public int getJobSetSize() {
        return jobSetSize;
    }
    public int getJobSize() throws Exception {
        GroupMatcher groupMatcher = GroupMatcher.groupEquals("inspectionTract");
        Set<JobKey> jobKeys = scheduler.getJobKeys(groupMatcher);
        return jobKeys.size();
    }
    public void addJob (int count, String cronExp) throws Exception {
        int addCount = 0;
        GroupMatcher groupMatcher = GroupMatcher.groupEquals("inspectionTract");
        Set<JobKey> jobKeys = scheduler.getJobKeys(groupMatcher);
        int activeJob = jobKeys.size();
        for (int i = 0; i < count; i++) {
            if (i + activeJob >= schedulerConfig.getMaxSize()) {
                break;
            }
            String suffix = UUID.randomUUID().toString().substring(0, 8);
            JobDetail jobDetail = newJob(InspectionExtractJob.class)
                    .withIdentity("inspectionTractJob-" + suffix, "inspectionTract")
                    .build();
            CronTrigger trigger = newTrigger()
                    .withIdentity("inspectionTractJob-" + suffix, "inspectionTract")
                    .withSchedule(CronScheduleBuilder.cronSchedule(cronExp))
                    .startNow()
                    .build();
            scheduler.scheduleJob(jobDetail, trigger);
            addCount = i + 1;
        }
        this.jobSetSize += addCount;
        if (this.jobSetSize > schedulerConfig.getMaxSize()) {
            jobSetSize = schedulerConfig.getMaxSize();
        }
    }
    public void minusJob (int count) throws Exception {
        int minusCount = count;
        GroupMatcher groupMatcher = GroupMatcher.groupEquals("inspectionTract");
        Set<JobKey> jobKeySet = scheduler.getJobKeys(groupMatcher);
        for (JobKey jobKey : jobKeySet) {
            scheduler.deleteJob(jobKey);
            if (--count == 0) {
                break;
            }
        }
        this.jobSetSize -= minusCount;
        if (this.jobSetSize < 0) {
            jobSetSize = 0;
        }
    }
}

+ 49 - 3
src/main/java/com/yihu/ehr/svrinspection/model/AssistanceApplyModel.java

@ -30,11 +30,17 @@ public class AssistanceApplyModel extends IntegerIdentityEntity {
    private String examDept;
    private String examItemName;
    private String patientName;
    private Integer patientAge;
    private String patientAge;
    private String patientSex;
    private String inspector;
    private String examDeptName;
    private String examItemCode;
    private String applyOrgName;
    private String solutionOrgName;
    @Basic
    @Column(name = "apply_org", nullable = true, length = 32)
    public String getApplyOrg() {
@ -209,11 +215,11 @@ public class AssistanceApplyModel extends IntegerIdentityEntity {
    @Basic
    @Column(name = "patient_age", nullable = true, length = 4)
    public Integer getPatientAge() {
    public String getPatientAge() {
        return patientAge;
    }
    public void setPatientAge(Integer patientAge) {
    public void setPatientAge(String patientAge) {
        this.patientAge = patientAge;
    }
@ -236,4 +242,44 @@ public class AssistanceApplyModel extends IntegerIdentityEntity {
    public void setInspector(String inspector) {
        this.inspector = inspector;
    }
    @Basic
    @Column(name = "exam_dept_name", nullable = true, length = 255)
    public String getExamDeptName() {
        return examDeptName;
    }
    public void setExamDeptName(String examDeptName) {
        this.examDeptName = examDeptName;
    }
    @Basic
    @Column(name = "exam_item_code", nullable = true, length = 255)
    public String getExamItemCode() {
        return examItemCode;
    }
    public void setExamItemCode(String examItemCode) {
        this.examItemCode = examItemCode;
    }
    @Basic
    @Column(name = "apply_org_name", nullable = true, length = 255)
    public String getApplyOrgName() {
        return applyOrgName;
    }
    public void setApplyOrgName(String applyOrgName) {
        this.applyOrgName = applyOrgName;
    }
    @Basic
    @Column(name = "solution_org_name", nullable = true, length = 255)
    public String getSolutionOrgName() {
        return solutionOrgName;
    }
    public void setSolutionOrgName(String solutionOrgName) {
        this.solutionOrgName = solutionOrgName;
    }
}

+ 79 - 34
src/main/java/com/yihu/ehr/svrinspection/service/AssistanceApplyService.java

@ -1,10 +1,12 @@
package com.yihu.ehr.svrinspection.service;
import com.yihu.ehr.query.BaseJpaService;
import com.yihu.ehr.redis.schema.OrgKeySchema;
import com.yihu.ehr.svrinspection.commons.exception.ManageException;
import com.yihu.ehr.svrinspection.dao.AssistanceApplyDao;
import com.yihu.ehr.svrinspection.model.AssistanceApplyModel;
import com.yihu.ehr.util.datetime.DateUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -13,34 +15,59 @@ import java.util.Date;
/**
 *  检验申请 业务类
 * 检验申请 业务类
 *
 * @author HZY
 * @created 2018/11/14 9:21
 */
@Transactional
@Service
public class AssistanceApplyService  extends BaseJpaService<AssistanceApplyModel, AssistanceApplyDao> {
public class AssistanceApplyService extends BaseJpaService<AssistanceApplyModel, AssistanceApplyDao> {
    @Autowired
    private AssistanceApplyDao assistanceApplyDao;
    @Autowired
    private OrgKeySchema orgKeySchema;
    public AssistanceApplyModel findById(int id){
    public AssistanceApplyModel findById(int id) {
        return assistanceApplyDao.findOne(id);
    }
    public AssistanceApplyModel saveApply(AssistanceApplyModel assistanceApplyModel) throws ManageException {
        if (assistanceApplyModel.getId() == null ){
            assistanceApplyModel.setCreateTime(new Date());
            //已申请
            assistanceApplyModel.setSolutionStatus(0);
            assistanceApplyModel.setIsRead(0);
        }
         assistanceApplyModel = assistanceApplyDao.save(assistanceApplyModel);
    public AssistanceApplyModel addApply(AssistanceApplyModel assistanceApplyModel) throws ManageException {
        assistanceApplyModel.setCreateTime(new Date());
        assistanceApplyModel.setSolutionStatus(-1);
        assistanceApplyModel.setIsRead(0);
        assistanceApplyModel = assistanceApplyDao.save(assistanceApplyModel);
        return assistanceApplyModel;
    }
    //申请
    public AssistanceApplyModel saveOrUpdateApply(AssistanceApplyModel assistanceApplyModel) throws ManageException {
        //申请机构名
        String applyOrgName = getOrgName(assistanceApplyModel.getApplyOrg());
        //处理机构名
        String solutionOrgName = getOrgName(assistanceApplyModel.getSolutionOrg());
        assistanceApplyModel.setCreateTime(new Date());
        //已申请
        assistanceApplyModel.setSolutionStatus(0);
        assistanceApplyModel.setIsRead(0);
        assistanceApplyModel.setApplyOrgName(applyOrgName);
        assistanceApplyModel.setSolutionOrgName(solutionOrgName);
        assistanceApplyModel = assistanceApplyDao.save(assistanceApplyModel);
        return assistanceApplyModel;
    }
        public AssistanceApplyModel solutionApply(int id,String replyUserId,String replyContent) throws ManageException {
    /**
     *  申请处理
     *
     * @param id                申请记录ID
     * @param replyUserId      处理人ID
     * @param replyContent      回复内容
     * @return
     * @throws ManageException
     */
    public AssistanceApplyModel solutionApply(int id, String replyUserId, String replyContent) throws ManageException {
        AssistanceApplyModel applyModel = findById(id);
        if (applyModel == null) {
            throw new ManageException("申请记录不存在!");
@ -55,13 +82,14 @@ public class AssistanceApplyService  extends BaseJpaService<AssistanceApplyModel
    /**
     * 根据申请状态-获取今日统计量
     *
     * @param status
     * @return
     */
    public long toDayCount(int status) {
        String toDay = DateUtil.getNowDate(DateUtil.DEFAULT_DATE_YMD_FORMAT);
        Date start = DateUtil.parseDate(toDay + " 00:00:00",DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
        Date end = DateUtil.parseDate(toDay + " 23:59:59",DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
        Date start = DateUtil.parseDate(toDay + " 00:00:00", DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
        Date end = DateUtil.parseDate(toDay + " 23:59:59", DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
        long todayCount = assistanceApplyDao.countAllBySolutionStatusAndCreateTimeBetween(status, start, end);
        return todayCount;
    }
@ -71,25 +99,27 @@ public class AssistanceApplyService  extends BaseJpaService<AssistanceApplyModel
    /**
     * 通过申请机构 获取检验处理总数
     * @param applyOrg  申请机构编码
     * @param status    处理状态
     *
     * @param applyOrg 申请机构编码
     * @param status   处理状态
     * @return
     */
    public long toDayIncreaseByApplyOrg(String applyOrg,int status){
    public long toDayIncreaseByApplyOrg(String applyOrg, int status) {
        long count = assistanceApplyDao.countAllByApplyOrgAndSolutionStatus(applyOrg, status);
        return count;
    }
    /**
     * 通过申请机构获取 今日已处理/未处理量
     * @param solutionOrg   申请处理机构
     *
     * @param solutionOrg 申请处理机构
     * @return
     */
    public long toDayCountByApplyOrg(String solutionOrg,int status) {
    public long toDayCountByApplyOrg(String solutionOrg, int status) {
        String toDay = DateUtil.getNowDate(DateUtil.DEFAULT_DATE_YMD_FORMAT);
        Date start = DateUtil.parseDate(toDay + " 00:00:00",DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
        Date end = DateUtil.parseDate(toDay + " 23:59:59",DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
        long todayCount = assistanceApplyDao.countAllByApplyOrgAndSolutionStatusAndCreateTimeBetween(solutionOrg,status, start, end);
        Date start = DateUtil.parseDate(toDay + " 00:00:00", DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
        Date end = DateUtil.parseDate(toDay + " 23:59:59", DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
        long todayCount = assistanceApplyDao.countAllByApplyOrgAndSolutionStatusAndCreateTimeBetween(solutionOrg, status, start, end);
        return todayCount;
    }
@ -98,39 +128,42 @@ public class AssistanceApplyService  extends BaseJpaService<AssistanceApplyModel
    /**
     * 通过处理机构获取 今日新增申请量
     * @param solutionOrg   申请处理机构
     *
     * @param solutionOrg 申请处理机构
     * @return
     */
    public long toDayIncreaseBySolutionOrg(String solutionOrg){
    public long toDayIncreaseBySolutionOrg(String solutionOrg) {
        String toDay = DateUtil.getNowDate(DateUtil.DEFAULT_DATE_YMD_FORMAT);
        Date start = DateUtil.parseDate(toDay + " 00:00:00",DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
        Date end = DateUtil.parseDate(toDay + " 23:59:59",DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
        Date start = DateUtil.parseDate(toDay + " 00:00:00", DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
        Date end = DateUtil.parseDate(toDay + " 23:59:59", DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
        long count = assistanceApplyDao.countAllBySolutionOrgAndCreateTimeBetween(solutionOrg, start, end);
        return count;
    }
    /**
     * 通过处理机构获取 今日已处理/未处理量
     * @param solutionOrg   申请处理机构
     *
     * @param solutionOrg 申请处理机构
     * @return
     */
    public long toDayCountBySolutionOrg(String solutionOrg,int status) {
    public long toDayCountBySolutionOrg(String solutionOrg, int status) {
        String toDay = DateUtil.getNowDate(DateUtil.DEFAULT_DATE_YMD_FORMAT);
        Date start = DateUtil.parseDate(toDay + " 00:00:00",DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
        Date end = DateUtil.parseDate(toDay + " 23:59:59",DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
        long todayCount = assistanceApplyDao.countAllBySolutionOrgAndSolutionStatusAndCreateTimeBetween(solutionOrg,status, start, end);
        Date start = DateUtil.parseDate(toDay + " 00:00:00", DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
        Date end = DateUtil.parseDate(toDay + " 23:59:59", DateUtil.DEFAULT_YMDHMSDATE_FORMAT);
        long todayCount = assistanceApplyDao.countAllBySolutionOrgAndSolutionStatusAndCreateTimeBetween(solutionOrg, status, start, end);
        return todayCount;
    }
    /**
     * 申请撤回
     * @param id        申请记录id
     * @param status    申请记录状态
     *
     * @param id     申请记录id
     * @param status 申请记录状态
     * @return
     * @throws ManageException
     */
    public AssistanceApplyModel retractApply(int id,int status) throws ManageException {
    public AssistanceApplyModel retractApply(int id, int status) throws ManageException {
        AssistanceApplyModel applyModel = findById(id);
        if (applyModel == null) {
            throw new ManageException("申请记录不存在!");
@ -141,4 +174,16 @@ public class AssistanceApplyService  extends BaseJpaService<AssistanceApplyModel
        return applyModel;
    }
    /**
     *获取机构名称redis
     * @return
     */
    public String getOrgName(String key) {
        if (StringUtils.isEmpty(key)) {
            return "";
        }else {
            return orgKeySchema.get(key);
        }
    }
}

+ 22 - 1
src/main/resources/application.yml

@ -15,6 +15,23 @@ spring:
    min-idle: 8
    validation-query: SELECT 1
    test-on-borrow: true
  # REDIS
  redis:
    database: 0 # Database index used by the connection factory.
    port: 6379 # Redis server port.
    password: # Login password of the redis server.
    timeout: 0 # Connection timeout in milliseconds.
    pool:
      max-active: 8
      max-idle: 8
      max-wait: -1
      min-idle: 1
extract:
  job:
    init-size: 5 #抽取初始任务数
    max-size: 5 #抽取最大任务数
    cron-exp: 0/1 * * * * ? #抽取任务触发间隔表达式
---
spring:
@ -25,4 +42,8 @@ spring:
    password: o8t$P39ekYSZ
  data:
    solr:
      zk-host: 11.1.2.30:2181/solr
      zk-host: 11.1.2.35:2181/solr
  redis:
    host: 172.18.20.20 # Redis server host.
    port: 6381
    password: jkzl2015