فهرست منبع

优化代码,以及检验检查,无法在医嘱页面中查询到。

xiaochan 2 سال پیش
والد
کامیت
1d5cbbda09

+ 1 - 1
pom.xml

@@ -10,7 +10,7 @@
     </parent>
     <groupId>thyyxxk</groupId>
     <artifactId>web-server</artifactId>
-    <version>11.0.7</version>
+    <version>11.0.9</version>
     <name>web-server</name>
     <description>server for yibao-web</description>
     <properties>

+ 17 - 3
src/main/java/thyyxxk/webserver/controller/jiekou/MedicalTechnologyIsPaidController.java

@@ -8,6 +8,7 @@ import thyyxxk.webserver.config.auth.PassToken;
 import thyyxxk.webserver.config.exception.ExceptionEnum;
 import thyyxxk.webserver.entity.ResultVo;
 import thyyxxk.webserver.service.jiekou.MedicalTechnologyIsPaidService;
+import thyyxxk.webserver.utils.ListUtil;
 import thyyxxk.webserver.utils.ResultVoUtil;
 import thyyxxk.webserver.utils.StringUtil;
 
@@ -35,19 +36,20 @@ public class MedicalTechnologyIsPaidController {
     public ResultVo<String> medConfirm(@RequestParam("reqNo") Integer reqNo,
                                        @RequestParam("confirmId") String confirmId,
                                        @RequestParam("type") Integer type) {
+
         ResultVo<String> INVALID_PARAM = verify(reqNo, confirmId, type);
+
         if (INVALID_PARAM != null) return INVALID_PARAM;
 
         if (type == 1) {
             return service.mzProject(reqNo, confirmId, "1");
         } else if (type == 2) {
-            return service.zyProject(reqNo, confirmId, "1");
+            return service.zyProject(reqNo, confirmId);
         }
 
         return ResultVoUtil.success(ExceptionEnum.SUCCESS);
     }
 
-
     @GetMapping("/medCancel")
     @PassToken
     public ResultVo<String> medCancel(@RequestParam("reqNo") Integer reqNo,
@@ -58,11 +60,23 @@ public class MedicalTechnologyIsPaidController {
         if (type == 1) {
             return service.mzProject(reqNo, confirmId, "3");
         } else if (type == 2) {
-            return ResultVoUtil.fail(ExceptionEnum.INVALID_PARAM, "住院接口不提供取消接口");
+            return service.zyProjectCancel(reqNo, confirmId);
         }
         return ResultVoUtil.success(ExceptionEnum.SUCCESS);
     }
 
+    @PassToken
+    @PostMapping("/medConfirmList")
+    public ResultVo<String> medConfirmList(@RequestBody MedicalTechnologyIsPaidService.ConfirmList param) {
+        if (param == null) {
+            return ResultVoUtil.fail(ExceptionEnum.INVALID_PARAM, "参数为空");
+        }
+        if (ListUtil.notBlank(param.getReqNoAndPatNoList())) {
+            return ResultVoUtil.fail(ExceptionEnum.INVALID_PARAM, "申请唯一id不能为空。");
+        }
+        return service.medConfirmList(param.getReqNoAndPatNoList(), param.getConfirmId());
+    }
+
     @Nullable
     private static ResultVo<String> verify(Integer reqNo, String confirmId, Integer type) {
         if (reqNo == null) {

+ 0 - 5
src/main/java/thyyxxk/webserver/controller/zhuyuanyizheng/YizhuLuRuController.java

@@ -131,11 +131,6 @@ public class YizhuLuRuController {
         return server.stopOrder(param);
     }
 
-    @GetMapping("/huoQuZhuYuanPinLv")
-    public ResultVo<List<GetDropdownBox>> huoQuZhuYuanPinLv(String code) {
-        return server.huoQuZhuYuanPinLv(code);
-    }
-
     @GetMapping("/huoQuZhiXinKeShi")
     public ResultVo<List<GetDropdownBox>> huoQuZhiXinKeShi(String code) {
         return server.huoQuZhiXinKeShi(code);

+ 7 - 5
src/main/java/thyyxxk/webserver/dao/his/jiekou/DuiWaiJieKouDao.java

@@ -68,7 +68,7 @@ public interface DuiWaiJieKouDao {
     int whetherToGenerateAConfirmationFee(BigDecimal orderNo);
 
     @Update("update ysh_yj_req " +
-            "set confirm_flag = 1, " +
+            "set confirm_flag = ${flag}, " +
             "    confirm_id   = #{confirmId}, " +
             "    confirm_time = #{date}," +
             "    exec_dept = #{deptCode} " +
@@ -76,18 +76,20 @@ public interface DuiWaiJieKouDao {
     int updateYshYjReqFlag(String confirmId,
                            Integer reqNo,
                            Date date,
-                           String deptCode);
+                           String deptCode,
+                           int flag);
 
     @Update("update yz_zy_patient_fee " +
-            "set charge_status = '1', " +
+            "set charge_status = '${flag}', " +
             "    op_id         = #{confirmId}, " +
             "    op_date       = #{date}," +
             "    exec_unit     = #{deptCode} " +
-            "where inpatient_no = #{patNo} and admiss_times = #{times} and act_order_no = #{orderNo} ")
+            "where inpatient_no = #{patNo} and admiss_times = #{times} and act_order_no = #{orderNo}")
     int confirmTheIntermediateTable(String confirmId,
                                     BigDecimal orderNo,
                                     Date date,
                                     String deptCode,
                                     String patNo,
-                                    Integer times);
+                                    Integer times,
+                                    int flag);
 }

+ 3 - 2
src/main/java/thyyxxk/webserver/dao/his/zhuyuanyisheng/YiZhuLuRuDao.java

@@ -633,10 +633,10 @@ public interface YiZhuLuRuDao {
             "WHERE isnull(a.del_flag, '') <> '1' " +
             "  and (py_code like #{code} or order_name like #{code} or order_code like #{code}) " +
             "  and order_code not in (select zy_order_code from jc_zd_item) " +
-            "  and isnull(exec_dept, '') <> '2010000' ")
+            "  and isnull(exec_dept, '') <> '2010000' " +
+            "  and order_class not in ('B','C','D') ")
     List<YiZhuMingChen> yiZhuXiangMu(String code);
 
-
     @Select("SELECT a.py_code, " +
             "       a.d_code, " +
             "       a.pattern_code as order_code, " +
@@ -1146,6 +1146,7 @@ public interface YiZhuLuRuDao {
             "WHERE a.pattern_code = #{code} " +
             "  and isnull(a.group_no, '00') = '00' " +
             "  and a.order_code = b.order_code " +
+            "  and b.order_type not in ('B','C','D')  " +
             "UNION " +
             "SELECT                 cast(cast(act_order_no as decimal) as varchar) id," +
             "                       act_order_no,  " +

+ 19 - 3
src/main/java/thyyxxk/webserver/service/PublicServer.java

@@ -6,6 +6,9 @@ import com.baomidou.dynamic.datasource.annotation.DS;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.ListUtils;
+import org.apache.ibatis.session.ExecutorType;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
 import org.jetbrains.annotations.NotNull;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
@@ -65,13 +68,15 @@ public class PublicServer {
     private final RedisLikeService redisLikeService;
     private final SettingsDao settingsDao;
     private final WebSocketService socketService;
+    private final SqlSessionFactory sqlSessionFactory;
 
-    public PublicServer(PublicDao dao, TransferInOfExpensesDao transferInOfExpensesDao, RedisLikeService redisLikeService, SettingsDao settingsDao, WebSocketService socketService) {
+    public PublicServer(PublicDao dao, TransferInOfExpensesDao transferInOfExpensesDao, RedisLikeService redisLikeService, SettingsDao settingsDao, WebSocketService socketService, SqlSessionFactory sqlSessionFactory) {
         this.dao = dao;
         this.transferInOfExpensesDao = transferInOfExpensesDao;
         this.redisLikeService = redisLikeService;
         this.settingsDao = settingsDao;
         this.socketService = socketService;
+        this.sqlSessionFactory = sqlSessionFactory;
     }
 
     /**
@@ -658,12 +663,23 @@ public class PublicServer {
         }
         List<List<SocketMessage>> fenGeFaSongFang = ListUtils.partition(socketMessage1, 20);
         List<List<SocketMessage>> fenGeJieShouFang = ListUtils.partition(socketMessage2, 20);
+
+        SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
+        PublicDao mapper = sqlSession.getMapper(PublicDao.class);
+
         for (List<SocketMessage> item : fenGeFaSongFang) {
-            dao.chaRuTongZhiXinXi(item);
+            mapper.chaRuTongZhiXinXi(item);
         }
         for (List<SocketMessage> item : fenGeJieShouFang) {
-            dao.chaRuJieShouShuJu(item);
+            mapper.chaRuJieShouShuJu(item);
         }
+
+        try {
+            sqlSession.commit();
+        } finally {
+            sqlSession.close();
+        }
+
         JSONObject json = new JSONObject();
         UserInfo userInfo = redisLikeService.getUserInfoByCode(sender);
         json.put("avatar", userInfo.getAvatar());

+ 3 - 3
src/main/java/thyyxxk/webserver/service/hospitalizationCosts/HospitalizationCostsService.java

@@ -348,15 +348,15 @@ public class HospitalizationCostsService {
 
 
     @Transactional(rollbackFor = Exception.class)
-    public int refundsByPatientOrder(String patNo, Integer times, BigDecimal orderNo) {
+    public void refundsByPatientOrder(String patNo, Integer times, BigDecimal orderNo) {
         QueryWrapper<ZyDetailChargeTable> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("inpatient_no", patNo)
                 .eq("admiss_times", times)
-                .eq("order_no", orderNo)
+                .eq("ABS(order_no)", orderNo)
                 .gt("charge_fee", 0)
                 .isNull("ori_detail_sn");
 
-        return refundsByQueryWrapper(queryWrapper, patNo, times);
+        refundsByQueryWrapper(queryWrapper, patNo, times);
     }
 
 

+ 110 - 4
src/main/java/thyyxxk/webserver/service/jiekou/MedicalTechnologyIsPaidService.java

@@ -1,6 +1,10 @@
 package thyyxxk.webserver.service.jiekou;
 
+import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.ibatis.session.ExecutorType;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import thyyxxk.webserver.config.exception.BizException;
@@ -10,11 +14,15 @@ import thyyxxk.webserver.entity.ResultVo;
 import thyyxxk.webserver.entity.datamodify.MzChargeDetail;
 import thyyxxk.webserver.entity.login.UserInfo;
 import thyyxxk.webserver.entity.zhuyuanyisheng.jianyanjiancha.YshYjReq;
+import thyyxxk.webserver.service.hospitalizationCosts.HospitalizationCostsService;
 import thyyxxk.webserver.service.redislike.RedisLikeService;
+import thyyxxk.webserver.utils.ListUtil;
 import thyyxxk.webserver.utils.ResultVoUtil;
 import thyyxxk.webserver.utils.StringUtil;
 
+import java.math.BigDecimal;
 import java.util.Date;
+import java.util.List;
 
 /**
  * <p>
@@ -29,10 +37,35 @@ import java.util.Date;
 public class MedicalTechnologyIsPaidService {
     private final DuiWaiJieKouDao dao;
     private final RedisLikeService redisLikeService;
+    private final HospitalizationCostsService hospitalizationCostsService;
 
-    public MedicalTechnologyIsPaidService(DuiWaiJieKouDao dao, RedisLikeService redisLikeService) {
+    public MedicalTechnologyIsPaidService(DuiWaiJieKouDao dao, RedisLikeService redisLikeService, HospitalizationCostsService hospitalizationCostsService) {
         this.dao = dao;
         this.redisLikeService = redisLikeService;
+        this.hospitalizationCostsService = hospitalizationCostsService;
+    }
+
+    @Data
+    public static class ConfirmList {
+        private List<String> reqNoAndPatNoList;
+        private String confirmId;
+        private Boolean changePrint;
+    }
+
+    @Data
+    public static class Param {
+        Param(String reqStr) {
+            String[] temp = reqStr.split("_");
+            reqNo = Integer.parseInt(temp[0]);
+            patNo = temp[1];
+            times = Integer.parseInt(temp[2]);
+            orderNo = new BigDecimal(temp[3]);
+        }
+
+        private Integer reqNo;
+        private String patNo;
+        private Integer times;
+        private BigDecimal orderNo;
     }
 
     @Transactional(rollbackFor = Exception.class)
@@ -41,7 +74,9 @@ public class MedicalTechnologyIsPaidService {
         if (mz == null) {
             return ResultVoUtil.fail(ExceptionEnum.INVALID_PARAM, "未查询到原申请。");
         }
+
         UserInfo userInfo = redisLikeService.getUserInfoByCode(confirmId);
+
         if (userInfo == null) {
             return ResultVoUtil.fail(ExceptionEnum.INVALID_PARAM, "未查询到确认人数据");
         }
@@ -61,8 +96,10 @@ public class MedicalTechnologyIsPaidService {
     }
 
 
-    public ResultVo<String> zyProject(Integer reqNo, String confirmId, String type) {
+    public ResultVo<String> zyProject(Integer reqNo, String confirmId) {
+
         YshYjReq yshYjReq = dao.selectedYshJyReqOne(reqNo);
+
         if (yshYjReq == null) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未查询到申请单");
         }
@@ -82,16 +119,21 @@ public class MedicalTechnologyIsPaidService {
             return ResultVoUtil.fail(ExceptionEnum.INVALID_PARAM, "未查询到确认人数据");
         }
 
-        int yshFlag = dao.updateYshYjReqFlag(confirmId, reqNo, date, userInfo.getDeptCode());
+        // 1 确认 2 取消
+        int flag = 1;
+
+        int yshFlag = dao.updateYshYjReqFlag(confirmId, reqNo, date, userInfo.getDeptCode(), flag);
+
         if (yshFlag == 0) {
             return ResultVoUtil.fail(ExceptionEnum.INVALID_PARAM, "更新失败请联系管理员");
         }
+
         int feeCount = dao.confirmTheIntermediateTable(confirmId,
                 yshYjReq.getActOrderNo(),
                 date,
                 userInfo.getDeptCode(),
                 yshYjReq.getInpatientNo(),
-                yshYjReq.getAdmissTimes());
+                yshYjReq.getAdmissTimes(), flag);
 
         if (feeCount == 0) {
             throw new BizException(ExceptionEnum.INVALID_PARAM, "更新失败请联系管理员");
@@ -99,4 +141,68 @@ public class MedicalTechnologyIsPaidService {
         return ResultVoUtil.success(ExceptionEnum.SUCCESS);
     }
 
+    public ResultVo<String> zyProjectCancel(Integer reqNo, String confirmId) {
+        UserInfo userInfo = redisLikeService.getUserInfoByCode(confirmId);
+        if (userInfo == null) {
+            return ResultVoUtil.fail(ExceptionEnum.INVALID_PARAM, "未查询到确认人数据");
+        }
+
+        YshYjReq yshYjReq = dao.selectedYshJyReqOne(reqNo);
+
+        if (yshYjReq == null) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未查询到申请单");
+        }
+
+        // 1 确认 2 取消
+        int flag = 1;
+
+        Date date = new Date();
+        int yshFlag = dao.updateYshYjReqFlag(confirmId, reqNo, date, userInfo.getDeptCode(), flag);
+
+        if (yshFlag == 0) {
+            return ResultVoUtil.fail(ExceptionEnum.INVALID_PARAM, "更新失败请联系管理员");
+        }
+
+        int feeCount = dao.confirmTheIntermediateTable(confirmId,
+                yshYjReq.getActOrderNo(),
+                date,
+                userInfo.getDeptCode(),
+                yshYjReq.getInpatientNo(),
+                yshYjReq.getAdmissTimes(), flag);
+
+        if (feeCount == 0) {
+            throw new BizException(ExceptionEnum.INVALID_PARAM, "更新失败请联系管理员");
+        }
+        hospitalizationCostsService.refundsByPatientOrder(yshYjReq.getInpatientNo(), yshYjReq.getAdmissTimes(), yshYjReq.getActOrderNo());
+        return ResultVoUtil.success("操作成功。");
+    }
+
+    /**
+     * 批量更新数据
+     * reqNo_inpatient_no_admiss_times_act_order_no
+     *
+     * @param reqNoList 申请号 和 patNo , times 加 医嘱号 联合 ,下滑线连接起来
+     * @param confirmId 确认人的 id
+     * @return 返回提示
+     */
+    public ResultVo<String> medConfirmList(List<String> reqNoList, String confirmId) {
+        UserInfo userInfo = redisLikeService.getUserInfoByCode(confirmId);
+        if (userInfo == null) {
+            return ResultVoUtil.fail(ExceptionEnum.INVALID_PARAM, "未查询到确认人数据");
+        }
+        // 1 确认 2 取消
+        int flag = 1;
+        Date now = new Date();
+
+        ListUtil.batchList(reqNoList, DuiWaiJieKouDao.class, (mapper, item) -> {
+            // 解析出来的信息
+            Param p = new Param(item);
+            mapper.updateYshYjReqFlag(confirmId, p.getReqNo(), now, userInfo.getDeptCode(), flag);
+            mapper.confirmTheIntermediateTable(confirmId, p.getOrderNo(), now, userInfo.getDeptCode(), p.getPatNo(), p.getTimes(), flag);
+        });
+
+        return ResultVoUtil.success("确认成功。");
+    }
+
+
 }

+ 10 - 28
src/main/java/thyyxxk/webserver/service/zhuyuanyisheng/YiZhuLuRuServer.java

@@ -8,7 +8,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections4.ListUtils;
 import org.apache.ibatis.session.ExecutorType;
 import org.apache.ibatis.session.SqlSession;
 import org.apache.ibatis.session.SqlSessionFactory;
@@ -19,8 +18,6 @@ import org.springframework.transaction.annotation.Transactional;
 import thyyxxk.webserver.config.exception.BizException;
 import thyyxxk.webserver.config.exception.ExceptionEnum;
 import thyyxxk.webserver.constants.sidicts.ChargeStatus;
-import thyyxxk.webserver.dao.his.inpatient.XiangMuLuRuDao;
-import thyyxxk.webserver.dao.his.medicaladvice.nursing.NursingManagementDao;
 import thyyxxk.webserver.dao.his.zhuyuanyisheng.YiZhuLuRuDao;
 import thyyxxk.webserver.entity.ResultVo;
 import thyyxxk.webserver.entity.RoleCode;
@@ -63,7 +60,6 @@ public class YiZhuLuRuServer {
     private final YiZhuLuRuDao dao;
     private final PublicServer publicServer;
     private final RedisLikeService redisLikeService;
-    private final XiangMuLuRuDao xiangMuLuRuDao;
     private final DrgWebServices drgWebServices;
     private final CaseFrontSheetMainService caseFrontSheetMainService;
     private final SqlSessionFactory sqlSessionFactory;
@@ -80,17 +76,15 @@ public class YiZhuLuRuServer {
     }
 
 
-    public YiZhuLuRuServer(YiZhuLuRuDao dao, PublicServer publicServer, RedisLikeService redisLikeService, XiangMuLuRuDao xiangMuLuRuDao, DrgWebServices drgWebServices, CaseFrontSheetMainService caseFrontSheetMainService, SqlSessionFactory sqlSessionFactory) {
+    public YiZhuLuRuServer(YiZhuLuRuDao dao, PublicServer publicServer, RedisLikeService redisLikeService, DrgWebServices drgWebServices, CaseFrontSheetMainService caseFrontSheetMainService, SqlSessionFactory sqlSessionFactory) {
         this.dao = dao;
         this.publicServer = publicServer;
         this.redisLikeService = redisLikeService;
-        this.xiangMuLuRuDao = xiangMuLuRuDao;
         this.drgWebServices = drgWebServices;
         this.caseFrontSheetMainService = caseFrontSheetMainService;
         this.sqlSessionFactory = sqlSessionFactory;
     }
 
-
     public ResultVo<String> getOrderNo() {
         return ResultVoUtil.success(publicServer.getActOrderNo().stripTrailingZeros().toPlainString());
     }
@@ -126,7 +120,7 @@ public class YiZhuLuRuServer {
      * 设置医嘱号的数状图
      *
      * @param yiZhuList 医嘱数据
-     * @return
+     * @return s
      */
     @NotNull
     public static List<XinZhenYzActOrder> getOrderList(List<XinZhenYzActOrder> yiZhuList) {
@@ -302,7 +296,7 @@ public class YiZhuLuRuServer {
 
         Date now = new Date();
         try {
-            ListUtil.partitionAndFunc(confirmOrderInformation, (list) -> {
+            ListUtil.partitionAndFunc(confirmOrderInformation, 50, (list) -> {
                 for (BigDecimal decimal : list) {
                     mapper.confirmOrders(decimal, userCode, now);
                 }
@@ -409,6 +403,9 @@ public class YiZhuLuRuServer {
         Map<String, Object> errorMessageMap = checkData.init(data, huanZheXinXi)
                 .startCheck(null);
 
+        if (checkData.getFailed()) {
+            return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "请修改有错误的医嘱。", errorMessageMap);
+        }
 
         if (data.getParentNo() != null) {
             XinZhenYzActOrder parentOrder = dao.getActOrderNoOne(data.getParentNo().stripTrailingZeros().toPlainString());
@@ -456,10 +453,6 @@ public class YiZhuLuRuServer {
             dao.howOftenTheSubPhysicianOrderIsModified(param.getData());
         }
 
-        if (checkData.getFailed()) {
-            return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "请修改有错误的医嘱。", errorMessageMap);
-        }
-
         QueryWrapper<?> qw = new QueryWrapper<>();
 
         qw.eq("a.inpatient_no", param.getInpatientNo());
@@ -805,18 +798,6 @@ public class YiZhuLuRuServer {
         return ResultVoUtil.success(dao.selectSupplyType());
     }
 
-
-    /**
-     * 获取频率 准备不要了
-     *
-     * @param code 五笔,拼音,中文,编码
-     * @return 返回对应的数据
-     */
-    @Deprecated
-    public ResultVo<List<GetDropdownBox>> huoQuZhuYuanPinLv(String code) {
-        return ResultVoUtil.success(dao.huoQuZhuYuanPinLv("%" + code.toUpperCase() + "%"));
-    }
-
     /**
      * 获取执行科室
      *
@@ -853,10 +834,10 @@ public class YiZhuLuRuServer {
     }
 
     /**
-     * 保存模板数据
+     * 保存模板 数据
      *
-     * @param param
-     * @return
+     * @param param 模板数据
+     * @return 成功
      */
     public ResultVo<String> saveTemplate(YzOrderPattern param) {
         // 如果名字重复了,那么就修改原来的模板
@@ -866,6 +847,7 @@ public class YiZhuLuRuServer {
         if (null == yzOrderPattern) {
             yzOrderPattern = new YzOrderPattern();
         }
+
         String patternCode = yzOrderPattern.getPatternCode();
 
         // 有原来的模板名称而且 还要是自己创建的才能删除,否则就只能创建新的模板了

+ 1 - 2
src/main/java/thyyxxk/webserver/utils/CacheOnce.java

@@ -1,8 +1,6 @@
 package thyyxxk.webserver.utils;
 
 
-import com.alibaba.fastjson.JSON;
-
 import java.util.*;
 import java.util.function.Function;
 
@@ -35,6 +33,7 @@ public class CacheOnce<V> {
         }
 
         Object object = filter.apply(name);
+
         if (object == null) {
             notQueried.add(name);
             return null;

+ 24 - 0
src/main/java/thyyxxk/webserver/utils/ListUtil.java

@@ -1,8 +1,14 @@
 package thyyxxk.webserver.utils;
 
+import cn.hutool.extra.spring.SpringUtil;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.ListUtils;
+import org.apache.ibatis.session.ExecutorType;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
 
 import java.util.List;
+import java.util.function.BiConsumer;
 import java.util.function.Consumer;
 
 /**
@@ -13,6 +19,7 @@ import java.util.function.Consumer;
  * @author xc
  * @date 2021-09-18 09:10
  */
+@Slf4j
 public class ListUtil {
     public static boolean isBlank(List<?> list) {
         return list == null || list.isEmpty();
@@ -33,4 +40,21 @@ public class ListUtil {
         partitionAndFunc(list, 20, a);
     }
 
+    public static <M, T> void batchList(List<T> list, Class<M> clazz, BiConsumer<M, T> biConsumer) {
+        SqlSessionFactory sqlSessionFactory = SpringUtil.getBean(SqlSessionFactory.class);
+        SqlSession session = sqlSessionFactory.openSession(ExecutorType.BATCH);
+        M mapper = session.getMapper(clazz);
+        List<List<T>> partitionList = ListUtils.partition(list, 50);
+        try {
+            for (List<T> ts : partitionList) {
+                for (T t : ts) {
+                    biConsumer.accept(mapper, t);
+                }
+                session.commit();
+            }
+        } finally {
+            session.close();
+        }
+    }
+
 }