利用map传参进行增删改查的操作

对于需要进行增删改查,但是没有封装的实体类的一些表该如何操作

假设这是我们需要修改的字段,但是目前F58H0411和F58H0401是没有封装的实体类的
在这里插入图片描述

public int updateBatchTdpSoOffline(TdpSo tdpSo, TdpSoOffline[] tdpSoOfflines, String po_Qty2Flg, String... paras) {
//		表头信息
		int rtn = tdpSoMapper.updateTdpSo1(tdpSo);
==============================================================================================		
	更新此类拥有实体类的表可直接调用,在xml中用sql进行更新,是否登陆验证以及是否重复提交已在
	Controller方法中进行了校验。
	<update id="updateTdpSo1" parameterType="com.el.entity.po.TdpSo">
    update TDP_SO
    <set>
    <if test="orderDate != null">
      ORDER_DATE=#{orderDate,jdbcType=DATE},
    </if>
      <if test="promisePickupDate != null">
        PROMISE_PICKUP_DATE=#{promisePickupDate,jdbcType=DATE},
      </if>
      <if test="promiseReadyDate != null">
        PROMISE_READY_DATE=#{promiseReadyDate,jdbcType=DATE},
      </if>
      <if test="shouldpayAmt != null">
        SHOULDPAY_AMT=#{shouldpayAmt,jdbcType=NUMERIC},
      </if>
      <if test="amt != null">
        AMT=#{amt,jdbcType=NUMERIC},
      </if>
      <if test="discountAmt != null">
        DISCOUNT_AMT=#{discountAmt,jdbcType=NUMERIC},
      </if>
    </set>
    where ID=#{id,jdbcType=NUMERIC}
  </update>
  ==============================================================================================		
//		更新F58H0401
		Map<String,Object> map = new HashMap<>();
		//订单日期
		Integer date = JdeUtil.toJdeDate(tdpSo.getOrderDate());
		map.put("CHTRDJ",date);
		//根据 特殊优惠 自动修改 折扣金额
		int DiscountAmt = tdpSo.getDiscountAmt().intValue()*100;
		map.put("CHE58TSUA",DiscountAmt);
		//根据 特殊优惠 自动修改 结算金额
		int CHE58ODA = tdpSo.getShouldpayAmt().intValue()*100;
		map.put("CHE58ODA",CHE58ODA);
		map.put("ouCode",tdpSo.getOuCode());
		map.put("docType",tdpSo.getDocType());
		map.put("docNo",tdpSo.getDocNo());
		int f = tdpSoMapper.updateF58H0401(map);
===========================================================================================
  /**
  当更新此类没有实体类的表时,需要去看我们需要更新的是些什么类型的数据,根据不同的数据类型
  选择合适的存放方式,看是存到Map、List集合里呢还是用Array数组呢,此处我用的是Map集合的方式
  这里需要注意:
  parameterType属性,次属性为是传进这个sql里面的数据类型是什么样的
  大致可以分为两种  
  	 1. 基本数据类型:int,string,long,Date;
     2. 复杂数据类型:类(封装的实体类)和Map 
  然后下面CHTRDJ=#{CHTRDJ}是用来获取参数中的值,根据上面的parameterType属性也会有不同的表现
  	 1. 基本数据类型:#{参数} 获取参数中的值
  	 2. 复杂数据类型:#{属性名}  ,map中则是#{key}
  */
  <update id="updateF58H0401" parameterType="map">
    update crpdta.F58H0401
    <set>
      <if test="CHTRDJ != null">
        CHTRDJ=#{CHTRDJ},
      </if>
      <if test="CHE58TSUA != null">
        CHE58TSUA=#{CHE58TSUA},
      </if>
      <if test="CHE58ODA != null">
        CHE58ODA=#{CHE58ODA}
      </if>
    </set>
    where CHDOCO=#{docNo} AND CHKCOO=#{ouCode} AND CHDCTO=#{docType}
  </update>
===========================================================================================
//		订单明细
		int updateF=0;
				TdpSoItem item = new TdpSoItem();
				try {
 /**
  * 然后使用org.springframework.beans.BeanUtils.copyProperties方法进行对象之间属性的赋值,
  * 避免通过get、set方法一个一个属性的赋值,此方法就是将tdpSoOfflines的属性全部复制给item(仅为自己
  * 的理解)
  */
					BeanUtils.copyProperties(tdpSoOfflines, item);
				} catch (IllegalAccessException e) {
					e.printStackTrace();
				} catch (InvocationTargetException e) {
					e.printStackTrace();
				}
			int ite = tdpSoItemMapper.updateTdpSoItem1(item);
				//		更新F58H0411
				Map<String,Object> map1 = new HashMap<>();
				//订单日期
				map1.put("CHTRDJ",date);
				//承诺提货日期
				Integer readyDate = JdeUtil.toJdeDate(tdpSo.getPromiseReadyDate());
				map1.put("CHE58HUD04",readyDate);
				//特殊优惠
				int CHE58HUN03 = item.getSpecialDiscountAmt().intValue()*10000;
				//后返金额
				int CHE58HUN02 = item.getAfterAmt().intValue()*10000;
				map1.put("CHE58HUN03",CHE58HUN03);
				map1.put("CHE58HUN02",CHE58HUN02);
				//根据 特殊优惠 自动更新 结算金额
				int CHE58AEXP = item.getNetAmt().intValue()*100;
				int CHE58CCDA = item.getNetAmt().intValue()*100;
				int CHURAT = item.getNetAmt().intValue()*100;
				map1.put("CHE58AEXP",CHE58AEXP);
				map1.put("CHE58CCDA",CHE58CCDA);
				map1.put("CHURAT",CHURAT);
				map1.put("ouCode",tdpSo.getOuCode());
				map1.put("docType",tdpSo.getDocType());
				map1.put("docNo",tdpSo.getDocNo());
				int no = item.getLineNo().intValue()*1000;
				map1.put("chlnid",no);
				//item.getNetPrice().intValue()*10000;
				BigDecimal netPrice = new BigDecimal(CHURAT).divide(new BigDecimal(item.getQty()), 2, ROUND_HALF_UP);
				int CHE58UPRC = netPrice.intValue()*1000;
				map1.put("CHE58UPRC",CHE58UPRC);
				updateF=tdpSoItemMapper.updateF58H0411(map1);
		return updateF;
	}

PS:仅供参考,如有不对的地方还请各位大佬多多指正(来自职场小白的呐喊—.—),让我们一起进步吧,冲!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值