package com.bofeng.service; import com.baomidou.mybatisplus.toolkit.IdWorker; import com.bofeng.dao.*; import com.bofeng.entity.*; import org.apache.commons.collections.CollectionUtils; import org.joda.time.DateTime; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; /** * @Author: songjiaqing * @Date: 2020/2/4 15:44 */ @Service @Transactional() public class RiBaoService { @Autowired private MsSuspectedMapper msSuspectedMapper; @Autowired private MsReportMapper msReportMapper; @Autowired private UptownHouseMapper uptownHouseMapper; @Autowired private UptownUnitMapper uptownUnitMapper; @Autowired private UserRoleMapper userRoleMapper; @Autowired private OwnerMapper ownerMapper; @Autowired private UptownMapper uptownMapper; @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) public MsReport editRibao(Long reportId) { DateTime dateTime = new DateTime(); MsReport msReport = msReportMapper.selectById(reportId); if (msReport != null) { msReport.setReportStatus(1); msReport.setTimeUpdate(dateTime); msReportMapper.updateById(msReport); } return msReport; } // 删除家人 @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) public int delRibaoDetail(Long suspectedId) { MsSuspected msSuspectedDb = msSuspectedMapper.selectById(suspectedId); int num = msSuspectedMapper.deleteById(suspectedId); //更新今日日报 updateRibao(msSuspectedDb.getReportId()); return num; } // 添加修改家人 @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) public MsSuspected addOrEditRibaoDetail(MsSuspected ribaoDetail) { DateTime dateTime = new DateTime(); //判断是否疑似 Integer suspectedStatus = 0; if (ribaoDetail.getMuscle().intValue() == 1 || ribaoDetail.getSingleRoom().intValue() == 1 || ribaoDetail.getTemperature().compareTo(new BigDecimal(36)) == -1 || ribaoDetail.getTemperature().compareTo(new BigDecimal(37.3)) == 1 || ribaoDetail.getCough() > 0 || ribaoDetail.getMuscle() > 0 || ribaoDetail.getDyspnea() > 0 || ribaoDetail.getFatigue() > 0 || ribaoDetail.getDiarrhea() > 0) { suspectedStatus = 1; } ribaoDetail.setSuspectedStatus(suspectedStatus); if (ribaoDetail.getSuspectedId() != null && ribaoDetail.getSuspectedId().longValue() > 0L) { ribaoDetail.setTimeUpdate(dateTime); msSuspectedMapper.updateById(ribaoDetail); } else { ribaoDetail.setSuspectedId(IdWorker.getId()); ribaoDetail.setTimeCreate(dateTime); ribaoDetail.setTimeUpdate(dateTime); msSuspectedMapper.insert(ribaoDetail); } //更新今日日报 updateRibao(ribaoDetail.getReportId()); return ribaoDetail; } // 更新今日日报 @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) public void updateRibao(Long reportId) { //更新今日日报 Integer trueNum = 0, singleNum = 0, isSuspected = 0, isNoSuspected = 0, isFamliy = 0; //确诊 trueNum = msReportMapper.selectSuspectedNum(reportId); //疑似 isNoSuspected = msReportMapper.selectisNoSuspectedNum(reportId); //居家隔离 singleNum = msReportMapper.selectSingleRoomNum(reportId); //正常 isSuspected = msReportMapper.selectisSuspectedNum(reportId); //今日居家 List list = msSuspectedMapper.selectByReportId(reportId); if (list != null && list.size() > 0) isFamliy = list.size(); MsReport msReport = msReportMapper.selectById(reportId); if (msReport != null) { msReport.setSureNum(trueNum); msReport.setSuspectedNum(isNoSuspected); msReport.setNormalNum(isSuspected); msReport.setSingleNum(singleNum); msReport.setSafetyNum(isFamliy); if (trueNum > 0 || isNoSuspected > 0 || singleNum > 0) { msReport.setMsStatus(2);// 健康状态:1正常,2异常 } else { msReport.setMsStatus(1); } msReportMapper.updateById(msReport); } } public MsReport getRibao(Long reportId) { MsReport msReport = msReportMapper.selectById(reportId); String houseStr = this.getHouseStr(msReport.getHouseId()); msReport.setHouseIdStr(houseStr); return msReport; } //获取今天数据 public String getHouseStr(Long houseId) { UptownHouse house = uptownHouseMapper.selectById(houseId); if (null == house) { return ""; } UptownUnit unit = uptownUnitMapper.selectById(house.getUnitId()); StringBuffer sb = new StringBuffer(); if (null == unit) { sb.append(house.getDoorplate()).append("室"); String houseStr = sb.toString(); return houseStr; } sb.append(unit.getRidgepole()).append("栋").append(unit.getUnit()).append("单元").append(house.getDoorplate()).append("室"); String houseStr = sb.toString(); return houseStr; } public MsSuspected getRibaoDetail(Long suspectedId) { MsSuspected obj = msSuspectedMapper.selectById(suspectedId); if (obj.getGrender().intValue() == 1) { obj.setGrenderStr("男"); } else if (obj.getGrender().intValue() == 2) { obj.setGrenderStr("女"); } if (obj.getFamilyStatus().intValue() == 0) { obj.setFamilyStatusStr("正常"); } else if (obj.getFamilyStatus().intValue() == 1) { obj.setFamilyStatusStr("心血管疾病(服用ARB)"); } else if (obj.getFamilyStatus().intValue() == 2) { obj.setFamilyStatusStr("心血管疾病(未服用ARB)"); } else if (obj.getFamilyStatus().intValue() == 3) { obj.setFamilyStatusStr("呼吸系统病史"); } else if (obj.getFamilyStatus().intValue() == 4) { obj.setFamilyStatusStr("肿瘤病史"); } else if (obj.getFamilyStatus().intValue() == 5) { obj.setFamilyStatusStr("糖尿病史"); } else if (obj.getFamilyStatus().intValue() == 6) { obj.setFamilyStatusStr("服用过激素药物"); } else if (obj.getFamilyStatus().intValue() == 7) { obj.setFamilyStatusStr("妊娠期"); } else if (obj.getFamilyStatus().intValue() == 8) { obj.setFamilyStatusStr("其他"); } if (obj.getMedical().intValue() == 0) { obj.setMedicalStr("否"); } else if (obj.getMedical().intValue() == 1) { obj.setMedicalStr("是"); } if (obj.getCough().intValue() == 0) { obj.setCoughStr("无咳嗽"); } else if (obj.getCough().intValue() == 1) { obj.setCoughStr("偶有短暂咳嗽"); } else if (obj.getCough().intValue() == 2) { obj.setCoughStr("咳嗽轻度影响生活"); } else if (obj.getCough().intValue() == 3) { obj.setCoughStr("咳嗽严重影响生活"); } if (obj.getMuscle().intValue() == 0) { obj.setMuscleStr("无"); } else if (obj.getMuscle().intValue() == 1) { obj.setMuscleStr("按压有"); } else if (obj.getMuscle().intValue() == 2) { obj.setMuscleStr("偶尔"); } else if (obj.getMuscle().intValue() == 3) { obj.setMuscleStr("持续有"); } if (obj.getDyspnea().intValue() == 0) { obj.setDyspneaStr("无"); } else if (obj.getDyspnea().intValue() == 1) { obj.setDyspneaStr("急走或上坡气短"); } else if (obj.getDyspnea().intValue() == 2) { obj.setDyspneaStr("气短而走路变慢"); } else if (obj.getDyspnea().intValue() == 3) { obj.setDyspneaStr("走路数分钟后气短"); } else if (obj.getDyspnea().intValue() == 4) { obj.setDyspneaStr("气短无法离开房间"); } if (obj.getFatigue().intValue() == 0) { obj.setFatigueStr("无"); } else if (obj.getFatigue().intValue() == 1) { obj.setFatigueStr("可体力劳动但觉得累"); } else if (obj.getFatigue().intValue() == 2) { obj.setFatigueStr("轻体力劳动后长时间不能恢复"); } else if (obj.getFatigue().intValue() == 3) { obj.setFatigueStr("不能正常生活"); } if (obj.getDiarrhea().intValue() == 0) { obj.setDiarrheaStr("无"); } else if (obj.getDiarrhea().intValue() == 1) { obj.setDiarrheaStr("轻度腹泻少于于3次"); } else if (obj.getDiarrhea().intValue() == 2) { obj.setDiarrheaStr("中度腹泻4-6次"); } else if (obj.getDiarrhea().intValue() == 3) { obj.setDiarrheaStr("重度腹泻超过6次"); } if (obj.getSingleRoom().intValue() == 0) { obj.setSingleRoomStr("否"); } else if (obj.getSingleRoom().intValue() == 1) { obj.setSingleRoomStr("是"); } if (obj.getSuspectedStatus().intValue() == 0) { obj.setSuspectedStatusStr("否"); } else if (obj.getSuspectedStatus().intValue() == 1) { obj.setSuspectedStatusStr("是"); } return obj; } // @Pd(name = "userName") String userName,// 家人姓名 // @Pd(name = "grender") Integer grender,// 性别:0未设置,1男,2女 // @Pd(name = "age") Integer age,// 年龄 // @Pd(name = "familyStatus") Integer familyStatus,// 基本状态:0正常,1心血管疾病(服用ARB),2心血管疾病(未服用ARB),3呼吸系统病史,4肿瘤病史,5糖尿病史,6服用过激素药物,7妊娠期,8其他 // @Pd(name = "statusDesp") String statusDesp,// 状态描述 // @Pd(name = "medical") Integer medical,// 是否确诊:0否,1是 // @Pd(name = "temperature") BigDecimal temperature,// 体温 // @Pd(name = "cough") Integer cough,// 咳嗽:0无咳嗽,1偶有短暂咳嗽,2咳嗽轻度影响生活,3咳嗽严重影响生活 // @Pd(name = "muscle") Integer muscle,// 肌肉酸痛:0无,1按压有,2偶尔,3持续有 // @Pd(name = "dyspnea") Integer dyspnea,// 呼吸困难:0无,1急走或上坡气短,2气短而走路变慢,3走路数分钟后气短,4气短无法离开房间 // @Pd(name = "fatigue") Integer fatigue,// 乏力:0无,1可体力劳动但觉得累,2轻体力劳动后长时间不能恢复,3不能正常生活 // @Pd(name = "diarrhea") Integer diarrhea,// 腹泻:0无,1轻度腹泻少于于3次,2中度腹泻4-6次,3重度腹泻超过6次 // @Pd(name = "singleRoom") Integer singleRoom,// 单间隔离:0否,1是 // // @Pd(name = "suspectedStatus") String suspectedStatus,// 是否疑似:0否,1是 // @Pd(name = "others") String others,// 其他 //获取前一天数据 public List queryRibaoDetailList(Long reportId) { List listSuspected = msSuspectedMapper.selectByReportId(reportId); if (CollectionUtils.isEmpty(listSuspected)) { listSuspected = new ArrayList(); } else { for (MsSuspected obj : listSuspected) { if (obj.getGrender().intValue() == 1) { obj.setGrenderStr("男"); } else if (obj.getGrender().intValue() == 2) { obj.setGrenderStr("女"); } if (obj.getFamilyStatus().intValue() == 0) { obj.setFamilyStatusStr("正常"); } else if (obj.getFamilyStatus().intValue() == 1) { obj.setFamilyStatusStr("心血管疾病(服用ARB)"); } else if (obj.getFamilyStatus().intValue() == 2) { obj.setFamilyStatusStr("心血管疾病(未服用ARB)"); } else if (obj.getFamilyStatus().intValue() == 3) { obj.setFamilyStatusStr("呼吸系统病史"); } else if (obj.getFamilyStatus().intValue() == 4) { obj.setFamilyStatusStr("肿瘤病史"); } else if (obj.getFamilyStatus().intValue() == 5) { obj.setFamilyStatusStr("糖尿病史"); } else if (obj.getFamilyStatus().intValue() == 6) { obj.setFamilyStatusStr("服用过激素药物"); } else if (obj.getFamilyStatus().intValue() == 7) { obj.setFamilyStatusStr("妊娠期"); } else if (obj.getFamilyStatus().intValue() == 8) { obj.setFamilyStatusStr("其他"); } if (obj.getMedical().intValue() == 0) { obj.setMedicalStr("否"); } else if (obj.getMedical().intValue() == 1) { obj.setMedicalStr("是"); } if (obj.getCough().intValue() == 0) { obj.setCoughStr("无咳嗽"); } else if (obj.getCough().intValue() == 1) { obj.setCoughStr("偶有短暂咳嗽"); } else if (obj.getCough().intValue() == 2) { obj.setCoughStr("咳嗽轻度影响生活"); } else if (obj.getCough().intValue() == 3) { obj.setCoughStr("咳嗽严重影响生活"); } if (obj.getMuscle().intValue() == 0) { obj.setMuscleStr("无"); } else if (obj.getMuscle().intValue() == 1) { obj.setMuscleStr("按压有"); } else if (obj.getMuscle().intValue() == 2) { obj.setMuscleStr("偶尔"); } else if (obj.getMuscle().intValue() == 3) { obj.setMuscleStr("持续有"); } if (obj.getDyspnea().intValue() == 0) { obj.setDyspneaStr("无"); } else if (obj.getDyspnea().intValue() == 1) { obj.setDyspneaStr("急走或上坡气短"); } else if (obj.getDyspnea().intValue() == 2) { obj.setDyspneaStr("气短而走路变慢"); } else if (obj.getDyspnea().intValue() == 3) { obj.setDyspneaStr("走路数分钟后气短"); } else if (obj.getDyspnea().intValue() == 4) { obj.setDyspneaStr("气短无法离开房间"); } if (obj.getFatigue().intValue() == 0) { obj.setFatigueStr("无"); } else if (obj.getFatigue().intValue() == 1) { obj.setFatigueStr("可体力劳动但觉得累"); } else if (obj.getFatigue().intValue() == 2) { obj.setFatigueStr("轻体力劳动后长时间不能恢复"); } else if (obj.getFatigue().intValue() == 3) { obj.setFatigueStr("不能正常生活"); } if (obj.getDiarrhea().intValue() == 0) { obj.setDiarrheaStr("无"); } else if (obj.getDiarrhea().intValue() == 1) { obj.setDiarrheaStr("轻度腹泻少于于3次"); } else if (obj.getDiarrhea().intValue() == 2) { obj.setDiarrheaStr("中度腹泻4-6次"); } else if (obj.getDiarrhea().intValue() == 3) { obj.setDiarrheaStr("重度腹泻超过6次"); } if (obj.getSingleRoom().intValue() == 0) { obj.setSingleRoomStr("否"); } else if (obj.getSingleRoom().intValue() == 1) { obj.setSingleRoomStr("是"); } if (obj.getSuspectedStatus().intValue() == 0) { obj.setSuspectedStatusStr("否"); } else if (obj.getSuspectedStatus().intValue() == 1) { obj.setSuspectedStatusStr("是"); } } } return listSuspected; } //通过昨天数据更新今天数据 @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) public Long getNowByYesterday(Long userCreate) { // 判断今天是否有数据 Date today = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String todayStr = sdf.format(today); List listReportDb = msReportMapper.selectByReportDate(todayStr, userCreate); if (CollectionUtils.isNotEmpty(listReportDb)) { Long reportId = listReportDb.get(0).getReportId(); return reportId; } // 判断昨天是否有数据 Calendar calendar = Calendar.getInstance(); calendar.setTime(today); calendar.add(Calendar.DATE, -1); String yestodayStr = sdf.format(calendar.getTime()); listReportDb = msReportMapper.selectByReportDate(yestodayStr, userCreate); //有数据 Long reportId = 0L; DateTime dateTime = new DateTime(); if (CollectionUtils.isNotEmpty(listReportDb)) { Long reportIdDb = listReportDb.get(0).getReportId(); //添加到今天日报 MsReport msReportDb = msReportMapper.selectById(reportIdDb); if (msReportDb != null) { MsReport msReport = new MsReport(); BeanUtils.copyProperties(msReportDb, msReport); reportId = IdWorker.getId(); msReport.setReportId(reportId); msReport.setReportDate(dateTime.toDate()); msReport.setReportStatus(0);//未上报 msReport.setUserCreate(userCreate); msReport.setTimeCreate(dateTime); msReport.setUserUpdate(userCreate); msReport.setTimeUpdate(dateTime); msReportMapper.insert(msReport); //添加今日家庭 List suspectedListDb = msSuspectedMapper.selectByReportId(reportIdDb); if (CollectionUtils.isNotEmpty(suspectedListDb)) { for (MsSuspected msSuspectedDb : suspectedListDb) { MsSuspected msSuspected = new MsSuspected(); BeanUtils.copyProperties(msSuspectedDb, msSuspected); msSuspected.setSuspectedId(IdWorker.getId()); msSuspected.setReportId(reportId); msSuspected.setSuspectedStatus(0); msSuspected.setUserCreate(userCreate); msSuspected.setTimeCreate(dateTime); msSuspected.setUserUpdate(userCreate); msSuspected.setTimeUpdate(dateTime); msSuspectedMapper.insert(msSuspected); } } } else { Long houseId = msReportMapper.selectHouseIdByUserId(userCreate); reportId = IdWorker.getId(); MsReport msReport = new MsReport(); msReport.setReportId(reportId); msReport.setHouseId(houseId); msReport.setSafetyNum(0); msReport.setSureNum(0); msReport.setSuspectedNum(0); msReport.setNormalNum(0); msReport.setSingleNum(0); msReport.setRemarks(""); msReport.setReportDate(dateTime.toDate()); msReport.setMsStatus(0); msReport.setUserCreate(userCreate); msReport.setTimeCreate(dateTime); msReport.setUserUpdate(userCreate); msReport.setTimeUpdate(dateTime); msReportMapper.insert(msReport); } } else { List houseIds = msReportMapper.selectHouseIdsByUserId(userCreate); reportId = IdWorker.getId(); MsReport msReport = new MsReport(); msReport.setReportId(reportId); msReport.setHouseId(houseIds.get(0).longValue()); msReport.setSafetyNum(0); msReport.setSureNum(0); msReport.setSuspectedNum(0); msReport.setNormalNum(0); msReport.setSingleNum(0); msReport.setRemarks(""); msReport.setReportDate(dateTime.toDate()); msReport.setMsStatus(0); msReport.setUserCreate(userCreate); msReport.setTimeCreate(dateTime); msReport.setUserUpdate(userCreate); msReport.setTimeUpdate(dateTime); msReportMapper.insert(msReport); } return reportId; } //----------------------------------------------------------------- public UptownUnit getRibaoYwh(Long userId) { DateTime dateTime = new DateTime(); UptownUnit uptownUnitVo = new UptownUnit(); uptownUnitVo.setUptownId(0L); uptownUnitVo.setUptownName(""); uptownUnitVo.setReportDate(dateTime.toDate()); uptownUnitVo.setDoorplateNum(0); uptownUnitVo.setYiBaoNum(0); uptownUnitVo.setWeiBaoNum(0); uptownUnitVo.setYiChangNum(0); uptownUnitVo.setYiChangAddNum(0); uptownUnitVo.setYiChangSubNum(0); List userRoles = userRoleMapper.getUserRoleYwhsByUserId(userId); Long ownerId = userRoles.get(0).getPropertyId(); Owner owner = ownerMapper.selectById(ownerId); Uptown uptown = uptownMapper.selectById(owner.getUptownId()); Long uptownId = uptown.getUptownId(); List dongList = uptownUnitMapper.queryDongList(uptownId); if (CollectionUtils.isNotEmpty(dongList)) { List xiaoQuList = uptownUnitMapper.queryXiaoQuList(uptownId); if (null == xiaoQuList) { xiaoQuList = new ArrayList(); } int doorplateNum = xiaoQuList.size(); Date today = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String todayStr = sdf.format(today); List yiBaoList = uptownUnitMapper.queryYiBaoList(uptownId, todayStr); if (null == yiBaoList) { yiBaoList = new ArrayList(); } int yiBaoNum = yiBaoList.size(); List yiChangList = uptownUnitMapper.queryYiChangList(uptownId, todayStr); if (null == yiChangList) { yiChangList = new ArrayList(); } int yiChangNum = yiChangList.size(); // System.out.println("yiChangNum================>>" + yiChangNum); Calendar calendar = Calendar.getInstance(); calendar.setTime(today); calendar.add(Calendar.DATE, -1); String yestodayStr = sdf.format(calendar.getTime()); List yiChangYestodayList = uptownUnitMapper.queryYiChangList(uptownId, yestodayStr); if (null == yiChangList) { yiChangYestodayList = new ArrayList(); } int yiChangYestodayNum = yiChangYestodayList.size(); // System.out.println("yiChangYestodayNum================>>" + yiChangYestodayNum); UptownUnit uptownUnitDb = dongList.get(0); uptownUnitVo.setUptownId(uptownUnitDb.getUptownId());// 小区id uptownUnitVo.setUptownName(uptownUnitDb.getUptownName());// 小区名称 uptownUnitVo.setReportDate(dateTime.toDate());// 日报日期 uptownUnitVo.setDoorplateNum(doorplateNum);// 户数 uptownUnitVo.setYiBaoNum(yiBaoNum);// 已报数 uptownUnitVo.setWeiBaoNum(doorplateNum - yiBaoNum);// 未报数 uptownUnitVo.setYiChangNum(yiChangNum);// 异常数 if (yiChangNum - yiChangYestodayNum > 0) { uptownUnitVo.setYiChangAddNum(yiChangNum - yiChangYestodayNum);// 异常新增数 } if (yiBaoNum > 0 && yiChangYestodayNum - yiChangNum > 0) { uptownUnitVo.setYiChangSubNum(yiChangYestodayNum - yiChangNum);// 异常减少数 } } return uptownUnitVo; } public List queryRibaoYwhDongList(Long uptownId) { List dongList = uptownUnitMapper.queryDongList(uptownId); return dongList; } public List queryDanYuanList(Long uptownId, Long ridgepole) { List dongList = uptownUnitMapper.queryDanYuanList(uptownId, ridgepole); return dongList; } public List queryMenPaiList(Long uptownId, Long ridgepole, Long unitId) { Date today = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String todayStr = sdf.format(today); Calendar calendar = Calendar.getInstance(); calendar.setTime(today); calendar.add(Calendar.DATE, -2); String yestodayStr = sdf.format(calendar.getTime()); List dongList = uptownUnitMapper.queryMenPaiList(uptownId, ridgepole, unitId, yestodayStr); if (CollectionUtils.isNotEmpty(dongList)) { for (UptownUnit obj : dongList) { if (obj.getMsStatus() != null && obj.getMsStatus().intValue() == 1) { // 健康状态:1正常,2异常 obj.setMsStatusStr("正常"); } else if (obj.getMsStatus() != null && obj.getMsStatus().intValue() == 2) { // 健康状态:1正常,2异常 obj.setMsStatusStr("异常"); } else { obj.setMsStatus(-1); obj.setMsStatusStr("未报"); obj.setSafetyNum(0); } } } return dongList; } }