LISServiceImpl.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. package com.jyxt.getdatabyrestful.service.impl;
  2. import com.jyxt.getdatabyrestful.service.LISService;
  3. import org.slf4j.Logger;
  4. import org.slf4j.LoggerFactory;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.beans.factory.annotation.Qualifier;
  7. import org.springframework.jdbc.core.JdbcTemplate;
  8. import org.springframework.jdbc.core.SqlOutParameter;
  9. import org.springframework.jdbc.core.SqlParameter;
  10. import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
  11. import org.springframework.jdbc.core.simple.SimpleJdbcCall;
  12. import org.springframework.stereotype.Service;
  13. import org.springframework.util.StringUtils;
  14. import java.sql.Types;
  15. import java.util.ArrayList;
  16. import java.util.HashMap;
  17. import java.util.List;
  18. import java.util.Map;
  19. @Service
  20. public class LISServiceImpl implements LISService {
  21. private static final Logger log = LoggerFactory.getLogger(LISServiceImpl.class);
  22. @Autowired
  23. @Qualifier("secondJdbcTemplate")
  24. private JdbcTemplate jdbcTemplate;
  25. public static List<Map<String, Object>> testList = new ArrayList<>();
  26. public List<Map<String, Object>> GetGroupConfig() {
  27. // //----------以下为测试用----------
  28. // // 1. 创建最外层的List
  29. // List<Map<String, Object>> list = new ArrayList<>();
  30. // // 2. 创建内层Map
  31. // Map<String, Object> map = new HashMap<>(); // 保持插入顺序
  32. // // 3. 向Map中添加数据
  33. // map.put("SORTID", "001");
  34. // map.put("GROUPCODE", "G002");
  35. // map.put("GROUPNAME", "茂源生化");
  36. // map.put("SAVEDAY", "7");
  37. // map.put("OPRATIONTYPE", "直接转交公司统一焚烧");
  38. // list.add(map);
  39. // Map<String, Object> map2 = new HashMap<>(); // 保持插入顺序
  40. // // 3. 向Map中添加数据
  41. // map2.put("SORTID", "002");
  42. // map2.put("GROUPCODE", "G004");
  43. // map2.put("GROUPNAME", "茂源免疫");
  44. // map2.put("SAVEDAY", "14");
  45. // map2.put("OPRATIONTYPE", "直接转交公司统一焚烧");
  46. // list.add(map2);
  47. //
  48. // Map<String, Object> map3 = new HashMap<>(); // 保持插入顺序
  49. // // 3. 向Map中添加数据
  50. // map3.put("SORTID", "003");
  51. // map3.put("GROUPCODE", "G032");
  52. // map3.put("GROUPNAME", "茂源临检");
  53. // map3.put("SAVEDAY", "7");
  54. // map3.put("OPRATIONTYPE", "灭菌后转交公司统一焚烧");
  55. // list.add(map3);
  56. // return list;
  57. // //----------以上为测试用----------
  58. List<Map<String, Object>> resultList = null;
  59. String SqlQry = "select SORTID,GROUPCODE,GROUPNAME,SAVEDAY,OPRATIONTYPE from v_jt_lisgroupcustom";
  60. log.info("excute sql:"+SqlQry);
  61. resultList = jdbcTemplate.queryForList(SqlQry);
  62. return resultList;
  63. }
  64. public List<Map<String, Object>> GetSampleList(List<Map<String, Object>> inputList){
  65. // //----------以下为测试用----------
  66. // // 1. 创建最外层的List
  67. // List<Map<String, Object>> list = new ArrayList<>();
  68. // // 2. 创建内层Map
  69. // Map<String, Object> map = new HashMap<>(); // 保持插入顺序
  70. // // 3. 向Map中添加数据
  71. // map.put("STATE", "1");
  72. // map.put("SAVE_DATE", "20250720");
  73. // map.put("INSPECTION_ID", "20250720G0364061112");
  74. // map.put("PATIENT_NAME", "赵春香11");
  75. // map.put("TEST_ORDER_NAME", "血常规11");
  76. // map.put("DESTROY_DATE", "20250727");
  77. // list.add(map);
  78. // Map<String, Object> map2 = new HashMap<>(); // 保持插入顺序
  79. // // 3. 向Map中添加数据
  80. // map2.put("STATE", "1");
  81. // map2.put("SAVE_DATE", "20250720");
  82. // map2.put("INSPECTION_ID", "20250720G036123124062");
  83. // map2.put("PATIENT_NAME", "赵春香22");
  84. // map2.put("TEST_ORDER_NAME", "血常规22");
  85. // map2.put("DESTROY_DATE", "20250727");
  86. // list.add(map2);
  87. //
  88. // Map<String, Object> map3 = new HashMap<>(); // 保持插入顺序
  89. // // 3. 向Map中添加数据
  90. // map3.put("STATE", "1");
  91. // map3.put("SAVE_DATE", "20250720");
  92. // map3.put("INSPECTION_ID", "2020G03123312364062");
  93. // map3.put("PATIENT_NAME", "赵春香33");
  94. // map3.put("TEST_ORDER_NAME", "血常规33");
  95. // map3.put("DESTROY_DATE", "20250727");
  96. // list.add(map3);
  97. // return list;
  98. // //----------以上为测试用----------
  99. List<Map<String, Object>> resultList = new ArrayList<>();
  100. for(Map<String, Object> inputMap : inputList) {
  101. if (!inputMap.containsKey("STATE") || inputMap.get("STATE") == null) {
  102. continue;
  103. }
  104. StringBuilder sql = new StringBuilder(
  105. "select STATE,SAVE_DATE,DESTROY_DATE,INSPECTION_ID,PATIENT_NAME,TEST_ORDER_NAME from V_JT_SAVEANDDESTROY where ");
  106. // 处理STATE参数(可能为单个值或多个值)
  107. String stateValue = inputMap.get("STATE").toString();
  108. if (stateValue.contains(",")) {
  109. String[] states = stateValue.split(",");
  110. sql.append("STATE IN (");
  111. for (int i = 0; i < states.length; i++) {
  112. sql.append("'").append(states[i].trim()).append("'");
  113. if (i < states.length - 1) {
  114. sql.append(",");
  115. }
  116. }
  117. sql.append(")");
  118. } else {
  119. sql.append("STATE = '").append(stateValue).append("'");
  120. }
  121. // 处理其他查询条件
  122. if (inputMap.containsKey("SAVE_DATE") && inputMap.get("SAVE_DATE") != null) {
  123. sql.append(" AND SAVE_DATE = '").append(inputMap.get("SAVE_DATE")).append("'");
  124. }
  125. // if (inputMap.containsKey("DESTROY_DATE") && inputMap.get("DESTROY_DATE") != null) {
  126. // sql.append(" AND DESTROY_DATE = '").append(inputMap.get("DESTROY_DATE")).append("'");
  127. // }
  128. if (inputMap.containsKey("GROUPCODE") && inputMap.get("GROUPCODE") != null) {
  129. sql.append(" AND GROUPCODE = '").append(inputMap.get("GROUPCODE")).append("'");
  130. }
  131. if (inputMap.containsKey("INSPECTION_ID") && inputMap.get("INSPECTION_ID") != null) {
  132. sql.append(" AND INSPECTION_ID like '%").append(inputMap.get("INSPECTION_ID")).append("%'");
  133. }
  134. if (inputMap.containsKey("PATIENT_NAME") && inputMap.get("PATIENT_NAME") != null) {
  135. sql.append(" AND PATIENT_NAME like '%").append(inputMap.get("PATIENT_NAME")).append("%'");
  136. }
  137. if (inputMap.containsKey("TEST_ORDER_NAME") && inputMap.get("TEST_ORDER_NAME") != null) {
  138. sql.append(" AND TEST_ORDER_NAME like '%").append(inputMap.get("TEST_ORDER_NAME")).append("%'");
  139. }
  140. log.info("execute sql: " + sql.toString());
  141. resultList.addAll(jdbcTemplate.queryForList(sql.toString()));
  142. int num = resultList.size();
  143. log.info("get data size: " + String.valueOf(num));
  144. }
  145. return resultList;
  146. }
  147. public List<Map<String, Object>> getSavedSampleList(List<Map<String, Object>> inputList){
  148. List<Map<String, Object>> resultList = new ArrayList<>();
  149. for(Map<String, Object> inputMap : inputList) {
  150. StringBuilder sql = new StringBuilder(
  151. "select SAVE_DATE,INSPECTION_ID,PATIENT_NAME,TEST_ORDER_NAME from V_JT_SAVEANDDESTROY where STATE=2");
  152. MapSqlParameterSource params = new MapSqlParameterSource();
  153. // 处理SAVE_DATE(字符串类型)
  154. if (inputMap.containsKey("OPERATION_DATE") && inputMap.get("OPERATION_DATE") != null) {
  155. sql.append(" AND SAVE_DATE = '"+inputMap.get("OPERATION_DATE")+"'");
  156. // params.addValue("saveDate", inputMap.get("SAVE_DATE"), Types.VARCHAR);
  157. }
  158. // 处理GROUPCODE(字符串类型)
  159. if (inputMap.containsKey("GROUPCODE") && inputMap.get("GROUPCODE") != null) {
  160. sql.append(" AND GROUPCODE = '"+inputMap.get("GROUPCODE")+"'");
  161. // params.addValue("groupCode", inputMap.get("GROUPCODE"), Types.VARCHAR);
  162. }
  163. // INSPECTION_ID(字符串类型)
  164. if (inputMap.containsKey("INSPECTION_ID") && inputMap.get("INSPECTION_ID") != null) {
  165. sql.append(" AND INSPECTION_ID like '%"+inputMap.get("INSPECTION_ID")+"%'");
  166. // params.addValue("INSPECTION_ID", inputMap.get("INSPECTION_ID"), Types.VARCHAR);
  167. }
  168. //PATIENT_NAME(字符串类型)
  169. if (inputMap.containsKey("PATIENT_NAME") && inputMap.get("PATIENT_NAME") != null) {
  170. sql.append(" AND PATIENT_NAME like '%"+inputMap.get("PATIENT_NAME")+"%'");
  171. // params.addValue("PATIENT_NAME", inputMap.get("PATIENT_NAME"), Types.VARCHAR);
  172. }
  173. //TEST_ORDER_NAME(字符串类型)
  174. if (inputMap.containsKey("TEST_ORDER_NAME") && inputMap.get("TEST_ORDER_NAME") != null) {
  175. sql.append(" AND TEST_ORDER_NAME like '%"+inputMap.get("TEST_ORDER_NAME")+"%'");
  176. // params.addValue("TEST_ORDER_NAME", inputMap.get("TEST_ORDER_NAME"), Types.VARCHAR);
  177. }
  178. log.info("execute sql: " + sql.toString());
  179. resultList.addAll(jdbcTemplate.queryForList(sql.toString()));
  180. int num = resultList.size();
  181. log.info("get data size: " + String.valueOf(num));
  182. }
  183. return resultList;
  184. }
  185. public List<Map<String, Object>> getDestorySampleList(List<Map<String, Object>> inputList){
  186. List<Map<String, Object>> resultList = new ArrayList<>();
  187. for(Map<String, Object> inputMap : inputList) {
  188. StringBuilder sql = new StringBuilder(
  189. "select SAVE_DATE,INSPECTION_ID,PATIENT_NAME,TEST_ORDER_NAME from V_JT_SAVEANDDESTROY where STATE=2");
  190. MapSqlParameterSource params = new MapSqlParameterSource();
  191. // 处理SAVE_DATE(字符串类型)
  192. if (inputMap.containsKey("OPERATION_DATE") && inputMap.get("OPERATION_DATE") != null) {
  193. sql.append(" AND DESTROY_DATE = '"+inputMap.get("OPERATION_DATE")+"'");
  194. // params.addValue("saveDate", inputMap.get("SAVE_DATE"), Types.VARCHAR);
  195. }
  196. // 处理GROUPCODE(字符串类型)
  197. if (inputMap.containsKey("GROUPCODE") && inputMap.get("GROUPCODE") != null) {
  198. sql.append(" AND GROUPCODE = '"+inputMap.get("GROUPCODE")+"'");
  199. // params.addValue("groupCode", inputMap.get("GROUPCODE"), Types.VARCHAR);
  200. }
  201. // INSPECTION_ID(字符串类型)
  202. if (inputMap.containsKey("INSPECTION_ID") && inputMap.get("INSPECTION_ID") != null) {
  203. sql.append(" AND INSPECTION_ID like '%"+inputMap.get("INSPECTION_ID")+"%'");
  204. // params.addValue("INSPECTION_ID", inputMap.get("INSPECTION_ID"), Types.VARCHAR);
  205. }
  206. //PATIENT_NAME(字符串类型)
  207. if (inputMap.containsKey("PATIENT_NAME") && inputMap.get("PATIENT_NAME") != null) {
  208. sql.append(" AND PATIENT_NAME like '%"+inputMap.get("PATIENT_NAME")+"%'");
  209. // params.addValue("PATIENT_NAME", inputMap.get("PATIENT_NAME"), Types.VARCHAR);
  210. }
  211. //TEST_ORDER_NAME(字符串类型)
  212. if (inputMap.containsKey("TEST_ORDER_NAME") && inputMap.get("TEST_ORDER_NAME") != null) {
  213. sql.append(" AND TEST_ORDER_NAME like '%"+inputMap.get("TEST_ORDER_NAME")+"%'");
  214. // params.addValue("TEST_ORDER_NAME", inputMap.get("TEST_ORDER_NAME"), Types.VARCHAR);
  215. }
  216. log.info("execute sql: " + sql.toString());
  217. resultList.addAll(jdbcTemplate.queryForList(sql.toString()));
  218. int num = resultList.size();
  219. log.info("get data size: " + String.valueOf(num));
  220. }
  221. return resultList;
  222. }
  223. public List<Map<String, Object>> getDestoryedSampleList(List<Map<String, Object>> inputList){
  224. List<Map<String, Object>> resultList = new ArrayList<>();
  225. for(Map<String, Object> inputMap : inputList) {
  226. StringBuilder sql = new StringBuilder(
  227. "select SAVE_DATE,INSPECTION_ID,PATIENT_NAME,TEST_ORDER_NAME from V_JT_SAVEANDDESTROY where STATE=4");
  228. MapSqlParameterSource params = new MapSqlParameterSource();
  229. // 处理SAVE_DATE(字符串类型)
  230. if (inputMap.containsKey("OPERATION_DATE") && inputMap.get("OPERATION_DATE") != null) {
  231. sql.append(" AND DESTROY_DATE = '"+inputMap.get("OPERATION_DATE")+"'");
  232. // params.addValue("saveDate", inputMap.get("SAVE_DATE"), Types.VARCHAR);
  233. }
  234. // 处理GROUPCODE(字符串类型)
  235. if (inputMap.containsKey("GROUPCODE") && inputMap.get("GROUPCODE") != null) {
  236. sql.append(" AND GROUPCODE = '"+inputMap.get("GROUPCODE")+"'");
  237. // params.addValue("groupCode", inputMap.get("GROUPCODE"), Types.VARCHAR);
  238. }
  239. // INSPECTION_ID(字符串类型)
  240. if (inputMap.containsKey("INSPECTION_ID") && inputMap.get("INSPECTION_ID") != null) {
  241. sql.append(" AND INSPECTION_ID like '%"+inputMap.get("INSPECTION_ID")+"%'");
  242. // params.addValue("INSPECTION_ID", inputMap.get("INSPECTION_ID"), Types.VARCHAR);
  243. }
  244. //PATIENT_NAME(字符串类型)
  245. if (inputMap.containsKey("PATIENT_NAME") && inputMap.get("PATIENT_NAME") != null) {
  246. sql.append(" AND PATIENT_NAME like '%"+inputMap.get("PATIENT_NAME")+"%'");
  247. // params.addValue("PATIENT_NAME", inputMap.get("PATIENT_NAME"), Types.VARCHAR);
  248. }
  249. //TEST_ORDER_NAME(字符串类型)
  250. if (inputMap.containsKey("TEST_ORDER_NAME") && inputMap.get("TEST_ORDER_NAME") != null) {
  251. sql.append(" AND TEST_ORDER_NAME like '%"+inputMap.get("TEST_ORDER_NAME")+"%'");
  252. // params.addValue("TEST_ORDER_NAME", inputMap.get("TEST_ORDER_NAME"), Types.VARCHAR);
  253. }
  254. log.info("execute sql: " + sql.toString());
  255. resultList.addAll(jdbcTemplate.queryForList(sql.toString()));
  256. int num = resultList.size();
  257. log.info("get data size: " + String.valueOf(num));
  258. }
  259. return resultList;
  260. }
  261. public int SaveSample(List<Map<String, Object>> inputList){
  262. log.info("ready to save:"+String.valueOf(inputList));
  263. String OperationDate = null;
  264. String GroupCode = null;
  265. String OperationName = null;
  266. int ret = -1;
  267. // //----------以下为测试用----------
  268. // if(1==1){
  269. // return 0;
  270. // }
  271. // //----------以上为测试用----------
  272. List<String> RemoveSampleList = new ArrayList<>();
  273. for(Map<String, Object> inputMap : inputList) {
  274. if (inputMap.containsKey("OPERATION_DATE")) {
  275. OperationDate = String.valueOf(inputMap.get("OPERATION_DATE"));
  276. }
  277. if (inputMap.containsKey("GROUPCODE")) {
  278. GroupCode = String.valueOf(inputMap.get("GROUPCODE"));
  279. }
  280. if (inputMap.containsKey("OPERATIONNAME")) {
  281. OperationName = String.valueOf(inputMap.get("OPERATIONNAME"));
  282. }
  283. if (inputMap.containsKey("RemoveSampleList")) {
  284. Object obj = inputMap.get("RemoveSampleList");
  285. if (obj instanceof List<?>) {
  286. for (Object item : (List<?>) obj) {
  287. RemoveSampleList.add(String.valueOf(item));
  288. }
  289. }
  290. }
  291. }
  292. String result = "";
  293. if (RemoveSampleList == null || RemoveSampleList.isEmpty()) {
  294. result = "";
  295. }else{
  296. for (String item : RemoveSampleList) {
  297. result += item + ",";
  298. }
  299. }
  300. result = result.substring(0, result.length() - 1);
  301. String xml =
  302. "<OprationDate>" + OperationDate + "</OprationDate>" +
  303. "<GroupCode>" + GroupCode + "</GroupCode>" +
  304. "<RemoveSampleList>" + result + "</RemoveSampleList>" +
  305. "<OprationName>" + OperationName + "</OprationName>";
  306. //准备调用存储过程
  307. String methodCode = "SaveSample";
  308. SimpleJdbcCall jdbcCall = new SimpleJdbcCall(jdbcTemplate)
  309. .withProcedureName("USP_JT_INTERFACE")
  310. .declareParameters(
  311. new SqlParameter("methodCode", Types.VARCHAR),
  312. new SqlParameter("inParamXml", Types.VARCHAR),
  313. new SqlOutParameter("a_result", Types.VARCHAR)
  314. );
  315. Map<String, Object> inParams = new HashMap<>();
  316. inParams.put("methodCode", "SaveSample");
  317. inParams.put("inParamXml", xml);
  318. log.info("call process:Save-> " + xml);
  319. Map<String, Object> out = jdbcCall.execute(inParams);
  320. ret = Integer.parseInt((String) out.get("a_result"));
  321. if(!(ret ==0)){
  322. log.info("---------------call process:Save-> fail!---------------");
  323. }else{
  324. log.info("call process:Save-> success!");
  325. }
  326. return ret;
  327. }
  328. public int DestorySample(List<Map<String, Object>> inputList){
  329. log.info("ready to destory:"+String.valueOf(inputList));
  330. String OperationDate = null;
  331. String GroupCode = null;
  332. String OperationName = null;
  333. int ret = -1;
  334. // //----------以下为测试用----------
  335. // if(1==1){
  336. // return 0;
  337. // }
  338. // //----------以上为测试用----------
  339. List<String> RemoveSampleList = new ArrayList<>();
  340. for(Map<String, Object> inputMap : inputList) {
  341. if (inputMap.containsKey("OPERATION_DATE")) {
  342. OperationDate = String.valueOf(inputMap.get("OPERATION_DATE"));
  343. }
  344. if (inputMap.containsKey("GROUPCODE")) {
  345. GroupCode = String.valueOf(inputMap.get("GROUPCODE"));
  346. }
  347. if (inputMap.containsKey("USERNAME")) {
  348. OperationName = String.valueOf(inputMap.get("USERNAME"));
  349. }
  350. if (inputMap.containsKey("RemoveSampleList")) {
  351. Object obj = inputMap.get("RemoveSampleList");
  352. if (obj instanceof List<?>) {
  353. for (Object item : (List<?>) obj) {
  354. RemoveSampleList.add(String.valueOf(item));
  355. }
  356. }
  357. }
  358. }
  359. String result = "";
  360. if (RemoveSampleList == null || RemoveSampleList.isEmpty()) {
  361. result = "";
  362. }else{
  363. for (String item : RemoveSampleList) {
  364. result += item + ",";
  365. }
  366. }
  367. result = result.substring(0, result.length() - 1);
  368. String xml =
  369. "<OprationDate>" + OperationDate + "</OprationDate>" +
  370. "<GroupCode>" + GroupCode + "</GroupCode>" +
  371. "<RemoveSampleList>" + result + "</RemoveSampleList>" +
  372. "<OprationName>" + OperationName + "</OprationName>";
  373. //准备调用存储过程
  374. String methodCode = "DestorySample";
  375. SimpleJdbcCall jdbcCall = new SimpleJdbcCall(jdbcTemplate)
  376. .withProcedureName("USP_JT_INTERFACE")
  377. .declareParameters(
  378. new SqlParameter("methodCode", Types.VARCHAR),
  379. new SqlParameter("inParamXml", Types.VARCHAR),
  380. new SqlOutParameter("a_result", Types.VARCHAR)
  381. );
  382. Map<String, Object> inParams = new HashMap<>();
  383. inParams.put("methodCode", "DestorySample");
  384. inParams.put("inParamXml", xml);
  385. log.info("call process:Destory-> " + xml);
  386. Map<String, Object> out = jdbcCall.execute(inParams);
  387. ret = Integer.parseInt((String) out.get("a_result"));
  388. if(!(ret ==0)){
  389. log.info("---------------call process:Save-> fail!---------------");
  390. }else{
  391. log.info("call process:Save-> success!");
  392. }
  393. return ret;
  394. }
  395. }