YBJServiceImpl.java 108 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717
  1. package com.malk.yibaoju.service.impl;
  2. import cn.hutool.core.date.DateUtil;
  3. import cn.hutool.core.util.ObjectUtil;
  4. import com.alibaba.fastjson.JSON;
  5. import com.alibaba.fastjson.JSONArray;
  6. import com.alibaba.fastjson.JSONObject;
  7. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  8. import com.malk.server.aliwork.YDConf;
  9. import com.malk.server.aliwork.YDParam;
  10. import com.malk.service.aliwork.YDClient;
  11. import com.malk.service.aliwork.YDService;
  12. import com.malk.utils.UtilDateTime;
  13. import com.malk.utils.UtilMap;
  14. import com.malk.yibaoju.entity.Plan;
  15. import com.malk.yibaoju.mapper.PlanMapper;
  16. import com.malk.yibaoju.service.PlanService;
  17. import com.malk.yibaoju.service.YBJService;
  18. import lombok.SneakyThrows;
  19. import lombok.extern.slf4j.Slf4j;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.beans.factory.annotation.Value;
  22. import org.springframework.stereotype.Service;
  23. import java.io.*;
  24. import java.net.HttpURLConnection;
  25. import java.net.URL;
  26. import java.nio.file.Files;
  27. import java.nio.file.Paths;
  28. import java.sql.*;
  29. import java.text.ParseException;
  30. import java.text.SimpleDateFormat;
  31. import java.time.LocalDate;
  32. import java.time.format.TextStyle;
  33. import java.time.temporal.TemporalAdjusters;
  34. import java.util.Date;
  35. import java.util.*;
  36. import java.util.stream.Collectors;
  37. @Service
  38. @Slf4j
  39. public class YBJServiceImpl implements YBJService {
  40. @Autowired
  41. private YDClient ydClient;
  42. @Autowired
  43. private YDService ydService;
  44. @Autowired
  45. private PlanMapper planMapper;
  46. @Value("${spring.datasource.username}")
  47. private String username;
  48. @Value("${spring.datasource.password}")
  49. private String password;
  50. @Value("${spring.datasource.url}")
  51. private String url;
  52. @Value("${spring.datasource.driver-class-name}")
  53. private String driver;
  54. @Autowired
  55. private PlanService planService;
  56. LocalDate currentDate = LocalDate.now();
  57. //获取下月1号的日期
  58. LocalDate firstDayOfNextMonth = currentDate.plusMonths(1).with(TemporalAdjusters.firstDayOfMonth());
  59. // 数据库下月数据日期
  60. String nextDataMonth = firstDayOfNextMonth.getYear() +"-"+ String.format("%02d",firstDayOfNextMonth.getMonthValue());
  61. // 数据库当月数据日期
  62. String dataMonth = currentDate.getYear() +"-"+ String.format("%02d", currentDate.getMonthValue());
  63. //获取下月月末最后一天日期
  64. LocalDate lastDayOfNextMonth = currentDate.plusMonths(1).with(TemporalAdjusters.lastDayOfMonth());
  65. /**
  66. * 每月创建护理计划
  67. */
  68. @Override
  69. @SneakyThrows
  70. public void syncNursePlan() {
  71. YDParam ydParam = new YDParam();
  72. log.info("创建护理计划定时任务Start", new Date());
  73. ydParam = YDParam.builder()
  74. .formUuid("FORM-RK966E7105DFD27FA7EQHAOH9IFS2RN6MP3OL2") //获取护理计划
  75. .searchFieldJson(JSON.toJSONString(UtilMap.map("selectField_lo2b6bvf", "正常")))//护理对象暂停和正常、月度计划创建只查询正常的护理计划
  76. .build();
  77. //pagesize设为1获取总数
  78. ydParam.setPageSize(1);
  79. long totalCount = ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getTotalCount();
  80. float pageSize = 50;
  81. ydParam.setCurrentPage(1);
  82. ydParam.setPageSize((int) pageSize);
  83. log.info("totalCount:----{}----", totalCount);
  84. List<Map> dataList = new ArrayList<>();
  85. for (int page = 1; page <= Math.ceil(totalCount / pageSize); page++) {
  86. ydParam.setCurrentPage(page);
  87. //创建护理计划 1次获取50条
  88. dataList = (List<Map>) ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getData();
  89. log.info("dataList:{}-----page:" + page + "---", dataList.size());
  90. LocalDate currentDate = LocalDate.now();
  91. //获取当前日期是本月几号
  92. int dayOfMonth = currentDate.getDayOfMonth();
  93. //获取本月天数
  94. int daysInMonth = currentDate.lengthOfMonth();
  95. dataList.forEach(dataItem -> {
  96. Map formMap = (Map) dataItem.get("formData");
  97. List<Map> mapList = (List<Map>) formMap.get("tableField_lo3pmohx");
  98. for (int i = 0; i <= (daysInMonth - dayOfMonth); i++) {
  99. //获取当前日期是本月几号
  100. LocalDate currentDay = LocalDate.now();
  101. //获取是周几
  102. String dayOfWeek = currentDay.plusDays(i).getDayOfWeek().getDisplayName(TextStyle.FULL, new Locale("zh", "CN"));
  103. //获取循环每天的日期
  104. LocalDate nextDay = currentDate.plusDays(i);
  105. List<Map> maps = mapList.stream().filter(items -> items.get("selectField_lo3pmohy").equals(dayOfWeek.replace("星期", "周"))).collect(Collectors.toList());
  106. for (Map map : maps) {
  107. Map hashMap = new HashMap();
  108. hashMap.put("associationFormField_lo3pmohz", JSON.parse(map.get("associationFormField_lo3pmohz_id").toString())); //护理人员名称
  109. hashMap.put("textField_lo3pmoi0", map.get("textField_lo3pmoi0")); //护理人员所属机构
  110. hashMap.put("textField_lombve2g", map.get("textField_lomchzi3")); //护理人员身份证
  111. hashMap.put("textField_lo3pmoi3", map.get("textField_lo3pmoi3")); //护理人员手机号
  112. hashMap.put("associationFormField_lo3pmohw", JSON.parse(formMap.get("associationFormField_lo3pmohw_id").toString())); //护理对象姓名
  113. hashMap.put("textField_lnyhv5tn", formMap.get("textField_lnyhv5tn")); //护理对象身份证
  114. hashMap.put("selectField_lnyhv5tp", formMap.get("selectField_lnyhv5tp")); //护理对象等级
  115. hashMap.put("textField_lnyhv5tr", formMap.get("textField_lnyhv5tr")); //护理对象住址
  116. hashMap.put("selectField_lo3pmohy", dayOfWeek.replace("星期", "周")); //护理时间 (星期几)
  117. hashMap.put("dateField_lred6eoj", UtilDateTime.parse(String.valueOf(nextDay) + " " + map.get("selectField_lr1uxpu3"), "yyyy-MM-dd HH:mm")); //护理开始时间。 用当前日期+护理计划的 时分 转成时间戳
  118. hashMap.put("dateField_lred6eok", UtilDateTime.parse(String.valueOf(nextDay) + " " + map.get("selectField_lr1uxpu4"), "yyyy-MM-dd HH:mm")); //护理结束时间。 用当前日期+护理计划的 时分 转成时间戳
  119. hashMap.put("selectField_lqcgsbw2", "未执行"); //执行情况
  120. hashMap.put("selectField_lo56u5fn", "待上报"); //任务状态
  121. hashMap.put("textField_lvae7q5n", formMap.get("textField_lvae99fj")); //护理对象经度
  122. hashMap.put("textField_lvae7q5o", formMap.get("textField_lvae99fk")); //护理对象纬度
  123. hashMap.put("textField_lrx0r38x", String.valueOf(nextDay)); //护理日期-文本
  124. hashMap.put("selectField_lr36z6hd", "是"); //任务状态
  125. hashMap.put("textField_lo55rupj", formMap.get("textField_lo55rupj")); //护理对象姓名-文本
  126. hashMap.put("textField_lo3pmoi4", map.get("textField_lo3pmoi4")); //护理证书类型
  127. hashMap.put("employeeField_lo3pmoi6", JSON.parse(map.get("employeeField_lo3pmoi6_id").toString())); //护理人员姓名-成员
  128. hashMap.put("textField_lpgi8scj", map.get("textField_lo701pwy")); //计划明细id
  129. hashMap.put("textField_lq9llmhl", formMap.get("textField_lop4v4qx")); //护理对象ID
  130. if (formMap.get("departmentSelectField_lxztlnnx_id") != null) {
  131. hashMap.put("departmentSelectField_lxzto1e1", String.valueOf(formMap.get("departmentSelectField_lxztlnnx_id"))); //部门
  132. }
  133. try {
  134. Thread.sleep(200);
  135. } catch (InterruptedException e) {
  136. throw new RuntimeException(e);
  137. }
  138. try {
  139. ydClient.operateData(YDParam.builder()
  140. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  141. .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"))))
  142. .formDataJson(JSON.toJSONString(hashMap))
  143. .build(), YDConf.FORM_OPERATION.upsert);
  144. } catch (Exception e) {
  145. log.info("异常数据{}", hashMap);
  146. }
  147. }
  148. }
  149. });
  150. }
  151. log.info("创建护理计划定时任务end", new Date());
  152. }
  153. /**
  154. * 定时任务每月25号创建下月的数据
  155. */
  156. @Override
  157. @SneakyThrows
  158. public void syncCreatePlan() {
  159. YDParam ydParam = new YDParam();
  160. log.info("创建下月护理计划定时任务Start:{}", new Date());
  161. ydParam = YDParam.builder()
  162. .formUuid("FORM-RK966E7105DFD27FA7EQHAOH9IFS2RN6MP3OL2") //获取护理计划
  163. .searchFieldJson(JSON.toJSONString(UtilMap.map("selectField_lo2b6bvf", "正常")))//护理对象暂停和正常、月度计划创建只查询正常的护理计划
  164. .build();
  165. //pagesize设为1获取总数
  166. ydParam.setPageSize(1);
  167. long totalCount = ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getTotalCount();
  168. float pageSize = 50;
  169. ydParam.setCurrentPage(1);
  170. ydParam.setPageSize((int) pageSize);
  171. List<Map> dataList = new ArrayList<>();
  172. LocalDate currentDate = LocalDate.now();
  173. //获取下月1号的日期
  174. LocalDate firstDayOfNextMonth = currentDate.plusMonths(1).with(TemporalAdjusters.firstDayOfMonth());
  175. //获取日期是几号
  176. int dayOfMonth = firstDayOfNextMonth.getDayOfMonth();
  177. //获取月天数
  178. int daysInMonth = firstDayOfNextMonth.lengthOfMonth();
  179. for (int page = 1; page <= Math.ceil(totalCount / pageSize); page++) {
  180. ydParam.setCurrentPage(page);
  181. //创建护理计划 1次获取50条
  182. dataList = (List<Map>) ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getData();
  183. log.info("dataList:{}-----page:" + page + "---", dataList.size());
  184. dataList.forEach(dataItem -> {
  185. Map formMap = (Map) dataItem.get("formData");
  186. List<Map> mapList = (List<Map>) formMap.get("tableField_lo3pmohx");
  187. for (int i = 0; i <= (daysInMonth - dayOfMonth); i++) {
  188. //获取是周几
  189. String dayOfWeek = firstDayOfNextMonth.plusDays(i).getDayOfWeek().getDisplayName(TextStyle.FULL, new Locale("zh", "CN"));
  190. //获取循环每天的日期
  191. LocalDate nextDay = firstDayOfNextMonth.plusDays(i);
  192. List<Map> maps = mapList.stream().filter(items -> items.get("selectField_lo3pmohy").equals(dayOfWeek.replace("星期", "周"))).collect(Collectors.toList());
  193. for (Map map : maps) {
  194. Map hashMap = new HashMap();
  195. hashMap.put("associationFormField_lo3pmohz", JSON.parse(map.get("associationFormField_lo3pmohz_id").toString())); //护理人员名称
  196. hashMap.put("textField_lo3pmoi0", map.get("textField_lo3pmoi0")); //护理人员所属机构
  197. hashMap.put("textField_lombve2g", map.get("textField_lomchzi3")); //护理人员身份证
  198. hashMap.put("textField_lo3pmoi3", map.get("textField_lo3pmoi3")); //护理人员手机号
  199. hashMap.put("associationFormField_lo3pmohw", JSON.parse(formMap.get("associationFormField_lo3pmohw_id").toString())); //护理对象姓名
  200. hashMap.put("textField_lnyhv5tn", formMap.get("textField_lnyhv5tn")); //护理对象身份证
  201. hashMap.put("selectField_lnyhv5tp", formMap.get("selectField_lnyhv5tp")); //护理对象等级
  202. hashMap.put("textField_lnyhv5tr", formMap.get("textField_lnyhv5tr")); //护理对象住址
  203. hashMap.put("selectField_lo3pmohy", dayOfWeek.replace("星期", "周")); //护理时间 (星期几)
  204. hashMap.put("dateField_lred6eoj", UtilDateTime.parse(String.valueOf(nextDay) + " " + map.get("selectField_lr1uxpu3"), "yyyy-MM-dd HH:mm")); //护理开始时间。 用当前日期+护理计划的 时分 转成时间戳
  205. hashMap.put("dateField_lred6eok", UtilDateTime.parse(String.valueOf(nextDay) + " " + map.get("selectField_lr1uxpu4"), "yyyy-MM-dd HH:mm")); //护理结束时间。 用当前日期+护理计划的 时分 转成时间戳
  206. hashMap.put("selectField_lqcgsbw2", "未执行"); //执行情况
  207. hashMap.put("selectField_lo56u5fn", "待上报"); //任务状态
  208. hashMap.put("textField_lvae7q5n", formMap.get("textField_lvae99fj")); //护理对象经度
  209. hashMap.put("textField_lvae7q5o", formMap.get("textField_lvae99fk")); //护理对象纬度
  210. hashMap.put("textField_lrx0r38x", String.valueOf(nextDay)); //护理日期-文本
  211. hashMap.put("selectField_lr36z6hd", "是"); //任务状态
  212. hashMap.put("textField_lo55rupj", formMap.get("textField_lo55rupj")); //护理对象姓名-文本
  213. hashMap.put("textField_lo3pmoi4", map.get("textField_lo3pmoi4")); //护理证书类型
  214. hashMap.put("employeeField_lo3pmoi6", JSON.parse(map.get("employeeField_lo3pmoi6_id").toString())); //护理人员姓名-成员
  215. hashMap.put("textField_lpgi8scj", map.get("textField_lo701pwy")); //计划明细id
  216. hashMap.put("textField_lq9llmhl", formMap.get("textField_lop4v4qx")); //护理对象ID
  217. if (formMap.get("departmentSelectField_lxztlnnx_id") != null) {
  218. hashMap.put("departmentSelectField_lxzto1e1", String.valueOf(formMap.get("departmentSelectField_lxztlnnx_id"))); //部门
  219. }
  220. try {
  221. Thread.sleep(200);
  222. } catch (InterruptedException e) {
  223. log.info("睡眠异常");
  224. }
  225. try {
  226. ydClient.operateData(YDParam.builder()
  227. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  228. // .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"))))
  229. .formDataJson(JSON.toJSONString(hashMap))
  230. .build(), YDConf.FORM_OPERATION.create);
  231. } catch (Exception e) {
  232. log.info("异常数据{}", hashMap);
  233. }
  234. }
  235. }
  236. });
  237. }
  238. log.info("创建下月护理计划定时任务end", new Date());
  239. }
  240. /**
  241. * 定时任务创建下月护理计划插入数据库
  242. */
  243. @Override
  244. public void insertDatabaseTask() {
  245. log.info("创建下月护理计划定时任务生成到数据库:{}", new Date());
  246. YDParam ydParam = new YDParam();
  247. ydParam = YDParam.builder()
  248. .formUuid("FORM-RK966E7105DFD27FA7EQHAOH9IFS2RN6MP3OL2") //获取护理计划
  249. .searchFieldJson(JSON.toJSONString(UtilMap.map("selectField_lo2b6bvf", "正常")))//护理对象暂停和正常、月度计划创建只查询正常的护理计划
  250. .build();
  251. //获取日期是几号
  252. int dayOfMonth = firstDayOfNextMonth.getDayOfMonth();
  253. //获取月天数
  254. int daysInMonth = firstDayOfNextMonth.lengthOfMonth();
  255. try {
  256. Class.forName(driver);
  257. Connection connection = DriverManager.getConnection(url, username, password);
  258. final PreparedStatement[] ps = {null};
  259. String insertSql = "INSERT INTO `yida_plan_details`( `caregiver_form`, `caregiver_name`, `caregiver_member`, `caregiver_department`, " +
  260. "`caregiver_card`, `caregiver_phone`, `department`, `care_object_form`, `care_object_name`, `care_object_card`, `care_object_level`, " +
  261. "`care_object_address`, `care_object_longitude`, `care_object_latitude`, `within_the_week` , `care_start_time`, `care_end_time`, " +
  262. "`execute_status`, `task_status`, `plan_id`, `care_object_id`, `certificate_type`, `is_choose`, `care_date_text` , `start_time_text` ," +
  263. " `end_time_text` ,`form_inst_id`, `data_month`, `is_cogradient`, `start_time`, `end_time`, `is_delete`) " +
  264. "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
  265. ps[0] = connection.prepareStatement(insertSql);
  266. // for (int page = 1; page <= Math.ceil(totalCount / pageSize); page++) {
  267. // ydParam.setCurrentPage(page);
  268. //创建护理计划 1次获取50条
  269. // dataList = (List<Map>) ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getData();
  270. List<Map> dataList = ydService.queryFormData_all(ydParam);
  271. // log.info("dataList:{}-----page:" + page + "---", dataList.size());
  272. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  273. dataList.forEach(dataItem -> {
  274. // Map formMap = (Map) dataItem.get("formData");
  275. List<Map> mapList = (List<Map>) dataItem.get("tableField_lo3pmohx");
  276. try {
  277. for (int i = 0; i <= (daysInMonth - dayOfMonth); i++) {
  278. //获取是周几
  279. String dayOfWeek = firstDayOfNextMonth.plusDays(i).getDayOfWeek().getDisplayName(TextStyle.FULL, new Locale("zh", "CN"));
  280. //获取循环每天的日期
  281. LocalDate nextDay = firstDayOfNextMonth.plusDays(i);
  282. List<Map> maps = mapList.stream().filter(items -> items.get("selectField_lo3pmohy").equals(dayOfWeek.replace("星期", "周"))).collect(Collectors.toList());
  283. for (Map map : maps) {
  284. Object parse = JSON.parse(map.get("associationFormField_lo3pmohz_id").toString());
  285. JSONArray jsonArray = JSON.parseArray(parse.toString());
  286. JSONObject jsonObject = (JSONObject) jsonArray.get(0);
  287. // 创建Statement对象,用于执行SQL语句
  288. ps[0].setObject(1,map.get("associationFormField_lo3pmohz_id").toString()); //护理人员名称(关联表单)
  289. ps[0].setObject(2, jsonObject.get("title")); //护理人员名称
  290. ps[0].setObject(3,map.get("employeeField_lo3pmoi6_id").toString()); //护理人员姓名-成员
  291. ps[0].setObject(4,map.get("textField_lo3pmoi0")); //护理人员所属机构
  292. ps[0].setObject(5,map.get("textField_lomchzi3")); //护理人员身份证
  293. ps[0].setObject(6,map.get("textField_lo3pmoi3")); //护理人员手机号
  294. if (dataItem.get("departmentSelectField_lxztlnnx_id") != null) {
  295. ps[0].setObject(7,String.valueOf(dataItem.get("departmentSelectField_lxztlnnx_id"))); //部门
  296. }
  297. ps[0].setObject(8,dataItem.get("associationFormField_lo3pmohw_id").toString());//护理对象姓名(关联表单)
  298. ps[0].setObject(9,dataItem.get("textField_lo55rupj")); //护理对象姓名-文本
  299. ps[0].setObject(10,dataItem.get("textField_lnyhv5tn")); //护理对象身份证
  300. ps[0].setObject(11,dataItem.get("selectField_lnyhv5tp")); //护理对象等级
  301. ps[0].setObject(12,dataItem.get("textField_lnyhv5tr")); //护理对象住址
  302. ps[0].setObject(13, dataItem.get("textField_lvae99fj")); //护理对象经度
  303. ps[0].setObject(14, dataItem.get("textField_lvae99fk")); //护理对象纬度
  304. ps[0].setObject(15, dayOfWeek.replace("星期", "周")); //护理时间 (星期几)
  305. // 将字符串时间转换为Date对象
  306. Date startDate = dateFormat.parse(String.valueOf(nextDay) + " " + map.get("selectField_lr1uxpu3") + ":00");
  307. Date endDate = dateFormat.parse(String.valueOf(nextDay) + " " + map.get("selectField_lr1uxpu4") + ":00");
  308. ps[0].setObject(16, startDate.getTime()); //护理开始时间。 用当前日期+护理计划的 时分 转成时间戳
  309. ps[0].setObject(17, endDate.getTime()); //护理结束时间。 用当前日期+护理计划的 时分 转成时间戳
  310. ps[0].setObject(18, "未执行"); //执行情况
  311. ps[0].setObject(19, "待上报"); //任务状态
  312. ps[0].setObject(20, map.get("textField_lo701pwy")); //计划明细id
  313. ps[0].setObject(21, dataItem.get("textField_lop4v4qx")); //护理对象ID
  314. ps[0].setObject(22, map.get("textField_lo3pmoi4")); //护理证书类型
  315. ps[0].setObject(23, "是"); //是否可选
  316. ps[0].setObject(24, String.valueOf(nextDay)); //护理日期-文本
  317. ps[0].setObject(25, String.valueOf(nextDay) + " " + map.get("selectField_lr1uxpu3")); //护理开始时间。 用当前日期+护理计划的 时分
  318. ps[0].setObject(26, String.valueOf(nextDay) + " " + map.get("selectField_lr1uxpu4")); //护理结束时间。 用当前日期+护理计划的 时分
  319. ps[0].setObject(27, dataItem.get("formInstanceId").toString()); //护理结束时间。 用当前日期+护理计划的 时分
  320. ps[0].setObject(28, nextDataMonth); //下月数据日期
  321. ps[0].setObject(29, "否"); //是否已同步宜搭
  322. ps[0].setObject(30,map.get("selectField_lr1uxpu3"));
  323. ps[0].setObject(31,map.get("selectField_lr1uxpu4"));
  324. ps[0].setObject(32,0);
  325. // 执行SQL查询
  326. ps[0].addBatch();
  327. }
  328. }
  329. ps[0].executeBatch();
  330. ps[0].clearBatch();
  331. } catch (SQLException e) {
  332. log.info("sql或插入数据库执行失败:{}",dataItem.get("formInstanceId"));
  333. e.printStackTrace();
  334. } catch (ParseException e) {
  335. throw new RuntimeException(e);
  336. }
  337. });
  338. // }
  339. // 关闭资源
  340. ps[0].close();
  341. connection.close();
  342. } catch (Exception ex) {
  343. log.info("数据库连接失败");
  344. ex.printStackTrace();
  345. }
  346. log.info("创建下月护理计划定时任务end:{}", new Date());
  347. }
  348. /**
  349. * 根据流程id创建下月护理计划插入数据库
  350. */
  351. @Override
  352. public void insertDatabaseNextMonth(String formInstId) {
  353. log.info("创建下月护理计划定时任务生成到数据库:{}", new Date());
  354. List<Map> dataList = new ArrayList<>();
  355. //获取日期是几号
  356. int dayOfMonth = firstDayOfNextMonth.getDayOfMonth();
  357. //获取月天数
  358. int daysInMonth = firstDayOfNextMonth.lengthOfMonth();
  359. try {
  360. Class.forName(driver);
  361. Connection connection = DriverManager.getConnection(url, username, password);
  362. final PreparedStatement[] ps = {null};
  363. String insertSql = "INSERT INTO `yida_plan_details`( `caregiver_form`, `caregiver_name`, `caregiver_member`, `caregiver_department`, " +
  364. "`caregiver_card`, `caregiver_phone`, `department`, `care_object_form`, `care_object_name`, `care_object_card`, `care_object_level`, " +
  365. "`care_object_address`, `care_object_longitude`, `care_object_latitude`, `within_the_week` , `care_start_time`, `care_end_time`, " +
  366. "`execute_status`, `task_status`, `plan_id`, `care_object_id`, `certificate_type`, `is_choose`, `care_date_text` , `start_time_text` ," +
  367. " `end_time_text` ,`form_inst_id`, `data_month`, `is_cogradient`, `start_time`, `end_time`, `is_delete`) " +
  368. "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
  369. ps[0] = connection.prepareStatement(insertSql);
  370. //创建护理计划 1次获取50条
  371. //根据实例ID 查询护理计划
  372. YDParam ydParam = YDParam.builder()
  373. .formInstId(formInstId)
  374. .build();
  375. Map formMap = ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_id).getFormData();
  376. List<Map> mapList = (List<Map>) formMap.get("tableField_lo3pmohx");
  377. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  378. for (int i = 0; i <= (daysInMonth - dayOfMonth); i++) {
  379. //获取是周几
  380. String dayOfWeek = firstDayOfNextMonth.plusDays(i).getDayOfWeek().getDisplayName(TextStyle.FULL, new Locale("zh", "CN"));
  381. //获取循环每天的日期
  382. LocalDate nextDay = firstDayOfNextMonth.plusDays(i);
  383. List<Map> maps = mapList.stream().filter(items -> items.get("selectField_lo3pmohy").equals(dayOfWeek.replace("星期", "周"))).collect(Collectors.toList());
  384. try {
  385. for (Map map : maps) {
  386. Object parse = JSON.parse(map.get("associationFormField_lo3pmohz_id").toString());
  387. JSONArray jsonArray = JSON.parseArray(parse.toString());
  388. JSONObject jsonObject = (JSONObject) jsonArray.get(0);
  389. // 创建Statement对象,用于执行SQL语句
  390. ps[0].setObject(1,map.get("associationFormField_lo3pmohz_id").toString()); //护理人员名称(关联表单)
  391. ps[0].setObject(2, jsonObject.get("title")); //护理人员名称
  392. ps[0].setObject(3,map.get("employeeField_lo3pmoi6_id").toString()); //护理人员姓名-成员
  393. ps[0].setObject(4,map.get("textField_lo3pmoi0")); //护理人员所属机构
  394. ps[0].setObject(5,map.get("textField_lomchzi3")); //护理人员身份证
  395. ps[0].setObject(6,map.get("textField_lo3pmoi3")); //护理人员手机号
  396. if (formMap.get("departmentSelectField_lxztlnnx_id") != null) {
  397. ps[0].setObject(7,String.valueOf(formMap.get("departmentSelectField_lxztlnnx_id"))); //部门
  398. }
  399. ps[0].setObject(8,map.get("associationFormField_lo3pmohw_id").toString()); //护理对象姓名(关联表单)
  400. ps[0].setObject(9,formMap.get("textField_lo55rupj")); //护理对象姓名-文本
  401. ps[0].setObject(10,formMap.get("textField_lnyhv5tn")); //护理对象身份证
  402. ps[0].setObject(11,formMap.get("selectField_lnyhv5tp")); //护理对象等级
  403. ps[0].setObject(12,formMap.get("textField_lnyhv5tr")); //护理对象住址
  404. ps[0].setObject(13, formMap.get("textField_lvae99fj")); //护理对象经度
  405. ps[0].setObject(14, formMap.get("textField_lvae99fk")); //护理对象纬度
  406. ps[0].setObject(15, dayOfWeek.replace("星期", "周")); //护理时间 (星期几)
  407. Date startDate = dateFormat.parse(String.valueOf(nextDay) + " " + map.get("selectField_lr1uxpu3") + ":00");
  408. Date endDate = dateFormat.parse(String.valueOf(nextDay) + " " + map.get("selectField_lr1uxpu4") + ":00");
  409. ps[0].setObject(16, startDate.getTime()); //护理开始时间。 用当前日期+护理计划的 时分 转成时间戳
  410. ps[0].setObject(17, endDate.getTime()); //护理结束时间。 用当前日期+护理计划的 时分 转成时间戳
  411. ps[0].setObject(18, "未执行"); //执行情况
  412. ps[0].setObject(19, "待上报"); //任务状态
  413. ps[0].setObject(20, map.get("textField_lo701pwy")); //计划明细id
  414. ps[0].setObject(21, formMap.get("textField_lop4v4qx")); //护理对象ID
  415. ps[0].setObject(22, map.get("textField_lo3pmoi4")); //护理证书类型
  416. ps[0].setObject(23, "是"); //是否可选
  417. ps[0].setObject(24, String.valueOf(nextDay)); //护理日期-文本
  418. ps[0].setObject(25, String.valueOf(nextDay) + " " + map.get("selectField_lr1uxpu3")); //护理开始时间。 用当前日期+护理计划的 时分
  419. ps[0].setObject(26, String.valueOf(nextDay) + " " + map.get("selectField_lr1uxpu4")); //护理结束时间。 用当前日期+护理计划的 时分
  420. ps[0].setObject(27, formMap.get("formInstanceId").toString()); //护理结束时间。 用当前日期+护理计划的 时分
  421. ps[0].setObject(28, nextDataMonth); //下月数据日期
  422. ps[0].setObject(29, "否"); //是否已同步宜搭
  423. ps[0].setObject(30,map.get("selectField_lr1uxpu3"));
  424. ps[0].setObject(31,map.get("selectField_lr1uxpu4"));
  425. // 执行SQL查询
  426. ps[0].setObject(32,0);
  427. ps[0].addBatch();
  428. }
  429. ps[0].executeBatch();
  430. ps[0].clearBatch();
  431. } catch (SQLException e) {
  432. log.info("sql或插入数据库执行失败:{}",formMap.get("formInstanceId"));
  433. e.printStackTrace();
  434. }
  435. }
  436. // 关闭资源
  437. ps[0].close();
  438. connection.close();
  439. } catch (Exception ex) {
  440. log.info("数据库连接失败");
  441. ex.printStackTrace();
  442. }
  443. log.info("创建下月护理计划定时任务end:{}", new Date());
  444. }
  445. @Override
  446. public void insertDatabaseTaskNew() {
  447. log.info("创建下月护理计划定时任务生成到数据库:{}", new Date());
  448. YDParam ydParam = new YDParam();
  449. String formId = getFormId(nextDataMonth);
  450. ydParam = YDParam.builder()
  451. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM") //获取护理计划
  452. // .searchFieldJson(JSON.toJSONString(UtilMap.map("selectField_m4hsya94", "未回写")))//护理对象暂停和正常、月度计划创建只查询正常的护理计划
  453. .build();
  454. List<Map> dataList = ydService.queryFormData_all(ydParam);
  455. try {
  456. List<Plan> planCopies = new ArrayList<>();
  457. Class.forName(driver);
  458. Connection connection = DriverManager.getConnection(url, username, password);
  459. final PreparedStatement[] ps = {null};
  460. String insertSql = "INSERT INTO `yida_plan_details_c`( `caregiver_form`, `caregiver_name`, `caregiver_member`, `caregiver_department`, " +
  461. "`caregiver_card`, `caregiver_phone`, `department`, `care_object_form`, `care_object_name`, `care_object_card`, `care_object_level`, " +
  462. "`care_object_address`, `care_object_longitude`, `care_object_latitude`, `within_the_week` , `care_start_time`, `care_end_time`, " +
  463. "`execute_status`, `task_status`, `plan_id`, `care_object_id`, `certificate_type`, `is_choose`, `care_date_text` , `start_time_text` ," +
  464. " `end_time_text` ,`form_inst_id`, `data_month`, `is_cogradient`, `start_time`, `end_time`, `is_delete`) " +
  465. "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
  466. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  467. dataList.forEach(dataItem -> {
  468. // Map formMap = (Map) dataItem.get("formData");
  469. List<Map> mapList = (List<Map>) dataItem.get("tableField_lo3pmohx");
  470. try {
  471. for (Map map : mapList) {
  472. ps[0] = connection.prepareStatement(insertSql);
  473. Object parse = JSON.parse(map.get("associationFormField_lo3pmohz_id").toString());
  474. JSONArray jsonArray = JSON.parseArray(parse.toString());
  475. JSONObject jsonObject = (JSONObject) jsonArray.get(0);
  476. // 创建Statement对象,用于执行SQL语句
  477. ps[0].setObject(1,map.get("associationFormField_lo3pmohz_id").toString()); //护理人员名称(关联表单)
  478. ps[0].setObject(2, jsonObject.get("title")); //护理人员名称
  479. ps[0].setObject(3,map.get("employeeField_lo3pmoi6_id").toString()); //护理人员姓名-成员
  480. ps[0].setObject(4,map.get("textField_lo3pmoi0")); //护理人员所属机构
  481. ps[0].setObject(5,map.get("textField_lombve2g")); //护理人员身份证
  482. ps[0].setObject(6,map.get("textField_lo3pmoi3")); //护理人员手机号
  483. if (dataItem.get("departmentSelectField_lxzto1e1_id") != null) {
  484. ps[0].setObject(7,String.valueOf(dataItem.get("departmentSelectField_lxzto1e1_id"))); //部门
  485. }
  486. ps[0].setObject(8,dataItem.get("associationFormField_lo3pmohw_id").toString());//护理对象姓名(关联表单)
  487. ps[0].setObject(9,dataItem.get("textField_lo55rupj")); //护理对象姓名-文本
  488. ps[0].setObject(10,dataItem.get("textField_lnyhv5tn")); //护理对象身份证
  489. ps[0].setObject(11,dataItem.get("selectField_lnyhv5tp")); //护理对象等级
  490. ps[0].setObject(12,dataItem.get("textField_lnyhv5tr")); //护理对象住址
  491. ps[0].setObject(13, dataItem.get("textField_lvae7q5n")); //护理对象经度
  492. ps[0].setObject(14, dataItem.get("textField_lvae7q5o")); //护理对象纬度
  493. ps[0].setObject(15, dataItem.get("selectField_lo3pmohy")); //护理时间 (星期几)
  494. // 将字符串时间转换为Date对象
  495. ps[0].setObject(16, dataItem.get("dateField_lred6eoj")); //护理开始时间。 用当前日期+护理计划的 时分 转成时间戳
  496. ps[0].setObject(17, dataItem.get("dateField_lred6eok")); //护理结束时间。 用当前日期+护理计划的 时分 转成时间戳
  497. ps[0].setObject(18, "未执行"); //执行情况
  498. ps[0].setObject(19, "待上报"); //任务状态
  499. ps[0].setObject(20, map.get("textField_lpgi8scj")); //计划明细id
  500. ps[0].setObject(21, dataItem.get("textField_lq9llmhl")); //护理对象ID
  501. ps[0].setObject(22, map.get("textField_lo3pmoi4")); //护理证书类型
  502. ps[0].setObject(23, "是"); //是否可选
  503. ps[0].setObject(24, dataItem.get("textField_lrx0r38x")); //护理日期-文本
  504. ps[0].setObject(25, dateFormat.parse(dataItem.get("dateField_lred6eoj").toString())); //护理开始时间。 用当前日期+护理计划的 时分
  505. ps[0].setObject(26, dateFormat.parse(dataItem.get("dateField_lred6eok").toString())); //护理结束时间。 用当前日期+护理计划的 时分
  506. ps[0].setObject(27, dataItem.get("formInstanceId").toString()); //护理结束时间。 用当前日期+护理计划的 时分
  507. ps[0].setObject(28, nextDataMonth); //下月数据日期
  508. ps[0].setObject(29, "否"); //是否已同步宜搭
  509. ps[0].setObject(30,map.get("selectField_lr1uxpu3"));//开始时间
  510. ps[0].setObject(31,map.get("selectField_lr1uxpu4"));//结束时间
  511. ps[0].setObject(32,0);
  512. // 执行SQL查询
  513. ps[0].addBatch();
  514. // ps[0].execute();
  515. // ydClient.operateData(YDParam.builder()
  516. // .formInstanceId(dataItem.get("formInstanceId").toString())
  517. // .updateFormDataJson(JSON.toJSONString(UtilMap.map("selectField_m4hsya94","已回写")))
  518. // .useLatestVersion(true)
  519. // .build(), YDConf.FORM_OPERATION.update);
  520. }
  521. ps[0].executeBatch();
  522. ps[0].clearBatch();
  523. } catch (SQLException e) {
  524. log.info("sql或插入数据库执行失败:{}",dataItem.get("formInstanceId"));
  525. e.printStackTrace();
  526. } catch (ParseException e) {
  527. throw new RuntimeException(e);
  528. }
  529. });
  530. // 关闭资源
  531. ps[0].close();
  532. connection.close();
  533. } catch (Exception ex) {
  534. log.info("数据库连接失败");
  535. ex.printStackTrace();
  536. }
  537. log.info("创建下月护理计划定时任务end:{}", new Date());
  538. }
  539. @Override
  540. public void insertHistory() {
  541. log.info("创建下月护理计划定时任务生成到数据库:{}", new Date());
  542. YDParam ydParam = new YDParam();
  543. // String formId = getFormId(nextDataMonth);
  544. ydParam = YDParam.builder()
  545. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM") //获取护理计划
  546. // .searchFieldJson(JSON.toJSONString(UtilMap.map("selectField_m4hsya94", "未回写")))//护理对象暂停和正常、月度计划创建只查询正常的护理计划
  547. .build();
  548. ydParam.setPageSize(1);
  549. long totalCount = ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getTotalCount();
  550. float pageSize = 50;
  551. ydParam.setCurrentPage(1);
  552. ydParam.setPageSize((int) pageSize);
  553. List<Map> dataList = new ArrayList<>();
  554. // dataList = ydService.queryFormData_all(ydParam);
  555. List<Plan> planCopies = new ArrayList<>();
  556. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  557. for (int page = 1; page <= Math.ceil(totalCount / pageSize); page++) {
  558. ydParam.setCurrentPage(page);
  559. //创建护理计划 1次获取50条
  560. dataList = (List<Map>) ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getData();
  561. dataList.forEach(e -> {
  562. Map formMap = (Map) e.get("formData");
  563. System.out.println(e);
  564. //护理人员
  565. Object parse = JSON.parse(formMap.get("associationFormField_lo3pmohz_id").toString());
  566. JSONArray jsonArray = JSON.parseArray(parse.toString());
  567. JSONObject jsonObject = (JSONObject) jsonArray.get(0);
  568. Plan planCopy = new Plan();
  569. planCopy.setDataMonth(dateFormat.format(new Date(Long.parseLong(formMap.get("dateField_lred6eoj").toString()))).substring(0, 7));
  570. //planCopy.setFormInstId();
  571. planCopy.setPlanInstId(e.get("formInstanceId").toString());
  572. planCopy.setCaregiverForm(formMap.get("associationFormField_lo3pmohz_id").toString());
  573. planCopy.setCaregiverName(jsonObject.get("title").toString());
  574. planCopy.setCaregiverMember(ObjectUtil.isNotNull(formMap.get("employeeField_lo3pmoi6_id"))?formMap.get("employeeField_lo3pmoi6_id").toString():"");
  575. planCopy.setCaregiverDepartment(formMap.get("textField_lo3pmoi0").toString());
  576. planCopy.setCaregiverCard(formMap.get("textField_lombve2g").toString());
  577. planCopy.setCaregiverPhone(formMap.get("textField_lo3pmoi3").toString());
  578. if (formMap.get("departmentSelectField_lxzto1e1_id") != null) {
  579. planCopy.setDepartment(formMap.get("departmentSelectField_lxzto1e1_id").toString());
  580. }
  581. //护理对象
  582. parse = JSON.parse(formMap.get("associationFormField_lo3pmohw_id").toString());
  583. jsonArray = JSON.parseArray(parse.toString());
  584. jsonObject = (JSONObject) jsonArray.get(0);
  585. planCopy.setCareObjectForm(formMap.get("associationFormField_lo3pmohw_id").toString());
  586. planCopy.setCareObjectName(jsonObject.get("title").toString());
  587. planCopy.setCareObjectCard(formMap.get("textField_lnyhv5tn").toString());
  588. planCopy.setCareObjectLevel(ObjectUtil.isNotNull(formMap.get("selectField_lnyhv5tp"))?formMap.get("selectField_lnyhv5tp").toString():"");
  589. planCopy.setCareObjectAddress(ObjectUtil.isNotNull(formMap.get("textField_lnyhv5tr"))?formMap.get("textField_lnyhv5tr").toString():"");
  590. planCopy.setCareObjectLongitude(ObjectUtil.isNotNull(formMap.get("textField_lvae7q5n"))?formMap.get("textField_lvae7q5n").toString():"");
  591. planCopy.setCareObjectLatitude(ObjectUtil.isNotNull(formMap.get("textField_lvae7q5o"))?formMap.get("textField_lvae7q5o").toString():"");
  592. planCopy.setWithinTheWeek(formMap.get("selectField_lo3pmohy").toString());
  593. planCopy.setCareStartTime(Long.parseLong(formMap.get("dateField_lred6eoj").toString()));
  594. planCopy.setCareEndTime(Long.parseLong(formMap.get("dateField_lred6eok").toString()));
  595. planCopy.setStartTime(dateFormat.format(new Date(Long.parseLong(formMap.get("dateField_lred6eoj").toString()))).substring(11, 16));
  596. planCopy.setEndTime(dateFormat.format(new Date(Long.parseLong(formMap.get("dateField_lred6eok").toString()))).substring(11, 16));
  597. if (ObjectUtil.isNotNull(formMap.get("dateField_lp7obkef"))) {
  598. if (ObjectUtil.isNotNull(formMap.get("imageField_lrq19cti"))) {
  599. parse = JSON.parse(formMap.get("imageField_lrq19cti").toString());
  600. jsonArray = JSON.parseArray(parse.toString());
  601. jsonObject = (JSONObject) jsonArray.get(0);
  602. // "https://xvuk8m.aliwork.com" +
  603. planCopy.setSignInPhoto(jsonObject.get("previewUrl").toString());
  604. planCopy.setSignInPhotoDown(jsonObject.get("downloadUrl").toString());
  605. planCopy.setSignInPhotoName(jsonObject.get("name").toString());
  606. }
  607. planCopy.setSignInLongitude(formMap.get("textField_ljghmc0e").toString());
  608. planCopy.setSignInLatitude(formMap.get("textField_ljghmc0f").toString());
  609. planCopy.setSignInTime(Long.parseLong(formMap.get("dateField_lp7obkef").toString()));
  610. planCopy.setSignInTimeText(dateFormat.format(new Date(Long.parseLong(formMap.get("dateField_lp7obkef").toString()))));
  611. planCopy.setSignInPosition(formMap.get("textField_lrr62xq6").toString());
  612. planCopy.setSignInDistance(ObjectUtil.isNotNull(formMap.get("numberField_lv4mhawr"))?formMap.get("numberField_lv4mhawr").toString():"");
  613. planCopy.setClockInDate(dateFormat.format(new Date(Long.parseLong(formMap.get("dateField_lp7obkef").toString()))).substring(0, 10));
  614. }
  615. if (ObjectUtil.isNotNull(formMap.get("dateField_lr36z6ha"))) {
  616. if (ObjectUtil.isNotNull(formMap.get("imageField_lt893c3q"))){
  617. parse = JSON.parse(formMap.get("imageField_lt893c3q").toString());
  618. jsonArray = JSON.parseArray(parse.toString());
  619. jsonObject = (JSONObject) jsonArray.get(0);
  620. // "https://xvuk8m.aliwork.com" +
  621. planCopy.setSignOutPhoto(jsonObject.get("previewUrl").toString());
  622. planCopy.setSignOutPhotoDown(jsonObject.get("downloadUrl").toString());
  623. planCopy.setSignOutPhotoName(jsonObject.get("name").toString());
  624. }
  625. planCopy.setSignOutLongitude(formMap.get("textField_lr36z6h6").toString());
  626. planCopy.setSignOutLatitude(formMap.get("textField_lr36z6h8").toString());
  627. planCopy.setSignOutTime(Long.parseLong(formMap.get("dateField_lr36z6ha").toString()));
  628. planCopy.setSignOutTimeText(dateFormat.format(new Date(Long.parseLong(formMap.get("dateField_lr36z6ha").toString()))));
  629. planCopy.setSignOutPosition(formMap.get("textField_lrreodfe").toString());
  630. planCopy.setSignOutDistance(ObjectUtil.isNotNull(formMap.get("numberField_lv4mhawi"))?formMap.get("numberField_lv4mhawi").toString():"");
  631. planCopy.setClockOutDate(dateFormat.format(new Date(Long.parseLong(formMap.get("dateField_lr36z6ha").toString()))).substring(0, 10));
  632. }
  633. planCopy.setExecuteStatus(formMap.get("selectField_lqcgsbw2").toString());
  634. planCopy.setTaskStatus(formMap.get("selectField_lo56u5fn").toString());
  635. planCopy.setPlanId(formMap.get("textField_lpgi8scj").toString());
  636. planCopy.setCareObjectId(formMap.get("textField_lq9llmhl").toString());
  637. planCopy.setCertificateType(ObjectUtil.isNotNull(formMap.get("textField_lo3pmoi4"))?formMap.get("textField_lo3pmoi4").toString():"");
  638. planCopy.setIsChoose(formMap.get("selectField_lr36z6hd").toString());
  639. planCopy.setIsDelete("0");
  640. planCopy.setIsCogradient("是");
  641. planCopy.setCareDateText(dateFormat.format(new Date(Long.parseLong(formMap.get("dateField_lred6eoj").toString()))).substring(0, 10));
  642. planCopy.setStartTimeText(dateFormat.format(new Date(Long.parseLong(formMap.get("dateField_lred6eoj").toString()))));
  643. planCopy.setEndTimeText(dateFormat.format(new Date(Long.parseLong(formMap.get("dateField_lred6eok").toString()))));
  644. planCopies.add(planCopy);
  645. try {
  646. Thread.sleep(200);
  647. } catch (InterruptedException ex) {
  648. throw new RuntimeException(ex);
  649. }
  650. });
  651. if (planCopies.size() > 0) {
  652. planService.saveBatch(planCopies);
  653. planCopies.clear();
  654. }
  655. }
  656. }
  657. @Override
  658. public void insertHistory2() {
  659. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  660. // Date date = new Date();
  661. long lastTime = 1735660800000L;
  662. List<String> dateList = new ArrayList<>();
  663. long startTime = 1721318400000L;
  664. dateList.add(String.valueOf(startTime));
  665. // 创建一个Calendar实例并设置为给定的时间戳
  666. Calendar calendar = Calendar.getInstance();
  667. calendar.setTimeInMillis(startTime);
  668. // 将Calendar的时间设置为第二天的0点
  669. calendar.add(Calendar.DAY_OF_MONTH, 1); // 增加一天
  670. calendar.set(Calendar.HOUR_OF_DAY, 0); // 设置小时为0点
  671. calendar.set(Calendar.MINUTE, 0); // 设置分钟为0
  672. calendar.set(Calendar.SECOND, 0); // 设置秒为0
  673. calendar.set(Calendar.MILLISECOND, 0); // 设置毫秒为0
  674. // 获取第二天0点的时间戳
  675. long secondDayTime = calendar.getTimeInMillis();
  676. dateList.add(String.valueOf(secondDayTime));
  677. log.info("创建下月护理计划定时任务生成到数据库:{}", new Date());
  678. while (startTime <= lastTime){
  679. YDParam ydParam = new YDParam();
  680. ydParam = YDParam.builder()
  681. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM") //获取护理计划
  682. .searchFieldJson(JSON.toJSONString(UtilMap.map("dateField_lred6eoj", dateList)))//护理对象暂停和正常、月度计划创建只查询正常的护理计划
  683. .build();
  684. List<Map> dataList = ydService.queryFormData_all(ydParam);
  685. List<Plan> planCopies = new ArrayList<>();
  686. System.out.println(startTime+" - "+secondDayTime+"-"+dataList.size());
  687. if (ObjectUtil.isNotNull(dataList)&&dataList.size()>0) {
  688. dataList.forEach(formMap -> {
  689. // Map formMap = (Map) e.get("formData");
  690. // System.out.println(e);
  691. //护理人员
  692. Object parse = JSON.parse(formMap.get("associationFormField_lo3pmohz_id").toString());
  693. JSONArray jsonArray = JSON.parseArray(parse.toString());
  694. JSONObject jsonObject = (JSONObject) jsonArray.get(0);
  695. Plan planCopy = new Plan();
  696. planCopy.setDataMonth(dateFormat.format(new Date(Long.parseLong(formMap.get("dateField_lred6eoj").toString()))).substring(0, 7));
  697. //planCopy.setFormInstId();
  698. planCopy.setPlanInstId(formMap.get("formInstanceId").toString());
  699. planCopy.setCaregiverForm(formMap.get("associationFormField_lo3pmohz_id").toString());
  700. planCopy.setCaregiverName(jsonObject.get("title").toString());
  701. planCopy.setCaregiverMember(ObjectUtil.isNotNull(formMap.get("employeeField_lo3pmoi6_id")) ? formMap.get("employeeField_lo3pmoi6_id").toString() : "");
  702. planCopy.setCaregiverDepartment(formMap.get("textField_lo3pmoi0").toString());
  703. planCopy.setCaregiverCard(formMap.get("textField_lombve2g").toString());
  704. planCopy.setCaregiverPhone(formMap.get("textField_lo3pmoi3").toString());
  705. if (formMap.get("departmentSelectField_lxzto1e1_id") != null) {
  706. planCopy.setDepartment(formMap.get("departmentSelectField_lxzto1e1_id").toString());
  707. }
  708. //护理对象
  709. parse = JSON.parse(formMap.get("associationFormField_lo3pmohw_id").toString());
  710. jsonArray = JSON.parseArray(parse.toString());
  711. jsonObject = (JSONObject) jsonArray.get(0);
  712. planCopy.setCareObjectForm(formMap.get("associationFormField_lo3pmohw_id").toString());
  713. planCopy.setCareObjectName(jsonObject.get("title").toString());
  714. planCopy.setCareObjectCard(formMap.get("textField_lnyhv5tn").toString());
  715. planCopy.setCareObjectLevel(ObjectUtil.isNotNull(formMap.get("selectField_lnyhv5tp")) ? formMap.get("selectField_lnyhv5tp").toString() : "");
  716. planCopy.setCareObjectAddress(ObjectUtil.isNotNull(formMap.get("textField_lnyhv5tr")) ? formMap.get("textField_lnyhv5tr").toString() : "");
  717. planCopy.setCareObjectLongitude(ObjectUtil.isNotNull(formMap.get("textField_lvae7q5n")) ? formMap.get("textField_lvae7q5n").toString() : "");
  718. planCopy.setCareObjectLatitude(ObjectUtil.isNotNull(formMap.get("textField_lvae7q5o")) ? formMap.get("textField_lvae7q5o").toString() : "");
  719. planCopy.setWithinTheWeek(formMap.get("selectField_lo3pmohy").toString());
  720. planCopy.setCareStartTime(Long.parseLong(formMap.get("dateField_lred6eoj").toString()));
  721. planCopy.setCareEndTime(Long.parseLong(formMap.get("dateField_lred6eok").toString()));
  722. planCopy.setStartTime(dateFormat.format(new Date(Long.parseLong(formMap.get("dateField_lred6eoj").toString()))).substring(11, 16));
  723. planCopy.setEndTime(dateFormat.format(new Date(Long.parseLong(formMap.get("dateField_lred6eok").toString()))).substring(11, 16));
  724. if (ObjectUtil.isNotNull(formMap.get("dateField_lp7obkef"))) {
  725. if (ObjectUtil.isNotNull(formMap.get("imageField_lrq19cti"))) {
  726. parse = JSON.parse(formMap.get("imageField_lrq19cti").toString());
  727. jsonArray = JSON.parseArray(parse.toString());
  728. jsonObject = (JSONObject) jsonArray.get(0);
  729. // "https://xvuk8m.aliwork.com" +
  730. planCopy.setSignInPhoto(jsonObject.get("previewUrl").toString());
  731. planCopy.setSignInPhotoDown(jsonObject.get("downloadUrl").toString());
  732. planCopy.setSignInPhotoName(jsonObject.get("name").toString());
  733. }
  734. planCopy.setSignInLongitude(formMap.get("textField_ljghmc0e").toString());
  735. planCopy.setSignInLatitude(formMap.get("textField_ljghmc0f").toString());
  736. planCopy.setSignInTime(Long.parseLong(formMap.get("dateField_lp7obkef").toString()));
  737. planCopy.setSignInTimeText(dateFormat.format(new Date(Long.parseLong(formMap.get("dateField_lp7obkef").toString()))));
  738. planCopy.setSignInPosition(formMap.get("textField_lrr62xq6").toString());
  739. planCopy.setSignInDistance(ObjectUtil.isNotNull(formMap.get("numberField_lv4mhawr")) ? formMap.get("numberField_lv4mhawr").toString() : "");
  740. planCopy.setClockInDate(dateFormat.format(new Date(Long.parseLong(formMap.get("dateField_lp7obkef").toString()))).substring(0, 10));
  741. }
  742. if (ObjectUtil.isNotNull(formMap.get("dateField_lr36z6ha"))) {
  743. if (ObjectUtil.isNotNull(formMap.get("imageField_lt893c3q"))) {
  744. parse = JSON.parse(formMap.get("imageField_lt893c3q").toString());
  745. jsonArray = JSON.parseArray(parse.toString());
  746. jsonObject = (JSONObject) jsonArray.get(0);
  747. // "https://xvuk8m.aliwork.com" +
  748. planCopy.setSignOutPhoto(jsonObject.get("previewUrl").toString());
  749. planCopy.setSignOutPhotoDown(jsonObject.get("downloadUrl").toString());
  750. planCopy.setSignOutPhotoName(jsonObject.get("name").toString());
  751. }
  752. planCopy.setSignOutLongitude(formMap.get("textField_lr36z6h6").toString());
  753. planCopy.setSignOutLatitude(formMap.get("textField_lr36z6h8").toString());
  754. planCopy.setSignOutTime(Long.parseLong(formMap.get("dateField_lr36z6ha").toString()));
  755. planCopy.setSignOutTimeText(dateFormat.format(new Date(Long.parseLong(formMap.get("dateField_lr36z6ha").toString()))));
  756. planCopy.setSignOutPosition(formMap.get("textField_lrreodfe").toString());
  757. planCopy.setSignOutDistance(ObjectUtil.isNotNull(formMap.get("numberField_lv4mhawi")) ? formMap.get("numberField_lv4mhawi").toString() : "");
  758. planCopy.setClockOutDate(dateFormat.format(new Date(Long.parseLong(formMap.get("dateField_lr36z6ha").toString()))).substring(0, 10));
  759. }
  760. planCopy.setExecuteStatus(formMap.get("selectField_lqcgsbw2").toString());
  761. planCopy.setTaskStatus(formMap.get("selectField_lo56u5fn").toString());
  762. planCopy.setPlanId(formMap.get("textField_lpgi8scj").toString());
  763. planCopy.setCareObjectId(formMap.get("textField_lq9llmhl").toString());
  764. planCopy.setCertificateType(ObjectUtil.isNotNull(formMap.get("textField_lo3pmoi4")) ? formMap.get("textField_lo3pmoi4").toString() : "");
  765. planCopy.setIsChoose(formMap.get("selectField_lr36z6hd").toString());
  766. planCopy.setIsDelete("0");
  767. planCopy.setIsCogradient("是");
  768. planCopy.setCareDateText(dateFormat.format(new Date(Long.parseLong(formMap.get("dateField_lred6eoj").toString()))).substring(0, 10));
  769. planCopy.setStartTimeText(dateFormat.format(new Date(Long.parseLong(formMap.get("dateField_lred6eoj").toString()))));
  770. planCopy.setEndTimeText(dateFormat.format(new Date(Long.parseLong(formMap.get("dateField_lred6eok").toString()))));
  771. planCopies.add(planCopy);
  772. });
  773. }
  774. if (planCopies.size() > 0) {
  775. planService.saveBatch(planCopies);
  776. planCopies.clear();
  777. }
  778. startTime = secondDayTime;
  779. calendar.setTimeInMillis(secondDayTime);
  780. // 将Calendar的时间设置为第二天的0点
  781. calendar.add(Calendar.DAY_OF_MONTH, 1); // 增加一天
  782. calendar.set(Calendar.HOUR_OF_DAY, 0); // 设置小时为0点
  783. calendar.set(Calendar.MINUTE, 0); // 设置分钟为0
  784. calendar.set(Calendar.SECOND, 0); // 设置秒为0
  785. calendar.set(Calendar.MILLISECOND, 0); // 设置毫秒为0
  786. secondDayTime = calendar.getTimeInMillis();
  787. dateList.clear();
  788. dateList.add(String.valueOf(startTime));
  789. dateList.add(String.valueOf(secondDayTime));
  790. try {
  791. Thread.sleep(100);
  792. } catch (InterruptedException ex) {
  793. throw new RuntimeException(ex);
  794. }
  795. }
  796. }
  797. @Override
  798. public void afterDatabaseToYiDaTask() {
  799. log.info("开始执行同步宜搭是否同步和流程id到数据库");
  800. List<String> dataMonths = new ArrayList<>();
  801. dataMonths.add(dataMonth);
  802. dataMonths.add(nextDataMonth);
  803. Connection connection = null;
  804. PreparedStatement ps = null;
  805. for (int j = 0; j < dataMonths.size(); j++) {
  806. log.info("数据月份为:{}",dataMonths.get(j));
  807. String formId = getFormId(dataMonths.get(j));
  808. YDParam ydParam = YDParam.builder()
  809. .formUuid(formId)
  810. .searchFieldJson(JSON.toJSONString(UtilMap.map("selectField_m4hsya94", "未回写")))
  811. .build();
  812. List<Map> dataList = ydService.queryFormData_all(ydParam);
  813. if(dataList.size()>0){
  814. log.info("已获取数据{}条,正在执行更新数据库",dataList.size());
  815. try {
  816. Class.forName(driver);
  817. connection = DriverManager.getConnection(url, username, password);
  818. for (int h = 0; h < dataList.size(); h++) {
  819. String updateSql = "UPDATE `yida_plan_details` SET is_cogradient = '是', plan_inst_id = '"+dataList.get(h).get("formInstanceId")+"' " +
  820. "where data_month in ('" + dataMonth + "','"+nextDataMonth+"') AND is_cogradient = '否' AND id = '" + dataList.get(h).get("textField_m3wp95ge") + "';";
  821. ps = connection.prepareStatement(updateSql);
  822. ps.executeUpdate();
  823. ydClient.operateData(YDParam.builder()
  824. .formInstanceId(dataList.get(h).get("formInstanceId").toString())
  825. .updateFormDataJson(JSON.toJSONString(UtilMap.map("selectField_m4hsya94", "已回写")))
  826. .useLatestVersion(true)
  827. .build(), YDConf.FORM_OPERATION.update);
  828. }
  829. } catch (SQLException e) {
  830. throw new RuntimeException(e);
  831. } catch (ClassNotFoundException e) {
  832. throw new RuntimeException(e);
  833. }
  834. }}
  835. }
  836. @Override
  837. public void breakPersonUpdate(Map<String, Object> data) {
  838. long now = new Date().getTime();
  839. String name = data.get("name").toString();
  840. Plan plan = new Plan();
  841. UpdateWrapper<Plan> updateWrapper = new UpdateWrapper<>();
  842. updateWrapper.eq("care_object_name",name);
  843. updateWrapper.ge("care_start_time",now);
  844. updateWrapper.eq("task_status","待上报");
  845. plan.setIsDelete("1");
  846. planMapper.update(plan,updateWrapper);
  847. }
  848. /**
  849. * 定时任务同步数据库到宜搭
  850. */
  851. @Override
  852. public void databaseToYiDaTask() {
  853. List<String> dataMonths = new ArrayList<>();
  854. dataMonths.add(dataMonth);
  855. dataMonths.add(nextDataMonth);
  856. Connection connection = null;
  857. PreparedStatement ps = null;
  858. log.info("开始执行数据库更新到宜搭护理计划");
  859. ArrayList<Integer> ids = new ArrayList<>();
  860. for (int j = 0; j < dataMonths.size(); j++) {
  861. int times = 0;
  862. String formId = getFormId(dataMonths.get(j));
  863. try {
  864. Class.forName(driver);
  865. connection = DriverManager.getConnection(url, username, password);
  866. String selectSql = "SELECT `id`, `caregiver_form`,`caregiver_name`,`caregiver_member`,`caregiver_department`,`caregiver_card`," +
  867. "`caregiver_phone`,`department`,`care_object_form`,`care_object_name`,`care_object_card`,`care_object_level`," +
  868. "`care_object_address`,`care_object_longitude`,`care_object_latitude`,`within_the_week`,`care_start_time`," +
  869. "`care_end_time`,`execute_status`,`task_status`,`plan_id`,`care_object_id`,`certificate_type`,`is_choose`," +
  870. "`care_date_text`,`start_time_text`,`end_time_text`,`sign_in_photo`, `sign_in_photo_down`, `sign_in_photo_name`, `sign_out_photo`, " +
  871. "`sign_out_photo_down`, `sign_out_photo_name`, `sign_in_longitude`, `sign_in_latitude`, `sign_in_time`, `sign_in_position`, " +
  872. "`sign_out_longitude`, `sign_out_latitude`, `sign_out_time`, `sign_out_position`, `sign_in_distance`, `sign_out_distance` " +
  873. "FROM `yida_plan_details` where data_month = '" + dataMonths.get(j) + "' AND is_cogradient = '否' ORDER BY id ASC LIMIT 400";
  874. ps = connection.prepareStatement(selectSql);
  875. ResultSet rs = ps.executeQuery(selectSql);
  876. while (rs.next()){
  877. Map hashMap = new HashMap();
  878. HashMap<String, Object> imageMap = new HashMap<>();
  879. List<Map<String,Object>> images = new ArrayList<>();
  880. hashMap.put("associationFormField_lo3pmohz", JSON.parse(rs.getString("caregiver_form"))); //护理人员名称
  881. hashMap.put("textField_lo3pmoi0", rs.getString( "caregiver_department")); //护理人员所属机构
  882. hashMap.put("textField_lombve2g", rs.getString("caregiver_card")); //护理人员身份证
  883. hashMap.put("textField_lo3pmoi3", rs.getString("caregiver_phone")); //护理人员手机号
  884. hashMap.put("associationFormField_lo3pmohw", JSON.parse(rs.getString("care_object_form"))); //护理对象姓名
  885. hashMap.put("textField_lnyhv5tn", rs.getString("care_object_card")); //护理对象身份证
  886. hashMap.put("selectField_lnyhv5tp", rs.getString("care_object_level")); //护理对象等级
  887. hashMap.put("textField_lnyhv5tr", rs.getString("care_object_address")); //护理对象住址
  888. hashMap.put("selectField_lo3pmohy",rs.getString("within_the_week")); //护理时间 (星期几)
  889. hashMap.put("dateField_lred6eoj", rs.getString("care_start_time")); //护理开始时间。 用当前日期+护理计划的 时分 转成时间戳
  890. hashMap.put("dateField_lred6eok", rs.getString("care_end_time")); //护理结束时间。 用当前日期+护理计划的 时分 转成时间戳
  891. hashMap.put("selectField_lqcgsbw2", "未执行"); //执行情况
  892. hashMap.put("selectField_lo56u5fn", "待上报"); //任务状态
  893. hashMap.put("textField_lvae7q5n", rs.getString("care_object_longitude")); //护理对象经度
  894. hashMap.put("textField_lvae7q5o", rs.getString("care_object_latitude")); //护理对象纬度
  895. hashMap.put("textField_lrx0r38x", rs.getString("care_date_text")); //护理日期-文本
  896. hashMap.put("selectField_lr36z6hd", "是"); //任务状态
  897. hashMap.put("textField_lo55rupj", rs.getString("care_object_name")); //护理对象姓名-文本
  898. hashMap.put("textField_lo3pmoi4", rs.getString("certificate_type")); //护理证书类型
  899. hashMap.put("employeeField_lo3pmoi6", JSON.parse(rs.getString("caregiver_member"))); //护理人员姓名-成员
  900. hashMap.put("textField_lpgi8scj", rs.getString("plan_id")); //计划明细id
  901. hashMap.put("textField_lq9llmhl", rs.getString("care_object_id")); //护理对象ID
  902. if (rs.getString("department") != null) {
  903. hashMap.put("departmentSelectField_lxzto1e1", rs.getString("department")); //部门
  904. }
  905. hashMap.put("textField_m3wp95ge",rs.getInt("id"));//数据库id
  906. imageMap.put("downloadUrl",rs.getString("sign_in_photo_down"));
  907. imageMap.put("name",rs.getString("sign_in_photo_name"));
  908. imageMap.put("previewUrl",rs.getString("sign_in_photo"));
  909. imageMap.put("url",rs.getString("sign_in_photo_down"));
  910. images.add(imageMap);
  911. //, `sign_in_photo_down`, `sign_in_photo_name`, `sign_out_photo`, `sign_out_photo_down`, `sign_out_photo_name`
  912. hashMap.put("textField_ljghmc0e",rs.getString("sign_in_longitude"));
  913. hashMap.put("textField_ljghmc0f",rs.getString("sign_in_latitude"));
  914. hashMap.put("dateField_lp7obkef",rs.getString("sign_in_time"));
  915. hashMap.put("textField_lrr62xq6",rs.getString("sign_in_position"));
  916. hashMap.put("selectField_lqcgsbw2",rs.getString("execute_status"));
  917. hashMap.put("imageField_lrq19cti",JSON.toJSONString(images));
  918. images.clear();
  919. imageMap.put("downloadUrl",rs.getString("sign_out_photo_down"));
  920. imageMap.put("name",rs.getString("sign_out_photo_name"));
  921. imageMap.put("previewUrl",rs.getString("sign_out_photo"));
  922. imageMap.put("url",rs.getString("sign_out_photo_down"));
  923. images.add(imageMap);
  924. hashMap.put("textField_lr36z6h6",rs.getString("sign_out_longitude"));
  925. hashMap.put("textField_lr36z6h8",rs.getString("sign_out_latitude"));
  926. hashMap.put("dateField_lr36z6ha",rs.getString("sign_out_time"));
  927. hashMap.put("textField_lrreodfe",rs.getString("sign_out_position"));
  928. hashMap.put("imageField_lt893c3q",JSON.toJSONString(images));
  929. hashMap.put("numberField_lv4mhawr",rs.getString("sign_in_distance"));
  930. hashMap.put("numberField_lv4mhawi",rs.getString("sign_out_distance"));
  931. hashMap.put("selectField_m4hsya94", "未回写"); //回写数据库状态
  932. times++;
  933. ids.add(rs.getInt("id"));
  934. // if (times%200==0 && ObjectUtil.isNotNull(ids)){
  935. // for (int i = 0; i < ids.size(); i++) {
  936. // YDParam ydParam = YDParam.builder()
  937. // .formUuid(formId)
  938. // .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_m3wp95ge",ids.get(i))))
  939. // .build();
  940. // List<Map> dataList = (List<Map>) ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getData();
  941. // if(dataList.size()>0){
  942. // Map map = (Map) dataList.get(0);
  943. // String updateSql = "UPDATE `yida_plan_details` SET is_cogradient = '是', plan_inst_id = '"+map.get("formInstanceId")+"' " +
  944. // "where data_month in ('" + dataMonth + "','"+nextDataMonth+"') AND is_cogradient = '否' AND id = '" + ids.get(i) + "';";
  945. // ps = connection.prepareStatement(updateSql);
  946. // ps.executeUpdate();
  947. // }
  948. // }
  949. // Thread.sleep(2000);
  950. // ids.clear();
  951. // }
  952. if (times%200==0){
  953. Thread.sleep(4000);
  954. }
  955. ydClient.operateData(YDParam.builder()
  956. .formUuid(formId)
  957. .searchCondition(JSON.toJSONString(UtilMap.map("textField_m3wp95ge",rs.getInt("id"))))
  958. .formDataJson(JSON.toJSONString(hashMap))
  959. .build(), YDConf.FORM_OPERATION.upsert);
  960. }
  961. //关闭资源
  962. ps.close();
  963. connection.close();
  964. } catch (SQLException e) {
  965. log.info("SQL执行错误");
  966. } catch (ClassNotFoundException e) {
  967. log.info("驱动注册失败");
  968. } catch (InterruptedException e) {
  969. throw new RuntimeException(e);
  970. }
  971. }
  972. }
  973. /**
  974. * 根据护理计划安排流程id逻辑删除数据库当月护理计划
  975. * @param formInstId 护理计划安排流程id
  976. */
  977. @Override
  978. public void deleteDatabaseInfo(String formInstId) {
  979. log.info("开始执行数据库更新到宜搭护理计划");
  980. try {
  981. Class.forName(driver);
  982. Connection connection = DriverManager.getConnection(url, username, password);
  983. PreparedStatement ps = null;
  984. // String deleteSql = "DELETE FROM`yida_plan_details` where data_month in ('" + dataMonth + "','"+nextDataMonth+"') AND form_inst_id = '"+formInstId+"' AND task_status = '待上报'";
  985. String deleteSql = "UPDATE `yida_plan_details` SET is_delete = 1 where data_month in ('" + dataMonth + "','"+nextDataMonth+"') AND form_inst_id = '"+formInstId+"' AND task_status = '待上报'";
  986. ps = connection.prepareStatement(deleteSql);
  987. ps.executeUpdate(deleteSql);
  988. ps.close();
  989. connection.close();
  990. } catch (SQLException e) {
  991. log.info("SQL执行错误");
  992. throw new RuntimeException(e);
  993. } catch (ClassNotFoundException e) {
  994. log.info("驱动注册失败");
  995. }
  996. }
  997. @SneakyThrows
  998. @Override
  999. public void deleteBothInfo() {
  1000. Connection connection = null;
  1001. PreparedStatement ps = null;
  1002. log.info("开始执行数据库更新到宜搭护理计划");
  1003. try {
  1004. Class.forName(driver);
  1005. connection = DriverManager.getConnection(url, username, password);
  1006. String selectSql = "SELECT `plan_inst_id` FROM`yida_plan_details` where is_delete = 1 ";
  1007. ps = connection.prepareStatement(selectSql);
  1008. ResultSet rs = ps.executeQuery(selectSql);
  1009. String deleteSql = "DELETE FROM`yida_plan_details` where is_delete = 1 ";
  1010. ps = connection.prepareStatement(deleteSql);
  1011. ps.executeUpdate();
  1012. while (rs.next()){
  1013. log.info("删除流程id:{}",rs.getString("plan_inst_id"));
  1014. //删除
  1015. ydClient.operateData(YDParam.builder()
  1016. .formInstanceId(rs.getString("plan_inst_id"))
  1017. .build(), YDConf.FORM_OPERATION.delete);
  1018. }
  1019. } catch (ClassNotFoundException | SQLException e) {
  1020. e.printStackTrace();
  1021. }finally {
  1022. connection.close();
  1023. ps.close();
  1024. }
  1025. }
  1026. /**
  1027. * 生成当月数据库未上报护理计划
  1028. * @param formInstId
  1029. */
  1030. @Override
  1031. public void thisMonthDataBase(String formInstId){
  1032. log.info("开始生成当月数据库未上报护理计划:{}",new Date());
  1033. //根据实例ID 查询护理计划
  1034. YDParam ydParam = YDParam.builder()
  1035. .formInstId(formInstId)
  1036. .build();
  1037. Map formData = ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_id).getFormData();
  1038. log.info("formData{}",formData);
  1039. List<Map> mapList = (List<Map>) formData.get("tableField_lo3pmohx");
  1040. //获取当前日期是本月几号
  1041. int dayOfMonth = currentDate.getDayOfMonth();
  1042. //获取本月天数
  1043. int daysInMonth = currentDate.lengthOfMonth();
  1044. try {
  1045. Class.forName(driver);
  1046. Connection connection = DriverManager.getConnection(url, username, password);
  1047. final PreparedStatement[] ps = {null};
  1048. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1049. String insertSql = "INSERT INTO `yida_plan_details`( `caregiver_form`, `caregiver_name`, `caregiver_member`, `caregiver_department`, " +
  1050. "`caregiver_card`, `caregiver_phone`, `department`, `care_object_form`, `care_object_name`, `care_object_card`, `care_object_level`, " +
  1051. "`care_object_address`, `care_object_longitude`, `care_object_latitude`, `within_the_week` , `care_start_time`, `care_end_time`, " +
  1052. "`execute_status`, `task_status`, `plan_id`, `care_object_id`, `certificate_type`, `is_choose`, `care_date_text` , `start_time_text` ," +
  1053. " `end_time_text` ,`form_inst_id`, `data_month`, `is_cogradient`, `start_time`, `end_time` ,`is_delete`) " +
  1054. "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?);";
  1055. ps[0] = connection.prepareStatement(insertSql);
  1056. for (int i = 0; i <= daysInMonth - dayOfMonth; i++) {
  1057. //获取当前日期是本月几号
  1058. //获取是周几
  1059. String dayOfWeek = currentDate.plusDays(i).getDayOfWeek().getDisplayName(TextStyle.FULL, new Locale("zh", "CN"));
  1060. //获取循环每天的日期
  1061. LocalDate nextDay = currentDate.plusDays(i);
  1062. List<Map> maps = mapList.stream().filter(item -> item.get("selectField_lo3pmohy").equals(dayOfWeek.replace("星期", "周"))).collect(Collectors.toList());
  1063. for (Map map : maps) {
  1064. // 创建Statement对象,用于执行SQL语句
  1065. ps[0].setObject(1, map.get("associationFormField_lo3pmohz_id").toString()); //护理人员名称(关联表单)
  1066. ps[0].setObject(2, JSONObject.parseObject(map.get("associationFormField_lo3pmohz_id").toString()).get("title")); //护理人员名称
  1067. ps[0].setObject(3, map.get("employeeField_lo3pmoi6_id")); //护理人员姓名-成员
  1068. ps[0].setObject(4, map.get("textField_lo3pmoi0")); //护理人员所属机构
  1069. ps[0].setObject(5, map.get("textField_lomchzi3")); //护理人员身份证
  1070. ps[0].setObject(6, map.get("textField_lo3pmoi3")); //护理人员手机号
  1071. if (formData.get("departmentSelectField_lxztlnnx_id") != null) {
  1072. ps[0].setObject(7, String.valueOf(formData.get("departmentSelectField_lxztlnnx_id"))); //部门
  1073. }
  1074. ps[0].setObject(8, map.get("associationFormField_lo3pmohw_id").toString()); //护理对象姓名(关联表单)
  1075. ps[0].setObject(9, formData.get("textField_lo55rupj")); //护理对象姓名-文本
  1076. ps[0].setObject(10, formData.get("textField_lnyhv5tn")); //护理对象身份证
  1077. ps[0].setObject(11, formData.get("selectField_lnyhv5tp")); //护理对象等级
  1078. ps[0].setObject(12, formData.get("textField_lnyhv5tr")); //护理对象住址
  1079. ps[0].setObject(13, formData.get("textField_lvae99fj")); //护理对象经度
  1080. ps[0].setObject(14, formData.get("textField_lvae99fk")); //护理对象纬度
  1081. ps[0].setObject(15, dayOfWeek.replace("星期", "周")); //护理时间 (星期几)
  1082. Date startDate = dateFormat.parse(String.valueOf(nextDay) + " " + map.get("selectField_lr1uxpu3") + ":00");
  1083. Date endDate = dateFormat.parse(String.valueOf(nextDay) + " " + map.get("selectField_lr1uxpu4") + ":00");
  1084. ps[0].setObject(16, startDate.getTime()); //护理开始时间。 用当前日期+护理计划的 时分 转成时间戳
  1085. ps[0].setObject(17, endDate.getTime()); //护理结束时间。 用当前日期+护理计划的 时分 转成时间戳
  1086. ps[0].setObject(18, "未执行"); //执行情况
  1087. ps[0].setObject(19, "待上报"); //任务状态
  1088. ps[0].setObject(20, map.get("textField_lo701pwy")); //计划明细id
  1089. ps[0].setObject(21, formData.get("textField_lop4v4qx")); //护理对象ID
  1090. ps[0].setObject(22, map.get("textField_lo3pmoi4")); //护理证书类型
  1091. ps[0].setObject(23, "是"); //是否可选
  1092. ps[0].setObject(24, String.valueOf(nextDay)); //护理日期-文本
  1093. ps[0].setObject(25, String.valueOf(nextDay) + " " + map.get("selectField_lr1uxpu3")); //护理开始时间。 用当前日期+护理计划的 时分
  1094. ps[0].setObject(26, String.valueOf(nextDay) + " " + map.get("selectField_lr1uxpu4")); //护理结束时间。 用当前日期+护理计划的 时分
  1095. ps[0].setObject(27, map.get("formInstanceId").toString()); //护理结束时间。 用当前日期+护理计划的 时分
  1096. ps[0].setObject(28, dataMonth); //当月数据日期
  1097. ps[0].setObject(29, "否"); //是否已同步宜搭
  1098. ps[0].setObject(30,map.get("selectField_lr1uxpu3"));
  1099. ps[0].setObject(31,map.get("selectField_lr1uxpu4"));
  1100. ps[0].setObject(32,0);
  1101. // 执行SQL查询
  1102. ps[0].addBatch();
  1103. }
  1104. }
  1105. } catch (SQLException e) {
  1106. throw new RuntimeException(e);
  1107. } catch (ClassNotFoundException e) {
  1108. throw new RuntimeException(e);
  1109. } catch (ParseException e) {
  1110. throw new RuntimeException(e);
  1111. }
  1112. }
  1113. /**
  1114. * 生成当月宜搭未上报护理计划
  1115. * @param formInstId
  1116. */
  1117. public void thisMonthDataBaseToYiDa(String formInstId){
  1118. log.info("开始生成当月和下月宜搭未上报护理计划");
  1119. String formId = getFormId(dataMonth);
  1120. Connection connection = null;
  1121. PreparedStatement ps = null;
  1122. log.info("开始执行数据库更新到宜搭护理计划");
  1123. try {
  1124. Class.forName(driver);
  1125. connection = DriverManager.getConnection(url, username, password);
  1126. String selectSql = "SELECT `id`, `caregiver_form`,`caregiver_name`,`caregiver_member`,`caregiver_department`,`caregiver_card`," +
  1127. "`caregiver_phone`,`department`,`care_object_form`,`care_object_name`,`care_object_card`,`care_object_level`," +
  1128. "`care_object_address`,`care_object_longitude`,`care_object_latitude`,`within_the_week`,`care_start_time`," +
  1129. "`care_end_time`,`execute_status`,`task_status`,`plan_id`,`care_object_id`,`certificate_type`,`is_choose`," +
  1130. "`care_date_text`,`start_time_text`,`end_time_text` FROM`yida_plan_details` " +
  1131. "WHERE data_month IN ('" + dataMonth + "','" + nextDataMonth + "') AND is_cogradient = '否' AND form_inst_id = '"+formInstId+"'";
  1132. ps = connection.prepareStatement(selectSql);
  1133. ResultSet rs = ps.executeQuery(selectSql);
  1134. List<Integer> ids = new ArrayList<Integer>();
  1135. while (rs.next()){
  1136. Map hashMap = new HashMap();
  1137. hashMap.put("associationFormField_lo3pmohz", JSON.parse(rs.getString("caregiver_form"))); //护理人员名称
  1138. hashMap.put("textField_lo3pmoi0", rs.getString( "caregiver_department")); //护理人员所属机构
  1139. hashMap.put("textField_lombve2g", rs.getString("caregiver_card")); //护理人员身份证
  1140. hashMap.put("textField_lo3pmoi3", rs.getString("caregiver_phone")); //护理人员手机号
  1141. hashMap.put("associationFormField_lo3pmohw", JSON.parse(rs.getString("care_object_form"))); //护理对象姓名
  1142. hashMap.put("textField_lnyhv5tn", rs.getString("care_object_card")); //护理对象身份证
  1143. hashMap.put("selectField_lnyhv5tp", rs.getString("care_object_level")); //护理对象等级
  1144. hashMap.put("textField_lnyhv5tr", rs.getString("care_object_address")); //护理对象住址
  1145. hashMap.put("selectField_lo3pmohy",rs.getString("within_the_week")); //护理时间 (星期几)
  1146. hashMap.put("dateField_lred6eoj", rs.getString("care_start_time")); //护理开始时间。 用当前日期+护理计划的 时分 转成时间戳
  1147. hashMap.put("dateField_lred6eok", rs.getString("care_end_time")); //护理结束时间。 用当前日期+护理计划的 时分 转成时间戳
  1148. hashMap.put("selectField_lqcgsbw2", "未执行"); //执行情况
  1149. hashMap.put("selectField_lo56u5fn", "待上报"); //任务状态
  1150. hashMap.put("textField_lvae7q5n", rs.getString("care_object_longitude")); //护理对象经度
  1151. hashMap.put("textField_lvae7q5o", rs.getString("care_object_latitude")); //护理对象纬度
  1152. hashMap.put("textField_lrx0r38x", rs.getString("care_date_text")); //护理日期-文本
  1153. hashMap.put("selectField_lr36z6hd", "是"); //任务状态
  1154. hashMap.put("textField_lo55rupj", rs.getString("care_object_name")); //护理对象姓名-文本
  1155. hashMap.put("textField_lo3pmoi4", rs.getString("certificate_type")); //护理证书类型
  1156. hashMap.put("employeeField_lo3pmoi6", JSON.parse(rs.getString("caregiver_member"))); //护理人员姓名-成员
  1157. hashMap.put("textField_lpgi8scj", rs.getString("plan_id")); //计划明细id
  1158. hashMap.put("textField_lq9llmhl", rs.getString("care_object_id")); //护理对象ID
  1159. if (rs.getString("department") != null) {
  1160. hashMap.put("departmentSelectField_lxzto1e1", rs.getString("department")); //部门
  1161. }
  1162. hashMap.put("textField_m3wp95ge",rs.getInt("id"));//数据库id
  1163. ids.add(rs.getInt("id"));
  1164. ydClient.operateData(YDParam.builder()
  1165. .formUuid(formId)
  1166. .formDataJson(JSON.toJSONString(hashMap))
  1167. .build(), YDConf.FORM_OPERATION.create);
  1168. }
  1169. if (ObjectUtil.isNotNull(ids)&&ids.size()>0){
  1170. for (int i = 0; i < ids.size(); i++) {
  1171. YDParam ydParam = YDParam.builder()
  1172. .formUuid("FORM-RK966E7105DFD27FA7EQHAOH9IFS2RN6MP3OL2")
  1173. .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_m3wp95ge",ids.get(i))))
  1174. .build();
  1175. List<Map> dataList = (List<Map>) ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getData();
  1176. if(dataList.size()>0){
  1177. Map map = (Map) dataList.get(0);
  1178. String updateSql = "UPDATE `yida_plan_details` SET is_cogradient = '是', plan_inst_id = '"+map.get("formInstanceId")+"'" +
  1179. " where data_month IN ('" + dataMonth + "','" + nextDataMonth + "') AND is_cogradient = '否' AND id = '" + ids.get(i) + "'";
  1180. ps = connection.prepareStatement(updateSql);
  1181. ps.executeUpdate();
  1182. }
  1183. }
  1184. }
  1185. //关闭资源
  1186. ps.close();
  1187. connection.close();
  1188. } catch (SQLException e) {
  1189. log.info("SQL执行错误");
  1190. } catch (ClassNotFoundException e) {
  1191. log.info("驱动注册失败");
  1192. }
  1193. }
  1194. @Override
  1195. public void updateFromClock(Map<String, Object> data) {
  1196. Plan plan = new Plan();
  1197. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1198. String id = data.get("id").toString();
  1199. UpdateWrapper<Plan> updateWrapper = new UpdateWrapper<>();
  1200. updateWrapper.eq("id",id);
  1201. List<Map<String,Object>> image = (List<Map<String, Object>>) data.get("imageField_lp7obkee");
  1202. String remoteUrl = "https://xvuk8m.aliwork.com" + image.get(0).get("previewUrl");
  1203. String fileName = image.get(0).get("name").toString();
  1204. String downLoad = image.get(0).get("downloadUrl").toString();
  1205. // downloadFile(remoteUrl,localUrl+fileName);
  1206. Date date = new Date(Long.parseLong(data.get("dateField_lp7obkef").toString()));
  1207. Map<String, Object> updateMap = new HashMap<>();
  1208. if ("签到".equals(data.get("textField_lqoldqro"))){
  1209. plan.setSignInLongitude(data.get("textField_lu2ewbl7").toString());//签到经度
  1210. plan.setSignInLatitude(data.get("textField_lu2ewbl8").toString());//签到维度
  1211. plan.setSignInTime(Long.parseLong(data.get("dateField_lp7obkef").toString()));//签到时间
  1212. plan.setSignInPosition(data.get("textField_lrr62xq6").toString());//签到位置信息
  1213. plan.setExecuteStatus("执行中");
  1214. plan.setClockInDate(dateFormat.format(date));//打卡时间文本
  1215. plan.setSignInPhoto(remoteUrl);
  1216. plan.setSignInPhotoName(fileName);
  1217. plan.setSignInPhotoDown(downLoad);
  1218. plan.setSignInDistance(data.get("numberField_luw22bp4").toString());
  1219. updateMap.put("textField_ljghmc0e",data.get("textField_lu2ewbl7"));
  1220. updateMap.put("textField_ljghmc0f",data.get("textField_lu2ewbl8"));
  1221. updateMap.put("dateField_lp7obkef",data.get("dateField_lp7obkef"));
  1222. updateMap.put("textField_lrr62xq6",data.get("textField_lrr62xq6"));
  1223. updateMap.put("selectField_lqcgsbw2",data.get("执行中"));
  1224. updateMap.put("imageField_lrq19cti",data.get("imageField_lp7obkee"));
  1225. updateMap.put("numberField_lv4mhawr",data.get("numberField_luw22bp4"));
  1226. } else if ("签退".equals(data.get("textField_lqoldqro"))) {
  1227. plan.setSignOutLongitude(data.get("textField_lu2ewbl7").toString());//签到经度
  1228. plan.setSignOutLatitude(data.get("textField_lu2ewbl8").toString());//签到维度
  1229. plan.setSignOutTime(Long.parseLong(data.get("dateField_lp7obkef").toString()));//签到时间
  1230. plan.setSignOutPosition(data.get("textField_lrr62xq6").toString());//签到位置信息
  1231. plan.setExecuteStatus("已完成");
  1232. plan.setClockOutDate(dateFormat.format(date));//打卡时间文本
  1233. plan.setSignOutPhoto(remoteUrl);
  1234. plan.setSignInPhotoName(fileName);
  1235. plan.setSignInPhotoDown(downLoad);
  1236. plan.setSignOutDistance(data.get("numberField_luw22bp4").toString());
  1237. updateMap.put("textField_lr36z6h6",data.get("textField_lu2ewbl7"));
  1238. updateMap.put("textField_lr36z6h8",data.get("textField_lu2ewbl8"));
  1239. updateMap.put("dateField_lr36z6ha",data.get("dateField_lp7obkef"));
  1240. updateMap.put("textField_lrreodfe",data.get("textField_lrr62xq6"));
  1241. updateMap.put("selectField_lqcgsbw2",data.get("已完成"));
  1242. updateMap.put("imageField_lt893c3q",data.get("imageField_lp7obkee"));
  1243. updateMap.put("numberField_lv4mhawi",data.get("numberField_luw22bp4"));
  1244. }
  1245. if (data.containsKey("planInstId")){
  1246. String planInstId = data.get("planInstId").toString();
  1247. ydClient.operateData(YDParam.builder()
  1248. .formInstanceId(planInstId)
  1249. .updateFormDataJson(JSON.toJSONString(updateMap))
  1250. .useLatestVersion(true)
  1251. .build(), YDConf.FORM_OPERATION.update);
  1252. }else {
  1253. plan.setIsCogradient("否");
  1254. }
  1255. planMapper.update(plan,updateWrapper);
  1256. }
  1257. @Override
  1258. public void updateDBStatus() {
  1259. String date = DateUtil.date().toString("yyyy-MM-dd");
  1260. UpdateWrapper<Plan> updateWrapper = new UpdateWrapper<>();
  1261. updateWrapper.eq("care_date_text",date);
  1262. Plan plan = new Plan();
  1263. plan.setTaskStatus("已上报");
  1264. planMapper.update(plan,updateWrapper);
  1265. }
  1266. @Override
  1267. public void deleteClockIn() {
  1268. long time = DateUtil.offsetDay(DateUtil.date(), -30).getTime();
  1269. List<String> dateList = new ArrayList<>();
  1270. dateList.add(null);
  1271. dateList.add(String.valueOf(time));
  1272. YDParam ydParam = YDParam.builder()
  1273. .appType("APP_YIDJ71B8QORD2YHNZ26Q")
  1274. .systemToken("RH766AC1707FCUZQAKET09YV8I8K3VZA1GVNLN2")
  1275. .formUuid("FORM-1683937473624B108E28436FB8A06129K78N")
  1276. .searchFieldJson(JSON.toJSONString(UtilMap.map("dateField_lp7obkef", dateList)))
  1277. .build();
  1278. List<Map> allList = ydService.queryFormData_all(ydParam);
  1279. allList.forEach(e->{
  1280. ydClient.operateData(YDParam.builder()
  1281. .formInstanceId(e.get("formInstanceId").toString())
  1282. .build(), YDConf.FORM_OPERATION.delete);
  1283. });
  1284. }
  1285. @Override
  1286. public String getFormId(String month){
  1287. log.info("获取{}表单id",month);
  1288. YDParam ydParamDelete = YDParam.builder()
  1289. .formUuid("FORM-E22142AB07F643C4A9E2EA3A5A48B3C9RUH8")
  1290. .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_m3wgvuuu",month)))
  1291. .build();
  1292. List<Map> allFormData = ydService.queryFormData_all(ydParamDelete);
  1293. if (ObjectUtil.isNotNull(allFormData) && allFormData.size() > 0){
  1294. log.info("当月{}表单id为:{}",month,allFormData.get(0).get("textField_m3wgvuuv"));
  1295. return allFormData.get(0).get("textField_m3wgvuuv").toString();
  1296. }else {
  1297. log.info("未获取到{}月份对应的表单id,请检查护理计划配置表",month);
  1298. return null;
  1299. }
  1300. }
  1301. /**
  1302. * 每天同步护理状态
  1303. */
  1304. @Override
  1305. public void syncUpdatePlanStatus() {
  1306. log.info("每天同步护理状态开始{}", new Date());
  1307. syncPlanStatus();
  1308. log.info("每天同步护理状态结束{}", new Date());
  1309. }
  1310. /**
  1311. * 不同上报状态 定时任务每天执行
  1312. */
  1313. @SneakyThrows
  1314. public void syncPlanStatus() {
  1315. LocalDate currentDate = LocalDate.now();
  1316. //获取需要更新的护理任务 护理日期是当天 且状态为未上报
  1317. YDParam ydParam = YDParam.builder()
  1318. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  1319. .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")))))
  1320. .build();
  1321. //pagesize设为1获取总数
  1322. ydParam.setPageSize(1);
  1323. long totalCount = ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getTotalCount();
  1324. log.info("totalCount{}",totalCount);
  1325. //如果条数不为0 就一直递归
  1326. if (totalCount>0){
  1327. ydParam.setPageSize(50);
  1328. List<Map> dataList = new ArrayList<>();
  1329. dataList = (List<Map>) ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getData();
  1330. log.info("dataList:{}",dataList.size());
  1331. //循环处理修改状态为已上报
  1332. dataList.forEach(item -> {
  1333. //修改状态为已上报
  1334. try {
  1335. ydClient.operateData(YDParam.builder()
  1336. .formInstanceId(item.get("formInstanceId").toString())
  1337. .updateFormDataJson(JSON.toJSONString(UtilMap.map("selectField_lo56u5fn","已上报")))
  1338. .useLatestVersion(true)
  1339. .build(), YDConf.FORM_OPERATION.update);
  1340. } catch (Exception e) {
  1341. log.info("异常流程ID为:{}",item.get("formInstanceId").toString());
  1342. e.printStackTrace();
  1343. }
  1344. });
  1345. Thread.sleep(5000);
  1346. syncUpdatePlanStatus();
  1347. }
  1348. }
  1349. /**
  1350. * 新增护理计划1条 生成本月护理数据
  1351. * @param formInstId
  1352. */
  1353. @Override
  1354. public void creatInfo(String formInstId){
  1355. log.info("新增护理计划:{}",new Date());
  1356. //根据实例ID 查询护理计划
  1357. log.info("护理计划安排ID:{}",formInstId);
  1358. YDParam ydParam = YDParam.builder()
  1359. .formInstId(formInstId)
  1360. .build();
  1361. Map formData = ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_id).getFormData();
  1362. log.info("formData{}",formData);
  1363. List<Map> mapList = (List<Map>) formData.get("tableField_lo3pmohx");
  1364. LocalDate currentDate = LocalDate.now();
  1365. //获取当前日期是本月几号
  1366. int dayOfMonth = currentDate.getDayOfMonth();
  1367. //获取本月天数
  1368. int daysInMonth = currentDate.lengthOfMonth();
  1369. for (int i = 0; i <=daysInMonth-dayOfMonth ; i++) {
  1370. //获取当前日期是本月几号
  1371. LocalDate currentDay = LocalDate.now();
  1372. //获取是周几
  1373. String dayOfWeek = currentDay.plusDays(i).getDayOfWeek().getDisplayName(TextStyle.FULL, new Locale("zh", "CN"));
  1374. //获取循环每天的日期
  1375. LocalDate nextDay = currentDate.plusDays(i);
  1376. List<Map> maps = mapList.stream().filter(item -> item.get("selectField_lo3pmohy").equals(dayOfWeek.replace("星期","周"))).collect(Collectors.toList());
  1377. for (Map map : maps) {
  1378. //通过护理时间 护理对象ID 证数据是否已经存在
  1379. YDParam ydParam1 = YDParam.builder()
  1380. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  1381. .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"))))
  1382. .build();
  1383. List<Map> dataList = (List<Map>) ydClient.queryData(ydParam1, YDConf.FORM_QUERY.retrieve_search_form).getData();
  1384. //如果已存在数据 则不新增
  1385. if (1>dataList.size()){
  1386. Map hashMap = new HashMap();
  1387. hashMap.put("associationFormField_lo3pmohz",JSON.parse(map.get("associationFormField_lo3pmohz_id").toString())); //护理人员名称
  1388. hashMap.put("textField_lo3pmoi0",map.get("textField_lo3pmoi0")); //护理人员所属机构
  1389. hashMap.put("textField_lombve2g",map.get("textField_lomchzi3")); //护理人员身份证
  1390. hashMap.put("textField_lo3pmoi3",map.get("textField_lo3pmoi3")); //护理人员手机号
  1391. hashMap.put("associationFormField_lo3pmohw",JSON.parse(formData.get("associationFormField_lo3pmohw_id").toString())); //护理对象姓名
  1392. hashMap.put("textField_lnyhv5tn",formData.get("textField_lnyhv5tn")); //护理对象身份证
  1393. hashMap.put("selectField_lnyhv5tp",formData.get("selectField_lnyhv5tp")); //护理对象等级
  1394. hashMap.put("textField_lnyhv5tr",formData.get("textField_lnyhv5tr")); //护理对象住址
  1395. hashMap.put("selectField_lo3pmohy",dayOfWeek.replace("星期","周")); //护理时间 (星期几)
  1396. hashMap.put("dateField_lred6eoj", UtilDateTime.parse(String.valueOf(nextDay)+" "+map.get("selectField_lr1uxpu3"),"yyyy-MM-dd HH:mm")); //护理开始时间。 用当前日期+护理计划的 时分 转成时间戳
  1397. hashMap.put("dateField_lred6eok",UtilDateTime.parse(String.valueOf(nextDay)+" "+map.get("selectField_lr1uxpu4"),"yyyy-MM-dd HH:mm")); //护理结束时间。 用当前日期+护理计划的 时分 转成时间戳
  1398. hashMap.put("selectField_lqcgsbw2","未执行"); //执行情况
  1399. hashMap.put("selectField_lo56u5fn","待上报"); //任务状态
  1400. hashMap.put("textField_lvae7q5n",formData.get("textField_lvae99fj")); //护理对象经度
  1401. hashMap.put("textField_lvae7q5o",formData.get("textField_lvae99fk")); //护理对象纬度
  1402. hashMap.put("textField_lrx0r38x",String.valueOf(nextDay)); //护理日期-文本
  1403. hashMap.put("selectField_lr36z6hd","是"); //任务状态
  1404. hashMap.put("textField_lo55rupj",formData.get("textField_lo55rupj")); //护理对象姓名-文本
  1405. hashMap.put("textField_lo3pmoi4",map.get("textField_lo3pmoi4")); //护理证书类型
  1406. hashMap.put("employeeField_lo3pmoi6",map.get("employeeField_lo3pmoi6_id")); //护理人员姓名-成员
  1407. hashMap.put("textField_lpgi8scj",map.get("textField_lo701pwy")); //计划明细id
  1408. hashMap.put("textField_lq9llmhl",formData.get("textField_lop4v4qx")); //护理对象ID
  1409. if (formData.get("departmentSelectField_lxztlnnx_id")!=null){
  1410. hashMap.put("departmentSelectField_lxzto1e1",String.valueOf(formData.get("departmentSelectField_lxztlnnx_id"))); //部门
  1411. }
  1412. try {
  1413. ydClient.operateData(YDParam.builder()
  1414. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  1415. .formDataJson(JSON.toJSONString(hashMap))
  1416. .build(), YDConf.FORM_OPERATION.create);
  1417. } catch (Exception e) {
  1418. log.info("定时任务创建计划失败:{}",e);
  1419. }
  1420. }
  1421. }
  1422. }
  1423. }
  1424. /**
  1425. * 新增护理计划下月月数据
  1426. * @param formInstId
  1427. */
  1428. @Override
  1429. public void creatNextInfo(String formInstId) {
  1430. log.info("新增护理计划下月数据",new Date());
  1431. //根据实例ID 查询护理计划
  1432. YDParam ydParam = YDParam.builder()
  1433. .formInstId(formInstId)
  1434. .build();
  1435. Map formData = ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_id).getFormData();
  1436. List<Map> mapList = (List<Map>) formData.get("tableField_lo3pmohx");
  1437. LocalDate currentDate = LocalDate.now();
  1438. //获取下月1号的日期
  1439. LocalDate firstDayOfNextMonth = currentDate.plusMonths(1).with(TemporalAdjusters.firstDayOfMonth());
  1440. //获取下月1号
  1441. int dayOfMonth = firstDayOfNextMonth.getDayOfMonth();
  1442. //获取下月月天数
  1443. int daysInMonth = firstDayOfNextMonth.lengthOfMonth();
  1444. for (int i = 0; i <=daysInMonth-dayOfMonth ; i++) {
  1445. //获取是周几
  1446. String dayOfWeek = firstDayOfNextMonth.plusDays(i).getDayOfWeek().getDisplayName(TextStyle.FULL, new Locale("zh", "CN"));
  1447. //获取循环每天的日期
  1448. LocalDate nextDay = firstDayOfNextMonth.plusDays(i);
  1449. List<Map> maps = mapList.stream().filter(item -> item.get("selectField_lo3pmohy").equals(dayOfWeek.replace("星期","周"))).collect(Collectors.toList());
  1450. for (Map map : maps) {
  1451. Map hashMap = new HashMap();
  1452. hashMap.put("associationFormField_lo3pmohz",JSON.parse(map.get("associationFormField_lo3pmohz_id").toString())); //护理人员名称
  1453. hashMap.put("textField_lo3pmoi0",map.get("textField_lo3pmoi0")); //护理人员所属机构
  1454. hashMap.put("textField_lombve2g",map.get("textField_lomchzi3")); //护理人员身份证
  1455. hashMap.put("textField_lo3pmoi3",map.get("textField_lo3pmoi3")); //护理人员手机号
  1456. hashMap.put("associationFormField_lo3pmohw",JSON.parse(formData.get("associationFormField_lo3pmohw_id").toString())); //护理对象姓名
  1457. hashMap.put("textField_lnyhv5tn",formData.get("textField_lnyhv5tn")); //护理对象身份证
  1458. hashMap.put("selectField_lnyhv5tp",formData.get("selectField_lnyhv5tp")); //护理对象等级
  1459. hashMap.put("textField_lnyhv5tr",formData.get("textField_lnyhv5tr")); //护理对象住址
  1460. hashMap.put("selectField_lo3pmohy",dayOfWeek.replace("星期","周")); //护理时间 (星期几)
  1461. hashMap.put("dateField_lred6eoj", UtilDateTime.parse(String.valueOf(nextDay)+" "+map.get("selectField_lr1uxpu3"),"yyyy-MM-dd HH:mm")); //护理开始时间。 用当前日期+护理计划的 时分 转成时间戳
  1462. hashMap.put("dateField_lred6eok",UtilDateTime.parse(String.valueOf(nextDay)+" "+map.get("selectField_lr1uxpu4"),"yyyy-MM-dd HH:mm")); //护理结束时间。 用当前日期+护理计划的 时分 转成时间戳
  1463. hashMap.put("selectField_lqcgsbw2","未执行"); //执行情况
  1464. hashMap.put("selectField_lo56u5fn","待上报"); //任务状态
  1465. hashMap.put("textField_lvae7q5n",formData.get("textField_lvae99fj")); //护理对象经度
  1466. hashMap.put("textField_lvae7q5o",formData.get("textField_lvae99fk")); //护理对象纬度
  1467. hashMap.put("textField_lrx0r38x",String.valueOf(nextDay)); //护理日期-文本
  1468. hashMap.put("selectField_lr36z6hd","是"); //任务状态
  1469. hashMap.put("textField_lo55rupj",formData.get("textField_lo55rupj")); //护理对象姓名-文本
  1470. hashMap.put("textField_lo3pmoi4",map.get("textField_lo3pmoi4")); //护理证书类型
  1471. hashMap.put("employeeField_lo3pmoi6",map.get("employeeField_lo3pmoi6_id")); //护理人员姓名-成员
  1472. hashMap.put("textField_lpgi8scj",map.get("textField_lo701pwy")); //计划明细id
  1473. hashMap.put("textField_lq9llmhl",formData.get("textField_lop4v4qx")); //护理对象ID
  1474. if (formData.get("departmentSelectField_lxztlnnx_id")!=null){
  1475. hashMap.put("departmentSelectField_lxzto1e1",String.valueOf(formData.get("departmentSelectField_lxztlnnx_id"))); //部门
  1476. }
  1477. try {
  1478. ydClient.operateData(YDParam.builder()
  1479. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  1480. .formDataJson(JSON.toJSONString(hashMap))
  1481. .build(), YDConf.FORM_OPERATION.create);
  1482. } catch (Exception e) {
  1483. log.info("定时任务创建计划失败:{}",e);
  1484. }
  1485. }
  1486. }
  1487. }
  1488. /**
  1489. * 编辑功能只做删除操作
  1490. * @param formInstId
  1491. */
  1492. @SneakyThrows
  1493. @Override
  1494. // @Async
  1495. public void updateInfo(String formInstId) {
  1496. //根据实例ID 查询护理计划
  1497. YDParam ydParam = YDParam.builder()
  1498. .formInstId(formInstId)
  1499. .build();
  1500. Map formData = ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_id).getFormData();
  1501. LocalDate currentDate = LocalDate.now();
  1502. //获取下月1号的日期
  1503. LocalDate firstDayOfNextMonth = currentDate.plusMonths(1).with(TemporalAdjusters.firstDayOfMonth());
  1504. //删除当前时间节点以后得数据
  1505. //获取需要更新的护理任务 状态为待上报 护理对象身份证 护理日期是当天
  1506. YDParam ydParamDelete = YDParam.builder()
  1507. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  1508. .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")))))
  1509. .build();
  1510. List<Map> queryAllFormData = ydService.queryAllFormData(ydParamDelete);
  1511. queryAllFormData.forEach(item -> {
  1512. log.info("删除",item.get("dateField_lred6eoj"));
  1513. //删除
  1514. ydClient.operateData(YDParam.builder()
  1515. .formInstanceId(item.get("formInstanceId").toString())
  1516. .build(), YDConf.FORM_OPERATION.delete);
  1517. });
  1518. }
  1519. /**
  1520. * 删除护理任务
  1521. * @param cId 护理对象身份证
  1522. */
  1523. @Override
  1524. public void deletePlan(String cId) {
  1525. LocalDate currentDate = LocalDate.now();
  1526. //获取下月1号的日期
  1527. LocalDate firstDayOfNextMonth = currentDate.plusMonths(1).with(TemporalAdjusters.firstDayOfMonth());
  1528. //获取需要删除护理任务 执行状态为未执行 护理对象身份证 护理日期是当天以后
  1529. YDParam ydParamDelete = YDParam.builder()
  1530. .formUuid("FORM-IY966L71PJ8FV10D61M1HBHU6FB320M2765OLM")
  1531. .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")))))
  1532. .build();
  1533. List<Map> mapList = ydService.queryAllFormData(ydParamDelete);
  1534. //删除当前时间节点以后得数据
  1535. mapList.forEach(item -> {
  1536. //删除
  1537. ydClient.operateData(YDParam.builder()
  1538. .formInstanceId(item.get("formInstanceId").toString())
  1539. .build(), YDConf.FORM_OPERATION.delete);
  1540. });
  1541. }
  1542. /**
  1543. 2 * TODO 下载文件到本地
  1544. 3 * @author nadim
  1545. 4 * @date Sep 11, 2015 11:45:31 AM
  1546. 5 * @param fileUrl 远程浏览地址
  1547. 6 * @param fileLocal 本地路径
  1548. 7 * @throws Exception
  1549. 8 */
  1550. public void downloadFile(String fileUrl,String fileLocal) {
  1551. try {
  1552. URL url = new URL(fileUrl);
  1553. HttpURLConnection urlCon = (HttpURLConnection) url.openConnection();
  1554. urlCon.setConnectTimeout(6000);
  1555. urlCon.setReadTimeout(6000);
  1556. int code = urlCon.getResponseCode();
  1557. if (code != HttpURLConnection.HTTP_OK) {
  1558. throw new Exception("文件读取失败");
  1559. }
  1560. //读文件流
  1561. InputStream in = new DataInputStream(urlCon.getInputStream());
  1562. OutputStream out = new DataOutputStream(Files.newOutputStream(Paths.get(fileLocal)));
  1563. byte[] buffer = new byte[2048];
  1564. int count = 0;
  1565. while ((count = in.read(buffer)) > 0) {
  1566. out.write(buffer, 0, count);
  1567. }
  1568. out.close();
  1569. in.close();
  1570. } catch (IOException e) {
  1571. log.info("读写文件异常");
  1572. e.printStackTrace();
  1573. } catch (Exception e) {
  1574. log.info("处理文件异常");
  1575. e.printStackTrace();
  1576. }
  1577. }
  1578. }