123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- 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;
- import java.util.Date;
- /**
- * 检验申请 业务类
- *
- * @author HZY
- * @created 2018/11/14 9:21
- */
- @Transactional
- @Service
- public class AssistanceApplyService extends BaseJpaService<AssistanceApplyModel, AssistanceApplyDao> {
- @Autowired
- private AssistanceApplyDao assistanceApplyDao;
- @Autowired
- private OrgKeySchema orgKeySchema;
- public AssistanceApplyModel findById(int id) {
- return assistanceApplyDao.findOne(id);
- }
- 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;
- }
- /**
- * 申请处理
- *
- * @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("申请记录不存在!");
- }
- applyModel.setSolutionUserId(replyUserId);
- applyModel.setSolutionReply(replyContent);
- applyModel.setSolutionDate(new Date());
- applyModel.setSolutionStatus(1);
- assistanceApplyDao.save(applyModel);
- return applyModel;
- }
- /**
- * 根据申请状态-获取今日统计量
- *
- * @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);
- long todayCount = assistanceApplyDao.countAllBySolutionStatusAndCreateTimeBetween(status, start, end);
- return todayCount;
- }
- /* **************** 基层医疗机构 ********** */
- /**
- * 通过申请机构 获取检验处理总数
- *
- * @param applyOrg 申请机构编码
- * @param status 处理状态
- * @return
- */
- public long toDayIncreaseByApplyOrg(String applyOrg, int status) {
- long count = assistanceApplyDao.countAllByApplyOrgAndSolutionStatus(applyOrg, status);
- return count;
- }
- /**
- * 通过申请机构获取 今日已处理/未处理量
- *
- * @param solutionOrg 申请处理机构
- * @return
- */
- 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);
- return todayCount;
- }
- /*************************** 医生端 ************************************/
- /**
- * 通过处理机构获取 今日新增申请量
- *
- * @param solutionOrg 申请处理机构
- * @return
- */
- 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);
- long count = assistanceApplyDao.countAllBySolutionOrgAndCreateTimeBetween(solutionOrg, start, end);
- return count;
- }
- /**
- * 通过处理机构获取 今日已处理/未处理量
- *
- * @param solutionOrg 申请处理机构
- * @return
- */
- 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);
- return todayCount;
- }
- /**
- * 申请撤回
- *
- * @param id 申请记录id
- * @param status 申请记录状态
- * @return
- * @throws ManageException
- */
- public AssistanceApplyModel retractApply(int id, int status) throws ManageException {
- AssistanceApplyModel applyModel = findById(id);
- if (applyModel == null) {
- throw new ManageException("申请记录不存在!");
- }
- applyModel.setSolutionStatus(status);
- assistanceApplyDao.save(applyModel);
- return applyModel;
- }
- /**
- *获取机构名称redis
- * @return
- */
- public String getOrgName(String key) {
- if (StringUtils.isEmpty(key)) {
- return "";
- }else {
- return orgKeySchema.get(key);
- }
- }
- }
|