# Conflicts: # mallinkAdmin/src/main/java/com/iformall/controller/HomeController.java # mallinkService/src/main/java/com/iformall/common/GlobalDefultExceptionHandler.java # mallinkService/src/main/java/com/iformall/service/impl/MarkingDataReportServiceImpl.java # mallinkService/src/main/resources/mapper/WxCouponActionLogMapper.xml # mallinkService/src/main/resources/mapper/WxCouponOrderMapper.xmlrelease_toaliyun_real
| @@ -3,7 +3,10 @@ | |||||
| logs/** | logs/** | ||||
| logPath_IS_UNDEFINED/** | logPath_IS_UNDEFINED/** | ||||
| uploads/** | uploads/** | ||||
| /.project | |||||
| /.gitignore | |||||
| .gitignore | |||||
| *.iml | *.iml | ||||
| .DS_Store | .DS_Store | ||||
| .classpath | |||||
| .factorypath | |||||
| .project | |||||
| .settings | |||||
| @@ -13,7 +13,8 @@ | |||||
| <artifactId>mallinkAdmin</artifactId> | <artifactId>mallinkAdmin</artifactId> | ||||
| <properties> | <properties> | ||||
| <weixin-java-open.version>3.2.0</weixin-java-open.version> | |||||
| <weixin-java-mp.version>3.3.0</weixin-java-mp.version> | |||||
| <weixin-java-open.version>3.3.0</weixin-java-open.version> | |||||
| </properties> | </properties> | ||||
| <dependencies> | <dependencies> | ||||
| @@ -27,11 +28,27 @@ | |||||
| <artifactId>mybatis-multi-tenancy</artifactId> | <artifactId>mybatis-multi-tenancy</artifactId> | ||||
| <version>1.0</version> | <version>1.0</version> | ||||
| </dependency> | </dependency> | ||||
| <dependency> | |||||
| <groupId>com.github.binarywang</groupId> | |||||
| <artifactId>weixin-java-mp</artifactId> | |||||
| <version>${weixin-java-mp.version}</version> | |||||
| </dependency> | |||||
| <dependency> | <dependency> | ||||
| <groupId>com.github.binarywang</groupId> | <groupId>com.github.binarywang</groupId> | ||||
| <artifactId>weixin-java-open</artifactId> | <artifactId>weixin-java-open</artifactId> | ||||
| <version>${weixin-java-open.version}</version> | <version>${weixin-java-open.version}</version> | ||||
| </dependency> | </dependency> | ||||
| <dependency> | |||||
| <groupId>commons-fileupload</groupId> | |||||
| <artifactId>commons-fileupload</artifactId> | |||||
| <version>1.3.3</version> | |||||
| </dependency> | |||||
| <dependency> | |||||
| <groupId>com.google.zxing</groupId> | |||||
| <artifactId>core</artifactId> | |||||
| <version>3.3.3</version> | |||||
| </dependency> | |||||
| </dependencies> | </dependencies> | ||||
| <build> | <build> | ||||
| @@ -0,0 +1,11 @@ | |||||
| package com.iformall.advice; | |||||
| import org.springframework.web.bind.annotation.ControllerAdvice; | |||||
| import org.springframework.web.servlet.mvc.method.annotation.AbstractJsonpResponseBodyAdvice; | |||||
| @ControllerAdvice | |||||
| public class JsonpAdvice extends AbstractJsonpResponseBodyAdvice { | |||||
| public JsonpAdvice() { | |||||
| super("callback"); | |||||
| } | |||||
| } | |||||
| @@ -96,6 +96,8 @@ public class ShiroConfig { | |||||
| //配置退出 过滤器,其中的具体的退出代码Shiro已经替我们实现了 | //配置退出 过滤器,其中的具体的退出代码Shiro已经替我们实现了 | ||||
| filterChainDefinitionMap.put("/logout", "anon"); | filterChainDefinitionMap.put("/logout", "anon"); | ||||
| //filterChainDefinitionMap.put("/ue/**", "anon"); | |||||
| //filterChainDefinitionMap.put("/config.json", "anon"); | |||||
| filterChainDefinitionMap.put("/doLogin/**", "anon"); | filterChainDefinitionMap.put("/doLogin/**", "anon"); | ||||
| filterChainDefinitionMap.put("/bHidLogin/**", "anon"); | filterChainDefinitionMap.put("/bHidLogin/**", "anon"); | ||||
| filterChainDefinitionMap.put("/css/**", "anon"); | filterChainDefinitionMap.put("/css/**", "anon"); | ||||
| @@ -6,14 +6,26 @@ import com.fasterxml.jackson.databind.DeserializationFeature; | |||||
| import com.fasterxml.jackson.databind.ObjectMapper; | import com.fasterxml.jackson.databind.ObjectMapper; | ||||
| import com.fasterxml.jackson.databind.module.SimpleModule; | import com.fasterxml.jackson.databind.module.SimpleModule; | ||||
| import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | ||||
| import com.iformall.interceptor.HttpServletRequestWrapperFilter; | |||||
| import com.iformall.interceptor.RequestInterceptor; | |||||
| import com.iformall.ueditor.ActionEnter; | |||||
| import com.iformall.ueditor.ConfigManager; | |||||
| import com.iformall.ueditor.UEditorConfig; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | |||||
| import org.springframework.boot.context.properties.EnableConfigurationProperties; | |||||
| import org.springframework.boot.web.servlet.FilterRegistrationBean; | |||||
| import org.springframework.context.annotation.Bean; | |||||
| import org.springframework.context.annotation.Configuration; | import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.http.converter.HttpMessageConverter; | import org.springframework.http.converter.HttpMessageConverter; | ||||
| import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | ||||
| import org.springframework.web.servlet.config.annotation.CorsRegistry; | |||||
| import org.springframework.web.servlet.config.annotation.EnableWebMvc; | |||||
| import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | |||||
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | |||||
| import org.springframework.web.cors.CorsConfiguration; | |||||
| import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | |||||
| import org.springframework.web.filter.CharacterEncodingFilter; | |||||
| import org.springframework.web.filter.CorsFilter; | |||||
| import org.springframework.web.servlet.config.annotation.*; | |||||
| import javax.servlet.Filter; | |||||
| import java.math.BigDecimal; | import java.math.BigDecimal; | ||||
| import java.math.BigInteger; | import java.math.BigInteger; | ||||
| import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||
| @@ -21,7 +33,53 @@ import java.util.List; | |||||
| @Configuration | @Configuration | ||||
| @EnableWebMvc | @EnableWebMvc | ||||
| @EnableConfigurationProperties({UEditorConfig.class, AwsProperty.class}) | |||||
| public class WebConfig implements WebMvcConfigurer { | public class WebConfig implements WebMvcConfigurer { | ||||
| @Autowired | |||||
| private UEditorConfig uEditorConfig; | |||||
| @Autowired | |||||
| private AwsProperty awsProperty; | |||||
| @Autowired | |||||
| private RequestInterceptor requestInterceptor; | |||||
| @Bean | |||||
| @ConditionalOnMissingBean(ActionEnter.class) | |||||
| public ActionEnter actionEnter() { | |||||
| ActionEnter actionEnter = new ActionEnter(ConfigManager.getInstance(uEditorConfig, awsProperty)); | |||||
| return actionEnter; | |||||
| } | |||||
| @Bean | |||||
| public CorsFilter corsFilter() { | |||||
| final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource(); | |||||
| final CorsConfiguration corsConfiguration = new CorsConfiguration(); | |||||
| corsConfiguration.setAllowCredentials(true); | |||||
| corsConfiguration.addAllowedOrigin("*"); | |||||
| corsConfiguration.addAllowedHeader("*"); | |||||
| corsConfiguration.addAllowedMethod("*"); | |||||
| urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration); | |||||
| return new CorsFilter(urlBasedCorsConfigurationSource); | |||||
| } | |||||
| /** | |||||
| * 用于处理编码问题 | |||||
| * | |||||
| * @return | |||||
| */ | |||||
| @Bean | |||||
| public Filter characterEncodingFilter() { | |||||
| CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); | |||||
| characterEncodingFilter.setEncoding("UTF-8"); | |||||
| characterEncodingFilter.setForceEncoding(true); | |||||
| return characterEncodingFilter; | |||||
| } | |||||
| @Override | |||||
| public void addInterceptors(InterceptorRegistry registry) { | |||||
| registry.addInterceptor(requestInterceptor).addPathPatterns("/**"); | |||||
| } | |||||
| @Override | @Override | ||||
| public void addResourceHandlers(ResourceHandlerRegistry registry) { | public void addResourceHandlers(ResourceHandlerRegistry registry) { | ||||
| @@ -29,7 +87,10 @@ public class WebConfig implements WebMvcConfigurer { | |||||
| .addResourceLocations("classpath:/META-INF/resources/"); | .addResourceLocations("classpath:/META-INF/resources/"); | ||||
| registry.addResourceHandler("/webjars/**") | registry.addResourceHandler("/webjars/**") | ||||
| .addResourceLocations("classpath:/META-INF/resources/webjars/"); | .addResourceLocations("classpath:/META-INF/resources/webjars/"); | ||||
| //registry.addResourceHandler("/app/**").addResourceLocations("classpath:/app/"); | |||||
| // ueditor | |||||
| registry.addResourceHandler("/upload/**") | |||||
| .addResourceLocations("file:" + uEditorConfig.getUploadPath()); | |||||
| registry.addResourceHandler("/config.json").addResourceLocations("classpath:/config.json"); | |||||
| } | } | ||||
| @@ -75,5 +136,12 @@ public class WebConfig implements WebMvcConfigurer { | |||||
| converters.add(jackson2HttpMessageConverter); | converters.add(jackson2HttpMessageConverter); | ||||
| } | } | ||||
| @Bean | |||||
| public FilterRegistrationBean<HttpServletRequestWrapperFilter> Filters() { | |||||
| FilterRegistrationBean<HttpServletRequestWrapperFilter> registrationBean = new FilterRegistrationBean<HttpServletRequestWrapperFilter>(); | |||||
| registrationBean.setFilter(new HttpServletRequestWrapperFilter()); | |||||
| registrationBean.addUrlPatterns("/*"); | |||||
| registrationBean.setName("koalaSignFilter"); | |||||
| return registrationBean; | |||||
| } | |||||
| } | } | ||||
| @@ -8,7 +8,6 @@ import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.MallRolePermission; | import com.iformall.domain.po.MallRolePermission; | ||||
| import com.iformall.domain.po.MallUserInfo; | import com.iformall.domain.po.MallUserInfo; | ||||
| import com.iformall.domain.po.MallUserRole; | import com.iformall.domain.po.MallUserRole; | ||||
| import com.iformall.enums.EnumUserAdmin; | |||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.service.MallRolePermissionService; | import com.iformall.service.MallRolePermissionService; | ||||
| import com.iformall.service.MallUserInfoService; | import com.iformall.service.MallUserInfoService; | ||||
| @@ -109,22 +108,8 @@ public class HomeController extends BaseController { | |||||
| MallUserInfo info = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); | MallUserInfo info = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); | ||||
| info.setPassword("保密"); | info.setPassword("保密"); | ||||
| // System.out.println("id:"+ SecurityUtils.getSubject().getSession().getId()); | // System.out.println("id:"+ SecurityUtils.getSubject().getSession().getId()); | ||||
| MallUserRole ur = new MallUserRole(); | |||||
| ur.setUid(info.getId()); | |||||
| PageInfo<MallUserRole> page = mallUserRoleService.listAsPage(ur, 1, 1); | |||||
| if (page.getSize() > 0) { | |||||
| Long roleId = page.getList().get(0).getRoleId(); | |||||
| MallRolePermission p = new MallRolePermission(); | |||||
| p.setRoleId(roleId); | |||||
| p.setTenantId(info.getTenantId()); | |||||
| PageInfo<MallRolePermission> listAsPage = mallRolePermissionService.listAsPage(p, 1, 100); | |||||
| String menus = ""; | |||||
| for (MallRolePermission rp : listAsPage.getList()) { | |||||
| menus += rp.getPermissionId() + ","; | |||||
| } | |||||
| if (menus.length() > 0) { | |||||
| menus = menus.substring(0, menus.length() - 1); | |||||
| } | |||||
| String menus = getPermissionsByRole(info); | |||||
| if(menus != null) { | |||||
| info.setMenus(menus); | info.setMenus(menus); | ||||
| } | } | ||||
| data.data = info; | data.data = info; | ||||
| @@ -134,6 +119,28 @@ public class HomeController extends BaseController { | |||||
| return data; | return data; | ||||
| } | } | ||||
| private String getPermissionsByRole(MallUserInfo info) { | |||||
| MallUserRole ur = new MallUserRole(); | |||||
| ur.setUid(info.getId()); | |||||
| PageInfo<MallUserRole> page = mallUserRoleService.listAsPage(ur, 1, 1); | |||||
| if (page.getSize() > 0) { | |||||
| Long roleId = page.getList().get(0).getRoleId(); | |||||
| MallRolePermission p = new MallRolePermission(); | |||||
| p.setRoleId(roleId); | |||||
| p.setTenantId(info.getTenantId()); | |||||
| PageInfo<MallRolePermission> listAsPage = mallRolePermissionService.listAsPage(p, 1, 100); | |||||
| String menus = ""; | |||||
| for (MallRolePermission rp : listAsPage.getList()) { | |||||
| menus += rp.getPermissionId() + ","; | |||||
| } | |||||
| if (menus.length() > 0) { | |||||
| menus = menus.substring(0, menus.length() - 1); | |||||
| } | |||||
| return menus; | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private boolean isInMobileAdmin(MallUserInfo user) { | private boolean isInMobileAdmin(MallUserInfo user) { | ||||
| // 检查用户是否有 移动端数据塔台 权限 | // 检查用户是否有 移动端数据塔台 权限 | ||||
| boolean isInMobile = false; | boolean isInMobile = false; | ||||
| @@ -193,22 +200,8 @@ public class HomeController extends BaseController { | |||||
| MallUserInfo info = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); | MallUserInfo info = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); | ||||
| info.setPassword("保密"); | info.setPassword("保密"); | ||||
| // System.out.println("id:"+ SecurityUtils.getSubject().getSession().getId()); | // System.out.println("id:"+ SecurityUtils.getSubject().getSession().getId()); | ||||
| MallUserRole ur = new MallUserRole(); | |||||
| ur.setUid(info.getId()); | |||||
| PageInfo<MallUserRole> page = mallUserRoleService.listAsPage(ur, 1, 1); | |||||
| if (page.getSize() > 0) { | |||||
| Long roleId = page.getList().get(0).getRoleId(); | |||||
| MallRolePermission p = new MallRolePermission(); | |||||
| p.setRoleId(roleId); | |||||
| p.setTenantId(info.getTenantId()); | |||||
| PageInfo<MallRolePermission> listAsPage = mallRolePermissionService.listAsPage(p, 1, 100); | |||||
| String menus = ""; | |||||
| for (MallRolePermission rp : listAsPage.getList()) { | |||||
| menus += rp.getPermissionId() + ","; | |||||
| } | |||||
| if (menus.length() > 0) { | |||||
| menus = menus.substring(0, menus.length() - 1); | |||||
| } | |||||
| String menus = getPermissionsByRole(info); | |||||
| if(menus != null) { | |||||
| info.setMenus(menus); | info.setMenus(menus); | ||||
| } | } | ||||
| data.data = info; | data.data = info; | ||||
| @@ -0,0 +1,25 @@ | |||||
| package com.iformall.controller; | |||||
| import com.iformall.ueditor.ActionEnter; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.RequestMapping; | |||||
| import org.springframework.web.bind.annotation.ResponseBody; | |||||
| import org.springframework.web.bind.annotation.RestController; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| @RestController | |||||
| @RequestMapping("/ue") | |||||
| public class UeditorController { | |||||
| @Autowired | |||||
| private ActionEnter actionEnter; | |||||
| @ResponseBody | |||||
| @RequestMapping("/ueditor/exec") | |||||
| public Object exe(HttpServletRequest request){ | |||||
| return actionEnter.exec(request); | |||||
| } | |||||
| } | |||||
| @@ -13,6 +13,7 @@ import com.amazonaws.services.s3.model.ObjectMetadata; | |||||
| import com.amazonaws.services.s3.model.PutObjectRequest; | import com.amazonaws.services.s3.model.PutObjectRequest; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.config.AwsProperty; | import com.iformall.config.AwsProperty; | ||||
| import com.iformall.utils.AwsClient; | |||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| @@ -104,49 +105,10 @@ public class UploadController extends BaseController { | |||||
| } | } | ||||
| */ | */ | ||||
| /** | |||||
| * 上传文件 | |||||
| * | |||||
| * @param multiReq | |||||
| * @return | |||||
| * @throws Exception | |||||
| */ | |||||
| @PostMapping(value = "/awsFileUpload", consumes = "multipart/*", headers = "content-type=multipart/form-data") | |||||
| @ApiOperation("上传文件") | |||||
| public ResultData awsfileUpload(@RequestParam("file") MultipartFile multiReq) { | |||||
| logger.info("[" + getIpAddr() + "] UploadController::awsfileUpload"); | |||||
| private ResultData awsUpload(MultipartFile multiReq, ObjectMetadata metadata, String fileName) { | |||||
| ResultData data = new ResultData(); | ResultData data = new ResultData(); | ||||
| ObjectMetadata metadata = new ObjectMetadata(); | |||||
| metadata.setContentType(multiReq.getContentType()); | |||||
| metadata.setContentLength(multiReq.getSize()); | |||||
| FileOutputStream fos = null; | |||||
| BufferedInputStream fs = null; | |||||
| try { | try { | ||||
| AmazonS3 s3 = AmazonS3ClientBuilder.standard() | |||||
| .withRegion(awsProperty.getClientRegion()) | |||||
| .withCredentials(new AWSCredentialsProvider() { | |||||
| @Override | |||||
| public AWSCredentials getCredentials() { | |||||
| return new BasicAWSCredentials(awsProperty.getAccess(), awsProperty.getSecret()); | |||||
| } | |||||
| @Override | |||||
| public void refresh() { | |||||
| } | |||||
| }) | |||||
| .build(); | |||||
| String fileName = UUID.randomUUID().toString(); | |||||
| int dot = multiReq.getOriginalFilename().lastIndexOf('.'); | |||||
| if (dot >= 0) { | |||||
| fileName = getTenantId() + "/" + fileName + multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); | |||||
| } else { | |||||
| fileName = getTenantId() + "/" + fileName; | |||||
| } | |||||
| AmazonS3 s3 = AwsClient.getInstance(); | |||||
| s3.putObject( | s3.putObject( | ||||
| new PutObjectRequest(awsProperty.getBucketName(), fileName, multiReq.getInputStream(), metadata) | new PutObjectRequest(awsProperty.getBucketName(), fileName, multiReq.getInputStream(), metadata) | ||||
| @@ -158,7 +120,6 @@ public class UploadController extends BaseController { | |||||
| Map<String, String> map = new HashMap<>(); | Map<String, String> map = new HashMap<>(); | ||||
| map.put("url", url.toString()); | map.put("url", url.toString()); | ||||
| data.data = map; | data.data = map; | ||||
| return data; | |||||
| } catch (AmazonServiceException ase) { | } catch (AmazonServiceException ase) { | ||||
| data.code = ResultData.ERROR; | data.code = ResultData.ERROR; | ||||
| logger.warn("Caught an AmazonServiceException, which " + | logger.warn("Caught an AmazonServiceException, which " + | ||||
| @@ -187,5 +148,66 @@ public class UploadController extends BaseController { | |||||
| return data; | return data; | ||||
| } | } | ||||
| /** | |||||
| * 上传文件 | |||||
| * | |||||
| * @param multiReq | |||||
| * @return | |||||
| * @throws Exception | |||||
| */ | |||||
| @PostMapping(value = "/awsFileUpload", consumes = "multipart/*", headers = "content-type=multipart/form-data") | |||||
| @ApiOperation("上传文件") | |||||
| public ResultData awsfileUpload(@RequestParam("file") MultipartFile multiReq) { | |||||
| logger.info("[" + getIpAddr() + "] UploadController::awsfileUpload"); | |||||
| ObjectMetadata metadata = new ObjectMetadata(); | |||||
| metadata.setContentType(multiReq.getContentType()); | |||||
| metadata.setContentLength(multiReq.getSize()); | |||||
| FileOutputStream fos = null; | |||||
| BufferedInputStream fs = null; | |||||
| String fileName = UUID.randomUUID().toString(); | |||||
| int dot = multiReq.getOriginalFilename().lastIndexOf('.'); | |||||
| if (dot >= 0) { | |||||
| fileName = getTenantId() + "/" + fileName + multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); | |||||
| } else { | |||||
| fileName = getTenantId() + "/" + fileName; | |||||
| } | |||||
| ResultData data = awsUpload(multiReq, metadata, fileName); | |||||
| return data; | |||||
| } | |||||
| /** | |||||
| * C端上传图片文件 | |||||
| * | |||||
| * @param multiReq | |||||
| * @return | |||||
| * @throws Exception | |||||
| */ | |||||
| @PostMapping(value = "/cimgUpload", consumes = "multipart/*", headers = "content-type=multipart/form-data") | |||||
| @ApiOperation("C端上传图片文件") | |||||
| public ResultData cimgUpload(@RequestParam("file") MultipartFile multiReq) { | |||||
| logger.info("[" + getIpAddr() + "] UploadController::cimgUpload"); | |||||
| ObjectMetadata metadata = new ObjectMetadata(); | |||||
| metadata.setContentType(multiReq.getContentType()); | |||||
| metadata.setContentLength(multiReq.getSize()); | |||||
| FileOutputStream fos = null; | |||||
| BufferedInputStream fs = null; | |||||
| String fileName = ""; | |||||
| int dot = multiReq.getOriginalFilename().lastIndexOf('.'); | |||||
| if (dot >= 0) { | |||||
| fileName = "cimg/" + multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); | |||||
| } else { | |||||
| fileName = "cimg/" + UUID.randomUUID().toString(); | |||||
| } | |||||
| ResultData data = awsUpload(multiReq, metadata, fileName); | |||||
| return data; | |||||
| } | |||||
| } | } | ||||
| @@ -1,72 +0,0 @@ | |||||
| package com.iformall.controller; | |||||
| import com.iformall.service.WxOpenService; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | |||||
| import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult; | |||||
| import me.chanjar.weixin.open.bean.result.WxOpenQueryAuthResult; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Controller; | |||||
| 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.ResponseBody; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.io.IOException; | |||||
| /** | |||||
| * Stormeye Wu | |||||
| */ | |||||
| @Controller | |||||
| @RequestMapping("/wtauth") | |||||
| public class WechatApiController { | |||||
| private final Logger logger = LoggerFactory.getLogger(getClass()); | |||||
| @Autowired | |||||
| private WxOpenService wxOpenService; | |||||
| @GetMapping("/goto_auth_url_show") | |||||
| @ResponseBody | |||||
| public String gotoPreAuthUrlShow() { | |||||
| return "<a href='goto_auth_url'>go</a>"; | |||||
| } | |||||
| @GetMapping("/goto_auth_url") | |||||
| public void gotoPreAuthUrl(HttpServletRequest request, HttpServletResponse response) { | |||||
| String host = request.getHeader("host"); | |||||
| String url = "http://" + host + "/api/auth/jump"; | |||||
| try { | |||||
| url = wxOpenService.getWxOpenComponentService().getPreAuthUrl(url); | |||||
| response.sendRedirect(url); | |||||
| } catch (WxErrorException | IOException e) { | |||||
| logger.error("gotoPreAuthUrl", e); | |||||
| throw new RuntimeException(e); | |||||
| } | |||||
| } | |||||
| @GetMapping("/jump") | |||||
| @ResponseBody | |||||
| public WxOpenQueryAuthResult jump(@RequestParam("auth_code") String authorizationCode) { | |||||
| try { | |||||
| WxOpenQueryAuthResult queryAuthResult = wxOpenService.getWxOpenComponentService().getQueryAuth(authorizationCode); | |||||
| logger.info("getQueryAuth", queryAuthResult); | |||||
| return queryAuthResult; | |||||
| } catch (WxErrorException e) { | |||||
| logger.error("gotoPreAuthUrl", e); | |||||
| throw new RuntimeException(e); | |||||
| } | |||||
| } | |||||
| @GetMapping("/get_authorizer_info") | |||||
| @ResponseBody | |||||
| public WxOpenAuthorizerInfoResult getAuthorizerInfo(@RequestParam String appId) { | |||||
| try { | |||||
| return wxOpenService.getWxOpenComponentService().getAuthorizerInfo(appId); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error("getAuthorizerInfo", e); | |||||
| throw new RuntimeException(e); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,104 @@ | |||||
| package com.iformall.controller; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.Result; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.WxAuthorizerInfo; | |||||
| import com.iformall.enums.EnumWxAuthorizationInfoType; | |||||
| import com.iformall.enums.EnumWxAuthorizationStatus; | |||||
| import com.iformall.service.WxAuthorizerInfoService; | |||||
| import com.iformall.service.wechat.WxOpenService; | |||||
| import io.swagger.annotations.Api; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | |||||
| import me.chanjar.weixin.open.api.WxOpenMaService; | |||||
| import me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate; | |||||
| import me.chanjar.weixin.open.bean.ma.WxMaOpenCommitExtInfo; | |||||
| import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult; | |||||
| import me.chanjar.weixin.open.bean.result.WxOpenQueryAuthResult; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Controller; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.io.IOException; | |||||
| import java.util.List; | |||||
| /** | |||||
| * Stormeye Wu | |||||
| */ | |||||
| @Controller | |||||
| @RequestMapping("/wt_auth") | |||||
| @Api(description = "微信第三方开放平台授权相关接口") | |||||
| public class WechatAuthController { | |||||
| private final Logger logger = LoggerFactory.getLogger(getClass()); | |||||
| @Autowired | |||||
| private WxOpenService openService; | |||||
| @Autowired | |||||
| private WxAuthorizerInfoService authorizerInfoService; | |||||
| @GetMapping("/goto_auth_url_show") | |||||
| @ResponseBody | |||||
| public String gotoPreAuthUrlShow() { | |||||
| return "<html>" + | |||||
| "<body>" + | |||||
| "<a href='/api/wt_auth/goto_auth_url'>go</a>" + | |||||
| "</body>" + | |||||
| "</html>"; | |||||
| } | |||||
| @GetMapping("/goto_auth_url") | |||||
| public void gotoPreAuthUrl(HttpServletRequest request, HttpServletResponse response) { | |||||
| String host = request.getHeader("host"); | |||||
| String url = "https://" + host + "/api/wt_auth/jump"; | |||||
| try { | |||||
| url = openService.getWxOpenComponentService().getPreAuthUrl(url); | |||||
| response.sendRedirect(url); | |||||
| } catch (WxErrorException | IOException e) { | |||||
| logger.error("gotoPreAuthUrl", e); | |||||
| throw new RuntimeException(e); | |||||
| } | |||||
| } | |||||
| @GetMapping("/jump") | |||||
| @ResponseBody | |||||
| public WxOpenQueryAuthResult jump(@RequestParam("auth_code") String authorizationCode) { | |||||
| try { | |||||
| WxOpenQueryAuthResult queryAuthResult = openService.getWxOpenComponentService().getQueryAuth(authorizationCode); | |||||
| logger.info("getQueryAuth", queryAuthResult); | |||||
| WxOpenAuthorizerInfoResult openAuthorizerInfoResult = openService.getWxOpenComponentService().getAuthorizerInfo( | |||||
| queryAuthResult.getAuthorizationInfo().getAuthorizerAppid()); | |||||
| // save auth info | |||||
| authorizerInfoService.saveOrUpdate(new WxAuthorizerInfo(){ | |||||
| { | |||||
| setAuthorizerAppid(openAuthorizerInfoResult.getAuthorizationInfo().getAuthorizerAppid()); | |||||
| setAlias(openAuthorizerInfoResult.getAuthorizerInfo().getAlias()); | |||||
| setHeadImg(openAuthorizerInfoResult.getAuthorizerInfo().getHeadImg()); | |||||
| setQrcodeUrl(openAuthorizerInfoResult.getAuthorizerInfo().getQrcodeUrl()); | |||||
| setAuthorizationStatus(EnumWxAuthorizationStatus.AUTHORIZED.getCode()); | |||||
| } | |||||
| }); | |||||
| return queryAuthResult; | |||||
| } catch (WxErrorException e) { | |||||
| logger.error("gotoPreAuthUrl", e); | |||||
| throw new RuntimeException(e); | |||||
| } | |||||
| } | |||||
| @GetMapping("/getMobilePreAuthUrl") | |||||
| @ResponseBody | |||||
| public String getMobilePreAuthUrl(HttpServletRequest request, HttpServletResponse response) { | |||||
| String host = request.getHeader("host"); | |||||
| String url = "https://" + host + "/api/wt_auth/jump"; | |||||
| try { | |||||
| url = openService.getWxOpenComponentService().getMobilePreAuthUrl(url); | |||||
| return url; | |||||
| } catch (WxErrorException e) { | |||||
| logger.error("getMobilePreAuthUrl", e); | |||||
| throw new RuntimeException(e); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,34 +1,89 @@ | |||||
| package com.iformall.controller; | package com.iformall.controller; | ||||
| import com.iformall.service.WxOpenService; | |||||
| import com.iformall.domain.po.WxAuthorizerInfo; | |||||
| import com.iformall.domain.po.WxComponentVerifyTicket; | |||||
| import com.iformall.enums.EnumWxAuthorizationInfoType; | |||||
| import com.iformall.enums.EnumWxAuthorizationStatus; | |||||
| import com.iformall.service.WxAuthorizerInfoService; | |||||
| import com.iformall.service.WxComponentVerifyTicketService; | |||||
| import com.iformall.service.wechat.WxOpenService; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
| import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; | ||||
| import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; | import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; | ||||
| import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; | import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; | ||||
| import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage; | import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage; | ||||
| import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult; | |||||
| import me.chanjar.weixin.open.bean.result.WxOpenQueryAuthResult; | |||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Controller; | |||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
| @RestController | |||||
| @RequestMapping("wxOpen") | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import java.io.ByteArrayOutputStream; | |||||
| import java.io.IOException; | |||||
| import java.io.InputStream; | |||||
| import java.nio.charset.Charset; | |||||
| import java.util.Date; | |||||
| @Controller | |||||
| @RequestMapping("/wxOpen") | |||||
| @Api(description = "微信第三方开放平台回调相关接口") | |||||
| public class WechatCalllbackController extends BaseController { | public class WechatCalllbackController extends BaseController { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| @Autowired | @Autowired | ||||
| protected WxOpenService wxOpenService; | protected WxOpenService wxOpenService; | ||||
| @RequestMapping("/notify") | |||||
| public Object receiveTicket(@RequestBody(required = false) String requestBody, @RequestParam("timestamp") String timestamp, | |||||
| @RequestParam("nonce") String nonce, @RequestParam("signature") String signature, | |||||
| @RequestParam(name = "encrypt_type", required = false) String encType, | |||||
| @RequestParam(name = "msg_signature", required = false) String msgSignature) { | |||||
| logger.info( | |||||
| "\n接收微信请求:[signature=[{}], encType=[{}], msgSignature=[{}]," | |||||
| @Autowired | |||||
| private WxComponentVerifyTicketService componentVerifyTicketService; | |||||
| @Autowired | |||||
| private WxAuthorizerInfoService authorizerInfoService; | |||||
| @RequestMapping(value = "/notify", method = RequestMethod.POST) | |||||
| @ApiOperation("接收ticket回调") | |||||
| public Object receiveTicket(HttpServletRequest request) throws IOException { | |||||
| logger.info("[" +getIpAddr() + "]接收微信请求 /wxOpen/notify"); | |||||
| InputStream inStream = request.getInputStream(); | |||||
| ByteArrayOutputStream outSteam = new ByteArrayOutputStream(); | |||||
| byte[] buffer = new byte[1024]; | |||||
| int len = 0; | |||||
| while ((len = inStream.read(buffer)) != -1) { | |||||
| outSteam.write(buffer, 0, len); | |||||
| } | |||||
| String resultxml = new String(outSteam.toByteArray(), Charset.forName("UTF-8")); | |||||
| logger.info(resultxml); | |||||
| outSteam.close(); | |||||
| inStream.close(); | |||||
| String timestamp = request.getParameter("timestamp"); | |||||
| String nonce = request.getParameter("nonce"); | |||||
| String signature = request.getParameter("signature"); | |||||
| String encType = request.getParameter("encrypt_type"); | |||||
| String msgSignature= request.getParameter("msg_signature"); | |||||
| /* | |||||
| // 测试数据 | |||||
| String timestamp = "1545708083"; | |||||
| String nonce = "1052028699"; | |||||
| String signature = "b5fa8296b46c726cbed35f744944f20f682776a6"; | |||||
| String encType = "aes"; | |||||
| String msgSignature= "54bec4c513f447cb312fd091bea48326f87aedde"; | |||||
| String resultxml = "<xml>\n" + | |||||
| " <AppId><![CDATA[wx897e4673286c915d]]></AppId>\n" + | |||||
| " <Encrypt><![CDATA[92gl+PCgxooLh85YZ74VX8gNPV3tq2w8br4tuBl2UIc9uJuJiSNBgohFxgS7tRXSMUtr5t+75MiLKlaMKvv4FH5iF3WdYbxjF6ojnA1+MBzD7mf9fo6KkWUdDq+1V0OtrooP4s8iuAC0Lx3elCtWUZXYGnCeP5Y/2A8ZZBwpvcBz73d7n2Kv8QVvLsw2dmrej1b8KGdmRAEbm/oYoVthlAkmoTTAAx+Gj10XTMem1wp1vT/a0mGxN88oJxNZoHdFvAbmc24A7VD4i5VDOt9FqwerqlGXnBX5pBAmOx8ZUsndM8yuf3I54GE9hEPRvdWBiyLb96Lb8ZnjEBlvc9kvs7PpFOSQhkbGMNQKWGW1os8UImr7O3+IiKLuBv2G1pJBb2/kIeZn5v9NuxYLOsXQmb2XijHYMXwCNHCI3Eji22k9XDiiuK1miHlUuL8Gz8X7lN9JuVcE24jd7Ty4H0pThQ==]]></Encrypt>\n" + | |||||
| "</xml>"; | |||||
| */ | |||||
| logger.info("\n接收微信请求:[signature=[{}], encType=[{}], msgSignature=[{}]," | |||||
| + " timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] ", | + " timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] ", | ||||
| signature, encType, msgSignature, timestamp, nonce, requestBody); | |||||
| signature, encType, msgSignature, timestamp, nonce, resultxml); | |||||
| if (!StringUtils.equalsIgnoreCase("aes", encType) | if (!StringUtils.equalsIgnoreCase("aes", encType) | ||||
| || !wxOpenService.getWxOpenComponentService().checkSignature(timestamp, nonce, signature)) { | || !wxOpenService.getWxOpenComponentService().checkSignature(timestamp, nonce, signature)) { | ||||
| @@ -36,9 +91,49 @@ public class WechatCalllbackController extends BaseController { | |||||
| } | } | ||||
| // aes加密的消息 | // aes加密的消息 | ||||
| WxOpenXmlMessage inMessage = WxOpenXmlMessage.fromEncryptedXml(requestBody, | |||||
| WxOpenXmlMessage inMessage = WxOpenXmlMessage.fromEncryptedXml(resultxml, | |||||
| wxOpenService.getWxOpenConfigStorage(), timestamp, nonce, msgSignature); | wxOpenService.getWxOpenConfigStorage(), timestamp, nonce, msgSignature); | ||||
| this.logger.debug("\n消息解密后内容为:\n{} ", inMessage.toString()); | this.logger.debug("\n消息解密后内容为:\n{} ", inMessage.toString()); | ||||
| if(inMessage.getInfoType().equals(EnumWxAuthorizationInfoType.COMPONENT_VERIFY_TICKET.getMessage())) { | |||||
| // 保存component_verify_ticket | |||||
| componentVerifyTicketService.saveOrUpdate(new WxComponentVerifyTicket(){ | |||||
| { | |||||
| setComponentVerifyTicket(inMessage.getComponentVerifyTicket()); | |||||
| setCreateTime(new Date(Long.valueOf(inMessage.getCreateTime() * 1000))); | |||||
| setComponentAppid(inMessage.getAppId()); | |||||
| setDeadline(new Date(Long.valueOf(System.currentTimeMillis() + (60*60*1000)))); | |||||
| } | |||||
| }); | |||||
| } else if (inMessage.getInfoType().equals(EnumWxAuthorizationInfoType.AUTHORIZED.getMessage()) || | |||||
| inMessage.getInfoType().equals(EnumWxAuthorizationInfoType.UPDATEAUTHORIZED.getMessage()) | |||||
| ) { | |||||
| try { | |||||
| WxOpenQueryAuthResult queryAuthResult = wxOpenService.getWxOpenComponentService().getQueryAuth(inMessage.getAuthorizationCode()); | |||||
| logger.info("getQueryAuth", queryAuthResult); | |||||
| WxOpenAuthorizerInfoResult openAuthorizerInfoResult = wxOpenService.getWxOpenComponentService().getAuthorizerInfo( | |||||
| queryAuthResult.getAuthorizationInfo().getAuthorizerAppid()); | |||||
| // save auth info | |||||
| authorizerInfoService.saveOrUpdate(new WxAuthorizerInfo(){ | |||||
| { | |||||
| setAuthorizerAppid(openAuthorizerInfoResult.getAuthorizationInfo().getAuthorizerAppid()); | |||||
| setAlias(openAuthorizerInfoResult.getAuthorizerInfo().getAlias()); | |||||
| setHeadImg(openAuthorizerInfoResult.getAuthorizerInfo().getHeadImg()); | |||||
| setQrcodeUrl(openAuthorizerInfoResult.getAuthorizerInfo().getQrcodeUrl()); | |||||
| setAuthorizationStatus(EnumWxAuthorizationStatus.AUTHORIZED.getCode()); | |||||
| } | |||||
| }); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| } else if (inMessage.getInfoType().equals(EnumWxAuthorizationInfoType.UNAUTHORIZED.getMessage())) { | |||||
| authorizerInfoService.saveOrUpdate(new WxAuthorizerInfo(){ | |||||
| { | |||||
| setAuthorizerAppid(inMessage.getAuthorizerAppid()); | |||||
| setAuthorizationStatus(EnumWxAuthorizationStatus.UNAUTHORIZED.getCode()); | |||||
| } | |||||
| }); | |||||
| } | |||||
| try { | try { | ||||
| String out = wxOpenService.getWxOpenComponentService().route(inMessage); | String out = wxOpenService.getWxOpenComponentService().route(inMessage); | ||||
| this.logger.debug("\n组装回复信息:{}", out); | this.logger.debug("\n组装回复信息:{}", out); | ||||
| @@ -46,23 +141,37 @@ public class WechatCalllbackController extends BaseController { | |||||
| this.logger.error("notify", e); | this.logger.error("notify", e); | ||||
| } | } | ||||
| return "success"; | return "success"; | ||||
| } | } | ||||
| @RequestMapping("callback/{appId}") | |||||
| public Object callback(@RequestBody(required = false) String requestBody, | |||||
| @PathVariable("appId") String appId, | |||||
| @RequestParam("signature") String signature, | |||||
| @RequestParam("timestamp") String timestamp, | |||||
| @RequestParam("nonce") String nonce, | |||||
| @RequestParam("openid") String openid, | |||||
| @RequestParam("encrypt_type") String encType, | |||||
| @RequestParam("msg_signature") String msgSignature) { | |||||
| @RequestMapping(value = "/{appId}/callback") | |||||
| @ApiOperation("消息回调") | |||||
| public Object callback(@PathVariable("appId") String appId, HttpServletRequest request) throws IOException { | |||||
| logger.info("[" +getIpAddr() + "]接收微信请求 /{appId}/callback"); | |||||
| InputStream inStream = request.getInputStream(); | |||||
| ByteArrayOutputStream outSteam = new ByteArrayOutputStream(); | |||||
| byte[] buffer = new byte[1024]; | |||||
| int len = 0; | |||||
| while ((len = inStream.read(buffer)) != -1) { | |||||
| outSteam.write(buffer, 0, len); | |||||
| } | |||||
| String resultxml = new String(outSteam.toByteArray(), Charset.forName("UTF-8")); | |||||
| logger.info(resultxml); | |||||
| outSteam.close(); | |||||
| inStream.close(); | |||||
| String timestamp = request.getParameter("timestamp"); | |||||
| String nonce = request.getParameter("nonce"); | |||||
| String signature = request.getParameter("signature"); | |||||
| String encType = request.getParameter("encrypt_type"); | |||||
| String openid = request.getParameter("openid"); | |||||
| String msgSignature= request.getParameter("msg_signature"); | |||||
| logger.info( | logger.info( | ||||
| "\n接收微信请求:[appId=[{}], openid=[{}], signature=[{}], encType=[{}], msgSignature=[{}]," | "\n接收微信请求:[appId=[{}], openid=[{}], signature=[{}], encType=[{}], msgSignature=[{}]," | ||||
| + " timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] ", | + " timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] ", | ||||
| appId, openid, signature, encType, msgSignature, timestamp, nonce, requestBody); | |||||
| appId, openid, signature, encType, msgSignature, timestamp, nonce, resultxml); | |||||
| if (!StringUtils.equalsIgnoreCase("aes", encType) | if (!StringUtils.equalsIgnoreCase("aes", encType) | ||||
| || !wxOpenService.getWxOpenComponentService().checkSignature(timestamp, nonce, signature)) { | || !wxOpenService.getWxOpenComponentService().checkSignature(timestamp, nonce, signature)) { | ||||
| throw new IllegalArgumentException("非法请求,可能属于伪造的请求!"); | throw new IllegalArgumentException("非法请求,可能属于伪造的请求!"); | ||||
| @@ -70,11 +179,11 @@ public class WechatCalllbackController extends BaseController { | |||||
| String out = ""; | String out = ""; | ||||
| // aes加密的消息 | // aes加密的消息 | ||||
| WxMpXmlMessage inMessage = WxOpenXmlMessage.fromEncryptedMpXml(requestBody, | |||||
| WxMpXmlMessage inMessage = WxOpenXmlMessage.fromEncryptedMpXml(resultxml, | |||||
| wxOpenService.getWxOpenConfigStorage(), timestamp, nonce, msgSignature); | wxOpenService.getWxOpenConfigStorage(), timestamp, nonce, msgSignature); | ||||
| this.logger.debug("\n消息解密后内容为:\n{} ", inMessage.toString()); | |||||
| logger.debug("\n消息解密后内容为:\n{} ", inMessage.toString()); | |||||
| // 全网发布测试用例 | // 全网发布测试用例 | ||||
| if (StringUtils.equalsAnyIgnoreCase(appId, "wxd101a85aa106f53e", "wx570bc396a51b8ff8")) { | |||||
| if (StringUtils.equalsAnyIgnoreCase(appId, "wx570bc396a51b8ff8", "wxd101a85aa106f53e")) { | |||||
| try { | try { | ||||
| if (StringUtils.equals(inMessage.getMsgType(), "text")) { | if (StringUtils.equals(inMessage.getMsgType(), "text")) { | ||||
| if (StringUtils.equals(inMessage.getContent(), "TESTCOMPONENT_MSG_TYPE_TEXT")) { | if (StringUtils.equals(inMessage.getContent(), "TESTCOMPONENT_MSG_TYPE_TEXT")) { | ||||
| @@ -98,11 +207,36 @@ public class WechatCalllbackController extends BaseController { | |||||
| logger.error("callback", e); | logger.error("callback", e); | ||||
| } | } | ||||
| } else { | } else { | ||||
| WxMpXmlOutMessage outMessage = wxOpenService.getWxOpenMessageRouter().route(inMessage, appId); | |||||
| if (outMessage != null) { | |||||
| out = WxOpenXmlMessage.wxMpOutXmlMessageToEncryptedXml(outMessage, wxOpenService.getWxOpenConfigStorage()); | |||||
| /**判断消息类型,调用对应的方法*/ | |||||
| switch (inMessage.getMsgType()){ | |||||
| case "event": | |||||
| case "text": | |||||
| WxMpXmlOutMessage outMessage = wxOpenService.getWxOpenMessageRouter().route(inMessage, appId); | |||||
| if (outMessage != null) { | |||||
| out = WxOpenXmlMessage.wxMpOutXmlMessageToEncryptedXml(outMessage, wxOpenService.getWxOpenConfigStorage()); | |||||
| } | |||||
| /* | |||||
| else { | |||||
| WxMpXmlOutMessage outMsg = new WxMpXmlOutTextMessage(); | |||||
| outMsg.setCreateTime(System.currentTimeMillis()); | |||||
| outMsg.setToUserName(inMessage.getFromUser()); | |||||
| outMsg.setFromUserName(inMessage.getToUser()); | |||||
| outMsg.setMsgType("text"); | |||||
| ((WxMpXmlOutTextMessage) outMsg).setContent(inMessage.getContent()); | |||||
| out = WxOpenXmlMessage.wxMpOutXmlMessageToEncryptedXml(outMsg, wxOpenService.getWxOpenConfigStorage()); | |||||
| } | |||||
| */ | |||||
| else { | |||||
| out = "success"; | |||||
| } | |||||
| break; | |||||
| default: | |||||
| return "success"; | |||||
| } | } | ||||
| } | } | ||||
| logger.info(out); | |||||
| return out; | return out; | ||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,236 @@ | |||||
| package com.iformall.controller; | |||||
| import com.alibaba.fastjson.JSON; | |||||
| import com.google.gson.Gson; | |||||
| import com.google.gson.GsonBuilder; | |||||
| import com.google.gson.reflect.TypeToken; | |||||
| import com.iformall.common.Result; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.service.wechat.WxOpenService; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | |||||
| import me.chanjar.weixin.open.api.WxOpenMaService; | |||||
| import me.chanjar.weixin.open.bean.ma.WxMaOpenCommitExtInfo; | |||||
| import me.chanjar.weixin.open.bean.message.WxOpenMaSubmitAuditMessage; | |||||
| import me.chanjar.weixin.open.bean.result.*; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.GetMapping; | |||||
| import org.springframework.web.bind.annotation.PostMapping; | |||||
| import org.springframework.web.bind.annotation.RequestMapping; | |||||
| import org.springframework.web.bind.annotation.RestController; | |||||
| import javax.servlet.ServletOutputStream; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.io.File; | |||||
| import java.io.FileInputStream; | |||||
| import java.io.IOException; | |||||
| import java.io.InputStream; | |||||
| import java.util.Map; | |||||
| /** | |||||
| * Stormeye Wu | |||||
| */ | |||||
| @RestController | |||||
| @RequestMapping("/weappCode") | |||||
| @Api(description = "微信第三方开发平台-小程序-代码管理") | |||||
| public class WechatWeappCodeController { | |||||
| private final Logger logger = LoggerFactory.getLogger(getClass()); | |||||
| @Autowired | |||||
| private WxOpenService openService; | |||||
| @ApiOperation(value = "为授权的小程序帐号上传小程序代码", notes = "extInfo参考https://mp.weixin.qq.com/debug/wxadoc/dev/framework/config.html") | |||||
| @PostMapping("/codeCommit") | |||||
| public ResultData codeCommit(Long templateId, String userVersion, String userDesc, String extInfoStr) { | |||||
| try { | |||||
| Gson gson= new GsonBuilder().create(); | |||||
| WxMaOpenCommitExtInfo extInfo = gson.fromJson(extInfoStr, new TypeToken<WxMaOpenCommitExtInfo>() { }.getType()); | |||||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(extInfo.getExtAppid()); | |||||
| logger.info(extInfo.toString()); | |||||
| WxOpenResult openRet = openMaService.codeCommit(templateId, userVersion, userDesc, extInfo); | |||||
| logger.info(openRet.toString()); | |||||
| return new ResultData(openRet); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| return new ResultData(Result.ERROR); | |||||
| } | |||||
| @ApiOperation("获取体验小程序的体验二维码") | |||||
| @GetMapping("/getQrcode") | |||||
| public void getQrcode(String appId, String pagePath, Map<String, String> params, HttpServletResponse response, HttpServletRequest req) { | |||||
| try { | |||||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| File file = openMaService.getTestQrcode(pagePath, params); | |||||
| ServletOutputStream out = response.getOutputStream(); | |||||
| response.reset(); | |||||
| response.setContentType("bin"); | |||||
| String agent = req.getHeader("user-agent"); | |||||
| String filename = "qrcode"; | |||||
| if (agent.contains("Firefox")) { | |||||
| response.setHeader("Content-disposition", | |||||
| "attachment; filename=" | |||||
| + new String(filename.getBytes("GB2312"),"ISO-8859-1")); | |||||
| } else { | |||||
| response.setHeader("Content-disposition", | |||||
| "attachment; filename=" | |||||
| + java.net.URLEncoder.encode(filename,"UTF-8")); | |||||
| } | |||||
| // 循环取出流中的数据 | |||||
| byte[] b = new byte[1024]; | |||||
| int len; | |||||
| InputStream inStream = new FileInputStream(file); | |||||
| while ((len = inStream.read(b)) > 0) | |||||
| response.getOutputStream().write(b, 0, len); | |||||
| inStream.close(); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } catch (IOException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| } | |||||
| @ApiOperation("获取授权小程序帐号已设置的类目") | |||||
| @GetMapping("/getCategory") | |||||
| public ResultData getCategory(String appId) { | |||||
| try { | |||||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| WxOpenMaCategoryListResult openRet = openMaService.getCategoryList(); | |||||
| logger.info(openRet.toString()); | |||||
| return new ResultData(openRet); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| return new ResultData(Result.ERROR); | |||||
| } | |||||
| @ApiOperation("获取小程序的第三方提交代码的页面配置") | |||||
| @GetMapping("/getPage") | |||||
| public ResultData getPage(String appId) { | |||||
| try { | |||||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| WxOpenMaPageListResult openRet = openMaService.getPageList(); | |||||
| logger.info(openRet.toString()); | |||||
| return new ResultData(openRet); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| return new ResultData(Result.ERROR); | |||||
| } | |||||
| @ApiOperation("将第三方提交的代码包提交审核") | |||||
| @PostMapping("/submitAudit") | |||||
| public ResultData submitAudit(String appId, String subMesgStr) { | |||||
| try { | |||||
| WxOpenMaSubmitAuditMessage subMessage = JSON.parseObject(subMesgStr, WxOpenMaSubmitAuditMessage.class); | |||||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| WxOpenMaSubmitAuditResult openRet = openMaService.submitAudit(subMessage); | |||||
| logger.info(openRet.toString()); | |||||
| return new ResultData(openRet); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| return new ResultData(Result.ERROR); | |||||
| } | |||||
| @ApiOperation("查询某个指定版本的审核状态") | |||||
| @PostMapping("/getAuditstatus") | |||||
| public ResultData getAuditstatus(String appId, String auditidStr) { | |||||
| try { | |||||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| WxOpenMaQueryAuditResult openRet = openMaService.getAuditStatus(Long.valueOf(auditidStr)); | |||||
| logger.info(openRet.toString()); | |||||
| return new ResultData(openRet); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| return new ResultData(Result.ERROR); | |||||
| } | |||||
| @ApiOperation("查询最新一次提交的审核状态") | |||||
| @GetMapping("/getLatestAuditstatus") | |||||
| public ResultData get_latest_auditstatus(String appId) { | |||||
| try { | |||||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| WxOpenMaQueryAuditResult openRet = openMaService.getLatestAuditStatus(); | |||||
| logger.info(openRet.toString()); | |||||
| return new ResultData(openRet); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| return new ResultData(Result.ERROR); | |||||
| } | |||||
| @ApiOperation("发布已通过审核的小程序") | |||||
| @PostMapping("/releaesAudited") | |||||
| public ResultData releaesAudited(String appId) { | |||||
| try { | |||||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| WxOpenResult openRet = openMaService.releaesAudited(); | |||||
| logger.info(openRet.toString()); | |||||
| return new ResultData(openRet); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| return new ResultData(Result.ERROR); | |||||
| } | |||||
| @ApiOperation("小程序版本回退") | |||||
| @GetMapping("/revertCodeRelease") | |||||
| public ResultData revertCodeRelease(String appId) { | |||||
| try { | |||||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| WxOpenResult openRet = openMaService.revertCodeReleaes(); | |||||
| logger.info(openRet.toString()); | |||||
| return new ResultData(openRet); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| return new ResultData(Result.ERROR); | |||||
| } | |||||
| @ApiOperation("查询当前设置的最低基础库版本及各版本用户占比") | |||||
| @GetMapping("/getSupportVersion") | |||||
| public ResultData getSupportVersion(String appId) { | |||||
| try { | |||||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| String openRet = openMaService.getSupportVersion(); | |||||
| logger.info(openRet.toString()); | |||||
| return new ResultData(openRet); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| return new ResultData(Result.ERROR); | |||||
| } | |||||
| @ApiOperation("设置最低基础库版本") | |||||
| @GetMapping("/setSupportVersion") | |||||
| public ResultData setSupportVersion(String appId, String version) { | |||||
| try { | |||||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| String openRet = openMaService.setSupportVersion(version); | |||||
| logger.info(openRet.toString()); | |||||
| return new ResultData(openRet); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| return new ResultData(Result.ERROR); | |||||
| } | |||||
| @ApiOperation(value = "小程序审核撤回", notes = "单个帐号每天审核撤回次数最多不超过1次,一个月不超过10次。") | |||||
| @GetMapping("/undoCodeAudit") | |||||
| public ResultData undoCodeAudit(String appId) { | |||||
| try { | |||||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| openMaService.undoCodeAudit(); | |||||
| return new ResultData(); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| return new ResultData(Result.ERROR); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,83 @@ | |||||
| package com.iformall.controller; | |||||
| import com.iformall.common.Result; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.WxAuthorizerInfo; | |||||
| import com.iformall.enums.EnumWxAuthorizationStatus; | |||||
| import com.iformall.service.WxAuthorizerInfoService; | |||||
| import com.iformall.service.wechat.WxOpenService; | |||||
| import io.swagger.annotations.Api; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | |||||
| import me.chanjar.weixin.open.api.WxOpenMaService; | |||||
| import me.chanjar.weixin.open.bean.WxOpenMaCodeTemplate; | |||||
| import me.chanjar.weixin.open.bean.ma.WxMaOpenCommitExtInfo; | |||||
| import me.chanjar.weixin.open.bean.result.WxOpenAuthorizerInfoResult; | |||||
| import me.chanjar.weixin.open.bean.result.WxOpenQueryAuthResult; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Controller; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.io.IOException; | |||||
| import java.util.List; | |||||
| /** | |||||
| * Stormeye Wu | |||||
| */ | |||||
| @RestController | |||||
| @RequestMapping("/weappDraftTemplate") | |||||
| @Api(description = "微信第三方开发平台-小程序-代码模版库管理") | |||||
| public class WechatWeappDraftTemplateController { | |||||
| private final Logger logger = LoggerFactory.getLogger(getClass()); | |||||
| @Autowired | |||||
| private WxOpenService openService; | |||||
| @GetMapping("/tempDraftList") | |||||
| public ResultData getTempDraftList() { | |||||
| try { | |||||
| List<WxOpenMaCodeTemplate> list = openService.getWxOpenComponentService().getTemplateDraftList(); | |||||
| return new ResultData(list); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(Result.ERROR, e.getMessage()); | |||||
| } | |||||
| } | |||||
| @GetMapping("/tempList") | |||||
| public ResultData getTempList() { | |||||
| try { | |||||
| List<WxOpenMaCodeTemplate> list = openService.getWxOpenComponentService().getTemplateList(); | |||||
| return new ResultData(list); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(Result.ERROR, e.getMessage()); | |||||
| } | |||||
| } | |||||
| @PostMapping("/addToTemplate") | |||||
| public ResultData addToTemplate(Long draftId) { | |||||
| try { | |||||
| openService.getWxOpenComponentService().addToTemplate(draftId); | |||||
| return new ResultData(); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(Result.ERROR, e.getMessage()); | |||||
| } | |||||
| } | |||||
| @PostMapping("/deleteTemplate") | |||||
| public ResultData deleteTemplate(Long templateId) { | |||||
| try { | |||||
| openService.getWxOpenComponentService().deleteTemplate(templateId); | |||||
| return new ResultData(); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(Result.ERROR, e.getMessage()); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,115 @@ | |||||
| package com.iformall.controller; | |||||
| import cn.binarywang.wx.miniapp.api.WxMaService; | |||||
| import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateAddResult; | |||||
| import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateLibraryGetResult; | |||||
| import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateLibraryListResult; | |||||
| import cn.binarywang.wx.miniapp.bean.template.WxMaTemplateListResult; | |||||
| import com.iformall.common.Result; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.service.wechat.WxOpenService; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import java.util.List; | |||||
| /** | |||||
| * Stormeye Wu | |||||
| */ | |||||
| @RestController | |||||
| @RequestMapping("/weappMsgTemplate") | |||||
| @Api(description = "微信第三方开发平台-小程序-消息模板设置") | |||||
| public class WechatWeappMsgTemplateController { | |||||
| private final Logger logger = LoggerFactory.getLogger(getClass()); | |||||
| @Autowired | |||||
| private WxOpenService openService; | |||||
| @ApiOperation("获取小程序模板库标题列表") | |||||
| @GetMapping("getTmpLibList") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "appId", value = "appId", dataType = "String", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| public ResultData getTmpLibList(String appId, Integer pageNum, Integer pageSize) { | |||||
| try { | |||||
| WxMaService maService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| WxMaTemplateLibraryListResult ret = maService.getTemplateService().findTemplateLibraryList(pageNum, pageSize); | |||||
| return new ResultData(ret); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(Result.ERROR, e.getMessage()); | |||||
| } | |||||
| } | |||||
| @ApiOperation("获取模板库某个模板标题下关键词库") | |||||
| @GetMapping("getTemplateLibraryKeywordList") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "appId", value = "appId", dataType = "String", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "id", value = "页数", dataType = "String", paramType = "query", required = true)}) | |||||
| public ResultData findTemplateLibraryKeywordList(String appId, String id) { | |||||
| try { | |||||
| WxMaService maService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| WxMaTemplateLibraryGetResult ret = maService.getTemplateService().findTemplateLibraryKeywordList(id); | |||||
| return new ResultData(ret); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(Result.ERROR, e.getMessage()); | |||||
| } | |||||
| } | |||||
| @ApiOperation("组合模板并添加至帐号下的个人模板库") | |||||
| @PostMapping("addTemplate") | |||||
| public ResultData addTemplate( | |||||
| @RequestParam(value = "appId") String appId, | |||||
| @RequestParam(value = "id") String id, | |||||
| @RequestParam(value = "keywordIdList")List<Integer> keywordIdList) { | |||||
| try { | |||||
| WxMaService maService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| WxMaTemplateAddResult ret = maService.getTemplateService().addTemplate(id, keywordIdList); | |||||
| return new ResultData(ret); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(Result.ERROR, e.getMessage()); | |||||
| } | |||||
| } | |||||
| @ApiOperation("获取帐号下已存在的模板列表") | |||||
| @GetMapping("getTemplateList") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "appId", value = "appId", dataType = "String", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| public ResultData findTemplateList(String appId, Integer pageNum, Integer pageSize) { | |||||
| try { | |||||
| WxMaService maService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| WxMaTemplateListResult ret = maService.getTemplateService().findTemplateList(pageNum, pageSize); | |||||
| return new ResultData(ret); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(Result.ERROR, e.getMessage()); | |||||
| } | |||||
| } | |||||
| @ApiOperation("删除帐号下的某个模板") | |||||
| @PostMapping("delTemplate") | |||||
| public ResultData delTemplate(@RequestParam(value = "appId") String appId, @RequestParam(value = "templateId") String templateId) { | |||||
| try { | |||||
| WxMaService maService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| maService.getTemplateService().delTemplate(templateId); | |||||
| return new ResultData(); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(Result.ERROR, e.getMessage()); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,126 @@ | |||||
| package com.iformall.controller; | |||||
| import com.iformall.common.Result; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.service.wechat.WxOpenService; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | |||||
| import me.chanjar.weixin.open.api.WxOpenMaService; | |||||
| import me.chanjar.weixin.open.bean.result.*; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import java.util.List; | |||||
| /** | |||||
| * Stormeye Wu | |||||
| */ | |||||
| @RestController | |||||
| @RequestMapping("/weappSet") | |||||
| @Api(description = "微信第三方开发平台-小程序设置") | |||||
| public class WechatWeappSetController { | |||||
| private final Logger logger = LoggerFactory.getLogger(getClass()); | |||||
| @Autowired | |||||
| private WxOpenService openService; | |||||
| @ApiOperation("获取小程序服务器域名") | |||||
| @GetMapping("/getDomain") | |||||
| public ResultData modifyDomain(String appId) { | |||||
| try { | |||||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| WxOpenResult openRet = openMaService.getDomain(); | |||||
| logger.info(openRet.toString()); | |||||
| return new ResultData(openRet); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| return new ResultData(Result.ERROR); | |||||
| } | |||||
| @ApiOperation(value = "设置小程序服务器域名", notes = "{\n" + | |||||
| " \"action\":\"add\",\n" + | |||||
| " \"requestdomain\":[\"https://www.qq.com\",\"https://www.qq.com\"],\n" + | |||||
| " \"wsrequestdomain\":[\"wss://www.qq.com\",\"wss://www.qq.com\"],\n" + | |||||
| " \"uploaddomain\":[\"https://www.qq.com\",\"https://www.qq.com\"],\n" + | |||||
| " \"downloaddomain\":[\"https://www.qq.com\",\"https://www.qq.com\"],\n" + | |||||
| " }") | |||||
| @PostMapping("/modifyDomain") | |||||
| public ResultData modifyDomain(@RequestParam(value = "appId") String appId, @RequestParam(value = "action") String action, | |||||
| @RequestParam(value = "requestDomain") List<String> requestDomain, @RequestParam(value = "wsrequestdomain") List<String> wsrequestdomain, | |||||
| @RequestParam(value = "uploaddomain") List<String> uploaddomain, @RequestParam(value = "downloaddomain") List<String> downloaddomain) { | |||||
| try { | |||||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| WxOpenMaDomainResult openRet = openMaService.modifyDomain(action, | |||||
| requestDomain, wsrequestdomain, | |||||
| uploaddomain, downloaddomain); | |||||
| logger.info(openRet.toString()); | |||||
| return new ResultData(openRet); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| return new ResultData(Result.ERROR); | |||||
| } | |||||
| @ApiOperation(value = "设置小程序业务域名", notes = "{\n" + | |||||
| " \"action\":\"add\",\n" + | |||||
| " \"webviewdomain\":[\"https://www.qq.com\",\"https://m.qq.com\"]\n" + | |||||
| " }") | |||||
| @PostMapping("/setWebViewDomain") | |||||
| public ResultData setWebViewDomain(@RequestParam(value = "appId") String appId, @RequestParam(value = "action") String action, | |||||
| @RequestParam(value = "urlList") List<String> urlList) { | |||||
| try { | |||||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| String openRet = openMaService.setWebViewDomain(action, urlList); | |||||
| logger.info(openRet.toString()); | |||||
| return new ResultData(openRet); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| return new ResultData(Result.ERROR); | |||||
| } | |||||
| @ApiOperation(value = "绑定微信用户为小程序体验者", notes = "") | |||||
| @PostMapping("/bindTester") | |||||
| public ResultData bindTester(@RequestParam(value = "appId") String appId, @RequestParam(value = "wechatId") String wechatId) { | |||||
| try { | |||||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| WxOpenResult openRet = openMaService.bindTester(wechatId); | |||||
| logger.info(openRet.toString()); | |||||
| return new ResultData(openRet); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| return new ResultData(Result.ERROR); | |||||
| } | |||||
| @ApiOperation(value = "解除绑定小程序的体验者", notes = "") | |||||
| @PostMapping("/unbindTester") | |||||
| public ResultData unbindTester(@RequestParam(value = "appId") String appId, @RequestParam(value = "wechatId") String wechatId) { | |||||
| try { | |||||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| WxOpenResult openRet = openMaService.unbindTester(wechatId); | |||||
| logger.info(openRet.toString()); | |||||
| return new ResultData(openRet); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| return new ResultData(Result.ERROR); | |||||
| } | |||||
| @ApiOperation(value = "获取体验者列表", notes = "") | |||||
| @PostMapping("/getTesterList") | |||||
| public ResultData getTesterList(@RequestParam(value = "appId") String appId) { | |||||
| try { | |||||
| WxOpenMaService openMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(appId); | |||||
| WxOpenResult openRet = openMaService.getTesterList(); | |||||
| logger.info(openRet.toString()); | |||||
| return new ResultData(openRet); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| return new ResultData(Result.ERROR); | |||||
| } | |||||
| } | |||||
| @@ -1,10 +1,8 @@ | |||||
| package com.iformall.controller; | package com.iformall.controller; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxPropertyContract; | |||||
| import com.iformall.domain.vo.WxBillAll; | import com.iformall.domain.vo.WxBillAll; | ||||
| import com.iformall.service.WxBillAllService; | import com.iformall.service.WxBillAllService; | ||||
| import com.iformall.service.WxPropertyContractService; | |||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| @@ -15,6 +13,8 @@ import org.springframework.web.bind.annotation.ModelAttribute; | |||||
| import org.springframework.web.bind.annotation.RequestMapping; | import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.RestController; | import org.springframework.web.bind.annotation.RestController; | ||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| /** | /** | ||||
| @@ -42,5 +42,12 @@ public class WxBillAllController extends BaseController | |||||
| Map<String, Object> result = wxBillAllService.listAsPage(wxBillAll, pageNum, pageSize); | Map<String, Object> result = wxBillAllService.listAsPage(wxBillAll, pageNum, pageSize); | ||||
| return new ResultData(result); | return new ResultData(result); | ||||
| } | } | ||||
| @GetMapping("exportBill") | |||||
| public void exportBill(@ModelAttribute WxBillAll wxBillAll,HttpServletRequest request, HttpServletResponse response){ | |||||
| wxBillAll.setTenantId(getTenantId()); | |||||
| wxBillAllService.exportBill(request,response,wxBillAll); | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,93 @@ | |||||
| package com.iformall.controller; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.Result; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.WxBrand; | |||||
| import com.iformall.service.WxBrandService; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| import static com.iformall.domain.po.WxBrand.Field.Id_DESC; | |||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| @RestController | |||||
| @RequestMapping("wxBrand") | |||||
| public class WxBrandController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private WxBrandService wxBrandService; | |||||
| @GetMapping("list") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| public ResultData list(@ModelAttribute WxBrand wxBrand, Integer pageNum, Integer pageSize) { | |||||
| logger.debug("[" + getIpAddr() + "] WxBrandController::list"); | |||||
| if (null == wxBrand) { | |||||
| wxBrand = new WxBrand(); | |||||
| } | |||||
| wxBrand.setSortColumns(Id_DESC); | |||||
| final PageInfo<WxBrand> page = wxBrandService.listAsPage(wxBrand, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| @PostMapping("add") | |||||
| public ResultData add(@RequestBody WxBrand wxBrand) { | |||||
| logger.debug("[" + getIpAddr() + "] WxBrandController::add"); | |||||
| wxBrand.setTenantId(getTenantId()); | |||||
| return wxBrandService.save(wxBrand); | |||||
| } | |||||
| @PostMapping("update") | |||||
| public ResultData update(@RequestBody WxBrand wxBrand) { | |||||
| logger.debug("[" + getIpAddr() + "] WxBrandController::update"); | |||||
| wxBrand.setTenantId(getTenantId()); | |||||
| return wxBrandService.update(wxBrand); | |||||
| } | |||||
| @GetMapping("/del") | |||||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||||
| public ResultData delete(Long id) { | |||||
| logger.debug("[" + getIpAddr() + "] WxBrandController::del"); | |||||
| wxBrandService.deleteById(id); | |||||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||||
| } | |||||
| @GetMapping("/findById") | |||||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||||
| public ResultData findById(Long id) { | |||||
| return new ResultData(Result.SUCCESS, "查询成功", wxBrandService.getById(id)); | |||||
| } | |||||
| @GetMapping("/queryBrand") | |||||
| public ResultData queryBrand() { | |||||
| List<Map<String,Object>> brandList = wxBrandService.queryBrand(getTenantId()); | |||||
| return new ResultData(brandList); | |||||
| } | |||||
| @ApiOperation("查询品牌名称是否存在") | |||||
| @GetMapping("hasBrand") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "name", value = "name", dataType = "String", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query")}) | |||||
| public ResultData hasBrand(String name, Long id) { | |||||
| logger.debug("[" + getIpAddr() + "] WxBrandController::hasBrand"); | |||||
| return wxBrandService.hasBrand(getTenantId(), name, id); | |||||
| } | |||||
| } | |||||
| @@ -5,6 +5,7 @@ import com.iformall.common.Result; | |||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxBusiness; | import com.iformall.domain.po.WxBusiness; | ||||
| import com.iformall.service.WxBusinessService; | import com.iformall.service.WxBusinessService; | ||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| @@ -13,8 +14,12 @@ import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
| import java.util.List; | |||||
| import java.util.stream.Collectors; | |||||
| @RestController | @RestController | ||||
| @RequestMapping("wxBusiness") | @RequestMapping("wxBusiness") | ||||
| @Api(description = "业态接口") | |||||
| public class WxBusinessController extends BaseController { | public class WxBusinessController extends BaseController { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| @@ -33,13 +38,32 @@ public class WxBusinessController extends BaseController { | |||||
| return new ResultData(page); | return new ResultData(page); | ||||
| } | } | ||||
| @ApiOperation("成长值业态列表接口") | |||||
| @GetMapping("busListForScore") | |||||
| public ResultData getList() { | |||||
| logger.debug("[" + getIpAddr() + "] WxBusinessController::getList"); | |||||
| WxBusiness wxBusiness = new WxBusiness(); | |||||
| final List<WxBusiness> busList = wxBusinessService.getList(wxBusiness); | |||||
| // 业态 全部 不返回 | |||||
| List<WxBusiness> busList2 = busList.stream().filter(b -> !b.getId().equals(0L)).collect(Collectors.toList()); | |||||
| return new ResultData(busList2); | |||||
| } | |||||
| @ApiOperation("业态全列表接口") | |||||
| @GetMapping("allist") | |||||
| public ResultData getAllList() { | |||||
| logger.debug("[" + getIpAddr() + "] WxBusinessController::getList"); | |||||
| WxBusiness wxBusiness = new WxBusiness(); | |||||
| final List<WxBusiness> busList = wxBusinessService.getList(wxBusiness); | |||||
| return new ResultData(busList); | |||||
| } | |||||
| @ApiOperation("新增接口") | @ApiOperation("新增接口") | ||||
| @PostMapping("add") | @PostMapping("add") | ||||
| public ResultData add(@RequestBody WxBusiness wxBusiness) { | public ResultData add(@RequestBody WxBusiness wxBusiness) { | ||||
| logger.debug("[" + getIpAddr() + "] WxBusinessController::add"); | logger.debug("[" + getIpAddr() + "] WxBusinessController::add"); | ||||
| //Assert.notNull(wxBusiness.getName(), "角色名不能为空"); | //Assert.notNull(wxBusiness.getName(), "角色名不能为空"); | ||||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | ||||
| wxBusinessService.saveOrUpdate(wxBusiness); | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| @@ -47,7 +71,6 @@ public class WxBusinessController extends BaseController { | |||||
| @PostMapping("update") | @PostMapping("update") | ||||
| public ResultData update(@RequestBody WxBusiness wxBusiness) { | public ResultData update(@RequestBody WxBusiness wxBusiness) { | ||||
| logger.debug("[" + getIpAddr() + "] WxBusinessController::update"); | logger.debug("[" + getIpAddr() + "] WxBusinessController::update"); | ||||
| wxBusinessService.saveOrUpdate(wxBusiness); | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| @@ -56,14 +79,13 @@ public class WxBusinessController extends BaseController { | |||||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | ||||
| public ResultData delete(Long id) { | public ResultData delete(Long id) { | ||||
| logger.debug("[" + getIpAddr() + "] WxBusinessController::delete"); | logger.debug("[" + getIpAddr() + "] WxBusinessController::delete"); | ||||
| wxBusinessService.deleteById(id); | |||||
| return new ResultData(Result.SUCCESS, "删除成功", null); | return new ResultData(Result.SUCCESS, "删除成功", null); | ||||
| } | } | ||||
| @ApiOperation("根据id查询接口") | @ApiOperation("根据id查询接口") | ||||
| @GetMapping("/findById") | @GetMapping("/findById") | ||||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | ||||
| public ResultData findById(Long id) { | |||||
| public ResultData findById(Integer id) { | |||||
| logger.debug("[" + getIpAddr() + "] WxBusinessController::findById"); | logger.debug("[" + getIpAddr() + "] WxBusinessController::findById"); | ||||
| return new ResultData(Result.SUCCESS, "查询成功", wxBusinessService.getById(id)); | return new ResultData(Result.SUCCESS, "查询成功", wxBusinessService.getById(id)); | ||||
| } | } | ||||
| @@ -30,6 +30,8 @@ import java.util.Map; | |||||
| import java.util.concurrent.TimeUnit; | import java.util.concurrent.TimeUnit; | ||||
| import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||
| import static com.iformall.domain.po.WxCouponOrder.Field.CreateDate_DESC; | |||||
| @RestController | @RestController | ||||
| @RequestMapping("wxCUserBasicInfo") | @RequestMapping("wxCUserBasicInfo") | ||||
| @Api(description = "会员管理相关接口") | @Api(description = "会员管理相关接口") | ||||
| @@ -206,6 +208,7 @@ public class WxCUserBasicInfoController extends BaseController { | |||||
| WxCouponOrder corder = new WxCouponOrder(); | WxCouponOrder corder = new WxCouponOrder(); | ||||
| corder.setCUserId(userId); | corder.setCUserId(userId); | ||||
| corder.setTenantId(getTenantId()); | corder.setTenantId(getTenantId()); | ||||
| corder.setSortColumns(CreateDate_DESC); | |||||
| PageInfo<WxCouponOrder> page = wxCouponOrderService.listAsPage(corder, pageNum, pageSize); | PageInfo<WxCouponOrder> page = wxCouponOrderService.listAsPage(corder, pageNum, pageSize); | ||||
| if (page.getSize() > 0) { | if (page.getSize() > 0) { | ||||
| List<WxCouponOrder> list = page.getList(); | List<WxCouponOrder> list = page.getList(); | ||||
| @@ -247,8 +250,10 @@ public class WxCUserBasicInfoController extends BaseController { | |||||
| if (allCount) { | if (allCount) { | ||||
| return new ResultData(Result.SUCCESS, "模板正在导入"); | return new ResultData(Result.SUCCESS, "模板正在导入"); | ||||
| } | } | ||||
| stringRedisTemplate.opsForHash().putIfAbsent(userId, "allCount",1+""); | |||||
| stringRedisTemplate.opsForHash().putIfAbsent(userId, "successCount",0+""); | |||||
| stringRedisTemplate.opsForHash().putIfAbsent(userId, "allCount", 0 + ""); | |||||
| stringRedisTemplate.opsForHash().putIfAbsent(userId, "allSuccessCount", 0 + ""); | |||||
| stringRedisTemplate.opsForHash().putIfAbsent(userId, "successCount", ""); | |||||
| stringRedisTemplate.opsForHash().putIfAbsent(userId, "failCount", ""); | |||||
| wxCUserBasicInfoService.importTemplate(file, getTenantId(), userId); | wxCUserBasicInfoService.importTemplate(file, getTenantId(), userId); | ||||
| stringRedisTemplate.expire(userId,30,TimeUnit.MINUTES); | stringRedisTemplate.expire(userId,30,TimeUnit.MINUTES); | ||||
| return new ResultData(Result.SUCCESS, "模板正在导入"); | return new ResultData(Result.SUCCESS, "模板正在导入"); | ||||
| @@ -256,14 +261,35 @@ public class WxCUserBasicInfoController extends BaseController { | |||||
| @GetMapping("/queryTemplateCount") | @GetMapping("/queryTemplateCount") | ||||
| public ResultData queryTemplateCount() { | public ResultData queryTemplateCount() { | ||||
| String userId = getUser().getId().toString(); | String userId = getUser().getId().toString(); | ||||
| Long size = stringRedisTemplate.opsForHash().size(userId); | |||||
| if(size>0){ | |||||
| Map entries = stringRedisTemplate.opsForHash().entries(userId); | |||||
| return new ResultData(Result.SUCCESS,"查询成功",entries); | |||||
| Map entries = stringRedisTemplate.opsForHash().entries(userId); | |||||
| if (entries.size() < 4) { | |||||
| entries.clear(); | |||||
| return new ResultData(Result.SUCCESS, "ok", entries); | |||||
| } | |||||
| String allCount = entries.get("allCount").toString(); | |||||
| String allSuccessCount = entries.get("allSuccessCount").toString(); | |||||
| String successCount = entries.get("successCount").toString(); | |||||
| String failCount = entries.get("failCount").toString(); | |||||
| if (allCount.equals(failCount)) {//stringRedisTemplate.expire(userId,1,TimeUnit.SECONDS); | |||||
| //完全失败 | |||||
| stringRedisTemplate.opsForHash().delete(userId, "allCount"); | |||||
| stringRedisTemplate.opsForHash().delete(userId, "allSuccessCount"); | |||||
| stringRedisTemplate.opsForHash().delete(userId, "successCount"); | |||||
| stringRedisTemplate.opsForHash().delete(userId, "failCount"); | |||||
| return new ResultData(ErrorCode.MEM_IMPORT_ERR); | |||||
| } | |||||
| //导入完成 | |||||
| if (allSuccessCount.equals(successCount)) { | |||||
| ResultData ok = new ResultData(Result.SUCCESS, "ok", entries); | |||||
| stringRedisTemplate.opsForHash().delete(userId, "allCount"); | |||||
| stringRedisTemplate.opsForHash().delete(userId, "allSuccessCount"); | |||||
| stringRedisTemplate.opsForHash().delete(userId, "successCount"); | |||||
| stringRedisTemplate.opsForHash().delete(userId, "failCount"); | |||||
| return ok; | |||||
| } | } | ||||
| return new ResultData(Result.SUCCESS,"查询成功","ok"); | |||||
| return new ResultData(Result.SUCCESS, "查询成功", entries); | |||||
| } | } | ||||
| } | } | ||||
| @@ -12,7 +12,6 @@ import com.iformall.enums.EnumCampaignStatus; | |||||
| import com.iformall.enums.EnumCouponChannelType; | import com.iformall.enums.EnumCouponChannelType; | ||||
| import com.iformall.service.WxCampaignService; | import com.iformall.service.WxCampaignService; | ||||
| import com.iformall.service.WxCouponChannelService; | import com.iformall.service.WxCouponChannelService; | ||||
| import com.iformall.service.WxCouponService; | |||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| @@ -34,9 +33,6 @@ public class WxCampaignController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private WxCampaignService wxCampaignService; | private WxCampaignService wxCampaignService; | ||||
| @Autowired | |||||
| private WxCouponService wxCouponService; | |||||
| @Autowired | @Autowired | ||||
| private WxCouponChannelService wxCouponChannelService; | private WxCouponChannelService wxCouponChannelService; | ||||
| @@ -61,9 +57,6 @@ public class WxCampaignController extends BaseController { | |||||
| @PostMapping("add") | @PostMapping("add") | ||||
| public ResultData add(@RequestBody WxCampaign wxCampaign) { | public ResultData add(@RequestBody WxCampaign wxCampaign) { | ||||
| logger.debug("[" + getIpAddr() + "] WxCampaignController::add"); | logger.debug("[" + getIpAddr() + "] WxCampaignController::add"); | ||||
| //Assert.notNull(wxCampaign.getName(), "角色名不能为空"); | |||||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||||
| // int sortNum = wxCampaignService.getMaxSortNum(getTenantId()); | |||||
| if (StringUtils.isNotBlank(wxCampaign.getCouponIds())) { | if (StringUtils.isNotBlank(wxCampaign.getCouponIds())) { | ||||
| String[] arys = wxCampaign.getCouponIds().split(","); | String[] arys = wxCampaign.getCouponIds().split(","); | ||||
| wxCampaign.setCouponIds(JSON.toJSONString(arys)); | wxCampaign.setCouponIds(JSON.toJSONString(arys)); | ||||
| @@ -72,7 +65,6 @@ public class WxCampaignController extends BaseController { | |||||
| } | } | ||||
| wxCampaign.setStatus(EnumCampaignStatus.STATUS_THROW_IN.getCode()); | wxCampaign.setStatus(EnumCampaignStatus.STATUS_THROW_IN.getCode()); | ||||
| wxCampaign.setTenantId(getTenantId()); | wxCampaign.setTenantId(getTenantId()); | ||||
| // wxCampaign.setSortNum(sortNum+1); | |||||
| wxCampaignService.saveOrUpdate(wxCampaign); | wxCampaignService.saveOrUpdate(wxCampaign); | ||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| @@ -81,14 +73,21 @@ public class WxCampaignController extends BaseController { | |||||
| @PostMapping("update") | @PostMapping("update") | ||||
| public ResultData update(@RequestBody WxCampaign wxCampaign) { | public ResultData update(@RequestBody WxCampaign wxCampaign) { | ||||
| logger.debug("[" + getIpAddr() + "] WxCampaignController::update"); | logger.debug("[" + getIpAddr() + "] WxCampaignController::update"); | ||||
| if (StringUtils.isNotBlank(wxCampaign.getCouponIds())) { | if (StringUtils.isNotBlank(wxCampaign.getCouponIds())) { | ||||
| String[] arys = wxCampaign.getCouponIds().split(","); | String[] arys = wxCampaign.getCouponIds().split(","); | ||||
| wxCampaign.setCouponIds(JSON.toJSONString(arys)); | wxCampaign.setCouponIds(JSON.toJSONString(arys)); | ||||
| } else { | } else { | ||||
| wxCampaign.setCouponIds(JSONArray.toJSONString(new String[0])); | wxCampaign.setCouponIds(JSONArray.toJSONString(new String[0])); | ||||
| } | } | ||||
| wxCampaignService.saveOrUpdate(wxCampaign); | |||||
| return new ResultData(); | |||||
| return wxCampaignService.saveOrUpdate(wxCampaign); | |||||
| } | |||||
| @ApiOperation("根据id更新接口") | |||||
| @PostMapping("updateStatus") | |||||
| public ResultData updateStatus(@RequestBody WxCampaign wxCampaign) { | |||||
| logger.debug("[" + getIpAddr() + "] WxCampaignController::updateStatus"); | |||||
| return wxCampaignService.updateStatus(wxCampaign); | |||||
| } | } | ||||
| @ApiOperation("根据id删除接口") | @ApiOperation("根据id删除接口") | ||||
| @@ -112,7 +111,7 @@ public class WxCampaignController extends BaseController { | |||||
| wxCouponChannel.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_CAMPAIN.getCode()); | wxCouponChannel.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_CAMPAIN.getCode()); | ||||
| wxCouponChannel.setSubTargetId(wxCampaign.getId()); | wxCouponChannel.setSubTargetId(wxCampaign.getId()); | ||||
| wxCouponChannel.setStatus(EnumCampaignStatus.STATUS_THROW_IN.getCode()); | wxCouponChannel.setStatus(EnumCampaignStatus.STATUS_THROW_IN.getCode()); | ||||
| List<WxCouponChannelVo> couponList = wxCouponChannelService.listAPI(wxCouponChannel); | |||||
| List<WxCouponChannelVo> couponList = wxCouponChannelService.listVo(wxCouponChannel); | |||||
| wxCampaign.setCoupons(couponList); | wxCampaign.setCoupons(couponList); | ||||
| } | } | ||||
| return new ResultData(Result.SUCCESS, "查询成功", wxCampaign); | return new ResultData(Result.SUCCESS, "查询成功", wxCampaign); | ||||
| @@ -109,7 +109,7 @@ public class WxCarCallBackController extends BaseController { | |||||
| // TODO 可能多用户关联同一张车牌 | // TODO 可能多用户关联同一张车牌 | ||||
| List<WxCUserCar> userCarList = wxCUserCarService.getList(userCarQ); | List<WxCUserCar> userCarList = wxCUserCarService.getList(userCarQ); | ||||
| for (WxCUserCar userCar : userCarList) { | for (WxCUserCar userCar : userCarList) { | ||||
| wxCouponSendService.sendCouponToUser(tenantId, userCar.getCUserId(), EnumCouponSendSendType.CAR_STOP); | |||||
| wxCouponSendService.sendCouponToUser(EnumCouponSendSendType.CAR_STOP, userCar); | |||||
| } | } | ||||
| } | } | ||||
| @@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONArray; | |||||
| import com.alibaba.fastjson.JSONObject; | import com.alibaba.fastjson.JSONObject; | ||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.dto.WxCouponCarDto; | |||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.domain.vo.WxCouponCarVo; | import com.iformall.domain.vo.WxCouponCarVo; | ||||
| import com.iformall.enums.EnumCarVendor; | import com.iformall.enums.EnumCarVendor; | ||||
| @@ -182,8 +181,6 @@ public class WxCarController extends BaseController { | |||||
| public ResultData save(@RequestBody WxCouponCarVo coupon) { | public ResultData save(@RequestBody WxCouponCarVo coupon) { | ||||
| logger.debug("[" + getIpAddr() + "] WxCarController::save"); | logger.debug("[" + getIpAddr() + "] WxCarController::save"); | ||||
| logger.info(coupon.toString()); | logger.info(coupon.toString()); | ||||
| //Assert.notNull(wxCoupon.getName(), "角色名不能为空"); | |||||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||||
| // Save to wx_counpon | // Save to wx_counpon | ||||
| Date curDate = new Date(); | Date curDate = new Date(); | ||||
| MallUserInfo user = getUser(); | MallUserInfo user = getUser(); | ||||
| @@ -207,58 +204,17 @@ public class WxCarController extends BaseController { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "已达到停车厂商优免券数量限制"); | return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "已达到停车厂商优免券数量限制"); | ||||
| } | } | ||||
| // check End | // check End | ||||
| coupon.setTenantId(user.getTenantId()); | |||||
| WxCoupon wxCoupon = new WxCoupon(); | |||||
| wxCoupon.setTenantId(user.getTenantId()); | |||||
| wxCoupon.setMerchantId(coupon.getMerchantId()); | |||||
| if (StringUtils.isNotEmpty(coupon.getSalePriceStr())) { | |||||
| wxCoupon.setSalePrice((int) (Double.parseDouble(coupon.getSalePriceStr()) * 100)); | |||||
| } | |||||
| if (StringUtils.isNotEmpty(coupon.getUsePriceStr())) { | |||||
| wxCoupon.setUsePrice((int) (Double.parseDouble(coupon.getUsePriceStr()) * 100)); | |||||
| } | |||||
| if (StringUtils.isNotEmpty(coupon.getPriceStr())) { | |||||
| // 不管时间是小时还是金额,都乘100 | |||||
| String priceStr = coupon.getPriceStr(); | |||||
| priceStr = priceStr.replace("元", ""); | |||||
| priceStr = priceStr.replace("小时", ""); | |||||
| wxCoupon.setPrice((int) (Double.parseDouble(priceStr) * 100)); | |||||
| ResultData resultData = wxCouponService.saveOrUpdate(coupon); | |||||
| if (resultData.code != ResultData.SUCCESS){ | |||||
| return resultData; | |||||
| } | } | ||||
| if (StringUtils.isNotBlank(coupon.getBusiness())) { | |||||
| String[] arys = coupon.getBusiness().split(","); | |||||
| wxCoupon.setBusiness(JSON.toJSONString(arys)); | |||||
| } | |||||
| if(coupon.getId() != null && coupon.getId().longValue() > 0) { | |||||
| wxCoupon.setId(coupon.getId()); | |||||
| } | |||||
| wxCoupon.setType(coupon.getType()); | |||||
| wxCoupon.setCoverImg(coupon.getCoverImg()); | |||||
| wxCoupon.setTitle(coupon.getTitle()); | |||||
| wxCoupon.setSubTitle(coupon.getSubTitle()); | |||||
| wxCoupon.setUseLimitQuantity(coupon.getUseLimitQuantity()); | |||||
| wxCoupon.setTargetAd(coupon.getTargetAd()); | |||||
| wxCoupon.setSendType(coupon.getSendType()); | |||||
| wxCoupon.setValidType(coupon.getValidType()); | |||||
| wxCoupon.setValidStartDate(coupon.getValidStartDate()); | |||||
| wxCoupon.setValidEndDate(coupon.getValidEndDate()); | |||||
| wxCoupon.setValidDays(coupon.getValidDays()); | |||||
| wxCoupon.setDetail(coupon.getDetail()); | |||||
| wxCoupon.setUnit(coupon.getUnit()); | |||||
| wxCoupon.setRemainInventory(coupon.getRemainInventory()); | |||||
| wxCoupon.setInventory(coupon.getInventory()); | |||||
| wxCoupon.setRemark(coupon.getRemark()); | |||||
| wxCoupon.setStatus(EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode()); | |||||
| wxCoupon.setCreateDate(curDate); | |||||
| wxCoupon.setUpdateDate(curDate); | |||||
| wxCoupon.setChannels(""); | |||||
| Long id = wxCouponService.saveOrUpdate(wxCoupon); | |||||
| // Save to wx_coupon_car | // Save to wx_coupon_car | ||||
| WxCouponCar couponCar = new WxCouponCar(); | WxCouponCar couponCar = new WxCouponCar(); | ||||
| couponCar.setId(id); | |||||
| couponCar.setId(coupon.getId()); | |||||
| couponCar.setTenantId(user.getTenantId()); | couponCar.setTenantId(user.getTenantId()); | ||||
| couponCar.setMerchantId(coupon.getMerchantId()); | |||||
| WxPark park = getCurrentPark(user); | WxPark park = getCurrentPark(user); | ||||
| couponCar.setParkId(park.getId()); | couponCar.setParkId(park.getId()); | ||||
| @@ -273,8 +229,7 @@ public class WxCarController extends BaseController { | |||||
| wxCouponCarService.update(couponCar); | wxCouponCarService.update(couponCar); | ||||
| } | } | ||||
| return new ResultData(id); | |||||
| return new ResultData(coupon.getId()); | |||||
| } | } | ||||
| @@ -314,26 +269,9 @@ public class WxCarController extends BaseController { | |||||
| @ApiOperation("停车券detail") | @ApiOperation("停车券detail") | ||||
| @GetMapping("/detail") | @GetMapping("/detail") | ||||
| public ResultData getCouponCarDetail(@ModelAttribute WxCoupon coupon) { | |||||
| public ResultData getCouponCarDetail(@RequestParam Long id) { | |||||
| logger.debug("[" + getIpAddr() + "] WxCarController::getCouponCarDetail"); | logger.debug("[" + getIpAddr() + "] WxCarController::getCouponCarDetail"); | ||||
| MallUserInfo user = getUser(); | |||||
| coupon.setTenantId(user.getTenantId()); | |||||
| try { | |||||
| WxCouponCarVo couponCarVo = wxCouponCarService.getByCoupon(coupon); | |||||
| if (couponCarVo != null) { | |||||
| WxCouponCarDto dto = new WxCouponCarDto(); | |||||
| org.springframework.beans.BeanUtils.copyProperties(couponCarVo, dto); | |||||
| WxMerchant merchant = wxMerchantService.getById(couponCarVo.getMerchantId()); | |||||
| dto.setWxMerchant(merchant); | |||||
| return new ResultData(dto); | |||||
| } else { | |||||
| return new ResultData(ErrorCode.COUPON_IS_EMPTY); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(ErrorCode.DB_FAIL.getCode(), e.getMessage()); | |||||
| } | |||||
| return new ResultData(wxCouponCarService.findDetailVo(id)); | |||||
| } | } | ||||
| @ApiOperation(value = "停车场状态") | @ApiOperation(value = "停车场状态") | ||||
| @@ -0,0 +1,156 @@ | |||||
| package com.iformall.controller; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.*; | |||||
| import com.iformall.domain.vo.WxCardSpendVo; | |||||
| import com.iformall.domain.vo.WxCardVo; | |||||
| import com.iformall.enums.EnumCardSpendStatus; | |||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.service.WxCardInfoService; | |||||
| import com.iformall.service.WxCardSpendService; | |||||
| import com.iformall.service.WxMerchantService; | |||||
| import com.iformall.service.WxOrderService; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.util.ArrayList; | |||||
| import java.util.Date; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| /** | |||||
| * @author Stormeye Wu wuguoqiang@iformall.com | |||||
| */ | |||||
| @RestController | |||||
| @Api(description = "C端扫B端商户码储值卡支付") | |||||
| @RequestMapping("cardPay") | |||||
| public class WxCardPayController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| WxMerchantService wxMerchantService; | |||||
| @Autowired | |||||
| WxOrderService wxOrderService; | |||||
| @Autowired | |||||
| WxCardInfoService wxCardInfoService; | |||||
| @Autowired | |||||
| WxCardSpendService wxCardSpendService; | |||||
| @ApiOperation("售卡记录列表接口") | |||||
| @GetMapping("list") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| public ResultData cardOrderList(@ModelAttribute WxCardVo wxCardVo, Integer pageNum, Integer pageSize) { | |||||
| String ipStr = getIpAddr(); | |||||
| logger.info("cardOrderList: " + ipStr); | |||||
| if (wxCardVo == null) wxCardVo = new WxCardVo(); | |||||
| MallUserInfo user = getUser(); | |||||
| wxCardVo.setTenantId(user.getTenantId()); | |||||
| if(StringUtils.isNotBlank(wxCardVo.getStatusStr())) { | |||||
| String [] statusAttr = wxCardVo.getStatusStr().split(","); | |||||
| List<Integer> tmpList = new ArrayList<Integer>(); | |||||
| for(String status: statusAttr) { | |||||
| tmpList.add(Integer.valueOf(status)); | |||||
| } | |||||
| if(!tmpList.isEmpty()) { | |||||
| wxCardVo.setStatusS(tmpList); | |||||
| } | |||||
| } | |||||
| final PageInfo<WxCardVo> page = wxCardInfoService.listAsPage(wxCardVo, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| @ApiOperation("C端扫B端储值卡交易流水(消费记录 + 补贴)列表接口") | |||||
| @GetMapping("cardSpendlist") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| public ResultData cardSpendlist(@ModelAttribute WxCardSpendVo wxCardSpendVo, Integer pageNum, Integer pageSize) { | |||||
| String ipStr = getIpAddr(); | |||||
| logger.info("cardSpendlist: " + ipStr); | |||||
| if (wxCardSpendVo == null) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "过滤条件为空"); | |||||
| } | |||||
| MallUserInfo user = getUser(); | |||||
| wxCardSpendVo.setTenantId(user.getTenantId()); | |||||
| if(StringUtils.isNotBlank(wxCardSpendVo.getPayStatusStr())) { | |||||
| String [] statusAttr = wxCardSpendVo.getPayStatusStr().split(","); | |||||
| List<Integer> tmpList = new ArrayList<Integer>(); | |||||
| for(String status: statusAttr) { | |||||
| tmpList.add(Integer.valueOf(status)); | |||||
| } | |||||
| if(!tmpList.isEmpty()) { | |||||
| wxCardSpendVo.setPayStatusS(tmpList); | |||||
| } | |||||
| } | |||||
| final PageInfo<WxCardSpendVo> page = wxCardSpendService.listAsPage(wxCardSpendVo, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| @ApiOperation("C端扫B端储值卡交易流水SUM") | |||||
| @GetMapping("sum") | |||||
| public ResultData sumCardSpendList(@ModelAttribute WxCardSpendVo wxCardSpend) { | |||||
| String ipStr = getIpAddr(); | |||||
| logger.info("sumCardSpendList: " + ipStr + " :" + wxCardSpend.toString()); | |||||
| if (wxCardSpend == null) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "过滤条件为空"); | |||||
| } | |||||
| MallUserInfo user = getUser(); | |||||
| wxCardSpend.setTenantId(user.getTenantId()); | |||||
| final Map map = wxCardSpendService.sumCardSpendForMerchant(wxCardSpend); | |||||
| return new ResultData(map); | |||||
| } | |||||
| @ApiOperation("交易流水导出") | |||||
| @GetMapping("/exportData") | |||||
| public void exportData(@ModelAttribute WxCardSpendVo wxCardSpendVo, HttpServletRequest request, HttpServletResponse response) { | |||||
| logger.info("[" + getIpAddr() + "] WxCardPayController::exportData"); | |||||
| if (wxCardSpendVo == null) { | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "过滤条件为空"); | |||||
| } | |||||
| wxCardSpendVo.setTenantId(getTenantId()); | |||||
| if(StringUtils.isNotBlank(wxCardSpendVo.getPayStatusStr())) { | |||||
| String [] statusAttr = wxCardSpendVo.getPayStatusStr().split(","); | |||||
| List<Integer> tmpList = new ArrayList<Integer>(); | |||||
| for(String status: statusAttr) { | |||||
| tmpList.add(Integer.valueOf(status)); | |||||
| } | |||||
| if(!tmpList.isEmpty()) { | |||||
| wxCardSpendVo.setPayStatusS(tmpList); | |||||
| } | |||||
| } | |||||
| wxCardSpendService.exportData(wxCardSpendVo, request, response); | |||||
| } | |||||
| @ApiOperation("更新补贴记录") | |||||
| @PostMapping("update") | |||||
| public ResultData update(@RequestBody WxCardSpendVo wxCardSpendVo) { | |||||
| String ipStr = getIpAddr(); | |||||
| logger.info("subsidy/update: " + ipStr + " :" + wxCardSpendVo.toString()); | |||||
| if (wxCardSpendVo == null) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "过滤条件为空"); | |||||
| } | |||||
| MallUserInfo user = getUser(); | |||||
| wxCardSpendVo.setTenantId(user.getTenantId()); | |||||
| wxCardSpendVo.setStatus(EnumCardSpendStatus.MANUAL_PAY.getCode()); | |||||
| wxCardSpendVo.setUpdateDate(new Date()); | |||||
| int num = wxCardSpendService.update(wxCardSpendVo); | |||||
| return new ResultData(num); | |||||
| } | |||||
| } | |||||
| @@ -52,7 +52,7 @@ public class WxCouponChannelController extends BaseController { | |||||
| } | } | ||||
| wxCouponChannel.setTenantId(getUser().getTenantId()); | wxCouponChannel.setTenantId(getUser().getTenantId()); | ||||
| wxCouponChannel.setSortColumns(WxCouponChannel.Field.Id_DESC); | wxCouponChannel.setSortColumns(WxCouponChannel.Field.Id_DESC); | ||||
| final PageInfo<WxCouponChannelVo> page = wxCouponChannelService.listPageCAPI(wxCouponChannel, pageNum, pageSize ,false); | |||||
| final PageInfo<WxCouponChannelVo> page = wxCouponChannelService.listPageCVo(wxCouponChannel, pageNum, pageSize); | |||||
| return new ResultData(page); | return new ResultData(page); | ||||
| } | } | ||||
| @@ -2,13 +2,14 @@ package com.iformall.controller; | |||||
| import com.alibaba.fastjson.JSON; | import com.alibaba.fastjson.JSON; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.dto.WxCounponDto; | |||||
| import com.iformall.domain.po.WxCoupon; | import com.iformall.domain.po.WxCoupon; | ||||
| import com.iformall.domain.po.WxCouponChannel; | import com.iformall.domain.po.WxCouponChannel; | ||||
| import com.iformall.domain.po.WxMerchant; | import com.iformall.domain.po.WxMerchant; | ||||
| import com.iformall.enums.EnumCouponStatus; | import com.iformall.enums.EnumCouponStatus; | ||||
| import com.iformall.enums.EnumCouponType; | |||||
| import com.iformall.enums.EnumCouponValidType; | import com.iformall.enums.EnumCouponValidType; | ||||
| import com.iformall.enums.EnumMerchantStatus; | import com.iformall.enums.EnumMerchantStatus; | ||||
| import com.iformall.service.WxCouponChannelService; | import com.iformall.service.WxCouponChannelService; | ||||
| @@ -38,25 +39,17 @@ public class WxCouponController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private WxCouponService wxCouponService; | private WxCouponService wxCouponService; | ||||
| @Autowired | |||||
| private WxMerchantService wxMerchantService; | |||||
| @Autowired | @Autowired | ||||
| private WxCouponChannelService wxCouponChannelService; | private WxCouponChannelService wxCouponChannelService; | ||||
| @ApiOperation("分页列表接口") | |||||
| @GetMapping("list") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| public ResultData list(@ModelAttribute WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { | |||||
| logger.debug("[" + getIpAddr() + "] WxCouponController::list"); | |||||
| private ResultData listType(@ModelAttribute WxCoupon wxCoupon, Integer pageNum, Integer pageSize, Integer type) { | |||||
| if (null == wxCoupon) wxCoupon = new WxCoupon(); | if (null == wxCoupon) wxCoupon = new WxCoupon(); | ||||
| wxCoupon.setTenantId(getTenantId()); | wxCoupon.setTenantId(getTenantId()); | ||||
| wxCoupon.setSortColumns(WxCoupon.Field.Id_DESC); | wxCoupon.setSortColumns(WxCoupon.Field.Id_DESC); | ||||
| PageInfo<WxCoupon> page = null; | PageInfo<WxCoupon> page = null; | ||||
| if (wxCoupon.getStatus() != null && wxCoupon.getStatus() == -1) | if (wxCoupon.getStatus() != null && wxCoupon.getStatus() == -1) | ||||
| wxCoupon.setStatus(null); | wxCoupon.setStatus(null); | ||||
| page = wxCouponService.listAsPage(wxCoupon, pageNum, pageSize); | |||||
| page = wxCouponService.listAsPage(wxCoupon, pageNum, pageSize, type); | |||||
| List<WxCoupon> wxCouponList = page.getList(); | List<WxCoupon> wxCouponList = page.getList(); | ||||
| @@ -95,41 +88,45 @@ public class WxCouponController extends BaseController { | |||||
| } | } | ||||
| } | } | ||||
| return new ResultData(page); | return new ResultData(page); | ||||
| } | } | ||||
| @ApiOperation("分页列表接口") | |||||
| @GetMapping("listCoupon") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| public ResultData listCoupon(@ModelAttribute WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { | |||||
| logger.debug("[" + getIpAddr() + "] WxCouponController::listCoupon"); | |||||
| return listType(wxCoupon, pageNum, pageSize, 0); //券列表 | |||||
| } | |||||
| @ApiOperation("分页列表接口") | |||||
| @GetMapping("listCard") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| public ResultData listCard(@ModelAttribute WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { | |||||
| logger.debug("[" + getIpAddr() + "] WxCouponController::listCard"); | |||||
| return listType(wxCoupon, pageNum, pageSize, EnumCouponType.CARD_MULTIMCH.getCode()); //卡列表 | |||||
| } | |||||
| @ApiOperation("分页列表接口") | |||||
| @GetMapping("list") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| public ResultData list(@ModelAttribute WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { | |||||
| logger.debug("[" + getIpAddr() + "] WxCouponController::list"); | |||||
| return listType(wxCoupon, pageNum, pageSize, null); //全列表 | |||||
| } | |||||
| @ApiOperation("新增接口") | @ApiOperation("新增接口") | ||||
| @PostMapping("add") | @PostMapping("add") | ||||
| public ResultData add(@RequestBody WxCoupon wxCoupon) { | public ResultData add(@RequestBody WxCoupon wxCoupon) { | ||||
| logger.debug("[" + getIpAddr() + "] WxCouponController::add"); | logger.debug("[" + getIpAddr() + "] WxCouponController::add"); | ||||
| //Assert.notNull(wxCoupon.getName(), "角色名不能为空"); | |||||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||||
| if (StringUtils.isNotEmpty(wxCoupon.getSalePriceStr())) { | |||||
| wxCoupon.setSalePrice((int) (Double.parseDouble(wxCoupon.getSalePriceStr()) * 100)); | |||||
| } | |||||
| if (StringUtils.isNotEmpty(wxCoupon.getUsePriceStr())) { | |||||
| wxCoupon.setUsePrice((int) (Double.parseDouble(wxCoupon.getUsePriceStr()) * 100)); | |||||
| } | |||||
| if (StringUtils.isNotEmpty(wxCoupon.getPriceStr())) { | |||||
| wxCoupon.setPrice((int) (Double.parseDouble(wxCoupon.getPriceStr()) * 100)); | |||||
| } | |||||
| if (StringUtils.isNotBlank(wxCoupon.getBusiness())) { | |||||
| String[] arys = wxCoupon.getBusiness().split(","); | |||||
| wxCoupon.setBusiness(JSON.toJSONString(arys)); | |||||
| } | |||||
| wxCoupon.setTenantId(getUser().getTenantId()); | |||||
| wxCoupon.setChannels(""); | |||||
| if (wxCoupon.getValidType() != null) { | |||||
| if (wxCoupon.getValidType().equals(EnumCouponValidType.DAYS_AFTER_RECEIVING)) { | |||||
| wxCoupon.setValidStartDate(null); | |||||
| wxCoupon.setValidEndDate(null); | |||||
| } else if (wxCoupon.getValidType().equals(EnumCouponValidType.BETWEEN_TWO_TIME)) { | |||||
| wxCoupon.setValidDays(null); | |||||
| } | |||||
| } | |||||
| Long id = wxCouponService.saveOrUpdate(wxCoupon); | |||||
| return new ResultData(id); | |||||
| return wxCouponService.saveOrUpdate(wxCoupon); | |||||
| } | } | ||||
| @ApiOperation("根据id更新接口") | @ApiOperation("根据id更新接口") | ||||
| @@ -139,28 +136,8 @@ public class WxCouponController extends BaseController { | |||||
| if (wxCoupon.getId() == null) { | if (wxCoupon.getId() == null) { | ||||
| return new ResultData(ResultData.ERROR, "缺少id"); | return new ResultData(ResultData.ERROR, "缺少id"); | ||||
| } | } | ||||
| if (StringUtils.isNotEmpty(wxCoupon.getSalePriceStr())) { | |||||
| wxCoupon.setSalePrice((int) (Double.parseDouble(wxCoupon.getSalePriceStr()) * 100)); | |||||
| } | |||||
| if (StringUtils.isNotEmpty(wxCoupon.getUsePriceStr())) { | |||||
| wxCoupon.setUsePrice((int) (Double.parseDouble(wxCoupon.getUsePriceStr()) * 100)); | |||||
| } | |||||
| if (StringUtils.isNotEmpty(wxCoupon.getPriceStr())) { | |||||
| wxCoupon.setPrice((int) (Double.parseDouble(wxCoupon.getPriceStr()) * 100)); | |||||
| } | |||||
| if (StringUtils.isNotBlank(wxCoupon.getBusiness())) { | |||||
| String[] arys = wxCoupon.getBusiness().split(","); | |||||
| wxCoupon.setBusiness(JSON.toJSONString(arys)); | |||||
| } | |||||
| if (wxCoupon.getValidType() != null) { | |||||
| if (wxCoupon.getValidType().equals(EnumCouponValidType.DAYS_AFTER_RECEIVING)) { | |||||
| wxCoupon.setValidStartDate(null); | |||||
| wxCoupon.setValidEndDate(null); | |||||
| } else if (wxCoupon.getValidType().equals(EnumCouponValidType.BETWEEN_TWO_TIME)) { | |||||
| wxCoupon.setValidDays(null); | |||||
| } | |||||
| } | |||||
| return wxCouponService.updateCoupon(wxCoupon); | |||||
| wxCoupon.setTenantId(getTenantId()); | |||||
| return wxCouponService.saveOrUpdate(wxCoupon); | |||||
| } | } | ||||
| @ApiOperation("根据id删除接口") | @ApiOperation("根据id删除接口") | ||||
| @@ -175,32 +152,8 @@ public class WxCouponController extends BaseController { | |||||
| @ApiOperation("根据id查询接口") | @ApiOperation("根据id查询接口") | ||||
| @GetMapping("/findById") | @GetMapping("/findById") | ||||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | ||||
| public ResultData findById(Long id) { | |||||
| logger.debug("[" + getIpAddr() + "] WxCouponController::findById"); | |||||
| WxCoupon c = wxCouponService.getById(id); | |||||
| WxMerchant merchant = wxMerchantService.getById(c.getMerchantId()); | |||||
| if(merchant.getStatus().equals(EnumMerchantStatus.NOT_VALID.getCode())) | |||||
| return new ResultData(Result.ERROR, "此券的商户已禁用"); | |||||
| WxCounponDto dto = new WxCounponDto(); | |||||
| org.springframework.beans.BeanUtils.copyProperties(c, dto); | |||||
| dto.setWxMerchant(merchant); | |||||
| return new ResultData(Result.SUCCESS, "查询成功", dto); | |||||
| } | |||||
| @ApiOperation("分页列表接口") | |||||
| @GetMapping("send/list") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| public ResultData sendList(@ModelAttribute WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { | |||||
| logger.debug("[" + getIpAddr() + "] WxCouponController::sendList"); | |||||
| if (null == wxCoupon) wxCoupon = new WxCoupon(); | |||||
| wxCoupon.setTenantId(getTenantId()); | |||||
| wxCoupon.setStatus(EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode()); | |||||
| return new ResultData(wxCouponService.listAsPage(wxCoupon, pageNum, pageSize)); | |||||
| public ResultData findById(@RequestParam Long id) { | |||||
| logger.debug("[" + getIpAddr() + "] WxCouponController::findById");; | |||||
| return new ResultData(wxCouponService.getVoById(id)); | |||||
| } | } | ||||
| } | } | ||||
| @@ -8,7 +8,7 @@ import com.iformall.domain.po.WxAppinfo; | |||||
| import com.iformall.domain.po.WxCouponOrder; | import com.iformall.domain.po.WxCouponOrder; | ||||
| import com.iformall.domain.vo.WxCouponOrderBVo; | import com.iformall.domain.vo.WxCouponOrderBVo; | ||||
| import com.iformall.enums.EnumAppType; | import com.iformall.enums.EnumAppType; | ||||
| import com.iformall.enums.EnumRefundWay; | |||||
| import com.iformall.enums.EnumPayType; | |||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.service.WxAppinfoService; | import com.iformall.service.WxAppinfoService; | ||||
| import com.iformall.service.WxCouponOrderService; | import com.iformall.service.WxCouponOrderService; | ||||
| @@ -26,7 +26,6 @@ import org.springframework.web.bind.annotation.*; | |||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||
| import javax.servlet.http.HttpServletResponse; | import javax.servlet.http.HttpServletResponse; | ||||
| import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||
| import java.util.Date; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| @RestController | @RestController | ||||
| @@ -56,10 +55,26 @@ public class WxCouponOrderController extends BaseController { | |||||
| logger.debug("[" + getIpAddr() + "] WxCouponOrderController::list"); | logger.debug("[" + getIpAddr() + "] WxCouponOrderController::list"); | ||||
| if (wxCouponOrder == null) wxCouponOrder = new WxCouponOrderBVo(); | if (wxCouponOrder == null) wxCouponOrder = new WxCouponOrderBVo(); | ||||
| wxCouponOrder.setTenantId(getTenantId()); | wxCouponOrder.setTenantId(getTenantId()); | ||||
| if (wxCouponOrder.getMerchantName() != null && | |||||
| wxCouponOrder.getMerchantName().isEmpty()) { | |||||
| wxCouponOrder.setMerchantName(null); | |||||
| } | |||||
| wxCouponOrder.setSortColumns(WxCouponOrder.Field.Id_DESC); | wxCouponOrder.setSortColumns(WxCouponOrder.Field.Id_DESC); | ||||
| return wxCouponOrderService.listAdminAsPage(wxCouponOrder, pageNum, pageSize); | return wxCouponOrderService.listAdminAsPage(wxCouponOrder, pageNum, pageSize); | ||||
| } | } | ||||
| @ApiOperation(value = "卡券详情接口") | |||||
| @GetMapping("detail") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "couponOrderId", value = "券ID", dataType = "Long", paramType = "query", required = true) | |||||
| }) | |||||
| public ResultData detail(@RequestParam("couponOrderId") Long couponOrderId) { | |||||
| if(couponOrderId == null) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| } | |||||
| return wxCouponOrderService.detailAdminVo(couponOrderId); | |||||
| } | |||||
| @RequestMapping("/exportData") | @RequestMapping("/exportData") | ||||
| public void exportData( | public void exportData( | ||||
| @RequestParam("endDate") String endDate, | @RequestParam("endDate") String endDate, | ||||
| @@ -128,7 +143,7 @@ public class WxCouponOrderController extends BaseController { | |||||
| WxAppinfo appinfo = appinfoPageInfo.getList().get(0); | WxAppinfo appinfo = appinfoPageInfo.getList().get(0); | ||||
| if (appinfo != null) { | if (appinfo != null) { | ||||
| try { | try { | ||||
| wxRefundOrderService.createRefundOrder(payProperty.isReal(), appinfo, couponOrderId, EnumRefundWay.ADMIN, null); | |||||
| wxRefundOrderService.createRefundOrder(payProperty.isReal(), appinfo, couponOrderId, EnumPayType.PAY_ADMIN_REFUND, null); | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| @@ -0,0 +1,63 @@ | |||||
| package com.iformall.controller; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.WxCouponSendConfig; | |||||
| import com.iformall.service.WxCouponSendConfigService; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import java.util.Date; | |||||
| @RestController | |||||
| @RequestMapping("wxCouponSendConfig") | |||||
| @Api(description = "停车发券和核销发劵接口") | |||||
| public class WxCouponSendConfigController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private WxCouponSendConfigService wxCouponSendConfigService; | |||||
| @ApiOperation("获取开关") | |||||
| @GetMapping("get") | |||||
| public ResultData getCouponSendConfig(@ModelAttribute WxCouponSendConfig wxCouponSendConfig) { | |||||
| logger.debug("[" + getIpAddr() + "] WxMallConfigController::getCouponSendConfig"); | |||||
| if (wxCouponSendConfig == null || wxCouponSendConfig.getSendType() == null) | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||||
| wxCouponSendConfig.setTenantId(getTenantId()); | |||||
| PageInfo<WxCouponSendConfig> page = wxCouponSendConfigService.listAsPage(wxCouponSendConfig, 1, 1); | |||||
| if (page.getSize() > 0) { | |||||
| return new ResultData(page.getList().get(0)); | |||||
| } | |||||
| return new ResultData(); | |||||
| } | |||||
| @PostMapping("update") | |||||
| @ApiOperation("修改开关") | |||||
| public ResultData updateCouponSendConfig(@RequestBody WxCouponSendConfig wxCouponSendConfig) { | |||||
| logger.debug("[" + getIpAddr() + "] WxMallConfigController::updateStopCarConpon"); | |||||
| if (wxCouponSendConfig == null) | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||||
| if (wxCouponSendConfig.getId() == null) | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||||
| if (wxCouponSendConfig.getSendType() == null) | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||||
| if (wxCouponSendConfig.getValue() == null) | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||||
| wxCouponSendConfig.setTenantId(getTenantId()); | |||||
| wxCouponSendConfig.setUpdateTime(new Date()); | |||||
| wxCouponSendConfigService.update(wxCouponSendConfig); | |||||
| return new ResultData(); | |||||
| } | |||||
| } | |||||
| @@ -67,6 +67,7 @@ public class WxCouponSendController extends BaseController { | |||||
| if (wxCouponSendList != null && wxCouponSendList.size() > 0) { | if (wxCouponSendList != null && wxCouponSendList.size() > 0) { | ||||
| return new ResultData(ErrorCode.COUPON_SEND_IS_EXISTED); | return new ResultData(ErrorCode.COUPON_SEND_IS_EXISTED); | ||||
| } | } | ||||
| WxCoupon wxCoupon = wxCouponService.getById(wxCouponSend.getCouponId()); | WxCoupon wxCoupon = wxCouponService.getById(wxCouponSend.getCouponId()); | ||||
| if (!wxCoupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode()) ){ | if (!wxCoupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode()) ){ | ||||
| return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); | return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); | ||||
| @@ -76,9 +77,6 @@ public class WxCouponSendController extends BaseController { | |||||
| return new ResultData(ErrorCode.COUPON_TYPE_IS_NOT_PASSIVE); | return new ResultData(ErrorCode.COUPON_TYPE_IS_NOT_PASSIVE); | ||||
| } | } | ||||
| wxCouponSend.setMerchantId(wxCoupon.getMerchantId()); | |||||
| wxCouponSend.setType(wxCoupon.getType()); | |||||
| wxCouponSend.setTenantId(wxCoupon.getTenantId()); | wxCouponSend.setTenantId(wxCoupon.getTenantId()); | ||||
| wxCouponSend.setTitle(wxCoupon.getTitle()); | wxCouponSend.setTitle(wxCoupon.getTitle()); | ||||
| wxCouponSend.setCreateDate(new Date()); | wxCouponSend.setCreateDate(new Date()); | ||||
| @@ -102,8 +100,6 @@ public class WxCouponSendController extends BaseController { | |||||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | ||||
| public ResultData delete(Long id) { | public ResultData delete(Long id) { | ||||
| logger.debug("[" + getIpAddr() + "] WxCouponSendController::delete"); | logger.debug("[" + getIpAddr() + "] WxCouponSendController::delete"); | ||||
| //wxCouponSendService.deleteById(id); | |||||
| //return new ResultData(Result.SUCCESS, "删除成功", null); | |||||
| WxCouponSend wxCouponSend = wxCouponSendService.getById(id); | WxCouponSend wxCouponSend = wxCouponSendService.getById(id); | ||||
| if (wxCouponSend == null) | if (wxCouponSend == null) | ||||
| return new ResultData(ErrorCode.COUPON_SEND_IS_INVALID); | return new ResultData(ErrorCode.COUPON_SEND_IS_INVALID); | ||||
| @@ -1,5 +1,6 @@ | |||||
| package com.iformall.controller; | package com.iformall.controller; | ||||
| import com.iformall.common.ErrorCode; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -13,7 +14,6 @@ import org.springframework.web.bind.annotation.RestController; | |||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.dto.WxLevelConfigDto; | |||||
| import com.iformall.domain.po.WxLevelConfig; | import com.iformall.domain.po.WxLevelConfig; | ||||
| import com.iformall.service.WxLevelConfigService; | import com.iformall.service.WxLevelConfigService; | ||||
| @@ -22,6 +22,8 @@ import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import java.util.List; | |||||
| @RestController | @RestController | ||||
| @RequestMapping("wxLevelConfig") | @RequestMapping("wxLevelConfig") | ||||
| @Api(description="等级权益相关接口") | @Api(description="等级权益相关接口") | ||||
| @@ -47,26 +49,16 @@ public class WxLevelConfigController extends BaseController { | |||||
| @ApiOperation("新增接口") | @ApiOperation("新增接口") | ||||
| @PostMapping("add") | @PostMapping("add") | ||||
| public ResultData add(@RequestBody WxLevelConfigDto dto) { | |||||
| public ResultData add(@RequestBody List<WxLevelConfig> levelConfigs) { | |||||
| logger.debug("[" + getIpAddr() + "] WxLevelConfigController::add"); | logger.debug("[" + getIpAddr() + "] WxLevelConfigController::add"); | ||||
| //Assert.notNull(wxLevelConfig.getName(), "角色名不能为空"); | //Assert.notNull(wxLevelConfig.getName(), "角色名不能为空"); | ||||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | ||||
| String[] points = dto.getPoints().split("&"); | |||||
| String[] level = dto.getLevel().split("&"); | |||||
| String[] descs =dto.getDescription().split("&"); | |||||
| if (points.length != level.length) { | |||||
| return new ResultData(Result.ERROR, "请同时设置成长值和等级"); | |||||
| } | |||||
| String tenantId = getTenantId(); | String tenantId = getTenantId(); | ||||
| wxLevelConfigService.deleteAll(tenantId); | |||||
| for(int i=0;i<points.length;i++) { | |||||
| WxLevelConfig wxLevelConfig = new WxLevelConfig(); | |||||
| wxLevelConfig.setTenantId(tenantId); | |||||
| wxLevelConfig.setPoints(Integer.parseInt(points[i])); | |||||
| wxLevelConfig.setLevel(level[i]); | |||||
| if (descs.length > 0 && i < descs.length) | |||||
| wxLevelConfig.setDescription(descs[i]); | |||||
| wxLevelConfigService.saveOrUpdate(wxLevelConfig); | |||||
| try { | |||||
| wxLevelConfigService.batchSave(tenantId, levelConfigs); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(ErrorCode.DB_FAIL); | |||||
| } | } | ||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| @@ -1,148 +0,0 @@ | |||||
| package com.iformall.controller; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.WxMallConfig; | |||||
| import com.iformall.service.WxMallConfigService; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| @RestController | |||||
| @RequestMapping("wxMallConfig") | |||||
| @Api(description = "停车发券和核销发劵接口") | |||||
| public class WxMallConfigController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private WxMallConfigService wxMallConfigService; | |||||
| @ApiOperation("获取停车劵开关") | |||||
| @GetMapping("getStopCarCoupon") | |||||
| public ResultData getStopCarConpon() { | |||||
| logger.debug("[" + getIpAddr() + "] WxMallConfigController::getStopCarConpon"); | |||||
| WxMallConfig wxMallConfig = new WxMallConfig(); | |||||
| wxMallConfig.setKey("stopCarCouponSwitch"); | |||||
| wxMallConfig.setTenantId(getTenantId()); | |||||
| PageInfo<WxMallConfig> page = wxMallConfigService.listAsPage(wxMallConfig, 1, 1); | |||||
| if (page.getSize() > 0) { | |||||
| WxMallConfig config = page.getList().get(0); | |||||
| return new ResultData(config); | |||||
| } | |||||
| return new ResultData(); | |||||
| } | |||||
| @ApiOperation("获取核销劵开关") | |||||
| @GetMapping("getVerifyCoupon") | |||||
| public ResultData getVerifyConpon() { | |||||
| logger.debug("[" + getIpAddr() + "] WxMallConfigController::getVerifyConpon"); | |||||
| WxMallConfig wxMallConfig = new WxMallConfig(); | |||||
| wxMallConfig.setKey("verifyCouponSwitch"); | |||||
| wxMallConfig.setTenantId(getTenantId()); | |||||
| PageInfo<WxMallConfig> page = wxMallConfigService.listAsPage(wxMallConfig, 1, 1); | |||||
| if (page.getSize() > 0) { | |||||
| WxMallConfig config = page.getList().get(0); | |||||
| return new ResultData(config); | |||||
| } | |||||
| return new ResultData(); | |||||
| } | |||||
| @ApiOperation("获取B端刷卡支付发劵开关") | |||||
| @GetMapping("getMicroPayCouponSwitch") | |||||
| public ResultData getMicroPayConpon() { | |||||
| logger.debug("[" + getIpAddr() + "] WxMallConfigController::getMicroPayConpon"); | |||||
| WxMallConfig wxMallConfig = new WxMallConfig(); | |||||
| wxMallConfig.setKey("microPayCouponSwitch"); | |||||
| wxMallConfig.setTenantId(getTenantId()); | |||||
| PageInfo<WxMallConfig> page = wxMallConfigService.listAsPage(wxMallConfig, 1, 1); | |||||
| if (page.getSize() > 0) { | |||||
| WxMallConfig config = page.getList().get(0); | |||||
| return new ResultData(config); | |||||
| } | |||||
| return new ResultData(); | |||||
| } | |||||
| @PostMapping("updateStopCarCoupon") | |||||
| @ApiOperation("修改停车发券开关") | |||||
| public ResultData updateStopCarConpon(@RequestBody WxMallConfig wxMallConfig) { | |||||
| logger.debug("[" + getIpAddr() + "] WxMallConfigController::updateStopCarConpon"); | |||||
| WxMallConfig temp = new WxMallConfig(); | |||||
| // temp.setKey("stopCarCouponSwitch"); | |||||
| temp.setValue(wxMallConfig.getValue()); | |||||
| temp.setId(wxMallConfig.getId()); | |||||
| wxMallConfigService.saveOrUpdate(temp); | |||||
| return new ResultData(); | |||||
| } | |||||
| @PostMapping("updateVerifyCoupon") | |||||
| @ApiOperation("修改核销发券开关") | |||||
| public ResultData updateVerifyConpon(@RequestBody WxMallConfig wxMallConfig) { | |||||
| logger.debug("[" + getIpAddr() + "] WxMallConfigController::updateVerifyConpon"); | |||||
| WxMallConfig temp = new WxMallConfig(); | |||||
| // temp.setKey("verifyCouponSwitch"); | |||||
| temp.setValue(wxMallConfig.getValue()); | |||||
| temp.setId(wxMallConfig.getId()); | |||||
| wxMallConfigService.saveOrUpdate(temp); | |||||
| return new ResultData(); | |||||
| } | |||||
| @PostMapping("updateMicroPayCouponSwitch") | |||||
| @ApiOperation("修改刷卡支付发券开关") | |||||
| public ResultData updateMicroPayCoupon(@RequestBody WxMallConfig wxMallConfig) { | |||||
| logger.debug("[" + getIpAddr() + "] WxMallConfigController::updateMicroPayCoupon"); | |||||
| WxMallConfig temp = new WxMallConfig(); | |||||
| // temp.setKey("verifyCouponSwitch"); | |||||
| temp.setValue(wxMallConfig.getValue()); | |||||
| temp.setId(wxMallConfig.getId()); | |||||
| wxMallConfigService.saveOrUpdate(temp); | |||||
| return new ResultData(); | |||||
| } | |||||
| // @ApiOperation("分页列表接口") | |||||
| // @GetMapping("list") | |||||
| // @ApiImplicitParams({ | |||||
| // @ApiImplicitParam(name="pageNum",value="页数",dataType="int", paramType = "query",required=true), | |||||
| // @ApiImplicitParam(name="pageSize",value="每页条数",dataType="int", paramType = "query",required=true)}) | |||||
| // public ResultData list(@ModelAttribute WxMallConfig wxMallConfig,Integer pageNum, Integer pageSize) { | |||||
| // if (null == wxMallConfig) wxMallConfig = new WxMallConfig(); | |||||
| // final PageInfo<WxMallConfig> page = wxMallConfigService.listAsPage(wxMallConfig, pageNum, pageSize); | |||||
| // return new ResultData(page); | |||||
| // } | |||||
| // | |||||
| // @ApiOperation("新增接口") | |||||
| // @PostMapping("add") | |||||
| // public ResultData add(@RequestBody WxMallConfig wxMallConfig) { | |||||
| // //Assert.notNull(wxMallConfig.getName(), "角色名不能为空"); | |||||
| // //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||||
| // wxMallConfigService.saveOrUpdate(wxMallConfig); | |||||
| // return new ResultData(); | |||||
| // } | |||||
| // | |||||
| // @ApiOperation("根据id更新接口") | |||||
| // @PostMapping("update") | |||||
| // public ResultData update(@RequestBody WxMallConfig wxMallConfig) { | |||||
| // wxMallConfigService.saveOrUpdate(wxMallConfig); | |||||
| // return new ResultData(); | |||||
| // } | |||||
| // | |||||
| // @ApiOperation("根据id删除接口") | |||||
| // @GetMapping("/del") | |||||
| // @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||||
| // public ResultData delete(Long id) { | |||||
| // wxMallConfigService.deleteById(id); | |||||
| // return new ResultData(Result.SUCCESS, "删除成功", null); | |||||
| // } | |||||
| // | |||||
| // @ApiOperation("根据id查询接口") | |||||
| // @GetMapping("/findById") | |||||
| // @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||||
| // public ResultData findById(Long id) { | |||||
| // return new ResultData(Result.SUCCESS,"查询成功",wxMallConfigService.getById(id)); | |||||
| // } | |||||
| } | |||||
| @@ -123,5 +123,21 @@ public class WxMerchantController extends BaseController { | |||||
| return wxMerchantService.updateMerchantAdmin(wxMerchant); | return wxMerchantService.updateMerchantAdmin(wxMerchant); | ||||
| } | } | ||||
| @ApiOperation("更新法人接口") | |||||
| @PostMapping("updateMerchantCorp") | |||||
| public ResultData updateMerchantCopr(@RequestBody WxMerchant wxMerchant) { | |||||
| logger.debug("[" + getIpAddr() + "] WxMerchantController::updateMerchantCorp"); | |||||
| wxMerchant.setTenantId(getTenantId()); | |||||
| return wxMerchantService.updateMerchantCorp(wxMerchant); | |||||
| } | |||||
| @ApiOperation("更新税务接口") | |||||
| @PostMapping("updateMerchantTax") | |||||
| public ResultData updateMerchantTax(@RequestBody WxMerchant wxMerchant) { | |||||
| logger.debug("[" + getIpAddr() + "] WxMerchantController::updateMerchantTax"); | |||||
| wxMerchant.setTenantId(getTenantId()); | |||||
| return wxMerchantService.updateMerchantTax(wxMerchant); | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,64 @@ | |||||
| package com.iformall.controller; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.dto.WxOrderReportDto; | |||||
| import com.iformall.domain.vo.WxMerchantMicroPayVo; | |||||
| import com.iformall.domain.vo.WxMerchantTradeDailyVo; | |||||
| import com.iformall.enums.EnumOrderType; | |||||
| import com.iformall.service.MarkingDataReportService; | |||||
| import com.iformall.service.WxMerchantTradeDailyService; | |||||
| import com.iformall.service.WxOrderService; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import java.text.SimpleDateFormat; | |||||
| import java.util.Calendar; | |||||
| import java.util.Date; | |||||
| @RestController | |||||
| @RequestMapping("wxMerchantMicroPay") | |||||
| public class WxMerchantMicroPayController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private MarkingDataReportService markingDataReportService; | |||||
| @ApiOperation("获得商场近30日刷卡") | |||||
| @GetMapping("/listMonth") | |||||
| public ResultData listMonth() { | |||||
| logger.debug("[" + getIpAddr() + "] WxMerchantMicroPayController::listMonth"); | |||||
| WxOrderReportDto wxOrderReportDto = new WxOrderReportDto(); | |||||
| wxOrderReportDto.setTenantId(getTenantId()); | |||||
| wxOrderReportDto.setType(EnumOrderType.MICROPAY.getCode()); | |||||
| return new ResultData(markingDataReportService.listOrderReportByDate(wxOrderReportDto)); | |||||
| } | |||||
| @ApiOperation("获商户得近30日刷卡") | |||||
| @GetMapping("/detail") | |||||
| public ResultData detail(@RequestParam Long merchantId) { | |||||
| logger.debug("[" + getIpAddr() + "] WxMerchantMicroPayController::detail"); | |||||
| WxOrderReportDto wxOrderReportDto = new WxOrderReportDto(); | |||||
| wxOrderReportDto.setTenantId(getTenantId()); | |||||
| wxOrderReportDto.setMerchantId(merchantId); | |||||
| return new ResultData(markingDataReportService.listMicroPayOrderReportByDateAndMerchant(wxOrderReportDto)); | |||||
| } | |||||
| @ApiOperation("获得昨日刷卡列表") | |||||
| @GetMapping("/listYesterday") | |||||
| public ResultData listYesterday(@ModelAttribute WxOrderReportDto wxOrderReportDto, Integer pageNum, Integer pageSize) { | |||||
| logger.debug("[" + getIpAddr() + "] WxMerchantTradeDailyController::listYesterday"); | |||||
| if (wxOrderReportDto == null) | |||||
| wxOrderReportDto = new WxOrderReportDto(); | |||||
| wxOrderReportDto.setTenantId(getTenantId()); | |||||
| final PageInfo<WxMerchantMicroPayVo> page = markingDataReportService.listMerchantMicroPayOrderReportByDate(wxOrderReportDto, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,136 @@ | |||||
| package com.iformall.controller; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.MallUserInfo; | |||||
| import com.iformall.domain.po.WxMerchantSubsidy; | |||||
| import com.iformall.domain.vo.WxMerchantSubsidyVo; | |||||
| import com.iformall.enums.EnumMerchantSubsidyStatus; | |||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.service.WxMerchantSubsidyService; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.util.ArrayList; | |||||
| import java.util.Date; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| @RestController | |||||
| @Api(description = "商户补贴接口") | |||||
| @RequestMapping("subsidy") | |||||
| public class WxMerchantSubsidyController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| WxMerchantSubsidyService wxMerchantSubsidyService; | |||||
| @ApiOperation("补贴记录汇总") | |||||
| @GetMapping("sum") | |||||
| public ResultData count(@ModelAttribute WxMerchantSubsidy wxMerchantSubsidy) { | |||||
| String ipStr = getIpAddr(); | |||||
| logger.info("subsidy/sum: " + ipStr + " :" + wxMerchantSubsidy.toString()); | |||||
| if (wxMerchantSubsidy == null) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "过滤条件为空"); | |||||
| } | |||||
| MallUserInfo user = getUser(); | |||||
| wxMerchantSubsidy.setTenantId(user.getTenantId()); | |||||
| if(StringUtils.isNotBlank(wxMerchantSubsidy.getStatusStr())) { | |||||
| String [] statusAttr = wxMerchantSubsidy.getStatusStr().split(","); | |||||
| List<Integer> tmpList = new ArrayList<Integer>(); | |||||
| for(String status: statusAttr) { | |||||
| tmpList.add(Integer.valueOf(status)); | |||||
| } | |||||
| if(!tmpList.isEmpty()) { | |||||
| wxMerchantSubsidy.setStatusS(tmpList); | |||||
| } | |||||
| } | |||||
| Map retMap = wxMerchantSubsidyService.sumForSubsidy(wxMerchantSubsidy); | |||||
| return new ResultData(retMap); | |||||
| } | |||||
| @ApiOperation("补贴记录") | |||||
| @GetMapping("list") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| public ResultData listMonth(@ModelAttribute WxMerchantSubsidy wxMerchantSubsidy, Integer pageNum, Integer pageSize) { | |||||
| String ipStr = getIpAddr(); | |||||
| logger.info("subsidy/list: " + ipStr + " :" + wxMerchantSubsidy.toString()); | |||||
| if (wxMerchantSubsidy == null) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "过滤条件为空"); | |||||
| } | |||||
| MallUserInfo user = getUser(); | |||||
| wxMerchantSubsidy.setTenantId(user.getTenantId()); | |||||
| if(StringUtils.isNotBlank(wxMerchantSubsidy.getStatusStr())) { | |||||
| String [] statusAttr = wxMerchantSubsidy.getStatusStr().split(","); | |||||
| List<Integer> tmpList = new ArrayList<Integer>(); | |||||
| for(String status: statusAttr) { | |||||
| tmpList.add(Integer.valueOf(status)); | |||||
| } | |||||
| if(!tmpList.isEmpty()) { | |||||
| wxMerchantSubsidy.setStatusS(tmpList); | |||||
| } | |||||
| } | |||||
| wxMerchantSubsidy.setSortColumns(WxMerchantSubsidy.Field.CreateDate_DESC); | |||||
| final PageInfo<WxMerchantSubsidyVo> page = wxMerchantSubsidyService.listAsPage(wxMerchantSubsidy, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| @ApiOperation("更新补贴记录") | |||||
| @PostMapping("updateSubsidied") | |||||
| public ResultData updateSubsidied(@RequestBody WxMerchantSubsidy wxMerchantSubsidy) { | |||||
| String ipStr = getIpAddr(); | |||||
| logger.info("subsidy/update: " + ipStr + " :" + wxMerchantSubsidy.toString()); | |||||
| if (wxMerchantSubsidy == null) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "过滤条件为空"); | |||||
| } | |||||
| MallUserInfo user = getUser(); | |||||
| wxMerchantSubsidy.setTenantId(user.getTenantId()); | |||||
| wxMerchantSubsidy.setStatus(EnumMerchantSubsidyStatus.MANUAL_SUBSIDIED.getCode()); | |||||
| wxMerchantSubsidy.setUpdateDate(new Date()); | |||||
| if(StringUtils.isNotBlank(wxMerchantSubsidy.getIdStr())) { | |||||
| String [] idArr = wxMerchantSubsidy.getIdStr().split(","); | |||||
| List<Long> tmpList = new ArrayList<Long>(); | |||||
| for(String id: idArr) { | |||||
| tmpList.add(Long.valueOf(id)); | |||||
| } | |||||
| if(!tmpList.isEmpty()) { | |||||
| wxMerchantSubsidy.setIds(tmpList); | |||||
| } | |||||
| } | |||||
| return wxMerchantSubsidyService.update(wxMerchantSubsidy); | |||||
| } | |||||
| @ApiOperation("补贴记录导出") | |||||
| @GetMapping("/exportData") | |||||
| public void exportData(@ModelAttribute WxMerchantSubsidy wxMerchantSubsidy, HttpServletRequest request, HttpServletResponse response) { | |||||
| logger.info("[" + getIpAddr() + "] subsidy/exportData"); | |||||
| if (wxMerchantSubsidy == null) { | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "过滤条件不能为空"); | |||||
| } | |||||
| wxMerchantSubsidy.setTenantId(getTenantId()); | |||||
| if(StringUtils.isNotBlank(wxMerchantSubsidy.getStatusStr())) { | |||||
| String [] statusAttr = wxMerchantSubsidy.getStatusStr().split(","); | |||||
| List<Integer> tmpList = new ArrayList<Integer>(); | |||||
| for(String status: statusAttr) { | |||||
| tmpList.add(Integer.valueOf(status)); | |||||
| } | |||||
| if(!tmpList.isEmpty()) { | |||||
| wxMerchantSubsidy.setStatusS(tmpList); | |||||
| } | |||||
| } | |||||
| wxMerchantSubsidyService.exportData(wxMerchantSubsidy, request, response); | |||||
| } | |||||
| } | |||||
| @@ -46,14 +46,14 @@ public class WxMerchantTradeDailyController extends BaseController { | |||||
| return new ResultData(page); | return new ResultData(page); | ||||
| } | } | ||||
| @ApiOperation("获得近30日解单") | |||||
| @ApiOperation("获商户得近30日解单") | |||||
| @GetMapping("/detail") | @GetMapping("/detail") | ||||
| public ResultData detail(Long merchantId) { | public ResultData detail(Long merchantId) { | ||||
| logger.debug("[" + getIpAddr() + "] WxMerchantTradeDailyController::detail"); | logger.debug("[" + getIpAddr() + "] WxMerchantTradeDailyController::detail"); | ||||
| return wxMerchantTradeDailyService.getVolumeOfMonth(merchantId); | return wxMerchantTradeDailyService.getVolumeOfMonth(merchantId); | ||||
| } | } | ||||
| @ApiOperation("获得昨日解单列表") | |||||
| @ApiOperation("获得商场近30日解单") | |||||
| @GetMapping("/listMonth") | @GetMapping("/listMonth") | ||||
| public ResultData listMonth() { | public ResultData listMonth() { | ||||
| logger.debug("[" + getIpAddr() + "] WxMerchantTradeDailyController::listMonth"); | logger.debug("[" + getIpAddr() + "] WxMerchantTradeDailyController::listMonth"); | ||||
| @@ -1,5 +1,6 @@ | |||||
| package com.iformall.controller; | package com.iformall.controller; | ||||
| import com.iformall.domain.vo.WxOrderQueryVo; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -15,6 +16,8 @@ import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import java.util.Map; | |||||
| @RestController | @RestController | ||||
| @RequestMapping("wxOrder") | @RequestMapping("wxOrder") | ||||
| public class WxOrderController extends BaseController { | public class WxOrderController extends BaseController { | ||||
| @@ -73,7 +76,34 @@ public class WxOrderController extends BaseController { | |||||
| logger.debug("[" + getIpAddr() + "] WxOrderController::findById"); | logger.debug("[" + getIpAddr() + "] WxOrderController::findById"); | ||||
| return new ResultData(Result.SUCCESS,"查询成功",wxOrderService.getById(id)); | return new ResultData(Result.SUCCESS,"查询成功",wxOrderService.getById(id)); | ||||
| } | } | ||||
| @ApiOperation("交易列表") | |||||
| @GetMapping("listOrder") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true) | |||||
| }) | |||||
| public ResultData listOrder(@ModelAttribute WxOrderQueryVo wxOrderQueryVo, Integer pageNum, Integer pageSize) { | |||||
| logger.debug("[" + getIpAddr() + "] WxOrderController::listOrder"); | |||||
| if (null == wxOrderQueryVo){ | |||||
| wxOrderQueryVo = new WxOrderQueryVo(); | |||||
| } | |||||
| wxOrderQueryVo.setTenantId(getTenantId()); | |||||
| final PageInfo<WxOrder> page = wxOrderService.listOrderAsPage(wxOrderQueryVo, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| @ApiOperation("交易统计") | |||||
| @PostMapping("/queryOrderSummary") | |||||
| public ResultData queryOrderSummary() { | |||||
| logger.debug("[" + getIpAddr() + "] WxOrderController::queryOrderSummary"); | |||||
| Map<String, Object> data = wxOrderService.queryOrderSummary(getTenantId()); | |||||
| return new ResultData(data); | |||||
| } | |||||
| } | } | ||||
| @@ -5,8 +5,8 @@ import com.iformall.exception.BizMessageException; | |||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.pay.WxPayment; | import com.iformall.pay.WxPayment; | ||||
| import com.iformall.service.WxPayOrderService; | import com.iformall.service.WxPayOrderService; | ||||
| import com.iformall.service.WxProfitSharingOrderService; | |||||
| import com.iformall.service.WxRefundOrderService; | import com.iformall.service.WxRefundOrderService; | ||||
| import com.iformall.service.WxSubsidyService; | |||||
| import com.iformall.utils.XmlUtil; | import com.iformall.utils.XmlUtil; | ||||
| import org.apache.commons.io.IOUtils; | import org.apache.commons.io.IOUtils; | ||||
| import org.jdom2.JDOMException; | import org.jdom2.JDOMException; | ||||
| @@ -36,6 +36,9 @@ public class WxPayController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private WxRefundOrderService wxRefundOrderService; | private WxRefundOrderService wxRefundOrderService; | ||||
| @Autowired | |||||
| private WxSubsidyService wxSubsidyService; | |||||
| /** | /** | ||||
| * | * | ||||
| * @return 接收微信异步通知 | * @return 接收微信异步通知 | ||||
| @@ -177,5 +180,68 @@ public class WxPayController extends BaseController { | |||||
| return XmlUtil.getRequestXml(resultMap); | return XmlUtil.getRequestXml(resultMap); | ||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * | |||||
| * @return 接收微信异步通知 | |||||
| * @throws Exception 可能产生的任何异常 | |||||
| */ | |||||
| @RequestMapping(value = "/subsidyPay", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) | |||||
| @ResponseBody | |||||
| public String _subsidyPayNotify(HttpServletRequest request) throws IOException, JDOMException { | |||||
| logger.info("[" +getIpAddr() + "] 补贴微信支付回调"); | |||||
| InputStream inStream = request.getInputStream(); | |||||
| ByteArrayOutputStream outSteam = new ByteArrayOutputStream(); | |||||
| byte[] buffer = new byte[1024]; | |||||
| int len = 0; | |||||
| while ((len = inStream.read(buffer)) != -1) { | |||||
| outSteam.write(buffer, 0, len); | |||||
| } | |||||
| String resultxml = new String(outSteam.toByteArray(), Charset.forName("UTF-8")); | |||||
| logger.info(resultxml); | |||||
| outSteam.close(); | |||||
| inStream.close(); | |||||
| Map<String, String> paramMap = null; | |||||
| try { | |||||
| paramMap = WxPayment.xmlToMap(resultxml); | |||||
| logger.info("微信支付回调, notify, param: " + paramMap.toString() ); | |||||
| String response = wxSubsidyService.notify(paramMap, EnumPayWay.PAY_WAY_WEAPP); | |||||
| logger.info("微信支付回调, notify success, req : " + resultxml + ", resp: " + response.toString()); | |||||
| return response; | |||||
| } catch (BizMessageException e) { | |||||
| if (paramMap == null) { | |||||
| logger.error("微信支付回调, order create error, e: " + e.getMessage()); | |||||
| } else { | |||||
| logger.error("微信支付回调, order create error, req: " + resultxml + ", e: " + e.getMessage()); | |||||
| } | |||||
| SortedMap resultMap = new TreeMap<>(); | |||||
| resultMap.put("return_code", "FAIL"); | |||||
| resultMap.put("return_msg", e.getMessage()); | |||||
| return XmlUtil.getRequestXml(resultMap); | |||||
| } catch (MallinkException e) { | |||||
| if (paramMap == null) { | |||||
| logger.error("微信支付回调, order create error, e: " + e.getMessage()); | |||||
| } else { | |||||
| logger.error("微信支付回调, order create error, req: " + resultxml + ", e: " + e.getMessage()); | |||||
| } | |||||
| SortedMap resultMap = new TreeMap<>(); | |||||
| resultMap.put("return_code", "FAIL"); | |||||
| resultMap.put("return_msg", e.getMessage()); | |||||
| return XmlUtil.getRequestXml(resultMap); | |||||
| } catch (Exception e) { | |||||
| if (paramMap == null) { | |||||
| logger.error("微信支付回调, order create error, e: " + e.getMessage()); | |||||
| } else { | |||||
| logger.error("微信支付回调, order create error, req: " + resultxml + ", e: " + e.getMessage()); | |||||
| } | |||||
| SortedMap resultMap = new TreeMap(); | |||||
| resultMap.put("return_code", "FAIL"); | |||||
| resultMap.put("return_msg", e.getMessage()); | |||||
| return XmlUtil.getRequestXml(resultMap); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,64 @@ | |||||
| package com.iformall.controller; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.vo.WxProfitSharingOrderQueryVo; | |||||
| import com.iformall.domain.vo.WxProfitSharingOrderVo; | |||||
| import com.iformall.service.WxProfitSharingOrderService; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import java.util.Map; | |||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| @RestController | |||||
| @RequestMapping("wxProfitSharingOrder") | |||||
| public class WxProfitSharingOrderController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private WxProfitSharingOrderService wxProfitSharingOrderService; | |||||
| @ApiOperation("分页列表接口") | |||||
| @GetMapping("list") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| public ResultData list(@ModelAttribute WxProfitSharingOrderQueryVo order, Integer pageNum, Integer pageSize) { | |||||
| logger.debug("[" + getIpAddr() + "] WxProfitSharingOrderController::list"); | |||||
| if (null == order) { | |||||
| order = new WxProfitSharingOrderQueryVo(); | |||||
| } | |||||
| final PageInfo<WxProfitSharingOrderVo> page = wxProfitSharingOrderService.listAsPage(order, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| @ApiOperation("交易统计") | |||||
| @PostMapping("/queryOrderSummary") | |||||
| public ResultData queryOrderSummary() { | |||||
| logger.debug("[" + getIpAddr() + "] WxProfitSharingOrderController::queryOrderSummary"); | |||||
| Map<String, Object> data = wxProfitSharingOrderService.queryOrderSummary(getTenantId()); | |||||
| return new ResultData(data); | |||||
| } | |||||
| @ApiOperation("分账详情") | |||||
| @GetMapping("findOrderDetails") | |||||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||||
| public ResultData findOrderDetails(Long id) { | |||||
| logger.debug("[" + getIpAddr() + "] WxProfitSharingOrderController::findOrderDetails"); | |||||
| return wxProfitSharingOrderService.findOrderDetails(id); | |||||
| } | |||||
| } | |||||
| @@ -16,7 +16,7 @@ import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| @RestController | @RestController | ||||
| @RequestMapping("/api/refund") | |||||
| @RequestMapping("/refund") | |||||
| public class WxRefundOrderController extends BaseController { | public class WxRefundOrderController extends BaseController { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| @@ -44,16 +44,31 @@ public class WxRentContractController extends BaseController { | |||||
| public ResultData add(@RequestBody WxRentContract wxRentContract) { | public ResultData add(@RequestBody WxRentContract wxRentContract) { | ||||
| logger.debug("[" + getIpAddr() + "] WxRentContractController::add"); | logger.debug("[" + getIpAddr() + "] WxRentContractController::add"); | ||||
| wxRentContract.setTenantId(getTenantId()); | wxRentContract.setTenantId(getTenantId()); | ||||
| return wxRentContractService.saveOrUpdate(wxRentContract); | |||||
| return wxRentContractService.save(wxRentContract); | |||||
| } | } | ||||
| @PostMapping("update") | @PostMapping("update") | ||||
| public ResultData update(@RequestBody WxRentContract wxRentContract) { | public ResultData update(@RequestBody WxRentContract wxRentContract) { | ||||
| logger.debug("[" + getIpAddr() + "] WxRentContractController::update"); | logger.debug("[" + getIpAddr() + "] WxRentContractController::update"); | ||||
| wxRentContract.setTenantId(getTenantId()); | wxRentContract.setTenantId(getTenantId()); | ||||
| return wxRentContractService.saveOrUpdate(wxRentContract); | |||||
| return wxRentContractService.update(wxRentContract); | |||||
| } | } | ||||
| @PostMapping("updateMoney") | |||||
| public ResultData updateMoney(@RequestBody WxRentContract wxRentContract) { | |||||
| logger.debug("[" + getIpAddr() + "] WxRentContractController::updateMoney"); | |||||
| wxRentContract.setTenantId(getTenantId()); | |||||
| return wxRentContractService.update(wxRentContract); | |||||
| } | |||||
| @PostMapping("updateFile") | |||||
| public ResultData updateFile(@RequestBody WxRentContract wxRentContract) { | |||||
| logger.debug("[" + getIpAddr() + "] WxRentContractController::updateFile"); | |||||
| wxRentContract.setTenantId(getTenantId()); | |||||
| return wxRentContractService.updateFile(wxRentContract); | |||||
| } | |||||
| @GetMapping("/del") | @GetMapping("/del") | ||||
| @ApiImplicitParam(name = "id", value = "id", dataType = "String", paramType = "query", required = true) | @ApiImplicitParam(name = "id", value = "id", dataType = "String", paramType = "query", required = true) | ||||
| public ResultData delete(String id) { | public ResultData delete(String id) { | ||||
| @@ -104,5 +119,18 @@ public class WxRentContractController extends BaseController { | |||||
| return new ResultData(wxRentContractService.getRentContractList(getTenantId(),pageNum, pageSize)); | return new ResultData(wxRentContractService.getRentContractList(getTenantId(),pageNum, pageSize)); | ||||
| } | } | ||||
| @GetMapping("exportContract") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)}) | |||||
| public void exportContract(Long id,HttpServletRequest request, HttpServletResponse response){ | |||||
| wxRentContractService.exportContract(request,response,getTenantId(),id); | |||||
| } | |||||
| @GetMapping("updateRentContractStatus") | |||||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||||
| public ResultData updateRentContractStatus(Long id) { | |||||
| logger.debug("[" + getIpAddr() + "] WxRentContractController::updateRentContractStatus"); | |||||
| return wxRentContractService.updateRentContractStatus(id); | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,103 @@ | |||||
| package com.iformall.controller; | |||||
| import com.iformall.domain.po.MallUserInfo; | |||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.utils.PayUtil; | |||||
| import io.swagger.annotations.Api; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.Result; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.WxSubsidy; | |||||
| import com.iformall.service.WxSubsidyService; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import javax.imageio.ImageIO; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.awt.image.BufferedImage; | |||||
| import java.util.Map; | |||||
| @RestController | |||||
| @Api(description = "商城补贴支付接口") | |||||
| @RequestMapping("wxSubsidy") | |||||
| public class WxSubsidyController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private WxSubsidyService wxSubsidyService; | |||||
| @ApiOperation("补贴扫码支付发起") | |||||
| @GetMapping("prePay") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "amount", value = "金额", dataType = "String", paramType = "query", required = true)}) | |||||
| public void subsidyPrepay(String amount, HttpServletResponse response) throws Exception { | |||||
| String ipStr = getIpAddr(); | |||||
| logger.info("subsidyPrepay: " + ipStr + "-" + amount); | |||||
| MallUserInfo userInfo = getUser(); | |||||
| ResultData resultData = wxSubsidyService.createSubsidy(userInfo, ipStr, amount); | |||||
| if(resultData.code == 200) { | |||||
| String codeUrl = ((Map<String, String>)resultData.data).get("code_url"); | |||||
| BufferedImage image = PayUtil.getQRCodeImge(codeUrl); | |||||
| response.setContentType("image/jpeg"); | |||||
| response.setHeader("Pragma","no-cache"); | |||||
| response.setHeader("Cache-Control","no-cache"); | |||||
| response.setIntHeader("Expires",-1); | |||||
| ImageIO.write(image, "JPEG", response.getOutputStream()); | |||||
| } else { | |||||
| throw new MallinkException(resultData.code, resultData.message); | |||||
| } | |||||
| } | |||||
| @ApiOperation("分页列表接口") | |||||
| @GetMapping("list") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name="pageNum",value="页数",dataType="int", paramType = "query",required=true), | |||||
| @ApiImplicitParam(name="pageSize",value="每页条数",dataType="int", paramType = "query",required=true)}) | |||||
| public ResultData list(@ModelAttribute WxSubsidy wxSubsidy,Integer pageNum, Integer pageSize) { | |||||
| if (null == wxSubsidy) wxSubsidy = new WxSubsidy(); | |||||
| final PageInfo<WxSubsidy> page = wxSubsidyService.listAsPage(wxSubsidy, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| @ApiOperation("新增接口") | |||||
| @PostMapping("add") | |||||
| public ResultData add(@RequestBody WxSubsidy wxSubsidy) { | |||||
| //Assert.notNull(wxSubsidy.getName(), "角色名不能为空"); | |||||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||||
| wxSubsidyService.saveOrUpdate(wxSubsidy); | |||||
| return new ResultData(); | |||||
| } | |||||
| @ApiOperation("根据id更新接口") | |||||
| @PostMapping("update") | |||||
| public ResultData update(@RequestBody WxSubsidy wxSubsidy) { | |||||
| wxSubsidyService.saveOrUpdate(wxSubsidy); | |||||
| return new ResultData(); | |||||
| } | |||||
| @ApiOperation("根据id删除接口") | |||||
| @GetMapping("/del") | |||||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||||
| public ResultData delete(Long id) { | |||||
| wxSubsidyService.deleteById(id); | |||||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||||
| } | |||||
| @ApiOperation("根据id查询接口") | |||||
| @GetMapping("/findById") | |||||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||||
| public ResultData findById(Long id) { | |||||
| return new ResultData(Result.SUCCESS,"查询成功",wxSubsidyService.getById(id)); | |||||
| } | |||||
| } | |||||
| @@ -37,4 +37,7 @@ public class WxUserCouponController extends BaseController { | |||||
| return new ResultData(Result.SUCCESS,"查询成功",wxUserCouponService.findList(wxUserCoupon.getcUserId(),wxUserCoupon.getCouponStatus())); | return new ResultData(Result.SUCCESS,"查询成功",wxUserCouponService.findList(wxUserCoupon.getcUserId(),wxUserCoupon.getCouponStatus())); | ||||
| } | } | ||||
| } | } | ||||
| @@ -1,12 +1,14 @@ | |||||
| package com.iformall.controller; | package com.iformall.controller; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.dto.WxCUserBasicInfoDto; | import com.iformall.domain.dto.WxCUserBasicInfoDto; | ||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.domain.vo.UserStructureVo; | import com.iformall.domain.vo.UserStructureVo; | ||||
| import com.iformall.enums.EnumAgeInfo; | import com.iformall.enums.EnumAgeInfo; | ||||
| import com.iformall.enums.EnumCUserBaseInfoSex; | import com.iformall.enums.EnumCUserBaseInfoSex; | ||||
| import com.iformall.enums.EnumScoreType; | |||||
| import com.iformall.enums.EnumTag; | import com.iformall.enums.EnumTag; | ||||
| import com.iformall.service.*; | import com.iformall.service.*; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| @@ -17,10 +19,7 @@ import org.apache.commons.lang3.StringUtils; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.web.bind.annotation.GetMapping; | |||||
| import org.springframework.web.bind.annotation.ModelAttribute; | |||||
| import org.springframework.web.bind.annotation.RequestMapping; | |||||
| import org.springframework.web.bind.annotation.RestController; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import java.math.BigDecimal; | import java.math.BigDecimal; | ||||
| import java.text.NumberFormat; | import java.text.NumberFormat; | ||||
| @@ -51,6 +50,9 @@ public class WxUserStructureController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private WxUserChannelService wxUserChannelService; | private WxUserChannelService wxUserChannelService; | ||||
| @Autowired | |||||
| private WxScoreRulesService wxScoreRulesService; | |||||
| /***************************会员结构*****************************/ | /***************************会员结构*****************************/ | ||||
| @ApiOperation("查询会员性别结构") | @ApiOperation("查询会员性别结构") | ||||
| @@ -542,5 +544,61 @@ public class WxUserStructureController extends BaseController { | |||||
| return vo; | return vo; | ||||
| } | } | ||||
| // 成长值扣除 | |||||
| @ApiOperation(value = "用户成长值扣减", notes = "{\"userId\":\"Long\", \"reason\":\"String\", \"score\":\"Integer\"}") | |||||
| @PostMapping("/scoreReduce") | |||||
| public ResultData scoreReduce(@RequestBody Map<String, String> params) { | |||||
| logger.debug("[" + getIpAddr() + "] WxUserStructureController::scoreReduce"); | |||||
| String userIdStr = params.get("userId"); | |||||
| String reason = params.get("reason"); | |||||
| String scoreStr = params.get("score"); | |||||
| if (StringUtils.isBlank(userIdStr)) { | |||||
| logger.error("userId为空:" + userIdStr); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "userId为空"); | |||||
| } | |||||
| if (StringUtils.isBlank(reason)) { | |||||
| logger.error("reason为空:" + reason); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "reason为空"); | |||||
| } | |||||
| if (StringUtils.isBlank(scoreStr)) { | |||||
| logger.error("score为空:" + scoreStr); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "score为空"); | |||||
| } | |||||
| Long userId = null; | |||||
| Integer score = null; | |||||
| try { | |||||
| userId = Long.valueOf(userIdStr); | |||||
| score = Integer.valueOf(scoreStr); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| if(userId == null || userId == 0) { | |||||
| logger.error(ErrorCode.USER_IS_EMPTY.getMessage()); | |||||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
| } | |||||
| if(score == null ) { | |||||
| logger.error(ErrorCode.SYS_PARAMETER_NOT_NULL.getMessage()); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "score不能为空"); | |||||
| } | |||||
| // 1. 检查用户积分 | |||||
| WxCUserBasicInfo info = wxCUserBasicInfoService.getById(userId); | |||||
| if(info == null) { | |||||
| logger.error(ErrorCode.USER_IS_EMPTY.getMessage()); | |||||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
| } | |||||
| if(info.getPoins() < score) { | |||||
| logger.error(ErrorCode.MEM_SCORE_NOT_ENOUGH.getMessage()); | |||||
| return new ResultData(ErrorCode.MEM_SCORE_NOT_ENOUGH); | |||||
| } | |||||
| // 2. 扣减积分 | |||||
| wxScoreRulesService.reduceScore(EnumScoreType.MEM_REDUCE, info, reason, score); | |||||
| return new ResultData(); | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,77 @@ | |||||
| package com.iformall.interceptor; | |||||
| import javax.servlet.ReadListener; | |||||
| import javax.servlet.ServletInputStream; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletRequestWrapper; | |||||
| import java.io.*; | |||||
| public class BodyReaderHttpServletRequestWrapper extends HttpServletRequestWrapper { | |||||
| private final String body; | |||||
| public BodyReaderHttpServletRequestWrapper(HttpServletRequest request) throws IOException { | |||||
| super(request); | |||||
| StringBuffer stringBuilder = new StringBuffer(); | |||||
| BufferedReader bufferedReader = null; | |||||
| try { | |||||
| InputStream inputStream = request.getInputStream(); | |||||
| if (inputStream != null) { | |||||
| bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"utf-8")); | |||||
| char[] charBuffer = new char[1024]; | |||||
| int bytesRead = -1; | |||||
| while ((bytesRead = bufferedReader.read(charBuffer)) > 0) { | |||||
| stringBuilder.append(charBuffer, 0, bytesRead); | |||||
| } | |||||
| } else { | |||||
| stringBuilder.append(""); | |||||
| } | |||||
| } catch (IOException ex) { | |||||
| throw ex; | |||||
| } finally { | |||||
| if (bufferedReader != null) { | |||||
| try { | |||||
| bufferedReader.close(); | |||||
| } catch (IOException ex) { | |||||
| throw ex; | |||||
| } | |||||
| } | |||||
| } | |||||
| body = stringBuilder.toString(); | |||||
| } | |||||
| @Override | |||||
| public ServletInputStream getInputStream() throws IOException { | |||||
| final ByteArrayInputStream byteArrayInputStream = | |||||
| new ByteArrayInputStream(body.getBytes("utf-8")); | |||||
| return new ServletInputStream() { | |||||
| @Override | |||||
| public boolean isFinished() { | |||||
| return false; | |||||
| } | |||||
| @Override | |||||
| public boolean isReady() { | |||||
| return false; | |||||
| } | |||||
| @Override | |||||
| public void setReadListener(ReadListener readListener) { | |||||
| } | |||||
| @Override | |||||
| public int read() throws IOException { | |||||
| return byteArrayInputStream.read(); | |||||
| } | |||||
| }; | |||||
| } | |||||
| @Override | |||||
| public BufferedReader getReader() throws IOException { | |||||
| return new BufferedReader(new InputStreamReader(this.getInputStream())); | |||||
| } | |||||
| public String getBody() { | |||||
| return this.body; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,39 @@ | |||||
| package com.iformall.interceptor; | |||||
| import javax.servlet.*; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import java.io.IOException; | |||||
| public class HttpServletRequestWrapperFilter implements Filter { | |||||
| @Override | |||||
| public void init(FilterConfig filterConfig) throws ServletException { | |||||
| } | |||||
| @Override | |||||
| public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | |||||
| throws IOException, ServletException { | |||||
| ServletRequest requestWrapper = null; | |||||
| if (request instanceof HttpServletRequest) { | |||||
| String url = ((HttpServletRequest) request).getRequestURI(); | |||||
| if (!url.contains("awsFileUpload") && !url.contains("ueditor/exec") | |||||
| && !url.contains("/wxCUserBasicInfo/importTemplate")) { | |||||
| requestWrapper = new BodyReaderHttpServletRequestWrapper((HttpServletRequest) request); | |||||
| } else { | |||||
| requestWrapper = null; | |||||
| } | |||||
| } | |||||
| if (null == requestWrapper) { | |||||
| chain.doFilter(request, response); | |||||
| } else { | |||||
| chain.doFilter(requestWrapper, response); | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public void destroy() { | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,100 @@ | |||||
| package com.iformall.interceptor; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.utils.HashUtil; | |||||
| import com.iformall.utils.IPUtil; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.data.redis.core.RedisTemplate; | |||||
| import org.springframework.stereotype.Component; | |||||
| import org.springframework.web.servlet.ModelAndView; | |||||
| import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; | |||||
| import javax.annotation.Resource; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.io.ByteArrayOutputStream; | |||||
| import java.io.InputStream; | |||||
| import java.nio.charset.Charset; | |||||
| import java.util.Enumeration; | |||||
| import java.util.concurrent.TimeUnit; | |||||
| /** | |||||
| * 幂等检查 | |||||
| * @author stormeye.wu | |||||
| * @email wuguoqiang@iformall.com | |||||
| * @date 2017-03-23 15:38 | |||||
| */ | |||||
| @Component | |||||
| public class RequestInterceptor extends HandlerInterceptorAdapter { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Resource | |||||
| private RedisTemplate<String, String> redisTemplate; | |||||
| @Override | |||||
| public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | |||||
| if ("GET".equalsIgnoreCase(request.getMethod())) { | |||||
| // 获取不检查幂等 | |||||
| return true; | |||||
| } | |||||
| String ipaddress = IPUtil.getIpAddr(request); | |||||
| String url = request.getRequestURL().toString(); | |||||
| if(url.contains("pvlog") | |||||
| || url.contains("awsFileUpload") | |||||
| || url.contains("ueditor/exec")) { | |||||
| // pvlog不检查幂等 | |||||
| // awsFileUpload不检查幂等 | |||||
| // ueditor 不检查幂等 | |||||
| return true; | |||||
| } | |||||
| StringBuilder sb = new StringBuilder(); | |||||
| sb.append(url); | |||||
| sb.append("method=").append(request.getMethod()).append("&"); | |||||
| sb.append("ip=").append(ipaddress).append("&"); | |||||
| final Enumeration parameterNames = request.getParameterNames(); | |||||
| while (parameterNames.hasMoreElements()) { | |||||
| String key = (String) parameterNames.nextElement(); | |||||
| if(key.equalsIgnoreCase("ran")) // 跳过ran | |||||
| continue; | |||||
| String parameter = request.getParameter(key); | |||||
| sb.append(key).append("=").append(parameter).append("&"); | |||||
| } | |||||
| InputStream inStream = request.getInputStream(); | |||||
| ByteArrayOutputStream outSteam = new ByteArrayOutputStream(); | |||||
| byte[] buffer = new byte[1024]; | |||||
| int len = 0; | |||||
| while ((len = inStream.read(buffer)) != -1) { | |||||
| outSteam.write(buffer, 0, len); | |||||
| } | |||||
| String resultBody = new String(outSteam.toByteArray(), Charset.forName("UTF-8")); | |||||
| inStream.close(); | |||||
| outSteam.close(); | |||||
| sb.append(resultBody); | |||||
| String key = "request: " + HashUtil.md5(sb.toString()); | |||||
| if (redisTemplate.opsForValue().setIfAbsent(key, key)) { | |||||
| redisTemplate.expire(key, 3, TimeUnit.SECONDS); | |||||
| logger.info(key + ": 第一次提交"); | |||||
| return true; | |||||
| } | |||||
| logger.info(key + ": 第二次提交"); | |||||
| throw new MallinkException(ErrorCode.SYS_REPEAT_SUBMIT_EXCEPTION); | |||||
| } | |||||
| @Override | |||||
| public void postHandle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { | |||||
| } | |||||
| @Override | |||||
| public void afterCompletion(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object handler, Exception ex) throws Exception { | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,225 @@ | |||||
| package com.iformall.service.wechat; | |||||
| import com.iformall.common.IdWorker; | |||||
| import com.iformall.domain.po.WxComponentVerifyTicket; | |||||
| import com.iformall.mapper.WxComponentVerifyTicketMapper; | |||||
| import me.chanjar.weixin.open.api.impl.WxOpenInMemoryConfigStorage; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import redis.clients.jedis.Jedis; | |||||
| import redis.clients.jedis.JedisPool; | |||||
| import redis.clients.util.Pool; | |||||
| public class WxOpenInRedisDBConfigStorage extends WxOpenInMemoryConfigStorage { | |||||
| private final static String COMPONENT_VERIFY_TICKET_KEY = "wechat_component_verify_ticket:"; | |||||
| private final static String COMPONENT_ACCESS_TOKEN_KEY = "wechat_component_access_token:"; | |||||
| private final static String AUTHORIZER_REFRESH_TOKEN_KEY = "wechat_authorizer_refresh_token:"; | |||||
| private final static String AUTHORIZER_ACCESS_TOKEN_KEY = "wechat_authorizer_access_token:"; | |||||
| private final static String JSAPI_TICKET_KEY = "wechat_jsapi_ticket:"; | |||||
| private final static String CARD_API_TICKET_KEY = "wechat_card_api_ticket:"; | |||||
| protected final Pool<Jedis> jedisPool; | |||||
| /** | |||||
| * redis 存储的 key 的前缀,可为空 | |||||
| */ | |||||
| private String keyPrefix; | |||||
| private String componentVerifyTicketKey; | |||||
| private String componentAccessTokenKey; | |||||
| private String authorizerRefreshTokenKey; | |||||
| private String authorizerAccessTokenKey; | |||||
| private String jsapiTicketKey; | |||||
| private String cardApiTicket; | |||||
| @Autowired | |||||
| WxComponentVerifyTicketMapper wxComponentVerifyTicketMapper; | |||||
| public WxOpenInRedisDBConfigStorage(Pool<Jedis> jedisPool) { | |||||
| this.jedisPool = jedisPool; | |||||
| } | |||||
| public WxOpenInRedisDBConfigStorage(Pool<Jedis> jedisPool, String keyPrefix) { | |||||
| this.jedisPool = jedisPool; | |||||
| this.keyPrefix = keyPrefix; | |||||
| } | |||||
| public WxOpenInRedisDBConfigStorage(JedisPool jedisPool) { | |||||
| this.jedisPool = jedisPool; | |||||
| } | |||||
| @Override | |||||
| public void setComponentAppId(String componentAppId) { | |||||
| super.setComponentAppId(componentAppId); | |||||
| String prefix = StringUtils.isBlank(keyPrefix) ? "" : | |||||
| (StringUtils.endsWith(keyPrefix, ":") ? keyPrefix : (keyPrefix + ":")); | |||||
| componentVerifyTicketKey = prefix + COMPONENT_VERIFY_TICKET_KEY.concat(componentAppId); | |||||
| componentAccessTokenKey = prefix + COMPONENT_ACCESS_TOKEN_KEY.concat(componentAppId); | |||||
| authorizerRefreshTokenKey = prefix + AUTHORIZER_REFRESH_TOKEN_KEY.concat(componentAppId); | |||||
| authorizerAccessTokenKey = prefix + AUTHORIZER_ACCESS_TOKEN_KEY.concat(componentAppId); | |||||
| this.jsapiTicketKey = JSAPI_TICKET_KEY.concat(componentAppId); | |||||
| this.cardApiTicket = CARD_API_TICKET_KEY.concat(componentAppId); | |||||
| } | |||||
| @Override | |||||
| public String getComponentVerifyTicket() { | |||||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||||
| return jedis.get(this.componentVerifyTicketKey); | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public void setComponentVerifyTicket(String componentVerifyTicket) { | |||||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||||
| jedis.set(this.componentVerifyTicketKey, componentVerifyTicket); | |||||
| } | |||||
| // TODO update to DB | |||||
| } | |||||
| @Override | |||||
| public String getComponentAccessToken() { | |||||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||||
| return jedis.get(this.componentAccessTokenKey); | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public boolean isComponentAccessTokenExpired() { | |||||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||||
| return jedis.ttl(this.componentAccessTokenKey) < 2; | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public void expireComponentAccessToken(){ | |||||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||||
| jedis.expire(this.componentAccessTokenKey, 0); | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public void updateComponentAccessTokent(String componentAccessToken, int expiresInSeconds) { | |||||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||||
| jedis.setex(this.componentAccessTokenKey, expiresInSeconds - 200, componentAccessToken); | |||||
| } | |||||
| // TODO update to DB | |||||
| } | |||||
| private String getKey(String prefix, String appId) { | |||||
| return prefix.endsWith(":") ? prefix.concat(appId) : prefix.concat(":").concat(appId); | |||||
| } | |||||
| @Override | |||||
| public String getAuthorizerRefreshToken(String appId) { | |||||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||||
| return jedis.get(this.getKey(this.authorizerRefreshTokenKey, appId)); | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public void setAuthorizerRefreshToken(String appId, String authorizerRefreshToken) { | |||||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||||
| jedis.set(this.getKey(this.authorizerRefreshTokenKey, appId), authorizerRefreshToken); | |||||
| } | |||||
| // TODO update to DB | |||||
| } | |||||
| @Override | |||||
| public String getAuthorizerAccessToken(String appId) { | |||||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||||
| return jedis.get(this.getKey(this.authorizerAccessTokenKey, appId)); | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public boolean isAuthorizerAccessTokenExpired(String appId) { | |||||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||||
| return jedis.ttl(this.getKey(this.authorizerAccessTokenKey, appId)) < 2; | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public void expireAuthorizerAccessToken(String appId) { | |||||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||||
| jedis.expire(this.getKey(this.authorizerAccessTokenKey, appId), 0); | |||||
| } | |||||
| // TODO update to DB | |||||
| } | |||||
| @Override | |||||
| public void updateAuthorizerAccessToken(String appId, String authorizerAccessToken, int expiresInSeconds) { | |||||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||||
| jedis.setex(this.getKey(this.authorizerAccessTokenKey, appId), expiresInSeconds - 200, authorizerAccessToken); | |||||
| } | |||||
| // TODO update to DB | |||||
| } | |||||
| /* | |||||
| @Override | |||||
| public void changeAuthorizationStatus(String appId) { | |||||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||||
| jedis.expire(this.getKey(this.authorizerAccessTokenKey, appId), 0); | |||||
| } | |||||
| // TODO update to DB | |||||
| } | |||||
| */ | |||||
| @Override | |||||
| public String getJsapiTicket(String appId) { | |||||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||||
| return jedis.get(this.getKey(this.jsapiTicketKey, appId)); | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public boolean isJsapiTicketExpired(String appId) { | |||||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||||
| return jedis.ttl(this.getKey(this.jsapiTicketKey, appId)) < 2; | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public void expireJsapiTicket(String appId) { | |||||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||||
| jedis.expire(this.getKey(this.jsapiTicketKey, appId), 0); | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public void updateJsapiTicket(String appId, String jsapiTicket, int expiresInSeconds) { | |||||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||||
| jedis.setex(this.getKey(this.jsapiTicketKey, appId), expiresInSeconds - 200, jsapiTicket); | |||||
| } | |||||
| // TODO update to DB | |||||
| } | |||||
| @Override | |||||
| public String getCardApiTicket(String appId) { | |||||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||||
| return jedis.get(this.getKey(this.cardApiTicket, appId)); | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public boolean isCardApiTicketExpired(String appId) { | |||||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||||
| return jedis.ttl(this.getKey(this.cardApiTicket, appId)) < 2; | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public void expireCardApiTicket(String appId) { | |||||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||||
| jedis.expire(this.getKey(this.cardApiTicket, appId), 0); | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public void updateCardApiTicket(String appId, String cardApiTicket, int expiresInSeconds) { | |||||
| try (Jedis jedis = this.jedisPool.getResource()) { | |||||
| jedis.setex(this.getKey(this.cardApiTicket, appId), expiresInSeconds - 200, cardApiTicket); | |||||
| } | |||||
| // TODO update to DB | |||||
| } | |||||
| } | |||||
| @@ -1,8 +1,7 @@ | |||||
| package com.iformall.service; | |||||
| package com.iformall.service.wechat; | |||||
| import com.iformall.config.RedisProperies; | import com.iformall.config.RedisProperies; | ||||
| import com.iformall.config.WechatOpenProperties; | import com.iformall.config.WechatOpenProperties; | ||||
| import me.chanjar.weixin.open.api.impl.WxOpenInRedisConfigStorage; | |||||
| import me.chanjar.weixin.open.api.impl.WxOpenMessageRouter; | import me.chanjar.weixin.open.api.impl.WxOpenMessageRouter; | ||||
| import me.chanjar.weixin.open.api.impl.WxOpenServiceImpl; | import me.chanjar.weixin.open.api.impl.WxOpenServiceImpl; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| @@ -15,14 +14,14 @@ import redis.clients.jedis.JedisPool; | |||||
| import javax.annotation.PostConstruct; | import javax.annotation.PostConstruct; | ||||
| /** | /** | ||||
| * @author <a href="https://github.com/007gzs">007</a> | |||||
| * Stormeye WU | |||||
| */ | */ | ||||
| @Service | @Service | ||||
| @EnableConfigurationProperties({WechatOpenProperties.class, RedisProperies.class}) | @EnableConfigurationProperties({WechatOpenProperties.class, RedisProperies.class}) | ||||
| public class WxOpenService extends WxOpenServiceImpl { | public class WxOpenService extends WxOpenServiceImpl { | ||||
| private Logger logger = LoggerFactory.getLogger(getClass()); | private Logger logger = LoggerFactory.getLogger(getClass()); | ||||
| @Autowired | @Autowired | ||||
| private WechatOpenProperties wechatOpenProperties; | |||||
| private WechatOpenProperties wechatProperties; | |||||
| @Autowired | @Autowired | ||||
| private RedisProperies redisProperies; | private RedisProperies redisProperies; | ||||
| private static JedisPool pool; | private static JedisPool pool; | ||||
| @@ -30,12 +29,12 @@ public class WxOpenService extends WxOpenServiceImpl { | |||||
| @PostConstruct | @PostConstruct | ||||
| public void init() { | public void init() { | ||||
| WxOpenInRedisConfigStorage inRedisConfigStorage = new WxOpenInRedisConfigStorage(getJedisPool()); | |||||
| inRedisConfigStorage.setComponentAppId(wechatOpenProperties.getComponentAppId()); | |||||
| inRedisConfigStorage.setComponentAppSecret(wechatOpenProperties.getComponentSecret()); | |||||
| inRedisConfigStorage.setComponentToken(wechatOpenProperties.getComponentToken()); | |||||
| inRedisConfigStorage.setComponentAesKey(wechatOpenProperties.getComponentAesKey()); | |||||
| setWxOpenConfigStorage(inRedisConfigStorage); | |||||
| WxOpenInRedisDBConfigStorage configStorage = new WxOpenInRedisDBConfigStorage(getJedisPool()); | |||||
| configStorage.setComponentAppId(wechatProperties.getComponentAppId()); | |||||
| configStorage.setComponentAppSecret(wechatProperties.getComponentSecret()); | |||||
| configStorage.setComponentToken(wechatProperties.getComponentToken()); | |||||
| configStorage.setComponentAesKey(wechatProperties.getComponentAesKey()); | |||||
| setWxOpenConfigStorage(configStorage); | |||||
| wxOpenMessageRouter = new WxOpenMessageRouter(this); | wxOpenMessageRouter = new WxOpenMessageRouter(this); | ||||
| wxOpenMessageRouter.rule().handler((wxMpXmlMessage, map, wxMpService, wxSessionManager) -> { | wxOpenMessageRouter.rule().handler((wxMpXmlMessage, map, wxMpService, wxSessionManager) -> { | ||||
| logger.info("\n接收到 {} 公众号请求消息,内容:{}", wxMpService.getWxMpConfigStorage().getAppId(), wxMpXmlMessage); | logger.info("\n接收到 {} 公众号请求消息,内容:{}", wxMpService.getWxMpConfigStorage().getAppId(), wxMpXmlMessage); | ||||
| @@ -57,7 +57,10 @@ public class TenantInfoImpl implements TenantInfo { | |||||
| if ("wx_tags_type".equals(tableName)) { | if ("wx_tags_type".equals(tableName)) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| if ("wx_user_channel".equals(tableName)) { | |||||
| if ("wx_component_verify_ticket".equals(tableName)) { | |||||
| return true; | |||||
| } | |||||
| if ("wx_authorizer_info".equals(tableName)) { | |||||
| return true; | return true; | ||||
| } | } | ||||
| return false; | return false; | ||||
| @@ -0,0 +1,119 @@ | |||||
| package com.iformall.ueditor; | |||||
| import com.iformall.ueditor.define.ActionMap; | |||||
| import com.iformall.ueditor.define.AppInfo; | |||||
| import com.iformall.ueditor.define.BaseState; | |||||
| import com.iformall.ueditor.define.State; | |||||
| import com.iformall.ueditor.hunter.FileManager; | |||||
| import com.iformall.ueditor.hunter.ImageHunter; | |||||
| import com.iformall.ueditor.upload.Uploader; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import java.util.Map; | |||||
| public class ActionEnter { | |||||
| private HttpServletRequest request = null; | |||||
| private String actionType = null; | |||||
| private ConfigManager configManager = null; | |||||
| public ActionEnter(ConfigManager configManager) { | |||||
| this.configManager = configManager; | |||||
| } | |||||
| public Object exec(HttpServletRequest request) { | |||||
| this.request = request; | |||||
| this.actionType = request.getParameter("action"); | |||||
| String callbackName = this.request.getParameter("callback"); | |||||
| if (callbackName != null) { | |||||
| if (!validCallbackName(callbackName)) { | |||||
| return new BaseState(false, AppInfo.ILLEGAL).toJSONString(); | |||||
| } | |||||
| //return callbackName + "(" + this.invoke() + ");"; | |||||
| return this.invoke(); | |||||
| } else { | |||||
| return this.invoke(); | |||||
| } | |||||
| } | |||||
| public Object invoke() { | |||||
| if (actionType == null || !ActionMap.mapping.containsKey(actionType)) { | |||||
| return new BaseState(false, AppInfo.INVALID_ACTION).toJSONString(); | |||||
| } | |||||
| if (this.configManager == null || !this.configManager.valid()) { | |||||
| return new BaseState(false, AppInfo.CONFIG_ERROR).toJSONString(); | |||||
| } | |||||
| State state = null; | |||||
| int actionCode = ActionMap.getType(this.actionType); | |||||
| Map<String, Object> conf = null; | |||||
| switch (actionCode) { | |||||
| case ActionMap.CONFIG: | |||||
| return this.configManager.getAllConfig(); | |||||
| case ActionMap.UPLOAD_IMAGE: | |||||
| case ActionMap.UPLOAD_SCRAWL: | |||||
| case ActionMap.UPLOAD_VIDEO: | |||||
| case ActionMap.UPLOAD_FILE: | |||||
| conf = this.configManager.getConfig(actionCode); | |||||
| state = new Uploader(request, conf).doExec(); | |||||
| break; | |||||
| case ActionMap.CATCH_IMAGE: | |||||
| conf = configManager.getConfig(actionCode); | |||||
| String[] list = this.request.getParameterValues((String) conf.get("fieldName")); | |||||
| state = new ImageHunter(conf).capture(list); | |||||
| break; | |||||
| case ActionMap.LIST_IMAGE: | |||||
| case ActionMap.LIST_FILE: | |||||
| conf = configManager.getConfig(actionCode); | |||||
| int start = this.getStartIndex(); | |||||
| state = new FileManager(conf).listFile(start); | |||||
| break; | |||||
| } | |||||
| return state.toJSONString(); | |||||
| } | |||||
| public int getStartIndex() { | |||||
| String start = this.request.getParameter("start"); | |||||
| try { | |||||
| return Integer.parseInt(start); | |||||
| } catch (Exception e) { | |||||
| return 0; | |||||
| } | |||||
| } | |||||
| /** | |||||
| * callback参数验证 | |||||
| */ | |||||
| public boolean validCallbackName(String name) { | |||||
| if (name.matches("^[a-zA-Z_]+[\\w0-9_]*$")) { | |||||
| return true; | |||||
| } | |||||
| return false; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,223 @@ | |||||
| package com.iformall.ueditor; | |||||
| import com.alibaba.fastjson.JSON; | |||||
| import com.alibaba.fastjson.JSONArray; | |||||
| import com.alibaba.fastjson.JSONException; | |||||
| import com.alibaba.fastjson.JSONObject; | |||||
| import com.iformall.config.AwsProperty; | |||||
| import com.iformall.ueditor.define.ActionMap; | |||||
| import java.io.*; | |||||
| import java.util.HashMap; | |||||
| import java.util.Map; | |||||
| import java.util.Set; | |||||
| /** | |||||
| * 配置管理器 | |||||
| * | |||||
| * @author hancong03@baidu.com | |||||
| */ | |||||
| public final class ConfigManager { | |||||
| private static final String configFileName = "config.json"; | |||||
| private JSONObject jsonConfig = null; | |||||
| // 涂鸦上传filename定义 | |||||
| private final static String SCRAWL_FILE_NAME = "scrawl"; | |||||
| // 远程图片抓取filename定义 | |||||
| private final static String REMOTE_FILE_NAME = "remote"; | |||||
| //配置信息 | |||||
| private UEditorConfig uEditorConfig; | |||||
| private AwsProperty awsProperty; | |||||
| /* | |||||
| * 通过一个给定的路径构建一个配置管理器, 该管理器要求地址路径所在目录下必须存在config.properties文件 | |||||
| */ | |||||
| private ConfigManager(UEditorConfig uEditorConfig, AwsProperty awsProperty) throws IOException { | |||||
| this.uEditorConfig = uEditorConfig; | |||||
| this.awsProperty = awsProperty; | |||||
| String configPath = uEditorConfig.getConfig(); | |||||
| configPath = configPath == null || configPath.isEmpty() ? configFileName : configPath; | |||||
| this.initEnv(configPath); | |||||
| } | |||||
| /** | |||||
| * 配置管理器构造工厂 | |||||
| * | |||||
| * @param uEditorConfig 配置文件 | |||||
| * @return 配置管理器实例或者null | |||||
| */ | |||||
| public static ConfigManager getInstance(UEditorConfig uEditorConfig, AwsProperty awsProperty) { | |||||
| try { | |||||
| return new ConfigManager(uEditorConfig, awsProperty); | |||||
| } catch (Exception e) { | |||||
| System.err.println("UEditor ConfigManager load error~"); | |||||
| return null; | |||||
| } | |||||
| } | |||||
| // 验证配置文件加载是否正确 | |||||
| public boolean valid() { | |||||
| return this.jsonConfig != null; | |||||
| } | |||||
| public JSONObject getAllConfig() { | |||||
| return this.jsonConfig; | |||||
| } | |||||
| public Map<String, Object> getConfig(int type) { | |||||
| Map<String, Object> conf = new HashMap<String, Object>(); | |||||
| String savePath = null; | |||||
| try { | |||||
| switch (type) { | |||||
| case ActionMap.UPLOAD_FILE: | |||||
| conf.put("isBase64", "false"); | |||||
| conf.put("maxSize", this.jsonConfig.getLong("fileMaxSize")); | |||||
| conf.put("allowFiles", this.getArray("fileAllowFiles")); | |||||
| conf.put("fieldName", this.jsonConfig.getString("fileFieldName")); | |||||
| conf.put("clientRegion", this.awsProperty.getClientRegion()); | |||||
| conf.put("bucketName", this.awsProperty.getBucketName()); | |||||
| conf.put("access", this.awsProperty.getAccess()); | |||||
| conf.put("secret", this.awsProperty.getSecret()); | |||||
| savePath = this.jsonConfig.getString("filePathFormat"); | |||||
| break; | |||||
| case ActionMap.UPLOAD_IMAGE: | |||||
| conf.put("isBase64", "false"); | |||||
| conf.put("maxSize", this.jsonConfig.getLong("imageMaxSize")); | |||||
| conf.put("allowFiles", this.getArray("imageAllowFiles")); | |||||
| conf.put("fieldName", this.jsonConfig.getString("imageFieldName")); | |||||
| conf.put("clientRegion", this.awsProperty.getClientRegion()); | |||||
| conf.put("bucketName", this.awsProperty.getBucketName()); | |||||
| conf.put("access", this.awsProperty.getAccess()); | |||||
| conf.put("secret", this.awsProperty.getSecret()); | |||||
| savePath = this.jsonConfig.getString("imagePathFormat"); | |||||
| break; | |||||
| case ActionMap.UPLOAD_VIDEO: | |||||
| conf.put("maxSize", this.jsonConfig.getLong("videoMaxSize")); | |||||
| conf.put("allowFiles", this.getArray("videoAllowFiles")); | |||||
| conf.put("fieldName", this.jsonConfig.getString("videoFieldName")); | |||||
| conf.put("clientRegion", this.awsProperty.getClientRegion()); | |||||
| conf.put("bucketName", this.awsProperty.getBucketName()); | |||||
| conf.put("access", this.awsProperty.getAccess()); | |||||
| conf.put("secret", this.awsProperty.getSecret()); | |||||
| savePath = this.jsonConfig.getString("videoPathFormat"); | |||||
| break; | |||||
| case ActionMap.UPLOAD_SCRAWL: | |||||
| conf.put("filename", ConfigManager.SCRAWL_FILE_NAME); | |||||
| conf.put("maxSize", this.jsonConfig.getLong("scrawlMaxSize")); | |||||
| conf.put("fieldName", this.jsonConfig.getString("scrawlFieldName")); | |||||
| conf.put("isBase64", "true"); | |||||
| savePath = this.jsonConfig.getString("scrawlPathFormat"); | |||||
| break; | |||||
| case ActionMap.CATCH_IMAGE: | |||||
| conf.put("filename", ConfigManager.REMOTE_FILE_NAME); | |||||
| conf.put("filter", this.getArray("catcherLocalDomain")); | |||||
| conf.put("maxSize", this.jsonConfig.getLong("catcherMaxSize")); | |||||
| conf.put("allowFiles", this.getArray("catcherAllowFiles")); | |||||
| conf.put("fieldName", this.jsonConfig.getString("catcherFieldName") + "[]"); | |||||
| savePath = this.jsonConfig.getString("catcherPathFormat"); | |||||
| break; | |||||
| case ActionMap.LIST_IMAGE: | |||||
| conf.put("allowFiles", this.getArray("imageManagerAllowFiles")); | |||||
| conf.put("dir", this.jsonConfig.getString("imageManagerListPath")); | |||||
| conf.put("count", this.jsonConfig.getIntValue("imageManagerListSize")); | |||||
| break; | |||||
| case ActionMap.LIST_FILE: | |||||
| conf.put("allowFiles", this.getArray("fileManagerAllowFiles")); | |||||
| conf.put("dir", this.jsonConfig.getString("fileManagerListPath")); | |||||
| conf.put("count", this.jsonConfig.getIntValue("fileManagerListSize")); | |||||
| break; | |||||
| } | |||||
| } catch (JSONException e) { | |||||
| e.printStackTrace(); | |||||
| } | |||||
| conf.put("savePath", savePath); | |||||
| conf.put("rootPath", uEditorConfig.getUploadPath()); | |||||
| conf.put("urlPrefix", uEditorConfig.getUrlPrefix()); | |||||
| return conf; | |||||
| } | |||||
| private void initEnv(String configPath) throws IOException { | |||||
| String configContent = this.readFile(configPath); | |||||
| try { | |||||
| JSONObject jsonConfig = JSON.parseObject(configContent); | |||||
| //统一url访问前缀 | |||||
| if (uEditorConfig.getUnified()) { | |||||
| Set<Map.Entry<String, Object>> entrySet = jsonConfig.entrySet(); | |||||
| for (Map.Entry<String, Object> entry : entrySet) { | |||||
| String key = entry.getKey(); | |||||
| if(key.contains("UrlPrefix")) { | |||||
| jsonConfig.put(key, uEditorConfig.getUrlPrefix()); | |||||
| } | |||||
| } | |||||
| } | |||||
| this.jsonConfig = jsonConfig; | |||||
| } catch (Exception e) { | |||||
| this.jsonConfig = null; | |||||
| } | |||||
| } | |||||
| private String[] getArray(String key) throws JSONException { | |||||
| JSONArray jsonArray = this.jsonConfig.getJSONArray(key); | |||||
| String[] result = new String[jsonArray.size()]; | |||||
| for (int i = 0, len = jsonArray.size(); i < len; i++) { | |||||
| result[i] = jsonArray.getString(i); | |||||
| } | |||||
| return result; | |||||
| } | |||||
| private String readFile(String path) throws IOException { | |||||
| StringBuilder builder = new StringBuilder(); | |||||
| try { | |||||
| InputStream inputStream = getClass().getClassLoader().getResourceAsStream(path); | |||||
| InputStreamReader reader = new InputStreamReader(inputStream, "UTF-8"); | |||||
| BufferedReader bfReader = new BufferedReader(reader); | |||||
| String tmpContent = null; | |||||
| while ((tmpContent = bfReader.readLine()) != null) { | |||||
| builder.append(tmpContent); | |||||
| } | |||||
| bfReader.close(); | |||||
| } catch (UnsupportedEncodingException e) { | |||||
| // 忽略 | |||||
| } | |||||
| return this.filter(builder.toString()); | |||||
| } | |||||
| // 过滤输入字符串, 剔除多行注释以及替换掉反斜杠 | |||||
| private String filter(String input) { | |||||
| return input.replaceAll("/\\*[\\s\\S]*?\\*/", ""); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,24 @@ | |||||
| package com.iformall.ueditor; | |||||
| public class Encoder { | |||||
| public static String toUnicode ( String input ) { | |||||
| StringBuilder builder = new StringBuilder(); | |||||
| char[] chars = input.toCharArray(); | |||||
| for ( char ch : chars ) { | |||||
| if ( ch < 256 ) { | |||||
| builder.append( ch ); | |||||
| } else { | |||||
| builder.append( "\\u" + Integer.toHexString( ch& 0xffff ) ); | |||||
| } | |||||
| } | |||||
| return builder.toString(); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,157 @@ | |||||
| package com.iformall.ueditor; | |||||
| import java.text.SimpleDateFormat; | |||||
| import java.util.Date; | |||||
| import java.util.regex.Matcher; | |||||
| import java.util.regex.Pattern; | |||||
| public class PathFormat { | |||||
| private static final String TIME = "time"; | |||||
| private static final String FULL_YEAR = "yyyy"; | |||||
| private static final String YEAR = "yy"; | |||||
| private static final String MONTH = "mm"; | |||||
| private static final String DAY = "dd"; | |||||
| private static final String HOUR = "hh"; | |||||
| private static final String MINUTE = "ii"; | |||||
| private static final String SECOND = "ss"; | |||||
| private static final String RAND = "rand"; | |||||
| private static Date currentDate = null; | |||||
| public static String parse ( String input ) { | |||||
| Pattern pattern = Pattern.compile( "\\{([^\\}]+)\\}", Pattern.CASE_INSENSITIVE ); | |||||
| Matcher matcher = pattern.matcher(input); | |||||
| PathFormat.currentDate = new Date(); | |||||
| StringBuffer sb = new StringBuffer(); | |||||
| while ( matcher.find() ) { | |||||
| matcher.appendReplacement(sb, PathFormat.getString( matcher.group( 1 ) ) ); | |||||
| } | |||||
| matcher.appendTail(sb); | |||||
| return sb.toString(); | |||||
| } | |||||
| /** | |||||
| * 格式化路径, 把windows路径替换成标准路径 | |||||
| * @param input 待格式化的路径 | |||||
| * @return 格式化后的路径 | |||||
| */ | |||||
| public static String format ( String input ) { | |||||
| return input.replace( "\\", "/" ); | |||||
| } | |||||
| public static String parse ( String input, String filename ) { | |||||
| Pattern pattern = Pattern.compile( "\\{([^\\}]+)\\}", Pattern.CASE_INSENSITIVE ); | |||||
| Matcher matcher = pattern.matcher(input); | |||||
| String matchStr = null; | |||||
| PathFormat.currentDate = new Date(); | |||||
| StringBuffer sb = new StringBuffer(); | |||||
| while ( matcher.find() ) { | |||||
| matchStr = matcher.group( 1 ); | |||||
| if ( matchStr.indexOf( "filename" ) != -1 ) { | |||||
| filename = filename.replace( "$", "\\$" ).replaceAll( "[\\/:*?\"<>|]", "" ); | |||||
| matcher.appendReplacement(sb, filename ); | |||||
| } else { | |||||
| matcher.appendReplacement(sb, PathFormat.getString( matchStr ) ); | |||||
| } | |||||
| } | |||||
| matcher.appendTail(sb); | |||||
| return sb.toString(); | |||||
| } | |||||
| private static String getString ( String pattern ) { | |||||
| pattern = pattern.toLowerCase(); | |||||
| // time 处理 | |||||
| if ( pattern.indexOf( PathFormat.TIME ) != -1 ) { | |||||
| return PathFormat.getTimestamp(); | |||||
| } else if ( pattern.indexOf( PathFormat.FULL_YEAR ) != -1 ) { | |||||
| return PathFormat.getFullYear(); | |||||
| } else if ( pattern.indexOf( PathFormat.YEAR ) != -1 ) { | |||||
| return PathFormat.getYear(); | |||||
| } else if ( pattern.indexOf( PathFormat.MONTH ) != -1 ) { | |||||
| return PathFormat.getMonth(); | |||||
| } else if ( pattern.indexOf( PathFormat.DAY ) != -1 ) { | |||||
| return PathFormat.getDay(); | |||||
| } else if ( pattern.indexOf( PathFormat.HOUR ) != -1 ) { | |||||
| return PathFormat.getHour(); | |||||
| } else if ( pattern.indexOf( PathFormat.MINUTE ) != -1 ) { | |||||
| return PathFormat.getMinute(); | |||||
| } else if ( pattern.indexOf( PathFormat.SECOND ) != -1 ) { | |||||
| return PathFormat.getSecond(); | |||||
| } else if ( pattern.indexOf( PathFormat.RAND ) != -1 ) { | |||||
| return PathFormat.getRandom( pattern ); | |||||
| } | |||||
| return pattern; | |||||
| } | |||||
| private static String getTimestamp () { | |||||
| return System.currentTimeMillis() + ""; | |||||
| } | |||||
| private static String getFullYear () { | |||||
| return new SimpleDateFormat( "yyyy" ).format( PathFormat.currentDate ); | |||||
| } | |||||
| private static String getYear () { | |||||
| return new SimpleDateFormat( "yy" ).format( PathFormat.currentDate ); | |||||
| } | |||||
| private static String getMonth () { | |||||
| return new SimpleDateFormat( "MM" ).format( PathFormat.currentDate ); | |||||
| } | |||||
| private static String getDay () { | |||||
| return new SimpleDateFormat( "dd" ).format( PathFormat.currentDate ); | |||||
| } | |||||
| private static String getHour () { | |||||
| return new SimpleDateFormat( "HH" ).format( PathFormat.currentDate ); | |||||
| } | |||||
| private static String getMinute () { | |||||
| return new SimpleDateFormat( "mm" ).format( PathFormat.currentDate ); | |||||
| } | |||||
| private static String getSecond () { | |||||
| return new SimpleDateFormat( "ss" ).format( PathFormat.currentDate ); | |||||
| } | |||||
| private static String getRandom ( String pattern ) { | |||||
| int length = 0; | |||||
| pattern = pattern.split( ":" )[ 1 ].trim(); | |||||
| length = Integer.parseInt( pattern ); | |||||
| return ( Math.random() + "" ).replace( ".", "" ).substring( 0, length ); | |||||
| } | |||||
| public static void main(String[] args) { | |||||
| // TODO Auto-generated method stub | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,59 @@ | |||||
| package com.iformall.ueditor; | |||||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||||
| /** | |||||
| * Created by pangxiaofeng on 2017/9/27. | |||||
| */ | |||||
| @ConfigurationProperties(prefix = "ueditor") | |||||
| public class UEditorConfig { | |||||
| /** | |||||
| * config.json的文件存放地址 | |||||
| */ | |||||
| private String config; | |||||
| /** | |||||
| * 是否同统一上传地址:图片上传地址,视频上传地址... | |||||
| */ | |||||
| private boolean unified; | |||||
| /** | |||||
| * 文件上传路径 | |||||
| */ | |||||
| private String uploadPath; | |||||
| /** | |||||
| * 文件url前缀 | |||||
| */ | |||||
| private String urlPrefix; | |||||
| public String getConfig() { | |||||
| return config; | |||||
| } | |||||
| public void setConfig(String config) { | |||||
| this.config = config; | |||||
| } | |||||
| public String getUploadPath() { | |||||
| return uploadPath; | |||||
| } | |||||
| public void setUploadPath(String uploadPath) { | |||||
| this.uploadPath = uploadPath; | |||||
| } | |||||
| public String getUrlPrefix() { | |||||
| return urlPrefix; | |||||
| } | |||||
| public void setUrlPrefix(String urlPrefix) { | |||||
| this.urlPrefix = urlPrefix; | |||||
| } | |||||
| public boolean getUnified() { | |||||
| return unified; | |||||
| } | |||||
| public void setUnified(boolean unified) { | |||||
| this.unified = unified; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,42 @@ | |||||
| package com.iformall.ueditor.define; | |||||
| import java.util.HashMap; | |||||
| import java.util.Map; | |||||
| /** | |||||
| * 定义请求action类型 | |||||
| * @author hancong03@baidu.com | |||||
| * | |||||
| */ | |||||
| @SuppressWarnings("serial") | |||||
| public final class ActionMap { | |||||
| public static final Map<String, Integer> mapping; | |||||
| // 获取配置请求 | |||||
| public static final int CONFIG = 0; | |||||
| public static final int UPLOAD_IMAGE = 1; | |||||
| public static final int UPLOAD_SCRAWL = 2; | |||||
| public static final int UPLOAD_VIDEO = 3; | |||||
| public static final int UPLOAD_FILE = 4; | |||||
| public static final int CATCH_IMAGE = 5; | |||||
| public static final int LIST_FILE = 6; | |||||
| public static final int LIST_IMAGE = 7; | |||||
| static { | |||||
| mapping = new HashMap<String, Integer>(){{ | |||||
| put( "config", ActionMap.CONFIG ); | |||||
| put( "uploadimage", ActionMap.UPLOAD_IMAGE ); | |||||
| put( "uploadscrawl", ActionMap.UPLOAD_SCRAWL ); | |||||
| put( "uploadvideo", ActionMap.UPLOAD_VIDEO ); | |||||
| put( "uploadfile", ActionMap.UPLOAD_FILE ); | |||||
| put( "catchimage", ActionMap.CATCH_IMAGE ); | |||||
| put( "listfile", ActionMap.LIST_FILE ); | |||||
| put( "listimage", ActionMap.LIST_IMAGE ); | |||||
| }}; | |||||
| } | |||||
| public static int getType ( String key ) { | |||||
| return ActionMap.mapping.get( key ); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,5 @@ | |||||
| package com.iformall.ueditor.define; | |||||
| public enum ActionState { | |||||
| UNKNOW_ERROR | |||||
| } | |||||
| @@ -0,0 +1,77 @@ | |||||
| package com.iformall.ueditor.define; | |||||
| import java.util.HashMap; | |||||
| import java.util.Map; | |||||
| public final class AppInfo { | |||||
| public static final int SUCCESS = 0; | |||||
| public static final int MAX_SIZE = 1; | |||||
| public static final int PERMISSION_DENIED = 2; | |||||
| public static final int FAILED_CREATE_FILE = 3; | |||||
| public static final int IO_ERROR = 4; | |||||
| public static final int NOT_MULTIPART_CONTENT = 5; | |||||
| public static final int PARSE_REQUEST_ERROR = 6; | |||||
| public static final int NOTFOUND_UPLOAD_DATA = 7; | |||||
| public static final int NOT_ALLOW_FILE_TYPE = 8; | |||||
| public static final int INVALID_ACTION = 101; | |||||
| public static final int CONFIG_ERROR = 102; | |||||
| public static final int PREVENT_HOST = 201; | |||||
| public static final int CONNECTION_ERROR = 202; | |||||
| public static final int REMOTE_FAIL = 203; | |||||
| public static final int NOT_DIRECTORY = 301; | |||||
| public static final int NOT_EXIST = 302; | |||||
| public static final int ILLEGAL = 401; | |||||
| public static Map<Integer, String> info = new HashMap<Integer, String>(){{ | |||||
| put( AppInfo.SUCCESS, "SUCCESS" ); | |||||
| // 无效的Action | |||||
| put( AppInfo.INVALID_ACTION, "\u65E0\u6548\u7684Action" ); | |||||
| // 配置文件初始化失败 | |||||
| put( AppInfo.CONFIG_ERROR, "\u914D\u7F6E\u6587\u4EF6\u521D\u59CB\u5316\u5931\u8D25" ); | |||||
| // 抓取远程图片失败 | |||||
| put( AppInfo.REMOTE_FAIL, "\u6293\u53D6\u8FDC\u7A0B\u56FE\u7247\u5931\u8D25" ); | |||||
| // 被阻止的远程主机 | |||||
| put( AppInfo.PREVENT_HOST, "\u88AB\u963B\u6B62\u7684\u8FDC\u7A0B\u4E3B\u673A" ); | |||||
| // 远程连接出错 | |||||
| put( AppInfo.CONNECTION_ERROR, "\u8FDC\u7A0B\u8FDE\u63A5\u51FA\u9519" ); | |||||
| // "文件大小超出限制" | |||||
| put( AppInfo.MAX_SIZE, "\u6587\u4ef6\u5927\u5c0f\u8d85\u51fa\u9650\u5236" ); | |||||
| // 权限不足, 多指写权限 | |||||
| put( AppInfo.PERMISSION_DENIED, "\u6743\u9650\u4E0D\u8DB3" ); | |||||
| // 创建文件失败 | |||||
| put( AppInfo.FAILED_CREATE_FILE, "\u521B\u5EFA\u6587\u4EF6\u5931\u8D25" ); | |||||
| // IO错误 | |||||
| put( AppInfo.IO_ERROR, "IO\u9519\u8BEF" ); | |||||
| // 上传表单不是multipart/form-data类型 | |||||
| put( AppInfo.NOT_MULTIPART_CONTENT, "\u4E0A\u4F20\u8868\u5355\u4E0D\u662Fmultipart/form-data\u7C7B\u578B" ); | |||||
| // 解析上传表单错误 | |||||
| put( AppInfo.PARSE_REQUEST_ERROR, "\u89E3\u6790\u4E0A\u4F20\u8868\u5355\u9519\u8BEF" ); | |||||
| // 未找到上传数据 | |||||
| put( AppInfo.NOTFOUND_UPLOAD_DATA, "\u672A\u627E\u5230\u4E0A\u4F20\u6570\u636E" ); | |||||
| // 不允许的文件类型 | |||||
| put( AppInfo.NOT_ALLOW_FILE_TYPE, "\u4E0D\u5141\u8BB8\u7684\u6587\u4EF6\u7C7B\u578B" ); | |||||
| // 指定路径不是目录 | |||||
| put( AppInfo.NOT_DIRECTORY, "\u6307\u5B9A\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55" ); | |||||
| // 指定路径并不存在 | |||||
| put( AppInfo.NOT_EXIST, "\u6307\u5B9A\u8DEF\u5F84\u5E76\u4E0D\u5B58\u5728" ); | |||||
| // callback参数名不合法 | |||||
| put( AppInfo.ILLEGAL, "Callback\u53C2\u6570\u540D\u4E0D\u5408\u6CD5" ); | |||||
| }}; | |||||
| public static String getStateInfo ( int key ) { | |||||
| return AppInfo.info.get( key ); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,90 @@ | |||||
| package com.iformall.ueditor.define; | |||||
| import com.iformall.ueditor.Encoder; | |||||
| import java.util.HashMap; | |||||
| import java.util.Iterator; | |||||
| import java.util.Map; | |||||
| public class BaseState implements State { | |||||
| private boolean state = false; | |||||
| private String info = null; | |||||
| private Map<String, String> infoMap = new HashMap<String, String>(); | |||||
| public BaseState () { | |||||
| this.state = true; | |||||
| } | |||||
| public BaseState ( boolean state ) { | |||||
| this.setState( state ); | |||||
| } | |||||
| public BaseState ( boolean state, String info ) { | |||||
| this.setState( state ); | |||||
| this.info = info; | |||||
| } | |||||
| public BaseState ( boolean state, int infoCode ) { | |||||
| this.setState( state ); | |||||
| this.info = AppInfo.getStateInfo( infoCode ); | |||||
| } | |||||
| public boolean isSuccess () { | |||||
| return this.state; | |||||
| } | |||||
| public void setState ( boolean state ) { | |||||
| this.state = state; | |||||
| } | |||||
| public void setInfo ( String info ) { | |||||
| this.info = info; | |||||
| } | |||||
| public void setInfo ( int infoCode ) { | |||||
| this.info = AppInfo.getStateInfo( infoCode ); | |||||
| } | |||||
| @Override | |||||
| public String toJSONString() { | |||||
| return this.toString(); | |||||
| } | |||||
| public String toString () { | |||||
| String key = null; | |||||
| String stateVal = this.isSuccess() ? AppInfo.getStateInfo( AppInfo.SUCCESS ) : this.info; | |||||
| StringBuilder builder = new StringBuilder(); | |||||
| builder.append( "{\"state\": \"" + stateVal + "\"" ); | |||||
| Iterator<String> iterator = this.infoMap.keySet().iterator(); | |||||
| while ( iterator.hasNext() ) { | |||||
| key = iterator.next(); | |||||
| builder.append( ",\"" + key + "\": \"" + this.infoMap.get(key) + "\"" ); | |||||
| } | |||||
| builder.append( "}" ); | |||||
| return Encoder.toUnicode( builder.toString() ); | |||||
| } | |||||
| @Override | |||||
| public void putInfo(String name, String val) { | |||||
| this.infoMap.put(name, val); | |||||
| } | |||||
| @Override | |||||
| public void putInfo(String name, long val) { | |||||
| this.putInfo(name, val+""); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,31 @@ | |||||
| package com.iformall.ueditor.define; | |||||
| import java.util.HashMap; | |||||
| import java.util.Map; | |||||
| public class FileType { | |||||
| public static final String JPG = "JPG"; | |||||
| private static final Map<String, String> types = new HashMap<String, String>(){{ | |||||
| put( FileType.JPG, ".jpg" ); | |||||
| }}; | |||||
| public static String getSuffix ( String key ) { | |||||
| return FileType.types.get( key ); | |||||
| } | |||||
| /** | |||||
| * 根据给定的文件名,获取其后缀信息 | |||||
| * @param filename | |||||
| * @return | |||||
| */ | |||||
| public static String getSuffixByFilename ( String filename ) { | |||||
| return filename.substring( filename.lastIndexOf( "." ) ).toLowerCase(); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,20 @@ | |||||
| package com.iformall.ueditor.define; | |||||
| import java.util.HashMap; | |||||
| import java.util.Map; | |||||
| public class MIMEType { | |||||
| public static final Map<String, String> types = new HashMap<String, String>(){{ | |||||
| put( "image/gif", ".gif" ); | |||||
| put( "image/jpeg", ".jpg" ); | |||||
| put( "image/jpg", ".jpg" ); | |||||
| put( "image/png", ".png" ); | |||||
| put( "image/bmp", ".bmp" ); | |||||
| }}; | |||||
| public static String getSuffix ( String mime ) { | |||||
| return MIMEType.types.get( mime ); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,108 @@ | |||||
| package com.iformall.ueditor.define; | |||||
| import com.iformall.ueditor.Encoder; | |||||
| import java.util.*; | |||||
| /** | |||||
| * 多状态集合状态 | |||||
| * 其包含了多个状态的集合, 其本身自己也是一个状态 | |||||
| * @author hancong03@baidu.com | |||||
| * | |||||
| */ | |||||
| public class MultiState implements State { | |||||
| private boolean state = false; | |||||
| private String info = null; | |||||
| private Map<String, Long> intMap = new HashMap<String, Long>(); | |||||
| private Map<String, String> infoMap = new HashMap<String, String>(); | |||||
| private List<String> stateList = new ArrayList<String>(); | |||||
| public MultiState ( boolean state ) { | |||||
| this.state = state; | |||||
| } | |||||
| public MultiState ( boolean state, String info ) { | |||||
| this.state = state; | |||||
| this.info = info; | |||||
| } | |||||
| public MultiState ( boolean state, int infoKey ) { | |||||
| this.state = state; | |||||
| this.info = AppInfo.getStateInfo( infoKey ); | |||||
| } | |||||
| @Override | |||||
| public boolean isSuccess() { | |||||
| return this.state; | |||||
| } | |||||
| public void addState ( State state ) { | |||||
| stateList.add( state.toJSONString() ); | |||||
| } | |||||
| /** | |||||
| * 该方法调用无效果 | |||||
| */ | |||||
| @Override | |||||
| public void putInfo(String name, String val) { | |||||
| this.infoMap.put(name, val); | |||||
| } | |||||
| @Override | |||||
| public String toJSONString() { | |||||
| String stateVal = this.isSuccess() ? AppInfo.getStateInfo( AppInfo.SUCCESS ) : this.info; | |||||
| StringBuilder builder = new StringBuilder(); | |||||
| builder.append( "{\"state\": \"" + stateVal + "\"" ); | |||||
| // 数字转换 | |||||
| Iterator<String> iterator = this.intMap.keySet().iterator(); | |||||
| while ( iterator.hasNext() ) { | |||||
| stateVal = iterator.next(); | |||||
| builder.append( ",\""+ stateVal +"\": " + this.intMap.get( stateVal ) ); | |||||
| } | |||||
| iterator = this.infoMap.keySet().iterator(); | |||||
| while ( iterator.hasNext() ) { | |||||
| stateVal = iterator.next(); | |||||
| builder.append( ",\""+ stateVal +"\": \"" + this.infoMap.get( stateVal ) + "\"" ); | |||||
| } | |||||
| builder.append( ", list: [" ); | |||||
| iterator = this.stateList.iterator(); | |||||
| while ( iterator.hasNext() ) { | |||||
| builder.append( iterator.next() + "," ); | |||||
| } | |||||
| if ( this.stateList.size() > 0 ) { | |||||
| builder.deleteCharAt( builder.length() - 1 ); | |||||
| } | |||||
| builder.append( " ]}" ); | |||||
| return Encoder.toUnicode( builder.toString() ); | |||||
| } | |||||
| @Override | |||||
| public void putInfo(String name, long val) { | |||||
| this.intMap.put( name, val ); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,18 @@ | |||||
| package com.iformall.ueditor.define; | |||||
| /** | |||||
| * 处理状态接口 | |||||
| * @author hancong03@baidu.com | |||||
| * | |||||
| */ | |||||
| public interface State { | |||||
| public boolean isSuccess(); | |||||
| public void putInfo(String name, String val); | |||||
| public void putInfo(String name, long val); | |||||
| public String toJSONString(); | |||||
| } | |||||
| @@ -0,0 +1,111 @@ | |||||
| package com.iformall.ueditor.hunter; | |||||
| import com.iformall.ueditor.PathFormat; | |||||
| import com.iformall.ueditor.define.AppInfo; | |||||
| import com.iformall.ueditor.define.BaseState; | |||||
| import com.iformall.ueditor.define.MultiState; | |||||
| import com.iformall.ueditor.define.State; | |||||
| import org.apache.commons.io.FileUtils; | |||||
| import java.io.File; | |||||
| import java.util.Arrays; | |||||
| import java.util.Collection; | |||||
| import java.util.Map; | |||||
| public class FileManager { | |||||
| private String dir = null; | |||||
| private String rootPath = null; | |||||
| private String[] allowFiles = null; | |||||
| private int count = 0; | |||||
| public FileManager(Map<String, Object> conf) { | |||||
| this.rootPath = (String) conf.get("rootPath"); | |||||
| this.dir = this.rootPath + (String) conf.get("dir"); | |||||
| this.allowFiles = this.getAllowFiles(conf.get("allowFiles")); | |||||
| this.count = (Integer) conf.get("count"); | |||||
| } | |||||
| public State listFile(int index) { | |||||
| File dir = new File(this.dir); | |||||
| State state = null; | |||||
| if (!dir.exists()) { | |||||
| return new BaseState(false, AppInfo.NOT_EXIST); | |||||
| } | |||||
| if (!dir.isDirectory()) { | |||||
| return new BaseState(false, AppInfo.NOT_DIRECTORY); | |||||
| } | |||||
| Collection<File> list = FileUtils.listFiles(dir, this.allowFiles, true); | |||||
| if (index < 0 || index > list.size()) { | |||||
| state = new MultiState(true); | |||||
| } else { | |||||
| Object[] fileList = Arrays.copyOfRange(list.toArray(), index, index + this.count); | |||||
| state = this.getState(fileList); | |||||
| } | |||||
| state.putInfo("start", index); | |||||
| state.putInfo("total", list.size()); | |||||
| return state; | |||||
| } | |||||
| private State getState(Object[] files) { | |||||
| MultiState state = new MultiState(true); | |||||
| BaseState fileState = null; | |||||
| File file = null; | |||||
| for (Object obj : files) { | |||||
| if (obj == null) { | |||||
| break; | |||||
| } | |||||
| file = (File) obj; | |||||
| fileState = new BaseState(true); | |||||
| fileState.putInfo("url", PathFormat.format(this.getPath(file))); | |||||
| state.addState(fileState); | |||||
| } | |||||
| return state; | |||||
| } | |||||
| private String getPath(File file) { | |||||
| String path = file.getAbsolutePath(); | |||||
| path = PathFormat.format(path); | |||||
| return path.replace(this.rootPath, "/"); | |||||
| } | |||||
| private String[] getAllowFiles(Object fileExt) { | |||||
| String[] exts = null; | |||||
| String ext = null; | |||||
| if (fileExt == null) { | |||||
| return new String[0]; | |||||
| } | |||||
| exts = (String[]) fileExt; | |||||
| for (int i = 0, len = exts.length; i < len; i++) { | |||||
| ext = exts[i]; | |||||
| exts[i] = ext.replace(".", ""); | |||||
| } | |||||
| return exts; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,140 @@ | |||||
| package com.iformall.ueditor.hunter; | |||||
| import com.iformall.ueditor.PathFormat; | |||||
| import com.iformall.ueditor.define.*; | |||||
| import com.iformall.ueditor.upload.StorageManager; | |||||
| import java.net.HttpURLConnection; | |||||
| import java.net.InetAddress; | |||||
| import java.net.URL; | |||||
| import java.net.UnknownHostException; | |||||
| import java.util.Arrays; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| /** | |||||
| * 图片抓取器 | |||||
| * @author hancong03@baidu.com | |||||
| * | |||||
| */ | |||||
| public class ImageHunter { | |||||
| private String filename = null; | |||||
| private String savePath = null; | |||||
| private String rootPath = null; | |||||
| private List<String> allowTypes = null; | |||||
| private long maxSize = -1; | |||||
| private List<String> filters = null; | |||||
| public ImageHunter ( Map<String, Object> conf ) { | |||||
| this.filename = (String)conf.get( "filename" ); | |||||
| this.savePath = (String)conf.get( "savePath" ); | |||||
| this.rootPath = (String)conf.get( "rootPath" ); | |||||
| this.maxSize = (Long)conf.get( "maxSize" ); | |||||
| this.allowTypes = Arrays.asList( (String[])conf.get( "allowFiles" ) ); | |||||
| this.filters = Arrays.asList( (String[])conf.get( "filter" ) ); | |||||
| } | |||||
| public State capture (String[] list ) { | |||||
| MultiState state = new MultiState( true ); | |||||
| for ( String source : list ) { | |||||
| state.addState( captureRemoteData( source ) ); | |||||
| } | |||||
| return state; | |||||
| } | |||||
| public State captureRemoteData ( String urlStr ) { | |||||
| HttpURLConnection connection = null; | |||||
| URL url = null; | |||||
| String suffix = null; | |||||
| try { | |||||
| url = new URL( urlStr ); | |||||
| if ( !validHost( url.getHost() ) ) { | |||||
| return new BaseState( false, AppInfo.PREVENT_HOST ); | |||||
| } | |||||
| connection = (HttpURLConnection) url.openConnection(); | |||||
| connection.setInstanceFollowRedirects( true ); | |||||
| connection.setUseCaches( true ); | |||||
| if ( !validContentState( connection.getResponseCode() ) ) { | |||||
| return new BaseState( false, AppInfo.CONNECTION_ERROR ); | |||||
| } | |||||
| suffix = MIMEType.getSuffix( connection.getContentType() ); | |||||
| if ( !validFileType( suffix ) ) { | |||||
| return new BaseState( false, AppInfo.NOT_ALLOW_FILE_TYPE ); | |||||
| } | |||||
| if ( !validFileSize( connection.getContentLength() ) ) { | |||||
| return new BaseState( false, AppInfo.MAX_SIZE ); | |||||
| } | |||||
| String savePath = this.getPath( this.savePath, this.filename, suffix ); | |||||
| String physicalPath = this.rootPath + savePath; | |||||
| State state = StorageManager.saveFileByInputStream( connection.getInputStream(), physicalPath ); | |||||
| if ( state.isSuccess() ) { | |||||
| state.putInfo( "url", PathFormat.format( savePath ) ); | |||||
| state.putInfo( "source", urlStr ); | |||||
| } | |||||
| return state; | |||||
| } catch ( Exception e ) { | |||||
| return new BaseState( false, AppInfo.REMOTE_FAIL ); | |||||
| } | |||||
| } | |||||
| private String getPath ( String savePath, String filename, String suffix ) { | |||||
| return PathFormat.parse( savePath + suffix, filename ); | |||||
| } | |||||
| private boolean validHost ( String hostname ) { | |||||
| try { | |||||
| InetAddress ip = InetAddress.getByName(hostname); | |||||
| if (ip.isSiteLocalAddress()) { | |||||
| return false; | |||||
| } | |||||
| } catch (UnknownHostException e) { | |||||
| return false; | |||||
| } | |||||
| return !filters.contains( hostname ); | |||||
| } | |||||
| private boolean validContentState ( int code ) { | |||||
| return HttpURLConnection.HTTP_OK == code; | |||||
| } | |||||
| private boolean validFileType ( String type ) { | |||||
| return this.allowTypes.contains( type ); | |||||
| } | |||||
| private boolean validFileSize ( int size ) { | |||||
| return size < this.maxSize; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,51 @@ | |||||
| package com.iformall.ueditor.upload; | |||||
| import com.iformall.ueditor.PathFormat; | |||||
| import com.iformall.ueditor.define.AppInfo; | |||||
| import com.iformall.ueditor.define.BaseState; | |||||
| import com.iformall.ueditor.define.FileType; | |||||
| import com.iformall.ueditor.define.State; | |||||
| import org.apache.commons.codec.binary.Base64; | |||||
| import java.util.Map; | |||||
| public final class Base64Uploader { | |||||
| public static State save(String content, Map<String, Object> conf) { | |||||
| byte[] data = decode(content); | |||||
| long maxSize = ((Long) conf.get("maxSize")).longValue(); | |||||
| if (!validSize(data, maxSize)) { | |||||
| return new BaseState(false, AppInfo.MAX_SIZE); | |||||
| } | |||||
| String suffix = FileType.getSuffix("JPG"); | |||||
| String savePath = PathFormat.parse((String) conf.get("savePath"), | |||||
| (String) conf.get("filename")); | |||||
| savePath = savePath + suffix; | |||||
| String physicalPath = (String) conf.get("rootPath") + savePath; | |||||
| State storageState = StorageManager.saveBinaryFile(data, physicalPath); | |||||
| if (storageState.isSuccess()) { | |||||
| storageState.putInfo("url", PathFormat.format(savePath)); | |||||
| storageState.putInfo("type", suffix); | |||||
| storageState.putInfo("original", ""); | |||||
| } | |||||
| return storageState; | |||||
| } | |||||
| private static byte[] decode(String content) { | |||||
| return Base64.decodeBase64(content); | |||||
| } | |||||
| private static boolean validSize(byte[] data, long length) { | |||||
| return data.length <= length; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,70 @@ | |||||
| package com.iformall.ueditor.upload; | |||||
| import com.iformall.ueditor.PathFormat; | |||||
| import com.iformall.ueditor.define.AppInfo; | |||||
| import com.iformall.ueditor.define.BaseState; | |||||
| import com.iformall.ueditor.define.FileType; | |||||
| import com.iformall.ueditor.define.State; | |||||
| import org.apache.commons.fileupload.servlet.ServletFileUpload; | |||||
| import org.springframework.web.multipart.MultipartFile; | |||||
| import org.springframework.web.multipart.MultipartHttpServletRequest; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import java.io.IOException; | |||||
| import java.io.InputStream; | |||||
| import java.util.Arrays; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| public class BinaryUploader { | |||||
| public static final State save(HttpServletRequest request, Map<String, Object> conf) { | |||||
| if (!ServletFileUpload.isMultipartContent(request)) { | |||||
| return new BaseState(false, AppInfo.NOT_MULTIPART_CONTENT); | |||||
| } | |||||
| MultipartFile file = ((MultipartHttpServletRequest) request).getFile("upfile"); | |||||
| try { | |||||
| if (file == null) { | |||||
| return new BaseState(false, AppInfo.NOTFOUND_UPLOAD_DATA); | |||||
| } | |||||
| String savePath = (String) conf.get("savePath"); | |||||
| String originFileName = file.getOriginalFilename(); | |||||
| String suffix = FileType.getSuffixByFilename(file.getOriginalFilename()); | |||||
| originFileName = originFileName.substring(0, | |||||
| originFileName.length() - suffix.length()); | |||||
| savePath = savePath + suffix; | |||||
| long maxSize = ((Long) conf.get("maxSize")).longValue(); | |||||
| if (!validType(suffix, (String[]) conf.get("allowFiles"))) { | |||||
| return new BaseState(false, AppInfo.NOT_ALLOW_FILE_TYPE); | |||||
| } | |||||
| savePath = PathFormat.parse(savePath, originFileName); | |||||
| String physicalPath = (String) conf.get("rootPath") + savePath; | |||||
| InputStream is = file.getInputStream(); | |||||
| State storageState = StorageManager.saveFileByInputStream(is, physicalPath, maxSize); | |||||
| is.close(); | |||||
| if (storageState.isSuccess()) { | |||||
| storageState.putInfo("url", PathFormat.format(savePath)); | |||||
| storageState.putInfo("local", physicalPath); | |||||
| storageState.putInfo("type", suffix); | |||||
| storageState.putInfo("original", originFileName + suffix); | |||||
| } | |||||
| return storageState; | |||||
| } catch (IOException e) { | |||||
| } | |||||
| return new BaseState(false, AppInfo.IO_ERROR); | |||||
| } | |||||
| private static boolean validType(String type, String[] allowTypes) { | |||||
| List<String> list = Arrays.asList(allowTypes); | |||||
| return list.contains(type); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,148 @@ | |||||
| package com.iformall.ueditor.upload; | |||||
| import com.iformall.ueditor.define.AppInfo; | |||||
| import com.iformall.ueditor.define.BaseState; | |||||
| import com.iformall.ueditor.define.State; | |||||
| import org.apache.commons.io.FileUtils; | |||||
| import java.io.*; | |||||
| public class StorageManager { | |||||
| public static final int BUFFER_SIZE = 8192; | |||||
| public StorageManager() { | |||||
| } | |||||
| public static State saveBinaryFile(byte[] data, String path) { | |||||
| File file = new File(path); | |||||
| State state = valid(file); | |||||
| if (!state.isSuccess()) { | |||||
| return state; | |||||
| } | |||||
| try { | |||||
| BufferedOutputStream bos = new BufferedOutputStream( | |||||
| new FileOutputStream(file)); | |||||
| bos.write(data); | |||||
| bos.flush(); | |||||
| bos.close(); | |||||
| } catch (IOException ioe) { | |||||
| return new BaseState(false, AppInfo.IO_ERROR); | |||||
| } | |||||
| state = new BaseState(true, file.getAbsolutePath()); | |||||
| state.putInfo("size", data.length); | |||||
| state.putInfo("title", file.getName()); | |||||
| return state; | |||||
| } | |||||
| public static State saveFileByInputStream(InputStream is, String path, long maxSize) { | |||||
| State state = null; | |||||
| File tmpFile = getTmpFile(); | |||||
| byte[] dataBuf = new byte[2048]; | |||||
| BufferedInputStream bis = new BufferedInputStream(is, StorageManager.BUFFER_SIZE); | |||||
| try { | |||||
| BufferedOutputStream bos = new BufferedOutputStream( | |||||
| new FileOutputStream(tmpFile), StorageManager.BUFFER_SIZE); | |||||
| int count = 0; | |||||
| while ((count = bis.read(dataBuf)) != -1) { | |||||
| bos.write(dataBuf, 0, count); | |||||
| } | |||||
| bos.flush(); | |||||
| bos.close(); | |||||
| if (tmpFile.length() > maxSize) { | |||||
| tmpFile.delete(); | |||||
| return new BaseState(false, AppInfo.MAX_SIZE); | |||||
| } | |||||
| state = saveTmpFile(tmpFile, path); | |||||
| if (!state.isSuccess()) { | |||||
| tmpFile.delete(); | |||||
| } | |||||
| return state; | |||||
| } catch (IOException e) { | |||||
| } | |||||
| return new BaseState(false, AppInfo.IO_ERROR); | |||||
| } | |||||
| public static State saveFileByInputStream(InputStream is, String path) { | |||||
| State state = null; | |||||
| File tmpFile = getTmpFile(); | |||||
| byte[] dataBuf = new byte[2048]; | |||||
| BufferedInputStream bis = new BufferedInputStream(is, StorageManager.BUFFER_SIZE); | |||||
| try { | |||||
| BufferedOutputStream bos = new BufferedOutputStream( | |||||
| new FileOutputStream(tmpFile), StorageManager.BUFFER_SIZE); | |||||
| int count = 0; | |||||
| while ((count = bis.read(dataBuf)) != -1) { | |||||
| bos.write(dataBuf, 0, count); | |||||
| } | |||||
| bos.flush(); | |||||
| bos.close(); | |||||
| state = saveTmpFile(tmpFile, path); | |||||
| if (!state.isSuccess()) { | |||||
| tmpFile.delete(); | |||||
| } | |||||
| return state; | |||||
| } catch (IOException e) { | |||||
| } | |||||
| return new BaseState(false, AppInfo.IO_ERROR); | |||||
| } | |||||
| private static File getTmpFile() { | |||||
| File tmpDir = FileUtils.getTempDirectory(); | |||||
| String tmpFileName = (Math.random() * 10000 + "").replace(".", ""); | |||||
| return new File(tmpDir, tmpFileName); | |||||
| } | |||||
| private static State saveTmpFile(File tmpFile, String path) { | |||||
| State state = null; | |||||
| File targetFile = new File(path); | |||||
| if (targetFile.canWrite()) { | |||||
| return new BaseState(false, AppInfo.PERMISSION_DENIED); | |||||
| } | |||||
| try { | |||||
| FileUtils.moveFile(tmpFile, targetFile); | |||||
| } catch (IOException e) { | |||||
| return new BaseState(false, AppInfo.IO_ERROR); | |||||
| } | |||||
| state = new BaseState(true); | |||||
| state.putInfo("size", targetFile.length()); | |||||
| state.putInfo("title", targetFile.getName()); | |||||
| return state; | |||||
| } | |||||
| private static State valid(File file) { | |||||
| File parentPath = file.getParentFile(); | |||||
| if ((!parentPath.exists()) && (!parentPath.mkdirs())) { | |||||
| return new BaseState(false, AppInfo.FAILED_CREATE_FILE); | |||||
| } | |||||
| if (!parentPath.canWrite()) { | |||||
| return new BaseState(false, AppInfo.PERMISSION_DENIED); | |||||
| } | |||||
| return new BaseState(true); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,121 @@ | |||||
| package com.iformall.ueditor.upload; | |||||
| import com.alibaba.fastjson.JSON; | |||||
| import com.alibaba.fastjson.JSONObject; | |||||
| import com.amazonaws.AmazonClientException; | |||||
| import com.amazonaws.AmazonServiceException; | |||||
| import com.amazonaws.auth.AWSCredentials; | |||||
| import com.amazonaws.auth.AWSCredentialsProvider; | |||||
| import com.amazonaws.auth.BasicAWSCredentials; | |||||
| import com.amazonaws.services.s3.AmazonS3; | |||||
| import com.amazonaws.services.s3.AmazonS3ClientBuilder; | |||||
| import com.amazonaws.services.s3.model.CannedAccessControlList; | |||||
| import com.amazonaws.services.s3.model.ObjectMetadata; | |||||
| import com.amazonaws.services.s3.model.PutObjectRequest; | |||||
| import com.iformall.shiro.UserSession; | |||||
| import com.iformall.ueditor.define.BaseState; | |||||
| import com.iformall.ueditor.define.State; | |||||
| import com.iformall.utils.AwsClient; | |||||
| import org.apache.shiro.SecurityUtils; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.web.multipart.MultipartFile; | |||||
| import org.springframework.web.multipart.MultipartHttpServletRequest; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import java.io.IOException; | |||||
| import java.net.URL; | |||||
| import java.util.Map; | |||||
| import java.util.UUID; | |||||
| public class Uploader { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| private HttpServletRequest request = null; | |||||
| private Map<String, Object> conf = null; | |||||
| private AmazonS3 s3 = null; | |||||
| public Uploader(HttpServletRequest request, Map<String, Object> conf) { | |||||
| this.request = request; | |||||
| this.conf = conf; | |||||
| this.s3 = AmazonS3ClientBuilder.standard() | |||||
| .withRegion(conf.get("clientRegion").toString()) | |||||
| .withCredentials(new AWSCredentialsProvider() { | |||||
| @Override | |||||
| public AWSCredentials getCredentials() { | |||||
| return new BasicAWSCredentials(conf.get("access").toString(), conf.get("secret").toString()); | |||||
| } | |||||
| @Override | |||||
| public void refresh() { | |||||
| } | |||||
| }) | |||||
| .build(); | |||||
| } | |||||
| public final State doExec() { | |||||
| String filedName = (String) this.conf.get("fieldName"); | |||||
| State state = null; | |||||
| if ("true".equals(this.conf.get("isBase64"))) { | |||||
| state = Base64Uploader.save(this.request.getParameter(filedName), | |||||
| this.conf); | |||||
| } else { | |||||
| MultipartFile multiReq= ((MultipartHttpServletRequest) this.request).getFile("upfile"); | |||||
| String tenantId = (String)SecurityUtils.getSubject().getSession().getAttribute(UserSession.tenantId); | |||||
| String fileName = UUID.randomUUID().toString(); | |||||
| int dot = multiReq.getOriginalFilename().lastIndexOf('.'); | |||||
| if (dot >= 0) { | |||||
| fileName = tenantId + "/" + fileName + multiReq.getOriginalFilename().substring(dot, multiReq.getOriginalFilename().length()); | |||||
| } else { | |||||
| fileName = tenantId + "/" + fileName; | |||||
| } | |||||
| state = state = new BaseState(true); | |||||
| state.putInfo("size", multiReq.getSize()); | |||||
| state.putInfo("title", filedName); | |||||
| JSONObject stateJson = JSON.parseObject(state.toJSONString()); | |||||
| ObjectMetadata metadata = new ObjectMetadata(); | |||||
| metadata.setContentType(multiReq.getContentType()); | |||||
| metadata.setContentLength(multiReq.getSize()); | |||||
| try { | |||||
| s3.putObject( | |||||
| new PutObjectRequest(conf.get("bucketName").toString(), fileName, multiReq.getInputStream(), metadata) | |||||
| .withCannedAcl(CannedAccessControlList.PublicRead)); | |||||
| URL url = s3.getUrl(conf.get("bucketName").toString(), fileName); | |||||
| //logger.info(url.toString()); | |||||
| state.putInfo("url", url.toString()); | |||||
| } catch (AmazonServiceException ase) { | |||||
| /* | |||||
| logger.warn("Caught an AmazonServiceException, which " + | |||||
| "means your request made it " + | |||||
| "to Amazon S3, but was rejected with an error response" + | |||||
| " for some reason."); | |||||
| logger.warn(ase.getMessage()); | |||||
| */ | |||||
| ase.printStackTrace(); | |||||
| } catch (AmazonClientException ace) { | |||||
| /* | |||||
| logger.warn("Caught an AmazonClientException, which " + | |||||
| "means the client encountered " + | |||||
| "an internal error while trying to " + | |||||
| "communicate with S3, " + | |||||
| "such as not being able to access the network."); | |||||
| logger.warn("Error Message: " + ace.getMessage()); | |||||
| */ | |||||
| ace.printStackTrace(); | |||||
| } catch (IOException ioe) { | |||||
| //logger.warn("Caught an IOException: " + ioe.getMessage()); | |||||
| ioe.printStackTrace(); | |||||
| } | |||||
| } | |||||
| return state; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,41 @@ | |||||
| package com.iformall.utils; | |||||
| import com.amazonaws.auth.AWSCredentials; | |||||
| import com.amazonaws.auth.AWSCredentialsProvider; | |||||
| import com.amazonaws.auth.BasicAWSCredentials; | |||||
| import com.amazonaws.services.s3.AmazonS3; | |||||
| import com.amazonaws.services.s3.AmazonS3ClientBuilder; | |||||
| import com.iformall.config.AwsProperty; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| public class AwsClient { | |||||
| @Autowired | |||||
| private static AwsProperty awsProperty; | |||||
| private static AmazonS3 s3 = null; | |||||
| private AwsClient() { | |||||
| } | |||||
| public static AmazonS3 getInstance() { | |||||
| if(s3 == null) { | |||||
| s3 = AmazonS3ClientBuilder.standard() | |||||
| .withRegion(awsProperty.getClientRegion()) | |||||
| .withCredentials(new AWSCredentialsProvider() { | |||||
| @Override | |||||
| public AWSCredentials getCredentials() { | |||||
| return new BasicAWSCredentials(awsProperty.getAccess(), awsProperty.getSecret()); | |||||
| } | |||||
| @Override | |||||
| public void refresh() { | |||||
| } | |||||
| }) | |||||
| .build(); | |||||
| } | |||||
| return s3; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,37 @@ | |||||
| package com.iformall.utils; | |||||
| import com.google.zxing.BarcodeFormat; | |||||
| import com.google.zxing.EncodeHintType; | |||||
| import com.google.zxing.MultiFormatWriter; | |||||
| import com.google.zxing.WriterException; | |||||
| import com.google.zxing.common.BitMatrix; | |||||
| import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; | |||||
| import java.awt.image.BufferedImage; | |||||
| import java.util.Hashtable; | |||||
| import java.util.Map; | |||||
| public class PayUtil { | |||||
| /** | |||||
| * 根据url生成二位图片对象 | |||||
| * | |||||
| * @param codeUrl | |||||
| * @return | |||||
| * @throws WriterException | |||||
| */ | |||||
| public static BufferedImage getQRCodeImge(String codeUrl) throws WriterException { | |||||
| Map<EncodeHintType, Object> hints = new Hashtable(); | |||||
| hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M); | |||||
| hints.put(EncodeHintType.CHARACTER_SET, "UTF8"); | |||||
| int width = 256; | |||||
| BitMatrix bitMatrix = (new MultiFormatWriter()).encode(codeUrl, BarcodeFormat.QR_CODE, width, width, hints); | |||||
| BufferedImage image = new BufferedImage(width, width, 1); | |||||
| for(int x = 0; x < width; ++x) { | |||||
| for(int y = 0; y < width; ++y) { | |||||
| image.setRGB(x, y, bitMatrix.get(x, y) ? -16777216 : -1); | |||||
| } | |||||
| } | |||||
| return image; | |||||
| } | |||||
| } | |||||
| @@ -1,7 +1,7 @@ | |||||
| spring: | spring: | ||||
| # JDBC | # JDBC | ||||
| datasource: | datasource: | ||||
| url: jdbc:mysql://202.165.179.86:3306/mallink?characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useUnicode=true&useSSL=false | |||||
| url: jdbc:mysql://202.165.179.86:3306/mallinkDev?characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useUnicode=true&useSSL=false | |||||
| username: ENC(dZ8fmrtuBMQYaRytKQgTqg==) | username: ENC(dZ8fmrtuBMQYaRytKQgTqg==) | ||||
| password: ENC(OZXsE6/Tj+V1Yu2wdjnIGbNOaBVQzi9W) | password: ENC(OZXsE6/Tj+V1Yu2wdjnIGbNOaBVQzi9W) | ||||
| type: com.alibaba.druid.pool.DruidDataSource | type: com.alibaba.druid.pool.DruidDataSource | ||||
| @@ -42,6 +42,12 @@ spring: | |||||
| fm: | fm: | ||||
| exception: false | exception: false | ||||
| ueditor: | |||||
| config: config.json | |||||
| unified: true | |||||
| upload-path: ./upload/ | |||||
| url-prefix: "" | |||||
| logging: | logging: | ||||
| level: | level: | ||||
| tk.mybatis: debug | tk.mybatis: debug | ||||
| @@ -39,6 +39,12 @@ spring: | |||||
| fm: | fm: | ||||
| exception: true | exception: true | ||||
| ueditor: | |||||
| config: config.json | |||||
| unified: true | |||||
| upload-path: ./upload/ | |||||
| url-prefix: "" | |||||
| logging: | logging: | ||||
| level: | level: | ||||
| tk.mybatis: debug | tk.mybatis: debug | ||||
| @@ -39,6 +39,12 @@ spring: | |||||
| fm: | fm: | ||||
| exception: true | exception: true | ||||
| ueditor: | |||||
| config: config.json | |||||
| unified: true | |||||
| upload-path: ./upload/ | |||||
| url-prefix: "" | |||||
| logging: | logging: | ||||
| level: | level: | ||||
| tk.mybatis: debug | tk.mybatis: debug | ||||
| @@ -0,0 +1,94 @@ | |||||
| /* 前后端通信相关的配置,注释只允许使用多行方式 */ | |||||
| { | |||||
| /* 上传图片配置项 */ | |||||
| "imageActionName": "uploadimage", /* 执行上传图片的action名称 */ | |||||
| "imageFieldName": "upfile", /* 提交的图片表单名称 */ | |||||
| "imageMaxSize": 2048000, /* 上传大小限制,单位B */ | |||||
| "imageAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 上传图片格式显示 */ | |||||
| "imageCompressEnable": true, /* 是否压缩图片,默认是true */ | |||||
| "imageCompressBorder": 1600, /* 图片压缩最长边限制 */ | |||||
| "imageInsertAlign": "none", /* 插入的图片浮动方式 */ | |||||
| "imageUrlPrefix": "", /* 图片访问路径前缀 */ | |||||
| "imagePathFormat": "/ueditor/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */ | |||||
| /* {filename} 会替换成原文件名,配置这项需要注意中文乱码问题 */ | |||||
| /* {rand:6} 会替换成随机数,后面的数字是随机数的位数 */ | |||||
| /* {time} 会替换成时间戳 */ | |||||
| /* {yyyy} 会替换成四位年份 */ | |||||
| /* {yy} 会替换成两位年份 */ | |||||
| /* {mm} 会替换成两位月份 */ | |||||
| /* {dd} 会替换成两位日期 */ | |||||
| /* {hh} 会替换成两位小时 */ | |||||
| /* {ii} 会替换成两位分钟 */ | |||||
| /* {ss} 会替换成两位秒 */ | |||||
| /* 非法字符 \ : * ? " < > | */ | |||||
| /* 具请体看线上文档: fex.baidu.com/ueditor/#use-format_upload_filename */ | |||||
| /* 涂鸦图片上传配置项 */ | |||||
| "scrawlActionName": "uploadscrawl", /* 执行上传涂鸦的action名称 */ | |||||
| "scrawlFieldName": "upfile", /* 提交的图片表单名称 */ | |||||
| "scrawlPathFormat": "/ueditor/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */ | |||||
| "scrawlMaxSize": 2048000, /* 上传大小限制,单位B */ | |||||
| "scrawlUrlPrefix": "", /* 图片访问路径前缀 */ | |||||
| "scrawlInsertAlign": "none", | |||||
| /* 截图工具上传 */ | |||||
| "snapscreenActionName": "uploadimage", /* 执行上传截图的action名称 */ | |||||
| "snapscreenPathFormat": "/ueditor/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */ | |||||
| "snapscreenUrlPrefix": "", /* 图片访问路径前缀 */ | |||||
| "snapscreenInsertAlign": "none", /* 插入的图片浮动方式 */ | |||||
| /* 抓取远程图片配置 */ | |||||
| "catcherLocalDomain": ["127.0.0.1", "localhost", "img.baidu.com"], | |||||
| "catcherActionName": "catchimage", /* 执行抓取远程图片的action名称 */ | |||||
| "catcherFieldName": "source", /* 提交的图片列表表单名称 */ | |||||
| "catcherPathFormat": "/ueditor/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */ | |||||
| "catcherUrlPrefix": "", /* 图片访问路径前缀 */ | |||||
| "catcherMaxSize": 2048000, /* 上传大小限制,单位B */ | |||||
| "catcherAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 抓取图片格式显示 */ | |||||
| /* 上传视频配置 */ | |||||
| "videoActionName": "uploadvideo", /* 执行上传视频的action名称 */ | |||||
| "videoFieldName": "upfile", /* 提交的视频表单名称 */ | |||||
| "videoPathFormat": "/ueditor/video/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */ | |||||
| "videoUrlPrefix": "", /* 视频访问路径前缀 */ | |||||
| "videoMaxSize": 102400000, /* 上传大小限制,单位B,默认100MB */ | |||||
| "videoAllowFiles": [ | |||||
| ".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg", | |||||
| ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid"], /* 上传视频格式显示 */ | |||||
| /* 上传文件配置 */ | |||||
| "fileActionName": "uploadfile", /* controller里,执行上传视频的action名称 */ | |||||
| "fileFieldName": "upfile", /* 提交的文件表单名称 */ | |||||
| "filePathFormat": "/ueditor/file/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */ | |||||
| "fileUrlPrefix": "", /* 文件访问路径前缀 */ | |||||
| "fileMaxSize": 51200000, /* 上传大小限制,单位B,默认50MB */ | |||||
| "fileAllowFiles": [ | |||||
| ".png", ".jpg", ".jpeg", ".gif", ".bmp", | |||||
| ".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg", | |||||
| ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid", | |||||
| ".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso", | |||||
| ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml" | |||||
| ], /* 上传文件格式显示 */ | |||||
| /* 列出指定目录下的图片 */ | |||||
| "imageManagerActionName": "listimage", /* 执行图片管理的action名称 */ | |||||
| "imageManagerListPath": "/ueditor/image/", /* 指定要列出图片的目录 */ | |||||
| "imageManagerListSize": 20, /* 每次列出文件数量 */ | |||||
| "imageManagerUrlPrefix": "", /* 图片访问路径前缀 */ | |||||
| "imageManagerInsertAlign": "none", /* 插入的图片浮动方式 */ | |||||
| "imageManagerAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 列出的文件类型 */ | |||||
| /* 列出指定目录下的文件 */ | |||||
| "fileManagerActionName": "listfile", /* 执行文件管理的action名称 */ | |||||
| "fileManagerListPath": "/ueditor/file/", /* 指定要列出文件的目录 */ | |||||
| "fileManagerUrlPrefix": "", /* 文件访问路径前缀 */ | |||||
| "fileManagerListSize": 20, /* 每次列出文件数量 */ | |||||
| "fileManagerAllowFiles": [ | |||||
| ".png", ".jpg", ".jpeg", ".gif", ".bmp", | |||||
| ".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg", | |||||
| ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid", | |||||
| ".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso", | |||||
| ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml" | |||||
| ] /* 列出的文件类型 */ | |||||
| } | |||||
| @@ -7,8 +7,12 @@ import com.fasterxml.jackson.databind.ObjectMapper; | |||||
| import com.fasterxml.jackson.databind.module.SimpleModule; | import com.fasterxml.jackson.databind.module.SimpleModule; | ||||
| import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | ||||
| import com.iformall.interceptor.AuthorizationInterceptor; | import com.iformall.interceptor.AuthorizationInterceptor; | ||||
| import com.iformall.interceptor.HttpServletRequestWrapperFilter; | |||||
| import com.iformall.interceptor.RequestInterceptor; | |||||
| import com.iformall.resolver.LoginUserHandlerMethodArgumentResolver; | import com.iformall.resolver.LoginUserHandlerMethodArgumentResolver; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.boot.web.servlet.FilterRegistrationBean; | |||||
| import org.springframework.context.annotation.Bean; | |||||
| import org.springframework.context.annotation.Configuration; | import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.http.converter.HttpMessageConverter; | import org.springframework.http.converter.HttpMessageConverter; | ||||
| import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | ||||
| @@ -33,11 +37,14 @@ public class WebMvcConfig implements WebMvcConfigurer { | |||||
| @Autowired | @Autowired | ||||
| private AuthorizationInterceptor authorizationInterceptor; | private AuthorizationInterceptor authorizationInterceptor; | ||||
| @Autowired | @Autowired | ||||
| private RequestInterceptor requestInterceptor; | |||||
| @Autowired | |||||
| private LoginUserHandlerMethodArgumentResolver loginUserHandlerMethodArgumentResolver; | private LoginUserHandlerMethodArgumentResolver loginUserHandlerMethodArgumentResolver; | ||||
| @Override | @Override | ||||
| public void addInterceptors(InterceptorRegistry registry) { | public void addInterceptors(InterceptorRegistry registry) { | ||||
| registry.addInterceptor(authorizationInterceptor).addPathPatterns("/api/**"); | registry.addInterceptor(authorizationInterceptor).addPathPatterns("/api/**"); | ||||
| registry.addInterceptor(requestInterceptor).addPathPatterns("/api/**"); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -95,4 +102,13 @@ public class WebMvcConfig implements WebMvcConfigurer { | |||||
| jackson2HttpMessageConverter.setObjectMapper(objectMapper); | jackson2HttpMessageConverter.setObjectMapper(objectMapper); | ||||
| converters.add(jackson2HttpMessageConverter); | converters.add(jackson2HttpMessageConverter); | ||||
| } | } | ||||
| @Bean | |||||
| public FilterRegistrationBean<HttpServletRequestWrapperFilter> Filters() { | |||||
| FilterRegistrationBean<HttpServletRequestWrapperFilter> registrationBean = new FilterRegistrationBean<HttpServletRequestWrapperFilter>(); | |||||
| registrationBean.setFilter(new HttpServletRequestWrapperFilter()); | |||||
| registrationBean.addUrlPatterns("/*"); | |||||
| registrationBean.setName("koalaSignFilter"); | |||||
| return registrationBean; | |||||
| } | |||||
| } | } | ||||
| @@ -13,6 +13,7 @@ import com.iformall.exception.MallinkException; | |||||
| import com.iformall.interceptor.AuthorizationInterceptor; | import com.iformall.interceptor.AuthorizationInterceptor; | ||||
| import com.iformall.service.WxAppinfoService; | import com.iformall.service.WxAppinfoService; | ||||
| import com.iformall.service.WxMerchantBUserService; | import com.iformall.service.WxMerchantBUserService; | ||||
| import com.iformall.utils.IPUtil; | |||||
| import com.iformall.utils.MaUtil; | import com.iformall.utils.MaUtil; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.web.bind.WebDataBinder; | import org.springframework.web.bind.WebDataBinder; | ||||
| @@ -87,4 +88,10 @@ public class BaseController { | |||||
| WxMaService service = MaUtil.getWeappService(appinfo); | WxMaService service = MaUtil.getWeappService(appinfo); | ||||
| return service; | return service; | ||||
| } | } | ||||
| public String getIpAddr() { | |||||
| HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | |||||
| String ipaddress = IPUtil.getIpAddr(request); | |||||
| return ipaddress; | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,229 @@ | |||||
| package com.iformall.controller; | |||||
| import com.alibaba.fastjson.JSONObject; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.IdWorker; | |||||
| import com.iformall.common.Result; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.dto.WxCUserFromBDto; | |||||
| import com.iformall.domain.po.WxCUser; | |||||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||||
| import com.iformall.domain.po.WxCUserFromB; | |||||
| import com.iformall.domain.po.WxMerchantBUser; | |||||
| import com.iformall.enums.EnumAssignTagsTrigger; | |||||
| import com.iformall.enums.EnumScoreType; | |||||
| import com.iformall.service.*; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import java.util.Date; | |||||
| import java.util.List; | |||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| @RestController | |||||
| @RequestMapping("/api/cuser") | |||||
| @Api(description = "B端来源会员") | |||||
| public class WxCUserController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private WxCUserBasicInfoService wxCUserBasicInfoService; | |||||
| @Autowired | |||||
| private WxScoreRulesService wxScoreRulesService; | |||||
| @Autowired | |||||
| private WxCUserTagsService wxCUserTagsService; | |||||
| @Autowired | |||||
| private WxMerchantBUserService wxMerchantBUserService; | |||||
| @Autowired | |||||
| private WxCUserFromBService wxCUserFromBService; | |||||
| @Autowired | |||||
| private WxCUserService wxCUserService; | |||||
| /** | |||||
| * 会员更新信息 | |||||
| * | |||||
| * @return | |||||
| */ | |||||
| @PostMapping("/updateUserInfo") | |||||
| @ApiOperation(value = "用户更新信息", notes = "") | |||||
| public ResultData updateUserInfo(@RequestBody WxCUserFromBDto wxCUserFromBDto) { | |||||
| logger.info("WxCUserController::updateUserInfo"); | |||||
| if (wxCUserFromBDto == null) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL, "没有传入用户信息"); | |||||
| } | |||||
| if (StringUtils.isEmpty(wxCUserFromBDto.getOpenid())) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL, "C端openid不能为空"); | |||||
| } | |||||
| if (StringUtils.isEmpty(wxCUserFromBDto.getAppId())) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL, "C端appId不能为空"); | |||||
| } | |||||
| if (wxCUserFromBDto.getbUserId() == null) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL, "bUserId不能为空"); | |||||
| } | |||||
| //根据bUserId查询B端用户是否存在 | |||||
| WxMerchantBUser bUser = wxMerchantBUserService.getById(wxCUserFromBDto.getbUserId()); | |||||
| if (bUser == null) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL, "B端用户不存在"); | |||||
| } | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| WxCUserFromB wxCUserFromB = wxCUserFromBService.getByOpenidAndAppId(wxCUserFromBDto); | |||||
| //查询C端微信信息 | |||||
| WxCUser wxCUser = new WxCUser(); | |||||
| wxCUser.setAppId(wxCUserFromBDto.getAppId()); | |||||
| wxCUser.setOpenId(wxCUserFromBDto.getOpenid()); | |||||
| wxCUser = wxCUserService.getByOpenId(wxCUser); | |||||
| if (wxCUserFromB == null) { | |||||
| String phone = wxCUser.getPhone(); | |||||
| String tenantId = wxCUser.getTenantId(); | |||||
| //查询会员信息 | |||||
| List<WxCUserBasicInfo> byPhone = wxCUserBasicInfoService.findByPhone(tenantId, phone); | |||||
| //存在会员信息 | |||||
| if (!byPhone.isEmpty()) { | |||||
| //更新会员信息 | |||||
| WxCUserBasicInfo wxCUserBasicInfo = byPhone.get(0); | |||||
| if (!StringUtils.isEmpty(wxCUserFromBDto.getName())) { | |||||
| wxCUserBasicInfo.setName(wxCUserFromBDto.getName()); | |||||
| } | |||||
| if (wxCUserFromBDto != null) { | |||||
| wxCUserBasicInfo.setBirthdate(wxCUserFromBDto.getBirthdate()); | |||||
| } | |||||
| if (wxCUserFromBDto.getSex() != null) { | |||||
| wxCUserBasicInfo.setSex(wxCUserFromBDto.getSex()); | |||||
| } | |||||
| if (!StringUtils.isEmpty(wxCUserFromBDto.getAddress())) { | |||||
| wxCUserBasicInfo.setAddress(wxCUserFromBDto.getAddress()); | |||||
| } | |||||
| wxCUserBasicInfo.setPhone(wxCUser.getPhone()); | |||||
| wxCUserBasicInfo.setUpdateDate(new Date()); | |||||
| wxCUserBasicInfoService.update(wxCUserBasicInfo); | |||||
| wxScoreRulesService.addScore(EnumScoreType.COMPLETE_INFO, wxCUserBasicInfo); | |||||
| wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_IMPORT, wxCUserBasicInfo); | |||||
| //新增来自B端的会员关联数据 | |||||
| wxCUserFromB = new WxCUserFromB(); | |||||
| wxCUserFromB.setbUserId(wxCUserFromBDto.getbUserId()); | |||||
| wxCUserFromB.setcUserId(wxCUserBasicInfo.getId()); | |||||
| wxCUserFromB.setOpenid(wxCUserFromBDto.getOpenid()); | |||||
| wxCUserFromB.setMerchantId(bUser.getMerchantId()); | |||||
| wxCUserFromB.setTenantId(bUser.getTenantId()); | |||||
| wxCUserFromB.setAppId(wxCUserFromBDto.getAppId()); | |||||
| wxCUserFromB.setInfo(JSONObject.toJSONString(wxCUserBasicInfo)); | |||||
| wxCUserFromBService.saveOrUpdate(wxCUserFromB); | |||||
| } else { | |||||
| //新增来自B端的会员 | |||||
| long cUserId = idWorker.nextId(); | |||||
| WxCUserBasicInfo wxCUserBasicInfo = new WxCUserBasicInfo(); | |||||
| wxCUserBasicInfo.setId(cUserId); | |||||
| if (!StringUtils.isEmpty(wxCUserFromBDto.getName())) { | |||||
| wxCUserBasicInfo.setName(wxCUserFromBDto.getName()); | |||||
| } | |||||
| if (wxCUserFromBDto != null) { | |||||
| wxCUserBasicInfo.setBirthdate(wxCUserFromBDto.getBirthdate()); | |||||
| } | |||||
| if (wxCUserFromBDto.getSex() != null) { | |||||
| wxCUserBasicInfo.setSex(wxCUserFromBDto.getSex()); | |||||
| } | |||||
| if (!StringUtils.isEmpty(wxCUserFromBDto.getAddress())) { | |||||
| wxCUserBasicInfo.setAddress(wxCUserFromBDto.getAddress()); | |||||
| } | |||||
| wxCUserBasicInfo.setPhone(wxCUser.getPhone()); | |||||
| wxCUserBasicInfo.setUpdateDate(new Date()); | |||||
| wxCUserBasicInfoService.save(wxCUserBasicInfo); | |||||
| //新增来自B端的会员关联数据 | |||||
| wxCUserFromB = new WxCUserFromB(); | |||||
| wxCUserFromB.setbUserId(wxCUserFromBDto.getbUserId()); | |||||
| wxCUserFromB.setcUserId(cUserId); | |||||
| wxCUserFromB.setOpenid(wxCUserFromBDto.getOpenid()); | |||||
| wxCUserFromB.setMerchantId(bUser.getMerchantId()); | |||||
| wxCUserFromB.setTenantId(bUser.getTenantId()); | |||||
| wxCUserFromB.setAppId(wxCUserFromBDto.getAppId()); | |||||
| wxCUserFromB.setInfo(JSONObject.toJSONString(wxCUserBasicInfo)); | |||||
| wxCUserFromBService.saveOrUpdate(wxCUserFromB); | |||||
| } | |||||
| } else { | |||||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(wxCUserFromB.getcUserId()); | |||||
| if (!StringUtils.isEmpty(wxCUserFromBDto.getName())) { | |||||
| wxCUserBasicInfo.setName(wxCUserFromBDto.getName()); | |||||
| } | |||||
| if (wxCUserFromBDto != null) { | |||||
| wxCUserBasicInfo.setBirthdate(wxCUserFromBDto.getBirthdate()); | |||||
| } | |||||
| if (wxCUserFromBDto.getSex() != null) { | |||||
| wxCUserBasicInfo.setSex(wxCUserFromBDto.getSex()); | |||||
| } | |||||
| if (!StringUtils.isEmpty(wxCUserFromBDto.getAddress())) { | |||||
| wxCUserBasicInfo.setAddress(wxCUserFromBDto.getAddress()); | |||||
| } | |||||
| wxCUserBasicInfo.setPhone(wxCUser.getPhone()); | |||||
| wxCUserBasicInfoService.update(wxCUserBasicInfo); | |||||
| wxScoreRulesService.addScore(EnumScoreType.COMPLETE_INFO, wxCUserBasicInfo); | |||||
| wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_IMPORT, wxCUserBasicInfo); | |||||
| //更新B端来源会员 | |||||
| wxCUserFromB.setInfo(JSONObject.toJSONString(wxCUserBasicInfo)); | |||||
| wxCUserFromBService.saveOrUpdate(wxCUserFromB); | |||||
| } | |||||
| return new ResultData(); | |||||
| } | |||||
| /** | |||||
| * 会员信息 | |||||
| * | |||||
| * @return | |||||
| */ | |||||
| @PostMapping("/findUserInfo") | |||||
| @ApiOperation(value = "获取会员信息", notes = "") | |||||
| public ResultData findUserInfo(@RequestBody WxCUserFromBDto wxCUserFromBDto) { | |||||
| logger.info("WxCUserController::findUserInfo"); | |||||
| if (wxCUserFromBDto == null) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL, "没有传入用户信息"); | |||||
| } | |||||
| if (StringUtils.isEmpty(wxCUserFromBDto.getOpenid())) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL, "C端openid不能为空"); | |||||
| } | |||||
| if (StringUtils.isEmpty(wxCUserFromBDto.getAppId())) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL, "C端appid不能为空"); | |||||
| } | |||||
| if (wxCUserFromBDto.getbUserId() == null) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL, "bUserId不能为空"); | |||||
| } | |||||
| WxCUserFromB wxCUserFromB = wxCUserFromBService.getByOpenidAndAppId(wxCUserFromBDto); | |||||
| if(wxCUserFromB!=null){ | |||||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(wxCUserFromB.getcUserId()); | |||||
| return new ResultData(wxCUserBasicInfo); | |||||
| } | |||||
| return new ResultData(Result.SUCCESS,"查询成功",null); | |||||
| } | |||||
| @ApiOperation("分页列表接口") | |||||
| @GetMapping("listCUser") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| public ResultData listCUser(@ModelAttribute WxCUserFromBDto wxCUserFromBDto, Integer pageNum, Integer pageSize) { | |||||
| logger.debug("[" + getIpAddr() + "] WxCUserController::listCUser"); | |||||
| if (wxCUserFromBDto == null) { | |||||
| wxCUserFromBDto = new WxCUserFromBDto(); | |||||
| } | |||||
| PageInfo<WxCUserFromB> wxCUserFromBPageInfo = wxCUserFromBService.listCUser(wxCUserFromBDto, pageNum, pageSize); | |||||
| return new ResultData(wxCUserFromBPageInfo); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,68 @@ | |||||
| package com.iformall.controller; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.*; | |||||
| import com.iformall.domain.vo.WxCardSpendVo; | |||||
| import com.iformall.service.WxCardSpendService; | |||||
| import com.iformall.service.WxMerchantService; | |||||
| import com.iformall.service.WxOrderService; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import java.util.Map; | |||||
| /** | |||||
| * @author Stormeye Wu wuguoqiang@iformall.com | |||||
| */ | |||||
| @RestController | |||||
| @Api(description = "C端扫B端商户码储值卡支付") | |||||
| @RequestMapping("/api/cardPay") | |||||
| public class WxCardPayController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| WxMerchantService wxMerchantService; | |||||
| @Autowired | |||||
| WxOrderService wxOrderService; | |||||
| @Autowired | |||||
| WxCardSpendService wxCardSpendService; | |||||
| @ApiOperation("C端扫B端储值卡交易流水(消费记录 + 补贴)列表接口") | |||||
| @GetMapping("list") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| public ResultData cardSpendlist(@ModelAttribute WxCardSpendVo wxCardSpendVo, Integer pageNum, Integer pageSize) { | |||||
| String ipStr = getIpAddr(); | |||||
| logger.info("cardSpendlist: " + ipStr + " :" + wxCardSpendVo.toString()); | |||||
| if (wxCardSpendVo == null) wxCardSpendVo = new WxCardSpendVo(); | |||||
| WxMerchantBUser user = getUser(); | |||||
| wxCardSpendVo.setTenantId(user.getTenantId()); | |||||
| wxCardSpendVo.setMerchantId(user.getMerchantId()); | |||||
| final PageInfo<WxCardSpendVo> page = wxCardSpendService.listAsPage(wxCardSpendVo, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| @ApiOperation("C端扫B端储值卡交易流水SUM") | |||||
| @GetMapping("sum") | |||||
| public ResultData sumCardSpendList(@ModelAttribute WxCardSpendVo wxCardSpend) { | |||||
| String ipStr = getIpAddr(); | |||||
| logger.info("sumCardSpendList: " + ipStr + " :" + wxCardSpend.toString()); | |||||
| if (wxCardSpend == null) wxCardSpend = new WxCardSpendVo(); | |||||
| WxMerchantBUser user = getUser(); | |||||
| wxCardSpend.setTenantId(user.getTenantId()); | |||||
| wxCardSpend.setMerchantId(user.getMerchantId()); | |||||
| final Map map = wxCardSpendService.sumCardSpendForMerchant(wxCardSpend); | |||||
| return new ResultData(map); | |||||
| } | |||||
| } | |||||
| @@ -28,8 +28,6 @@ public class WxCouponOrderController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private WxCouponOrderService wxCouponOrderService; | private WxCouponOrderService wxCouponOrderService; | ||||
| @ApiOperation("分页列表接口") | @ApiOperation("分页列表接口") | ||||
| @GetMapping("list") | @GetMapping("list") | ||||
| @ApiImplicitParams({ | @ApiImplicitParams({ | ||||
| @@ -48,8 +46,6 @@ public class WxCouponOrderController extends BaseController { | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| @ApiOperation("交易流水分页列表接口") | @ApiOperation("交易流水分页列表接口") | ||||
| @GetMapping("listUnverified") | @GetMapping("listUnverified") | ||||
| @ApiImplicitParams({ | @ApiImplicitParams({ | ||||
| @@ -93,8 +89,7 @@ public class WxCouponOrderController extends BaseController { | |||||
| @ApiImplicitParams({ | @ApiImplicitParams({ | ||||
| @ApiImplicitParam(name = "couponOrderId", value = "券ID", dataType = "string", paramType = "query", required = true) | @ApiImplicitParam(name = "couponOrderId", value = "券ID", dataType = "string", paramType = "query", required = true) | ||||
| }) | }) | ||||
| public ResultData detail(String couponOrderId) { | |||||
| public ResultData detail(String couponOrderId) { | |||||
| if(couponOrderId == null) { | if(couponOrderId == null) { | ||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | ||||
| } | } | ||||
| @@ -128,28 +123,32 @@ public class WxCouponOrderController extends BaseController { | |||||
| logger.error("核销异常: " + e.getMessage()); | logger.error("核销异常: " + e.getMessage()); | ||||
| return new ResultData(ErrorCode.VERIFY_ERROR, e.getMessage()); | return new ResultData(ErrorCode.VERIFY_ERROR, e.getMessage()); | ||||
| } | } | ||||
| // 核销分账 | |||||
| if (couponOrder != null) { | if (couponOrder != null) { | ||||
| try { | try { | ||||
| wxCouponOrderService.shareAfterVerify(couponOrder); | |||||
| // 核销分账 | |||||
| wxCouponOrderService.shareAfterVerify(couponOrder, getUser().getMerchantId()); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| } | } | ||||
| } | |||||
| boolean bSentCoupon = false; | |||||
| try { | |||||
| // 核销补贴 | |||||
| wxCouponOrderService.subsidyAfterVerify(couponOrder, getUser().getMerchantId()); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| // 核销发券 | |||||
| if (couponOrder != null) { | |||||
| boolean bSentCoupon = false; | |||||
| // 核销发券 | |||||
| try { | try { | ||||
| bSentCoupon = wxCouponOrderService.sendCouponAfterVerify(couponOrder, getUser()); | bSentCoupon = wxCouponOrderService.sendCouponAfterVerify(couponOrder, getUser()); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| } | } | ||||
| } | |||||
| // 核销发模板消息 | |||||
| if (couponOrder != null) { | |||||
| // 核销发模板消息 | |||||
| try { | try { | ||||
| wxCouponOrderService.sendVerifyMsg(couponOrder, getUser(), bSentCoupon); | wxCouponOrderService.sendVerifyMsg(couponOrder, getUser(), bSentCoupon); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| @@ -60,7 +60,7 @@ public class WxDateAmountRecordController extends BaseController { | |||||
| temp.setTenantId(u.getTenantId()); | temp.setTenantId(u.getTenantId()); | ||||
| temp.setMerchantId(u.getMerchantId()); | temp.setMerchantId(u.getMerchantId()); | ||||
| temp.setType(dateAmtType); | temp.setType(dateAmtType); | ||||
| temp.setSortColumns(WxDateAmountRecord.Field.UpdateDate_DESC); | |||||
| temp.setSortColumns(WxDateAmountRecord.Field.Date_DESC); | |||||
| SimpleDateFormat fmt = new SimpleDateFormat("MM/dd"); | SimpleDateFormat fmt = new SimpleDateFormat("MM/dd"); | ||||
| @@ -0,0 +1,116 @@ | |||||
| package com.iformall.controller; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.*; | |||||
| import com.iformall.domain.vo.WxCUserVo; | |||||
| import com.iformall.service.WxCUserBasicInfoService; | |||||
| import com.iformall.service.WxCUserService; | |||||
| import com.iformall.service.WxLevelConfigService; | |||||
| import com.iformall.service.WxMerchantService; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| 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 java.util.List; | |||||
| import java.util.Map; | |||||
| /** | |||||
| * @author Stormeye | |||||
| */ | |||||
| @RestController | |||||
| @Api(description = "C端会员信息") | |||||
| @RequestMapping("/api/mem") | |||||
| public class WxMemController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private WxCUserService userService; | |||||
| @Autowired | |||||
| private WxLevelConfigService wxLevelConfigService; | |||||
| @Autowired | |||||
| private WxCUserBasicInfoService wxCUserBasicInfoService; | |||||
| @Autowired | |||||
| private WxMerchantService wxMerchantService; | |||||
| @ApiOperation(value = "扫C端会员码返回会员信息", notes = "params:{\"memCode\":\"String\"}\n") | |||||
| @PostMapping("mem_scan") | |||||
| public ResultData memScan(@RequestBody Map<String, String> paramMap) { | |||||
| logger.info("memScan" + getIpAddr() + ": " + paramMap.toString()); | |||||
| String memCode = paramMap.get("memCode"); | |||||
| if (StringUtils.isBlank(memCode)) { | |||||
| logger.error("memCode不能为空"); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "memCode不能为空"); | |||||
| } | |||||
| Long id = null; | |||||
| try { | |||||
| id = Long.valueOf(memCode); | |||||
| } catch (Exception e) { | |||||
| logger.error("memCode convert failed"); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "memCode转换失败"); | |||||
| } | |||||
| WxMerchantBUser bUser = getUser(); | |||||
| WxCUser cUser = userService.getById(id); | |||||
| if(cUser == null) { | |||||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
| } | |||||
| WxCUserVo userVo = new WxCUserVo(); | |||||
| org.springframework.beans.BeanUtils.copyProperties(cUser, userVo); | |||||
| if (userVo.getScore() == null || userVo.getScore() == 0) { | |||||
| userVo.setLevelName("无"); | |||||
| userVo.setDiscountRate(10000); // 无折扣 | |||||
| } else { | |||||
| userVo.setLevelName("无"); | |||||
| Integer levelConfigDiscount = null; | |||||
| List<WxLevelConfig> levelList = wxLevelConfigService.getByTenantId(bUser.getTenantId()); | |||||
| for(WxLevelConfig levelConfig: levelList) { | |||||
| if (userVo.getScore() >= levelConfig.getPoints()) { | |||||
| userVo.setLevelId(levelConfig.getId()); | |||||
| userVo.setLevelName(levelConfig.getLevel()); | |||||
| levelConfigDiscount = levelConfig.getDiscountEnable(); | |||||
| } | |||||
| } | |||||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(cUser.getId()); | |||||
| if (wxCUserBasicInfo != null) { | |||||
| userVo.setName(wxCUserBasicInfo.getName()); | |||||
| userVo.setBirthdate(wxCUserBasicInfo.getBirthdate()); | |||||
| userVo.setSex(wxCUserBasicInfo.getSex()); | |||||
| userVo.setAddress(wxCUserBasicInfo.getAddress()); | |||||
| } | |||||
| if(levelConfigDiscount > 0) { | |||||
| // 用户折扣率 | |||||
| WxMerchant wxMerchant = wxMerchantService.getById(bUser.getMerchantId()); | |||||
| if(wxMerchant != null) { | |||||
| if(levelConfigDiscount.equals(1)) { // first level | |||||
| userVo.setDiscountRate(wxMerchant.getVipDiscountRate1()); | |||||
| } else if(levelConfigDiscount.equals(2)) { // second level | |||||
| userVo.setDiscountRate(wxMerchant.getVipDiscountRate2()); | |||||
| } else if(levelConfigDiscount.equals(3)) { // third level | |||||
| userVo.setDiscountRate(wxMerchant.getVipDiscountRate3()); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| return new ResultData(userVo); | |||||
| } | |||||
| } | |||||
| @@ -4,15 +4,12 @@ package com.iformall.controller; | |||||
| import com.iformall.annotation.AuthIgnore; | import com.iformall.annotation.AuthIgnore; | ||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxMall; | |||||
| import com.iformall.domain.po.WxMerchant; | |||||
| import com.iformall.domain.po.WxMerchantBUser; | |||||
| import com.iformall.domain.po.*; | |||||
| import com.iformall.domain.vo.WxCUserVo; | |||||
| import com.iformall.enums.EnumMerchantBUserStatus; | import com.iformall.enums.EnumMerchantBUserStatus; | ||||
| import com.iformall.enums.EnumMerchantStatus; | import com.iformall.enums.EnumMerchantStatus; | ||||
| import com.iformall.interceptor.AuthorizationInterceptor; | import com.iformall.interceptor.AuthorizationInterceptor; | ||||
| import com.iformall.service.WxMallService; | |||||
| import com.iformall.service.WxMerchantBUserService; | |||||
| import com.iformall.service.WxMerchantService; | |||||
| import com.iformall.service.*; | |||||
| import com.iformall.utils.IPUtil; | import com.iformall.utils.IPUtil; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| @@ -27,6 +24,7 @@ import org.springframework.web.context.request.ServletRequestAttributes; | |||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||
| import java.util.Date; | import java.util.Date; | ||||
| import java.util.HashMap; | import java.util.HashMap; | ||||
| import java.util.List; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| @RestController | @RestController | ||||
| @@ -44,13 +42,22 @@ public class WxMerchantBUserController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private WxMallService wxMallService; | private WxMallService wxMallService; | ||||
| @Autowired | |||||
| private WxLevelConfigService wxLevelConfigService; | |||||
| @Autowired | |||||
| private WxCUserService wxCUserService; | |||||
| @Autowired | |||||
| private WxCUserBasicInfoService wxCUserBasicInfoService; | |||||
| @ApiOperation("查寻当bUser详情接口") | @ApiOperation("查寻当bUser详情接口") | ||||
| @GetMapping("/detail") | @GetMapping("/detail") | ||||
| public ResultData detail() { | public ResultData detail() { | ||||
| Map resultMap = new HashMap(); | Map resultMap = new HashMap(); | ||||
| WxMerchantBUser user = wxMerchantBUserService.getById(getUser().getId()); | |||||
| WxMerchantBUser user = getUser(); | |||||
| if (user == null){ | if (user == null){ | ||||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | return new ResultData(ErrorCode.USER_IS_EMPTY); | ||||
| @@ -78,6 +85,85 @@ public class WxMerchantBUserController extends BaseController { | |||||
| return new ResultData(resultMap); | return new ResultData(resultMap); | ||||
| } | } | ||||
| @GetMapping("/getUserInfo") | |||||
| @ApiOperation(value="获取用户等级及在此商户的折扣率及折扣后的金额", notes="{\"id\":\"string\", \"amount\":\"string\"}") | |||||
| public ResultData getDiscountRate(@RequestBody Map<String, String> map) { | |||||
| WxMerchantBUser bUser = getUser(); | |||||
| List<WxLevelConfig> levelList = wxLevelConfigService.getByTenantId(bUser.getTenantId()); | |||||
| String idStr = map.get("id"); | |||||
| String amountStr = map.get("amount"); | |||||
| if (StringUtils.isBlank(idStr)) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "id不能为空"); | |||||
| } | |||||
| if (StringUtils.isBlank(amountStr)) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "amount不能为空"); | |||||
| } | |||||
| Long id = Long.valueOf(idStr); | |||||
| Integer amount = Integer.valueOf(amountStr) * 100; // 元->分 | |||||
| WxCUserBasicInfo userInfo = null; | |||||
| WxCUser user = wxCUserService.getById(id); | |||||
| if(user == null) { | |||||
| userInfo = wxCUserBasicInfoService.getById(id); | |||||
| } | |||||
| if(user == null && userInfo == null) { | |||||
| logger.error("C端用户不存在"); | |||||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
| } | |||||
| WxCUserVo userVo = new WxCUserVo(); | |||||
| if(user != null) { | |||||
| org.springframework.beans.BeanUtils.copyProperties(user, userVo); | |||||
| } else if(userInfo != null) { | |||||
| userVo.setId(userInfo.getId()); | |||||
| userVo.setName(userInfo.getName()); | |||||
| userVo.setScore(userInfo.getPoins()); | |||||
| } | |||||
| WxLevelConfig curLConfig = null; | |||||
| int curDiscountRateIndex = 0; | |||||
| int curDiscountRate = 0; | |||||
| for(WxLevelConfig levelConfig: levelList) { | |||||
| if (userVo.getScore() >= levelConfig.getPoints()) { | |||||
| curLConfig = levelConfig; | |||||
| } | |||||
| } | |||||
| if (curLConfig != null) { | |||||
| userVo.setLevelId(curLConfig.getId()); | |||||
| userVo.setLevelName(curLConfig.getLevel()); | |||||
| curDiscountRateIndex = curLConfig.getDiscountEnable(); | |||||
| if(curLConfig.getDiscountEnable() == 0) { // 未启用等级折扣 | |||||
| userVo.setDiscountRate(0); // 折扣率为0 | |||||
| userVo.setAmount(amount); | |||||
| } else { | |||||
| // 当前商户折扣率 | |||||
| WxMerchant merchant = wxMerchantService.getById(bUser.getMerchantId()); | |||||
| if (merchant == null){ | |||||
| return new ResultData(ErrorCode.MCH_INFO_NOT_FOUND); | |||||
| } | |||||
| if(curDiscountRateIndex == 1) { | |||||
| curDiscountRate = merchant.getVipDiscountRate1(); | |||||
| } else if(curDiscountRateIndex == 2) { | |||||
| curDiscountRate = merchant.getVipDiscountRate2(); | |||||
| } else if(curDiscountRateIndex == 3) { | |||||
| curDiscountRate = merchant.getVipDiscountRate3(); | |||||
| } | |||||
| userVo.setDiscountRate(curDiscountRate); | |||||
| userVo.setAmount(amount*curDiscountRate/10000); | |||||
| } | |||||
| } | |||||
| return new ResultData(userVo); | |||||
| } | |||||
| /** | /** | ||||
| * 用户登录 | * 用户登录 | ||||
| * | * | ||||
| @@ -0,0 +1,58 @@ | |||||
| package com.iformall.controller; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.MallUserInfo; | |||||
| import com.iformall.domain.po.WxMerchantBUser; | |||||
| import com.iformall.domain.po.WxMerchantSubsidy; | |||||
| import com.iformall.domain.vo.WxMerchantSubsidyVo; | |||||
| import com.iformall.service.WxMerchantSubsidyService; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import java.util.Date; | |||||
| import java.util.Map; | |||||
| @RestController | |||||
| @RequestMapping("/api/subsidy") | |||||
| public class WxMerchantSubsidyController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| WxMerchantSubsidyService wxMerchantSubsidyService; | |||||
| @ApiOperation("补贴记录汇总") | |||||
| @GetMapping("sum") | |||||
| public ResultData count(@ModelAttribute WxMerchantSubsidy wxMerchantSubsidy) { | |||||
| String ipStr = getIpAddr(); | |||||
| logger.info("subsidy/sum: " + ipStr + " :" + wxMerchantSubsidy.toString()); | |||||
| if (wxMerchantSubsidy == null) wxMerchantSubsidy = new WxMerchantSubsidy(); | |||||
| WxMerchantBUser user = getUser(); | |||||
| wxMerchantSubsidy.setTenantId(user.getTenantId()); | |||||
| wxMerchantSubsidy.setMerchantId(user.getMerchantId()); | |||||
| Map retMap = wxMerchantSubsidyService.sumForSubsidy(wxMerchantSubsidy); | |||||
| return new ResultData(retMap); | |||||
| } | |||||
| @ApiOperation("补贴记录") | |||||
| @GetMapping("list") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| public ResultData listMonth(@ModelAttribute WxMerchantSubsidy wxMerchantSubsidy, Integer pageNum, Integer pageSize) { | |||||
| String ipStr = getIpAddr(); | |||||
| logger.info("subsidy/list: " + ipStr + " :" + wxMerchantSubsidy.toString()); | |||||
| if (wxMerchantSubsidy == null) wxMerchantSubsidy = new WxMerchantSubsidy(); | |||||
| WxMerchantBUser user = getUser(); | |||||
| wxMerchantSubsidy.setTenantId(user.getTenantId()); | |||||
| wxMerchantSubsidy.setMerchantId(user.getMerchantId()); | |||||
| final PageInfo<WxMerchantSubsidyVo> page = wxMerchantSubsidyService.listAsPage(wxMerchantSubsidy, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| } | |||||
| @@ -5,10 +5,9 @@ import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.config.PayProperty; | import com.iformall.config.PayProperty; | ||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.enums.EnumAppType; | |||||
| import com.iformall.enums.EnumOrderType; | import com.iformall.enums.EnumOrderType; | ||||
| import com.iformall.enums.EnumPayType; | |||||
| import com.iformall.enums.EnumPayWay; | import com.iformall.enums.EnumPayWay; | ||||
| import com.iformall.enums.EnumRefundWay; | |||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.service.*; | import com.iformall.service.*; | ||||
| import com.iformall.utils.IPUtil; | import com.iformall.utils.IPUtil; | ||||
| @@ -55,7 +54,7 @@ public class WxMicroPayController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| WxAppinfoService wxAppinfoService; | WxAppinfoService wxAppinfoService; | ||||
| @ApiOperation(value = "刷卡支付订单", notes = "params:{\"authCode\":\"String\",\"totalFee\":\"String\"},\n" + | |||||
| @ApiOperation(value = "付款码支付订单", notes = "params:{\"authCode\":\"String\",\"totalFee\":\"String\"},\n" + | |||||
| "注意:\n" + | "注意:\n" + | ||||
| "提醒1:提交支付请求后微信会同步返回支付结果。当返回结果为“系统错误”时,商户系统等待5秒后调用【查询订单API】,查询支付实际交易结果;当返回结果为“USERPAYING”时,商户系统可设置间隔时间(建议10秒)重新查询支付结果,直到支付成功或超时(建议30秒);\n" + | "提醒1:提交支付请求后微信会同步返回支付结果。当返回结果为“系统错误”时,商户系统等待5秒后调用【查询订单API】,查询支付实际交易结果;当返回结果为“USERPAYING”时,商户系统可设置间隔时间(建议10秒)重新查询支付结果,直到支付成功或超时(建议30秒);\n" + | ||||
| "提醒2:在调用查询接口返回后,如果交易状况不明晰,请调用【撤销订单API】,此时如果交易失败则关闭订单,该单不能再支付成功;如果交易成功,则将扣款退回到用户账户。当撤销无返回或错误时,请再次调用。注意:请勿扣款后立即调用【撤销订单API】,建议至少15秒后再调用。撤销订单API需要双向证书。") | "提醒2:在调用查询接口返回后,如果交易状况不明晰,请调用【撤销订单API】,此时如果交易失败则关闭订单,该单不能再支付成功;如果交易成功,则将扣款退回到用户账户。当撤销无返回或错误时,请再次调用。注意:请勿扣款后立即调用【撤销订单API】,建议至少15秒后再调用。撤销订单API需要双向证书。") | ||||
| @@ -82,7 +81,7 @@ public class WxMicroPayController extends BaseController { | |||||
| WxOrder order = null; | WxOrder order = null; | ||||
| try { | try { | ||||
| order = wxOrderService.saveMicroOrder(user, totalFeeStr); | |||||
| order = wxOrderService.saveMicroPayOrder(user, totalFeeStr); | |||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error("saveMicopayOrder 1" + e.getMessage()); | logger.error("saveMicopayOrder 1" + e.getMessage()); | ||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | return new ResultData(e.getErrorCode(), e.getMessage()); | ||||
| @@ -109,7 +108,7 @@ public class WxMicroPayController extends BaseController { | |||||
| } | } | ||||
| } | } | ||||
| @ApiOperation(value = "查询刷卡支付订单", notes = "{\"payOrderId\":\"String\",\"orderId\":\"String\"}") | |||||
| @ApiOperation(value = "查询付款码支付订单", notes = "{\"payOrderId\":\"String\",\"orderId\":\"String\"}") | |||||
| @PostMapping("order_query") | @PostMapping("order_query") | ||||
| public ResultData queryMicopayOrder(@RequestBody Map<String, String> paramMap) { | public ResultData queryMicopayOrder(@RequestBody Map<String, String> paramMap) { | ||||
| logger.info("queryMicopayOrder: " + paramMap.toString()); | logger.info("queryMicopayOrder: " + paramMap.toString()); | ||||
| @@ -161,7 +160,7 @@ public class WxMicroPayController extends BaseController { | |||||
| } | } | ||||
| } | } | ||||
| @ApiOperation(value = "撤销刷卡支付订单", notes = "{\"payOrderId\":\"String\",\"orderId\":\"String\"}") | |||||
| @ApiOperation(value = "撤销付款码支付订单", notes = "{\"payOrderId\":\"String\",\"orderId\":\"String\"}") | |||||
| @PostMapping("order_reverse") | @PostMapping("order_reverse") | ||||
| public ResultData reverseMicopayOrder(@RequestBody Map<String, String> paramMap) { | public ResultData reverseMicopayOrder(@RequestBody Map<String, String> paramMap) { | ||||
| logger.info("reverseMicopayOrder: " + paramMap.toString()); | logger.info("reverseMicopayOrder: " + paramMap.toString()); | ||||
| @@ -213,7 +212,7 @@ public class WxMicroPayController extends BaseController { | |||||
| } | } | ||||
| } | } | ||||
| @ApiOperation("刷卡支付交易流水分页列表接口") | |||||
| @ApiOperation("付款码支付交易流水分页列表接口") | |||||
| @GetMapping("listMicroPay") | @GetMapping("listMicroPay") | ||||
| @ApiImplicitParams({ | @ApiImplicitParams({ | ||||
| @ApiImplicitParam(name = "date", value = "日期yyyy-MM-dd", dataType = "string", paramType = "query"), | @ApiImplicitParam(name = "date", value = "日期yyyy-MM-dd", dataType = "string", paramType = "query"), | ||||
| @@ -223,7 +222,7 @@ public class WxMicroPayController extends BaseController { | |||||
| return wxOrderService.microPayListOnDateAsPage(getUser().getId(), EnumOrderType.MICROPAY.getCode(), date, pageNum, pageSize); | return wxOrderService.microPayListOnDateAsPage(getUser().getId(), EnumOrderType.MICROPAY.getCode(), date, pageNum, pageSize); | ||||
| } | } | ||||
| @ApiOperation("刷卡支付某日期交易总流水") | |||||
| @ApiOperation("付款码支付某日期交易总流水") | |||||
| @GetMapping("getMicroPayAmountOnDate") | @GetMapping("getMicroPayAmountOnDate") | ||||
| @ApiImplicitParams({ | @ApiImplicitParams({ | ||||
| @ApiImplicitParam(name = "date", value = "日期yyyy-MM-dd", dataType = "string", paramType = "query")}) | @ApiImplicitParam(name = "date", value = "日期yyyy-MM-dd", dataType = "string", paramType = "query")}) | ||||
| @@ -232,7 +231,7 @@ public class WxMicroPayController extends BaseController { | |||||
| } | } | ||||
| @ApiOperation(value = "刷卡支付退款", notes = "{\"orderId\":\"string\"}") | |||||
| @ApiOperation(value = "付款码支付退款", notes = "{\"orderId\":\"string\"}") | |||||
| @PostMapping("/microPayRefund") | @PostMapping("/microPayRefund") | ||||
| public ResultData create(@RequestBody Map<String, String> paramMap) { | public ResultData create(@RequestBody Map<String, String> paramMap) { | ||||
| //Assert.notNull(wxRefundOrder.getName(), "角色名不能为空"); | //Assert.notNull(wxRefundOrder.getName(), "角色名不能为空"); | ||||
| @@ -254,7 +253,7 @@ public class WxMicroPayController extends BaseController { | |||||
| WxMerchantBUser bUser = getUser(); | WxMerchantBUser bUser = getUser(); | ||||
| WxAppinfo appinfo = getAppInfo(bUser.getAppId()); | WxAppinfo appinfo = getAppInfo(bUser.getAppId()); | ||||
| try { | try { | ||||
| ResultData rd = wxRefundOrderService.createRefundOrderFromMicroPay(payProperty.isReal(), appinfo, orderId, EnumRefundWay.B, bUser.getId()); | |||||
| ResultData rd = wxRefundOrderService.createRefundOrderFromMicroPay(payProperty.isReal(), appinfo, orderId, EnumPayType.PAY_B_REFUND, bUser.getId()); | |||||
| return rd; | return rd; | ||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error("退款 1:" + e.getMessage()); | logger.error("退款 1:" + e.getMessage()); | ||||
| @@ -8,7 +8,7 @@ import com.iformall.config.PayProperty; | |||||
| import com.iformall.domain.po.WxAppinfo; | import com.iformall.domain.po.WxAppinfo; | ||||
| import com.iformall.domain.po.WxMerchantBUser; | import com.iformall.domain.po.WxMerchantBUser; | ||||
| import com.iformall.domain.po.WxRefundOrder; | import com.iformall.domain.po.WxRefundOrder; | ||||
| import com.iformall.enums.EnumRefundWay; | |||||
| import com.iformall.enums.EnumPayType; | |||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.service.WxRefundOrderService; | import com.iformall.service.WxRefundOrderService; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| @@ -57,7 +57,7 @@ public class WxRefundOrderController extends BaseController { | |||||
| WxMerchantBUser bUser = getUser(); | WxMerchantBUser bUser = getUser(); | ||||
| WxAppinfo appinfo = getAppInfo(bUser.getAppId()); | WxAppinfo appinfo = getAppInfo(bUser.getAppId()); | ||||
| try { | try { | ||||
| ResultData rd = wxRefundOrderService.createRefundOrder(payProperty.isReal(), appinfo, couponOrderId, EnumRefundWay.B, bUser.getId()); | |||||
| ResultData rd = wxRefundOrderService.createRefundOrder(payProperty.isReal(), appinfo, couponOrderId, EnumPayType.PAY_B_REFUND, bUser.getId()); | |||||
| return rd; | return rd; | ||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| @@ -0,0 +1,77 @@ | |||||
| package com.iformall.interceptor; | |||||
| import javax.servlet.ReadListener; | |||||
| import javax.servlet.ServletInputStream; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletRequestWrapper; | |||||
| import java.io.*; | |||||
| public class BodyReaderHttpServletRequestWrapper extends HttpServletRequestWrapper { | |||||
| private final String body; | |||||
| public BodyReaderHttpServletRequestWrapper(HttpServletRequest request) throws IOException { | |||||
| super(request); | |||||
| StringBuffer stringBuilder = new StringBuffer(); | |||||
| BufferedReader bufferedReader = null; | |||||
| try { | |||||
| InputStream inputStream = request.getInputStream(); | |||||
| if (inputStream != null) { | |||||
| bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"utf-8")); | |||||
| char[] charBuffer = new char[1024]; | |||||
| int bytesRead = -1; | |||||
| while ((bytesRead = bufferedReader.read(charBuffer)) > 0) { | |||||
| stringBuilder.append(charBuffer, 0, bytesRead); | |||||
| } | |||||
| } else { | |||||
| stringBuilder.append(""); | |||||
| } | |||||
| } catch (IOException ex) { | |||||
| throw ex; | |||||
| } finally { | |||||
| if (bufferedReader != null) { | |||||
| try { | |||||
| bufferedReader.close(); | |||||
| } catch (IOException ex) { | |||||
| throw ex; | |||||
| } | |||||
| } | |||||
| } | |||||
| body = stringBuilder.toString(); | |||||
| } | |||||
| @Override | |||||
| public ServletInputStream getInputStream() throws IOException { | |||||
| final ByteArrayInputStream byteArrayInputStream = | |||||
| new ByteArrayInputStream(body.getBytes("utf-8")); | |||||
| return new ServletInputStream() { | |||||
| @Override | |||||
| public boolean isFinished() { | |||||
| return false; | |||||
| } | |||||
| @Override | |||||
| public boolean isReady() { | |||||
| return false; | |||||
| } | |||||
| @Override | |||||
| public void setReadListener(ReadListener readListener) { | |||||
| } | |||||
| @Override | |||||
| public int read() throws IOException { | |||||
| return byteArrayInputStream.read(); | |||||
| } | |||||
| }; | |||||
| } | |||||
| @Override | |||||
| public BufferedReader getReader() throws IOException { | |||||
| return new BufferedReader(new InputStreamReader(this.getInputStream())); | |||||
| } | |||||
| public String getBody() { | |||||
| return this.body; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,33 @@ | |||||
| package com.iformall.interceptor; | |||||
| import javax.servlet.*; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import java.io.IOException; | |||||
| public class HttpServletRequestWrapperFilter implements Filter { | |||||
| @Override | |||||
| public void init(FilterConfig filterConfig) throws ServletException { | |||||
| } | |||||
| @Override | |||||
| public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | |||||
| throws IOException, ServletException { | |||||
| ServletRequest requestWrapper = null; | |||||
| if (request instanceof HttpServletRequest) { | |||||
| requestWrapper = new BodyReaderHttpServletRequestWrapper((HttpServletRequest) request); | |||||
| } | |||||
| if (null == requestWrapper) { | |||||
| chain.doFilter(request, response); | |||||
| } else { | |||||
| chain.doFilter(requestWrapper, response); | |||||
| } | |||||
| } | |||||
| @Override | |||||
| public void destroy() { | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,91 @@ | |||||
| package com.iformall.interceptor; | |||||
| import com.iformall.utils.HashUtil; | |||||
| import com.iformall.utils.IPUtil; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.data.redis.core.RedisTemplate; | |||||
| import org.springframework.stereotype.Component; | |||||
| import org.springframework.web.servlet.ModelAndView; | |||||
| import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; | |||||
| import javax.annotation.Resource; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.io.ByteArrayOutputStream; | |||||
| import java.io.InputStream; | |||||
| import java.nio.charset.Charset; | |||||
| import java.util.Enumeration; | |||||
| import java.util.concurrent.TimeUnit; | |||||
| /** | |||||
| * 幂等检查 | |||||
| * @author stormeye.wu | |||||
| * @email wuguoqiang@iformall.com | |||||
| * @date 2017-03-23 15:38 | |||||
| */ | |||||
| @Component | |||||
| public class RequestInterceptor extends HandlerInterceptorAdapter { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Resource | |||||
| private RedisTemplate<String, String> redisTemplate; | |||||
| @Override | |||||
| public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | |||||
| if ("GET".equalsIgnoreCase(request.getMethod())) { | |||||
| // 获取不检查幂等 | |||||
| return true; | |||||
| } | |||||
| StringBuilder sb = new StringBuilder(); | |||||
| sb.append(request.getRequestURL().toString()); | |||||
| sb.append("method=").append(request.getMethod()).append("&"); | |||||
| String ipaddress = IPUtil.getIpAddr(request); | |||||
| sb.append("ip=").append(ipaddress).append("&"); | |||||
| final Enumeration parameterNames = request.getParameterNames(); | |||||
| while (parameterNames.hasMoreElements()) { | |||||
| String key = (String) parameterNames.nextElement(); | |||||
| if(key.equalsIgnoreCase("ran")) // 跳过ran | |||||
| continue; | |||||
| String parameter = request.getParameter(key); | |||||
| sb.append(key).append("=").append(parameter).append("&"); | |||||
| } | |||||
| InputStream inStream = request.getInputStream(); | |||||
| ByteArrayOutputStream outSteam = new ByteArrayOutputStream(); | |||||
| byte[] buffer = new byte[1024]; | |||||
| int len = 0; | |||||
| while ((len = inStream.read(buffer)) != -1) { | |||||
| outSteam.write(buffer, 0, len); | |||||
| } | |||||
| String resultBody = new String(outSteam.toByteArray(), Charset.forName("UTF-8")); | |||||
| inStream.close(); | |||||
| outSteam.close(); | |||||
| sb.append(resultBody); | |||||
| String key = "request: " + HashUtil.md5(sb.toString()); | |||||
| if (redisTemplate.opsForValue().setIfAbsent(key, key)) { | |||||
| redisTemplate.expire(key, 3, TimeUnit.SECONDS); | |||||
| logger.info(key + ": 第一次提交"); | |||||
| return true; | |||||
| } | |||||
| logger.info(key + ": 第二次提交"); | |||||
| return false; | |||||
| } | |||||
| @Override | |||||
| public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { | |||||
| } | |||||
| @Override | |||||
| public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { | |||||
| } | |||||
| } | |||||
| @@ -1,7 +1,7 @@ | |||||
| spring: | spring: | ||||
| # JDBC | # JDBC | ||||
| datasource: | datasource: | ||||
| url: jdbc:mysql://202.165.179.86:3306/mallink?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8 | |||||
| url: jdbc:mysql://202.165.179.86:3306/mallinkDev?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8 | |||||
| username: ENC(dZ8fmrtuBMQYaRytKQgTqg==) | username: ENC(dZ8fmrtuBMQYaRytKQgTqg==) | ||||
| password: ENC(OZXsE6/Tj+V1Yu2wdjnIGbNOaBVQzi9W) | password: ENC(OZXsE6/Tj+V1Yu2wdjnIGbNOaBVQzi9W) | ||||
| type: com.alibaba.druid.pool.DruidDataSource | type: com.alibaba.druid.pool.DruidDataSource | ||||
| @@ -7,8 +7,12 @@ import com.fasterxml.jackson.databind.ObjectMapper; | |||||
| import com.fasterxml.jackson.databind.module.SimpleModule; | import com.fasterxml.jackson.databind.module.SimpleModule; | ||||
| import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | ||||
| import com.iformall.interceptor.AuthorizationInterceptor; | import com.iformall.interceptor.AuthorizationInterceptor; | ||||
| import com.iformall.interceptor.HttpServletRequestWrapperFilter; | |||||
| import com.iformall.interceptor.RequestInterceptor; | |||||
| import com.iformall.resolver.LoginUserHandlerMethodArgumentResolver; | import com.iformall.resolver.LoginUserHandlerMethodArgumentResolver; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.boot.web.servlet.FilterRegistrationBean; | |||||
| import org.springframework.context.annotation.Bean; | |||||
| import org.springframework.context.annotation.Configuration; | import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.http.converter.HttpMessageConverter; | import org.springframework.http.converter.HttpMessageConverter; | ||||
| import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | ||||
| @@ -33,11 +37,14 @@ public class WebMvcConfig implements WebMvcConfigurer { | |||||
| @Autowired | @Autowired | ||||
| private AuthorizationInterceptor authorizationInterceptor; | private AuthorizationInterceptor authorizationInterceptor; | ||||
| @Autowired | @Autowired | ||||
| private RequestInterceptor requestInterceptor; | |||||
| @Autowired | |||||
| private LoginUserHandlerMethodArgumentResolver loginUserHandlerMethodArgumentResolver; | private LoginUserHandlerMethodArgumentResolver loginUserHandlerMethodArgumentResolver; | ||||
| @Override | @Override | ||||
| public void addInterceptors(InterceptorRegistry registry) { | public void addInterceptors(InterceptorRegistry registry) { | ||||
| registry.addInterceptor(authorizationInterceptor).addPathPatterns("/api/**"); | registry.addInterceptor(authorizationInterceptor).addPathPatterns("/api/**"); | ||||
| registry.addInterceptor(requestInterceptor).addPathPatterns("/api/**"); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -95,4 +102,13 @@ public class WebMvcConfig implements WebMvcConfigurer { | |||||
| jackson2HttpMessageConverter.setObjectMapper(objectMapper); | jackson2HttpMessageConverter.setObjectMapper(objectMapper); | ||||
| converters.add(jackson2HttpMessageConverter); | converters.add(jackson2HttpMessageConverter); | ||||
| } | } | ||||
| @Bean | |||||
| public FilterRegistrationBean<HttpServletRequestWrapperFilter> Filters() { | |||||
| FilterRegistrationBean<HttpServletRequestWrapperFilter> registrationBean = new FilterRegistrationBean<HttpServletRequestWrapperFilter>(); | |||||
| registrationBean.setFilter(new HttpServletRequestWrapperFilter()); | |||||
| registrationBean.addUrlPatterns("/*"); | |||||
| registrationBean.setName("koalaSignFilter"); | |||||
| return registrationBean; | |||||
| } | |||||
| } | } | ||||
| @@ -10,6 +10,7 @@ import com.iformall.interceptor.AuthorizationInterceptor; | |||||
| import com.iformall.service.WxAppinfoService; | import com.iformall.service.WxAppinfoService; | ||||
| import com.iformall.service.WxCUserBasicInfoService; | import com.iformall.service.WxCUserBasicInfoService; | ||||
| import com.iformall.service.WxCUserService; | import com.iformall.service.WxCUserService; | ||||
| import com.iformall.utils.IPUtil; | |||||
| import com.iformall.utils.MaUtil; | import com.iformall.utils.MaUtil; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -136,4 +137,10 @@ public class BaseController { | |||||
| wxCUserBasicInfoService.save(basicInfo); | wxCUserBasicInfoService.save(basicInfo); | ||||
| } | } | ||||
| } | } | ||||
| public String getIpAddr() { | |||||
| HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); | |||||
| String ipaddress = IPUtil.getIpAddr(request); | |||||
| return ipaddress; | |||||
| } | |||||
| } | } | ||||
| @@ -13,9 +13,13 @@ import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.web.bind.annotation.GetMapping; | import org.springframework.web.bind.annotation.GetMapping; | ||||
| import org.springframework.web.bind.annotation.ModelAttribute; | |||||
| import org.springframework.web.bind.annotation.RequestMapping; | import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.RestController; | import org.springframework.web.bind.annotation.RestController; | ||||
| import java.util.List; | |||||
| import java.util.stream.Collectors; | |||||
| @RestController | @RestController | ||||
| @RequestMapping("/api/wxBusiness") | @RequestMapping("/api/wxBusiness") | ||||
| @Api(description = "业态查询接口") | @Api(description = "业态查询接口") | ||||
| @@ -36,4 +40,22 @@ public class WxBusinessController extends BaseController { | |||||
| final PageInfo<WxBusiness> page = wxBusinessService.listAsPage(wxBusiness, pageNum, pageSize); | final PageInfo<WxBusiness> page = wxBusinessService.listAsPage(wxBusiness, pageNum, pageSize); | ||||
| return new ResultData(page); | return new ResultData(page); | ||||
| } | } | ||||
| @ApiOperation("成长值业态列表接口") | |||||
| @GetMapping("busListForScore") | |||||
| public ResultData getList(@ModelAttribute WxBusiness wxBusiness) { | |||||
| if (null == wxBusiness) wxBusiness = new WxBusiness(); | |||||
| final List<WxBusiness> busList = wxBusinessService.getList(wxBusiness); | |||||
| // 业态 全部 不返回 | |||||
| List<WxBusiness> busList2 = busList.stream().filter(b -> !b.getId().equals(0L)).collect(Collectors.toList()); | |||||
| return new ResultData(busList2); | |||||
| } | |||||
| @ApiOperation("业态全列表接口") | |||||
| @GetMapping("allist") | |||||
| public ResultData getAllList(@ModelAttribute WxBusiness wxBusiness) { | |||||
| if (null == wxBusiness) wxBusiness = new WxBusiness(); | |||||
| final List<WxBusiness> busList = wxBusinessService.getList(wxBusiness); | |||||
| return new ResultData(busList); | |||||
| } | |||||
| } | } | ||||
| @@ -23,8 +23,10 @@ import org.springframework.web.bind.annotation.ModelAttribute; | |||||
| import org.springframework.web.bind.annotation.RequestMapping; | import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.RestController; | import org.springframework.web.bind.annotation.RestController; | ||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.util.List; | import java.util.List; | ||||
| import static com.iformall.domain.po.WxCampaign.Field.CreateTime_ASC; | |||||
| import static com.iformall.domain.po.WxCampaign.Field.SortNum_ASC; | import static com.iformall.domain.po.WxCampaign.Field.SortNum_ASC; | ||||
| @RestController | @RestController | ||||
| @@ -50,7 +52,7 @@ public class WxCampaignController extends BaseController { | |||||
| wxCampaign.setStatus(EnumCampaignStatus.STATUS_THROW_IN.getCode()); | wxCampaign.setStatus(EnumCampaignStatus.STATUS_THROW_IN.getCode()); | ||||
| wxCampaign.setTenantId(getTenantId()); | wxCampaign.setTenantId(getTenantId()); | ||||
| wxCampaign.setSortColumns(SortNum_ASC); | |||||
| wxCampaign.setSortColumns(SortNum_ASC, CreateTime_ASC); | |||||
| final PageInfo<WxCampaign> page = wxCampaignService.listAsPage(wxCampaign, pageNum, pageSize); | final PageInfo<WxCampaign> page = wxCampaignService.listAsPage(wxCampaign, pageNum, pageSize); | ||||
| return new ResultData(page); | return new ResultData(page); | ||||
| } | } | ||||
| @@ -66,7 +68,7 @@ public class WxCampaignController extends BaseController { | |||||
| wxCouponChannel.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_CAMPAIN.getCode()); | wxCouponChannel.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_CAMPAIN.getCode()); | ||||
| wxCouponChannel.setSubTargetId(wxCampaign.getId()); | wxCouponChannel.setSubTargetId(wxCampaign.getId()); | ||||
| wxCouponChannel.setStatus(0); | wxCouponChannel.setStatus(0); | ||||
| List<WxCouponChannelVo> couponList = wxCouponChannelService.listAPI(wxCouponChannel); | |||||
| List<WxCouponChannelVo> couponList = wxCouponChannelService.listVo(wxCouponChannel); | |||||
| wxCampaign.setCoupons(couponList); | wxCampaign.setCoupons(couponList); | ||||
| } | } | ||||
| return new ResultData(Result.SUCCESS, "查询成功", wxCampaign); | return new ResultData(Result.SUCCESS, "查询成功", wxCampaign); | ||||
| @@ -91,5 +93,11 @@ public class WxCampaignController extends BaseController { | |||||
| return new ResultData(Result.SUCCESS, "调整顺序成功", null); | return new ResultData(Result.SUCCESS, "调整顺序成功", null); | ||||
| } | } | ||||
| @ApiOperation("输出富文本内容") | |||||
| @GetMapping("/printHtmlById") | |||||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||||
| public void printHtmlById(Long id,HttpServletResponse response){ | |||||
| wxCampaignService.printHtmlById(id,response); | |||||
| } | |||||
| } | } | ||||
| @@ -648,13 +648,12 @@ public class WxCarController extends BaseController { | |||||
| } | } | ||||
| WxCouponOrderCarCVo userCar = null; | WxCouponOrderCarCVo userCar = null; | ||||
| WxCouponOrderCarCVo userCarQ = new WxCouponOrderCarCVo(); | |||||
| WxCouponOrder userCarQ = new WxCouponOrder(); | |||||
| userCarQ.setTenantId(user.getTenantId()); | userCarQ.setTenantId(user.getTenantId()); | ||||
| userCarQ.setCUserId(user.getId()); | userCarQ.setCUserId(user.getId()); | ||||
| userCarQ.setType(EnumCouponType.COUPON_TINGCHE.getCode()); | |||||
| userCarQ.setId(couponOrderId); | userCarQ.setId(couponOrderId); | ||||
| userCarQ.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); | userCarQ.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); | ||||
| List<WxCouponOrderCarCVo> list = wxCouponOrderService.carlistCUserVo(userCarQ); | |||||
| List<WxCouponOrderCarCVo> list = wxCouponOrderService.carListCUserVo(userCarQ); | |||||
| if (list.size() > 0) { | if (list.size() > 0) { | ||||
| userCar = list.get(0); | userCar = list.get(0); | ||||
| } | } | ||||
| @@ -704,7 +703,7 @@ public class WxCarController extends BaseController { | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | ||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), | @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), | ||||
| }) | }) | ||||
| public ResultData list(@ModelAttribute WxCouponOrderCarCVo wxCouponOrder, Integer pageNum, Integer pageSize) { | |||||
| public ResultData list(@ModelAttribute WxCouponOrder wxCouponOrder, Integer pageNum, Integer pageSize) { | |||||
| if(pageNum == null || pageSize == null) { | if(pageNum == null || pageSize == null) { | ||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | ||||
| @@ -719,7 +718,7 @@ public class WxCarController extends BaseController { | |||||
| wxCouponOrder.setSortColumns(WxCouponOrder.Field.CreateDate_DESC); | wxCouponOrder.setSortColumns(WxCouponOrder.Field.CreateDate_DESC); | ||||
| else | else | ||||
| wxCouponOrder.setSortColumns(WxCouponOrder.Field.UpdateDate_DESC); | wxCouponOrder.setSortColumns(WxCouponOrder.Field.UpdateDate_DESC); | ||||
| return wxCouponOrderService.carlistCUserVoAsPage(wxCouponOrder, pageNum, pageSize); | |||||
| return wxCouponOrderService.carListCUserVoAsPage(wxCouponOrder, pageNum, pageSize); | |||||
| } | } | ||||
| @ApiOperation(value = "停车场状态") | @ApiOperation(value = "停车场状态") | ||||
| @@ -0,0 +1,168 @@ | |||||
| package com.iformall.controller; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.*; | |||||
| import com.iformall.domain.vo.WxCardSpendVo; | |||||
| import com.iformall.exception.MallinkException; | |||||
| import com.iformall.service.*; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import java.math.BigDecimal; | |||||
| import java.util.Map; | |||||
| /** | |||||
| * @author Stormeye Wu wuguoqiang@iformall.com | |||||
| */ | |||||
| @RestController | |||||
| @Api(description = "C端扫B端商户码储值卡支付") | |||||
| @RequestMapping("/api/cardPay") | |||||
| public class WxCardPayController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| WxMerchantService wxMerchantService; | |||||
| @Autowired | |||||
| WxOrderService wxOrderService; | |||||
| @Autowired | |||||
| WxCardInfoService wxCardInfoService; | |||||
| @Autowired | |||||
| WxCardSpendService wxCardSpendService; | |||||
| @ApiOperation(value = "C端扫B端储值卡支付订单", notes = "params:{\"cardId\":\"String\",\"merchantCode\":\"String\",\"totalFee\":\"String(元)\"}") | |||||
| @PostMapping("order_create") | |||||
| public ResultData saveCardPayOrder(@RequestBody Map<String, String> paramMap, HttpServletRequest request) { | |||||
| String ipStr = getIpAddr(); | |||||
| logger.info("saveCardPayOrder: " + ipStr + " :" + paramMap.toString()); | |||||
| String cardIdStr = paramMap.get("cardId"); | |||||
| String merchantCode = paramMap.get("merchantCode"); | |||||
| String totalFeeStr = paramMap.get("totalFee"); | |||||
| if (StringUtils.isBlank(cardIdStr)) { | |||||
| logger.error("cardId不能为空"); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "cardId不能为空"); | |||||
| } | |||||
| if (StringUtils.isBlank(merchantCode)) { | |||||
| logger.error("merchantCode不能为空"); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "merchantCode不能为空"); | |||||
| } | |||||
| if (StringUtils.isBlank(totalFeeStr)) { | |||||
| logger.error("totalFee不能为空"); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "totalFee不能为空"); | |||||
| } | |||||
| Long cardId = null; | |||||
| Long merchantId = null; | |||||
| try { | |||||
| cardId = Long.valueOf(cardIdStr); | |||||
| } catch (Exception e) { | |||||
| logger.error("cardId convert failed:" + cardIdStr); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "cardIdStr转换失败"); | |||||
| } | |||||
| try { | |||||
| merchantId = Long.valueOf(merchantCode); | |||||
| } catch (Exception e) { | |||||
| logger.error("merchantCode convert failed:" + merchantCode); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "merchantCode转换失败"); | |||||
| } | |||||
| BigDecimal totalFee = new BigDecimal(totalFeeStr); | |||||
| totalFee.setScale(2, BigDecimal.ROUND_HALF_UP); // 第一个变量是小数位数,第二个变量是取舍方法(四舍五入) | |||||
| Integer payment = totalFee.multiply(new BigDecimal(100)).intValue(); | |||||
| WxCardInfo cardInfo = wxCardInfoService.getById(cardId); | |||||
| if(cardInfo == null) { | |||||
| logger.error("卡不存在: " + cardIdStr); | |||||
| return new ResultData(ErrorCode.CARD_IS_NOT_FOUND); | |||||
| } | |||||
| if(payment>cardInfo.getRemainingAmount()) { | |||||
| logger.error("卡余额不足: " + cardIdStr); | |||||
| return new ResultData(ErrorCode.CARD_REMAIN_AMOUNT_IS_NOT_ENOUGH); | |||||
| } | |||||
| WxCouponMerchant couponMerchant = wxCardSpendService.checkMerchantInCoupon(cardInfo, merchantId); | |||||
| if(couponMerchant == null) { | |||||
| logger.error("商户不支持此卡 " + cardIdStr); | |||||
| return new ResultData(ErrorCode.COUPON_ORDER_MERANT_IS_NULL.getCode(), "商户不支持此卡"); | |||||
| } | |||||
| WxCUser user = getUser(); | |||||
| WxMerchant merchant = wxMerchantService.getById(merchantId); | |||||
| WxOrder order = null; | |||||
| try { | |||||
| order = wxOrderService.saveCardPayOrder(merchant, totalFeeStr, payment); | |||||
| } catch (MallinkException e) { | |||||
| logger.error("saveCardPayOrder 1" + e.getMessage()); | |||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| } catch (Exception e) { | |||||
| logger.error("saveCardPayOrder 2" + e.getMessage()); | |||||
| return new ResultData(ErrorCode.ORDER_IS_FAIL, e.getMessage()); | |||||
| } | |||||
| WxCardSpend record = new WxCardSpend(); | |||||
| record.setTenantId(merchant.getTenantId()); | |||||
| record.setCardId(cardId); | |||||
| record.setOwnerId(user.getId()); | |||||
| record.setMerchantId(merchantId); | |||||
| record.setOrderId(order.getId()); | |||||
| record.setIp(ipStr); | |||||
| record.setDeductionAmount(payment); | |||||
| try { | |||||
| return wxCardSpendService.createCardSpend(record, order, couponMerchant, user); | |||||
| } catch (MallinkException e) { | |||||
| logger.error("card spend error, req 2: " + record.toString() + ", e:" + e.getMessage()); | |||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| } catch (Exception e) { | |||||
| logger.error("card spend error, req 3: " + record.toString() + ", e:" + e.getMessage()); | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR, e.getMessage()); | |||||
| } | |||||
| } | |||||
| @ApiOperation("C端扫B端储值卡交易流水列表接口") | |||||
| @GetMapping("list") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| public ResultData cardSpendList(@ModelAttribute WxCardSpendVo wxCardSpend, Integer pageNum, Integer pageSize) { | |||||
| String ipStr = getIpAddr(); | |||||
| logger.info("saveCardPayOrder: " + ipStr + " :" + wxCardSpend.toString()); | |||||
| if (wxCardSpend == null) wxCardSpend = new WxCardSpendVo(); | |||||
| WxCUser user = getUser(); | |||||
| wxCardSpend.setTenantId(user.getTenantId()); | |||||
| wxCardSpend.setOwnerId(user.getId()); | |||||
| final PageInfo<WxCardSpendVo> page = wxCardSpendService.listAsPage(wxCardSpend, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| @ApiOperation("C端扫B端储值卡交易流水SUM接口") | |||||
| @GetMapping("sum") | |||||
| public ResultData sumCardSpendList(@ModelAttribute WxCardSpendVo wxCardSpend) { | |||||
| String ipStr = getIpAddr(); | |||||
| logger.info("sumCardSpendList: " + ipStr + " :" + wxCardSpend.toString()); | |||||
| if (wxCardSpend == null) wxCardSpend = new WxCardSpendVo(); | |||||
| WxCUser user = getUser(); | |||||
| wxCardSpend.setTenantId(user.getTenantId()); | |||||
| wxCardSpend.setOwnerId(user.getId()); | |||||
| final Map map = wxCardSpendService.sumCardSpendForOwner(wxCardSpend); | |||||
| return new ResultData(map); | |||||
| } | |||||
| } | |||||
| @@ -1,68 +0,0 @@ | |||||
| package com.iformall.controller; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.Result; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.WxCouponCar; | |||||
| import com.iformall.service.WxCouponCarService; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| @RestController | |||||
| @RequestMapping("wxCouponCar") | |||||
| @Api(description = "停车发券相关接口") | |||||
| public class WxCouponCarController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| private WxCouponCarService wxCouponCarService; | |||||
| @ApiOperation("分页列表接口") | |||||
| @GetMapping("list") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| public ResultData list(@ModelAttribute WxCouponCar wxCouponCar, Integer pageNum, Integer pageSize) { | |||||
| if (null == wxCouponCar) wxCouponCar = new WxCouponCar(); | |||||
| final PageInfo<WxCouponCar> page = wxCouponCarService.listAsPage(wxCouponCar, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| @ApiOperation("新增接口") | |||||
| @PostMapping("add") | |||||
| public ResultData add(@RequestBody WxCouponCar wxCouponCar) { | |||||
| //Assert.notNull(wxCouponCar.getName(), "角色名不能为空"); | |||||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||||
| wxCouponCarService.save(wxCouponCar); | |||||
| return new ResultData(); | |||||
| } | |||||
| @ApiOperation("根据id更新接口") | |||||
| @PostMapping("update") | |||||
| public ResultData update(@RequestBody WxCouponCar wxCouponCar) { | |||||
| wxCouponCarService.update(wxCouponCar); | |||||
| return new ResultData(); | |||||
| } | |||||
| @ApiOperation("根据id删除接口") | |||||
| @GetMapping("/del") | |||||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||||
| public ResultData delete(Long id) { | |||||
| wxCouponCarService.deleteById(id); | |||||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||||
| } | |||||
| @ApiOperation("根据id查询接口") | |||||
| @GetMapping("/findById") | |||||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||||
| public ResultData findById(Long id) { | |||||
| return new ResultData(Result.SUCCESS, "查询成功", wxCouponCarService.getById(id)); | |||||
| } | |||||
| } | |||||
| @@ -27,8 +27,6 @@ public class WxCouponChannelController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private WxCouponChannelService wxCouponChannelService; | private WxCouponChannelService wxCouponChannelService; | ||||
| @ApiOperation("分页列表接口") | @ApiOperation("分页列表接口") | ||||
| @GetMapping("list") | @GetMapping("list") | ||||
| @ApiImplicitParams({ | @ApiImplicitParams({ | ||||
| @@ -39,13 +37,8 @@ public class WxCouponChannelController extends BaseController { | |||||
| wxCouponChannel.setTenantId(getTenantId()); | wxCouponChannel.setTenantId(getTenantId()); | ||||
| wxCouponChannel.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode()); | wxCouponChannel.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode()); | ||||
| wxCouponChannel.setSortColumns(WxCouponChannel.Field.CreateDate_DESC); | wxCouponChannel.setSortColumns(WxCouponChannel.Field.CreateDate_DESC); | ||||
| PageInfo<WxCouponChannelVo> page; | |||||
| if (wxCouponChannel.getTargetAd() != null | |||||
| && wxCouponChannel.getTargetAd().equals(EnumCouponChannelType.COUPON_CHANNEL_ID_TIMED.getCode())) | |||||
| page = wxCouponChannelService.listPageCAPI(wxCouponChannel, pageNum, pageSize,true); | |||||
| else | |||||
| page = wxCouponChannelService.listPageCAPI(wxCouponChannel, pageNum, pageSize,false); | |||||
| return new ResultData(page); | |||||
| return new ResultData(wxCouponChannelService.listPageCVo(wxCouponChannel, pageNum, pageSize)); | |||||
| } | } | ||||
| } | } | ||||
| @@ -2,10 +2,10 @@ package com.iformall.controller; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxCoupon; | |||||
| import com.iformall.domain.po.WxCouponChannel; | import com.iformall.domain.po.WxCouponChannel; | ||||
| import com.iformall.domain.vo.WxCouponCVo; | import com.iformall.domain.vo.WxCouponCVo; | ||||
| import com.iformall.service.WxCouponService; | |||||
| import com.iformall.service.WxCouponChannelService; | |||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| @@ -25,7 +25,7 @@ public class WxCouponController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| @Autowired | @Autowired | ||||
| private WxCouponService wxCouponService; | |||||
| private WxCouponChannelService wxCouponChannelService; | |||||
| @ApiOperation("根据id(couponChannel)查询接口") | @ApiOperation("根据id(couponChannel)查询接口") | ||||
| @@ -43,10 +43,8 @@ public class WxCouponController extends BaseController { | |||||
| logger.error("id转换失败" + couponChannelId); | logger.error("id转换失败" + couponChannelId); | ||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId转换失败" + couponChannelId); | return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId转换失败" + couponChannelId); | ||||
| } | } | ||||
| WxCouponChannel wxCouponChannel = new WxCouponChannel(); | |||||
| wxCouponChannel.setId(couponChannelIdL); | |||||
| wxCouponChannel.setTenantId(getTenantId()); | |||||
| WxCouponCVo wxCouponCVo = wxCouponService.selectDetailForCUser(wxCouponChannel); | |||||
| WxCouponCVo wxCouponCVo = wxCouponChannelService.findDetailVo(couponChannelIdL); | |||||
| if (wxCouponCVo == null) | if (wxCouponCVo == null) | ||||
| return new ResultData(ErrorCode.COUPON_IS_EMPTY); | return new ResultData(ErrorCode.COUPON_IS_EMPTY); | ||||
| @@ -2,7 +2,9 @@ package com.iformall.controller; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxCUser; | |||||
| import com.iformall.domain.po.WxCouponOrder; | import com.iformall.domain.po.WxCouponOrder; | ||||
| import com.iformall.domain.vo.WxCardCVo; | |||||
| import com.iformall.domain.vo.WxCouponOrderCVo; | import com.iformall.domain.vo.WxCouponOrderCVo; | ||||
| import com.iformall.enums.EnumCouponOrderStatus; | import com.iformall.enums.EnumCouponOrderStatus; | ||||
| import com.iformall.service.WxCouponOrderService; | import com.iformall.service.WxCouponOrderService; | ||||
| @@ -10,6 +12,7 @@ import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -18,7 +21,9 @@ import org.springframework.web.bind.annotation.ModelAttribute; | |||||
| import org.springframework.web.bind.annotation.RequestMapping; | import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.RestController; | import org.springframework.web.bind.annotation.RestController; | ||||
| import java.util.ArrayList; | |||||
| import java.util.HashMap; | import java.util.HashMap; | ||||
| import java.util.List; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| @RestController | @RestController | ||||
| @@ -36,7 +41,7 @@ public class WxCouponOrderController extends BaseController { | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | ||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), | @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), | ||||
| }) | }) | ||||
| public ResultData list(@ModelAttribute WxCouponOrderCVo wxCouponOrder, Integer pageNum, Integer pageSize) { | |||||
| public ResultData list(@ModelAttribute WxCouponOrder wxCouponOrder, Integer pageNum, Integer pageSize) { | |||||
| if (pageNum == null || pageSize == null) { | if (pageNum == null || pageSize == null) { | ||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | ||||
| @@ -52,7 +57,7 @@ public class WxCouponOrderController extends BaseController { | |||||
| return wxCouponOrderService.listCUserVoAsPage(wxCouponOrder, pageNum, pageSize); | return wxCouponOrderService.listCUserVoAsPage(wxCouponOrder, pageNum, pageSize); | ||||
| } | } | ||||
| @ApiOperation(value = "卡券详情接口") | |||||
| @ApiOperation(value = "券详情接口") | |||||
| @GetMapping("detail") | @GetMapping("detail") | ||||
| @ApiImplicitParams({ | @ApiImplicitParams({ | ||||
| @ApiImplicitParam(name = "couponOrderId", value = "券ID", dataType = "string", paramType = "query", required = true) | @ApiImplicitParam(name = "couponOrderId", value = "券ID", dataType = "string", paramType = "query", required = true) | ||||
| @@ -83,4 +88,53 @@ public class WxCouponOrderController extends BaseController { | |||||
| return new ResultData(res); | return new ResultData(res); | ||||
| } | } | ||||
| //// ------ 卡相关接口 | |||||
| @ApiOperation("卡包分页列表接口") | |||||
| @GetMapping("cardList") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), | |||||
| }) | |||||
| public ResultData cardList(@ModelAttribute WxCardCVo cardCVo, Integer pageNum, Integer pageSize) { | |||||
| if (pageNum == null || pageSize == null) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| } | |||||
| if (cardCVo == null) cardCVo = new WxCardCVo(); | |||||
| WxCUser user = getUser(); | |||||
| cardCVo.setTenantId(user.getTenantId()); | |||||
| cardCVo.setOwnerId(user.getId()); | |||||
| if(StringUtils.isNotBlank(cardCVo.getStatusStr())) { | |||||
| String [] statusAttr = cardCVo.getStatusStr().split(","); | |||||
| List<Integer> tmpList = new ArrayList<Integer>(); | |||||
| for(String status: statusAttr) { | |||||
| tmpList.add(Integer.valueOf(status)); | |||||
| } | |||||
| if(!tmpList.isEmpty()) { | |||||
| cardCVo.setStatusS(tmpList); | |||||
| } | |||||
| } | |||||
| if (cardCVo.getCouponOrderStatus() == null) | |||||
| cardCVo.setSortColumns(WxCouponOrder.Field.CreateDate_DESC); | |||||
| else if (cardCVo.getCouponOrderStatus() == EnumCouponOrderStatus.CARD_USING.getCode()) | |||||
| cardCVo.setSortColumns(WxCouponOrder.Field.CreateDate_DESC); | |||||
| else | |||||
| cardCVo.setSortColumns(WxCouponOrder.Field.UpdateDate_DESC); | |||||
| return wxCouponOrderService.listCardVoAsPage(cardCVo, pageNum, pageSize); | |||||
| } | |||||
| @ApiOperation(value = "卡券详情接口") | |||||
| @GetMapping("cardDetail") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "couponOrderId", value = "券ID", dataType = "string", paramType = "query", required = true) | |||||
| }) | |||||
| public ResultData cardDetail(String couponOrderId) { | |||||
| if (couponOrderId == null) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| } | |||||
| return wxCouponOrderService.cardDetailCUserVo(getUserId(), couponOrderId); | |||||
| } | |||||
| } | } | ||||
| @@ -4,14 +4,10 @@ import com.iformall.annotation.AuthIgnore; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxAppinfo; | |||||
| import com.iformall.domain.po.WxLevelConfig; | |||||
| import com.iformall.domain.po.WxMall; | |||||
| import com.iformall.domain.po.WxScoreRules; | |||||
| import com.iformall.service.WxAppinfoService; | |||||
| import com.iformall.service.WxLevelConfigService; | |||||
| import com.iformall.service.WxMallService; | |||||
| import com.iformall.service.WxScoreRulesService; | |||||
| import com.iformall.domain.po.*; | |||||
| import com.iformall.domain.vo.WxMerchantDiscountVo; | |||||
| import com.iformall.enums.EnumMerchantStatus; | |||||
| import com.iformall.service.*; | |||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| @@ -48,9 +44,12 @@ public class WxMallController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private WxLevelConfigService wxLevelConfigService; | private WxLevelConfigService wxLevelConfigService; | ||||
| @Autowired | |||||
| private WxMerchantService wxMerchantService; | |||||
| @AuthIgnore | @AuthIgnore | ||||
| @ApiOperation("根据appId获取") | |||||
| @ApiOperation("商场图标") | |||||
| @GetMapping("/getAppIcon") | @GetMapping("/getAppIcon") | ||||
| @ApiImplicitParam(name = "appId", value = "appId", dataType = "String", paramType = "query", required = true) | @ApiImplicitParam(name = "appId", value = "appId", dataType = "String", paramType = "query", required = true) | ||||
| public ResultData getAppIcon(String appId) { | public ResultData getAppIcon(String appId) { | ||||
| @@ -69,7 +68,7 @@ public class WxMallController extends BaseController { | |||||
| } | } | ||||
| @AuthIgnore | @AuthIgnore | ||||
| @ApiOperation("根据appId获取") | |||||
| @ApiOperation("商场提示信息") | |||||
| @GetMapping("/getWeapNote") | @GetMapping("/getWeapNote") | ||||
| @ApiImplicitParam(name = "appId", value = "appId", dataType = "String", paramType = "query", required = true) | @ApiImplicitParam(name = "appId", value = "appId", dataType = "String", paramType = "query", required = true) | ||||
| public ResultData getWeapNote(String appId) { | public ResultData getWeapNote(String appId) { | ||||
| @@ -86,37 +85,48 @@ public class WxMallController extends BaseController { | |||||
| return new ResultData(Result.SUCCESS, "查询成功", resultMap); | return new ResultData(Result.SUCCESS, "查询成功", resultMap); | ||||
| } | } | ||||
| @ApiOperation("根据appId获取") | |||||
| @ApiOperation("商场信息") | |||||
| @GetMapping("/mallInfo") | @GetMapping("/mallInfo") | ||||
| @ApiImplicitParam(name = "appId", value = "appId", dataType = "String", paramType = "query", required = true) | |||||
| public ResultData getMallInfo(String appId) { | |||||
| WxAppinfo appInfo = wxAppinfoService.getByAppId(appId); | |||||
| if (appInfo == null) { | |||||
| return new ResultData(ErrorCode.APP_ID_NOT_FOUND); | |||||
| } | |||||
| WxMall mall = wxMallService.getByTenantId(appInfo.getTenantId()); | |||||
| public ResultData getMallInfo() { | |||||
| WxCUser user = getUser(); | |||||
| WxMall mall = wxMallService.getByTenantId(user.getTenantId()); | |||||
| if (mall == null) { | if (mall == null) { | ||||
| return new ResultData(ErrorCode.MALL_INFO_NOT_FOUND); | return new ResultData(ErrorCode.MALL_INFO_NOT_FOUND); | ||||
| } | } | ||||
| return new ResultData(Result.SUCCESS, "查询成功", mall); | return new ResultData(Result.SUCCESS, "查询成功", mall); | ||||
| } | } | ||||
| @ApiOperation("根据appId获取") | |||||
| @ApiOperation("成长值相关信息") | |||||
| @GetMapping("/scoreLevelInfo") | @GetMapping("/scoreLevelInfo") | ||||
| @ApiImplicitParam(name = "appId", value = "appId", dataType = "String", paramType = "query", required = true) | |||||
| public ResultData getScoreLevelInfo(String appId) { | |||||
| WxAppinfo appInfo = wxAppinfoService.getByAppId(appId); | |||||
| if (appInfo == null) { | |||||
| return new ResultData(ErrorCode.APP_ID_NOT_FOUND); | |||||
| } | |||||
| public ResultData getScoreLevelInfo() { | |||||
| WxCUser user = getUser(); | |||||
| Map map = new HashMap(); | Map map = new HashMap(); | ||||
| WxScoreRules scoreRules = wxScoreRulesService.getScoreRules(appInfo.getTenantId()); | |||||
| WxScoreRules scoreRules = wxScoreRulesService.getScoreRules(user.getTenantId()); | |||||
| map.put("score", scoreRules); | map.put("score", scoreRules); | ||||
| List<WxLevelConfig> levelConfigList = wxLevelConfigService.getByTenantId(appInfo.getTenantId()); | |||||
| List<WxLevelConfig> levelConfigList = wxLevelConfigService.getByTenantId(user.getTenantId()); | |||||
| boolean disscountEnable = false; | |||||
| for(WxLevelConfig levelConfig: levelConfigList) { | |||||
| if (levelConfig.getDiscountEnable() > 0 ) { | |||||
| disscountEnable = true; | |||||
| break; | |||||
| } | |||||
| } | |||||
| map.put("levelList", levelConfigList); | map.put("levelList", levelConfigList); | ||||
| map.put("discountEnable", disscountEnable); | |||||
| return new ResultData(Result.SUCCESS, "查询成功", map); | return new ResultData(Result.SUCCESS, "查询成功", map); | ||||
| } | } | ||||
| @ApiOperation("获取打折商户列表") | |||||
| @GetMapping("/discountMerchantList") | |||||
| public ResultData getMerchantId() { | |||||
| WxCUser user = getUser(); | |||||
| WxMerchant merchantQ = new WxMerchant(); | |||||
| merchantQ.setTenantId(user.getTenantId()); | |||||
| merchantQ.setStatus(EnumMerchantStatus.VALID.getCode()); | |||||
| List<WxMerchantDiscountVo> list = wxMerchantService.getDisCountList(merchantQ); | |||||
| return new ResultData(Result.SUCCESS, "查询成功", list); | |||||
| } | |||||
| @AuthIgnore | @AuthIgnore | ||||
| @ApiOperation("获取后端版本号") | @ApiOperation("获取后端版本号") | ||||
| @GetMapping("/version") | @GetMapping("/version") | ||||
| @@ -7,10 +7,9 @@ import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.WxCUser; | import com.iformall.domain.po.WxCUser; | ||||
| import com.iformall.domain.po.WxCouponChannel; | import com.iformall.domain.po.WxCouponChannel; | ||||
| import com.iformall.domain.po.WxOrder; | import com.iformall.domain.po.WxOrder; | ||||
| import com.iformall.domain.vo.WxOrderCVo; | |||||
| import com.iformall.domain.vo.WxOrderCouponVo; | |||||
| import com.iformall.enums.EnumCouponChannelStatus; | import com.iformall.enums.EnumCouponChannelStatus; | ||||
| import com.iformall.enums.EnumOrderStatus; | import com.iformall.enums.EnumOrderStatus; | ||||
| import com.iformall.enums.EnumOrderType; | |||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.service.WxCouponChannelService; | import com.iformall.service.WxCouponChannelService; | ||||
| import com.iformall.service.WxOrderService; | import com.iformall.service.WxOrderService; | ||||
| @@ -73,7 +72,7 @@ public class WxOrderController extends BaseController { | |||||
| WxOrder order = null; | WxOrder order = null; | ||||
| try { | try { | ||||
| order = wxOrderService.sendUserFreeCoupon(user.getId(), couponId); | |||||
| order = wxOrderService.saveFreeCouponOrder(user.getId(), couponId); | |||||
| return new ResultData(order); | return new ResultData(order); | ||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| @@ -135,7 +134,7 @@ public class WxOrderController extends BaseController { | |||||
| WxCUser user = getUser(); | WxCUser user = getUser(); | ||||
| try { | try { | ||||
| WxOrder order = wxOrderService.saveOrder(user, couponChannelId, couponId); | |||||
| WxOrder order = wxOrderService.saveCouponOrder(user, couponChannelId, couponId); | |||||
| return new ResultData(order); | return new ResultData(order); | ||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| @@ -214,9 +213,9 @@ public class WxOrderController extends BaseController { | |||||
| public ResultData list(@ModelAttribute WxOrder wxOrder, Integer pageNum, Integer pageSize) { | public ResultData list(@ModelAttribute WxOrder wxOrder, Integer pageNum, Integer pageSize) { | ||||
| // c端用户应该只能看到自己的订单 | // c端用户应该只能看到自己的订单 | ||||
| if (wxOrder == null) wxOrder = new WxOrder(); | if (wxOrder == null) wxOrder = new WxOrder(); | ||||
| wxOrder.setCUserId(getUser().getId()); | |||||
| wxOrder.setcUserId(getUser().getId()); | |||||
| wxOrder.setSortColumns(WxOrder.Field.CreateDate_DESC); | wxOrder.setSortColumns(WxOrder.Field.CreateDate_DESC); | ||||
| final PageInfo<WxOrderCVo> page = wxOrderService.listCUserVoAsPage(wxOrder, pageNum, pageSize); | |||||
| final PageInfo<WxOrderCouponVo> page = wxOrderService.listCUserVoAsPage(wxOrder, pageNum, pageSize); | |||||
| return new ResultData(page); | return new ResultData(page); | ||||
| } | } | ||||
| @@ -236,8 +235,8 @@ public class WxOrderController extends BaseController { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "订单ID转换异常"); | return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "订单ID转换异常"); | ||||
| } | } | ||||
| wxOrder.setId(id); | wxOrder.setId(id); | ||||
| wxOrder.setCUserId(getUser().getId()); | |||||
| WxOrderCVo wxOrderCVo = wxOrderService.detailCUserVo(wxOrder); | |||||
| wxOrder.setcUserId(getUser().getId()); | |||||
| WxOrderCouponVo wxOrderCVo = wxOrderService.detailCUserVo(wxOrder); | |||||
| if (wxOrderCVo == null) | if (wxOrderCVo == null) | ||||
| return new ResultData(ErrorCode.ORDER_IS_NOT_FIND); | return new ResultData(ErrorCode.ORDER_IS_NOT_FIND); | ||||
| return new ResultData(wxOrderCVo); | return new ResultData(wxOrderCVo); | ||||