`

可录入列后台动态取值赋值

 
阅读更多
public void mesMisAdjust(MesMisInventory mes,List<String> values){
	//实际结存=实际结存-合格品出库-不合格品出库-检验报废-其它出库+入库调整
	//合格品出库-hgout,不合格品出库-unhgout,检验报废-scrapout,其它出库-otherout,入库调整+asnAdjust
	String[] function = new String[]{//依次代表页面输入列参与加减
			"-","-","-","-",""
	};
	if(function.length!=values.size()){
		throw new BusinessException("当前页面输入列与需求计算列不符,请联系技术人员");
	}
	String[] columns = new String[]{//页面输入列
			"hgout","unhgout","scrapout","otherout","asnAdjust"
	};
	//如果将来要调整业务,就调整上面的两个String数组即可(function,columns)
	Class<MesMisInventory> c = MesMisInventory.class; 
	int j = 0;
	Double quantity = 0D;
	Double tempQty = mes.getCalQuantity();
	for(String s : values){
		if(JavaTools.isNumber(s)){
			quantity = Double.valueOf(function[j]+s);
		}else{
			quantity = 0D;//录入不为数字时默认0
		}
		tempQty += quantity;
		//字段赋值
		try {
			Field xf = c.getField(columns[j]);
			try {
				xf.set(mes,Math.abs(quantity));
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		} catch (SecurityException e) {
			e.printStackTrace();
			throw new BusinessException(e.getMessage());
		} catch (NoSuchFieldException e) {
			e.printStackTrace();
			throw new BusinessException(e.getMessage());
		}
		j++;
	}
	mes.setCalQuantity(tempQty);
	commonDao.store(mes);
}

 

public static Boolean isNumber(String value){
	if(StringUtils.isEmpty(value)){
		return false;
	}
	return value.matches("[0-9]+");
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics