package com.glxp.api.res.alihealth; import cn.hutool.Hutool; import cn.hutool.http.HttpUtil; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.annotation.TableField; import com.glxp.api.entity.collect.RelCodeBatch; import com.glxp.api.entity.collect.RelCodeDetail; import com.taobao.api.TaobaoObject; import com.taobao.api.internal.mapping.ApiField; import com.taobao.api.internal.mapping.ApiListField; import com.taobao.api.response.AlibabaAlihealthDrugtraceTopLsydQueryRelationResponse; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import org.apache.commons.lang3.StringUtils; import org.apache.poi.ss.formula.functions.T; import org.springframework.beans.BeanUtils; import java.io.Serializable; import java.util.*; @Data public class AlihealthKytSinglerelationResponse extends AlihealthKytCommonParametersResponse{ private JSONObject base_infos_d_t_o; private String code; private JSONObject code_active_info_d_t_o; private JSONObject code_relation_list; private String is_smallest; private JSONObject pkg_info_d_t_o; private JSONObject produce_info_list; public AlihealthKytSinglerelationResponse(String json) { // 初始化请求的值 cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(json); JSONObject jsonObjectResult = null; for (String s : jsonObject.keySet()) { jsonObjectResult = jsonObject.getJSONObject(s).getJSONObject("result"); } AlihealthKytCommonParametersResponse alihealthKytCommonParametersResponse = JSONUtil.toBean(jsonObjectResult.toString(), AlihealthKytCommonParametersResponse.class); BeanUtils.copyProperties(alihealthKytCommonParametersResponse,this); if(StringUtils.isNotEmpty(this.getMsg_info()) && this.getMsg_info().equals("调用成功") ){ this.disposeResult(jsonObjectResult); } } public void disposeResult(JSONObject jsonObjectResult){ JSONArray jsonArray = jsonObjectResult.getJSONObject("model_list").getJSONArray("code_relation_dto"); JSONObject codeRelationDto = (JSONObject) jsonArray.get(0); if (!Objects.isNull(codeRelationDto)) { this.setBase_infos_d_t_o(codeRelationDto.getJSONObject("base_infos_d_t_o")); this.setCode(codeRelationDto.getStr("code")); this.setCode_active_info_d_t_o(codeRelationDto.getJSONObject("code_active_info_d_t_o")); this.setCode_relation_list(codeRelationDto.getJSONObject("code_relation_list")); this.setIs_smallest(codeRelationDto.getStr("is_smallest")); this.setPkg_info_d_t_o(codeRelationDto.getJSONObject("pkg_info_d_t_o")); this.setProduce_info_list(codeRelationDto.getJSONObject("produce_info_list")); } } public RelCodeBatch disposeRelCodeBatch(String customerId){ JSONArray jsonArrayBaseInfoDto = this.getBase_infos_d_t_o().getJSONObject("base_info_list").getJSONArray("base_info_dto"); JSONObject jsonObject = (JSONObject) jsonArrayBaseInfoDto.get(0); RelCodeBatch relCodeBatch = new RelCodeBatch(); List> jsonArray = (List) this.getCode_relation_list().get("code_info"); Integer oneLevelCount = 0; Integer twoLevelCount = 0; Integer threeLevelCount = 0; String parentCode = null; if (jsonArray != null && jsonArray.size() > 0) { parentCode = jsonArray.get(0).get("parent_code"); relCodeBatch.setCurCode(parentCode); for (Map map : jsonArray) { switch (map.get("code_level")) { case "1": oneLevelCount++; break; case "2": twoLevelCount++; break; case "3": threeLevelCount++; break; } } } // relCodeBatch.setId(); relCodeBatch.setProductCode(parentCode); relCodeBatch.setSubTypeNo(jsonObject.getStr("relation_type")); relCodeBatch.setCascadeRatio(jsonObject.getStr("pkg_ratio")); relCodeBatch.setPackageSpec(jsonObject.getStr("pkg_spec")); // relCodeBatch.setComment(); relCodeBatch.setBatchNo(jsonObject.getStr("produce_batch_no")); relCodeBatch.setMadeDate(jsonObject.getStr("produce_date")); relCodeBatch.setValidateDate(jsonObject.getStr("exprie_date")); relCodeBatch.setWorkShop(jsonObject.getStr("exprie_date")); // relCodeBatch.setLineName(); relCodeBatch.setLineManager(jsonObject.getStr("oper_ic_name")); // relCodeBatch.setCreateTime(); // relCodeBatch.setCreateUser(); relCodeBatch.setUpdateTime(new Date()); relCodeBatch.setUpdateUser(customerId); relCodeBatch.setUploadFlagUp(0); relCodeBatch.setUploadFlagDown(0); relCodeBatch.setParentCode(null); // relCodeBatch.setErpId(); relCodeBatch.setOneLevelCount(oneLevelCount); relCodeBatch.setTwoLevelCount(twoLevelCount); relCodeBatch.setThreeLevelCount(threeLevelCount); return relCodeBatch; } public List disposeRelRodeDetailList(Integer batchIdFk) { List list = new ArrayList<>(); List> jsonArray = (List) this.getCode_relation_list().get("code_info"); if (jsonArray != null && jsonArray.size() > 0) { for (Map map : jsonArray) { if (!Objects.isNull(map)) { RelCodeDetail relCodeDetail = new RelCodeDetail(); relCodeDetail.setCurCode(map.get("code")); relCodeDetail.setPackLayer(Integer.valueOf(map.get("code_level"))); relCodeDetail.setParentCode(map.get("parent_code")); Integer flag = null; switch (map.get("status")) { case "I": flag = 1; break; case "O": flag = 0; break; } relCodeDetail.setFlag(flag); relCodeDetail.setBatchIdFk(batchIdFk); list.add(relCodeDetail); } } } return list; } }