wenhongquan 3 年之前
父节点
当前提交
5aa16951c4

+ 198 - 7
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/TblTaskController.java

@@ -1,11 +1,20 @@
 package com.ruoyi.web.controller.system;
 
-import java.util.List;
+import java.security.Security;
+import java.util.*;
 import javax.servlet.http.HttpServletResponse;
 
+import com.alibaba.fastjson.JSON;
+import com.ruoyi.common.core.domain.entity.SysDept;
+import com.ruoyi.common.core.domain.entity.SysDictData;
+import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.JSUtils;
+import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.quartz.task.RyTask;
 import com.ruoyi.system.domain.TblTaskLog;
-import com.ruoyi.system.service.ITblTaskLogService;
+import com.ruoyi.system.service.*;
+import org.apache.commons.jexl3.JxltEngine;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -21,7 +30,6 @@ import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.enums.BusinessType;
 import com.ruoyi.system.domain.TblTask;
-import com.ruoyi.system.service.ITblTaskService;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.common.core.page.TableDataInfo;
 
@@ -44,6 +52,15 @@ public class TblTaskController extends BaseController
     @Autowired
     private ITblTaskLogService tblTaskLogService;
 
+    @Autowired
+    private ISysDictDataService sysDictDataService;
+
+    @Autowired
+    private ISysUserService userService;
+
+    @Autowired
+    private ISysDeptService deptService;
+
     /**
      * 查询工单任务列表
      */
@@ -62,11 +79,185 @@ public class TblTaskController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:task:export')")
     @Log(title = "工单任务", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
-    public void export(HttpServletResponse response, TblTask tblTask)
+    public void export(HttpServletResponse response,@RequestBody TblTask tblTask)
     {
-        List<TblTask> list = tblTaskService.selectTblTaskList(tblTask);
-        ExcelUtil<TblTask> util = new ExcelUtil<TblTask>(TblTask.class);
-        util.exportExcel(response, list, "工单任务数据");
+        TblTask task = tblTaskService.selectTblTaskByTaskId(tblTask.getTaskId());
+        if(task==null){
+            try{
+                response.getWriter().write(JSON.toJSONString(error("未找到任务")));
+            }catch (Exception e){
+
+            }finally {
+                return;
+            }
+        }
+        //过滤相同的log状态
+        Map<Long,TblTaskLog> logs = new HashMap<>();
+        for (TblTaskLog l:task.getTblTaskLogList()
+             ) {
+            if(logs.get(l.getTaskStatus())!=null){
+                TblTaskLog log = logs.get(l.getTaskStatus());
+                if(log.getCreateTime().getTime()<l.getCreateTime().getTime()) {
+                    logs.put(l.getTaskStatus(), l);
+                }
+            }else{
+                logs.put(l.getTaskStatus(),l);
+            }
+        }
+        List<TblTaskLog> loglist = new ArrayList<>();
+        loglist.addAll(logs.values());
+        task.setTblTaskLogList(loglist);
+
+
+
+
+        SysDictData sysDictData = new SysDictData();
+        sysDictData.setDictType("task_type");
+        List<SysDictData>  list1 = sysDictDataService.selectDictDataList(sysDictData);
+        Map<Long,String> typemap = new HashMap<>();
+        for (SysDictData d:list1
+        ) {
+            typemap.put(Long.parseLong(d.getDictValue()),d.getDictLabel());
+        }
+        
+        sysDictData = new SysDictData();
+        sysDictData.setDictType("sys_area");
+        list1 = sysDictDataService.selectDictDataList(sysDictData);
+        Map<String,String> areamap = new HashMap<>();
+        for (SysDictData d:list1
+        ) {
+            areamap.put(d.getDictValue(),d.getDictLabel());
+        }
+
+        List<SysUser> users = userService.selectUserList(new SysUser());
+        Map<Long,SysUser> usermap = new HashMap<>();
+        for (SysUser d:users
+        ) {
+            usermap.put(d.getUserId(),d);
+        }
+
+        List<SysDept> depts = deptService.selectDeptList(new SysDept());
+        Map<Long,SysDept> deptmap = new HashMap<>();
+        for (SysDept d:depts
+        ) {
+            deptmap.put(d.getDeptId(),d);
+        }
+
+        Map<Long,TblTaskLog> logmap = new HashMap<>();
+        for (TblTaskLog d:task.getTblTaskLogList()
+        ) {
+            logmap.put(d.getTaskStatus(),d);
+        }
+
+        String commjs = "function run(){"+ "var allusers="+JSON.toJSONString(users)+";";
+        commjs+="var alldept = "+JSON.toJSONString(depts)+";";
+        commjs+="var taskinfo = "+JSON.toJSONString(task)+";";
+//        commjs +="function run(){";
+
+
+
+
+        String runjs = commjs+"return allusers.filter(function(i){ return (JSON.parse(taskinfo.tblTaskLogList.filter(function(ii){return ii.taskStatus ===-1})[0].logDes).zyfzr+'').indexOf(i.userId+'')!=-1 }).map(function(i){return i.nickName}).join(',') }";
+        Object fzr = JSUtils.runjs(runjs);
+        runjs = commjs+"return JSON.parse(\n" +
+                "                          taskinfo.tblTaskLogList.filter(\n" +
+                "                            function(ii) { return ii.taskStatus === -1}\n" +
+                "                          )[0].logDes\n" +
+                "                        ).zyrs }";
+        Object zyrs = JSUtils.runjs(runjs);
+        runjs =commjs+"return allusers.filter(function(i){ return (JSON.parse(taskinfo.tblTaskLogList.filter(function(ii){return ii.taskStatus ===-1})[0].logDes).zyfzr+'').indexOf(i.userId+'')!=-1 }).map(function(i){return i.phonenumber}).join(',') }";
+        Object lxfs = JSUtils.runjs(runjs);
+
+        runjs = commjs+"return JSON.parse(\n" +
+                "                          taskinfo.tblTaskLogList.filter(\n" +
+                "                            function(ii) { return ii.taskStatus === -1}\n" +
+                "                          )[0].logDes\n" +
+                "                        ).carxh }";
+        Object zycl = JSUtils.runjs(runjs);
+        runjs = commjs+"return JSON.parse(\n" +
+                "                          taskinfo.tblTaskLogList.filter(\n" +
+                "                            function(ii) { return ii.taskStatus === -1}\n" +
+                "                          )[0].logDes\n" +
+                "                        ).carnumber }";
+        Object cph = JSUtils.runjs(runjs);
+
+        runjs = commjs+"return JSON.parse(\n" +
+                "                          taskinfo.tblTaskLogList.filter(\n" +
+                "                            function(ii) { return ii.taskStatus === -1}\n" +
+                "                          )[0].logDes\n" +
+                "                        ).gls }";
+        Object gls = JSUtils.runjs(runjs);
+
+
+
+        runjs= commjs+ "return eval(JSON.toJSONString(JSON.parse(taskinfo.tblTaskLogList.filter(function(ii){return ii.taskStatus === 3 })[0].logDes).gzldata)).map(function(i,index){ if(index==0){return (i.value1 == '' ? '□' : '✔')+i.name + '   ' + i.value1 + '   ' + i.unit1+'\\r\\n\\r\\n';}  return (index%3!=1?'    ':'')+ (i.value1 == '' ? '□' : '✔') + i.name + '   ' + i.value1 + '   ' + i.unit1 +(index%3==0?'\\r\\n\\r\\n':'');}).join('') }" ;
+        Object gzl = JSUtils.runjs(runjs);
+
+        runjs= commjs+ "return (( eval(JSON.toJSONString(JSON.parse(taskinfo.tblTaskLogList.filter(function(ii){return ii.taskStatus === 3 })[0].logDes).clsbdata)).map(function(i,index){  return { content: (i.value1 == '' ? '□' : '✔') + i.name + '   ' + i.value1 + '   ' + i.unit1 +(i.hasOwnProperty('value2')?('   '+i.value2+'   '+i.unit2+';'):'') ,index:index}}))).filter(function(i){return i.index%2==0;}) }" ;
+        Collection cl1 = JSON.parseObject(JSON.toJSONString(JSUtils.runjs(runjs)),Map.class).values();
+
+        runjs= commjs+ "return (( eval(JSON.toJSONString(JSON.parse(taskinfo.tblTaskLogList.filter(function(ii){return ii.taskStatus === 3 })[0].logDes).clsbdata)).map(function(i,index){  return { content: (i.value1 == '' ? '□' : '✔') + i.name + '   ' + i.value1 + '   ' + i.unit1 +(i.hasOwnProperty('value2')?('   '+i.value2+'   '+i.unit2+';'):'') ,index:index}}))).filter(function(i){return i.index%2==1;}) }" ;
+        Collection cl2 = JSON.parseObject(JSON.toJSONString(JSUtils.runjs(runjs)),Map.class).values();
+
+
+        runjs= commjs+ "return (( eval(JSON.toJSONString(JSON.parse(taskinfo.tblTaskLogList.filter(function(ii){return ii.taskStatus === 3 })[0].logDes).hcdata)).filter(function(i){return i.name.indexOf('其他物资')==-1;}).map(function(i,index){  return { content: (i.value1 == '' ? '□' : '✔') + i.name + '   ' + i.value1 + '   ' + i.unit1 +(i.hasOwnProperty('value2')?('   '+i.value2+'   '+i.unit2+';'):'') ,index:index}}))).filter(function(i){return i.index%3==0;}) }" ;
+        Collection hc1 = JSON.parseObject(JSON.toJSONString(JSUtils.runjs(runjs)),Map.class).values();
+
+        runjs= commjs+ "return (( eval(JSON.toJSONString(JSON.parse(taskinfo.tblTaskLogList.filter(function(ii){return ii.taskStatus === 3 })[0].logDes).hcdata)).filter(function(i){return i.name.indexOf('其他物资')==-1;}).map(function(i,index){  return { content: (i.value1 == '' ? '□' : '✔') + i.name + '   ' + i.value1 + '   ' + i.unit1 +(i.hasOwnProperty('value2')?('   '+i.value2+'   '+i.unit2+';'):'') ,index:index}}))).filter(function(i){return i.index%3==1;}) }" ;
+        Collection hc2 = JSON.parseObject(JSON.toJSONString(JSUtils.runjs(runjs)),Map.class).values();
+
+        runjs= commjs+ "return (( eval(JSON.toJSONString(JSON.parse(taskinfo.tblTaskLogList.filter(function(ii){return ii.taskStatus === 3 })[0].logDes).hcdata)).filter(function(i){return i.name.indexOf('其他物资')==-1;}).map(function(i,index){  return { content: (i.value1 == '' ? '□' : '✔') + i.name + '   ' + i.value1 + '   ' + i.unit1 +(i.hasOwnProperty('value2')?('   '+i.value2+'   '+i.unit2+';'):'') ,index:index}}))).filter(function(i){return i.index%3==2;}) }" ;
+        Collection hc3 = JSON.parseObject(JSON.toJSONString(JSUtils.runjs(runjs)),Map.class).values();
+
+        runjs= commjs+ "return (( eval(JSON.toJSONString(JSON.parse(taskinfo.tblTaskLogList.filter(function(ii){return ii.taskStatus === 3 })[0].logDes).hcdata)).filter(function(i){return i.name.indexOf('其他物资')!=-1;}).map(function(i,index){  return { content: (i.value1 == '' ? '□' : '✔') + i.name + '   ' + i.value1 + '   ' + i.unit1 +(i.hasOwnProperty('value2')?('   '+i.value2+'   '+i.unit2+';'):'') ,index:index}}))) }" ;
+        Collection hc4 = JSON.parseObject(JSON.toJSONString(JSUtils.runjs(runjs)),Map.class).values();
+
+        runjs = commjs+"return JSON.parse(\n" +
+                "                          taskinfo.tblTaskLogList.filter(\n" +
+                "                            function(ii) { return ii.taskStatus === 6}\n" +
+                "                          )[0].logDes\n" +
+                "                        ).hctime }";
+        Object hcsj = JSUtils.runjs(runjs);
+
+        runjs = commjs+"return JSON.parse(\n" +
+                "                          taskinfo.tblTaskLogList.filter(\n" +
+                "                            function(ii) { return ii.taskStatus === 6}\n" +
+                "                          )[0].logDes\n" +
+                "                        ).hcdes }";
+        Object hcdes = JSUtils.runjs(runjs);
+
+        Map<String,Object> rw = new HashMap<>();
+        rw.put("fzr",fzr);
+        rw.put("zyrs",zyrs);
+        rw.put("lxfs",lxfs);
+        rw.put("zycl",zycl);
+        rw.put("cph",cph);
+        rw.put("gls",gls);
+        rw.put("gzl",gzl);
+        rw.put("cl1",cl1);
+        rw.put("cl2",cl2);
+        rw.put("hc1",hc1);
+        rw.put("hc2",hc2);
+        rw.put("hc3",hc3);
+        rw.put("hc4",hc4);
+
+        rw.put("hcsj",hcsj);
+        rw.put("hcdes",hcdes);
+
+
+        
+        
+        Map<String,Object> data = new HashMap<>();
+
+        data.put("rw", rw);
+        data.put("task",task);
+        data.put("dt", DateUtils.class);
+        data.put("typemap",typemap);
+        data.put("areamap",areamap);
+
+        exportExcel("反馈单","fk",data,response);
+//        ExcelUtil<TblTask> util = new ExcelUtil<TblTask>(TblTask.class);
+//        util.exportExcel(response, list, "工单任务数据");
     }
 
     /**

二进制
ruoyi-admin/src/main/resources/fk.xlsx


+ 23 - 0
ruoyi-common/pom.xml

@@ -126,6 +126,29 @@
         </dependency>
 
 
+        <!--excel-->
+        <dependency>
+            <groupId>org.jxls</groupId>
+            <artifactId>jxls</artifactId>
+            <version>[2.12.0,)</version>
+        </dependency>
+        <dependency>
+            <groupId>org.jxls</groupId>
+            <artifactId>jxls-poi</artifactId>
+            <version>[2.12.0,)</version>
+        </dependency>
+        <dependency>
+            <groupId>org.jxls</groupId>
+            <artifactId>jxls-jexcel</artifactId>
+            <version>[1.0.9,)</version>
+        </dependency>
+        <dependency>
+            <groupId>org.jxls</groupId>
+            <artifactId>jxls-reader</artifactId>
+            <version>[2.0.6,)</version>
+        </dependency>
+
+
 
 
     </dependencies>

+ 64 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java

@@ -1,8 +1,17 @@
 package com.ruoyi.common.core.controller;
 
 import java.beans.PropertyEditorSupport;
+import java.io.*;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.jexl3.JexlBuilder;
+import org.jxls.expression.ExpressionEvaluator;
+import org.jxls.expression.JexlExpressionEvaluator;
+import org.jxls.util.JxlsConfigProvider;
+import org.jxls.util.TransformerFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.web.bind.WebDataBinder;
@@ -21,6 +30,10 @@ import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.sql.SqlUtil;
 
+import javax.servlet.http.HttpServletResponse;
+import org.jxls.common.Context;
+import org.jxls.util.JxlsHelper;
+
 /**
  * web层通用数据处理
  * 
@@ -183,4 +196,55 @@ public class BaseController
     {
         return getLoginUser().getUsername();
     }
+
+    public void exportExcel(String fileName, String excelTemplateName, Map<String, Object> map,
+                                    HttpServletResponse resp) {
+        String path = "./" + fileName + ".xlsx";
+//        String tpath = "/Users/wenhongquan/gitdata/nnbp/ruoyi-admin/src/main/resources/fk.xlsx";
+//        tpath = "/" + excelTemplateName + ".xlsx";
+//        File filex = new File(tpath);
+        //
+//        InputStream is =  new FileInputStream(filex)
+        try (InputStream is =  this.getClass().getResourceAsStream("/" + excelTemplateName + ".xlsx") ) {
+            try (OutputStream os = new FileOutputStream(path)) {
+                Context context = new Context();
+                // context.putVar("list", map.get("list"));
+                // context.putVar("totalMan", map.get("totalMan"));
+
+                for (String key : map.keySet()) {
+                    context.putVar(key, map.get(key));
+                }
+
+                JxlsHelper.getInstance().processTemplate(is, os, context);
+            }
+            Thread.sleep(1000);
+            // path是指欲下载的文件的路径。
+            File file = new File(path);
+            // 取得文件名。
+            String filename = file.getName();
+            // 以流的形式下载文件。
+            InputStream bis = new BufferedInputStream(new FileInputStream(file));
+            byte[] buffer = new byte[bis.available()];
+            bis.read(buffer);
+            bis.close();
+            // 清空response
+            resp.reset();
+            // 设置response的Header
+            resp.addHeader("Content-Disposition",
+                    "attachment;filename=" + new String(filename.getBytes("gb2312"), "ISO8859-1"));
+            resp.addHeader("Content-Length", "" + file.length());
+            OutputStream toClient = new BufferedOutputStream(resp.getOutputStream());
+            resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=gb2312");
+            toClient.write(buffer);
+            toClient.flush();
+            toClient.close();
+            // 删除生成的临时文件
+            if (file.exists()) {
+                file.delete();
+            }
+
+        } catch (Exception e) {
+            logger.error(e.toString());
+        }
+    }
 }

+ 34 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/JSUtils.java

@@ -0,0 +1,34 @@
+package com.ruoyi.common.utils;
+
+import com.alibaba.fastjson.JSON;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.script.*;
+
+public class JSUtils {
+    private final static Logger logger = LoggerFactory.getLogger(JSUtils.class);
+    public  static Object runjs(String js){
+        try{
+            if(js==null) return "";
+
+            ScriptEngine engine = new ScriptEngineManager().getEngineByName("javascript");
+            Compilable compilable = (Compilable) engine;
+            Bindings bindings = engine.createBindings(); //Local级别的Binding
+            String script ="var JSON = com.alibaba.fastjson.JSON; "+ js+";run();"; //定义函数并调用
+            CompiledScript JSFunction = compilable.compile(script); //解析编译脚本函数
+
+            Object result = JSFunction.eval(bindings);
+            return result;
+        }catch (Exception e){
+            JSUtils.logger.error(e.getMessage());
+        }
+        return "";
+    }
+
+
+    public static void main(String[] args) {
+
+       System.out.println(JSUtils.runjs("function run(){ var c=[{  status:2,log:'{\"aa\":[\"21\",\"22\"]}'},{  status:1,log:'{\"aa\":[\"11\",\"12\"]}'}];return JSON.parse(c.filter(function(i){return i.status==2})[0].log).aa[0]  }"));
+    }
+}

+ 4 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/TblTaskLog.java

@@ -1,5 +1,7 @@
 package com.ruoyi.system.domain;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
 import com.ruoyi.common.annotation.Excel;
@@ -38,6 +40,8 @@ public class TblTaskLog extends BaseEntity
     @Excel(name = "日志视频")
     private String logVideos;
 
+
+
     public void setId(Long id) 
     {
         this.id = id;