`

controler层重复校验

阅读更多
/**
 * =================================================================
 * 版权所有 2011-2020 泰海网络支付服务有限公司,并保留所有权利
 * -----------------------------------------------------------------
 * 这不是一个自由软件!您不能在任何未经允许的前提下对程序代码进行修改和使用;
 * 不允许对程序代码以任何形式任何目的的再发布
 * =================================================================
 */
package com.sf.novatar.tpl.controller;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.sf.novatar.tpl.bean.BeanBase;
import com.sf.novatar.tpl.enums.BusinessStatus;
import com.sf.novatar.tpl.p2.business.BillInvBusiness;
import com.sf.novatar.tpl.service.IService;
import com.sf.novatar.tpl.util.StringUtil;
import com.sf.novatar.tpl.util.UserUtil;
import com.sf.novatar.tpl.util.Util;
import com.sf.novatar.tpl.util.ViewExcel;
import com.sfpay.framework.base.exception.ServiceException;
import com.sfpay.framework.base.utils.StringUtils;
import com.sfpay.framework2.core.util.JsonUtil;
import com.sfpay.framework2.web.json.JsonMessage;

/**
 * 类说明:<br>
 * 
 * 
 * <p>
 * 详细描述:<br>
 * 
 * 
 * </p>
 * 
 * @author 608279 向鹏
 * 
 *         CreateDate: May 20, 2015
 */
@Controller
@RequestMapping("/service")
public class ServiceController extends BaseController {

	private final static Logger logger = LoggerFactory
			.getLogger(ServiceController.class);

	@Resource(name = "billInvBusiness")
	private BillInvBusiness billInvBusiness;

	@Resource
	private IService service;

	/**
	 * 进页面方法 方法说明:<br>
	 * 
	 * @param bean
	 * @return
	 */
	@RequestMapping("/page")
	public String page(BeanBase bean, Model model) {
		// 1.判断是否发送CORE
		// 2.无需调核心则找CONTROLL处理类
		/*
		 * try { service.service(bean); } catch (Exception e) {
		 * logger.info(bean.getProcessMsg(), e); }
		 */
		return bean.getName();
	}

	@RequestMapping("/modelView")
	public ModelAndView modelView(BeanBase bean) {
		ModelAndView mv = new ModelAndView(bean.getName());
		bean.setDatas(Util.converToBean(bean));
		mv.getModel().putAll(bean.getDatas().get(0));
		return mv;
	}

	/**
	 * 业务处理方法 方法说明:<br>
	 * 
	 * @param bean
	 * @return
	 */
	@RequestMapping(value = "/pageReq")
	@ResponseBody
	public Object pageReq(BeanBase bean, HttpServletRequest request,
			HttpServletResponse response) {
		// 1.判断是否发送CORE
		// 2.无需调核心则找CONTROLL处理类
		String splitRegex = ";";
		String message = "操作成功";
		String result = repeatSubmitPreCheck(bean.getRepeatCheckBuz(), request,
				response);
		if (!StringUtil.areBlank(result)) {
			bean.setStatus(BusinessStatus.FAIL);
			bean.setProcessMsg("请不要重复提交");
			return bean;
		}
		try {
			String processorName = bean.getNeedcontrolprocess();
			String createId = UserUtil.getCurrentUser().getCreateId();
			if (StringUtils.isEmpty(processorName)) {
				bean.setContent(bean.getContent() + createId);
				bean = service.service(bean);
			} else {
				String[] contents = bean.getContent().split(splitRegex);
				int length = contents.length;
				for (int i = 0; i < length; i++) {
					contents[i] += createId;
				}
				bean.setContent(org.apache.commons.lang3.StringUtils.join(
						contents, splitRegex));
				process(bean);
				bean.setStatus(BusinessStatus.FINLISH);
				if (org.apache.commons.lang3.StringUtils.isBlank(bean
						.getProcessMsg())) {
					bean.setProcessMsg(message);
				}
			}
		} catch (Throwable e) {
			logger.error(e.getMessage(), e);
			bean.setStatus(BusinessStatus.FAIL);
			String msg = e.getMessage();
			if (!StringUtil.areBlank(msg) && msg.length() > 64
					&& (e instanceof ServiceException == false)) {
				msg = "处理失败,请联系管理员";
			}
			bean.setProcessMsg(msg);
		} finally {
			// repeatSubmitPostCheck(bean.getRepeatCheckBuz(), request);
		}
		return bean;
	}

	/**
	 * 业务处理方法 导出:<br>
	 * 
	 * @param bean
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/export")
	public ModelAndView export(BeanBase bean, HttpServletRequest request) {
		Map<String, Object> map = null;
		try {
			bean.setContent(bean.getContent() + getCreateId());
			String processorName = bean.getNeedcontrolprocess();
			if (StringUtils.isEmpty(processorName)) {
				bean = service.service(bean);
			} else {
				process(bean);
			}
			map = (Map<String, Object>) bean.getExpData().get("excelData");
		} catch (Throwable e) {
			logger.info(e.getMessage(), e);
			bean.setStatus(BusinessStatus.FAIL);
			bean.setProcessMsg(e.getMessage());
		}
		return new ModelAndView(new ViewExcel(), map);
	}

	/**
	 * 业务处理方法 导出:<br>
	 * 
	 * @param bean
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/exportForInv")
	public ModelAndView exportForInv(BeanBase bean, HttpServletRequest request) {
		Map<String, Object> map = null;
		try {
			billInvBusiness.invExport(bean);
			map = (Map<String, Object>) bean.getExpData().get("excelData");
		} catch (Throwable e) {
			logger.info(e.getMessage(), e);
			bean.setStatus(BusinessStatus.FAIL);
			bean.setProcessMsg(e.getMessage());
		}
		return new ModelAndView(new ViewExcel(), map);
	}

	/**
	 * 模板导出:<br>
	 * 
	 * @param bean
	 * @return
	 */
	@RequestMapping("/template_export")
	public ModelAndView template_export(BeanBase bean) {
		ModelAndView modelview = null;
		try {
			process(bean);
			modelview = (ModelAndView) bean.getExpData().get("modelview");
		} catch (Throwable e) {
			logger.info(e.getMessage(), e);
			bean.setStatus(BusinessStatus.FAIL);
			bean.setProcessMsg(e.getMessage());
		}
		return modelview;
	}

	/**
	 * 模板导入:<br>
	 * 
	 * @param bean
	 * @return
	 */
	@RequestMapping("/template_import")
	@ResponseBody
	public Object template_import(BeanBase bean, HttpServletRequest request) {
		try {
			bean.setContent(bean.getContent() + getCreateId());
			String processorName = bean.getNeedcontrolprocess();
			if (StringUtils.isEmpty(processorName)) {
				bean = service.service(bean);
			} else {
				process(bean);
			}
		} catch (Throwable e) {
			logger.error(e.getMessage(), e);
			bean.setStatus(BusinessStatus.FAIL);
			bean.setProcessMsg(e.getMessage());
		}
		return bean;
	}

	/**
	 * 文件上传
	 * 
	 * @param bean
	 * @param request
	 * @param response
	 */
	@RequestMapping("/file_upload")
	public void ajaxfileupload(BeanBase bean, HttpServletRequest request,
			HttpServletResponse response) {
		response.setContentType("text/html;charset=utf-8");
		String result = repeatSubmitPreCheck(bean.getRepeatCheckBuz(), request,
				response);
		if (!StringUtil.areBlank(result)) {
			bean.setStatus(BusinessStatus.FAIL);
			bean.setProcessMsg("请不要重复提交");
			return;
		}
		JsonMessage jsonMessage = new JsonMessage();
		try {
			bean.setContent(bean.getContent() + getCreateId());
			String processorName = bean.getNeedcontrolprocess();
			if (StringUtils.isEmpty(processorName)) {
				bean = service.service(bean);
			} else {
				process(bean);
			}
			jsonMessage.setCode("FINISH");
			jsonMessage.setMessage("上传成功");
		} catch (Throwable e) {
			logger.error(e.getMessage(), e);
			jsonMessage.setCode("FAIL");
			if (e instanceof ServiceException) {
				jsonMessage.setMessage(e.getMessage());
			} else {
				jsonMessage.setMessage("上传失败");
			}
		}
		try {
			response.getWriter().write(JsonUtil.toJSONString(jsonMessage));
		} catch (IOException e) {
			logger.error(e.getMessage(), e);
			e.printStackTrace();
		}
	}

	/**
	 * 文件上传
	 * 
	 * @param bean
	 * @param request
	 * @param response
	 */
	@RequestMapping("/file_upload_bean")
	@ResponseBody
	public Object ajaxfileupload_bean(BeanBase bean,
			HttpServletRequest request, HttpServletResponse response) {
		response.setContentType("text/html;charset=utf-8");
		String result = repeatSubmitPreCheck(bean.getRepeatCheckBuz(), request,
				response);
		if (!StringUtil.areBlank(result)) {
			bean.setStatus(BusinessStatus.FAIL);
			bean.setProcessMsg("请不要重复提交");
			return bean;
		}
		try {
			bean.setContent(bean.getContent() + getCreateId());
			String processorName = bean.getNeedcontrolprocess();
			if (StringUtils.isEmpty(processorName)) {
				bean = service.service(bean);
			} else {
				process(bean);
			}
			bean.setStatus(BusinessStatus.FINLISH);
			bean.setProcessMsg("上传成功");
		} catch (Throwable e) {
			logger.error(e.getMessage(), e);

			bean.setStatus(BusinessStatus.FAIL);
			if (e instanceof ServiceException) {
				bean.setProcessMsg(e.getMessage());
			} else {
				bean.setProcessMsg("上传失败");
			}
		}
		return bean;
	}

	/**
	 * 文件上传
	 * 
	 * @param bean
	 * @param request
	 * @param response
	 */
	@RequestMapping("/ajax_form_submit")
	public void ajaxformSubmit(BeanBase bean, HttpServletRequest request,
			HttpServletResponse response) {
		response.setContentType("text/html;charset=utf-8");
		String splitRegex = ";";
		String result = repeatSubmitPreCheck(bean.getRepeatCheckBuz(), request,
				response);
		if (!StringUtil.areBlank(result)) {
			bean.setStatus(BusinessStatus.FAIL);
			bean.setProcessMsg("请不要重复提交");
			return;
		}
		try {
			String processorName = bean.getNeedcontrolprocess();
			String createId = UserUtil.getCurrentUser().getCreateId();
			if (StringUtils.isEmpty(processorName)) {
				bean = service.service(bean);
			} else {
				String[] contents = bean.getContent().split(splitRegex);
				int length = contents.length;
				for (int i = 0; i < length; i++) {
					contents[i] += createId;
				}
				bean.setContent(org.apache.commons.lang3.StringUtils.join(
						contents, splitRegex));
				process(bean);
			}
			bean.setStatus(BusinessStatus.FINLISH);
			if (org.apache.commons.lang3.StringUtils.isBlank(bean
					.getProcessMsg())) {
				bean.setProcessMsg("操作成功");
			}
		} catch (Throwable e) {
			logger.error(e.getMessage(), e);
			bean.setStatus(BusinessStatus.FAIL);
			if (e instanceof ServiceException) {
				bean.setProcessMsg(e.getMessage());
			} else {
				bean.setProcessMsg("操作失败");
			}
		}
		try {
			response.getWriter().write(JsonUtil.toJSONString(bean));
		} catch (IOException e) {
			logger.error(e.getMessage(), e);
			e.printStackTrace();
		}
	}

	/**
	 * 防重复前置检查
	 * 
	 * @param buzCode
	 * @param request
	 *            void
	 */
	@SuppressWarnings("unchecked")
	private String repeatSubmitPreCheck(String buzCode,
			HttpServletRequest request, HttpServletResponse response) {
		if (!StringUtil.areBlank(buzCode)) {
			Map<String, Integer> map = (Map<String, Integer>) request
					.getSession().getAttribute("repeatSubmit");
			if (map == null) {
				map = new ConcurrentHashMap<String, Integer>();
				request.getSession().setAttribute("repeatSubmit", map);
			}
			Integer submitTargetVersion = map.get(buzCode);
			if (submitTargetVersion == null) {
				submitTargetVersion = 0;
			}
			Cookie tarC = null;
			Integer submitSourceVersion = 0;
			for (Cookie c : request.getCookies()) {
				if (c.getName().equalsIgnoreCase("repeatSubmit")) {
					submitSourceVersion = Integer.parseInt(c.getValue());
					tarC = c;
					break;
				}
			}

			if (submitSourceVersion < submitTargetVersion) {
				return "请不要重复提交";
			} else {
				map.put(buzCode, submitSourceVersion + 1);
				if (tarC == null) {
					tarC = new Cookie("repeatSubmit",
							String.valueOf(submitSourceVersion + 1));
				} else {
					tarC.setValue(String.valueOf(submitSourceVersion + 1));
				}
				response.addCookie(tarC);
			}
		}
		return null;
	}

}

分享到:
评论

相关推荐

    springboot+mybatis+shiro+rabbitmq+redis项目实战,自动生成dao,service,controler层代码

    2. mybatisplus根据表自动生成dao,service,controler层的增删改成方法,极大提升开发效率 3. 包含功能:登录,用户管理,角色管理,菜单管理。用到插件:插件:lombok,finbugs,p3c等 4. 项目有源代码,有数据库...

    memery controler

    内存控制器(Memory Controller)是计算机系统中的关键组件,负责管理和协调CPU与主存之间的数据传输。在本场景中,我们关注的是一个经过FPGA验证的内存控制器设计,具体实现为"ddr_ctrl.v"文件,这表明我们讨论的是...

    GRBL上位机,grbl_controler

    该资源适合GRBL0.8以上版本,可以正常兼容最新的GRBL1.1F版本。以前的grbl controler,包括3.6.1版本都在GRBL1.1F上没法使用,典型的是设置界面无响应,虽然有数据返回,但是界面无显示,

    Woodwood Controler Example Protocol Program.rar

    本资料包“Woodwood Controler Example Protocol Program”提供了一个具体的示例,帮助学习者深入理解欧母龙PLC的控制协议和编程方法。 首先,我们要明确欧母龙PLC的工作原理。PLC是通过用户程序(即我们常说的梯形...

    SystemInfo Controler

    【SystemInfo Controler】是一个基于Delphi5开发的控件,专为Windows 98/ME/2000操作系统设计。在这些较早的Windows版本中,它提供了获取和展示系统信息的功能,如硬件配置、操作系统详细信息、内存状态等。通过集成...

    controler-size-change.rar_Size 0_mfc controler

    在本文中,我们将深入探讨如何在Visual C++ 6.0环境下使用MFC(Microsoft Foundation Classes)进行基于对话框的应用程序开发,特别是关注当窗口大小发生变化时,如何使控件大小随之调整。这一主题通常涉及到窗口...

    传智播客_俄罗斯方块游戏05_编写Controler类实现事件监听

    在本课程"传智播客_俄罗斯方块游戏05_编写Controller类实现事件监听"中,我们将深入探讨Java编程中的关键概念,特别是面向对象设计和事件处理。这些概念是JavaEE和JavaME开发的基础,对于任何希望在IT领域建立稳固...

    PID_Controler.rar_PID Simulink_matlab PID_matlab pid_pid mat

    PID Controler_Matlab Simulink

    extensible-host-controler-interface-usb-xhci-1.1(解密有书签).pdf

    xHCI1.1协议,解密板,有书签。eXtensible Host Controller Interface for Universal Serial Bus (xHCI) Requirements Specification November 2017 Revision 1.1

    controler.rar_controler_圆 运动_插补_步进_步进电机

    用电键控制步进电机朝各个方向做曲线,圆和直线运动。

    address.rar

    这是一个非常有意思的搭载在Tomcat上面运行的小案例哈,博主为了... MVC架构,是MVC而不是三层架构,也即我的整个操作分为Model层,Controler层和view层 第三,利用jsp以及Servlet类来完成数据交互 第四,就是c标签的使用

    Code Atmega16A mach nho_controler_

    【标题】"Code Atmega16A mach nho_controler_" 涉及的是使用Atmega16A微控制器进行小型机器控制的编程项目。这个控制器是Arduino系列中的一种,基于 AVR 单片机架构,由Atmel(现已被Microchip收购)生产。Atmega...

    extensible-host-controler-interface-usb-xhci.pdf

    这份文档是《可扩展主机控制器接口USB XHCI(eXtensible Host Controller Interface for Universal Serial Bus)需求规范》2019年5月的修订版1.22。该文档提供了xHCI技术的详细要求和规范,是USB接口标准的一部分。...

    传智播客_俄罗斯方块游戏05_编写controler类实现事件监听

    传智播客_俄罗斯方块游戏05_编写controler类实现事件监听.rar 传智播客_俄罗斯方块游戏05_编写controler类实现事件监听.rar 传智播客_俄罗斯方块游戏05_编写controler类实现事件监听.rar

    Smart-Room-Controler

    斯蒂芬妮·佩里亚(Stephanie Perea)智能房间控制器概述该项目的目的是在房间变暗时打开照明灯。 开灯使用光电二极管感应光水平允许用户使用按钮手动摇动灯细节该项目使用以下组件: 菲利普斯色相灯面包板电线...

    PID_Dc_ctrl.rar_DC-DC_controler dc motor_dc motor_motor DC + PID

    标题中的“PID_Dc_ctrl.rar_DC-DC_controler dc motor_dc motor_motor DC + PID”表明这是一个关于使用PID控制器(比例-积分-微分控制器)来控制DC电机的项目,其中涉及到了DC-DC转换器。DC-DC转换器是电子设备中...

    JSP网页民航售票系统课程设计源代码+文档

    3)最后使用tomcat服务器和Google浏览器进行web工程的部署和前端页面的调试,而后台设计思想是通过myeclipse编码调试,分别为dao层、damain层、exception层、formbean层、service层、utils工具层、controler层、ui层...

    RF controler

    ### 知识点一:红外遥控器的基本原理与应用 #### 1.1 红外遥控技术概述 红外遥控技术是一种广泛应用于家电、汽车、安防等领域的无线通信技术。它利用红外线作为信号传输媒介,通过发射端发送编码后的红外光脉冲,...

    pid.rar_pid_pid controler_简单pid

    描述中提到"pid controler(pid控制器)程序比较简单,但比较实用",暗示了这是一个简易实现的PID控制算法,适合初学者或者用于基础教学。 PID控制器是一种在自动化领域广泛应用的控制算法,它通过整合比例(P)、...

    sublime-package_controler

    内含sublime text3安装包,Package Control.sublime-package文件,channel_v3.json,以及SFTP插件文件SFTP.sublime-package文件。还有我解决安装SFTP插件时因为packagecontrol.io无法访问的相关心得,

Global site tag (gtag.js) - Google Analytics