|
@@ -2,24 +2,30 @@ package org.jeecg.modules.medical.service.impl;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.lang.StringUtils;
|
|
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
|
|
+import org.jeecg.common.exception.JeecgBootException;
|
|
|
import org.jeecg.common.system.util.JwtUtil;
|
|
import org.jeecg.common.system.util.JwtUtil;
|
|
|
|
|
+import org.jeecg.common.util.oConvertUtils;
|
|
|
import org.jeecg.modules.medical.common.ExcelImportUtilService;
|
|
import org.jeecg.modules.medical.common.ExcelImportUtilService;
|
|
|
import org.jeecg.modules.medical.entity.AdviceDetailsVO;
|
|
import org.jeecg.modules.medical.entity.AdviceDetailsVO;
|
|
|
|
|
+import org.jeecg.modules.medical.entity.MaterialItems;
|
|
|
import org.jeecg.modules.medical.entity.MedicalInsuranceDrugs;
|
|
import org.jeecg.modules.medical.entity.MedicalInsuranceDrugs;
|
|
|
import org.jeecg.modules.medical.mapper.MedicalInsuranceDrugsMapper;
|
|
import org.jeecg.modules.medical.mapper.MedicalInsuranceDrugsMapper;
|
|
|
import org.jeecg.modules.medical.service.IMedicalInsuranceDrugsService;
|
|
import org.jeecg.modules.medical.service.IMedicalInsuranceDrugsService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -50,7 +56,24 @@ public class MedicalInsuranceDrugsServiceImpl extends ServiceImpl<MedicalInsuran
|
|
|
log.error("找不到用户登录的tokne");
|
|
log.error("找不到用户登录的tokne");
|
|
|
}
|
|
}
|
|
|
final String finalUsername = username;
|
|
final String finalUsername = username;
|
|
|
- return excelImportUtilService.importExcel(request,
|
|
|
|
|
|
|
+
|
|
|
|
|
+ return excelImportUtilService.importExcel2(request,
|
|
|
|
|
+ MedicalInsuranceDrugs.class,
|
|
|
|
|
+ this::requiredCheck,
|
|
|
|
|
+ true,
|
|
|
|
|
+ this::getDuplicateRm,
|
|
|
|
|
+ this::loadDbExistsList,
|
|
|
|
|
+ (nd, od) -> {
|
|
|
|
|
+ nd.setId(od.getId());
|
|
|
|
|
+ nd.setUpdateBy(finalUsername); //更新人
|
|
|
|
|
+ nd.setUpdateTime(new Date());
|
|
|
|
|
+ return nd;
|
|
|
|
|
+ },
|
|
|
|
|
+ // 根据导入数据,和数据库中的数据,取出差集 用于新增
|
|
|
|
|
+ this::updateBatchById,
|
|
|
|
|
+ this::saveBatch
|
|
|
|
|
+ );
|
|
|
|
|
+ /*return excelImportUtilService.importExcel(request,
|
|
|
MedicalInsuranceDrugs.class,
|
|
MedicalInsuranceDrugs.class,
|
|
|
// 根据什么字段去重,以及筛选哪些数据已经有了的依据
|
|
// 根据什么字段去重,以及筛选哪些数据已经有了的依据
|
|
|
MedicalInsuranceDrugs::getMedicineCode,
|
|
MedicalInsuranceDrugs::getMedicineCode,
|
|
@@ -69,92 +92,57 @@ public class MedicalInsuranceDrugsServiceImpl extends ServiceImpl<MedicalInsuran
|
|
|
// 根据导入数据,和数据库中的数据,取出差集 用于新增
|
|
// 根据导入数据,和数据库中的数据,取出差集 用于新增
|
|
|
this::updateBatchById,
|
|
this::updateBatchById,
|
|
|
this::saveBatch
|
|
this::saveBatch
|
|
|
- );
|
|
|
|
|
- /*if (1 == 1) {
|
|
|
|
|
- return null;
|
|
|
|
|
|
|
+ );*/
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据数据,查询数据库中是否有重复
|
|
|
|
|
+ * @param list
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<MedicalInsuranceDrugs> loadDbExistsList(List<MedicalInsuranceDrugs> list) {
|
|
|
|
|
+ // 固定这两个字段,projectCode为必须,correlationProjectCode为可选
|
|
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
|
|
+ return new ArrayList<>();
|
|
|
}
|
|
}
|
|
|
- MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
|
|
- Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
|
|
- for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
|
|
- // 获取上传文件对象
|
|
|
|
|
- MultipartFile file = entity.getValue();
|
|
|
|
|
- ImportParams params = new ImportParams();
|
|
|
|
|
- params.setTitleRows(2);
|
|
|
|
|
- params.setHeadRows(1);
|
|
|
|
|
- params.setNeedSave(true);
|
|
|
|
|
- try {
|
|
|
|
|
- List<MedicalInsuranceDrugs> list = ExcelImportUtil.importExcel(file.getInputStream(), MedicalInsuranceDrugs.class, params);
|
|
|
|
|
- if (CollectionUtils.isEmpty(list)) {
|
|
|
|
|
- return Result.error("文件导入失败:没有找到要导入的数据!");
|
|
|
|
|
- }
|
|
|
|
|
- if (list.size() > 10000) {
|
|
|
|
|
- return Result.error("文件导入失败:不可一次性导入超过10000条数据!");
|
|
|
|
|
- }
|
|
|
|
|
- // 去重
|
|
|
|
|
- list = list.stream().collect(
|
|
|
|
|
- Collectors.collectingAndThen(
|
|
|
|
|
- Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(MedicalInsuranceDrugs::getMedicineCode))), ArrayList::new
|
|
|
|
|
- )
|
|
|
|
|
- );
|
|
|
|
|
- //检查是否有更新的数据,根据医保药品编码
|
|
|
|
|
- List<String> collect = list.stream().map(MedicalInsuranceDrugs::getMedicineCode).collect(Collectors.toList());
|
|
|
|
|
- List<MedicalInsuranceDrugs> dbExistsList = this.listByMedicineCodeIn(collect);
|
|
|
|
|
- // 更新列表
|
|
|
|
|
- List<MedicalInsuranceDrugs> updateList = new ArrayList<>();
|
|
|
|
|
- // 新增列表
|
|
|
|
|
- List<MedicalInsuranceDrugs> instalList = list;
|
|
|
|
|
- if (!CollectionUtils.isEmpty(dbExistsList)) { // 不为空时, 需要将存在的做更新操作
|
|
|
|
|
- // 取出交集
|
|
|
|
|
- updateList = list.stream().filter(
|
|
|
|
|
- a -> dbExistsList.stream().map(MedicalInsuranceDrugs::getMedicineCode)
|
|
|
|
|
- .anyMatch(
|
|
|
|
|
- medicineCode -> ObjectUtils.nullSafeEquals(a.getMedicineCode(), medicineCode)
|
|
|
|
|
- )
|
|
|
|
|
- ).collect(Collectors.toList());
|
|
|
|
|
- // 如果有则需要更新
|
|
|
|
|
- if (!CollectionUtils.isEmpty(updateList)) {
|
|
|
|
|
- this.updateBatchById(updateList, 500);
|
|
|
|
|
- }
|
|
|
|
|
- // 取出差集
|
|
|
|
|
- instalList = list.stream().filter(
|
|
|
|
|
- excelData -> dbExistsList.stream().map(MedicalInsuranceDrugs::getMedicineCode).noneMatch(medicineCode ->
|
|
|
|
|
- ObjectUtils.nullSafeEquals(excelData.getMedicineCode(), medicineCode))
|
|
|
|
|
- ).collect(Collectors.toList());
|
|
|
|
|
- }
|
|
|
|
|
- //update-begin-author:taoyan date:20190528 for:批量插入数据
|
|
|
|
|
- long start = System.currentTimeMillis();
|
|
|
|
|
- if (!CollectionUtils.isEmpty(instalList)) {
|
|
|
|
|
- this.saveBatch(instalList, 500);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ QueryWrapper<MedicalInsuranceDrugs> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
+ List<String> itemIdHostKeys = new ArrayList<>();
|
|
|
|
|
+ for (MedicalInsuranceDrugs item : list) {
|
|
|
|
|
+ String itemIdHosp = item.getItemIdHosp();
|
|
|
|
|
+ if (!StringUtils.hasText(itemIdHosp)) {
|
|
|
|
|
+ log.error("数据导入时,没有找到{}请检查导入文件内容", "医保项目编码");
|
|
|
|
|
+ throw new JeecgBootException("没有找到项目编码,请检查导入内容");
|
|
|
|
|
+ }
|
|
|
|
|
+ itemIdHostKeys.add(itemIdHosp);
|
|
|
|
|
+ }
|
|
|
|
|
+ String itemIdHostSQLField = oConvertUtils.camelToUnderline("itemIdHosp");
|
|
|
|
|
+ queryWrapper.in(itemIdHostSQLField, itemIdHostKeys);
|
|
|
|
|
+ return this.list(queryWrapper);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- //400条 saveBatch消耗时间1592毫秒 循环插入消耗时间1947毫秒
|
|
|
|
|
- //1200条 saveBatch消耗时间3687毫秒 循环插入消耗时间5212毫秒
|
|
|
|
|
- log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
|
|
|
|
|
- //update-end-author:taoyan date:20190528 for:批量插入数据
|
|
|
|
|
- return Result.ok("文件导入成功!数据行数:" + list.size());
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- //update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示
|
|
|
|
|
- String msg = e.getMessage();
|
|
|
|
|
- log.error(msg, e);
|
|
|
|
|
- if(msg!=null && msg.contains("Duplicate entry")){
|
|
|
|
|
- return Result.error("文件导入失败:有重复数据!");
|
|
|
|
|
- }else{
|
|
|
|
|
- return Result.error("文件导入失败:" + e.getMessage());
|
|
|
|
|
- }
|
|
|
|
|
- //update-end-author:taoyan date:20211124 for: 导入数据重复增加提示
|
|
|
|
|
- } finally {
|
|
|
|
|
- try {
|
|
|
|
|
- file.getInputStream().close();
|
|
|
|
|
- } catch (IOException e) {
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 构建去重因子
|
|
|
|
|
+ private String getDuplicateRm(MedicalInsuranceDrugs medicalInsuranceDrugs) {
|
|
|
|
|
+ return ifnull(medicalInsuranceDrugs.getItemIdHosp());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private Object requiredCheck(List<MedicalInsuranceDrugs> list) {
|
|
|
|
|
+ // 检查导入必填数据
|
|
|
|
|
+ for (MedicalInsuranceDrugs item : list) {
|
|
|
|
|
+ // 医院项目编码
|
|
|
|
|
+ String itemIdHosp = item.getItemIdHosp();
|
|
|
|
|
+ if (!StringUtils.hasText(itemIdHosp)) {
|
|
|
|
|
+ log.error("数据导入时,找不到医院项目编码,请检查");
|
|
|
|
|
+ throw new JeecgBootException("医院项目编码为空,医院项目编码必填,请检查!");
|
|
|
}
|
|
}
|
|
|
- }*/
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/*@NotNull
|
|
/*@NotNull
|
|
|
private static List<MedicalInsuranceDrugs> getUpdateDatas(final String updateOperator, List<MedicalInsuranceDrugs> list, List<MedicalInsuranceDrugs> dbExistsList) {
|
|
private static List<MedicalInsuranceDrugs> getUpdateDatas(final String updateOperator, List<MedicalInsuranceDrugs> list, List<MedicalInsuranceDrugs> dbExistsList) {
|
|
|
List<MedicalInsuranceDrugs> collect = list.stream().filter(
|
|
List<MedicalInsuranceDrugs> collect = list.stream().filter(
|