From c58ff6620b5f6780b3bcadce1752d40f5e5052b3 Mon Sep 17 00:00:00 2001 From: jiangjiazhi Date: Mon, 27 Mar 2017 11:25:27 +0800 Subject: [PATCH] commit --- .../web/facade/PatientCheckTicketFacade.java | 446 ++++++++++----------- 1 file changed, 221 insertions(+), 225 deletions(-) diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/PatientCheckTicketFacade.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/PatientCheckTicketFacade.java index 77c038e..9337b6b 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/PatientCheckTicketFacade.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/PatientCheckTicketFacade.java @@ -1,226 +1,222 @@ -package com.lyms.platform.operate.web.facade; - -import com.lyms.platform.biz.service.AreaCodeService; -import com.lyms.platform.biz.service.AutoIncermentService; -import com.lyms.platform.biz.service.PatientCheckTicketService; -import com.lyms.platform.biz.service.PatientsService; -import com.lyms.platform.common.constants.ErrorCodeConstants; -import com.lyms.platform.common.enums.YnEnums; -import com.lyms.platform.common.result.BaseResponse; -import com.lyms.platform.common.utils.DateUtil; -import com.lyms.platform.common.utils.ExceptionUtils; -import com.lyms.platform.common.utils.StringUtils; -import com.lyms.platform.operate.web.worker.WorkHR; -import com.lyms.platform.permission.model.Organization; -import com.lyms.platform.permission.service.OrganizationService; -import com.lyms.platform.pojo.AreaCodeModel; -import com.lyms.platform.pojo.PatientCheckTicket; -import com.lyms.platform.pojo.Patients; -import com.lyms.platform.query.AreaCodeQuery; -import com.lyms.platform.query.PatientCheckTicketQuery; -import com.lyms.platform.query.PatientsQuery; -import org.apache.commons.collections.CollectionUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.concurrent.Future; - -/** - * 产检劵补发 - *

- * 补发规则: - *

- * 当前孕周 <= 孕12周+6天 补发1、2、3、4、5券 - * 孕12周+6天 < 当前孕周 <= 孕20周+6天 补发2、3、4、5券 - * 孕20周+6天 < 当前孕周 <= 孕24周+6天 补发3、4、5券 - * 孕24周+6天 < 当前孕周 <= 孕36周+6天 补发4、5券 - * 孕36周+6天 < 当前孕周 <= 孕40周+6天 补发5券 - *

- *

- *

- *

- * Created by Administrator on 2017/1/5 0005. - */ -@Component -public class PatientCheckTicketFacade { - - @Autowired - private PatientCheckTicketService checkTicketServicel; - @Autowired - private PatientsService patientsService; - - @Autowired - private AreaCodeService areaCodeService; - - @Autowired - private AutoIncermentService autoIncermentService; - @Autowired - private OrganizationService organizationService; - - @Autowired - @Qualifier("commonThreadPool") - private ThreadPoolTaskExecutor commonThreadPool; - - /** - * 补发以前建档的产检劵 - * - * @return - */ - public BaseResponse supplyCheckTicket(String hId) { - PatientsQuery patientsQuery1 = new PatientsQuery(); - patientsQuery1.setHospitalId(hId); - patientsQuery1.setYn(YnEnums.YES.getId()); - patientsQuery1.setType(1); - patientsQuery1.setExtEnable(false); - List buildType = new ArrayList(); - buildType.add(0); - buildType.add(2); - patientsQuery1.setBuildTypeList(buildType); - - List patientses = patientsService.queryPatient(patientsQuery1); - - int batchSize = 400; - int end = 0; - for (int i = 0; i < patientses.size(); i += batchSize) { - end = (end + batchSize); - if (end > patientses.size()) { - end = patientses.size(); - } - commonThreadPool.execute(new SupplyCheckTicketThread(patientses.subList(i, end))); - } - return new BaseResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功"); - } - - /** - * 补发单个建档的产检劵 - * - * @param parentId - * @return - */ - public BaseResponse supplyCheckTicketByPatientId(String parentId) { - - - Patients patients = patientsService.findOnePatientById(parentId); - //表示不是隐藏建档 - PatientsQuery patientsQuery1 = new PatientsQuery(); - patientsQuery1.setYn(YnEnums.YES.getId()); - patientsQuery1.setType(1); - patientsQuery1.setExtEnable(false); - List buildType = new ArrayList(); - buildType.add(0); - buildType.add(2); - patientsQuery1.setBuildTypeList(buildType); - - if (!"2".equals(patients.getEnable())) { - patientsQuery1.setId(parentId); - } else { - patientsQuery1.setPid(patients.getPid()); - } - List patientses = patientsService.queryPatient(patientsQuery1); - if (CollectionUtils.isNotEmpty(patientses)) { - PatientCheckTicketQuery checkTicketQuery = new PatientCheckTicketQuery(); - for (Patients p : patientses) { - checkTicketQuery.setPatientId(p.getId()); - /** - * 执行补发操作 - */ - doBiz(checkTicketQuery, p); - } - } - return new BaseResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("操作成功."); - } - - - private class SupplyCheckTicketThread extends Thread { - private List patientses; - - public SupplyCheckTicketThread(List patientses) { - this.patientses = patientses; - } - - @Override - public void run() { - PatientCheckTicketQuery checkTicketQuery = new PatientCheckTicketQuery(); - for (Patients p : patientses) { - try { - checkTicketQuery.setPatientId(p.getId()); - /** - * 执行补发操作 - */ - doBiz(checkTicketQuery, p); - } catch (Exception e) { - ExceptionUtils.catchException(e, "SupplyCheckTicketThread Error."); - } - } - } - } - - private void doBiz(PatientCheckTicketQuery checkTicketQuery, Patients p) { - if (0 == checkTicketServicel.queryTicketCount(checkTicketQuery)) { - //建档成功后,给孕妇造五个条形码 - Organization organization = organizationService.getOrganization(Integer.valueOf(p.getHospitalId())); - if (null != organization) { - AreaCodeQuery areaCodeQuery = new AreaCodeQuery(); - areaCodeQuery.setAreaId(organization.getCityId()); - areaCodeQuery.setYn(YnEnums.YES.getId()); - List code = areaCodeService.queryList(areaCodeQuery); - AreaCodeModel areaCode = null; - if (CollectionUtils.isNotEmpty(code)) { - areaCode = code.get(0); - } - if (null != areaCode && StringUtils.isNotEmpty(areaCode.getAreaCode())) { - String ticketPid = null; - int index = 0; - //重试3次获取劵,取不到就失败 - do { - index++; - ticketPid = autoIncermentService.nextPatientTicketId(areaCode.getAreaCode()); - } while (StringUtils.isEmpty(ticketPid) && index < 3); - - if (StringUtils.isEmpty(ticketPid)) { - ExceptionUtils.catchException(null, "补发产检劵失败.id : "+p.getId()); - return; - } - // 建档成功后,给孕妇造五个条形码 - for (Integer i = complyCurrentDay(p.getLastMenses()); i <= 5; i++) { - PatientCheckTicket ticket = new PatientCheckTicket(); - ticket.setStatus(1); - ticket.setHospitalId(p.getHospitalId()); - ticket.setPatientId(p.getId()); - ticket.setCreated(new Date()); - ticket.setId(areaCode.getAreaCode() + ticketPid + i); - ticket.setPid(p.getPid()); - checkTicketServicel.addTicket(ticket); - } - } - } - } - } - - - /** - * 获取当前月经从第几期开始补发 - * - * @param lastMess - * @return - */ - public static int complyCurrentDay(Date lastMess) { - int day = DateUtil.getDays(lastMess, new Date()); - if (day <= 12 * 7 + 6) - return 1; - if (12 * 7 + 6 < day && day <= 20 * 7 + 6) - return 2; - if (20 * 7 + 6 < day && day <= 24 * 7 + 6) - return 3; - if (24 * 7 + 6 < day && day <= 36 * 7 + 6) - return 4; - if (36 * 7 + 6 < day && day <= 40 * 7 + 6) - return 5; - return 6; - } +package com.lyms.platform.operate.web.facade; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.apache.commons.collections.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +import org.springframework.stereotype.Component; + +import com.lyms.platform.biz.service.AreaCodeService; +import com.lyms.platform.biz.service.AutoIncermentService; +import com.lyms.platform.biz.service.PatientCheckTicketService; +import com.lyms.platform.biz.service.PatientsService; +import com.lyms.platform.common.constants.ErrorCodeConstants; +import com.lyms.platform.common.enums.YnEnums; +import com.lyms.platform.common.result.BaseResponse; +import com.lyms.platform.common.utils.DateUtil; +import com.lyms.platform.common.utils.ExceptionUtils; +import com.lyms.platform.common.utils.StringUtils; +import com.lyms.platform.permission.model.Organization; +import com.lyms.platform.permission.service.OrganizationService; +import com.lyms.platform.pojo.AreaCodeModel; +import com.lyms.platform.pojo.PatientCheckTicket; +import com.lyms.platform.pojo.Patients; +import com.lyms.platform.query.AreaCodeQuery; +import com.lyms.platform.query.PatientCheckTicketQuery; +import com.lyms.platform.query.PatientsQuery; + +/** + * 产检劵补发 + *

+ * 补发规则: + *

+ * 当前孕周   <= 孕12周+6天 补发1、2、3、4、5券 
+ * 孕12周+6天 < 当前孕周 <= 孕20周+6天 补发2、3、4、5券 
+ * 孕20周+6天 < 当前孕周 <= 孕24周+6天 补发3、4、5券 
+ * 孕24周+6天 < 当前孕周 <= 孕36周+6天 补发4、5券 
+ * 孕36周+6天 <当前孕周 <= 孕40周+6天 补发5券
+ * 
+ * 

+ * Created by Administrator on 2017/1/5 0005. + */ +@Component +public class PatientCheckTicketFacade { + + @Autowired + private PatientCheckTicketService checkTicketServicel; + + @Autowired + private PatientsService patientsService; + + @Autowired + private AreaCodeService areaCodeService; + + @Autowired + private AutoIncermentService autoIncermentService; + + @Autowired + private OrganizationService organizationService; + + @Autowired + @Qualifier("commonThreadPool") + private ThreadPoolTaskExecutor commonThreadPool; + + /** + * 补发以前建档的产检劵 + * + * @return + */ + public BaseResponse supplyCheckTicket(String hId) { + PatientsQuery patientsQuery1 = new PatientsQuery(); + patientsQuery1.setHospitalId(hId); + patientsQuery1.setYn(YnEnums.YES.getId()); + patientsQuery1.setType(1); + patientsQuery1.setExtEnable(false); + List buildType = new ArrayList(); + buildType.add(0); + buildType.add(2); + patientsQuery1.setBuildTypeList(buildType); + + List patientses = patientsService.queryPatient(patientsQuery1); + + int batchSize = 400; + int end = 0; + for (int i = 0; i < patientses.size(); i += batchSize) { + end = (end + batchSize); + if (end > patientses.size()) { + end = patientses.size(); + } + commonThreadPool.execute(new SupplyCheckTicketThread(patientses.subList(i, end))); + } + return new BaseResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功"); + } + + /** + * 补发单个建档的产检劵 + * + * @param parentId + * @return + */ + public BaseResponse supplyCheckTicketByPatientId(String parentId) { + + Patients patients = patientsService.findOnePatientById(parentId); + // 表示不是隐藏建档 + PatientsQuery patientsQuery1 = new PatientsQuery(); + patientsQuery1.setYn(YnEnums.YES.getId()); + patientsQuery1.setType(1); + patientsQuery1.setExtEnable(false); + List buildType = new ArrayList(); + buildType.add(0); + buildType.add(2); + patientsQuery1.setBuildTypeList(buildType); + + if (!"2".equals(patients.getEnable())) { + patientsQuery1.setId(parentId); + } else { + patientsQuery1.setPid(patients.getPid()); + } + List patientses = patientsService.queryPatient(patientsQuery1); + if (CollectionUtils.isNotEmpty(patientses)) { + PatientCheckTicketQuery checkTicketQuery = new PatientCheckTicketQuery(); + for (Patients p : patientses) { + checkTicketQuery.setPatientId(p.getId()); + /** + * 执行补发操作 + */ + doBiz(checkTicketQuery, p); + } + } + return new BaseResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("操作成功."); + } + + private class SupplyCheckTicketThread extends Thread { + private List patientses; + + public SupplyCheckTicketThread(List patientses) { + this.patientses = patientses; + } + + @Override + public void run() { + PatientCheckTicketQuery checkTicketQuery = new PatientCheckTicketQuery(); + for (Patients p : patientses) { + try { + checkTicketQuery.setPatientId(p.getId()); + /** + * 执行补发操作 + */ + doBiz(checkTicketQuery, p); + } catch (Exception e) { + ExceptionUtils.catchException(e, "SupplyCheckTicketThread Error."); + } + } + } + } + + private void doBiz(PatientCheckTicketQuery checkTicketQuery, Patients p) { + if (0 == checkTicketServicel.queryTicketCount(checkTicketQuery)) { + // 建档成功后,给孕妇造五个条形码 + Organization organization = organizationService.getOrganization(Integer.valueOf(p.getHospitalId())); + if (null != organization) { + AreaCodeQuery areaCodeQuery = new AreaCodeQuery(); + areaCodeQuery.setAreaId(organization.getCityId()); + areaCodeQuery.setYn(YnEnums.YES.getId()); + List code = areaCodeService.queryList(areaCodeQuery); + AreaCodeModel areaCode = null; + if (CollectionUtils.isNotEmpty(code)) { + areaCode = code.get(0); + } + if (null != areaCode && StringUtils.isNotEmpty(areaCode.getAreaCode())) { + String ticketPid = null; + int index = 0; + // 重试3次获取劵,取不到就失败 + do { + index++; + ticketPid = autoIncermentService.nextPatientTicketId(areaCode.getAreaCode()); + } while (StringUtils.isEmpty(ticketPid) && index < 3); + + if (StringUtils.isEmpty(ticketPid)) { + ExceptionUtils.catchException(null, "补发产检劵失败.id : " + p.getId()); + return; + } + // 建档成功后,给孕妇造五个条形码 + for (Integer i = complyCurrentDay(p.getLastMenses()); i <= 5; i++) { + PatientCheckTicket ticket = new PatientCheckTicket(); + ticket.setStatus(1); + ticket.setHospitalId(p.getHospitalId()); + ticket.setPatientId(p.getId()); + ticket.setCreated(new Date()); + ticket.setId(areaCode.getAreaCode() + ticketPid + i); + ticket.setPid(p.getPid()); + checkTicketServicel.addTicket(ticket); + } + } + } + } + } + + /** + * 获取当前月经从第几期开始补发 + * + * @param lastMess + * @return + */ + public static int complyCurrentDay(Date lastMess) { + int day = DateUtil.getDays(lastMess, new Date()); + if (day <= 12 * 7 + 6) + return 1; + if (12 * 7 + 6 < day && day <= 20 * 7 + 6) + return 2; + if (20 * 7 + 6 < day && day <= 24 * 7 + 6) + return 3; + if (24 * 7 + 6 < day && day <= 36 * 7 + 6) + return 4; + if (36 * 7 + 6 < day && day <= 40 * 7 + 6) + return 5; + return 6; + } } \ No newline at end of file -- 1.8.3.1