Browse Source

initial repository

lhm 4 years ago
parent
commit
a3bb876cf3
23 changed files with 1093 additions and 0 deletions
  1. 60 0
      pom.xml
  2. 13 0
      src/main/java/com/ematou/wxbase/WxbaseApplication.java
  3. 43 0
      src/main/java/com/ematou/wxbase/aop/LogAspect.java
  4. 35 0
      src/main/java/com/ematou/wxbase/api/WxApi.java
  5. 64 0
      src/main/java/com/ematou/wxbase/common/utils/CapturePackageClasses.java
  6. 22 0
      src/main/java/com/ematou/wxbase/common/utils/DateUtils.java
  7. 66 0
      src/main/java/com/ematou/wxbase/common/web/R.java
  8. 14 0
      src/main/java/com/ematou/wxbase/common/web/ResponseCodeConstant.java
  9. 36 0
      src/main/java/com/ematou/wxbase/config/AppConfig.java
  10. 45 0
      src/main/java/com/ematou/wxbase/config/WxGeneralConfig.java
  11. 17 0
      src/main/java/com/ematou/wxbase/controller/TokenRecordController.java
  12. 81 0
      src/main/java/com/ematou/wxbase/entity/OperationRecord.java
  13. 131 0
      src/main/java/com/ematou/wxbase/entity/TokenRecord.java
  14. 81 0
      src/main/java/com/ematou/wxbase/interceptor/MybatisInsertInterceptor.java
  15. 79 0
      src/main/java/com/ematou/wxbase/interceptor/MybatisUpdateInterceptor.java
  16. 24 0
      src/main/java/com/ematou/wxbase/mapper/OperationRecordMapper.java
  17. 24 0
      src/main/java/com/ematou/wxbase/mapper/TokenRecordMapper.java
  18. 30 0
      src/main/java/com/ematou/wxbase/service/OperationRecordService.java
  19. 30 0
      src/main/java/com/ematou/wxbase/service/TokenRecordService.java
  20. 16 0
      src/main/resources/application.yml
  21. 70 0
      src/main/resources/mybatis/OperationRecordMapper.xml
  22. 99 0
      src/main/resources/mybatis/TokenRecordMapper.xml
  23. 13 0
      src/test/java/com/ematou/wxbase/WxbaseApplicationTests.java

+ 60 - 0
pom.xml

@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>2.4.5</version>
+        <relativePath/> <!-- lookup parent from repository -->
+    </parent>
+    <groupId>com.ematou</groupId>
+    <artifactId>wxbase</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <name>wxbase</name>
+    <description>Demo project for Spring Boot</description>
+    <properties>
+        <java.version>1.8</java.version>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.mybatis.spring.boot</groupId>
+            <artifactId>mybatis-spring-boot-starter</artifactId>
+            <version>2.1.4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-logging</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-aop</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <version>8.0.11</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 13 - 0
src/main/java/com/ematou/wxbase/WxbaseApplication.java

@@ -0,0 +1,13 @@
+package com.ematou.wxbase;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class WxbaseApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(WxbaseApplication.class, args);
+    }
+
+}

+ 43 - 0
src/main/java/com/ematou/wxbase/aop/LogAspect.java

@@ -0,0 +1,43 @@
+package com.ematou.wxbase.aop;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.Signature;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Pointcut;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author lhm
+ * @version 1.0
+ * 2021-04-30 16:30
+ */
+@Aspect
+@Component
+public class LogAspect {
+
+    private static final Logger logger = LoggerFactory.getLogger(LogAspect.class);
+
+    @Pointcut("execution(* com.ematou.wxbase.service.*Service.*(..))")
+    public void targetMethod() {}
+
+    @Around("targetMethod()")
+    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
+        Signature signature = joinPoint.getSignature();
+        MethodSignature ms = (MethodSignature) signature;
+        String targetMethodName = ms.getMethod().getName();
+
+        ObjectMapper objectMapper = new ObjectMapper();
+
+        logger.info("----------------方法: " + targetMethodName + "的参数为: " + objectMapper.writeValueAsString(joinPoint.getArgs()) + ".----------------");
+        Object proceed = joinPoint.proceed();
+        logger.info("----------------方法: " + targetMethodName + "执行的返回值为: " + proceed + ".----------------");
+        return proceed;
+    }
+
+}

+ 35 - 0
src/main/java/com/ematou/wxbase/api/WxApi.java

@@ -0,0 +1,35 @@
+package com.ematou.wxbase.api;
+
+/**
+ * @author lhm
+ * @version 1.0
+ * 2021-04-30 11:54
+ */
+public enum WxApi {
+
+    GENERAL_TOKEN("https://api.weixin.qq.com/cgi-bin/token?grant_type=%s&appid=%s&secret=%s", "GET");
+
+    private String url;
+    private String method;
+
+    WxApi(String url, String method) {
+        this.url = url;
+        this.method = method;
+    }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+    public String getMethod() {
+        return method;
+    }
+
+    public void setMethod(String method) {
+        this.method = method;
+    }
+}

+ 64 - 0
src/main/java/com/ematou/wxbase/common/utils/CapturePackageClasses.java

@@ -0,0 +1,64 @@
+package com.ematou.wxbase.common.utils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.ResourceLoaderAware;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.ResourceLoader;
+import org.springframework.core.io.support.ResourcePatternResolver;
+import org.springframework.core.io.support.ResourcePatternUtils;
+import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
+import org.springframework.core.type.classreading.MetadataReader;
+import org.springframework.core.type.classreading.MetadataReaderFactory;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author lhm
+ * @version 1.0
+ * 2021-04-30 15:54
+ */
+@Component
+public class CapturePackageClasses implements ResourceLoaderAware {
+
+    private ResourceLoader resourceLoader;
+
+    private static final Logger logger = LoggerFactory.getLogger(CapturePackageClasses.class);
+
+    public List<Class<?>> getClass(String packageName) {
+
+        List<Class<?>> classes = new ArrayList<>();
+
+        packageName = packageName.replace('.' ,'/');
+
+        ResourcePatternResolver resolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
+        MetadataReaderFactory metaReader = new CachingMetadataReaderFactory(resourceLoader);
+        Resource[] resources = new Resource[0];
+        try {
+            resources = resolver.getResources("classpath*:" + packageName + "/**/*.class");
+        } catch (IOException e) {
+            logger.error("包名格式不对!");
+        }
+
+        for (Resource resource : resources) {
+            MetadataReader reader = null;
+            try {
+                reader = metaReader.getMetadataReader(resource);
+            } catch (IOException e) {
+                logger.error(e.getMessage());
+            }
+            assert reader != null : "reader为null!";
+            classes.add(reader.getClass());
+        }
+
+        return classes;
+    }
+
+    @Override
+    public void setResourceLoader(ResourceLoader resourceLoader) {
+        this.resourceLoader = resourceLoader;
+    }
+}

+ 22 - 0
src/main/java/com/ematou/wxbase/common/utils/DateUtils.java

@@ -0,0 +1,22 @@
+package com.ematou.wxbase.common.utils;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * @author lhm
+ * @version 1.0
+ * 2021-04-30 15:23
+ */
+public class DateUtils {
+
+
+    public static String formatDate(Date date){
+
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+        return sdf.format(date);
+
+    }
+
+}

+ 66 - 0
src/main/java/com/ematou/wxbase/common/web/R.java

@@ -0,0 +1,66 @@
+package com.ematou.wxbase.common.web;
+
+/**
+ * @author lhm
+ * @version 1.0
+ * 2021-04-30 14:25
+ */
+public class R<T> {
+
+    private int code;
+
+    private String message;
+
+    private T data;
+
+    public R() {
+    }
+
+    public R(int code, String message, T data) {
+        this.code = code;
+        this.message = message;
+        this.data = data;
+    }
+
+    public static R<?> build(){
+        return new R<>();
+    }
+
+    public R<T> success(T data) {
+        this.setCode(ResponseCodeConstant.code_200);
+        this.setMessage("Success");
+        this.setData(data);
+        return this;
+    }
+
+    public R<?> error(String message) {
+        this.setCode(ResponseCodeConstant.code_100);
+        this.setMessage(message);
+        this.setData(null);
+        return this;
+    }
+
+    public int getCode() {
+        return code;
+    }
+
+    public void setCode(int code) {
+        this.code = code;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
+    public T getData() {
+        return data;
+    }
+
+    public void setData(T data) {
+        this.data = data;
+    }
+}

+ 14 - 0
src/main/java/com/ematou/wxbase/common/web/ResponseCodeConstant.java

@@ -0,0 +1,14 @@
+package com.ematou.wxbase.common.web;
+
+/**
+ * @author lhm
+ * @version 1.0
+ * 2021-04-30 14:39
+ */
+public class ResponseCodeConstant {
+
+    public static final int code_200 = 200;
+
+    public static final int code_100 = 100;
+
+}

+ 36 - 0
src/main/java/com/ematou/wxbase/config/AppConfig.java

@@ -0,0 +1,36 @@
+package com.ematou.wxbase.config;
+
+import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.http.client.SimpleClientHttpRequestFactory;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * @author lhm
+ * @version 1.0
+ * 2021-04-30 14:02
+ */
+@Configuration
+@EnableAspectJAutoProxy
+@MapperScan("com.ematou.wxbase.mapper")
+@ComponentScan("com.ematou.wxbase.*")
+public class AppConfig {
+
+    @Bean
+    public WxGeneralConfig wxGeneralConfig() {
+        return new WxGeneralConfig();
+    }
+
+    @Bean
+    public RestTemplate restTemplate() {
+        // 可发送HTTPS请求的RestTemplate
+        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
+        factory.setReadTimeout(60000);
+        factory.setConnectTimeout(15000);
+        return new RestTemplate(factory);
+    }
+
+}

+ 45 - 0
src/main/java/com/ematou/wxbase/config/WxGeneralConfig.java

@@ -0,0 +1,45 @@
+package com.ematou.wxbase.config;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author lhm
+ * @version 1.0
+ * 2021-04-30 11:22
+ */
+public class WxGeneralConfig {
+
+    @Value("${wx.general.appId}")
+    private String appId;
+
+    @Value("${wx.general.appSecret}")
+    private String appSecret;
+
+    @Value("${wx.general.grantType}")
+    private String grantType;
+
+    public String getAppId() {
+        return appId;
+    }
+
+    public void setAppId(String appId) {
+        this.appId = appId;
+    }
+
+    public String getAppSecret() {
+        return appSecret;
+    }
+
+    public void setAppSecret(String appSecret) {
+        this.appSecret = appSecret;
+    }
+
+    public String getGrantType() {
+        return grantType;
+    }
+
+    public void setGrantType(String grantType) {
+        this.grantType = grantType;
+    }
+}

+ 17 - 0
src/main/java/com/ematou/wxbase/controller/TokenRecordController.java

@@ -0,0 +1,17 @@
+package com.ematou.wxbase.controller;
+
+import com.ematou.wxbase.service.OperationRecordService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author lhm
+ * @version 1.0
+ * 2021-04-30 17:52
+ */
+@RestController
+public class TokenRecordController {
+
+
+
+}

+ 81 - 0
src/main/java/com/ematou/wxbase/entity/OperationRecord.java

@@ -0,0 +1,81 @@
+package com.ematou.wxbase.entity;
+
+import java.sql.Timestamp;
+
+/**
+ * @author lhm
+ * @version 1.0
+ * 2021-04-30 11:35
+ */
+public class OperationRecord {
+
+    private Integer opId;
+
+    private String appCode;
+
+    private String createrSn;
+
+    private String createTime;
+
+    private String moderSn;
+
+    private String modTime;
+
+    private Timestamp tstm;
+
+    public Integer getOpId() {
+        return opId;
+    }
+
+    public void setOpId(Integer opId) {
+        this.opId = opId;
+    }
+
+    public String getAppCode() {
+        return appCode;
+    }
+
+    public void setAppCode(String appCode) {
+        this.appCode = appCode;
+    }
+
+    public String getCreaterSn() {
+        return createrSn;
+    }
+
+    public void setCreaterSn(String createrSn) {
+        this.createrSn = createrSn;
+    }
+
+    public String getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(String createTime) {
+        this.createTime = createTime;
+    }
+
+    public String getModerSn() {
+        return moderSn;
+    }
+
+    public void setModerSn(String moderSn) {
+        this.moderSn = moderSn;
+    }
+
+    public String getModTime() {
+        return modTime;
+    }
+
+    public void setModTime(String modTime) {
+        this.modTime = modTime;
+    }
+
+    public Timestamp getTstm() {
+        return tstm;
+    }
+
+    public void setTstm(Timestamp tstm) {
+        this.tstm = tstm;
+    }
+}

+ 131 - 0
src/main/java/com/ematou/wxbase/entity/TokenRecord.java

@@ -0,0 +1,131 @@
+package com.ematou.wxbase.entity;
+
+import java.sql.Timestamp;
+
+/**
+ * @author lhm
+ * @version 1.0
+ * 2021-04-30 11:45
+ */
+public class TokenRecord {
+
+    private Integer id;
+
+    private String accessToken;
+
+    private String expiresTime;
+
+    private String effectTime;
+
+    private Integer expiresIn;
+
+    private Integer opId;
+
+    private Integer isValid;
+
+    private String createrSn;
+
+    private String createTime;
+
+    private String moderSn;
+
+    private String modTime;
+
+    private Timestamp tstm;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getAccessToken() {
+        return accessToken;
+    }
+
+    public void setAccessToken(String accessToken) {
+        this.accessToken = accessToken;
+    }
+
+    public String getExpiresTime() {
+        return expiresTime;
+    }
+
+    public void setExpiresTime(String expiresTime) {
+        this.expiresTime = expiresTime;
+    }
+
+    public String getEffectTime() {
+        return effectTime;
+    }
+
+    public void setEffectTime(String effectTime) {
+        this.effectTime = effectTime;
+    }
+
+    public Integer getExpiresIn() {
+        return expiresIn;
+    }
+
+    public void setExpiresIn(Integer expiresIn) {
+        this.expiresIn = expiresIn;
+    }
+
+    public Integer getOpId() {
+        return opId;
+    }
+
+    public void setOpId(Integer opId) {
+        this.opId = opId;
+    }
+
+    public Integer getIsValid() {
+        return isValid;
+    }
+
+    public void setIsValid(Integer isValid) {
+        this.isValid = isValid;
+    }
+
+    public String getCreaterSn() {
+        return createrSn;
+    }
+
+    public void setCreaterSn(String createrSn) {
+        this.createrSn = createrSn;
+    }
+
+    public String getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(String createTime) {
+        this.createTime = createTime;
+    }
+
+    public String getModerSn() {
+        return moderSn;
+    }
+
+    public void setModerSn(String moderSn) {
+        this.moderSn = moderSn;
+    }
+
+    public String getModTime() {
+        return modTime;
+    }
+
+    public void setModTime(String modTime) {
+        this.modTime = modTime;
+    }
+
+    public Timestamp getTstm() {
+        return tstm;
+    }
+
+    public void setTstm(Timestamp tstm) {
+        this.tstm = tstm;
+    }
+}

+ 81 - 0
src/main/java/com/ematou/wxbase/interceptor/MybatisInsertInterceptor.java

@@ -0,0 +1,81 @@
+package com.ematou.wxbase.interceptor;
+
+import com.ematou.wxbase.common.utils.DateUtils;
+import org.apache.ibatis.executor.Executor;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlCommandType;
+import org.apache.ibatis.plugin.*;
+import org.springframework.stereotype.Component;
+
+import java.lang.reflect.Field;
+import java.sql.Timestamp;
+import java.util.*;
+
+/**
+ * @author lhm
+ * @version 1.0
+ * 2021-04-30 15:30
+ */
+@Intercepts({@Signature(type = Executor.class, method = "insert", args = {MappedStatement.class, Object.class})})
+@Component
+public class MybatisInsertInterceptor implements Interceptor {
+
+
+    @Override
+    public Object intercept(Invocation invocation) throws Throwable {
+
+        Object[] args = invocation.getArgs();
+        MappedStatement mappedStatement = (MappedStatement) args[0];
+
+        if (mappedStatement.getSqlCommandType() == SqlCommandType.INSERT) {
+            Object arg = args[1];
+            if (arg instanceof Map) {
+                Map<?, ?> map = (Map<?, ?>) arg;
+                for (Object key : map.keySet()) {
+                    if (key.toString().contains("param")) {
+                        handleInsertData(map.get(key));
+                    }
+                }
+            } else {
+                handleInsertData(arg);
+            }
+        }
+
+        return null;
+    }
+
+    private void handleInsertData(Object o) throws IllegalAccessException {
+        Field[] fields = o.getClass().getDeclaredFields();
+
+        for (Field field : fields) {
+            switch (field.getName()) {
+                case "getCreateTime":
+                    field.setAccessible(true);
+                    field.set(o, DateUtils.formatDate(new Date()));
+                    break;
+                case "getModTime":
+                    field.setAccessible(true);
+                    field.set(o, DateUtils.formatDate(new Date()));
+                    break;
+                case "getTstm":
+                    field.setAccessible(true);
+                    field.set(o, new Timestamp(System.currentTimeMillis()));
+                    break;
+                case "getCreaterSn":
+                    // TODO
+                    break;
+            }
+        }
+
+    }
+
+    @Override
+    public Object plugin(Object target) {
+        return Plugin.wrap(target, this);
+    }
+
+    @Override
+    public void setProperties(Properties properties) {
+
+    }
+}

+ 79 - 0
src/main/java/com/ematou/wxbase/interceptor/MybatisUpdateInterceptor.java

@@ -0,0 +1,79 @@
+package com.ematou.wxbase.interceptor;
+
+import com.ematou.wxbase.common.utils.DateUtils;
+import org.apache.ibatis.executor.Executor;
+import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlCommandType;
+import org.apache.ibatis.plugin.*;
+import org.springframework.stereotype.Component;
+
+import java.lang.reflect.Field;
+import java.sql.Timestamp;
+import java.util.Date;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * @author lhm
+ * @version 1.0
+ * 2021-04-30 15:30
+ */
+@Intercepts({@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})})
+@Component
+public class MybatisUpdateInterceptor implements Interceptor {
+
+
+    @Override
+    public Object intercept(Invocation invocation) throws Throwable {
+
+        Object[] args = invocation.getArgs();
+        MappedStatement mappedStatement = (MappedStatement) args[0];
+
+        if (mappedStatement.getSqlCommandType() == SqlCommandType.UPDATE) {
+            Object arg = args[1];
+            if (arg instanceof Map) {
+                Map<?, ?> map = (Map<?, ?>) arg;
+                for (Object key : map.keySet()) {
+                    if (key.toString().contains("param")) {
+                        handleInsertData(map.get(key));
+                    }
+                }
+            } else {
+                handleInsertData(arg);
+            }
+        }
+
+        return null;
+    }
+
+    private void handleInsertData(Object o) throws IllegalAccessException {
+        Field[] fields = o.getClass().getDeclaredFields();
+
+        for (Field field : fields) {
+            switch (field.getName()) {
+                case "getModTime":
+                    field.setAccessible(true);
+                    field.set(o, DateUtils.formatDate(new Date()));
+                    break;
+                case "getTstm":
+                    field.setAccessible(true);
+                    field.set(o, new Timestamp(System.currentTimeMillis()));
+                    break;
+                case "getModerSn":
+                    // TODO
+                    break;
+            }
+        }
+
+    }
+
+    @Override
+    public Object plugin(Object target) {
+        return Plugin.wrap(target, this);
+    }
+
+    @Override
+    public void setProperties(Properties properties) {
+
+    }
+}

+ 24 - 0
src/main/java/com/ematou/wxbase/mapper/OperationRecordMapper.java

@@ -0,0 +1,24 @@
+package com.ematou.wxbase.mapper;
+
+import com.ematou.wxbase.entity.OperationRecord;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author lhm
+ * @version 1.0
+ * 2021-04-30 12:02
+ */
+@Mapper
+@Repository
+public interface OperationRecordMapper {
+
+    public List<OperationRecord> queryAll(@Param("param") Map<String, Object> param);
+
+    public int insertRecord(@Param("record") OperationRecord record);
+
+}

+ 24 - 0
src/main/java/com/ematou/wxbase/mapper/TokenRecordMapper.java

@@ -0,0 +1,24 @@
+package com.ematou.wxbase.mapper;
+
+import com.ematou.wxbase.entity.TokenRecord;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.Map;
+
+/**
+ * @author lhm
+ * @version 1.0
+ * 2021-04-30 16:51
+ */
+@Mapper
+@Repository
+public interface TokenRecordMapper {
+
+    public int insertRecord(@Param("record") TokenRecord record);
+
+    public TokenRecord queryLatestAndValidRecord();
+
+    public int queryLatestAndValidRecordCount();
+}

+ 30 - 0
src/main/java/com/ematou/wxbase/service/OperationRecordService.java

@@ -0,0 +1,30 @@
+package com.ematou.wxbase.service;
+
+import com.ematou.wxbase.entity.OperationRecord;
+import com.ematou.wxbase.mapper.OperationRecordMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author lhm
+ * @version 1.0
+ * 2021-04-30 16:45
+ */
+@Service
+public class OperationRecordService {
+
+    @Autowired
+    OperationRecordMapper operationRecordMapper;
+
+    public int insertRecord(OperationRecord record) {
+        return operationRecordMapper.insertRecord(record);
+    }
+
+    public List<OperationRecord> queryAll(Map<String, Object> param) {
+        return operationRecordMapper.queryAll(param);
+    }
+
+}

+ 30 - 0
src/main/java/com/ematou/wxbase/service/TokenRecordService.java

@@ -0,0 +1,30 @@
+package com.ematou.wxbase.service;
+
+import com.ematou.wxbase.mapper.OperationRecordMapper;
+import com.ematou.wxbase.mapper.TokenRecordMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * @author lhm
+ * @version 1.0
+ * 2021-04-30 17:53
+ */
+@Service
+public class TokenRecordService {
+
+    @Autowired
+    OperationRecordMapper operationRecordMapper;
+
+    @Autowired
+    TokenRecordMapper tokenRecordMapper;
+
+    @Autowired
+    RestTemplate restTemplate;
+
+    public void generatorToken () {
+
+    }
+
+}

+ 16 - 0
src/main/resources/application.yml

@@ -0,0 +1,16 @@
+server:
+  port: 3030
+
+wx:
+  general:
+    appId: wxf9360d70bc1406ee
+    appSecret:
+    grantType: client_credential
+spring:
+  datasource:
+    driver-class-name: com.mysql.cj.jdbc.Driver
+    username:
+    password:
+    url: jdbc:mysql://localhost:3306/wx_base?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
+mybatis:
+  mapper-locations: classpath:mybatis/*.xml

+ 70 - 0
src/main/resources/mybatis/OperationRecordMapper.xml

@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ematou.wxbase.mapper.OperationRecordMapper">
+
+    <sql id="Base_Column_List">
+        op_id, app_code, creater_sn, create_time, moder_sn, mod_time, tstm
+    </sql>
+
+    <insert id="insertRecord" parameterType="com.ematou.wxbase.entity.OperationRecord">
+        insert into wxoperation_record
+        <trim prefix="(" suffix=")" suffixOverrides="," >
+            <if test="record.appCode != null">
+                app_code,
+            </if>
+            <if test="record.createrSn != null">
+                creater_sn,
+            </if>
+            <if test="record.createTime != null">
+                create_time,
+            </if>
+            <if test="record.moderSn != null">
+                moder_sn,
+            </if>
+            <if test="record.modTime != null">
+                mod_time,
+            </if>
+            <if test="record.tstm != null">
+                tstm,
+            </if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides="," >
+            <if test="record.appCode != null">
+                #{record.appCode},
+            </if>
+            <if test="record.createrSn != null">
+                #{record.createrSn},
+            </if>
+            <if test="record.createTime != null">
+                #{record.createTime,jdbcType=VARCHAR},
+            </if>
+            <if test="record.moderSn != null">
+                #{record.moderSn},
+            </if>
+            <if test="record.modTime != null">
+                #{record.modTime,jdbcType=VARCHAR},
+            </if>
+            <if test="record.tstm != null">
+                #{record.tstm},
+            </if>
+        </trim>
+    </insert>
+
+    <select id="queryAll" resultType="com.ematou.wxbase.entity.OperationRecord" parameterType="map">
+        select
+        <include refid="Base_Column_List"/>
+        from wx_operation_record
+        <if test="param.containsKey('order')">
+            order by #{param.order}
+        </if>
+        <if test="param.containsKey('page') and param.containsKey('limit')">
+            limit #{param.page},#{param.limit}
+        </if>
+        <if test="param.containsKey('page') == false and param.containsKey('limit')">
+            limit #{param.limit}
+        </if>
+    </select>
+
+</mapper>

+ 99 - 0
src/main/resources/mybatis/TokenRecordMapper.xml

@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ematou.wxbase.mapper.TokenRecordMapper">
+
+    <sql id="Base_Column_List">
+        id, access_token, expires_time, effect_time, expires_in, op_id, is_valid, creater_sn, create_time, moder_sn, mod_time, tstm
+    </sql>
+
+    <insert id="insertRecord" parameterType="com.ematou.wxbase.entity.TokenRecord">
+        insert into wx_token_record
+        <trim prefix="(" suffix=")" suffixOverrides="," >
+            <if test="record.accessToken != null">
+                access_token,
+            </if>
+            <if test="record.expiresTime != null">
+                expires_time,
+            </if>
+            <if test="record.effectTime != null">
+                effect_time,
+            </if>
+            <if test="record.expiresIn != null">
+                expires_in,
+            </if>
+            <if test="record.opId != null">
+                op_id,
+            </if>
+            <if test="record.isValid != null">
+                is_valid,
+            </if>
+            <if test="record.createrSn != null">
+                creater_sn,
+            </if>
+            <if test="record.createTime != null">
+                create_time,
+            </if>
+            <if test="record.moderSn != null">
+                moder_sn,
+            </if>
+            <if test="record.modTime != null">
+                mod_time,
+            </if>
+            <if test="record.tstm != null">
+                tstm,
+            </if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides="," >
+            <if test="record.accessToken != null">
+                #{record.accessToken},
+            </if>
+            <if test="record.expiresTime != null">
+                #{record.expiresTime},
+            </if>
+            <if test="record.effectTime != null">
+                #{record.effectTime},
+            </if>
+            <if test="record.expiresIn != null">
+                #{record.expiresIn},
+            </if>
+            <if test="record.opId != null">
+                #{record.opId},
+            </if>
+            <if test="record.isValid != null">
+                #{record.isValid},
+            </if>
+            <if test="record.createrSn != null">
+                #{record.createrSn},
+            </if>
+            <if test="record.createTime != null">
+                #{record.createTime},
+            </if>
+            <if test="record.moderSn != null">
+                #{record.moderSn},
+            </if>
+            <if test="record.modTime != null">
+                #{record.modTime},
+            </if>
+            <if test="record.tstm != null">
+                #{record.tstm},
+            </if>
+        </trim>
+    </insert>
+
+    <select id="queryLatestAndValidRecord" resultType="com.ematou.wxbase.entity.TokenRecord">
+        select
+        <include refid="Base_Column_List"/>
+        from wx_token_record
+        where is_valid=0
+        order by id desc
+        limit 1
+    </select>
+
+    <select id="queryLatestAndValidRecordCount" resultType="java.lang.Integer">
+        select count(1) from wx_token_record where is_valid=0
+    </select>
+
+
+</mapper>

+ 13 - 0
src/test/java/com/ematou/wxbase/WxbaseApplicationTests.java

@@ -0,0 +1,13 @@
+package com.ematou.wxbase;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+class WxbaseApplicationTests {
+
+    @Test
+    void contextLoads() {
+    }
+
+}