Procházet zdrojové kódy

营销户表信息导入,增加表类型

欧阳劲驰 před 16 hodinami
rodič
revize
4b5dd6964f

+ 40 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/constants/CustomerMeterType.java

@@ -0,0 +1,40 @@
+package com.shkpr.service.customgateway.core.constants;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * 营销表类型
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Getter
+@AllArgsConstructor
+public enum CustomerMeterType {
+    //机械表
+    NO_CYCLE_INFO((short) 0, "机械表"),
+    //远传表
+    MONTHLY((short) 1, "远传表"),
+    ;
+    /**
+     * 码
+     */
+    private final Short code;
+    /**
+     * 名称
+     */
+    private final String name;
+
+    /**
+     * @return 编码集合
+     */
+    public static short[] codes() {
+        CustomerMeterType[] values = values();
+        short[] codes = new short[values.length];
+        for (int i = 0; i < values.length; i++) {
+            codes[i] = values[i].getCode();
+        }
+        return codes;
+    }
+}

+ 7 - 2
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/domain/po/CustomerInfo.java

@@ -68,6 +68,11 @@ public class CustomerInfo {
     private String stampInfo;
 
     /**
+     * 水表类型
+     */
+    private Short meterType;
+
+    /**
      * 开户时间
      */
     @ExcelMapping("开户时间")
@@ -119,13 +124,13 @@ public class CustomerInfo {
      * 抄表册
      */
     @ExcelMapping("抄表册")
-    private String readbookName;
+    private String readBookName;
 
     /**
      * 抄表册类型
      */
     @ExcelMapping("抄表册类型")
-    private Short readbookType;
+    private Short readBookType;
 
     /**
      * 水表GIS经纬度

+ 18 - 29
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/filter/AccessFilter.java

@@ -48,7 +48,10 @@ public class AccessFilter extends OncePerRequestFilter {
     @Override
     protected void doFilterInternal(@NonNull HttpServletRequest request, @NonNull HttpServletResponse response, @NonNull FilterChain chain) throws IOException, ServletException {
         //忽略非get请求
-        if (!request.getMethod().equals(HttpMethod.GET.name())) return;
+        if (!request.getMethod().equals(HttpMethod.GET.name())) {
+            chain.doFilter(request, response);
+            return;
+        }
         //如果忽略列表包含该url,则直接放行
         if (securityProperties.getPermitPattern().stream()
                 .anyMatch(s -> new AntPathRequestMatcher(s).matches(request))) {
@@ -68,50 +71,36 @@ public class AccessFilter extends OncePerRequestFilter {
 
         //请求头访问密钥
         String accessKey = request.getHeader(AccessMetadata.Headers.ACCESS_KEY);
-        if (StringUtils.isBlank(accessKey)) {
-            AccessUtil.writeResponseCode(response, ResponseCode.ACCESS_KEY_MISS);
-            return;
-        }
+        if (StringUtils.isBlank(accessKey)) AccessUtil.writeResponseCode(response, ResponseCode.ACCESS_KEY_MISS);
         //访问密钥
         AccessKeys accessKeys = accessKeysService.findByAccessKey(accessKey);
-        if (accessKeys == null || accessKeys.getSecurityKey() == null) {
+        if (accessKeys == null || accessKeys.getSecurityKey() == null)
             AccessUtil.writeResponseCode(response, ResponseCode.ACCESS_KEY_INVALID);
-            return;
-        }
         //请求头时间戳
         String timestampStr = request.getHeader(AccessMetadata.Headers.TIMESTAMP);
-        if (StringUtils.isBlank(timestampStr)) {
-            AccessUtil.writeResponseCode(response, ResponseCode.TIMESTAMP_MISS);
-            return;
-        }
-        if (!NumberUtils.isDigits(timestampStr)) {
-            AccessUtil.writeResponseCode(response, ResponseCode.TIMESTAMP_INVALID);
-            return;
-        }
+        if (StringUtils.isBlank(timestampStr)) AccessUtil.writeResponseCode(response, ResponseCode.TIMESTAMP_MISS);
+        if (!NumberUtils.isDigits(timestampStr)) AccessUtil.writeResponseCode(response, ResponseCode.TIMESTAMP_INVALID);
         //时间戳
         long timestamp = Long.parseLong(timestampStr);
         if (ChronoUnit.MINUTES.between(Instant.ofEpochMilli(timestamp), Instant.now()) > 5 ||
-                ChronoUnit.MINUTES.between(Instant.ofEpochMilli(timestamp), Instant.now()) < -1) {
+                ChronoUnit.MINUTES.between(Instant.ofEpochMilli(timestamp), Instant.now()) < -1)
             AccessUtil.writeResponseCode(response, ResponseCode.TIMESTAMP_EXPIRED);
-            return;
-        }
         //签名
         String signature = request.getHeader(AccessMetadata.Headers.SIGNATURE);
-        if (StringUtils.isBlank(signature)) {
-            AccessUtil.writeResponseCode(response, ResponseCode.SIGNATURE_MISS);
-            return;
-        }
+        if (StringUtils.isBlank(signature)) AccessUtil.writeResponseCode(response, ResponseCode.SIGNATURE_MISS);
         //参数
         Map<String, String> params = request.getParameterMap().entrySet().stream()
                 .collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue()[0]));
+
         //签名验证
-        boolean matched = AccessUtil.matchesSignature(params, timestamp, accessKeys.getSecurityKey(), signature);
-        if (!matched) {
-            AccessUtil.writeResponseCode(response, ResponseCode.SIGNATURE_INVALID);
-            return;
+        if (accessKeys != null && accessKeys.getSecurityKey() != null) {
+            boolean matched = AccessUtil.matchesSignature(params, timestamp, accessKeys.getSecurityKey(), signature);
+            //签发token
+            if (matched)
+                SecurityUtil.setAuthentication(AccessToken.authenticated(accessKey, Collections.singletonList(new SimpleGrantedAuthority(AccessMetadata.AUTHORITY))));
+            else AccessUtil.writeResponseCode(response, ResponseCode.SIGNATURE_INVALID);
         }
-        //签发token
-        SecurityUtil.setAuthentication(AccessToken.authenticated(accessKey, Collections.singletonList(new SimpleGrantedAuthority(AccessMetadata.AUTHORITY))));
+
         chain.doFilter(request, response);
     }
 }

+ 6 - 6
custom-gateway-core/src/main/resources/mapper/CustomerInfoMapper.xml

@@ -18,9 +18,9 @@
             <if test="statusName != null and statusName != ''">status_name,</if>
             <if test="readCycleName != null and readCycleName != ''">read_cycle_name,</if>
             <if test="readerName != null and readerName != ''">reader_name,</if>
-            <if test="readbookName != null and readbookName != ''">readbook_name,</if>
+            <if test="readBookName != null and readBookName != ''">readbook_name,</if>
             <if test="readCycle != null">read_cycle,</if>
-            <if test="readbookType != null">readbook_type,</if>
+            <if test="readBookType != null">readbook_type,</if>
             <if test="gis != null and gis != ''">gis,</if>
             <if test="geomGis != null">geom_gis,</if>
         </trim>
@@ -41,9 +41,9 @@
             <if test="statusName != null and statusName != ''">#{statusName,jdbcType=VARCHAR},</if>
             <if test="readCycleName != null and readCycleName != ''">#{readCycleName,jdbcType=VARCHAR},</if>
             <if test="readerName != null and readerName != ''">#{readerName,jdbcType=VARCHAR},</if>
-            <if test="readbookName != null and readbookName != ''">#{readbookName,jdbcType=VARCHAR},</if>
+            <if test="readBookName != null and readBookName != ''">#{readBookName,jdbcType=VARCHAR},</if>
             <if test="readCycle != null">#{readCycle,jdbcType=SMALLINT},</if>
-            <if test="readbookType != null">#{readbookType,jdbcType=SMALLINT},</if>
+            <if test="readBookType != null">#{readBookType,jdbcType=SMALLINT},</if>
             <if test="gis != null and gis != ''">#{gis,jdbcType=VARCHAR},</if>
             <if test="geomGis != null">#{geomGis,jdbcType=OTHER},</if>
         </trim>
@@ -62,9 +62,9 @@
             <if test="statusName != null and statusName != ''">status_name = excluded.status_name,</if>
             <if test="readCycleName != null and readCycleName != ''">read_cycle_name = excluded.read_cycle_name,</if>
             <if test="readerName != null and readerName != ''">reader_name = excluded.reader_name,</if>
-            <if test="readbookName != null and readbookName != ''">readbook_name = excluded.readbook_name,</if>
+            <if test="readBookName != null and readBookName != ''">readbook_name = excluded.readbook_name,</if>
             <if test="readCycle != null">read_cycle = excluded.read_cycle,</if>
-            <if test="readbookType != null">readbook_type = excluded.readbook_type,</if>
+            <if test="readBookType != null">readbook_type = excluded.readbook_type,</if>
             <if test="gis != null and gis != ''">gis = excluded.gis,</if>
             <if test="geomGis != null">geom_gis = excluded.geom_gis,</if>
         </trim>

+ 13 - 9
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/controller/CustomerController.java

@@ -4,15 +4,16 @@ import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.customgateway.core.constants.*;
 import com.shkpr.service.customgateway.core.domain.ResultResponse;
-import com.shkpr.service.customgateway.core.exception.SelfException;
-import com.shkpr.service.customgateway.core.utils.CommTool;
-import com.shkpr.service.customgateway.core.utils.ExcelUtil;
 import com.shkpr.service.customgateway.core.domain.po.CustomerInfo;
 import com.shkpr.service.customgateway.core.domain.po.CustomerMeterRead;
+import com.shkpr.service.customgateway.core.exception.SelfException;
 import com.shkpr.service.customgateway.core.service.CustomerInfoService;
 import com.shkpr.service.customgateway.core.service.CustomerMeterReadService;
+import com.shkpr.service.customgateway.core.utils.CommTool;
+import com.shkpr.service.customgateway.core.utils.ExcelUtil;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.MapUtils;
+import org.apache.commons.lang3.ArrayUtils;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
@@ -71,6 +72,7 @@ public class CustomerController {
     public ResultResponse<String> customerInfoImport(HttpServletRequest request
             , @RequestHeader(value = Api.HEADER_CLIENT_TYPE, required = false) String strClientType
             , @RequestHeader(value = Api.HEADER_USER_AGENT, required = false) String strUserAgent
+            , @RequestParam(value = "meterType", required = false) Short meterType
             , @RequestParam(value = "file", required = false) MultipartFile file) throws SelfException {
         //初始化序列
         requestSeq.putIfAbsent(Api.URI_XXX_CUSTOMER_INFO_IMPORT, new AtomicInteger(0));
@@ -78,11 +80,12 @@ public class CustomerController {
         final String requestURI = request.getRequestURI();
         final String strPlatform = CommTool.getPlatformByAgent(strClientType, strUserAgent);
         //参数校验
-        if (file == null || file.isEmpty()) throw new SelfException(ResponseCode.STATUS_ERROR_JSON_FORMAT.getCode() + ""
-                , String.format(Api.EXCEPTION_FORMAT
-                , strPlatform
-                , requestURI
-                , ResponseCode.STATUS_ERROR_JSON_FORMAT.getMessage()));
+        if (meterType == null || file == null || file.isEmpty() || !ArrayUtils.contains(CustomerMeterType.codes(), meterType))
+            throw new SelfException(ResponseCode.STATUS_ERROR_JSON_FORMAT.getCode() + ""
+                    , String.format(Api.EXCEPTION_FORMAT
+                    , strPlatform
+                    , requestURI
+                    , ResponseCode.STATUS_ERROR_JSON_FORMAT.getMessage()));
 
         //begin
         long begin = System.currentTimeMillis();
@@ -106,8 +109,9 @@ public class CustomerController {
         if (MapUtils.isNotEmpty(excel)) for (Map.Entry<String, List<CustomerInfo>> dataEntry : excel.entrySet()) {
             //获取数据
             List<CustomerInfo> dates = dataEntry.getValue().stream()
-                    //修改表状态为正常
+                    //修改表类型,表状态为正常
                     .peek(info -> {
+                        info.setMeterType(meterType);
                         info.setStatusCode(CustomerInfoStatus.NORMAL.getCode());
                         info.setStatusName(CustomerInfoStatus.NORMAL.getName());
                     })