修改余额问题

33 阅读1分钟
<update id="updateLoanMarket" parameterType="LoanMarket">
    update loan_market
    <trim prefix="SET" suffixOverrides=",">
        <if test="name != null">name = #{name},</if>
        <if test="limits != null">limits = #{limits},</if>
        <if test="link != null">link = #{link},</if>
        <if test="price != null">price = #{price},</if>
        <if test="balance != null">balance = #{balance},</if>
        <if test="logoPath != null">logo_path = #{logoPath},</if>
        <if test="openDates != null">open_dates = #{openDates},</if>
        <if test="openTime != null">open_time = #{openTime},</if>
        <if test="timePrice != null">time_price = #{timePrice},</if>
        <if test="status != null">status = #{status},</if>
        <if test="textMatch != null">text_match = #{textMatch},</if>
        <if test="textMax != null">text_max = #{textMax},</if>
        <if test="textRange != null">text_range = #{textRange},</if>
        <if test="textAnnualRate != null">text_annual_rate = #{textAnnualRate},</if>
        <if test="textMonthlyRate != null">text_monthly_rate = #{textMonthlyRate},</if>
        <if test="textTerm != null">text_term = #{textTerm},</if>
        <if test="apiDataExchangeUrl != null">api_data_exchange_url = #{apiDataExchangeUrl},</if>
        <if test="apiDataExchangeType != null">api_data_exchange_type = #{apiDataExchangeType},</if>
        <if test="apiFederateUrl != null">api_federate_url = #{apiFederateUrl},</if>
        <if test="apiFederateType != null">api_federate_type = #{apiFederateType},</if>
        <if test="apiProviderType != null">api_provider_type = #{apiProviderType},</if>
        <if test="contactName != null">contact_name = #{contactName},</if>
        <if test="contactPhone != null">contact_phone = #{contactPhone},</if>
        <if test="contactType != null">contact_type = #{contactType},</if>
        <if test="enableClick != null">enable_click = #{enableClick},</if>
        <if test="createBy != null">create_by = #{createBy},</if>
        <if test="createTime != null">create_time = #{createTime},</if>
        <if test="updateBy != null">update_by = #{updateBy},</if>
        <if test="updateTime != null">update_time = #{updateTime},</if>
        <if test="remark != null">remark = #{remark},</if>
        <if test="delStatus != null">del_status = #{delStatus},</if>
        <if test="blockWechat != nu||ll">block_wechat = #{blockWechat},</if>
    </trim>
    where id = #{id}
</update>

多线程进行修改

  原方案是:在进行修改的时候,查询到的实体是之前的数据。还没有进行修改,但是把数据查询了出来,再将查询出来的数据进行余额的扣减。然后对每个线程进行加锁,在没有这把锁的情况下,不允许任何线程做update的操作。但是之前的线程已经将之前的数据做了备份,保存到了相应的实体,所以不论怎么修改都不能再相应的最新数据做扣减。
  问题:
      1.实体的余额不正确
      2.查询之前的余额,不是最新的
      3.admin修改的时候,余额查询出来的不会改变,再原来的基础上做修改。
  解决方案:
          一、update loan_market set blance = blance - ${blance} where id = 1;
          二、添加充值表,记录充值的时间和主体,金额等。