Browse Source

在线增员

guozheng 1 month ago
parent
commit
8d165e7bbd

+ 1 - 0
build.gradle

@@ -48,6 +48,7 @@ dependencies {
     implementation('org.springframework.boot:spring-boot-starter-data-redis')
     implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.1'
     implementation "org.apache.poi:poi:4.1.0"
+    implementation "com.belerweb:pinyin4j:2.5.0"
 }
 
 test {

+ 11 - 1
out/production/resources/application.properties

@@ -90,4 +90,14 @@ spring.redis.jedis.pool.max-wait=30000
 spring.redis.jedis.pool.max-active=100
 spring.redis.jedis.pool.max-idle=20
 spring.redis.jedis.pool.min-idle=0
-spring.redis.timeout=3000
+spring.redis.timeout=3000
+
+#open api
+openapi.domain=http://testapi.kunlunhealth.com.cn
+openapi.client_id=finogeeks
+openapi.client_secret=finogeeks_test
+
+#生产
+#openapi.domain=https://api.kunlunhealth.com.cn/
+#openapi.client_id=finogeeks
+#openapi.client_id=9J8u0Hi@WVdFVM3z

File diff suppressed because it is too large
+ 0 - 2
src/json.txt


+ 2 - 2
src/main/java/com/finogeeks/swan/hxaccountsync/client/OcrClient.java

@@ -48,7 +48,7 @@ public class OcrClient {
     private String ocrAppSecret;
     @Value("${net_disk_url}")
     private String net_disk;
-    @Value("${check_phoone_disk}")
+    @Value("${check_phone_url}")
     private String check_phone_url;
 
     private RestTemplate restTemplate;
@@ -113,7 +113,7 @@ public class OcrClient {
         MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
         parts.add("image", image);
         HttpHeaders headers = new HttpHeaders();
-        headers.add("X-Consumer-Custom-ID", operator);
+        headers.add("X-Consumer-Custom-Public", operator);
         headers.setContentType(MediaType.MULTIPART_FORM_DATA);
         HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(parts, headers);
         ResponseEntity<JSONObject> exchange = restTemplate.exchange(net_disk, method, request, JSONObject.class);

+ 191 - 74
src/main/java/com/finogeeks/swan/hxaccountsync/config/InitBankDataConfig.java

@@ -1,74 +1,191 @@
-//package com.finogeeks.swan.hxaccountsync.config;
-//
-//import lombok.extern.slf4j.Slf4j;
-//import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-//import org.apache.poi.ss.usermodel.Workbook;
-//import org.springframework.beans.factory.InitializingBean;
-//import org.springframework.context.annotation.Configuration;
-//import org.springframework.core.io.ClassPathResource;
-//import org.springframework.web.context.ServletContextAware;
-//
-//import javax.servlet.ServletContext;
-//import java.io.IOException;
-//import java.io.InputStream;
-//import java.util.Map;
-//import java.util.concurrent.ConcurrentHashMap;
-//
-///**
-// * @author Guo Zheng
-// * @date 2020/9/7 11:15 上午
-// */
-//@Configuration
-//@Slf4j
-//public class InitBankDataConfig  implements InitializingBean, ServletContextAware {
-//    /**
-//     * 银行词典
-//     */
-//    public static Map<String, String> MONTH_SHOULD_HOURS_MAP = new ConcurrentHashMap<String, String>();
-//
-//    @Override
-//    public void setServletContext(ServletContext servletContext) {
-//        //读取数据文件中的数据 银行数据
-//        ClassPathResource areaResource = new ClassPathResource("static/area.xls");
-//        ClassPathResource bankResource = new ClassPathResource("static/bank.xls");
-//        ClassPathResource cncapCodeResource = new ClassPathResource("static/cncapCode.xls");
-//        Workbook workbook=null;
-//        try {
-//            workbook = new HSSFWorkbook(areaResource.getInputStream());
-//            loadArea(workbook);
-//        } catch (IOException e) {
-//           log.error("区域数据读取失败");
-//        }
-//        try {
-//            workbook = new HSSFWorkbook(bankResource.getInputStream());
-//            loadBank(workbook);
-//        } catch (IOException e) {
-//            log.error("银行数据读取失败");
-//        }
-//        try {
-//            workbook = new HSSFWorkbook(cncapCodeResource.getInputStream());
-//            loadCncapCode(workbook);
-//        } catch (IOException e) {
-//            log.error("支行号读取失败");
-//        }
-//
-//    }
-//
-//    private void loadCncapCode(Workbook workbook) {
-//
-//    }
-//
-//    private void loadBank(Workbook workbook) {
-//
-//    }
-//
-//    private void loadArea(Workbook areaBook) {
-//
-//    }
-//
-//    @Override
-//    public void afterPropertiesSet() throws Exception {
-//
-//    }
-//
-//}
+package com.finogeeks.swan.hxaccountsync.config;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.finogeeks.swan.hxaccountsync.entity.onlineStaff.BankInfo;
+import com.finogeeks.swan.hxaccountsync.entity.onlineStaff.CncapCode;
+import com.finogeeks.swan.hxaccountsync.exception.ServiceException;
+import com.finogeeks.swan.hxaccountsync.util.ChineseCharacterUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.*;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.data.mongodb.core.aggregation.ArrayOperators;
+import org.springframework.http.HttpStatus;
+import org.springframework.util.StringUtils;
+import org.springframework.web.context.ServletContextAware;
+
+import javax.servlet.ServletContext;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author Guo Zheng
+ * @date 2020/9/7 11:15 上午
+ */
+@Configuration
+@Slf4j
+public class InitBankDataConfig  implements InitializingBean, ServletContextAware {
+
+    //联行号词典 key:银行Id ,value :Map<String,List<CncapCode>> key:首字母 value:cncapcode数组
+    public static Map<Integer, Map<String,List<CncapCode>>> lianhanghaoMap = new ConcurrentHashMap();
+
+    public static Map<Integer,String > areaMap =  new ConcurrentHashMap();
+    //银行词典
+    public static Map<String, List<BankInfo>> bankMap = new TreeMap();
+    // 银行 json数组
+    public static JSONArray bankArray =new JSONArray();
+
+    @Override
+    public void setServletContext(ServletContext servletContext) {
+        //读取数据文件中的数据 银行数据
+        ClassPathResource areaResource = new ClassPathResource("static/area.xls");
+        ClassPathResource bankResource = new ClassPathResource("static/bank.xls");
+        ClassPathResource cncapCodeResource = new ClassPathResource("static/cncapCode.xls");
+        System.out.println("读取数据开始");
+        Workbook workbook = null;
+        try {
+            workbook = new HSSFWorkbook(areaResource.getInputStream());
+            loadArea(workbook);
+        } catch (IOException e) {
+            log.error("区域数据读取失败");
+        }
+        try {
+            workbook = new HSSFWorkbook(bankResource.getInputStream());
+            loadBank(workbook);
+        } catch (IOException e) {
+            log.error("银行数据读取失败");
+        }
+        try {
+            workbook = new HSSFWorkbook(cncapCodeResource.getInputStream());
+            loadCncapCode(workbook);
+        } catch (IOException e) {
+            log.error("支行号读取失败");
+        }
+
+    }
+
+    //载入区域信息
+    private void loadArea(Workbook wb) {
+
+        if (wb == null) {
+            throw new ServiceException(HttpStatus.BAD_REQUEST, "", "找不到区域文件");
+        }
+
+        Sheet sheet = wb.getSheetAt(0);
+        for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
+            Row row = sheet.getRow(i);
+            Cell codeCell = row.getCell(2);
+            Cell nameCell = row.getCell(3);
+            if(nameCell==null || codeCell==null){
+                log.info("区域 第"+i+"行数据有问题");
+            }
+            String name = nameCell.getStringCellValue();
+            Integer code = new Double(codeCell.getNumericCellValue()).intValue();
+            areaMap.put(code,name);
+        }
+    }
+
+
+    //载入联行号文件中的数据
+    private void loadCncapCode(Workbook wb) {
+
+        if (wb == null) {
+            throw new ServiceException(HttpStatus.BAD_REQUEST, "", "找不到联行号文件");
+        }
+        Sheet sheet = wb.getSheetAt(0);
+        //遍历 每一行数据 封装成 CncapCode 对象 放入联行号字典
+        for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
+            Row row = sheet.getRow(i);
+            Cell codeCell = row.getCell(2);
+            Cell nameCell = row.getCell(3);
+            Cell bankIdCell = row.getCell(5);
+            Cell standCell = row.getCell(6);
+            if(codeCell==null || nameCell==null || bankIdCell==null ||standCell==null){
+                log.info("联行号第"+i+"行数据有问题");
+                continue;
+            }
+            Long code = new Double(codeCell.getNumericCellValue()).longValue();
+            String name = nameCell.getStringCellValue();
+            String[] bankNames = StringUtils.split(name, "银行");
+            if(bankNames.length != 2){
+                log.info("丢弃不标准银行名"+name);
+                continue;
+            }
+            name = bankNames[1];
+            //获取首字母作为key
+            String index = ChineseCharacterUtil.getUpperCase(name.substring(0, 1), false);
+
+            Integer bankId = new Double(bankIdCell.getNumericCellValue()).intValue();
+            Integer STANDARDAREAID = new Double(standCell.getNumericCellValue()).intValue();
+            CncapCode cncapCode = new CncapCode(code, name, bankId, STANDARDAREAID);
+            Map<String, List<CncapCode>> indexSubBankMap = lianhanghaoMap.get(bankId);
+
+            if(indexSubBankMap==null){
+                indexSubBankMap=new TreeMap<>();
+                List<CncapCode> cncapCodeList=new ArrayList<>();
+                cncapCodeList.add(cncapCode);
+                indexSubBankMap.put(index,cncapCodeList);
+                lianhanghaoMap.put(bankId,indexSubBankMap);
+            }else {
+                List<CncapCode> cncapCodes = indexSubBankMap.get(index);
+                if(cncapCodes==null){
+                    cncapCodes=new ArrayList<>();
+                    cncapCodes.add(cncapCode);
+                    indexSubBankMap.put(index,cncapCodes);
+                }else{
+                    cncapCodes.add(cncapCode);
+                }
+            }
+        }
+
+    }
+    //载入银行文件的信息
+    private void loadBank(Workbook wb) {
+        if (wb == null) {
+            throw new ServiceException(HttpStatus.BAD_REQUEST, "", "找不到银行文件");
+        }
+        Sheet sheet = wb.getSheetAt(0);
+        for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
+            Row row = sheet.getRow(i);
+            Cell nameCell = row.getCell(3);
+            Cell codeCell = row.getCell(4);
+            if(nameCell==null || codeCell==null){
+                log.info("银行 第"+i+"行数据有问题");
+            }
+            String name = nameCell.getStringCellValue();
+            Integer code = new Double(codeCell.getNumericCellValue()).intValue();
+            //获取首字母 作为key
+            String index= ChineseCharacterUtil.getUpperCase(name.substring(0,1),false);
+            //以首字母作为key,放入同一个首字母开头的银行集合
+            List<BankInfo> bankInfoList = bankMap.get(index);
+            if(bankInfoList == null){
+                bankInfoList = new ArrayList<>();
+                bankInfoList.add(new BankInfo(name,code));
+                bankMap.put(index,bankInfoList);
+            }else {
+                bankInfoList.add(new BankInfo(name,code));
+            }
+        }
+        Set<String> indexSet = bankMap.keySet();
+        for(String index: indexSet){
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("index",index);
+            List<BankInfo> bankInfos = bankMap.get(index);
+            jsonObject.put("banks",bankInfos);
+            bankArray.add(jsonObject);
+        }
+    }
+
+
+    @Override
+    public void afterPropertiesSet() throws Exception {
+
+    }
+
+
+}

+ 2 - 1
src/main/java/com/finogeeks/swan/hxaccountsync/controllers/OnlineStaffController.java

@@ -834,7 +834,8 @@ public class OnlineStaffController {
         //查询当前在线增员信息
         log.info(bankOcrResult.toString());
         if (!StringUtils.equals(bankOcrResult.getResult(), "1001") || StringUtils.isEmpty(bankOcrResult.getBank())
-                ||StringUtils.isEmpty(bankOcrResult.getNumber() ) || StringUtils.equals(bankOcrResult.getBank(),"null")) {
+                ||StringUtils.isEmpty(bankOcrResult.getNumber() ) || StringUtils.equals(bankOcrResult.getBank(),"null")
+                ||!ValidatorUtil.checkBankCard(bankOcrResult.getNumber())) {
             throw new ServiceException(HttpStatus.BAD_REQUEST, "code_error", "证件图像未符合要求");
         }
         //上传图片到服务器

+ 10 - 0
src/main/java/com/finogeeks/swan/hxaccountsync/entity/onlineStaff/Area.java

@@ -0,0 +1,10 @@
+package com.finogeeks.swan.hxaccountsync.entity.onlineStaff;
+
+/**
+ * @author Guo Zheng
+ * @date 2020/9/8 9:46 上午
+ */
+public class Area {
+    private String name;
+    private Integer code;
+}

+ 18 - 0
src/main/java/com/finogeeks/swan/hxaccountsync/entity/onlineStaff/BankInfo.java

@@ -0,0 +1,18 @@
+package com.finogeeks.swan.hxaccountsync.entity.onlineStaff;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.checkerframework.checker.units.qual.A;
+
+/**
+ * @author Guo Zheng
+ * @date 2020/9/8 9:46 上午
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class BankInfo {
+    private String name;
+    private Integer directBankCode;
+}

+ 19 - 0
src/main/java/com/finogeeks/swan/hxaccountsync/entity/onlineStaff/CncapCode.java

@@ -0,0 +1,19 @@
+package com.finogeeks.swan.hxaccountsync.entity.onlineStaff;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author Guo Zheng
+ * @date 2020/9/8 9:46 上午
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class CncapCode {
+    private Long code;
+    private String name;
+    private Integer bankId;
+    private Integer STANDARDAREAID;
+}

+ 3 - 0
src/main/java/com/finogeeks/swan/hxaccountsync/entity/product/OnlineStaff.java

@@ -69,4 +69,7 @@ public class OnlineStaff {
     private String wxname;//微信名称
     private String politicCountenance;
     private String groupId;
+    private String subBank;
+    private String area;
+    private String cncapCode;
 }

+ 132 - 0
src/main/java/com/finogeeks/swan/hxaccountsync/util/ChineseCharacterUtil.java

@@ -0,0 +1,132 @@
+package com.finogeeks.swan.hxaccountsync.util;
+
+/**
+ * @author Guo Zheng
+ * @date 2020/9/8 2:53 下午
+ */
+
+
+import net.sourceforge.pinyin4j.PinyinHelper;
+import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
+import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * 获取首字母工具
+ *
+ * @author
+ * @Date
+ */
+public class ChineseCharacterUtil {
+
+    /**
+     *  获取汉字首字母或全拼大写字母
+     *
+     * @param chinese 汉字
+     * @param isFull  是否全拼 true:表示全拼 false表示:首字母
+     *
+     * @return 全拼或者首字母大写字符窜
+     */
+    public static String getUpperCase(String chinese,boolean isFull){
+        return convertHanzi2Pinyin(chinese,isFull).toUpperCase();
+    }
+
+    /**
+     * 获取汉字首字母或全拼小写字母
+     *
+     * @param chinese 汉字
+     * @param isFull 是否全拼 true:表示全拼 false表示:首字母
+     *
+     * @return 全拼或者首字母小写字符窜
+     */
+    public static  String getLowerCase(String chinese,boolean isFull){
+        return convertHanzi2Pinyin(chinese,isFull).toLowerCase();
+    }
+
+    /**
+     * 将汉字转成拼音
+     * <P>
+     * 取首字母或全拼
+     *
+     * @param hanzi 汉字字符串
+     * @param isFull 是否全拼 true:表示全拼 false表示:首字母
+     *
+     * @return 拼音
+     */
+    private static String convertHanzi2Pinyin(String hanzi,boolean isFull){
+        /***
+         * ^[\u2E80-\u9FFF]+$ 匹配所有东亚区的语言
+         * ^[\u4E00-\u9FFF]+$ 匹配简体和繁体
+         * ^[\u4E00-\u9FA5]+$ 匹配简体
+         */
+        String regExp="^[\u4E00-\u9FFF]+$";
+        StringBuffer sb=new StringBuffer();
+        if(hanzi==null||"".equals(hanzi.trim())){
+            return "";
+        }
+        String pinyin="";
+        for(int i=0;i<hanzi.length();i++){
+            char unit=hanzi.charAt(i);
+            //是汉字,则转拼音
+            if(match(String.valueOf(unit),regExp)){
+                pinyin=convertSingleHanzi2Pinyin(unit);
+                if(isFull){
+                    sb.append(pinyin);
+                }
+                else{
+                    sb.append(pinyin.charAt(0));
+                }
+            }else{
+                sb.append(unit);
+            }
+        }
+        return sb.toString();
+    }
+
+    /**
+     * 将单个汉字转成拼音
+     *
+     * @param hanzi 汉字字符
+     *
+     * @return 拼音
+     */
+    private static String convertSingleHanzi2Pinyin(char hanzi){
+        HanyuPinyinOutputFormat outputFormat = new HanyuPinyinOutputFormat();
+        outputFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
+        String[] res;
+        StringBuffer sb=new StringBuffer();
+        try {
+            res = PinyinHelper.toHanyuPinyinStringArray(hanzi,outputFormat);
+            sb.append(res[0]);//对于多音字,只用第一个拼音
+        } catch (Exception e) {
+            e.printStackTrace();
+            return "";
+        }
+        return sb.toString();
+    }
+
+    /***
+     * 匹配
+     * <P>
+     * 根据字符和正则表达式进行匹配
+     *
+     * @param str 源字符串
+     * @param regex 正则表达式
+     *
+     * @return true:匹配成功  false:匹配失败
+     */
+    private static boolean match(String str,String regex){
+        Pattern pattern= Pattern.compile(regex);
+        Matcher matcher=pattern.matcher(str);
+        return matcher.find();
+    }
+
+    /**
+     * 测试方法
+     */
+    public static void main(String[] args) {
+        System.out.println(convertHanzi2Pinyin("弗格森的广东省q",false).toUpperCase());
+    }
+}

+ 48 - 0
src/main/java/com/finogeeks/swan/hxaccountsync/util/ValidatorUtil.java

@@ -103,4 +103,52 @@ public class ValidatorUtil {
             return 0;
         }
     }
+
+       /*
+    校验过程:
+    1、从卡号最后一位数字开始,逆向将奇数位(1、3、5等等)相加。
+    2、从卡号最后一位数字开始,逆向将偶数位数字,先乘以2(如果乘积为两位数,将个位十位数字相加,即将其减去9),再求和。
+    3、将奇数位总和加上偶数位总和,结果应该可以被10整除。
+    */
+    /**
+     * 校验银行卡卡号
+     */
+    public static boolean checkBankCard(String bankCard) {
+        if(bankCard.length() < 15 || bankCard.length() > 19) {
+            return false;
+        }
+        char bit = getBankCardCheckCode(bankCard.substring(0, bankCard.length() - 1));
+        if(bit == 'N'){
+            return false;
+        }
+        return bankCard.charAt(bankCard.length() - 1) == bit;
+    }
+
+    /**
+     * 从不含校验位的银行卡卡号采用 Luhm 校验算法获得校验位
+     * @param nonCheckCodeBankCard
+     * @return
+     */
+    public static char getBankCardCheckCode(String nonCheckCodeBankCard){
+        if(nonCheckCodeBankCard == null || nonCheckCodeBankCard.trim().length() == 0
+                || !nonCheckCodeBankCard.matches("\\d+")) {
+            //如果传的不是数据返回N
+            return 'N';
+        }
+        char[] chs = nonCheckCodeBankCard.trim().toCharArray();
+        int luhmSum = 0;
+        for(int i = chs.length - 1, j = 0; i >= 0; i--, j++) {
+            int k = chs[i] - '0';
+            if(j % 2 == 0) {
+                k *= 2;
+                k = k / 10 + k % 10;
+            }
+            luhmSum += k;
+        }
+        return (luhmSum % 10 == 0) ? '0' : (char)((10 - luhmSum % 10) + '0');
+    }
+
+    public static void main(String[] args) {
+        System.out.println(checkBankCard("6228480116682997371"));
+    }
 }

BIN
src/main/resources/static/cncapCode.xls


Some files were not shown because too many files changed in this diff