java中对于页面传入ids的数组进行的批量操作

  • Post author:
  • Post category:java


对于页面上的代码:

<script type="text/javascript">
function batchApproval() {
if ($("input[name='ids']:checked").length <= 0) {
$(this).alertmsg("error", '请选择需要审批的项目');
return;
}
var ids = "";
var aprrovalDetails = ""
var idArr = $("input[name='ids']:checked");
var aprrovalDetailArr = $(".aprrovalDetail");
for (var i = 0; i < idArr.length; i++) {
ids += idArr[i].value + ",";
aprrovalDetails += aprrovalDetailArr[i].value + ",";
   }
approval(ids, aprrovalDetails);
}


function batchRefuse() {
if ($("input[name='ids']:checked").length <= 0) {
$(this).alertmsg("error", '请选择需要拒绝的项目');
return;
}
var ids = "";
var aprrovalDetails = ""
var idArr = $("input[name='ids']:checked");
var aprrovalDetailArr = $(".aprrovalDetail");
for (var i = 0; i < idArr.length; i++) {
ids += idArr[i].value + ",";
aprrovalDetails += aprrovalDetailArr[i].value + ",";
 }
refuse(ids, aprrovalDetails);
}


function approval(ids, aprrovalDetails) {
$(this).alertmsg('confirm', "确定要审批?", {
okCall : function() {
$.ajax({
type : "POST",
url : '${base}/fundDetail/batchApproval.htm',
data : {
'ids' : ids,
'aprrovalDetails' : aprrovalDetails
},
async : false,
success : function(msg) {
$(this).alertmsg("correct", '审批成功');
$(this).dialog("close", 'approvalTempList');
$("#pagerForm").submit();
},
error : function(error) {
$(this).alertmsg("error", '审批失败');
$(this).dialog("close", 'approvalTempList');

            }
      });

   }
 });
}


function refuse(ids, aprrovalDetails) {
$(this).alertmsg('confirm', "确定要拒绝吗?", {
okCall : function() {
$.ajax({
type : "POST",
url : '${base}/fundDetail/batchRefuse.htm',
data : {
'ids' : ids,
'aprrovalDetails' : aprrovalDetails
},
async : false,
success : function(msg) {
$(this).alertmsg("correct", '拒绝成功');
$(this).dialog("close", 'approvalTempList');
},
error : function(error) {
$(this).alertmsg("error", '拒绝失败');
$(this).dialog("close", 'approvalTempList');
}
});
}
});
}
</script>

<div class="bjui-pageContent">
	<table data-toggle="tablefixed" class="table table-bordered table-hover table-striped table-top" style="table-layout: fixed; border-collapse: collapse;" border="1" width="250" bordercolor=#666666>
		<thead>
			<tr>
				<th width="30"><input type="checkbox" class="checkboxCtrl" data-group="ids" data-toggle="icheck"></th>
				<th width="80" align="center">对账日期</th>
				<th width="80" align="center">银行名称</th>
				<th width="80" align="center">渠道名称</th>
				<th width="80" align="center">备付金账号</th>
				<th width="80" align="center">资金日期</th>
				<th width="80" align="center">资金类型</th>
				<th width="80" align="center">出金</th>
				<th width="80" align="center">入金</th>
				<th width="80" align="center">申请信息</th>
				<th width="100" align="center">审批信息</th>
				<th width="80" align="center">备注</th>
				<th width="80" align="center">状态</th>
				<th width="80" align="center">操作</th>
			</tr>
		</thead>
		<tbody>
			<#if form??&&form.dto_l??> <#escape x as x?html> <#list form.dto_l as fundDetailTemp>
			<tr>
				<td><#if fundDetailTemp.aprrovalStatus??&&fundDetailTemp.aprrovalStatus == 1> <input type="checkbox" name="ids" data-toggle="icheck" value="${fundDetailTemp.id}"> </#if>
				</td>
				<td align="center">${fundDetailTemp.reconDate?string("yyyy-MM-dd")!''}</td>
				<td align="center">${fundDetailTemp.bankName!''}</td>
				<td align="center">${fundDetailTemp.channelName!''}</td>
				<td align="center">${fundDetailTemp.bankAcct!''}</td>
				<td align="center">${fundDetailTemp.fundsDate?string("yyyy-MM-dd")!''}</td>
				<td align="center"><#if fundDetailTemp.fundsType??> <#list fundsTypeEnum as fte> <#if fundDetailTemp.fundsType == fte.key>${(fte.value)!} </#if> </#list> </#if></td>
				<td align="right">${(fundDetailTemp.fundsAmtOut?default(0)/1000)?string(',##0.00')}</td>
				<td align="right">${(fundDetailTemp.fundsAmtIn?default(0)/1000)?string(',##0.00')}</td>
				<td align="center">${fundDetailTemp.submitDetail!''}</td>
				<td align="center"><#if fundDetailTemp.aprrovalStatus??&&fundDetailTemp.aprrovalStatus == 1> <input class="aprrovalDetail" size="9" type="text" value="${fundDetailTemp.aprrovalDetail!''}">
					</#if> <#if fundDetailTemp.aprrovalStatus??&&fundDetailTemp.aprrovalStatus != 1> ${fundDetailTemp.aprrovalDetail!''} </#if>
				</td>
				<td align="center">${fundDetailTemp.memo!''}</td>
				<td align="center">
				    <#if fundDetailTemp.aprrovalStatus??&&fundDetailTemp.aprrovalStatus ==1>
				                 待审批
				    <#elseif fundDetailTemp.aprrovalStatus == 2>
				                已审批通过   
				    <#elseif fundDetailTemp.aprrovalStatus == 3>
					  已拒绝  				              
				    <#elseif fundDetailTemp.aprrovalStatus == 4>
				                已同步
				    <#elseif fundDetailTemp.aprrovalStatus == 5>
					     已失效           
				    </#if> 
				   </td>
				<td align="center">
				  <#if fundDetailTemp.aprrovalStatus?? && fundDetailTemp.aprrovalStatus==4>
					 <a href="#" class="btn btn-red"  οnclick="openRemoveView(${fundDetailTemp.id})">撤回</a> 
				  </#if>
				</td>
			</tr>
			</#list> </#escape> </#if>
		</tbody>
	</table>
</div>
<div class="bjui-pageFooter">
	<ul>
		<li><button id="closebutton" type="button" class="btn-close" data-icon="close">关闭</button></li> <#if status??> <#if status == "show">
		<li><button id="refuse" type="button" οnclick="batchRefuse()" class="btn-default" data-toggle="alertmsg">批量拒绝</button></li>
		<li><button id="approval" type="button" οnclick="batchApproval()" class="btn-default" data-toggle="alertmsg">批量审批</button></li> </#if> </#if>
	</ul>
</div>

后台代码的批量操作:

// 批量审批
	@ResponseBody
	@RequestMapping("/batchApproval")
	public ModelAndView batchApproval(HttpServletRequest request, HttpServletResponse response) {
		try {
			String ids = request.getParameter("ids");
			ids = StringUtils.removeEnd(ids, ",");
			String aprrovalDetails = request.getParameter("aprrovalDetails");
			aprrovalDetails = StringUtils.removeEnd(aprrovalDetails, ",");
			String[] detailTmpIds = ids.split(",");
			String[] detailTmpAprrovalDetails = aprrovalDetails.split(",");
			for (int i = 0; i < detailTmpIds.length; i++) {
				// 更改拆分表为审批状态
				ReconFundsDetailTmpDto detailTempDto = new ReconFundsDetailTmpDto();
				// 获取用户姓名
				String userName = SSOUtil.getSSOInfo(request).getUserName();
				detailTempDto.setId(Long.valueOf(detailTmpIds[i]));
				detailTempDto.setAprrovalStatus(AprrovalStatus.SYNCHRONIZED.getKey());
				detailTempDto.setAprrovalBy(userName);// 审批人员
				if (detailTmpAprrovalDetails.length != 0 && StringUtils.isNotBlank(detailTmpAprrovalDetails[i])) {
					detailTempDto.setAprrovalDetail(detailTmpAprrovalDetails[i]);
				} else {
					detailTempDto.setAprrovalDetail(StringUtils.EMPTY);
				}
				detailTempDto.setAprrovalTime(new Date()); // 审批时间
				reconFundsDetailTmpService.update(detailTempDto);

				ReconFundsDetailTmpForQuery query = new ReconFundsDetailTmpForQuery();
				query.setId(Long.valueOf(detailTmpIds[i]));
				List<ReconFundsDetailTmpDto> dto_l = reconFundsDetailTmpService.query(query);
				ReconFundsDetailTmpDto tmpDto = dto_l.get(0);
				// 更改明细表金额
				ReconFundsDetailForQuery detailQuery = new ReconFundsDetailForQuery();
				detailQuery.setId(tmpDto.getParentFundsId());
				List<ReconFundsDetailDto> detail_dto_l = reconFundsDetailService.query(detailQuery);
				ReconFundsDetailDto detail_dto = detail_dto_l.get(0);
				Long adjustAmtIn = detail_dto.getAdjustAmtIn() != null ? detail_dto.getAdjustAmtIn() : LONG_ZERO;// 已调整入金
				Long adjustAmtOut = detail_dto.getAdjustAmtOut() != null ? detail_dto.getAdjustAmtOut() : LONG_ZERO;// 已调整出金
				Long unAdjustAmt = detail_dto.getUnAdjustAmt();// 未分配余额
				ReconFundsDetailDto updateDetailDto = getUpdateDetailDto(tmpDto, detail_dto, adjustAmtIn, adjustAmtOut, unAdjustAmt);
				reconFundsDetailService.update(updateDetailDto);
				// 插入审批通过的拆分数据到明细表
				ReconFundsDetailDto insertDetailDto = getInsertDetailDto(tmpDto, detail_dto);
				Long id = reconFundsDetailService.save(insertDetailDto);// 插入资金明细表
				//将插入到明细表的id,设置到临时表中
				detailTempDto.setChildFundsId(id);
				reconFundsDetailTmpService.update(detailTempDto);
			}
			return ajaxDoneSuccess("审批完成");
		} catch (Exception e) {
			logger.error("FundDetailController_batchApproval_error", e);
			return ajaxDoneError("审批发生错误");
		}
	}

// 批量拒绝
	@ResponseBody
	@RequestMapping("/batchRefuse")
	public ModelAndView batchRefuse(HttpServletRequest request, HttpServletResponse response) {
		try {
			String ids = request.getParameter("ids");
			ids = StringUtils.removeEnd(ids, ",");
			String aprrovalDetails = request.getParameter("aprrovalDetails");
			aprrovalDetails = StringUtils.removeEnd(aprrovalDetails, ",");
			String[] detailTmpIds = ids.split(",");
			String[] detailTmpAprrovalDetails = aprrovalDetails.split(",");
			for (int i = 0; i < detailTmpIds.length; i++) {
				ReconFundsDetailTmpDto dto = new ReconFundsDetailTmpDto();
				// 获取用户姓名
				String userName = SSOUtil.getSSOInfo(request).getUserName();
				dto.setId(Long.valueOf(detailTmpIds[i]));
				if (detailTmpAprrovalDetails.length != 0 && StringUtils.isNotBlank(detailTmpAprrovalDetails[i])) {
					dto.setAprrovalDetail(detailTmpAprrovalDetails[i]);
				} else {
					dto.setAprrovalDetail(StringUtils.EMPTY);
				}
				dto.setAprrovalStatus(AprrovalStatus.REJECTED.getKey());
				dto.setAprrovalBy(userName);// 审批人员
				dto.setAprrovalTime(new Date()); // 审批时间
				reconFundsDetailTmpService.update(dto);
			}
			return ajaxDoneSuccess("拒绝完成");
		} catch (Exception e) {
			logger.error("FundDetailController_batchRefuse_error", e);
			return ajaxDoneError("拒绝发生错误");
		}


	}







版权声明:本文为wanghang88原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。