diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..465eca3 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +springbootstart \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..1c7d7c9 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..c8ff0fb --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..71b8943 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,40 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..4b661a5 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/bin/build.sh b/bin/build.sh new file mode 100644 index 0000000..3ac88fa --- /dev/null +++ b/bin/build.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +PWD=$(cd `dirname $0`;pwd); +TARGET='test' + +set -e + +help() { + echo "Usage: $1 IMAGE." + exit 1 +} + +if [ $# -lt 1 ];then + help $0 +fi + +IMAGE=$1 + +if [ $# -ge 2 ];then + TARGET=$2 +fi + +cd $PWD/.. + +mvn clean package -P $TARGET +cp web/target/springbootstart-web-1.0.0.jar docker/springbootstart-1.0.0.jar + +docker build -t $IMAGE docker diff --git a/bin/run.sh b/bin/run.sh new file mode 100644 index 0000000..a5ab6bc --- /dev/null +++ b/bin/run.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +PWD=$(cd `dirname $0`;pwd); + +IMG_NAME="springbootstart" +IMG_VER='1.0.1' +PORT=8090 + +if [ $# -gt 1 ];then + PORT=$2 +fi + +if [ $# -gt 2 ];then + IMG_VER=$3 +fi + +NAME="springbootstart-$IMG_VER" + +run() { + echo "docker run --restart=on-failure:10 --name $NAME -d -p$PORT:8080 ${IMG_NAME}:${IMG_VER}" + docker run --restart=on-failure:10 --name $NAME -d -p$PORT:8080 ${IMG_NAME}:${IMG_VER} +} + +case $1 in + start) + docker start $NAME + exit $? + ;; + stop) + docker stop $NAME + exit $? + ;; + rm) + docker rm $NAME + exit $? + ;; + run) + run + exit $? + ;; + *) + echo "Usage: run.sh {start|stop|rm|run} port version." >&2 + echo "port and version are optional." >&2 + exit 1 + ;; +esac diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..2516908 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,7 @@ +FROM tonywell/alpine-jre8:1.0.0 + +RUN mkdir /app +WORKDIR /app +COPY springbootstart-1.0.0.jar /app/ +ENTRYPOINT ["java", "-jar", "-Xms256m", "-Xmx256m", "/app/springbootstart-1.0.0.jar"] +EXPOSE 8080 diff --git a/modules/common/README.md b/modules/common/README.md new file mode 100644 index 0000000..fd7aeed --- /dev/null +++ b/modules/common/README.md @@ -0,0 +1,21 @@ +# 返回的分页数据 请用pagehelp的PageInfo + +# 引入redis +## 需要在yml文件中配置prefix指定前缀 +```yaml +zhehe: + common: + redis: + prefix: +``` +# 引入md5加密 +## 需配置secretSalt +```yaml +zhehe: + common: + md5: + secretSalt: + ``` + + + diff --git a/modules/common/pom.xml b/modules/common/pom.xml new file mode 100644 index 0000000..6198415 --- /dev/null +++ b/modules/common/pom.xml @@ -0,0 +1,130 @@ + + + 4.0.0 + com.zhehekeji + common + 1.0.0 + + + 1.8 + 2.1.9.RELEASE + 1.2.47 + 2.1 + UTF-8 + 1.0.0 + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + + + org.springframework.boot + spring-boot-autoconfigure + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + org.projectlombok + lombok + true + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-validation + + + + org.springframework.boot + spring-boot-starter-data-redis + + + org.springframework.boot + spring-boot-starter-aop + + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + + com.alibaba + fastjson + ${fastjson.version} + + + + com.google.zxing + core + ${qrcode.version} + + + com.google.zxing + javase + ${qrcode.version} + + + org.apache.httpcomponents + httpclient + + + redis.clients + jedis + + + com.zhehekeji + core + 1.0.0 + + + com.zhehekeji + base-assembly + 1.0.0 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + nexus + Nexus + http://47.99.98.250:28888/repository/maven-public/ + + false + + + + \ No newline at end of file diff --git a/modules/common/src/main/java/com/zhehekeji/common/CommonConfigure.java b/modules/common/src/main/java/com/zhehekeji/common/CommonConfigure.java new file mode 100644 index 0000000..874114d --- /dev/null +++ b/modules/common/src/main/java/com/zhehekeji/common/CommonConfigure.java @@ -0,0 +1,25 @@ +package com.zhehekeji.common; + +import com.zhehekeji.common.properities.Md5Properity; +import com.zhehekeji.common.properities.RedisProperity; +import com.zhehekeji.common.util.MD5Util; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @Description + * @Author wangyiming1031@aliyun.com + * @Date 2019/10/28 15:39 + **/ +@Configuration +@EnableConfigurationProperties({RedisProperity.class, Md5Properity.class}) +public class CommonConfigure { + //todo 把result的version放进来 + + @Bean + public MD5Util md5Util(Md5Properity md5Properity){ + return new MD5Util(md5Properity); + } + +} diff --git a/modules/common/src/main/java/com/zhehekeji/common/constant/CommonConstant.java b/modules/common/src/main/java/com/zhehekeji/common/constant/CommonConstant.java new file mode 100644 index 0000000..b981f78 --- /dev/null +++ b/modules/common/src/main/java/com/zhehekeji/common/constant/CommonConstant.java @@ -0,0 +1,32 @@ +package com.zhehekeji.common.constant; + +public abstract class CommonConstant { + + public static final Integer RESULT_ERROR_CODE = 500; + + public static final String RESULT_ADD_OK_MSG = "新增成功"; + + public static final String RESULT_ADD_ERROR_MSG = "新增失败"; + + public static final String RESULT_DELETE_OK_MSG = "删除成功"; + + public static final String RESULT_DELETE_ERROR_MSG = "删除失败"; + + public static final String RESULT_EDIT_OK_MSG = "修改成功"; + + public static final String RESULT_EDIT_ERROR_MSG = "修改失败"; + + public static final String RESULT_OK_MSG = "操作成功"; + + public static final String RESULT_ERROR_MSG = "生成失败"; + + public static final String MODULE_URL = "/module"; + + public static final String PROJECT_URL = "/project"; + + public static final String ACCOUNT_URL = "/account"; + + public static final String ROLE_URL = "/role"; + + public static final String DEPARTMENT_URL = "/department"; +} diff --git a/modules/common/src/main/java/com/zhehekeji/common/properities/Md5Properity.java b/modules/common/src/main/java/com/zhehekeji/common/properities/Md5Properity.java new file mode 100644 index 0000000..2990e0e --- /dev/null +++ b/modules/common/src/main/java/com/zhehekeji/common/properities/Md5Properity.java @@ -0,0 +1,17 @@ +package com.zhehekeji.common.properities; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties("zhehe.common.md5") +public class Md5Properity { + + private String secretSalt = "zheHeKeJi"; + + public String getSecretSalt() { + return secretSalt; + } + + public void setSecretSalt(String secretSalt) { + this.secretSalt = secretSalt; + } +} diff --git a/modules/common/src/main/java/com/zhehekeji/common/properities/Properity.java b/modules/common/src/main/java/com/zhehekeji/common/properities/Properity.java new file mode 100644 index 0000000..ca5ceef --- /dev/null +++ b/modules/common/src/main/java/com/zhehekeji/common/properities/Properity.java @@ -0,0 +1,16 @@ +package com.zhehekeji.common.properities; + +import lombok.Getter; +import lombok.Setter; +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties("zhehe.common") +@Getter +@Setter +public class Properity { + + private String version; + + private String successMsg = "SUCCESS"; + +} diff --git a/modules/common/src/main/java/com/zhehekeji/common/properities/RedisProperity.java b/modules/common/src/main/java/com/zhehekeji/common/properities/RedisProperity.java new file mode 100644 index 0000000..40d9edf --- /dev/null +++ b/modules/common/src/main/java/com/zhehekeji/common/properities/RedisProperity.java @@ -0,0 +1,15 @@ +package com.zhehekeji.common.properities; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties("zhehe.common.redis") +@Data +public class RedisProperity { + + /** + * redis前缀 + */ + private String prefix; + +} diff --git a/modules/common/src/main/java/com/zhehekeji/common/util/HttpUtil.java b/modules/common/src/main/java/com/zhehekeji/common/util/HttpUtil.java new file mode 100644 index 0000000..726637b --- /dev/null +++ b/modules/common/src/main/java/com/zhehekeji/common/util/HttpUtil.java @@ -0,0 +1,153 @@ +package com.zhehekeji.common.util; + +import com.zhehekeji.core.util.Assert; +import lombok.extern.slf4j.Slf4j; +import org.apache.http.HttpEntity; +import org.apache.http.HttpStatus; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; + +import java.io.IOException; +import java.net.URLEncoder; +import java.util.Iterator; +import java.util.Map; + +@Slf4j +public class HttpUtil { + + private static final CloseableHttpClient httpClient; + + static { + httpClient = HttpClients.createDefault(); + } + + private static RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(5000) + .setConnectionRequestTimeout(1000).setSocketTimeout(6000).build(); + + /** + * get请求 + * + * @return + */ + public static String doGet(String url) { + HttpGet httpGet = new HttpGet(url); + httpGet.setConfig(requestConfig); + return response(httpGet); + } + + /** + * post请求(请求参数是 name1=value1&name2=value2 的形式) + * + * @param url + * @param params + * @return + */ + public static String doPost(String url, String params) { + HttpPost httpPost = new HttpPost(url); + httpPost.setHeader("Accept", "*/*"); + httpPost.setHeader("Accept-Charset", "UTF-8"); + httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); + StringEntity entity = new StringEntity(params, "UTF-8"); + httpPost.setEntity(entity); + httpPost.setConfig(requestConfig); + return response(httpPost); + } + + /** + * POST请求,请求参数是map形式 + * + * @param url + * @param map + * @return + */ + public static String doMapPost(String url, Map map) { + String params = buildParam(map); + return doPost(url, params); + } + + /** + * post请求(用于请求参数是json格式) + * + * @param url + * @param params + * @return + */ + public static String doJsonPost(String url, String params) { + HttpPost httpPost = new HttpPost(url); + httpPost.setHeader("Accept", "application/json"); + httpPost.setHeader("Content-Type", "application/json"); + StringEntity entity = new StringEntity(params, "UTF-8"); + httpPost.setEntity(entity); + httpPost.setConfig(requestConfig); + return response(httpPost); + } + + private static String response(HttpUriRequest request) { + CloseableHttpResponse response = null; + try { + response = httpClient.execute(request); + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + HttpEntity responseEntity = response.getEntity(); + if (responseEntity != null) { + String jsonString = EntityUtils.toString(responseEntity, "UTF-8"); + /** 消耗掉entity对象 **/ + EntityUtils.consume(responseEntity); + return jsonString; + } + } else { + log.error("发起http请求异常:url:{}", request.getURI()); + } + } catch (Exception e) { + log.error("请求异常:{}" + e); + } finally { + if (response != null) { + try { + response.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + return null; + } + + /** + * 将map对象转换为URL参数格式 + * + * @param params + * @return + */ + public static String buildParam(Map params) { + if (params.isEmpty()) { + return ""; + } + StringBuilder param = new StringBuilder(); + Iterator keyIter = params.keySet().iterator(); + try { + while (keyIter.hasNext()) { + String key = keyIter.next(); + Object o = params.get(key); + if (o == null) { + param.append(key + "=&"); + } else { + param.append(key + "=" + URLEncoder.encode(String.valueOf(o), "UTF-8") + "&"); + } + } + if (param.length() != 0) { + param.deleteCharAt(param.length() - 1); + } + } catch (Exception ex) { + log.error("map对象转换为URL异常:{}", ex); + Assert.isTrue(false, "map对象转换为URL异常"); + } + return param.toString(); + } + +} diff --git a/modules/common/src/main/java/com/zhehekeji/common/util/MD5Util.java b/modules/common/src/main/java/com/zhehekeji/common/util/MD5Util.java new file mode 100644 index 0000000..e650e15 --- /dev/null +++ b/modules/common/src/main/java/com/zhehekeji/common/util/MD5Util.java @@ -0,0 +1,54 @@ +package com.zhehekeji.common.util; + +import com.zhehekeji.common.properities.Md5Properity; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class MD5Util { + + private String salt; + + public MD5Util(Md5Properity md5Properity){ + this.salt = md5Properity.getSecretSalt(); + } + + private String getMD5(String content) { + try { + MessageDigest digest = MessageDigest.getInstance("MD5"); + digest.update(content.getBytes()); + return getHashString(digest); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + return null; + } + + /** + * 获取加盐md5 + * @param content + * @return + */ + public String getMD5WithSalt(String content) { + return getMD5(getMD5(content) + salt); + } + + private String getHashString(MessageDigest digest) { + StringBuilder builder = new StringBuilder(); + for (byte b : digest.digest()) { + builder.append(Integer.toHexString((b >> 4) & 0xf)); + builder.append(Integer.toHexString(b & 0xf)); + } + return builder.toString(); + } + + /** + * 检验密码是否正确 + * @param password + * @param md5 + * @return + */ + public Boolean checkPassword(String password,String md5){ + return md5.equals(getMD5WithSalt(password)); + } +} diff --git a/modules/common/src/main/java/com/zhehekeji/common/util/QrUtil.java b/modules/common/src/main/java/com/zhehekeji/common/util/QrUtil.java new file mode 100644 index 0000000..1ca4bf7 --- /dev/null +++ b/modules/common/src/main/java/com/zhehekeji/common/util/QrUtil.java @@ -0,0 +1,72 @@ +package com.zhehekeji.common.util; + +import com.google.zxing.BarcodeFormat; +import com.google.zxing.EncodeHintType; +import com.google.zxing.MultiFormatWriter; +import com.google.zxing.WriterException; +import com.google.zxing.client.j2se.MatrixToImageWriter; +import com.google.zxing.common.BitMatrix; +import com.zhehekeji.core.util.Assert; +import org.apache.commons.codec.binary.Base64; +import org.springframework.util.StringUtils; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.*; +import java.util.Hashtable; + +/** + * 二维码Util + */ +public class QrUtil { + + private static String BASE64 = "data:image/jpg;base64,"; + + public static BufferedImage createCode(String content, BarcodeFormat format,Integer width,Integer height) throws WriterException { + Assert.isTrue(!StringUtils.isEmpty(content),"二维码生成要素为空"); + Hashtable hints = new Hashtable<>(); + hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); + + BitMatrix bitMatrix = new MultiFormatWriter().encode(content, format , width, height, hints); + return MatrixToImageWriter.toBufferedImage(bitMatrix); + } + + /** + * 将二维码显示在web上 + * @param os OutputStream + * @param extension 图片类型 jpg jpeg + * @param content 二维码要素 + * @param format 二维码类型 QR_CODE : 正方形二维码 + * 见 com.google.zxing.BarcodeFormat + * @param width 宽 + * @param height 高 + * @throws IOException + * @throws WriterException + */ + public static void outPut2Web(OutputStream os, String extension, String content, BarcodeFormat format, Integer width, Integer height) throws IOException, WriterException { + BufferedImage image = createCode(content,format,width,height); + ImageIO.write(image, extension, os); + } + + /** + * 二维码转base64 + * @param content 二维码要素 + * @param format 二维码类型 QR_CODE : 正方形二维码 + * @param width 宽 + * @param height 高 + * @param extension 图片类型 jpg/jpeg + * @return + * @throws WriterException + * @throws IOException + */ + public static String image2Base64(String content, BarcodeFormat format,Integer width,Integer height,String extension) throws WriterException, IOException { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + BufferedImage image = createCode(content,format,width,height); + ImageIO.write(image, extension, outputStream); + String base = Base64.encodeBase64String(outputStream.toByteArray()); + return BASE64 + base; + } + + + +} diff --git a/modules/common/src/main/java/com/zhehekeji/common/util/SpringContextUtil.java b/modules/common/src/main/java/com/zhehekeji/common/util/SpringContextUtil.java new file mode 100644 index 0000000..28cece2 --- /dev/null +++ b/modules/common/src/main/java/com/zhehekeji/common/util/SpringContextUtil.java @@ -0,0 +1,33 @@ +package com.zhehekeji.common.util; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +import java.util.Map; + +@Component +public class SpringContextUtil implements ApplicationContextAware { + + private static ApplicationContext applicationContext; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + SpringContextUtil.applicationContext = applicationContext; + } + + public static T getBean(String id, Class type) { + return applicationContext.getBean(id, type); + } + + public static T getBean(Class type) { + return applicationContext.getBean(type); + } + + public static Map getBeansOfType(Class type) { + return applicationContext.getBeansOfType(type); + } + + +} diff --git a/modules/common/src/main/java/com/zhehekeji/common/util/Tools.java b/modules/common/src/main/java/com/zhehekeji/common/util/Tools.java new file mode 100644 index 0000000..ec03c77 --- /dev/null +++ b/modules/common/src/main/java/com/zhehekeji/common/util/Tools.java @@ -0,0 +1,45 @@ +package com.zhehekeji.common.util; + +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; + +/** + * 通用工具类 + */ +public class Tools { + + /** + * 返回uuid,替换“-” + * + * @return + */ + public static String UUID() { + return UUID.randomUUID().toString().replaceAll("-", ""); + } + + + /** + * url 拼接参数 + * @param sourceUrl + * @param parameters + * @return + */ + public static String joinParameters(String sourceUrl, Map parameters) { + StringBuffer sb = new StringBuffer(sourceUrl) + .append("?"); + String andChar = "&"; + parameters.entrySet().forEach(entry -> { + sb.append(entry.getKey()) + .append("=") + .append(entry.getValue()) + .append(andChar); + }); + if (sb.indexOf(andChar) > 0) { + sb.deleteCharAt(sb.length() - 1); + } + return sb.toString(); + } + +} diff --git a/modules/common/src/main/java/com/zhehekeji/common/util/ValidatorUtil.java b/modules/common/src/main/java/com/zhehekeji/common/util/ValidatorUtil.java new file mode 100644 index 0000000..8a56117 --- /dev/null +++ b/modules/common/src/main/java/com/zhehekeji/common/util/ValidatorUtil.java @@ -0,0 +1,28 @@ +package com.zhehekeji.common.util; + +import com.zhehekeji.core.util.Assert; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.validation.ConstraintViolation; +import javax.validation.Validator; +import java.util.Set; + +@Component +public class ValidatorUtil { + + @Autowired + private Validator validator; + + public void validate(T object, Class... groups) { + Set> constraintViolations = validator.validate(object, groups); + if (!constraintViolations.isEmpty()) { + StringBuilder msg = new StringBuilder(); + for (ConstraintViolation violation : constraintViolations) { + msg.append(violation.getMessage()).append(";"); + } + Assert.isTrue(Boolean.FALSE, msg != null ? msg.toString() : ""); + } + } + +} diff --git a/modules/filter/README.md b/modules/filter/README.md new file mode 100644 index 0000000..9bc4ba8 --- /dev/null +++ b/modules/filter/README.md @@ -0,0 +1,13 @@ +# 使用说明 +## CurrentUserUtil +##### 该类只能获取controller类里面被SessionHandler注解修饰的方法 +## 请在yml中做如下配置 +```yaml +zhehe: + filter: + sessionExpireTime: ##session过期时间,单位分钟,必须要填!!!!!!! + header: ##token请求头,默认为token + jwtSecret: ## jwt密钥,默认zheHeKeJi + sessionPrefix: ## redis上的session头,默认为 :session: +``` + diff --git a/modules/filter/pom.xml b/modules/filter/pom.xml new file mode 100644 index 0000000..5ce40d3 --- /dev/null +++ b/modules/filter/pom.xml @@ -0,0 +1,79 @@ + + + + modules + com.zhehekeji + 1.0.0 + + 4.0.0 + + com.zhehekeji + 1.0.0 + filter + + + 1.8 + 2.1.9.RELEASE + 0.7.0 + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + + + org.springframework.boot + spring-boot-autoconfigure + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + org.springframework.boot + spring-boot-starter-aop + + + org.projectlombok + lombok + true + + + + com.zhehekeji + core + 1.0.0 + + + + org.springframework.boot + spring-boot-starter-data-redis + + + + io.jsonwebtoken + jjwt + ${jwt.version} + + + + com.zhehekeji + common + 1.0.0 + compile + + + \ No newline at end of file diff --git a/modules/filter/src/main/java/com/zhehekeji/filter/FilterConstance.java b/modules/filter/src/main/java/com/zhehekeji/filter/FilterConstance.java new file mode 100644 index 0000000..5e2d1ba --- /dev/null +++ b/modules/filter/src/main/java/com/zhehekeji/filter/FilterConstance.java @@ -0,0 +1,12 @@ +package com.zhehekeji.filter; + +public interface FilterConstance { + + String HEADER = "token"; + + String JWT_KEY = "zhehekeji"; + + String SESSION_PREFIX = "session:"; + + Long SESSION_EXPIRE = 10800l; +} diff --git a/modules/filter/src/main/java/com/zhehekeji/filter/aspect/SessionAspect.java b/modules/filter/src/main/java/com/zhehekeji/filter/aspect/SessionAspect.java new file mode 100644 index 0000000..9cf0963 --- /dev/null +++ b/modules/filter/src/main/java/com/zhehekeji/filter/aspect/SessionAspect.java @@ -0,0 +1,67 @@ +package com.zhehekeji.filter.aspect; + +import com.zhehekeji.core.pojo.HttpStatus; +import com.zhehekeji.core.util.Assert; +import com.zhehekeji.filter.FilterConstance; +import com.zhehekeji.filter.pojo.CurrentUser; +import com.zhehekeji.filter.pojo.SessionHandler; +import com.zhehekeji.filter.pojo.UserType; +import com.zhehekeji.filter.util.CurrentUserUtil; +import com.zhehekeji.filter.util.JwtUtil; +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; + +/** + * @Description Session切面 + * @Author wangyiming1031@aliyun.com + * @Date 2019/10/28 19:26 + **/ +@Aspect +@Component +@Slf4j +public class SessionAspect { + + @Value("${zhehe.filter.enable}") + private Boolean enable; + + /** + * zhehekeji..*.controller + * 匹配zhehekeji 到controller多级目录 + * + * @param sessionHandler + */ + @Before("execution(public * com.zhehekeji..*.controller.*.*(..))&&@annotation(sessionHandler)") + public void handler(SessionHandler sessionHandler) { + if(!enable){ + return; + } + HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + CurrentUser currentUser = null; + String token = request.getHeader(FilterConstance.HEADER); + if (UserType.ACCOUNT.equals(sessionHandler.userType())) { + log.info("token:" + token); + if (!StringUtils.isEmpty(token)) { + currentUser = JwtUtil.getUser(request); + if (currentUser != null) { + + } + } + } else if (UserType.USER.equals(sessionHandler.userType())) { + } + if (sessionHandler.login()) { + Assert.isTrue(currentUser != null, HttpStatus.UNAUTHORIZED.getCode(), HttpStatus.UNAUTHORIZED.getReasonPhrase()); + } + if (sessionHandler.auth()) { + //todo 权限检验 + } + CurrentUserUtil.setCurrentUser(currentUser); + } +} diff --git a/modules/filter/src/main/java/com/zhehekeji/filter/pojo/CurrentUser.java b/modules/filter/src/main/java/com/zhehekeji/filter/pojo/CurrentUser.java new file mode 100644 index 0000000..fcc379e --- /dev/null +++ b/modules/filter/src/main/java/com/zhehekeji/filter/pojo/CurrentUser.java @@ -0,0 +1,40 @@ +package com.zhehekeji.filter.pojo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@Builder +@NoArgsConstructor +public class CurrentUser { + + /** + * 主键 + */ + private Integer id; + + /** + * 手机号 + */ + private String phone; + + /** + * 账号 某些系统可能账号就是手机号 + */ + private String account; + + private String email; + + /** + * 昵称 + */ + private String name; + + /** + * 用户类型 + */ + private UserType userType; +} diff --git a/modules/filter/src/main/java/com/zhehekeji/filter/pojo/SessionHandler.java b/modules/filter/src/main/java/com/zhehekeji/filter/pojo/SessionHandler.java new file mode 100644 index 0000000..3d07997 --- /dev/null +++ b/modules/filter/src/main/java/com/zhehekeji/filter/pojo/SessionHandler.java @@ -0,0 +1,25 @@ +package com.zhehekeji.filter.pojo; + +import java.lang.annotation.*; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface SessionHandler { + + String value() default ""; + + UserType userType() default UserType.USER; + + /** + * 是否检验登录 + * @return true:检验 false:不检验 + */ + boolean login() default true; + + /** + * 是否检验权限 + * @return true:检验 false:不检验 默认检验 + */ + boolean auth() default true; +} diff --git a/modules/filter/src/main/java/com/zhehekeji/filter/pojo/UserType.java b/modules/filter/src/main/java/com/zhehekeji/filter/pojo/UserType.java new file mode 100644 index 0000000..4f863f9 --- /dev/null +++ b/modules/filter/src/main/java/com/zhehekeji/filter/pojo/UserType.java @@ -0,0 +1,19 @@ +package com.zhehekeji.filter.pojo; + +/** + * @Description 用户分类 + * @Author wangyiming1031@aliyun.com + * @Date 2019/10/28 19:30 + **/ +public enum UserType { + + /** + * 后台用户 + */ + ACCOUNT, + /** + * 用户 + */ + USER, + ; +} diff --git a/modules/filter/src/main/java/com/zhehekeji/filter/util/CurrentUserUtil.java b/modules/filter/src/main/java/com/zhehekeji/filter/util/CurrentUserUtil.java new file mode 100644 index 0000000..eedf95c --- /dev/null +++ b/modules/filter/src/main/java/com/zhehekeji/filter/util/CurrentUserUtil.java @@ -0,0 +1,30 @@ +package com.zhehekeji.filter.util; + +import com.zhehekeji.filter.pojo.CurrentUser; + +/** + * @Description 当前操作人线程 + * @Author wangyiming1031@aliyun.com + * @Date 2019/10/28 19:22 + **/ +public class CurrentUserUtil { + + private static ThreadLocal currentUser = new ThreadLocal<>(); + + /** + * 获取当前操作人 + * + * @return + */ + public static CurrentUser getCurrentUser() { + return currentUser.get(); + } + + public static void setCurrentUser(CurrentUser user) { + currentUser.set(user); + } + + public static void delCurrentUser() { + currentUser.remove(); + } +} diff --git a/modules/filter/src/main/java/com/zhehekeji/filter/util/JwtUtil.java b/modules/filter/src/main/java/com/zhehekeji/filter/util/JwtUtil.java new file mode 100644 index 0000000..c744b85 --- /dev/null +++ b/modules/filter/src/main/java/com/zhehekeji/filter/util/JwtUtil.java @@ -0,0 +1,85 @@ +package com.zhehekeji.filter.util; + +import com.alibaba.fastjson.JSONObject; +import com.zhehekeji.filter.FilterConstance; +import com.zhehekeji.filter.pojo.CurrentUser; +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.JwtBuilder; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.Date; + +/** + * @Description JWTUtil + * @Author wangyiming1031@aliyun.com + * @Date 2019/10/28 19:11 + **/ +public class JwtUtil { + + /** + * 生成JWT + * + * @return + */ + private static String createJWT(CurrentUser currentUser) { + String userJson = JSONObject.toJSONString(currentUser); + JwtBuilder builder = Jwts.builder() + .setSubject(userJson) + .setIssuedAt(new Date()) + .signWith(SignatureAlgorithm.HS256, FilterConstance.JWT_KEY); + return builder.compact(); + } + + /** + * 解析JWT + * 抛出异常 则jwt错误 + * @param jwtStr + * @return + */ + public static Claims parseJWT(String jwtStr) { + return Jwts.parser() + .setSigningKey(FilterConstance.JWT_KEY) + .parseClaimsJws(jwtStr) + .getBody(); + } + + /** + * 获取当前操作人 + * + * @param request + * @return + */ + public static CurrentUser getUser(HttpServletRequest request) { + String token = getToken(request); + Claims claims; + try { + claims = parseJWT(token); + } catch (Exception e) { + return null; + } + String json = claims.getSubject(); + CurrentUser userInfo = JSONObject.parseObject(json, CurrentUser.class); + return userInfo; + } + + private static String getToken(HttpServletRequest request) { + return request.getHeader(FilterConstance.HEADER); + } + + /** + * 生成jwt,并将jwt放入返回头 + * 主要考虑的是 返回header 由用户过滤模块维护 + * @param response + * @param currentUser + * @return + */ + public static String createTokenAndHeader(HttpServletResponse response,CurrentUser currentUser){ + String jwt = createJWT(currentUser); + response.setHeader(FilterConstance.HEADER,jwt); + return jwt; + } + +} diff --git a/modules/filter/src/main/resources/config/application.yml b/modules/filter/src/main/resources/config/application.yml new file mode 100644 index 0000000..631213b --- /dev/null +++ b/modules/filter/src/main/resources/config/application.yml @@ -0,0 +1,3 @@ +zhehe: + filter: + enable: true \ No newline at end of file diff --git a/modules/pom.xml b/modules/pom.xml new file mode 100644 index 0000000..f3ee85d --- /dev/null +++ b/modules/pom.xml @@ -0,0 +1,55 @@ + + + + springbootstart + com.zhehekeji + 1.0.0 + + 4.0.0 + + modules + pom + + + 1.8 + 1.0.0 + 1.0.0 + 1.0.0 + + + + + com.zhehekeji + base-assembly + ${base.assembly.version} + + + com.zhehekeji + common + ${common.version} + + + org.springframework.boot + spring-boot-starter-web + + + org.projectlombok + lombok + true + + + + + + nexus + Nexus + http://47.99.98.250:28888/repository/maven-public/ + + false + + + + + diff --git a/playbook/roles/springbootstart-test/files/docker-compose.yml b/playbook/roles/springbootstart-test/files/docker-compose.yml new file mode 100644 index 0000000..2485588 --- /dev/null +++ b/playbook/roles/springbootstart-test/files/docker-compose.yml @@ -0,0 +1,15 @@ +version: '2' +services: + backend: + image: springbootstart:1.0.0 + container_name: lipo-duoji + ports: + - "8990:8099" + hostname: lipo-duoji + volumes: + - /home/work/lia/duoji/logs:/data/log/duoji + +networks: + default: + external: + name: zhehe007 diff --git a/playbook/roles/springbootstart-test/tasks/main.yml b/playbook/roles/springbootstart-test/tasks/main.yml new file mode 100644 index 0000000..d4ec19b --- /dev/null +++ b/playbook/roles/springbootstart-test/tasks/main.yml @@ -0,0 +1,22 @@ +--- +- name: Ensures /home/work/springbootstart/springbootstart_backend_test dir exists + file: path=/home/work/springbootstart/springbootstart_backend_test state=directory + +- name: stop admin Service + shell: docker-compose -f /home/work/springbootstart/springbootstart_backend_test/docker-compose.yml down + ignore_errors: True + +- name: copy admin docker-compose.yml + copy: + src: docker-compose.yml + dest: /home/work/springbootstart/springbootstart_backend_test/docker-compose.yml + backup: yes + +- name: docker-pull + shell: docker pull {{ DOCKER_REPO }}/{{ IMAGE }} && docker tag {{ DOCKER_REPO }}/{{ IMAGE }} {{ IMAGE }} && docker rmi {{ DOCKER_REPO }}/{{ IMAGE }} + +- name: modify docker-compose.yml + shell: cd /home/work/springbootstart/springbootstart_backend_test && sed -i "s/springbootstart:1.0.0/{{ IMAGE }}/g" docker-compose.yml + +- name: start Service + shell: docker-compose -f /home/work/springbootstart/springbootstart_backend_test/docker-compose.yml up -d diff --git a/playbook/test-hosts b/playbook/test-hosts new file mode 100644 index 0000000..cb9b43a --- /dev/null +++ b/playbook/test-hosts @@ -0,0 +1 @@ +192.168.1.232 \ No newline at end of file diff --git a/playbook/test.yml b/playbook/test.yml new file mode 100644 index 0000000..4b90468 --- /dev/null +++ b/playbook/test.yml @@ -0,0 +1,6 @@ +--- +- name: deploy springbootstart + hosts: all + remote_user: work + roles: + - springbootstart-test diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..f103003 --- /dev/null +++ b/pom.xml @@ -0,0 +1,132 @@ + + + 4.0.0 + pom + + web + modules + modules/common + modules/filter + + + org.springframework.boot + spring-boot-starter-parent + 2.1.9.RELEASE + + + com.zhehekeji + springbootstart + 1.0.0 + springbootstart + Demo project for Spring Boot + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.boot + spring-boot-starter-data-redis + + + + com.alibaba + fastjson + 1.2.47 + + + org.apache.commons + commons-lang3 + + + + + + + test + + test + + + true + + + + + prod + + prod + + + false + + + + + + + nexus + Nexus + http://47.99.98.250:28888/repository/maven-public/ + + false + + + + + + + src/main/resources + true + + application*.yml + + + + true + src/main/resources + + bootstrap.yml + application.yml + application-${profileActive}.yml + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + + diff --git a/web/pom.xml b/web/pom.xml new file mode 100644 index 0000000..9933df6 --- /dev/null +++ b/web/pom.xml @@ -0,0 +1,57 @@ + + + + springbootstart + com.zhehekeji + 1.0.0 + + 4.0.0 + + springbootstart-web + + + 1.8 + 1.0.0 + 1.0.0 + 1.0.0 + + + + + + com.zhehekeji + base-assembly + ${base.assembly.version} + + + org.springframework.boot + spring-boot-starter-web + + + org.projectlombok + lombok + true + + + com.zhehekeji + common + 1.0.0 + + + + com.zhehekeji + filter + 1.0.0 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/web/src/main/java/com/zhehekeji/web/Application.java b/web/src/main/java/com/zhehekeji/web/Application.java new file mode 100644 index 0000000..374f60b --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/Application.java @@ -0,0 +1,14 @@ +package com.zhehekeji.web; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication(scanBasePackages = {"com.zhehekeji"}) +@MapperScan("com.zhehekeji.**.mapper.**") +public class Application { + public static void main(String[] args) { + SpringApplication springApplication = new SpringApplication(Application.class); + springApplication.run(args); + } +} diff --git a/web/src/main/java/com/zhehekeji/web/config/PackagesSqlSessionFactory.java b/web/src/main/java/com/zhehekeji/web/config/PackagesSqlSessionFactory.java new file mode 100644 index 0000000..1ad8ae7 --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/config/PackagesSqlSessionFactory.java @@ -0,0 +1,59 @@ +package com.zhehekeji.web.config; + +import lombok.extern.slf4j.Slf4j; +import org.mybatis.spring.SqlSessionFactoryBean; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.core.io.support.ResourcePatternResolver; +import org.springframework.core.type.classreading.CachingMetadataReaderFactory; +import org.springframework.core.type.classreading.MetadataReader; +import org.springframework.core.type.classreading.MetadataReaderFactory; +import org.springframework.util.ClassUtils; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +@Slf4j +public class PackagesSqlSessionFactory extends SqlSessionFactoryBean { + + static final String DEFAULT_RESOURCE_PATTERN = "**/*.class"; + + @Override + public void setTypeAliasesPackage(String typeAliasesPackage) { + ResourcePatternResolver resolver = (ResourcePatternResolver) new PathMatchingResourcePatternResolver(); + MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver); + typeAliasesPackage = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + + ClassUtils.convertClassNameToResourcePath(typeAliasesPackage) + "/" + DEFAULT_RESOURCE_PATTERN; + + //将加载多个绝对匹配的所有Resource + //将首先通过ClassLoader.getResource("META-INF")加载非模式路径部分 + //然后进行遍历模式匹配 + try { + List result = new ArrayList(); + Resource[] resources = resolver.getResources(typeAliasesPackage); + if (resources != null && resources.length > 0) { + MetadataReader metadataReader = null; + for (Resource resource : resources) { + if (resource.isReadable()) { + metadataReader = metadataReaderFactory.getMetadataReader(resource); + try { + result.add(Class.forName(metadataReader.getClassMetadata().getClassName()).getPackage().getName()); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + } + } + if (result.size() > 0) { + super.setTypeAliasesPackage(String.join(",", result)); + } else { + log.error("参数typeAliasesPackage:" + typeAliasesPackage + ",未找到任何包"); + } + //logger.info("d"); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/web/src/main/java/com/zhehekeji/web/config/SwaggerConfig.java b/web/src/main/java/com/zhehekeji/web/config/SwaggerConfig.java new file mode 100644 index 0000000..df86d41 --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/config/SwaggerConfig.java @@ -0,0 +1,36 @@ +package com.zhehekeji.web.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableSwagger2 +@Profile({"test", "dev"}) +public class SwaggerConfig { + + @Bean + public Docket petApi() { + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()) + .select() + //指定提供接口所在的基包 + .apis(RequestHandlerSelectors.basePackage("com.zhehekeji")) + .build(); + } + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("舵机Api") + .version("1.0.0") + .description("web 舵机Api") + .build(); + } +} diff --git a/web/src/main/java/com/zhehekeji/web/controller/OrderController.java b/web/src/main/java/com/zhehekeji/web/controller/OrderController.java new file mode 100644 index 0000000..518a8d2 --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/controller/OrderController.java @@ -0,0 +1,53 @@ +package com.zhehekeji.web.controller; + +import com.github.pagehelper.PageInfo; +import com.zhehekeji.core.pojo.Result; +import com.zhehekeji.core.util.Assert; +import com.zhehekeji.filter.pojo.SessionHandler; +import com.zhehekeji.filter.pojo.UserType; +import com.zhehekeji.web.entity.Order; +import com.zhehekeji.web.pojo.OrderSearch; +import com.zhehekeji.web.service.OrderService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +@Api(value = "OrderController",tags = "订单管理") +@RestController(value = "OrderController") +@RequestMapping("/order") +public class OrderController { + + @Resource + private OrderService orderService; + + @ApiOperation("新增") + @PostMapping("/") + //@SessionHandler(userType = UserType.ACCOUNT) + public Result save(@RequestBody Order order){ + + return Result.success(orderService.add(order)); + } + + @PostMapping("/list") + @ApiOperation(value = "查询") + //@SessionHandler(userType = UserType.ACCOUNT) + public Result> findRoleList(@RequestBody OrderSearch orderSearch) { + return new Result<>(orderService.orders(orderSearch)); + } + + + + + + /*@GetMapping("/userCenter") + @ApiOperation("用户中心地址") + public Result userCenter(){ + return Result.success(applicationService.userCenter()); + }*/ + + +} diff --git a/web/src/main/java/com/zhehekeji/web/controller/StreetController.java b/web/src/main/java/com/zhehekeji/web/controller/StreetController.java new file mode 100644 index 0000000..5f4aace --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/controller/StreetController.java @@ -0,0 +1,46 @@ +package com.zhehekeji.web.controller; + +import com.zhehekeji.core.pojo.Result; +import com.zhehekeji.web.entity.Order; +import com.zhehekeji.web.entity.Street; +import com.zhehekeji.web.mapper.StreetMapper; +import com.zhehekeji.web.pojo.OrderSearch; +import com.zhehekeji.web.service.OrderService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; + +@Api(value = "StreetController",tags = "巷道管理") +@RestController(value = "StreetController") +@RequestMapping("/street") +public class StreetController { + + @Resource + private StreetMapper streetMapper; + + @PostMapping("/list") + @ApiOperation(value = "巷道查询") + //@SessionHandler(userType = UserType.ACCOUNT) + public Result> list() { + return new Result<>(streetMapper.selectByMap(new HashMap<>(0))); + } + + + + + + /*@GetMapping("/userCenter") + @ApiOperation("用户中心地址") + public Result userCenter(){ + return Result.success(applicationService.userCenter()); + }*/ + + +} diff --git a/web/src/main/java/com/zhehekeji/web/controller/controller.java b/web/src/main/java/com/zhehekeji/web/controller/controller.java new file mode 100644 index 0000000..239f65c --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/controller/controller.java @@ -0,0 +1,14 @@ +package com.zhehekeji.web.controller; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class controller { + + @RequestMapping(value = "/web",method = RequestMethod.GET) + public String get(){ + return "web"; + } +} diff --git a/web/src/main/java/com/zhehekeji/web/entity/Order.java b/web/src/main/java/com/zhehekeji/web/entity/Order.java new file mode 100644 index 0000000..afef16e --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/entity/Order.java @@ -0,0 +1,34 @@ +package com.zhehekeji.web.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +@TableName("`order`") +public class Order { + + @TableId(type = IdType.AUTO) + private Long id; + + private Long serialNum; + + @ApiModelProperty("订单号") + private String orderNum; + + @ApiModelProperty("仓位号") + private String positionNum; + + @ApiModelProperty("视频图片地址") + private String filePath; + + private String mediaType; + + private String deviceid; + + private LocalDateTime createTime; +} diff --git a/web/src/main/java/com/zhehekeji/web/entity/Street.java b/web/src/main/java/com/zhehekeji/web/entity/Street.java new file mode 100644 index 0000000..5c1cec1 --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/entity/Street.java @@ -0,0 +1,24 @@ +package com.zhehekeji.web.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +@TableName +public class Street { + + @TableId(type = IdType.AUTO) + private Integer id; + + private String name; + + private String url1; + + private String url2; + + private LocalDateTime createTime; +} diff --git a/web/src/main/java/com/zhehekeji/web/mapper/OrderMapper.java b/web/src/main/java/com/zhehekeji/web/mapper/OrderMapper.java new file mode 100644 index 0000000..1069b06 --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/mapper/OrderMapper.java @@ -0,0 +1,7 @@ +package com.zhehekeji.web.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.zhehekeji.web.entity.Order; + +public interface OrderMapper extends BaseMapper { +} diff --git a/web/src/main/java/com/zhehekeji/web/mapper/StreetMapper.java b/web/src/main/java/com/zhehekeji/web/mapper/StreetMapper.java new file mode 100644 index 0000000..55468d1 --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/mapper/StreetMapper.java @@ -0,0 +1,7 @@ +package com.zhehekeji.web.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.zhehekeji.web.entity.Street; + +public interface StreetMapper extends BaseMapper { +} diff --git a/web/src/main/java/com/zhehekeji/web/pojo/OrderSearch.java b/web/src/main/java/com/zhehekeji/web/pojo/OrderSearch.java new file mode 100644 index 0000000..1dbcd9e --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/pojo/OrderSearch.java @@ -0,0 +1,11 @@ +package com.zhehekeji.web.pojo; + +import lombok.Data; + +import javax.validation.constraints.NotEmpty; + +@Data +public class OrderSearch { + + private String orderNum; +} diff --git a/web/src/main/java/com/zhehekeji/web/service/OrderService.java b/web/src/main/java/com/zhehekeji/web/service/OrderService.java new file mode 100644 index 0000000..5a97a2d --- /dev/null +++ b/web/src/main/java/com/zhehekeji/web/service/OrderService.java @@ -0,0 +1,28 @@ +package com.zhehekeji.web.service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.zhehekeji.web.entity.Order; +import com.zhehekeji.web.mapper.OrderMapper; +import com.zhehekeji.web.pojo.OrderSearch; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +@Service +public class OrderService { + + @Resource + private OrderMapper orderMapper; + + public List orders(OrderSearch orderSearch){ + List orders = orderMapper.selectList(new QueryWrapper().eq("order_num",orderSearch.getOrderNum())); + return orders; + } + + public Long add(Order order){ + orderMapper.insert(order); + return order.getId(); + } + +} diff --git a/web/src/main/resources/application-test.yml b/web/src/main/resources/application-test.yml new file mode 100644 index 0000000..fffd4a8 --- /dev/null +++ b/web/src/main/resources/application-test.yml @@ -0,0 +1,32 @@ +logging: + level: + com.zhehekeji: debug + org.springframework.web: info + root: info +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + initialSize: 15 + maxActive: 20 + maxPoolPreparedStatementPerConnectionSize: 20 + maxWait: 60000 + minEvictableIdleTimeMillis: 300000 + minIdle: 15 + password: lipoLiPo + poolPreparedStatements: true + testOnBorrow: true + testOnReturn: false + testWhileIdle: false + timeBetweenEvictionRunsMillis: 60000 + type: com.alibaba.druid.pool.DruidDataSource + url: jdbc:mysql://47.98.255.48:8008/lipo_duoji?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8 + username: lipo + validationQuery: SELECT 1 FROM DUAL +zhehe: + common: + redis: + prefix: spring + filter: + enable: true +server: + port: 8099 diff --git a/web/src/main/resources/application.yml b/web/src/main/resources/application.yml new file mode 100644 index 0000000..d0f5ce9 --- /dev/null +++ b/web/src/main/resources/application.yml @@ -0,0 +1,23 @@ +spring: + profiles: + active: @profileActive@ + application: + name: springbootstart-web + mvc: + #视图路径配置 + view: + prefix: / + suffix: .html + servlet: + path: /api/ +mybatis-plus: + mapper-locations: classpath*:mapper/**/*.xml + #实体扫描,多个package用逗号或者分号分隔 + type-aliases-package: com.zhehekeji.*.entity + configuration: + map-underscore-to-camel-case: true #下划线转驼峰 + cache-enabled: false #不加这个查询数据为空时,字段将被隐藏 +mapper: + identity: MYSQL + not-empty: true + style: normal diff --git a/web/src/main/resources/logback-spring.xml b/web/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..cc623b6 --- /dev/null +++ b/web/src/main/resources/logback-spring.xml @@ -0,0 +1,124 @@ + + + + + + + %d %p (%file:%line\)- %m%n + UTF-8 + + + + ${LOG_HOME}/${logName}-info.log + + ${LOG_HOME}/${logName}-info-%d{yyyy-MM-dd}.%i.log + 30 + + 10MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + info + ACCEPT + DENY + + + + ${LOG_HOME}/${logName}-warn.log + + ${LOG_HOME}/${logName}-warn-%d{yyyy-MM-dd}.%i.log + 30 + + 10MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + warn + ACCEPT + DENY + + + + ${LOG_HOME}/${logName}-error.log + + ${LOG_HOME}/${logName}-error-%d{yyyy-MM-dd}.%i.log + 30 + + 10MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + error + ACCEPT + DENY + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +