فهرست منبع

工作票导出功能,修改2

wangchangsheng 3 سال پیش
والد
کامیت
dfda51d6f4

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 12739 - 0
logrecord/viewticket.log


+ 53 - 0
src/main/java/com/gyee/viewticket/comm/task/TaskThreadCallable.java

@@ -0,0 +1,53 @@
+package com.gyee.viewticket.comm.task;
+
+import com.gyee.viewticket.mapper.ticket.WorkticketMapper;
+import com.gyee.viewticket.model.ticket.Datadictionary;
+import com.gyee.viewticket.service.ticket.LocationsService;
+
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+
+public class TaskThreadCallable implements Callable {
+
+
+
+    private String workdept;
+    private Datadictionary type;
+    private String st;
+    private  String et;
+    private WorkticketMapper workticketMapper;
+    private LocationsService locationsService;
+
+    public TaskThreadCallable(String workdept, Datadictionary type, String st, String et, WorkticketMapper workticketMapper, LocationsService locationsService) {
+        this.workdept = workdept;
+        this.type = type;
+        this.st = st;
+        this.et = et;
+        this.workticketMapper = workticketMapper;
+        this.locationsService = locationsService;
+    }
+
+    @Override
+    public Map<String,List<Map>> call() throws Exception {
+
+        Map<String,List<Map>> m = new LinkedHashMap<>();
+
+        List<Map> map = this.workticketMapper.selectWorkticketList(this.workdept, this.type.getParam(), this.st, this.et);
+
+        if ("风场风机".equals(this.type.getParam())){
+            map.stream().forEach(i->{
+                String  wtnum = i.get("wtnum").toString();
+                String location = this.locationsService.getLocations(wtnum);
+                i.put("location",location);
+            });
+
+        }
+        m.put(this.workdept,map);
+
+        return m;
+    }
+
+}

+ 60 - 0
src/main/java/com/gyee/viewticket/comm/task/ThreadPoolTaskConfig.java

@@ -0,0 +1,60 @@
+package com.gyee.viewticket.comm.task;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.ThreadPoolExecutor;
+
+@Configuration
+public class ThreadPoolTaskConfig {
+
+
+    /**
+     *   默认情况下,在创建了线程池后,线程池中的线程数为0,当有任务来之后,就会创建一个线程去执行任务,
+     *	当线程池中的线程数目达到corePoolSize后,就会把到达的任务放到缓存队列当中;
+     *  当队列满了,就继续创建线程,当线程数量大于等于maxPoolSize后,开始使用拒绝策略拒绝
+     */
+
+    /** 核心线程数(默认线程数) */
+    private static final int corePoolSize = 100;
+    /** 最大线程数 */
+    private static final int maxPoolSize = 500;
+    /** 允许线程空闲时间(单位:默认为秒) */
+    private static final int keepAliveTime = 60;
+    /** 缓冲队列大小 */
+    private static final int queueCapacity = 500;
+    /** 允许等待最长时间 */
+    private static final int awaitTime = 10;
+    /** 线程池名前缀 */
+    private static final String threadNamePrefix = "view-thread-";
+
+    private ThreadPoolTaskExecutor executor;
+
+    public ThreadPoolTaskExecutor getExecutor(){
+        if (executor == null)
+            executor = taskExecutor();
+
+        return executor;
+    }
+
+
+    private ThreadPoolTaskExecutor taskExecutor(){
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        executor.setCorePoolSize(corePoolSize);
+        executor.setMaxPoolSize(maxPoolSize);
+        executor.setQueueCapacity(queueCapacity);
+        executor.setKeepAliveSeconds(keepAliveTime);
+        executor.setThreadNamePrefix(threadNamePrefix);
+        executor.setAwaitTerminationSeconds(awaitTime);
+
+        // 线程池对拒绝任务的处理策略
+        // CallerRunsPolicy:由调用线程(提交任务的线程)处理该任务
+        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+        // 初始化
+        executor.initialize();
+        return executor;
+    }
+
+
+
+}

+ 36 - 0
src/main/java/com/gyee/viewticket/controller/viewticket/LocationsController.java

@@ -0,0 +1,36 @@
+package com.gyee.viewticket.controller.viewticket;
+
+
+import com.gyee.viewticket.comm.domain.AjaxResult;
+import com.gyee.viewticket.service.ticket.LocationsService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author admin
+ * @since 2022-01-18
+ */
+@RestController
+@RequestMapping("/locations")
+public class LocationsController {
+
+    @Autowired
+    LocationsService locationsService;
+
+    @GetMapping(value = "getlocation")
+    public String getLocations(String location) {
+
+      String s =   locationsService.getLocations(location);
+
+      return s;
+    }
+
+}
+

+ 30 - 9
src/main/java/com/gyee/viewticket/service/impl/ticket/WorkticketServiceImpl.java

@@ -1,5 +1,7 @@
 package com.gyee.viewticket.service.impl.ticket;
 
+import com.gyee.viewticket.comm.task.TaskThreadCallable;
+import com.gyee.viewticket.comm.task.ThreadPoolTaskConfig;
 import com.gyee.viewticket.mapper.ticket.WoworktaskMapper;
 import com.gyee.viewticket.model.ticket.*;
 import com.gyee.viewticket.mapper.ticket.WorkticketMapper;
@@ -10,6 +12,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
 import java.util.stream.Collectors;
 
 /**
@@ -40,6 +46,9 @@ public class WorkticketServiceImpl extends ServiceImpl<WorkticketMapper, Worktic
     @Autowired
     private DatadictionaryService datadictionaryService;
 
+    @Autowired
+    private ThreadPoolTaskConfig taskConfig;
+
 
     @Override
     public boolean saveWorkticket(String workdept, String location, String description, String wspeed, String worktypeid, String labornum) {
@@ -113,23 +122,35 @@ public class WorkticketServiceImpl extends ServiceImpl<WorkticketMapper, Worktic
         for (Datadictionary type : datalist) {
 
             Map<String, List<Map>> wpMap = new LinkedHashMap<>();
+            List<Future<Map<String,List<Map>>>> list = new LinkedList<>();
             for (String wp : workdepts) {
                 if ("风场风机".equals(type.getParam()) && wp.endsWith("DZ")) {
                     continue;
                 }
-                List<Map> map = workticketMapper.selectWorkticketList(wp, type.getParam(), st, et);
+                TaskThreadCallable task = new TaskThreadCallable(wp,type,st,et,workticketMapper,locationsService);
+                Future submit = taskConfig.getExecutor().submit(task);
+                list.add(submit);
 
-                if ("风场风机".equals(type.getParam())) {
-                    map.stream().forEach(i->{
-                        String  wtnum = i.get("wtnum").toString();
-                        String location = locationsService.getLocations(wtnum);
-                        i.put("location",location);
 
-                    });
-                }
+//                List<Map> map = workticketMapper.selectWorkticketList(wp, type.getParam(), st, et);
+//
+//                  if ("风场风机".equals(type.getParam())){
+//                    map.stream().forEach(i->{
+//                        String  wtnum = i.get("wtnum").toString();
+//                        String location = locationsService.getLocations(wtnum);
+//                        i.put("location",location);
+//                    });
+//
+//                }
 
 
-                wpMap.put(wp, map);
+            }
+
+            for (Future<Map<String,List<Map>>> future :list){
+                Map<String,List<Map>> map = future.get();
+                for (Map.Entry<String, List<Map>> entry : map.entrySet()) {
+                    wpMap.put(entry.getKey(), entry.getValue());
+                }
             }
             objectType.put(type.getValue(), wpMap);
         }

+ 3 - 2
src/main/resources/mapper/ticket/WorkticketMapper.xml

@@ -272,11 +272,12 @@
 
         WITH cte1 AS (
         SELECT
+        w.id,
         w.wtnum,
         w.ticketnum,
         w.principal,
         w.deptgroup1,
-        t.description2,
+        CASE WHEN  t.description2 IS NULL THEN w.worktask ELSE t.description2 END AS  description2,
         t.address,
         w.wspeed,
         CASE WHEN w.startdate IS NULL THEN w.applyfirestarttime ELSE w.startdate END AS startdate,
@@ -328,7 +329,7 @@
         </where>
 
         )
-        select  *  from cte1 order by ticketnum desc
+        select  *  from cte1 order by id desc
 
     </select>