Browse Source

工作票导出功能,修改

wangchangsheng 3 years ago
parent
commit
7b71501caf

+ 1 - 1
pom.xml

@@ -66,7 +66,7 @@
         <dependency>
         <dependency>
             <groupId>com.alibaba</groupId>
             <groupId>com.alibaba</groupId>
             <artifactId>druid-spring-boot-starter</artifactId>
             <artifactId>druid-spring-boot-starter</artifactId>
-            <version>1.1.10</version>
+            <version>1.1.21</version>
         </dependency>
         </dependency>
 
 
         <dependency>
         <dependency>

+ 1 - 1
src/main/java/com/gyee/viewticket/MpGenerator.java

@@ -28,7 +28,7 @@ public class MpGenerator {
     //作者
     //作者
     private static String authorName = "admin";
     private static String authorName = "admin";
     //要生成的表名
     //要生成的表名
-    private static String[] tables = {"WINDFARM"};
+    private static String[] tables = {"LOCATIONS"};
     //table前缀
     //table前缀
     private static String prefix = "";
     private static String prefix = "";
 
 

+ 3 - 0
src/main/java/com/gyee/viewticket/mapper/ticket/LocationsMapper.java

@@ -18,5 +18,8 @@ import java.util.List;
 @Repository
 @Repository
 @Mapper
 @Mapper
 public interface LocationsMapper extends BaseMapper<Locations> {
 public interface LocationsMapper extends BaseMapper<Locations> {
+
     List<Locations> selectDescription(String location, String description);
     List<Locations> selectDescription(String location, String description);
+
+    List<Locations> selectLocations(String location);
 }
 }

+ 1 - 0
src/main/java/com/gyee/viewticket/model/ticket/Locations.java

@@ -3,6 +3,7 @@ package com.gyee.viewticket.model.ticket;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.extension.activerecord.Model;
 import com.baomidou.mybatisplus.extension.activerecord.Model;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableId;
+import java.time.LocalDateTime;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableField;
 import java.io.Serializable;
 import java.io.Serializable;
 import java.util.Date;
 import java.util.Date;

+ 22 - 1
src/main/java/com/gyee/viewticket/service/impl/ticket/LocationsServiceImpl.java

@@ -23,11 +23,32 @@ public class LocationsServiceImpl extends ServiceImpl<LocationsMapper, Locations
     LocationsMapper locationsMapper;
     LocationsMapper locationsMapper;
 
 
     @Override
     @Override
-    public String gerDescription(String location, String description) {
+    public String getDescription(String location, String description) {
         List<Locations> list = locationsMapper.selectDescription(location+"%",description);
         List<Locations> list = locationsMapper.selectDescription(location+"%",description);
         if (list.size()>0){
         if (list.size()>0){
             return list.get(0).getLocation();
             return list.get(0).getLocation();
         }
         }
         return null;
         return null;
     }
     }
+
+    @Override
+    public String getLocations(String location) {
+
+        int d = 2;
+        StringBuilder sb = new StringBuilder();
+        while (null !=location && location.length() >=d){
+            List<Locations> list  = locationsMapper.selectLocations(location.substring(0,d));
+
+            if (null != list && list.size()>0){
+
+                sb.append("/").append(list.get(0).getDescription());
+            }
+            d = d+2;
+
+        }
+
+
+        return sb.toString();
+    }
+
 }
 }

+ 13 - 6
src/main/java/com/gyee/viewticket/service/impl/ticket/WorkticketServiceImpl.java

@@ -8,10 +8,6 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.gyee.viewticket.util.TicketUtil;
 import com.gyee.viewticket.util.TicketUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
-import sun.text.resources.fr.FormatData_fr;
-
-import java.lang.reflect.Array;
-import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.*;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
@@ -67,7 +63,7 @@ public class WorkticketServiceImpl extends ServiceImpl<WorkticketMapper, Worktic
         workticket.setWspeed(wspeed);//风速
         workticket.setWspeed(wspeed);//风速
         String wxbj = TicketUtil.getWxbj(description);
         String wxbj = TicketUtil.getWxbj(description);
         if (wxbj.length() > 0) {
         if (wxbj.length() > 0) {
-            String loc = locationsService.gerDescription(location.trim(), wxbj.trim());
+            String loc = locationsService.getDescription(location.trim(), wxbj.trim());
             workticket.setWtnum(loc.length() > 0 ? loc : location);
             workticket.setWtnum(loc.length() > 0 ? loc : location);
         } else {
         } else {
             workticket.setWtnum(location);//风电机编号
             workticket.setWtnum(location);//风电机编号
@@ -118,10 +114,21 @@ public class WorkticketServiceImpl extends ServiceImpl<WorkticketMapper, Worktic
 
 
             Map<String, List<Map>> wpMap = new LinkedHashMap<>();
             Map<String, List<Map>> wpMap = new LinkedHashMap<>();
             for (String wp : workdepts) {
             for (String wp : workdepts) {
-                if ("风场风机".equals(type) && wp.endsWith("DZ")) {
+                if ("风场风机".equals(type.getParam()) && wp.endsWith("DZ")) {
                     continue;
                     continue;
                 }
                 }
                 List<Map> map = workticketMapper.selectWorkticketList(wp, type.getParam(), st, et);
                 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);
                 wpMap.put(wp, map);
             }
             }
             objectType.put(type.getValue(), wpMap);
             objectType.put(type.getValue(), wpMap);

+ 19 - 1
src/main/java/com/gyee/viewticket/service/ticket/LocationsService.java

@@ -4,6 +4,8 @@ import com.gyee.viewticket.model.ticket.Locations;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
+import java.util.List;
+
 /**
 /**
  * <p>
  * <p>
  *  服务类
  *  服务类
@@ -14,6 +16,22 @@ import org.springframework.stereotype.Service;
  */
  */
 @Service
 @Service
 public interface LocationsService extends IService<Locations> {
 public interface LocationsService extends IService<Locations> {
-    String gerDescription(String location,String description);
+    /**
+     *
+     * @param location
+     * @param description
+     * @return
+     */
+    String getDescription(String location, String description);
+
+    /**
+     * 获取位置信息
+     * @param location
+     * @return
+     */
+    String getLocations(String location);
+
+
+
 
 
 }
 }

+ 11 - 0
src/main/resources/mapper/ticket/LocationsMapper.xml

@@ -37,4 +37,15 @@
             and DESCRIPTION =  #{description}
             and DESCRIPTION =  #{description}
         </where>
         </where>
     </select>
     </select>
+
+
+    <select id="selectLocations" resultType="com.gyee.viewticket.model.ticket.Locations">
+        SELECT
+        *
+        FROM
+        LOCATIONS
+        <where>
+           location =  #{location}
+        </where>
+    </select>
 </mapper>
 </mapper>

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

@@ -272,6 +272,7 @@
 
 
         WITH cte1 AS (
         WITH cte1 AS (
         SELECT
         SELECT
+        w.wtnum,
         w.ticketnum,
         w.ticketnum,
         w.principal,
         w.principal,
         w.deptgroup1,
         w.deptgroup1,
@@ -281,7 +282,7 @@
         CASE WHEN w.startdate IS NULL THEN w.applyfirestarttime ELSE w.startdate END AS startdate,
         CASE WHEN w.startdate IS NULL THEN w.applyfirestarttime ELSE w.startdate END AS startdate,
         CASE WHEN w.enddate IS NULL THEN w.applyfireendtime ELSE w.enddate END AS enddate,
         CASE WHEN w.enddate IS NULL THEN w.applyfireendtime ELSE w.enddate END AS enddate,
         w.signatory,
         w.signatory,
-        w.inceptdate,
+        CASE WHEN w.inceptdate IS NULL THEN  w.signdate ELSE w.inceptdate END AS inceptdate,
         CASE WHEN w.fiatuser1 IS NULL THEN w.fiatuser ELSE w.fiatuser1 END AS fiatuser1,
         CASE WHEN w.fiatuser1 IS NULL THEN w.fiatuser ELSE w.fiatuser1 END AS fiatuser1,
         w.fiatdate,
         w.fiatdate,
         w.startworktime,
         w.startworktime,

+ 77 - 1
src/test/java/com/gyee/viewticket/ViewticketApplicationTests.java

@@ -3,11 +3,87 @@ package com.gyee.viewticket;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.Test;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.SpringBootTest;
 
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
 @SpringBootTest
 @SpringBootTest
 class ViewticketApplicationTests {
 class ViewticketApplicationTests {
 
 
     @Test
     @Test
-    void contextLoads() {
+    void contextLoads() throws Exception {
+
+
+            // 开始时间
+            long start = System.currentTimeMillis();
+            List<String> list = new ArrayList<String>();
+
+            for (int i = 1; i <= 3000; i++) {
+                list.add(i + "");
+            }
+            // 每500条数据开启一条线程
+            int threadSize = 500;
+            // 总数据条数
+            int dataSize = list.size();
+            // 线程数
+            int threadNum = dataSize / threadSize + 1;
+            // 定义标记,过滤threadNum为整数
+            boolean special = dataSize % threadSize == 0;
+
+            // 创建一个线程池
+            ExecutorService exec = Executors.newFixedThreadPool(threadNum);
+            // 定义一个任务集合
+            List<Callable<Integer>> tasks = new ArrayList<Callable<Integer>>();
+            Callable<Integer> task = null;
+            List<String> cutList = null;
+
+            // 确定每条线程的数据
+            for (int i = 0; i < threadNum; i++) {
+                if (i == threadNum - 1) {
+                    if (special) {
+                        break;
+                    }
+                    cutList = list.subList(threadSize * i, dataSize);
+                } else {
+                    cutList = list.subList(threadSize * i, threadSize * (i + 1));
+                }
+                // System.out.println("第" + (i + 1) + "组:" + cutList.toString());
+                final List<String> listStr = cutList;
+                task = new Callable<Integer>() {
+
+                    @Override
+                    public Integer call() throws Exception {
+                        //System.out.println(Thread.currentThread().getName() + "线程:" + listStr);
+
+                        listStr.stream().forEach(i->{
+
+                            System.out.println(Thread.currentThread().getName() + "线程:" + i);
+                        });
+
+
+                        return 1;
+                    }
+                };
+                // 这里提交的任务容器列表和返回的Future列表存在顺序对应的关系
+                tasks.add(task);
+            }
+
+            List<Future<Integer>> results = exec.invokeAll(tasks);
+//
+//            for (Future<Integer> future : results) {
+//                System.out.println(future.get());
+//            }
+
+            // 关闭线程池
+            exec.shutdown();
+            System.out.println("线程任务执行结束");
+            System.err.println("执行任务消耗了 :" + (System.currentTimeMillis() - start) + "毫秒");
+
+
+
     }
     }
 
 
 }
 }