fs-danaus
2023-09-14 31400fffd7b31397d6d8882d3927e7b870924233
src/com/yc/action/BaseAction.java
@@ -54,7 +54,7 @@
   public static void clearDuplicateSubmitUNID(){//删除指定的key
      RedisTemplate redisTemplate= (RedisTemplate) FactoryBean.getBean("redisTemplate");
      if(CurrentLocal.getunidLocal()!=null) {
         redisTemplate.delete(CurrentLocal.getunidLocal());
            redisTemplate.delete(CurrentLocal.getunidLocal());
      }
   }
@@ -542,7 +542,8 @@
   }
    @SuppressWarnings("unchecked")
   protected void print2Excel(HttpServletRequest request,HttpServletResponse resp, Page page, Object object,int formid,String type)  {
         try {
      SXSSFWorkbook wb=null;
      try {
             //读取当前功能号哪些字段是需要导出的
             String s=FileUtil.readFile(request.getServletContext().getRealPath("/")+request.getSession().getAttribute(SessionKey.PAGE_PATH)+File.separator+formid+File.separator+type+File.separator+"data");//
             if(request.getSession().getAttribute(SessionKey.USERCODE)==null){
@@ -597,7 +598,7 @@
             Map m=poi.writeExcel( dbid,str[0], page, name, filed,panel_name, panel_tfiled,
            map!=null?(List<?>)map.get("plist"):null,str[0],local,
            map!=null?(((String)map.get("desc")).split("-").length==5?this.replaceBlank(((String)map.get("desc")).split("-")[4]):""):"",hostUrl);
             SXSSFWorkbook wb=(SXSSFWorkbook)m.get("wb");
              wb=(SXSSFWorkbook)m.get("wb");
             String fileName=m.get("title")+"";
             if(wb!=null){
                File file1=new File(request.getServletContext().getRealPath("/")+"excel"+File.separator+dbid+File.separator+formid+File.separator+type);
@@ -607,7 +608,7 @@
               String path=request.getServletContext().getRealPath("/")+"excel"+File.separator+dbid+File.separator+formid+File.separator+type+File.separator+fileName.replace("/","_").replace("*","")+".xlsx";
               File file=new File(path);    
                 resp.setContentType("application/msexcel");
                 resp.setHeader("Content-Disposition", "attachment;Filename=" +new String(fileName.getBytes("utf-8"), "ISO8859-1")+ ".xlsx");
                 resp.setHeader("Content-Disposition", "attachment;Filename=\"" +new String(fileName.getBytes("utf-8"), "ISO8859-1")+ ".xlsx\"");//增加双引号,以解决文件下载报ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION by danaus 2023-07-20 14:41
                 //写到磁盘生成文件,为了给审计用 by danaus 2020/11/10 16:12
            FileOutputStream fileOut = new FileOutputStream(file);
@@ -633,14 +634,19 @@
            excelRecords(formid,type,map,file,request,page);//导出数据审计记录执行方法
                wb.dispose();
             }
             page = null;
         }catch (ParseException e) {
          e.printStackTrace();
          this.printJson(resp, "error;"+e.getMessage());   
         } catch (Exception e) {
             e.printStackTrace();
             this.printJson(resp, "error;"+e.getMessage());
         }
         }finally {
         try {
            wb.close();
         } catch (IOException e) {
            throw new RuntimeException(e);
         }
      }
    }
    /**
@@ -684,7 +690,7 @@
         e.printStackTrace();
      }finally {
         if(file!=null&&file.exists()&&file.isFile()) {
            log.info("del>>userCode:"+request.getSession().getAttribute(SessionKey.USERCODE)+"|dbid:"+request.getSession().getAttribute(SessionKey.DATA_BASE_ID)+"|"+file.getAbsolutePath());
            //log.info("del>>userCode:"+request.getSession().getAttribute(SessionKey.USERCODE)+"|dbid:"+request.getSession().getAttribute(SessionKey.DATA_BASE_ID)+"|"+file.getAbsolutePath());
            file.delete();
         }
      }   
@@ -700,18 +706,21 @@
               if(StringUtils.isNotBlank(ss[1])) {
                  //标题存在复合标题的情况,需要处理
                  String[] value = ss[1].split("\\|");
                  if (value.length > 1) {
                     StringJoiner newTitle = new StringJoiner("|");
                     String[] dyValue=new String[10];
                     if(gmap.get(ss[0].toLowerCase())!=null) {
                        dyValue = gmap.get(ss[0].toLowerCase()).split("\\|");
                     }
                     int index=0;//标记有动态标题
                     for (String s : value) {
                        if (s.trim().startsWith("!"))//如果是动态标题则替换
                           newTitle.add(gmap.get(ss[0].toLowerCase()));
                        else
                        if (s.trim().startsWith("!")) {//如果是动态标题则替换
                           newTitle.add(dyValue[index]);
                           index++;
                        }else {
                           newTitle.add(s);
                        }
                     }
                     name[i] = newTitle.toString();
                  } else {
                     name[i] = value[0];
                  }
               }
                  }else{
                     name[i]="";
@@ -769,25 +778,27 @@
        }
    }
    public void checkDuplicateSubmit(String unid){
   /**
    *
    * @param key
    * @param overtime 过期时间 秒为单位
    */
    public void checkDuplicateSubmit(String key,int overtime){
        RedisTemplate redisTemplate= (RedisTemplate) FactoryBean.getBean("redisTemplate");
        if(unid.equals("excel")){return;}//导入的跳出
        if(unid!=null&&!"".equalsIgnoreCase(unid)) {
        if(key.equals("excel")){return;}//导入的跳出
        if(key !=null&&!"".equalsIgnoreCase(key)) {
         synchronized(lock) {
            Object object = redisTemplate.opsForValue().get(unid);
            Object object = redisTemplate.opsForValue().get(key);
            if (object == null) {
               //不存在,加到redis里,过期时间设置为2分钟
               final int OVERTIME = 2;
               redisTemplate.opsForValue().set(unid, 1, OVERTIME, TimeUnit.MINUTES);
               CurrentLocal.setUnidLocal(unid);
               //不存在,加到redis里,过期时间设置为5秒
               //final int OVERTIME = 5;
               redisTemplate.opsForValue().set(key, 1, overtime, TimeUnit.SECONDS);
               CurrentLocal.setUnidLocal(key);
            } else {
               throw new ApplicationException("正在处理中...请不要重复提交");
            }
         }
        }else{
            throw new ApplicationException("参数unid不能为空,请确认前端是否有传递过来");
        }
    }
}