1.封装阳光采购平台院内目录查询接口

master
MrZhai 3 years ago
parent 94ec33f4a4
commit e4854f9a1e

@ -15,4 +15,5 @@ public interface BaseHttpClient {
BaseResponse getOrders(UdiwmsOrderRequest udiwmsOrderRequest);
BaseResponse getInvProducts(UdiwmsOnhandRequest udiwmsOnhandRequest);
}

@ -0,0 +1,207 @@
package com.glxp.mipsdl.admin.client.http;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.glxp.mipsdl.admin.client.BaseHttpClient;
import com.glxp.mipsdl.admin.config.UdPlatConfig;
import com.glxp.mipsdl.admin.entity.ygudplat.UdplatGoodsEntity;
import com.glxp.mipsdl.admin.req.UdiwmsOnhandRequest;
import com.glxp.mipsdl.admin.req.UdiwmsOrderRequest;
import com.glxp.mipsdl.admin.req.UdiwmsProductRequest;
import com.glxp.mipsdl.admin.req.UdiwmsUnitRequest;
import com.glxp.mipsdl.admin.res.system.UdiwmsProductInfoResponse;
import com.glxp.mipsdl.admin.util.Md5Utils;
import com.glxp.mipsdl.common.res.BaseResponse;
import com.glxp.mipsdl.common.util.ResultVOUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@Slf4j
@Service
public class UdPlatClient implements BaseHttpClient {
@Autowired
private UdPlatConfig udPlatConfig;
@Override
public BaseResponse getUnit(UdiwmsUnitRequest testUnitRequest) {
return null;
}
@Override
public BaseResponse getPrdoucts(UdiwmsProductRequest udiwmsProductRequest) {
StringBuilder builder = new StringBuilder();
Map<String, String> params = new TreeMap<>();
if (null != udiwmsProductRequest) {
Field[] fields = ReflectUtil.getFields(UdiwmsProductRequest.class);
for (Field field : fields) {
Object fieldValue = ReflectUtil.getFieldValue(udiwmsProductRequest, field);
if (null != fieldValue && "" != fieldValue) {
if ("limit".equals(field.getName())) {
params.put("pageSize", String.valueOf(fieldValue));
} else if ("manufactory".equals(field.getName())) {
params.put("manufactureId", String.valueOf(fieldValue));
} else if ("name".equals(field.getName())) {
params.put("brandName", String.valueOf(fieldValue));
} else if ("model".equals(field.getName())) {
params.put("model", String.valueOf(fieldValue));
} else if ("sepc".equals(field.getName())) {
params.put("spec", String.valueOf(fieldValue));
} else if ("standard".equals(field.getName())) {
params.put("spec", String.valueOf(fieldValue));
} else {
params.put(field.getName(), String.valueOf(fieldValue));
}
}
}
if (CollUtil.isNotEmpty(params)) {
for (String key : params.keySet()) {
if (StrUtil.isBlank(builder.toString())) {
builder.append("?").append(key).append("=").append(params.get(key));
} else {
builder.append("&").append(key).append("=").append(params.get(key));
}
}
}
}
String url = udPlatConfig.getHost() + "/hsapi/purchase/hosp/goods/query";
url += builder;
HttpResponse response = HttpRequest.get(url).headerMap(getHeader(params), true).execute();
List<UdiwmsProductInfoResponse> result = new ArrayList<>();
if (!response.body().contains("校验失败")) {
JSONObject jsonObject = JSON.parseObject(response.body());
List<UdplatGoodsEntity> udplatGoodsEntities = JSON.parseArray(jsonObject.getJSONObject("data").getString("data"), UdplatGoodsEntity.class);
udplatGoodsEntities = getSingleSpecProduct(udplatGoodsEntities);
result.addAll(convertProduct(udplatGoodsEntities));
}
return ResultVOUtils.success(result);
}
/**
*
*
* @param udplatGoodsEntities
*/
private List<UdplatGoodsEntity> getSingleSpecProduct(List<UdplatGoodsEntity> udplatGoodsEntities) {
List<UdplatGoodsEntity> data = new ArrayList<>();
for (UdplatGoodsEntity udplatGoodsEntity : udplatGoodsEntities) {
if (udplatGoodsEntity.getMatchLevel().equals(1)) {
//对照层级为产品,调用院内目录查询此产品关联的所有规格型号
Map<String, String> params = new TreeMap<>();
params.put("hospGoodsId", String.valueOf(udplatGoodsEntity.getId()));
params.put("compId", udplatGoodsEntity.getCompId());
String paramUrl = "?hospGoodsId=" + udplatGoodsEntity.getId() + "&compId=" + udplatGoodsEntity.getCompId();
HttpResponse response = HttpRequest.get(udPlatConfig.getHost() + "/hsapi/purchase/hospGoods/spec/query" + paramUrl).headerMap(getHeader(params), true).execute();
JSONObject resp = JSON.parseObject(response.body());
if (resp.getBoolean("success").equals(true)) {
JSONArray jsonArray = resp.getJSONObject("data").getJSONArray("data");
if (!jsonArray.isEmpty()) {
for (Object o : jsonArray) {
Map map = JSON.parseObject(JSON.toJSONString(o), Map.class);
UdplatGoodsEntity entity = new UdplatGoodsEntity();
BeanUtil.copyProperties(udplatGoodsEntity, entity);
entity.setSpec(String.valueOf(map.get("spec")));
entity.setModel(String.valueOf(map.get("model")));
data.add(entity);
}
}
}
} else {
//单一规格
data.add(udplatGoodsEntity);
}
}
return data;
}
@Override
public BaseResponse getOrders(UdiwmsOrderRequest udiwmsOrderRequest) {
return null;
}
@Override
public BaseResponse getInvProducts(UdiwmsOnhandRequest udiwmsOnhandRequest) {
return null;
}
/**
*
*
* @param udplatGoodsEntities
* @return
*/
private List<UdiwmsProductInfoResponse> convertProduct(List<UdplatGoodsEntity> udplatGoodsEntities) {
List<UdiwmsProductInfoResponse> list = new ArrayList<>(udplatGoodsEntities.size());
for (UdplatGoodsEntity udplatGoodsEntity : udplatGoodsEntities) {
UdiwmsProductInfoResponse productInfoResponse = new UdiwmsProductInfoResponse();
BeanUtil.copyProperties(udplatGoodsEntity, productInfoResponse);
productInfoResponse.setRegisterNo(udplatGoodsEntity.getRegNum());
productInfoResponse.setYlqxzcrbarmc(udplatGoodsEntity.getRegName());
productInfoResponse.setSupName(udplatGoodsEntity.getDistributorName());
productInfoResponse.setManufactory(udplatGoodsEntity.getManufactureName());
productInfoResponse.setYbbm(udplatGoodsEntity.getMedicalCode());
productInfoResponse.setZczyxqz(DateUtil.format(udplatGoodsEntity.getRegValidTo(), "YYYY-MM-dd HH:mm:ss"));
productInfoResponse.setStandard(udplatGoodsEntity.getSpec());
productInfoResponse.setSpec(udplatGoodsEntity.getSpec() + udplatGoodsEntity.getModel());
productInfoResponse.setName(udplatGoodsEntity.getProductName());
list.add(productInfoResponse);
}
return list;
}
private Map<String, String> getHeader(Map<String, String> mapParam) {
Map<String, String> map = new TreeMap<>();
String time = String.valueOf(System.currentTimeMillis());
mapParam.put("time", time);
map.put("appId", udPlatConfig.getAppId());
map.put("Content-Type", "application/json");
map.put("userName", udPlatConfig.getUserName());
map.put("time", time);
map.put("secretKey", udPlatConfig.getSecretKey());
map.put("sign", getSign(mapParam));
log.info(map.toString());
return map;
}
/**
*
*
* @param mapParam
* @return
*/
private String getSign(Map<String, String> mapParam) {
TreeMap<String, String> map = new TreeMap<>();
map.put("appId", udPlatConfig.getAppId());
map.put("userName", udPlatConfig.getUserName());
map.put("secretKey", udPlatConfig.getUdPlatConfig().getSecretKey());
map.put("time", mapParam.get("time"));
map.putAll(mapParam);
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, String> entry : map.entrySet()) {
sb.append(entry.getKey()).append("=").append(entry.getValue());
sb.append("&");
}
String str = sb.toString();
String str0 = str.substring(0, str.length() - 1);
return Md5Utils.stringToMD5(str0);
}
}

@ -0,0 +1,60 @@
package com.glxp.mipsdl.admin.config;
import com.glxp.mipsdl.admin.dao.config.ThrConfigDao;
import com.glxp.mipsdl.admin.entity.config.ThrPartConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
import java.net.URLEncoder;
@Slf4j
@Configuration
public class UdPlatConfig {
@Autowired
private ThrConfigDao thrConfigDao;
private ThrPartConfig udPlatConfig;
@PostConstruct
public void initConfig() {
this.udPlatConfig = thrConfigDao.selectByPartName("udplat");
}
public ThrPartConfig getUdPlatConfig() {
return udPlatConfig;
}
public String getHost() {
return udPlatConfig.getHost();
}
public String getAppId() {
return udPlatConfig.getAppId();
}
public String getSecretKey() {
return udPlatConfig.getSecretKey();
}
/**
*
*
* @return
*/
public String getUserName() {
try {
return URLEncoder.encode(udPlatConfig.getUserName(), "UTF-8");
} catch (Exception e) {
log.error("用户名编码异常", e);
return "";
}
}
public String getPartName() {
return udPlatConfig.getPartName();
}
}

@ -1,5 +1,6 @@
package com.glxp.mipsdl.admin.controller;
import com.glxp.mipsdl.admin.client.http.UdPlatClient;
import com.glxp.mipsdl.admin.client.http.YyUCloud31Client;
import com.glxp.mipsdl.admin.http.request.USignRequest;
import com.glxp.mipsdl.admin.req.*;
@ -23,6 +24,9 @@ public class UdiWmsController {
@Resource
YyUCloud31Client pzhzdClient;
@Resource
private UdPlatClient udPlatClient;
//获取erp往来单位信息接口
@PostMapping("/udiwms/erp/getUnits")
public BaseResponse getUnits(@RequestBody UdiwmsUnitRequest testUnitRequest,
@ -41,7 +45,9 @@ public class UdiWmsController {
public BaseResponse getProducts(@RequestBody UdiwmsProductRequest udiwmsProductRequest) {
if (curFlag.equals("YONGYOU_U8_V3.1")) {
return pzhzdClient.getPrdoucts(udiwmsProductRequest);
} else
} else if (curFlag.equals("YG_UDPLAT_V1.0")){
return udPlatClient.getPrdoucts(udiwmsProductRequest);
}
return ResultVOUtils.error(500, "未设置系统版本!");
}

@ -0,0 +1,12 @@
package com.glxp.mipsdl.admin.dao.config;
import com.glxp.mipsdl.admin.entity.config.ThrPartConfig;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface ThrConfigDao {
ThrPartConfig selectByPartName(@Param("partName") String partName);
}

@ -0,0 +1,40 @@
package com.glxp.mipsdl.admin.entity.config;
import lombok.Data;
@Data
public class ThrPartConfig {
private Integer id;
/**
* /
*/
private String partName;
/**
*
*/
private String host;
/**
* appId
*/
private String appId;
/**
*
*/
private String secretKey;
/**
*
*/
private String userName;
/**
*
*/
private String remark;
}

@ -42,4 +42,6 @@ public class UdplatGoodsEntity {
private Date createTime;//创建时间
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;//最后更新时间
private Integer matchLevel; //对照层级 1.产品 2.单一规格
}

@ -8,4 +8,71 @@ public class UdiwmsProductRequest extends ListPageRequest{
private String code; //产品编码
private String name; //产品名称
//计量单位
private String measname;
//规格型号
private String spec;
//注册/备案号
private String registerNo;
//生产厂家
private String manufactory;
//产品类别
private String cplb;
//分类编码
private String flbm;
//器械类别
private String qxlb;
//医保编码
private String ybbm;
//商品条码
private String sptm;
//注册人社会信用号
private String tyshxydm;
//注册证 备案证号
private String zczbhhzbapzbh;
//注册/备案人
private String ylqxzcrbarmc;
//注册/备案人英文
private String ylqxzcrbarywmc;
//产品描述
private String cpms;
//型号
private String model;
//型号
private String standard;
//商品名称
private String spmc;
//其他编码
private String qtbm;
//注册证有效期至
private String zczyxqz;
//备注
private String remark;
//备注1
private String remark1;
//备注2
private String remark2;
//备注3
private String remark3;
}

@ -2,14 +2,74 @@ package com.glxp.mipsdl.admin.res.system;
import lombok.Data;
import java.util.Date;
@Data
public class UdiwmsProductInfoResponse {
private String code; //产品编码
private String name;
private String name; //通用名称
private String measname; //计量单位
private String spec; //规格型号
private String registerNo; //注册证号
private String manufactory; //生产厂家
private String supName; //配送企业
private Date updateTime;
private boolean isChecked;
//产品类别
private String cplb;
//分类编码
private String flbm;
//器械类别
private String qxlb;
//医保编码
private String ybbm;
//商品条码
private String sptm;
//注册人社会信用号
private String tyshxydm;
//注册证 备案证号
private String zczbhhzbapzbh;
//注册/备案人
private String ylqxzcrbarmc;
//注册/备案人英文
private String ylqxzcrbarywmc;
//产品描述
private String cpms;
//型号
private String model;
//型号
private String standard;
//商品名称
private String spmc;
//其他编码
private String qtbm;
//注册证有效期至
private String zczyxqz;
//备注
private String remark;
//备注1
private String remark1;
//备注2
private String remark2;
//备注3
private String remark3;
}

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.glxp.mipsdl.admin.dao.config.ThrConfigDao">
<select id="selectByPartName" resultType="com.glxp.mipsdl.admin.entity.config.ThrPartConfig">
select * from thr_part_config where partName = #{partName}
</select>
</mapper>
Loading…
Cancel
Save