批量更新Java

   <!-- 批量更新UserIndex对象 -->
    <update id="batchUpdateUserIndex" parameterType="java.util.List">
        INSERT INTO sys_user_index (user_id, flag, blood_flag, blood_oxygen_flag)
        VALUES
        <foreach collection="list" item="userIndex" index="index" separator=",">
            (#{userIndex.userId}, #{userIndex.flag}, #{userIndex.bloodFlag}, #{userIndex.bloodOxygenFlag})
        </foreach>
        ON DUPLICATE KEY UPDATE
        flag = VALUES(flag),
        blood_flag = VALUES(blood_flag),
        blood_oxygen_flag = VALUES(blood_oxygen_flag);
    </update>
void batchUpdateUserIndex(@Param("list") List<UserIndex> userIndexesToUpdate);
 public List<SysUserExport> allUserDetectionDetailIndex(Map<String, Object> map) {
        List<SysUserExport> SysUserList = sysUserInfoRecordMapper.selectAllSysUserInfoRecordListIndex(map); // 查询全部
        List<UserIndex> userIndexesToUpdate = new ArrayList<>(); // 用于收集需要更新的UserIndex对象
        for (SysUserExport list : SysUserList) {
            // 处理酒精检测结果
            if (list.getAlcoholDetectionResult() != null && !list.getAlcoholDetectionResult().equals(" ")) {
                String alcohol = list.getAlcoholDetectionResult();
                alcohol = alcohol.replace("测酒结果:", "");
                list.setAlcoholDetectionResult(alcohol);
                String alcoholValue = alcohol.substring(0, alcohol.indexOf("mg"));
                double alcoholNumber = Double.parseDouble(alcoholValue);
                if (alcoholNumber >= 20.0) {
                    list.setHealth(list.getHealth() + "酒精检测不通过;");
                    list.setFlag("2");
                } else {
                    list.setHealth(list.getHealth() + "酒精检测通过;");
                    list.setFlag("1");
                }
            }
            
            // 处理血压检测结果
            if (list.getBloodPressureDetectionResult() != null && !list.getBloodPressureDetectionResult().equals(" ")) {
                String blood = list.getBloodPressureDetectionResult();
                blood = blood.replace("血压检测结果:", "");
                list.setBloodPressureDetectionResult(blood);
                if (blood.contains("高血压")) {
                    list.setHealth(list.getHealth() + "高血压;");
                    list.setBloodFlag("2");
                } else if (blood.contains("低血压")) {
                    list.setHealth(list.getHealth() + "低血压;");
                    list.setBloodFlag("2");
                } else if (blood.contains("Error")) {
                    list.setHealth(list.getHealth() + "检测过程异常");
                    list.setBloodFlag("2");
                } else {
                    list.setHealth(list.getHealth() + "血压检测通过;");
                    list.setBloodFlag("1");
                }
            }

            // 处理血氧检测结果
            if (list.getBloodOxygenDetectionResult() != null && !list.getBloodOxygenDetectionResult().equals(" ")) {
                String bloodO = list.getBloodOxygenDetectionResult();
                int percentIndex = bloodO.indexOf("%");
                String bloodONumS = bloodO.substring(13, percentIndex); // 假设血氧值在"mg"之后,"%"之前
                int bloodONum = Integer.parseInt(bloodONumS);
                if (bloodONum >= 95 && bloodONum < 100) {
                    list.setHealth(list.getHealth() + "血氧正常;");
                    list.setBloodOxygenFlag("1");
                } else {
                    list.setHealth(list.getHealth() + "低血氧;");
                    list.setBloodOxygenFlag("2");
                }
            }

            // 如果需要更新UserIndex,添加到待更新列表
            if (list.getFlag() != null || list.getBloodFlag() != null || list.getBloodOxygenFlag() != null) {
                UserIndex sysUser = new UserIndex();
                sysUser.setUserId(list.getUserId());
                sysUser.setFlag(list.getFlag());
                sysUser.setBloodFlag(list.getBloodFlag());
                sysUser.setBloodOxygenFlag(list.getBloodOxygenFlag());
                userIndexesToUpdate.add(sysUser);
            }
        }

        // 批量更新UserIndex
        if (!userIndexesToUpdate.isEmpty()) {
            userIndexMapper.batchUpdateUserIndex(userIndexesToUpdate);
        }
        return SysUserList;
    }
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值