魏熙美 6 jaren geleden
bovenliggende
commit
48d620577f
18 gewijzigde bestanden met toevoegingen van 924 en 1 verwijderingen
  1. 19
    0
      CODE/foreign-service/pom.xml
  2. 16
    0
      CODE/foreign-service/src/main/java/com/community/huiju/foreign/ForeignServiceApplication.java
  3. 91
    0
      CODE/foreign-service/src/main/java/com/community/huiju/foreign/aop/LogAOP.java
  4. 4
    0
      CODE/foreign-service/src/main/java/com/community/huiju/foreign/common/base/BaseController.java
  5. 26
    0
      CODE/foreign-service/src/main/java/com/community/huiju/foreign/common/perproties/DaSuProperties.java
  6. 44
    0
      CODE/foreign-service/src/main/java/com/community/huiju/foreign/common/perproties/FuShiProperties.java
  7. 40
    0
      CODE/foreign-service/src/main/java/com/community/huiju/foreign/config/FuShiConfig.java
  8. 116
    0
      CODE/foreign-service/src/main/java/com/community/huiju/foreign/controller/FSController.java
  9. 58
    0
      CODE/foreign-service/src/main/java/com/community/huiju/foreign/jwt/JwtUtil.java
  10. 32
    0
      CODE/foreign-service/src/main/java/com/community/huiju/foreign/log/LogAnnotation.java
  11. 43
    0
      CODE/foreign-service/src/main/java/com/community/huiju/foreign/log/LogEnums.java
  12. 101
    0
      CODE/foreign-service/src/main/java/com/community/huiju/foreign/log/LogFactory.java
  13. 46
    0
      CODE/foreign-service/src/main/java/com/community/huiju/foreign/log/LogFileManager.java
  14. 77
    0
      CODE/foreign-service/src/main/java/com/community/huiju/foreign/service/IFuShiService.java
  15. 167
    0
      CODE/foreign-service/src/main/java/com/community/huiju/foreign/service/impl/FuShiServiceImpl.java
  16. 4
    1
      CODE/foreign-service/src/main/resources/application-dev.yml
  17. 7
    0
      CODE/foreign-service/src/main/resources/application-prod.yml
  18. 33
    0
      CODE/foreign-service/src/main/resources/application.yml

+ 19
- 0
CODE/foreign-service/pom.xml Bestand weergeven

@@ -119,12 +119,31 @@
119 119
             <version>1.4</version>
120 120
         </dependency>
121 121
 
122
+        <!-- JWT -->
123
+        <dependency>
124
+            <groupId>org.bitbucket.b_c</groupId>
125
+            <artifactId>jose4j</artifactId>
126
+            <version>0.6.5</version>
127
+        </dependency>
128
+
129
+        <dependency>
130
+            <groupId>com.community</groupId>
131
+            <artifactId>community-common</artifactId>
132
+            <version>0.0.1</version>
133
+        </dependency>
122 134
 
123 135
         <dependency>
124 136
             <groupId>org.springframework.boot</groupId>
125 137
             <artifactId>spring-boot-starter-test</artifactId>
126 138
             <scope>test</scope>
127 139
         </dependency>
140
+
141
+        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-aop -->
142
+        <dependency>
143
+            <groupId>org.springframework.boot</groupId>
144
+            <artifactId>spring-boot-starter-aop</artifactId>
145
+            <version>2.0.4.RELEASE</version>
146
+        </dependency>
128 147
     </dependencies>
129 148
 
130 149
     <build>

+ 16
- 0
CODE/foreign-service/src/main/java/com/community/huiju/foreign/ForeignServiceApplication.java Bestand weergeven

@@ -1,7 +1,12 @@
1 1
 package com.community.huiju.foreign;
2 2
 
3
+import com.alibaba.fastjson.serializer.SerializerFeature;
4
+import com.alibaba.fastjson.support.config.FastJsonConfig;
5
+import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
3 6
 import org.springframework.boot.SpringApplication;
4 7
 import org.springframework.boot.autoconfigure.SpringBootApplication;
8
+import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
9
+import org.springframework.context.annotation.Bean;
5 10
 
6 11
 @SpringBootApplication
7 12
 public class ForeignServiceApplication {
@@ -10,4 +15,15 @@ public class ForeignServiceApplication {
10 15
         SpringApplication.run(ForeignServiceApplication.class, args);
11 16
     }
12 17
 
18
+    @Bean
19
+    public HttpMessageConverters fastJsonConfigure(){
20
+        FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
21
+        FastJsonConfig fastJsonConfig = new FastJsonConfig();
22
+        fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat,SerializerFeature.DisableCircularReferenceDetect,SerializerFeature.WriteMapNullValue, SerializerFeature.BrowserCompatible);
23
+        //日期格式化
24
+        //fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
25
+        converter.setFastJsonConfig(fastJsonConfig);
26
+        return new HttpMessageConverters(converter);
27
+    }
28
+
13 29
 }

+ 91
- 0
CODE/foreign-service/src/main/java/com/community/huiju/foreign/aop/LogAOP.java Bestand weergeven

@@ -0,0 +1,91 @@
1
+package com.community.huiju.foreign.aop;
2
+
3
+import com.alibaba.fastjson.JSONObject;
4
+import com.community.commom.fushi.error.FuShiException;
5
+import com.community.huiju.foreign.log.LogAnnotation;
6
+import com.community.huiju.foreign.log.LogEnums;
7
+import com.community.huiju.foreign.log.LogFactory;
8
+import com.community.huiju.foreign.log.LogFileManager;
9
+import lombok.extern.slf4j.Slf4j;
10
+import org.aspectj.lang.JoinPoint;
11
+import org.aspectj.lang.ProceedingJoinPoint;
12
+import org.aspectj.lang.Signature;
13
+import org.aspectj.lang.annotation.AfterThrowing;
14
+import org.aspectj.lang.annotation.Around;
15
+import org.aspectj.lang.annotation.Aspect;
16
+import org.aspectj.lang.annotation.Pointcut;
17
+import org.aspectj.lang.reflect.MethodSignature;
18
+import org.springframework.stereotype.Component;
19
+
20
+import java.lang.reflect.Method;
21
+
22
+@Aspect
23
+@Component
24
+@Slf4j
25
+public class LogAOP {
26
+
27
+    @Pointcut("@annotation(com.community.huiju.log.LogAnnotation)")
28
+    public void pointLog() {
29
+
30
+    }
31
+
32
+    @Around("pointLog()")
33
+    public Object logAround(ProceedingJoinPoint point) throws Throwable {
34
+
35
+        // 获取切面的点的实例
36
+        Object target = point.getTarget();
37
+        // 获取反射对象
38
+        Class<?> zClass = target.getClass();
39
+        // 获取切面点
40
+        Signature signature = point.getSignature();
41
+
42
+        // 判断日志注解是否用在方法上
43
+        if (!(signature instanceof MethodSignature)) {
44
+            throw new RuntimeException("该注解只允许在方法上使用!");
45
+        }
46
+
47
+        // 方法名称
48
+        String methodName = signature.getName();
49
+        // 获取方法参数类型
50
+        Class<?>[] parameterTypes = ((MethodSignature) signature).getMethod().getParameterTypes();
51
+
52
+        // 通过方法名称和方法参数类型
53
+        // 获取当前正在执行切面的方法
54
+        Method method = zClass.getMethod(methodName, parameterTypes);
55
+
56
+        // 所有方法输入参数
57
+        Object[] args = point.getArgs();
58
+        // 执行方法的返回值
59
+        Object result = null;
60
+        if (null != method && method.isAnnotationPresent(LogAnnotation.class)) {
61
+
62
+            // 获取这个注解
63
+            LogAnnotation logAnnotation = method.getAnnotation(LogAnnotation.class);
64
+            // 大苏操作
65
+            if (logAnnotation.record() && logAnnotation.value() == LogEnums.DA_SU) {
66
+                String alias = "".equals(logAnnotation.alias()) ? "未设置别名" : logAnnotation.alias();
67
+                    log.info("AOP拦截----大苏操作----执行方法:{},方法别名:{}, 请求参数:{}", methodName, alias,args);
68
+                    // 方法返回值
69
+                    result = point.proceed();
70
+                    log.info("AOP拦截----大苏操作----执行方法:{},方法别名:{},请求参数:{},返回结果:{}", methodName, alias,args, result);
71
+
72
+                    String strPararmeter = String.format( "AOP拦截----大苏操作----执行方法:%s,方法别名:%s,请求参数:%s", methodName, alias, JSONObject.toJSONString(args));
73
+                    String strReturn = String.format("AOP拦截----大苏操作----执行方法:%s,方法别名:%s, 请求参数:%s,返回结果:%s", methodName, alias , JSONObject.toJSONString(args), JSONObject.toJSONString(result));
74
+
75
+                    LogFileManager.getInstance().executeLog(LogFactory.parametersAndReturn(strPararmeter, strReturn));
76
+
77
+            }
78
+
79
+        }
80
+
81
+        return result;
82
+    }
83
+
84
+    @AfterThrowing(value = "pointLog()", throwing = "cause")
85
+    public void doException(JoinPoint joinPoint, Throwable cause) {
86
+        if (null != cause) {
87
+            throw new FuShiException(cause.getMessage());
88
+        }
89
+    }
90
+
91
+}

+ 4
- 0
CODE/foreign-service/src/main/java/com/community/huiju/foreign/common/base/BaseController.java Bestand weergeven

@@ -0,0 +1,4 @@
1
+package com.community.huiju.foreign.common.base;
2
+
3
+public class BaseController {
4
+}

+ 26
- 0
CODE/foreign-service/src/main/java/com/community/huiju/foreign/common/perproties/DaSuProperties.java Bestand weergeven

@@ -0,0 +1,26 @@
1
+package com.community.huiju.foreign.common.perproties;
2
+
3
+import lombok.AllArgsConstructor;
4
+import lombok.Data;
5
+import lombok.NoArgsConstructor;
6
+import org.springframework.boot.context.properties.ConfigurationProperties;
7
+import org.springframework.stereotype.Component;
8
+
9
+/**
10
+ * 提供给 大苏 的 appid 和 appsecret
11
+ * @author weiximei
12
+ */
13
+@Component
14
+@ConfigurationProperties(prefix = "da-su")
15
+@Data
16
+@AllArgsConstructor
17
+@NoArgsConstructor
18
+public class DaSuProperties {
19
+
20
+    private String appid;
21
+
22
+    private String appSecret;
23
+
24
+    private String communityId;
25
+
26
+}

+ 44
- 0
CODE/foreign-service/src/main/java/com/community/huiju/foreign/common/perproties/FuShiProperties.java Bestand weergeven

@@ -0,0 +1,44 @@
1
+package com.community.huiju.foreign.common.perproties;
2
+
3
+import lombok.AllArgsConstructor;
4
+import lombok.Data;
5
+import lombok.NoArgsConstructor;
6
+import org.springframework.boot.context.properties.ConfigurationProperties;
7
+import org.springframework.stereotype.Component;
8
+
9
+/**
10
+ * 富士配置类
11
+ * @author weiximei
12
+ */
13
+@AllArgsConstructor
14
+@NoArgsConstructor
15
+@Data
16
+@Component
17
+@ConfigurationProperties(prefix = "fu-shi")
18
+public class FuShiProperties {
19
+
20
+    /**
21
+     * 富士云 请求地址
22
+     */
23
+    private String url;
24
+
25
+    /**
26
+     * 富士云 appid
27
+     */
28
+    private String appid;
29
+
30
+    /**
31
+     * 富士云 appSecret
32
+     */
33
+    private String appSecret;
34
+
35
+    /**
36
+     * 富士云 私钥 privateKey
37
+     */
38
+    private String privateKey;
39
+
40
+    /**
41
+     * 停车场编码
42
+     */
43
+    private String parkingCode;
44
+}

+ 40
- 0
CODE/foreign-service/src/main/java/com/community/huiju/foreign/config/FuShiConfig.java Bestand weergeven

@@ -0,0 +1,40 @@
1
+package com.community.huiju.foreign.config;
2
+
3
+import com.community.commom.fushi.FuShiHttpClient;
4
+import com.community.commom.fushi.FuShiRequestAPI;
5
+import com.community.huiju.foreign.common.perproties.FuShiProperties;
6
+import org.springframework.beans.factory.annotation.Autowired;
7
+import org.springframework.context.annotation.Bean;
8
+import org.springframework.context.annotation.Configuration;
9
+
10
+/**
11
+ * 富士配置类
12
+ * @author weiximei
13
+ */
14
+@Configuration
15
+public class FuShiConfig {
16
+
17
+    @Autowired
18
+    private FuShiProperties fuShiProperties;
19
+
20
+
21
+    /**
22
+     * 初始化富士HTTP客户端
23
+     * @return FuShiHttpClient
24
+     */
25
+    @Bean
26
+    public FuShiHttpClient fuShiHttpClient() {
27
+        return new FuShiHttpClient(fuShiProperties.getUrl(), fuShiProperties.getAppid(), fuShiProperties.getAppSecret(), fuShiProperties.getPrivateKey());
28
+    }
29
+
30
+    /**
31
+     * 初始化富士请求 API
32
+     * @param fuShiHttpClient
33
+     * @return
34
+     */
35
+    @Bean
36
+    public FuShiRequestAPI fuShiRequestAPI(FuShiHttpClient fuShiHttpClient) {
37
+        return new FuShiRequestAPI(fuShiHttpClient);
38
+    }
39
+
40
+}

+ 116
- 0
CODE/foreign-service/src/main/java/com/community/huiju/foreign/controller/FSController.java Bestand weergeven

@@ -0,0 +1,116 @@
1
+package com.community.huiju.foreign.controller;
2
+
3
+import com.alibaba.fastjson.JSONObject;
4
+import com.community.commom.mode.ResponseBean;
5
+import com.community.huiju.foreign.common.base.BaseController;
6
+import com.community.huiju.foreign.service.IFuShiService;
7
+import io.swagger.annotations.Api;
8
+import io.swagger.annotations.ApiImplicitParam;
9
+import io.swagger.annotations.ApiImplicitParams;
10
+import io.swagger.annotations.ApiOperation;
11
+import org.springframework.beans.factory.annotation.Autowired;
12
+import org.springframework.web.bind.annotation.*;
13
+
14
+@RestController
15
+@RequestMapping("/")
16
+@Api(value = "车辆操作API", description = "车辆操作API")
17
+public class FSController extends BaseController {
18
+
19
+    @Autowired
20
+    private IFuShiService iFuShiService;
21
+
22
+    @RequestMapping(value = "/car/getParkInfoByCarNo/{carNo}", method = RequestMethod.GET)
23
+    @ApiOperation(value = "获取停车信息(通过车牌号)", notes = "获取停车信息(通过车牌号)")
24
+    @ApiImplicitParams({
25
+            @ApiImplicitParam(dataTypeClass = String.class, paramType = "path", name = "carNo", value = "车牌号")
26
+    })
27
+    public ResponseBean getParkInfoByCarNo(@PathVariable("carNo") String carNo) {
28
+        ResponseBean responseBean = new ResponseBean();
29
+        responseBean = iFuShiService.getParkInfoByCarNo(carNo);
30
+        return responseBean;
31
+    }
32
+
33
+    @RequestMapping(value = "/car/parkGetMonthCardInfoByCarNo/{carNo}", method = RequestMethod.GET)
34
+    @ApiOperation(value = "获取月租车信息(通过车牌号)", notes = "获取月租车信息(通过车牌号)")
35
+    @ApiImplicitParams({
36
+            @ApiImplicitParam(dataTypeClass = String.class, paramType = "path", name = "carNo", value = "车牌号")
37
+    })
38
+    public ResponseBean parkGetMonthCardInfoByCarNo(@PathVariable("carNo") String carNo) {
39
+        ResponseBean responseBean = new ResponseBean();
40
+        responseBean = iFuShiService.parkGetMonthCardInfoByCarNo(carNo);
41
+        return responseBean;
42
+    }
43
+
44
+    @RequestMapping(value = "/car/parkGetTempCarPaymentInfoByCarNo/{carNo}", method = RequestMethod.GET)
45
+    @ApiOperation(value = "获取临时车信息(通过车牌号)", notes = "获取临时车信息(通过车牌号)")
46
+    @ApiImplicitParams({
47
+            @ApiImplicitParam(dataTypeClass = String.class, paramType = "path", name = "carNo", value = "车牌号")
48
+    })
49
+    public ResponseBean parkGetTempCarPaymentInfoByCarNo(@PathVariable("carNo") String carNo) {
50
+        ResponseBean responseBean = new ResponseBean();
51
+        responseBean = iFuShiService.parkGetTempCarPaymentInfoByCarNo(carNo);
52
+        return responseBean;
53
+    }
54
+
55
+    @RequestMapping(value = "/car/apiThirdPartyMonthCardPay", method = RequestMethod.POST)
56
+    @ApiOperation(value = "月卡续费", notes = "月卡续费")
57
+    @ApiImplicitParams({
58
+            @ApiImplicitParam(dataTypeClass = String.class, paramType = "body", name = "parameter", value = "Phone手机号;RenewDayType续费日期类型( 3:年 2:月 1:日, 选入对应的数字);" +
59
+                    "RenewDay续费日期数目;" +
60
+                    "PayStyle交易方式(中文描述),例如:微信、 支付宝、 银联;" +
61
+                    "CarNo车牌号;" +
62
+                    "CardNo停车卡号;" +
63
+                    "RechargeAmt充值续费金额;")
64
+    })
65
+    public ResponseBean apiThirdPartyMonthCardPay(@RequestBody String parameter) {
66
+        ResponseBean responseBean = new ResponseBean();
67
+        JSONObject jsonObject = JSONObject.parseObject(parameter);
68
+        responseBean = iFuShiService.apiThirdPartyMonthCardPay(jsonObject.getString("Phone"),
69
+                jsonObject.getString("RenewDayType"),
70
+                jsonObject.getString("RenewDay"),
71
+                jsonObject.getString("PayStyle"),
72
+                jsonObject.getString("CarNo"),
73
+                jsonObject.getString("CardNo"),
74
+                jsonObject.getString("RechargeAmt"));
75
+        return responseBean;
76
+    }
77
+
78
+    @RequestMapping(value = "/car/apiThirdPartyTemporaryCardPay", method = RequestMethod.POST)
79
+    @ApiOperation(value = "第三方临时卡上发缴费", notes = "第三方临时卡上发缴费")
80
+    @ApiImplicitParams({
81
+            @ApiImplicitParam(dataTypeClass = String.class, paramType = "body", name = "parameter", value = "Amount应缴金额(单位元);" +
82
+                    "ActualAmount实缴金额(单位元);" +
83
+                    "DeductionAmount抵扣金额(单位元);" +
84
+                    "Reason抵扣原因;" +
85
+                    "PayStyle交易方式(汉字描述),例如:微信、支付宝、银联;" +
86
+                    "CarNo车牌号;" +
87
+                    "CardNo停车卡号;" +
88
+                    "CouponList使用的优惠券列表")
89
+    })
90
+    public ResponseBean apiThirdPartyTemporaryCardPay(@RequestBody String parameter) {
91
+        ResponseBean responseBean = new ResponseBean();
92
+        JSONObject jsonObject = JSONObject.parseObject(parameter);
93
+        responseBean = iFuShiService.apiThirdPartyTemporaryCardPay(jsonObject.getString("Amount"),
94
+                jsonObject.getString("ActualAmount"),
95
+                jsonObject.getString("DeductionAmount"),
96
+                jsonObject.getString("Reason"),
97
+                jsonObject.getString("PayStyle"),
98
+                jsonObject.getString("CarNo"),
99
+                jsonObject.getString("CardNo"),
100
+                jsonObject.getString("CouponList"));
101
+        return responseBean;
102
+    }
103
+
104
+
105
+    @RequestMapping(value = "/car/apiGetOfflineFee/{carNoOrCardNo}", method = RequestMethod.GET)
106
+    @ApiOperation(value = "获取线下算费结果", notes = "获取线下算费结果")
107
+    @ApiImplicitParams({
108
+        @ApiImplicitParam(paramType = "path", dataTypeClass = String.class, name = "carNoOrCardNo" , value = "车牌号码或卡号")
109
+    })
110
+    public ResponseBean apiGetOfflineFee(@PathVariable("carNoOrCardNo") String carNoOrCardNo) {
111
+        ResponseBean responseBean = new ResponseBean();
112
+        responseBean = iFuShiService.apiGetOfflineFee(carNoOrCardNo);
113
+        return responseBean;
114
+    }
115
+
116
+}

+ 58
- 0
CODE/foreign-service/src/main/java/com/community/huiju/foreign/jwt/JwtUtil.java Bestand weergeven

@@ -0,0 +1,58 @@
1
+package com.community.huiju.foreign.jwt;
2
+
3
+
4
+import lombok.extern.slf4j.Slf4j;
5
+import org.jose4j.jwa.AlgorithmConstraints;
6
+import org.jose4j.jwe.ContentEncryptionAlgorithmIdentifiers;
7
+import org.jose4j.jwe.JsonWebEncryption;
8
+import org.jose4j.jwe.KeyManagementAlgorithmIdentifiers;
9
+import org.jose4j.keys.AesKey;
10
+import org.jose4j.lang.ByteUtil;
11
+import org.jose4j.lang.JoseException;
12
+
13
+import javax.crypto.SecretKey;
14
+import java.security.Key;
15
+import java.util.Date;
16
+import java.util.HashMap;
17
+import java.util.Map;
18
+
19
+@Slf4j
20
+public class JwtUtil {
21
+
22
+    public static String sigin() {
23
+        Key key = new AesKey(ByteUtil.randomBytes(16));
24
+        JsonWebEncryption jwe = new JsonWebEncryption();
25
+        jwe.setPayload("Hello World!");
26
+        jwe.setAlgorithmHeaderValue(KeyManagementAlgorithmIdentifiers.A128KW);
27
+        jwe.setEncryptionMethodHeaderParameter(ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256);
28
+        jwe.setKey(key);
29
+        String sigin = null;
30
+        try {
31
+            sigin = jwe.getCompactSerialization();
32
+        } catch (JoseException e) {
33
+            e.printStackTrace();
34
+        }
35
+
36
+        log.info("创建签名: " + sigin);
37
+
38
+        jwe = new JsonWebEncryption();
39
+        jwe.setAlgorithmConstraints(new AlgorithmConstraints(AlgorithmConstraints.ConstraintType.WHITELIST,
40
+                KeyManagementAlgorithmIdentifiers.A128KW));
41
+        jwe.setContentEncryptionAlgorithmConstraints(new AlgorithmConstraints(AlgorithmConstraints.ConstraintType.WHITELIST,
42
+                ContentEncryptionAlgorithmIdentifiers.AES_128_CBC_HMAC_SHA_256));
43
+        jwe.setKey(key);
44
+        try {
45
+            jwe.setCompactSerialization(sigin);
46
+            log.info("解密:: " + jwe.getPayload());
47
+        } catch (JoseException e) {
48
+            e.printStackTrace();
49
+        }
50
+
51
+        return sigin;
52
+    }
53
+
54
+
55
+    public static void main(String[] args) {
56
+        sigin();
57
+    }
58
+}

+ 32
- 0
CODE/foreign-service/src/main/java/com/community/huiju/foreign/log/LogAnnotation.java Bestand weergeven

@@ -0,0 +1,32 @@
1
+package com.community.huiju.foreign.log;
2
+
3
+import java.lang.annotation.*;
4
+
5
+/**
6
+ * 日志注解
7
+ * @author weiximei
8
+ */
9
+@Retention(RetentionPolicy.RUNTIME) // 在运行时使用
10
+@Target({ ElementType.METHOD }) // 在方法上使用
11
+@Documented
12
+public @interface LogAnnotation {
13
+
14
+    /**
15
+     * 日志类型
16
+     * @return
17
+     */
18
+    LogEnums value() default LogEnums.NOT;
19
+
20
+    /**
21
+     * 是否记录
22
+     * @return
23
+     */
24
+    boolean record() default true;
25
+
26
+    /**
27
+     * 别名, 作为注释用
28
+     * @return
29
+     */
30
+    String alias() default "";
31
+
32
+}

+ 43
- 0
CODE/foreign-service/src/main/java/com/community/huiju/foreign/log/LogEnums.java Bestand weergeven

@@ -0,0 +1,43 @@
1
+package com.community.huiju.foreign.log;
2
+
3
+/**
4
+ * 日志类型
5
+ *
6
+ * @author weiximei
7
+ */
8
+public enum LogEnums {
9
+
10
+    NOT(8000, "无类型"),
11
+
12
+    DA_SU(8001, "大苏")
13
+
14
+    ;
15
+
16
+    private Integer code;
17
+
18
+    private String value;
19
+
20
+
21
+    LogEnums(Integer code, String value) {
22
+        this.code = code;
23
+        this.value = value;
24
+    }
25
+
26
+    public Integer getCode() {
27
+        return code;
28
+    }
29
+
30
+    public void setCode(Integer code) {
31
+        this.code = code;
32
+    }
33
+
34
+    public String getValue() {
35
+        return value;
36
+    }
37
+
38
+    public void setValue(String value) {
39
+        this.value = value;
40
+    }
41
+
42
+
43
+}

+ 101
- 0
CODE/foreign-service/src/main/java/com/community/huiju/foreign/log/LogFactory.java Bestand weergeven

@@ -0,0 +1,101 @@
1
+package com.community.huiju.foreign.log;
2
+
3
+import java.io.File;
4
+import java.io.RandomAccessFile;
5
+import java.nio.ByteBuffer;
6
+import java.nio.channels.FileChannel;
7
+import java.nio.channels.FileLock;
8
+import java.time.LocalDate;
9
+import java.time.LocalDateTime;
10
+import java.time.format.DateTimeFormatter;
11
+import java.util.TimerTask;
12
+
13
+/**
14
+ * 日志工厂
15
+ * @author weiximei
16
+ */
17
+public class LogFactory {
18
+
19
+    public static File getFile() {
20
+        LocalDate localDate = LocalDate.now();
21
+        String pathMkdir = "";
22
+
23
+        String os = System.getProperty("os.name");
24
+        if(os.toLowerCase().startsWith("win")){
25
+            pathMkdir = "E:" + File.separator + "log" + File.separator + "foreign-log" + File.separator + localDate.getYear() + "-" + localDate.getMonthValue() + "-" + localDate.getDayOfMonth();
26
+        } else {
27
+            pathMkdir = "/home/fxf/smart-community" + File.separator + "log" + File.separator + "foreign-log" + File.separator + localDate.getYear() + "-" + localDate.getMonthValue() + "-" + localDate.getDayOfMonth();
28
+        }
29
+
30
+        File file = new File(pathMkdir);
31
+        if (!file.exists()) {
32
+            file.mkdirs();
33
+        }
34
+        file = new File(pathMkdir + File.separator + "foreign-log.log");
35
+
36
+        return file;
37
+    }
38
+
39
+    /**
40
+     * 记录请求参数和返回值
41
+     * @param parameters
42
+     * @param returnValue
43
+     * @return
44
+     */
45
+    public static TimerTask parametersAndReturn(String parameters, String returnValue){
46
+        return new TimerTask() {
47
+            @Override
48
+            public void run() {
49
+
50
+                RandomAccessFile accessFile = null;
51
+                FileChannel fileChannel = null;
52
+                FileLock fileLock = null;
53
+                try {
54
+                    // 获取这个文件的读和写的权限
55
+                    accessFile = new RandomAccessFile(getFile(), "rw");
56
+                    // 文件通道
57
+                    fileChannel = accessFile.getChannel();
58
+                    fileLock = null;
59
+                    while (true) {
60
+                        try {
61
+                            // 获取锁,如果失败,继续尝试
62
+                            fileLock = fileChannel.tryLock();
63
+                            break;
64
+                        } catch (Exception e) {
65
+                            Thread.sleep(100);
66
+                        }
67
+                    }
68
+
69
+                    // 获取当前这个文件的大小
70
+                    long length = accessFile.length();
71
+                    // 设置写入的指针, 设置到这个文件的末尾
72
+                    accessFile.seek(length);
73
+                    // 开始写入文件
74
+                    LocalDateTime localDateTime = LocalDateTime.now();
75
+                    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
76
+                    String str = dateTimeFormatter.format(localDateTime) + " === " + Thread.currentThread().getName() + "  : " + parameters + "\n";
77
+                    fileChannel.write(ByteBuffer.wrap(str.getBytes()));
78
+                    str = dateTimeFormatter.format(localDateTime) + " === " + Thread.currentThread().getName() + "  : " + returnValue + "\n";
79
+                    fileChannel.write(ByteBuffer.wrap(str.getBytes()));
80
+
81
+                } catch (Exception e) {
82
+                    e.printStackTrace();
83
+                } finally {
84
+                    if (fileLock != null && fileChannel != null && accessFile != null) {
85
+                        // 释放锁
86
+                        try {
87
+                            fileLock.release();
88
+                            fileChannel.close();
89
+                            accessFile.close();
90
+                        } catch (Exception e) {
91
+                            e.printStackTrace();
92
+                        }
93
+                    }
94
+                }
95
+
96
+
97
+            }
98
+        };
99
+    }
100
+
101
+}

+ 46
- 0
CODE/foreign-service/src/main/java/com/community/huiju/foreign/log/LogFileManager.java Bestand weergeven

@@ -0,0 +1,46 @@
1
+package com.community.huiju.foreign.log;
2
+
3
+import java.util.TimerTask;
4
+import java.util.concurrent.ScheduledThreadPoolExecutor;
5
+
6
+/**
7
+ * 日志文件记录
8
+ * @author weiximei
9
+ */
10
+public class LogFileManager {
11
+
12
+    // 记录日志的线程池
13
+    private ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(10);
14
+
15
+    private LogFileManager() {}
16
+
17
+    public static LogFileManager getInstance() {
18
+        return LogSingleton.INSTANCE.getInstance();
19
+    }
20
+
21
+    /**
22
+     * 记录日志
23
+     * @param timerTask 任务
24
+     */
25
+    public void executeLog(TimerTask timerTask){
26
+        // 日志记录
27
+        scheduledThreadPoolExecutor.execute(timerTask);
28
+    }
29
+
30
+    /**
31
+     * 枚举
32
+     */
33
+    private static enum LogSingleton {
34
+        INSTANCE;
35
+
36
+        private LogFileManager logFileManager;
37
+        private LogSingleton() {
38
+            logFileManager = new LogFileManager();
39
+        }
40
+
41
+        public LogFileManager getInstance() {
42
+            return logFileManager;
43
+        }
44
+
45
+    }
46
+}

+ 77
- 0
CODE/foreign-service/src/main/java/com/community/huiju/foreign/service/IFuShiService.java Bestand weergeven

@@ -0,0 +1,77 @@
1
+package com.community.huiju.foreign.service;
2
+
3
+import com.community.commom.mode.ResponseBean;
4
+
5
+/**
6
+ * 富士 业务接口
7
+ */
8
+public interface IFuShiService {
9
+
10
+    /**
11
+     * 获取停车信息(通过车牌号)
12
+     *
13
+     * @param carNo
14
+     * @return
15
+     */
16
+    ResponseBean getParkInfoByCarNo(String carNo);
17
+
18
+    /**
19
+     * 第三方月卡上发续费
20
+     * @param Phone 车主手机号
21
+     * @param RenewDayType 续费日期类型: 3:年; 2:月; 1:日;
22
+     * @param RenewDay 续费日期数目
23
+     * @param PayStyle 交易方式(中文描述),例如:微信、 支付宝、 银联
24
+     * @param CarNo 车牌号
25
+     * @param CardNo 停车卡号
26
+     * @param RechargeAmt 充值续费金额
27
+     * @return
28
+     */
29
+    ResponseBean apiThirdPartyMonthCardPay(String Phone, String RenewDayType, String RenewDay, String PayStyle, String CarNo, String CardNo, String RechargeAmt);
30
+
31
+
32
+    /**
33
+     * 第三方临时卡上发缴费
34
+     * @param Amount 应缴金额(单位元)
35
+     * @param ActualAmount 实缴金额(单位元)
36
+     * @param DeductionAmount 抵扣金额(单位元)
37
+     * @param Reason 抵扣原因
38
+     * @param PayStyle 交易方式(汉字描述),例如:微信、支付宝、银联
39
+     * @param CarNo 车牌号
40
+     * @param CardNo 停车卡号
41
+     * @param CouponList 使用的优惠券列表(JSON字符串)
42
+     *               MerchantName: 商户名称
43
+     *               CouponType: 优惠券优惠类型1全免2减免金额3减免时长4减免百分比
44
+     *               CouponValue: 对应优惠券类型的值 金额/时间/折扣
45
+     *               CouponCode: 优惠券编码
46
+     *               FavorableType: 优惠券类型1 纸质券 2 电子券 3 活动券
47
+     *               UseStatus:标识优惠券是线上或线下使用的状态 1只在线上使用 2只在线下使用 3线上线下都可以使用
48
+     *               IsAuto: 是否自动使用优惠券1是2否
49
+     *               EndTime: 截至时间
50
+     *               CouponDescribe: 优惠券描述
51
+     *               CouponName: 优惠券名称
52
+     *
53
+     * @return
54
+     */
55
+    ResponseBean apiThirdPartyTemporaryCardPay(String Amount, String ActualAmount, String DeductionAmount, String Reason, String PayStyle, String CarNo, String CardNo, String CouponList);
56
+
57
+    /**
58
+     * 获取线下算费结果
59
+     * @param CarNoOrCardNo 车牌号码或卡号
60
+     * @return
61
+     */
62
+    ResponseBean apiGetOfflineFee(String CarNoOrCardNo);
63
+
64
+    /**
65
+     * 获取月租车信息(通过车牌号)
66
+     * @param CarNo
67
+     * @return
68
+     */
69
+    ResponseBean parkGetMonthCardInfoByCarNo(String CarNo);
70
+
71
+    /**
72
+     * 获取临时车信息(通过车牌号)
73
+     * @param CarNo
74
+     * @return
75
+     */
76
+    ResponseBean parkGetTempCarPaymentInfoByCarNo(String CarNo);
77
+}

+ 167
- 0
CODE/foreign-service/src/main/java/com/community/huiju/foreign/service/impl/FuShiServiceImpl.java Bestand weergeven

@@ -0,0 +1,167 @@
1
+package com.community.huiju.foreign.service.impl;
2
+
3
+import com.alibaba.fastjson.JSONObject;
4
+import com.community.commom.fushi.FuShiRequestAPI;
5
+import com.community.commom.mode.ResponseBean;
6
+import com.community.commom.uuid.IdGen;
7
+import com.community.huiju.foreign.common.perproties.FuShiProperties;
8
+import com.community.huiju.foreign.log.LogAnnotation;
9
+import com.community.huiju.foreign.log.LogEnums;
10
+import com.community.huiju.foreign.service.IFuShiService;
11
+import com.google.common.collect.Maps;
12
+import lombok.extern.slf4j.Slf4j;
13
+import org.springframework.beans.factory.annotation.Autowired;
14
+import org.springframework.stereotype.Service;
15
+
16
+import java.time.LocalDateTime;
17
+import java.time.format.DateTimeFormatter;
18
+import java.util.Map;
19
+
20
+/**
21
+ * 富士业务实现
22
+ * @author weiximei
23
+ */
24
+@Slf4j
25
+@Service
26
+public class FuShiServiceImpl implements IFuShiService {
27
+
28
+    @Autowired
29
+    private FuShiRequestAPI fuShiRequestAPI;
30
+
31
+    @Autowired
32
+    private FuShiProperties fuShiProperties;
33
+
34
+    private IdGen idGen = IdGen.get();
35
+
36
+    /**
37
+     * 获取 富士 json 值
38
+     * @param jsonString
39
+     * @return
40
+     */
41
+    private Map<String,Object> getFuShiInfo(String jsonString) {
42
+        JSONObject jsonObject = JSONObject.parseObject(jsonString);
43
+        Map<String, Object> map = Maps.newHashMap();
44
+        Map<String, Object> jsonParam = jsonObject.getJSONObject("JsonParam").getInnerMap();
45
+        // 移除优惠券
46
+        jsonParam.remove("CouponList");
47
+        map.put("JsonParam", jsonParam);
48
+        map.put("Redirect", jsonObject.getString("Redirect"));
49
+        map.put("DataType", jsonObject.getInteger("DataType"));
50
+        return map;
51
+    }
52
+
53
+    @LogAnnotation(value = LogEnums.DA_SU, alias = "获取停车信息(通过车牌号)")
54
+    @Override
55
+    public ResponseBean getParkInfoByCarNo(String carNo) {
56
+        ResponseBean responseBean = new ResponseBean();
57
+        String parkInfo = fuShiRequestAPI.getParkInfoByCarNo(fuShiProperties.getParkingCode(), carNo);
58
+        Map<String, Object> fuShiInfo = getFuShiInfo(parkInfo);
59
+        responseBean.addSuccess(fuShiInfo);
60
+        return responseBean;
61
+    }
62
+
63
+    @LogAnnotation(value = LogEnums.DA_SU, alias = "第三方月卡上发续费")
64
+    @Override
65
+    public ResponseBean apiThirdPartyMonthCardPay(String Phone, String RenewDayType, String RenewDay, String PayStyle, String CarNo, String CardNo, String RechargeAmt) {
66
+        ResponseBean responseBean = new ResponseBean();
67
+        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
68
+        // 交易编码
69
+        String dealNo = idGen.nextId() + "";
70
+        // 第三方交易日期
71
+        String dateTime = dateTimeFormatter.format(LocalDateTime.now());
72
+        // 富士云请求
73
+        String partyMonthCardPay = fuShiRequestAPI.apiThirdPartyMonthCardPay(RenewDayType, RenewDay, dealNo, PayStyle, CarNo, fuShiProperties.getParkingCode(), CardNo, RechargeAmt, dateTime);
74
+        String tradeNo = JSONObject.parseObject(partyMonthCardPay).getString("TradeNo");
75
+        Map<String, Object> map = Maps.newHashMap();
76
+        map.put("TradeNo", tradeNo);
77
+        responseBean.addSuccess(map);
78
+        return responseBean;
79
+    }
80
+
81
+    /**
82
+     * 第三方临时卡上发缴费
83
+     * @param Amount 应缴金额(单位元)
84
+     * @param ActualAmount 实缴金额(单位元)
85
+     * @param DeductionAmount 抵扣金额(单位元)
86
+     * @param Reason 抵扣原因
87
+     * @param PayStyle 交易方式(汉字描述),例如:微信、支付宝、银联
88
+     * @param CarNo 车牌号
89
+     * @param CardNo 停车卡号
90
+     * @param CouponList 使用的优惠券列表(JSON字符串)
91
+     *               MerchantName: 商户名称
92
+     *               CouponType: 优惠券优惠类型1全免2减免金额3减免时长4减免百分比
93
+     *               CouponValue: 对应优惠券类型的值 金额/时间/折扣
94
+     *               CouponCode: 优惠券编码
95
+     *               FavorableType: 优惠券类型1 纸质券 2 电子券 3 活动券
96
+     *               UseStatus:标识优惠券是线上或线下使用的状态 1只在线上使用 2只在线下使用 3线上线下都可以使用
97
+     *               IsAuto: 是否自动使用优惠券1是2否
98
+     *               EndTime: 截至时间
99
+     *               CouponDescribe: 优惠券描述
100
+     *               CouponName: 优惠券名称
101
+     *
102
+     * @return
103
+     */
104
+    @LogAnnotation(value = LogEnums.DA_SU, alias = "第三方临时卡上发缴费")
105
+    @Override
106
+    public ResponseBean apiThirdPartyTemporaryCardPay(String Amount, String ActualAmount, String DeductionAmount, String Reason, String PayStyle, String CarNo, String CardNo, String CouponList) {
107
+        ResponseBean responseBean = new ResponseBean();
108
+        // 交易编号
109
+        String dealNo = idGen.nextId() + "";
110
+        String apiThirdPartyTemporaryCardPay = fuShiRequestAPI.apiThirdPartyTemporaryCardPay(Amount, ActualAmount, DeductionAmount, Reason, dealNo, PayStyle, CarNo, fuShiProperties.getParkingCode(), CardNo, "", CouponList);
111
+        String tradeNo = JSONObject.parseObject(apiThirdPartyTemporaryCardPay).getString("TradeNo");
112
+        Map<String, Object> map = Maps.newHashMap();
113
+        map.put("TradeNo", tradeNo);
114
+        responseBean.addSuccess(map);
115
+        return responseBean;
116
+    }
117
+
118
+    @LogAnnotation(value = LogEnums.DA_SU, alias = "获取线下算费结果")
119
+    @Override
120
+    public ResponseBean apiGetOfflineFee(String CarNoOrCardNo) {
121
+        ResponseBean responseBean = new ResponseBean();
122
+        String apiGetOfflineFee = fuShiRequestAPI.apiGetOfflineFee(fuShiProperties.getParkingCode(), CarNoOrCardNo);
123
+        String result = JSONObject.parseObject(apiGetOfflineFee).getString("Result");
124
+        Map<String, Object> map = Maps.newHashMap();
125
+        map.put("Result", result);
126
+        responseBean.addSuccess(map);
127
+        return responseBean;
128
+    }
129
+
130
+    /**
131
+     * 获取月租车信息(通过车牌号)
132
+     * @param CarNo
133
+     * @return
134
+     */
135
+    @LogAnnotation(value = LogEnums.DA_SU, alias = "获取月租车信息(通过车牌号)")
136
+    @Override
137
+    public ResponseBean parkGetMonthCardInfoByCarNo(String CarNo) {
138
+        ResponseBean responseBean = new ResponseBean();
139
+        String parkGetMonthCardInfoByCarNo = fuShiRequestAPI.parkGetMonthCardInfoByCarNo(fuShiProperties.getParkingCode(), CarNo);
140
+        JSONObject jsonObject = JSONObject.parseObject(parkGetMonthCardInfoByCarNo);
141
+        Map<String, Object> map = Maps.newHashMap();
142
+        Map<String, Object> result = jsonObject.getJSONObject("Result").getInnerMap();
143
+        result.remove("CouponList");
144
+        map.put("Result", result);
145
+        responseBean.addSuccess(map);
146
+        return responseBean;
147
+    }
148
+
149
+    /**
150
+     * 获取临时车信息(通过车牌号)
151
+     * @param CarNo
152
+     * @return
153
+     */
154
+    @LogAnnotation(value = LogEnums.DA_SU, alias = "获取临时车信息(通过车牌号)")
155
+    @Override
156
+    public ResponseBean parkGetTempCarPaymentInfoByCarNo(String CarNo) {
157
+        ResponseBean responseBean = new ResponseBean();
158
+        String parkGetMonthCardInfoByCarNo = fuShiRequestAPI.parkGetTempCarPaymentInfoByCarNo(fuShiProperties.getParkingCode(), CarNo);
159
+        JSONObject jsonObject = JSONObject.parseObject(parkGetMonthCardInfoByCarNo);
160
+        Map<String, Object> map = Maps.newHashMap();
161
+        Map<String, Object> result = jsonObject.getJSONObject("Result").getInnerMap();
162
+        result.remove("CouponList");
163
+        map.put("Result", result);
164
+        responseBean.addSuccess(map);
165
+        return responseBean;
166
+    }
167
+}

+ 4
- 1
CODE/foreign-service/src/main/resources/application-dev.yml Bestand weergeven

@@ -1,4 +1,7 @@
1 1
 spring:
2 2
   datasource:
3 3
     druid:
4
-      driver-class-name: com
4
+      driver-class-name: com.mysql.jdbc.Driver
5
+      username: root
6
+      password: DQ@0lW##kBb2+-jPZC1s$Ma0h5$9W((q
7
+      url: jdbc:mysql://rm-uf6z3z6jq11x653d77o.mysql.rds.aliyuncs.com:3306/smart_community2.0?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true

+ 7
- 0
CODE/foreign-service/src/main/resources/application-prod.yml Bestand weergeven

@@ -0,0 +1,7 @@
1
+spring:
2
+  datasource:
3
+    druid:
4
+      driver-class-name: com.mysql.jdbc.Driver
5
+      username: root
6
+      password: DQ@0lW##kBb2+-jPZC1s$Ma0h5$9W((q
7
+      url: jdbc:mysql://rm-uf6z3z6jq11x653d77o.mysql.rds.aliyuncs.com:3306/smart_community_prod2.0?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true

+ 33
- 0
CODE/foreign-service/src/main/resources/application.yml Bestand weergeven

@@ -13,3 +13,36 @@ spring:
13 13
 mybatis-plus:
14 14
   type-aliases-package: com.community.huiju.foreign.model
15 15
   mapper-locations: classpath:mapper/*.xml
16
+# 打印sql
17
+logging:
18
+  level:
19
+    com.community.huiju.foreign.dao: debug
20
+
21
+# 大苏
22
+da-su:
23
+  appid: dssdw2576sd997
24
+  app-secret: fgexhd855sf4
25
+  community-id: 101
26
+
27
+# 富士E7+云平台
28
+fu-shi:
29
+  url: http://api.mops.fujica.com.cn/v2/Api
30
+  appid: fujica_a354fedcb214c86b
31
+  app-secret: 0a0897e0bf154169833f709d6693fe84
32
+  private-key: MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAL8wJdXId6Pa6l/O
33
+    d6a+vE0z0RgujUTR2KxRZiRhEWpc4JSi1uyQPS2RS+CleByllAXkgPYCxhxelt6Y
34
+    wtFb3nuUVrQboesUrxv7DuGoRnbOeakMC2Cb83AanQlEC/erXspsTx9x9lecygAt
35
+    yOsEPv6nb8VHu8tTEEhFJIyWSTQBAgMBAAECgYA07AH9HGGptKZd4MwUFwYOpMJD
36
+    XFd0blX41QteFJR6ib0Mx8qQbxjQLUEArS0DWP4RZ4AfGQN3xOMkOMrsou6BcVjR
37
+    oVXvlKate4tIRQy3ay77dabM8LQFNg8uuigD7EWeGh9s4V1E5Jfuw8Y8zfmBKBbz
38
+    Id/Mm7bafgbfd4jCtQJBAPn0ik8Iv3pkJ90V60eQG4l6sVGAaskM0GWzyENpecLP
39
+    6UA7oYmAaqIx9vsY0UyiF4XctgxpMvqG6pM/U0y8LacCQQDDz8h7nhUWF0ZUH1IS
40
+    H+Qj3sUWR3hHel/WCjGPPKWO5iQUTfwVY9+L54IDIanAjisc40ueO3zK573zzlBE
41
+    /VYXAkEA61Qmm356+DovpeErILc2ldsj8r3ay+r6kaYQGBfIAXhJ/KWn0pNK0eYE
42
+    yCd3dpTtXKSN6WVqD6DSXUuzm31X5QJAEDMqlP+ZIwC98su8kH9O8qDFkXhMPS2k
43
+    rCKfwwfzcoUbywpApsxifEKlAPlR//pDGtq7MNYfFvJhRsB056BF9QJBAKHlCCnt
44
+    gtzRlhQxwYRg0th4uoJ99BT03+WM94Kepu6zfh3OmKLvPk2gW30TKSeYC5xmursq
45
+    xGP2TC4KxH2tAn0=
46
+  parking-code: 19000100250504 # 停车场编码
47
+
48
+