From 0738b44fe051878706298958e76a6e74babb2ab2 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期四, 19 九月 2024 15:11:18 +0800
Subject: [PATCH] #

---
 zy-acs-flow/src/page/route/importTemp.csv                                                    |    2 
 zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/RouteService.java            |    2 +
 zy-acs-flow/src/i18n/en.js                                                                   |    2 
 zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/CodeGapServiceImpl.java |   33 ++++++++++++++++
 zy-acs-manager/src/main/java/com/zy/acs/manager/common/domain/RouteExcel.java                |   17 ++++++++
 zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/RouteServiceImpl.java   |   27 +++++++++----
 zy-acs-manager/src/main/java/com/zy/acs/manager/manager/controller/RouteController.java      |   20 ++++++++--
 zy-acs-manager/src/main/java/com/zy/acs/manager/manager/entity/Route.java                    |    4 --
 zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/CodeGapService.java          |    3 +
 9 files changed, 91 insertions(+), 19 deletions(-)

diff --git a/zy-acs-flow/src/i18n/en.js b/zy-acs-flow/src/i18n/en.js
index 4c789ce..66a91f1 100644
--- a/zy-acs-flow/src/i18n/en.js
+++ b/zy-acs-flow/src/i18n/en.js
@@ -55,7 +55,7 @@
                 tips: 'The import is running, please do not close this tab.',
                 err: 'Failed to import this file, please make sure your provided a valid CSV file.',
                 download: 'Download Import Template',
-                result: 'Contacts import complete. Imported %{success} contacts, with %{error} errors',
+                result: 'Contacts import complete. Imported %{success} success, with %{error} errors',
             }
         },
     },
diff --git a/zy-acs-flow/src/page/route/importTemp.csv b/zy-acs-flow/src/page/route/importTemp.csv
index 03b80d5..5fb071e 100644
--- a/zy-acs-flow/src/page/route/importTemp.csv
+++ b/zy-acs-flow/src/page/route/importTemp.csv
@@ -1 +1 @@
-start_code,end_code,distance,"direction(0:鏃犲簭,1:姝e悜,2:鍙嶅悜)"
+start_code,end_code,"direction(0:鏃犲簭,1:姝e悜,2:鍙嶅悜)"
diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/common/domain/RouteExcel.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/common/domain/RouteExcel.java
new file mode 100644
index 0000000..aeb9c0d
--- /dev/null
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/common/domain/RouteExcel.java
@@ -0,0 +1,17 @@
+package com.zy.acs.manager.common.domain;
+
+import lombok.Data;
+
+/**
+ * Created by vincent on 9/19/2024
+ */
+@Data
+public class RouteExcel {
+
+    private String startCode;
+
+    private String endCode;
+
+    private Integer direction;
+
+}
diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/controller/RouteController.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/controller/RouteController.java
index 58d15e3..e1d0eb6 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/controller/RouteController.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/controller/RouteController.java
@@ -2,7 +2,7 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.zy.acs.common.utils.GsonUtils;
+import com.zy.acs.common.constant.CommonConstant;
 import com.zy.acs.common.utils.Utils;
 import com.zy.acs.framework.common.Cools;
 import com.zy.acs.framework.common.R;
@@ -10,8 +10,11 @@
 import com.zy.acs.manager.common.domain.BaseParam;
 import com.zy.acs.manager.common.domain.KeyValVo;
 import com.zy.acs.manager.common.domain.PageParam;
+import com.zy.acs.manager.common.domain.RouteExcel;
 import com.zy.acs.manager.common.utils.ExcelUtil;
+import com.zy.acs.manager.manager.entity.Code;
 import com.zy.acs.manager.manager.entity.Route;
+import com.zy.acs.manager.manager.service.CodeGapService;
 import com.zy.acs.manager.manager.service.CodeService;
 import com.zy.acs.manager.manager.service.RouteService;
 import com.zy.acs.manager.system.controller.BaseController;
@@ -32,6 +35,8 @@
     private RouteService routeService;
     @Autowired
     private CodeService codeService;
+    @Autowired
+    private CodeGapService codeGapService;
 
     @PreAuthorize("hasAuthority('manager:route:list')")
     @PostMapping("/route/page")
@@ -118,7 +123,7 @@
     @PreAuthorize("hasAuthority('manager:route:save')")
     @PostMapping("/route/import")
     public R importBatch(@RequestBody List<Map<String, Object>> list) {
-        Date now = new Date();  Long userId = getLoginUserId();
+        Long userId = getLoginUserId();
         String regex = "([a-zA-Z]+)\\(";
         Pattern pattern = Pattern.compile(regex);
         for (Map<String, Object> map : list) {
@@ -132,8 +137,15 @@
                 key = Utils.toCamelCase(key);
                 one.put(key, entry.getValue());
             }
-            Route route = Cools.conver(one, Route.class);
-            System.out.println(GsonUtils.toJson(route));
+            RouteExcel excelDto = Cools.conver(one, RouteExcel.class);
+
+            Code code0 = codeService.selectByData(Utils.zeroFill(excelDto.getStartCode(), CommonConstant.QR_CODE_LEN));
+            Code code1 = codeService.selectByData(Utils.zeroFill(excelDto.getEndCode(), CommonConstant.QR_CODE_LEN));
+
+            if (null == code0 || null == code1) { continue; }
+
+            routeService.createRouteByCode(code0, code1, excelDto.getDirection(), userId);
+            codeGapService.createCodeGapByCode(code0, code1, userId);
         }
         return R.ok();
     }
diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/entity/Route.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/entity/Route.java
index c77e036..7d4df2a 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/entity/Route.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/entity/Route.java
@@ -1,7 +1,6 @@
 package com.zy.acs.manager.manager.entity;
 
 import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.zy.acs.framework.common.SpringUtils;
@@ -114,9 +113,6 @@
      */
     @ApiModelProperty(value= "澶囨敞")
     private String memo;
-
-    @TableField(exist = false)
-    private Double distance;
 
     public Route() {}
 
diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/CodeGapService.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/CodeGapService.java
index 9c06c13..390c8a8 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/CodeGapService.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/CodeGapService.java
@@ -1,10 +1,13 @@
 package com.zy.acs.manager.manager.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.zy.acs.manager.manager.entity.Code;
 import com.zy.acs.manager.manager.entity.CodeGap;
 
 public interface CodeGapService extends IService<CodeGap> {
 
+    CodeGap createCodeGapByCode(Code code0, Code code1, Long userId);
+
     CodeGap findByCodeOfBoth(Long code0, Long code1);
 
 }
diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/RouteService.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/RouteService.java
index 031c534..551ef87 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/RouteService.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/RouteService.java
@@ -10,6 +10,8 @@
 
     Route createRouteByCode(Code code0, Code code1);
 
+    Route createRouteByCode(Code code0, Code code1, Integer direction, Long userId);
+
     List<String> findCodeDataOfSingle(Long code);
 
     Route findByCodeOfBoth(Long code0, Long code1);
diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/CodeGapServiceImpl.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/CodeGapServiceImpl.java
index 4c8daae..1193822 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/CodeGapServiceImpl.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/CodeGapServiceImpl.java
@@ -2,14 +2,47 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.zy.acs.framework.exception.CoolException;
+import com.zy.acs.manager.core.service.MapService;
+import com.zy.acs.manager.manager.entity.Code;
 import com.zy.acs.manager.manager.entity.CodeGap;
 import com.zy.acs.manager.manager.mapper.CodeGapMapper;
 import com.zy.acs.manager.manager.service.CodeGapService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+
+import java.util.Date;
 
 @Service("codeGapService")
 public class CodeGapServiceImpl extends ServiceImpl<CodeGapMapper, CodeGap> implements CodeGapService {
 
+    @Autowired
+    private MapService mapService;
+
+    @Override
+    public CodeGap createCodeGapByCode(Code code0, Code code1, Long userId) {
+        CodeGap codeGap = findByCodeOfBoth(code0.getId(), code1.getId());
+        if (null == codeGap) {
+            Date now = new Date();
+            codeGap = new CodeGap();
+
+            codeGap.setCode0(code0.getId());
+            codeGap.setCode1(code1.getId());
+            double distance = mapService.calculateDistance(code0.getX(), code0.getY(), code1.getX(), code1.getY());
+            codeGap.setDistance(distance);
+
+            codeGap.setStatus(1);
+            codeGap.setCreateBy(userId);
+            codeGap.setCreateTime(now);
+            codeGap.setUpdateBy(userId);
+            codeGap.setUpdateTime(now);
+            if (!this.save(codeGap)) {
+                throw new CoolException(code0.getData() + "-" + code1.getData() + " save fail![Route]");
+            }
+        }
+        return codeGap;
+    }
+
     @Override
     public CodeGap findByCodeOfBoth(Long code0, Long code1) {
         CodeGap codeGap = getOne(new LambdaQueryWrapper<CodeGap>().eq(CodeGap::getCode0, code0).eq(CodeGap::getCode1, code1));
diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/RouteServiceImpl.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/RouteServiceImpl.java
index f799b6f..639d150 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/RouteServiceImpl.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/RouteServiceImpl.java
@@ -1,9 +1,9 @@
 package com.zy.acs.manager.manager.service.impl;
 
-import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.zy.acs.manager.common.exception.BusinessException;
+import com.zy.acs.common.utils.GsonUtils;
+import com.zy.acs.framework.exception.CoolException;
 import com.zy.acs.manager.manager.entity.Code;
 import com.zy.acs.manager.manager.entity.Route;
 import com.zy.acs.manager.manager.mapper.RouteMapper;
@@ -12,9 +12,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import java.util.*;
 
 @Service("routeService")
 public class RouteServiceImpl extends ServiceImpl<RouteMapper, Route> implements RouteService {
@@ -24,16 +22,27 @@
 
     @Override
     public Route createRouteByCode(Code code0, Code code1) {
+        return createRouteByCode(code0, code1, 0, null);
+    }
+
+    @Override
+    public Route createRouteByCode(Code code0, Code code1, Integer direction, Long userId) {
         Route route = this.findByCodeOfBoth(code0.getId(), code1.getId());
+        direction = Optional.ofNullable(direction).orElse(0);
         if (null == route) {
+            Date now = new Date();
             route = new Route();
-            route.setUuid(code0.getData()+"-"+code1.getData());
+            route.setUuid(code0.getData() + "-" + code1.getData());
             route.setStartCode(code0.getId());
             route.setEndCode(code1.getId());
-            route.setDirection(0);
-            route.setCodeArr(JSON.toJSONString(Arrays.asList(code0.getId(), code1.getId())));
+            route.setDirection(direction);
+            route.setCodeArr(GsonUtils.toJson(Arrays.asList(code0.getId(), code1.getId())));
+            route.setCreateBy(userId);
+            route.setCreateTime(now);
+            route.setUpdateBy(userId);
+            route.setUpdateTime(now);
             if (!this.save(route)) {
-                throw new BusinessException(route.getCodeArr()+" save fail![Route]");
+                throw new CoolException(route.getCodeArr()+" save fail![Route]");
             }
         }
         return route;

--
Gitblit v1.9.1