YBJServiceImpl.java 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  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. log.info("totalCount:----{}----",totalCount);
  47. List<Map> dataList = new ArrayList<>();
  48. for (int page = 1; page <= Math.ceil(totalCount / pageSize); page++) {
  49. ydParam.setCurrentPage(page);
  50. //创建护理计划 1次获取50条
  51. dataList = (List<Map>) ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getData();
  52. log.info("dataList:{}-----page:"+page+"---",dataList.size());
  53. LocalDate currentDate = LocalDate.now();
  54. //获取当前日期是本月几号
  55. int dayOfMonth = currentDate.getDayOfMonth();
  56. //获取本月天数
  57. int daysInMonth = currentDate.lengthOfMonth();
  58. dataList.forEach(dataItem -> {
  59. Map formMap = (Map) dataItem.get("formData");
  60. List<Map> mapList = (List<Map>) formMap.get("tableField_lo3pmohx");
  61. for (int i =0 ; i <=(daysInMonth-dayOfMonth) ; i++) {
  62. //获取当前日期是本月几号
  63. LocalDate currentDay = LocalDate.now();
  64. //获取是周几
  65. String dayOfWeek = currentDay.plusDays(i).getDayOfWeek().getDisplayName(TextStyle.FULL, new Locale("zh", "CN"));
  66. //获取循环每天的日期
  67. LocalDate nextDay = currentDate.plusDays(i);
  68. List<Map> maps = mapList.stream().filter(items -> items.get("selectField_lo3pmohy").equals(dayOfWeek.replace("星期","周"))).collect(Collectors.toList());
  69. for (Map map : maps) {
  70. Map hashMap = new HashMap();
  71. hashMap.put("associationFormField_lo3pmohz",JSON.parse(map.get("associationFormField_lo3pmohz_id").toString())); //护理人员名称
  72. hashMap.put("textField_lo3pmoi0",map.get("textField_lo3pmoi0")); //护理人员所属机构
  73. hashMap.put("textField_lombve2g",map.get("textField_lomchzi3")); //护理人员身份证
  74. hashMap.put("textField_lo3pmoi3",map.get("textField_lo3pmoi3")); //护理人员手机号
  75. hashMap.put("associationFormField_lo3pmohw",JSON.parse(formMap.get("associationFormField_lo3pmohw_id").toString())); //护理对象姓名
  76. hashMap.put("textField_lnyhv5tn",formMap.get("textField_lnyhv5tn")); //护理对象身份证
  77. hashMap.put("selectField_lnyhv5tp",formMap.get("selectField_lnyhv5tp")); //护理对象等级
  78. hashMap.put("textField_lnyhv5tr",formMap.get("textField_lnyhv5tr")); //护理对象住址
  79. hashMap.put("selectField_lo3pmohy",dayOfWeek.replace("星期","周")); //护理时间 (星期几)
  80. hashMap.put("dateField_lred6eoj", UtilDateTime.parse(String.valueOf(nextDay)+" "+map.get("selectField_lr1uxpu3"),"yyyy-MM-dd HH:mm")); //护理开始时间。 用当前日期+护理计划的 时分 转成时间戳
  81. hashMap.put("dateField_lred6eok", UtilDateTime.parse(String.valueOf(nextDay)+" "+map.get("selectField_lr1uxpu4"),"yyyy-MM-dd HH:mm")); //护理结束时间。 用当前日期+护理计划的 时分 转成时间戳
  82. hashMap.put("selectField_lqcgsbw2","未执行"); //执行情况
  83. hashMap.put("selectField_lo56u5fn","待上报"); //任务状态
  84. hashMap.put("textField_lvae7q5n",formMap.get("textField_lvae99fj")); //护理对象经度
  85. hashMap.put("textField_lvae7q5o",formMap.get("textField_lvae99fk")); //护理对象纬度
  86. hashMap.put("textField_lrx0r38x",String.valueOf(nextDay)); //护理日期-文本
  87. hashMap.put("selectField_lr36z6hd","是"); //任务状态
  88. hashMap.put("textField_lo55rupj",formMap.get("textField_lo55rupj")); //护理对象姓名-文本
  89. hashMap.put("textField_lo3pmoi4",map.get("textField_lo3pmoi4")); //护理证书类型
  90. hashMap.put("employeeField_lo3pmoi6",JSON.parse(map.get("employeeField_lo3pmoi6_id").toString())); //护理人员姓名-成员
  91. hashMap.put("textField_lpgi8scj",map.get("textField_lo701pwy")); //计划明细id
  92. hashMap.put("textField_lq9llmhl",formMap.get("textField_lop4v4qx")); //护理对象ID
  93. if (formMap.get("departmentSelectField_lxztlnnx_id")!=null){
  94. hashMap.put("departmentSelectField_lxzto1e1",String.valueOf(formMap.get("departmentSelectField_lxztlnnx_id"))); //部门
  95. }
  96. try {
  97. Thread.sleep(200);
  98. } catch (InterruptedException e) {
  99. throw new RuntimeException(e);
  100. }
  101. try {
  102. ydClient.operateData(YDParam.builder()
  103. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  104. .searchCondition(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+ " 23:59:59","yyyy-MM-dd HH:mm:ss")),formMap.get("textField_lnyhv5tn"),map.get("textField_lomchzi3"))))
  105. .formDataJson(JSON.toJSONString(hashMap))
  106. .build(), YDConf.FORM_OPERATION.upsert);
  107. } catch (Exception e) {
  108. log.info("异常数据{}",hashMap);
  109. }
  110. }
  111. }
  112. });
  113. }
  114. log.info("创建护理计划定时任务end",new Date());
  115. }
  116. /**
  117. *定时任务每月25号创建下月的数据
  118. */
  119. @Override
  120. @SneakyThrows
  121. public void syncCreatePlan() {
  122. YDParam ydParam = new YDParam();
  123. log.info("创建下月护理计划定时任务Start",new Date());
  124. ydParam = YDParam.builder()
  125. .formUuid("FORM-RK966E7105DFD27FA7EQHAOH9IFS2RN6MP3OL2") //获取护理计划
  126. .searchFieldJson(JSON.toJSONString(UtilMap.map("selectField_lo2b6bvf","正常")))//护理对象暂停和正常、月度计划创建只查询正常的护理计划
  127. .build();
  128. //pagesize设为1获取总数
  129. ydParam.setPageSize(1);
  130. long totalCount = ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getTotalCount();
  131. float pageSize = 50;
  132. ydParam.setCurrentPage(1);
  133. ydParam.setPageSize((int) pageSize);
  134. List<Map> dataList = new ArrayList<>();
  135. LocalDate currentDate = LocalDate.now();
  136. //获取下月1号的日期
  137. LocalDate firstDayOfNextMonth = currentDate.plusMonths(1).with(TemporalAdjusters.firstDayOfMonth());
  138. //获取日期是几号
  139. int dayOfMonth = firstDayOfNextMonth .getDayOfMonth();
  140. //获取月天数
  141. int daysInMonth = firstDayOfNextMonth.lengthOfMonth();
  142. for (int page = 1; page <= Math.ceil(totalCount / pageSize); page++) {
  143. ydParam.setCurrentPage(page);
  144. //创建护理计划 1次获取50条
  145. dataList = (List<Map>) ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getData();
  146. log.info("dataList:{}-----page:"+page+"---",dataList.size());
  147. dataList.forEach(dataItem -> {
  148. Map formMap = (Map) dataItem.get("formData");
  149. List<Map> mapList = (List<Map>) formMap.get("tableField_lo3pmohx");
  150. for (int i =0 ; i <=(daysInMonth-dayOfMonth) ; i++) {
  151. //获取是周几
  152. String dayOfWeek = firstDayOfNextMonth.plusDays(i).getDayOfWeek().getDisplayName(TextStyle.FULL, new Locale("zh", "CN"));
  153. //获取循环每天的日期
  154. LocalDate nextDay = firstDayOfNextMonth.plusDays(i);
  155. List<Map> maps = mapList.stream().filter(items -> items.get("selectField_lo3pmohy").equals(dayOfWeek.replace("星期","周"))).collect(Collectors.toList());
  156. for (Map map : maps) {
  157. Map hashMap = new HashMap();
  158. hashMap.put("associationFormField_lo3pmohz",JSON.parse(map.get("associationFormField_lo3pmohz_id").toString())); //护理人员名称
  159. hashMap.put("textField_lo3pmoi0",map.get("textField_lo3pmoi0")); //护理人员所属机构
  160. hashMap.put("textField_lombve2g",map.get("textField_lomchzi3")); //护理人员身份证
  161. hashMap.put("textField_lo3pmoi3",map.get("textField_lo3pmoi3")); //护理人员手机号
  162. hashMap.put("associationFormField_lo3pmohw",JSON.parse(formMap.get("associationFormField_lo3pmohw_id").toString())); //护理对象姓名
  163. hashMap.put("textField_lnyhv5tn",formMap.get("textField_lnyhv5tn")); //护理对象身份证
  164. hashMap.put("selectField_lnyhv5tp",formMap.get("selectField_lnyhv5tp")); //护理对象等级
  165. hashMap.put("textField_lnyhv5tr",formMap.get("textField_lnyhv5tr")); //护理对象住址
  166. hashMap.put("selectField_lo3pmohy",dayOfWeek.replace("星期","周")); //护理时间 (星期几)
  167. hashMap.put("dateField_lred6eoj", UtilDateTime.parse(String.valueOf(nextDay)+" "+map.get("selectField_lr1uxpu3"),"yyyy-MM-dd HH:mm")); //护理开始时间。 用当前日期+护理计划的 时分 转成时间戳
  168. hashMap.put("dateField_lred6eok", UtilDateTime.parse(String.valueOf(nextDay)+" "+map.get("selectField_lr1uxpu4"),"yyyy-MM-dd HH:mm")); //护理结束时间。 用当前日期+护理计划的 时分 转成时间戳
  169. hashMap.put("selectField_lqcgsbw2","未执行"); //执行情况
  170. hashMap.put("selectField_lo56u5fn","待上报"); //任务状态
  171. hashMap.put("textField_lvae7q5n",formMap.get("textField_lvae99fj")); //护理对象经度
  172. hashMap.put("textField_lvae7q5o",formMap.get("textField_lvae99fk")); //护理对象纬度
  173. hashMap.put("textField_lrx0r38x",String.valueOf(nextDay)); //护理日期-文本
  174. hashMap.put("selectField_lr36z6hd","是"); //任务状态
  175. hashMap.put("textField_lo55rupj",formMap.get("textField_lo55rupj")); //护理对象姓名-文本
  176. hashMap.put("textField_lo3pmoi4",map.get("textField_lo3pmoi4")); //护理证书类型
  177. hashMap.put("employeeField_lo3pmoi6",JSON.parse(map.get("employeeField_lo3pmoi6_id").toString())); //护理人员姓名-成员
  178. hashMap.put("textField_lpgi8scj",map.get("textField_lo701pwy")); //计划明细id
  179. hashMap.put("textField_lq9llmhl",formMap.get("textField_lop4v4qx")); //护理对象ID
  180. if (formMap.get("departmentSelectField_lxztlnnx_id")!=null){
  181. hashMap.put("departmentSelectField_lxzto1e1",String.valueOf(formMap.get("departmentSelectField_lxztlnnx_id"))); //部门
  182. }
  183. try {
  184. Thread.sleep(200);
  185. } catch (InterruptedException e) {
  186. log.info("睡眠异常");
  187. }
  188. try {
  189. ydClient.operateData(YDParam.builder()
  190. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  191. // .searchCondition(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+ " 23:59:59","yyyy-MM-dd HH:mm:ss")),formMap.get("textField_lnyhv5tn"),map.get("textField_lomchzi3"))))
  192. .formDataJson(JSON.toJSONString(hashMap))
  193. .build(), YDConf.FORM_OPERATION.create);
  194. } catch (Exception e) {
  195. log.info("异常数据{}",hashMap);
  196. }
  197. }
  198. }
  199. });
  200. }
  201. log.info("创建下月护理计划定时任务end",new Date());
  202. }
  203. /**
  204. *每天同步护理状态
  205. */
  206. @Override
  207. public void syncUpdatePlanStatus() {
  208. log.info("每天同步护理状态开始{}",new Date());
  209. syncPlanStatus();
  210. log.info("每天同步护理状态结束{}",new Date());
  211. }
  212. /**
  213. * 不同上报状态 定时任务每天执行
  214. */
  215. @SneakyThrows
  216. public void syncPlanStatus() {
  217. LocalDate currentDate = LocalDate.now();
  218. //获取需要更新的护理任务 护理日期是当天 且状态为未上报
  219. YDParam ydParam = YDParam.builder()
  220. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  221. .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")))))
  222. .build();
  223. //pagesize设为1获取总数
  224. ydParam.setPageSize(1);
  225. long totalCount = ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getTotalCount();
  226. log.info("totalCount{}",totalCount);
  227. //如果条数不为0 就一直递归
  228. if (totalCount>0){
  229. ydParam.setPageSize(50);
  230. List<Map> dataList = new ArrayList<>();
  231. dataList = (List<Map>) ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getData();
  232. log.info("dataList:{}",dataList.size());
  233. //循环处理修改状态为已上报
  234. dataList.forEach(item -> {
  235. //修改状态为已上报
  236. try {
  237. ydClient.operateData(YDParam.builder()
  238. .formInstanceId(item.get("formInstanceId").toString())
  239. .updateFormDataJson(JSON.toJSONString(UtilMap.map("selectField_lo56u5fn","已上报")))
  240. .build(), YDConf.FORM_OPERATION.update);
  241. } catch (Exception e) {
  242. log.info("异常流程ID为:{}",item.get("formInstanceId").toString());
  243. throw new RuntimeException(e);
  244. }
  245. });
  246. Thread.sleep(5000);
  247. syncUpdatePlanStatus();
  248. }
  249. }
  250. /**
  251. * 新增护理计划1条 生成本月护理数据
  252. * @param formInstId
  253. */
  254. @Override
  255. public void creatInfo(String formInstId) {
  256. log.info("新增护理计划",new Date());
  257. //根据实例ID 查询护理计划
  258. YDParam ydParam = YDParam.builder()
  259. .formInstId(formInstId)
  260. .build();
  261. Map formData = ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_id).getFormData();
  262. log.info("formData{}",formData);
  263. List<Map> mapList = (List<Map>) formData.get("tableField_lo3pmohx");
  264. LocalDate currentDate = LocalDate.now();
  265. //获取当前日期是本月几号
  266. int dayOfMonth = currentDate.getDayOfMonth();
  267. //获取本月天数
  268. int daysInMonth = currentDate.lengthOfMonth();
  269. for (int i = 0; i <=daysInMonth-dayOfMonth ; i++) {
  270. //获取当前日期是本月几号
  271. LocalDate currentDay = LocalDate.now();
  272. //获取是周几
  273. String dayOfWeek = currentDay.plusDays(i).getDayOfWeek().getDisplayName(TextStyle.FULL, new Locale("zh", "CN"));
  274. //获取循环每天的日期
  275. LocalDate nextDay = currentDate.plusDays(i);
  276. List<Map> maps = mapList.stream().filter(item -> item.get("selectField_lo3pmohy").equals(dayOfWeek.replace("星期","周"))).collect(Collectors.toList());
  277. for (Map map : maps) {
  278. //通过护理时间 护理对象ID 证数据是否已经存在
  279. YDParam ydParam1 = YDParam.builder()
  280. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  281. .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+ " 23:59:59","yyyy-MM-dd HH:mm:ss")),formData.get("textField_lnyhv5tn"),map.get("textField_lomchzi3"))))
  282. .build();
  283. List<Map> dataList = (List<Map>) ydClient.queryData(ydParam1, YDConf.FORM_QUERY.retrieve_search_form).getData();
  284. //如果已存在数据 则不新增
  285. if (1>dataList.size()){
  286. Map hashMap = new HashMap();
  287. hashMap.put("associationFormField_lo3pmohz",JSON.parse(map.get("associationFormField_lo3pmohz_id").toString())); //护理人员名称
  288. hashMap.put("textField_lo3pmoi0",map.get("textField_lo3pmoi0")); //护理人员所属机构
  289. hashMap.put("textField_lombve2g",map.get("textField_lomchzi3")); //护理人员身份证
  290. hashMap.put("textField_lo3pmoi3",map.get("textField_lo3pmoi3")); //护理人员手机号
  291. hashMap.put("associationFormField_lo3pmohw",JSON.parse(formData.get("associationFormField_lo3pmohw_id").toString())); //护理对象姓名
  292. hashMap.put("textField_lnyhv5tn",formData.get("textField_lnyhv5tn")); //护理对象身份证
  293. hashMap.put("selectField_lnyhv5tp",formData.get("selectField_lnyhv5tp")); //护理对象等级
  294. hashMap.put("textField_lnyhv5tr",formData.get("textField_lnyhv5tr")); //护理对象住址
  295. hashMap.put("selectField_lo3pmohy",dayOfWeek.replace("星期","周")); //护理时间 (星期几)
  296. hashMap.put("dateField_lred6eoj", UtilDateTime.parse(String.valueOf(nextDay)+" "+map.get("selectField_lr1uxpu3"),"yyyy-MM-dd HH:mm")); //护理开始时间。 用当前日期+护理计划的 时分 转成时间戳
  297. hashMap.put("dateField_lred6eok",UtilDateTime.parse(String.valueOf(nextDay)+" "+map.get("selectField_lr1uxpu4"),"yyyy-MM-dd HH:mm")); //护理结束时间。 用当前日期+护理计划的 时分 转成时间戳
  298. hashMap.put("selectField_lqcgsbw2","未执行"); //执行情况
  299. hashMap.put("selectField_lo56u5fn","待上报"); //任务状态
  300. hashMap.put("textField_lvae7q5n",formData.get("textField_lvae99fj")); //护理对象经度
  301. hashMap.put("textField_lvae7q5o",formData.get("textField_lvae99fk")); //护理对象纬度
  302. hashMap.put("textField_lrx0r38x",String.valueOf(nextDay)); //护理日期-文本
  303. hashMap.put("selectField_lr36z6hd","是"); //任务状态
  304. hashMap.put("textField_lo55rupj",formData.get("textField_lo55rupj")); //护理对象姓名-文本
  305. hashMap.put("textField_lo3pmoi4",map.get("textField_lo3pmoi4")); //护理证书类型
  306. hashMap.put("employeeField_lo3pmoi6",map.get("employeeField_lo3pmoi6_id")); //护理人员姓名-成员
  307. hashMap.put("textField_lpgi8scj",map.get("textField_lo701pwy")); //计划明细id
  308. hashMap.put("textField_lq9llmhl",formData.get("textField_lop4v4qx")); //护理对象ID
  309. if (formData.get("departmentSelectField_lxztlnnx_id")!=null){
  310. hashMap.put("departmentSelectField_lxzto1e1",String.valueOf(formData.get("departmentSelectField_lxztlnnx_id"))); //部门
  311. }
  312. try {
  313. ydClient.operateData(YDParam.builder()
  314. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  315. .formDataJson(JSON.toJSONString(hashMap))
  316. .build(), YDConf.FORM_OPERATION.create);
  317. } catch (Exception e) {
  318. log.info("定时任务创建计划失败:{}",e);
  319. }
  320. }
  321. }
  322. }
  323. }
  324. /**
  325. * 新增护理计划下月月数据
  326. * @param formInstId
  327. */
  328. @Override
  329. public void creatNextInfo(String formInstId) {
  330. log.info("新增护理计划下月数据",new Date());
  331. //根据实例ID 查询护理计划
  332. YDParam ydParam = YDParam.builder()
  333. .formInstId(formInstId)
  334. .build();
  335. Map formData = ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_id).getFormData();
  336. List<Map> mapList = (List<Map>) formData.get("tableField_lo3pmohx");
  337. LocalDate currentDate = LocalDate.now();
  338. //获取下月1号的日期
  339. LocalDate firstDayOfNextMonth = currentDate.plusMonths(1).with(TemporalAdjusters.firstDayOfMonth());
  340. //获取下月1号
  341. int dayOfMonth = firstDayOfNextMonth.getDayOfMonth();
  342. //获取下月月天数
  343. int daysInMonth = firstDayOfNextMonth.lengthOfMonth();
  344. for (int i = 0; i <=daysInMonth-dayOfMonth ; i++) {
  345. //获取是周几
  346. String dayOfWeek = firstDayOfNextMonth.plusDays(i).getDayOfWeek().getDisplayName(TextStyle.FULL, new Locale("zh", "CN"));
  347. //获取循环每天的日期
  348. LocalDate nextDay = firstDayOfNextMonth.plusDays(i);
  349. List<Map> maps = mapList.stream().filter(item -> item.get("selectField_lo3pmohy").equals(dayOfWeek.replace("星期","周"))).collect(Collectors.toList());
  350. for (Map map : maps) {
  351. Map hashMap = new HashMap();
  352. hashMap.put("associationFormField_lo3pmohz",JSON.parse(map.get("associationFormField_lo3pmohz_id").toString())); //护理人员名称
  353. hashMap.put("textField_lo3pmoi0",map.get("textField_lo3pmoi0")); //护理人员所属机构
  354. hashMap.put("textField_lombve2g",map.get("textField_lomchzi3")); //护理人员身份证
  355. hashMap.put("textField_lo3pmoi3",map.get("textField_lo3pmoi3")); //护理人员手机号
  356. hashMap.put("associationFormField_lo3pmohw",JSON.parse(formData.get("associationFormField_lo3pmohw_id").toString())); //护理对象姓名
  357. hashMap.put("textField_lnyhv5tn",formData.get("textField_lnyhv5tn")); //护理对象身份证
  358. hashMap.put("selectField_lnyhv5tp",formData.get("selectField_lnyhv5tp")); //护理对象等级
  359. hashMap.put("textField_lnyhv5tr",formData.get("textField_lnyhv5tr")); //护理对象住址
  360. hashMap.put("selectField_lo3pmohy",dayOfWeek.replace("星期","周")); //护理时间 (星期几)
  361. hashMap.put("dateField_lred6eoj", UtilDateTime.parse(String.valueOf(nextDay)+" "+map.get("selectField_lr1uxpu3"),"yyyy-MM-dd HH:mm")); //护理开始时间。 用当前日期+护理计划的 时分 转成时间戳
  362. hashMap.put("dateField_lred6eok",UtilDateTime.parse(String.valueOf(nextDay)+" "+map.get("selectField_lr1uxpu4"),"yyyy-MM-dd HH:mm")); //护理结束时间。 用当前日期+护理计划的 时分 转成时间戳
  363. hashMap.put("selectField_lqcgsbw2","未执行"); //执行情况
  364. hashMap.put("selectField_lo56u5fn","待上报"); //任务状态
  365. hashMap.put("textField_lvae7q5n",formData.get("textField_lvae99fj")); //护理对象经度
  366. hashMap.put("textField_lvae7q5o",formData.get("textField_lvae99fk")); //护理对象纬度
  367. hashMap.put("textField_lrx0r38x",String.valueOf(nextDay)); //护理日期-文本
  368. hashMap.put("selectField_lr36z6hd","是"); //任务状态
  369. hashMap.put("textField_lo55rupj",formData.get("textField_lo55rupj")); //护理对象姓名-文本
  370. hashMap.put("textField_lo3pmoi4",map.get("textField_lo3pmoi4")); //护理证书类型
  371. hashMap.put("employeeField_lo3pmoi6",map.get("employeeField_lo3pmoi6_id")); //护理人员姓名-成员
  372. hashMap.put("textField_lpgi8scj",map.get("textField_lo701pwy")); //计划明细id
  373. hashMap.put("textField_lq9llmhl",formData.get("textField_lop4v4qx")); //护理对象ID
  374. if (formData.get("departmentSelectField_lxztlnnx_id")!=null){
  375. hashMap.put("departmentSelectField_lxzto1e1",String.valueOf(formData.get("departmentSelectField_lxztlnnx_id"))); //部门
  376. }
  377. try {
  378. ydClient.operateData(YDParam.builder()
  379. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  380. .formDataJson(JSON.toJSONString(hashMap))
  381. .build(), YDConf.FORM_OPERATION.create);
  382. } catch (Exception e) {
  383. log.info("定时任务创建计划失败:{}",e);
  384. }
  385. }
  386. }
  387. }
  388. /**
  389. * 编辑功能只做删除操作
  390. * @param formInstId
  391. */
  392. @SneakyThrows
  393. @Override
  394. @Async
  395. public void updateInfo(String formInstId) {
  396. //根据实例ID 查询护理计划
  397. YDParam ydParam = YDParam.builder()
  398. .formInstId(formInstId)
  399. .build();
  400. Map formData = ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_id).getFormData();
  401. LocalDate currentDate = LocalDate.now();
  402. //获取下月1号的日期
  403. LocalDate firstDayOfNextMonth = currentDate.plusMonths(1).with(TemporalAdjusters.firstDayOfMonth());
  404. //删除当前时间节点以后得数据
  405. //获取需要更新的护理任务 状态为待上报 护理对象身份证 护理日期是当天
  406. YDParam ydParamDelete = YDParam.builder()
  407. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  408. .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")))))
  409. .build();
  410. List<Map> queryAllFormData = ydService.queryAllFormData(ydParamDelete);
  411. queryAllFormData.forEach(item -> {
  412. //删除
  413. ydClient.operateData(YDParam.builder()
  414. .formInstanceId(item.get("formInstanceId").toString())
  415. .build(), YDConf.FORM_OPERATION.delete);
  416. });
  417. }
  418. /**
  419. * 删除护理任务
  420. * @param cId 护理对象身份证
  421. */
  422. @Override
  423. public void deletePlan(String cId) {
  424. LocalDate currentDate = LocalDate.now();
  425. //获取下月1号的日期
  426. LocalDate firstDayOfNextMonth = currentDate.plusMonths(1).with(TemporalAdjusters.firstDayOfMonth());
  427. //获取需要删除护理任务 执行状态为未执行 护理对象身份证 护理日期是当天以后
  428. YDParam ydParamDelete = YDParam.builder()
  429. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  430. .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")))))
  431. .build();
  432. List<Map> mapList = ydService.queryAllFormData(ydParamDelete);
  433. //删除当前时间节点以后得数据
  434. mapList.forEach(item -> {
  435. //删除
  436. ydClient.operateData(YDParam.builder()
  437. .formInstanceId(item.get("formInstanceId").toString())
  438. .build(), YDConf.FORM_OPERATION.delete);
  439. });
  440. }
  441. }