YBJServiceImpl.java 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. package com.malk.yibaoju.service.impl;
  2. import com.alibaba.fastjson.JSON;
  3. import com.malk.server.aliwork.YDConf;
  4. import com.malk.server.aliwork.YDParam;
  5. import com.malk.service.aliwork.YDClient;
  6. import com.malk.service.aliwork.YDService;
  7. import com.malk.utils.UtilDateTime;
  8. import com.malk.utils.UtilMap;
  9. import com.malk.yibaoju.service.YBJService;
  10. import lombok.SneakyThrows;
  11. import lombok.extern.slf4j.Slf4j;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.scheduling.annotation.Async;
  14. import org.springframework.stereotype.Service;
  15. import java.time.LocalDate;
  16. import java.time.format.TextStyle;
  17. import java.time.temporal.TemporalAdjusters;
  18. import java.util.*;
  19. import java.util.concurrent.ExecutionException;
  20. import java.util.stream.Collectors;
  21. @Service
  22. @Slf4j
  23. public class YBJServiceImpl implements YBJService {
  24. @Autowired
  25. private YDClient ydClient;
  26. @Autowired
  27. private YDService ydService;
  28. /**
  29. * 每月创建护理计划
  30. */
  31. @Override
  32. @SneakyThrows
  33. public void syncNursePlan() {
  34. YDParam ydParam = new YDParam();
  35. log.info("创建护理计划定时任务Start",new Date());
  36. ydParam = YDParam.builder()
  37. .formUuid("FORM-RK966E7105DFD27FA7EQHAOH9IFS2RN6MP3OL2") //获取护理计划
  38. .searchFieldJson(JSON.toJSONString(UtilMap.map("selectField_lo2b6bvf","正常")))//护理对象暂停和正常、月度计划创建只查询正常的护理计划
  39. .build();
  40. //pagesize设为1获取总数
  41. ydParam.setPageSize(1);
  42. long totalCount = ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getTotalCount();
  43. float pageSize = 50;
  44. ydParam.setCurrentPage(1);
  45. ydParam.setPageSize((int) pageSize);
  46. List<Map> dataList = new ArrayList<>();
  47. for (int page = 1; page <= Math.ceil(totalCount / pageSize); page++) {
  48. ydParam.setCurrentPage(page);
  49. //创建护理计划 1次获取50条
  50. dataList = (List<Map>) ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getData();
  51. log.info("dataList:{}-----page:"+page+"---",dataList.size());
  52. LocalDate currentDate = LocalDate.now();
  53. //获取当前日期是本月几号
  54. int dayOfMonth = currentDate.getDayOfMonth();
  55. //获取本月天数
  56. int daysInMonth = currentDate.lengthOfMonth();
  57. dataList.forEach(dataItem -> {
  58. Map formMap = (Map) dataItem.get("formData");
  59. List<Map> mapList = (List<Map>) formMap.get("tableField_lo3pmohx");
  60. for (int i =0 ; i <=(daysInMonth-dayOfMonth) ; i++) {
  61. //获取当前日期是本月几号
  62. LocalDate currentDay = LocalDate.now();
  63. //获取是周几
  64. String dayOfWeek = currentDay.plusDays(i).getDayOfWeek().getDisplayName(TextStyle.FULL, new Locale("zh", "CN"));
  65. //获取循环每天的日期
  66. LocalDate nextDay = currentDate.plusDays(i);
  67. List<Map> maps = mapList.stream().filter(items -> items.get("selectField_lo3pmohy").equals(dayOfWeek.replace("星期","周"))).collect(Collectors.toList());
  68. for (Map map : maps) {
  69. Map hashMap = new HashMap();
  70. try {
  71. Thread.sleep(100);
  72. } catch (InterruptedException e) {
  73. throw new RuntimeException(e);
  74. }
  75. //通过护理时间 护理对象 护理人员验证数据是否已经存在
  76. YDParam ydParam1 = YDParam.builder()
  77. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  78. .searchFieldJson(JSON.toJSONString(UtilMap.map("dateField_lred6eoj, textField_lnyhv5tn, textField_lombve2g",Arrays.asList(UtilDateTime.parse( nextDay+ " 00:00:01","yyyy-MM-dd HH:mm:ss"),UtilDateTime.parse( currentDate.with(TemporalAdjusters.lastDayOfMonth())+ " 23:59:59","yyyy-MM-dd HH:mm:ss")),formMap.get("textField_lnyhv5tn"),map.get("textField_lomchzi3"))))
  79. .build();
  80. List<Map> dataLists = (List<Map>) ydClient.queryData(ydParam1, YDConf.FORM_QUERY.retrieve_search_form).getData();
  81. if (dataLists.size()<1){
  82. hashMap.put("associationFormField_lo3pmohz",JSON.parse(map.get("associationFormField_lo3pmohz_id").toString())); //护理人员名称
  83. hashMap.put("textField_lo3pmoi0",map.get("textField_lo3pmoi0")); //护理人员所属机构
  84. hashMap.put("textField_lombve2g",map.get("textField_lomchzi3")); //护理人员身份证
  85. hashMap.put("textField_lo3pmoi3",map.get("textField_lo3pmoi3")); //护理人员手机号
  86. hashMap.put("associationFormField_lo3pmohw",JSON.parse(formMap.get("associationFormField_lo3pmohw_id").toString())); //护理对象姓名
  87. hashMap.put("textField_lnyhv5tn",formMap.get("textField_lnyhv5tn")); //护理对象身份证
  88. hashMap.put("selectField_lnyhv5tp",formMap.get("selectField_lnyhv5tp")); //护理对象等级
  89. hashMap.put("textField_lnyhv5tr",formMap.get("textField_lnyhv5tr")); //护理对象住址
  90. hashMap.put("selectField_lo3pmohy",dayOfWeek.replace("星期","周")); //护理时间 (星期几)
  91. hashMap.put("dateField_lred6eoj", UtilDateTime.parse(String.valueOf(nextDay)+" "+map.get("selectField_lr1uxpu3"),"yyyy-MM-dd HH:mm")); //护理开始时间。 用当前日期+护理计划的 时分 转成时间戳
  92. hashMap.put("dateField_lred6eok", UtilDateTime.parse(String.valueOf(nextDay)+" "+map.get("selectField_lr1uxpu4"),"yyyy-MM-dd HH:mm")); //护理结束时间。 用当前日期+护理计划的 时分 转成时间戳
  93. hashMap.put("selectField_lqcgsbw2","未执行"); //执行情况
  94. hashMap.put("selectField_lo56u5fn","待上报"); //任务状态
  95. hashMap.put("textField_lvae7q5n",formMap.get("textField_lvae99fj")); //护理对象经度
  96. hashMap.put("textField_lvae7q5o",formMap.get("textField_lvae99fk")); //护理对象纬度
  97. hashMap.put("textField_lrx0r38x",String.valueOf(nextDay)); //护理日期-文本
  98. hashMap.put("selectField_lr36z6hd","是"); //任务状态
  99. hashMap.put("textField_lo55rupj",formMap.get("textField_lo55rupj")); //护理对象姓名-文本
  100. hashMap.put("textField_lo3pmoi4",map.get("textField_lo3pmoi4")); //护理证书类型
  101. hashMap.put("employeeField_lo3pmoi6",JSON.parse(map.get("employeeField_lo3pmoi6_id").toString())); //护理人员姓名-成员
  102. hashMap.put("textField_lpgi8scj",map.get("textField_lo701pwy")); //计划明细id
  103. hashMap.put("textField_lq9llmhl",formMap.get("textField_lop4v4qx")); //护理对象ID
  104. try {
  105. Thread.sleep(100);
  106. } catch (InterruptedException e) {
  107. throw new RuntimeException(e);
  108. }
  109. try {
  110. ydClient.operateData(YDParam.builder()
  111. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  112. .formDataJson(JSON.toJSONString(hashMap))
  113. .build(), YDConf.FORM_OPERATION.create);
  114. } catch (Exception e) {
  115. log.info("异常数据{}",hashMap);
  116. }
  117. }
  118. }
  119. }
  120. });
  121. }
  122. log.info("创建护理计划定时任务end",new Date());
  123. }
  124. /**
  125. *定时任务每月25号创建下月的数据
  126. */
  127. @Override
  128. @SneakyThrows
  129. public void syncCreatePlan() {
  130. YDParam ydParam = new YDParam();
  131. log.info("创建下月护理计划定时任务Start",new Date());
  132. ydParam = YDParam.builder()
  133. .formUuid("FORM-RK966E7105DFD27FA7EQHAOH9IFS2RN6MP3OL2") //获取护理计划
  134. .searchFieldJson(JSON.toJSONString(UtilMap.map("selectField_lo2b6bvf","正常")))//护理对象暂停和正常、月度计划创建只查询正常的护理计划
  135. .build();
  136. //pagesize设为1获取总数
  137. ydParam.setPageSize(1);
  138. long totalCount = ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getTotalCount();
  139. float pageSize = 50;
  140. ydParam.setCurrentPage(1);
  141. ydParam.setPageSize((int) pageSize);
  142. List<Map> dataList = new ArrayList<>();
  143. LocalDate currentDate = LocalDate.now();
  144. //获取下月1号的日期
  145. LocalDate firstDayOfNextMonth = currentDate.plusMonths(1).with(TemporalAdjusters.firstDayOfMonth());
  146. //获取日期是几号
  147. int dayOfMonth = firstDayOfNextMonth .getDayOfMonth();
  148. //获取月天数
  149. int daysInMonth = firstDayOfNextMonth.lengthOfMonth();
  150. for (int page = 1; page <= Math.ceil(totalCount / pageSize); page++) {
  151. ydParam.setCurrentPage(page);
  152. //创建护理计划 1次获取50条
  153. dataList = (List<Map>) ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getData();
  154. log.info("dataList:{}-----page:"+page+"---",dataList.size());
  155. dataList.forEach(dataItem -> {
  156. Map formMap = (Map) dataItem.get("formData");
  157. List<Map> mapList = (List<Map>) formMap.get("tableField_lo3pmohx");
  158. for (int i =0 ; i <=(daysInMonth-dayOfMonth) ; i++) {
  159. //获取是周几
  160. String dayOfWeek = firstDayOfNextMonth.plusDays(i).getDayOfWeek().getDisplayName(TextStyle.FULL, new Locale("zh", "CN"));
  161. //获取循环每天的日期
  162. LocalDate nextDay = firstDayOfNextMonth.plusDays(i);
  163. List<Map> maps = mapList.stream().filter(items -> items.get("selectField_lo3pmohy").equals(dayOfWeek.replace("星期","周"))).collect(Collectors.toList());
  164. for (Map map : maps) {
  165. Map hashMap = new HashMap();
  166. try {
  167. Thread.sleep(200);
  168. } catch (InterruptedException e) {
  169. throw new RuntimeException(e);
  170. }
  171. //通过护理时间 护理对象 护理人员验证数据是否已经存在
  172. YDParam ydParam1 = YDParam.builder()
  173. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  174. .searchFieldJson(JSON.toJSONString(UtilMap.map("dateField_lred6eoj, textField_lnyhv5tn, textField_lombve2g",Arrays.asList(UtilDateTime.parse( nextDay+ " 00:00:01","yyyy-MM-dd HH:mm:ss"),UtilDateTime.parse( nextDay.with(TemporalAdjusters.lastDayOfMonth())+ " 23:59:59","yyyy-MM-dd HH:mm:ss")),formMap.get("textField_lnyhv5tn"),map.get("textField_lomchzi3"))))
  175. .build();
  176. List<Map> dataLists = (List<Map>) ydClient.queryData(ydParam1, YDConf.FORM_QUERY.retrieve_search_form).getData();
  177. if (dataLists.size()<1){
  178. hashMap.put("associationFormField_lo3pmohz",JSON.parse(map.get("associationFormField_lo3pmohz_id").toString())); //护理人员名称
  179. hashMap.put("textField_lo3pmoi0",map.get("textField_lo3pmoi0")); //护理人员所属机构
  180. hashMap.put("textField_lombve2g",map.get("textField_lomchzi3")); //护理人员身份证
  181. hashMap.put("textField_lo3pmoi3",map.get("textField_lo3pmoi3")); //护理人员手机号
  182. hashMap.put("associationFormField_lo3pmohw",JSON.parse(formMap.get("associationFormField_lo3pmohw_id").toString())); //护理对象姓名
  183. hashMap.put("textField_lnyhv5tn",formMap.get("textField_lnyhv5tn")); //护理对象身份证
  184. hashMap.put("selectField_lnyhv5tp",formMap.get("selectField_lnyhv5tp")); //护理对象等级
  185. hashMap.put("textField_lnyhv5tr",formMap.get("textField_lnyhv5tr")); //护理对象住址
  186. hashMap.put("selectField_lo3pmohy",dayOfWeek.replace("星期","周")); //护理时间 (星期几)
  187. hashMap.put("dateField_lred6eoj", UtilDateTime.parse(String.valueOf(nextDay)+" "+map.get("selectField_lr1uxpu3"),"yyyy-MM-dd HH:mm")); //护理开始时间。 用当前日期+护理计划的 时分 转成时间戳
  188. hashMap.put("dateField_lred6eok", UtilDateTime.parse(String.valueOf(nextDay)+" "+map.get("selectField_lr1uxpu4"),"yyyy-MM-dd HH:mm")); //护理结束时间。 用当前日期+护理计划的 时分 转成时间戳
  189. hashMap.put("selectField_lqcgsbw2","未执行"); //执行情况
  190. hashMap.put("selectField_lo56u5fn","待上报"); //任务状态
  191. hashMap.put("textField_lvae7q5n",formMap.get("textField_lvae99fj")); //护理对象经度
  192. hashMap.put("textField_lvae7q5o",formMap.get("textField_lvae99fk")); //护理对象纬度
  193. hashMap.put("textField_lrx0r38x",String.valueOf(nextDay)); //护理日期-文本
  194. hashMap.put("selectField_lr36z6hd","是"); //任务状态
  195. hashMap.put("textField_lo55rupj",formMap.get("textField_lo55rupj")); //护理对象姓名-文本
  196. hashMap.put("textField_lo3pmoi4",map.get("textField_lo3pmoi4")); //护理证书类型
  197. hashMap.put("employeeField_lo3pmoi6",JSON.parse(map.get("employeeField_lo3pmoi6_id").toString())); //护理人员姓名-成员
  198. hashMap.put("textField_lpgi8scj",map.get("textField_lo701pwy")); //计划明细id
  199. hashMap.put("textField_lq9llmhl",formMap.get("textField_lop4v4qx")); //护理对象ID
  200. try {
  201. Thread.sleep(200);
  202. } catch (InterruptedException e) {
  203. log.info("睡眠异常");
  204. }
  205. try {
  206. ydClient.operateData(YDParam.builder()
  207. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  208. .formDataJson(JSON.toJSONString(hashMap))
  209. .build(), YDConf.FORM_OPERATION.create);
  210. } catch (Exception e) {
  211. log.info("异常数据{}",hashMap);
  212. }
  213. }
  214. }
  215. }
  216. });
  217. }
  218. log.info("创建下月护理计划定时任务end",new Date());
  219. }
  220. /**
  221. *每天同步护理状态
  222. */
  223. @Override
  224. public void syncUpdatePlanStatus() {
  225. log.info("每天同步护理状态开始{}",new Date());
  226. syncPlanStatus();
  227. log.info("每天同步护理状态结束{}",new Date());
  228. }
  229. /**
  230. * 不同上报状态 定时任务每天执行
  231. */
  232. @SneakyThrows
  233. public void syncPlanStatus() {
  234. LocalDate currentDate = LocalDate.now();
  235. //获取需要更新的护理任务 护理日期是当天 且状态为未上报
  236. YDParam ydParam = YDParam.builder()
  237. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  238. .searchFieldJson(JSON.toJSONString(UtilMap.map("selectField_lo56u5fn, dateField_lred6eoj","待上报",Arrays.asList(UtilDateTime.parse( currentDate+ " 00:00:59","yyyy-MM-dd HH:mm:ss"),UtilDateTime.parse( currentDate+ " 23:59:59","yyyy-MM-dd HH:mm:ss")))))
  239. .build();
  240. //pagesize设为1获取总数
  241. ydParam.setPageSize(1);
  242. long totalCount = ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getTotalCount();
  243. log.info("totalCount{}",totalCount);
  244. //如果条数不为0 就一直递归
  245. if (totalCount>0){
  246. ydParam.setPageSize(50);
  247. List<Map> dataList = new ArrayList<>();
  248. dataList = (List<Map>) ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getData();
  249. log.info("dataList:{}",dataList.size());
  250. //循环处理修改状态为已上报
  251. dataList.forEach(item -> {
  252. //修改状态为已上报
  253. ydClient.operateData(YDParam.builder()
  254. .formInstanceId(item.get("formInstanceId").toString())
  255. .updateFormDataJson(JSON.toJSONString(UtilMap.map("selectField_lo56u5fn","已上报")))
  256. .build(), YDConf.FORM_OPERATION.update);
  257. });
  258. Thread.sleep(5000);
  259. syncUpdatePlanStatus();
  260. }
  261. }
  262. /**
  263. * 新增护理计划1条 生成本月护理数据
  264. * @param formInstId
  265. */
  266. @Override
  267. public void creatInfo(String formInstId) {
  268. log.info("新增护理计划",new Date());
  269. //根据实例ID 查询护理计划
  270. YDParam ydParam = YDParam.builder()
  271. .formInstId(formInstId)
  272. .build();
  273. Map formData = ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_id).getFormData();
  274. log.info("formData{}",formData);
  275. List<Map> mapList = (List<Map>) formData.get("tableField_lo3pmohx");
  276. LocalDate currentDate = LocalDate.now();
  277. //获取当前日期是本月几号
  278. int dayOfMonth = currentDate.getDayOfMonth();
  279. //获取本月天数
  280. int daysInMonth = currentDate.lengthOfMonth();
  281. for (int i = 0; i <(daysInMonth-dayOfMonth)+1 ; i++) {
  282. //获取当前日期是本月几号
  283. LocalDate currentDay = LocalDate.now();
  284. //获取是周几
  285. String dayOfWeek = currentDay.plusDays(i).getDayOfWeek().getDisplayName(TextStyle.FULL, new Locale("zh", "CN"));
  286. //获取循环每天的日期
  287. LocalDate nextDay = currentDate.plusDays(i);
  288. List<Map> maps = mapList.stream().filter(item -> item.get("selectField_lo3pmohy").equals(dayOfWeek.replace("星期","周"))).collect(Collectors.toList());
  289. for (Map map : maps) {
  290. Map hashMap = new HashMap();
  291. hashMap.put("associationFormField_lo3pmohz",JSON.parse(map.get("associationFormField_lo3pmohz_id").toString())); //护理人员名称
  292. hashMap.put("textField_lo3pmoi0",map.get("textField_lo3pmoi0")); //护理人员所属机构
  293. hashMap.put("textField_lombve2g",map.get("textField_lomchzi3")); //护理人员身份证
  294. hashMap.put("textField_lo3pmoi3",map.get("textField_lo3pmoi3")); //护理人员手机号
  295. hashMap.put("associationFormField_lo3pmohw",JSON.parse(formData.get("associationFormField_lo3pmohw_id").toString())); //护理对象姓名
  296. hashMap.put("textField_lnyhv5tn",formData.get("textField_lnyhv5tn")); //护理对象身份证
  297. hashMap.put("selectField_lnyhv5tp",formData.get("selectField_lnyhv5tp")); //护理对象等级
  298. hashMap.put("textField_lnyhv5tr",formData.get("textField_lnyhv5tr")); //护理对象住址
  299. hashMap.put("selectField_lo3pmohy",dayOfWeek.replace("星期","周")); //护理时间 (星期几)
  300. hashMap.put("dateField_lred6eoj", UtilDateTime.parse(String.valueOf(nextDay)+" "+map.get("selectField_lr1uxpu3"),"yyyy-MM-dd HH:mm")); //护理开始时间。 用当前日期+护理计划的 时分 转成时间戳
  301. hashMap.put("dateField_lred6eok",UtilDateTime.parse(String.valueOf(nextDay)+" "+map.get("selectField_lr1uxpu4"),"yyyy-MM-dd HH:mm")); //护理结束时间。 用当前日期+护理计划的 时分 转成时间戳
  302. hashMap.put("selectField_lqcgsbw2","未执行"); //执行情况
  303. hashMap.put("selectField_lo56u5fn","待上报"); //任务状态
  304. hashMap.put("textField_lvae7q5n",formData.get("textField_lvae99fj")); //护理对象经度
  305. hashMap.put("textField_lvae7q5o",formData.get("textField_lvae99fk")); //护理对象纬度
  306. hashMap.put("textField_lrx0r38x",String.valueOf(nextDay)); //护理日期-文本
  307. hashMap.put("selectField_lr36z6hd","是"); //任务状态
  308. hashMap.put("textField_lo55rupj",formData.get("textField_lo55rupj")); //护理对象姓名-文本
  309. hashMap.put("textField_lo3pmoi4",map.get("textField_lo3pmoi4")); //护理证书类型
  310. hashMap.put("employeeField_lo3pmoi6",map.get("employeeField_lo3pmoi6_id")); //护理人员姓名-成员
  311. hashMap.put("textField_lpgi8scj",map.get("textField_lo701pwy")); //计划明细id
  312. hashMap.put("textField_lq9llmhl",formData.get("textField_lop4v4qx")); //护理对象ID
  313. //通过护理时间 护理对象ID 证数据是否已经存在
  314. YDParam ydParam1 = YDParam.builder()
  315. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  316. .searchFieldJson(JSON.toJSONString(UtilMap.map("dateField_lred6eoj, textField_lnyhv5tn, textField_lombve2g",Arrays.asList(UtilDateTime.parse( nextDay+ " 00:00:01","yyyy-MM-dd HH:mm:ss"),UtilDateTime.parse( currentDate.with(TemporalAdjusters.lastDayOfMonth())+ " 23:59:59","yyyy-MM-dd HH:mm:ss")),formData.get("textField_lnyhv5tn"),map.get("textField_lomchzi3"))))
  317. .build();
  318. List<Map> dataList = (List<Map>) ydClient.queryData(ydParam1, YDConf.FORM_QUERY.retrieve_search_form).getData();
  319. //判断是否存在
  320. if (dataList.size()<1){
  321. try {
  322. ydClient.operateData(YDParam.builder()
  323. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  324. .formDataJson(JSON.toJSONString(hashMap))
  325. .build(), YDConf.FORM_OPERATION.create);
  326. } catch (Exception e) {
  327. log.info("定时任务创建计划失败:{}",e);
  328. }
  329. }
  330. }
  331. }
  332. }
  333. /**
  334. * 新增护理计划下月月数据
  335. * @param formInstId
  336. */
  337. @Override
  338. public void creatNextInfo(String formInstId) {
  339. log.info("新增护理计划下月数据",new Date());
  340. //根据实例ID 查询护理计划
  341. YDParam ydParam = YDParam.builder()
  342. .formInstId(formInstId)
  343. .build();
  344. Map formData = ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_id).getFormData();
  345. List<Map> mapList = (List<Map>) formData.get("tableField_lo3pmohx");
  346. LocalDate currentDate = LocalDate.now();
  347. //获取下月1号的日期
  348. LocalDate firstDayOfNextMonth = currentDate.plusMonths(1).with(TemporalAdjusters.firstDayOfMonth());
  349. //获取下月1号
  350. int dayOfMonth = firstDayOfNextMonth.getDayOfMonth();
  351. //获取下月月天数
  352. int daysInMonth = firstDayOfNextMonth.lengthOfMonth();
  353. for (int i = 0; i <=(daysInMonth-dayOfMonth)+1 ; i++) {
  354. //获取是周几
  355. String dayOfWeek = firstDayOfNextMonth.plusDays(i).getDayOfWeek().getDisplayName(TextStyle.FULL, new Locale("zh", "CN"));
  356. //获取循环每天的日期
  357. LocalDate nextDay = firstDayOfNextMonth.plusDays(i);
  358. List<Map> maps = mapList.stream().filter(item -> item.get("selectField_lo3pmohy").equals(dayOfWeek.replace("星期","周"))).collect(Collectors.toList());
  359. for (Map map : maps) {
  360. Map hashMap = new HashMap();
  361. hashMap.put("associationFormField_lo3pmohz",JSON.parse(map.get("associationFormField_lo3pmohz_id").toString())); //护理人员名称
  362. hashMap.put("textField_lo3pmoi0",map.get("textField_lo3pmoi0")); //护理人员所属机构
  363. hashMap.put("textField_lombve2g",map.get("textField_lomchzi3")); //护理人员身份证
  364. hashMap.put("textField_lo3pmoi3",map.get("textField_lo3pmoi3")); //护理人员手机号
  365. hashMap.put("associationFormField_lo3pmohw",JSON.parse(formData.get("associationFormField_lo3pmohw_id").toString())); //护理对象姓名
  366. hashMap.put("textField_lnyhv5tn",formData.get("textField_lnyhv5tn")); //护理对象身份证
  367. hashMap.put("selectField_lnyhv5tp",formData.get("selectField_lnyhv5tp")); //护理对象等级
  368. hashMap.put("textField_lnyhv5tr",formData.get("textField_lnyhv5tr")); //护理对象住址
  369. hashMap.put("selectField_lo3pmohy",dayOfWeek.replace("星期","周")); //护理时间 (星期几)
  370. hashMap.put("dateField_lred6eoj", UtilDateTime.parse(String.valueOf(nextDay)+" "+map.get("selectField_lr1uxpu3"),"yyyy-MM-dd HH:mm")); //护理开始时间。 用当前日期+护理计划的 时分 转成时间戳
  371. hashMap.put("dateField_lred6eok",UtilDateTime.parse(String.valueOf(nextDay)+" "+map.get("selectField_lr1uxpu4"),"yyyy-MM-dd HH:mm")); //护理结束时间。 用当前日期+护理计划的 时分 转成时间戳
  372. hashMap.put("selectField_lqcgsbw2","未执行"); //执行情况
  373. hashMap.put("selectField_lo56u5fn","待上报"); //任务状态
  374. hashMap.put("textField_lvae7q5n",formData.get("textField_lvae99fj")); //护理对象经度
  375. hashMap.put("textField_lvae7q5o",formData.get("textField_lvae99fk")); //护理对象纬度
  376. hashMap.put("textField_lrx0r38x",String.valueOf(nextDay)); //护理日期-文本
  377. hashMap.put("selectField_lr36z6hd","是"); //任务状态
  378. hashMap.put("textField_lo55rupj",formData.get("textField_lo55rupj")); //护理对象姓名-文本
  379. hashMap.put("textField_lo3pmoi4",map.get("textField_lo3pmoi4")); //护理证书类型
  380. hashMap.put("employeeField_lo3pmoi6",map.get("employeeField_lo3pmoi6_id")); //护理人员姓名-成员
  381. hashMap.put("textField_lpgi8scj",map.get("textField_lo701pwy")); //计划明细id
  382. hashMap.put("textField_lq9llmhl",formData.get("textField_lop4v4qx")); //护理对象ID
  383. //通过护理时间 护理对象ID 证数据是否已经存在
  384. YDParam ydParam1 = YDParam.builder()
  385. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  386. .searchFieldJson(JSON.toJSONString(UtilMap.map("dateField_lred6eoj, textField_lnyhv5tn, textField_lombve2g",Arrays.asList(UtilDateTime.parse( nextDay+ " 00:00:01","yyyy-MM-dd HH:mm:ss"),UtilDateTime.parse( currentDate.with(TemporalAdjusters.lastDayOfMonth())+ " 23:59:59","yyyy-MM-dd HH:mm:ss")),formData.get("textField_lnyhv5tn"),map.get("textField_lomchzi3"))))
  387. .build();
  388. List<Map> dataList = (List<Map>) ydClient.queryData(ydParam1, YDConf.FORM_QUERY.retrieve_search_form).getData();
  389. //判断是否存在
  390. if (dataList.size()<1){
  391. try {
  392. ydClient.operateData(YDParam.builder()
  393. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  394. .formDataJson(JSON.toJSONString(hashMap))
  395. .build(), YDConf.FORM_OPERATION.create);
  396. } catch (Exception e) {
  397. log.info("定时任务创建计划失败:{}",e);
  398. }
  399. }
  400. }
  401. }
  402. }
  403. /**
  404. * 编辑护理计划
  405. * @param formInstId
  406. */
  407. @SneakyThrows
  408. @Override
  409. @Async
  410. public void updateInfo(String formInstId) {
  411. Thread.sleep(2000);
  412. //根据实例ID 查询护理计划
  413. YDParam ydParam = YDParam.builder()
  414. .formInstId(formInstId)
  415. .build();
  416. Map formData = ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_id).getFormData();
  417. List<Map> mapList = (List<Map>) formData.get("tableField_lo3pmohx");
  418. LocalDate currentDate = LocalDate.now();
  419. //获取下月1号的日期
  420. LocalDate firstDayOfNextMonth = currentDate.plusMonths(1).with(TemporalAdjusters.firstDayOfMonth());
  421. //删除当前时间节点以后得数据
  422. //获取需要更新的护理任务 状态为待上报 护理对象身份证 护理日期是当天
  423. YDParam ydParamDelete = YDParam.builder()
  424. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  425. .searchFieldJson(JSON.toJSONString(UtilMap.map("selectField_lo56u5fn, textField_lnyhv5tn, dateField_lred6eoj","待上报",formData.get("textField_lnyhv5tn"),Arrays.asList(UtilDateTime.parse( currentDate+ " 00:00:01","yyyy-MM-dd HH:mm:ss"),UtilDateTime.parse( firstDayOfNextMonth.with(TemporalAdjusters.lastDayOfMonth())+ " 23:59:59","yyyy-MM-dd HH:mm:ss")))))
  426. .build();
  427. List<Map> queryAllFormData = ydService.queryAllFormData(ydParamDelete);
  428. queryAllFormData.forEach(item -> {
  429. //删除
  430. ydClient.operateData(YDParam.builder()
  431. .formInstanceId(item.get("formInstanceId").toString())
  432. .build(), YDConf.FORM_OPERATION.delete);
  433. });
  434. //获取当前日期是本月几号
  435. int dayOfMonth = currentDate.getDayOfMonth();
  436. //获取本月天数
  437. int daysInMonth = currentDate.lengthOfMonth();
  438. //重新创建计划任务
  439. for (int i = 0; i <(daysInMonth-dayOfMonth)+1 ; i++) {
  440. //获取是周几
  441. String dayOfWeek = currentDate.plusDays(i).getDayOfWeek().getDisplayName(TextStyle.FULL, new Locale("zh", "CN"));
  442. //获取循环每天的日期
  443. LocalDate nextDay = currentDate.plusDays(i);
  444. List<Map> maps = mapList.stream().filter(item -> item.get("selectField_lo3pmohy").equals(dayOfWeek.replace("星期","周"))).collect(Collectors.toList());
  445. for (Map map : maps) {
  446. Map hashMap = new HashMap();
  447. hashMap.put("associationFormField_lo3pmohz",JSON.parse(map.get("associationFormField_lo3pmohz_id").toString())); //护理人员名称
  448. hashMap.put("textField_lo3pmoi0",map.get("textField_lo3pmoi0")); //护理人员所属机构
  449. hashMap.put("textField_lombve2g",map.get("textField_lomchzi3")); //护理人员身份证
  450. hashMap.put("textField_lo3pmoi3",map.get("textField_lo3pmoi3")); //护理人员手机号
  451. hashMap.put("associationFormField_lo3pmohw",JSON.parse(formData.get("associationFormField_lo3pmohw_id").toString())); //护理对象姓名
  452. hashMap.put("textField_lnyhv5tn",formData.get("textField_lnyhv5tn")); //护理对象身份证
  453. hashMap.put("selectField_lnyhv5tp",formData.get("selectField_lnyhv5tp")); //护理对象等级
  454. hashMap.put("textField_lnyhv5tr",formData.get("textField_lnyhv5tr")); //护理对象住址
  455. hashMap.put("selectField_lo3pmohy",dayOfWeek.replace("星期","周")); //护理时间 (星期几)
  456. hashMap.put("dateField_lred6eoj", UtilDateTime.parse(String.valueOf(nextDay)+" "+map.get("selectField_lr1uxpu3"),"yyyy-MM-dd HH:mm")); //护理开始时间。 用当前日期+护理计划的 时分 转成时间戳
  457. hashMap.put("dateField_lred6eok",UtilDateTime.parse(String.valueOf(nextDay)+" "+map.get("selectField_lr1uxpu4"),"yyyy-MM-dd HH:mm")); //护理结束时间。 用当前日期+护理计划的 时分 转成时间戳
  458. hashMap.put("selectField_lqcgsbw2","未执行"); //执行情况
  459. hashMap.put("selectField_lo56u5fn","待上报"); //任务状态
  460. hashMap.put("textField_lvae7q5n",formData.get("textField_lvae99fj")); //护理对象经度
  461. hashMap.put("textField_lvae7q5o",formData.get("textField_lvae99fk")); //护理对象纬度
  462. hashMap.put("textField_lrx0r38x",String.valueOf(nextDay)); //护理日期-文本
  463. hashMap.put("selectField_lr36z6hd","是"); //任务状态
  464. hashMap.put("textField_lo55rupj",formData.get("textField_lo55rupj")); //护理对象姓名-文本
  465. hashMap.put("textField_lo3pmoi4",map.get("textField_lo3pmoi4")); //护理证书类型
  466. hashMap.put("employeeField_lo3pmoi6",JSON.parse(map.get("employeeField_lo3pmoi6_id").toString())); //护理人员姓名-成员
  467. hashMap.put("textField_lpgi8scj",map.get("textField_lo701pwy")); //计划明细id
  468. hashMap.put("textField_lq9llmhl",formData.get("textField_lop4v4qx")); //护理对象ID
  469. //通过护理时间 护理对象CID 护理人员CID验证数据是否已经存在
  470. YDParam ydParam1 = YDParam.builder()
  471. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  472. .searchFieldJson(JSON.toJSONString(UtilMap.map("dateField_lred6eoj, textField_lnyhv5tn, textField_lombve2g",Arrays.asList(UtilDateTime.parse( nextDay+ " 00:00:01","yyyy-MM-dd HH:mm:ss"),UtilDateTime.parse( currentDate.with(TemporalAdjusters.lastDayOfMonth())+ " 23:59:59","yyyy-MM-dd HH:mm:ss")),formData.get("textField_lnyhv5tn"),map.get("textField_lomchzi3"))))
  473. .build();
  474. List<Map> dataList = (List<Map>) ydClient.queryData(ydParam1, YDConf.FORM_QUERY.retrieve_search_form).getData();
  475. if (dataList.size()<1){
  476. ydClient.operateData(YDParam.builder()
  477. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  478. .formDataJson(JSON.toJSONString(hashMap))
  479. .build(), YDConf.FORM_OPERATION.create);
  480. }
  481. }
  482. }
  483. }
  484. /**
  485. * 删除护理任务
  486. * @param cId 护理对象身份证
  487. */
  488. @Override
  489. public void deletePlan(String cId) {
  490. LocalDate currentDate = LocalDate.now();
  491. //获取下月1号的日期
  492. LocalDate firstDayOfNextMonth = currentDate.plusMonths(1).with(TemporalAdjusters.firstDayOfMonth());
  493. //获取需要删除护理任务 执行状态为未执行 护理对象身份证 护理日期是当天以后
  494. YDParam ydParamDelete = YDParam.builder()
  495. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  496. .searchFieldJson(JSON.toJSONString(UtilMap.map("selectField_lqcgsbw2, textField_lnyhv5tn, dateField_lred6eoj","未执行",cId,Arrays.asList(UtilDateTime.parse( currentDate+ " 00:00:01","yyyy-MM-dd HH:mm:ss"),UtilDateTime.parse( firstDayOfNextMonth.with(TemporalAdjusters.lastDayOfMonth())+ " 23:59:59","yyyy-MM-dd HH:mm:ss")))))
  497. .build();
  498. List<Map> mapList = ydService.queryAllFormData(ydParamDelete);
  499. //删除当前时间节点以后得数据
  500. mapList.forEach(item -> {
  501. //删除
  502. ydClient.operateData(YDParam.builder()
  503. .formInstanceId(item.get("formInstanceId").toString())
  504. .build(), YDConf.FORM_OPERATION.delete);
  505. });
  506. }
  507. }