/** * ================================================================= * 版权所有 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; /** * 类说明:
* * ** 详细描述:
* * @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; /** * 进页面方法 方法说明:
* * *
* * @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; } /** * 业务处理方法 方法说明:
* * @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; } /** * 业务处理方法 导出:
* * @param bean * @return */ @SuppressWarnings("unchecked") @RequestMapping("/export") public ModelAndView export(BeanBase bean, HttpServletRequest request) { Mapmap = null; try { bean.setContent(bean.getContent() + getCreateId()); String processorName = bean.getNeedcontrolprocess(); if (StringUtils.isEmpty(processorName)) { bean = service.service(bean); } else { process(bean); } map = (Map ) 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); } /** * 业务处理方法 导出:
* * @param bean * @return */ @SuppressWarnings("unchecked") @RequestMapping("/exportForInv") public ModelAndView exportForInv(BeanBase bean, HttpServletRequest request) { Mapmap = null; try { billInvBusiness.invExport(bean); map = (Map ) 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); } /** * 模板导出:
* * @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; } /** * 模板导入:
* * @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)) { Mapmap = (Map ) request .getSession().getAttribute("repeatSubmit"); if (map == null) { map = new ConcurrentHashMap (); 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; } }