RiBaoService.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. package com.bofeng.service;
  2. import com.baomidou.mybatisplus.toolkit.IdWorker;
  3. import com.bofeng.dao.MsReportMapper;
  4. import com.bofeng.dao.MsSuspectedMapper;
  5. import com.bofeng.dao.UptownHouseMapper;
  6. import com.bofeng.dao.UptownUnitMapper;
  7. import com.bofeng.entity.MsReport;
  8. import com.bofeng.entity.MsSuspected;
  9. import com.bofeng.entity.UptownHouse;
  10. import com.bofeng.entity.UptownUnit;
  11. import org.apache.commons.collections.CollectionUtils;
  12. import org.joda.time.DateTime;
  13. import org.springframework.beans.BeanUtils;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16. import org.springframework.transaction.annotation.Propagation;
  17. import org.springframework.transaction.annotation.Transactional;
  18. import java.math.BigDecimal;
  19. import java.text.SimpleDateFormat;
  20. import java.util.ArrayList;
  21. import java.util.Calendar;
  22. import java.util.Date;
  23. import java.util.List;
  24. /**
  25. * @Author: songjiaqing
  26. * @Date: 2020/2/4 15:44
  27. */
  28. @Service
  29. @Transactional()
  30. public class RiBaoService {
  31. @Autowired
  32. private MsSuspectedMapper msSuspectedMapper;
  33. @Autowired
  34. private MsReportMapper msReportMapper;
  35. @Autowired
  36. private UptownHouseMapper uptownHouseMapper;
  37. @Autowired
  38. private UptownUnitMapper uptownUnitMapper;
  39. @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
  40. public MsReport editRibao(Long reportId) {
  41. DateTime dateTime = new DateTime();
  42. MsReport msReport = msReportMapper.selectById(reportId);
  43. if (msReport != null) {
  44. msReport.setReportStatus(1);
  45. msReport.setTimeUpdate(dateTime);
  46. msReportMapper.updateById(msReport);
  47. }
  48. return msReport;
  49. }
  50. // 删除家人
  51. @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
  52. public int delRibaoDetail(Long suspectedId) {
  53. MsSuspected msSuspectedDb = msSuspectedMapper.selectById(suspectedId);
  54. int num = msSuspectedMapper.deleteById(suspectedId);
  55. //更新今日日报
  56. updateRibao(msSuspectedDb.getReportId());
  57. return num;
  58. }
  59. // 添加修改家人
  60. @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
  61. public MsSuspected addOrEditRibaoDetail(MsSuspected ribaoDetail) {
  62. DateTime dateTime = new DateTime();
  63. //判断是否疑似
  64. Integer suspectedStatus = 0;
  65. if (ribaoDetail.getMuscle().intValue() == 1 ||
  66. ribaoDetail.getSingleRoom().intValue() == 1 ||
  67. ribaoDetail.getTemperature().compareTo(new BigDecimal(36)) == -1 ||
  68. ribaoDetail.getTemperature().compareTo(new BigDecimal(37.3)) == 1 ||
  69. ribaoDetail.getCough() > 0 ||
  70. ribaoDetail.getMuscle() > 0 ||
  71. ribaoDetail.getDyspnea() > 0 ||
  72. ribaoDetail.getFatigue() > 0 ||
  73. ribaoDetail.getDiarrhea() > 0) {
  74. suspectedStatus = 1;
  75. }
  76. ribaoDetail.setSuspectedStatus(suspectedStatus);
  77. if (ribaoDetail.getSuspectedId() != null && ribaoDetail.getSuspectedId().longValue() > 0L) {
  78. ribaoDetail.setTimeUpdate(dateTime);
  79. msSuspectedMapper.updateById(ribaoDetail);
  80. } else {
  81. ribaoDetail.setSuspectedId(IdWorker.getId());
  82. ribaoDetail.setTimeCreate(dateTime);
  83. ribaoDetail.setTimeUpdate(dateTime);
  84. msSuspectedMapper.insert(ribaoDetail);
  85. }
  86. //更新今日日报
  87. updateRibao(ribaoDetail.getReportId());
  88. return ribaoDetail;
  89. }
  90. // 更新今日日报
  91. @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
  92. public void updateRibao(Long reportId) {
  93. //更新今日日报
  94. Integer trueNum = 0, singleNum = 0, isSuspected = 0, isNoSuspected = 0, isFamliy = 0;
  95. //确诊
  96. trueNum = msReportMapper.selectSuspectedNum(reportId);
  97. //居家隔离
  98. singleNum = msReportMapper.selectSingleRoomNum(reportId);
  99. //正常
  100. isSuspected = msReportMapper.selectisSuspectedNum(reportId);
  101. //疑似
  102. isNoSuspected = msReportMapper.selectisNoSuspectedNum(reportId);
  103. //今日居家
  104. List<MsSuspected> list = msSuspectedMapper.selectByReportId(reportId);
  105. if (list != null && list.size() > 0)
  106. isFamliy = list.size();
  107. MsReport msReport = msReportMapper.selectById(reportId);
  108. if (msReport != null) {
  109. msReport.setSureNum(trueNum);
  110. msReport.setSingleNum(singleNum);
  111. msReport.setSuspectedNum(isNoSuspected);
  112. msReport.setNormalNum(isSuspected);
  113. msReport.setSafetyNum(isFamliy);
  114. if (isNoSuspected > 0)
  115. msReport.setMsStatus(2);// 健康状态:1正常,2异常
  116. else
  117. msReport.setMsStatus(1);
  118. msReportMapper.updateById(msReport);
  119. }
  120. }
  121. public MsReport getRibao(Long reportId) {
  122. MsReport msReport = msReportMapper.selectById(reportId);
  123. String houseStr = this.getHouseStr(msReport.getHouseId());
  124. msReport.setHouseIdStr(houseStr);
  125. return msReport;
  126. }
  127. //获取今天数据
  128. public String getHouseStr(Long houseId) {
  129. UptownHouse house = uptownHouseMapper.selectById(houseId);
  130. if (null == house) {
  131. return "";
  132. }
  133. UptownUnit unit = uptownUnitMapper.selectById(house.getUnitId());
  134. StringBuffer sb = new StringBuffer();
  135. if (null == unit) {
  136. sb.append(house.getDoorplate()).append("室");
  137. String houseStr = sb.toString();
  138. return houseStr;
  139. }
  140. sb.append(unit.getRidgepole()).append("栋").append(unit.getUnit()).append("单元").append(house.getDoorplate()).append("室");
  141. String houseStr = sb.toString();
  142. return houseStr;
  143. }
  144. public MsSuspected getRibaoDetail(Long suspectedId) {
  145. MsSuspected obj = msSuspectedMapper.selectById(suspectedId);
  146. if (obj.getGrender().intValue() == 1) {
  147. obj.setGrenderStr("男");
  148. } else if (obj.getGrender().intValue() == 2) {
  149. obj.setGrenderStr("女");
  150. }
  151. if (obj.getFamilyStatus().intValue() == 0) {
  152. obj.setFamilyStatusStr("正常");
  153. } else if (obj.getFamilyStatus().intValue() == 1) {
  154. obj.setFamilyStatusStr("心血管疾病(服用ARB)");
  155. } else if (obj.getFamilyStatus().intValue() == 2) {
  156. obj.setFamilyStatusStr("心血管疾病(未服用ARB)");
  157. } else if (obj.getFamilyStatus().intValue() == 3) {
  158. obj.setFamilyStatusStr("呼吸系统病史");
  159. } else if (obj.getFamilyStatus().intValue() == 4) {
  160. obj.setFamilyStatusStr("肿瘤病史");
  161. } else if (obj.getFamilyStatus().intValue() == 5) {
  162. obj.setFamilyStatusStr("糖尿病史");
  163. } else if (obj.getFamilyStatus().intValue() == 6) {
  164. obj.setFamilyStatusStr("服用过激素药物");
  165. } else if (obj.getFamilyStatus().intValue() == 7) {
  166. obj.setFamilyStatusStr("妊娠期");
  167. } else if (obj.getFamilyStatus().intValue() == 8) {
  168. obj.setFamilyStatusStr("其他");
  169. }
  170. if (obj.getMedical().intValue() == 0) {
  171. obj.setMedicalStr("否");
  172. } else if (obj.getMedical().intValue() == 1) {
  173. obj.setMedicalStr("是");
  174. }
  175. if (obj.getCough().intValue() == 0) {
  176. obj.setCoughStr("无咳嗽");
  177. } else if (obj.getCough().intValue() == 1) {
  178. obj.setCoughStr("偶有短暂咳嗽");
  179. } else if (obj.getCough().intValue() == 2) {
  180. obj.setCoughStr("咳嗽轻度影响生活");
  181. } else if (obj.getCough().intValue() == 3) {
  182. obj.setCoughStr("咳嗽严重影响生活");
  183. }
  184. if (obj.getMuscle().intValue() == 0) {
  185. obj.setMuscleStr("无");
  186. } else if (obj.getMuscle().intValue() == 1) {
  187. obj.setMuscleStr("按压有");
  188. } else if (obj.getMuscle().intValue() == 2) {
  189. obj.setMuscleStr("偶尔");
  190. } else if (obj.getMuscle().intValue() == 3) {
  191. obj.setMuscleStr("持续有");
  192. }
  193. if (obj.getDyspnea().intValue() == 0) {
  194. obj.setDyspneaStr("无");
  195. } else if (obj.getDyspnea().intValue() == 1) {
  196. obj.setDyspneaStr("急走或上坡气短");
  197. } else if (obj.getDyspnea().intValue() == 2) {
  198. obj.setDyspneaStr("气短而走路变慢");
  199. } else if (obj.getDyspnea().intValue() == 3) {
  200. obj.setDyspneaStr("走路数分钟后气短");
  201. } else if (obj.getDyspnea().intValue() == 4) {
  202. obj.setDyspneaStr("气短无法离开房间");
  203. }
  204. if (obj.getFatigue().intValue() == 0) {
  205. obj.setFatigueStr("无");
  206. } else if (obj.getFatigue().intValue() == 1) {
  207. obj.setFatigueStr("可体力劳动但觉得累");
  208. } else if (obj.getFatigue().intValue() == 2) {
  209. obj.setFatigueStr("轻体力劳动后长时间不能恢复");
  210. } else if (obj.getFatigue().intValue() == 3) {
  211. obj.setFatigueStr("不能正常生活");
  212. }
  213. if (obj.getDiarrhea().intValue() == 0) {
  214. obj.setDiarrheaStr("无");
  215. } else if (obj.getDiarrhea().intValue() == 1) {
  216. obj.setDiarrheaStr("轻度腹泻少于于3次");
  217. } else if (obj.getDiarrhea().intValue() == 2) {
  218. obj.setDiarrheaStr("中度腹泻4-6次");
  219. } else if (obj.getDiarrhea().intValue() == 3) {
  220. obj.setDiarrheaStr("重度腹泻超过6次");
  221. }
  222. if (obj.getSingleRoom().intValue() == 0) {
  223. obj.setSingleRoomStr("否");
  224. } else if (obj.getSingleRoom().intValue() == 1) {
  225. obj.setSingleRoomStr("是");
  226. }
  227. if (obj.getSuspectedStatus().intValue() == 0) {
  228. obj.setSuspectedStatusStr("否");
  229. } else if (obj.getSuspectedStatus().intValue() == 1) {
  230. obj.setSuspectedStatusStr("是");
  231. }
  232. return obj;
  233. }
  234. // @Pd(name = "userName") String userName,// 家人姓名
  235. // @Pd(name = "grender") Integer grender,// 性别:0未设置,1男,2女
  236. // @Pd(name = "age") Integer age,// 年龄
  237. // @Pd(name = "familyStatus") Integer familyStatus,// 基本状态:0正常,1心血管疾病(服用ARB),2心血管疾病(未服用ARB),3呼吸系统病史,4肿瘤病史,5糖尿病史,6服用过激素药物,7妊娠期,8其他
  238. // @Pd(name = "statusDesp") String statusDesp,// 状态描述
  239. // @Pd(name = "medical") Integer medical,// 是否确诊:0否,1是
  240. // @Pd(name = "temperature") BigDecimal temperature,// 体温
  241. // @Pd(name = "cough") Integer cough,// 咳嗽:0无咳嗽,1偶有短暂咳嗽,2咳嗽轻度影响生活,3咳嗽严重影响生活
  242. // @Pd(name = "muscle") Integer muscle,// 肌肉酸痛:0无,1按压有,2偶尔,3持续有
  243. // @Pd(name = "dyspnea") Integer dyspnea,// 呼吸困难:0无,1急走或上坡气短,2气短而走路变慢,3走路数分钟后气短,4气短无法离开房间
  244. // @Pd(name = "fatigue") Integer fatigue,// 乏力:0无,1可体力劳动但觉得累,2轻体力劳动后长时间不能恢复,3不能正常生活
  245. // @Pd(name = "diarrhea") Integer diarrhea,// 腹泻:0无,1轻度腹泻少于于3次,2中度腹泻4-6次,3重度腹泻超过6次
  246. // @Pd(name = "singleRoom") Integer singleRoom,// 单间隔离:0否,1是
  247. // // @Pd(name = "suspectedStatus") String suspectedStatus,// 是否疑似:0否,1是
  248. // @Pd(name = "others") String others,// 其他
  249. //获取前一天数据
  250. public List<MsSuspected> queryRibaoDetailList(Long reportId) {
  251. List<MsSuspected> listSuspected = msSuspectedMapper.selectByReportId(reportId);
  252. if (CollectionUtils.isEmpty(listSuspected)) {
  253. listSuspected = new ArrayList<MsSuspected>();
  254. } else {
  255. for (MsSuspected obj : listSuspected) {
  256. if (obj.getGrender().intValue() == 1) {
  257. obj.setGrenderStr("男");
  258. } else if (obj.getGrender().intValue() == 2) {
  259. obj.setGrenderStr("女");
  260. }
  261. if (obj.getFamilyStatus().intValue() == 0) {
  262. obj.setFamilyStatusStr("正常");
  263. } else if (obj.getFamilyStatus().intValue() == 1) {
  264. obj.setFamilyStatusStr("心血管疾病(服用ARB)");
  265. } else if (obj.getFamilyStatus().intValue() == 2) {
  266. obj.setFamilyStatusStr("心血管疾病(未服用ARB)");
  267. } else if (obj.getFamilyStatus().intValue() == 3) {
  268. obj.setFamilyStatusStr("呼吸系统病史");
  269. } else if (obj.getFamilyStatus().intValue() == 4) {
  270. obj.setFamilyStatusStr("肿瘤病史");
  271. } else if (obj.getFamilyStatus().intValue() == 5) {
  272. obj.setFamilyStatusStr("糖尿病史");
  273. } else if (obj.getFamilyStatus().intValue() == 6) {
  274. obj.setFamilyStatusStr("服用过激素药物");
  275. } else if (obj.getFamilyStatus().intValue() == 7) {
  276. obj.setFamilyStatusStr("妊娠期");
  277. } else if (obj.getFamilyStatus().intValue() == 8) {
  278. obj.setFamilyStatusStr("其他");
  279. }
  280. if (obj.getMedical().intValue() == 0) {
  281. obj.setMedicalStr("否");
  282. } else if (obj.getMedical().intValue() == 1) {
  283. obj.setMedicalStr("是");
  284. }
  285. if (obj.getCough().intValue() == 0) {
  286. obj.setCoughStr("无咳嗽");
  287. } else if (obj.getCough().intValue() == 1) {
  288. obj.setCoughStr("偶有短暂咳嗽");
  289. } else if (obj.getCough().intValue() == 2) {
  290. obj.setCoughStr("咳嗽轻度影响生活");
  291. } else if (obj.getCough().intValue() == 3) {
  292. obj.setCoughStr("咳嗽严重影响生活");
  293. }
  294. if (obj.getMuscle().intValue() == 0) {
  295. obj.setMuscleStr("无");
  296. } else if (obj.getMuscle().intValue() == 1) {
  297. obj.setMuscleStr("按压有");
  298. } else if (obj.getMuscle().intValue() == 2) {
  299. obj.setMuscleStr("偶尔");
  300. } else if (obj.getMuscle().intValue() == 3) {
  301. obj.setMuscleStr("持续有");
  302. }
  303. if (obj.getDyspnea().intValue() == 0) {
  304. obj.setDyspneaStr("无");
  305. } else if (obj.getDyspnea().intValue() == 1) {
  306. obj.setDyspneaStr("急走或上坡气短");
  307. } else if (obj.getDyspnea().intValue() == 2) {
  308. obj.setDyspneaStr("气短而走路变慢");
  309. } else if (obj.getDyspnea().intValue() == 3) {
  310. obj.setDyspneaStr("走路数分钟后气短");
  311. } else if (obj.getDyspnea().intValue() == 4) {
  312. obj.setDyspneaStr("气短无法离开房间");
  313. }
  314. if (obj.getFatigue().intValue() == 0) {
  315. obj.setFatigueStr("无");
  316. } else if (obj.getFatigue().intValue() == 1) {
  317. obj.setFatigueStr("可体力劳动但觉得累");
  318. } else if (obj.getFatigue().intValue() == 2) {
  319. obj.setFatigueStr("轻体力劳动后长时间不能恢复");
  320. } else if (obj.getFatigue().intValue() == 3) {
  321. obj.setFatigueStr("不能正常生活");
  322. }
  323. if (obj.getDiarrhea().intValue() == 0) {
  324. obj.setDiarrheaStr("无");
  325. } else if (obj.getDiarrhea().intValue() == 1) {
  326. obj.setDiarrheaStr("轻度腹泻少于于3次");
  327. } else if (obj.getDiarrhea().intValue() == 2) {
  328. obj.setDiarrheaStr("中度腹泻4-6次");
  329. } else if (obj.getDiarrhea().intValue() == 3) {
  330. obj.setDiarrheaStr("重度腹泻超过6次");
  331. }
  332. if (obj.getSingleRoom().intValue() == 0) {
  333. obj.setSingleRoomStr("否");
  334. } else if (obj.getSingleRoom().intValue() == 1) {
  335. obj.setSingleRoomStr("是");
  336. }
  337. if (obj.getSuspectedStatus().intValue() == 0) {
  338. obj.setSuspectedStatusStr("否");
  339. } else if (obj.getSuspectedStatus().intValue() == 1) {
  340. obj.setSuspectedStatusStr("是");
  341. }
  342. }
  343. }
  344. return listSuspected;
  345. }
  346. //通过昨天数据更新今天数据
  347. @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
  348. public Long getNowByYesterday(Long userCreate) {
  349. // 判断今天是否有数据
  350. Date today = new Date();
  351. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  352. String todayStr = sdf.format(today);
  353. List<MsReport> listReportDb = msReportMapper.selectByReportDate(todayStr, userCreate);
  354. if (CollectionUtils.isNotEmpty(listReportDb)) {
  355. Long reportId = listReportDb.get(0).getReportId();
  356. return reportId;
  357. }
  358. // 判断昨天是否有数据
  359. Calendar calendar = Calendar.getInstance();
  360. calendar.setTime(today);
  361. calendar.add(Calendar.DATE, -1);
  362. String yestodayStr = sdf.format(calendar.getTime());
  363. listReportDb = msReportMapper.selectByReportDate(yestodayStr, userCreate);
  364. //有数据
  365. Long reportId = 0L;
  366. DateTime dateTime = new DateTime();
  367. if (CollectionUtils.isNotEmpty(listReportDb)) {
  368. Long reportIdDb = listReportDb.get(0).getReportId();
  369. //添加到今天日报
  370. MsReport msReportDb = msReportMapper.selectById(reportIdDb);
  371. if (msReportDb != null) {
  372. MsReport msReport = new MsReport();
  373. BeanUtils.copyProperties(msReportDb, msReport);
  374. reportId = IdWorker.getId();
  375. msReport.setReportId(reportId);
  376. msReport.setReportDate(dateTime.toDate());
  377. msReport.setReportStatus(0);//未上报
  378. msReport.setUserCreate(userCreate);
  379. msReport.setTimeCreate(dateTime);
  380. msReport.setUserUpdate(userCreate);
  381. msReport.setTimeUpdate(dateTime);
  382. msReportMapper.insert(msReport);
  383. //添加今日家庭
  384. List<MsSuspected> suspectedListDb = msSuspectedMapper.selectByReportId(reportIdDb);
  385. if (CollectionUtils.isNotEmpty(suspectedListDb)) {
  386. for (MsSuspected msSuspectedDb : suspectedListDb) {
  387. MsSuspected msSuspected = new MsSuspected();
  388. BeanUtils.copyProperties(msSuspectedDb, msSuspected);
  389. msSuspected.setSuspectedId(IdWorker.getId());
  390. msSuspected.setReportId(reportId);
  391. msSuspected.setSuspectedStatus(0);
  392. msSuspected.setUserCreate(userCreate);
  393. msSuspected.setTimeCreate(dateTime);
  394. msSuspected.setUserUpdate(userCreate);
  395. msSuspected.setTimeUpdate(dateTime);
  396. msSuspectedMapper.insert(msSuspected);
  397. }
  398. }
  399. } else {
  400. Long houseId = msReportMapper.selectHouseIdByUserId(userCreate);
  401. reportId = IdWorker.getId();
  402. MsReport msReport = new MsReport();
  403. msReport.setReportId(reportId);
  404. msReport.setHouseId(houseId);
  405. msReport.setSafetyNum(0);
  406. msReport.setSureNum(0);
  407. msReport.setSuspectedNum(0);
  408. msReport.setNormalNum(0);
  409. msReport.setSingleNum(0);
  410. msReport.setRemarks("");
  411. msReport.setReportDate(dateTime.toDate());
  412. msReport.setMsStatus(0);
  413. msReport.setUserCreate(userCreate);
  414. msReport.setTimeCreate(dateTime);
  415. msReport.setUserUpdate(userCreate);
  416. msReport.setTimeUpdate(dateTime);
  417. msReportMapper.insert(msReport);
  418. }
  419. } else {
  420. List<Long> houseIds = msReportMapper.selectHouseIdsByUserId(userCreate);
  421. reportId = IdWorker.getId();
  422. MsReport msReport = new MsReport();
  423. msReport.setReportId(reportId);
  424. msReport.setHouseId(houseIds.get(0).longValue());
  425. msReport.setSafetyNum(0);
  426. msReport.setSureNum(0);
  427. msReport.setSuspectedNum(0);
  428. msReport.setNormalNum(0);
  429. msReport.setSingleNum(0);
  430. msReport.setRemarks("");
  431. msReport.setReportDate(dateTime.toDate());
  432. msReport.setMsStatus(0);
  433. msReport.setUserCreate(userCreate);
  434. msReport.setTimeCreate(dateTime);
  435. msReport.setUserUpdate(userCreate);
  436. msReport.setTimeUpdate(dateTime);
  437. msReportMapper.insert(msReport);
  438. }
  439. return reportId;
  440. }
  441. }