java 中对于传入ids进行批量的删除

前台页面的js 代码:

<script type="text/javascript">
function clearAndquery(){
	$("input").val('');
	$("select").val('');
	$("#pagerForm").attr("action","${base}/reconfile/queryByConditions.htm");
	$("#pagerForm").submit();
}

function batchremove(){
	if($("input[name='ids']:checked").length<=0){
		return ;
	}
	var ids="";
	var selectedCount=0;
	$("input[name='ids']:checked").each(function(){
		ids+=$(this).val()+",";
		selectedCount++;
	})
	var idsCount = $("[name='ids']").length;
	
	 $(this).alertmsg('confirm', "确定要删除该行信息吗?", {okCall: function() { 
		 if(selectedCount ==  idsCount){
				doAjaxDelete(ids);
			}else{
				doAjaxDeleteSelected(ids);
			}
	 }})
}

function doAjaxDeleteSelected(ids){
	 $.ajax({
		   type: "POST",
		   url: '${base}/reconfile/batchDeleteSelected.htm',
		   data: {'idList':ids},
		   success: function(msg){
			 $(this).alertmsg("correct", msg);	
		   },
		   error:function(error){
			   $(this).alertmsg("error", '删除失败');					  
		   } 
		});
	 $("#pagerForm").submit();
}

function doAjaxDelete(ids){
	 $.ajax({
		   type: "POST",
		   url: '${base}/reconfile/batchDelete.htm',
		   data: {'idList':ids},
		   success: function(data){
			 var msg = JSON.parse(data);
			 if(msg.statusCode == 200){
				 $(this).alertmsg("correct", msg.message);
			 }else{
				 $(this).alertmsg("error", msg.message);
			 }
			 $("#pagerForm").submit();
		   },
		   error:function(error){
			   $(this).alertmsg("error", '删除失败');					  
		   } 
		})
}
</script>
<div class="bjui-pageHeader">
    <form id="pagerForm" data-toggle="ajaxsearch" class="pageForm" action="${base}/reconfile/queryByConditions.htm" data-toggle="validate" method="post">
	     <#include "/common/hidden.html" >
		<fieldset>
			<legend>查询条件</legend>
				<table width="100%">
				<tr>
               		<td width="30%">
                		<table>
	                		<tr>
		                		<td align="right"><label class="control-label x80">对账日期:</label></td>
								<td align="left">
									<input type="text" name="beginReconDate"  value="${(form.beginReconDate?string('yyyy-MM-dd'))!}" data-toggle="datepicker" size="12">
									-
									<input type="text" name="endReconDate" value="${(form.endReconDate?string('yyyy-MM-dd'))!}" data-toggle="datepicker"  size="12">									
								</td>
	                		</tr>
                		</table>
               		</td>
               		<td width="30%">
                		<table>
	                		<tr>
		                		<td align="right"><label class="control-label x80">回单类型:</label></td>
								<td align="left"><select data-toggle="selectpicker" name="fileType" data-width="200">
								    <option value="">全部</option>
									  <#list reconFileTypeList as rl>
	               		            <option value="${(rl.key)!''}" <#if form.fileType?? && form.fileType==rl.key>selected</#if>>${(rl.value)!''}</option>
	               	                  </#list>  							
								</select>	</td>
	                		</tr>
                		</table>
               		</td>
               		<td width="40%">
               			<table>
	                		<tr>
		                		<td align="right"><label class="control-label x80">银行渠道:</label></td>
								<td align="left"><#include "/common/cpsBankAndChannel.html"></td>
	                		</tr>
                		</table>
               		</td>
				</tr>
				<tr>
               		<td width="30%">
               			<table>
	                		<tr>
		                		<td align="right"><label class="control-label x80">文件名称:</label></td>
								<td align="left"><input type="text" name="fileName"  value="${(form.fileName)!''}" size="15"></td>
	                		</tr>
                		</table>
               		</td>
               		<td width="30%"></td>
               		<td width="40%"></td>
				</tr>
			
				<tr height="40">
          			<td width="30%"></td>
          			<td align="left" width="30%">
          			<button type="submit" class="btn-default" data-icon="search">查询</button> 
			        <button type="button" οnclick="clearAndquery()" class="btn-orange" data-icon="undo">清空查询</button>
			        <button type="button" class="btn-blue" οnclick="batchremove()"  
			             data-icon="remove" >删除选中行</button> 
					</td>
          			<td width="40%"></td>
           		</tr>
            </table>
		</fieldset>
		  </form>
		</div>
<div class="bjui-pageContent">
    <table class="table table-bordered table-hover table-striped table-top" data-selected-multi="true">
        <thead>
            <tr>
                <th width="26"  align="center"><input type="checkbox" class="checkboxCtrl" data-group="ids" data-toggle="icheck"></th>
	            <th  align="center">渠道</th>
			    <th width="100"  align="center">回单类型</th>
			    <th align="center">文件名称</th>
			    <th align="center">记录数</th>
			    <th align="center">状态</th>
			    <th align="center">失败原因</th>
			    <th data-order-field="RECON_DATE"  align="center">对账日期</th>
			    <th align="center">上传类型</th>
			    <th data-order-field="CRT_TIME"  align="center">上传日期</th>
				<th width="120"  align="center">操作</th>
            </tr>
        </thead>
        <tbody>
       
        <#if form??&&form.dtoList??>
			<#list form.dtoList as item>
			 <tr data-id="">
			      <td  align="center"><input type="checkbox" name="ids" data-toggle="icheck" value="${item.uploadId}"></td>
				  <td  align="center">${item.channelName!''}</td>
				  <td  align="center">${form.fileTypeEnum[item.fileType+'']!''}</td>
				  <td  align="center">${item.fileName!''}</td>
				  <td  align="center">${item.totalNum!''}</td>
				  <td  align="center">${form.uploadStatusEnum[item.status+'']!''}</td>
				  <td  align="center">${item.failReason!''}</td>
				  <td  align="center">${item.reconDate?string("yyyy-MM-dd")!''}</td>
				  <#if item.uploadType??&&item.uploadType == 0>		
				  <td  width="100" align="center">手工上传</td>
				  <#elseif item.uploadType??&&item.uploadType == 1>
				  <td  width="100" align="center">自动上传</td>
				  <#else>
				  <td width="100"  align="center"</td>
				  </#if>
				  <td  align="center">${item.crtTime?string("yyyy-MM-dd HH:mm:ss")!''}</td>
				  <td  align="center">
				  <a href="${base}/reconfile/downLoad.htm?uploadId=${item.uploadId}" class="btn btn-green" >下载</a>
				  <a href="${base}/reconfile/delete.htm?uploadId=${item.uploadId}" class="btn btn-red" data-toggle="doajax" data-confirm-msg="确定要删除该行信息吗?">删除</a>
				  </td>
            </tr>			
           </#list>       	
			</#if>
			
        </tbody>
    </table>
</div>

<#include "/common/page.html" >


 


后台处理批量的代码: 当然加了点别的代码


//批量

@RequestMapping("/batchDelete")
	@ResponseBody
	public ModelAndView batchDelete(HttpServletRequest request) {
		String ids = request.getParameter("idList");
		String[] idArray = ids.split(",");

		String userCode = SSOUtil.getSSOInfo(request).getUserCode();
		try {
			UserDto userDto = userService.queryUserInfoByCode(userCode);
			if (userDto == null || userDto.getUserType() == null) {
				logger.error("删除失败,用户登录失效");
				return ajaxDeleteERROR("删除失败,用户登录失效");
			}
			if (idArray != null && idArray.length > 0) {
				List<Long> uploadIds = new LinkedList<Long>();
				for (String id : idArray) {
					uploadIds.add(Long.valueOf(id));
				}
				Iterator<Long> iterator = uploadIds.iterator();
				while (iterator.hasNext()) {
					Long upload = (Long) iterator.next();
					List<Long> uploadIdList = new LinkedList<Long>();
					uploadIdList.add(upload);
					ReconFileUploadForQuery query = new ReconFileUploadForQuery();
					query.setUploadId(upload);
					List<ReconFileUploadDto> uploadObjs = reconFileUploadService.query(query);
					if (CollectionUtils.isNotEmpty(uploadObjs)) {
						ReconFileUploadDto reconFileUploadDto = uploadObjs.get(0);
						// 品牌服务费
						if (reconFileUploadDto.getFileType().intValue() == ReconFileTypeEnum.BRAND_FEE.getCode()) {
							// 删除list中的品牌服务文件uploadId
							iterator.remove();

							if (!checkReconStatusByChannel(reconFileUploadDto.getChannelNo())) {
								logger.error("删除失败,有对账正在进行中...");
								return ajaxDeleteERROR("删除失败,有对账正在进行中");
							}
							if (!checkBrandFeeReconStatus(upload)) {
								logger.error("删除失败,文件已认领...");
								return ajaxDeleteERROR("删除失败,文件已认领");
							}
							ReconFileUploadForQuery reconFileUploadForQuery = new ReconFileUploadForQuery();
							reconFileUploadForQuery.setUploadIds(uploadIdList);
							reconFileUploadForQuery.setStatus(FileUploadStatusEnum.DOING_DELETE.getCode());
							reconFileUploadService.updateStatus(reconFileUploadForQuery); // 更新回单对象状态为删除中

							reconFundsBrandFeeService.deleteUploadId(upload);// 删除品牌服务费明细
							reconFileUploadService.deleteById(upload);// 删除文件记录
						}
					}
				}
				// 如果list为空值, 则都是品牌服务文件。 不用进行下一步操作。
				if (uploadIds.size() == 0) {
					return ajaxDeleteSuccess("文件开始删除并重置对账结果,请稍后查询删除结果");
				}

				// 删除之前对文件的资金对账进行判断
				if (!checkFundsReconStatus(uploadIds)) {
					logger.error("删除失败,文件已认领...");
					return ajaxDeleteERROR("删除失败,文件已认领");
				}
				if (!checkReconStatus(uploadIds)) {
					logger.error("删除失败,有对账正在进行中...");
					return ajaxDeleteERROR("删除失败,有对账正在进行中");
				}

				ReconFileUploadForQuery reconFileUploadForQuery = new ReconFileUploadForQuery();
				reconFileUploadForQuery.setUploadIds(uploadIds);
				reconFileUploadForQuery.setStatus(FileUploadStatusEnum.DOING_DELETE.getCode());
				reconFileUploadService.updateStatus(reconFileUploadForQuery); // 更新回单对象状态为删除中

				reconfileRemoveService.deleteReconFile(userDto.getUserType(), uploadIds);
				return ajaxDeleteSuccess("文件开始删除并重置对账结果,请稍后查询删除结果");
			}
		} catch (Exception e) {
			logger.error("批量删除失败", e);
			return ajaxDeleteERROR("批量删除失败");
		}
		return ajaxDeleteSuccess("批量删除成功");
	}

//删除选中:

@RequestMapping(value = "/batchDeleteSelected", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String batchDeleteSelected(HttpServletRequest request) {
		String ids = request.getParameter("idList");
		String[] idArray = ids.split(",");

		String userCode = SSOUtil.getSSOInfo(request).getUserCode();
		try {
			UserDto userDto = userService.queryUserInfoByCode(userCode);
			if (userDto == null || userDto.getUserType() == null) {
				logger.error("删除失败,用户登录失效");
				return "删除失败,用户登录失效";
			}
			if (idArray != null && idArray.length > 0) {
				List<Long> uploadIds = new LinkedList<Long>();
				for (String id : idArray) {
					uploadIds.add(Long.valueOf(id));
				}

				Iterator<Long> iterator = uploadIds.iterator();
				while (iterator.hasNext()) {
					Long upload = (Long) iterator.next();
					List<Long> uploadIdList = new LinkedList<Long>();
					uploadIdList.add(upload);
					ReconFileUploadForQuery query = new ReconFileUploadForQuery();
					query.setUploadId(upload);
					List<ReconFileUploadDto> uploadObjs = reconFileUploadService.query(query);
					if (CollectionUtils.isNotEmpty(uploadObjs)) {
						ReconFileUploadDto reconFileUploadDto = uploadObjs.get(0);
						// 品牌服务费
						if (reconFileUploadDto.getFileType().intValue() == ReconFileTypeEnum.BRAND_FEE.getCode()) {
							// 删除list中的品牌服务文件uploadId
							iterator.remove();

							if (!checkReconStatusByChannel(reconFileUploadDto.getChannelNo())) {
								logger.error("删除失败,有对账正在进行中...");
								return "删除失败,有对账正在进行中";
							}
							if (!checkBrandFeeReconStatus(upload)) {
								logger.error("删除失败,文件已认领...");
								return "删除失败,文件已认领";
							}
							ReconFileUploadForQuery reconFileUploadForQuery = new ReconFileUploadForQuery();
							reconFileUploadForQuery.setUploadIds(uploadIdList);
							reconFileUploadForQuery.setStatus(FileUploadStatusEnum.DOING_DELETE.getCode());
							reconFileUploadService.updateStatus(reconFileUploadForQuery); // 更新回单对象状态为删除中

							reconFundsBrandFeeService.deleteUploadId(upload);// 删除品牌服务费明细
							reconFileUploadService.deleteById(upload);// 删除文件记录
						}
					}
				}
				// 如果list为空值, 则都是品牌服务文件。 不用进行下一步操作。
				if (uploadIds.size() == 0) {
					return "文件开始删除并重置对账结果,请稍后查询删除结果";
				}

				// 删除之前对文件的资金对账进行判断
				if (!checkFundsReconStatus(uploadIds)) {
					logger.error("删除失败,文件已认领...");
					return "删除失败,文件已认领";
				}

				if (!checkReconStatus(uploadIds)) {
					logger.error("删除失败,有对账正在进行中...");
					return "删除失败,有对账正在进行中";
				}
				ReconFileUploadForQuery reconFileUploadForQuery = new ReconFileUploadForQuery();
				reconFileUploadForQuery.setUploadIds(uploadIds);
				reconFileUploadForQuery.setStatus(FileUploadStatusEnum.DOING_DELETE.getCode());
				reconFileUploadService.updateStatus(reconFileUploadForQuery); // 更新回单对象状态为删除中

				reconfileRemoveService.deleteReconFile(userDto.getUserType(), uploadIds);
				return "文件开始删除并重置对账结果,请稍后查询删除结果";
			}
		} catch (Exception e) {
			logger.error("批量删除失败", e);
			return "批量删除失败";
		}
		return "批量删除成功";
	}










  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值