develop # Conflicts: # mallinkService/src/main/java/com/iformall/common/ErrorCode.javarelease_toaliyun_real
| @@ -34,6 +34,18 @@ | |||
| <version>1.3.3</version> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>com.google.zxing</groupId> | |||
| <artifactId>core</artifactId> | |||
| <version>3.3.3</version> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>com.github.axet</groupId> | |||
| <artifactId>kaptcha</artifactId> | |||
| <version>0.0.9</version> | |||
| </dependency> | |||
| </dependencies> | |||
| <build> | |||
| @@ -1,6 +1,7 @@ | |||
| package com.iformall; | |||
| import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; | |||
| import org.rocketmq.starter.annotation.EnableRocketMQ; | |||
| import org.springframework.beans.factory.annotation.Value; | |||
| import org.springframework.boot.SpringApplication; | |||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | |||
| @@ -18,6 +19,7 @@ import tk.mybatis.spring.annotation.MapperScan; | |||
| @EnableSwagger2 | |||
| @EnableEncryptableProperties | |||
| @EnableAsync | |||
| @EnableRocketMQ | |||
| public class UserApplication { | |||
| @Value("${fm.exception}") | |||
| @@ -1,6 +1,7 @@ | |||
| package com.iformall.config; | |||
| import com.iformall.domain.po.PushLimit; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxScoreRules; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -109,4 +110,36 @@ public class RedisConfig extends CachingConfigurerSupport { | |||
| return template; | |||
| } | |||
| @Bean("openRedisTemplate") | |||
| public RedisTemplate<String, String> getWeChatOpen(RedisConnectionFactory connectionFactory) { | |||
| RedisTemplate<String, String> template = new RedisTemplate<String, String>(); | |||
| // value值的序列化 | |||
| template.setValueSerializer(new StringRedisSerializer()); | |||
| // key的序列化 | |||
| template.setKeySerializer(new StringRedisSerializer()); | |||
| template.setHashKeySerializer(new StringRedisSerializer()); | |||
| template.setConnectionFactory(connectionFactory); | |||
| return template; | |||
| } | |||
| @Bean("cuserTokenRedisTemplate") | |||
| public RedisTemplate<String, WxCUser> getCUserTokenRedisTemplate(RedisConnectionFactory connectionFactory) { | |||
| RedisTemplate<String, WxCUser> template = new RedisTemplate<String, WxCUser>(); | |||
| Jackson2JsonRedisSerializer<WxCUser> j = new Jackson2JsonRedisSerializer<WxCUser>(WxCUser.class); | |||
| // value值的序列化 | |||
| template.setValueSerializer(j); | |||
| template.setHashKeySerializer(j); | |||
| // key的序列化 | |||
| template.setKeySerializer(new StringRedisSerializer()); | |||
| template.setHashKeySerializer(new StringRedisSerializer()); | |||
| template.setConnectionFactory(connectionFactory); | |||
| return template; | |||
| } | |||
| } | |||
| @@ -94,16 +94,32 @@ public class ShiroConfig { | |||
| //拦截器. | |||
| Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>(); | |||
| //配置退出 过滤器,其中的具体的退出代码Shiro已经替我们实现了 | |||
| filterChainDefinitionMap.put("/logout", "anon"); | |||
| //filterChainDefinitionMap.put("/ue/**", "anon"); | |||
| //filterChainDefinitionMap.put("/config.json", "anon"); | |||
| // login | |||
| filterChainDefinitionMap.put("/doLogin/**", "anon"); | |||
| filterChainDefinitionMap.put("/bHidLogin/**", "anon"); | |||
| filterChainDefinitionMap.put("/sendLoginPhoneCode/**", "anon"); | |||
| filterChainDefinitionMap.put("/doLoginByPhone/**", "anon"); | |||
| filterChainDefinitionMap.put("/wechat/callback", "anon"); // 微信第三方登录callback | |||
| filterChainDefinitionMap.put("/wechat/weChatUserLogin", "anon"); // 微信第三方登录绑定 | |||
| // callback | |||
| filterChainDefinitionMap.put("/wxPay/notify/**", "anon"); // 支付回调 | |||
| filterChainDefinitionMap.put("/wxPayBill/notify/**", "anon"); | |||
| filterChainDefinitionMap.put("/wxMsgCallback/**", "anon"); | |||
| filterChainDefinitionMap.put("/user/sendvalidationcode", "anon"); | |||
| filterChainDefinitionMap.put("/user/updatepwd", "anon"); | |||
| filterChainDefinitionMap.put("/carCallback/**", "anon"); | |||
| filterChainDefinitionMap.put("/wxMallApply/add", "anon"); | |||
| filterChainDefinitionMap.put("/wxMallApply/sendvalidationcode", "anon"); | |||
| // static files | |||
| filterChainDefinitionMap.put("/css/**", "anon"); | |||
| filterChainDefinitionMap.put("/js/**", "anon"); | |||
| filterChainDefinitionMap.put("/img/**", "anon"); | |||
| filterChainDefinitionMap.put("/font-awesome/**", "anon"); | |||
| // 验证码 | |||
| filterChainDefinitionMap.put("/captcha.jpg", "anon"); | |||
| //<!-- 过滤链定义,从上向下顺序执行,一般将 /**放在最为下边 -->:这是一个坑呢,一不小心代码就不好使了; | |||
| //<!-- authc:所有url都必须认证通过才可以访问; anon:所有url都都可以匿名访问--> | |||
| //自定义加载权限资源关系 | |||
| @@ -116,22 +132,20 @@ public class ShiroConfig { | |||
| // filterChainDefinitionMap.put(resources.getUrl(),permission); | |||
| // } | |||
| // } | |||
| // swagger-ui | |||
| filterChainDefinitionMap.put("/swagger-ui.html", "anon"); | |||
| filterChainDefinitionMap.put("/wxPay/notify/**", "anon"); | |||
| filterChainDefinitionMap.put("/wxOpen/**", "anon"); | |||
| filterChainDefinitionMap.put("/wxPayBill/notify/**", "anon"); | |||
| filterChainDefinitionMap.put("/v2/**", "anon"); | |||
| filterChainDefinitionMap.put("/swagger-resources/**", "anon"); | |||
| filterChainDefinitionMap.put("/webjars/**", "anon"); | |||
| filterChainDefinitionMap.put("/wxMsgCallback/**", "anon"); | |||
| filterChainDefinitionMap.put("/user/sendvalidationcode", "anon"); | |||
| filterChainDefinitionMap.put("/user/updatepwd", "anon"); | |||
| filterChainDefinitionMap.put("/carCallback/**", "anon"); | |||
| filterChainDefinitionMap.put("/wxMallApply/add", "anon"); | |||
| filterChainDefinitionMap.put("/wxMallApply/sendvalidationcode", "anon"); | |||
| filterChainDefinitionMap.put("/captcha.jpg", "anon"); | |||
| filterChainDefinitionMap.put("/version", "anon"); | |||
| filterChainDefinitionMap.put("/wxDeviceScreenAd/**", "anon"); | |||
| // filterChainDefinitionMap.put("/role/**", "corsFilter,token"); | |||
| //配置退出 过滤器,其中的具体的退出代码Shiro已经替我们实现了 | |||
| filterChainDefinitionMap.put("/logout", "authc"); | |||
| filterChainDefinitionMap.put("/**", "corsFilter,token,authc"); | |||
| // filterChainDefinitionMap.put("/**", "anon"); | |||
| @@ -0,0 +1,33 @@ | |||
| package com.iformall.config; | |||
| import me.chanjar.weixin.mp.api.WxMpConfigStorage; | |||
| import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage; | |||
| import me.chanjar.weixin.mp.api.WxMpService; | |||
| import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.context.annotation.Bean; | |||
| import org.springframework.stereotype.Component; | |||
| @Component | |||
| public class WechatMpConfig { | |||
| @Autowired | |||
| private WechatWebProperties wechatWebProperties; | |||
| @Bean | |||
| public WxMpService wxMpService() { | |||
| //创建WxMpService实例并设置appid和sectret | |||
| WxMpService wxMpService = new WxMpServiceImpl(); | |||
| //这里的设置方式是跟着这个sdk的文档写的 | |||
| wxMpService.setWxMpConfigStorage(wxConfigProvider()); | |||
| return wxMpService; | |||
| } | |||
| @Bean | |||
| public WxMpConfigStorage wxConfigProvider(){ | |||
| WxMpInMemoryConfigStorage wxConfigProvider = new WxMpInMemoryConfigStorage(); | |||
| wxConfigProvider.setAppId(wechatWebProperties.getAppId()); | |||
| wxConfigProvider.setSecret(wechatWebProperties.getSecret()); | |||
| return wxConfigProvider; | |||
| } | |||
| } | |||
| @@ -0,0 +1,59 @@ | |||
| package com.iformall.config; | |||
| import org.apache.commons.lang3.builder.ToStringBuilder; | |||
| import org.apache.commons.lang3.builder.ToStringStyle; | |||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||
| import org.springframework.stereotype.Component; | |||
| /** | |||
| * Stormeye | |||
| */ | |||
| @Component | |||
| @ConfigurationProperties(prefix = "wechat.web") | |||
| public class WechatWebProperties { | |||
| /** | |||
| * 设置微信第三方平台-微信登录的web应用appid | |||
| */ | |||
| private String appId; | |||
| /** | |||
| * 设置微信第三方平台-微信登录的web应用app secret | |||
| */ | |||
| private String secret; | |||
| /** | |||
| * 网页URL | |||
| * @return | |||
| */ | |||
| private String url; | |||
| public String getAppId() { | |||
| return appId; | |||
| } | |||
| public void setAppId(String appId) { | |||
| this.appId = appId; | |||
| } | |||
| public String getSecret() { | |||
| return secret; | |||
| } | |||
| public void setSecret(String secret) { | |||
| this.secret = secret; | |||
| } | |||
| public String getUrl() { | |||
| return url; | |||
| } | |||
| public void setUrl(String url) { | |||
| this.url = url; | |||
| } | |||
| @Override | |||
| public String toString() { | |||
| return ToStringBuilder.reflectionToString(this, | |||
| ToStringStyle.MULTI_LINE_STYLE); | |||
| } | |||
| } | |||
| @@ -19,6 +19,7 @@ import javax.servlet.http.HttpServletRequest; | |||
| @RestController | |||
| public class BaseController { | |||
| @InitBinder | |||
| public void InitBinder(WebDataBinder dataBinder) { | |||
| dataBinder.registerCustomEditor(Date.class, new PropertyEditorSupport() { | |||
| @@ -1,25 +1,28 @@ | |||
| package com.iformall.controller; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.google.code.kaptcha.Constants; | |||
| import com.google.code.kaptcha.Producer; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.MallRolePermission; | |||
| import com.iformall.domain.po.MallUserInfo; | |||
| import com.iformall.domain.po.MallUserRole; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.vo.MallUserInfoVo; | |||
| import com.iformall.enums.EnumMallUserStatus; | |||
| import com.iformall.enums.EnumMsgModel; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.MallRolePermissionService; | |||
| import com.iformall.service.MallUserInfoService; | |||
| import com.iformall.service.MallUserRoleService; | |||
| import com.iformall.service.*; | |||
| import com.iformall.shiro.UserSession; | |||
| import com.iformall.shiro.UseriFormallToken; | |||
| import com.iformall.utils.ShiroUtils; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.apache.commons.io.IOUtils; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.apache.shiro.SecurityUtils; | |||
| import org.apache.shiro.authc.DisabledAccountException; | |||
| import org.apache.shiro.authc.UnknownAccountException; | |||
| import org.apache.shiro.authc.UsernamePasswordToken; | |||
| import org.apache.shiro.subject.Subject; | |||
| import org.slf4j.Logger; | |||
| @@ -31,9 +34,13 @@ import org.springframework.web.bind.annotation.*; | |||
| import javax.imageio.ImageIO; | |||
| import javax.servlet.ServletException; | |||
| import javax.servlet.ServletOutputStream; | |||
| import javax.servlet.http.Cookie; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import java.awt.image.BufferedImage; | |||
| import java.io.IOException; | |||
| import java.net.URLEncoder; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| @RestController | |||
| @@ -54,7 +61,10 @@ public class HomeController extends BaseController { | |||
| private MallUserRoleService mallUserRoleService; | |||
| @Autowired | |||
| private MallRolePermissionService mallRolePermissionService; | |||
| private WxAppinfoService appinfoService; | |||
| @Autowired | |||
| private WxMsgValidationcodeService wxMsgValidationcodeService; | |||
| @GetMapping("/captcha.jpg") | |||
| public void captcha(HttpServletResponse response)throws ServletException, IOException { | |||
| @@ -76,7 +86,7 @@ public class HomeController extends BaseController { | |||
| @ApiOperation("登录") | |||
| @PostMapping("/doLogin") | |||
| public ResultData login(@RequestBody MallUserInfo user) { | |||
| public ResultData login(@RequestBody MallUserInfo user, HttpServletResponse response) { | |||
| logger.debug("[" + getIpAddr() + "] HomeController::login"); | |||
| try { | |||
| String kaptcha = ShiroUtils.getKaptcha(Constants.KAPTCHA_SESSION_KEY); | |||
| @@ -92,97 +102,101 @@ public class HomeController extends BaseController { | |||
| ResultData data = new ResultData(); | |||
| if (StringUtils.isBlank(user.getUsername()) || StringUtils.isBlank(user.getPassword())) { | |||
| // throw new SystemException(ErrorCode.LOGIN_USER_OR_PWD_ERROR); | |||
| return new ResultData(ResultData.ERROR, "用户名或者密码错误"); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| // check user | |||
| MallUserInfo userCheck = mallUserInfoService.getByUsername(user.getUsername()); | |||
| if(userCheck == null) { | |||
| logger.error(ErrorCode.USER_IS_EMPTY.getMessage()); | |||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||
| } | |||
| if(userCheck.getStatus().equals(EnumMallUserStatus.NOT_VALID.getCode())) { | |||
| logger.error(ErrorCode.USER_IS_LOCKED.getMessage()); | |||
| return new ResultData(ErrorCode.USER_IS_LOCKED); | |||
| } | |||
| boolean isLogin = false; | |||
| try { | |||
| Subject subject = SecurityUtils.getSubject(); | |||
| UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(), user.getPassword()); | |||
| subject.login(token); | |||
| // List<MallRole> roleList = sysRoleService.findRoleByUserId(user.getId()); | |||
| // if (null != roleList && roleList.size() > 0) { | |||
| // List<MallPermission> permissionList = sysPermissionService | |||
| // .findPermissionByRoleIds(roleList.stream().map(MallRole::getId).collect(Collectors.toList())); | |||
| // user.setRole(roleList); | |||
| // user.setPermission(permissionList); | |||
| // } | |||
| isLogin = true; | |||
| } catch (UnknownAccountException e) { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||
| } catch (DisabledAccountException e) { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(ErrorCode.USER_IS_LOCKED); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(ErrorCode.USER_PASSWD_ERR); | |||
| } | |||
| if(isLogin) { | |||
| MallUserInfo info = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); | |||
| info.setPassword("保密"); | |||
| // System.out.println("id:"+ SecurityUtils.getSubject().getSession().getId()); | |||
| String menus = getPermissionsByRole(info); | |||
| if(StringUtils.isNotBlank(info.getBopenId())) | |||
| info.setBopenId("保密"); | |||
| if(StringUtils.isNotBlank(info.getWebOpenId())) { | |||
| info.setWebOpenId("保密"); | |||
| } | |||
| String menus = mallUserRoleService.getPermissionsByUser(info); | |||
| if(menus != null) { | |||
| info.setMenus(menus); | |||
| } | |||
| data.data = info; | |||
| } catch (Exception e) { | |||
| return new ResultData(ResultData.ERROR, "用户名或者密码错误"); | |||
| } | |||
| 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); | |||
| try { | |||
| String cookieName = URLEncoder.encode(info.getUsername(), "utf-8"); | |||
| Cookie unameCookie = new Cookie("uname", cookieName); | |||
| unameCookie.setMaxAge(3600); | |||
| response.addCookie(unameCookie); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(Result.ERROR, e.getMessage()); | |||
| } | |||
| return menus; | |||
| data.data = info; | |||
| } | |||
| return null; | |||
| return data; | |||
| } | |||
| private boolean isInMobileAdmin(MallUserInfo user) { | |||
| // 检查用户是否有 移动端数据塔台 权限 | |||
| boolean isInMobile = false; | |||
| MallUserRole ur = new MallUserRole(); | |||
| ur.setUid(user.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(user.getTenantId()); | |||
| PageInfo<MallRolePermission> listAsPage = mallRolePermissionService.listAsPage(p, 1, 100); | |||
| for (MallRolePermission rp : listAsPage.getList()) { | |||
| if (rp.getPermissionId().equals(8L)) { /// 移动端数据塔台 | |||
| isInMobile = true; | |||
| } | |||
| } | |||
| } | |||
| isInMobile = mallUserRoleService.checkIsMobileAdmin(user); | |||
| return isInMobile; | |||
| } | |||
| @ApiOperation("B端登录") | |||
| @PostMapping("/bHidLogin") | |||
| public ResultData bLogin(@RequestBody MallUserInfo user) { | |||
| public ResultData bLogin(@RequestBody MallUserInfo user, HttpServletResponse response) { | |||
| logger.debug("[" + getIpAddr() + "] HomeController::bHidLogin"); | |||
| ResultData data = new ResultData(); | |||
| // tenantId is appId | |||
| if(StringUtils.isBlank(user.getTenantId())) { | |||
| logger.error("appid信息未提供"); | |||
| return new ResultData(ErrorCode.MALL_INFO_NOT_FOUND); | |||
| } | |||
| WxAppinfo appinfo = appinfoService.getByAppId(user.getTenantId()); | |||
| if(appinfo == null) { | |||
| logger.error("appid未找到"); | |||
| return new ResultData(ErrorCode.MALL_INFO_NOT_FOUND); | |||
| } | |||
| if(StringUtils.isNotBlank(user.getPhone())) { | |||
| // 领导登录 | |||
| user = mallUserInfoService.getByPhone(user.getPhone()); | |||
| user = mallUserInfoService.getByPhone(user.getPhone(), appinfo.getTenantId()); | |||
| if(user == null || !isInMobileAdmin(user)) { | |||
| return new ResultData(ErrorCode.USER_NOT_ADMIN); | |||
| return new ResultData(ErrorCode.USER_NO_PERMISSION); | |||
| } | |||
| } else if(StringUtils.isNotBlank(user.getOpenId())) { | |||
| } else if(StringUtils.isNotBlank(user.getBopenId())) { | |||
| // 领导登录 | |||
| user = mallUserInfoService.getByOpenId(user.getOpenId()); | |||
| user = mallUserInfoService.getByBOpenId(user.getBopenId(), appinfo.getTenantId()); | |||
| if(user == null || !isInMobileAdmin(user)) { | |||
| return new ResultData(ErrorCode.USER_NOT_ADMIN); | |||
| return new ResultData(ErrorCode.USER_NO_PERMISSION); | |||
| } | |||
| } else { | |||
| if (StringUtils.isEmpty(user.getUsername()) || StringUtils.isEmpty(user.getPassword())) { | |||
| // throw new SystemException(ErrorCode.LOGIN_USER_OR_PWD_ERROR); | |||
| return new ResultData(ResultData.ERROR, "用户名或者密码错误"); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| } | |||
| @@ -190,27 +204,128 @@ public class HomeController extends BaseController { | |||
| Subject subject = SecurityUtils.getSubject(); | |||
| UseriFormallToken token = new UseriFormallToken(user.getUsername()); | |||
| subject.login(token); | |||
| // List<MallRole> roleList = sysRoleService.findRoleByUserId(user.getId()); | |||
| // if (null != roleList && roleList.size() > 0) { | |||
| // List<MallPermission> permissionList = sysPermissionService | |||
| // .findPermissionByRoleIds(roleList.stream().map(MallRole::getId).collect(Collectors.toList())); | |||
| // user.setRole(roleList); | |||
| // user.setPermission(permissionList); | |||
| // } | |||
| MallUserInfo info = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); | |||
| info.setPassword("保密"); | |||
| // System.out.println("id:"+ SecurityUtils.getSubject().getSession().getId()); | |||
| String menus = getPermissionsByRole(info); | |||
| if(StringUtils.isNotBlank(info.getBopenId())) | |||
| info.setBopenId("保密"); | |||
| if(StringUtils.isNotBlank(info.getWebOpenId())) { | |||
| info.setWebOpenId("保密"); | |||
| } | |||
| String menus = mallUserRoleService.getPermissionsByUser(info); | |||
| if(menus != null) { | |||
| info.setMenus(menus); | |||
| } | |||
| String cookieName = URLEncoder.encode(info.getUsername(), "utf-8"); | |||
| Cookie unameCookie = new Cookie("uname", cookieName); | |||
| unameCookie.setMaxAge(3600); | |||
| response.addCookie(unameCookie); | |||
| data.data = info; | |||
| } catch (MallinkException e) { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| return new ResultData(ResultData.ERROR, "用户名或者密码错误"); | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(ErrorCode.USER_PASSWD_ERR); | |||
| } | |||
| return data; | |||
| } | |||
| @GetMapping("sendLoginPhoneCode") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "phone", value = "手机号", dataType = "String", paramType = "query", required = true)}) | |||
| public ResultData sendLoginPhoneCode(String phone) { | |||
| logger.debug("[" + getIpAddr() + "] HomeController::sendlogincode"); | |||
| // 1. 检查手机号是否在用户列表里, 是否只有一个 | |||
| // 2. 发送手机验证码, 直接发 | |||
| List<MallUserInfoVo> users = mallUserInfoService.getUserByPhone(phone); | |||
| if(users.size() <= 0) { | |||
| logger.error(ErrorCode.USER_IS_EMPTY.getMessage()); | |||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||
| } | |||
| if(users.size() > 1) { | |||
| logger.error(ErrorCode.USER_IS_MULTI.getMessage()); | |||
| return new ResultData(ErrorCode.USER_IS_MULTI); | |||
| } | |||
| MallUserInfoVo user = users.get(0); | |||
| if (user==null) { | |||
| logger.error("用户不存在, userName: " + user.getUsername()); | |||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||
| } | |||
| if(user.getStatus() == EnumMallUserStatus.NOT_VALID.getCode()){ | |||
| logger.error("用户已停用, userName: " + user.getUsername()); | |||
| return new ResultData(ErrorCode.USER_IS_LOCKED); | |||
| } | |||
| WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | |||
| wxMsgValidationcode.setPhone(phone); | |||
| wxMsgValidationcode.setTenantId(user.getTenantId()); | |||
| wxMsgValidationcode.setType(EnumMsgModel.VALIDATION_CODE.getCode()); | |||
| return wxMsgValidationcodeService.sendvalidationcode(wxMsgValidationcode); | |||
| } | |||
| @ApiOperation(value = "手机验证码登录", notes = "{\"phone\",\"string\",\"code\",\"string\"}") | |||
| @PostMapping("/doLoginByPhone") | |||
| public ResultData doLoginByPhone(@RequestBody Map<String, String> params, HttpServletResponse response) { | |||
| logger.debug("[" + getIpAddr() + "] HomeController::doLoginByPhone"); | |||
| // String phone,String code,String pwd | |||
| String phone = params.get("phone"); | |||
| String code = params.get("code"); | |||
| if (StringUtils.isBlank(phone)) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "userName不能为空"); | |||
| } | |||
| if (StringUtils.isBlank(code)) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "验证码不能为空"); | |||
| } | |||
| // 获取用户信息列表 | |||
| List<MallUserInfoVo> userList = mallUserInfoService.getUserByPhone(phone); | |||
| if(userList.size() == 1) { | |||
| MallUserInfoVo user = userList.get(0); | |||
| // check 验证码正确 | |||
| boolean isValidCode = false; | |||
| try { | |||
| isValidCode = mallUserInfoService.checkCodeValid(user, code); | |||
| } catch (Exception e) { | |||
| return new ResultData(Result.ERROR, e.getMessage()); | |||
| } | |||
| if(isValidCode) { | |||
| // 验证码正确,直接登录 | |||
| try { | |||
| Subject subject = SecurityUtils.getSubject(); | |||
| UseriFormallToken token = new UseriFormallToken(user.getUsername()); | |||
| subject.login(token); | |||
| MallUserInfo info = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); | |||
| info.setPassword("保密"); | |||
| if(StringUtils.isNotBlank(info.getBopenId())) | |||
| info.setBopenId("保密"); | |||
| if(StringUtils.isNotBlank(info.getWebOpenId())) { | |||
| info.setWebOpenId("保密"); | |||
| } | |||
| String menus = mallUserRoleService.getPermissionsByUser(info); | |||
| if(menus != null) { | |||
| info.setMenus(menus); | |||
| } | |||
| String cookieName = URLEncoder.encode(info.getUsername(), "utf-8"); | |||
| Cookie unameCookie = new Cookie("uname", cookieName); | |||
| unameCookie.setMaxAge(3600); | |||
| response.addCookie(unameCookie); | |||
| return new ResultData(info); | |||
| } catch (MallinkException e) { | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| return new ResultData(ErrorCode.USER_PASSWD_ERR); | |||
| } | |||
| } else { | |||
| return new ResultData(ErrorCode.MSG_VERIFY_CODE_NOT_FOUND); | |||
| } | |||
| } else { | |||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||
| } | |||
| } | |||
| @ApiOperation("登出") | |||
| @GetMapping("/logout") | |||
| public ResultData logout() { | |||
| @@ -5,9 +5,11 @@ import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.vo.MallUserInfoVo; | |||
| import com.iformall.enums.EnumMallUserStatus; | |||
| import com.iformall.enums.EnumUserAdmin; | |||
| import com.iformall.enums.EnumFlowPermissionType; | |||
| import com.iformall.enums.EnumUserWechat; | |||
| import com.iformall.service.*; | |||
| import com.iformall.shiro.PasswordHelper; | |||
| import com.iformall.shiro.UserSession; | |||
| @@ -24,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.util.Assert; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import javax.print.DocFlavor; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| @@ -81,7 +84,12 @@ public class MallUserInfoController extends BaseController { | |||
| u.setRoleId(role.getId()); | |||
| } | |||
| } | |||
| u.setPassword(null);//不返回密码 | |||
| // 保密 | |||
| u.setPassword(null); | |||
| u.setBopenId(null); | |||
| if(StringUtils.isNotBlank(u.getWebOpenId())) { | |||
| u.setWebOpenId("保密"); | |||
| } | |||
| } | |||
| return new ResultData(page); | |||
| } | |||
| @@ -91,6 +99,12 @@ public class MallUserInfoController extends BaseController { | |||
| public ResultData detail(Long id) { | |||
| logger.debug("[" + getIpAddr() + "] MallUserInfoController::detail"); | |||
| final MallUserInfo user = userInfoService.getById(id); | |||
| user.setPassword(null); | |||
| user.setBopenId(null); | |||
| if(StringUtils.isNotBlank(user.getWebOpenId())) { | |||
| user.setWebOpenId("保密"); | |||
| } | |||
| return new ResultData(user); | |||
| } | |||
| @@ -103,10 +117,10 @@ public class MallUserInfoController extends BaseController { | |||
| return new ResultData(ErrorCode.USER_NOT_ADMIN.getCode(), "只有超级管理员才能添加用户"); | |||
| } | |||
| if(checkUniqueName(userInfo.getUsername(), currentUser.getTenantId()) > 0){ | |||
| if(checkUniqueName(userInfo.getUsername()) > 0){ | |||
| return new ResultData(ErrorCode.USER_NAME_IS_FOUND.getCode(),"用户名已存在"); | |||
| } | |||
| if(checkUniquePhone(userInfo.getPhone(), currentUser.getTenantId()) > 0){ | |||
| if(checkUniquePhone(userInfo.getPhone()) > 0){ | |||
| return new ResultData(ErrorCode.USER_PHONE_IS_FOUND.getCode(),"手机号已存在"); | |||
| } | |||
| Assert.notNull(userInfo.getPassword(), "密码不能为空"); | |||
| @@ -137,12 +151,12 @@ public class MallUserInfoController extends BaseController { | |||
| } | |||
| MallUserInfo oldUser = userInfoService.getById(userInfo.getId()); | |||
| if (!oldUser.getUsername().equals(userInfo.getUsername())) { | |||
| if(checkUniqueName(userInfo.getUsername(), currentUser.getTenantId()) > 0){ | |||
| if(checkUniqueName(userInfo.getUsername()) > 0){ | |||
| return new ResultData(ErrorCode.USER_NAME_IS_FOUND.getCode(),"用户名已存在"); | |||
| } | |||
| } | |||
| if (!oldUser.getPhone().equals(userInfo.getPhone())) { | |||
| if(checkUniquePhone(userInfo.getPhone(), currentUser.getTenantId()) > 0){ | |||
| if(checkUniquePhone(userInfo.getPhone()) > 0){ | |||
| return new ResultData(ErrorCode.USER_PHONE_IS_FOUND.getCode(),"手机号已存在"); | |||
| } | |||
| } | |||
| @@ -211,36 +225,39 @@ public class MallUserInfoController extends BaseController { | |||
| /** | |||
| * 启用,停用用户 | |||
| * | |||
| * @param userId | |||
| * @param status | |||
| * @return | |||
| */ | |||
| @ApiOperation(value = "起停用户接口", response = String.class) | |||
| @GetMapping("status") | |||
| public ResultData modifyStatus(Long userId, Integer status) { | |||
| @ApiOperation(value = "起停用户接口") | |||
| @PostMapping("updateStatus") | |||
| public ResultData modifyStatus(@RequestBody MallUserInfo userInfo) { | |||
| logger.debug("[" + getIpAddr() + "] MallUserInfoController::modifyStatus"); | |||
| MallUserInfo currentUser = getUser(); | |||
| if (currentUser.getIsAdmin().equals(EnumUserAdmin.Normal.getCode())) { | |||
| return new ResultData(ErrorCode.USER_NOT_ADMIN.getCode(), "只有超级管理员才能删除用户"); | |||
| if (currentUser.getIsAdmin().equals(EnumUserAdmin.ADMIN.getCode())) { | |||
| MallUserInfo userInfo1 = userInfoService.getById(userInfo.getId()); | |||
| if(userInfo1 == null) { | |||
| logger.error(ErrorCode.USER_IS_EMPTY.getMessage()); | |||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||
| } | |||
| MallUserInfo updateUserInfo = new MallUserInfo(); | |||
| updateUserInfo.setId(userInfo.getId()); | |||
| updateUserInfo.setTenantId(getTenantId()); | |||
| updateUserInfo.setStatus(userInfo.getStatus()); | |||
| userInfoService.saveOrUpdate(userInfo); | |||
| return new ResultData(); | |||
| } else { | |||
| return new ResultData(ErrorCode.USER_NO_PERMISSION); | |||
| } | |||
| MallUserInfo userInfo = userInfoService.getById(userId); | |||
| userInfo.setStatus(status); | |||
| userInfo.setTenantId(getTenantId()); | |||
| userInfoService.saveOrUpdate(userInfo); | |||
| return new ResultData(userInfo); | |||
| } | |||
| private int checkUniqueName(String userName, String tenantId) { | |||
| private int checkUniqueName(String userName) { | |||
| MallUserInfo userQ = new MallUserInfo(); | |||
| userQ.setUsername(userName); | |||
| userQ.setTenantId(tenantId); | |||
| return userInfoService.cntUserList(userQ); | |||
| } | |||
| private int checkUniquePhone(String phone, String tenantId) { | |||
| private int checkUniquePhone(String phone) { | |||
| MallUserInfo userQ = new MallUserInfo(); | |||
| userQ.setPhone(phone); | |||
| userQ.setTenantId(tenantId); | |||
| return userInfoService.cntUserList(userQ); | |||
| } | |||
| @@ -392,4 +409,5 @@ public class MallUserInfoController extends BaseController { | |||
| resultMap.put("billUserList",billUserList); | |||
| return new ResultData(resultMap); | |||
| } | |||
| } | |||
| @@ -0,0 +1,338 @@ | |||
| package com.iformall.controller; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.MallUserInfo; | |||
| import com.iformall.domain.vo.MallUserInfoVo; | |||
| import com.iformall.enums.EnumUserAdmin; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.MallUserInfoService; | |||
| import com.iformall.service.MallUserRoleService; | |||
| import com.iformall.shiro.UserSession; | |||
| import com.iformall.shiro.UseriFormallToken; | |||
| import com.iformall.utils.TOTP; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import lombok.Data; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import me.chanjar.weixin.common.error.WxErrorException; | |||
| import me.chanjar.weixin.mp.api.WxMpService; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | |||
| import me.chanjar.weixin.mp.bean.result.WxMpUser; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.apache.shiro.SecurityUtils; | |||
| import org.apache.shiro.authc.DisabledAccountException; | |||
| import org.apache.shiro.authc.UnknownAccountException; | |||
| import org.apache.shiro.subject.Subject; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.beans.factory.annotation.Qualifier; | |||
| import org.springframework.data.redis.core.RedisTemplate; | |||
| import org.springframework.stereotype.Controller; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import javax.servlet.http.Cookie; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import java.io.IOException; | |||
| import java.net.URLEncoder; | |||
| import java.util.ArrayList; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import java.util.concurrent.TimeUnit; | |||
| @Controller | |||
| @RequestMapping("/wechat") | |||
| @Slf4j | |||
| public class WechatLoginController extends BaseController { | |||
| private String WECHAT_PREV = "OPEN-"; | |||
| @Autowired | |||
| private WxMpService wxMpService; | |||
| @Autowired | |||
| private MallUserInfoService mallUserInfoService; | |||
| @Autowired | |||
| private MallUserRoleService mallUserRoleService; | |||
| @Autowired | |||
| @Qualifier("openRedisTemplate") | |||
| RedisTemplate<String, String> openRedisTemplate; | |||
| @Data | |||
| private class DisplayUserInfo { | |||
| String mallName; | |||
| String userName; | |||
| String userRole; | |||
| } | |||
| @ApiOperation(value = "微信网页登录回调", notes = "请配置此callback到网页redirect_uri") | |||
| @GetMapping("callback") | |||
| @ResponseBody | |||
| public void getAccessToken(String code, String state, HttpServletRequest request, HttpServletResponse response) { | |||
| log.debug("[" + getIpAddr() + "] WechatLoginController::getAccessToken"); | |||
| String host = request.getHeader("host"); | |||
| log.debug("host: " + host); | |||
| log.debug("code: " + code); | |||
| try { | |||
| WxMpOAuth2AccessToken accessToken = wxMpService.oauth2getAccessToken(code); | |||
| log.debug("accessToken: " + accessToken.getAccessToken() + ", openId: " + accessToken.getOpenId() + ", unionId: " + accessToken.getUnionId()); | |||
| // 获取 用户信息 | |||
| WxMpUser mpUser = wxMpService.oauth2getUserInfo(accessToken, null); | |||
| if(mpUser != null) { | |||
| log.debug(mpUser.toString()); | |||
| } | |||
| // check user openid 是否是已授权用户 | |||
| List<MallUserInfoVo> userList = mallUserInfoService.getUsersByWebOpenId(accessToken.getOpenId()); | |||
| log.info("login user list count " + userList.size()); | |||
| if(userList.size() > 0) { | |||
| if(userList.size() == 1) { | |||
| Map<String, Object> ret = new HashMap<>(); | |||
| // 唯一用户 | |||
| MallUserInfo user = userList.get(0); | |||
| boolean isLogin = false; | |||
| try { | |||
| Subject subject = SecurityUtils.getSubject(); | |||
| UseriFormallToken token = new UseriFormallToken(user.getUsername()); | |||
| subject.login(token); | |||
| isLogin = true; | |||
| } catch (UnknownAccountException e) { | |||
| log.error(e.getMessage()); | |||
| ret.put("code", ErrorCode.USER_IS_EMPTY.getCode()); | |||
| ret.put("message", e.getMessage()); | |||
| } catch (DisabledAccountException e) { | |||
| log.error(e.getMessage()); | |||
| ret.put("code", ErrorCode.USER_IS_LOCKED.getCode()); | |||
| ret.put("message", e.getMessage()); | |||
| } catch (Exception e) { | |||
| log.error(e.getMessage()); | |||
| ret.put("code", Result.ERROR); | |||
| ret.put("message", e.getMessage()); | |||
| } | |||
| if(isLogin) { | |||
| MallUserInfo info = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); | |||
| info.setPassword("保密"); | |||
| info.setBopenId("保密"); | |||
| if(StringUtils.isNotBlank(info.getWebOpenId())) { | |||
| info.setWebOpenId("保密"); | |||
| } | |||
| String menus = mallUserRoleService.getPermissionsByUser(info); | |||
| if(menus != null) { | |||
| info.setMenus(menus); | |||
| } | |||
| try { | |||
| String cookieName = URLEncoder.encode(info.getUsername(), "utf-8"); | |||
| Cookie unameCookie = new Cookie("uname", cookieName); | |||
| unameCookie.setMaxAge(3600); | |||
| response.addCookie(unameCookie); | |||
| } catch (Exception e) { | |||
| log.error(e.getMessage()); | |||
| ret.put("code", Result.ERROR); | |||
| ret.put("message", e.getMessage()); | |||
| } | |||
| Object codeObj = ret.get("code"); | |||
| if(codeObj == null) { | |||
| try { | |||
| response.sendRedirect("https://" + host + "/#/layout"); | |||
| } catch (Exception e) { | |||
| log.error(e.getMessage()); | |||
| } | |||
| } else { | |||
| try { | |||
| String errCode = URLEncoder.encode(JSON.toJSONString(ret), "utf-8"); | |||
| response.sendRedirect("https://" + host + "/#/login?errcode=" + errCode); | |||
| } catch (Exception e) { | |||
| log.error(e.getMessage()); | |||
| } | |||
| } | |||
| } else { | |||
| try { | |||
| String errCode = URLEncoder.encode(JSON.toJSONString(ret), "utf-8"); | |||
| response.sendRedirect("https://" + host + "/#/login?errcode="+errCode); | |||
| } catch (Exception e) { | |||
| log.error(e.getMessage()); | |||
| } | |||
| } | |||
| } else { | |||
| // 跳转登录选择页面 | |||
| String key = TOTP.generateWechatOpen(accessToken.getOpenId()); | |||
| if (openRedisTemplate.opsForValue().setIfAbsent(WECHAT_PREV + key, accessToken.getOpenId())){ | |||
| openRedisTemplate.expire(key, 30, TimeUnit.SECONDS); | |||
| } | |||
| List<DisplayUserInfo> users = new ArrayList<DisplayUserInfo>(); | |||
| for(MallUserInfoVo user: userList) { | |||
| DisplayUserInfo disUser = new DisplayUserInfo(); | |||
| disUser.setMallName(user.getMallName()); | |||
| disUser.setUserName(user.getUsername()); | |||
| disUser.setUserRole(user.getRoleName()); | |||
| users.add(disUser); | |||
| } | |||
| String usersStr = JSON.toJSONString(users); | |||
| log.info(usersStr); | |||
| try { | |||
| usersStr = URLEncoder.encode(usersStr, "utf-8"); | |||
| response.sendRedirect("https://" + host + "/#/loginselect?key=" + key + "&list=" + usersStr); | |||
| } catch (Exception e) { | |||
| log.error(e.getMessage()); | |||
| } | |||
| } | |||
| } else { | |||
| // 跳转登录页面 | |||
| Map<String, Object> ret = new HashMap<>(); | |||
| ret.put("code", ErrorCode.WECHAT_LOGIN_NOT_BIND.getCode()); | |||
| ret.put("message", ErrorCode.WECHAT_LOGIN_NOT_BIND.getMessage()); | |||
| try { | |||
| String errCode = URLEncoder.encode(JSON.toJSONString(ret), "utf-8"); | |||
| response.sendRedirect("https://" + host + "/#/login?errcode="+errCode); | |||
| } catch (Exception e) { | |||
| log.error(e.getMessage()); | |||
| } | |||
| } | |||
| //return r; | |||
| } catch (WxErrorException e) { | |||
| log.error(e.getMessage()); | |||
| } | |||
| } | |||
| @ApiOperation(value = "微信用户登录") | |||
| @GetMapping("weChatUserLogin") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "key", value = "key", dataType = "String", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "userName", value = "userName", dataType = "String", paramType = "query", required = true)}) | |||
| public ResultData weChatUserLogin(String key, String userName, HttpServletRequest request, HttpServletResponse response) { | |||
| log.debug("[" + getIpAddr() + "] MallUserInfoController::weChatUserLogin"); | |||
| String host = request.getHeader("host"); | |||
| log.debug("Host: " + host); | |||
| if(StringUtils.isBlank(userName)) { | |||
| log.error("请选择要登录的用户"); | |||
| return new ResultData(ErrorCode.WECHAT_LOGIN_USER_SELECT); | |||
| } | |||
| String openKey = WECHAT_PREV + key; | |||
| // 限时时间内查找到此用户openId | |||
| if (openRedisTemplate.hasKey(WECHAT_PREV + key)){ | |||
| String openId = openRedisTemplate.opsForValue().get(openKey); | |||
| // 删除缓存 | |||
| openRedisTemplate.delete(openKey); | |||
| MallUserInfo userInfo = mallUserInfoService.getByUsername(userName); | |||
| if(userInfo.getWebOpenId().equals(openId)) { | |||
| boolean isLogin = false; | |||
| try { | |||
| Subject subject = SecurityUtils.getSubject(); | |||
| UseriFormallToken token = new UseriFormallToken(userInfo.getUsername()); | |||
| subject.login(token); | |||
| MallUserInfo info = (MallUserInfo) SecurityUtils.getSubject().getSession().getAttribute(UserSession.userInfo); | |||
| info.setPassword("保密"); | |||
| info.setBopenId("保密"); | |||
| if(StringUtils.isNotBlank(info.getWebOpenId())) { | |||
| info.setWebOpenId("保密"); | |||
| } | |||
| String menus = mallUserRoleService.getPermissionsByUser(info); | |||
| if(menus != null) { | |||
| info.setMenus(menus); | |||
| } | |||
| // 登录cookie | |||
| String cookieName = URLEncoder.encode(info.getUsername(), "utf-8"); | |||
| Cookie unameCookie = new Cookie("uname", cookieName); | |||
| unameCookie.setMaxAge(3600); | |||
| response.addCookie(unameCookie); | |||
| return new ResultData(); | |||
| } catch (UnknownAccountException e) { | |||
| log.error(e.getMessage()); | |||
| return new ResultData(ErrorCode.USER_IS_EMPTY.getCode(), e.getMessage()); | |||
| } catch (DisabledAccountException e) { | |||
| log.error(e.getMessage()); | |||
| return new ResultData(ErrorCode.USER_IS_LOCKED.getCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| log.error(e.getMessage()); | |||
| return new ResultData(Result.ERROR, e.getMessage()); | |||
| } | |||
| } else { | |||
| // 登录失败 | |||
| log.error("微信登录失败,未找到对应的openId"); | |||
| return new ResultData(ErrorCode.WECHAT_LOGIN_KEY_OVERTIME); | |||
| } | |||
| } | |||
| return new ResultData(ErrorCode.WECHAT_LOGIN_KEY_OVERTIME); | |||
| } | |||
| @ApiOperation(value = "微信第三方登录绑定", notes = "请配置此callback到网页redirect_uri") | |||
| @GetMapping("bindWebOpenId") | |||
| public void userBindWebOpenId(String code, String state, HttpServletRequest request, HttpServletResponse response) { | |||
| log.debug("[" + getIpAddr() + "] WechatLoginController::bindWebOpenId"); | |||
| String host = request.getHeader("host"); | |||
| String errCode = null; | |||
| try { | |||
| WxMpOAuth2AccessToken accessToken = wxMpService.oauth2getAccessToken(code); | |||
| log.debug("accessToken: " + accessToken.getAccessToken() + ", openId: " + accessToken.getOpenId() + ", unionId: " + accessToken.getUnionId()); | |||
| // 获取 用户信息 | |||
| WxMpUser mpUser = wxMpService.oauth2getUserInfo(accessToken, null); | |||
| if(mpUser != null) { | |||
| log.debug(mpUser.toString()); | |||
| } | |||
| String uname = state; | |||
| MallUserInfo user = mallUserInfoService.getByUsername(uname); | |||
| if(user != null) { | |||
| user.setWebOpenId(accessToken.getOpenId()); | |||
| mallUserInfoService.updateWebOpenId(user); | |||
| log.debug("https://" + host + "/#/layout"); | |||
| response.sendRedirect("https://" + host + "/#/layout"); | |||
| } else { | |||
| log.debug("https://" + host + "/#/layout?errcode=绑定失败"); | |||
| errCode = URLEncoder.encode("绑定失败", "utf-8"); | |||
| response.sendRedirect("https://" + host + "/#/layout?errcode="+errCode); | |||
| } | |||
| } catch (WxErrorException e) { | |||
| log.error(e.getMessage()); | |||
| errCode = e.getMessage(); | |||
| } catch (IOException e) { | |||
| log.error(e.getMessage()); | |||
| errCode = e.getMessage(); | |||
| } | |||
| if(StringUtils.isNotBlank(errCode)) { | |||
| try { | |||
| errCode = URLEncoder.encode(errCode, "utf-8"); | |||
| response.sendRedirect("https://" + host + "/#/layout?errcode="+errCode); | |||
| } catch (Exception e) { | |||
| log.error(e.getMessage()); | |||
| } | |||
| } | |||
| } | |||
| @ApiOperation(value = "微信第三方登录解绑", notes = "请配置此callback到网页redirect_uri") | |||
| @GetMapping("cleanWebOpenId") | |||
| public ResultData cleanWebOpenId(@ModelAttribute MallUserInfo userInfo) { | |||
| log.debug("[" + getIpAddr() + "] WechatLoginController::cleanWebOpenId"); | |||
| MallUserInfo user = getUser(); | |||
| if(userInfo == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| if(StringUtils.isBlank(userInfo.getTenantId())) { | |||
| userInfo.setTenantId(user.getTenantId()); | |||
| } | |||
| if(userInfo.getId() == null && userInfo.getUsername() == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| // 只有本人及超级管理员可以解绑微信 | |||
| if(userInfo.getId().equals(user.getId()) | |||
| || user.getIsAdmin().equals(EnumUserAdmin.ADMIN.getCode())) { | |||
| mallUserInfoService.cleanWebOpenId(userInfo); | |||
| return new ResultData(); | |||
| } else { | |||
| return new ResultData(ErrorCode.USER_NO_PERMISSION); | |||
| } | |||
| } | |||
| } | |||
| @@ -75,12 +75,12 @@ public class WxAppinfoController extends BaseController { | |||
| } | |||
| @ApiOperation("更新AccessToken, 无限制二维码生成需要更新token") | |||
| @ApiOperation("C端更新AccessToken, 无限制二维码生成需要更新token") | |||
| @GetMapping("/accessTokenUpdate") | |||
| public ResultData tokenUpdate() { | |||
| logger.debug("[" + getIpAddr() + "] WxAppinfoController::tokenUpdate"); | |||
| public ResultData ctokenUpdate() { | |||
| logger.debug("[" + getIpAddr() + "] WxAppinfoController::ctokenUpdate"); | |||
| try { | |||
| wxAppinfoService.tokenUpdate(getTenantId()); | |||
| wxAppinfoService.ctokenUpdate(getTenantId()); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| @@ -49,5 +49,13 @@ public class WxBillAllController extends BaseController | |||
| wxBillAllService.exportBill(request,response,wxBillAll); | |||
| } | |||
| @GetMapping("getBillInfo") | |||
| public ResultData getBillInfo(@ModelAttribute WxBillAll wxBillAll) { | |||
| wxBillAll.setTenantId(getTenantId()); | |||
| Object billInfo = wxBillAllService.getBillInfo(wxBillAll); | |||
| return new ResultData(billInfo); | |||
| } | |||
| } | |||
| @@ -76,5 +76,19 @@ public class WxBillDepositController extends BaseController { | |||
| return wxBillDepositService.updatePaid(id); | |||
| } | |||
| @PostMapping("returnDeposit") | |||
| public ResultData returnDeposit(@RequestBody WxBillDeposit wxBillDeposit) { | |||
| logger.debug("[" + getIpAddr() + "] WxBillDepositController::returnDeposit"); | |||
| return wxBillDepositService.returnDeposit(wxBillDeposit); | |||
| } | |||
| @PostMapping("adjustDeposit") | |||
| public ResultData adjustDeposit(@RequestBody WxBillDeposit wxBillDeposit) { | |||
| logger.debug("[" + getIpAddr() + "] WxBillDepositController::adjustDeposit"); | |||
| return wxBillDepositService.adjustDeposit(wxBillDeposit); | |||
| } | |||
| } | |||
| @@ -76,5 +76,18 @@ public class WxBillOtherDepositController extends BaseController { | |||
| return wxBillOtherDepositService.updatePaid(id); | |||
| } | |||
| @PostMapping("returnDeposit") | |||
| public ResultData returnDeposit(@RequestBody WxBillOtherDeposit wxBillDeposit) { | |||
| logger.debug("[" + getIpAddr() + "] WxBillOtherDepositController::returnDeposit"); | |||
| return wxBillOtherDepositService.returnDeposit(wxBillDeposit); | |||
| } | |||
| @PostMapping("adjustDeposit") | |||
| public ResultData adjustDeposit(@RequestBody WxBillOtherDeposit wxBillDeposit) { | |||
| logger.debug("[" + getIpAddr() + "] WxBillOtherDepositController::adjustDeposit"); | |||
| return wxBillOtherDepositService.adjustDeposit(wxBillDeposit); | |||
| } | |||
| } | |||
| @@ -35,6 +35,7 @@ public class WxBillPropertyController extends BaseController { | |||
| wxBillProperty = new WxBillProperty(); | |||
| } | |||
| wxBillProperty.setTenantId(getTenantId()); | |||
| wxBillProperty.setSortColumns(WxBillProperty.Field.Id_DESC); | |||
| PageInfo<Map<String, Object>> result = wxBillPropertyService.listAsPage(wxBillProperty, pageNum, pageSize); | |||
| return new ResultData(result); | |||
| } | |||
| @@ -76,5 +77,21 @@ public class WxBillPropertyController extends BaseController { | |||
| return wxBillPropertyService.updatePaid(id); | |||
| } | |||
| @GetMapping("/detail") | |||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||
| public ResultData detail(Long id) { | |||
| logger.debug("[" + getIpAddr() + "] WxBillPropertyController::detail"); | |||
| return new ResultData(Result.SUCCESS, "查询成功", wxBillPropertyService.detail(id)); | |||
| } | |||
| @GetMapping("/findByPropertyContractId") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "propertyContractId", value = "merchantId", dataType = "Long", 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 findByPropertyContractId(Long propertyContractId, Integer pageNum, Integer pageSize) { | |||
| logger.debug("[" + getIpAddr() + "] WxBillPropertyController::findByPropertyContractId"); | |||
| final PageInfo<Map<String, Object>> page = wxBillPropertyService.findByPropertyContractId(propertyContractId, getTenantId(), pageNum, pageSize); | |||
| return new ResultData(page); | |||
| } | |||
| } | |||
| @@ -3,6 +3,7 @@ package com.iformall.controller; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxBillOtherDeposit; | |||
| import com.iformall.domain.po.WxBillPropertyDeposit; | |||
| import com.iformall.service.WxBillPropertyDepositService; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| @@ -51,8 +52,7 @@ public class WxBillPropertyDepositController extends BaseController | |||
| @PostMapping("update") | |||
| public ResultData update(@RequestBody WxBillPropertyDeposit wxBillPropertyDeposit) { | |||
| logger.debug("[" + getIpAddr() + "] WxBillPropertyDepositController::update"); | |||
| wxBillPropertyDepositService.saveOrUpdate(wxBillPropertyDeposit); | |||
| return new ResultData(); | |||
| return wxBillPropertyDepositService.saveOrUpdate(wxBillPropertyDeposit); | |||
| } | |||
| @GetMapping("/del") | |||
| @@ -76,6 +76,22 @@ public class WxBillPropertyDepositController extends BaseController | |||
| logger.debug("[" + getIpAddr() + "] WxBillPropertyDepositController::updatePaid"); | |||
| return wxBillPropertyDepositService.updatePaid(id); | |||
| } | |||
| @PostMapping("returnDeposit") | |||
| public ResultData returnDeposit(@RequestBody WxBillPropertyDeposit wxBillPropertyDeposit) { | |||
| logger.debug("[" + getIpAddr() + "] WxBillPropertyDepositController::returnDeposit"); | |||
| return wxBillPropertyDepositService.returnDeposit(wxBillPropertyDeposit); | |||
| } | |||
| @PostMapping("adjustDeposit") | |||
| public ResultData adjustDeposit(@RequestBody WxBillPropertyDeposit wxBillPropertyDeposit) { | |||
| logger.debug("[" + getIpAddr() + "] WxBillPropertyDepositController::adjustDeposit"); | |||
| return wxBillPropertyDepositService.adjustDeposit(wxBillPropertyDeposit); | |||
| } | |||
| } | |||
| @@ -68,11 +68,15 @@ public class WxBillRentController extends BaseController { | |||
| return new ResultData(Result.SUCCESS, "查询成功", wxBillRentService.getById(id)); | |||
| } | |||
| @GetMapping("/findByMerchantId") | |||
| @ApiImplicitParam(name = "merchantId", value = "merchantId", dataType = "Long", paramType = "query", required = true) | |||
| public ResultData findByMerchantId(Long merchantId) { | |||
| logger.debug("[" + getIpAddr() + "] WxBillRentController::findByMerchantId"); | |||
| return new ResultData(Result.SUCCESS, "查询成功", wxBillRentService.findByMerchantId(merchantId)); | |||
| @GetMapping("/findByRentContractId") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "rentContractId", value = "merchantId", dataType = "Long", 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 findByRentContractId(Long rentContractId, Integer pageNum, Integer pageSize) { | |||
| logger.debug("[" + getIpAddr() + "] WxBillRentController::findByRentContractId"); | |||
| final PageInfo<Map<String, Object>> page = wxBillRentService.findByRentContractId(rentContractId, getTenantId(), pageNum, pageSize); | |||
| return new ResultData(page); | |||
| } | |||
| @GetMapping("/updatePaid") | |||
| @@ -82,4 +86,18 @@ public class WxBillRentController extends BaseController { | |||
| return wxBillRentService.updatePaid(id); | |||
| } | |||
| @GetMapping("/detail") | |||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||
| public ResultData detail(Long id) { | |||
| logger.debug("[" + getIpAddr() + "] WxBillRentController::detail"); | |||
| return new ResultData(Result.SUCCESS, "查询成功", wxBillRentService.detail(id)); | |||
| } | |||
| @PostMapping("updateRevenue") | |||
| public ResultData updateRevenue(@RequestBody WxBillRent wxBillRent) { | |||
| logger.debug("[" + getIpAddr() + "] WxBillRentController::updateRevenue"); | |||
| return wxBillRentService.updateRevenue(wxBillRent); | |||
| } | |||
| } | |||
| @@ -218,7 +218,7 @@ public class WxCUserBasicInfoController extends BaseController { | |||
| public ResultData findOrderCouponByUserId(Long userId, Integer pageNum, Integer pageSize) { | |||
| logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::findOrderCouponByUserId"); | |||
| WxCouponOrder corder = new WxCouponOrder(); | |||
| corder.setCUserId(userId); | |||
| corder.setcUserId(userId); | |||
| corder.setTenantId(getTenantId()); | |||
| corder.setSortColumns(CreateDate_DESC); | |||
| PageInfo<WxCouponOrder> page = wxCouponOrderService.listAsPage(corder, pageNum, pageSize); | |||
| @@ -51,7 +51,7 @@ public class WxCardPayController extends BaseController { | |||
| @Autowired | |||
| WxCardSpendService wxCardSpendService; | |||
| @ApiOperation("售卡记录列表接口") | |||
| @ApiOperation("售卡记录列表分页接口") | |||
| @GetMapping("list") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| @@ -0,0 +1,42 @@ | |||
| package com.iformall.controller; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.service.WxChartDataService; | |||
| 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.GetMapping; | |||
| import org.springframework.web.bind.annotation.RequestMapping; | |||
| import org.springframework.web.bind.annotation.RequestParam; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| import java.util.Map; | |||
| @Api(description = "图表") | |||
| @RestController | |||
| @RequestMapping("chart") | |||
| public class WxChartDataController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxChartDataService wxChartDataService; | |||
| @ApiOperation("queryData") | |||
| @GetMapping("/queryData") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "chart", value = "chart", dataType = "String", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "startdate", value = "startdate", dataType = "String", paramType = "query"), | |||
| @ApiImplicitParam(name = "enddate", value = "enddate", dataType = "String", paramType = "query") | |||
| }) | |||
| public ResultData queryData(@RequestParam Map<String, String> params) { | |||
| logger.debug("[" + getIpAddr() + "] WxChartDataController::queryData"); | |||
| params.put("tenantId",super.getTenantId()); | |||
| return wxChartDataService.queryData(params); | |||
| } | |||
| } | |||
| @@ -39,6 +39,7 @@ public class WxCouponChannelController extends BaseController { | |||
| @Autowired | |||
| private WxCouponService wxCouponService; | |||
| @ApiOperation("分页列表接口") | |||
| @GetMapping("list") | |||
| @ApiImplicitParams({ | |||
| @@ -62,31 +63,8 @@ public class WxCouponChannelController extends BaseController { | |||
| public ResultData update(@RequestBody WxCouponChannel wxCouponChannel) { | |||
| logger.debug("[" + getIpAddr() + "] WxCouponChannelController::update"); | |||
| wxCouponChannel.setTenantId(getUser().getTenantId()); | |||
| if (wxCouponChannel.getCouponId() != null && wxCouponChannel.getStatus() != null) { | |||
| WxCouponChannel orignal = wxCouponChannelService.getById(wxCouponChannel.getId()); | |||
| if (orignal.getStatus().equals(EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode()) | |||
| && wxCouponChannel.getStatus().equals(EnumCouponChannelStatus.STATUS_THROW_IN.getCode())) { | |||
| WxCoupon wxCoupon = wxCouponService.getById(orignal.getCouponId()); | |||
| if (wxCoupon == null) | |||
| return new ResultData(ErrorCode.COUPON_IS_EMPTY); | |||
| if (wxCoupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF)) | |||
| return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); | |||
| //查找是否该券 在该频道有其他上架 | |||
| WxCouponChannel query = new WxCouponChannel(); | |||
| query.setTenantId(orignal.getTenantId()); | |||
| query.setCouponId(orignal.getCouponId()); | |||
| query.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode());//已上架 | |||
| query.setTargetAd(orignal.getTargetAd()); | |||
| List<WxCouponChannel> list = wxCouponChannelService.listAsPage(query, 1, 1).getList(); | |||
| if (list != null && list.size() > 0) { | |||
| return new ResultData(ErrorCode.COUPON_CHANNEL_IS_EXISTED); | |||
| } | |||
| } | |||
| } | |||
| wxCouponChannelService.saveOrUpdate(wxCouponChannel); | |||
| return new ResultData(); | |||
| return wxCouponChannelService.saveOrUpdate(wxCouponChannel); | |||
| } | |||
| @ApiOperation("根据id删除接口") | |||
| @@ -1,34 +1,22 @@ | |||
| package com.iformall.controller; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.WxCouponChannel; | |||
| import com.iformall.domain.po.WxMerchant; | |||
| import com.iformall.enums.EnumCouponStatus; | |||
| import com.iformall.enums.EnumCouponType; | |||
| import com.iformall.enums.EnumCouponValidType; | |||
| import com.iformall.enums.EnumMerchantStatus; | |||
| import com.iformall.service.WxCouponChannelService; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.service.WxCouponService; | |||
| import com.iformall.service.WxMerchantService; | |||
| import com.iformall.utils.DateUtils; | |||
| 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.apache.commons.collections.map.HashedMap; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import java.util.stream.Collectors; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.*; | |||
| @RestController | |||
| @RequestMapping("wxCoupon") | |||
| @@ -39,58 +27,6 @@ public class WxCouponController extends BaseController { | |||
| @Autowired | |||
| private WxCouponService wxCouponService; | |||
| @Autowired | |||
| private WxCouponChannelService wxCouponChannelService; | |||
| private ResultData listType(@ModelAttribute WxCoupon wxCoupon, Integer pageNum, Integer pageSize, Integer type) { | |||
| if (null == wxCoupon) wxCoupon = new WxCoupon(); | |||
| wxCoupon.setTenantId(getTenantId()); | |||
| wxCoupon.setSortColumns(WxCoupon.Field.Id_DESC); | |||
| PageInfo<WxCoupon> page = null; | |||
| if (wxCoupon.getStatus() != null && wxCoupon.getStatus() == -1) | |||
| wxCoupon.setStatus(null); | |||
| page = wxCouponService.listAsPage(wxCoupon, pageNum, pageSize, type); | |||
| List<WxCoupon> wxCouponList = page.getList(); | |||
| if (wxCouponList.isEmpty()) { | |||
| return new ResultData(page); | |||
| } | |||
| List<Long> ids = wxCouponList.stream().map(p -> p.getId()).collect(Collectors.toList()); | |||
| WxCouponChannel wxCouponChannel = new WxCouponChannel(); | |||
| wxCouponChannel.setTenantId(getTenantId()); | |||
| wxCouponChannel.setCouponIds(ids); | |||
| wxCouponChannel.setStatus(0); | |||
| //上架状态 | |||
| List<WxCouponChannel> list = wxCouponChannelService.listAsPage(wxCouponChannel, 1, 10000).getList(); | |||
| if (!list.isEmpty()) { | |||
| Map<Long, List<WxCouponChannel>> groupBy = list.stream().collect(Collectors.groupingBy(WxCouponChannel::getCouponId)); | |||
| for (WxCoupon temp : wxCouponList) { | |||
| if (groupBy.get(temp.getId()) != null) { | |||
| List<Integer> channels = new ArrayList<>(); | |||
| for (WxCouponChannel tempchannel : groupBy.get(temp.getId())) { | |||
| if (!channels.contains(tempchannel.getTargetAd())) { | |||
| channels.add(tempchannel.getTargetAd()); | |||
| } | |||
| } | |||
| String sss = JSON.toJSONString(channels); | |||
| temp.setChannels(sss); | |||
| } else { | |||
| temp.setChannels(""); | |||
| } | |||
| } | |||
| } else { | |||
| for (WxCoupon temp : wxCouponList) { | |||
| temp.setChannels(""); | |||
| } | |||
| } | |||
| return new ResultData(page); | |||
| } | |||
| @ApiOperation("分页列表接口") | |||
| @GetMapping("listCoupon") | |||
| @@ -99,7 +35,9 @@ public class WxCouponController extends BaseController { | |||
| @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); //券列表 | |||
| if (wxCoupon == null) wxCoupon = new WxCoupon(); | |||
| wxCoupon.setTenantId(getTenantId()); | |||
| return wxCouponService.listType(wxCoupon, pageNum, pageSize, 0); //券列表 | |||
| } | |||
| @ApiOperation("卡分页列表接口") | |||
| @@ -109,7 +47,9 @@ public class WxCouponController extends BaseController { | |||
| @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()); //卡列表 | |||
| if (wxCoupon == null) wxCoupon = new WxCoupon(); | |||
| wxCoupon.setTenantId(getTenantId()); | |||
| return wxCouponService.listType(wxCoupon, pageNum, pageSize, EnumCouponType.CARD_MULTIMCH.getCode()); //卡列表 | |||
| } | |||
| @ApiOperation("砍价分页列表接口") | |||
| @@ -119,7 +59,9 @@ public class WxCouponController extends BaseController { | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||
| public ResultData listPress(@ModelAttribute WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { | |||
| logger.debug("[" + getIpAddr() + "] WxCouponController::listPress"); | |||
| return listType(wxCoupon, pageNum, pageSize, EnumCouponType.COUPON_PRESS.getCode()); //砍价列表 | |||
| if (wxCoupon == null) wxCoupon = new WxCoupon(); | |||
| wxCoupon.setTenantId(getTenantId()); | |||
| return wxCouponService.listType(wxCoupon, pageNum, pageSize, EnumCouponType.COUPON_PRESS.getCode()); //砍价列表 | |||
| } | |||
| @ApiOperation("分页列表接口") | |||
| @@ -129,7 +71,9 @@ public class WxCouponController extends BaseController { | |||
| @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); //全列表 | |||
| if (wxCoupon == null) wxCoupon = new WxCoupon(); | |||
| wxCoupon.setTenantId(getTenantId()); | |||
| return wxCouponService.listType(wxCoupon, pageNum, pageSize, null); //全列表 | |||
| } | |||
| @ApiOperation("新增接口") | |||
| @@ -166,4 +110,75 @@ public class WxCouponController extends BaseController { | |||
| logger.debug("[" + getIpAddr() + "] WxCouponController::findById");; | |||
| return new ResultData(wxCouponService.getVoById(id)); | |||
| } | |||
| @ApiOperation("卡类列表接口") | |||
| @GetMapping("findList") | |||
| public ResultData findList(@ModelAttribute WxCoupon wxCoupon) { | |||
| return new ResultData(wxCouponService.list(wxCoupon)); | |||
| } | |||
| @ApiOperation("卡营销列表接口") | |||
| @GetMapping("findCardCountList") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||
| public ResultData findCardCountList(@ModelAttribute WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { | |||
| //默认时间本月第一天,截止到当天 | |||
| Map<String,Object> result = new HashedMap(); | |||
| if(wxCoupon.getStartdate() == null){ | |||
| Calendar c = Calendar.getInstance(); | |||
| c.add(Calendar.MONTH, 0); | |||
| c.set(Calendar.DAY_OF_MONTH,1); | |||
| wxCoupon.setStartdate(c.getTime()); | |||
| } | |||
| if(wxCoupon.getEnddate() == null){ | |||
| wxCoupon.setEnddate(DateUtils.stringToDate(DateUtils.getSystemTime("yyyy-MM-dd") + " 23:59:59")); | |||
| } | |||
| result.put("list",wxCouponService.findCountData(wxCoupon,pageNum,pageSize)); | |||
| return new ResultData(result); | |||
| } | |||
| @ApiOperation("卷营销列表接口") | |||
| @GetMapping("findCouponCountList") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||
| public ResultData findCouponCountList(@ModelAttribute WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { | |||
| //默认时间本月第一天,截止到当天 | |||
| Map<String,Object> result = new HashedMap(); | |||
| if(wxCoupon.getStartdate() == null){ | |||
| Calendar c = Calendar.getInstance(); | |||
| c.add(Calendar.MONTH, 0); | |||
| c.set(Calendar.DAY_OF_MONTH,1); | |||
| wxCoupon.setStartdate(c.getTime()); | |||
| } | |||
| if(wxCoupon.getEnddate() == null){ | |||
| wxCoupon.setEnddate(DateUtils.stringToDate(DateUtils.getSystemTime("yyyy-MM-dd") + " 23:59:59")); | |||
| } | |||
| return new ResultData(wxCouponService.findCouponData(wxCoupon,pageNum,pageSize)); | |||
| } | |||
| @ApiOperation("砍价营销列表接口") | |||
| @GetMapping("findPressCountList") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||
| public ResultData findPressCountList(@ModelAttribute WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { | |||
| //默认时间本月第一天,截止到当天 | |||
| Map<String,Object> result = new HashedMap(); | |||
| if(wxCoupon.getStartdate() == null){ | |||
| Calendar c = Calendar.getInstance(); | |||
| c.add(Calendar.MONTH, 0); | |||
| c.set(Calendar.DAY_OF_MONTH,1); | |||
| wxCoupon.setStartdate(c.getTime()); | |||
| } | |||
| if(wxCoupon.getEnddate() == null){ | |||
| wxCoupon.setEnddate(DateUtils.stringToDate(DateUtils.getSystemTime("yyyy-MM-dd") + " 23:59:59")); | |||
| } | |||
| return new ResultData(wxCouponService.findPressData(wxCoupon,pageNum,pageSize)); | |||
| } | |||
| } | |||
| @@ -62,13 +62,7 @@ public class WxCouponSendController extends BaseController { | |||
| if (null == wxCouponSend) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| } | |||
| wxCouponSend.setTenantId(getTenantId()); | |||
| wxCouponSend.setStatus(EnumCouponSendStatus.VALID.getCode()); | |||
| List<WxCouponSendVo> wxCouponSendList = wxCouponSendService.listAsPage(wxCouponSend, 1, 1).getList(); | |||
| if (wxCouponSendList != null && wxCouponSendList.size() > 0) { | |||
| return new ResultData(ErrorCode.COUPON_SEND_IS_EXISTED); | |||
| } | |||
| WxCoupon wxCoupon = wxCouponService.getById(wxCouponSend.getCouponId()); | |||
| if (!wxCoupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_THROW_IN.getCode()) ){ | |||
| return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF); | |||
| @@ -0,0 +1,97 @@ | |||
| package com.iformall.controller; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxDevice; | |||
| import com.iformall.enums.EnumDeviceOnlineStatus; | |||
| import com.iformall.enums.EnumDeviceStatus; | |||
| import com.iformall.service.WxDeviceService; | |||
| 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.List; | |||
| @RestController | |||
| @RequestMapping("wxDevice") | |||
| @Api(description="IOT设备") | |||
| public class WxDeviceController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxDeviceService wxDeviceService; | |||
| @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 Result list(@ModelAttribute WxDevice wxDevice, Integer pageNum, Integer pageSize) { | |||
| wxDevice.setTenantId(getTenantId()); | |||
| wxDevice.setStatus(EnumDeviceStatus.VALID.getCode()); | |||
| return new ResultData(wxDeviceService.listAsPage(wxDevice, pageNum,pageSize)); | |||
| } | |||
| @ApiOperation("添加设备") | |||
| @PostMapping("add") | |||
| public Result add(@RequestBody WxDevice wxDevice) { | |||
| WxDevice record = new WxDevice(); | |||
| record.setDeviceId(wxDevice.getDeviceId()); | |||
| record.setStatus(EnumDeviceStatus.VALID.getCode()); | |||
| List<WxDevice> list = wxDeviceService.findList(record); | |||
| if (list.size() > 0) | |||
| return new ResultData(ErrorCode.DEVICE_ALREADY_EXIST); | |||
| wxDevice.setStatus(EnumDeviceStatus.VALID.getCode()); | |||
| wxDevice.setOnlineStatus(EnumDeviceOnlineStatus.OFFLINE.getCode()); | |||
| wxDevice.setTenantId(getTenantId()); | |||
| wxDeviceService.saveOrUpdate(wxDevice); | |||
| return new ResultData(); | |||
| } | |||
| @ApiOperation("更新设备") | |||
| @PostMapping("update") | |||
| public Result update(@RequestBody WxDevice wxDevice) { | |||
| if (wxDevice == null) | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| if (wxDevice.getId() == null) | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| wxDevice.setTenantId(getTenantId()); | |||
| wxDeviceService.saveOrUpdate(wxDevice); | |||
| return new ResultData(); | |||
| } | |||
| @ApiOperation("设备详情") | |||
| @GetMapping("detail") | |||
| public Result detail(@RequestParam Long id) { | |||
| if (id == null) | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| WxDevice wxDevice = wxDeviceService.getById(id); | |||
| if (wxDevice == null) | |||
| return new ResultData(ErrorCode.SCREENAD_NOT_FOUND); | |||
| return new ResultData(wxDevice); | |||
| } | |||
| @ApiOperation("删除设备") | |||
| @PostMapping("delete") | |||
| public Result delete(@RequestParam Long id) { | |||
| if (id == null) | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| WxDevice wxDevice = new WxDevice(); | |||
| wxDevice.setId(id); | |||
| wxDevice.setTenantId(getTenantId()); | |||
| wxDevice.setStatus(EnumDeviceStatus.INVALID.getCode()); | |||
| wxDeviceService.saveOrUpdate(wxDevice); | |||
| return new ResultData(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,110 @@ | |||
| package com.iformall.controller; | |||
| import com.github.pagehelper.Page; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxDevice; | |||
| import com.iformall.domain.po.WxMall; | |||
| import com.iformall.domain.po.WxScreenAd; | |||
| import com.iformall.enums.EnumScreenAdStatus; | |||
| import com.iformall.enums.EnumScreenAdType; | |||
| 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.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; | |||
| import java.util.Map; | |||
| @RestController | |||
| @RequestMapping("wxDeviceScreenAd") | |||
| @Api(description="广告屏") | |||
| public class WxDeviceScreenAdController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxScreenAdService wxScreenAdService; | |||
| @Autowired | |||
| private WxMallService wxMallService; | |||
| @Autowired | |||
| private WxDeviceService wxDeviceService; | |||
| @Autowired | |||
| private WxCampaignService wxCampaignService; | |||
| @Autowired | |||
| private WxCouponChannelService wxCouponChannelService; | |||
| private WxDevice findDevice(String deviceId) | |||
| { | |||
| WxDevice wxDevice = new WxDevice(); | |||
| wxDevice.setDeviceId(deviceId); | |||
| wxDevice.setStatus(EnumScreenAdStatus.VALID.getCode()); | |||
| List<WxDevice> list = wxDeviceService.findList(wxDevice); | |||
| if (list.size() <= 0) | |||
| return null; | |||
| else | |||
| return list.get(0); | |||
| } | |||
| @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 Result list(@RequestParam String deviceId, Integer pageNum, Integer pageSize) { | |||
| WxDevice wxDevice = findDevice(deviceId); | |||
| if (wxDevice == null) | |||
| return new ResultData(ErrorCode.DEVICE_NOT_FOUND); | |||
| WxScreenAd wxScreenAd = new WxScreenAd(); | |||
| wxScreenAd.setTenantId(wxDevice.getTenantId()); | |||
| wxScreenAd.setStatus(EnumScreenAdStatus.VALID.getCode()); | |||
| PageInfo<WxScreenAd> page = wxScreenAdService.listAsPage(wxScreenAd,pageNum,pageSize); | |||
| page.getList().stream().forEach(s->{ | |||
| Object target = null; | |||
| if (s.getType().equals(EnumScreenAdType.COUPON.getCode())) | |||
| target = wxCouponChannelService.findDetailVo(s.getTargetId()); | |||
| else if (s.getType().equals(EnumScreenAdType.CAMPAIGN.getCode())) | |||
| target = wxCampaignService.getById(s.getTargetId()); | |||
| s.setTarget(target); | |||
| }); | |||
| return new ResultData(page); | |||
| } | |||
| @ApiOperation("心跳") | |||
| @PostMapping("heartbeat") | |||
| public Result heartbeat(@RequestParam String deviceId,@RequestBody Map<String,String> paramMap) { | |||
| WxDevice wxDevice = findDevice(deviceId); | |||
| if (wxDevice == null) | |||
| return new ResultData(ErrorCode.DEVICE_NOT_FOUND); | |||
| if (wxDevice.getFirstHbTime() == null) | |||
| wxDevice.setFirstHbTime(new Date()); | |||
| wxDevice.setLastHbTime(new Date()); | |||
| wxDevice.setVersion(paramMap.get("version")); | |||
| wxDeviceService.saveOrUpdate(wxDevice); | |||
| return new ResultData(wxDevice); | |||
| } | |||
| @ApiOperation("基础信息") | |||
| @GetMapping("info") | |||
| public Result info(@RequestParam String deviceId) { | |||
| WxDevice wxDevice = findDevice(deviceId); | |||
| if (wxDevice == null) | |||
| return new ResultData(ErrorCode.DEVICE_NOT_FOUND); | |||
| return new ResultData(wxMallService.getByTenantId(wxDevice.getTenantId())); | |||
| } | |||
| } | |||
| @@ -1,11 +1,15 @@ | |||
| package com.iformall.controller; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCUserTags; | |||
| import com.iformall.domain.po.WxFlowRecord; | |||
| import com.iformall.enums.EnumFlowRecordStatus; | |||
| import com.iformall.service.WxFlowService; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.flowable.engine.RuntimeService; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| @@ -21,6 +25,8 @@ public class WxFlowAbleController extends BaseController { | |||
| @Autowired | |||
| private WxFlowService wxFlowService; | |||
| @Autowired | |||
| RuntimeService runtimeService; | |||
| @ApiOperation(value = "启动流程",notes = "{\"businessId\":\"221178539888607232\",\"businessType\":1,\"remark\":\"意见意见。\",\"taskAssignee\":[{\"taskKey\":\"firstTaskUser\",\"assignee\":\"243650055783841792\"},{\"taskKey\":\"secondTaskUser\",\"assignee\":\"\"}],\"variables\":[{\"key\":\"contractType\",\"value\":\"1\"},{\"key\":\"contractNumber\",\"value\":\"1111\"}]}") | |||
| @PostMapping("/start") | |||
| @@ -29,6 +35,12 @@ public class WxFlowAbleController extends BaseController { | |||
| return wxFlowService.start(params,super.getUser().getId(),super.getUser().getName(),super.getTenantId()); | |||
| } | |||
| @GetMapping(value = "/del") | |||
| public ResultData list(String id) { | |||
| runtimeService.deleteProcessInstance(id, "驳回"); | |||
| return new ResultData(); | |||
| } | |||
| /** | |||
| * 用户代办列表 | |||
| */ | |||
| @@ -37,13 +49,30 @@ public class WxFlowAbleController extends BaseController { | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "flowType", value = "流程类型,1合同流程 2账单流程", dataType = "int", paramType = "query", required = true) | |||
| @ApiImplicitParam(name = "flowType", value = "流程类型,1合同流程 2账单流程", dataType = "string", paramType = "query", required = true) | |||
| }) | |||
| public ResultData list(Integer flowType,Integer pageNum, Integer pageSize) { | |||
| public ResultData list(String flowType,Integer pageNum, Integer pageSize) { | |||
| logger.debug("[" + getIpAddr() + "] FlowAbleController::list"); | |||
| return wxFlowService.list(flowType,pageNum,pageSize,super.getUser().getId()); | |||
| } | |||
| /** | |||
| * 我的申请列表 | |||
| */ | |||
| @ApiOperation("我的申请列表") | |||
| @GetMapping(value = "/myApplyList") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), | |||
| }) | |||
| public ResultData myApplyList(@ModelAttribute WxFlowRecord record, Integer pageNum, Integer pageSize) { | |||
| logger.debug("[" + getIpAddr() + "] FlowAbleController::myApplyList"); | |||
| record.setUserId(super.getUser().getId()); | |||
| record.setStatus(EnumFlowRecordStatus.NEW.getCode()); | |||
| return new ResultData(wxFlowService.listAsPage(record,pageNum,pageSize)); | |||
| } | |||
| /** | |||
| * 审批历史 | |||
| */ | |||
| @@ -84,10 +113,20 @@ public class WxFlowAbleController extends BaseController { | |||
| */ | |||
| @ApiOperation(value = "驳回",notes = "{\"taskId\":\"\",\"processInstanceId\":\"\",\"remark\":\"\"}") | |||
| @PostMapping(value = "reject") | |||
| public ResultData reject(@RequestBody Map<String, String> params) { | |||
| public ResultData reject(@RequestBody Map<String, Object> params) { | |||
| return wxFlowService.reject(params,super.getUser().getId(),super.getUser().getName(),super.getTenantId()); | |||
| } | |||
| /** | |||
| * 撤回 | |||
| */ | |||
| @ApiOperation(value = "撤回",notes = "{\"taskId\":\"\",\"processInstanceId\":\"\",\"remark\":\"\"}") | |||
| @PostMapping(value = "setBack") | |||
| public ResultData setBack(@RequestBody Map<String, Object> params) { | |||
| return wxFlowService.setBack(params,super.getUser().getId(),super.getUser().getName()); | |||
| } | |||
| /** | |||
| * 生成流程图 | |||
| * | |||
| @@ -0,0 +1,40 @@ | |||
| package com.iformall.controller; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.vo.WxOrderGroupMarketing; | |||
| import com.iformall.service.WxOrderGroupService; | |||
| 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.GetMapping; | |||
| import org.springframework.web.bind.annotation.ModelAttribute; | |||
| import org.springframework.web.bind.annotation.RequestMapping; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| @RestController | |||
| @RequestMapping("/orderGroup") | |||
| @Api(description = "拼团接口") | |||
| public class WxOrderGroupController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| WxOrderGroupService wxOrderGroupService; | |||
| @ApiOperation(value = "拼团营销分析") | |||
| @GetMapping("queryOrderGroupMarketingList") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "couponId", value = "couponId", dataType = "String", paramType = "query"), | |||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), | |||
| }) | |||
| public ResultData queryOrderGroupMarketingList(@ModelAttribute WxOrderGroupMarketing wxOrderGroupMarketing, Integer pageNum, Integer pageSize) { | |||
| final PageInfo<WxOrderGroupMarketing> page = wxOrderGroupService.queryOrderGroupMarketingList(wxOrderGroupMarketing, pageNum, pageSize); | |||
| return new ResultData(page); | |||
| } | |||
| } | |||
| @@ -2,10 +2,16 @@ package com.iformall.controller; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxBillProperty; | |||
| import com.iformall.domain.po.WxFlowRecord; | |||
| import com.iformall.domain.po.WxPropertyContract; | |||
| import com.iformall.domain.po.WxRentContract; | |||
| import com.iformall.enums.EnumFlowRecordStatus; | |||
| import com.iformall.service.WxBillPropertyService; | |||
| import com.iformall.service.WxPropertyContractService; | |||
| 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; | |||
| @@ -20,10 +26,11 @@ import java.util.Map; | |||
| */ | |||
| @RestController | |||
| @RequestMapping("wxPropertyContract") | |||
| public class WxPropertyContractController extends BaseController | |||
| { | |||
| public class WxPropertyContractController extends BaseController { | |||
| @Autowired | |||
| private WxPropertyContractService wxPropertyContractService; | |||
| @Autowired | |||
| private WxBillPropertyService wxBillPropertyService; | |||
| private Logger logger = LoggerFactory.getLogger(WxPropertyContractController.class); | |||
| @@ -67,6 +74,9 @@ public class WxPropertyContractController extends BaseController | |||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||
| public ResultData findById(Long id) { | |||
| logger.debug("[" + getIpAddr() + "] WxPropertyContractController::findById"); | |||
| WxBillProperty wxBillProperty = new WxBillProperty(); | |||
| wxBillProperty.setTenantId(super.getTenantId()); | |||
| wxBillPropertyService.updateBillStatus(wxBillProperty); | |||
| return wxPropertyContractService.getById(id); | |||
| } | |||
| @@ -2,7 +2,9 @@ package com.iformall.controller; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxBillRent; | |||
| import com.iformall.domain.po.WxRentContract; | |||
| import com.iformall.service.WxBillRentService; | |||
| import com.iformall.service.WxRentContractService; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| @@ -25,6 +27,8 @@ public class WxRentContractController extends BaseController { | |||
| @Autowired | |||
| private WxRentContractService wxRentContractService; | |||
| @Autowired | |||
| private WxBillRentService wxBillRentService; | |||
| @GetMapping("list") | |||
| @ApiImplicitParams({ | |||
| @@ -79,6 +83,10 @@ public class WxRentContractController extends BaseController { | |||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) | |||
| public ResultData findById(Long id) { | |||
| logger.debug("[" + getIpAddr() + "] WxRentContractController::findById"); | |||
| // 同步欠缴状态 | |||
| WxBillRent wxBillRent = new WxBillRent(); | |||
| wxBillRent.setTenantId(super.getTenantId()); | |||
| wxBillRentService.updateBillStatus(wxBillRent); | |||
| return wxRentContractService.getById(id); | |||
| } | |||
| @@ -0,0 +1,109 @@ | |||
| package com.iformall.controller; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCampaign; | |||
| import com.iformall.domain.po.WxScreenAd; | |||
| import com.iformall.enums.EnumScoreType; | |||
| import com.iformall.enums.EnumScreenAdStatus; | |||
| import com.iformall.enums.EnumScreenAdType; | |||
| import com.iformall.service.WxCampaignService; | |||
| import com.iformall.service.WxCouponChannelService; | |||
| import com.iformall.service.WxScreenAdService; | |||
| 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.ArrayList; | |||
| import java.util.List; | |||
| @RestController | |||
| @RequestMapping("wxScreenAd") | |||
| @Api(description="广告屏") | |||
| public class WxScreenAdController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxScreenAdService wxScreenAdService; | |||
| @Autowired | |||
| private WxCampaignService wxCampaignService; | |||
| @Autowired | |||
| 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 Result list(@ModelAttribute WxScreenAd wxScreenAd, Integer pageNum, Integer pageSize) { | |||
| if (wxScreenAd == null) wxScreenAd = new WxScreenAd(); | |||
| wxScreenAd.setTenantId(getTenantId()); | |||
| wxScreenAd.setStatus(EnumScreenAdStatus.VALID.getCode()); | |||
| return new ResultData(wxScreenAdService.listAsPage(wxScreenAd,pageNum,pageSize)); | |||
| } | |||
| @ApiOperation("添加广告") | |||
| @PostMapping("add") | |||
| public Result add(@RequestBody WxScreenAd wxScreenAd) { | |||
| if (wxScreenAd == null) wxScreenAd = new WxScreenAd(); | |||
| wxScreenAd.setStatus(EnumScreenAdStatus.VALID.getCode()); | |||
| wxScreenAd.setTenantId(getTenantId()); | |||
| return wxScreenAdService.saveOrUpdate(wxScreenAd); | |||
| } | |||
| @ApiOperation("更新广告") | |||
| @PostMapping("update") | |||
| public Result update(@RequestBody WxScreenAd wxScreenAd) { | |||
| if (wxScreenAd == null) | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| if (wxScreenAd.getId() == null) | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| wxScreenAd.setTenantId(getTenantId()); | |||
| wxScreenAdService.saveOrUpdate(wxScreenAd); | |||
| return new ResultData(); | |||
| } | |||
| @ApiOperation("广告详情") | |||
| @GetMapping("detail") | |||
| public Result detail(@RequestParam Long id) { | |||
| if (id == null) | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| WxScreenAd wxScreenAd = wxScreenAdService.getById(id); | |||
| if (wxScreenAd == null) | |||
| return new ResultData(ErrorCode.SCREENAD_NOT_FOUND); | |||
| Object target = null; | |||
| if (wxScreenAd.getType().equals(EnumScreenAdType.COUPON.getCode())) | |||
| target = wxCouponChannelService.findDetailVo(wxScreenAd.getTargetId()); | |||
| if (wxScreenAd.getType().equals(EnumScreenAdType.COUPON.getCode())) | |||
| target = wxCampaignService.getById(wxScreenAd.getTargetId()); | |||
| wxScreenAd.setTarget(target); | |||
| return new ResultData(wxScreenAd); | |||
| } | |||
| @ApiOperation("删除广告") | |||
| @PostMapping("delete") | |||
| public Result delete(@RequestParam Long id) { | |||
| if (id == null) | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| WxScreenAd wxScreenAd = new WxScreenAd(); | |||
| wxScreenAd.setId(id); | |||
| wxScreenAd.setTenantId(getTenantId()); | |||
| wxScreenAd.setStatus(EnumScreenAdStatus.INVALID.getCode()); | |||
| wxScreenAdService.saveOrUpdate(wxScreenAd); | |||
| return new ResultData(); | |||
| } | |||
| } | |||
| @@ -3,16 +3,20 @@ package com.iformall.controller; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||
| import com.iformall.domain.po.WxShop; | |||
| import com.iformall.service.WxShopService; | |||
| 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.Map; | |||
| /** | |||
| @@ -119,4 +123,19 @@ public class WxShopController extends BaseController { | |||
| return new ResultData(page); | |||
| } | |||
| @ApiOperation("导出店铺") | |||
| @GetMapping("/exportShop") | |||
| public void exportShop(@ModelAttribute WxShop wxShop, HttpServletRequest request, HttpServletResponse response) { | |||
| logger.debug("[" + getIpAddr() + "] WxShopController::exportShop"); | |||
| if (null == wxShop){ | |||
| wxShop = new WxShop(); | |||
| } | |||
| wxShop.setTenantId(getTenantId()); | |||
| wxShop.setSortColumns(WxShop.Field.Id_DESC); | |||
| wxShopService.exportShop(wxShop, request, response); | |||
| } | |||
| } | |||
| @@ -77,7 +77,7 @@ public class RequestInterceptor extends HandlerInterceptorAdapter { | |||
| sb.append(resultBody); | |||
| String key = "request: " + HashUtil.md5(sb.toString()); | |||
| String key = "request-" + HashUtil.md5(sb.toString()); | |||
| if (redisTemplate.opsForValue().setIfAbsent(key, key)) { | |||
| redisTemplate.expire(key, 3, TimeUnit.SECONDS); | |||
| logger.info(key + ": 第一次提交"); | |||
| @@ -1,18 +1,39 @@ | |||
| package com.iformall.shiro; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.domain.po.MallUserInfo; | |||
| import com.iformall.enums.EnumLoginType; | |||
| import com.iformall.enums.EnumMallUserStatus; | |||
| import com.iformall.service.MallUserInfoService; | |||
| import org.apache.shiro.authc.AuthenticationInfo; | |||
| import org.apache.shiro.authc.AuthenticationToken; | |||
| import org.apache.shiro.authc.DisabledAccountException; | |||
| import org.apache.shiro.authc.UnknownAccountException; | |||
| import org.apache.shiro.authc.credential.HashedCredentialsMatcher; | |||
| import org.springframework.context.annotation.Configuration; | |||
| import javax.annotation.Resource; | |||
| @Configuration | |||
| public class MyRetryLimitCredentialsMatcher extends HashedCredentialsMatcher { | |||
| @Resource | |||
| private MallUserInfoService userService; | |||
| @Override | |||
| public boolean doCredentialsMatch(AuthenticationToken authcToken, AuthenticationInfo info) { | |||
| if(authcToken instanceof UseriFormallToken) { | |||
| UseriFormallToken tk = (UseriFormallToken) authcToken; | |||
| if(tk.getType().equals(EnumLoginType.NOPASSWD)){ | |||
| // 获取用户的输入的账号. | |||
| String username = (String)tk.getPrincipal(); | |||
| MallUserInfo user = userService.getByUsername(username); | |||
| if(user == null) { | |||
| throw new UnknownAccountException(ErrorCode.USER_IS_EMPTY.getMessage()); | |||
| } | |||
| // 用户被禁用 | |||
| if(user.getStatus()==null ||!EnumMallUserStatus.VALID.getCode().equals(user.getStatus())) { | |||
| throw new DisabledAccountException(ErrorCode.USER_IS_LOCKED.getMessage()); | |||
| } | |||
| return true; | |||
| } | |||
| boolean matches = super.doCredentialsMatch(authcToken, info); | |||
| @@ -2,14 +2,12 @@ package com.iformall.shiro; | |||
| import javax.annotation.Resource; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.enums.EnumMallUserStatus; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.MallUserInfoService; | |||
| import org.apache.shiro.SecurityUtils; | |||
| import org.apache.shiro.authc.AuthenticationException; | |||
| import org.apache.shiro.authc.AuthenticationInfo; | |||
| import org.apache.shiro.authc.AuthenticationToken; | |||
| import org.apache.shiro.authc.SimpleAuthenticationInfo; | |||
| import org.apache.shiro.authc.UnknownAccountException; | |||
| import org.apache.shiro.authc.*; | |||
| import org.apache.shiro.authz.AuthorizationInfo; | |||
| import org.apache.shiro.authz.SimpleAuthorizationInfo; | |||
| import org.apache.shiro.realm.AuthorizingRealm; | |||
| @@ -53,14 +51,11 @@ public class MyShiroRealm extends AuthorizingRealm { | |||
| String username = (String)token.getPrincipal(); | |||
| MallUserInfo user = userService.getByUsername(username); | |||
| if(user == null) { | |||
| throw new UnknownAccountException("用户名不存在"); | |||
| throw new UnknownAccountException(ErrorCode.USER_IS_EMPTY.getMessage()); | |||
| } | |||
| // if (0==user.getEnable()) { | |||
| // throw new LockedAccountException(); // 帐号锁定 | |||
| // } | |||
| if(user.getStatus()==null || | |||
| !EnumMallUserStatus.VALID.getCode().equals(user.getStatus())) {//用户被禁用 | |||
| throw new UnknownAccountException("用户被禁用"); | |||
| throw new DisabledAccountException(ErrorCode.USER_IS_LOCKED.getMessage()); | |||
| } | |||
| SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo( | |||
| user, //用户 | |||
| @@ -1,7 +1,9 @@ | |||
| spring: | |||
| profiles: | |||
| include: rabbitMQ | |||
| # JDBC | |||
| datasource: | |||
| url: jdbc:mysql://202.165.179.86:3306/mallinkDev?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&useAffectedRows=true | |||
| username: ENC(dZ8fmrtuBMQYaRytKQgTqg==) | |||
| password: ENC(WGu0+1DPIHrqorDhrbq1+7wr7xNG53mN) | |||
| type: com.alibaba.druid.pool.DruidDataSource | |||
| @@ -22,9 +24,6 @@ spring: | |||
| connectionProperties: "druid.stat.mergeSql=true;druid.stat.slowSqlMillis=6000" | |||
| #jackson: | |||
| #date-format: yyyy-MM-dd HH:mm:ss | |||
| flowable: | |||
| async-executor-activate: false | |||
| # REDIS | |||
| redis: | |||
| host: 202.165.179.86 | |||
| @@ -51,12 +50,37 @@ spring: | |||
| auth: true | |||
| starttls: | |||
| enable: true | |||
| # ROCKETMQ | |||
| rocketmq: | |||
| nameServer: 127.0.0.1:9876 | |||
| producer: | |||
| retry-times-when-send-async-failed: 0 | |||
| send-msg-timeout: 300000 | |||
| compress-msg-body-over-howmuch: 4096 | |||
| max-message-size: 4194304 | |||
| retry-another-broker-when-not-store-ok: false | |||
| retry-times-when-send-failed: 2 | |||
| # RABBITMQ | |||
| rabbitmq: | |||
| host: 202.165.179.86 | |||
| port: 5672 | |||
| username: fumao | |||
| password: f8l89&*%%u7f1t22 | |||
| publisher-confirms: true | |||
| virtual-host: / | |||
| aws: | |||
| clientRegion: cn-northwest-1 | |||
| bucketName: iformall-net | |||
| access: ENC(3gx5ghDFBqGrEhO3Wf8aYmXsnwHO7Cj3HNKJGOeUj0o=) | |||
| secret: ENC(HVKIJwCJKVXLlUpGlQPwNqJOlnpxn4xYuy91SH0seTSm2uAttIQHvA49fXWWax90v5wloIk0QuU=) | |||
| wechat: | |||
| web: | |||
| appId: "wxe31beafbfd8295ba" | |||
| secret: "c689fabf3c4c9f5b6424ff2a36a26727" | |||
| url: "https://mall.youlane.cn" | |||
| jasypt: | |||
| encryptor: | |||
| password: oRqdnDbK5pj3eMmB | |||
| @@ -1,7 +1,9 @@ | |||
| spring: | |||
| profiles: | |||
| include: rocketMQ | |||
| # JDBC | |||
| datasource: | |||
| url: jdbc:mysql://formalldb.cfqyqflkdlit.rds.cn-northwest-1.amazonaws.com.cn:3306/mallink?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false | |||
| url: jdbc:mysql://formalldb.cfqyqflkdlit.rds.cn-northwest-1.amazonaws.com.cn:3306/mallink?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false&useAffectedRows=true | |||
| username: ENC(NUzgQOdJnCbVLKT6BaX0aw==) | |||
| password: ENC(mvuoDRiu0jqYaKNRwwTuXZ6U7aoIaqsjdiPqTLgi/nY=) | |||
| type: com.alibaba.druid.pool.DruidDataSource | |||
| @@ -46,8 +48,14 @@ spring: | |||
| auth: true | |||
| starttls: | |||
| enable: true | |||
| flowable: | |||
| async-executor-activate: false | |||
| # RABBITMQ | |||
| rabbitmq: | |||
| host: localhost | |||
| port: 5672 | |||
| username: ENC(lRmLd6EzgeY1RT5ktcHv9g==) | |||
| password: ENC(gBI8mCjr3OC0v57jcnSb660Ux7mW03K2oePgvohhg7w=) | |||
| publisher-confirms: true | |||
| virtual-host: / | |||
| aws: | |||
| clientRegion: cn-northwest-1 | |||
| @@ -55,6 +63,12 @@ aws: | |||
| access: ENC(a6SN1sZ1enNL49ypiOXkg/pPPAnZD8H4buQFTTKN08s=) | |||
| secret: ENC(5P5ff4bTMJUbXVR4ZsM03UHzOKZ4+Zg5Iutcdkyp/Quny/oXg+A4KpfwEyGarlLu3vQMJahGP5M=) | |||
| wechat: | |||
| web: | |||
| appId: "wx9cc4ca09eb20fe03" | |||
| secret: "af1d7f7a1268022a73cb4ce0b9cf0985" | |||
| url: "https://admin.malls.iformall.com" | |||
| fm: | |||
| exception: true | |||
| @@ -1,7 +1,9 @@ | |||
| spring: | |||
| profiles: | |||
| include: rocketMQ | |||
| # JDBC | |||
| datasource: | |||
| url: jdbc:mysql://formalldb.cfqyqflkdlit.rds.cn-northwest-1.amazonaws.com.cn:3306/mallinkTest?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false | |||
| url: jdbc:mysql://formalldb.cfqyqflkdlit.rds.cn-northwest-1.amazonaws.com.cn:3306/mallinkTest?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false&useAffectedRows=true | |||
| username: ENC(Uc0AjgkytxHHCwZrmDASWg==) | |||
| password: ENC(nV4Mi3bEbBx0Fj7uUyYH55eTaqsFMjKvmNzagicH4pc=) | |||
| type: com.alibaba.druid.pool.DruidDataSource | |||
| @@ -46,8 +48,14 @@ spring: | |||
| auth: true | |||
| starttls: | |||
| enable: true | |||
| flowable: | |||
| async-executor-activate: false | |||
| # RABBITMQ | |||
| rabbitmq: | |||
| host: 127.0.0.1 | |||
| port: 5672 | |||
| username: ENC(aSRr6mnSryEqzHHz1hJf1g==) | |||
| password: ENC(GnjF/mdqKdvmDYC0tIIso7+20/jBALPw39tiWCYJ4iw=) | |||
| publisher-confirms: true | |||
| virtual-host: / | |||
| aws: | |||
| clientRegion: cn-northwest-1 | |||
| @@ -55,6 +63,11 @@ aws: | |||
| access: ENC(NCLcmjwKpAWdn/abD17OKIY7yKepVLWzEpqRYUlURCw=) | |||
| secret: ENC(TRcZqql0Rq5PExlMeH/4WiZ/i02b8FXKmLTBChJmbluTa1uoLS9LrHyNEMrqe1DK+QgOAdvqGBo=) | |||
| wechat: | |||
| web: | |||
| appId: "wx091907dd0bfd3f6b" | |||
| secret: "2a2ca10738998b9ef92c1fe8a4d366a6" | |||
| url: "https://admintest.malls.iformall.com" | |||
| fm: | |||
| exception: true | |||
| @@ -21,6 +21,26 @@ spring: | |||
| cache-names: redis_cache #缓存的名字(可以不指定) | |||
| redis: | |||
| time-to-live: 60000ms #很重要,缓存的有效时间,以便缓存的过期(单位为毫秒) | |||
| rocketmq: | |||
| nameServer: 202.165.179.86:9876 | |||
| producer: | |||
| retry-times-when-send-async-failed: 0 | |||
| send-msg-timeout: 300000 | |||
| compress-msg-body-over-howmuch: 4096 | |||
| max-message-size: 4194304 | |||
| retry-another-broker-when-not-store-ok: false | |||
| retry-times-when-send-failed: 2 | |||
| rabbitmq: | |||
| host: 202.165.179.86 | |||
| port: 5672 | |||
| username: guest | |||
| password: guest | |||
| publisher-confirms: true | |||
| virtual-host: / | |||
| # FLOWABLE | |||
| flowable: | |||
| async-executor-activate: false | |||
| # @{link} https://github.com/abel533 | |||
| #Mybatis | |||
| @@ -0,0 +1,45 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:flowable="http://flowable.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/processdef"> | |||
| <process id="end_contract_flow" name="endContractflow" isExecutable="true"> | |||
| <documentation>终止合同审批流程</documentation> | |||
| <startEvent id="startEvent1"></startEvent> | |||
| <userTask id="firstTaskUser" name="初审" flowable:candidateUsers="${firstTaskUser}"> | |||
| <documentation>初审</documentation> | |||
| </userTask> | |||
| <endEvent id="sid-9692A856-E39A-4B8C-95C2-7C04A3646D6F"></endEvent> | |||
| <sequenceFlow id="sid-AA24EF6A-4416-4FAF-9FF5-E15E46D87BD9" sourceRef="startEvent1" targetRef="firstTaskUser"></sequenceFlow> | |||
| <sequenceFlow id="sid-C4925653-8894-42FF-81F4-412B3D11A3C9" sourceRef="firstTaskUser" targetRef="secondTaskUser"></sequenceFlow> | |||
| <sequenceFlow id="sid-9FCAF465-99E7-4EFE-BEEA-7D59481E684C" sourceRef="secondTaskUser" targetRef="sid-9692A856-E39A-4B8C-95C2-7C04A3646D6F"></sequenceFlow> | |||
| <userTask id="secondTaskUser" name="复审" flowable:candidateUsers="${secondTaskUser}"> | |||
| <documentation>复审</documentation> | |||
| </userTask> | |||
| </process> | |||
| <bpmndi:BPMNDiagram id="BPMNDiagram_end_contract_flow"> | |||
| <bpmndi:BPMNPlane bpmnElement="end_contract_flow" id="BPMNPlane_end_contract_flow"> | |||
| <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1"> | |||
| <omgdc:Bounds height="30.0" width="30.0" x="100.0" y="157.0"></omgdc:Bounds> | |||
| </bpmndi:BPMNShape> | |||
| <bpmndi:BPMNShape bpmnElement="firstTaskUser" id="BPMNShape_firstTask"> | |||
| <omgdc:Bounds height="80.0" width="100.0" x="285.0" y="132.0"></omgdc:Bounds> | |||
| </bpmndi:BPMNShape> | |||
| <bpmndi:BPMNShape bpmnElement="sid-9692A856-E39A-4B8C-95C2-7C04A3646D6F" id="BPMNShape_sid-9692A856-E39A-4B8C-95C2-7C04A3646D6F"> | |||
| <omgdc:Bounds height="28.0" width="28.0" x="835.0" y="158.0"></omgdc:Bounds> | |||
| </bpmndi:BPMNShape> | |||
| <bpmndi:BPMNShape bpmnElement="secondTaskUser" id="BPMNShape_secondTask"> | |||
| <omgdc:Bounds height="80.0" width="100.0" x="554.0" y="132.0"></omgdc:Bounds> | |||
| </bpmndi:BPMNShape> | |||
| <bpmndi:BPMNEdge bpmnElement="sid-C4925653-8894-42FF-81F4-412B3D11A3C9" id="BPMNEdge_sid-C4925653-8894-42FF-81F4-412B3D11A3C9"> | |||
| <omgdi:waypoint x="384.94999999987203" y="172.0"></omgdi:waypoint> | |||
| <omgdi:waypoint x="553.9999999998877" y="172.0"></omgdi:waypoint> | |||
| </bpmndi:BPMNEdge> | |||
| <bpmndi:BPMNEdge bpmnElement="sid-9FCAF465-99E7-4EFE-BEEA-7D59481E684C" id="BPMNEdge_sid-9FCAF465-99E7-4EFE-BEEA-7D59481E684C"> | |||
| <omgdi:waypoint x="653.9499999999999" y="172.0"></omgdi:waypoint> | |||
| <omgdi:waypoint x="835.0" y="172.0"></omgdi:waypoint> | |||
| </bpmndi:BPMNEdge> | |||
| <bpmndi:BPMNEdge bpmnElement="sid-AA24EF6A-4416-4FAF-9FF5-E15E46D87BD9" id="BPMNEdge_sid-AA24EF6A-4416-4FAF-9FF5-E15E46D87BD9"> | |||
| <omgdi:waypoint x="129.9499996223143" y="172.0"></omgdi:waypoint> | |||
| <omgdi:waypoint x="284.9999999998994" y="172.0"></omgdi:waypoint> | |||
| </bpmndi:BPMNEdge> | |||
| </bpmndi:BPMNPlane> | |||
| </bpmndi:BPMNDiagram> | |||
| </definitions> | |||
| @@ -1,6 +1,7 @@ | |||
| package com.iformall; | |||
| import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; | |||
| import org.rocketmq.starter.annotation.EnableRocketMQ; | |||
| import org.springframework.beans.factory.annotation.Value; | |||
| import org.springframework.boot.SpringApplication; | |||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | |||
| @@ -14,6 +15,7 @@ import tk.mybatis.spring.annotation.MapperScan; | |||
| @SpringBootApplication | |||
| @MapperScan(basePackages = {"com.iformall.mapper"}) | |||
| @EnableEncryptableProperties | |||
| @EnableRocketMQ | |||
| public class BApplication { | |||
| @Value("${fm.exception}") | |||
| @@ -1,6 +1,7 @@ | |||
| package com.iformall.config; | |||
| import com.iformall.domain.po.PushLimit; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxScoreRules; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -86,4 +87,21 @@ public class RedisConfig extends CachingConfigurerSupport { | |||
| return template; | |||
| } | |||
| @Bean("cuserTokenRedisTemplate") | |||
| public RedisTemplate<String, WxCUser> getCUserTokenRedisTemplate(RedisConnectionFactory connectionFactory) { | |||
| RedisTemplate<String, WxCUser> template = new RedisTemplate<String, WxCUser>(); | |||
| Jackson2JsonRedisSerializer<WxCUser> j = new Jackson2JsonRedisSerializer<WxCUser>(WxCUser.class); | |||
| // value值的序列化 | |||
| template.setValueSerializer(j); | |||
| template.setHashKeySerializer(j); | |||
| // key的序列化 | |||
| template.setKeySerializer(new StringRedisSerializer()); | |||
| template.setHashKeySerializer(new StringRedisSerializer()); | |||
| template.setConnectionFactory(connectionFactory); | |||
| return template; | |||
| } | |||
| } | |||
| @@ -5,6 +5,9 @@ import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCouponOrder; | |||
| import com.iformall.domain.vo.WxCouponOrderCVo; | |||
| import com.iformall.enums.EnumCouponChannelActivityStatus; | |||
| import com.iformall.enums.EnumCouponOrderValidStatus; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.WxCouponOrderService; | |||
| import io.swagger.annotations.Api; | |||
| @@ -17,6 +20,7 @@ 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 | |||
| @@ -99,7 +103,7 @@ public class WxCouponOrderController extends BaseController { | |||
| @ApiOperation(value = "核销接口", notes = "{\"couponOrderId\":\"string\"}") | |||
| @PostMapping("verify") | |||
| public ResultData verify(@RequestBody Map<String, String> paramMap) { | |||
| logger.info(paramMap.toString()); | |||
| logger.info("couponOrderController.verify:"+paramMap.toString()); | |||
| String couponOrderIdStr = paramMap.get("couponOrderId"); | |||
| if (StringUtils.isBlank(couponOrderIdStr)) { | |||
| logger.error("couponOrderId不能为空: " + paramMap.toString()); | |||
| @@ -113,6 +117,25 @@ public class WxCouponOrderController extends BaseController { | |||
| logger.error("couponOrderId参数不正确: " + paramMap.toString()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| WxCouponOrderCVo wxCouponOrderCVo = wxCouponOrderService.detailCUserVo(couponOrderIdStr); | |||
| if (wxCouponOrderCVo == null) | |||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_NULL); | |||
| if (wxCouponOrderCVo.getValidStartDate() != null && wxCouponOrderCVo.getValidEndDate() != null ) { | |||
| Date now = new Date(); | |||
| if (wxCouponOrderCVo.getValidStartDate().getTime() > now.getTime()) { | |||
| logger.error("此券有效期未开始:" + couponOrderIdStr); | |||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_EARLIER_THAN_VALIDDATE); | |||
| } | |||
| if (wxCouponOrderCVo.getValidEndDate().getTime() < now.getTime()) { | |||
| logger.error("此券有效期已结束:" + couponOrderIdStr); | |||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_LATER_THAN_VALIDDATE); | |||
| } | |||
| } | |||
| WxCouponOrder couponOrder = null; | |||
| try { | |||
| couponOrder = wxCouponOrderService.verify(couponOrderId, getUser().getId()); | |||
| @@ -152,7 +175,7 @@ public class WxCouponOrderController extends BaseController { | |||
| try { | |||
| wxCouponOrderService.sendVerifyMsg(couponOrder, getUser(), bSentCoupon); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| logger.error("核销发送消息发生错误:"+e.getMessage()); | |||
| } | |||
| } | |||
| @@ -86,15 +86,17 @@ public class WxInfoController extends BaseController { | |||
| if (StringUtils.isBlank(code)) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "code不能为空"); | |||
| } | |||
| WxAppinfo wxAppinfo = getAppInfo(appId); | |||
| try { | |||
| Map<String, String> retMap = getOpenIdInfo(appId, code); | |||
| String openId = retMap.get("openId"); | |||
| MallUserInfo user = mallUserInfoService.getByOpenId(openId); | |||
| MallUserInfo user = mallUserInfoService.getByBOpenId(openId, wxAppinfo.getTenantId()); | |||
| if(user == null) { | |||
| return new ResultData(ErrorCode.USER_NO_PERMISSION, retMap); | |||
| } | |||
| if(!isInMobileAdmin(user)) { | |||
| if(!mallUserRoleService.checkIsMobileAdmin(user)) { | |||
| return new ResultData(ErrorCode.USER_NO_PERMISSION, retMap); | |||
| } | |||
| @@ -107,31 +109,6 @@ public class WxInfoController extends BaseController { | |||
| } | |||
| } | |||
| private boolean isInMobileAdmin(MallUserInfo user) { | |||
| // 检查用户是否有 移动端数据塔台 权限 | |||
| boolean isInMobile = false; | |||
| if(EnumUserAdmin.ADMIN.getCode().equals(user.getIsAdmin())) { // 超管 | |||
| isInMobile = true; | |||
| return isInMobile; | |||
| } | |||
| MallUserRole ur = new MallUserRole(); | |||
| ur.setUid(user.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(user.getTenantId()); | |||
| PageInfo<MallRolePermission> listAsPage = mallRolePermissionService.listAsPage(p, 1, 100); | |||
| for (MallRolePermission rp : listAsPage.getList()) { | |||
| if (rp.getPermissionId().equals(8L)) { /// 移动端数据塔台 | |||
| isInMobile = true; | |||
| } | |||
| } | |||
| } | |||
| return isInMobile; | |||
| } | |||
| private Map<String,String> getOpenIdInfo(String appId, String code) { | |||
| WxAppinfo wxAppinfo = getAppInfo(appId); | |||
| WxMaService wxMaService = getWeappServiceByAppInfo(wxAppinfo); | |||
| @@ -218,6 +195,8 @@ public class WxInfoController extends BaseController { | |||
| } | |||
| WxMaService wxMaService = getWeappService(appId); | |||
| WxAppinfo wxAppinfo = getAppInfo(appId); | |||
| try { | |||
| // 解密 | |||
| WxMaPhoneNumberInfo phoneNoInfo = wxMaService.getUserService().getPhoneNoInfo(session_key, encryptedData, iv); | |||
| @@ -226,15 +205,15 @@ public class WxInfoController extends BaseController { | |||
| String phone = phoneNoInfo.getPhoneNumber(); | |||
| resultMap.put("phone", phone); | |||
| MallUserInfo user = mallUserInfoService.getByPhone(phone); | |||
| MallUserInfo user = mallUserInfoService.getByPhone(phone, wxAppinfo.getTenantId()); | |||
| if(user == null) { | |||
| return new ResultData(ErrorCode.USER_NO_PERMISSION, resultMap); | |||
| } | |||
| if (isInMobileAdmin(user)) { | |||
| if (mallUserRoleService.checkIsMobileAdmin(user)) { | |||
| resultMap.put("phone", user.getPhone()); | |||
| resultMap.put("admin", "1"); | |||
| user.setOpenId(openId); | |||
| user.setBopenId(openId); | |||
| mallUserInfoService.saveOrUpdate(user); | |||
| return new ResultData(resultMap); | |||
| @@ -5,11 +5,11 @@ import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.config.PayProperty; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxMerchantBUser; | |||
| import com.iformall.domain.po.WxRefundOrder; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.enums.EnumPayType; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.WxCouponOrderService; | |||
| import com.iformall.service.WxOrderService; | |||
| import com.iformall.service.WxRefundOrderService; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| @@ -69,7 +69,7 @@ public class RequestInterceptor extends HandlerInterceptorAdapter { | |||
| sb.append(resultBody); | |||
| String key = "request: " + HashUtil.md5(sb.toString()); | |||
| String key = "request-" + HashUtil.md5(sb.toString()); | |||
| if (redisTemplate.opsForValue().setIfAbsent(key, key)) { | |||
| redisTemplate.expire(key, 3, TimeUnit.SECONDS); | |||
| logger.info(key + ": 第一次提交"); | |||
| @@ -1,7 +1,9 @@ | |||
| spring: | |||
| profiles: | |||
| include: rabbitMQ | |||
| # JDBC | |||
| datasource: | |||
| url: jdbc:mysql://202.165.179.86:3306/mallinkDev?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&useAffectedRows=true | |||
| username: ENC(dZ8fmrtuBMQYaRytKQgTqg==) | |||
| password: ENC(WGu0+1DPIHrqorDhrbq1+7wr7xNG53mN) | |||
| type: com.alibaba.druid.pool.DruidDataSource | |||
| @@ -1,7 +1,9 @@ | |||
| spring: | |||
| profiles: | |||
| include: rocketMQ | |||
| # JDBC | |||
| datasource: | |||
| url: jdbc:mysql://formalldb.cfqyqflkdlit.rds.cn-northwest-1.amazonaws.com.cn:3306/mallink?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false | |||
| url: jdbc:mysql://formalldb.cfqyqflkdlit.rds.cn-northwest-1.amazonaws.com.cn:3306/mallink?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false&useAffectedRows=true | |||
| username: ENC(NUzgQOdJnCbVLKT6BaX0aw==) | |||
| password: ENC(mvuoDRiu0jqYaKNRwwTuXZ6U7aoIaqsjdiPqTLgi/nY=) | |||
| type: com.alibaba.druid.pool.DruidDataSource | |||
| @@ -45,6 +47,14 @@ spring: | |||
| auth: true | |||
| starttls: | |||
| enable: true | |||
| # RABBITMQ | |||
| rabbitmq: | |||
| host: localhost | |||
| port: 5672 | |||
| username: ENC(lRmLd6EzgeY1RT5ktcHv9g==) | |||
| password: ENC(gBI8mCjr3OC0v57jcnSb660Ux7mW03K2oePgvohhg7w=) | |||
| publisher-confirms: true | |||
| virtual-host: / | |||
| aws: | |||
| clientRegion: cn-northwest-1 | |||
| @@ -1,7 +1,7 @@ | |||
| spring: | |||
| # JDBC | |||
| datasource: | |||
| url: jdbc:mysql://formalldb.cfqyqflkdlit.rds.cn-northwest-1.amazonaws.com.cn:3306/mallinkTest?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false | |||
| url: jdbc:mysql://formalldb.cfqyqflkdlit.rds.cn-northwest-1.amazonaws.com.cn:3306/mallinkTest?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false&useAffectedRows=true | |||
| username: ENC(Uc0AjgkytxHHCwZrmDASWg==) | |||
| password: ENC(nV4Mi3bEbBx0Fj7uUyYH55eTaqsFMjKvmNzagicH4pc=) | |||
| type: com.alibaba.druid.pool.DruidDataSource | |||
| @@ -45,6 +45,14 @@ spring: | |||
| auth: true | |||
| starttls: | |||
| enable: true | |||
| # RABBITMQ | |||
| rabbitmq: | |||
| host: 127.0.0.1 | |||
| port: 5672 | |||
| username: ENC(aSRr6mnSryEqzHHz1hJf1g==) | |||
| password: ENC(GnjF/mdqKdvmDYC0tIIso7+20/jBALPw39tiWCYJ4iw=) | |||
| publisher-confirms: true | |||
| virtual-host: / | |||
| aws: | |||
| clientRegion: cn-northwest-1 | |||
| @@ -12,6 +12,15 @@ spring: | |||
| date-format: yyyy-MM-dd HH:mm:ss | |||
| time-zone: GMT+8 | |||
| default-property-inclusion: non_null | |||
| rocketmq: | |||
| nameServer: 127.0.0.1:9876 | |||
| producer: | |||
| retry-times-when-send-async-failed: 0 | |||
| send-msg-timeout: 300000 | |||
| compress-msg-body-over-howmuch: 4096 | |||
| max-message-size: 4194304 | |||
| retry-another-broker-when-not-store-ok: false | |||
| retry-times-when-send-failed: 2 | |||
| # @{link} https://github.com/abel533 | |||
| #Mybatis | |||
| @@ -1,6 +1,7 @@ | |||
| package com.iformall; | |||
| import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; | |||
| import org.rocketmq.starter.annotation.EnableRocketMQ; | |||
| import org.springframework.beans.factory.annotation.Value; | |||
| import org.springframework.boot.SpringApplication; | |||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | |||
| @@ -14,6 +15,7 @@ import tk.mybatis.spring.annotation.MapperScan; | |||
| @SpringBootApplication | |||
| @MapperScan(basePackages = {"com.iformall.mapper"}) | |||
| @EnableEncryptableProperties | |||
| @EnableRocketMQ | |||
| public class CApplication { | |||
| @Value("${fm.exception}") | |||
| @@ -1,6 +1,7 @@ | |||
| package com.iformall.config; | |||
| import com.iformall.domain.po.PushLimit; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxScoreRules; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -86,4 +87,21 @@ public class RedisConfig extends CachingConfigurerSupport { | |||
| return template; | |||
| } | |||
| @Bean("cuserTokenRedisTemplate") | |||
| public RedisTemplate<String, WxCUser> getCUserTokenRedisTemplate(RedisConnectionFactory connectionFactory) { | |||
| RedisTemplate<String, WxCUser> template = new RedisTemplate<String, WxCUser>(); | |||
| Jackson2JsonRedisSerializer<WxCUser> j = new Jackson2JsonRedisSerializer<WxCUser>(WxCUser.class); | |||
| // value值的序列化 | |||
| template.setValueSerializer(j); | |||
| template.setHashKeySerializer(j); | |||
| // key的序列化 | |||
| template.setKeySerializer(new StringRedisSerializer()); | |||
| template.setHashKeySerializer(new StringRedisSerializer()); | |||
| template.setConnectionFactory(connectionFactory); | |||
| return template; | |||
| } | |||
| } | |||
| @@ -645,7 +645,7 @@ public class WxCarController extends BaseController { | |||
| WxCouponOrderCarCVo userCar = null; | |||
| WxCouponOrder userCarQ = new WxCouponOrder(); | |||
| userCarQ.setTenantId(user.getTenantId()); | |||
| userCarQ.setCUserId(user.getId()); | |||
| userCarQ.setcUserId(user.getId()); | |||
| userCarQ.setId(couponOrderId); | |||
| userCarQ.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); | |||
| List<WxCouponOrderCarCVo> list = wxCouponOrderService.carListCUserVo(userCarQ); | |||
| @@ -712,7 +712,7 @@ public class WxCarController extends BaseController { | |||
| if (wxCouponOrder == null) wxCouponOrder = new WxCouponOrderCarCVo(); | |||
| WxCUser user = getUser(); | |||
| wxCouponOrder.setTenantId(user.getTenantId()); | |||
| wxCouponOrder.setCUserId(user.getId()); | |||
| wxCouponOrder.setcUserId(user.getId()); | |||
| if (wxCouponOrder.getCouponOrderStatus() == null) | |||
| wxCouponOrder.setSortColumns(WxCouponOrder.Field.CreateDate_DESC); | |||
| else if (wxCouponOrder.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()) | |||
| @@ -45,6 +45,9 @@ public class WxCardPayController extends BaseController { | |||
| @Autowired | |||
| WxCardSpendService wxCardSpendService; | |||
| @Autowired | |||
| WxCouponOrderService wxCouponOrderService; | |||
| @ApiOperation(value = "C端扫B端储值卡支付订单", notes = "params:{\"cardId\":\"String\",\"merchantId\":\"String\",\"totalFee\":\"String(元)\"}") | |||
| @PostMapping("order_create") | |||
| public ResultData saveCardPayOrder(@RequestBody Map<String, String> paramMap, HttpServletRequest request) { | |||
| @@ -87,6 +90,8 @@ public class WxCardPayController extends BaseController { | |||
| Integer payment = totalFee.multiply(new BigDecimal(100)).intValue(); | |||
| WxCUser user = getUser(); | |||
| WxCardInfo cardInfo = wxCardInfoService.getById(cardId); | |||
| if(cardInfo == null) { | |||
| logger.error("卡不存在: " + cardIdStr); | |||
| @@ -98,14 +103,19 @@ public class WxCardPayController extends BaseController { | |||
| return new ResultData(ErrorCode.CARD_REMAIN_AMOUNT_IS_NOT_ENOUGH); | |||
| } | |||
| //查看所有者与扫码者是否为一致 | |||
| WxCouponOrder couponOrder = wxCouponOrderService.getById(cardId); | |||
| if (!couponOrder.getOwnerId().equals(user.getId())) { | |||
| logger.error("卡已被领取: " + cardIdStr); | |||
| return new ResultData(ErrorCode.CARD_TRANSFERED); | |||
| } | |||
| 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); | |||
| if (merchant.getStatus() == EnumMerchantStatus.NOT_VALID.getCode()) { | |||
| logger.error("商户已禁用, merchantId: " + merchant.getId()); | |||
| @@ -1,6 +1,10 @@ | |||
| package com.iformall.controller; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.domain.vo.WxCouponChannelVo; | |||
| import com.iformall.enums.EnumCouponChannelActivityStatus; | |||
| import com.iformall.enums.EnumCouponChannelStatus; | |||
| import com.iformall.enums.EnumCouponChannelType; | |||
| import io.swagger.annotations.Api; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -15,6 +19,8 @@ import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import java.util.Date; | |||
| @RestController | |||
| @RequestMapping("/api/wxCouponChannel") | |||
| @Api(description = "发券渠道相关接口") | |||
| @@ -34,20 +40,25 @@ public class WxCouponChannelController extends BaseController { | |||
| wxCouponChannel.setTenantId(getTenantId()); | |||
| wxCouponChannel.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode()); | |||
| wxCouponChannel.setSortColumns(WxCouponChannel.Field.CreateDate_DESC); | |||
| wxCouponChannel.setIsCRequest(0);//标记为C端调用 | |||
| return new ResultData(wxCouponChannelService.listPageCVo(wxCouponChannel, pageNum, pageSize)); | |||
| } | |||
| @ApiOperation("分页列表接口") | |||
| @GetMapping("getCouponChannel") | |||
| public ResultData getCouponChannel(@ModelAttribute WxCouponChannel wxCouponChannel) { | |||
| if (null == wxCouponChannel) wxCouponChannel = new WxCouponChannel(); | |||
| wxCouponChannel.setTenantId(getTenantId()); | |||
| wxCouponChannel.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode()); | |||
| wxCouponChannel.setIsCRequest(0);//标记为C端调用 | |||
| return new ResultData(wxCouponChannelService.findCouponChannelVo(wxCouponChannel)); | |||
| } | |||
| PageInfo<WxCouponChannelVo> page = wxCouponChannelService.listPageCVo(wxCouponChannel, pageNum, pageSize); | |||
| if (wxCouponChannel.getTargetAd()!= null && | |||
| wxCouponChannel.getTargetAd().equals(EnumCouponChannelType.COUPON_CHANNEL_ID_TIMED.getCode())) { | |||
| Date now = new Date(); | |||
| page.getList().stream().forEach(cc->{ | |||
| if (cc.getBeginTime().getTime() > now.getTime()) { | |||
| cc.setActivityStatus(EnumCouponChannelActivityStatus.PREPARED.getCode()); | |||
| } else if (cc.getEndTime().getTime() < now.getTime()) { | |||
| cc.setActivityStatus(EnumCouponChannelActivityStatus.ENDED.getCode()); | |||
| } else { | |||
| cc.setActivityStatus(EnumCouponChannelActivityStatus.STARTED.getCode()); | |||
| } | |||
| }); | |||
| } | |||
| return new ResultData(page); | |||
| } | |||
| } | |||
| @@ -2,22 +2,31 @@ package com.iformall.controller; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCouponChannel; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.vo.MarkingSceneDataReportVo; | |||
| import com.iformall.domain.vo.WxCouponCVo; | |||
| import com.iformall.enums.EnumCouponChannelActivityStatus; | |||
| import com.iformall.enums.EnumCouponChannelType; | |||
| import com.iformall.service.WxCouponChannelService; | |||
| import com.iformall.service.WxCouponService; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.apache.commons.collections.map.HashedMap; | |||
| 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.GetMapping; | |||
| import org.springframework.web.bind.annotation.ModelAttribute; | |||
| import org.springframework.web.bind.annotation.RequestMapping; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.*; | |||
| import java.util.stream.Collectors; | |||
| @RestController | |||
| @RequestMapping("/api/wxCoupon") | |||
| @Api(description = "券类型相关接口") | |||
| @@ -26,6 +35,8 @@ public class WxCouponController extends BaseController { | |||
| @Autowired | |||
| private WxCouponChannelService wxCouponChannelService; | |||
| @Autowired | |||
| private WxCouponService wxCouponService; | |||
| @ApiOperation("根据id(couponChannel)查询接口") | |||
| @@ -48,7 +59,19 @@ public class WxCouponController extends BaseController { | |||
| if (wxCouponCVo == null) | |||
| return new ResultData(ErrorCode.COUPON_IS_EMPTY); | |||
| return new ResultData(wxCouponCVo); | |||
| if (wxCouponCVo.getTargetAd()!= null && | |||
| wxCouponCVo.getTargetAd().equals(EnumCouponChannelType.COUPON_CHANNEL_ID_TIMED.getCode())) { | |||
| Date now = new Date(); | |||
| if (wxCouponCVo.getBeginTime().getTime() > now.getTime()) { | |||
| wxCouponCVo.setActivityStatus(EnumCouponChannelActivityStatus.PREPARED.getCode()); | |||
| } else if (wxCouponCVo.getEndTime().getTime() < now.getTime()) { | |||
| wxCouponCVo.setActivityStatus(EnumCouponChannelActivityStatus.ENDED.getCode()); | |||
| } else { | |||
| wxCouponCVo.setActivityStatus(EnumCouponChannelActivityStatus.STARTED.getCode()); | |||
| } | |||
| } | |||
| return new ResultData(wxCouponCVo); | |||
| } | |||
| } | |||
| @@ -1,12 +1,16 @@ | |||
| package com.iformall.controller; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxCouponOrder; | |||
| import com.iformall.domain.vo.WxCardCVo; | |||
| import com.iformall.domain.vo.WxCouponOrderCVo; | |||
| import com.iformall.enums.EnumCouponChannelActivityStatus; | |||
| import com.iformall.enums.EnumCouponOrderStatus; | |||
| import com.iformall.enums.EnumCouponOrderValidStatus; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.WxCouponOrderService; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| @@ -16,15 +20,10 @@ 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.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.data.redis.core.StringRedisTemplate; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import java.util.ArrayList; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import java.util.*; | |||
| @RestController | |||
| @RequestMapping("/api/couponOrder") | |||
| @@ -35,6 +34,9 @@ public class WxCouponOrderController extends BaseController { | |||
| @Autowired | |||
| private WxCouponOrderService wxCouponOrderService; | |||
| @Autowired | |||
| StringRedisTemplate stringRedisTemplate; | |||
| @ApiOperation("券包分页列表接口") | |||
| @GetMapping("list") | |||
| @ApiImplicitParams({ | |||
| @@ -47,14 +49,30 @@ public class WxCouponOrderController extends BaseController { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| if (wxCouponOrder == null) wxCouponOrder = new WxCouponOrderCVo(); | |||
| wxCouponOrder.setCUserId(getUser().getId()); | |||
| wxCouponOrder.setcUserId(getUser().getId()); | |||
| if (wxCouponOrder.getCouponOrderStatus() == null) | |||
| wxCouponOrder.setSortColumns(WxCouponOrder.Field.CreateDate_DESC); | |||
| else if (wxCouponOrder.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()) | |||
| wxCouponOrder.setSortColumns(WxCouponOrder.Field.CreateDate_DESC); | |||
| else | |||
| wxCouponOrder.setSortColumns(WxCouponOrder.Field.UpdateDate_DESC); | |||
| return wxCouponOrderService.listCUserVoAsPage(wxCouponOrder, pageNum, pageSize); | |||
| PageInfo<WxCouponOrderCVo> page = wxCouponOrderService.listCUserVoAsPage(wxCouponOrder, pageNum, pageSize); | |||
| Date now = new Date(); | |||
| page.getList().stream().forEach(co->{ | |||
| if (co.getValidStartDate() != null && co.getValidEndDate() != null ) { | |||
| if (co.getValidStartDate().getTime() > now.getTime()) { | |||
| co.setValidStatus(EnumCouponOrderValidStatus.PREPARED.getCode()); | |||
| } else if (co.getValidEndDate().getTime() < now.getTime()) { | |||
| co.setValidStatus(EnumCouponOrderValidStatus.ENDED.getCode()); | |||
| } else { | |||
| co.setValidStatus(EnumCouponChannelActivityStatus.STARTED.getCode()); | |||
| } | |||
| } | |||
| }); | |||
| return new ResultData(page); | |||
| } | |||
| @ApiOperation(value = "券详情接口") | |||
| @@ -67,8 +85,27 @@ public class WxCouponOrderController extends BaseController { | |||
| if (couponOrderId == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| WxCouponOrderCVo wxCouponOrderCVo = wxCouponOrderService.detailCUserVo(couponOrderId); | |||
| if (wxCouponOrderCVo == null) { | |||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_NULL); | |||
| } | |||
| return wxCouponOrderService.detailCUserVo(getUser().getId(), couponOrderId); | |||
| if (!wxCouponOrderCVo.getcUserId().equals(getUserId())) { | |||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_NULL); | |||
| } | |||
| Date now = new Date(); | |||
| if (wxCouponOrderCVo.getValidStartDate() != null && wxCouponOrderCVo.getValidEndDate() != null ) { | |||
| if (wxCouponOrderCVo.getValidStartDate().getTime() > now.getTime()) { | |||
| wxCouponOrderCVo.setValidStatus(EnumCouponOrderValidStatus.PREPARED.getCode()); | |||
| } else if (wxCouponOrderCVo.getValidEndDate().getTime() < now.getTime()) { | |||
| wxCouponOrderCVo.setValidStatus(EnumCouponOrderValidStatus.ENDED.getCode()); | |||
| } else { | |||
| wxCouponOrderCVo.setValidStatus(EnumCouponChannelActivityStatus.STARTED.getCode()); | |||
| } | |||
| } | |||
| return new ResultData(wxCouponOrderCVo); | |||
| } | |||
| @ApiOperation(value = "卡券状态接口") | |||
| @@ -137,4 +174,57 @@ public class WxCouponOrderController extends BaseController { | |||
| return wxCouponOrderService.cardDetailCUserVo(getUserId(), couponOrderId); | |||
| } | |||
| @ApiOperation(value = "卡转赠领取") | |||
| @PostMapping("cardAccept") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "id", value = "coupon_order_id", dataType = "Long", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "cUserId", value = "转赠者", dataType = "Long", paramType = "query", required = true), | |||
| }) | |||
| public ResultData cardAccept(@RequestBody WxCouponOrder wxCouponOrder) { | |||
| //coupon_order_id判断 | |||
| Long id = wxCouponOrder.getId(); | |||
| if (id == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "id不能为空"); | |||
| } | |||
| //转赠人判断 | |||
| Long cUserId = wxCouponOrder.getcUserId(); | |||
| if (cUserId == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "cUserId不能为空"); | |||
| } | |||
| //当前领取人 | |||
| wxCouponOrder.setOwnerId(getUserId()); | |||
| //转赠者与当前领取人是否为同一个 | |||
| if (cUserId.equals(wxCouponOrder.getOwnerId())) { | |||
| logger.info("转赠人与卡所有者相同"); | |||
| return new ResultData(ErrorCode.CARD_TRANSFER_INVALID.getCode(), "转赠人与卡所有者相同"); | |||
| } | |||
| return wxCouponOrderService.cardAccept(wxCouponOrder); | |||
| } | |||
| @ApiOperation(value = "查询转赠卡状态") | |||
| @GetMapping("queryCardStatus") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "id", value = "coupon_order_id", dataType = "Long", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "cUserId", value = "转赠者", dataType = "Long", paramType = "query", required = true), | |||
| }) | |||
| public ResultData queryCardStatus(@ModelAttribute WxCouponOrder wxCouponOrder) { | |||
| //coupon_order_id判断 | |||
| Long id = wxCouponOrder.getId(); | |||
| if (id == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "id不能为空"); | |||
| } | |||
| //转赠人判断 | |||
| Long cUserId = wxCouponOrder.getcUserId(); | |||
| if (cUserId == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "cUserId不能为空"); | |||
| } | |||
| //当前领取人 | |||
| wxCouponOrder.setOwnerId(getUserId()); | |||
| return wxCouponOrderService.queryCardStatus(wxCouponOrder); | |||
| } | |||
| } | |||
| @@ -55,40 +55,26 @@ public class WxGameController extends BaseController { | |||
| @PostMapping("addActionLog") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "gameId", value = "游戏ID", dataType = "String", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "couponOrderId", value = "券ID", dataType = "String", paramType = "query", required = true)}) | |||
| public ResultData addActionLog(String gameId, String orderId) { | |||
| @ApiImplicitParam(name = "orderId", value = "券订单ID", dataType = "String", paramType = "query", required = true)}) | |||
| public ResultData addActionLog(@RequestBody Map<String,String> paramMap) { | |||
| Long gameIdL = null; | |||
| Long orderIdL = null; | |||
| Long couponOrderIdL = null; | |||
| try { | |||
| gameIdL = Long.valueOf(gameId); | |||
| if (orderId != null) { | |||
| orderIdL = Long.valueOf(orderId); | |||
| WxCouponOrder wxCouponOrder = new WxCouponOrder(); | |||
| wxCouponOrder.setCUserId(getUserId()); | |||
| wxCouponOrder.setOrderId(orderIdL); | |||
| PageInfo<WxCouponOrder> page = wxCouponOrderService.listAsPage(wxCouponOrder,1,1); | |||
| if (page.getList().size()>0) { | |||
| couponOrderIdL = page.getList().get(0).getId(); | |||
| } | |||
| } | |||
| gameIdL = Long.valueOf(paramMap.get("gameId")); | |||
| orderIdL = Long.valueOf(paramMap.get("orderId")); | |||
| } catch (Exception e){ | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| } | |||
| WxGameActionLog wxGameActionLog = new WxGameActionLog(); | |||
| wxGameActionLog.setUserId(getUserId()); | |||
| wxGameActionLog.setTenantId(getTenantId()); | |||
| wxGameActionLog.setGameId(gameIdL); | |||
| wxGameActionLog.setCouponOrderId(couponOrderIdL); | |||
| wxGameService.addActionLog(wxGameActionLog); | |||
| return new ResultData(); | |||
| return wxGameService.addActionLog(getUserId(), gameIdL, orderIdL); | |||
| } | |||
| @ApiOperation("添加游戏参与记录") | |||
| @PostMapping("checkLimit") | |||
| @GetMapping("getCount") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "gameId", value = "游戏ID", dataType = "String", paramType = "query", required = true)}) | |||
| public ResultData checkLimit(String gameId) { | |||
| public ResultData getCount(String gameId) { | |||
| Long gameIdL = null; | |||
| try { | |||
| gameIdL = Long.valueOf(gameId); | |||
| @@ -96,6 +82,6 @@ public class WxGameController extends BaseController { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); | |||
| } | |||
| return wxGameService.checkLimit(gameIdL,getUserId()); | |||
| return wxGameService.getCount(gameIdL,getUserId()); | |||
| } | |||
| } | |||
| @@ -1,11 +1,15 @@ | |||
| package com.iformall.controller; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxMerchant; | |||
| import com.iformall.domain.vo.WxMerchantVo; | |||
| import com.iformall.enums.EnumMerchantStatus; | |||
| import com.iformall.service.WxMerchantService; | |||
| import com.iformall.utils.HashUtil; | |||
| 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; | |||
| @@ -26,6 +30,17 @@ public class WxMerchantController extends BaseController { | |||
| @Autowired | |||
| private WxMerchantService wxMerchantService; | |||
| @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 WxMerchantVo wxMerchant, Integer pageNum, Integer pageSize) { | |||
| logger.debug("[" + getIpAddr() + "] WxMerchantController::list"); | |||
| if (null == wxMerchant) wxMerchant = new WxMerchantVo(); | |||
| wxMerchant.setMerchantStatus(EnumMerchantStatus.VALID.getCode()); | |||
| return new ResultData(wxMerchantService.listAsPageCVo(wxMerchant, pageNum, pageSize)); | |||
| } | |||
| @ApiOperation("根据code查询接口") | |||
| @GetMapping("/findByCode") | |||
| @@ -9,11 +9,11 @@ import com.iformall.domain.po.WxCouponChannel; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.vo.WxOrderCouponPressVo; | |||
| import com.iformall.domain.vo.WxOrderCouponVo; | |||
| import com.iformall.enums.EnumCouponChannelStatus; | |||
| import com.iformall.enums.EnumOrderStatus; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.WxCouponChannelService; | |||
| import com.iformall.service.WxOrderService; | |||
| import com.iformall.utils.DateUtils; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| @@ -24,7 +24,7 @@ import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import java.util.List; | |||
| import java.util.Date; | |||
| import java.util.Map; | |||
| @RestController | |||
| @@ -85,7 +85,7 @@ public class WxOrderController extends BaseController { | |||
| } | |||
| } | |||
| @ApiOperation(value = "下订单", notes = "{\"couponChannelId\":\"String\",\"couponId\":\"String\",\"press\":\"String\"}") | |||
| @ApiOperation(value = "下订单", notes = "{\"couponChannelId\":\"String\",\"couponId\":\"String\",\"press\":\"String\",\"orderGroupId\":\"String\"}") | |||
| @PostMapping("save") | |||
| public ResultData saveOrder(@RequestBody Map<String, String> paramMap) { | |||
| logger.info("OrderSave: " + paramMap.toString()); | |||
| @@ -94,11 +94,12 @@ public class WxOrderController extends BaseController { | |||
| String couponChannelIdStr = paramMap.get("couponChannelId"); | |||
| String couponIdStr = paramMap.get("couponId"); | |||
| String pressStr = paramMap.get("press"); | |||
| String orderGroupIdStr = paramMap.get("orderGroupId"); | |||
| if (StringUtils.isBlank(couponChannelIdStr)) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId不能为空"); | |||
| } | |||
| Long couponChannelId = 0L, couponId = 0L; | |||
| Long couponChannelId = 0L, couponId = 0L, orderGroupId = null; | |||
| boolean isPress = false; | |||
| if (StringUtils.isNotBlank(couponChannelIdStr)) { | |||
| @@ -111,11 +112,24 @@ public class WxOrderController extends BaseController { | |||
| WxCouponChannel wxCouponChannel = wxCouponChannelService.getById(couponChannelId); | |||
| if (wxCouponChannel == null) { | |||
| logger.error("couponChannelId convert error, " + couponChannelIdStr); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "找不到发布的频道"); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR); | |||
| } | |||
| if (wxCouponChannel.getTargetAd().equals(EnumCouponChannelType.COUPON_CHANNEL_ID_TIMED.getCode())) { | |||
| Date now = new Date(); | |||
| if (wxCouponChannel.getBeginTime().getTime() > now.getTime()) { | |||
| logger.error("此券活动未开始:" + couponChannelIdStr); | |||
| return new ResultData(ErrorCode.COUPON_CHANNEL_IS_NOT_STARTED); | |||
| } | |||
| if (wxCouponChannel.getEndTime().getTime() < now.getTime()) { | |||
| logger.error("此券活动已结束:" + couponChannelIdStr); | |||
| return new ResultData(ErrorCode.COUPON_CHANNEL_IS_END); | |||
| } | |||
| } | |||
| if (wxCouponChannel.getStatus() == EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode()) { | |||
| logger.error("此券已下架:" + couponChannelIdStr); | |||
| return new ResultData(ErrorCode.COUPON_CHANNEL_IS_TAKE_OFF.getCode(), "此券已下架"); | |||
| return new ResultData(ErrorCode.COUPON_CHANNEL_IS_TAKE_OFF); | |||
| } | |||
| if (StringUtils.isBlank(couponIdStr)) { | |||
| couponId = wxCouponChannel.getCouponId(); | |||
| @@ -143,10 +157,17 @@ public class WxOrderController extends BaseController { | |||
| } | |||
| } | |||
| WxCUser user = getUser(); | |||
| if (orderGroupIdStr != null) { | |||
| try { | |||
| orderGroupId = Long.valueOf(orderGroupIdStr); | |||
| } catch (Exception e) { | |||
| logger.error("orderGroupId转换失败"); | |||
| } | |||
| } | |||
| WxCUser user = getUser(); | |||
| try { | |||
| WxOrder order = wxOrderService.saveCouponOrder(user, couponChannelId, couponId, isPress); | |||
| WxOrder order = wxOrderService.saveCouponOrder(user, couponChannelId, couponId, isPress, orderGroupId); | |||
| return new ResultData(order); | |||
| } catch (MallinkException e) { | |||
| logger.error(e.getMessage()); | |||
| @@ -228,6 +249,21 @@ public class WxOrderController extends BaseController { | |||
| wxOrder.setcUserId(getUser().getId()); | |||
| wxOrder.setSortColumns(WxOrder.Field.UpdateDate_DESC); | |||
| final PageInfo<WxOrderCouponVo> page = wxOrderService.listCUserVoAsPage(wxOrder, pageNum, pageSize); | |||
| Date now = new Date(); | |||
| page.getList().stream().forEach(oc->{ | |||
| if (oc.getValidStartDate() != null && oc.getValidEndDate() != null ) { | |||
| if (oc.getValidStartDate().getTime() > now.getTime()) { | |||
| oc.setValidStatus(EnumCouponOrderValidStatus.PREPARED.getCode()); | |||
| } else if (oc.getValidEndDate().getTime() < now.getTime()) { | |||
| oc.setValidStatus(EnumCouponOrderValidStatus.ENDED.getCode()); | |||
| } else { | |||
| oc.setValidStatus(EnumCouponChannelActivityStatus.STARTED.getCode()); | |||
| } | |||
| } | |||
| }); | |||
| return new ResultData(page); | |||
| } | |||
| @@ -251,6 +287,19 @@ public class WxOrderController extends BaseController { | |||
| WxOrderCouponVo wxOrderCVo = wxOrderService.detailCUserVo(wxOrder); | |||
| if (wxOrderCVo == null) | |||
| return new ResultData(ErrorCode.ORDER_IS_NOT_FIND); | |||
| Date now = new Date(); | |||
| if (wxOrderCVo.getValidStartDate() != null && wxOrderCVo.getValidEndDate() != null ) { | |||
| if (wxOrderCVo.getValidStartDate().getTime() > now.getTime()) { | |||
| wxOrderCVo.setValidStatus(EnumCouponOrderValidStatus.PREPARED.getCode()); | |||
| } else if (wxOrderCVo.getValidEndDate().getTime() < now.getTime()) { | |||
| wxOrderCVo.setValidStatus(EnumCouponOrderValidStatus.ENDED.getCode()); | |||
| } else { | |||
| wxOrderCVo.setValidStatus(EnumCouponChannelActivityStatus.STARTED.getCode()); | |||
| } | |||
| } | |||
| return new ResultData(wxOrderCVo); | |||
| } | |||
| @@ -0,0 +1,138 @@ | |||
| package com.iformall.controller; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxOrderGroup; | |||
| import com.iformall.domain.vo.WxOrderGroupMarketing; | |||
| import com.iformall.enums.EnumOrderStatus; | |||
| import com.iformall.service.WxCouponService; | |||
| import com.iformall.service.WxOrderGroupService; | |||
| 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; | |||
| @RestController | |||
| @RequestMapping("/api/orderGroup") | |||
| @Api(description = "拼团接口") | |||
| public class WxOrderGroupController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| WxOrderService wxOrderService; | |||
| @Autowired | |||
| WxCouponService wxCouponService; | |||
| @Autowired | |||
| WxOrderGroupService wxOrderGroupService; | |||
| @ApiOperation(value = "查询差1个的团购信息") | |||
| @GetMapping("queryRemainOne") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "couponId", value = "券ID", dataType = "Long", paramType = "query", required = true) | |||
| }) | |||
| public ResultData queryRemainOne(@ModelAttribute WxOrderGroup wxOrderGroup) { | |||
| if (wxOrderGroup.getCouponId() == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponId不能为空"); | |||
| } | |||
| wxOrderGroup.setRemainPeople(1); | |||
| wxOrderGroup.setStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING.getCode()); | |||
| wxOrderGroup.setTenantId(getTenantId()); | |||
| return wxOrderGroupService.queryRemainOne(wxOrderGroup, getUserId()); | |||
| } | |||
| @ApiOperation(value = "我的拼团") | |||
| @GetMapping("queryOrderGroup") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), | |||
| }) | |||
| public ResultData queryOrderGroup(Integer pageNum, Integer pageSize) { | |||
| WxOrder wxOrder = new WxOrder(); | |||
| wxOrder.setCUserId(getUserId()); | |||
| wxOrder.setTenantId(getTenantId()); | |||
| final PageInfo<Map<String, Object>> page = wxOrderGroupService.queryOrderGroup(wxOrder, pageNum, pageSize); | |||
| return new ResultData(page); | |||
| } | |||
| @ApiOperation(value = "去拼团") | |||
| @PostMapping("toOrderGroup") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "orderId", value = "orderId", dataType = "Long", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "couponId", value = "couponId", dataType = "Long", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true), | |||
| }) | |||
| public ResultData toOrderGroup(@RequestBody WxOrderGroup wxOrderGroup) { | |||
| if (wxOrderGroup.getId() == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "id不能为空"); | |||
| } | |||
| if (wxOrderGroup.getCouponId() == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponId不能为空"); | |||
| } | |||
| if (wxOrderGroup.getOrderId() == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId不能为空"); | |||
| } | |||
| wxOrderGroup.setTenantId(getTenantId()); | |||
| return wxOrderGroupService.toOrderGroup(wxOrderGroup); | |||
| } | |||
| @ApiOperation(value = "查询拼团状态") | |||
| @GetMapping("queryOrderGroupStatus") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "orderId", value = "orderId", dataType = "Long", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "couponId", value = "couponId", dataType = "Long", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true), | |||
| }) | |||
| public ResultData queryOrderGroupStatus(@ModelAttribute WxOrderGroup wxOrderGroup) { | |||
| if (wxOrderGroup.getId() == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "id不能为空"); | |||
| } | |||
| if (wxOrderGroup.getCouponId() == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponId不能为空"); | |||
| } | |||
| if (wxOrderGroup.getOrderId() == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId不能为空"); | |||
| } | |||
| wxOrderGroup.setTenantId(getTenantId()); | |||
| return wxOrderGroupService.queryOrderGroupStatus(wxOrderGroup); | |||
| } | |||
| @ApiOperation(value = "查询是否已参团") | |||
| @GetMapping("queryAttendStatus") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true), | |||
| }) | |||
| public ResultData queryAttendStatus(@ModelAttribute WxOrderGroup wxOrderGroup) { | |||
| if (wxOrderGroup.getId() == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "id不能为空"); | |||
| } | |||
| wxOrderGroup.setUserId(getUserId()); | |||
| wxOrderGroup.setTenantId(getTenantId()); | |||
| return wxOrderGroupService.queryAttendStatus(wxOrderGroup); | |||
| } | |||
| @ApiOperation(value = "拼团营销分析") | |||
| @GetMapping("queryOrderGroupMarketingList") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "couponId", value = "couponId", dataType = "String", paramType = "query"), | |||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), | |||
| }) | |||
| public ResultData queryOrderGroupMarketingList(@ModelAttribute WxOrderGroupMarketing wxOrderGroupMarketing, Integer pageNum, Integer pageSize) { | |||
| final PageInfo<WxOrderGroupMarketing> page = wxOrderGroupService.queryOrderGroupMarketingList(wxOrderGroupMarketing, pageNum, pageSize); | |||
| return new ResultData(page); | |||
| } | |||
| } | |||
| @@ -7,10 +7,13 @@ import com.iformall.common.ResultData; | |||
| import com.iformall.config.PayProperty; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| import com.iformall.enums.EnumPayStatus; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.WxCouponService; | |||
| import com.iformall.service.WxOrderService; | |||
| import com.iformall.service.WxPayOrderService; | |||
| import com.iformall.utils.IPUtil; | |||
| import io.swagger.annotations.Api; | |||
| @@ -38,6 +41,12 @@ public class WxPayOrderController extends BaseController { | |||
| @Autowired | |||
| private WxPayOrderService wxPayOrderService; | |||
| @Autowired | |||
| private WxOrderService wxOrderService; | |||
| @Autowired | |||
| private WxCouponService wxCouponService; | |||
| @ApiOperation(value = "发起微信小程序支付订单", notes = "{\"orderId\":\"string\"}") | |||
| @RequestMapping(value = "/create", method = RequestMethod.POST) | |||
| public ResultData _create(@RequestBody Map<String, String> paramMap, HttpServletRequest request) throws Exception { | |||
| @@ -108,13 +117,17 @@ public class WxPayOrderController extends BaseController { | |||
| payOrder.setOrderId(orderId); | |||
| payOrder.setPayOrderStatus(status); | |||
| payOrder.setFailReason(reasonStr); | |||
| WxOrder order = null; | |||
| try { | |||
| if(status.equals(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()) && !payOrderIdStr.equals("0")) { | |||
| // 前端提示支付成功, 不作为支付成功标志,只检查支付订单状态 | |||
| // 有价券不走update, callback更新 | |||
| payOrder = wxPayOrderService.getById(payOrderId); | |||
| if(payOrder.getPayOrderStatus().equals(EnumPayStatus.PAY_STATUS_SUCCESS.getCode())) { | |||
| return new ResultData(Result.SUCCESS, "支付状态更新成功"); | |||
| order = wxOrderService.getById(orderId); | |||
| return new ResultData(Result.SUCCESS, "支付状态更新成功", order); | |||
| } else { | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR, "支付未状态,请等待!!"); | |||
| } | |||
| @@ -110,35 +110,14 @@ public class WxUserGrantController extends BaseController { | |||
| if(StringUtils.isBlank(wxAppinfo.getAccessToken())) { | |||
| // 如果没有accessToken,主动获取保存到数据库中,下次访问可以拿来使用 | |||
| try { | |||
| String accessToken = wxMaService.getAccessToken(true); | |||
| wxAppinfo.setAccessToken(accessToken); | |||
| wxAppinfo.setLastTokenTime(new Date()); | |||
| wxAppinfo.setExpiresIn(7200); | |||
| wxAppinfoService.saveOrUpdate(wxAppinfo); | |||
| } catch (WxErrorException e) { | |||
| logger.error(e.getMessage()); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| updateAppAccessToken(wxAppinfo, wxMaService); | |||
| wxMaService = getWeappServiceByAppInfo(wxAppinfo); | |||
| } else { | |||
| // 检查token是否已过期, 小时就重新获取 | |||
| // 检查token是否已过期, 1小时就重新获取 | |||
| Date curDate = new Date(); | |||
| if(curDate.getTime() > wxAppinfo.getLastTokenTime().getTime() + 3600000) { | |||
| try { | |||
| String accessToken = wxMaService.getAccessToken(true); | |||
| wxAppinfo.setAccessToken(accessToken); | |||
| wxAppinfo.setLastTokenTime(new Date()); | |||
| wxAppinfo.setExpiresIn(7200); | |||
| wxAppinfoService.saveOrUpdate(wxAppinfo); | |||
| } catch (WxErrorException e) { | |||
| logger.error(e.getMessage()); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| updateAppAccessToken(wxAppinfo, wxMaService); | |||
| wxMaService = getWeappServiceByAppInfo(wxAppinfo); | |||
| } | |||
| } | |||
| @@ -170,8 +149,7 @@ public class WxUserGrantController extends BaseController { | |||
| try { | |||
| WxCUser user1 = wxCUserService.getByOpenId(user); | |||
| if (user1 != null) { | |||
| user1.createToken(new Date()); | |||
| token = user1.getToken(); | |||
| token = user1.createToken(new Date()); | |||
| resultMap.put("token", token); | |||
| request.setAttribute(AuthorizationInterceptor.LOGIN_USER_KEY, user1.getId()); | |||
| @@ -192,6 +170,7 @@ public class WxUserGrantController extends BaseController { | |||
| extraInfo.put("systemInfo",JSONObject.parseObject(systemInfo)); | |||
| user1.setExtraInfo(extraInfo.toJSONString()); | |||
| user1.setLoginCount(user1.getLoginCount()+1); | |||
| wxCUserService.saveOrUpdate(user1); | |||
| // 成长值 | |||
| try { | |||
| @@ -202,8 +181,7 @@ public class WxUserGrantController extends BaseController { | |||
| wxCUserTagsService.triggerAssignTags(EnumAssignTagsTrigger.ASSIGN_TAGS_TRIGGER_LOGIN,user1); | |||
| } else { | |||
| user.setTenantId(wxAppinfo.getTenantId()); | |||
| user.createToken(new Date()); | |||
| token = user.getToken(); | |||
| token = user.createToken(new Date()); | |||
| user.setRegisterIp(ipaddress); | |||
| if (user.getSceneAddress() == null || user.getSceneAddress().equals("undefined")) | |||
| @@ -219,6 +197,7 @@ public class WxUserGrantController extends BaseController { | |||
| JSONObject extraInfo = new JSONObject(); | |||
| extraInfo.put("systemInfo",JSONObject.parseObject(systemInfo)); | |||
| user.setExtraInfo(extraInfo.toJSONString()); | |||
| user.setLoginCount(0); | |||
| wxCUserService.saveOrUpdate(user); | |||
| @@ -244,6 +223,25 @@ public class WxUserGrantController extends BaseController { | |||
| return new ResultData(resultMap); | |||
| } | |||
| /** | |||
| * WxAppInfo更新accessToken | |||
| * @param wxAppinfo | |||
| * @param wxMaService | |||
| */ | |||
| private void updateAppAccessToken(WxAppinfo wxAppinfo, WxMaService wxMaService) { | |||
| try { | |||
| String accessToken = wxMaService.getAccessToken(true); | |||
| wxAppinfo.setAccessToken(accessToken); | |||
| wxAppinfo.setLastTokenTime(new Date()); | |||
| wxAppinfo.setExpiresIn(7200); | |||
| wxAppinfoService.saveOrUpdate(wxAppinfo); | |||
| } catch (WxErrorException e) { | |||
| logger.error(e.getMessage()); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| } | |||
| /** | |||
| * 获取用户的昵称等信息 | |||
| * @param map | |||
| @@ -1,10 +1,14 @@ | |||
| package com.iformall.interceptor; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import javax.servlet.*; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import java.io.IOException; | |||
| public class HttpServletRequestWrapperFilter implements Filter { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Override | |||
| public void init(FilterConfig filterConfig) throws ServletException { | |||
| @@ -13,7 +17,8 @@ public class HttpServletRequestWrapperFilter implements Filter { | |||
| @Override | |||
| public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | |||
| throws IOException, ServletException { | |||
| logger.debug("doFilter start"); | |||
| long start = System.currentTimeMillis(); | |||
| ServletRequest requestWrapper = null; | |||
| if (request instanceof HttpServletRequest) { | |||
| requestWrapper = new BodyReaderHttpServletRequestWrapper((HttpServletRequest) request); | |||
| @@ -23,7 +28,7 @@ public class HttpServletRequestWrapperFilter implements Filter { | |||
| } else { | |||
| chain.doFilter(requestWrapper, response); | |||
| } | |||
| logger.debug("doFilter end: " + (System.currentTimeMillis()- start) + "ms"); | |||
| } | |||
| @Override | |||
| @@ -34,8 +34,10 @@ public class RequestInterceptor extends HandlerInterceptorAdapter { | |||
| @Override | |||
| public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | |||
| logger.debug("preHandle start"); | |||
| if ("GET".equalsIgnoreCase(request.getMethod())) { | |||
| // 获取不检查幂等 | |||
| logger.debug("preHandle start 1"); | |||
| return true; | |||
| } | |||
| StringBuilder sb = new StringBuilder(); | |||
| @@ -69,23 +71,25 @@ public class RequestInterceptor extends HandlerInterceptorAdapter { | |||
| sb.append(resultBody); | |||
| String key = "request: " + HashUtil.md5(sb.toString()); | |||
| String key = "request-" + HashUtil.md5(sb.toString()); | |||
| if (redisTemplate.opsForValue().setIfAbsent(key, key)) { | |||
| redisTemplate.expire(key, 3, TimeUnit.SECONDS); | |||
| logger.info(key + ": 第一次提交"); | |||
| logger.debug("preHandle start 2"); | |||
| return true; | |||
| } | |||
| logger.info(key + ": 第二次提交"); | |||
| logger.debug("preHandle start 3"); | |||
| return false; | |||
| } | |||
| @Override | |||
| public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { | |||
| logger.debug("postHandle"); | |||
| } | |||
| @Override | |||
| public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { | |||
| logger.debug("afterCompletion"); | |||
| } | |||
| } | |||
| @@ -0,0 +1,72 @@ | |||
| package com.iformall.interceptor; | |||
| import com.iformall.utils.IPUtil; | |||
| import lombok.Data; | |||
| import org.aspectj.lang.JoinPoint; | |||
| import org.aspectj.lang.annotation.AfterReturning; | |||
| import org.aspectj.lang.annotation.Aspect; | |||
| import org.aspectj.lang.annotation.Before; | |||
| import org.aspectj.lang.annotation.Pointcut; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.stereotype.Component; | |||
| import org.springframework.web.context.request.RequestContextHolder; | |||
| import org.springframework.web.context.request.ServletRequestAttributes; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import java.util.Arrays; | |||
| @Aspect | |||
| @Component | |||
| public class WebLogAspect { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Data | |||
| private class MethodInfo { | |||
| Long startTime; | |||
| String url; | |||
| String ip; | |||
| String method; | |||
| String classMethod; | |||
| } | |||
| ThreadLocal<MethodInfo> startInfo = new ThreadLocal<>(); | |||
| @Pointcut("execution(public * com.iformall.controller..*.*(..))") | |||
| public void webLog() {} | |||
| @Before("webLog()") | |||
| public void doBefore(JoinPoint joinPoint) throws Throwable { | |||
| logger.debug("aspect start"); | |||
| // 接收到请求,记录请求内容 | |||
| ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); | |||
| HttpServletRequest request = attributes.getRequest(); | |||
| MethodInfo info = new MethodInfo(); | |||
| info.setUrl(request.getRequestURL().toString()); | |||
| info.setStartTime(System.currentTimeMillis()); | |||
| info.setIp(IPUtil.getIpAddr(request)); | |||
| info.setMethod(request.getMethod()); | |||
| info.setClassMethod(joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName()); | |||
| startInfo.set(info); | |||
| logger.debug("aspect start ..."); | |||
| } | |||
| @AfterReturning(returning = "ret", pointcut = "webLog()") | |||
| public void doAfterReturning(Object ret) throws Throwable { | |||
| logger.debug("aspect after"); | |||
| // 处理完请求,返回内容 | |||
| MethodInfo info = startInfo.get(); | |||
| StringBuilder sb = new StringBuilder(); | |||
| sb.append("URL: ").append(info.getUrl()) | |||
| .append(", METHOD: ").append(info.getMethod()) | |||
| .append(", DO: ").append(info.getClassMethod()) | |||
| .append(", IP: ").append(info.getIp()) | |||
| .append(", SPEND TIME: ").append(System.currentTimeMillis() -info.getStartTime()).append("ms"); | |||
| logger.info(sb.toString()); | |||
| logger.debug("aspect after .."); | |||
| } | |||
| } | |||
| @@ -1,7 +1,9 @@ | |||
| spring: | |||
| profiles: | |||
| include: rabbitMQ | |||
| # JDBC | |||
| datasource: | |||
| url: jdbc:mysql://202.165.179.86:3306/mallinkDev?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&useAffectedRows=true | |||
| username: ENC(dZ8fmrtuBMQYaRytKQgTqg==) | |||
| password: ENC(WGu0+1DPIHrqorDhrbq1+7wr7xNG53mN) | |||
| type: com.alibaba.druid.pool.DruidDataSource | |||
| @@ -64,5 +66,5 @@ fm: | |||
| logging: | |||
| level: | |||
| tk.mybatis: debug | |||
| com.iformall.mapper: debug | |||
| com.iformall: debug | |||
| path: ./logs/c | |||
| @@ -1,7 +1,9 @@ | |||
| spring: | |||
| profiles: | |||
| include: rocketMQ | |||
| # JDBC | |||
| datasource: | |||
| url: jdbc:mysql://formalldb.cfqyqflkdlit.rds.cn-northwest-1.amazonaws.com.cn:3306/mallink?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false | |||
| url: jdbc:mysql://formalldb.cfqyqflkdlit.rds.cn-northwest-1.amazonaws.com.cn:3306/mallink?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false&useAffectedRows=true | |||
| username: ENC(NUzgQOdJnCbVLKT6BaX0aw==) | |||
| password: ENC(mvuoDRiu0jqYaKNRwwTuXZ6U7aoIaqsjdiPqTLgi/nY=) | |||
| type: com.alibaba.druid.pool.DruidDataSource | |||
| @@ -45,6 +47,14 @@ spring: | |||
| auth: true | |||
| starttls: | |||
| enable: true | |||
| # RABBITMQ | |||
| rabbitmq: | |||
| host: localhost | |||
| port: 5672 | |||
| username: ENC(lRmLd6EzgeY1RT5ktcHv9g==) | |||
| password: ENC(gBI8mCjr3OC0v57jcnSb660Ux7mW03K2oePgvohhg7w=) | |||
| publisher-confirms: true | |||
| virtual-host: / | |||
| aws: | |||
| clientRegion: cn-northwest-1 | |||
| @@ -1,7 +1,7 @@ | |||
| spring: | |||
| # JDBC | |||
| datasource: | |||
| url: jdbc:mysql://formalldb.cfqyqflkdlit.rds.cn-northwest-1.amazonaws.com.cn:3306/mallinkTest?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false | |||
| url: jdbc:mysql://formalldb.cfqyqflkdlit.rds.cn-northwest-1.amazonaws.com.cn:3306/mallinkTest?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false&useAffectedRows=true | |||
| username: ENC(Uc0AjgkytxHHCwZrmDASWg==) | |||
| password: ENC(nV4Mi3bEbBx0Fj7uUyYH55eTaqsFMjKvmNzagicH4pc=) | |||
| type: com.alibaba.druid.pool.DruidDataSource | |||
| @@ -45,6 +45,14 @@ spring: | |||
| auth: true | |||
| starttls: | |||
| enable: true | |||
| # RABBITMQ | |||
| rabbitmq: | |||
| host: 127.0.0.1 | |||
| port: 5672 | |||
| username: ENC(aSRr6mnSryEqzHHz1hJf1g==) | |||
| password: ENC(GnjF/mdqKdvmDYC0tIIso7+20/jBALPw39tiWCYJ4iw=) | |||
| publisher-confirms: true | |||
| virtual-host: / | |||
| aws: | |||
| clientRegion: cn-northwest-1 | |||
| @@ -12,6 +12,15 @@ spring: | |||
| date-format: yyyy-MM-dd HH:mm:ss | |||
| time-zone: GMT+8 | |||
| default-property-inclusion: non_null | |||
| rocketmq: | |||
| nameServer: 127.0.0.1:9876 | |||
| producer: | |||
| retry-times-when-send-async-failed: 0 | |||
| send-msg-timeout: 300000 | |||
| compress-msg-body-over-howmuch: 4096 | |||
| max-message-size: 4194304 | |||
| retry-another-broker-when-not-store-ok: false | |||
| retry-times-when-send-failed: 2 | |||
| # @{link} https://github.com/abel533 | |||
| #Mybatis | |||
| @@ -0,0 +1,35 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | |||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||
| <modelVersion>4.0.0</modelVersion> | |||
| <parent> | |||
| <artifactId>mallink</artifactId> | |||
| <groupId>com.iformall</groupId> | |||
| <version>1.0</version> | |||
| </parent> | |||
| <artifactId>mallinkMQConsumer</artifactId> | |||
| <dependencies> | |||
| <dependency> | |||
| <groupId>com.iformall</groupId> | |||
| <artifactId>mallinkService</artifactId> | |||
| <version>1.0</version> | |||
| </dependency> | |||
| </dependencies> | |||
| <build> | |||
| <plugins> | |||
| <plugin> | |||
| <groupId>org.springframework.boot</groupId> | |||
| <artifactId>spring-boot-maven-plugin</artifactId> | |||
| <configuration> | |||
| <executable>true</executable> | |||
| </configuration> | |||
| </plugin> | |||
| </plugins> | |||
| </build> | |||
| </project> | |||
| @@ -0,0 +1,35 @@ | |||
| package com.iformall; | |||
| import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; | |||
| import org.rocketmq.starter.annotation.EnableRocketMQ; | |||
| import org.springframework.beans.factory.annotation.Value; | |||
| import org.springframework.boot.SpringApplication; | |||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | |||
| import org.springframework.context.annotation.Bean; | |||
| import springfox.documentation.swagger2.annotations.EnableSwagger2; | |||
| import tk.mybatis.spring.annotation.MapperScan; | |||
| /** | |||
| * @author chenkx | |||
| * @date 2017-12-26 | |||
| */ | |||
| @SpringBootApplication | |||
| @MapperScan(basePackages = {"com.iformall.mapper"}) | |||
| @EnableSwagger2 | |||
| @EnableRocketMQ | |||
| @EnableEncryptableProperties | |||
| public class ConsumerApplication { | |||
| @Value("${fm.exception}") | |||
| private boolean fmException; | |||
| @Bean | |||
| public boolean isFmException() { | |||
| return fmException; | |||
| } | |||
| public static void main(String[] args) { | |||
| SpringApplication.run(ConsumerApplication.class, args); | |||
| } | |||
| } | |||
| @@ -0,0 +1,52 @@ | |||
| package com.iformall.config; | |||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||
| import org.springframework.stereotype.Component; | |||
| /** | |||
| * @author Stormeye | |||
| */ | |||
| @Component | |||
| @ConfigurationProperties(prefix = "aws") | |||
| public class AwsProperty { | |||
| // AWS ACCESS KEY | |||
| private String access; | |||
| private String secret; | |||
| private String clientRegion; | |||
| private String bucketName; | |||
| public String getAccess() { | |||
| return access; | |||
| } | |||
| public void setAccess(String access) { | |||
| this.access = access; | |||
| } | |||
| public String getSecret() { | |||
| return secret; | |||
| } | |||
| public void setSecret(String secret) { | |||
| this.secret = secret; | |||
| } | |||
| public String getClientRegion() { | |||
| return clientRegion; | |||
| } | |||
| public void setClientRegion(String clientRegion) { | |||
| this.clientRegion = clientRegion; | |||
| } | |||
| public String getBucketName() { | |||
| return bucketName; | |||
| } | |||
| public void setBucketName(String bucketName) { | |||
| this.bucketName = bucketName; | |||
| } | |||
| } | |||
| @@ -0,0 +1,24 @@ | |||
| package com.iformall.config; | |||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||
| import org.springframework.stereotype.Component; | |||
| /** | |||
| * @author Stormeye | |||
| */ | |||
| @Component | |||
| @ConfigurationProperties(prefix = "pay") | |||
| public class PayProperty { | |||
| /** | |||
| * 真实支付 | |||
| */ | |||
| private boolean real; | |||
| public boolean isReal() { | |||
| return real; | |||
| } | |||
| public void setReal(boolean real) { | |||
| this.real = real; | |||
| } | |||
| } | |||
| @@ -0,0 +1,129 @@ | |||
| package com.iformall.config; | |||
| import com.iformall.domain.po.PushLimit; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxScoreRules; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.cache.CacheManager; | |||
| import org.springframework.cache.annotation.CachingConfigurerSupport; | |||
| import org.springframework.cache.annotation.EnableCaching; | |||
| import org.springframework.context.annotation.Bean; | |||
| import org.springframework.context.annotation.Configuration; | |||
| import org.springframework.data.redis.cache.RedisCacheConfiguration; | |||
| import org.springframework.data.redis.cache.RedisCacheManager; | |||
| import org.springframework.data.redis.connection.RedisConnectionFactory; | |||
| import org.springframework.data.redis.core.RedisTemplate; | |||
| import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; | |||
| import org.springframework.data.redis.serializer.StringRedisSerializer; | |||
| import java.time.Duration; | |||
| import java.util.HashMap; | |||
| import java.util.HashSet; | |||
| import java.util.Map; | |||
| import java.util.Set; | |||
| /** | |||
| * Created by Stormeye on 2018/10/1. | |||
| */ | |||
| @Configuration | |||
| @EnableCaching | |||
| public class RedisConfig extends CachingConfigurerSupport { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| //缓存管理器 | |||
| @Bean | |||
| public CacheManager cacheManager(RedisConnectionFactory connectionFactory) { | |||
| /* | |||
| //user信息缓存配置 | |||
| RedisCacheConfiguration userCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig().entryTtl(Duration.ofSeconds(10)).disableCachingNullValues().prefixKeysWith("user"); | |||
| Map<String, RedisCacheConfiguration> redisCacheConfigurationMap = new HashMap<>(); | |||
| redisCacheConfigurationMap.put("user", userCacheConfiguration); | |||
| //初始化一个RedisCacheWriter | |||
| RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory); | |||
| // 设置CacheManager的值序列化方式为JdkSerializationRedisSerializer,但其实RedisCacheConfiguration默认就是使用StringRedisSerializer序列化key,JdkSerializationRedisSerializer序列化value,所以以下注释代码为默认实现 | |||
| // ClassLoader loader = this.getClass().getClassLoader(); | |||
| // JdkSerializationRedisSerializer jdkSerializer = new JdkSerializationRedisSerializer(loader); | |||
| // RedisSerializationContext.SerializationPair<Object> pair = RedisSerializationContext.SerializationPair.fromSerializer(jdkSerializer); | |||
| // RedisCacheConfiguration defaultCacheConfig = RedisCacheConfiguration.defaultCacheConfig().serializeValuesWith(pair); | |||
| RedisCacheConfiguration defaultCacheConfig = RedisCacheConfiguration.defaultCacheConfig(); | |||
| //设置默认超过期时间是30秒 | |||
| defaultCacheConfig.entryTtl(Duration.ofSeconds(30)); | |||
| //初始化RedisCacheManager | |||
| RedisCacheManager cacheManager = new RedisCacheManager(redisCacheWriter, defaultCacheConfig, redisCacheConfigurationMap); | |||
| return cacheManager; | |||
| */ | |||
| RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig(); // 生成一个默认配置,通过config对象即可对缓存进行自定义配置 | |||
| config = config.entryTtl(Duration.ofMinutes(1)) // 设置缓存的默认过期时间,也是使用Duration设置 | |||
| .disableCachingNullValues(); // 不缓存空值 | |||
| // 设置一个初始化的缓存空间set集合 | |||
| Set<String> cacheNames = new HashSet<>(); | |||
| cacheNames.add("my-redis-cache1"); | |||
| cacheNames.add("my-redis-cache2"); | |||
| // 对每个缓存空间应用不同的配置 | |||
| Map<String, RedisCacheConfiguration> configMap = new HashMap<>(); | |||
| configMap.put("my-redis-cache1", config); | |||
| configMap.put("my-redis-cache2", config.entryTtl(Duration.ofSeconds(120))); | |||
| RedisCacheManager cacheManager = RedisCacheManager.builder(connectionFactory) // 使用自定义的缓存配置初始化一个cacheManager | |||
| .initialCacheNames(cacheNames) // 注意这两句的调用顺序,一定要先调用该方法设置初始化的缓存名,再初始化相关的配置 | |||
| .withInitialCacheConfigurations(configMap) | |||
| .build(); | |||
| return cacheManager; | |||
| } | |||
| @Bean("pushLimitRedisTemplate") | |||
| public RedisTemplate<String, PushLimit> getPushLimitRedisTemplate(RedisConnectionFactory connectionFactory) { | |||
| RedisTemplate<String, PushLimit> template = new RedisTemplate<String, PushLimit>(); | |||
| Jackson2JsonRedisSerializer<PushLimit> j = new Jackson2JsonRedisSerializer<PushLimit>(PushLimit.class); | |||
| // value值的序列化 | |||
| template.setValueSerializer(j); | |||
| template.setHashKeySerializer(j); | |||
| // key的序列化 | |||
| template.setKeySerializer(new StringRedisSerializer()); | |||
| template.setHashKeySerializer(new StringRedisSerializer()); | |||
| template.setConnectionFactory(connectionFactory); | |||
| return template; | |||
| } | |||
| @Bean("scoreRuleRedisTemplate") | |||
| public RedisTemplate<String, WxScoreRules> getScoreRuleRedisTemplate(RedisConnectionFactory connectionFactory) { | |||
| RedisTemplate<String, WxScoreRules> template = new RedisTemplate<String, WxScoreRules>(); | |||
| Jackson2JsonRedisSerializer<WxScoreRules> j = new Jackson2JsonRedisSerializer<WxScoreRules>(WxScoreRules.class); | |||
| // value值的序列化 | |||
| template.setValueSerializer(j); | |||
| template.setHashKeySerializer(j); | |||
| // key的序列化 | |||
| template.setKeySerializer(new StringRedisSerializer()); | |||
| template.setHashKeySerializer(new StringRedisSerializer()); | |||
| template.setConnectionFactory(connectionFactory); | |||
| return template; | |||
| } | |||
| @Bean("cuserTokenRedisTemplate") | |||
| public RedisTemplate<String, WxCUser> getCUserTokenRedisTemplate(RedisConnectionFactory connectionFactory) { | |||
| RedisTemplate<String, WxCUser> template = new RedisTemplate<String, WxCUser>(); | |||
| Jackson2JsonRedisSerializer<WxCUser> j = new Jackson2JsonRedisSerializer<WxCUser>(WxCUser.class); | |||
| // value值的序列化 | |||
| template.setValueSerializer(j); | |||
| template.setHashKeySerializer(j); | |||
| // key的序列化 | |||
| template.setKeySerializer(new StringRedisSerializer()); | |||
| template.setHashKeySerializer(new StringRedisSerializer()); | |||
| template.setConnectionFactory(connectionFactory); | |||
| return template; | |||
| } | |||
| } | |||
| @@ -0,0 +1,52 @@ | |||
| package com.iformall.config; | |||
| import javax.servlet.*; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import java.io.IOException; | |||
| import java.util.Optional; | |||
| /** | |||
| * 前后端分离RESTful接口过滤器 | |||
| * | |||
| * @author xuguoqin | |||
| * | |||
| */ | |||
| public class RestFilter implements Filter { | |||
| @Override | |||
| public void init(FilterConfig filterConfig) throws ServletException { | |||
| } | |||
| @Override | |||
| public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | |||
| throws IOException, ServletException { | |||
| HttpServletRequest req = null; | |||
| if (request instanceof HttpServletRequest) { | |||
| req = (HttpServletRequest) request; | |||
| } | |||
| HttpServletResponse res = null; | |||
| if (response instanceof HttpServletResponse) { | |||
| res = (HttpServletResponse) response; | |||
| } | |||
| if (req != null && res != null) { | |||
| //设置允许传递的参数 | |||
| res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization"); | |||
| //设置允许带上cookie | |||
| res.setHeader("Access-Control-Allow-Credentials", "true"); | |||
| String origin = Optional.ofNullable(req.getHeader("Origin")).orElse(req.getHeader("Referer")); | |||
| //设置允许的请求来源 | |||
| res.setHeader("Access-Control-Allow-Origin", origin); | |||
| //设置允许的请求方法 | |||
| res.setHeader("Access-Control-Allow-Methods", "GET, POST, PATCH, PUT, DELETE, OPTIONS"); | |||
| } | |||
| chain.doFilter(request, response); | |||
| } | |||
| @Override | |||
| public void destroy() { | |||
| } | |||
| } | |||
| @@ -0,0 +1,24 @@ | |||
| package com.iformall.config; | |||
| import org.springframework.context.annotation.Bean; | |||
| import org.springframework.context.annotation.Configuration; | |||
| import org.springframework.http.client.ClientHttpRequestFactory; | |||
| import org.springframework.http.client.SimpleClientHttpRequestFactory; | |||
| import org.springframework.web.client.RestTemplate; | |||
| @Configuration | |||
| public class RestTemplateConfig { | |||
| @Bean | |||
| public RestTemplate restTemplate(ClientHttpRequestFactory factory) { | |||
| return new RestTemplate(factory); | |||
| } | |||
| @Bean | |||
| public ClientHttpRequestFactory simpleClientHttpRequestFactory() { | |||
| SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); | |||
| factory.setReadTimeout(5000);//ms | |||
| factory.setConnectTimeout(10000);//ms | |||
| return factory; | |||
| } | |||
| } | |||
| @@ -0,0 +1,79 @@ | |||
| package com.iformall.config; | |||
| import com.fasterxml.jackson.annotation.JsonInclude; | |||
| import com.fasterxml.jackson.databind.DeserializationConfig; | |||
| import com.fasterxml.jackson.databind.DeserializationFeature; | |||
| import com.fasterxml.jackson.databind.ObjectMapper; | |||
| import com.fasterxml.jackson.databind.module.SimpleModule; | |||
| import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; | |||
| import org.springframework.context.annotation.Configuration; | |||
| import org.springframework.http.converter.HttpMessageConverter; | |||
| 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 java.math.BigDecimal; | |||
| import java.math.BigInteger; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.List; | |||
| @Configuration | |||
| @EnableWebMvc | |||
| public class WebConfig implements WebMvcConfigurer { | |||
| @Override | |||
| public void addResourceHandlers(ResourceHandlerRegistry registry) { | |||
| registry.addResourceHandler("swagger-ui.html") | |||
| .addResourceLocations("classpath:/META-INF/resources/"); | |||
| registry.addResourceHandler("/webjars/**") | |||
| .addResourceLocations("classpath:/META-INF/resources/webjars/"); | |||
| //registry.addResourceHandler("/app/**").addResourceLocations("classpath:/app/"); | |||
| } | |||
| @Override | |||
| public void addCorsMappings(CorsRegistry registry) { | |||
| registry.addMapping("/**") | |||
| .allowedOrigins("*") | |||
| .allowCredentials(true) | |||
| .allowedMethods("GET", "POST", "DELETE", "PUT") | |||
| .maxAge(3600); | |||
| } | |||
| @Override | |||
| public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { | |||
| MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter(); | |||
| //ObjectMapper 是Jackson库的主要类。它提供一些功能将转换成Java对象匹配JSON结构,反之亦然 | |||
| ObjectMapper objectMapper = new ObjectMapper(); | |||
| SimpleModule simpleModule = new SimpleModule(); | |||
| //不显示为null的字段 | |||
| objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); | |||
| DeserializationConfig dc = objectMapper.getDeserializationConfig(); | |||
| // 设置反序列化日期格式、忽略不存在get、set的属性 | |||
| objectMapper.setConfig( | |||
| dc.with(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")) | |||
| .without(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) | |||
| ); | |||
| //序列化将Long转String类型 | |||
| simpleModule.addSerializer(Long.class, ToStringSerializer.instance); | |||
| simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); | |||
| SimpleModule bigIntegerModule = new SimpleModule(); | |||
| //序列化将BigInteger转String类型 | |||
| bigIntegerModule.addSerializer(BigInteger.class, ToStringSerializer.instance); | |||
| SimpleModule bigDecimalModule = new SimpleModule(); | |||
| //序列化将BigDecimal转String类型 | |||
| bigDecimalModule.addSerializer(BigDecimal.class, ToStringSerializer.instance); | |||
| objectMapper.registerModule(simpleModule); | |||
| objectMapper.registerModule(bigDecimalModule); | |||
| objectMapper.registerModule(bigIntegerModule); | |||
| jackson2HttpMessageConverter.setObjectMapper(objectMapper); | |||
| converters.add(jackson2HttpMessageConverter); | |||
| } | |||
| } | |||
| @@ -0,0 +1,32 @@ | |||
| package com.iformall.controller; | |||
| import com.iformall.common.ResultData; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Value; | |||
| import org.springframework.web.bind.annotation.GetMapping; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| @RestController | |||
| @Api(description = "登录相关接口") | |||
| public class HomeController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Value("${version}") | |||
| private String version; | |||
| @Value("${spring.mail.username}") | |||
| private String from; | |||
| @ApiOperation("获取后端版本号") | |||
| @GetMapping("/version") | |||
| public ResultData version() { | |||
| return new ResultData(version); | |||
| } | |||
| } | |||
| @@ -0,0 +1,73 @@ | |||
| package com.iformall.mq; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.mapper.WxMsgRecordMapper; | |||
| import com.iformall.service.impl.SendCallBackSmsServiceImpl; | |||
| import com.iformall.service.impl.SendEmailServiceImpl; | |||
| import com.iformall.service.impl.SendSmartAppMsgServiceImpl; | |||
| import com.iformall.service.impl.SendSmsServiceImpl; | |||
| import com.iformall.utils.JsonUtil; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| /** | |||
| * 消息消费入口 | |||
| */ | |||
| @Service | |||
| public class MqBaseConsumer { | |||
| private final Logger log = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxMsgRecordMapper wxMsgRecordMapper; | |||
| @Autowired | |||
| private SendSmsServiceImpl sendSmsService; | |||
| @Autowired | |||
| private SendCallBackSmsServiceImpl sendCallBackSmsService; | |||
| @Autowired | |||
| private SendEmailServiceImpl sendEmailService; | |||
| @Autowired | |||
| private SendSmartAppMsgServiceImpl sendSmartAppMsgService; | |||
| @Autowired | |||
| private MqBaseProducer mqBaseProducer; | |||
| public void doMessage(String message) { | |||
| log.info("received message: {}", message); | |||
| BaseMsg baseMsg = null; | |||
| try { | |||
| baseMsg = (BaseMsg)JsonUtil.readValue(message,BaseMsg.class); | |||
| if(EnumMsgRecordType.SMS.getCode().equals(baseMsg.getMsgType())){ | |||
| //短信 | |||
| sendSmsService.send((WxMsgRecord)JsonUtil.readValue(message,WxMsgRecord.class)); | |||
| }else if(EnumMsgRecordType.SMS_CALLBACK.getCode().equals(baseMsg.getMsgType())){ | |||
| //业务短信 | |||
| sendCallBackSmsService.send((WxMsg)JsonUtil.readValue(message,WxMsg.class)); | |||
| }else if(EnumMsgRecordType.EMAIL.getCode().equals(baseMsg.getMsgType())){ | |||
| //邮件 | |||
| sendEmailService.send((MailMsg)JsonUtil.readValue(message,MailMsg.class)); | |||
| }else if(EnumMsgRecordType.SMART_APP.getCode().equals(baseMsg.getMsgType())){ | |||
| //微信小程序 | |||
| sendSmartAppMsgService.send((SmartAppMsg)JsonUtil.readValue(message,SmartAppMsg.class)); | |||
| } | |||
| baseMsg.setMsgStatus(EnumMsgRecordStatus.CONSUME_SUCC.getCode()); | |||
| wxMsgRecordMapper.update(baseMsg); | |||
| }catch (Exception e){ | |||
| //todo:测试下 | |||
| if(null != baseMsg){ | |||
| if(baseMsg.getDelayTimeLevel() < 3){ | |||
| baseMsg.setDelayTimeLevel(3); //10s后重试 | |||
| mqBaseProducer.sendMessage(baseMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||
| }else{ | |||
| baseMsg.setStatusMessage(e.getMessage()); | |||
| baseMsg.setMsgStatus(EnumMsgRecordStatus.CONSUME_FAIL.getCode()); | |||
| wxMsgRecordMapper.update(baseMsg); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,42 @@ | |||
| package com.iformall.mq.impl; | |||
| import com.iformall.mq.MqBaseConsumer; | |||
| import com.iformall.mq.MQConfig; | |||
| import org.springframework.amqp.core.*; | |||
| import org.springframework.amqp.rabbit.annotation.RabbitListener; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.context.annotation.Profile; | |||
| import org.springframework.stereotype.Component; | |||
| import javax.annotation.PostConstruct; | |||
| @Component | |||
| @Profile(MQConfig.Impl.RABBIT_MQ) | |||
| public class RabbitMqConsumer extends MqBaseConsumer { | |||
| String queueName = "topic-1"; | |||
| @Autowired | |||
| private AmqpAdmin amqpAdmin; | |||
| @PostConstruct | |||
| public void init() { | |||
| DirectExchange exchange = new DirectExchange(queueName); | |||
| Queue queue = new Queue(queueName); | |||
| Binding binding = BindingBuilder.bind(queue).to(exchange).withQueueName(); | |||
| amqpAdmin.declareExchange(exchange); | |||
| amqpAdmin.declareQueue(queue); | |||
| amqpAdmin.declareBinding(binding); | |||
| } | |||
| @Autowired | |||
| private AmqpTemplate rabbitTemplate; | |||
| public void send(String msg) { | |||
| rabbitTemplate.convertAndSend(queueName, msg); | |||
| } | |||
| @RabbitListener(queues = "topic-1") | |||
| public void onMessage(String message) { | |||
| doMessage(message); | |||
| } | |||
| } | |||
| @@ -0,0 +1,19 @@ | |||
| package com.iformall.mq.impl; | |||
| import com.iformall.mq.MqBaseConsumer; | |||
| import com.iformall.mq.MQConfig; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.rocketmq.starter.annotation.RocketMQListener; | |||
| import org.rocketmq.starter.annotation.RocketMQMessage; | |||
| import org.springframework.context.annotation.Profile; | |||
| @Slf4j | |||
| @Profile(MQConfig.Impl.ROCKET_MQ) | |||
| @RocketMQListener(topic = "topic-1",consumeThreadMax=100,consumeThreadMin = 20) | |||
| public class RocketMqConsumer extends MqBaseConsumer { | |||
| @RocketMQMessage(messageClass = String.class, tag = "tag-1") | |||
| public void onMessage(String message) { | |||
| doMessage(message); | |||
| } | |||
| } | |||
| @@ -0,0 +1,89 @@ | |||
| spring: | |||
| profiles: | |||
| include: rabbitMQ | |||
| # JDBC | |||
| datasource: | |||
| url: jdbc:mysql://202.165.179.86:3306/mallinkDev?characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useUnicode=true&useSSL=false&useAffectedRows=true | |||
| username: ENC(dZ8fmrtuBMQYaRytKQgTqg==) | |||
| password: ENC(WGu0+1DPIHrqorDhrbq1+7wr7xNG53mN) | |||
| type: com.alibaba.druid.pool.DruidDataSource | |||
| driver-class-name: com.mysql.cj.jdbc.Driver | |||
| filters: stat | |||
| maxActive: 20 | |||
| initialSize: 1 | |||
| maxWait: 60000 | |||
| minIdle: 1 | |||
| timeBetweenEvictionRunsMillis: 28000 | |||
| minEvictableIdleTimeMillis: 28000 | |||
| validationQuery: select 'x' | |||
| testWhileIdle: true | |||
| testOnBorrow: false | |||
| testOnReturn: false | |||
| poolPreparedStatements: true | |||
| maxOpenPreparedStatements: 20 | |||
| connectionProperties: "druid.stat.mergeSql=true;druid.stat.slowSqlMillis=6000" | |||
| #jackson: | |||
| #date-format: yyyy-MM-dd HH:mm:ss | |||
| # REDIS | |||
| redis: | |||
| host: 202.165.179.86 | |||
| port: 6379 | |||
| password: ENC(aYJ3Wr2UWtkORRQjjrWWpz2ZeTISsHOA) | |||
| timeout: 3600 | |||
| expire: 1800 #30分钟 | |||
| database: 1 | |||
| defaultExpiration: 2592000 # 默认生命周期30天 | |||
| jedis: | |||
| pool: | |||
| max-active: 50 | |||
| max-idle: 50 | |||
| max-wait: -1 | |||
| min-idle: 10 | |||
| mail: | |||
| host: smtp.exmail.qq.com | |||
| username: ENC(R0bER9E9OB9/YQcpNXMyYDwofNVb8/pFl4nrApS8mi0=) | |||
| password: ENC(50YqJd0iK/2r2YnmEd5RKaki3ktU73UDapBJrVYfqmc=) # 授权密码 | |||
| properties: | |||
| mail: | |||
| smtp: | |||
| auth: true | |||
| starttls: | |||
| enable: true | |||
| rocketmq: | |||
| nameServer: 127.0.0.1:9876 | |||
| producer: | |||
| retry-times-when-send-async-failed: 0 | |||
| send-msg-timeout: 300000 | |||
| compress-msg-body-over-howmuch: 4096 | |||
| max-message-size: 4194304 | |||
| retry-another-broker-when-not-store-ok: false | |||
| retry-times-when-send-failed: 2 | |||
| rabbitmq: | |||
| host: 202.165.179.86 | |||
| port: 5672 | |||
| username: fumao | |||
| password: f8l89&*%%u7f1t22 | |||
| publisher-confirms: true | |||
| virtual-host: / | |||
| aws: | |||
| clientRegion: cn-northwest-1 | |||
| bucketName: iformall-net | |||
| access: ENC(3gx5ghDFBqGrEhO3Wf8aYmXsnwHO7Cj3HNKJGOeUj0o=) | |||
| secret: ENC(HVKIJwCJKVXLlUpGlQPwNqJOlnpxn4xYuy91SH0seTSm2uAttIQHvA49fXWWax90v5wloIk0QuU=) | |||
| jasypt: | |||
| encryptor: | |||
| password: oRqdnDbK5pj3eMmB | |||
| fm: | |||
| exception: false | |||
| logging: | |||
| level: | |||
| tk.mybatis: debug | |||
| com.iformall.mapper: debug | |||
| path: ./logs/s | |||
| @@ -0,0 +1,75 @@ | |||
| spring: | |||
| profiles: | |||
| include: rocketMQ | |||
| # JDBC | |||
| datasource: | |||
| url: jdbc:mysql://formalldb.cfqyqflkdlit.rds.cn-northwest-1.amazonaws.com.cn:3306/mallink?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false&useAffectedRows=true | |||
| username: ENC(NUzgQOdJnCbVLKT6BaX0aw==) | |||
| password: ENC(mvuoDRiu0jqYaKNRwwTuXZ6U7aoIaqsjdiPqTLgi/nY=) | |||
| type: com.alibaba.druid.pool.DruidDataSource | |||
| driver-class-name: com.mysql.cj.jdbc.Driver | |||
| filters: stat | |||
| maxActive: 20 | |||
| initialSize: 1 | |||
| maxWait: 60000 | |||
| minIdle: 1 | |||
| timeBetweenEvictionRunsMillis: 28000 | |||
| minEvictableIdleTimeMillis: 28000 | |||
| validationQuery: select 'x' | |||
| testWhileIdle: true | |||
| testOnBorrow: false | |||
| testOnReturn: false | |||
| poolPreparedStatements: true | |||
| maxOpenPreparedStatements: 20 | |||
| connectionProperties: "druid.stat.mergeSql=true;druid.stat.slowSqlMillis=6000" | |||
| # REDIS | |||
| redis: | |||
| host: 127.0.0.1 | |||
| port: 6379 | |||
| password: ENC(8gYU47Fu93NUJPhwPCiPbAT+6VFA1YDx1egK4Z0Nl6w=) | |||
| timeout: 3600 | |||
| expire: 1800 #30分钟 | |||
| database: 1 | |||
| defaultExpiration: 2592000 # 默认生命周期30天 | |||
| jedis: | |||
| pool: | |||
| max-active: 8 | |||
| max-idle: 8 | |||
| max-wait: -1 | |||
| min-idle: 0 | |||
| mail: | |||
| host: smtp.exmail.qq.com | |||
| username: ENC(I2YKxnRVPY7J1r/bwzwHOhQCjj3nVqCWEbVTJvBq7y0=) | |||
| password: ENC(APQMO9XQRzMKd0eap+oSSOYH9MQe/r5K0YFF9A9mizU=) # 授权密码 | |||
| properties: | |||
| mail: | |||
| smtp: | |||
| auth: true | |||
| starttls: | |||
| enable: true | |||
| # RABBITMQ | |||
| rabbitmq: | |||
| host: localhost | |||
| port: 5672 | |||
| username: ENC(lRmLd6EzgeY1RT5ktcHv9g==) | |||
| password: ENC(gBI8mCjr3OC0v57jcnSb660Ux7mW03K2oePgvohhg7w=) | |||
| publisher-confirms: true | |||
| virtual-host: / | |||
| aws: | |||
| clientRegion: cn-northwest-1 | |||
| bucketName: iformall-net | |||
| access: ENC(a6SN1sZ1enNL49ypiOXkg/pPPAnZD8H4buQFTTKN08s=) | |||
| secret: ENC(5P5ff4bTMJUbXVR4ZsM03UHzOKZ4+Zg5Iutcdkyp/Quny/oXg+A4KpfwEyGarlLu3vQMJahGP5M=) | |||
| fm: | |||
| exception: true | |||
| logging: | |||
| level: | |||
| tk.mybatis: debug | |||
| com.iformall: debug | |||
| path: ./logs/s | |||
| @@ -0,0 +1,71 @@ | |||
| spring: | |||
| # JDBC | |||
| datasource: | |||
| url: jdbc:mysql://formalldb.cfqyqflkdlit.rds.cn-northwest-1.amazonaws.com.cn:3306/mallinkTest?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false&useAffectedRows=true | |||
| username: ENC(Uc0AjgkytxHHCwZrmDASWg==) | |||
| password: ENC(nV4Mi3bEbBx0Fj7uUyYH55eTaqsFMjKvmNzagicH4pc=) | |||
| type: com.alibaba.druid.pool.DruidDataSource | |||
| driver-class-name: com.mysql.cj.jdbc.Driver | |||
| filters: stat | |||
| maxActive: 20 | |||
| initialSize: 1 | |||
| maxWait: 60000 | |||
| minIdle: 1 | |||
| timeBetweenEvictionRunsMillis: 28000 | |||
| minEvictableIdleTimeMillis: 28000 | |||
| validationQuery: select 'x' | |||
| testWhileIdle: true | |||
| testOnBorrow: false | |||
| testOnReturn: false | |||
| poolPreparedStatements: true | |||
| maxOpenPreparedStatements: 20 | |||
| connectionProperties: "druid.stat.mergeSql=true;druid.stat.slowSqlMillis=6000" | |||
| # REDIS | |||
| redis: | |||
| host: 127.0.0.1 | |||
| port: 6379 | |||
| password: ENC(QFwqv3NshvvGhFPiP8rwhvbnxk+rFSqhJi8Pw6TogSg=) | |||
| timeout: 3600 | |||
| expire: 1800 #30分钟 | |||
| database: 1 | |||
| defaultExpiration: 2592000 # 默认生命周期30天 | |||
| jedis: | |||
| pool: | |||
| max-active: 8 | |||
| max-idle: 8 | |||
| max-wait: -1 | |||
| min-idle: 0 | |||
| mail: | |||
| host: smtp.exmail.qq.com | |||
| username: ENC(HFbRXtAFVxU36Hk0yT3reyvRuLrw3RhMlbxFj9Ev/VY=) | |||
| password: ENC(pk4+/3C5n2hMYmgi+VTqI4P1m77DllW8y4KElMXXmIo=) # 授权密码 | |||
| properties: | |||
| mail: | |||
| smtp: | |||
| auth: true | |||
| starttls: | |||
| enable: true | |||
| # RABBITMQ | |||
| rabbitmq: | |||
| host: 127.0.0.1 | |||
| port: 5672 | |||
| username: ENC(aSRr6mnSryEqzHHz1hJf1g==) | |||
| password: ENC(GnjF/mdqKdvmDYC0tIIso7+20/jBALPw39tiWCYJ4iw=) | |||
| publisher-confirms: true | |||
| virtual-host: / | |||
| aws: | |||
| clientRegion: cn-northwest-1 | |||
| bucketName: iformall-net | |||
| access: ENC(NCLcmjwKpAWdn/abD17OKIY7yKepVLWzEpqRYUlURCw=) | |||
| secret: ENC(TRcZqql0Rq5PExlMeH/4WiZ/i02b8FXKmLTBChJmbluTa1uoLS9LrHyNEMrqe1DK+QgOAdvqGBo=) | |||
| fm: | |||
| exception: true | |||
| logging: | |||
| level: | |||
| tk.mybatis: debug | |||
| com.iformall: debug | |||
| path: ./logs/s | |||
| @@ -0,0 +1,73 @@ | |||
| server: | |||
| port: 5001 | |||
| servlet: | |||
| context-path: /mq | |||
| spring: | |||
| application: | |||
| name: mallink | |||
| profiles: | |||
| active: dev | |||
| jackson: | |||
| date-format: yyyy-MM-dd HH:mm:ss | |||
| time-zone: GMT+8 | |||
| default-property-inclusion: non_null | |||
| servlet: | |||
| multipart: | |||
| max-file-size: 2MB | |||
| max-request-size: 2MB | |||
| cache: | |||
| type: REDIS | |||
| cache-names: redis_cache #缓存的名字(可以不指定) | |||
| redis: | |||
| time-to-live: 60000ms #很重要,缓存的有效时间,以便缓存的过期(单位为毫秒) | |||
| rocketmq: | |||
| nameServer: 127.0.0.1:9876 | |||
| producer: | |||
| retry-times-when-send-async-failed: 0 | |||
| send-msg-timeout: 300000 | |||
| compress-msg-body-over-howmuch: 4096 | |||
| max-message-size: 4194304 | |||
| retry-another-broker-when-not-store-ok: false | |||
| retry-times-when-send-failed: 2 | |||
| rabbitmq: | |||
| host: 202.165.179.86 | |||
| port: 5672 | |||
| username: guest | |||
| password: guest | |||
| publisher-confirms: true | |||
| virtual-host: / | |||
| # @{link} https://github.com/abel533 | |||
| #Mybatis | |||
| mybatis: | |||
| type-aliases-package: com.iformall.domain.po | |||
| mapper-locations: classpath:mapper/*Mapper.xml | |||
| configuration: | |||
| map-underscore-to-camel-case: true | |||
| cache-enabled: true | |||
| lazy-loading-enabled: true | |||
| use-generated-keys: true | |||
| default-fetch-size: 100 | |||
| default-statement-timeout: 10 | |||
| #PageHelper | |||
| pagehelper: | |||
| helperDialect: mysql | |||
| reasonable: false | |||
| supportMethodsArguments: true | |||
| params: count=countSql | |||
| offset-as-page-num: true | |||
| page-size-zero: true | |||
| row-bounds-with-count: true | |||
| mapper: | |||
| mappers: | |||
| - com.iformall.common.CommonMapper | |||
| pay: | |||
| real: true | |||
| version: @project.version@ | |||
| @@ -0,0 +1,100 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <configuration scan="true" scanPeriod="10 seconds"> | |||
| <!-- 外部指定路径 --> | |||
| <springProperty scop="context" name="logPath" source="logging.path" /> | |||
| <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | |||
| <encoder> | |||
| <Pattern>[%date{yyyy-MM-dd HH:mm:ss}] [%-5level] --%mdc{client}%msg%n</Pattern> | |||
| </encoder> | |||
| </appender> | |||
| <appender name="TRACE_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | |||
| <file>${logPath}/trace.log</file> | |||
| <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | |||
| <FileNamePattern>${logPath}/daily/trace.%d{yyyy-MM-dd}.log</FileNamePattern> | |||
| <maxHistory>180</maxHistory> <!-- 保留180天 --> | |||
| </rollingPolicy> | |||
| <layout> | |||
| <pattern>[%date{yyyy-MM-dd HH:mm:ss}] [%-5level] [%logger:%line]--%mdc{client} %msg%n</pattern> | |||
| </layout> | |||
| </appender> | |||
| <appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | |||
| <file>${logPath}/info.log</file> | |||
| <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | |||
| <FileNamePattern>${logPath}/daily/info.%d{yyyy-MM-dd}.log</FileNamePattern> | |||
| <maxHistory>180</maxHistory> <!-- 保留180天 --> | |||
| </rollingPolicy> | |||
| <layout> | |||
| <pattern>[%date{yyyy-MM-dd HH:mm:ss}] [%-5level] [%logger:%line]--%mdc{client} %msg%n</pattern> | |||
| </layout> | |||
| <filter class="ch.qos.logback.classic.filter.LevelFilter"> | |||
| <level>INFO</level> | |||
| <onMatch>ACCEPT</onMatch> | |||
| <onMismatch>DENY</onMismatch> | |||
| </filter> | |||
| </appender> | |||
| <appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | |||
| <file>${logPath}/debug.log</file> | |||
| <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | |||
| <FileNamePattern>${logPath}/daily/debug.%d{yyyy-MM-dd}.log</FileNamePattern> | |||
| <maxHistory>180</maxHistory> <!-- 保留180天 --> | |||
| </rollingPolicy> | |||
| <layout> | |||
| <pattern>[%date{yyyy-MM-dd HH:mm:ss}] [%-5level] [%logger:%line]--%mdc{client} %msg%n</pattern> | |||
| </layout> | |||
| <filter class="ch.qos.logback.classic.filter.LevelFilter"> | |||
| <level>DEBUG</level> | |||
| <onMatch>ACCEPT</onMatch> | |||
| <onMismatch>DENY</onMismatch> | |||
| </filter> | |||
| </appender> | |||
| <appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | |||
| <file>${logPath}/warn.log</file> | |||
| <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | |||
| <FileNamePattern>${logPath}/daily/warn.%d{yyyy-MM-dd}.log</FileNamePattern> | |||
| <maxHistory>180</maxHistory> <!-- 保留180天 --> | |||
| </rollingPolicy> | |||
| <layout> | |||
| <pattern>[%date{yyyy-MM-dd HH:mm:ss}] [%-5level] [%logger:%line]--%mdc{client} %msg%n</pattern> | |||
| </layout> | |||
| <filter class="ch.qos.logback.classic.filter.LevelFilter"> | |||
| <level>WARN</level> | |||
| <onMatch>ACCEPT</onMatch> | |||
| <onMismatch>DENY</onMismatch> | |||
| </filter> | |||
| </appender> | |||
| <appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | |||
| <file>${logPath}/error.log</file> | |||
| <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | |||
| <FileNamePattern>${logPath}/daily/error.%d{yyyy-MM-dd}.log</FileNamePattern> | |||
| <maxHistory>180</maxHistory> <!-- 保留180天 --> | |||
| </rollingPolicy> | |||
| <layout> | |||
| <pattern>[%date{yyyy-MM-dd HH:mm:ss}] [%-5level] [%logger:%line]--%mdc{client} %msg%n</pattern> | |||
| </layout> | |||
| <filter class="ch.qos.logback.classic.filter.LevelFilter"> | |||
| <level>ERROR</level> | |||
| <onMatch>ACCEPT</onMatch> | |||
| <onMismatch>DENY</onMismatch> | |||
| </filter> | |||
| </appender> | |||
| <root level="TRACE"> | |||
| <appender-ref ref="TRACE_FILE" /> | |||
| <appender-ref ref="INFO_FILE" /> | |||
| <!-- <appender-ref ref="DEBUG_FILE" /> --> | |||
| <!-- <appender-ref ref="WARN_FILE" /> --> | |||
| <appender-ref ref="ERROR_FILE" /> | |||
| </root> | |||
| <root level="INFO"> | |||
| <appender-ref ref="STDOUT" /> | |||
| </root> | |||
| </configuration> | |||
| @@ -1,6 +1,7 @@ | |||
| package com.iformall; | |||
| import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; | |||
| import org.rocketmq.starter.annotation.EnableRocketMQ; | |||
| import org.springframework.beans.factory.annotation.Value; | |||
| import org.springframework.boot.SpringApplication; | |||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | |||
| @@ -15,6 +16,7 @@ import tk.mybatis.spring.annotation.MapperScan; | |||
| @SpringBootApplication | |||
| @MapperScan(basePackages = {"com.iformall.mapper"}) | |||
| @EnableSwagger2 | |||
| @EnableRocketMQ | |||
| @EnableEncryptableProperties | |||
| public class ScheduleApplication { | |||
| @@ -1,6 +1,7 @@ | |||
| package com.iformall.config; | |||
| import com.iformall.domain.po.PushLimit; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxScoreRules; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -109,4 +110,21 @@ public class RedisConfig extends CachingConfigurerSupport { | |||
| return template; | |||
| } | |||
| @Bean("cuserTokenRedisTemplate") | |||
| public RedisTemplate<String, WxCUser> getCUserTokenRedisTemplate(RedisConnectionFactory connectionFactory) { | |||
| RedisTemplate<String, WxCUser> template = new RedisTemplate<String, WxCUser>(); | |||
| Jackson2JsonRedisSerializer<WxCUser> j = new Jackson2JsonRedisSerializer<WxCUser>(WxCUser.class); | |||
| // value值的序列化 | |||
| template.setValueSerializer(j); | |||
| template.setHashKeySerializer(j); | |||
| // key的序列化 | |||
| template.setKeySerializer(new StringRedisSerializer()); | |||
| template.setHashKeySerializer(new StringRedisSerializer()); | |||
| template.setConnectionFactory(connectionFactory); | |||
| return template; | |||
| } | |||
| } | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.schedule; | |||
| package com.iformall.config; | |||
| import org.springframework.context.annotation.Configuration; | |||
| import org.springframework.scheduling.annotation.EnableScheduling; | |||
| @@ -1,11 +1,18 @@ | |||
| package com.iformall.controller; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxMsgRecord; | |||
| import com.iformall.mq.MQConfig; | |||
| import com.iformall.mq.MqBaseProducer; | |||
| import com.iformall.mq.impl.RabbitMqMessageProducer; | |||
| import com.iformall.mq.impl.RocketMqMessageProducer; | |||
| 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.beans.factory.annotation.Value; | |||
| import org.springframework.context.annotation.Profile; | |||
| import org.springframework.web.bind.annotation.GetMapping; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| @@ -18,10 +25,22 @@ public class HomeController { | |||
| @Value("${version}") | |||
| private String version; | |||
| @Autowired | |||
| private MqBaseProducer mqBaseProducer; | |||
| @Autowired | |||
| private RabbitMqMessageProducer rabbitMqMessageProducer; | |||
| @ApiOperation("获取后端版本号") | |||
| @GetMapping("/version") | |||
| public ResultData version() { | |||
| return new ResultData(version); | |||
| } | |||
| @GetMapping("/mqtest") | |||
| public ResultData mqtest() { | |||
| mqBaseProducer.sendMessage(new WxMsgRecord(), "topic-1", "tag-1", "key-1"); | |||
| return new ResultData(); | |||
| } | |||
| } | |||
| @@ -1,25 +1,18 @@ | |||
| package com.iformall.schedule; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.domain.po.WxMsgCallback; | |||
| import com.iformall.domain.po.WxMsgConfig; | |||
| import com.iformall.domain.po.WxMsgValidationcode; | |||
| import com.iformall.domain.po.WxMsgValidationcodeModel; | |||
| import com.iformall.enums.EnumMsgModel; | |||
| import com.iformall.enums.EnumMsgSendStatus; | |||
| import com.iformall.enums.EnumVerifyCode; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.utils.WiwideUtil; | |||
| import com.iformall.mq.MqBaseProducer; | |||
| import org.apache.commons.collections.map.HashedMap; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.scheduling.annotation.Scheduled; | |||
| import org.springframework.stereotype.Component; | |||
| import java.math.BigDecimal; | |||
| import java.math.RoundingMode; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| @@ -46,6 +39,9 @@ public class BillNotificationSchedule { | |||
| @Autowired | |||
| private WxMsgCallbackMapper wxMsgCallbackMapper; | |||
| @Autowired | |||
| private MqBaseProducer mqBaseProducer; | |||
| /** | |||
| * 每天9点执行 | |||
| @@ -69,22 +65,17 @@ public class BillNotificationSchedule { | |||
| String phone = bill.get("linkPhone").toString(); | |||
| String appname = bill.get("appname").toString(); | |||
| logger.info("欠缴账单检验短信配置信息"); | |||
| WxMsgConfig wxMsgConfig = checkMsgConfig(tenantId); | |||
| if (wxMsgConfig != null) { | |||
| logger.info("欠缴账单获取模板内容"); | |||
| WxMsgValidationcodeModel wxMsgValidationcodeModel = getMsgModel(tenantId, EnumMsgModel.BILL_OWE.getCode()); | |||
| if (wxMsgValidationcodeModel != null) { | |||
| String signature = wxMsgValidationcodeModel.getSignature(); | |||
| String msg = wxMsgValidationcodeModel.getContent(). | |||
| replace("{price}", price.toString()). | |||
| replace("{app}", appname); | |||
| String notifyUrl = wxMsgConfig.getNotifyurl(); | |||
| String secret = wxMsgConfig.getSecret(); | |||
| String bid = wxMsgConfig.getBid(); | |||
| String publickey = wxMsgConfig.getPublickey(); | |||
| sendWaitPayBillMsg(phone, signature, msg, notifyUrl, secret, bid, publickey); | |||
| } | |||
| } | |||
| WxMsgRecord wxMsgRecord = new WxMsgRecord(); | |||
| wxMsgRecord.setMsgType(EnumMsgRecordType.SMS.getCode()); | |||
| wxMsgRecord.setModelType(EnumMsgModel.BILL_OWE.getCode()); | |||
| wxMsgRecord.setReceiver(phone); | |||
| wxMsgRecord.setTenantId(tenantId); | |||
| Map<String,String> map = new HashedMap(); | |||
| map.put("price",price.toString()); | |||
| map.put("app",appname); | |||
| wxMsgRecord.setDynamicContentMap(map); | |||
| mqBaseProducer.sendMessage(wxMsgRecord, EnumMsgMqTopic.DEFAULT.getCode(),EnumMsgMqTag.DEFAULT.getCode(),EnumMsgMqKey.DEFAULT.getCode()); | |||
| } | |||
| } | |||
| @@ -100,87 +91,38 @@ public class BillNotificationSchedule { | |||
| String phone = bill.get("linkPhone").toString(); | |||
| String appname = bill.get("appname").toString(); | |||
| logger.info("待缴账单检验短信配置信息"); | |||
| WxMsgConfig wxMsgConfig = checkMsgConfig(tenantId); | |||
| if (wxMsgConfig != null) { | |||
| logger.info("待缴账单获取模板内容"); | |||
| WxMsgValidationcodeModel wxMsgValidationcodeModel = getMsgModel(tenantId, EnumMsgModel.BILL_WAIT_PAY.getCode()); | |||
| if (wxMsgValidationcodeModel != null) { | |||
| String signature = wxMsgValidationcodeModel.getSignature(); | |||
| String msg = wxMsgValidationcodeModel.getContent(). | |||
| replace("{price}", price.toString()). | |||
| replace("{date}", receiveDate). | |||
| replace("{app}", appname); | |||
| String notifyUrl = wxMsgConfig.getNotifyurl(); | |||
| String secret = wxMsgConfig.getSecret(); | |||
| String bid = wxMsgConfig.getBid(); | |||
| String publickey = wxMsgConfig.getPublickey(); | |||
| sendWaitPayBillMsg(phone, signature, msg, notifyUrl, secret, bid, publickey); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| private WxMsgConfig checkMsgConfig(String tenantId) { | |||
| WxMsgConfig wxMsgConfig = new WxMsgConfig(); | |||
| wxMsgConfig.setTenantId(tenantId); | |||
| List<WxMsgConfig> wxMsgConfigs = wxMsgConfigMapper.findList(wxMsgConfig); | |||
| if (wxMsgConfigs.size() == 0) { | |||
| logger.info("缺少系统短信配置"); | |||
| return null; | |||
| } | |||
| wxMsgConfig = wxMsgConfigs.get(0); | |||
| if (wxMsgConfig.getRemains() == 0) { | |||
| logger.info("短信数量为0"); | |||
| return null; | |||
| } | |||
| return wxMsgConfigs.get(0); | |||
| } | |||
| private WxMsgValidationcodeModel getMsgModel(String tenantId, Integer type) { | |||
| logger.info("获取通知模板-租户:" + tenantId + ",类型:" + type); | |||
| WxMsgValidationcodeModel wxMsgValidationcodeModel = new WxMsgValidationcodeModel(); | |||
| wxMsgValidationcodeModel.setTenantId(tenantId); | |||
| wxMsgValidationcodeModel.setType(type); | |||
| List<WxMsgValidationcodeModel> list = wxMsgValidationcodelModelMapper.findList(wxMsgValidationcodeModel); | |||
| if (!list.isEmpty()) { | |||
| return wxMsgValidationcodelModelMapper.findList(wxMsgValidationcodeModel).get(0); | |||
| } | |||
| return null; | |||
| } | |||
| private void sendWaitPayBillMsg(String phone, String signature, String msg, String notifyUrl, String secret, String bid, String publickey) { | |||
| logger.info("开始调用迈外迪短信接口"); | |||
| String result = WiwideUtil.sendMsg(secret, bid, publickey, phone, signature, msg, notifyUrl, EnumVerifyCode.YES.getCode().toString(), null); | |||
| logger.info("迈外迪短信接口返回值:" + result); | |||
| JSONObject jsonObjectResult = JSONObject.parseObject(result); | |||
| String ret = jsonObjectResult.get("ret").toString(); | |||
| String batchNo = jsonObjectResult.get("data").toString(); | |||
| if (ret.equals(EnumMsgSendStatus.MSG_SEND_SUCCESS.getCode())) { | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | |||
| wxMsgValidationcode.setId(idWorker.nextId()); | |||
| wxMsgValidationcode.setCreatetime(new Date()); | |||
| wxMsgValidationcodeMapper.insertSelective(wxMsgValidationcode); | |||
| addMsgCallback(wxMsgValidationcode, batchNo); | |||
| // WxMsgConfig wxMsgConfig = checkMsgConfig(tenantId); | |||
| // if (wxMsgConfig != null) { | |||
| // logger.info("待缴账单获取模板内容"); | |||
| // WxMsgValidationcodeModel wxMsgValidationcodeModel = getMsgModel(tenantId, EnumMsgModel.BILL_WAIT_PAY.getCode()); | |||
| // if (wxMsgValidationcodeModel != null) { | |||
| // String signature = wxMsgValidationcodeModel.getSignature(); | |||
| // String msg = wxMsgValidationcodeModel.getContent(). | |||
| // replace("{price}", price.toString()). | |||
| // replace("{date}", receiveDate). | |||
| // replace("{app}", appname); | |||
| // String notifyUrl = wxMsgConfig.getNotifyurl(); | |||
| // String secret = wxMsgConfig.getSecret(); | |||
| // String bid = wxMsgConfig.getBid(); | |||
| // String publickey = wxMsgConfig.getPublickey(); | |||
| // sendWaitPayBillMsg(phone, signature, msg, notifyUrl, secret, bid, publickey); | |||
| // } | |||
| // } | |||
| WxMsgRecord wxMsgRecord = new WxMsgRecord(); | |||
| wxMsgRecord.setMsgType(EnumMsgRecordType.SMS.getCode()); | |||
| wxMsgRecord.setModelType(EnumMsgModel.BILL_OWE.getCode()); | |||
| wxMsgRecord.setReceiver(phone); | |||
| wxMsgRecord.setTenantId(tenantId); | |||
| Map<String,String> map = new HashedMap(); | |||
| map.put("price",price.toString()); | |||
| map.put("app",appname); | |||
| map.put("date",receiveDate); | |||
| wxMsgRecord.setDynamicContentMap(map); | |||
| mqBaseProducer.sendMessage(wxMsgRecord, EnumMsgMqTopic.DEFAULT.getCode(),EnumMsgMqTag.DEFAULT.getCode(),EnumMsgMqKey.DEFAULT.getCode()); | |||
| } | |||
| } | |||
| public void addMsgCallback(WxMsgValidationcode wxmsg, String batchNo) { | |||
| logger.info("验证码发送时主动添加回调记录开始..."); | |||
| String phone = wxmsg.getPhone(); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| WxMsgCallback wxMsgCallback = new WxMsgCallback(); | |||
| wxMsgCallback.setId(idWorker.nextId()); | |||
| wxMsgCallback.setPhone(phone); | |||
| wxMsgCallback.setTenantId(wxmsg.getTenantId()); | |||
| wxMsgCallback.setBatchNo(batchNo); | |||
| wxMsgCallback.setMsgId(wxmsg.getId()); | |||
| wxMsgCallback.setStatus(EnumMsgSendStatus.MSG_SENDING.getCode()); | |||
| wxMsgCallback.setCreatetime(new Date()); | |||
| wxMsgCallbackMapper.insertSelective(wxMsgCallback); | |||
| logger.info("验证码发送时主动添加回调记录结束..."); | |||
| } | |||
| } | |||
| @@ -0,0 +1,238 @@ | |||
| package com.iformall.schedule; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.domain.dto.WxCUserBasicInfoDto; | |||
| import com.iformall.domain.po.WxChartDataEntity; | |||
| import com.iformall.domain.po.WxMall; | |||
| import com.iformall.domain.po.WxMerchantTradeDaily; | |||
| import com.iformall.enums.EnumCarCmd; | |||
| import com.iformall.enums.EnumChartType; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.utils.DateUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.scheduling.annotation.Scheduled; | |||
| import org.springframework.stereotype.Component; | |||
| import java.math.BigDecimal; | |||
| import java.util.Date; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| /** | |||
| * @author gongbiao | |||
| */ | |||
| @Component | |||
| public class ChartDataSchedule { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| WxCarCmdLogMapper wxCarCmdLogMapper; | |||
| @Autowired | |||
| WxMallMapper wxMallMapper; | |||
| @Autowired | |||
| WxCUserCarMapper wxCUserCarMapper; | |||
| @Autowired | |||
| WxChartDataMapper wxChartDataMapper; | |||
| @Autowired | |||
| WxCouponOrderMapper wxCouponOrderMapper; | |||
| @Autowired | |||
| WxMerchantTradeDailyMapper wxMerchantTradeDailyMapper; | |||
| /** | |||
| * 每天7点执行 | |||
| */ | |||
| @Scheduled(cron = "0 0 7 * * ?") | |||
| public void createData() { | |||
| createCarData(); | |||
| createSaleData(); | |||
| createMerchantTradeData(); | |||
| } | |||
| /** | |||
| * 出场车辆、缴费车辆、缴费金额、新增会员、新增停车会员、已绑车辆 | |||
| */ | |||
| public void createCarData() { | |||
| HashMap<String, Object> params = new HashMap<>(); | |||
| params.put("cmdType", EnumCarCmd.CAR_ETCP_CALLBACK_PARK_OUT.getCode()); | |||
| Date createtime = new Date(); | |||
| String startdate = DateUtils.getTimeBefore(1, createtime); | |||
| Date date = DateUtils.stringToDate(startdate); | |||
| params.put("startdate", startdate + " 00:00:00"); | |||
| params.put("enddate", startdate + " 23:59:59"); | |||
| WxChartDataEntity wxChartDataEntity = new WxChartDataEntity(); | |||
| wxChartDataEntity.setQuerytime(date); | |||
| List<WxMall> wxMalls = wxMallMapper.findList(null); | |||
| for (WxMall wxMall : wxMalls) { | |||
| String tenantId = wxMall.getTenantId(); | |||
| params.put("tenantId", tenantId); | |||
| wxChartDataEntity.setTenantId(tenantId); | |||
| wxChartDataEntity.setType(EnumChartType.CAR_OUT.getCode()); | |||
| int count = wxChartDataMapper.selectCount(wxChartDataEntity); | |||
| if (count == 0) { | |||
| logger.info("出场车数>>>>>>>>>>>>>>>>>>>>>>>>>>"); | |||
| carOutData(params, createtime, date, tenantId); | |||
| } | |||
| wxChartDataEntity.setType(EnumChartType.CAR_PAID.getCode()); | |||
| count = wxChartDataMapper.selectCount(wxChartDataEntity); | |||
| if (count == 0) { | |||
| params.put("cmdType", EnumCarCmd.CAR_ETCP_CALLBACK_PAY_MANUAL.getCode()); | |||
| logger.info("缴费车辆>>>>>>>>>>>>>>>>>>>>>>>>>>"); | |||
| carPaidData(params, createtime, date, tenantId); | |||
| } | |||
| wxChartDataEntity.setType(EnumChartType.CAR_PAY_FEE.getCode()); | |||
| count = wxChartDataMapper.selectCount(wxChartDataEntity); | |||
| if (count == 0) { | |||
| logger.info("缴费金额>>>>>>>>>>>>>>>>>>>>>>>>>>"); | |||
| carPayFeeData(params, createtime, date, tenantId); | |||
| } | |||
| wxChartDataEntity.setType(EnumChartType.CAR_MEMBER.getCode()); | |||
| count = wxChartDataMapper.selectCount(wxChartDataEntity); | |||
| if (count == 0) { | |||
| logger.info("新增会员>>>>>>>>>>>>>>>>>>>>>>>>>>"); | |||
| carMemberData(params, createtime, date, tenantId); | |||
| } | |||
| wxChartDataEntity.setType(EnumChartType.CAR_NEW_MEMBER.getCode()); | |||
| count = wxChartDataMapper.selectCount(wxChartDataEntity); | |||
| if (count == 0) { | |||
| logger.info("新增停车会员>>>>>>>>>>>>>>>>>>>>>>>>>>"); | |||
| carNewMemberData(createtime, date, tenantId); | |||
| } | |||
| wxChartDataEntity.setType(EnumChartType.CAR_BIND.getCode()); | |||
| count = wxChartDataMapper.selectCount(wxChartDataEntity); | |||
| if (count == 0) { | |||
| logger.info("已绑车辆>>>>>>>>>>>>>>>>>>>>>>>>>>"); | |||
| carBindData(params, createtime, date, tenantId); | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * 销售总交易额 | |||
| */ | |||
| public void createSaleData() { | |||
| HashMap<String, Object> params = new HashMap<>(); | |||
| Date createtime = new Date(); | |||
| String yesterday = DateUtils.getTimeBefore(1, createtime); | |||
| String today = DateUtils.getSystemTime("yyyy-MM-dd"); | |||
| Date startdate = DateUtils.stringToDate(yesterday); | |||
| Date enddate = DateUtils.stringToDate(today); | |||
| WxChartDataEntity wxChartDataEntity = new WxChartDataEntity(); | |||
| wxChartDataEntity.setQuerytime(startdate); | |||
| List<WxMall> wxMalls = wxMallMapper.findList(null); | |||
| for (WxMall wxMall : wxMalls) { | |||
| String tenantId = wxMall.getTenantId(); | |||
| params.put("tenantId", tenantId); | |||
| wxChartDataEntity.setTenantId(tenantId); | |||
| wxChartDataEntity.setType(EnumChartType.SALE_COUPON_PRICE.getCode()); | |||
| int count = wxChartDataMapper.selectCount(wxChartDataEntity); | |||
| if (count == 0) { | |||
| logger.info("销售总交易额>>>>>>>>>>>>>>>>>>>>>>>>>>"); | |||
| Integer price = wxCouponOrderMapper.queryPriceTotal(tenantId, startdate, enddate); | |||
| addChartData(tenantId, price.toString(), EnumChartType.SALE_COUPON_PRICE.getCode(), startdate, createtime); | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * 解单金额 | |||
| */ | |||
| public void createMerchantTradeData() { | |||
| HashMap<String, Object> params = new HashMap<>(); | |||
| Date createtime = new Date(); | |||
| String yesterday = DateUtils.getTimeBefore(1, createtime); | |||
| Date querytime = DateUtils.stringToDate(yesterday); | |||
| WxChartDataEntity wxChartDataEntity = new WxChartDataEntity(); | |||
| wxChartDataEntity.setQuerytime(querytime); | |||
| List<WxMall> wxMalls = wxMallMapper.findList(null); | |||
| for (WxMall wxMall : wxMalls) { | |||
| String tenantId = wxMall.getTenantId(); | |||
| params.put("tenantId", tenantId); | |||
| wxChartDataEntity.setTenantId(tenantId); | |||
| wxChartDataEntity.setType(EnumChartType.MERCHANT_TRADE.getCode()); | |||
| int count = wxChartDataMapper.selectCount(wxChartDataEntity); | |||
| if (count == 0) { | |||
| logger.info("解单金额>>>>>>>>>>>>>>>>>>>>>>>>>>"); | |||
| WxMerchantTradeDaily wxMerchantTradeDaily = new WxMerchantTradeDaily(); | |||
| wxMerchantTradeDaily.setTenantId(tenantId); | |||
| wxMerchantTradeDaily.setReportDate(yesterday); | |||
| List<WxMerchantTradeDaily> recordList = wxMerchantTradeDailyMapper.findTotalListOfMonth(wxMerchantTradeDaily); | |||
| Integer price = 0; | |||
| if (!recordList.isEmpty()) { | |||
| price = recordList.get(0).getTradeAmt(); | |||
| } | |||
| addChartData(tenantId, price.toString(), EnumChartType.MERCHANT_TRADE.getCode(), querytime, createtime); | |||
| } | |||
| } | |||
| } | |||
| public void carBindData(HashMap<String, Object> params, Date createtime, Date date, String tenantId) { | |||
| Long todaybindcar = wxCUserCarMapper.queryCarCount(params); | |||
| addChartData(tenantId, todaybindcar.toString(), EnumChartType.CAR_BIND.getCode(), date, createtime); | |||
| } | |||
| public void carNewMemberData(Date createtime, Date date, String tenantId) { | |||
| WxCUserBasicInfoDto wxCUserBasicInfoDto = new WxCUserBasicInfoDto(); | |||
| wxCUserBasicInfoDto.setTenantId(tenantId); | |||
| wxCUserBasicInfoDto.setStartTime(date); | |||
| wxCUserBasicInfoDto.setEndTime(date); | |||
| Integer carUserCount = wxCUserCarMapper.countUser(wxCUserBasicInfoDto); | |||
| addChartData(tenantId, carUserCount.toString(), EnumChartType.CAR_NEW_MEMBER.getCode(), date, createtime); | |||
| } | |||
| public void carMemberData(HashMap<String, Object> params, Date createtime, Date date, String tenantId) { | |||
| List<Map<String, Object>> carCountHistory = wxCUserCarMapper.queryCarCountHistory(params); | |||
| Long userCount = carCountHistory.isEmpty() ? 0L : (Long) carCountHistory.get(0).get("count"); | |||
| addChartData(tenantId, userCount.toString(), EnumChartType.CAR_MEMBER.getCode(), date, createtime); | |||
| } | |||
| public void carPayFeeData(HashMap<String, Object> params, Date createtime, Date date, String tenantId) { | |||
| List<Map<String, Object>> weekCarPayHistoryList = wxCarCmdLogMapper.queryWeekCarPay(params); | |||
| BigDecimal fee = weekCarPayHistoryList.isEmpty() ? new BigDecimal(0) : (BigDecimal) weekCarPayHistoryList.get(0).get("fee"); | |||
| addChartData(tenantId, fee.toString(), EnumChartType.CAR_PAY_FEE.getCode(), date, createtime); | |||
| } | |||
| public void carPaidData(HashMap<String, Object> params, Date createtime, Date date, String tenantId) { | |||
| Long carPayFeeCount = wxCarCmdLogMapper.queryWeekCarPayCount(params); | |||
| addChartData(tenantId, carPayFeeCount.toString(), EnumChartType.CAR_PAID.getCode(), date, createtime); | |||
| } | |||
| public void carOutData(HashMap<String, Object> params, Date createtime, Date date, String tenantId) { | |||
| List<Map<String, Object>> historylist = wxCarCmdLogMapper.queryHistory(params); | |||
| Long carOutCount = historylist.isEmpty() ? 0L : (Long) historylist.get(0).get("carcount"); | |||
| addChartData(tenantId, carOutCount.toString(), EnumChartType.CAR_OUT.getCode(), date, createtime); | |||
| } | |||
| private void addChartData(String tenantId, String result, Integer type, Date querytime, Date createtime) { | |||
| logger.info("即将插入数据>>>>>>>>>>>>>>>>>>>>>>>"); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| long id = idWorker.nextId(); | |||
| WxChartDataEntity wxChartDataEntity = new WxChartDataEntity(); | |||
| wxChartDataEntity.setId(id); | |||
| wxChartDataEntity.setTenantId(tenantId); | |||
| wxChartDataEntity.setResult(result); | |||
| wxChartDataEntity.setType(type); | |||
| wxChartDataEntity.setQuerytime(querytime); | |||
| wxChartDataEntity.setCreatetime(createtime); | |||
| logger.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>" + wxChartDataEntity.toString()); | |||
| wxChartDataMapper.insertSelective(wxChartDataEntity); | |||
| } | |||
| } | |||
| @@ -1,5 +1,10 @@ | |||
| package com.iformall.schedule; | |||
| import com.iformall.domain.po.WxCouponChannel; | |||
| import com.iformall.domain.po.WxGame; | |||
| import com.iformall.enums.EnumCouponChannelStatus; | |||
| import com.iformall.enums.EnumCouponChannelType; | |||
| import com.iformall.enums.EnumGameStatus; | |||
| import com.iformall.mapper.*; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -9,6 +14,8 @@ import org.springframework.stereotype.Component; | |||
| import org.springframework.transaction.annotation.Propagation; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import java.util.List; | |||
| @Component | |||
| public class CouponExpiringSchedule { | |||
| @@ -23,6 +30,12 @@ public class CouponExpiringSchedule { | |||
| @Autowired | |||
| private WxCouponSendMapper wxCouponSendMapper; | |||
| @Autowired | |||
| private WxScreenAdMapper wxScreenAdMapper; | |||
| @Autowired | |||
| private WxGameMapper wxGameMapper; | |||
| @Scheduled(cron = "0 5 0 * * ?") // 每天凌晨00:05 作废过期券,商户禁用券 | |||
| //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | |||
| @@ -41,7 +54,6 @@ public class CouponExpiringSchedule { | |||
| wxCouponSendMapper.offExpiriedCouponSendByCouponStatus(); | |||
| } | |||
| @Scheduled(cron = "0 10 0 * * ?") // 每天凌晨00:10 下架主动领取 | |||
| //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | |||
| public void couponChannelExpiringSchedule() { | |||
| @@ -51,9 +63,40 @@ public class CouponExpiringSchedule { | |||
| wxCouponChannelMapper.offExpiriedCouponChannelByCouponStatus(); | |||
| } | |||
| @Scheduled(cron = "0 15 0 * * ?") // 每天凌晨00:15 下架券广告 | |||
| //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | |||
| public void screenAdExpiringSchedule() { | |||
| wxScreenAdMapper.offScreeAdByCouponChannelStatus(); | |||
| } | |||
| @Scheduled(cron = "0 0,1,2,3 0/1 * * ?") // 每小时 0, 1 ,2 ,3 分钟(整点)执行//限时抢购 | |||
| //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | |||
| public void couponChannel2ExpiringSchedule() { | |||
| wxCouponChannelMapper.offExpiriedCouponChannel2ByEndTime(); | |||
| } | |||
| @Scheduled(cron = "0 20 0 * * ?") // 每天凌晨00:20 下架游戏 | |||
| //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | |||
| public void gameExpiringSchedule() { | |||
| WxGame wxGame = new WxGame(); | |||
| wxGame.setStatus(EnumGameStatus.STATUS_THROW_IN.getCode()); | |||
| List<WxGame> list = wxGameMapper.findList(wxGame); | |||
| list.stream().forEach(g->{ | |||
| WxCouponChannel couponChannel = new WxCouponChannel(); | |||
| couponChannel.setTenantId(g.getTenantId()); | |||
| couponChannel.setTargetAd(EnumCouponChannelType.COUPON_CHANNEL_ID_GAME.getCode()); | |||
| couponChannel.setSubTargetId(g.getId()); | |||
| couponChannel.setStatus(EnumCouponChannelStatus.STATUS_THROW_IN.getCode()); | |||
| int count = wxCouponChannelMapper.countCouponChannel(couponChannel); | |||
| if (count == 0) { | |||
| WxGame record = new WxGame(); | |||
| record.setId(g.getId()); | |||
| record.setStatus(EnumGameStatus.STATUS_TAKE_OFFF.getCode()); | |||
| wxGameMapper.updateByPrimaryKeySelective(record); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| @@ -3,14 +3,14 @@ package com.iformall.schedule; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.config.PayProperty; | |||
| import com.iformall.domain.dto.WxSharingOrderDto; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.enums.EnumAppType; | |||
| import com.iformall.enums.EnumCouponOrderStatus; | |||
| import com.iformall.enums.EnumCouponType; | |||
| import com.iformall.enums.EnumPayType; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.WxOrderService; | |||
| import com.iformall.service.WxPayOrderService; | |||
| import com.iformall.service.WxProfitSharingOrderService; | |||
| import com.iformall.service.WxRefundOrderService; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -38,59 +38,137 @@ public class CouponOrderExpiringSchedule { | |||
| private WxRefundOrderService wxRefundOrderService; | |||
| @Autowired | |||
| private WxPayOrderService wxPayOrderService; | |||
| private WxProfitSharingOrderService wxProfitSharingOrderService; | |||
| @Autowired | |||
| private WxAppinfoMapper wxAppinfoMapper; | |||
| @Autowired | |||
| private WxPayOrderMapper wxPayOrderMapper; | |||
| @Autowired | |||
| private WxOrderMapper wxOrderMapper; | |||
| @Autowired | |||
| private WxOrderService wxOrderService; | |||
| @Scheduled(cron = "0 5 0 * * ?") // 每天凌晨00:05 | |||
| //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| // @Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | |||
| public void couponOrderExpiringSchedule() { | |||
| wxCouponOrderMapper.offExpiredCouponOrderByValidDate(); | |||
| List<WxCouponOrder> list = wxCouponOrderMapper.findExpiredFreeCouponOrderByValidDate(); | |||
| list.stream().forEach(co -> { | |||
| // 券过期,更改状态及库存退回 | |||
| try { | |||
| couponOrderExpire(co, true); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| }); | |||
| } | |||
| @Scheduled(cron = "0 5 0 * * ?") // 每天凌晨00:05 | |||
| //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | |||
| // @Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | |||
| public void couponOrderRefundSchedule() { | |||
| List<WxCouponOrder> list = wxCouponOrderMapper.findExpiredCouponOrderByValidDate(); | |||
| list.parallelStream().forEach(co -> { | |||
| // 券过期与退款分离 | |||
| couponOrderExpire(co); | |||
| if(!co.getCouponType().equals(EnumCouponType.CARD_MULTIMCH.getCode())) { | |||
| // 非储值卡, 可以退款 | |||
| WxAppinfo appinfo = new WxAppinfo(); | |||
| appinfo.setTenantId(co.getTenantId()); | |||
| appinfo.setType(EnumAppType.B.getCode()); | |||
| appinfo = wxAppinfoMapper.findList(appinfo).get(0); | |||
| try { | |||
| wxRefundOrderService.createRefundOrder(payProperty.isReal(), appinfo, co.getId(), EnumPayType.PAY_AUTO_REFUND, null); | |||
| } catch (Exception e) { | |||
| logger.error("退款失败:"+e.getMessage()+"couponOrderId="+co.getId()); | |||
| } | |||
| list.stream().forEach(co -> { | |||
| // 券过期,更改状态及库存退回 | |||
| try { | |||
| couponOrderExpire(co, false); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| // 退款 | |||
| try { | |||
| couponOrderExpireRefund(co, true); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| }); | |||
| } | |||
| private void couponOrderExpire(WxCouponOrder co) { | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void couponOrderExpire(WxCouponOrder co, boolean bStockBack) { | |||
| // 标记 couponOrder过期 | |||
| WxCouponOrder wxCouponOrder = new WxCouponOrder(); | |||
| wxCouponOrder.setId(co.getId()); | |||
| WxCouponOrder updateRecord = new WxCouponOrder(); | |||
| updateRecord.setId(co.getId()); | |||
| if(co.getCouponType().equals(EnumCouponType.CARD_MULTIMCH.getCode())) { | |||
| wxCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.CARD_OVER_TIME.getCode()); // 卡线下退款 | |||
| updateRecord.setCouponOrderStatus(EnumCouponOrderStatus.CARD_OVER_TIME.getCode()); // 卡线下退款 | |||
| } else { | |||
| wxCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_OVER_TIME.getCode()); //券已过期 | |||
| updateRecord.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_OVER_TIME.getCode()); //券已过期 | |||
| } | |||
| updateRecord.setUpdateDate(new Date()); | |||
| wxCouponOrderMapper.updateByPrimaryKeySelective(updateRecord); | |||
| // 库存退回 | |||
| if(bStockBack) { | |||
| WxOrder order = wxOrderMapper.selectByPrimaryKey(co.getOrderId()); | |||
| if(order != null) { | |||
| wxOrderService.stockBack(order); | |||
| } | |||
| } | |||
| } | |||
| private void couponOrderExpireRefund(WxCouponOrder co, boolean bStockBack) { | |||
| // 非储值卡, 可以退款 | |||
| if(!co.getCouponType().equals(EnumCouponType.CARD_MULTIMCH.getCode()) | |||
| && !co.getAutoRefund().equals(EnumCouponAutoRefund.UNSUPPORTED.getCode())) { | |||
| WxAppinfo appinfo = new WxAppinfo(); | |||
| appinfo.setTenantId(co.getTenantId()); | |||
| appinfo.setType(EnumAppType.B.getCode()); | |||
| appinfo = wxAppinfoMapper.findList(appinfo).get(0); | |||
| try { | |||
| wxRefundOrderService.createRefundOrder(payProperty.isReal(), appinfo, co.getId(), EnumPayType.PAY_AUTO_REFUND, null); | |||
| } catch (MallinkException e) { | |||
| logger.error("退款失败:"+e.getMessage()+"couponOrderId="+co.getId()); | |||
| throw new MallinkException(e.getErrorCode(), e.getMessage()); | |||
| } | |||
| } | |||
| wxCouponOrder.setUpdateDate(new Date()); | |||
| try { | |||
| wxCouponOrderMapper.updateByPrimaryKeySelective(wxCouponOrder); | |||
| } catch (Exception e) { | |||
| logger.error("db failed: couponOrder-" + wxCouponOrder.getId() + ", e:" + e.getMessage()); | |||
| if (co.getAutoRefund().equals(EnumCouponAutoRefund.UNSUPPORTED.getCode())){ | |||
| // 微信分账 | |||
| try { | |||
| WxPayOrder wxPayOrder = new WxPayOrder(); | |||
| wxPayOrder.setTenantId(co.getTenantId()); | |||
| wxPayOrder.setOrderId(co.getOrderId()); | |||
| wxPayOrder.setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); | |||
| wxPayOrder = wxPayOrderMapper.selectOne(wxPayOrder); | |||
| if (wxPayOrder != null && wxPayOrder.getShare().equals(EnumPayShare.YES.getCode())) { | |||
| WxSharingOrderDto wxSharingOrderDto = new WxSharingOrderDto(); | |||
| wxSharingOrderDto.setcUserId(wxPayOrder.getcUserId()); | |||
| wxSharingOrderDto.setMerchantId(0L); | |||
| wxSharingOrderDto.setType(EnumProfitSharingOrderType.PROFIT_SHARING_FINISH.getCode()); | |||
| wxSharingOrderDto.setPayAmount(wxPayOrder.getPayAmount()); | |||
| wxSharingOrderDto.setOrderId(wxPayOrder.getId()); | |||
| wxSharingOrderDto.setPayTimeStart(wxPayOrder.getPayTimeStart()); | |||
| wxSharingOrderDto.setPayTimeEnd(wxPayOrder.getPayTimeEnd()); | |||
| wxSharingOrderDto.setTenantId(wxPayOrder.getTenantId()); | |||
| wxSharingOrderDto.setTransactionId(wxPayOrder.getTransactionId()); | |||
| wxSharingOrderDto.setShareAmount(wxPayOrder.getShareAmount()); | |||
| wxProfitSharingOrderService.finishSharingOrder(wxSharingOrderDto); | |||
| } | |||
| } catch (MallinkException e) { | |||
| logger.error("券过期不退款: " + co.getId() + " ERROR:" + e.getMessage()); | |||
| throw new MallinkException(e.getErrorCode(), e.getMessage()); | |||
| } | |||
| if(bStockBack) { | |||
| // 库存退回 | |||
| WxOrder order = wxOrderMapper.selectByPrimaryKey(co.getOrderId()); | |||
| if(order != null) { | |||
| wxOrderService.stockBack(order); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -44,9 +44,6 @@ public class CouponSendSchedule { | |||
| @Autowired | |||
| private WxCUserBasicInfoMapper wxCUserBasicInfoMapper; | |||
| @Autowired | |||
| private WxCUserMapper wxCUserMapper; | |||
| @Autowired | |||
| private WxCouponSendMapper wxCouponSendMapper; | |||
| @@ -0,0 +1,58 @@ | |||
| package com.iformall.schedule; | |||
| import com.iformall.domain.po.WxDevice; | |||
| import com.iformall.enums.EnumDeviceOnlineStatus; | |||
| import com.iformall.enums.EnumDeviceStatus; | |||
| import com.iformall.mapper.WxDeviceMapper; | |||
| import com.iformall.service.WxDeviceService; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.scheduling.annotation.Scheduled; | |||
| import org.springframework.stereotype.Component; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| @Component | |||
| public class DeviceHbCheckSchedule { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| private final int TIME_OUT_VALUE = 15 * 60 * 1000; //15分钟 | |||
| @Autowired | |||
| WxDeviceMapper wxDeviceMapper; | |||
| @Scheduled(cron = "0 */5 * * * *?") // 每5分钟检查一次 | |||
| //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | |||
| public void deviceHbCheckSchedule() { | |||
| WxDevice wxDevice = new WxDevice(); | |||
| wxDevice.setStatus(EnumDeviceStatus.VALID.getCode()); | |||
| List<WxDevice> list = wxDeviceMapper.findList(wxDevice); | |||
| list.stream().forEach(d->{ | |||
| WxDevice record = new WxDevice(); | |||
| record.setId(d.getId()); | |||
| if (d.getLastHbTime() == null) { | |||
| record.setOnlineStatus(EnumDeviceOnlineStatus.OFFLINE.getCode()); | |||
| } else { | |||
| if (new Date().getTime() - d.getLastHbTime().getTime() > TIME_OUT_VALUE) { | |||
| record.setOnlineStatus(EnumDeviceOnlineStatus.OFFLINE.getCode()); | |||
| } else { | |||
| record.setOnlineStatus(EnumDeviceOnlineStatus.ONLINE.getCode()); | |||
| } | |||
| } | |||
| if (!d.getOnlineStatus().equals(record.getOnlineStatus())) { | |||
| wxDeviceMapper.updateByPrimaryKeySelective(record); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| @@ -1,24 +1,18 @@ | |||
| package com.iformall.schedule; | |||
| import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.iformall.domain.po.WxMsg; | |||
| import com.iformall.domain.po.WxMsgConfig; | |||
| import com.iformall.domain.po.WxMsgModel; | |||
| import com.iformall.enums.EnumMsgSendStatus; | |||
| import com.iformall.enums.EnumMsgStatus; | |||
| import com.iformall.enums.EnumVerifyCode; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.mapper.WxMsgConfigMapper; | |||
| import com.iformall.mapper.WxMsgMapper; | |||
| import com.iformall.mapper.WxMsgModelMapper; | |||
| import com.iformall.mq.MqBaseProducer; | |||
| import com.iformall.utils.DateUtils; | |||
| import com.iformall.utils.WiwideUtil; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.scheduling.annotation.Scheduled; | |||
| import org.springframework.stereotype.Component; | |||
| import java.util.List; | |||
| /** | |||
| @@ -38,6 +32,9 @@ public class MsgSendingSchedule { | |||
| @Autowired | |||
| private WxMsgModelMapper wxMsgModelMapper; | |||
| @Autowired | |||
| private MqBaseProducer mqBaseProducer; | |||
| /** | |||
| * 每小时第一分钟执行 | |||
| */ | |||
| @@ -46,60 +43,63 @@ public class MsgSendingSchedule { | |||
| logger.info("sendmsg定时任务启动"); | |||
| String systemTime = DateUtils.getSystemTime("yyyy-MM-dd HH:00:00"); | |||
| WxMsg wxMsg = new WxMsg(); | |||
| wxMsg.setMsgType(EnumMsgRecordType.SMS_CALLBACK.getCode()); | |||
| wxMsg.setIsright(0); | |||
| wxMsg.setSendtime(systemTime); | |||
| List<WxMsg> list = wxMsgMapper.findList(wxMsg); | |||
| logger.info("将要发送的短信列表:" + JSONArray.toJSONString(list)); | |||
| for (WxMsg msg : list) { | |||
| sendmsg(msg); | |||
| //sendmsg(msg); | |||
| mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(),null); | |||
| } | |||
| logger.info("sendmsg定时任务结束"); | |||
| } | |||
| public void sendmsg(WxMsg wxMsg) { | |||
| logger.info("发送短信开始----------"); | |||
| //从短信配置中查询密钥 bid 等信息 | |||
| WxMsgConfig wxMsgConfig = new WxMsgConfig(); | |||
| wxMsgConfig.setTenantId(wxMsg.getTenantId()); | |||
| List<WxMsgConfig> wxMsgConfigs = wxMsgConfigMapper.findList(wxMsgConfig); | |||
| if (wxMsgConfigs.size() == 0) { | |||
| logger.info("短信相关配置不存在"); | |||
| return; | |||
| } | |||
| wxMsgConfig = wxMsgConfigs.get(0); | |||
| if (wxMsgConfig.getRemains() == 0) { | |||
| logger.info("短信数量为0"); | |||
| return; | |||
| } | |||
| if (wxMsgConfig.getRemains() < wxMsg.getExpectSendNumber()) { | |||
| logger.info("短信数量不足"); | |||
| return; | |||
| } | |||
| String secret = wxMsgConfig.getSecret(); | |||
| String bid = wxMsgConfig.getBid(); | |||
| String publickey = wxMsgConfig.getPublickey(); | |||
| String phone = wxMsg.getPhones(); | |||
| String signature = wxMsg.getSignature(); | |||
| String msg = wxMsg.getMsg(); | |||
| String notifyUrl = wxMsgConfig.getNotifyurl(); | |||
| Integer modelId = null; | |||
| Long modelIdParam = wxMsg.getModelId(); | |||
| if (modelIdParam != null) { | |||
| WxMsgModel wxMsgModel = wxMsgModelMapper.selectByPrimaryKey(modelIdParam); | |||
| modelId = wxMsgModel.getModelId(); | |||
| } | |||
| String result = WiwideUtil.sendMsg(secret, bid, publickey, phone, signature, msg, notifyUrl, EnumVerifyCode.NO.getCode().toString(), modelId); | |||
| logger.info("短信返回结果:" + result); | |||
| JSONObject jsonObjectResult = JSONObject.parseObject(result); | |||
| String ret = jsonObjectResult.get("ret").toString(); | |||
| if (ret.equals("1")) { | |||
| wxMsg.setSendstatus(EnumMsgSendStatus.MSG_SEND_SUCCESS.getCode()); | |||
| } else { | |||
| wxMsg.setSendstatus(EnumMsgSendStatus.MSG_SEND_FAIL.getCode()); | |||
| } | |||
| wxMsg.setStatus(EnumMsgStatus.MSG_STATUS_SENDED.getCode()); | |||
| wxMsgMapper.updateByPrimaryKeySelective(wxMsg); | |||
| logger.info("短信发送结束:" + jsonObjectResult.toJSONString()); | |||
| } | |||
| // @Deprecated | |||
| // public void sendmsg(WxMsg wxMsg) { | |||
| // logger.info("发送短信开始----------"); | |||
| // //从短信配置中查询密钥 bid 等信息 | |||
| // WxMsgConfig wxMsgConfig = new WxMsgConfig(); | |||
| // wxMsgConfig.setTenantId(wxMsg.getTenantId()); | |||
| // List<WxMsgConfig> wxMsgConfigs = wxMsgConfigMapper.findList(wxMsgConfig); | |||
| // if (wxMsgConfigs.size() == 0) { | |||
| // logger.info("短信相关配置不存在"); | |||
| // return; | |||
| // } | |||
| // wxMsgConfig = wxMsgConfigs.get(0); | |||
| // if (wxMsgConfig.getRemains() == 0) { | |||
| // logger.info("短信数量为0"); | |||
| // return; | |||
| // } | |||
| // if (wxMsgConfig.getRemains() < wxMsg.getExpectSendNumber()) { | |||
| // logger.info("短信数量不足"); | |||
| // return; | |||
| // } | |||
| // String secret = wxMsgConfig.getSecret(); | |||
| // String bid = wxMsgConfig.getBid(); | |||
| // String publickey = wxMsgConfig.getPublickey(); | |||
| // String phone = wxMsg.getPhones(); | |||
| // String signature = wxMsg.getSignature(); | |||
| // String msg = wxMsg.getMsg(); | |||
| // String notifyUrl = wxMsgConfig.getNotifyurl(); | |||
| // Integer modelId = null; | |||
| // Long modelIdParam = wxMsg.getModelId(); | |||
| // if (modelIdParam != null) { | |||
| // WxMsgModel wxMsgModel = wxMsgModelMapper.selectByPrimaryKey(modelIdParam); | |||
| // modelId = wxMsgModel.getModelId(); | |||
| // } | |||
| // String result = WiwideUtil.sendMsg(secret, bid, publickey, phone, signature, msg, notifyUrl, EnumVerifyCode.NO.getCode().toString(), modelId); | |||
| // logger.info("短信返回结果:" + result); | |||
| // JSONObject jsonObjectResult = JSONObject.parseObject(result); | |||
| // String ret = jsonObjectResult.get("ret").toString(); | |||
| // if (ret.equals("1")) { | |||
| // wxMsg.setSendstatus(EnumMsgSendStatus.MSG_SEND_SUCCESS.getCode()); | |||
| // } else { | |||
| // wxMsg.setSendstatus(EnumMsgSendStatus.MSG_SEND_FAIL.getCode()); | |||
| // } | |||
| // wxMsg.setStatus(EnumMsgStatus.MSG_STATUS_SENDED.getCode()); | |||
| // wxMsgMapper.updateByPrimaryKeySelective(wxMsg); | |||
| // logger.info("短信发送结束:" + jsonObjectResult.toJSONString()); | |||
| // } | |||
| } | |||
| @@ -1,10 +1,18 @@ | |||
| package com.iformall.schedule; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxOrderGroup; | |||
| import com.iformall.enums.EnumAppType; | |||
| import com.iformall.enums.EnumOrderStatus; | |||
| import com.iformall.enums.EnumOrderType; | |||
| import com.iformall.enums.EnumRefundStatus; | |||
| import com.iformall.mapper.WxAppinfoMapper; | |||
| import com.iformall.mapper.WxOrderGroupMapper; | |||
| import com.iformall.mapper.WxOrderMapper; | |||
| import com.iformall.service.WxOrderGroupService; | |||
| import com.iformall.service.WxOrderService; | |||
| import com.iformall.service.WxRefundOrderService; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| @@ -30,6 +38,17 @@ public class OrderExpiringSchedule { | |||
| @Autowired | |||
| WxOrderService wxOrderService; | |||
| @Autowired | |||
| WxOrderGroupMapper wxOrderGroupMapper; | |||
| @Autowired | |||
| WxOrderGroupService wxOrderGroupService; | |||
| @Autowired | |||
| WxAppinfoMapper wxAppinfoMapper; | |||
| @Autowired | |||
| WxRefundOrderService wxRefundOrderService; | |||
| @Scheduled(cron = "0 */5 * * * *?") // 每5分钟检查一次 | |||
| //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | |||
| @@ -39,31 +58,67 @@ public class OrderExpiringSchedule { | |||
| Date curDate = new Date(); | |||
| Date expireDate = new Date(curDate.getTime() - TIME_OUT_VALUE ); | |||
| // 券相关订单 | |||
| // 券相关订单, 15分钟未支付, 订单过期 | |||
| dateMap.put("type", EnumOrderType.COUPON.getCode()); | |||
| dateMap.put("endDate", expireDate); | |||
| List<WxOrder> orderCoupons = wxOrderMapper.findListOfUnpaidOrderByDate(dateMap); | |||
| orderCoupons.parallelStream().forEach( o -> { | |||
| orderExpired(o); | |||
| orderCoupons.stream().forEach( o -> { | |||
| try { | |||
| orderExpired(o); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| }); | |||
| // 砍价相关订单 | |||
| // 砍价相关订单, 已超过砍价结束时间, 订单过期 | |||
| dateMap.put("type", EnumOrderType.COUPON.getCode()); | |||
| dateMap.put("endDate", curDate); | |||
| List<WxOrder> orderPresss = wxOrderMapper.findListOfUnpaidPressOrderByDate(dateMap); | |||
| orderPresss.parallelStream().forEach( o -> { | |||
| orderPressExpired(o); | |||
| orderPresss.stream().forEach( o -> { | |||
| try { | |||
| orderPressExpired(o); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| }); | |||
| //拼团 过期与失败 | |||
| List<WxOrderGroup> orderGroups = wxOrderGroupService.findList(null); | |||
| orderGroups.stream().forEach(g -> { | |||
| try { | |||
| wxOrderGroupService.updateGroupStatus(g); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| }); | |||
| //参团失败 | |||
| WxOrder order = new WxOrder(); | |||
| order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING_FAILD.getCode()); | |||
| wxOrderMapper.select(order).parallelStream().forEach(o -> { | |||
| try { | |||
| returnMoney(o); | |||
| } catch (Exception e) { | |||
| logger.error("拼团订单退款失败" + e.getMessage()); | |||
| } | |||
| }); | |||
| } | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void orderExpired(WxOrder order) { | |||
| order.setUpdateDate(new Date()); | |||
| order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()); | |||
| wxOrderMapper.updateByPrimaryKeySelective(order); | |||
| WxOrder updateOrder = new WxOrder(); | |||
| updateOrder.setId(order.getId()); | |||
| updateOrder.setUpdateDate(new Date()); | |||
| updateOrder.setOrderStatus(EnumOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()); | |||
| wxOrderMapper.updateByPrimaryKeySelective(updateOrder); | |||
| // 库存退回 | |||
| wxOrderService.stockBack(order); | |||
| // 微信 关单 | |||
| wxOrderService.orderClose(order); | |||
| wxOrderService.orderClose(updateOrder); | |||
| logger.info("\nFound " + order.getId() + "\n" | |||
| + " create at " + order.getCreateDate() +"\n" | |||
| @@ -73,10 +128,31 @@ public class OrderExpiringSchedule { | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void orderPressExpired(WxOrder order) { | |||
| Date curDate = new Date(); | |||
| order.setUpdateDate(curDate); | |||
| order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PRESS_OVERTIME.getCode()); | |||
| wxOrderMapper.updateByPrimaryKeySelective(order); | |||
| WxOrder updateOrder = new WxOrder(); | |||
| updateOrder.setId(order.getId()); | |||
| updateOrder.setTenantId(order.getTenantId()); | |||
| updateOrder.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PRESS_OVERTIME.getCode()); | |||
| updateOrder.setUpdateDate(curDate); | |||
| wxOrderMapper.updateByPrimaryKeySelective(updateOrder); | |||
| // 库存退回 | |||
| wxOrderService.stockBack(order); | |||
| logger.info("\n砍价订单: " + order.getId() + " create at " + order.getCreateDate() + " expired at " + curDate); | |||
| } | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void returnMoney(WxOrder order) { | |||
| //获取APP信息 | |||
| WxAppinfo appinfo = new WxAppinfo(); | |||
| appinfo.setTenantId(order.getTenantId()); | |||
| appinfo.setType(EnumAppType.C.getCode()); | |||
| appinfo = wxAppinfoMapper.findList(appinfo).get(0); | |||
| //退款流程 | |||
| boolean has = wxRefundOrderService.hasRefundOrder(order.getId(), EnumRefundStatus.REFUND_SUCCESS.getCode()); | |||
| if (!has) { | |||
| wxRefundOrderService.returnMoney(appinfo, order.getId()); | |||
| } | |||
| } | |||
| } | |||
| @@ -1,6 +1,5 @@ | |||
| package com.iformall.schedule; | |||
| import com.iformall.domain.po.WxPayOrder; | |||
| import com.iformall.domain.po.WxProfitSharingOrder; | |||
| import com.iformall.enums.EnumProfitSharingOrderStatus; | |||
| import com.iformall.mapper.*; | |||
| @@ -24,9 +23,6 @@ public class SharingOrderResultSchedule { | |||
| @Autowired | |||
| private WxProfitSharingOrderMapper wxProfitSharingOrderMapper; | |||
| @Autowired | |||
| private WxPayOrderMapper wxPayOrderMapper; | |||
| @Scheduled(cron = "0 15 0 * * ?") // 每天凌晨00:15更新分账结果 | |||
| //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | |||
| public void sharingOrderResultSchedule() { | |||
| @@ -42,10 +42,11 @@ public class WeChatAccessTokenSchedule { | |||
| WxMaService wxMaService = MaUtil.getWeappService(appinfo); | |||
| try { | |||
| String accessToken = wxMaService.getAccessToken(true); | |||
| appinfo.setAccessToken(accessToken); | |||
| appinfo.setLastTokenTime(new Date()); | |||
| appinfo.setExpiresIn(7200); | |||
| wxAppinfoMapper.updateByPrimaryKey(appinfo); | |||
| WxAppinfo updateAppInfo = new WxAppinfo(); | |||
| updateAppInfo.setAccessToken(accessToken); | |||
| updateAppInfo.setLastTokenTime(new Date()); | |||
| updateAppInfo.setExpiresIn(7200); | |||
| wxAppinfoMapper.updateByPrimaryKeySelective(updateAppInfo); | |||
| } catch (WxErrorException e) { | |||
| logger.error(e.getMessage()); | |||
| } catch (Exception e) { | |||