feat: 药品关联关系功能

dev_unify
chenhc 6 months ago
parent bb10befc0f
commit 11b1c70394

@ -112,4 +112,7 @@ public class RelCodeBatch implements Serializable {
@ApiModelProperty(value = "")
private String updateUser;
@TableField(value = "uploadFlag")
@ApiModelProperty(value = "")
private Integer uploadFlag;
}

@ -5,11 +5,17 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.XmlUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import com.glxp.api.dao.collect.RelCodeBatchMapper;
import com.glxp.api.entity.auth.AuthAdmin;
import com.glxp.api.entity.basic.ProductInfoEntity;
import com.glxp.api.entity.collect.RelCodeBatch;
import com.glxp.api.entity.collect.RelCodeDetail;
import com.glxp.api.exception.JsonException;
@ -17,8 +23,10 @@ import com.glxp.api.req.collect.RelCodeBatchRequest;
import com.glxp.api.req.collect.RelCodeDetailRequest;
import com.glxp.api.res.collect.RelCodeBatchResponse;
import com.glxp.api.service.auth.CustomerService;
import com.glxp.api.util.HttpClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
@ -28,10 +36,7 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@Service
@ -217,4 +222,33 @@ public class RelCodeBatchService extends ServiceImpl<RelCodeBatchMapper, RelCode
});
}
}
@Value("${UDI_SERVER_URL}")
private String udiUrl;
/**
*
*/
@Transactional(rollbackFor = Exception.class)
public boolean uploadDrugDataOne(RelCodeBatchRequest relCodeBatchRequest) {
String json = JSONObject.toJSONString(relCodeBatchRequest);
String response = HttpClient.uCloudPost(udiUrl + "/udiwms/relCode/batch/add", json);
try {
BaseResponse<Object> baseResponse =
JSONObject.parseObject(response, new TypeReference<BaseResponse<Object>>() {
});
if (baseResponse.getCode() == 20000){
Integer id = relCodeBatchRequest.getId();
return this.update( new LambdaUpdateWrapper<RelCodeBatch>().set(RelCodeBatch::getUploadFlag,1).eq(RelCodeBatch::getId,id));
}else {
Integer id = relCodeBatchRequest.getId();
this.update( new LambdaUpdateWrapper<RelCodeBatch>().set(RelCodeBatch::getUploadFlag,3).eq(RelCodeBatch::getId,id));
return false;
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}

@ -0,0 +1,86 @@
package com.glxp.api.task;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.glxp.api.dao.schedule.ScheduledDao;
import com.glxp.api.entity.collect.RelCodeBatch;
import com.glxp.api.entity.collect.RelCodeDetail;
import com.glxp.api.entity.system.ScheduledEntity;
import com.glxp.api.idc.service.IdcService;
import com.glxp.api.req.collect.RelCodeBatchRequest;
import com.glxp.api.req.collect.RelCodeDetailRequest;
import com.glxp.api.req.system.ScheduledRequest;
import com.glxp.api.service.collect.RelCodeBatchService;
import com.glxp.api.service.collect.RelCodeDetailService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Component
@EnableScheduling
public class UploadDrugDataTask implements SchedulingConfigurer {
final Logger logger = LoggerFactory.getLogger(UploadDrugDataTask.class);
@Resource
private ScheduledDao scheduledDao;
@Resource
private RelCodeBatchService relCodeBatchService;
@Resource
private RelCodeDetailService relCodeDetailService;
@Override
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
scheduledTaskRegistrar.addTriggerTask(() -> process(),
triggerContext -> {
ScheduledRequest scheduledRequest = new ScheduledRequest();
scheduledRequest.setCronName("uploadDrugData");
logger.info("uploadDrugData----------------");
ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest);
String cron = scheduledEntity != null ? scheduledEntity.getCron() : "0 0/5 * * * ?";
if (cron.isEmpty()) {
logger.error("cron is null");
}
logger.info("uploadDrugData----------------");
return new CronTrigger(cron).nextExecutionTime(triggerContext);
});
}
private void process() {
logger.info("uploadDrugData----process------------");
//查找扫描
List<RelCodeBatch> list = relCodeBatchService.list(new LambdaUpdateWrapper<RelCodeBatch>().in(RelCodeBatch::getUploadFlag, 0, 2));
if (CollUtil.isNotEmpty(list)){
for (int i = 0; i < list.size(); i++) {
RelCodeBatch relCodeBatch = list.get(i);
Integer id = relCodeBatch.getId();
List<RelCodeDetail> list1 = relCodeDetailService.list(new LambdaUpdateWrapper<RelCodeDetail>().eq(RelCodeDetail::getBatchIdFk, id));
List<RelCodeDetailRequest> detailList = new ArrayList<>();
if (CollUtil.isNotEmpty(list)){
for (int i1 = 0; i1 < list1.size(); i1++) {
RelCodeDetail relCodeDetail = list1.get(i1);
RelCodeDetailRequest request = new RelCodeDetailRequest();
BeanUtils.copyProperties(relCodeDetail,request);
detailList.add(request);
}
}
RelCodeBatchRequest relCodeBatchRequest = new RelCodeBatchRequest();
BeanUtils.copyProperties(relCodeBatch,relCodeBatchRequest);
relCodeBatchRequest.setDetailList(detailList);
relCodeBatchService.uploadDrugDataOne(relCodeBatchRequest);
}
}
}
}

@ -1,6 +1,9 @@
package com.glxp.api.util;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.web.client.RestTemplate;
import java.io.UnsupportedEncodingException;
@ -13,18 +16,17 @@ import java.util.Map;
@Slf4j
public class HttpClient {
// public static String uCloudPost(String url, Object object) {
// RestTemplate restTemplate = new RestTemplate();
// String json = JSONObject.toJSON(object).toString();
// log.info(url + "\n" + json);
// HttpHeaders headers = new HttpHeaders();
// headers.add("Content-Type", "application/json");
// HttpEntity<String> httpEntity = new HttpEntity<>(json, headers);
// log.info(httpEntity.toString());
// String response = restTemplate.postForObject(url, httpEntity, String.class);
// log.info(response);
// return response;
// }
public static String uCloudPost(String url, String json) {
RestTemplate restTemplate = new RestTemplate();
log.info(url + "\n" + json);
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json");
HttpEntity<String> httpEntity = new HttpEntity<>(json, headers);
log.info(httpEntity.toString());
String response = restTemplate.postForObject(url, httpEntity, String.class);
log.info(response);
return response;
}
/**
*

Loading…
Cancel
Save