| @@ -25,11 +25,6 @@ | |||||
| <artifactId>mallinkService</artifactId> | <artifactId>mallinkService</artifactId> | ||||
| <version>1.0</version> | <version>1.0</version> | ||||
| </dependency> | </dependency> | ||||
| <dependency> | |||||
| <groupId>com.github.binarywang</groupId> | |||||
| <artifactId>weixin-java-miniapp</artifactId> | |||||
| <version>3.0.0</version> | |||||
| </dependency> | |||||
| </dependencies> | </dependencies> | ||||
| <build> | <build> | ||||
| <plugins> | <plugins> | ||||
| @@ -12,7 +12,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; | |||||
| */ | */ | ||||
| @SpringBootApplication | @SpringBootApplication | ||||
| @MapperScan(basePackages = {"com.simple.mapper"}) | @MapperScan(basePackages = {"com.simple.mapper"}) | ||||
| @EnableSwagger2 | |||||
| public class CApplication { | public class CApplication { | ||||
| public static void main(String[] args) { | public static void main(String[] args) { | ||||
| @@ -0,0 +1,16 @@ | |||||
| package com.simple.annotation; | |||||
| import java.lang.annotation.*; | |||||
| /** | |||||
| * api接口,忽略Token验证 | |||||
| * @author stormeye.wu | |||||
| * @email wuguoqiang@iformall.com | |||||
| * @date 2017-03-23 15:44 | |||||
| */ | |||||
| @Target(ElementType.METHOD) | |||||
| @Retention(RetentionPolicy.RUNTIME) | |||||
| @Documented | |||||
| public @interface AuthIgnore { | |||||
| } | |||||
| @@ -0,0 +1,19 @@ | |||||
| package com.simple.annotation; | |||||
| import java.lang.annotation.ElementType; | |||||
| import java.lang.annotation.Retention; | |||||
| import java.lang.annotation.RetentionPolicy; | |||||
| import java.lang.annotation.Target; | |||||
| /** | |||||
| * 登录用户信息 | |||||
| * | |||||
| * @author stormeye.wu | |||||
| * @email wuguoqiang@iformall.com | |||||
| * @date 2017-03-23 20:39 | |||||
| */ | |||||
| @Target(ElementType.PARAMETER) | |||||
| @Retention(RetentionPolicy.RUNTIME) | |||||
| public @interface LoginUser { | |||||
| } | |||||
| @@ -0,0 +1,22 @@ | |||||
| package com.simple.config; | |||||
| import org.springframework.context.annotation.Configuration; | |||||
| import org.springframework.web.servlet.config.annotation.CorsRegistry; | |||||
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | |||||
| /** | |||||
| * Created by Administrator on 2017/8/9. | |||||
| */ | |||||
| @Configuration | |||||
| public class CorsConfig extends WebMvcConfigurerAdapter { | |||||
| @Override | |||||
| public void addCorsMappings(CorsRegistry registry) { | |||||
| registry.addMapping("/api/**") | |||||
| .allowedOrigins("*") | |||||
| .allowCredentials(true) | |||||
| .allowedMethods("GET", "POST", "DELETE", "PUT") | |||||
| .maxAge(3600); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,49 @@ | |||||
| package com.simple.config; | |||||
| import org.springframework.context.annotation.Bean; | |||||
| import org.springframework.context.annotation.Configuration; | |||||
| import springfox.documentation.builders.ApiInfoBuilder; | |||||
| import springfox.documentation.builders.ParameterBuilder; | |||||
| import springfox.documentation.builders.PathSelectors; | |||||
| import springfox.documentation.builders.RequestHandlerSelectors; | |||||
| import springfox.documentation.schema.ModelRef; | |||||
| import springfox.documentation.service.ApiInfo; | |||||
| import springfox.documentation.service.Parameter; | |||||
| import springfox.documentation.spi.DocumentationType; | |||||
| import springfox.documentation.spring.web.plugins.Docket; | |||||
| import springfox.documentation.swagger2.annotations.EnableSwagger2; | |||||
| import java.util.ArrayList; | |||||
| import java.util.List; | |||||
| //参考:http://blog.csdn.net/catoop/article/details/50668896 | |||||
| @Configuration | |||||
| @EnableSwagger2 | |||||
| public class Swagger2Config { | |||||
| @Bean | |||||
| public Docket createRestApi() { | |||||
| ParameterBuilder tokenPar = new ParameterBuilder(); | |||||
| List<Parameter> pars = new ArrayList<Parameter>(); | |||||
| //增加一个request的header参数 | |||||
| tokenPar.name("token").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build(); | |||||
| pars.add(tokenPar.build()); | |||||
| return new Docket(DocumentationType.SWAGGER_2) | |||||
| .apiInfo(apiInfo()) | |||||
| .select() | |||||
| .apis(RequestHandlerSelectors.basePackage("com.simple.controller")) | |||||
| .paths(PathSelectors.any()) | |||||
| .build() | |||||
| .globalOperationParameters(pars); | |||||
| } | |||||
| private ApiInfo apiInfo() { | |||||
| return new ApiInfoBuilder() | |||||
| .title("c端 api") | |||||
| .description("c api") | |||||
| .termsOfServiceUrl("http://localhost:9000") | |||||
| .version("2.0") | |||||
| .build(); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,47 @@ | |||||
| package com.simple.config; | |||||
| import com.simple.interceptor.AuthorizationInterceptor; | |||||
| import com.simple.resolver.LoginUserHandlerMethodArgumentResolver; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.context.annotation.Configuration; | |||||
| import org.springframework.web.method.support.HandlerMethodArgumentResolver; | |||||
| import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | |||||
| import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | |||||
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | |||||
| import java.util.List; | |||||
| /** | |||||
| * MVC配置 | |||||
| * | |||||
| * @author stormeye.wu | |||||
| * @email wugq@mippoint.com | |||||
| * @date 2017-04-20 22:30 | |||||
| */ | |||||
| @Configuration | |||||
| public class WebMvcConfig extends WebMvcConfigurerAdapter { | |||||
| @Autowired | |||||
| private AuthorizationInterceptor authorizationInterceptor; | |||||
| @Autowired | |||||
| private LoginUserHandlerMethodArgumentResolver loginUserHandlerMethodArgumentResolver; | |||||
| @Override | |||||
| public void addInterceptors(InterceptorRegistry registry) { | |||||
| registry.addInterceptor(authorizationInterceptor).addPathPatterns("/api/**"); | |||||
| } | |||||
| @Override | |||||
| public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) { | |||||
| argumentResolvers.add(loginUserHandlerMethodArgumentResolver); | |||||
| } | |||||
| @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/"); | |||||
| } | |||||
| } | |||||
| @@ -5,12 +5,23 @@ import java.text.ParseException; | |||||
| import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||
| import java.util.Date; | import java.util.Date; | ||||
| import com.simple.domain.po.WxCUser; | |||||
| import com.simple.interceptor.AuthorizationInterceptor; | |||||
| import com.simple.service.WxCUserService; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.WebDataBinder; | import org.springframework.web.bind.WebDataBinder; | ||||
| import org.springframework.web.bind.annotation.InitBinder; | import org.springframework.web.bind.annotation.InitBinder; | ||||
| import org.springframework.web.bind.annotation.RestController; | import org.springframework.web.bind.annotation.RestController; | ||||
| import org.springframework.web.context.request.RequestContextHolder; | |||||
| import org.springframework.web.context.request.ServletRequestAttributes; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| @RestController | @RestController | ||||
| public class BaseController { | public class BaseController { | ||||
| @Autowired | |||||
| private WxCUserService wxCUserService; | |||||
| @InitBinder | @InitBinder | ||||
| public void InitBinder(WebDataBinder dataBinder) { | public void InitBinder(WebDataBinder dataBinder) { | ||||
| dataBinder.registerCustomEditor(Date.class, new PropertyEditorSupport() { | dataBinder.registerCustomEditor(Date.class, new PropertyEditorSupport() { | ||||
| @@ -32,4 +43,18 @@ public class BaseController { | |||||
| }); | }); | ||||
| } | } | ||||
| public WxCUser getUser(){ | |||||
| HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest(); | |||||
| Long cUserId = (Long)request.getAttribute(AuthorizationInterceptor.LOGIN_USER_KEY); | |||||
| WxCUser user = wxCUserService.getById(cUserId); | |||||
| return user; | |||||
| } | |||||
| public String getTenantId(){ | |||||
| HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest(); | |||||
| Long cUserId = (Long)request.getAttribute(AuthorizationInterceptor.LOGIN_USER_KEY); | |||||
| WxCUser user = wxCUserService.getById(cUserId); | |||||
| return user.getTenantId(); | |||||
| } | |||||
| } | } | ||||
| @@ -1,6 +1,10 @@ | |||||
| package com.simple.controller; | package com.simple.controller; | ||||
| import com.simple.common.ErrorCode; | |||||
| import com.simple.domain.po.WxCUser; | |||||
| import com.simple.enums.EnumOrderStatus; | import com.simple.enums.EnumOrderStatus; | ||||
| import com.simple.exception.MallinkException; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.util.Assert; | import org.springframework.util.Assert; | ||||
| @@ -16,6 +20,8 @@ import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import java.util.Map; | |||||
| @RestController | @RestController | ||||
| @RequestMapping("wxOrder") | @RequestMapping("wxOrder") | ||||
| public class WxOrderController extends BaseController { | public class WxOrderController extends BaseController { | ||||
| @@ -24,31 +30,24 @@ public class WxOrderController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private WxOrderService wxOrderService; | private WxOrderService wxOrderService; | ||||
| @ApiOperation("分页列表接口") | |||||
| @GetMapping("list") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "status", value = "订单状态:-1全部;0-已下单/待付款;1-已支付;2-已取消(限定时间内未付款);3-未退款/待退款;4-已退款;5-退款失败", defaultValue = "0", required = false, dataType = "Integer") | |||||
| }) | |||||
| public ResultData list(@ModelAttribute WxOrder wxOrder, Integer pageNum, Integer pageSize) { | |||||
| if (null == wxOrder) wxOrder = new WxOrder(); | |||||
| final PageInfo<WxOrder> page = wxOrderService.listAsPage(wxOrder, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| @ApiOperation("提交订单") | |||||
| @ApiOperation(value = "提交订单", notes = "{\"couponId\":\"String\"}") | |||||
| @PostMapping("save") | @PostMapping("save") | ||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "couponId", value = "券ID", required = true, dataType = "Long"), | |||||
| @ApiImplicitParam(name = "cUserId", value = "用户ID", required = true, dataType = "Long"), | |||||
| @ApiImplicitParam(name = "payment", value = "支付金额", required = true, dataType = "BigDecimal"), | |||||
| @ApiImplicitParam(name = "status", value = "订单状态:-1全部;0-已下单/待付款;1-已支付;2-已取消(限定时间内未付款);3-未退款/待退款;4-已退款;5-退款失败", defaultValue = "0", required = false, dataType = "Integer") | |||||
| }) | |||||
| public ResultData saveOrder(@RequestBody WxOrder wxOrder) { | |||||
| public ResultData saveOrder(@RequestBody Map<String, String> paramMap) { | |||||
| //Assert.notNull(wxOrders.getName(), "角色名不能为空"); | //Assert.notNull(wxOrders.getName(), "角色名不能为空"); | ||||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | ||||
| wxOrderService.saveOrder(wxOrder); | |||||
| String couponIdStr = paramMap.get("couponId"); | |||||
| if (StringUtils.isBlank(couponIdStr)) { | |||||
| return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "couponId不能为空"); | |||||
| } | |||||
| Long couponId = Long.valueOf(couponIdStr); | |||||
| WxCUser user = getUser(); | |||||
| try { | |||||
| WxOrder order = wxOrderService.saveOrder(user, couponId); | |||||
| return new ResultData(order); | |||||
| }catch (MallinkException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| @@ -1,14 +1,23 @@ | |||||
| package com.simple.controller; | package com.simple.controller; | ||||
| import cn.binarywang.wx.miniapp.api.WxMaService; | import cn.binarywang.wx.miniapp.api.WxMaService; | ||||
| import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; | |||||
| import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; | import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; | ||||
| import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; | |||||
| import cn.binarywang.wx.miniapp.bean.WxMaUserInfo; | |||||
| import cn.binarywang.wx.miniapp.config.WxMaInMemoryConfig; | |||||
| import com.alibaba.druid.wall.WallConfig; | |||||
| import com.simple.annotation.AuthIgnore; | |||||
| import com.simple.common.ErrorCode; | import com.simple.common.ErrorCode; | ||||
| import com.simple.common.IdWorker; | |||||
| import com.simple.common.ResultData; | import com.simple.common.ResultData; | ||||
| import com.simple.domain.po.WxAppinfo; | |||||
| import com.simple.domain.po.WxCUser; | import com.simple.domain.po.WxCUser; | ||||
| import com.simple.service.WxAppinfoService; | |||||
| import com.simple.service.WxCUserService; | import com.simple.service.WxCUserService; | ||||
| import com.simple.utils.IPUtil; | import com.simple.utils.IPUtil; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import me.chanjar.weixin.common.exception.WxErrorException; | |||||
| import me.chanjar.weixin.common.error.WxErrorException; | |||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| @@ -21,28 +30,52 @@ import org.springframework.web.context.request.RequestContextHolder; | |||||
| import org.springframework.web.context.request.ServletRequestAttributes; | import org.springframework.web.context.request.ServletRequestAttributes; | ||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||
| import java.util.Date; | |||||
| import java.util.HashMap; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| @RestController | @RestController | ||||
| @RequestMapping("/api/user") | @RequestMapping("/api/user") | ||||
| public class WxUserGrantController { | |||||
| public class WxUserGrantController extends BaseController { | |||||
| private final static Logger logger = LoggerFactory.getLogger(WxUserGrantController.class); | private final static Logger logger = LoggerFactory.getLogger(WxUserGrantController.class); | ||||
| @Autowired | @Autowired | ||||
| private WxMaService wxService; | |||||
| private WxAppinfoService wxAppinfoService; | |||||
| @Autowired | @Autowired | ||||
| private WxCUserService wxCUserService; | private WxCUserService wxCUserService; | ||||
| private WxMaService createFromId(String appId) { | |||||
| WxAppinfo appinfo = wxAppinfoService.getByAppId(appId); | |||||
| WxMaInMemoryConfig config = new WxMaInMemoryConfig(); | |||||
| config.setAppid(appinfo.getAppId()); | |||||
| config.setSecret(appinfo.getSecret()); | |||||
| config.setToken(appinfo.getToken()); | |||||
| config.setAesKey(appinfo.getAesKey()); | |||||
| config.setMsgDataFormat(appinfo.getMsgDataFormat()); | |||||
| WxMaService service = new WxMaServiceImpl(); | |||||
| service.setWxMaConfig(config); | |||||
| return service; | |||||
| } | |||||
| /** | /** | ||||
| * 用户登录 | * 用户登录 | ||||
| * @param map | * @param map | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| @AuthIgnore | |||||
| @PostMapping("/login") | @PostMapping("/login") | ||||
| @ApiOperation(value="用户登录", notes="{\"code\":\"string\",\"scene\":\"string\",\"sceneAddress\":\"string\"}") | |||||
| @ApiOperation(value="用户登录", notes="{\"appId\":\"string\",\"code\":\"string\",\"scene\":\"string\",\"sceneAddress\":\"string\"}") | |||||
| public ResultData userLogin(@RequestBody Map<String, String> map) { | public ResultData userLogin(@RequestBody Map<String, String> map) { | ||||
| logger.debug(map.toString()); | logger.debug(map.toString()); | ||||
| Map resultMap = new HashMap(); | |||||
| String appId = map.get("appId"); | |||||
| WxMaService wxMaService = createFromId(appId); | |||||
| String code = map.get("code"); | String code = map.get("code"); | ||||
| String scene = map.get("scene"); | String scene = map.get("scene"); | ||||
| String sceneAddress = map.get("sceneAddress"); | String sceneAddress = map.get("sceneAddress"); | ||||
| @@ -51,50 +84,59 @@ public class WxUserGrantController { | |||||
| return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "code不能为空"); | return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "code不能为空"); | ||||
| } | } | ||||
| String token = null; | |||||
| String session_key = null; | String session_key = null; | ||||
| String openId = null; | String openId = null; | ||||
| HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest(); | HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest(); | ||||
| String ipaddress = IPUtil.getIpAddr(request); | String ipaddress = IPUtil.getIpAddr(request); | ||||
| try { | try { | ||||
| WxMaJscode2SessionResult session = wxService.jsCode2SessionInfo(code); | |||||
| WxMaJscode2SessionResult session = wxMaService.jsCode2SessionInfo(code); | |||||
| //获取会话密钥(session_key) | //获取会话密钥(session_key) | ||||
| session_key = session.getSessionKey(); | session_key = session.getSessionKey(); | ||||
| openId = session.getOpenid(); | openId = session.getOpenid(); | ||||
| logger.info("session_key: " + session_key); | logger.info("session_key: " + session_key); | ||||
| logger.info("openId: " + openId); | logger.info("openId: " + openId); | ||||
| resultMap.put("openId", openId); | |||||
| } catch (WxErrorException e) { | } catch (WxErrorException e) { | ||||
| logger.error(e.getMessage(), e); | logger.error(e.getMessage(), e); | ||||
| return new ResultData(); | |||||
| return new ResultData(ErrorCode.SESSION_KEY_DECODE_ERR, resultMap); | |||||
| } | } | ||||
| /* | |||||
| WxCUser user = new WxCUser(); | |||||
| user.setAppId(appId); | |||||
| user.setOpenId(openId); | |||||
| try { | try { | ||||
| WxUserEntity user1 = wxCUserService.getById(); | |||||
| WxCUser user1 = wxCUserService.getByOpenId(user); | |||||
| if (user1 != null) { | if (user1 != null) { | ||||
| user1.createToken(new Date()); | |||||
| token = user1.getToken(); | |||||
| user1.setRegisterIp(ipaddress); | |||||
| user1.setSessionKey(session_key); | user1.setSessionKey(session_key); | ||||
| wxUserService.update(user1); | |||||
| if (user1.getScene() == null) | |||||
| user1.setScene(scene); | |||||
| if (user1.getSceneAddress() == null) | |||||
| user1.setSceneAddress(sceneAddress); | |||||
| wxCUserService.saveOrUpdate(user1); | |||||
| resultMap.put("token", token); | |||||
| } else { | } else { | ||||
| WxUserEntity user = new WxUserEntity(); | |||||
| user.setRegisterip(ipaddress); | |||||
| user.createToken(new Date()); | |||||
| token = user.getToken(); | |||||
| user.setRegisterIp(ipaddress); | |||||
| if (user.getScene() == null) | if (user.getScene() == null) | ||||
| user.setScene(scene); | user.setScene(scene); | ||||
| if (user.getSceneAddress() == null) | if (user.getSceneAddress() == null) | ||||
| user.setSceneAddress(sceneAddress); | user.setSceneAddress(sceneAddress); | ||||
| if (scene != null) { | |||||
| user.setQrcodesource(scene); | |||||
| } else { | |||||
| user.setQrcodesource(sceneAddress); | |||||
| } | |||||
| user.setOpenid(openId); | |||||
| user.setSessionKey(session_key); | user.setSessionKey(session_key); | ||||
| wxUserService.save(user); | |||||
| wxCUserService.saveOrUpdate(user); | |||||
| resultMap.put("token", token); | |||||
| } | } | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error(e.getMessage(), e); | |||||
| return R.error(e.toString()); | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(ErrorCode.DB_FAIL.getCode(), "wx_c_user数据库保存出错", resultMap); | |||||
| } | } | ||||
| */ | |||||
| return new ResultData(); | |||||
| return new ResultData(resultMap); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -103,64 +145,56 @@ public class WxUserGrantController { | |||||
| * @return | * @return | ||||
| */ | */ | ||||
| @PostMapping("/getUserInfo") | @PostMapping("/getUserInfo") | ||||
| @ApiOperation(value="授权后获取用户的昵称,unionId等信息", notes="{\"encryptedData\":\"string\",\"iv\":\"string\",\"openId\":\"string\"}") | |||||
| @ApiOperation(value="授权后获取用户的昵称,unionId等信息", notes="{\"encryptedData\":\"string\",\"iv\":\"string\"}") | |||||
| public ResultData getUserInfo(@RequestBody Map<String, String> map) { | public ResultData getUserInfo(@RequestBody Map<String, String> map) { | ||||
| logger.debug(map.toString()); | logger.debug(map.toString()); | ||||
| String openId = map.get("openId"); | |||||
| Map resultMap = new HashMap(); | |||||
| String encryptedData = map.get("encryptedData"); | String encryptedData = map.get("encryptedData"); | ||||
| String iv = map.get("iv"); | String iv = map.get("iv"); | ||||
| if (StringUtils.isBlank(encryptedData)) { | if (StringUtils.isBlank(encryptedData)) { | ||||
| return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "encryptedData不能为空"); | return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "encryptedData不能为空"); | ||||
| } | } | ||||
| if (StringUtils.isBlank(iv)) { | if (StringUtils.isBlank(iv)) { | ||||
| return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "iv不能为空"); | return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "iv不能为空"); | ||||
| } | } | ||||
| if (StringUtils.isBlank(openId)) { | |||||
| return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "openId不能为空"); | |||||
| } | |||||
| WxCUser user = null; | |||||
| /* | |||||
| try { | |||||
| //user = wxCUserService.queryObjectByOpenId(openId); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage(), e); | |||||
| return R.error(e.toString()); | |||||
| } | |||||
| WxCUser user = getUser(); | |||||
| if (user != null) { | if (user != null) { | ||||
| WxMaService wxMaService = createFromId(user.getAppId()); | |||||
| logger.debug(user.toString()); | logger.debug(user.toString()); | ||||
| String session_key = user.getSessionKey(); | String session_key = user.getSessionKey(); | ||||
| try { | try { | ||||
| // 解密用户信息 | // 解密用户信息 | ||||
| WxMaUserInfo userInfo = this.wxService.getUserService().getUserInfo(session_key, encryptedData, iv); | |||||
| WxMaUserInfo userInfo = wxMaService.getUserService().getUserInfo(session_key, encryptedData, iv); | |||||
| if (userInfo != null) { | if (userInfo != null) { | ||||
| logger.debug(userInfo.toString()); | logger.debug(userInfo.toString()); | ||||
| user.setUnionid(userInfo.getUnionId()); | |||||
| user.setNickname(userInfo.getNickName()); | |||||
| user.setUnionId(userInfo.getUnionId()); | |||||
| user.setNickName(userInfo.getNickName()); | |||||
| user.setGender(Integer.parseInt(userInfo.getGender())); | user.setGender(Integer.parseInt(userInfo.getGender())); | ||||
| user.setAvatarurl(userInfo.getAvatarUrl()); | |||||
| user.setAvatarUrl(userInfo.getAvatarUrl()); | |||||
| user.setProvince(userInfo.getProvince()); | user.setProvince(userInfo.getProvince()); | ||||
| user.setCity(userInfo.getCity()); | user.setCity(userInfo.getCity()); | ||||
| user.setLanguage(userInfo.getLanguage()); | user.setLanguage(userInfo.getLanguage()); | ||||
| wxUserService.update(user); | |||||
| r.put("openId", user.getOpenid()); | |||||
| r.put("unionId", user.getUnionid()); | |||||
| r.put("msg", "获取用户信息成功!"); | |||||
| return r; | |||||
| wxCUserService.saveOrUpdate(user); | |||||
| resultMap.put("openId", user.getOpenId()); | |||||
| resultMap.put("unionId", user.getUnionId()); | |||||
| resultMap.put("msg", "获取用户信息成功!"); | |||||
| return new ResultData(resultMap); | |||||
| } else { | } else { | ||||
| return R.code(22, "解密失败"); | |||||
| return new ResultData(ErrorCode.NICK_NAME_DECODE_ERR, resultMap); | |||||
| } | } | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error(e.getMessage(), e); | logger.error(e.getMessage(), e); | ||||
| return R.error(e.toString()); | |||||
| return new ResultData(ErrorCode.DB_FAIL.getCode(), "解密并保存出错", resultMap); | |||||
| } | } | ||||
| } else { | } else { | ||||
| return R.code(20, "用户信息未找到"); | |||||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
| } | } | ||||
| */ | |||||
| return new ResultData(); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -168,63 +202,50 @@ public class WxUserGrantController { | |||||
| * @param map | * @param map | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| /* | |||||
| @PostMapping("/getUserPhone") | @PostMapping("/getUserPhone") | ||||
| @ApiOperation(value = "授权后获取用户的手机号", notes="{\"encryptedData\":\"string\",\"iv\":\"\",\"openId\":\"\"}") | |||||
| public new ResultData getUserPhone(@RequestBody Map<String, String> map) { | |||||
| @ApiOperation(value = "授权后获取用户的手机号", notes="{\"encryptedData\":\"string\",\"iv\":\"string\"}") | |||||
| public ResultData getUserPhone(@RequestBody Map<String, String> map) { | |||||
| logger.debug(map.toString()); | logger.debug(map.toString()); | ||||
| R r = new R(); | |||||
| Map resultMap = new HashMap(); | |||||
| String encryptedData = map.get("encryptedData"); | String encryptedData = map.get("encryptedData"); | ||||
| String iv = map.get("iv"); | String iv = map.get("iv"); | ||||
| String openId = map.get("openId"); | |||||
| //登录凭证不能为空 | //登录凭证不能为空 | ||||
| if (StringUtils.isBlank(encryptedData)) { | if (StringUtils.isBlank(encryptedData)) { | ||||
| return R.code(1, "encryptedData 不能为空"); | |||||
| return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "encryptedData 不能为空"); | |||||
| } | } | ||||
| if (StringUtils.isBlank(iv)) { | if (StringUtils.isBlank(iv)) { | ||||
| return R.code(2, "iv 不能为空"); | |||||
| } | |||||
| if (StringUtils.isBlank(openId)) { | |||||
| return R.code(3, "openId 不能为空"); | |||||
| return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "iv 不能为空"); | |||||
| } | } | ||||
| WxUserEntity user = null; | |||||
| WxCUser user = getUser(); | |||||
| WxMaService wxMaService = createFromId(user.getAppId()); | |||||
| String session_key = user.getSessionKey(); | |||||
| try { | try { | ||||
| user = wxUserService.queryObjectByOpenId(openId); | |||||
| // 解密 | |||||
| WxMaPhoneNumberInfo phoneNoInfo = wxMaService.getUserService().getPhoneNoInfo(session_key, encryptedData, iv); | |||||
| if (null != phoneNoInfo) { | |||||
| logger.debug(phoneNoInfo.toString()); | |||||
| user.setPhone(phoneNoInfo.getPhoneNumber()); | |||||
| user.setPurePhone(phoneNoInfo.getPurePhoneNumber()); | |||||
| user.setCountryCode(phoneNoInfo.getCountryCode()); | |||||
| wxCUserService.saveOrUpdate(user); | |||||
| resultMap.put("msg","授权手机成功!"); | |||||
| resultMap.put("phone",phoneNoInfo.getPhoneNumber()); | |||||
| return new ResultData(resultMap); | |||||
| } else { | |||||
| return new ResultData(ErrorCode.PHONE_DECODE_ERR, resultMap); | |||||
| } | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| this.logger.error(e.getMessage(), e); | this.logger.error(e.getMessage(), e); | ||||
| return R.error(e.toString()); | |||||
| } | |||||
| if (user != null) { | |||||
| logger.debug(user.toString()); | |||||
| String session_key = user.getSessionKey(); | |||||
| try { | |||||
| // 解密 | |||||
| WxMaPhoneNumberInfo phoneNoInfo = this.wxService.getUserService().getPhoneNoInfo(session_key, encryptedData, iv); | |||||
| if (null != phoneNoInfo) { | |||||
| logger.debug(phoneNoInfo.toString()); | |||||
| user.setPhone(phoneNoInfo.getPhoneNumber()); | |||||
| user.setPurephone(phoneNoInfo.getPurePhoneNumber()); | |||||
| user.setCountrycode(phoneNoInfo.getCountryCode()); | |||||
| wxUserService.update(user); | |||||
| r.put("msg","授权手机成功!"); | |||||
| r.put("phone",phoneNoInfo.getPhoneNumber()); | |||||
| return r; | |||||
| } else { | |||||
| return R.code(22, "解密失败"); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| this.logger.error(e.getMessage(), e); | |||||
| return R.error(e.toString()); | |||||
| } | |||||
| } else { | |||||
| return R.code(20, "用户信息未找到"); | |||||
| return new ResultData(ErrorCode.DB_FAIL.getCode(), "解密并保存出错", resultMap); | |||||
| } | } | ||||
| } | } | ||||
| */ | |||||
| /** | /** | ||||
| * 判断是否是老用户 | * 判断是否是老用户 | ||||
| * @param map | * @param map | ||||
| @@ -0,0 +1,69 @@ | |||||
| package com.simple.interceptor; | |||||
| import com.simple.annotation.AuthIgnore; | |||||
| import com.simple.common.ErrorCode; | |||||
| import com.simple.domain.po.WxCUser; | |||||
| import com.simple.exception.MallinkException; | |||||
| import com.simple.service.WxCUserService; | |||||
| import org.apache.commons.lang.StringUtils; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.mail.MailException; | |||||
| import org.springframework.stereotype.Component; | |||||
| import org.springframework.web.method.HandlerMethod; | |||||
| import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| /** | |||||
| * 权限(Token)验证 | |||||
| * @author stormeye.wu | |||||
| * @email wuguoqiang@iformall.com | |||||
| * @date 2017-03-23 15:38 | |||||
| */ | |||||
| @Component | |||||
| public class AuthorizationInterceptor extends HandlerInterceptorAdapter { | |||||
| @Autowired | |||||
| private WxCUserService wxCUserService; | |||||
| public static final String LOGIN_USER_KEY = "LOGIN_USER_KEY"; | |||||
| @Override | |||||
| public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | |||||
| AuthIgnore annotation; | |||||
| if(handler instanceof HandlerMethod) { | |||||
| annotation = ((HandlerMethod) handler).getMethodAnnotation(AuthIgnore.class); | |||||
| }else{ | |||||
| return true; | |||||
| } | |||||
| //如果有@IgnoreAuth注解,则不验证token | |||||
| if(annotation != null){ | |||||
| return true; | |||||
| } | |||||
| //从header中获取token | |||||
| String token = request.getHeader("token"); | |||||
| //如果header中不存在token,则从参数中获取token | |||||
| if(StringUtils.isBlank(token)){ | |||||
| token = request.getParameter("token"); | |||||
| } | |||||
| //token为空 | |||||
| if(StringUtils.isBlank(token)){ | |||||
| throw new MallinkException(ErrorCode.TOKEN_EMPTY); | |||||
| } | |||||
| // 查询token信息 | |||||
| WxCUser wxCUser = wxCUserService.getByToken(token); | |||||
| if(wxCUser == null || wxCUser.getExpireTime().getTime() < System.currentTimeMillis()){ | |||||
| throw new MallinkException(ErrorCode.TOKEN_INVALID.getCode(), "URL:" + request.getRequestURL() + " token失效,请重新登录"); | |||||
| } | |||||
| //设置userId到request里,后续根据userId,获取用户信息 | |||||
| request.setAttribute(LOGIN_USER_KEY, wxCUser.getId()); | |||||
| return true; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,46 @@ | |||||
| package com.simple.resolver; | |||||
| import com.simple.annotation.LoginUser; | |||||
| import com.simple.domain.po.WxCUser; | |||||
| import com.simple.interceptor.AuthorizationInterceptor; | |||||
| import com.simple.service.WxCUserService; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.core.MethodParameter; | |||||
| import org.springframework.stereotype.Component; | |||||
| import org.springframework.web.bind.support.WebDataBinderFactory; | |||||
| import org.springframework.web.context.request.NativeWebRequest; | |||||
| import org.springframework.web.context.request.RequestAttributes; | |||||
| import org.springframework.web.method.support.HandlerMethodArgumentResolver; | |||||
| import org.springframework.web.method.support.ModelAndViewContainer; | |||||
| /** | |||||
| * 有@LoginUser注解的方法参数,注入当前登录用户 | |||||
| * @author stormeye.wu | |||||
| * @email wugq@mippoint.com | |||||
| * @date 2017-03-23 22:02 | |||||
| */ | |||||
| @Component | |||||
| public class LoginUserHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver { | |||||
| @Autowired | |||||
| private WxCUserService wxCUserService; | |||||
| @Override | |||||
| public boolean supportsParameter(MethodParameter parameter) { | |||||
| return parameter.getParameterType().isAssignableFrom(WxCUser.class) && parameter.hasParameterAnnotation(LoginUser.class); | |||||
| } | |||||
| @Override | |||||
| public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer container, | |||||
| NativeWebRequest request, WebDataBinderFactory factory) throws Exception { | |||||
| //获取用户ID | |||||
| Object object = request.getAttribute(AuthorizationInterceptor.LOGIN_USER_KEY, RequestAttributes.SCOPE_REQUEST); | |||||
| if(object == null){ | |||||
| return null; | |||||
| } | |||||
| //获取用户信息 | |||||
| WxCUser user = wxCUserService.getByToken((String)object); | |||||
| return user; | |||||
| } | |||||
| } | |||||
| @@ -1,5 +1,5 @@ | |||||
| server: | server: | ||||
| port: 8000 | |||||
| port: 8001 | |||||
| context-path: /C | context-path: /C | ||||
| spring: | spring: | ||||
| @@ -29,6 +29,9 @@ public enum ErrorCode{ | |||||
| LOGIN_DENIED(1014, "登录失败"), | LOGIN_DENIED(1014, "登录失败"), | ||||
| TOKEN_INVALID(1015, "TOKEN无效"), | TOKEN_INVALID(1015, "TOKEN无效"), | ||||
| TOKEN_EMPTY(1016, "token不能为空"), | |||||
| DB_FAIL(1045, "数据库访问出错"), | |||||
| TOO_MANY_REQUEST(1050, "太多的请求访问"), | TOO_MANY_REQUEST(1050, "太多的请求访问"), | ||||
| @@ -43,6 +46,10 @@ public enum ErrorCode{ | |||||
| PASSWORD_ERROR(2001, "密码错误"), | PASSWORD_ERROR(2001, "密码错误"), | ||||
| LOGIN_USER_OR_PWD_ERROR(2002, "用户名或密码错误"), | LOGIN_USER_OR_PWD_ERROR(2002, "用户名或密码错误"), | ||||
| USER_IS_LOCKED(2003, "用户已经被锁定不能登录,请与管理员联系"), | USER_IS_LOCKED(2003, "用户已经被锁定不能登录,请与管理员联系"), | ||||
| NEW_USER_FAILD(2004, "创建新用户失败"), | |||||
| COUPON_IS_EMPTY(2020, "券不存在"), | |||||
| /** | /** | ||||
| * 车流 2050 | * 车流 2050 | ||||
| @@ -72,7 +79,9 @@ public enum ErrorCode{ | |||||
| /** | /** | ||||
| * 微信 | * 微信 | ||||
| */ | */ | ||||
| SESSION_KEY_DECODE_ERR(11001, "session_key/openId解密失败"), | |||||
| NICK_NAME_DECODE_ERR(11002, "nickName,unionId解密失败"), | |||||
| PHONE_DECODE_ERR(11002, "Phoned解密失败"), | |||||
| /** | /** | ||||
| @@ -24,4 +24,9 @@ public class Result { | |||||
| this.message = message; | this.message = message; | ||||
| } | } | ||||
| public Result(ErrorCode errorCode) { | |||||
| this.code = errorCode.getCode(); | |||||
| this.message = errorCode.getMessage(); | |||||
| } | |||||
| } | } | ||||
| @@ -76,6 +76,12 @@ public class ResultData extends Result { | |||||
| this.data = data; | this.data = data; | ||||
| } | } | ||||
| public ResultData(ErrorCode errorCode, Object data) { | |||||
| this.code = errorCode.getCode(); | |||||
| this.message = errorCode.getMessage(); | |||||
| this.data = data; | |||||
| } | |||||
| public HashMap<String, Object> toHashMap() { | public HashMap<String, Object> toHashMap() { | ||||
| HashMap<String, Object> map = new HashMap<>(3); | HashMap<String, Object> map = new HashMap<>(3); | ||||
| map.put("code", this.code); | map.put("code", this.code); | ||||
| @@ -45,20 +45,23 @@ public class WxAppinfo implements Serializable { | |||||
| @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | ||||
| private String tenantId; | private String tenantId; | ||||
| /*小程序ID**/ | /*小程序ID**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="小程序ID",name="appid") | |||||
| private String appid; | |||||
| /*小程序secret**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="小程序secret",name="secret") | |||||
| private String secret; | |||||
| @io.swagger.annotations.ApiModelProperty(value="小程序ID",name="appId") | |||||
| private String appId; | |||||
| /*小程序名**/ | /*小程序名**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="小程序名",name="name") | @io.swagger.annotations.ApiModelProperty(value="小程序名",name="name") | ||||
| private String name; | private String name; | ||||
| /*小程序secret**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="小程序secret",name="secret") | |||||
| private String secret; | |||||
| /*消息token**/ | /*消息token**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="消息token",name="token") | @io.swagger.annotations.ApiModelProperty(value="消息token",name="token") | ||||
| private String token; | private String token; | ||||
| /*消息aeskey**/ | /*消息aeskey**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="消息aeskey",name="aeskey") | |||||
| private String aeskey; | |||||
| @io.swagger.annotations.ApiModelProperty(value="消息aeskey",name="aesKey") | |||||
| private String aesKey; | |||||
| /*消息类型**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="消息类型",name="msgDataFormat") | |||||
| private String msgDataFormat; | |||||
| /*微信访问token**/ | /*微信访问token**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="微信访问token",name="accessToken") | @io.swagger.annotations.ApiModelProperty(value="微信访问token",name="accessToken") | ||||
| private String accessToken; | private String accessToken; | ||||
| @@ -74,17 +77,11 @@ public class WxAppinfo implements Serializable { | |||||
| public void setTenantId(String _tenantId) { | public void setTenantId(String _tenantId) { | ||||
| tenantId = _tenantId; | tenantId = _tenantId; | ||||
| } | } | ||||
| public String getAppid() { | |||||
| return appid; | |||||
| public String getAppId() { | |||||
| return appId; | |||||
| } | } | ||||
| public void setAppid(String _appid) { | |||||
| appid = _appid; | |||||
| } | |||||
| public String getSecret() { | |||||
| return secret; | |||||
| } | |||||
| public void setSecret(String _secret) { | |||||
| secret = _secret; | |||||
| public void setAppId(String _appId) { | |||||
| appId = _appId; | |||||
| } | } | ||||
| public String getName() { | public String getName() { | ||||
| return name; | return name; | ||||
| @@ -92,17 +89,29 @@ public class WxAppinfo implements Serializable { | |||||
| public void setName(String _name) { | public void setName(String _name) { | ||||
| name = _name; | name = _name; | ||||
| } | } | ||||
| public String getSecret() { | |||||
| return secret; | |||||
| } | |||||
| public void setSecret(String _secret) { | |||||
| secret = _secret; | |||||
| } | |||||
| public String getToken() { | public String getToken() { | ||||
| return token; | return token; | ||||
| } | } | ||||
| public void setToken(String _token) { | public void setToken(String _token) { | ||||
| token = _token; | token = _token; | ||||
| } | } | ||||
| public String getAeskey() { | |||||
| return aeskey; | |||||
| public String getAesKey() { | |||||
| return aesKey; | |||||
| } | |||||
| public void setAesKey(String _aesKey) { | |||||
| aesKey = _aesKey; | |||||
| } | |||||
| public String getMsgDataFormat() { | |||||
| return msgDataFormat; | |||||
| } | } | ||||
| public void setAeskey(String _aeskey) { | |||||
| aeskey = _aeskey; | |||||
| public void setMsgDataFormat(String _msgDataFormat) { | |||||
| msgDataFormat = _msgDataFormat; | |||||
| } | } | ||||
| public String getAccessToken() { | public String getAccessToken() { | ||||
| return accessToken; | return accessToken; | ||||
| @@ -129,11 +138,12 @@ public class WxAppinfo implements Serializable { | |||||
| { | { | ||||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | ||||
| ,TenantId_ASC("`tenantId` ASC"),TenantId_DESC("`tenantId` DESC") | ,TenantId_ASC("`tenantId` ASC"),TenantId_DESC("`tenantId` DESC") | ||||
| ,Appid_ASC("`appid` ASC"),Appid_DESC("`appid` DESC") | |||||
| ,Secret_ASC("`secret` ASC"),Secret_DESC("`secret` DESC") | |||||
| ,AppId_ASC("`appId` ASC"),AppId_DESC("`appId` DESC") | |||||
| ,Name_ASC("`name` ASC"),Name_DESC("`name` DESC") | ,Name_ASC("`name` ASC"),Name_DESC("`name` DESC") | ||||
| ,Secret_ASC("`secret` ASC"),Secret_DESC("`secret` DESC") | |||||
| ,Token_ASC("`token` ASC"),Token_DESC("`token` DESC") | ,Token_ASC("`token` ASC"),Token_DESC("`token` DESC") | ||||
| ,Aeskey_ASC("`aeskey` ASC"),Aeskey_DESC("`aeskey` DESC") | |||||
| ,AesKey_ASC("`aesKey` ASC"),AesKey_DESC("`aesKey` DESC") | |||||
| ,MsgDataFormat_ASC("`msgDataFormat` ASC"),MsgDataFormat_DESC("`msgDataFormat` DESC") | |||||
| ,AccessToken_ASC("`accessToken` ASC"),AccessToken_DESC("`accessToken` DESC") | ,AccessToken_ASC("`accessToken` ASC"),AccessToken_DESC("`accessToken` DESC") | ||||
| ,LastTokenTime_ASC("`lastTokenTime` ASC"),LastTokenTime_DESC("`lastTokenTime` DESC") | ,LastTokenTime_ASC("`lastTokenTime` ASC"),LastTokenTime_DESC("`lastTokenTime` DESC") | ||||
| ,ExpiresIn_ASC("`expiresIn` ASC"),ExpiresIn_DESC("`expiresIn` DESC") | ,ExpiresIn_ASC("`expiresIn` ASC"),ExpiresIn_DESC("`expiresIn` DESC") | ||||
| @@ -11,12 +11,14 @@ import java.io.Serializable; | |||||
| @Table(name = "wx_c_user") | @Table(name = "wx_c_user") | ||||
| public class WxCUser implements Serializable { | public class WxCUser implements Serializable { | ||||
| private static final long serialVersionUID = 1L; | private static final long serialVersionUID = 1L; | ||||
| //12小时后过期 | |||||
| private final static int EXPIRE = 3600 * 12; | |||||
| @Id | @Id | ||||
| protected Long id; | protected Long id; | ||||
| @Transient | @Transient | ||||
| protected List<String> ids; | |||||
| protected List<Long> ids; | |||||
| @Transient | @Transient | ||||
| protected String sortColumns; | protected String sortColumns; | ||||
| @@ -32,10 +34,11 @@ public class WxCUser implements Serializable { | |||||
| return sortColumns; | return sortColumns; | ||||
| } | } | ||||
| public List<String> getIds() { | |||||
| public List<Long> getIds() { | |||||
| return ids; | return ids; | ||||
| } | } | ||||
| public void setIds(List<String> ids) { | |||||
| public void setIds(List<Long> ids) { | |||||
| this.ids = ids; | this.ids = ids; | ||||
| } | } | ||||
| @@ -104,6 +107,15 @@ public class WxCUser implements Serializable { | |||||
| /*创建时间**/ | /*创建时间**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | ||||
| private Date createDate; | private Date createDate; | ||||
| /*小程序的appId**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="小程序的appId",name="appId") | |||||
| private String appId; | |||||
| /*用户登录用token**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="用户登录用token",name="token") | |||||
| private String token; | |||||
| /*用户过期时间**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="用户过期时间",name="expireTime") | |||||
| private Date expireTime; | |||||
| public String getTenantId() { | public String getTenantId() { | ||||
| return tenantId; | return tenantId; | ||||
| } | } | ||||
| @@ -230,6 +242,24 @@ public class WxCUser implements Serializable { | |||||
| public void setCreateDate(Date _createDate) { | public void setCreateDate(Date _createDate) { | ||||
| createDate = _createDate; | createDate = _createDate; | ||||
| } | } | ||||
| public String getAppId() { | |||||
| return appId; | |||||
| } | |||||
| public void setAppId(String _appId) { | |||||
| appId = _appId; | |||||
| } | |||||
| public String getToken() { | |||||
| return token; | |||||
| } | |||||
| public void setToken(String _token) { | |||||
| token = _token; | |||||
| } | |||||
| public Date getExpireTime() { | |||||
| return expireTime; | |||||
| } | |||||
| public void setExpireTime(Date _expireTime) { | |||||
| expireTime = _expireTime; | |||||
| } | |||||
| @@ -257,6 +287,9 @@ public class WxCUser implements Serializable { | |||||
| ,Score_ASC("`score` ASC"),Score_DESC("`score` DESC") | ,Score_ASC("`score` ASC"),Score_DESC("`score` DESC") | ||||
| ,UpdateDate_ASC("`updateDate` ASC"),UpdateDate_DESC("`updateDate` DESC") | ,UpdateDate_ASC("`updateDate` ASC"),UpdateDate_DESC("`updateDate` DESC") | ||||
| ,CreateDate_ASC("`createDate` ASC"),CreateDate_DESC("`createDate` DESC") | ,CreateDate_ASC("`createDate` ASC"),CreateDate_DESC("`createDate` DESC") | ||||
| ,AppId_ASC("`appId` ASC"),AppId_DESC("`appId` DESC") | |||||
| ,Token_ASC("`token` ASC"),Token_DESC("`token` DESC") | |||||
| ,ExpireTime_ASC("`expireTime` ASC"),ExpireTime_DESC("`expireTime` DESC") | |||||
| ; | ; | ||||
| private String value; | private String value; | ||||
| Field(String value){ | Field(String value){ | ||||
| @@ -308,4 +341,16 @@ public class WxCUser implements Serializable { | |||||
| this.setSortColumns(Field.valueOf(sortColumns)); | this.setSortColumns(Field.valueOf(sortColumns)); | ||||
| } | } | ||||
| } | } | ||||
| public void createToken(Date currentDate) { | |||||
| if (expireTime == null || expireTime.getTime() < currentDate.getTime()) | |||||
| { | |||||
| //生成一个token | |||||
| String token = UUID.randomUUID().toString(); | |||||
| //过期时间 | |||||
| Date expireTime = new Date(currentDate.getTime() + EXPIRE * 1000); | |||||
| setToken(token); | |||||
| setExpireTime(expireTime); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,231 @@ | |||||
| package com.simple.domain.po; | |||||
| import javax.persistence.*; | |||||
| import java.util.*; | |||||
| import java.math.*; | |||||
| import javax.persistence.Transient; | |||||
| import java.util.List; | |||||
| import javax.persistence.Id; | |||||
| import java.io.Serializable; | |||||
| @Table(name = "wx_coupon_order") | |||||
| public class WxCouponOrder implements Serializable { | |||||
| private static final long serialVersionUID = 1L; | |||||
| @Id | |||||
| protected Long id; | |||||
| @Transient | |||||
| protected List<Long> ids; | |||||
| @Transient | |||||
| protected String sortColumns; | |||||
| public Long getId() { | |||||
| return id; | |||||
| } | |||||
| public void setId(Long id) { | |||||
| this.id = id; | |||||
| } | |||||
| public String getSortColumns() { | |||||
| return sortColumns; | |||||
| } | |||||
| public List<Long> getIds() { | |||||
| return ids; | |||||
| } | |||||
| public void setIds(List<Long> ids) { | |||||
| this.ids = ids; | |||||
| } | |||||
| /***/ | |||||
| @io.swagger.annotations.ApiModelProperty(value = "", name = "tenantId") | |||||
| private Long tenantId; | |||||
| /*单张券ID**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value = "单张券ID", name = "couponId") | |||||
| private Long couponId; | |||||
| /*c端用户id**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value = "c端用户id", name = "cUserId") | |||||
| private Long cUserId; | |||||
| /*操作券B端小程序用户ID**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value = "操作券B端小程序用户ID", name = "bUserId") | |||||
| private Long bUserId; | |||||
| /*用户订单ID**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value = "用户订单ID", name = "orderId") | |||||
| private Long orderId; | |||||
| /*该订单对应券的实际过期时间**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value = "该订单对应券的实际过期时间", name = "expiredTime") | |||||
| private Date expiredTime; | |||||
| /*状态:0,待使用 1,已核销 2,已过期 3,已作废 **/ | |||||
| @io.swagger.annotations.ApiModelProperty(value = "状态:0,待使用 1,已核销 2,已过期 3,已作废 ", name = "couponOrderStatus") | |||||
| private Integer couponOrderStatus; | |||||
| /***/ | |||||
| @io.swagger.annotations.ApiModelProperty(value = "", name = "createDate") | |||||
| private Date createDate; | |||||
| /***/ | |||||
| @io.swagger.annotations.ApiModelProperty(value = "", name = "updateDate") | |||||
| private Date updateDate; | |||||
| /*单券实际购买价格**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value = "单券实际购买价格", name = "couponPrice") | |||||
| private BigDecimal couponPrice; | |||||
| public Long getTenantId() { | |||||
| return tenantId; | |||||
| } | |||||
| public void setTenantId(Long _tenantId) { | |||||
| tenantId = _tenantId; | |||||
| } | |||||
| public Long getCouponId() { | |||||
| return couponId; | |||||
| } | |||||
| public void setCouponId(Long _couponId) { | |||||
| couponId = _couponId; | |||||
| } | |||||
| public Long getCUserId() { | |||||
| return cUserId; | |||||
| } | |||||
| public void setCUserId(Long _cUserId) { | |||||
| cUserId = _cUserId; | |||||
| } | |||||
| public Long getBUserId() { | |||||
| return bUserId; | |||||
| } | |||||
| public void setBUserId(Long _bUserId) { | |||||
| bUserId = _bUserId; | |||||
| } | |||||
| public Long getOrderId() { | |||||
| return orderId; | |||||
| } | |||||
| public void setOrderId(Long _orderId) { | |||||
| orderId = _orderId; | |||||
| } | |||||
| public Date getExpiredTime() { | |||||
| return expiredTime; | |||||
| } | |||||
| public void setExpiredTime(Date _expiredTime) { | |||||
| expiredTime = _expiredTime; | |||||
| } | |||||
| public Integer getCouponOrderStatus() { | |||||
| return couponOrderStatus; | |||||
| } | |||||
| public void setCouponOrderStatus(Integer _couponOrderStatus) { | |||||
| couponOrderStatus = _couponOrderStatus; | |||||
| } | |||||
| public Date getCreateDate() { | |||||
| return createDate; | |||||
| } | |||||
| public void setCreateDate(Date _createDate) { | |||||
| createDate = _createDate; | |||||
| } | |||||
| public Date getUpdateDate() { | |||||
| return updateDate; | |||||
| } | |||||
| public void setUpdateDate(Date _updateDate) { | |||||
| updateDate = _updateDate; | |||||
| } | |||||
| public BigDecimal getCouponPrice() { | |||||
| return couponPrice; | |||||
| } | |||||
| public void setCouponPrice(BigDecimal _couponPrice) { | |||||
| couponPrice = _couponPrice; | |||||
| } | |||||
| public static enum Field { | |||||
| CouponOrderId_ASC("`couponOrderId` ASC"), | |||||
| CouponOrderId_DESC("`couponOrderId` DESC"), | |||||
| TenantId_ASC("`tenantId` ASC"), | |||||
| TenantId_DESC("`tenantId` DESC"), | |||||
| CouponId_ASC("`couponId` ASC"), | |||||
| CouponId_DESC("`couponId` DESC"), | |||||
| CUserId_ASC("`cUserId` ASC"), | |||||
| CUserId_DESC("`cUserId` DESC"), | |||||
| BUserId_ASC("`bUserId` ASC"), | |||||
| BUserId_DESC("`bUserId` DESC"), | |||||
| OrderId_ASC("`orderId` ASC"), | |||||
| OrderId_DESC("`orderId` DESC"), | |||||
| ExpiredTime_ASC("`expiredTime` ASC"), | |||||
| ExpiredTime_DESC("`expiredTime` DESC"), | |||||
| CouponOrderStatus_ASC("`couponOrderStatus` ASC"), | |||||
| CouponOrderStatus_DESC("`couponOrderStatus` DESC"), | |||||
| CreateDate_ASC("`createDate` ASC"), | |||||
| CreateDate_DESC("`createDate` DESC"), | |||||
| UpdateDate_ASC("`updateDate` ASC"), | |||||
| UpdateDate_DESC("`updateDate` DESC"), | |||||
| CouponPrice_ASC("`couponPrice` ASC"), | |||||
| CouponPrice_DESC("`couponPrice` DESC"); | |||||
| private String value; | |||||
| Field(String value) { | |||||
| this.value = value; | |||||
| } | |||||
| public String getValue() { | |||||
| return value; | |||||
| } | |||||
| public void setCol(String value) { | |||||
| this.value = value; | |||||
| } | |||||
| @Override | |||||
| public String toString() { | |||||
| return this.getValue(); | |||||
| } | |||||
| } | |||||
| public void setSortColumns(WxCouponOrder.Field... fields) { | |||||
| if (fields == null || fields.length == 0) { | |||||
| return; | |||||
| } | |||||
| for (int k = 0; k < fields.length; k++) { | |||||
| if (fields[k] == null) { | |||||
| return; | |||||
| } | |||||
| } | |||||
| StringBuilder sb = new StringBuilder(fields[0].toString()); | |||||
| for (int k = 1; k < fields.length; k++) { | |||||
| sb.append(","); | |||||
| sb.append(fields[k].toString()); | |||||
| } | |||||
| } | |||||
| public void setSortColumns(String sortColumns) { | |||||
| if (sortColumns == null || "".equals(sortColumns.trim())) { | |||||
| return; | |||||
| } | |||||
| if (sortColumns.contains(",")) { | |||||
| String[] cols = sortColumns.split(","); | |||||
| java.util.List<Field> fList = new java.util.ArrayList(); | |||||
| for (int k = 0; k < cols.length; k++) { | |||||
| fList.add(Field.valueOf(cols[k])); | |||||
| } | |||||
| this.setSortColumns(fList.toArray(new Field[fList.size()])); | |||||
| } else { | |||||
| this.setSortColumns(Field.valueOf(sortColumns)); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -16,7 +16,7 @@ public class WxOrder implements Serializable { | |||||
| protected Long id; | protected Long id; | ||||
| @Transient | @Transient | ||||
| protected List<String> ids; | |||||
| protected List<Long> ids; | |||||
| @Transient | @Transient | ||||
| protected String sortColumns; | protected String sortColumns; | ||||
| @@ -32,73 +32,80 @@ public class WxOrder implements Serializable { | |||||
| return sortColumns; | return sortColumns; | ||||
| } | } | ||||
| public List<String> getIds() { | |||||
| public List<Long> getIds() { | |||||
| return ids; | return ids; | ||||
| } | } | ||||
| public void setIds(List<String> ids) { | |||||
| public void setIds(List<Long> ids) { | |||||
| this.ids = ids; | this.ids = ids; | ||||
| } | } | ||||
| /*订单码;正反向交易保持一致。**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="订单码;正反向交易保持一致。",name="orderNumber") | |||||
| private Long orderNumber; | |||||
| /*租户ID**/ | /*租户ID**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | ||||
| private String tenantId; | private String tenantId; | ||||
| /*卡券ID**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="卡券ID",name="couponId") | |||||
| private Long couponId; | |||||
| /*c端用户id**/ | /*c端用户id**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="c端用户id",name="cUserId") | @io.swagger.annotations.ApiModelProperty(value="c端用户id",name="cUserId") | ||||
| private Long cUserId; | private Long cUserId; | ||||
| /*支付金额**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="支付金额",name="payment") | |||||
| private BigDecimal payment; | |||||
| /*操作券B端小程序用户ID**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="操作券B端小程序用户ID",name="bUserId") | |||||
| private Long bUserId; | |||||
| /*0: 付款 1: 退款**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="0: 付款 1: 退款",name="paymentType") | |||||
| private Integer paymentType; | |||||
| /*支付金额(分):允许有负数,退款时为负值。**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="支付金额(分):允许有负数,退款时为负值。",name="payment") | |||||
| private Integer payment; | |||||
| /*支付时间**/ | /*支付时间**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="支付时间",name="paymentTime") | @io.swagger.annotations.ApiModelProperty(value="支付时间",name="paymentTime") | ||||
| private Date paymentTime; | private Date paymentTime; | ||||
| /*订单状态:-1全部;0-已下单/待付款;1-已支付;2-已取消(限定时间内未付款);3-未退款/待退款;4-已退款;5-退款失败**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="订单状态:-1全部;0-已下单/待付款;1-已支付;2-已取消(限定时间内未付款);3-未退款/待退款;4-已退款;5-退款失败",name="status") | |||||
| private Integer status; | |||||
| /*券状态(3:已领取/已购买/未核销/未使用,4:已核销/已使用,5:已过期,6:已退券 )**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="券状态(3:已领取/已购买/未核销/未使用,4:已核销/已使用,5:已过期,6:已退券 )",name="couponStatus") | |||||
| private Integer couponStatus; | |||||
| /*卡券过期时间**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="卡券过期时间",name="validDate") | |||||
| private Date validDate; | |||||
| /*有无退款(0: 无, 1:有)**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="有无退款(0: 无, 1:有)",name="refund") | |||||
| private Integer refund; | |||||
| /*退款时间**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="退款时间",name="refundTime") | |||||
| private Date refundTime; | |||||
| /*订单状态:-1全部;正向交易:0-已下单/待付款;1-已支付;2-已取消(限定时间内未付款)反向交易:3-已退款;4-退款失败**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="订单状态:-1全部;正向交易:0-已下单/待付款;1-已支付;2-已取消(限定时间内未付款)反向交易:3-已退款;4-退款失败",name="orderStatus") | |||||
| private Integer orderStatus; | |||||
| /*创建时间**/ | /*创建时间**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | ||||
| private Date createDate; | private Date createDate; | ||||
| /*更新时间**/ | /*更新时间**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") | @io.swagger.annotations.ApiModelProperty(value="更新时间",name="updateDate") | ||||
| private Date updateDate; | private Date updateDate; | ||||
| public Long getOrderNumber() { | |||||
| return orderNumber; | |||||
| } | |||||
| public void setOrderNumber(Long _orderNumber) { | |||||
| orderNumber = _orderNumber; | |||||
| } | |||||
| public String getTenantId() { | public String getTenantId() { | ||||
| return tenantId; | return tenantId; | ||||
| } | } | ||||
| public void setTenantId(String _tenantId) { | public void setTenantId(String _tenantId) { | ||||
| tenantId = _tenantId; | tenantId = _tenantId; | ||||
| } | } | ||||
| public Long getCouponId() { | |||||
| return couponId; | |||||
| } | |||||
| public void setCouponId(Long _couponId) { | |||||
| couponId = _couponId; | |||||
| } | |||||
| public Long getCUserId() { | public Long getCUserId() { | ||||
| return cUserId; | return cUserId; | ||||
| } | } | ||||
| public void setCUserId(Long _cUserId) { | public void setCUserId(Long _cUserId) { | ||||
| cUserId = _cUserId; | cUserId = _cUserId; | ||||
| } | } | ||||
| public BigDecimal getPayment() { | |||||
| public Long getBUserId() { | |||||
| return bUserId; | |||||
| } | |||||
| public void setBUserId(Long _bUserId) { | |||||
| bUserId = _bUserId; | |||||
| } | |||||
| public Integer getPaymentType() { | |||||
| return paymentType; | |||||
| } | |||||
| public void setPaymentType(Integer _paymentType) { | |||||
| paymentType = _paymentType; | |||||
| } | |||||
| public Integer getPayment() { | |||||
| return payment; | return payment; | ||||
| } | } | ||||
| public void setPayment(BigDecimal _payment) { | |||||
| public void setPayment(Integer _payment) { | |||||
| payment = _payment; | payment = _payment; | ||||
| } | } | ||||
| public Date getPaymentTime() { | public Date getPaymentTime() { | ||||
| @@ -107,35 +114,11 @@ public class WxOrder implements Serializable { | |||||
| public void setPaymentTime(Date _paymentTime) { | public void setPaymentTime(Date _paymentTime) { | ||||
| paymentTime = _paymentTime; | paymentTime = _paymentTime; | ||||
| } | } | ||||
| public Integer getStatus() { | |||||
| return status; | |||||
| } | |||||
| public void setStatus(Integer _status) { | |||||
| status = _status; | |||||
| } | |||||
| public Integer getCouponStatus() { | |||||
| return couponStatus; | |||||
| } | |||||
| public void setCouponStatus(Integer _couponStatus) { | |||||
| couponStatus = _couponStatus; | |||||
| } | |||||
| public Date getValidDate() { | |||||
| return validDate; | |||||
| } | |||||
| public void setValidDate(Date _validDate) { | |||||
| validDate = _validDate; | |||||
| } | |||||
| public Integer getRefund() { | |||||
| return refund; | |||||
| } | |||||
| public void setRefund(Integer _refund) { | |||||
| refund = _refund; | |||||
| } | |||||
| public Date getRefundTime() { | |||||
| return refundTime; | |||||
| public Integer getOrderStatus() { | |||||
| return orderStatus; | |||||
| } | } | ||||
| public void setRefundTime(Date _refundTime) { | |||||
| refundTime = _refundTime; | |||||
| public void setOrderStatus(Integer _orderStatus) { | |||||
| orderStatus = _orderStatus; | |||||
| } | } | ||||
| public Date getCreateDate() { | public Date getCreateDate() { | ||||
| return createDate; | return createDate; | ||||
| @@ -155,16 +138,14 @@ public class WxOrder implements Serializable { | |||||
| public static enum Field | public static enum Field | ||||
| { | { | ||||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | ||||
| ,OrderNumber_ASC("`orderNumber` ASC"),OrderNumber_DESC("`orderNumber` DESC") | |||||
| ,TenantId_ASC("`tenantId` ASC"),TenantId_DESC("`tenantId` DESC") | ,TenantId_ASC("`tenantId` ASC"),TenantId_DESC("`tenantId` DESC") | ||||
| ,CouponId_ASC("`couponId` ASC"),CouponId_DESC("`couponId` DESC") | |||||
| ,CUserId_ASC("`cUserId` ASC"),CUserId_DESC("`cUserId` DESC") | ,CUserId_ASC("`cUserId` ASC"),CUserId_DESC("`cUserId` DESC") | ||||
| ,BUserId_ASC("`bUserId` ASC"),BUserId_DESC("`bUserId` DESC") | |||||
| ,PaymentType_ASC("`paymentType` ASC"),PaymentType_DESC("`paymentType` DESC") | |||||
| ,Payment_ASC("`payment` ASC"),Payment_DESC("`payment` DESC") | ,Payment_ASC("`payment` ASC"),Payment_DESC("`payment` DESC") | ||||
| ,PaymentTime_ASC("`paymentTime` ASC"),PaymentTime_DESC("`paymentTime` DESC") | ,PaymentTime_ASC("`paymentTime` ASC"),PaymentTime_DESC("`paymentTime` DESC") | ||||
| ,Status_ASC("`status` ASC"),Status_DESC("`status` DESC") | |||||
| ,CouponStatus_ASC("`couponStatus` ASC"),CouponStatus_DESC("`couponStatus` DESC") | |||||
| ,ValidDate_ASC("`validDate` ASC"),ValidDate_DESC("`validDate` DESC") | |||||
| ,Refund_ASC("`refund` ASC"),Refund_DESC("`refund` DESC") | |||||
| ,RefundTime_ASC("`refundTime` ASC"),RefundTime_DESC("`refundTime` DESC") | |||||
| ,OrderStatus_ASC("`orderStatus` ASC"),OrderStatus_DESC("`orderStatus` DESC") | |||||
| ,CreateDate_ASC("`createDate` ASC"),CreateDate_DESC("`createDate` DESC") | ,CreateDate_ASC("`createDate` ASC"),CreateDate_DESC("`createDate` DESC") | ||||
| ,UpdateDate_ASC("`updateDate` ASC"),UpdateDate_DESC("`updateDate` DESC") | ,UpdateDate_ASC("`updateDate` ASC"),UpdateDate_DESC("`updateDate` DESC") | ||||
| ; | ; | ||||
| @@ -184,7 +165,7 @@ public class WxOrder implements Serializable { | |||||
| } | } | ||||
| } | } | ||||
| public void setSortColumns(Field... fields) | |||||
| public void setSortColumns(WxOrder.Field... fields) | |||||
| { | { | ||||
| if (fields == null || fields.length == 0) { | if (fields == null || fields.length == 0) { | ||||
| return; | return; | ||||
| @@ -209,7 +190,7 @@ public class WxOrder implements Serializable { | |||||
| } | } | ||||
| if (sortColumns.contains(",")) { | if (sortColumns.contains(",")) { | ||||
| String[] cols = sortColumns.split(","); | String[] cols = sortColumns.split(","); | ||||
| List<Field> fList = new ArrayList(); | |||||
| java.util.List<Field> fList = new java.util.ArrayList(); | |||||
| for (int k = 0; k < cols.length; k++) { | for (int k = 0; k < cols.length; k++) { | ||||
| fList.add(Field.valueOf(cols[k])); | fList.add(Field.valueOf(cols[k])); | ||||
| } | } | ||||
| @@ -0,0 +1,39 @@ | |||||
| package com.simple.enums; | |||||
| /** | |||||
| * Created by Stormeye on 2018/08/09. | |||||
| */ | |||||
| public enum EnumCouponOrderStatus { | |||||
| // 0-已领取/已购买/未核销/未使用/待使用,1:已核销/已使用,3:已过期,6:已作废 | |||||
| COUPON_ORDER_USE_WAIT(0, "待使用"), | |||||
| COUPON_ORDER_USED(1, "已核销"), | |||||
| COUPON_ORDER_OVER_TIME(2, "已过期"), | |||||
| COUPON_ORDER_INVALID(3, "已作废") | |||||
| ; | |||||
| public static EnumCouponOrderStatus getEnum(Integer code) { | |||||
| for (EnumCouponOrderStatus value : values()) { | |||||
| if (value.getCode().equals(code)) { | |||||
| return value; | |||||
| } | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private Integer code; | |||||
| private String message; | |||||
| EnumCouponOrderStatus(Integer code, String message) { | |||||
| this.code = code; | |||||
| this.message = message; | |||||
| } | |||||
| public Integer getCode() { | |||||
| return code; | |||||
| } | |||||
| public String getMessage() { | |||||
| return message; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,35 @@ | |||||
| package com.simple.enums; | |||||
| /** | |||||
| * Created by Stormeye on 2018/08/09. | |||||
| */ | |||||
| public enum EnumPayType { | |||||
| PAY_PAYMENT(0, "付款"), | |||||
| PAY_REFUND(1, "退款"); | |||||
| public static EnumPayType getEnum(Integer code) { | |||||
| for (EnumPayType value : values()) { | |||||
| if (value.getCode().equals(code)) { | |||||
| return value; | |||||
| } | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private Integer code; | |||||
| private String message; | |||||
| EnumPayType(Integer code, String message) { | |||||
| this.code = code; | |||||
| this.message = message; | |||||
| } | |||||
| public Integer getCode() { | |||||
| return code; | |||||
| } | |||||
| public String getMessage() { | |||||
| return message; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,38 @@ | |||||
| package com.simple.enums; | |||||
| /** | |||||
| * Created by Stormeye on 2018/08/09. | |||||
| */ | |||||
| public enum EnumValidStatus { | |||||
| // 1.时间范围(valid_start_date,valid_end_date). 2领取后几日有效(valid_days) | |||||
| VALID_RANGE(1, "时间范围"), | |||||
| VALID_DAYS(2, "领取后几日有效") | |||||
| ; | |||||
| public static EnumValidStatus getEnum(Integer code) { | |||||
| for (EnumValidStatus value : values()) { | |||||
| if (value.getCode().equals(code)) { | |||||
| return value; | |||||
| } | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private Integer code; | |||||
| private String message; | |||||
| EnumValidStatus(Integer code, String message) { | |||||
| this.code = code; | |||||
| this.message = message; | |||||
| } | |||||
| public Integer getCode() { | |||||
| return code; | |||||
| } | |||||
| public String getMessage() { | |||||
| return message; | |||||
| } | |||||
| } | |||||
| @@ -10,7 +10,7 @@ public interface WxAppinfoMapper extends CommonMapper<WxAppinfo, String> { | |||||
| List<WxAppinfo> findList(WxAppinfo wxAppinfo); | List<WxAppinfo> findList(WxAppinfo wxAppinfo); | ||||
| WxAppinfo findByAppId(String appId); | |||||
| @@ -5,13 +5,12 @@ import com.simple.common.CommonMapper; | |||||
| import org.apache.ibatis.annotations.Param; | import org.apache.ibatis.annotations.Param; | ||||
| import com.simple.domain.po.WxCUser; | import com.simple.domain.po.WxCUser; | ||||
| public interface WxCUserMapper extends CommonMapper<WxCUser, String> { | |||||
| public interface WxCUserMapper extends CommonMapper<WxCUser, Long> { | |||||
| List<WxCUser> findList(WxCUser wxCUser); | List<WxCUser> findList(WxCUser wxCUser); | ||||
| WxCUser findByOpenId(WxCUser record); | |||||
| WxCUser findByToken(String token); | |||||
| } | } | ||||
| @@ -0,0 +1,17 @@ | |||||
| package com.simple.mapper; | |||||
| import java.util.*; | |||||
| import com.simple.common.CommonMapper; | |||||
| import org.apache.ibatis.annotations.Param; | |||||
| import com.simple.domain.po.WxCouponOrder; | |||||
| public interface WxCouponOrderMapper extends CommonMapper<WxCouponOrder, Long> { | |||||
| List<WxCouponOrder> findList(WxCouponOrder wxCouponOrder); | |||||
| } | |||||
| @@ -10,8 +10,8 @@ public interface WxAppinfoService { | |||||
| * 根据实体查询分页列表 | * 根据实体查询分页列表 | ||||
| * | * | ||||
| * @param record | * @param record | ||||
| * @param offset | |||||
| * @param limit | |||||
| * @param pageIndex | |||||
| * @param pageSize | |||||
| * @return | * @return | ||||
| */ | */ | ||||
| PageInfo<WxAppinfo> listAsPage(WxAppinfo record, Integer pageIndex, Integer pageSize); | PageInfo<WxAppinfo> listAsPage(WxAppinfo record, Integer pageIndex, Integer pageSize); | ||||
| @@ -23,6 +23,14 @@ public interface WxAppinfoService { | |||||
| * @return | * @return | ||||
| */ | */ | ||||
| WxAppinfo getById(Long id); | WxAppinfo getById(Long id); | ||||
| /** | |||||
| * 根据appId获得实体 | |||||
| * | |||||
| * @param appId | |||||
| * @return | |||||
| */ | |||||
| WxAppinfo getByAppId(String appId); | |||||
| /** | /** | ||||
| * 保存或更新实体 | * 保存或更新实体 | ||||
| @@ -25,12 +25,28 @@ public interface WxCUserService { | |||||
| */ | */ | ||||
| WxCUser getById(Long id); | WxCUser getById(Long id); | ||||
| /** | |||||
| * 根据token获得实体 | |||||
| * | |||||
| * @param token | |||||
| * @return | |||||
| */ | |||||
| WxCUser getByToken(String token); | |||||
| /** | |||||
| * 根据openId获得实体 | |||||
| * | |||||
| * @param record | |||||
| * @return | |||||
| */ | |||||
| WxCUser getByOpenId(WxCUser record); | |||||
| /** | /** | ||||
| * 保存或更新实体 | * 保存或更新实体 | ||||
| * | * | ||||
| * @param record | * @param record | ||||
| */ | */ | ||||
| void saveOrUpdate(WxCUser record); | |||||
| int saveOrUpdate(WxCUser record); | |||||
| /** | /** | ||||
| * 根据Id删除实体 | * 根据Id删除实体 | ||||
| @@ -2,6 +2,7 @@ package com.simple.service; | |||||
| import java.util.*; | import java.util.*; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.simple.domain.po.WxCUser; | |||||
| import com.simple.domain.po.WxOrder; | import com.simple.domain.po.WxOrder; | ||||
| import com.simple.domain.vo.OrderVo; | import com.simple.domain.vo.OrderVo; | ||||
| import com.simple.enums.EnumOrderStatus; | import com.simple.enums.EnumOrderStatus; | ||||
| @@ -37,10 +38,11 @@ public interface WxOrderService { | |||||
| /** | /** | ||||
| * 提交订单 | * 提交订单 | ||||
| * @param record | |||||
| * @param user | |||||
| * @param couponId | |||||
| * @return 订单id | * @return 订单id | ||||
| */ | */ | ||||
| WxOrder saveOrder(WxOrder record); | |||||
| WxOrder saveOrder(WxCUser user, Long couponId); | |||||
| /** | /** | ||||
| * 更新订单状态 | * 更新订单状态 | ||||
| @@ -16,6 +16,10 @@ public class WxAppinfoServiceImpl implements WxAppinfoService { | |||||
| @Autowired | @Autowired | ||||
| WxAppinfoMapper wxAppinfoMapper; | WxAppinfoMapper wxAppinfoMapper; | ||||
| @Override | |||||
| public WxAppinfo getByAppId(String appId) { | |||||
| return wxAppinfoMapper.findByAppId(appId); | |||||
| } | |||||
| @Override | @Override | ||||
| public PageInfo<WxAppinfo> listAsPage(WxAppinfo record, Integer pageIndex, Integer pageSize) { | public PageInfo<WxAppinfo> listAsPage(WxAppinfo record, Integer pageIndex, Integer pageSize) { | ||||
| @@ -12,7 +12,7 @@ import com.simple.common.IdWorker; | |||||
| @Service | @Service | ||||
| public class WxCUserServiceImpl implements WxCUserService { | public class WxCUserServiceImpl implements WxCUserService { | ||||
| @Autowired | @Autowired | ||||
| WxCUserMapper wxCUserMapper; | WxCUserMapper wxCUserMapper; | ||||
| @@ -28,15 +28,32 @@ public class WxCUserServiceImpl implements WxCUserService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public void saveOrUpdate(WxCUser record) { | |||||
| if (record.getId() == null) { | |||||
| public WxCUser getByOpenId(WxCUser record) { | |||||
| return wxCUserMapper.findByOpenId(record); | |||||
| } | |||||
| @Override | |||||
| public WxCUser getByToken(String token) { | |||||
| return wxCUserMapper.findByToken(token); | |||||
| } | |||||
| @Override | |||||
| public int saveOrUpdate(WxCUser user) { | |||||
| int ret = 0; | |||||
| Date curr = new Date(); | |||||
| if (user.getId() == null) { | |||||
| //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); | //record.setId(UUID.randomUUID().toString().replaceAll("-", "")); | ||||
| final IdWorker idWorker = IdWorker.get(); | final IdWorker idWorker = IdWorker.get(); | ||||
| record.setId(idWorker.nextId()); | |||||
| wxCUserMapper.insertSelective(record); | |||||
| user.setId(idWorker.nextId()); | |||||
| user.setCreateDate(curr); | |||||
| user.setUpdateDate(curr); | |||||
| ret = wxCUserMapper.insertSelective(user); | |||||
| } else { | } else { | ||||
| wxCUserMapper.updateByPrimaryKeySelective(record); | |||||
| user.setUpdateDate(curr); | |||||
| ret =wxCUserMapper.updateByPrimaryKeySelective(user); | |||||
| } | } | ||||
| return ret; | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -45,10 +62,4 @@ public class WxCUserServiceImpl implements WxCUserService { | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,16 +1,24 @@ | |||||
| package com.simple.service.impl; | package com.simple.service.impl; | ||||
| import java.math.BigDecimal; | |||||
| import java.util.*; | import java.util.*; | ||||
| import com.github.pagehelper.PageHelper; | import com.github.pagehelper.PageHelper; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.simple.common.ErrorCode; | import com.simple.common.ErrorCode; | ||||
| import com.simple.domain.po.WxCUser; | |||||
| import com.simple.domain.po.WxCoupon; | import com.simple.domain.po.WxCoupon; | ||||
| import com.simple.domain.po.WxCouponOrder; | |||||
| import com.simple.domain.po.WxOrder; | import com.simple.domain.po.WxOrder; | ||||
| import com.simple.domain.vo.OrderVo; | import com.simple.domain.vo.OrderVo; | ||||
| import com.simple.enums.EnumCouponOrderStatus; | |||||
| import com.simple.enums.EnumOrderStatus; | import com.simple.enums.EnumOrderStatus; | ||||
| import com.simple.enums.EnumPayType; | |||||
| import com.simple.enums.EnumValidStatus; | |||||
| import com.simple.exception.MallinkException; | import com.simple.exception.MallinkException; | ||||
| import com.simple.mapper.WxCUserMapper; | |||||
| import com.simple.mapper.WxCouponMapper; | import com.simple.mapper.WxCouponMapper; | ||||
| import com.simple.mapper.WxCouponOrderMapper; | |||||
| import com.simple.mapper.WxOrderMapper; | import com.simple.mapper.WxOrderMapper; | ||||
| import com.simple.service.WxOrderService; | import com.simple.service.WxOrderService; | ||||
| import com.simple.utils.RedisLock; | import com.simple.utils.RedisLock; | ||||
| @@ -29,12 +37,18 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| @Autowired | @Autowired | ||||
| RedisLock redisLock; | RedisLock redisLock; | ||||
| @Autowired | |||||
| WxCUserMapper wxCUserMapper; | |||||
| @Autowired | @Autowired | ||||
| WxCouponMapper wxCouponMapper; | WxCouponMapper wxCouponMapper; | ||||
| @Autowired | @Autowired | ||||
| WxOrderMapper wxOrderMapper; | WxOrderMapper wxOrderMapper; | ||||
| @Autowired | |||||
| WxCouponOrderMapper wxCouponOrderMapper; | |||||
| @Override | @Override | ||||
| public PageInfo<WxOrder> listAsPage(WxOrder record, Integer pageIndex, Integer pageSize) { | public PageInfo<WxOrder> listAsPage(WxOrder record, Integer pageIndex, Integer pageSize) { | ||||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxOrderMapper.findList(record)); | return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxOrderMapper.findList(record)); | ||||
| @@ -52,25 +66,34 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| @Override | @Override | ||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | ||||
| public WxOrder saveOrder(WxOrder record) { | |||||
| String couponIdStr = String.valueOf(record.getCouponId()); | |||||
| public WxOrder saveOrder(WxCUser user, Long couponId) { | |||||
| String couponIdStr = String.valueOf(couponId); | |||||
| WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(couponId); | |||||
| if (coupon == null) { | |||||
| logger.error("券不存在, couponId: " + couponIdStr); | |||||
| throw new MallinkException(ErrorCode.COUPON_IS_EMPTY); | |||||
| } | |||||
| //加锁 | //加锁 | ||||
| long time = System.currentTimeMillis() + RedisLock.TIMEOUT; | long time = System.currentTimeMillis() + RedisLock.TIMEOUT; | ||||
| String timeStr = String.valueOf(time); | String timeStr = String.valueOf(time); | ||||
| if(!redisLock.lock(couponIdStr, timeStr)) { | if(!redisLock.lock(couponIdStr, timeStr)) { | ||||
| logger.error("此券被锁定, couponId: " + record.getCouponId()); | |||||
| logger.error("此券被锁定, couponId: " + couponIdStr); | |||||
| throw new MallinkException(ErrorCode.TOO_MANY_REQUEST); | throw new MallinkException(ErrorCode.TOO_MANY_REQUEST); | ||||
| } | } | ||||
| BigDecimal payPrice = null; | |||||
| int payment = 0; | |||||
| Date curr = new Date(); | |||||
| Date valid_date = null; | |||||
| try { | try { | ||||
| // 检查 优惠券 库存 | // 检查 优惠券 库存 | ||||
| WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(record.getCouponId()); | |||||
| if (coupon.getRemainInventory() <= 0) { | if (coupon.getRemainInventory() <= 0) { | ||||
| //解锁 | //解锁 | ||||
| redisLock.unlock(couponIdStr, timeStr); | redisLock.unlock(couponIdStr, timeStr); | ||||
| logger.error("此券库存为0, couponId: " + record.getCouponId()); | |||||
| logger.error("此券库存为0, couponId: " + couponIdStr); | |||||
| throw new MallinkException(ErrorCode.REMAIN_IS_EMPTY); | throw new MallinkException(ErrorCode.REMAIN_IS_EMPTY); | ||||
| } | } | ||||
| // 减库存 | // 减库存 | ||||
| @@ -80,24 +103,60 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| //解锁 | //解锁 | ||||
| redisLock.unlock(couponIdStr, timeStr); | redisLock.unlock(couponIdStr, timeStr); | ||||
| logger.error("此券减库存失败, couponId: " + record.getCouponId()); | |||||
| logger.error("此券减库存失败, couponId: " + couponIdStr); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | ||||
| } | } | ||||
| payPrice = coupon.getSalePrice(); | |||||
| BigDecimal ll = coupon.getSalePrice().multiply(new BigDecimal(100)); | |||||
| payment = ll.intValue(); | |||||
| valid_date = (coupon.getValidType() == EnumValidStatus.VALID_RANGE.getCode())?coupon.getValidEndDate(): new Date((curr.getTime()/1000+coupon.getValidDays()*24*60*60)*1000); | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| Long orderNumber = idWorker.nextId(); | |||||
| WxOrder record = new WxOrder(); | |||||
| try { | try { | ||||
| // 保存订单 | // 保存订单 | ||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| record.setId(idWorker.nextId()); | |||||
| record.setStatus(EnumOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||||
| Date curr = new Date(); | |||||
| record.setId(orderNumber); | |||||
| record.setOrderNumber(orderNumber); | |||||
| record.setCUserId(user.getId()); | |||||
| record.setPaymentType(EnumPayType.PAY_PAYMENT.getCode()); | |||||
| record.setPayment(payment); | |||||
| record.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||||
| record.setCreateDate(curr); | record.setCreateDate(curr); | ||||
| record.setUpdateDate(curr); | record.setUpdateDate(curr); | ||||
| wxOrderMapper.insertSelective(record); | wxOrderMapper.insertSelective(record); | ||||
| // 返回 record | |||||
| return record; | |||||
| } catch (RuntimeException e) { | } catch (RuntimeException e) { | ||||
| logger.error("保存订单:" + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | ||||
| } | } | ||||
| try { | |||||
| WxCouponOrder couponOrder = new WxCouponOrder(); | |||||
| couponOrder.setId(idWorker.nextId()); | |||||
| couponOrder.setCouponId(couponId); | |||||
| couponOrder.setCUserId(user.getId()); | |||||
| couponOrder.setOrderId(orderNumber); | |||||
| couponOrder.setExpiredTime(valid_date); | |||||
| couponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); | |||||
| couponOrder.setCreateDate(curr); | |||||
| couponOrder.setUpdateDate(curr); | |||||
| couponOrder.setCouponPrice(payPrice); | |||||
| wxCouponOrderMapper.insertSelective(couponOrder); | |||||
| } catch (RuntimeException e) { | |||||
| logger.error("WxCouponOrder:" + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | |||||
| } | |||||
| return record; | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -109,7 +168,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND); | throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND); | ||||
| } | } | ||||
| Date currentDate = new Date(); | Date currentDate = new Date(); | ||||
| /* | |||||
| // 0:待付款 | // 0:待付款 | ||||
| // 1:已支付 | // 1:已支付 | ||||
| if (enumOrderStatus == EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS) { | if (enumOrderStatus == EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS) { | ||||
| @@ -139,6 +198,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| // 5:退款失败 | // 5:退款失败 | ||||
| updateRecord.setStatus(enumOrderStatus.getCode()); | updateRecord.setStatus(enumOrderStatus.getCode()); | ||||
| updateRecord.setUpdateDate(currentDate); | updateRecord.setUpdateDate(currentDate); | ||||
| */ | |||||
| return wxOrderMapper.updateByPrimaryKey(updateRecord); | return wxOrderMapper.updateByPrimaryKey(updateRecord); | ||||
| } | } | ||||
| @@ -78,7 +78,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| logger.warn("pay order, order not allow, repaymentReq: " + record.toString() +", payWay: " + payWay.toString()); | logger.warn("pay order, order not allow, repaymentReq: " + record.toString() +", payWay: " + payWay.toString()); | ||||
| throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND); | throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND); | ||||
| } | } | ||||
| if (order.getStatus() != EnumOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()) { | |||||
| if (order.getOrderStatus() != EnumOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()) { | |||||
| logger.warn("pay order, order status not allow, repaymentReq: " + order.toString() + " , payWay: " + payWay.toString()); | logger.warn("pay order, order status not allow, repaymentReq: " + order.toString() + " , payWay: " + payWay.toString()); | ||||
| throw new MallinkException(ErrorCode.ORDER_IS_NOT_PAY); | throw new MallinkException(ErrorCode.ORDER_IS_NOT_PAY); | ||||
| } | } | ||||
| @@ -97,8 +97,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| record.setPayTimeEnd(currentTime); | record.setPayTimeEnd(currentTime); | ||||
| // 支付单号 | // 支付单号 | ||||
| record.setPayOrderNo(String.valueOf(id)); | record.setPayOrderNo(String.valueOf(id)); | ||||
| BigDecimal pl = order.getPayment().multiply(new BigDecimal(100)); | |||||
| record.setPayAmount(pl.intValue()); | |||||
| record.setPayAmount(order.getPayment()); | |||||
| record.setPayVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | record.setPayVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | ||||
| record.setPayOrderStatus(EnumPayStatus.PAY_WAY_WAIT.getCode()); | record.setPayOrderStatus(EnumPayStatus.PAY_WAY_WAIT.getCode()); | ||||
| @@ -270,7 +269,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| updatePayOrder.setPayOrderStatus(EnumPayStatus.PAY_WAY_SUCCESS.getCode()); | updatePayOrder.setPayOrderStatus(EnumPayStatus.PAY_WAY_SUCCESS.getCode()); | ||||
| updatePayOrder.setTransactionId(transactionId); | updatePayOrder.setTransactionId(transactionId); | ||||
| wxPayOrderMapper.updateByPrimaryKeySelective(updatePayOrder); | wxPayOrderMapper.updateByPrimaryKeySelective(updatePayOrder); | ||||
| /* | |||||
| Map<String, String> msgMap = new HashMap<>(); | Map<String, String> msgMap = new HashMap<>(); | ||||
| try { | try { | ||||
| msgMap.put("name", String.valueOf(order.getCouponId())); | msgMap.put("name", String.valueOf(order.getCouponId())); | ||||
| @@ -282,6 +281,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("pay success handle, sms send exception, payOrderi: " + updatePayOrder+ ", msgMap: " + msgMap.toString() + ", e: " + e.getMessage()); | logger.error("pay success handle, sms send exception, payOrderi: " + updatePayOrder+ ", msgMap: " + msgMap.toString() + ", e: " + e.getMessage()); | ||||
| } | } | ||||
| */ | |||||
| } | } | ||||
| @@ -37,6 +37,7 @@ public class WxUserCouponServiceImpl implements WxUserCouponService { | |||||
| //查询订单表 | //查询订单表 | ||||
| WxOrder wxOrder = new WxOrder(); | WxOrder wxOrder = new WxOrder(); | ||||
| wxOrder.setCUserId(userId); | wxOrder.setCUserId(userId); | ||||
| /* | |||||
| wxOrder.setCouponStatus(status); | wxOrder.setCouponStatus(status); | ||||
| List<WxOrder> orders = wxOrderService.findList(wxOrder); | List<WxOrder> orders = wxOrderService.findList(wxOrder); | ||||
| List<String> ids = orders.stream().map(p->p.getCouponId()+"").distinct().collect(Collectors.toList()); | List<String> ids = orders.stream().map(p->p.getCouponId()+"").distinct().collect(Collectors.toList()); | ||||
| @@ -50,15 +51,18 @@ public class WxUserCouponServiceImpl implements WxUserCouponService { | |||||
| wxUserCoupons.add(getWxUserCoupon(temp,couponNamesMap.get(temp.getCouponId()))); | wxUserCoupons.add(getWxUserCoupon(temp,couponNamesMap.get(temp.getCouponId()))); | ||||
| } | } | ||||
| } | } | ||||
| */ | |||||
| return wxUserCoupons; | return wxUserCoupons; | ||||
| } | } | ||||
| public WxUserCouponDto getWxUserCoupon(WxOrder wxOrder, String title){ | public WxUserCouponDto getWxUserCoupon(WxOrder wxOrder, String title){ | ||||
| WxUserCouponDto wxUserCoupon = new WxUserCouponDto(); | WxUserCouponDto wxUserCoupon = new WxUserCouponDto(); | ||||
| wxUserCoupon.setOrderId(wxOrder.getId()); | wxUserCoupon.setOrderId(wxOrder.getId()); | ||||
| wxUserCoupon.setcUserId(wxOrder.getCUserId()); | wxUserCoupon.setcUserId(wxOrder.getCUserId()); | ||||
| /* | |||||
| wxUserCoupon.setCouponId(wxOrder.getCouponId()); | wxUserCoupon.setCouponId(wxOrder.getCouponId()); | ||||
| wxUserCoupon.setCouponStatus(wxOrder.getCouponStatus()); | wxUserCoupon.setCouponStatus(wxOrder.getCouponStatus()); | ||||
| wxUserCoupon.setValidDate(wxOrder.getValidDate()); | wxUserCoupon.setValidDate(wxOrder.getValidDate()); | ||||
| */ | |||||
| wxUserCoupon.setCouponTitle(title); | wxUserCoupon.setCouponTitle(title); | ||||
| return wxUserCoupon; | return wxUserCoupon; | ||||
| } | } | ||||
| @@ -4,18 +4,19 @@ | |||||
| <resultMap id="BaseResultMap" type="com.simple.domain.po.WxAppinfo"> | <resultMap id="BaseResultMap" type="com.simple.domain.po.WxAppinfo"> | ||||
| <id column="id" jdbcType="BIGINT" property="id" /> | <id column="id" jdbcType="BIGINT" property="id" /> | ||||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | ||||
| <result column="appid" jdbcType="VARCHAR" property="appid" /> | |||||
| <result column="secret" jdbcType="VARCHAR" property="secret" /> | |||||
| <result column="app_id" jdbcType="VARCHAR" property="appId" /> | |||||
| <result column="name" jdbcType="VARCHAR" property="name" /> | <result column="name" jdbcType="VARCHAR" property="name" /> | ||||
| <result column="secret" jdbcType="VARCHAR" property="secret" /> | |||||
| <result column="token" jdbcType="VARCHAR" property="token" /> | <result column="token" jdbcType="VARCHAR" property="token" /> | ||||
| <result column="aeskey" jdbcType="VARCHAR" property="aeskey" /> | |||||
| <result column="aes_key" jdbcType="VARCHAR" property="aesKey" /> | |||||
| <result column="msg_data_format" jdbcType="VARCHAR" property="msgDataFormat" /> | |||||
| <result column="access_token" jdbcType="VARCHAR" property="accessToken" /> | <result column="access_token" jdbcType="VARCHAR" property="accessToken" /> | ||||
| <result column="last_token_time" jdbcType="TIMESTAMP" property="lastTokenTime" /> | <result column="last_token_time" jdbcType="TIMESTAMP" property="lastTokenTime" /> | ||||
| <result column="expires_in" jdbcType="INTEGER" property="expiresIn" /> | <result column="expires_in" jdbcType="INTEGER" property="expiresIn" /> | ||||
| </resultMap> | </resultMap> | ||||
| <sql id="allColumns"> | <sql id="allColumns"> | ||||
| `id`,`tenant_id`,`appid`,`secret`,`name`,`token`,`aeskey`,`access_token`,`last_token_time`,`expires_in` | |||||
| `id`,`tenant_id`,`app_id`,`name`,`secret`,`token`,`aes_key`,`msg_data_format`,`access_token`,`last_token_time`,`expires_in` | |||||
| </sql> | </sql> | ||||
| <sql id="dynamicWhereConditions"> | <sql id="dynamicWhereConditions"> | ||||
| @@ -31,18 +32,18 @@ | |||||
| </if> | </if> | ||||
| <if test=" null != appid "> | |||||
| and `appid` like concat('%', #{appid},'%') | |||||
| <if test=" null != appId "> | |||||
| and `app_id` like concat('%', #{appId},'%') | |||||
| </if> | </if> | ||||
| <if test=" null != secret "> | |||||
| and `secret` like concat('%', #{secret},'%') | |||||
| <if test=" null != name "> | |||||
| and `name` like concat('%', #{name},'%') | |||||
| </if> | </if> | ||||
| <if test=" null != name "> | |||||
| and `name` like concat('%', #{name},'%') | |||||
| <if test=" null != secret "> | |||||
| and `secret` like concat('%', #{secret},'%') | |||||
| </if> | </if> | ||||
| @@ -51,8 +52,13 @@ | |||||
| </if> | </if> | ||||
| <if test=" null != aeskey "> | |||||
| and `aeskey` like concat('%', #{aeskey},'%') | |||||
| <if test=" null != aesKey "> | |||||
| and `aes_key` like concat('%', #{aesKey},'%') | |||||
| </if> | |||||
| <if test=" null != msgDataFormat "> | |||||
| and `msg_data_format` like concat('%', #{msgDataFormat},'%') | |||||
| </if> | </if> | ||||
| @@ -83,8 +89,14 @@ | |||||
| select <include refid="allColumns" /> from wx_appinfo | select <include refid="allColumns" /> from wx_appinfo | ||||
| <include refid="dynamicWhereConditions" /> | <include refid="dynamicWhereConditions" /> | ||||
| </select> | </select> | ||||
| <select id="findByAppId" parameterType="java.lang.String" resultMap="BaseResultMap"> | |||||
| SELECT * | |||||
| FROM wx_appinfo | |||||
| WHERE `app_id` = #{appId} | |||||
| </select> | |||||
| @@ -24,10 +24,13 @@ | |||||
| <result column="score" jdbcType="INTEGER" property="score" /> | <result column="score" jdbcType="INTEGER" property="score" /> | ||||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" /> | <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" /> | ||||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | <result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | ||||
| <result column="app_id" jdbcType="VARCHAR" property="appId" /> | |||||
| <result column="token" jdbcType="VARCHAR" property="token" /> | |||||
| <result column="expire_time" jdbcType="TIMESTAMP" property="expireTime" /> | |||||
| </resultMap> | </resultMap> | ||||
| <sql id="allColumns"> | <sql id="allColumns"> | ||||
| `id`,`tenant_id`,`open_id`,`union_id`,`nick_name`,`gender`,`avatar_url`,`phone`,`pure_phone`,`city`,`province`,`language`,`country_code`,`register_ip`,`verify_code_phone`,`qrcode_source`,`scene`,`scene_address`,`session_key`,`score`,`update_date`,`create_date` | |||||
| `id`,`tenant_id`,`open_id`,`union_id`,`nick_name`,`gender`,`avatar_url`,`phone`,`pure_phone`,`city`,`province`,`language`,`country_code`,`register_ip`,`verify_code_phone`,`qrcode_source`,`scene`,`scene_address`,`session_key`,`score`,`update_date`,`create_date`,`app_id`,`token`,`expire_time` | |||||
| </sql> | </sql> | ||||
| <sql id="dynamicWhereConditions"> | <sql id="dynamicWhereConditions"> | ||||
| @@ -141,6 +144,21 @@ | |||||
| <if test=" null != createDate "> | <if test=" null != createDate "> | ||||
| and `create_date` = #{createDate} | and `create_date` = #{createDate} | ||||
| </if> | |||||
| <if test=" null != appId "> | |||||
| and `app_id` like concat('%', #{appId},'%') | |||||
| </if> | |||||
| <if test=" null != token "> | |||||
| and `token` like concat('%', #{token},'%') | |||||
| </if> | |||||
| <if test=" null != expireTime "> | |||||
| and `expire_time` = #{expireTime} | |||||
| </if> | </if> | ||||
| <if test=" null != ids "> | <if test=" null != ids "> | ||||
| and id in | and id in | ||||
| @@ -155,10 +173,14 @@ | |||||
| select <include refid="allColumns" /> from wx_c_user | select <include refid="allColumns" /> from wx_c_user | ||||
| <include refid="dynamicWhereConditions" /> | <include refid="dynamicWhereConditions" /> | ||||
| </select> | </select> | ||||
| <select id="findByOpenId" parameterType="com.simple.domain.po.WxCUser" resultMap="BaseResultMap"> | |||||
| select * from wx_c_user | |||||
| where `app_id` = #{appId} and `open_id` = #{openId} | |||||
| </select> | |||||
| <select id="findByToken" resultMap="BaseResultMap"> | |||||
| select * from wx_c_user | |||||
| where `token` = #{token} | |||||
| </select> | |||||
| </mapper> | </mapper> | ||||
| @@ -0,0 +1,98 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
| <mapper namespace="com.simple.mapper.WxCouponOrderMapper"> | |||||
| <resultMap id="BaseResultMap" type="com.simple.domain.po.WxCouponOrder"> | |||||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||||
| <result column="tenant_id" jdbcType="BIGINT" property="tenantId" /> | |||||
| <result column="coupon_id" jdbcType="BIGINT" property="couponId" /> | |||||
| <result column="c_user_id" jdbcType="BIGINT" property="cUserId" /> | |||||
| <result column="b_user_id" jdbcType="BIGINT" property="bUserId" /> | |||||
| <result column="order_id" jdbcType="BIGINT" property="orderId" /> | |||||
| <result column="expired_time" jdbcType="TIMESTAMP" property="expiredTime" /> | |||||
| <result column="coupon_order_status" jdbcType="INTEGER" property="couponOrderStatus" /> | |||||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | |||||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" /> | |||||
| <result column="coupon_price" jdbcType="DECIMAL" property="couponPrice" /> | |||||
| </resultMap> | |||||
| <sql id="allColumns"> | |||||
| `id`,`tenant_id`,`coupon_id`,`c_user_id`,`b_user_id`,`order_id`,`expired_time`,`coupon_order_status`,`create_date`,`update_date`,`coupon_price` | |||||
| </sql> | |||||
| <sql id="dynamicWhereConditions"> | |||||
| where 1 = 1 | |||||
| <if test=" null != id "> | |||||
| and `id` = #{id} | |||||
| </if> | |||||
| <if test=" null != tenantId "> | |||||
| and `tenant_id` = #{tenantId} | |||||
| </if> | |||||
| <if test=" null != couponId "> | |||||
| and `coupon_id` = #{couponId} | |||||
| </if> | |||||
| <if test=" null != cUserId "> | |||||
| and `c_user_id` = #{cUserId} | |||||
| </if> | |||||
| <if test=" null != bUserId "> | |||||
| and `b_user_id` = #{bUserId} | |||||
| </if> | |||||
| <if test=" null != orderId "> | |||||
| and `order_id` = #{orderId} | |||||
| </if> | |||||
| <if test=" null != expiredTime "> | |||||
| and `expired_time` = #{expiredTime} | |||||
| </if> | |||||
| <if test=" null != couponOrderStatus "> | |||||
| and `coupon_order_status` = #{couponOrderStatus} | |||||
| </if> | |||||
| <if test=" null != createDate "> | |||||
| and `create_date` = #{createDate} | |||||
| </if> | |||||
| <if test=" null != updateDate "> | |||||
| and `update_date` = #{updateDate} | |||||
| </if> | |||||
| <if test=" null != couponPrice "> | |||||
| and `coupon_price` = #{couponPrice} | |||||
| </if> | |||||
| <if test=" null != ids "> | |||||
| and id in | |||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||||
| #{idItem} | |||||
| </foreach> | |||||
| </if> | |||||
| <if test=" null != sortColumns"> order by ${sortColumns} </if> | |||||
| </sql> | |||||
| <select id="findList" parameterType="com.simple.domain.po.WxCouponOrder" resultMap="BaseResultMap"> | |||||
| select <include refid="allColumns" /> from wx_coupon_order | |||||
| <include refid="dynamicWhereConditions" /> | |||||
| </select> | |||||
| </mapper> | |||||
| @@ -3,22 +3,20 @@ | |||||
| <mapper namespace="com.simple.mapper.WxOrderMapper"> | <mapper namespace="com.simple.mapper.WxOrderMapper"> | ||||
| <resultMap id="BaseResultMap" type="com.simple.domain.po.WxOrder"> | <resultMap id="BaseResultMap" type="com.simple.domain.po.WxOrder"> | ||||
| <id column="id" jdbcType="BIGINT" property="id" /> | <id column="id" jdbcType="BIGINT" property="id" /> | ||||
| <result column="order_number" jdbcType="BIGINT" property="orderNumber" /> | |||||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | ||||
| <result column="coupon_id" jdbcType="BIGINT" property="couponId" /> | |||||
| <result column="c_user_id" jdbcType="BIGINT" property="cUserId" /> | <result column="c_user_id" jdbcType="BIGINT" property="cUserId" /> | ||||
| <result column="payment" jdbcType="DECIMAL" property="payment" /> | |||||
| <result column="b_user_id" jdbcType="BIGINT" property="bUserId" /> | |||||
| <result column="payment_type" jdbcType="INTEGER" property="paymentType" /> | |||||
| <result column="payment" jdbcType="INTEGER" property="payment" /> | |||||
| <result column="payment_time" jdbcType="TIMESTAMP" property="paymentTime" /> | <result column="payment_time" jdbcType="TIMESTAMP" property="paymentTime" /> | ||||
| <result column="status" jdbcType="INTEGER" property="status" /> | |||||
| <result column="coupon_status" jdbcType="INTEGER" property="couponStatus" /> | |||||
| <result column="valid_date" jdbcType="TIMESTAMP" property="validDate" /> | |||||
| <result column="refund" jdbcType="INTEGER" property="refund" /> | |||||
| <result column="refund_time" jdbcType="TIMESTAMP" property="refundTime" /> | |||||
| <result column="order_status" jdbcType="INTEGER" property="orderStatus" /> | |||||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | <result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | ||||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" /> | <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" /> | ||||
| </resultMap> | </resultMap> | ||||
| <sql id="allColumns"> | <sql id="allColumns"> | ||||
| `id`,`tenant_id`,`coupon_id`,`c_user_id`,`payment`,`payment_time`,`status`,`coupon_status`,`valid_date`,`refund`,`refund_time`,`create_date`,`update_date` | |||||
| `id`,`order_number`,`tenant_id`,`c_user_id`,`b_user_id`,`payment_type`,`payment`,`payment_time`,`order_status`,`create_date`,`update_date` | |||||
| </sql> | </sql> | ||||
| <sql id="dynamicWhereConditions"> | <sql id="dynamicWhereConditions"> | ||||
| @@ -29,13 +27,13 @@ | |||||
| </if> | </if> | ||||
| <if test=" null != tenantId "> | |||||
| and `tenant_id` like concat('%', #{tenantId},'%') | |||||
| <if test=" null != orderNumber "> | |||||
| and `order_number` = #{orderNumber} | |||||
| </if> | </if> | ||||
| <if test=" null != couponId "> | |||||
| and `coupon_id` = #{couponId} | |||||
| <if test=" null != tenantId "> | |||||
| and `tenant_id` like concat('%', #{tenantId},'%') | |||||
| </if> | </if> | ||||
| @@ -44,38 +42,28 @@ | |||||
| </if> | </if> | ||||
| <if test=" null != payment "> | |||||
| and `payment` = #{payment} | |||||
| </if> | |||||
| <if test=" null != paymentTime "> | |||||
| and `payment_time` = #{paymentTime} | |||||
| </if> | |||||
| <if test=" null != status "> | |||||
| and `status` = #{status} | |||||
| <if test=" null != bUserId "> | |||||
| and `b_user_id` = #{bUserId} | |||||
| </if> | </if> | ||||
| <if test=" null != couponStatus "> | |||||
| and `coupon_status` = #{couponStatus} | |||||
| <if test=" null != paymentType "> | |||||
| and `payment_type` = #{paymentType} | |||||
| </if> | </if> | ||||
| <if test=" null != validDate "> | |||||
| and `valid_date` = #{validDate} | |||||
| <if test=" null != payment "> | |||||
| and `payment` = #{payment} | |||||
| </if> | </if> | ||||
| <if test=" null != refund "> | |||||
| and `refund` = #{refund} | |||||
| <if test=" null != paymentTime "> | |||||
| and `payment_time` = #{paymentTime} | |||||
| </if> | </if> | ||||
| <if test=" null != refundTime "> | |||||
| and `refund_time` = #{refundTime} | |||||
| <if test=" null != orderStatus "> | |||||
| and `order_status` = #{orderStatus} | |||||
| </if> | </if> | ||||