package com.imurs.controller; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.Wrapper; import com.imurs.controller.ApplyBModeController; import com.imurs.dto.SpecialistSubmitDto; import com.imurs.entity.ApplyBMode; import com.imurs.entity.ApplyBModeImg; import com.imurs.entity.ApplyBModeSpecialist; import com.imurs.entity.Patient; import com.imurs.entity.User; import com.imurs.service.ApplyBModeImgService; import com.imurs.service.ApplyBModeService; import com.imurs.service.ApplyBModeSpecialistService; import com.imurs.service.ApplyInformationService; import com.imurs.service.PatientService; import com.imurs.service.UserService; import com.imurs.service.impl.ApplyBModeServiceImpl; import com.imurs.service.impl.BmodeMachineModelServiceImpl; import com.imurs.util.DateUtils; import com.imurs.util.page.Pagetion; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @Controller @RestController @RequestMapping({"bmode"}) public class ApplyBModeController { @Autowired ApplyBModeService applyBModeService; @Autowired ApplyBModeServiceImpl applyBModeServiceImpl; @Autowired PatientService patientService; @Autowired ApplyBModeImgService applyBModeImgService; @Autowired ApplyInformationService applyInformationService; @Autowired ApplyBModeSpecialistService applyBModeSpecialistService; @Autowired UserService userService; @Autowired BmodeMachineModelServiceImpl bmodeMachineModelServiceImpl; @Transactional @RequestMapping({"insertBmodeImg"}) public Map insertBmodeImg(@RequestBody List abmiList) { Map map = new HashMap<>(); try { if (!abmiList.isEmpty()) { boolean result = this.applyBModeImgService.insertBatch(abmiList); map.put("msg", result ? "1" : "2"); } else { map.put("msg", "3"); } } catch (Exception e) { e.printStackTrace(); map.put("msg", "4"); } return map; } @Transactional @RequestMapping({"insertBmode"}) public Map insertBmode(@RequestBody List abmList) { Map map = new HashMap<>(); EntityWrapper wrapper = new EntityWrapper(); EntityWrapper wrapper2 = new EntityWrapper(); String ptEsrdNumber = ""; try { if (!abmList.isEmpty() && abmList.get(0) != null) { Date date = new Date(); Wrapper bModeWrapper = (new EntityWrapper()).eq("category_hospital_id", ((ApplyBMode)abmList.get(0)).getCategoryHospitalId()).and().ge("group_date", DateUtils.formatDateTime(DateUtils.getDateStart(date))).and().le("group_date", DateUtils.formatDateTime(DateUtils.getDateEnd(date))); Integer size = Integer.valueOf(this.applyBModeService.selectCount(bModeWrapper)); Integer abmNo = Integer.valueOf(size.intValue() + 1); ApplyBMode abm = abmList.get(0); abm.setBtype(DateUtils.format(date, "yyyyMMdd") + "0" + abmNo); // abm.setGroupDate(new Timestamp(date.getTime())); boolean result = this.applyBModeService.insert(abmList.get(0)); if (result == true) { map.put("id", ((ApplyBMode)abmList.get(0)).getId()); map.put("msg", "1"); if (StringUtils.isNotEmpty(((ApplyBMode)abmList.get(0)).getHisEsrdNumber())) { wrapper.eq("his_esrd_number", ((ApplyBMode)abmList.get(0)).getHisEsrdNumber()); wrapper2.eq("his_esrd_number", ((ApplyBMode)abmList.get(0)).getHisEsrdNumber()); } else { wrapper.eq("out_patien", ((ApplyBMode)abmList.get(0)).getOutPatien()); wrapper2.eq("out_patien", ((ApplyBMode)abmList.get(0)).getOutPatien()); } wrapper.eq("hospital_id", ((ApplyBMode)abmList.get(0)).getCategoryHospitalId()); Patient patient2 = (Patient)this.patientService.selectOne((Wrapper)wrapper); wrapper2.eq("hospital_id", ((ApplyBMode)abmList.get(0)).getGroupHospitalId()); Patient patient3 = (Patient)this.patientService.selectOne((Wrapper)wrapper2); if (patient2 == null || patient3 == null) { Patient patient = new Patient(); if (StringUtils.isNotEmpty(((ApplyBMode)abmList.get(0)).getPtCard())) patient.setCard(((ApplyBMode)abmList.get(0)).getPtCard()); if (StringUtils.isNotEmpty(((ApplyBMode)abmList.get(0)).getSex())) patient.setSex(((ApplyBMode)abmList.get(0)).getSex()); if (StringUtils.isNotEmpty(((ApplyBMode)abmList.get(0)).getPatientName())) patient.setPatientName(((ApplyBMode)abmList.get(0)).getPatientName()); if (StringUtils.isNotEmpty(((ApplyBMode)abmList.get(0)).getPtCity())) patient.setFamily(((ApplyBMode)abmList.get(0)).getPtCity()); if (StringUtils.isNotEmpty(((ApplyBMode)abmList.get(0)).getPtPhone())) patient.setPhone(((ApplyBMode)abmList.get(0)).getPtPhone()); if (StringUtils.isNotEmpty(((ApplyBMode)abmList.get(0)).getHisEsrdNumber())) patient.setHisEsrdNumber(((ApplyBMode)abmList.get(0)).getHisEsrdNumber()); if (StringUtils.isNotEmpty(((ApplyBMode)abmList.get(0)).getOutPatien())) patient.setOutPatien(((ApplyBMode)abmList.get(0)).getOutPatien()); if (patient2 == null) { patient.setHospitalId(((ApplyBMode)abmList.get(0)).getCategoryHospitalId()); result = this.patientService.insert(patient); if (result == true) { ptEsrdNumber = "yd03" + patient.getId(); patient.setEsrdNumber(ptEsrdNumber); this.patientService.updateById(patient); } } if (patient3 == null) { patient.setHospitalId(((ApplyBMode)abmList.get(0)).getGroupHospitalId()); result = this.patientService.insert(patient); if (result == true) { ptEsrdNumber = StringUtils.isNotEmpty(ptEsrdNumber) ? ptEsrdNumber : ("yd03" + patient.getId()); patient.setEsrdNumber(ptEsrdNumber); this.patientService.updateById(patient); } } } else { ptEsrdNumber = patient2.getEsrdNumber(); } Long id = ((ApplyBMode)abmList.get(0)).getId(); ((ApplyBMode)abmList.get(0)).setEsrdNumber(ptEsrdNumber); this.applyBModeService.updateById(abmList.get(0)); ApplyBMode applyBMode = abmList.get(0); List ImgList = applyBMode.getAbmList(); if (!ImgList.isEmpty()) { for (int i = 0; i < ImgList.size(); i++) ((ApplyBModeImg)ImgList.get(i)).setbId(id); this.applyBModeImgService.insertBatch(ImgList); } } else { map.put("msg", "2"); } } else { map.put("msg", "3"); } } catch (Exception e) { e.printStackTrace(); map.put("msg", "4"); } return map; } @RequestMapping({"updateBmode"}) public Map updateBmode(@RequestBody List acList) { ApplyBMode applyBMode = acList.get(0); Map map = new HashMap<>(8); boolean result = false; try { if (applyBMode != null) result = this.applyBModeService.updateBmodeById(applyBMode); map.put("msg", result ? "1" : "2"); } catch (Exception e) { e.printStackTrace(); map.put("msg", "4"); } return map; } @RequestMapping({"updateBmodeImg"}) public Map updateBmodeImg(@RequestBody List acList) { ApplyBMode applyBMode = acList.get(0); Map map = new HashMap<>(); try { EntityWrapper wrapper = new EntityWrapper(); wrapper.eq("b_id", applyBMode.getId()); List idList = this.applyBModeImgService.selectList((Wrapper)wrapper); List abmList = applyBMode.getAbmList(); if (!idList.isEmpty()) { if (!abmList.isEmpty()) { for (ApplyBModeImg applyBModeImg : idList) { if (applyBModeImg.getType().intValue() != 32) this.applyBModeImgService.deleteById(applyBModeImg.getId()); } for (int i = 0; i < abmList.size(); i++) { ApplyBModeImg applyBModeImg = abmList.get(i); applyBModeImg.setbId(applyBMode.getId()); this.applyBModeImgService.insert(applyBModeImg); } } else { for (ApplyBModeImg applyBModeImg : idList) { if (applyBModeImg.getType().intValue() != 32) this.applyBModeImgService.deleteById(applyBModeImg.getId()); } } } else if (!abmList.isEmpty()) { for (int i = 0; i < abmList.size(); i++) { ApplyBModeImg applyBModeImg = abmList.get(i); applyBModeImg.setbId(applyBMode.getId()); this.applyBModeImgService.insert(applyBModeImg); } } boolean result = this.applyBModeService.updateById(applyBMode); map.put("msg", (result == true) ? "1" : "2"); } catch (Exception e) { e.printStackTrace(); map.put("msg", "4"); } return map; } @Transactional @RequestMapping({"deleteBmodeById"}) public Map deleteBmodeById(Long id) { Map map = new HashMap<>(); try { boolean result = this.applyBModeService.deleteById(id); if (result == true) { map.put("b_id", id); this.applyBModeImgService.deleteByMap(map); map.clear(); map.put("msg", "1"); } else { map.put("msg", "2"); } } catch (Exception e) { e.printStackTrace(); map.put("msg", "4"); } return map; } @RequestMapping({"selectBmodeById"}) public Map selectBmodeById(Long id) { Map map = new HashMap<>(); String account = ""; String phone = ""; ApplyBMode applyBMode = new ApplyBMode(); List abmList = new ArrayList<>(); List abmSp = new ArrayList<>(); EntityWrapper wrapper = new EntityWrapper(); EntityWrapper wrapper2 = new EntityWrapper(); try { applyBMode = (ApplyBMode)this.applyBModeService.selectById(id); if (applyBMode != null) { map.put("patientType", applyBMode.getPatientType()); User user = (User)this.userService.selectById(applyBMode.getDocId()); if (user != null) account = user.getPhone(); wrapper2.eq("b_id", id); abmSp = this.applyBModeSpecialistService.selectList((Wrapper)wrapper2); map.put("b_id", id); wrapper.eq("b_id", id); abmList = this.applyBModeImgService.selectList((Wrapper)wrapper); if (!abmSp.isEmpty() && abmSp.get(0) != null) { applyBMode.setSpecialist(((ApplyBModeSpecialist)abmSp.get(0)).getSpeName()); applyBMode.setSpecialistId(((ApplyBModeSpecialist)abmSp.get(0)).getSpeId()); Long speId = ((ApplyBModeSpecialist)abmSp.get(0)).getSpeId(); //医生删了 那user 就为null 2025 0211 User selectById = (User)this.userService.selectById(speId); if(selectById!=null) phone = selectById.getPhone(); } } map.put("abmSp", abmSp); map.put("applyBMode", applyBMode); map.put("abmList", abmList); map.put("contactPhone", account); map.put("phone", phone); } catch (Exception e) { e.printStackTrace(); map.put("msg", "4"); } return map; } @RequestMapping({"selectBmodePage"}) public Map selectBmodePage(String categoryHospitalId, String groupHospitalId, String startTime, String endTime, String patientName, Integer pageNo, Integer pageSize, Integer type, String part, Long docId, Integer cureType, String diagnosisType, String status, String isRemote) { Map map = new HashMap<>(); map.put("categoryHospitalId", categoryHospitalId); map.put("groupHospitalId", groupHospitalId); map.put("startTime", startTime); map.put("endTime", endTime); map.put("patientName", patientName); map.put("type", type); map.put("part", part); map.put("docId", docId); map.put("isRemote", isRemote); map.put("diagnosisType", diagnosisType); map.put("cureType", Integer.valueOf((cureType == null) ? 1 : cureType.intValue())); map.put("status", status); pageNo = Integer.valueOf((pageNo == null) ? 1 : pageNo.intValue()); pageSize = Integer.valueOf((pageSize == null) ? 10 : pageSize.intValue()); try { Pagetion pagetion = this.applyBModeService.selectBmodePage(map, pageNo, pageSize); map.clear(); if (pagetion != null) for (int i = 0; i < pagetion.getList().size(); i++) { EntityWrapper wrapper = new EntityWrapper(); wrapper.eq("b_id", ((ApplyBMode)pagetion.getList().get(i)).getId()).ne("state", "80"); List abmSp = this.applyBModeSpecialistService.selectList((Wrapper)wrapper); if (!abmSp.isEmpty()) ((ApplyBMode)pagetion.getList().get(i)).setAbmSp(abmSp); } map.put("pagetion", pagetion); } catch (Exception e) { e.printStackTrace(); map.put("msg", "4"); } finally { map.remove("categoryHospitalId"); map.remove("groupHospitalId"); map.remove("startTime"); map.remove("endTime"); map.remove("patientName"); map.remove("type"); map.remove("part"); map.remove("docId"); map.remove("cureType"); map.remove("status"); } return map; } @RequestMapping({"insertBModeSpecialist"}) public Map insertBModeSpecialist(@RequestBody List acList) { Map map = new HashMap<>(); boolean insert = false; try { Long bId = ((ApplyBModeSpecialist)acList.get(0)).getbId(); EntityWrapper bModeWrapper = new EntityWrapper(); bModeWrapper.eq("id", bId); ApplyBMode bMode = (ApplyBMode)this.applyBModeService.selectOne((Wrapper)bModeWrapper); for (ApplyBModeSpecialist applyBModeSpecialist : acList) { EntityWrapper wrapper = new EntityWrapper(); if (applyBModeSpecialist.getbId() != null && applyBModeSpecialist.getSpeId() != null) { wrapper.eq("b_id", applyBModeSpecialist.getbId()) .eq("spe_id", applyBModeSpecialist.getSpeId()); ApplyBModeSpecialist queryApply = (ApplyBModeSpecialist)this.applyBModeSpecialistService.selectOne((Wrapper)wrapper); if (queryApply != null) { applyBModeSpecialist.setId(queryApply.getId()); applyBModeSpecialist.setGroupDate(bMode.getGroupDate()); insert = this.applyBModeSpecialistService.updateById(applyBModeSpecialist); } else { applyBModeSpecialist.setGroupDate(bMode.getGroupDate()); insert = this.applyBModeSpecialistService.insert(applyBModeSpecialist); } } if (!insert) break; } map.put("msg", insert ? "1" : "2"); } catch (Exception e) { e.printStackTrace(); map.put("msg", "4"); } return map; } @RequestMapping({"updateConSpecialist"}) public Map updateConSpecialist(ApplyBModeSpecialist abmSp) { ApplyBMode bmode = (ApplyBMode)this.applyBModeService.selectById(abmSp.getbId()); Map map = new HashMap<>(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = new Date(); EntityWrapper wrapper = new EntityWrapper(); String status = ""; try { if (abmSp != null) { abmSp.setUpdateTime(dateFormat.parse(dateFormat.format(date))); wrapper.eq("spe_id", abmSp.getSpeId()).eq("b_id", abmSp.getbId()); boolean result = this.applyBModeSpecialistService.update(abmSp, (Wrapper)wrapper); if (result == true) { if ("1".equals(bmode.getConsultationWay())) { status = abmSp.getState() + ""; } else { map.put("b_id", abmSp.getbId()); List accList = this.applyBModeSpecialistService.selectByMap(map); if (!accList.isEmpty()) { Map collect = (Map)accList.stream().collect(Collectors.groupingBy(ApplyBModeSpecialist::getState, Collectors.counting())); int sum30 = (collect.get(Integer.valueOf(30)) != null) ? ((Long)collect.get(Integer.valueOf(30))).intValue() : 0; int sum40 = (collect.get(Integer.valueOf(40)) != null) ? ((Long)collect.get(Integer.valueOf(40))).intValue() : 0; int sum80 = (collect.get(Integer.valueOf(80)) != null) ? ((Long)collect.get(Integer.valueOf(80))).intValue() : 0; if (sum40 != 0 && sum30 == 0 && sum80 == 0) { status = "40"; } else if (sum80 != 0 && sum40 == 0 && sum30 == 0) { status = "20"; } else { status = "30"; } } } if (StringUtils.isNotEmpty(status)) { ApplyBMode ab = new ApplyBMode(); ab.setStatus(status); ab.setId(abmSp.getbId()); ab.setDismissReason(abmSp.getDismissReason()); this.applyBModeService.updateById(ab); } map.put("msg", "1"); } else { map.put("msg", "2"); } } else { map.put("msg", "9"); } } catch (Exception e) { e.printStackTrace(); map.put("msg", "4"); } return map; } @RequestMapping({"selectBmodeSpePage"}) public Map selectBmodeSpePage(Integer pageNo, Integer pageSize, String patientName, String startTime, String endTime, String specialistId, Integer cureType, String diagnosisType, Integer part, Integer type, String status) { Map map = new HashMap<>(); pageNo = Integer.valueOf((pageNo == null) ? 1 : pageNo.intValue()); pageSize = Integer.valueOf((pageSize == null) ? 10 : pageSize.intValue()); map.put("patientName", patientName); map.put("startTime", startTime); map.put("endTime", endTime); map.put("specialistId", specialistId); map.put("cureType", Integer.valueOf((cureType == null) ? 1 : cureType.intValue())); map.put("diagnosisType", diagnosisType); map.put("part", part); map.put("type", type); map.put("status", status); try { Pagetion> pagetion = this.applyBModeService.selectBmodeSpePage(map, pageNo, pageSize); if (pagetion != null) for (int i = 0; i < pagetion.getList().size(); i++) { EntityWrapper wrapper = new EntityWrapper(); wrapper.eq("b_id", ((Map)pagetion.getList().get(i)).get("id")); List applyBModeSpecialists = this.applyBModeSpecialistService.selectList((Wrapper)wrapper); pagetion.getList().get(i).put("abmSp", applyBModeSpecialists); } map.put("pagetion", pagetion); } catch (Exception e) { e.printStackTrace(); map.put("msg", "4"); } finally { map.remove("patientName"); map.remove("startTime"); map.remove("endTime"); map.remove("specialistId"); map.remove("cureType"); map.remove("part"); map.remove("type"); map.remove("status"); } return map; } @RequestMapping({"selectMachineModel"}) public Map selectMachineModel() { Map map = this.bmodeMachineModelServiceImpl.selectMachineModel(); return map; } @RequestMapping({"DataStatistics"}) public Map DataStatistics() { Map dataStatistics = this.applyBModeServiceImpl.DataStatistics(); return dataStatistics; } @RequestMapping({"categoryHospitalStatistics"}) public Map categoryHospitalStatistics(String id, String startTime, String endTime) { Map map = this.applyBModeService.categoryHospitalStatistics(id, startTime, endTime); return map; } @RequestMapping({"manageHospitalDataStatistics"}) public Map dataStatisticsForHospital(String startTime, String endTime) { Map map = this.applyBModeService.dataStatisticsForHospital(startTime, endTime); return map; } @RequestMapping({"queuing"}) public Map getQueuing(Long id) { Map map = new HashMap<>(); EntityWrapper wrapper = new EntityWrapper(); int people = 0; int waitTime = 0; int active = 1; try { wrapper.eq("status", "40").eq("active", Integer.valueOf(3)); wrapper.orderBy("active", false); List applyBModes = this.applyBModeService.selectList((Wrapper)wrapper); if (!applyBModes.isEmpty()) for (int i = 0; i < applyBModes.size(); i++) { ApplyBMode bMode = applyBModes.get(i); if (bMode.getId().equals(id)) { people = i; waitTime = i * 15; active = bMode.getActive().intValue(); break; } } map.put("msg", "1"); map.put("people", Integer.valueOf(people)); map.put("waitTime", Integer.valueOf(waitTime)); map.put("active", Integer.valueOf(active)); } catch (Exception e) { e.printStackTrace(); map.put("msg", "4"); } return map; } @Transactional(rollbackFor = {Exception.class}) @RequestMapping({"updateSpecialistBySubmit"}) public Map updateSpecialistBySubmit(@RequestBody List submitDtos) { Map map = new HashMap<>(4); SpecialistSubmitDto submitDto = submitDtos.get(0); EntityWrapper speWrapper = new EntityWrapper(); speWrapper.eq("spe_id", submitDto.getContactsId()); speWrapper.eq("b_id", submitDto.getbId()); try { Long bId = null; String type = null; int successCount = 0; ApplyBModeSpecialist bModeSpecialist = (ApplyBModeSpecialist)this.applyBModeSpecialistService.selectOne((Wrapper)speWrapper); if (bModeSpecialist != null) { bId = bModeSpecialist.getbId(); type = bModeSpecialist.getDiagnosisType(); bModeSpecialist.setSpeId(submitDto.getUserId()); bModeSpecialist.setSpeName(submitDto.getUserName()); bModeSpecialist.setState(Integer.valueOf(70)); boolean updateResult = this.applyBModeSpecialistService.updateById(bModeSpecialist); if (updateResult) successCount++; } if (submitDtos.size() > 1) for (int i = 1; i < submitDtos.size(); i++) { ApplyBModeSpecialist addSpecialist = new ApplyBModeSpecialist(); addSpecialist.setSpeId(((SpecialistSubmitDto)submitDtos.get(i)).getUserId()); addSpecialist.setSpeName(((SpecialistSubmitDto)submitDtos.get(i)).getUserName()); addSpecialist.setState(Integer.valueOf(70)); if (bId != null && type != null) { addSpecialist.setbId(bId); addSpecialist.setDiagnosisType(type); } boolean addResult = this.applyBModeSpecialistService.insert(addSpecialist); if (addResult) successCount++; } if (successCount == submitDtos.size()) map.put("msg", "1"); } catch (Exception e) { e.printStackTrace(); map.put("msg", "4"); } return map; } }