springcloud_k8s_panzhihuazhihuishequ/shop_backstage/.gitignore
New file @@ -0,0 +1,33 @@ HELP.md target/ !.mvn/wrapper/maven-wrapper.jar !**/src/main/**/target/ !**/src/test/**/target/ ### STS ### .apt_generated .classpath .factorypath .project .settings .springBeans .sts4-cache ### IntelliJ IDEA ### .idea *.iws *.iml *.ipr ### NetBeans ### /nbproject/private/ /nbbuild/ /dist/ /nbdist/ /.nb-gradle/ build/ !**/src/main/**/build/ !**/src/test/**/build/ ### VS Code ### .vscode/ springcloud_k8s_panzhihuazhihuishequ/shop_backstage/mvnw
springcloud_k8s_panzhihuazhihuishequ/shop_backstage/mvnw.cmd
New file @@ -0,0 +1,182 @@ @REM ---------------------------------------------------------------------------- @REM Licensed to the Apache Software Foundation (ASF) under one @REM or more contributor license agreements. See the NOTICE file @REM distributed with this work for additional information @REM regarding copyright ownership. The ASF licenses this file @REM to you under the Apache License, Version 2.0 (the @REM "License"); you may not use this file except in compliance @REM with the License. You may obtain a copy of the License at @REM @REM https://www.apache.org/licenses/LICENSE-2.0 @REM @REM Unless required by applicable law or agreed to in writing, @REM software distributed under the License is distributed on an @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @REM KIND, either express or implied. See the License for the @REM specific language governing permissions and limitations @REM under the License. @REM ---------------------------------------------------------------------------- @REM ---------------------------------------------------------------------------- @REM Maven Start Up Batch script @REM @REM Required ENV vars: @REM JAVA_HOME - location of a JDK home dir @REM @REM Optional ENV vars @REM M2_HOME - location of maven2's installed home dir @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven @REM e.g. to debug Maven itself, use @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files @REM ---------------------------------------------------------------------------- @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' @echo off @REM set title of command window title %0 @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% @REM set %HOME% to equivalent of $HOME if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") @REM Execute a user defined script before this one if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre @REM check for pre script, once with legacy .bat ending and once with .cmd ending if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" :skipRcPre @setlocal set ERROR_CODE=0 @REM To isolate internal variables from possible post scripts, we use another setlocal @setlocal @REM ==== START VALIDATION ==== if not "%JAVA_HOME%" == "" goto OkJHome echo. echo Error: JAVA_HOME not found in your environment. >&2 echo Please set the JAVA_HOME variable in your environment to match the >&2 echo location of your Java installation. >&2 echo. goto error :OkJHome if exist "%JAVA_HOME%\bin\java.exe" goto init echo. echo Error: JAVA_HOME is set to an invalid directory. >&2 echo JAVA_HOME = "%JAVA_HOME%" >&2 echo Please set the JAVA_HOME variable in your environment to match the >&2 echo location of your Java installation. >&2 echo. goto error @REM ==== END VALIDATION ==== :init @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". @REM Fallback to current working directory if not found. set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir set EXEC_DIR=%CD% set WDIR=%EXEC_DIR% :findBaseDir IF EXIST "%WDIR%"\.mvn goto baseDirFound cd .. IF "%WDIR%"=="%CD%" goto baseDirNotFound set WDIR=%CD% goto findBaseDir :baseDirFound set MAVEN_PROJECTBASEDIR=%WDIR% cd "%EXEC_DIR%" goto endDetectBaseDir :baseDirNotFound set MAVEN_PROJECTBASEDIR=%EXEC_DIR% cd "%EXEC_DIR%" :endDetectBaseDir IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig @setlocal EnableExtensions EnableDelayedExpansion for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% :endReadAdditionalConfig SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B ) @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central @REM This allows using the maven wrapper in projects that prohibit checking in binary data. if exist %WRAPPER_JAR% ( if "%MVNW_VERBOSE%" == "true" ( echo Found %WRAPPER_JAR% ) ) else ( if not "%MVNW_REPOURL%" == "" ( SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" ) if "%MVNW_VERBOSE%" == "true" ( echo Couldn't find %WRAPPER_JAR%, downloading it ... echo Downloading from: %DOWNLOAD_URL% ) powershell -Command "&{"^ "$webclient = new-object System.Net.WebClient;"^ "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ "}"^ "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ "}" if "%MVNW_VERBOSE%" == "true" ( echo Finished downloading %WRAPPER_JAR% ) ) @REM End of extension @REM Provide a "standardized" way to retrieve the CLI args that will @REM work with both Windows and non-Windows executions. set MAVEN_CMD_LINE_ARGS=%* %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* if ERRORLEVEL 1 goto error goto end :error set ERROR_CODE=1 :end @endlocal & set ERROR_CODE=%ERROR_CODE% if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost @REM check for post script, once with legacy .bat ending and once with .cmd ending if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" :skipRcPost @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' if "%MAVEN_BATCH_PAUSE%" == "on" pause if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% exit /B %ERROR_CODE% springcloud_k8s_panzhihuazhihuishequ/shop_backstage/pom.xml
New file @@ -0,0 +1,108 @@ <?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>com.panzhihua</groupId> <artifactId>zhihuishequ</artifactId> <version>1.0-SNAPSHOT</version> </parent> <groupId>com.panzhihua</groupId> <artifactId>shop_backstage</artifactId> <version>0.0.1-SNAPSHOT</version> <name>shop_backstage</name> <description>商家后台</description> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>com.panzhihua</groupId> <artifactId>common</artifactId> </dependency> <dependency> <groupId>com.netflix.hystrix</groupId> <artifactId>hystrix-javanica</artifactId> </dependency> <dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>swagger-bootstrap-ui</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.panzhihua.community_backstage.CommunityBackstageApplication</mainClass> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>1.2.0</version> <configuration> <imageName>registry.cn-chengdu.aliyuncs.com/panzhihua/community_backstage:v1</imageName> <serverId></serverId> <baseImage>java</baseImage> <entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> </plugin> </plugins> </build> <repositories> <repository> <id>spring-snapshots</id> <name>Spring Snapshots</name> <url>https://repo.spring.io/snapshot</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> </repository> </repositories> </project> springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/java/com/panzhihua/shop_backstage/ShopBackstageApplication.java
New file @@ -0,0 +1,23 @@ package com.panzhihua.shop_backstage; import org.springframework.boot.SpringApplication; import org.springframework.cloud.client.SpringCloudApplication; import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.ComponentScan; import springfox.documentation.swagger2.annotations.EnableSwagger2; @EnableSwagger2 @SpringCloudApplication @EnableCircuitBreaker @EnableEurekaClient @EnableFeignClients(basePackages = {"com.panzhihua.common.service"}) @ComponentScan({"com.panzhihua.shop_backstage","com.panzhihua.common"}) public class ShopBackstageApplication { public static void main(String[] args) { SpringApplication.run(ShopBackstageApplication.class, args); } } springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/java/com/panzhihua/shop_backstage/aop/OperLogAspect.java
New file @@ -0,0 +1,326 @@ package com.panzhihua.shop_backstage.aop; import com.alibaba.fastjson.JSONObject; import com.panzhihua.common.constants.Constants; import com.panzhihua.common.constants.TokenConstant; import com.panzhihua.common.interfaces.ShopOperLog; import com.panzhihua.common.model.vos.LoginUserInfoVO; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.shop.ShopOperLogVO; import com.panzhihua.common.service.community.CommunityService; import com.panzhihua.common.service.user.UserService; import com.panzhihua.common.utlis.AES; import com.panzhihua.common.utlis.IPUtil; import com.panzhihua.shop_backstage.model.vos.LoginBody; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.reflect.MethodSignature; import org.springframework.stereotype.Component; import org.springframework.util.ObjectUtils; import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestContextHolder; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.BufferedReader; import java.io.IOException; import java.lang.reflect.Method; import java.util.Date; import java.util.HashMap; import java.util.Map; /** * @ClasssName 商家后台日志 * @Description * @Author cedoo * @Date 2021/4/16 * @Version 1.0 **/ @Slf4j @Aspect @Component public class OperLogAspect { @Resource private CommunityService communityService; @Resource private UserService userService; /** * 设置操作日志切入点 记录操作日志 在注解的位置切入代码 */ @Pointcut("@annotation(com.panzhihua.common.interfaces.ShopOperLog)") public void operLogPoinCut() { } // /** // * 设置操作异常切入点记录异常日志 扫描所有controller包下操作 // */ // @Pointcut("execution(* com.hyd.zcar.cms.controller..*.*(..))") // public void operExceptionLogPoinCut() { // } /** * 正常返回通知,拦截用户操作日志,连接点正常执行完成后执行, 如果连接点抛出异常,则不会执行 * * @param joinPoint 切入点 * @param keys 返回结果 */ @AfterReturning(value = "operLogPoinCut()", returning = "keys") public void saveOperLog(JoinPoint joinPoint, Object keys) { log.info("进入切面"); // 获取RequestAttributes RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); // 从获取RequestAttributes中获取HttpServletRequest的信息 HttpServletRequest request = (HttpServletRequest) requestAttributes .resolveReference(RequestAttributes.REFERENCE_REQUEST); // 登录对象信息 String userInfo = request.getHeader(TokenConstant.TOKEN_USERINFO); boolean empty = ObjectUtils.isEmpty(userInfo); if (empty) { log.error("操作日志获取登录用户信息失败【{}】",joinPoint); return; } byte[] bytes = AES.parseHexStr2Byte(userInfo); byte[] decrypt = AES.decrypt(bytes, Constants.AES_KEY); userInfo=new String(decrypt); LoginUserInfoVO loginUserInfoVO= JSONObject.parseObject(userInfo,LoginUserInfoVO.class); ShopOperLogVO shopOperlog = new ShopOperLogVO(); try { // 从切面织入点处通过反射机制获取织入点处的方法 MethodSignature signature = (MethodSignature) joinPoint.getSignature(); // 获取切入点所在的方法 Method method = signature.getMethod(); // 获取操作 ShopOperLog opLog = method.getAnnotation(ShopOperLog.class); if (opLog != null) { String operModul = opLog.operModul(); int operType = opLog.operType(); shopOperlog.setTitle(operModul); // 操作模块 shopOperlog.setBusinessType(operType); // 操作类型 } // 获取请求的类名 String className = joinPoint.getTarget().getClass().getName(); // 获取请求的方法名 String methodName = method.getName(); methodName = className + "." + methodName; shopOperlog.setMethod(methodName); // 请求方法 if (joinPoint.getArgs().length > 0) { for (Object o : joinPoint.getArgs()) { if (o instanceof HttpServletRequest || o instanceof HttpServletResponse) { continue; } shopOperlog.setOperParam(JSONObject.toJSONString(o)); // 请求参数 } } shopOperlog.setJsonResult(JSONObject.toJSONString(keys)); // 返回结果 shopOperlog.setAccount(loginUserInfoVO.getAccount()); shopOperlog.setOperName(loginUserInfoVO.getName()); // 请求用户名称 shopOperlog.setOperIp(IPUtil.getIpAddress(request)); // 请求IP shopOperlog.setOperUrl(request.getRequestURI()); // 请求URI shopOperlog.setRequestMethod(request.getMethod()); shopOperlog.setOperLocation(IPUtil.getIpBelongAddress(request)); shopOperlog.setOperTime(new Date()); // 创建时间 shopOperlog.setAccount(loginUserInfoVO.getAccount()); Long communityId = loginUserInfoVO.getCommunityId(); shopOperlog.setCommunityId(null==communityId?0:communityId); shopOperlog.setUserId(loginUserInfoVO.getUserId()); communityService.addShopOperLog(shopOperlog); } catch (Exception e) { e.printStackTrace(); } } // /** // * 异常返回通知,用于拦截异常日志信息 连接点抛出异常后执行 // * // * @param joinPoint 切入点 // * @param e 异常信息 // */ // @AfterThrowing(pointcut = "operExceptionLogPoinCut()", throwing = "e") // public void saveExceptionLog(JoinPoint joinPoint, Throwable e) { // // 获取RequestAttributes // RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); // // 从获取RequestAttributes中获取HttpServletRequest的信息 // HttpServletRequest request = (HttpServletRequest) requestAttributes // .resolveReference(RequestAttributes.REFERENCE_REQUEST); // // ExceptionLog excepLog = new ExceptionLog(); // try { // // 从切面织入点处通过反射机制获取织入点处的方法 // MethodSignature signature = (MethodSignature) joinPoint.getSignature(); // // 获取切入点所在的方法 // Method method = signature.getMethod(); // excepLog.setExcId(UuidUtil.get32UUID()); // // 获取请求的类名 // String className = joinPoint.getTarget().getClass().getName(); // // 获取请求的方法名 // String methodName = method.getName(); // methodName = className + "." + methodName; // // 请求的参数 // Map<String, String> rtnMap = converMap(request.getParameterMap()); // // 将参数所在的数组转换成json // String params = JSON.toJSONString(rtnMap); // excepLog.setExcRequParam(params); // 请求参数 // excepLog.setOperMethod(methodName); // 请求方法名 // excepLog.setExcName(e.getClass().getName()); // 异常名称 // excepLog.setExcMessage(stackTraceToString(e.getClass().getName(), e.getMessage(), e.getStackTrace())); // 异常信息 // excepLog.setOperUserId(UserShiroUtil.getCurrentUserLoginName()); // 操作员ID // excepLog.setOperUserName(UserShiroUtil.getCurrentUserName()); // 操作员名称 // excepLog.setOperUri(request.getRequestURI()); // 操作URI // excepLog.setOperIp(IPUtil.getRemortIP(request)); // 操作员IP // excepLog.setOperVer(operVer); // 操作版本号 // excepLog.setOperCreateTime(new Date()); // 发生异常时间 // // exceptionLogService.insert(excepLog); // // } catch (Exception e2) { // e2.printStackTrace(); // } // // } /** * 转换request 请求参数 * * @param paramMap request获取的参数数组 */ public Map<String, String> converMap(Map<String, String[]> paramMap) { Map<String, String> rtnMap = new HashMap<String, String>(); for (String key : paramMap.keySet()) { rtnMap.put(key, paramMap.get(key)[0]); } return rtnMap; } private String getPostData(HttpServletRequest request) { StringBuffer data = new StringBuffer(); String line = null; BufferedReader reader = null; try { reader = request.getReader(); while (null != (line = reader.readLine())) data.append(line); } catch (IOException e) { } finally { } return data.toString(); } /** * 转换异常信息为字符串 * * @param exceptionName 异常名称 * @param exceptionMessage 异常信息 * @param elements 堆栈信息 */ public String stackTraceToString(String exceptionName, String exceptionMessage, StackTraceElement[] elements) { StringBuffer strbuff = new StringBuffer(); for (StackTraceElement stet : elements) { strbuff.append(stet + "\n"); } String message = exceptionName + ":" + exceptionMessage + "\n\t" + strbuff.toString(); return message; } /** * 登录日志切入点 */ @Pointcut("execution(public * com.panzhihua.shop_backstage.api.LoginApi.login(..) )") public void operLogLoginPoinCut() { } /** * 正常返回通知,拦截用户操作日志,连接点正常执行完成后执行, 如果连接点抛出异常,则不会执行 * * @param joinPoint 切入点 * @param keys 返回结果 */ @AfterReturning(value = "operLogLoginPoinCut()", returning = "keys") public void saveLoginOperLog(JoinPoint joinPoint, Object keys) { log.info("进入商家后台登录日志切面"); // 获取RequestAttributes RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); // 从获取RequestAttributes中获取HttpServletRequest的信息 HttpServletRequest request = (HttpServletRequest) requestAttributes .resolveReference(RequestAttributes.REFERENCE_REQUEST); if(keys instanceof R ){ R r = (R)keys; if(r.getCode()==200 && "success".equals(r.getMsg())) { Object obj = joinPoint.getArgs(); Object[] obja = (Object[])obj; LoginBody loginBody = (LoginBody)obja[0]; String userName = loginBody.getAccount(); R<LoginUserInfoVO> userR = userService.getUserInfo(userName+"_5"); LoginUserInfoVO loginUserInfoVO = userR.getData(); ShopOperLogVO shopOperlog = new ShopOperLogVO(); try { // 从切面织入点处通过反射机制获取织入点处的方法 MethodSignature signature = (MethodSignature) joinPoint.getSignature(); // 获取切入点所在的方法 Method method = signature.getMethod(); // 获取操作 ShopOperLog opLog = method.getAnnotation(ShopOperLog.class); if (opLog != null) { String operModul = opLog.operModul(); int operType = opLog.operType(); shopOperlog.setTitle(operModul); // 操作模块 shopOperlog.setBusinessType(operType); // 操作类型 } // 获取请求的类名 String className = joinPoint.getTarget().getClass().getName(); // 获取请求的方法名 String methodName = method.getName(); methodName = className + "." + methodName; shopOperlog.setMethod(methodName); // 请求方法 if (joinPoint.getArgs().length > 0) { for (Object o : joinPoint.getArgs()) { if (o instanceof HttpServletRequest || o instanceof HttpServletResponse) { continue; } shopOperlog.setOperParam(JSONObject.toJSONString(o)); // 请求参数 } } shopOperlog.setJsonResult(JSONObject.toJSONString(keys)); // 返回结果 shopOperlog.setAccount(loginUserInfoVO.getAccount()); shopOperlog.setOperName(loginUserInfoVO.getName()); // 请求用户名称 shopOperlog.setOperIp(IPUtil.getIpAddress(request)); // 请求IP shopOperlog.setOperUrl(request.getRequestURI()); // 请求URI shopOperlog.setRequestMethod(request.getMethod()); shopOperlog.setOperLocation(IPUtil.getIpBelongAddress(request)); shopOperlog.setOperTime(new Date()); // 创建时间 shopOperlog.setAccount(loginUserInfoVO.getAccount()); Long communityId = loginUserInfoVO.getCommunityId(); shopOperlog.setCommunityId(null==communityId?0:communityId); shopOperlog.setUserId(loginUserInfoVO.getUserId()); communityService.addShopOperLog(shopOperlog); } catch (Exception e) { e.printStackTrace(); } } } } } springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/java/com/panzhihua/shop_backstage/api/FundsApi.java
New file @@ -0,0 +1,149 @@ package com.panzhihua.shop_backstage.api; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelWriter; import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.panzhihua.common.controller.BaseController; import com.panzhihua.common.interfaces.ShopOperLog; import com.panzhihua.common.model.dtos.shop.*; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.shop.ShopStoreVO; import com.panzhihua.common.service.community.CommunityService; import com.panzhihua.common.utlis.SFTPUtil; import com.panzhihua.shop_backstage.excel.CustomSheetWriteHandler; import com.panzhihua.shop_backstage.utils.ClazzUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.UUID; /** * @ClasssName GoodsApi 商品API * @Description * @Author cedoo * @Date 2021/4/16 * @Version 1.0 **/ @Slf4j @RestController @RequestMapping("/funs") @Api(tags = {"商家后台", "资金管理"}) public class FundsApi extends BaseController { @Resource private CommunityService communityService; @Value("${excel.userurl}") private String excelUrl; // FTP 登录用户名 @Value("${ftp.username}") private String userName; // FTP 登录密码 @Value("${ftp.password}") private String password; // FTP 服务器地址IP地址 @Value("${ftp.host}") private String host; // FTP 端口 @Value("${ftp.port}") private int port; @ApiOperation(value = "订单分页") @PostMapping("/page") public R page(@RequestBody PageComShopFundsSearchDTO pageComShopFundsSearchDTO){ pageComShopFundsSearchDTO.setUserId(getUserId()); ClazzUtils.setIfStringIsEmpty(pageComShopFundsSearchDTO); return communityService.pageShopFunds(pageComShopFundsSearchDTO); } @ApiOperation(value = "资金统计信息") @GetMapping("/stat") public R stat(){ return communityService.getFundsStat(getUserId()); } @ApiOperation(value = "导出表格") @PostMapping("/export") @ShopOperLog(operType = 12) public R export(@RequestBody ComShopFundsExportDTO comShopFundsExportDTO){ ClazzUtils.setIfStringIsEmpty(comShopFundsExportDTO); String url=excelUrl; String uuid= UUID.randomUUID().toString().replace("-",""); //String name=uuid+".xlsx"; String ftpUrl="/mnt/data/web/excel/"; R<ShopStoreVO> storeR = communityService.getUserStoreInfo(getUserId()); if(!R.isOk(storeR)){ return R.fail("用户不是商家"); } ShopStoreVO shopStoreVO = JSONObject.parseObject(JSONObject.toJSONString(storeR.getData()),ShopStoreVO.class); Long userId = this.getUserId(); comShopFundsExportDTO.setUserId(userId); R r=communityService.shopOrderFundsExportData(comShopFundsExportDTO); if (R.isOk(r)) { List<ExcelShopFundsDTO> excelShopFundsDTO = JSONArray.parseArray(JSONArray.toJSONString(r.getData()),ExcelShopFundsDTO.class); if(excelShopFundsDTO==null||excelShopFundsDTO.size()==0){ return R.ok("未找到数据"); } try { SFTPUtil sftp = new SFTPUtil(userName,password,host,port); sftp.login(); String name = shopStoreVO.getName() +"-商家资金流水-" + new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()) + ".xlsx"; boolean existDir = sftp.isExistDir(ftpUrl+name); if (!existDir) { String property = System.getProperty("user.dir"); String fileName = property + File.separator+name; // 这里 需要指定写用哪个class去写 ExcelWriter excelWriter = null; InputStream inputStream=null; try { excelWriter = EasyExcel.write(fileName, ExcelShopFundsDTO.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).registerWriteHandler(new CustomSheetWriteHandler()).build(); WriteSheet writeSheet = EasyExcel.writerSheet(shopStoreVO.getName()+"订单").build(); excelWriter.write(excelShopFundsDTO, writeSheet); excelWriter.finish(); File file=new File(fileName); inputStream=new FileInputStream(file); sftp.uploadMore(ftpUrl, name, inputStream); sftp.logout(); inputStream.close(); String absolutePath = file.getAbsolutePath(); boolean delete = file.delete(); log.info("删除excel【{}】结果【{}】",absolutePath,delete); } finally { // 千万别忘记finish 会帮忙关闭流 if (inputStream != null) { inputStream.close(); } if (excelWriter != null) { excelWriter.finish(); } } } return R.ok(url+ URLEncoder.encode(name,"UTF-8")); } catch (Exception e) { e.printStackTrace(); log.error("文件传输失败【{}】", e.getMessage()); return R.fail(); } } return R.fail("导出数据失败"); } } springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/java/com/panzhihua/shop_backstage/api/GoodsApi.java
New file @@ -0,0 +1,74 @@ package com.panzhihua.shop_backstage.api; import com.panzhihua.common.controller.BaseController; import com.panzhihua.common.model.dtos.shop.ComShopGoodsDTO; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.shop.AddShopGoodsVO; import com.panzhihua.common.service.community.CommunityService; import com.panzhihua.common.validated.PageGroup; import com.panzhihua.common.interfaces.ShopOperLog; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; /** * @ClasssName GoodsApi 商品API * @Description * @Author cedoo * @Date 2021/4/16 * @Version 1.0 **/ @Slf4j @RestController @RequestMapping("/goods") public class GoodsApi extends BaseController { @Resource private CommunityService communityService; @ApiOperation(value = "商品分页搜索") @PostMapping("/page") public R search(@RequestBody @Validated(PageGroup.class) ComShopGoodsDTO comShopGoodsDTO){ return communityService.pageShopGoods(comShopGoodsDTO); } @ApiOperation(value = "添加商品") @ShopOperLog(operType = 3) @PostMapping("/add") public R search(@RequestBody AddShopGoodsVO addShopGoodsVO){ return communityService.saveShopGoods(addShopGoodsVO); } @ApiOperation(value = "编辑商品") @ShopOperLog(operType = 4) @PutMapping("/edit/{id}") R editShopGoods(@PathVariable("id") Long id,@RequestBody AddShopGoodsVO addShopGoodsVO) { return communityService.editShopGoods(id,addShopGoodsVO); } @ApiOperation(value = "下架商品") @ShopOperLog(operType = 5) @PutMapping("/toggleDown/{id}") public R toggleDown(@PathVariable("id") Long id){ return communityService.changeStatus(id,2); } @ApiOperation(value = "上架商品") @ShopOperLog(operType = 6) @PutMapping("/toggleUp/{id}") public R toggleUp(@PathVariable("id") Long id){ return communityService.changeStatus(id,1); } @ApiOperation(value = "删除商品") @ShopOperLog(operType = 7) @DeleteMapping("/delete") R deleteShopGoods(@RequestBody Long[] id) { return communityService.deleteShopGoods(id); } } springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/java/com/panzhihua/shop_backstage/api/LogApi.java
New file @@ -0,0 +1,56 @@ package com.panzhihua.shop_backstage.api; import com.panzhihua.common.controller.BaseController; import com.panzhihua.common.model.dtos.PageDTO; import com.panzhihua.common.model.vos.LoginUserInfoVO; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.service.community.CommunityService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; /** * @ClasssName GoodsApi 商品API * @Description * @Author cedoo * @Date 2021/4/16 * @Version 1.0 **/ @Slf4j @RestController @RequestMapping("/log") @Api(tags = {"商家后台", "操作日志"}) public class LogApi extends BaseController { @Resource private CommunityService communityService; @ApiOperation(value = "登陆用户操作日志") @GetMapping("/page") public R page(@RequestParam("pageNum") Long pageNum, @RequestParam("pageSize") Long pageSize){ PageDTO pageDTO = new PageDTO(); pageDTO.setPageNum(pageNum); pageDTO.setPageSize(pageSize); if(pageNum==null||new Long(0).equals(pageNum.longValue())){ pageDTO.setPageNum(1l); } if(pageSize==null||new Long(0).equals(pageSize.longValue())){ pageDTO.setPageSize(10l); } LoginUserInfoVO loginUserInfoVO = this.getLoginUserInfo(); if(loginUserInfoVO==null){ return R.fail("未登陆"); } pageDTO.setUserId(loginUserInfoVO.getUserId()); return communityService.pageShopOperLog(pageDTO); } } springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/java/com/panzhihua/shop_backstage/api/LoginApi.java
New file @@ -0,0 +1,67 @@ package com.panzhihua.shop_backstage.api; import com.panzhihua.common.controller.BaseController; import com.panzhihua.common.model.vos.LoginUserInfoVO; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.user.ChangePasswordVO; import com.panzhihua.common.service.auth.TokenService; import com.panzhihua.common.service.user.UserService; import com.panzhihua.common.interfaces.ShopOperLog; import com.panzhihua.shop_backstage.model.vos.LoginBody; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.util.ObjectUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @Slf4j @RestController @RequestMapping("/") @Api(tags = {"商家后台", "登录"}) public class LoginApi extends BaseController { @Resource private TokenService tokenService; @Resource private UserService userService; @ApiOperation(value = "商家后台登录") @ShopOperLog(operType = 1) @PostMapping("login") public R login(@RequestBody LoginBody loginBody){ String account = loginBody.getAccount(); String password = loginBody.getPassword(); boolean empty = ObjectUtils.isEmpty(account); boolean empty1 = ObjectUtils.isEmpty(password); if (empty||empty1) { return R.fail("账户密码不能为空"); } log.info("登录用户信息【{}】",loginBody); R r = tokenService.loginShopBackStage(account,password); return r; } @ApiOperation(value = "修改密码") @PutMapping("changepassword") @ShopOperLog(operType = 2) public R changePassword(@Validated @RequestBody ChangePasswordVO changePasswordVO){ Long userId = this.getUserId(); String newPassword = changePasswordVO.getNewPassword(); String oldPassword=changePasswordVO.getOldPassword(); if (newPassword.equals(oldPassword)) { return R.fail("修改失败,新密码和原密码一致"); } changePasswordVO.setUserId(userId); return userService.changePassword(changePasswordVO); } @ApiOperation(value = "当前登录用户信息",response = LoginUserInfoVO.class) @GetMapping("user") public R detailUser(){ Long userId = this.getUserId(); return userService.detailUser(userId); } } springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/java/com/panzhihua/shop_backstage/api/OrderApi.java
New file @@ -0,0 +1,179 @@ package com.panzhihua.shop_backstage.api; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelWriter; import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.panzhihua.common.controller.BaseController; import com.panzhihua.common.model.dtos.shop.*; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.interfaces.ShopOperLog; import com.panzhihua.common.model.vos.shop.ShopStoreVO; import com.panzhihua.common.service.community.CommunityService; import com.panzhihua.common.utlis.SFTPUtil; import com.panzhihua.shop_backstage.excel.CustomSheetWriteHandler; import com.panzhihua.shop_backstage.utils.ClazzUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.UUID; /** * @ClasssName GoodsApi 商品API * @Description * @Author cedoo * @Date 2021/4/16 * @Version 1.0 **/ @Slf4j @RestController @RequestMapping("/order") @Api(tags = {"商家后台", "订单管理"}) public class OrderApi extends BaseController { @Resource private CommunityService communityService; @Value("${excel.userurl}") private String excelUrl; // FTP 登录用户名 @Value("${ftp.username}") private String userName; // FTP 登录密码 @Value("${ftp.password}") private String password; // FTP 服务器地址IP地址 @Value("${ftp.host}") private String host; // FTP 端口 @Value("${ftp.port}") private int port; @ApiOperation(value = "订单分页") @PostMapping("") public R page(@RequestBody @Validated PageComShopOrderSearchDTO pageComShopOrderSearchDTO){ pageComShopOrderSearchDTO.setUserId(this.getUserId()); ClazzUtils.setIfStringIsEmpty(pageComShopOrderSearchDTO); return communityService.pageShopOrder(pageComShopOrderSearchDTO); } @ApiOperation(value = "取消订单") @PutMapping("/cancel") @ShopOperLog(operType = 8) public R cancel(@RequestBody ComShopOrderQueryDTO comShopOrderQueryDTO){ return communityService.orderCancel(comShopOrderQueryDTO); } @ApiOperation(value = "发货") @PutMapping("/ship") @ShopOperLog(operType = 9) public R ship(@RequestBody ComShopOrderShipDTO orderShipDTO){ return communityService.shipOrder(orderShipDTO); } @ApiOperation(value = "配送") @PutMapping("/startDeliver") @ShopOperLog(operType = 10) public R deliver(@RequestBody ComShopOrderDeliverDTO deliverDTO){ return communityService.deliverOrder(deliverDTO); } @ApiOperation(value = "配送完成") @PutMapping("/finishDeliver") public R finishDeliver(@RequestBody ComShopOrderDeliverDTO deliverDTO){ return communityService.finishDeliverOrder(deliverDTO); } @ApiOperation(value = "订单详细") @GetMapping("/detail") @ShopOperLog(operType = 11) public R detail(@RequestParam("orderId") Long orderId){ return communityService.orderDetail(orderId); } @ApiOperation(value = "导出表格") @PostMapping("/export") @ShopOperLog(operType = 12) public R export(@RequestBody ComShopOrderExportDTO comShopOrderExportDTO){ ClazzUtils.setIfStringIsEmpty(comShopOrderExportDTO); String url=excelUrl; String uuid= UUID.randomUUID().toString().replace("-",""); //String name=uuid+".xlsx"; String ftpUrl="/mnt/data/web/excel/"; R<ShopStoreVO> storeR = communityService.getUserStoreInfo(getUserId()); if(!R.isOk(storeR)){ return R.fail("用户不是商家"); } ShopStoreVO shopStoreVO = JSONObject.parseObject(JSONObject.toJSONString(storeR.getData()),ShopStoreVO.class); Long userId = this.getUserId(); comShopOrderExportDTO.setUserId(userId); R r=communityService.shopOrderExportData(comShopOrderExportDTO); if (R.isOk(r)) { List<ExcelShopOrderDTO> excelShopOrderDTO = JSONArray.parseArray(JSONArray.toJSONString(r.getData()),ExcelShopOrderDTO.class); if(excelShopOrderDTO==null||excelShopOrderDTO.size()==0){ return R.ok("未找到数据"); } try { SFTPUtil sftp = new SFTPUtil(userName,password,host,port); sftp.login(); String name = shopStoreVO.getName() +"商城订单-" + new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()) + ".xlsx"; boolean existDir = sftp.isExistDir(ftpUrl+name); if (!existDir) { String property = System.getProperty("user.dir"); String fileName = property + File.separator+name; // 这里 需要指定写用哪个class去写 ExcelWriter excelWriter = null; InputStream inputStream=null; try { excelWriter = EasyExcel.write(fileName, ExcelShopOrderDTO.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).registerWriteHandler(new CustomSheetWriteHandler()).build(); WriteSheet writeSheet = EasyExcel.writerSheet(shopStoreVO.getName()+"订单").build(); excelWriter.write(excelShopOrderDTO, writeSheet); excelWriter.finish(); File file=new File(fileName); inputStream=new FileInputStream(file); sftp.uploadMore(ftpUrl, name, inputStream); sftp.logout(); inputStream.close(); String absolutePath = file.getAbsolutePath(); boolean delete = file.delete(); log.info("删除excel【{}】结果【{}】",absolutePath,delete); } finally { // 千万别忘记finish 会帮忙关闭流 if (inputStream != null) { inputStream.close(); } if (excelWriter != null) { excelWriter.finish(); } } } return R.ok(url+ URLEncoder.encode(name,"UTF-8")); } catch (Exception e) { e.printStackTrace(); log.error("文件传输失败【{}】", e.getMessage()); return R.fail(); } } return R.fail("导出数据失败"); } } springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/java/com/panzhihua/shop_backstage/config/SFTPConfig.java
New file @@ -0,0 +1,30 @@ package com.panzhihua.shop_backstage.config; import lombok.Data; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; /** * @Author: llming * @Description: */ @Configuration @Data public class SFTPConfig { // FTP 登录用户名 @Value("${ftp.username}") private String userName; // FTP 登录密码 @Value("${ftp.password}") private String password; // FTP 服务器地址IP地址 @Value("${ftp.host}") private String host; // FTP 端口 @Value("${ftp.port}") private int port; @Value("${ftp.url}") private String url; @Value("${excel.userurl}") private String excelUrl; } springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/java/com/panzhihua/shop_backstage/config/SwaggerConfig.java
New file @@ -0,0 +1,40 @@ package com.panzhihua.shop_backstage.config; import io.swagger.annotations.ApiOperation; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; 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; /** * @program: springcloud_k8s_panzhihuazhihuishequ * @description: swagger3 * @author: huang.hongfa weixin hhf9596 qq 959656820 * @create: 2020-11-19 16:08 **/ @Configuration public class SwaggerConfig { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("商家后台管理接口") .description("。") .contact(new Contact("Ray。", "http://www.ruiyeclub.cn", "ruiyeclub@foxmail.com")) .version("1.0") .build(); } } springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/java/com/panzhihua/shop_backstage/excel/CustomSheetWriteHandler.java
New file @@ -0,0 +1,47 @@ package com.panzhihua.shop_backstage.excel; import com.alibaba.excel.write.handler.SheetWriteHandler; import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; import com.alibaba.excel.write.metadata.holder.WriteWorkbookHolder; import org.apache.poi.ss.usermodel.DataValidation; import org.apache.poi.ss.usermodel.DataValidationConstraint; import org.apache.poi.ss.usermodel.DataValidationHelper; import org.apache.poi.ss.util.CellRangeAddressList; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * 自定义拦截器.对第一列第一行和第二行的数据新增下拉框,显示 测试1 测试2 * * @author Jiaju Zhuang */ public class CustomSheetWriteHandler implements SheetWriteHandler { private static final Logger LOGGER = LoggerFactory.getLogger(CustomSheetWriteHandler.class); @Override public void beforeSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) { } @Override public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) { LOGGER.info("第{}个Sheet写入成功。", writeSheetHolder.getSheetNo()); // 区间设置 第一列第一行和第二行的数据。由于第一行是头,所以第一、二行的数据实际上是第二三行 CellRangeAddressList cellRangeAddressList = new CellRangeAddressList(1, 2000, 1, 1); CellRangeAddressList cellRangeAddressList1 = new CellRangeAddressList(1, 2000, 3 ,3); CellRangeAddressList cellRangeAddressList2 = new CellRangeAddressList(1, 2000, 10 ,10); DataValidationHelper helper = writeSheetHolder.getSheet().getDataValidationHelper(); DataValidationConstraint constraint = helper.createExplicitListConstraint(new String[] {"是", "否"}); DataValidationConstraint constraint1 = helper.createExplicitListConstraint(new String[] {"中共党员","中共预备党员","共青团员","民革党员","民盟盟员","民建会员","农工党党员","致公党党员","九三学社社员","台盟盟员","无党派人士","群众"}); DataValidationConstraint constraint2 = helper.createExplicitListConstraint(new String[] {"男", "女","未知"}); DataValidation dataValidation = helper.createValidation(constraint2, cellRangeAddressList); DataValidation dataValidation1 = helper.createValidation(constraint, cellRangeAddressList1); DataValidation dataValidation2= helper.createValidation(constraint1, cellRangeAddressList2); writeSheetHolder.getSheet().addValidationData(dataValidation); writeSheetHolder.getSheet().addValidationData(dataValidation1); writeSheetHolder.getSheet().addValidationData(dataValidation2); } } springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/java/com/panzhihua/shop_backstage/model/vos/LoginBody.java
New file @@ -0,0 +1,26 @@ package com.panzhihua.shop_backstage.model.vos; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; /** * @program: springcloud_k8s_panzhihuazhihuishequ * @description: 登录 * @author: huang.hongfa weixin hhf9596 qq 959656820 * @create: 2020-11-24 10:54 **/ @Data @ApiModel(value = "小程序后台登录") @AllArgsConstructor @NoArgsConstructor public class LoginBody { @ApiModelProperty(value = "登录账户") private String account; @ApiModelProperty(value = "登录密码") private String password; } springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/java/com/panzhihua/shop_backstage/utils/ClazzUtils.java
New file @@ -0,0 +1,52 @@ package com.panzhihua.shop_backstage.utils; import com.panzhihua.common.model.dtos.shop.PageComShopOrderSearchDTO; import java.lang.reflect.Field; import java.text.DecimalFormat; import java.util.Arrays; /** * 工具类 */ public class ClazzUtils { /** * 如果string属性为“”, 则将其设置为NULL * @param o */ public static void setIfStringIsEmpty(Object o){ if(o==null){ return; } Class clazz = o.getClass(); Field[] fields = clazz.getDeclaredFields(); Arrays.stream(fields).forEach(field -> { if(String.class == field.getType()){ try { field.setAccessible(true); if(field.get(o)!=null) { String oVal = (String) field.get(o); if ("".equals(oVal)) { field.set(o, null); } } } catch (IllegalAccessException e) { } } }); } public static void main(String[] args){ PageComShopOrderSearchDTO dto = new PageComShopOrderSearchDTO(); dto.setGoodsName(""); dto.setOrderNo("123"); setIfStringIsEmpty(dto); System.out.println(dto); double d = 1234.200; DecimalFormat df = new DecimalFormat("0.00"); System.out.println(df.format(d)); } } springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/resources/bootstrap.yml
New file @@ -0,0 +1,22 @@ spring: application: name: shopbackstage cloud: config: discovery: enabled: true service-id: config # 注册中心的服务名 profile: ${ENV:dev} # 指定配置文件的环境 uri: http://${CONFIG_URL:localhost}:8193/ profiles: active: ${ENV:dev} servlet: multipart: max-file-size: 10MB max-request-size: 10MB eureka: client: service-url: defaultZone: http://${EUREKA_URL:localhost}:8192/eureka springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/resources/logback-spring.xml
New file @@ -0,0 +1,51 @@ <?xml version="1.0" encoding="UTF-8"?> <configuration debug="false"> <!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径--> <springProfile name="dev"> <property name="LOG_HOME" value="F:/log" /> </springProfile> <springProfile name="test"> <property name="LOG_HOME" value="/mnt/data/gocd/log" /> </springProfile> <property name="LOG_HOME" value="/mnt/data/gocd/log" /> <!-- 控制台输出 --> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符--> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> </encoder> </appender> <!-- 按照每天生成日志文件 --> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!--日志文件输出的文件名--> <FileNamePattern>${LOG_HOME}/community_backstage.log.%d{yyyy-MM-dd}.log</FileNamePattern> <!--日志文件保留天数--> <MaxHistory>30</MaxHistory> </rollingPolicy> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符--> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern> </encoder> <!--日志文件最大的大小--> <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> <MaxFileSize>10MB</MaxFileSize> </triggeringPolicy> </appender> <!--myibatis log configure--> <logger name="com.apache.ibatis" level="TRACE"/> <logger name="java.sql.Connection" level="DEBUG"/> <logger name="java.sql.Statement" level="DEBUG"/> <logger name="java.sql.PreparedStatement" level="DEBUG"/> <logger name="com.panzhihua.community_backstage" level="DEBUG"/> <!-- 日志输出级别 --> <root level="DEBUG"> <appender-ref ref="STDOUT" /> </root> <root level="INFO"> <appender-ref ref="STDOUT" /> <appender-ref ref="FILE" /> </root> </configuration>