You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
5.0 KiB
Java
115 lines
5.0 KiB
Java
package com.glxp.api.controller.basic;
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.util.ReflectUtil;
|
|
import com.glxp.api.dao.basic.UdiProductDao;
|
|
import com.glxp.api.dao.basic.UdiRelevanceDao;
|
|
import com.glxp.api.dao.thrsys.ThrProductsDao;
|
|
import com.glxp.api.entity.basic.UdiProductEntity;
|
|
import com.glxp.api.entity.basic.UdiRelevanceEntity;
|
|
import com.glxp.api.entity.thrsys.FilterThrProductsRequest;
|
|
import com.glxp.api.entity.thrsys.ThrProductsEntity;
|
|
import com.glxp.api.req.basic.FilterUdiRelRequest;
|
|
import com.glxp.api.req.basic.UdiInfoExportRequest;
|
|
import com.glxp.api.res.basic.UdiRelevanceExportJsonResponse;
|
|
import com.glxp.api.res.basic.UdiRelevanceResponse;
|
|
import com.glxp.api.service.basic.UdiRelevanceService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.io.File;
|
|
|
|
import java.lang.reflect.Field;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
@Slf4j
|
|
@Service
|
|
public class BasicGenJsonService {
|
|
@Resource
|
|
ThrProductsDao thrProductsDao;
|
|
|
|
|
|
@Resource
|
|
UdiRelevanceService udiRelevanceService;
|
|
@Resource
|
|
UdiProductDao udiProductDao;
|
|
@Resource
|
|
UdiRelevanceDao udiRelevanceDao;
|
|
|
|
|
|
public UdiRelevanceExportJsonResponse paresDataJson(UdiInfoExportRequest udiInfoExportRequest) {
|
|
UdiRelevanceExportJsonResponse exportData = new UdiRelevanceExportJsonResponse();
|
|
//选中导出
|
|
if (CollUtil.isNotEmpty(udiInfoExportRequest.getUuids())) {
|
|
List<String> uuids = udiInfoExportRequest.getUuids();
|
|
uuids.forEach(uuid -> {
|
|
FilterUdiRelRequest filterUdiRelRequest = new FilterUdiRelRequest();
|
|
filterUdiRelRequest.setUuid(uuid);
|
|
List<UdiRelevanceResponse> udiRelevanceResponses = udiRelevanceService.filterUdiRelevance(filterUdiRelRequest);
|
|
if (CollUtil.isNotEmpty(udiRelevanceResponses)) {
|
|
parseUdiRelevanceResponses(exportData, udiRelevanceResponses);
|
|
}
|
|
});
|
|
} else {
|
|
//一键导出
|
|
FilterUdiRelRequest filterUdiRelRequest = new FilterUdiRelRequest();
|
|
BeanUtil.copyProperties(udiInfoExportRequest, filterUdiRelRequest);
|
|
filterUdiRelRequest.setPage(null);
|
|
List<UdiRelevanceResponse> data = udiRelevanceService.filterUdiRelevance(filterUdiRelRequest);
|
|
if (CollUtil.isNotEmpty(data)) {
|
|
parseUdiRelevanceResponses(exportData, data);
|
|
}
|
|
}
|
|
return exportData;
|
|
}
|
|
/**
|
|
* 解析医疗器械信息查询结果,封装完整数据
|
|
*
|
|
* @param exportData
|
|
* @param udiRelevanceResponses
|
|
*/
|
|
private void parseUdiRelevanceResponses(UdiRelevanceExportJsonResponse exportData, List<UdiRelevanceResponse> udiRelevanceResponses) {
|
|
List<String> uuids = new ArrayList<>(udiRelevanceResponses.size());
|
|
udiRelevanceResponses.forEach(udi -> {
|
|
uuids.add(udi.getUuid());
|
|
});
|
|
List<UdiProductEntity> udiInfoEntities = udiProductDao.batchSelectByUuid(uuids);
|
|
List<UdiRelevanceEntity> udiRelevanceEntities = udiRelevanceDao.batchSelectByUuid(uuids);
|
|
if (CollUtil.isNotEmpty(udiRelevanceEntities)) {
|
|
List<ThrProductsEntity> thrProductsEntities = new ArrayList<>(udiRelevanceEntities.size());
|
|
Field[] fields = ReflectUtil.getFields(UdiRelevanceEntity.class);
|
|
udiRelevanceEntities.forEach(udiRelevanceEntity -> {
|
|
for (Field field : fields) {
|
|
if (field.getName().contains("thirdId")) {
|
|
Object fieldValue = ReflectUtil.getFieldValue(udiRelevanceEntity, field);
|
|
if (null != fieldValue) {
|
|
com.glxp.api.req.thrsys.FilterThrProductsRequest filter = new com.glxp.api.req.thrsys.FilterThrProductsRequest();
|
|
filter.setCode(String.valueOf(fieldValue));
|
|
filter.setThirdSysFk("thirdId");
|
|
List<ThrProductsEntity> result = thrProductsDao.filterThrProducts(filter);
|
|
if (CollUtil.isNotEmpty(result)) {
|
|
thrProductsEntities.addAll(result);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
if (CollUtil.isNotEmpty(thrProductsEntities)) {
|
|
exportData.setThrProductsEntities(thrProductsEntities);
|
|
}
|
|
}
|
|
List<UdiProductEntity> udiInfo = exportData.getUdiProductEntities();
|
|
List<UdiRelevanceEntity> udiRelevance = exportData.getUdiRelevanceEntities();
|
|
udiInfo.addAll(udiInfoEntities);
|
|
udiRelevance.addAll(udiRelevanceEntities);
|
|
exportData.setUdiProductEntities(udiInfo);
|
|
exportData.setUdiRelevanceEntities(udiRelevance);
|
|
}
|
|
|
|
}
|