Java tutorial
/** * Project: guahao-portal-web-home * * File Created at 2012-9-29 * * Copyright 2012 Greenline.com Corporation Limited. * All rights reserved. * * This software is the confidential and proprietary information of * Greenline Company. ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with Greenline.com. */ package com.greenline.guahao.web.module.home.controllers.expert; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Component; import org.springframework.ui.ModelMap; import com.greenline.gops.redis.client.expert.dataobject.ExpertPlusStatisticDO; import com.greenline.guahao.biz.manager.apply.ApplyHaoyuanManager; import com.greenline.guahao.biz.manager.apply.dataobject.OrderRequestCountDO; import com.greenline.guahao.biz.manager.area.AreaManager; import com.greenline.guahao.biz.manager.area.dataobject.AreaDO; import com.greenline.guahao.biz.manager.hrs.DepartmentManager; import com.greenline.guahao.biz.manager.hrs.ExpertManager; import com.greenline.guahao.biz.manager.hrs.HospitalManager; import com.greenline.guahao.biz.manager.hrs.dataobject.ClinicTypeDO; import com.greenline.guahao.biz.manager.hrs.dataobject.ExpertDO; import com.greenline.guahao.biz.manager.hrs.dataobject.FastOrderDO; import com.greenline.guahao.biz.manager.hrs.dataobject.HospitalDO; import com.greenline.guahao.biz.manager.hrs.dataobject.HospitalDepartmentDO; import com.greenline.guahao.biz.manager.hrs.dataobject.HospitalExtDO; import com.greenline.guahao.biz.util.BizCommonUtils; import com.greenline.guahao.biz.util.ShiftCasesUtils; import com.greenline.guahao.web.module.common.constants.HospitalConstants; import com.greenline.guahao.web.module.common.vo.KeyObjectVO; import com.greenline.guahao.web.module.common.vo.ValueTextVO; import com.greenline.guahao.web.module.home.controllers.hospital.HospitalProcess; import com.greenline.guahao.web.module.home.vo.apply.OrderRequestExpertVO; /** * @Type FastOrderProcess * @Desc ? * @author jianyun.zheng * @date 2012-9-29 * @Version V1.0 */ @Component public class FastOrderProcess { @Resource private AreaManager areaManager; @Resource private DepartmentManager departmentManager; @Resource private HospitalManager hospitalManager; @Resource private ExpertManager expertManager; @Resource private ApplyHaoyuanManager applyHaoyuanManager; @Resource private HospitalProcess hospitalProcess; @Resource private ShiftCasesUtils shiftCasesUtils; /** * ?json?? * * @return List<ValueTextVO> */ public List<ValueTextVO> getJsonProvinces() { List<AreaDO> provinces = areaManager.listFastOrderProvinces(); List<ValueTextVO> ps = new ArrayList<ValueTextVO>(); if (null != provinces && provinces.size() > 0) { for (AreaDO province : provinces) { ValueTextVO vt = new ValueTextVO(); vt.setValue(province.getId()); vt.setText(province.getName()); ps.add(vt); } } return ps; } /** * ?json?? * * @param provinceId * @return List<ValueTextVO> */ public List<ValueTextVO> getJsonCitys(String provinceId) { List<ValueTextVO> cs = new ArrayList<ValueTextVO>(); cs.add(this.getNotLimit()); List<AreaDO> citys = null; if (StringUtils.isNotBlank(provinceId)) { citys = areaManager.listFastOrderCitys(provinceId); } if (null != citys && citys.size() > 0) { for (AreaDO city : citys) { ValueTextVO vt = new ValueTextVO(); vt.setValue(city.getId()); vt.setText(city.getName()); cs.add(vt); } } return cs; } /** * ?? * * @param provinceId * @param cityId * @return List<ValueTextVO> */ public List<ValueTextVO> getHospitalsByArea(String provinceId, String cityId) { List<ValueTextVO> hs = new ArrayList<ValueTextVO>(); List<HospitalDO> hospitals = null; String areaId = null; if (StringUtils.isNotBlank(provinceId) && !FastOrderDO.NOT_LIMIT.equals(provinceId) && StringUtils.isNotBlank(cityId)) { if (FastOrderDO.NOT_LIMIT.equals(cityId)) { areaId = provinceId; } else { areaId = cityId; } } if (StringUtils.isNotBlank(areaId)) { hospitals = hospitalManager.listByAreaId(areaId);// ? if (null != hospitals && hospitals.size() > 0) { for (HospitalDO hospital : hospitals) { if (shiftCasesUtils.isFastOrderHospitalId(hospital.getId())) { String hospitalname = StringUtils.isBlank(hospital.getHospitalStdName()) ? hospital.getName() : hospital.getHospitalStdName(); if (hospital.getIshospialmerge() == 1 && StringUtils.isNotBlank(hospital.getPlatformname())) { hospitalname = hospitalname + "(" + hospital.getPlatformname() + ")"; } ValueTextVO vt = new ValueTextVO(); vt.setValue(hospital.getId()); vt.setText(hospitalname); String level = hospital.getHospitalLevel(); if (StringUtils.isNotBlank(level)) { vt.setText(vt.getText() + "[" + level + "]"); } hs.add(vt); } } } } return hs; } /** * ? * * @param hospitalId * @return List<KeyObjectVO> */ @SuppressWarnings({ "rawtypes", "unchecked" }) public List<KeyObjectVO> getDeptsByHospitalId(String hospitalId) { HospitalExtDO hospitalextdo = hospitalProcess.listHospitalDepts(null, hospitalId); Map<String, List<ValueTextVO>> hds = new LinkedHashMap<String, List<ValueTextVO>>(); // ?map if (HospitalConstants.HOSPITAL_ID_ZSSY.equals(hospitalId)) { List<KeyObjectVO> lhds = new ArrayList<KeyObjectVO>(); if (null != hospitalextdo && null != hospitalextdo.getParentFeatureDeptList() && hospitalextdo.getParentFeatureDeptList().size() > 0) { for (HospitalDepartmentDO hospDept : hospitalextdo.getFeatureDeptList()) { if (hospDept.getExpetrtCount() > 0) { // 0 String dept = "";// List<ValueTextVO> ihds = hds.get(dept); // if (null == ihds) { ihds = new ArrayList<ValueTextVO>(); hds.put(dept, ihds); } ValueTextVO vt = new ValueTextVO(); vt.setValue(hospDept.getId()); vt.setText(hospDept.getName()); ihds.add(vt); } } } if (null != hospitalextdo && null != hospitalextdo.getChildFeatureDeptList() && hospitalextdo.getChildFeatureDeptList().size() > 0) { for (HospitalDepartmentDO hospDept : hospitalextdo.getChildFeatureDeptList()) { if (hospDept.getExpetrtCount() > 0) { // 0 String dept = "";// List<ValueTextVO> ihds = hds.get(dept); // if (null == ihds) { ihds = new ArrayList<ValueTextVO>(); hds.put(dept, ihds); } ValueTextVO vt = new ValueTextVO(); vt.setValue(hospDept.getId()); vt.setText(hospDept.getName()); ihds.add(vt); } } } if (null != hospitalextdo && null != hospitalextdo.getParentProfitDeptList() && hospitalextdo.getParentProfitDeptList().size() > 0) { for (HospitalDepartmentDO hospDept : hospitalextdo.getParentProfitDeptList()) { if (hospDept.getExpetrtCount() > 0) { // 0 String dept = "??";// List<ValueTextVO> ihds = hds.get(dept); // if (null == ihds) { ihds = new ArrayList<ValueTextVO>(); hds.put(dept, ihds); } ValueTextVO vt = new ValueTextVO(); vt.setValue(hospDept.getId()); vt.setText(hospDept.getName()); ihds.add(vt); } } } if (null != hospitalextdo && null != hospitalextdo.getChildProfitDeptList() && hospitalextdo.getChildProfitDeptList().size() > 0) { for (HospitalDepartmentDO hospDept : hospitalextdo.getChildProfitDeptList()) { if (hospDept.getExpetrtCount() > 0) { // 0 String dept = "??";// List<ValueTextVO> ihds = hds.get(dept); // if (null == ihds) { ihds = new ArrayList<ValueTextVO>(); hds.put(dept, ihds); } ValueTextVO vt = new ValueTextVO(); vt.setValue(hospDept.getId()); vt.setText(hospDept.getName()); ihds.add(vt); } } } if (null != hospitalextdo && null != hospitalextdo.getParentDeptMap() && hospitalextdo.getParentDeptMap().size() > 0) { for (Map.Entry<String, List<HospitalDepartmentDO>> entry : hospitalextdo.getParentDeptMap() .entrySet()) { List<HospitalDepartmentDO> list = (List) entry.getValue(); for (HospitalDepartmentDO hospDept : list) { if (hospDept.getExpetrtCount() > 0) { // 0 String dept = hospDept.getCategory();// List<ValueTextVO> ihds = hds.get(dept); // if (null == ihds) { ihds = new ArrayList<ValueTextVO>(); hds.put(dept, ihds); } ValueTextVO vt = new ValueTextVO(); vt.setValue(hospDept.getId()); vt.setText(hospDept.getName()); ihds.add(vt); } } } } if (null != hospitalextdo && null != hospitalextdo.getChildDeptMap() && hospitalextdo.getChildDeptMap().size() > 0) { for (Map.Entry<String, List<HospitalDepartmentDO>> entry : hospitalextdo.getChildDeptMap() .entrySet()) { List<HospitalDepartmentDO> list = (List) entry.getValue(); for (HospitalDepartmentDO hospDept : list) { if (hospDept.getExpetrtCount() > 0) { // 0 String dept = hospDept.getCategory();// List<ValueTextVO> ihds = hds.get(dept); // if (null == ihds) { ihds = new ArrayList<ValueTextVO>(); hds.put(dept, ihds); } ValueTextVO vt = new ValueTextVO(); vt.setValue(hospDept.getId()); vt.setText(hospDept.getName()); ihds.add(vt); } } } } for (Iterator<String> it = hds.keySet().iterator(); it.hasNext();) { String key = it.next(); lhds.add(new KeyObjectVO(key, hds.get(key))); } return lhds; } else { List<KeyObjectVO> lhds = new ArrayList<KeyObjectVO>(); if (null != hospitalextdo && null != hospitalextdo.getFeatureDeptList() && hospitalextdo.getFeatureDeptList().size() > 0) { for (HospitalDepartmentDO hospDept : hospitalextdo.getFeatureDeptList()) { if (hospDept.getExpetrtCount() > 0) { // 0 String dept = "";// List<ValueTextVO> ihds = hds.get(dept); // if (null == ihds) { ihds = new ArrayList<ValueTextVO>(); hds.put(dept, ihds); } ValueTextVO vt = new ValueTextVO(); vt.setValue(hospDept.getId()); vt.setText(hospDept.getName()); ihds.add(vt); } } } if (null != hospitalextdo && null != hospitalextdo.getProfitDeptList() && hospitalextdo.getProfitDeptList().size() > 0) { for (HospitalDepartmentDO hospDept : hospitalextdo.getProfitDeptList()) { if (hospDept.getExpetrtCount() > 0) { // 0 String dept = "??";// List<ValueTextVO> ihds = hds.get(dept); // if (null == ihds) { ihds = new ArrayList<ValueTextVO>(); hds.put(dept, ihds); } ValueTextVO vt = new ValueTextVO(); vt.setValue(hospDept.getId()); vt.setText(hospDept.getName()); ihds.add(vt); } } } if (null != hospitalextdo && null != hospitalextdo.getDeptMap() && hospitalextdo.getDeptMap().size() > 0) { for (Map.Entry<String, List<HospitalDepartmentDO>> entry : hospitalextdo.getDeptMap().entrySet()) { List<HospitalDepartmentDO> list = (List) entry.getValue(); for (HospitalDepartmentDO hospDept : list) { if (hospDept.getExpetrtCount() > 0) { // 0 String dept = hospDept.getCategory();// List<ValueTextVO> ihds = hds.get(dept); // if (null == ihds) { ihds = new ArrayList<ValueTextVO>(); hds.put(dept, ihds); } ValueTextVO vt = new ValueTextVO(); vt.setValue(hospDept.getId()); vt.setText(hospDept.getName()); ihds.add(vt); } } } } for (Iterator<String> it = hds.keySet().iterator(); it.hasNext();) { String key = it.next(); lhds.add(new KeyObjectVO(key, hds.get(key))); } return lhds; } } /** * ? * * @param hospitalId * @return List<ValueTextVO> */ public List<ValueTextVO> getClinicTypesByHospitalId(String hospitalId) { List<ValueTextVO> cts = new ArrayList<ValueTextVO>(); List<ClinicTypeDO> clinicTypes = null; if (StringUtils.isNotBlank(hospitalId)) { // clinicTypes = hospitalManager.listClinicType(hospitalId); } if (null != clinicTypes && clinicTypes.size() > 0) { for (ClinicTypeDO clinicType : clinicTypes) { ValueTextVO vt = new ValueTextVO(); vt.setValue(clinicType.getId()); vt.setText(clinicType.getName()); cts.add(vt); } } return cts; } /** * ? * * @param hospitalId * @return Map<String, Object> */ public Map<String, Object> getDeptsAndCliTypes(String hospitalId) { List<KeyObjectVO> hospDepts = this.getDeptsByHospitalId(hospitalId); List<ValueTextVO> clinicTypes = this.getClinicTypesByHospitalId(hospitalId); Map<String, Object> map = new HashMap<String, Object>(); map.put("hospDepts", hospDepts); map.put("clinicTypes", clinicTypes); return map; } /** * ? * * @param model * @param fastOrder */ public void intFastOrder(ModelMap model, FastOrderDO fastOrder) { model.put("provinces", this.getJsonProvinces()); // ? model.put("clinicDateScopes", this.getClinicDateScopeList()); // String hospDeptIds = fastOrder.getHospDeptId(); String hospitalId = fastOrder.getHospitalId(); if (BizCommonUtils.isUUID(hospDeptIds) || BizCommonUtils.isUUID(hospitalId)) { // // ???? if (StringUtils.isNotBlank(hospDeptIds)) { String[] hospDeptIdsList = hospDeptIds.split(","); HospitalDepartmentDO hospDept = departmentManager.getHospitalDept(hospDeptIdsList[0]); if (null != hospDept) { // ??? if (hospDeptIdsList.length == 1) { fastOrder.setHospDeptId(hospDeptIdsList[0]); fastOrder.setHospDeptName(hospDept.getName()); } hospitalId = hospDept.getHospitalId(); } } HospitalDO hospital = hospitalManager.getHospital(hospitalId); if (null != hospital) { fastOrder.setHospitalId(hospitalId); String provinceId = hospital.getProvinceid(); fastOrder.setProvinceId(provinceId); model.put("citys", this.getJsonCitys(provinceId)); String cityId = hospital.getCityid(); if (FastOrderDO.NOT_LIMIT.equals(fastOrder.getCityId())) { cityId = FastOrderDO.NOT_LIMIT; // ????? } else { fastOrder.setCityId(cityId); } model.put("hospitals", this.getHospitalsByArea(provinceId, cityId)); // model.put("hospDepts", this.getDeptsByHospitalId(hospitalId)); // } } model.put("queryForm", fastOrder); } /** * ???select * * @return ValueTextVO */ public ValueTextVO getNotLimit() { ValueTextVO notLimit = new ValueTextVO(); notLimit.setValue(FastOrderDO.NOT_LIMIT); notLimit.setText("??"); return notLimit; } /** * ? * * @return String */ public String getInitClinicDateScope() { String clinicDateScope = ""; Calendar now = Calendar.getInstance(); Calendar time = Calendar.getInstance(); time.clear(); time.set(Calendar.YEAR, now.get(Calendar.YEAR)); time.set(Calendar.MONTH, now.get(Calendar.MONTH)); time.set(Calendar.DAY_OF_YEAR, now.get(Calendar.DAY_OF_YEAR)); time.add(Calendar.DAY_OF_YEAR, 1); // clinicDateScope += time.getTime().getTime(); clinicDateScope = clinicDateScope + "-"; time.add(Calendar.DAY_OF_YEAR, 15); // clinicDateScope += time.getTime().getTime(); return clinicDateScope; } /** * ? * * @return List<ValueTextVO> */ public List<ValueTextVO> getClinicDateScopeList() { List<ValueTextVO> list = new ArrayList<ValueTextVO>(); // ? Calendar now = Calendar.getInstance(); Calendar time = Calendar.getInstance(); time.clear(); time.set(Calendar.YEAR, now.get(Calendar.YEAR)); time.set(Calendar.MONTH, now.get(Calendar.MONTH)); time.set(Calendar.DAY_OF_YEAR, now.get(Calendar.DAY_OF_YEAR)); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); time.add(Calendar.DAY_OF_YEAR, 1); // StringBuffer scope0 = new StringBuffer(); StringBuffer scope1 = new StringBuffer(); StringBuffer scope2 = new StringBuffer(); StringBuffer value0 = new StringBuffer(); StringBuffer value1 = new StringBuffer(); StringBuffer value2 = new StringBuffer(); scope0.append(sdf.format(time.getTime())); value0.append(time.getTime().getTime()); scope0.append("-"); value0.append("-"); time.add(Calendar.DAY_OF_YEAR, 6); // scope0.append(sdf.format(time.getTime())); value0.append(time.getTime().getTime()); ValueTextVO vt0 = new ValueTextVO(); vt0.setValue(value0.toString()); vt0.setText(scope0.toString()); list.add(vt0); time.add(Calendar.DAY_OF_YEAR, 1); // scope1.append(sdf.format(time.getTime())); value1.append(time.getTime().getTime()); scope1.append("-"); value1.append("-"); time.add(Calendar.DAY_OF_YEAR, 6); // scope1.append(sdf.format(time.getTime())); value1.append(time.getTime().getTime()); // scope1 += "()"; ValueTextVO vt1 = new ValueTextVO(); vt1.setValue(value1.toString()); vt1.setText(scope1.toString()); list.add(vt1); time.add(Calendar.DAY_OF_YEAR, 1); // scope2.append(sdf.format(time.getTime())); value2.append(time.getTime().getTime()); scope2.append("??"); value2.append("-"); time.add(Calendar.DAY_OF_YEAR, 365);// 365 value2.append(time.getTime().getTime()); ValueTextVO vt2 = new ValueTextVO(); vt2.setValue(value2.toString()); vt2.setText(scope2.toString()); list.add(vt2); return list; } /** * ??? * * @param model * @param fastOrder */ public void setFastOrderList(ModelMap model, FastOrderDO fastOrder) { String hospitalId = ""; // ? String hospitalName = ""; // ?? String hospDeptName = ""; // ?? HospitalDepartmentDO hospDept = departmentManager.getHospitalDept(fastOrder.getHospDeptId()); // if (null != hospDept) { hospDeptName = hospDept.getName(); HospitalDO hospital = hospitalManager.getHospital(hospDept.getHospitalId()); // if (null != hospital) { hospitalId = hospital.getId(); hospitalName = hospital.getName(); } } model.put("hospitalId", hospitalId); model.put("hospitalName", hospitalName); model.put("hospDeptName", hospDeptName); } /** * ??? * * @param status * @return 01?2??3?4??5?6?7??8 * 9??1011 */ public boolean isCanReserveStatus(Integer status) { if (status == null) { return false; } if (status == 0 || status == 1 || status == 3 || status == 7 || status == 8 || status == 9 || status == 10) { return true; } return false; } /** * ?? ip? * * @param model * @param fastOrder * @param ip */ public void intFastOrder(ModelMap model, final String ip, FastOrderDO fastOrder) { boolean locationArea = Boolean.FALSE; String provinceId = fastOrder.getProvinceId(); // ? List<ValueTextVO> provinces = this.getJsonProvinces(); model.put("provinces", provinces); // ? if ((FastOrderDO.NOT_LIMIT.equals(provinceId) || StringUtils.isBlank(provinceId)) && StringUtils.isNotBlank(ip)) { String area = areaManager.getAreaInfo(ip); if (StringUtils.isNotBlank(area) && (null != provinces && !provinces.isEmpty())) { int idx = area.indexOf("?"); if (idx == -1) { idx = area.indexOf(""); } String ipProvince = null; if (idx != -1) { ipProvince = area.substring(0, idx + 1); area = area.substring(idx + 1); } if (null != ipProvince) { for (ValueTextVO a : provinces) { if (ipProvince.indexOf(a.getText()) != -1) { fastOrder.setProvinceId(a.getValue()); provinceId = a.getValue(); locationArea = Boolean.TRUE; break; } } } } if (locationArea) { List<ValueTextVO> citys = this.getJsonCitys(provinceId); fastOrder.setCityId(FastOrderDO.NOT_LIMIT); model.put("citys", citys); if (null != citys && !citys.isEmpty() && StringUtils.isNotBlank(area)) { int idx2 = area.indexOf(""); if (idx2 == -1) { idx2 = area.indexOf(""); } if (idx2 == -1) { idx2 = area.indexOf(""); } String ipCity = null; if (idx2 != -1) { ipCity = area.substring(0, idx2 + 1); } if (null != ipCity) { for (ValueTextVO a : citys) { if (ipCity.indexOf(a.getText()) != -1) { fastOrder.setCityId(a.getValue()); break; } } } } model.put("hospitals", this.getHospitalsByArea(provinceId, fastOrder.getCityId())); // } model.put("queryForm", fastOrder); } } /** * ? * * @param model * @param fastOrder */ public void setOrderRequestExpertList(ModelMap model, FastOrderDO fastOrder) { List<ExpertPlusStatisticDO> expertPlusStatisticList = expertManager .listOrderRequestExperts(fastOrder.getHospDeptId()); if (null != expertPlusStatisticList) { List<OrderRequestExpertVO> orderRequestExpertList = new ArrayList<OrderRequestExpertVO>(); String[] expertIds = null; if (expertPlusStatisticList.size() > 5) { expertIds = new String[5]; for (int i = 0; i < 5; i++) { OrderRequestExpertVO orderRequestExpertVO = new OrderRequestExpertVO(); orderRequestExpertVO.setExpertName(expertPlusStatisticList.get(i).getExpertName()); orderRequestExpertVO.setExpertUuid(expertPlusStatisticList.get(i).getExpertUuid()); orderRequestExpertVO.setStatistic(expertPlusStatisticList.get(i).getStatistic()); orderRequestExpertList.add(orderRequestExpertVO); expertIds[i] = expertPlusStatisticList.get(i).getExpertUuid(); } } else { expertIds = new String[expertPlusStatisticList.size()]; for (int i = 0; i < expertPlusStatisticList.size(); i++) { OrderRequestExpertVO orderRequestExpertVO = new OrderRequestExpertVO(); orderRequestExpertVO.setExpertName(expertPlusStatisticList.get(i).getExpertName()); orderRequestExpertVO.setExpertUuid(expertPlusStatisticList.get(i).getExpertUuid()); orderRequestExpertVO.setStatistic(expertPlusStatisticList.get(i).getStatistic()); orderRequestExpertList.add(orderRequestExpertVO); expertIds[i] = expertPlusStatisticList.get(i).getExpertUuid(); } } List<ExpertDO> expertsDiseaselist = expertManager.listExpertsContainDisease(expertIds); if (null != expertsDiseaselist && expertsDiseaselist.size() > 0) { for (ExpertDO expert : expertsDiseaselist) { String expertuuid = expert.getId(); for (OrderRequestExpertVO orderRequestExpert : orderRequestExpertList) { if (expertuuid.equals(orderRequestExpert.getExpertUuid())) { orderRequestExpert.setDiseases(expert.getDiseases()); orderRequestExpert.setScienceTitleTypeText(expert.getScienceTitleTypeText()); orderRequestExpert.setTitletypeText(expert.getTitleTypeText()); break; } } } } List<OrderRequestCountDO> orderRequestCountList = applyHaoyuanManager .getDepartOfDoctorRequestCount(fastOrder.getHospDeptId()); if (null != orderRequestCountList) { for (OrderRequestCountDO orderRequestCount : orderRequestCountList) { String expertuuid = orderRequestCount.getExpertUuid(); for (OrderRequestExpertVO orderRequestExpert : orderRequestExpertList) { if (expertuuid.equals(orderRequestExpert.getExpertUuid())) { orderRequestExpert .setStatistic(orderRequestExpert.getStatistic() + orderRequestCount.getCount()); break; } } } } model.put("orderRequestExpertList", orderRequestExpertList); } } }