lenovodn hace 2 años
padre
commit
858c019204

+ 19 - 23
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/controller/MedicineController.java

@@ -12,7 +12,9 @@ import javax.servlet.http.HttpServletResponse;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.query.QueryGenerator;
 import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.modules.medical.entity.MaterialItems;
 import org.jeecg.modules.medical.entity.Medicine;
+import org.jeecg.modules.medical.service.DefaultExcelSupportChineseService;
 import org.jeecg.modules.medical.service.IMedicineService;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -50,7 +52,8 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
 public class MedicineController extends JeecgController<Medicine, IMedicineService> {
 	@Autowired
 	private IMedicineService medicineService;
-	
+	 @Autowired
+	 private DefaultExcelSupportChineseService<Medicine> excelSupportChineseService;
 	/**
 	 * 分页列表查询
 	 *
@@ -62,7 +65,7 @@ public class MedicineController extends JeecgController<Medicine, IMedicineServi
 	 */
 	//@AutoLog(value = "medicine-分页列表查询")
 	@ApiOperation(value="medicine-分页列表查询", notes="medicine-分页列表查询")
-	@GetMapping(value = "/list")
+	@GetMapping(value = {"/list", "/list/{sourceType}"})
 	public Result<IPage<Medicine>> queryPageList(Medicine medicine,
 								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
 								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
@@ -146,27 +149,20 @@ public class MedicineController extends JeecgController<Medicine, IMedicineServi
 		return Result.OK(medicine);
 	}
 
-    /**
-    * 导出excel
-    *
-    * @param request
-    * @param medicine
-    */
-    @RequestMapping(value = "/exportXls")
-    public ModelAndView exportXls(HttpServletRequest request, Medicine medicine) {
-        return super.exportXls(request, medicine, Medicine.class, "medicine");
-    }
 
-    /**
-      * 通过excel导入数据
-    *
-    * @param request
-    * @param response
-    * @return
-    */
-    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
-    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
-        return super.importExcel(request, response, Medicine.class);
-    }
+	 @RequestMapping(value = "/exportXls")
+	 public ModelAndView exportXlsSunShine(HttpServletRequest request, Medicine medicine) {
+		 try{
+			 return excelSupportChineseService.exportXlsEmpty(request, medicine, Medicine.class, "阳光挂网");
+		 } catch (
+				 UnsupportedEncodingException e) {
+			 throw new RuntimeException(e);
+		 }
+	 }
+
+	 @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
+	 public Result<?> importExcelSunshine(HttpServletRequest request, HttpServletResponse response) {
+		 return medicineService.importExcel(request, response);
+	 }
 
 }

+ 167 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/controller/OtherMedicineController.java

@@ -0,0 +1,167 @@
+package org.jeecg.modules.medical.controller;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.aspect.annotation.AutoLog;
+import org.jeecg.common.system.base.controller.JeecgController;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.modules.medical.entity.Medicine;
+import org.jeecg.modules.medical.entity.OtherMedicine;
+import org.jeecg.modules.medical.service.DefaultExcelSupportChineseService;
+import org.jeecg.modules.medical.service.IMedicineService;
+import org.jeecg.modules.medical.service.IOtherMedicineService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+
+/**
+ * @Description: otherMedicine
+ * @Author: jeecg-boot
+ * @Date: 2023-04-23
+ * @Version: V1.0
+ */
+@Api(tags = "medicine")
+@RestController
+@RequestMapping("/medical/otherMedicine")
+@Slf4j
+public class OtherMedicineController extends JeecgController<OtherMedicine, IOtherMedicineService> {
+    @Autowired
+    private IOtherMedicineService otherMedicineService;
+    @Autowired
+    private DefaultExcelSupportChineseService<OtherMedicine> excelSupportChineseService;
+
+    /**
+     * 分页列表查询
+     *
+     * @param medicine
+     * @param pageNo
+     * @param pageSize
+     * @param req
+     * @return
+     */
+    //@AutoLog(value = "medicine-分页列表查询")
+    @ApiOperation(value = "medicine-分页列表查询", notes = "medicine-分页列表查询")
+    @GetMapping(value = "/list")
+    public Result<IPage<OtherMedicine>> queryPageList(OtherMedicine otherMedicine,
+                                                      @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
+                                                      HttpServletRequest req) {
+        QueryWrapper<OtherMedicine> queryWrapper = QueryGenerator.initQueryWrapper(otherMedicine, req.getParameterMap());
+        Page<OtherMedicine> page = new Page<OtherMedicine>(pageNo, pageSize);
+        IPage<OtherMedicine> pageList = otherMedicineService.page(page, queryWrapper);
+        return Result.OK(pageList);
+    }
+
+    /**
+     * 添加
+     *
+     * @param medicine
+     * @return
+     */
+    @AutoLog(value = "medicine-添加")
+    @ApiOperation(value = "medicine-添加", notes = "medicine-添加")
+    @PostMapping(value = "/add")
+    public Result<String> add(@RequestBody OtherMedicine medicine) {
+        otherMedicineService.save(medicine);
+        return Result.OK("添加成功!");
+    }
+
+    /**
+     * 编辑
+     *
+     * @param medicine
+     * @return
+     */
+    @AutoLog(value = "medicine-编辑")
+    @ApiOperation(value = "medicine-编辑", notes = "medicine-编辑")
+    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
+    public Result<String> edit(@RequestBody OtherMedicine medicine) {
+        otherMedicineService.updateById(medicine);
+        return Result.OK("编辑成功!");
+    }
+
+    /**
+     * 通过id删除
+     *
+     * @param id
+     * @return
+     */
+    @AutoLog(value = "medicine-通过id删除")
+    @ApiOperation(value = "medicine-通过id删除", notes = "medicine-通过id删除")
+    @DeleteMapping(value = "/delete")
+    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
+        otherMedicineService.removeById(id);
+        return Result.OK("删除成功!");
+    }
+
+    /**
+     * 批量删除
+     *
+     * @param ids
+     * @return
+     */
+    @AutoLog(value = "medicine-批量删除")
+    @ApiOperation(value = "medicine-批量删除", notes = "medicine-批量删除")
+    @DeleteMapping(value = "/deleteBatch")
+    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
+        this.otherMedicineService.removeByIds(Arrays.asList(ids.split(",")));
+        return Result.OK("批量删除成功!");
+    }
+
+    /**
+     * 通过id查询
+     *
+     * @param id
+     * @return
+     */
+    //@AutoLog(value = "medicine-通过id查询")
+    @ApiOperation(value = "medicine-通过id查询", notes = "medicine-通过id查询")
+    @GetMapping(value = "/queryById")
+    public Result<OtherMedicine> queryById(@RequestParam(name = "id", required = true) String id) {
+        OtherMedicine medicine = otherMedicineService.getById(id);
+        if (medicine == null) {
+            return Result.error("未找到对应数据");
+        }
+        return Result.OK(medicine);
+    }
+
+    /**
+     * 导出excel
+     *
+     * @param request
+     * @param medicine
+     */
+    @RequestMapping(value = "/exportXls")
+    public ModelAndView exportXls(HttpServletRequest request, OtherMedicine medicine) {
+        try {
+            return excelSupportChineseService.exportXlsEmpty(request, medicine, OtherMedicine.class, "毒麻精放、医院制剂、中药饮片");
+        } catch (
+                UnsupportedEncodingException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+
+    /**
+     * 通过excel导入数据
+     *
+     * @param request
+     * @param response
+     * @return
+     */
+    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
+    public Result<?> importExcelOtherMedicine(HttpServletRequest request, HttpServletResponse response) {
+        return otherMedicineService.importExcel(request, response);
+    }
+
+}

+ 9 - 6
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/entity/Medicine.java

@@ -33,9 +33,9 @@ public class Medicine implements Serializable {
     private static final long serialVersionUID = 1L;
 
     /**药品ID*/
-    @TableId(type = IdType.AUTO)
+    @TableId(type = IdType.ASSIGN_ID)
     @ApiModelProperty(value = "药品ID")
-    private java.lang.Integer id;
+    private java.lang.String id;
 
     /**项目编码*/
     @Excel(name = "项目编码", width = 15)
@@ -82,8 +82,8 @@ public class Medicine implements Serializable {
 //    @ApiModelProperty(value = "最小包装单位")
 //    private java.lang.String mpu;
     /**药品企业(厂家)*/
-    @Excel(name = "药品企业(厂家)", width = 15)
-    @ApiModelProperty(value = "药品企业(厂家)")
+    @Excel(name = "厂家", width = 15)
+    @ApiModelProperty(value = "厂家")
     private java.lang.String medicineEnterprise;
 //    /**批准文号*/
 //    @Excel(name = "批准文号", width = 15)
@@ -159,7 +159,7 @@ public class Medicine implements Serializable {
     /**生育保险是否支付*/
     @Excel(name = "生育保险是否支付", width = 15)
     @ApiModelProperty(value = "生育保险是否支付")
-    private java.lang.Integer isPay;
+    private java.lang.String isPay;
     /**计价单位*/
     @Excel(name = "计价单位", width = 15)
     @ApiModelProperty(value = "计价单位")
@@ -204,5 +204,8 @@ public class Medicine implements Serializable {
     @Excel(name = "挂网状态", width = 15)
     @ApiModelProperty(value = "挂网状态: in=挂网,out=暂停挂网,none=无")
     private java.lang.String gridStatus;
-
+    @ApiModelProperty(value = "数据来源:sunshine=阳光挂网,otherMedicine=毒麻精放、医院制剂、中药饮片")
+    private java.lang.String sourceType;
+    @ApiModelProperty(value = "省本级自付比例")
+    private java.lang.String proportions;
 }

+ 81 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/entity/OtherMedicine.java

@@ -0,0 +1,81 @@
+package org.jeecg.modules.medical.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.io.Serializable;
+
+/**
+ * @Description: medicine
+ * @Author: jeecg-boot
+ * @Date: 2023-05-17 23:35:41
+ * @Version: V1.0
+ */
+@Data
+@TableName("other_medicine")
+@Accessors(chain = true)
+@EqualsAndHashCode(callSuper = false)
+public class OtherMedicine implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    @TableId(type = IdType.ASSIGN_ID)
+    @ApiModelProperty(value = "药品ID")
+    private java.lang.String id;
+    @Excel(name = "备注", width = 15)
+    @ApiModelProperty(value = "备注")
+    private String remark;
+    @Excel(name = "项目编码", width = 15)
+    @ApiModelProperty(value = "项目编码")
+    private String medicineCode;
+    @Excel(name = "注册名称", width = 15)
+    @ApiModelProperty(value = "注册名称")
+    private String medicineName;
+    @Excel(name = "实际剂型", width = 15)
+    @ApiModelProperty(value = "实际剂型")
+    private String regDosForm;
+    @Excel(name = "实际规格", width = 15)
+    @ApiModelProperty(value = "实际规格")
+    private String regSpe;
+    @Excel(name = "最小包装单位", width = 15)
+    @ApiModelProperty(value = "最小包装单位")
+    private java.lang.String mpu;
+    @Excel(name = "药品企业", width = 15)
+    @ApiModelProperty(value = "药品企业")
+    private String medicineEnterprise;
+    @Excel(name = "2021版医保类别", width = 15)
+    @ApiModelProperty(value = "2021版医保类别")
+    private java.lang.String medicalInsClass;
+    @Excel(name = "省本级自付比例", width = 15)
+    @ApiModelProperty(value = "省本级自付比例")
+    private java.lang.String proportions;
+    /**发票项目*/
+    @Excel(name = "发票项目", width = 15)
+    @ApiModelProperty(value = "发票项目")
+    private java.lang.String invoiceItem;
+
+    /**创建人*/
+    @ApiModelProperty(value = "创建人")
+    private java.lang.String createBy;
+    /**创建时间*/
+    @JsonFormat(timezone = "GMT+8",pattern =  "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern= "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "创建时间")
+    private java.util.Date createTime;
+    /**更新人*/
+    @ApiModelProperty(value = "更新人")
+    private java.lang.String updateBy;
+    /**更新时间*/
+    @JsonFormat(timezone = "GMT+8",pattern =  "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern= "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "更新时间")
+    private java.util.Date updateTime;
+
+}

+ 15 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/mapper/OtherMedicineMapper.java

@@ -0,0 +1,15 @@
+package org.jeecg.modules.medical.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.jeecg.modules.medical.entity.Medicine;
+import org.jeecg.modules.medical.entity.OtherMedicine;
+
+/**
+ * @Description: medicine
+ * @Author: jeecg-boot
+ * @Date:   2023-04-23
+ * @Version: V1.0
+ */
+public interface OtherMedicineMapper extends BaseMapper<OtherMedicine> {
+
+}

+ 5 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/mapper/xml/OtherMedicineMapper.xml

@@ -0,0 +1,5 @@
+<?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="org.jeecg.modules.medical.mapper.OtherMedicineMapper">
+
+</mapper>

+ 18 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/service/IMedicineService.java

@@ -1,7 +1,14 @@
 package org.jeecg.modules.medical.service;
 
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.modules.medical.entity.MaterialItems;
 import org.jeecg.modules.medical.entity.Medicine;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.springframework.util.StringUtils;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
 
 /**
  * @Description: medicine
@@ -11,4 +18,15 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IMedicineService extends IService<Medicine> {
 
+    Result<?> importExcel(HttpServletRequest request, HttpServletResponse response);
+
+    default String ifnull(String str) {
+        if (StringUtils.hasText(str)) {
+            return str;
+        }
+        return "";
+    }
+
+    List<Medicine> loadDbExistsList(List<Medicine> list);
+
 }

+ 32 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/service/IOtherMedicineService.java

@@ -0,0 +1,32 @@
+package org.jeecg.modules.medical.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.modules.medical.entity.Medicine;
+import org.jeecg.modules.medical.entity.OtherMedicine;
+import org.springframework.util.StringUtils;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+/**
+ * @Description: medicine
+ * @Author: jeecg-boot
+ * @Date:   2023-04-23
+ * @Version: V1.0
+ */
+public interface IOtherMedicineService extends IService<OtherMedicine> {
+
+    Result<?> importExcel(HttpServletRequest request, HttpServletResponse response);
+
+    default String ifnull(String str) {
+        if (StringUtils.hasText(str)) {
+            return str;
+        }
+        return "";
+    }
+
+    List<OtherMedicine> loadDbExistsList(List<OtherMedicine> list);
+
+}

+ 163 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/service/impl/MedicineServiceImpl.java

@@ -1,11 +1,32 @@
 package org.jeecg.modules.medical.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.exception.JeecgBootException;
+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.entity.MaterialItems;
 import org.jeecg.modules.medical.entity.Medicine;
 import org.jeecg.modules.medical.mapper.MedicineMapper;
 import org.jeecg.modules.medical.service.IMedicineService;
+import org.jeecg.modules.utils.DefaultExcelImportUtil;
+import org.jeecgframework.poi.excel.entity.ImportParams;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @Description: medicine
@@ -14,6 +35,148 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  * @Version: V1.0
  */
 @Service
+@Slf4j
 public class MedicineServiceImpl extends ServiceImpl<MedicineMapper, Medicine> implements IMedicineService {
+    @Autowired
+    private ExcelImportUtilService<Medicine, String> excelImportUtilService;
+    @Override
+    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
+        Integer rmDuplicateNumber = 0; // excel文件重复数量
+        Integer totalNumber = 0;//导入文件总数
+        Integer addNumber = 0; //新增数量
+        Integer updateNumber = 0;//更新文件数量
+
+        String username = "";
+        try {
+            username = JwtUtil.getUsername(request.getHeader("X-Access-Token"));
+        } catch (Exception e) {
+            log.error("找不到用户登录的tokne");
+        }
+        final String finalUsername = username;
+
+        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<Medicine> list = DefaultExcelImportUtil
+                        .importExcel(file.getInputStream(), Medicine.class, params);
+                if (CollectionUtils.isEmpty(list)) {
+                    log.error("导入文件没有数据,请检查");
+                    return Result.ok("上传的文件没有数据,请检查");
+                }
+                totalNumber = list.size();
+                // 检查导入必填数据
+                for (Medicine item : list) {
+                    // 医院项目编码
+                    String itemIdHosp = item.getMedicineCode();
+                    if (!StringUtils.hasText(itemIdHosp)) {
+                        log.error("数据导入时,找不到医院项目编码,请检查");
+                        throw new JeecgBootException("医院项目编码为空,医院项目编码必填,请检查!");
+                    }
+                }
+                // 倒序去重
+                List<Medicine> collect = list.stream().map(item -> item).collect(Collectors.toList());
+                Collections.reverse(collect);
+                list = collect.stream().collect(
+                        Collectors.collectingAndThen(
+                                Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(
+                                        this::getDuplicateRm
+                                ))), ArrayList::new
+                        )
+                );
+                // 随后把顺序倒回来
+                Collections.reverse(list);
+                // 文件总条数 - 去重之后剩余数量 = excel 文件的重复数据
+                if (!CollectionUtils.isEmpty(list)) {
+                    rmDuplicateNumber = totalNumber - list.size();
+                }
+
+                // 根据条件,查询数据库去重。
+                List<Medicine> dbExistsList = this.loadDbExistsList(list);
+                // 更新列表
+                List<Medicine> updateList = new ArrayList<>();
+                // 新增列表
+                List<Medicine> instalList = list;
+                if (!CollectionUtils.isEmpty(dbExistsList)) { // 不为空时, 需要将存在的做更新操作
+                    // 取出交集
+                    updateList = excelImportUtilService.getUpdateDatas(list, dbExistsList,
+                            this::getDuplicateRm,
+                            (nd, od) -> {
+                                nd.setId(od.getId());
+                                nd.setUpdateBy(finalUsername); //更新人
+                                nd.setUpdateTime(new Date());
+                                return nd;
+                            });//
+                    // 如果有则需要更新
+                    if (!CollectionUtils.isEmpty(updateList)) {
+                        updateNumber = updateList.size();
+                        this.updateBatchById(updateList, 500);
+                    }
+                    // 取出差集
+                    instalList = excelImportUtilService.getInsertDatas(list, dbExistsList, this::getDuplicateRm);
+                }
+                long start = System.currentTimeMillis();
+                if (!CollectionUtils.isEmpty(instalList)) {
+                    addNumber = instalList.size();
+                    this.saveBatch(instalList, 500);
+                }
+                log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
+                //update-end-author:taoyan date:20190528 for:批量插入数据
+                return Result.ok("文件导入成功,请点击刷新!文件总行数:" + totalNumber + "; 文件自身重复:" + rmDuplicateNumber + "; 新增行数: " + addNumber + "; 更新行数: " + updateNumber);
+            } catch (Exception e) {
+                //update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示
+                String msg = e.getMessage();
+                log.error(msg, e);
+                if (msg != null && msg.indexOf("Duplicate entry") >= 0) {
+                    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();
+                }
+            }
+        }
+        return Result.error("文件导入失败!");
+    }
+
+    /**
+     * 构建去重因子
+     * @param
+     * @return
+     */
+    private String getDuplicateRm(Medicine medicine) {
+        return ifnull(medicine.getMedicineCode());
+    }
 
+    @Override
+    public List<Medicine> loadDbExistsList(List<Medicine> list) {
+        if (CollectionUtils.isEmpty(list)) {
+            return new ArrayList<>();
+        }
+        QueryWrapper<Medicine> queryWrapper = new QueryWrapper<>();
+        List<String> itemIdHostKeys = new ArrayList<>();
+        for (Medicine item : list) {
+            String medicineCode = item.getMedicineCode();
+            if (!StringUtils.hasText(medicineCode)) {
+                log.error("数据导入时,没有找到{}请检查导入文件内容", "医保项目编码");
+                throw new JeecgBootException("没有找到项目编码,请检查导入内容");
+            }
+            itemIdHostKeys.add(medicineCode);
+        }
+        String itemIdHostSQLField = oConvertUtils.camelToUnderline("medicineCode");
+        queryWrapper.in(itemIdHostSQLField, itemIdHostKeys);
+        return this.list(queryWrapper);
+    }
 }

+ 181 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/service/impl/OtherMedicineServiceImpl.java

@@ -0,0 +1,181 @@
+package org.jeecg.modules.medical.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.exception.JeecgBootException;
+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.entity.Medicine;
+import org.jeecg.modules.medical.entity.OtherMedicine;
+import org.jeecg.modules.medical.mapper.OtherMedicineMapper;
+import org.jeecg.modules.medical.service.IOtherMedicineService;
+import org.jeecg.modules.utils.DefaultExcelImportUtil;
+import org.jeecgframework.poi.excel.entity.ImportParams;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * @Description: medicine
+ * @Author: jeecg-boot
+ * @Date:   2023-04-23
+ * @Version: V1.0
+ */
+@Service
+@Slf4j
+public class OtherMedicineServiceImpl extends ServiceImpl<OtherMedicineMapper, OtherMedicine> implements IOtherMedicineService {
+    @Autowired
+    private ExcelImportUtilService<OtherMedicine, String> excelImportUtilService;
+    @Override
+    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
+        Integer rmDuplicateNumber = 0; // excel文件重复数量
+        Integer totalNumber = 0;//导入文件总数
+        Integer addNumber = 0; //新增数量
+        Integer updateNumber = 0;//更新文件数量
+
+        String username = "";
+        try {
+            username = JwtUtil.getUsername(request.getHeader("X-Access-Token"));
+        } catch (Exception e) {
+            log.error("找不到用户登录的tokne");
+        }
+        final String finalUsername = username;
+
+        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<OtherMedicine> list = DefaultExcelImportUtil
+                        .importExcel(file.getInputStream(), OtherMedicine.class, params);
+                if (CollectionUtils.isEmpty(list)) {
+                    log.error("导入文件没有数据,请检查");
+                    return Result.ok("上传的文件没有数据,请检查");
+                }
+                totalNumber = list.size();
+                // 检查导入必填数据
+                for (OtherMedicine item : list) {
+                    // 医院项目编码
+                    String itemIdHosp = item.getMedicineCode();
+                    if (!StringUtils.hasText(itemIdHosp)) {
+                        log.error("数据导入时,找不到医院项目编码,请检查");
+                        throw new JeecgBootException("医院项目编码为空,医院项目编码必填,请检查!");
+                    }
+                }
+                // 倒序去重
+                List<OtherMedicine> collect = list.stream().map(item -> item).collect(Collectors.toList());
+                Collections.reverse(collect);
+                list = collect.stream().collect(
+                        Collectors.collectingAndThen(
+                                Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(
+                                        this::getDuplicateRm
+                                ))), ArrayList::new
+                        )
+                );
+                // 随后把顺序倒回来
+                Collections.reverse(list);
+                // 文件总条数 - 去重之后剩余数量 = excel 文件的重复数据
+                if (!CollectionUtils.isEmpty(list)) {
+                    rmDuplicateNumber = totalNumber - list.size();
+                }
+
+                // 根据条件,查询数据库去重。
+                List<OtherMedicine> dbExistsList = this.loadDbExistsList(list);
+                // 更新列表
+                List<OtherMedicine> updateList = new ArrayList<>();
+                // 新增列表
+                List<OtherMedicine> instalList = list;
+                if (!CollectionUtils.isEmpty(dbExistsList)) { // 不为空时, 需要将存在的做更新操作
+                    // 取出交集
+                    updateList = excelImportUtilService.getUpdateDatas(list, dbExistsList,
+                            this::getDuplicateRm,
+                            (nd, od) -> {
+                                nd.setId(od.getId());
+                                nd.setUpdateBy(finalUsername); //更新人
+                                nd.setUpdateTime(new Date());
+                                return nd;
+                            });//
+                    // 如果有则需要更新
+                    if (!CollectionUtils.isEmpty(updateList)) {
+                        updateNumber = updateList.size();
+                        this.updateBatchById(updateList, 500);
+                    }
+                    // 取出差集
+                    instalList = excelImportUtilService.getInsertDatas(list, dbExistsList, this::getDuplicateRm);
+                }
+                long start = System.currentTimeMillis();
+                if (!CollectionUtils.isEmpty(instalList)) {
+                    addNumber = instalList.size();
+                    this.saveBatch(instalList, 500);
+                }
+                log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
+                //update-end-author:taoyan date:20190528 for:批量插入数据
+                return Result.ok("文件导入成功,请点击刷新!文件总行数:" + totalNumber + "; 文件自身重复:" + rmDuplicateNumber + "; 新增行数: " + addNumber + "; 更新行数: " + updateNumber);
+            } catch (Exception e) {
+                //update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示
+                String msg = e.getMessage();
+                log.error(msg, e);
+                if (msg != null && msg.indexOf("Duplicate entry") >= 0) {
+                    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();
+                }
+            }
+        }
+        return Result.error("文件导入失败!");
+    }
+
+    /**
+     * 构建去重因子
+     * @param
+     * @return
+     */
+    private String getDuplicateRm(OtherMedicine medicine) {
+        return ifnull(medicine.getMedicineCode());
+    }
+
+    @Override
+    public List<OtherMedicine> loadDbExistsList(List<OtherMedicine> list) {
+        if (CollectionUtils.isEmpty(list)) {
+            return new ArrayList<>();
+        }
+        QueryWrapper<OtherMedicine> queryWrapper = new QueryWrapper<>();
+        List<String> itemIdHostKeys = new ArrayList<>();
+        for (OtherMedicine item : list) {
+            String medicineCode = item.getMedicineCode();
+            if (!StringUtils.hasText(medicineCode)) {
+                log.error("数据导入时,没有找到{}请检查导入文件内容", "医保项目编码");
+                throw new JeecgBootException("没有找到项目编码,请检查导入内容");
+            }
+            itemIdHostKeys.add(medicineCode);
+        }
+        String itemIdHostSQLField = oConvertUtils.camelToUnderline("medicineCode");
+        queryWrapper.in(itemIdHostSQLField, itemIdHostKeys);
+        return this.list(queryWrapper);
+    }
+}