From 2ed7494790b21d5227df7b01ec7c1df0ea5951e8 Mon Sep 17 00:00:00 2001 From: Sum1Dream <418471657@qq.com> Date: Fri, 27 May 2022 14:52:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OutRechargePriceController.java | 6 +- .../OutRechargeOrderController.java | 10 +- .../OutRechargePriceController.java | 7 +- .../hai/service/OutRechargePriceService.java | 3 +- .../hai/service/impl/BsConfigServiceImpl.java | 22 ++- .../impl/OutRechargeOrderServiceImpl.java | 46 ++++--- .../impl/OutRechargePriceServiceImpl.java | 4 +- pom.xml | 1 + v1/pom.xml | 45 ++++++ v1/src/main/java/com/V1Application.java | 28 ++++ .../main/java/com/v1/config/AuthConfig.java | 128 ++++++++++++++++++ .../java/com/v1/config/ConfigListener.java | 24 ++++ .../main/java/com/v1/config/CorsConfig.java | 49 +++++++ .../java/com/v1/config/MultipartConfig.java | 26 ++++ .../main/java/com/v1/config/RedisConfig.java | 109 +++++++++++++++ .../java/com/v1/config/SignatureConfig.java | 4 + .../java/com/v1/config/SwaggerConfig.java | 47 +++++++ v1/src/main/java/com/v1/config/SysConfig.java | 13 ++ v1/src/main/java/com/v1/config/SysConst.java | 19 +++ v1/src/main/resources/dev/application.yml | 56 ++++++++ v1/src/main/resources/dev/config.properties | 0 v1/src/main/resources/dev/logback.xml | 72 ++++++++++ v1/src/main/resources/pre/application.yml | 56 ++++++++ v1/src/main/resources/pre/config.properties | 0 v1/src/main/resources/pre/logback.xml | 72 ++++++++++ v1/src/main/resources/prod/application.yml | 74 ++++++++++ v1/src/main/resources/prod/config.properties | 0 v1/src/main/resources/prod/logback.xml | 72 ++++++++++ 28 files changed, 959 insertions(+), 34 deletions(-) create mode 100644 v1/pom.xml create mode 100644 v1/src/main/java/com/V1Application.java create mode 100644 v1/src/main/java/com/v1/config/AuthConfig.java create mode 100644 v1/src/main/java/com/v1/config/ConfigListener.java create mode 100644 v1/src/main/java/com/v1/config/CorsConfig.java create mode 100644 v1/src/main/java/com/v1/config/MultipartConfig.java create mode 100644 v1/src/main/java/com/v1/config/RedisConfig.java create mode 100644 v1/src/main/java/com/v1/config/SignatureConfig.java create mode 100644 v1/src/main/java/com/v1/config/SwaggerConfig.java create mode 100644 v1/src/main/java/com/v1/config/SysConfig.java create mode 100644 v1/src/main/java/com/v1/config/SysConst.java create mode 100644 v1/src/main/resources/dev/application.yml create mode 100644 v1/src/main/resources/dev/config.properties create mode 100644 v1/src/main/resources/dev/logback.xml create mode 100644 v1/src/main/resources/pre/application.yml create mode 100644 v1/src/main/resources/pre/config.properties create mode 100644 v1/src/main/resources/pre/logback.xml create mode 100644 v1/src/main/resources/prod/application.yml create mode 100644 v1/src/main/resources/prod/config.properties create mode 100644 v1/src/main/resources/prod/logback.xml diff --git a/hai-bweb/src/main/java/com/bweb/controller/OutRechargePriceController.java b/hai-bweb/src/main/java/com/bweb/controller/OutRechargePriceController.java index 9d713f07..765a00f2 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/OutRechargePriceController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/OutRechargePriceController.java @@ -188,7 +188,7 @@ public class OutRechargePriceController { object.put("integralDiscount" , new BigDecimal(0)); } - OutRechargePriceModel outRechargePrice = outRechargePriceService.findById(object.getLong("id")); + OutRechargePriceModel outRechargePrice = outRechargePriceService.findById(object.getLong("id") , null); if (outRechargePrice == null) { log.error("OutRechargePriceController -> updatePrice() error!"); @@ -225,7 +225,7 @@ public class OutRechargePriceController { public ResponseData findById(@RequestParam(value = "id", required = true) Long id) { try { - OutRechargePriceModel outRechargePriceModel = outRechargePriceService.findById(id); + OutRechargePriceModel outRechargePriceModel = outRechargePriceService.findById(id , null); return ResponseMsgUtil.success(outRechargePriceModel); } catch (Exception e) { @@ -258,7 +258,7 @@ public class OutRechargePriceController { SessionObject sessionObject = userCenter.getSessionObject(request); UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); - OutRechargePrice outRechargePrice = outRechargePriceService.findById(object.getLong("id")); + OutRechargePrice outRechargePrice = outRechargePriceService.findById(object.getLong("id") , null); if (object.getInteger("status") == 1 && outRechargePrice.getRechargePlatform().contains("-2-") && outRechargePrice.getGoodsId() == null) { log.error("OutRechargePriceController -> editPriceStatus() error!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "龙阅平台需要输入商品编码!"); diff --git a/hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java b/hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java index fae8221e..a2bae762 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java @@ -48,9 +48,6 @@ public class OutRechargeOrderController { @Resource private SecConfigService secConfigService; - @Resource - private HighUserCardService highUserCardService; - @Resource private HighUserPayPasswordService highUserPayPasswordService; @@ -91,7 +88,7 @@ public class OutRechargeOrderController { String rechargeContent = object.getString("rechargeContent"); // 查询产品详情 - OutRechargePriceModel outRechargePrice = outRechargePriceService.findById(goodsId); + OutRechargePriceModel outRechargePrice = outRechargePriceService.findById(goodsId , null); Map listMap = new HashMap<>(); listMap.put("productType", "3"); @@ -174,6 +171,11 @@ public class OutRechargeOrderController { if (object.getLong("integralNum") > 0 && bsProductDiscount.getDiscount().compareTo(new BigDecimal("0")) > 0) { + // 判断用户积分是否够 + if (object.getLong("integralNum") > userInfoModel.getHighUser().getGold()) { + log.error("HighOrderController --> addOrder() error!", "积分大于用户积分额度"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "用户积分" + userInfoModel.getHighUser().getGold()); + } // 积分抵扣金额 BigDecimal integralDeductionPrice = BigDecimal.valueOf(object.getLong("integralNum") / 100); diff --git a/hai-cweb/src/main/java/com/cweb/controller/OutRechargePriceController.java b/hai-cweb/src/main/java/com/cweb/controller/OutRechargePriceController.java index 46cce46b..b2157a73 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/OutRechargePriceController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/OutRechargePriceController.java @@ -88,10 +88,13 @@ public class OutRechargePriceController { @RequestMapping(value = "/findById", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "根据id查询详情") - public ResponseData findById(@RequestParam(value = "id", required = true) Long id) { + public ResponseData findById( + @RequestParam(value = "id", required = true) Long id , + @RequestParam(value = "platformId", required = true) Integer platformId + ) { try { - OutRechargePriceModel outRechargePriceModel = outRechargePriceService.findById(id); + OutRechargePriceModel outRechargePriceModel = outRechargePriceService.findById(id , platformId); return ResponseMsgUtil.success(outRechargePriceModel); } catch (Exception e) { diff --git a/hai-service/src/main/java/com/hai/service/OutRechargePriceService.java b/hai-service/src/main/java/com/hai/service/OutRechargePriceService.java index f4795b61..eb69e260 100644 --- a/hai-service/src/main/java/com/hai/service/OutRechargePriceService.java +++ b/hai-service/src/main/java/com/hai/service/OutRechargePriceService.java @@ -3,6 +3,7 @@ package com.hai.service; import com.alibaba.fastjson.JSONObject; import com.hai.entity.OutRechargePrice; import com.hai.model.OutRechargePriceModel; +import io.swagger.models.auth.In; import java.util.List; import java.util.Map; @@ -34,7 +35,7 @@ public interface OutRechargePriceService { * @Param [id] * @return com.hai.entity.OutRechargePrice **/ - OutRechargePriceModel findById(Long id); + OutRechargePriceModel findById(Long id , Integer platformId); /** * @Author Sum1Dream diff --git a/hai-service/src/main/java/com/hai/service/impl/BsConfigServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/BsConfigServiceImpl.java index 38e8f85e..3f68a290 100644 --- a/hai-service/src/main/java/com/hai/service/impl/BsConfigServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/BsConfigServiceImpl.java @@ -78,7 +78,7 @@ public class BsConfigServiceImpl implements BsConfigService { public String getProductPayTypeByMap(Map map) { BsProductPayTypeExample example = new BsProductPayTypeExample(); BsProductPayTypeExample.Criteria criteria = example.createCriteria(); - + Integer platformId = MapUtils.getInteger(map , "platformId"); if (MapUtils.getInteger(map , "productType") != null) { criteria.andProductTypeEqualTo(MapUtils.getInteger(map , "productType")); } @@ -92,9 +92,25 @@ public class BsConfigServiceImpl implements BsConfigService { StringBuilder stringName = new StringBuilder(); StringBuilder string = new StringBuilder(); + // 1:支付宝 2:微信 3:汇联通工会卡 4:银联 5:银联分期 for (BsProductPayType productPayType : list) { - stringName.append(productPayType.getPayTypeName()).append(","); - string.append(productPayType.getPayTypeId()).append(","); + if (platformId != null) { + if (platformId == 1 || platformId == 2) { + if (productPayType.getPayTypeId() == 2 || productPayType.getPayTypeId() == 3) { + stringName.append(productPayType.getPayTypeName()).append(","); + string.append(productPayType.getPayTypeId()).append(","); + } + } else if (platformId == 3) { + if (productPayType.getPayTypeId() == 4 || productPayType.getPayTypeId() == 5) { + stringName.append(productPayType.getPayTypeName()).append(","); + string.append(productPayType.getPayTypeId()).append(","); + } + } + } else { + stringName.append(productPayType.getPayTypeName()).append(","); + string.append(productPayType.getPayTypeId()).append(","); + } + } if (MapUtils.getInteger(map , "returnType") == 1) { diff --git a/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java index 97785206..8589aa60 100644 --- a/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java @@ -178,25 +178,31 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { @Transactional(propagation= Propagation.REQUIRES_NEW) public void cancelOrder(Long orderId) { OutRechargeOrder order = findByOrderId(orderId); -// if (order != null && order.getStatus() == 1) { -// order.setStatus(4); // 订单状态:1 待支付 2 已支付 3.已完成 4. 已取消 5.已退款 -// order.setCancelTime(new Date()); -// -// if (order.getMemDiscountId() != null) { -// HighDiscountUserRel rel = highDiscountUserRelService.getRelById(order.getMemDiscountId()); -// if (rel != null) { -// rel.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 -// rel.setUseTime(null); -// highDiscountUserRelService.updateDiscountUserRel(rel); -// -// HighDiscountAgentCode code = highDiscountAgentCodeService.getCodeById(rel.getDiscountAgentCodeId()); -// code.setStatus(2); -// highDiscountAgentCodeService.updateCode(code); -// } -// } -// -// updateOrder(order); -// } + if (order != null && order.getPayStatus() == 101) { + // 101.待支付 102.已支付 100.已完成 104.已取消 105.已退款 + order.setPayStatus(104); + order.setCancelTime(new Date()); + + if (order.getMemDiscountId() != null) { + HighDiscountUserRel rel = highDiscountUserRelService.getRelById(order.getMemDiscountId()); + if (rel != null) { + rel.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 + rel.setUseTime(null); + highDiscountUserRelService.updateDiscountUserRel(rel); + + HighDiscountAgentCode code = highDiscountAgentCodeService.getCodeById(rel.getDiscountAgentCodeId()); + code.setStatus(2); + highDiscountAgentCodeService.updateCode(code); + } + } + + if (order.getIntegralNum() != null) { + // 积分返回 + highUserService.goldHandle(order.getUserId(), order.getIntegralNum().intValue(), 1, 3, order.getId()); + } + + updateOrder(order); + } } @@ -512,7 +518,7 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { public void pollRequest(OutRechargeOrder outRechargeOrder) throws Exception { // 查询充值产品 - OutRechargePriceModel outRechargePrice = outRechargePriceService.findById(outRechargeOrder.getGoodsId()); + OutRechargePriceModel outRechargePrice = outRechargePriceService.findById(outRechargeOrder.getGoodsId() , null); // 查询充值子订单 Map childOrderMap = new HashMap<>(); diff --git a/hai-service/src/main/java/com/hai/service/impl/OutRechargePriceServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/OutRechargePriceServiceImpl.java index 3cde6aae..e356627e 100644 --- a/hai-service/src/main/java/com/hai/service/impl/OutRechargePriceServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/OutRechargePriceServiceImpl.java @@ -71,7 +71,7 @@ public class OutRechargePriceServiceImpl implements OutRechargePriceService { @Override - public OutRechargePriceModel findById(Long id) { + public OutRechargePriceModel findById(Long id , Integer platformId) { OutRechargePrice outRechargePrice = outRechargePriceMapper.selectByPrimaryKey(id); @@ -82,6 +82,7 @@ public class OutRechargePriceServiceImpl implements OutRechargePriceService { listMap.put("productType", "3"); listMap.put("returnType", 1); listMap.put("sourceId", outRechargePrice.getId()); + listMap.put("platformId", platformId); outRechargePriceModel.setIntegralDiscount(bsConfigService.getProductDiscountByMap(listMap).getDiscount()); outRechargePriceModel.setProductPayTypeString(bsConfigService.getProductPayTypeByMap(listMap)); @@ -89,6 +90,7 @@ public class OutRechargePriceServiceImpl implements OutRechargePriceService { return outRechargePriceModel; } + @Override @Transactional(propagation = Propagation.REQUIRES_NEW) public void insertRechargePrice(JSONObject object) { diff --git a/pom.xml b/pom.xml index 681a20d1..a0f74f18 100644 --- a/pom.xml +++ b/pom.xml @@ -67,6 +67,7 @@ hai-schedule hai-order hai-msg + v1 diff --git a/v1/pom.xml b/v1/pom.xml new file mode 100644 index 00000000..600d4c42 --- /dev/null +++ b/v1/pom.xml @@ -0,0 +1,45 @@ + + + + com.hai + hai-parent + 1.0-SNAPSHOT + + 4.0.0 + + com.hgj + hai-v1 + + + + com.hai + hai-service + PACKT-SNAPSHOT + + + + + + + src/main/resources/${env} + false + + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/v1/src/main/java/com/V1Application.java b/v1/src/main/java/com/V1Application.java new file mode 100644 index 00000000..d9e44505 --- /dev/null +++ b/v1/src/main/java/com/V1Application.java @@ -0,0 +1,28 @@ +package com; + +import com.hai.common.utils.SpringContextUtil; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.ServletComponentScan; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@SpringBootApplication +// @ComponentScan +@EnableTransactionManagement +@EnableScheduling +@ServletComponentScan +@EnableAspectJAutoProxy(proxyTargetClass = true) +@MapperScan("com.hai.dao") +public class V1Application +{ + public static void main( String[] args ) + { + ApplicationContext app = SpringApplication.run(V1Application.class, args); + SpringContextUtil.setApplicationContext(app); + } + +} diff --git a/v1/src/main/java/com/v1/config/AuthConfig.java b/v1/src/main/java/com/v1/config/AuthConfig.java new file mode 100644 index 00000000..c50c1bf6 --- /dev/null +++ b/v1/src/main/java/com/v1/config/AuthConfig.java @@ -0,0 +1,128 @@ +package com.v1.config; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import com.hai.common.security.UserCenter; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +@Configuration +public class AuthConfig implements WebMvcConfigurer { + + private static Logger log = LoggerFactory.getLogger(AuthConfig.class); + + @Autowired + private UserCenter userCenter; + + /** + * 获取配置文件debug变量 + */ + @Value("${debug}") + private boolean debug = false; + + /** + * 解决18位long类型数据转json失去精度问题 + * @param converters + */ + @Override + public void configureMessageConverters(List> converters){ + MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter(); + + ObjectMapper objectMapper = jsonConverter.getObjectMapper(); + SimpleModule simpleModule = new SimpleModule(); + simpleModule.addSerializer(Long.class, ToStringSerializer.instance); + simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); + objectMapper.registerModule(simpleModule); + + converters.add(jsonConverter); + } + + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(new HandlerInterceptorAdapter() { + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, + Object handler) throws Exception { + if(debug){ + return true; + } + String token = request.getParameter("Authorization"); + if (StringUtils.isBlank(token)) { + token = request.getHeader("Authorization"); + } + if((StringUtils.isNotBlank(token) && userCenter.isTokenLogin(token)) || userCenter.isLogin(request)){//如果未登录,将无法使用任何接口 + userCenter.refreshCookie(request, response); + return true; + } else if(request instanceof StandardMultipartHttpServletRequest) { + StandardMultipartHttpServletRequest re = (StandardMultipartHttpServletRequest)request; + if(userCenter.isLogin(re.getRequest())){ + return true; + } else { + log.error("the user is not logged in,remoteAddr:"+getIpAddress(request)+",requestUrl:"+request.getRequestURL()); + response.setStatus(401); + return false; + } + } else{ + log.error("the user is not logged in,remoteAddr:"+getIpAddress(request)+",requestUrl:"+request.getRequestURL()); + response.setStatus(401); + return false; + } + } + }) + .addPathPatterns("/**") + .excludePathPatterns("/swagger-resources/**") + .excludePathPatterns("/**/api-docs") + .excludePathPatterns("/**/springfox-swagger-ui/**") + .excludePathPatterns("/**/swagger-ui.html") + .excludePathPatterns("/websocket/*") + ; + } + + public String getIpAddress(HttpServletRequest request) { + // 获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址 + String ip = request.getHeader("X-Forwarded-For"); + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("Proxy-Client-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("WL-Proxy-Client-IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_CLIENT_IP"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getHeader("HTTP_X_FORWARDED_FOR"); + } + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { + ip = request.getRemoteAddr(); + } + } else if (ip.length() > 15) { + String[] ips = ip.split(","); + for (int index = 0; index < ips.length; index++) { + String strIp = ips[index]; + if (!("unknown".equalsIgnoreCase(strIp))) { + ip = strIp; + break; + } + } + } + return ip; + } + +} diff --git a/v1/src/main/java/com/v1/config/ConfigListener.java b/v1/src/main/java/com/v1/config/ConfigListener.java new file mode 100644 index 00000000..f1e7390e --- /dev/null +++ b/v1/src/main/java/com/v1/config/ConfigListener.java @@ -0,0 +1,24 @@ +package com.v1.config; + +import org.springframework.beans.factory.annotation.Autowired; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.servlet.annotation.WebListener; + +@WebListener +public class ConfigListener implements ServletContextListener { + + @Autowired + private SysConfig sysConfig; + + @Override + public void contextInitialized(ServletContextEvent sce) { + SysConst.setSysConfig(sysConfig); + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + } + +} diff --git a/v1/src/main/java/com/v1/config/CorsConfig.java b/v1/src/main/java/com/v1/config/CorsConfig.java new file mode 100644 index 00000000..db418670 --- /dev/null +++ b/v1/src/main/java/com/v1/config/CorsConfig.java @@ -0,0 +1,49 @@ +package com.v1.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; + +import java.util.ArrayList; +import java.util.List; + +/** + * @ClassName CorsConfig + * @Description: TODO () + * @Author 胡锐 + * @Date 2020/12/16 + **/ +@Configuration +public class CorsConfig extends WebMvcConfigurerAdapter { + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOrigins("*") + .allowCredentials(true) + .allowedMethods("GET", "POST", "DELETE", "PUT") + .maxAge(3600); + } + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + List list = new ArrayList<>(); + list.add("*"); + corsConfiguration.setAllowedOrigins(list); + /* + // 请求常用的三种配置,*代表允许所有,当时你也可以自定义属性(比如header只能带什么,只能是post方式等等) + */ + corsConfiguration.addAllowedOrigin("*"); + corsConfiguration.addAllowedHeader("*"); + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; + } + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } +} diff --git a/v1/src/main/java/com/v1/config/MultipartConfig.java b/v1/src/main/java/com/v1/config/MultipartConfig.java new file mode 100644 index 00000000..bbb740a0 --- /dev/null +++ b/v1/src/main/java/com/v1/config/MultipartConfig.java @@ -0,0 +1,26 @@ +package com.v1.config; + +import org.springframework.boot.web.servlet.MultipartConfigFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.servlet.MultipartConfigElement; + +@Configuration +public class MultipartConfig { + + /** + * 文件上传配置 + * @return + */ + @Bean + public MultipartConfigElement multipartConfigElement() { + MultipartConfigFactory factory = new MultipartConfigFactory(); + //文件最大 + factory.setMaxFileSize("300MB"); //KB,MB + //设置总上传数据总大小 + factory.setMaxRequestSize("350MB"); + return factory.createMultipartConfig(); + } + +} diff --git a/v1/src/main/java/com/v1/config/RedisConfig.java b/v1/src/main/java/com/v1/config/RedisConfig.java new file mode 100644 index 00000000..295cb9b8 --- /dev/null +++ b/v1/src/main/java/com/v1/config/RedisConfig.java @@ -0,0 +1,109 @@ +package com.v1.config; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.cache.annotation.CachingConfigurerSupport; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.*; +import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.StringRedisSerializer; + + +@Configuration +@EnableCaching //开启注解 +public class RedisConfig extends CachingConfigurerSupport { + + /** + * retemplate相关配置 + * @param factory + * @return + */ + @Bean + public RedisTemplate redisTemplate(RedisConnectionFactory factory) { + + RedisTemplate template = new RedisTemplate<>(); + // 配置连接工厂 + template.setConnectionFactory(factory); + + //使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值(默认使用JDK的序列化方式) + Jackson2JsonRedisSerializer jacksonSeial = new Jackson2JsonRedisSerializer(Object.class); + + ObjectMapper om = new ObjectMapper(); + // 指定要序列化的域,field,get和set,以及修饰符范围,ANY是都有包括private和public + om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); + // 指定序列化输入的类型,类必须是非final修饰的,final修饰的类,比如String,Integer等会跑出异常 + om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); + jacksonSeial.setObjectMapper(om); + + // 值采用json序列化 + template.setValueSerializer(jacksonSeial); + //使用StringRedisSerializer来序列化和反序列化redis的key值 + template.setKeySerializer(new StringRedisSerializer()); + + // 设置hash key 和value序列化模式 + template.setHashKeySerializer(new StringRedisSerializer()); + template.setHashValueSerializer(jacksonSeial); + template.afterPropertiesSet(); + + return template; + } + + /** + * 对hash类型的数据操作 + * + * @param redisTemplate + * @return + */ + @Bean + public HashOperations hashOperations(RedisTemplate redisTemplate) { + return redisTemplate.opsForHash(); + } + + /** + * 对redis字符串类型数据操作 + * + * @param redisTemplate + * @return + */ + @Bean + public ValueOperations valueOperations(RedisTemplate redisTemplate) { + return redisTemplate.opsForValue(); + } + + /** + * 对链表类型的数据操作 + * + * @param redisTemplate + * @return + */ + @Bean + public ListOperations listOperations(RedisTemplate redisTemplate) { + return redisTemplate.opsForList(); + } + + /** + * 对无序集合类型的数据操作 + * + * @param redisTemplate + * @return + */ + @Bean + public SetOperations setOperations(RedisTemplate redisTemplate) { + return redisTemplate.opsForSet(); + } + + /** + * 对有序集合类型的数据操作 + * + * @param redisTemplate + * @return + */ + @Bean + public ZSetOperations zSetOperations(RedisTemplate redisTemplate) { + return redisTemplate.opsForZSet(); + } +} diff --git a/v1/src/main/java/com/v1/config/SignatureConfig.java b/v1/src/main/java/com/v1/config/SignatureConfig.java new file mode 100644 index 00000000..bc27520c --- /dev/null +++ b/v1/src/main/java/com/v1/config/SignatureConfig.java @@ -0,0 +1,4 @@ +package com.v1.config; + +public class SignatureConfig { +} diff --git a/v1/src/main/java/com/v1/config/SwaggerConfig.java b/v1/src/main/java/com/v1/config/SwaggerConfig.java new file mode 100644 index 00000000..2f97941d --- /dev/null +++ b/v1/src/main/java/com/v1/config/SwaggerConfig.java @@ -0,0 +1,47 @@ +package com.v1.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +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; + +/** +* SwaggerConfig.java +* 项目名称: +* 包: +* 类名称: SwaggerConfig.java +* 类描述: 构建restful api接口文档 +* 创建人: +* 创建时间: 2017 下午4:23:45 +*/ +@Configuration +@EnableSwagger2 +public class SwaggerConfig +{ + + /** + * 描述api的基本信息 + * 基本信息会展现在文档页面中 + * @return [api的基本信息] + */ + ApiInfo apiInfo() + { + return new ApiInfoBuilder().title("hgj-BWeb").description("提供给管理平台的接口").termsOfServiceUrl("").version("1.0.0") + .contact(new Contact("", "", "")).build(); + } + + @Bean + public Docket customImplementation() + { + return new Docket(DocumentationType.SWAGGER_2).select() + .apis(RequestHandlerSelectors.basePackage("com")) + .build().directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class) + .directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class).apiInfo(apiInfo()); + } + +} diff --git a/v1/src/main/java/com/v1/config/SysConfig.java b/v1/src/main/java/com/v1/config/SysConfig.java new file mode 100644 index 00000000..47b1abec --- /dev/null +++ b/v1/src/main/java/com/v1/config/SysConfig.java @@ -0,0 +1,13 @@ +package com.v1.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.PropertySource; +import org.springframework.stereotype.Component; + +@Component("sysConfig") +@ConfigurationProperties +@PropertySource("classpath:/config.properties") +public class SysConfig { + + +} diff --git a/v1/src/main/java/com/v1/config/SysConst.java b/v1/src/main/java/com/v1/config/SysConst.java new file mode 100644 index 00000000..b4ff498a --- /dev/null +++ b/v1/src/main/java/com/v1/config/SysConst.java @@ -0,0 +1,19 @@ +package com.v1.config; + +public class SysConst { + + private static SysConfig sysConfig; + + public static void setSysConfig(SysConfig arg){ + sysConfig = arg; + } + + public static SysConfig getSysConfig(){ + if (null == sysConfig) { + //防止空指针异常 + sysConfig = new SysConfig(); + return sysConfig; + } + return sysConfig; + } +} diff --git a/v1/src/main/resources/dev/application.yml b/v1/src/main/resources/dev/application.yml new file mode 100644 index 00000000..f0e71e2f --- /dev/null +++ b/v1/src/main/resources/dev/application.yml @@ -0,0 +1,56 @@ +server: + port: 9902 + servlet: + context-path: /v1 + +#配置是否为debug模式,debug模式下,不开启权限校验 +debug: false + +#datasource数据源设置 +spring: + datasource: + url: jdbc:mysql://139.159.177.244:3306/hfkj?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false + username: root + password: HF123456. + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.jdbc.Driver + filters: stat + maxActive: 10 + initialSize: 5 + maxWait: 60000 + minIdle: 5 + timeBetweenEvictionRunsMillis: 60000 + minEvictableIdleTimeMillis: 300000 + validationQuery: select 'x' + testWhileIdle: true + testOnBorrow: false + testOnReturn: false + poolPreparedStatements: true + maxOpenPreparedStatements: 20 + redis: + database: 0 + host: 139.159.177.244 + port: 36379 + password: HF123456.Redis + timeout: 36000000 + jedis: + pool: + max-active: 20 + max-wait: -1 + max-idle: 10 + min-idle: 0 + #配置日期返回至前台为时间戳 + jackson: + serialization: + write-dates-as-timestamps: true +mybatis: + mapperLocations: + - classpath*:sqlmap*/*.xml + type-aliases-package: + org.springboot.sample.entity + +pagehelper: + helperDialect: mysql + reasonable: true + supportMethodsArguments: true + params: count=countSql diff --git a/v1/src/main/resources/dev/config.properties b/v1/src/main/resources/dev/config.properties new file mode 100644 index 00000000..e69de29b diff --git a/v1/src/main/resources/dev/logback.xml b/v1/src/main/resources/dev/logback.xml new file mode 100644 index 00000000..a7602e3d --- /dev/null +++ b/v1/src/main/resources/dev/logback.xml @@ -0,0 +1,72 @@ + + + + + %d %p (%file:%line\)- %m%n + UTF-8 + + + + log/base.log + + log/base.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + log/dao.log + + log/dao.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + log/error.log + + log/error.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + + + + + + + + + + + + diff --git a/v1/src/main/resources/pre/application.yml b/v1/src/main/resources/pre/application.yml new file mode 100644 index 00000000..1b034025 --- /dev/null +++ b/v1/src/main/resources/pre/application.yml @@ -0,0 +1,56 @@ +server: + port: 9902 + servlet: + context-path: /v1 + +#配置是否为debug模式,debug模式下,不开启权限校验 +debug: false + +#datasource数据源设置 +spring: + datasource: + url: jdbc:mysql://122.9.135.148:3306/hsg?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false + username: root + password: HF123456. + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.jdbc.Driver + filters: stat + maxActive: 10 + initialSize: 5 + maxWait: 60000 + minIdle: 5 + timeBetweenEvictionRunsMillis: 60000 + minEvictableIdleTimeMillis: 300000 + validationQuery: select 'x' + testWhileIdle: true + testOnBorrow: false + testOnReturn: false + poolPreparedStatements: true + maxOpenPreparedStatements: 20 + redis: + database: 1 + host: 139.159.177.244 + port: 36379 + password: HF123456.Redis + timeout: 1000 + jedis: + pool: + max-active: 20 + max-wait: -1 + max-idle: 10 + min-idle: 0 + #配置日期返回至前台为时间戳 + jackson: + serialization: + write-dates-as-timestamps: true +mybatis: + mapperLocations: + - classpath*:sqlmap*/*.xml + type-aliases-package: + org.springboot.sample.entity + +pagehelper: + helperDialect: mysql + reasonable: true + supportMethodsArguments: true + params: count=countSql diff --git a/v1/src/main/resources/pre/config.properties b/v1/src/main/resources/pre/config.properties new file mode 100644 index 00000000..e69de29b diff --git a/v1/src/main/resources/pre/logback.xml b/v1/src/main/resources/pre/logback.xml new file mode 100644 index 00000000..a7602e3d --- /dev/null +++ b/v1/src/main/resources/pre/logback.xml @@ -0,0 +1,72 @@ + + + + + %d %p (%file:%line\)- %m%n + UTF-8 + + + + log/base.log + + log/base.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + log/dao.log + + log/dao.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + log/error.log + + log/error.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + + + + + + + + + + + + diff --git a/v1/src/main/resources/prod/application.yml b/v1/src/main/resources/prod/application.yml new file mode 100644 index 00000000..28b711c3 --- /dev/null +++ b/v1/src/main/resources/prod/application.yml @@ -0,0 +1,74 @@ +server: + port: 9902 + servlet: + context-path: /v1 + +#配置是否为debug模式,debug模式下,不开启权限校验 +debug: false + +#datasource数据源设置 +spring: + datasource: + url: jdbc:mysql://192.168.0.63:21100/hsg?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8 + username: hsg + password: HUfukeji123456!@# + type: com.alibaba.druid.pool.DruidDataSource + driver-class-name: com.mysql.jdbc.Driver + filters: stat + maxActive: 10 + initialSize: 5 + maxWait: 60000 + minIdle: 5 + timeBetweenEvictionRunsMillis: 60000 + minEvictableIdleTimeMillis: 300000 + validationQuery: select 'x' + testWhileIdle: true + testOnBorrow: false + testOnReturn: false + poolPreparedStatements: true + maxOpenPreparedStatements: 20 + redis: + database: 0 + host: 127.0.0.1 + port: 36379 + password: HF123456.Redis + timeout: 1000 + jedis: + pool: + max-active: 20 + max-wait: -1 + max-idle: 10 + min-idle: 0 + #thymelea模板配置 + thymeleaf: + prefix: classpath:/templates/ + suffix: .html + mode: HTML5 + encoding: UTF-8 + #热部署文件,页面不产生缓存,及时更新 + cache: false + #配置日期返回至前台为时间戳 + jackson: + serialization: + write-dates-as-timestamps: true + + + thymeleaf: + cache: false + prefix: classpath:/templates/ + suffix: .html + encoding: UTF-8 + content-type: text/html + mode: HTML5 + +mybatis: + mapperLocations: + - classpath*:sqlmap*/*.xml + type-aliases-package: + org.springboot.sample.entity + +pagehelper: + helperDialect: mysql + reasonable: true + supportMethodsArguments: true + params: count=countSql diff --git a/v1/src/main/resources/prod/config.properties b/v1/src/main/resources/prod/config.properties new file mode 100644 index 00000000..e69de29b diff --git a/v1/src/main/resources/prod/logback.xml b/v1/src/main/resources/prod/logback.xml new file mode 100644 index 00000000..516350df --- /dev/null +++ b/v1/src/main/resources/prod/logback.xml @@ -0,0 +1,72 @@ + + + + + %d %p (%file:%line\)- %m%n + UTF-8 + + + + log/base.log + + log/base.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + log/dao.log + + log/dao.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + log/error.log + + log/error.log.%d.%i + + + 64 MB + + + + + %d %p (%file:%line\)- %m%n + + UTF-8 + + + + + + + + + + + + + + +