数据库批量更新,批量插入

 

java代码

/**
	 * 修改冻结数量
	 * 
	 * @param applyTbl
	 * @return
	 */
	int updateApplyNumber(List<Object> applyTbl);

	/**
	 * 添加到库存表
	 * 
	 * @param applyTbl
	 * @return
	 */
	int saveAdvStock(List<Object> applyTbl);
List<Object> updateList = new ArrayList<>();
		for (ApplyConfirmationTbl tempObj : applyNumber) {
			// 地区剩余播放量
			int as = tempObj.getAreaSurplus();
			// 套餐所需每天播放量
			int code = tempObj.getCode();
			// 投放地区id
			int areaid = tempObj.getAreaId();
			// 地区的视频播放总量
			int advn = tempObj.getAdvnumber();
			// 冻结量
			int fzb = tempObj.getFreezenumber();
			Long showdate = tempObj.getShowDate();
			// 播放占比
			double weight = new BigDecimal((float) code / advn).setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
			if (as < code)
				return -1;
			else
				// 添加冻结量
				tempObj.setFreezenumber(code + fzb);
			// 地址id
			tempObj.setAreaId(areaid);
			// 添加开始时间
			tempObj.setShowDate(showdate);
			// 占比
			tempObj.setWeight(weight);
			tempObj.setStatus(1);
			tempObj.setApplynumber(code);
			tempObj.setRestnumber(code);
			updateList.add(tempObj);

		}
		// 修改冻结量
		applyConfirmationMapper.updateApplyNumber(updateList);
		// 添加到库存表
		applyConfirmationMapper.saveAdvStock(updateList);

sql语句

<update id="updateApplyNumber" parameterType="java.util.List">
		<foreach collection="list" separator=";" item="applyTbl">
			UPDATE
			adv_source_tbl
			SET
			freezenumber =#{applyTbl.freezenumber},
			updated_time
			=#{applyTbl.updatedTime}
			WHERE
			area_id = #{applyTbl.areaId}
			and
			show_date=#{applyTbl.showDate}
		</foreach>
	</update>
<insert id="saveAdvStock" parameterType="java.util.List">
		<foreach collection="list" separator=";" item="applyTbl">
			INSERT
			INTO
			adv_stock_tbl(
			<if
				test="applyTbl.updatedTime != -1 and applyTbl.updatedTime != null ">
				updated_time,
			</if>
			<if test="applyTbl.deleted != -1 and applyTbl.deleted != null ">
				deleted,
			</if>
			<if
				test="applyTbl.deletedTime != -1 and applyTbl.deletedTime != null ">
				deleted_time,
			</if>
			applynumber,
			restnumber,
			source_id,
			status,
			video_id,
			show_date,
			weight,
			created_time
			)
			VALUES(
			<if
				test="applyTbl.updatedTime != -1 and applyTbl.updatedTime != null ">
				#{applyTbl.updatedTime},
			</if>
			<if test="applyTbl.deleted != -1 and applyTbl.deleted != null ">
				#{applyTbl.deleted},
			</if>
			<if
				test="applyTbl.deletedTime != -1 and applyTbl.deletedTime != null ">
				#{applyTbl.deletedTime},
			</if>
			#{applyTbl.applynumber},
			#{applyTbl.restnumber},
			#{applyTbl.id},
			#{applyTbl.status},
			#{applyTbl.videoId},
			#{applyTbl.showDate},
			#{applyTbl.weight},
			#{applyTbl.createdTime}

			)
		</foreach>

	</insert>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值