| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464 |
- package com.jyxt.getdatabyrestful.service.impl;
- import com.jyxt.getdatabyrestful.service.LISService;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Qualifier;
- import org.springframework.jdbc.core.JdbcTemplate;
- import org.springframework.jdbc.core.SqlOutParameter;
- import org.springframework.jdbc.core.SqlParameter;
- import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
- import org.springframework.jdbc.core.simple.SimpleJdbcCall;
- import org.springframework.stereotype.Service;
- import org.springframework.util.StringUtils;
- import java.sql.Types;
- import java.util.*;
- @Service
- public class LISServiceImpl implements LISService {
- private static final Logger log = LoggerFactory.getLogger(LISServiceImpl.class);
- @Autowired
- @Qualifier("secondJdbcTemplate")
- private JdbcTemplate jdbcTemplate;
- public static List<Map<String, Object>> testList = new ArrayList<>();
- public List<Map<String, Object>> GetGroupConfig() {
- // //----------以下为测试用----------
- // // 1. 创建最外层的List
- // List<Map<String, Object>> list = new ArrayList<>();
- // // 2. 创建内层Map
- // Map<String, Object> map = new HashMap<>(); // 保持插入顺序
- // // 3. 向Map中添加数据
- // map.put("SORTID", "001");
- // map.put("GROUPCODE", "G002");
- // map.put("GROUPNAME", "茂源生化");
- // map.put("SAVEDAY", "7");
- // map.put("OPRATIONTYPE", "直接转交公司统一焚烧");
- // list.add(map);
- // Map<String, Object> map2 = new HashMap<>(); // 保持插入顺序
- // // 3. 向Map中添加数据
- // map2.put("SORTID", "002");
- // map2.put("GROUPCODE", "G004");
- // map2.put("GROUPNAME", "茂源免疫");
- // map2.put("SAVEDAY", "14");
- // map2.put("OPRATIONTYPE", "直接转交公司统一焚烧");
- // list.add(map2);
- //
- // Map<String, Object> map3 = new HashMap<>(); // 保持插入顺序
- // // 3. 向Map中添加数据
- // map3.put("SORTID", "003");
- // map3.put("GROUPCODE", "G032");
- // map3.put("GROUPNAME", "茂源临检");
- // map3.put("SAVEDAY", "7");
- // map3.put("OPRATIONTYPE", "灭菌后转交公司统一焚烧");
- // list.add(map3);
- // return list;
- // //----------以上为测试用----------
- List<Map<String, Object>> resultList = null;
- String SqlQry = "select SORTID,GROUPCODE,GROUPNAME,SAVEDAY,OPRATIONTYPE from v_jt_lisgroupcustom";
- log.info("excute sql:"+SqlQry);
- resultList = jdbcTemplate.queryForList(SqlQry);
- return resultList;
- }
- public List<Map<String, Object>> GetSampleList(List<Map<String, Object>> inputList){
- // //----------以下为测试用----------
- // // 1. 创建最外层的List
- // List<Map<String, Object>> list = new ArrayList<>();
- // // 2. 创建内层Map
- // Map<String, Object> map = new HashMap<>(); // 保持插入顺序
- // // 3. 向Map中添加数据
- // map.put("STATE", "1");
- // map.put("SAVE_DATE", "20250720");
- // map.put("INSPECTION_ID", "20250720G0364061112");
- // map.put("PATIENT_NAME", "赵春香11");
- // map.put("TEST_ORDER_NAME", "血常规11");
- // map.put("DESTROY_DATE", "20250727");
- // list.add(map);
- // Map<String, Object> map2 = new HashMap<>(); // 保持插入顺序
- // // 3. 向Map中添加数据
- // map2.put("STATE", "1");
- // map2.put("SAVE_DATE", "20250720");
- // map2.put("INSPECTION_ID", "20250720G036123124062");
- // map2.put("PATIENT_NAME", "赵春香22");
- // map2.put("TEST_ORDER_NAME", "血常规22");
- // map2.put("DESTROY_DATE", "20250727");
- // list.add(map2);
- //
- // Map<String, Object> map3 = new HashMap<>(); // 保持插入顺序
- // // 3. 向Map中添加数据
- // map3.put("STATE", "1");
- // map3.put("SAVE_DATE", "20250720");
- // map3.put("INSPECTION_ID", "2020G03123312364062");
- // map3.put("PATIENT_NAME", "赵春香33");
- // map3.put("TEST_ORDER_NAME", "血常规33");
- // map3.put("DESTROY_DATE", "20250727");
- // list.add(map3);
- // return list;
- // //----------以上为测试用----------
- List<Map<String, Object>> resultList = new ArrayList<>();
- for(Map<String, Object> inputMap : inputList) {
- if (!inputMap.containsKey("STATE") || inputMap.get("STATE") == null) {
- continue;
- }
- // StringBuilder sql = new StringBuilder(
- // "select STATE,SAVE_DATE,DESTROY_DATE,INSPECTION_ID,PATIENT_NAME,TEST_ORDER_NAME from V_JT_SAVEANDDESTROY where ");
- //
- // // 处理STATE参数(可能为单个值或多个值)
- // String stateValue = inputMap.get("STATE").toString();
- // if (stateValue.contains(",")) {
- // String[] states = stateValue.split(",");
- // sql.append("STATE IN (");
- // for (int i = 0; i < states.length; i++) {
- // sql.append("'").append(states[i].trim()).append("'");
- // if (i < states.length - 1) {
- // sql.append(",");
- // }
- // }
- // sql.append(")");
- // } else {
- // sql.append("STATE = '").append(stateValue).append("'");
- // }
- StringBuilder sql = new StringBuilder("select ");
- if (inputMap.get("STATE").equals("1")){
- sql.append("STATE,SAVE_DATE,INSPECTION_ID,PATIENT_NAME,TEST_ORDER_NAME from v_jt_inspection_save where STATE=1 and ");
- } else if (inputMap.get("STATE").equals("1,2")){
- sql.append("STATE,SAVE_DATE,INSPECTION_ID,PATIENT_NAME,TEST_ORDER_NAME from v_jt_inspection_save where ");
- } else if (inputMap.get("STATE").equals("2")){
- sql.append("STATE,SAVE_DATE,DESTROY_DATE,INSPECTION_ID,PATIENT_NAME,TEST_ORDER_NAME from v_jt_inspection_destroy where STATE=2 and ");
- } else if (inputMap.get("STATE").equals("2,4")){
- sql.append("STATE,SAVE_DATE,DESTROY_DATE,INSPECTION_ID,PATIENT_NAME,TEST_ORDER_NAME from v_jt_inspection_destroy where ");
- }
- // 处理其他查询条件
- if (inputMap.containsKey("SAVE_DATE") && inputMap.get("SAVE_DATE") != null) {
- sql.append("SAVE_DATE = '").append(inputMap.get("SAVE_DATE")).append("'");
- }
- // if (inputMap.containsKey("DESTROY_DATE") && inputMap.get("DESTROY_DATE") != null) {
- // sql.append(" AND DESTROY_DATE = '").append(inputMap.get("DESTROY_DATE")).append("'");
- // }
- if (inputMap.containsKey("GROUPCODE") && inputMap.get("GROUPCODE") != null) {
- sql.append(" AND GROUPCODE = '").append(inputMap.get("GROUPCODE")).append("'");
- }
- if (inputMap.containsKey("INSPECTION_ID") && inputMap.get("INSPECTION_ID") != null) {
- sql.append(" AND INSPECTION_ID like '%").append(inputMap.get("INSPECTION_ID")).append("%'");
- }
- if (inputMap.containsKey("PATIENT_NAME") && inputMap.get("PATIENT_NAME") != null) {
- sql.append(" AND PATIENT_NAME like '%").append(inputMap.get("PATIENT_NAME")).append("%'");
- }
- if (inputMap.containsKey("TEST_ORDER_NAME") && inputMap.get("TEST_ORDER_NAME") != null) {
- sql.append(" AND TEST_ORDER_NAME like '%").append(inputMap.get("TEST_ORDER_NAME")).append("%'");
- }
- log.info("execute sql: " + sql.toString());
- resultList.addAll(jdbcTemplate.queryForList(sql.toString()));
- int num = resultList.size();
- log.info("get data size: " + String.valueOf(num));
- }
- return resultList;
- }
- public List<Map<String, Object>> getSavedSampleList(List<Map<String, Object>> inputList){
- List<Map<String, Object>> resultList = new ArrayList<>();
- for(Map<String, Object> inputMap : inputList) {
- StringBuilder sql = new StringBuilder(
- "select SAVE_DATE,INSPECTION_ID,PATIENT_NAME,TEST_ORDER_NAME from V_JT_SAVEANDDESTROY where STATE=2");
- MapSqlParameterSource params = new MapSqlParameterSource();
- // 处理SAVE_DATE(字符串类型)
- if (inputMap.containsKey("OPERATION_DATE") && inputMap.get("OPERATION_DATE") != null) {
- sql.append(" AND SAVE_DATE = '"+inputMap.get("OPERATION_DATE")+"'");
- // params.addValue("saveDate", inputMap.get("SAVE_DATE"), Types.VARCHAR);
- }
- // 处理GROUPCODE(字符串类型)
- if (inputMap.containsKey("GROUPCODE") && inputMap.get("GROUPCODE") != null) {
- sql.append(" AND GROUPCODE = '"+inputMap.get("GROUPCODE")+"'");
- // params.addValue("groupCode", inputMap.get("GROUPCODE"), Types.VARCHAR);
- }
- // INSPECTION_ID(字符串类型)
- if (inputMap.containsKey("INSPECTION_ID") && inputMap.get("INSPECTION_ID") != null) {
- sql.append(" AND INSPECTION_ID like '%"+inputMap.get("INSPECTION_ID")+"%'");
- // params.addValue("INSPECTION_ID", inputMap.get("INSPECTION_ID"), Types.VARCHAR);
- }
- //PATIENT_NAME(字符串类型)
- if (inputMap.containsKey("PATIENT_NAME") && inputMap.get("PATIENT_NAME") != null) {
- sql.append(" AND PATIENT_NAME like '%"+inputMap.get("PATIENT_NAME")+"%'");
- // params.addValue("PATIENT_NAME", inputMap.get("PATIENT_NAME"), Types.VARCHAR);
- }
- //TEST_ORDER_NAME(字符串类型)
- if (inputMap.containsKey("TEST_ORDER_NAME") && inputMap.get("TEST_ORDER_NAME") != null) {
- sql.append(" AND TEST_ORDER_NAME like '%"+inputMap.get("TEST_ORDER_NAME")+"%'");
- // params.addValue("TEST_ORDER_NAME", inputMap.get("TEST_ORDER_NAME"), Types.VARCHAR);
- }
- log.info("execute sql: " + sql.toString());
- resultList.addAll(jdbcTemplate.queryForList(sql.toString()));
- int num = resultList.size();
- log.info("get data size: " + String.valueOf(num));
- }
- return resultList;
- }
- public List<Map<String, Object>> getDestorySampleList(List<Map<String, Object>> inputList){
- List<Map<String, Object>> resultList = new ArrayList<>();
- for(Map<String, Object> inputMap : inputList) {
- StringBuilder sql = new StringBuilder(
- "select SAVE_DATE,INSPECTION_ID,PATIENT_NAME,TEST_ORDER_NAME from V_JT_SAVEANDDESTROY where STATE=2");
- MapSqlParameterSource params = new MapSqlParameterSource();
- // 处理SAVE_DATE(字符串类型)
- if (inputMap.containsKey("OPERATION_DATE") && inputMap.get("OPERATION_DATE") != null) {
- sql.append(" AND DESTROY_DATE = '"+inputMap.get("OPERATION_DATE")+"'");
- // params.addValue("saveDate", inputMap.get("SAVE_DATE"), Types.VARCHAR);
- }
- // 处理GROUPCODE(字符串类型)
- if (inputMap.containsKey("GROUPCODE") && inputMap.get("GROUPCODE") != null) {
- sql.append(" AND GROUPCODE = '"+inputMap.get("GROUPCODE")+"'");
- // params.addValue("groupCode", inputMap.get("GROUPCODE"), Types.VARCHAR);
- }
- // INSPECTION_ID(字符串类型)
- if (inputMap.containsKey("INSPECTION_ID") && inputMap.get("INSPECTION_ID") != null) {
- sql.append(" AND INSPECTION_ID like '%"+inputMap.get("INSPECTION_ID")+"%'");
- // params.addValue("INSPECTION_ID", inputMap.get("INSPECTION_ID"), Types.VARCHAR);
- }
- //PATIENT_NAME(字符串类型)
- if (inputMap.containsKey("PATIENT_NAME") && inputMap.get("PATIENT_NAME") != null) {
- sql.append(" AND PATIENT_NAME like '%"+inputMap.get("PATIENT_NAME")+"%'");
- // params.addValue("PATIENT_NAME", inputMap.get("PATIENT_NAME"), Types.VARCHAR);
- }
- //TEST_ORDER_NAME(字符串类型)
- if (inputMap.containsKey("TEST_ORDER_NAME") && inputMap.get("TEST_ORDER_NAME") != null) {
- sql.append(" AND TEST_ORDER_NAME like '%"+inputMap.get("TEST_ORDER_NAME")+"%'");
- // params.addValue("TEST_ORDER_NAME", inputMap.get("TEST_ORDER_NAME"), Types.VARCHAR);
- }
- log.info("execute sql: " + sql.toString());
- resultList.addAll(jdbcTemplate.queryForList(sql.toString()));
- int num = resultList.size();
- log.info("get data size: " + String.valueOf(num));
- }
- return resultList;
- }
- public List<Map<String, Object>> getDestoryedSampleList(List<Map<String, Object>> inputList){
- List<Map<String, Object>> resultList = new ArrayList<>();
- for(Map<String, Object> inputMap : inputList) {
- StringBuilder sql = new StringBuilder(
- "select SAVE_DATE,INSPECTION_ID,PATIENT_NAME,TEST_ORDER_NAME from V_JT_SAVEANDDESTROY where STATE=4");
- MapSqlParameterSource params = new MapSqlParameterSource();
- // 处理SAVE_DATE(字符串类型)
- if (inputMap.containsKey("OPERATION_DATE") && inputMap.get("OPERATION_DATE") != null) {
- sql.append(" AND DESTROY_DATE = '"+inputMap.get("OPERATION_DATE")+"'");
- // params.addValue("saveDate", inputMap.get("SAVE_DATE"), Types.VARCHAR);
- }
- // 处理GROUPCODE(字符串类型)
- if (inputMap.containsKey("GROUPCODE") && inputMap.get("GROUPCODE") != null) {
- sql.append(" AND GROUPCODE = '"+inputMap.get("GROUPCODE")+"'");
- // params.addValue("groupCode", inputMap.get("GROUPCODE"), Types.VARCHAR);
- }
- // INSPECTION_ID(字符串类型)
- if (inputMap.containsKey("INSPECTION_ID") && inputMap.get("INSPECTION_ID") != null) {
- sql.append(" AND INSPECTION_ID like '%"+inputMap.get("INSPECTION_ID")+"%'");
- // params.addValue("INSPECTION_ID", inputMap.get("INSPECTION_ID"), Types.VARCHAR);
- }
- //PATIENT_NAME(字符串类型)
- if (inputMap.containsKey("PATIENT_NAME") && inputMap.get("PATIENT_NAME") != null) {
- sql.append(" AND PATIENT_NAME like '%"+inputMap.get("PATIENT_NAME")+"%'");
- // params.addValue("PATIENT_NAME", inputMap.get("PATIENT_NAME"), Types.VARCHAR);
- }
- //TEST_ORDER_NAME(字符串类型)
- if (inputMap.containsKey("TEST_ORDER_NAME") && inputMap.get("TEST_ORDER_NAME") != null) {
- sql.append(" AND TEST_ORDER_NAME like '%"+inputMap.get("TEST_ORDER_NAME")+"%'");
- // params.addValue("TEST_ORDER_NAME", inputMap.get("TEST_ORDER_NAME"), Types.VARCHAR);
- }
- log.info("execute sql: " + sql.toString());
- resultList.addAll(jdbcTemplate.queryForList(sql.toString()));
- int num = resultList.size();
- log.info("get data size: " + String.valueOf(num));
- }
- return resultList;
- }
- public int SaveSample(List<Map<String, Object>> inputList){
- log.info("ready to save:"+String.valueOf(inputList));
- String OperationDate = null;
- String GroupCode = null;
- String OperationName = null;
- int ret = -1;
- // //----------以下为测试用----------
- // if(1==1){
- // return 0;
- // }
- // //----------以上为测试用----------
- List<String> RemoveSampleList = new ArrayList<>();
- for(Map<String, Object> inputMap : inputList) {
- if (inputMap.containsKey("OPERATION_DATE")) {
- OperationDate = String.valueOf(inputMap.get("OPERATION_DATE"));
- }
- if (inputMap.containsKey("GROUPCODE")) {
- GroupCode = String.valueOf(inputMap.get("GROUPCODE"));
- }
- if (inputMap.containsKey("OPERATIONNAME")) {
- OperationName = String.valueOf(inputMap.get("OPERATIONNAME"));
- }
- if (inputMap.containsKey("RemoveSampleList")) {
- Object obj = inputMap.get("RemoveSampleList");
- if (obj instanceof List<?>) {
- for (Object item : (List<?>) obj) {
- RemoveSampleList.add(String.valueOf(item));
- }
- }
- }
- }
- String result = "";
- if (RemoveSampleList == null || RemoveSampleList.isEmpty()) {
- result = "";
- }else{
- for (String item : RemoveSampleList) {
- result += item + ",";
- }
- }
- result = result.substring(0, result.length() - 1);
- String xml =
- "<OprationDate>" + OperationDate + "</OprationDate>" +
- "<GroupCode>" + GroupCode + "</GroupCode>" +
- "<RemoveSampleList>" + result + "</RemoveSampleList>" +
- "<OprationName>" + OperationName + "</OprationName>";
- //准备调用存储过程
- String methodCode = "SaveSample";
- SimpleJdbcCall jdbcCall = new SimpleJdbcCall(jdbcTemplate)
- .withProcedureName("USP_JT_INTERFACE")
- .declareParameters(
- new SqlParameter("methodCode", Types.VARCHAR),
- new SqlParameter("inParamXml", Types.VARCHAR),
- new SqlOutParameter("a_result", Types.VARCHAR)
- );
- Map<String, Object> inParams = new HashMap<>();
- inParams.put("methodCode", "SaveSample");
- inParams.put("inParamXml", xml);
- log.info("call process:Save-> " + xml);
- Map<String, Object> out = jdbcCall.execute(inParams);
- ret = Integer.parseInt((String) out.get("a_result"));
- if(!(ret ==0)){
- log.info("---------------call process:Save-> fail!---------------");
- }else{
- log.info("call process:Save-> success!");
- }
- return ret;
- }
- public int DestorySample(List<Map<String, Object>> inputList){
- log.info("ready to destory:"+String.valueOf(inputList));
- String OperationDate = null;
- String GroupCode = null;
- String OperationName = null;
- int ret = -1;
- // //----------以下为测试用----------
- // if(1==1){
- // return 0;
- // }
- // //----------以上为测试用----------
- List<String> RemoveSampleList = new ArrayList<>();
- for(Map<String, Object> inputMap : inputList) {
- if (inputMap.containsKey("OPERATION_DATE")) {
- OperationDate = String.valueOf(inputMap.get("OPERATION_DATE"));
- }
- if (inputMap.containsKey("GROUPCODE")) {
- GroupCode = String.valueOf(inputMap.get("GROUPCODE"));
- }
- if (inputMap.containsKey("OPERATIONNAME")) {
- OperationName = String.valueOf(inputMap.get("OPERATIONNAME"));
- }
- if (inputMap.containsKey("RemoveSampleList")) {
- Object obj = inputMap.get("RemoveSampleList");
- if (obj instanceof List<?>) {
- for (Object item : (List<?>) obj) {
- RemoveSampleList.add(String.valueOf(item));
- }
- }
- }
- }
- String result = "";
- if (RemoveSampleList == null || RemoveSampleList.isEmpty()) {
- result = "";
- }else{
- for (String item : RemoveSampleList) {
- result += item + ",";
- }
- }
- result = result.substring(0, result.length() - 1);
- String xml =
- "<OprationDate>" + OperationDate + "</OprationDate>" +
- "<GroupCode>" + GroupCode + "</GroupCode>" +
- "<RemoveSampleList>" + result + "</RemoveSampleList>" +
- "<OprationName>" + OperationName + "</OprationName>";
- //准备调用存储过程
- String methodCode = "DestorySample";
- SimpleJdbcCall jdbcCall = new SimpleJdbcCall(jdbcTemplate)
- .withProcedureName("USP_JT_INTERFACE")
- .declareParameters(
- new SqlParameter("methodCode", Types.VARCHAR),
- new SqlParameter("inParamXml", Types.VARCHAR),
- new SqlOutParameter("a_result", Types.VARCHAR)
- );
- Map<String, Object> inParams = new HashMap<>();
- inParams.put("methodCode", "DestorySample");
- inParams.put("inParamXml", xml);
- log.info("call process:Destory-> " + xml);
- Map<String, Object> out = jdbcCall.execute(inParams);
- ret = Integer.parseInt((String) out.get("a_result"));
- if(!(ret ==0)){
- log.info("---------------call process:Save-> fail!---------------");
- }else{
- log.info("call process:Save-> success!");
- }
- return ret;
- }
- @Override
- public List<Map<String, Object>> geteActualCountList(String qryDays) {
- //获取LIS指定天数内的实际保存数
- String QryActualSql = "select SAVE_DATE,GROUPNAME,count(*) as COUNT from v_jt_inspection_save where TO_DATE(SAVE_DATE, 'YYYYMMDD')>=TRUNC(SYSDATE)-"+Integer.valueOf(qryDays)+" group by GROUPNAME,SAVE_DATE";
- log.info("execute sql: " + QryActualSql.toString());
- List<Map<String, Object>> actualList = jdbcTemplate.queryForList(QryActualSql);
- return actualList;
- //以下为测试数据
- // 1. 创建最外层的List
- // List<Map<String, Object>> list = new ArrayList<>();
- // // 2. 创建内层Map
- // Map<String, Object> map = new HashMap<>(); // 保持插入顺序
- // // 3. 向Map中添加数据
- // map.put("SAVE_DATE", "20250807");
- // map.put("GROUPNAME", "茂源临检");
- // map.put("COUNT", "100");
- // list.add(map);
- // Map<String, Object> map2 = new HashMap<>(); // 保持插入顺序
- // // 3. 向Map中添加数据
- // map2.put("SAVE_DATE", "20250807");
- // map2.put("GROUPNAME", "茂源生化");
- // map2.put("COUNT", "1980");
- // list.add(map2);
- // return list;
- }
- }
|