web service 检验报告推送接口完成

docus_webservice_1.1
lzy 4 years ago
parent d7ca603988
commit 2ffa29525b

@ -150,6 +150,18 @@ public class TBasic implements Serializable {
@ApiModelProperty(value = "记账号") @ApiModelProperty(value = "记账号")
private String jzh; private String jzh;
@ApiModelProperty(value = "患者主索引号")
private String empId;
@ApiModelProperty(value = "就诊类别代码")
private String visitTypeCode;
@ApiModelProperty(value = "就诊类别名称")
private String visitTypeName;
@ApiModelProperty(value = "中医诊断代码")
private String tcmDiagCode;
@ApiModelProperty(value = "中医诊断名称")
private String tcmDiagName;
@ApiModelProperty(value = "所在院区")
private String wardPalce;
} }

@ -14,12 +14,14 @@ import com.docus.webservice.utils.XmlUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import javax.jws.WebService; import javax.jws.WebService;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@WebService @WebService
public class TBasicWebService implements ITBasicWebService { public class TBasicWebService implements ITBasicWebService {
@ -33,7 +35,6 @@ public class TBasicWebService implements ITBasicWebService {
@Override @Override
public String savaAndSub(String tbasic) { public String savaAndSub(String tbasic) {
XmlUtils xmlUtils = null; XmlUtils xmlUtils = null;
String resXml;
try { try {
//解析xml //解析xml
xmlUtils = new XmlUtils(new ByteArrayInputStream(tbasic.getBytes("UTF-8"))); xmlUtils = new XmlUtils(new ByteArrayInputStream(tbasic.getBytes("UTF-8")));
@ -46,8 +47,8 @@ public class TBasicWebService implements ITBasicWebService {
String value; String value;
for (SelectColumn selectColumn : selectColumns) { for (SelectColumn selectColumn : selectColumns) {
try { try {
value = String.valueOf(xmlUtils.getElementText(selectColumn.getQualityColumn())); value = xmlUtils.getElementText(selectColumn.getQualityColumn())==null?null:String.valueOf(xmlUtils.getElementText(selectColumn.getQualityColumn()));
}catch (RuntimeException e){ } catch (RuntimeException e) {
String message = e.getMessage(); String message = e.getMessage();
System.out.println(message); System.out.println(message);
return ResultUtils.fail(message); return ResultUtils.fail(message);
@ -68,23 +69,36 @@ public class TBasicWebService implements ITBasicWebService {
} }
} }
//处理业务 //处理业务
TBasic tBasic = new TBasic(); TBasic tBasic;
TBasicSub tBasicSub;
int insert; int insert;
if (tBasicMap != null && tBasicMap.size() > 0) { if (tBasicMap != null && tBasicMap.size() > 0) {
tBasic=JsonUtils.map2bean(tBasicMap,TBasic.class); tBasic = JSON.parseObject(JSON.toJSONString(tBasicMap), TBasic.class);
// insert = tBasicMapper.insert(tBasic); if (StringUtils.isBlank(tBasic.getPatientId())) {
// if (insert <= 0) { //新增
// return ResultUtils.fail("数据库执行出错,请重试"); insert = tBasicMapper.insert(tBasic);
// } if (insert <= 0) {
TBasicSub tBasicSub = new TBasicSub(); return ResultUtils.fail("数据库执行出错,请重试");
// BeanUtils.copyProperties(tBasicSubMap, tBasicSub); }
tBasicSub=JsonUtils.map2bean(tBasicSubMap,TBasicSub.class); tBasicSub = JSON.parseObject(JSON.toJSONString(tBasicSubMap), TBasicSub.class);
tBasicSub.setPatientId(tBasic.getPatientId()); tBasicSub.setPatientId(tBasic.getPatientId());
// insert = tBasicSubMapper.insert(tBasicSub); insert = tBasicSubMapper.insert(tBasicSub);
// if (insert <= 0) { if (insert <= 0) {
// return ResultUtils.fail("数据库执行出错,请重试"); return ResultUtils.fail("数据库执行出错,请重试");
// } }
} else {
//修改
insert=tBasicMapper.updateById(tBasic);
if (insert <= 0) {
return ResultUtils.fail("数据库执行出错,请重试");
}
tBasicSub = JSON.parseObject(JSON.toJSONString(tBasicSubMap), TBasicSub.class);
tBasicSub.setPatientId(tBasic.getPatientId());
insert = tBasicSubMapper.updateById(tBasicSub);
if (insert <= 0) {
return ResultUtils.fail("数据库执行出错,请重试");
}
}
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

@ -2,12 +2,16 @@ package com.docus.webservice.utils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.BeanUtils;
import java.beans.BeanInfo; import java.beans.BeanInfo;
import java.beans.Introspector; import java.beans.Introspector;
import java.beans.PropertyDescriptor; import java.beans.PropertyDescriptor;
import java.io.*; import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
@ -49,53 +53,4 @@ public class JsonUtils {
} }
} }
} }
private final static String STRINGCLASS = "";
private final static Long LONGCLASS = new Long(0);
private final static Date DATECLASS = new Date();
/**
* MapJavaBean
* mapkey
* bean
* @param map
* @param classType javabean
* @return
* @throws Exception
*/
public static <T> T map2bean(Map<String, Object> map, Class<T> classType) throws Exception {
// 1 采用反射动态创建对象
T obj = classType.newInstance();
// 2 获取对象字节码信息,不要Object的属性
BeanInfo beanInfo = Introspector.getBeanInfo(classType,Object.class);
// 3 获取bean对象中的所有属性
PropertyDescriptor[] list = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor pd : list) {
// 3.1 获取属性名
String key = pd.getName();
// 3.2 获取属性值:属性值在map中全部存的小写
Object value = map.get(key.toLowerCase());
// 3.3 转换数据类型
if (value != null && StringUtils.isNotBlank(value.toString())) {
Class<?> propertyType = pd.getPropertyType();
if (propertyType.isInstance(STRINGCLASS)) { // 转换成String类型
value = (String) value;
}
if (propertyType.isInstance(LONGCLASS)) { // 转换成Long类型
value = Long.parseLong((String) value);
}
if (propertyType.isInstance(DATECLASS)) {// 转换成日期类型
value = DateUtils.parseDate((String) value);
}
pd.getWriteMethod().invoke(obj, propertyType.cast(value)); //调用属性setter()方法,设置到javabean对象当中
}
}
return obj;
}
} }

Loading…
Cancel
Save