parent
04a8004074
commit
f2f28b402f
@ -0,0 +1,73 @@ |
||||
package com.cweb.controller; |
||||
|
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.security.UserCenter; |
||||
import com.hfkj.common.utils.HttpsUtils; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.BsMerchantUser; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.model.UserSessionObject; |
||||
import com.hfkj.service.BsMerchantUserService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestMethod; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @className: BsMerchantUserController |
||||
* @author: HuRui |
||||
* @date: 2024/6/11 |
||||
**/ |
||||
@Controller |
||||
@RequestMapping(value = "/merchantUser") |
||||
@Api(value = "登录业务") |
||||
public class BsMerchantUserController { |
||||
private static Logger log = LoggerFactory.getLogger(BsMerchantUserController.class); |
||||
@Resource |
||||
private BsMerchantUserService merchantUserService; |
||||
|
||||
@Resource |
||||
private UserCenter userCenter; |
||||
@RequestMapping(value = "/getUser", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询商户用户") |
||||
public ResponseData getUser(@RequestParam(value = "merNo", required = true) String merNo) { |
||||
try { |
||||
UserSessionObject sessionObject = userCenter.getSessionModel(UserSessionObject.class); |
||||
if (sessionObject == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_LOGIN_NOT, ""); |
||||
} |
||||
Map<String,Object> map = new HashMap<>(); |
||||
|
||||
// 商户会员
|
||||
BsMerchantUser user = merchantUserService.getUser(merNo, sessionObject.getUser().getPhone()); |
||||
if (user != null) { |
||||
map.put("vipLevel", user.getVipLevel()); |
||||
map.put("integral", user.getIntegral()); |
||||
map.put("discount", new ArrayList<>()); |
||||
} else { |
||||
map.put("vipLevel", null); |
||||
map.put("integral", 0); |
||||
map.put("discount", new ArrayList<>()); |
||||
} |
||||
return ResponseMsgUtil.success(map); |
||||
|
||||
} catch (Exception e) { |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,161 @@ |
||||
package com.cweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.security.UserCenter; |
||||
import com.hfkj.common.utils.HttpsUtils; |
||||
import com.hfkj.common.utils.MemberValidateUtil; |
||||
import com.hfkj.common.utils.RedisUtil; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.model.SecUserSessionObject; |
||||
import com.hfkj.model.UserSessionObject; |
||||
import com.hfkj.service.user.BsUserService; |
||||
import com.hfkj.sysenum.user.UserLoginPlatform; |
||||
import com.hfkj.sysenum.user.UserLoginType; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @className: BsUserController |
||||
* @author: HuRui |
||||
* @date: 2024/6/11 |
||||
**/ |
||||
@Controller |
||||
@RequestMapping(value = "/user") |
||||
@Api(value = "登录业务") |
||||
public class BsUserController { |
||||
private static Logger log = LoggerFactory.getLogger(BsUserController.class); |
||||
@Resource |
||||
private RedisUtil redisUtil; |
||||
@Resource |
||||
private UserCenter userCenter; |
||||
@Resource |
||||
private BsUserService userService; |
||||
|
||||
@RequestMapping(value = "/login", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "登录并注册") |
||||
public ResponseData login(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null |
||||
|| StringUtils.isBlank(body.getString("platform")) |
||||
|| StringUtils.isBlank(body.getString("type")) |
||||
|| StringUtils.isBlank(body.getString("phone")) |
||||
) { |
||||
log.error("LoginController --> phone() error!", "请求参数校验失败"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
String phone = body.getString("phone"); |
||||
|
||||
// 客户端
|
||||
UserLoginPlatform platform = UserLoginPlatform.getDataByType(body.getString("platform")); |
||||
if (platform == null) { |
||||
log.error("LoginController --> phone() error!", "未知客户端"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知客户端"); |
||||
} |
||||
// 校验手机号格式
|
||||
if (!MemberValidateUtil.validatePhone(phone)) { |
||||
log.error("LoginController --> phone() error!", "请输入正确的手机号"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入正确的手机号"); |
||||
} |
||||
// 登录类型
|
||||
UserLoginType loginType = UserLoginType.getDataByType(body.getString("type")); |
||||
if (loginType == null) { |
||||
log.error("LoginController --> phone() error!", "未知登录类型;" + body.getString("type")); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知登录类型"); |
||||
} |
||||
|
||||
// 账户密码登录
|
||||
if (body.getString("type").equals(UserLoginType.SMS.getCode())) { |
||||
if (StringUtils.isBlank(body.getString("smsCode"))) { |
||||
log.error("LoginController --> phone() error!", "请输入短信验证码"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入短信验证码"); |
||||
} |
||||
// 手机号的验证码
|
||||
Object phoneCodeObject = redisUtil.get("SMS_CODE:" + phone); |
||||
if (phoneCodeObject == null) { |
||||
log.error("LoginController --> phone() error!", "短信验证码错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "短信验证码错误"); |
||||
} |
||||
if (!body.getString("smsCode").equals(phoneCodeObject.toString())) { |
||||
log.error("LoginController --> phone() error!", "短信验证码错误"); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "短信验证码错误"); |
||||
} |
||||
redisUtil.del("SMS_CODE:" + phone); |
||||
|
||||
Map<String, Object> other = new HashMap<>(); |
||||
other.put("wxMpOpenId", body.getString("wxMpOpenId")); |
||||
other.put("wxMaOpenId", body.getString("wxMaOpenId")); |
||||
return ResponseMsgUtil.success(userService.login(platform, loginType, phone, other)); |
||||
} |
||||
|
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "登录失败"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("LoginController --> phone() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/queryUser", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询用户信息") |
||||
public ResponseData queryUser() { |
||||
try { |
||||
|
||||
return ResponseMsgUtil.success(userCenter.getSessionModel(UserSessionObject.class)); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("LoginController --> wechatMaPhone() error!", e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/loginOut",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "退出登录") |
||||
public ResponseData loginOut(HttpServletRequest request) { |
||||
try { |
||||
SecUserSessionObject session = userCenter.getSessionModel(SecUserSessionObject.class); |
||||
if (session != null) { |
||||
userCenter.remove(request); |
||||
} |
||||
return ResponseMsgUtil.success("退出成功"); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/getH5AccessToken", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "【H5】获取AccessToken") |
||||
public ResponseData getH5AccessToken(@RequestParam(value = "code", required = true) String code) { |
||||
try { |
||||
Map<String, Object> params = new HashMap<>(); |
||||
params.put("appid", "wxa075e8509802f826"); |
||||
params.put("secret", "0e606fc1378d35e359fcf3f15570b2c5"); |
||||
params.put("code", code); |
||||
params.put("grant_type", "authorization_code"); |
||||
return ResponseMsgUtil.success(HttpsUtils.doGet("https://api.weixin.qq.com/sns/oauth2/access_token", params)); |
||||
|
||||
} catch (Exception e) { |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1 @@ |
||||
package com.cweb.controller;
import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.utils.MemberValidateUtil;
import com.hfkj.common.utils.RedisUtil;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.config.MessageConfig;
import com.hfkj.model.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.Random;
/**
* @Auther: 胡锐
* @Description:
* @Date: 2021/3/26 23:08
*/
@Controller
@RequestMapping(value = "/sms")
@Api(value = "短信服务")
public class SmsController {
private static Logger log = LoggerFactory.getLogger(SmsController.class);
@Resource
private RedisUtil redisUtil;
@RequestMapping(value = "/sendLoginSMSCode", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "获取登录验证码")
public ResponseData sendLoginSMSCode(@RequestBody JSONObject body) {
try {
if (body == null || StringUtils.isBlank(body.getString("phone"))) {
log.error("LoginController --> phone() error!", "请求参数校验失败");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
String phone = body.getString("phone");
// 校验手机号格式
if (MemberValidateUtil.validatePhone(phone) == false) {
log.error("LoginController --> phone() error!", "请输入正确的手机号");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入正确的手机号");
}
// 生成随机6位验证码
String smsCode = String.valueOf(new Random().nextInt(899999) + 100000);
MessageConfig.req(phone,smsCode, MessageConfig.HWMSG_ID5);
// 验证码缓存5分钟
redisUtil.set("SMS_CODE:"+phone, smsCode, 60*5);
return ResponseMsgUtil.success("短信发送成功");
} catch (Exception e) {
log.error("SMSController --> getLoginSMSCode() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/sendBindCardSMSCode", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "获取绑定卡片验证码")
public ResponseData sendBindCardSMSCode(@RequestBody JSONObject body) {
try {
if (body == null || StringUtils.isBlank(body.getString("phone"))) {
log.error("LoginController --> phone() error!", "请求参数校验失败");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
String phone = body.getString("phone");
// 校验手机号格式
if (MemberValidateUtil.validatePhone(phone) == false) {
log.error("LoginController --> phone() error!", "请输入正确的手机号");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请输入正确的手机号");
}
// 生成随机6位验证码
String smsCode = String.valueOf(new Random().nextInt(899999) + 100000);
MessageConfig.req(phone,smsCode, MessageConfig.HWMSG_ID7);
// 验证码缓存5分钟
redisUtil.set("SMS_CODE:"+phone, smsCode, 60*5);
return ResponseMsgUtil.success("短信发送成功");
} catch (Exception e) {
log.error("SMSController --> getLoginSMSCode() error!", e);
return ResponseMsgUtil.exception(e);
}
}
}
|
@ -0,0 +1,121 @@ |
||||
package com.cweb.controller.order; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.security.UserCenter; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.BsMerchantPayConfig; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.model.UserSessionObject; |
||||
import com.hfkj.model.order.OrderChildModel; |
||||
import com.hfkj.model.order.OrderModel; |
||||
import com.hfkj.pay.HuiPayService; |
||||
import com.hfkj.service.BsMerchantPayConfigService; |
||||
import com.hfkj.service.order.BsOrderChildService; |
||||
import com.hfkj.service.order.BsOrderService; |
||||
import com.hfkj.sysenum.order.OrderPayTypeEnum; |
||||
import com.hfkj.sysenum.order.OrderStatusEnum; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestMethod; |
||||
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @className: OrderController |
||||
* @author: HuRui |
||||
* @date: 2024/4/30 |
||||
**/ |
||||
@Controller |
||||
@RequestMapping(value="/pay") |
||||
@Api(value="支付业务") |
||||
public class OrderPayController { |
||||
|
||||
Logger log = LoggerFactory.getLogger(OrderPayController.class); |
||||
@Resource |
||||
private BsOrderService orderService; |
||||
@Resource |
||||
private BsMerchantPayConfigService merPayConfigService; |
||||
|
||||
@RequestMapping(value="/wechat",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "微信") |
||||
public ResponseData wechat(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null |
||||
|| StringUtils.isBlank(body.getString("orderNo")) |
||||
|| StringUtils.isBlank(body.getString("openId")) |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
// 查询订单
|
||||
OrderModel order = orderService.getDetail(body.getString("orderNo")); |
||||
if (order == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的订单号"); |
||||
} |
||||
if (!order.getOrderStatus().equals(OrderStatusEnum.status1.getCode())) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "交易订单不处于待支付"); |
||||
} |
||||
String merNo = order.getOrderChildList().get(0).getMerNo(); |
||||
// 查询平台
|
||||
BsMerchantPayConfig merPay = merPayConfigService.getConfig(merNo); |
||||
if (merPay == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "商户未配置支付"); |
||||
} |
||||
// 请求支付渠道
|
||||
Map<Object, Object> preorder = HuiPayService.preorder(merPay.getChannelMerNo(), merPay.getChannelMerKey(), body.getString("userId"), order); |
||||
|
||||
return ResponseMsgUtil.success(preorder); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value="/alipay",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "支付宝") |
||||
public ResponseData alipay(@RequestBody JSONObject body) { |
||||
try { |
||||
if (body == null |
||||
|| StringUtils.isBlank(body.getString("orderNo")) |
||||
|| StringUtils.isBlank(body.getString("userId")) |
||||
) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); |
||||
} |
||||
// 查询订单
|
||||
OrderModel order = orderService.getDetail(body.getString("orderNo")); |
||||
if (order == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的订单号"); |
||||
} |
||||
if (order.getOrderStatus().equals(OrderStatusEnum.status2.getCode())) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "交易订单不处于待支付"); |
||||
} |
||||
String merNo = order.getOrderChildList().get(0).getMerNo(); |
||||
// 查询平台
|
||||
BsMerchantPayConfig merPay = merPayConfigService.getConfig(merNo); |
||||
if (merPay == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "商户未配置支付"); |
||||
} |
||||
// 请求支付渠道
|
||||
Map<Object, Object> preorder = HuiPayService.preorder(merPay.getChannelMerNo(), merPay.getChannelMerKey(), body.getString("userId"), order); |
||||
|
||||
return ResponseMsgUtil.success(preorder); |
||||
} catch (Exception e) { |
||||
log.error("error!",e); |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,85 @@ |
||||
package com.cweb.controller.order; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.model.order.OrderModel; |
||||
import com.hfkj.service.order.BsOrderService; |
||||
import com.hfkj.sysenum.order.OrderPayChannelEnum; |
||||
import com.hfkj.sysenum.order.OrderPayTypeEnum; |
||||
import com.hfkj.sysenum.order.OrderStatusEnum; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestMethod; |
||||
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.PrintWriter; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* @className: OrderPayNotifyController |
||||
* @author: HuRui |
||||
* @date: 2024/5/7 |
||||
**/ |
||||
@Controller |
||||
@RequestMapping(value="/notify") |
||||
@Api(value="通知业务") |
||||
public class OrderPayNotifyController { |
||||
Logger log = LoggerFactory.getLogger(OrderPayNotifyController.class); |
||||
@Resource |
||||
private BsOrderService orderService; |
||||
|
||||
@RequestMapping(value="/huipay",method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "【惠支付】主扫通知") |
||||
public void huipay(@RequestBody String body, HttpServletResponse response) { |
||||
try { |
||||
log.info("===============惠支付回调start=================="); |
||||
JSONObject dataObject = JSONObject.parseObject(body); |
||||
// 处理业务
|
||||
log.info("开始处理业务"); |
||||
log.info("惠支付-回调参数: " + dataObject); |
||||
|
||||
// 查询交易订单
|
||||
OrderModel order = orderService.getDetail(dataObject.getString("outTradeNo")); |
||||
if (order != null && order.getOrderStatus().equals(OrderStatusEnum.status1.getCode())) { |
||||
// 支付方式 微信:WECHAT 支付宝:ALIPAY 银联:UQRCODEPAY
|
||||
String payMode = dataObject.getString("payMode"); |
||||
if ("WECHAT".equals(payMode)) { |
||||
order.setPayType(OrderPayTypeEnum.type1.getCode()); |
||||
|
||||
} else if ("ALIPAY".equals(payMode)) { |
||||
order.setPayType(OrderPayTypeEnum.type2.getCode()); |
||||
} |
||||
order.setPayChannel(OrderPayChannelEnum.type1.getCode()); |
||||
order.setPayTime(new Date(dataObject.getLong("payTime"))); |
||||
order.setPaySerialNo(dataObject.getString("accTradeNo")); |
||||
orderService.orderPaySuccessHandle(order); |
||||
} |
||||
log.info("处理业务完成"); |
||||
log.info("============回调任务End============="); |
||||
|
||||
response.setCharacterEncoding("UTF-8"); |
||||
response.setContentType("text/html;charset=utf-8"); |
||||
PrintWriter writer= response.getWriter(); |
||||
|
||||
JSONObject postJson = new JSONObject(); |
||||
postJson.put("code" ,"SUCCESS"); |
||||
postJson.put("message" ,"执行成功"); |
||||
writer.write(postJson.toJSONString()); |
||||
writer.flush(); |
||||
writer.close(); |
||||
|
||||
} catch (Exception e) { |
||||
log.error("订单处理异常", e); |
||||
} finally { |
||||
log.info("===============微信支付回调end=================="); |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,79 +0,0 @@ |
||||
package com.cweb.controller.pay; |
||||
|
||||
import com.hfkj.common.pay.WechatPayUtil; |
||||
import com.hfkj.common.pay.util.IOUtil; |
||||
import com.hfkj.common.pay.util.XmlUtil; |
||||
import com.hfkj.common.pay.util.sdk.WXPayConstants; |
||||
import com.hfkj.service.pay.NotifyService; |
||||
import com.hfkj.service.pay.PayRecordService; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestMethod; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.BufferedOutputStream; |
||||
import java.util.*; |
||||
|
||||
@Controller |
||||
@RequestMapping(value = "/wechatpay") |
||||
@Api(value = "微信支付") |
||||
public class WechatPayController { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(WechatPayController.class); |
||||
|
||||
private WXPayConstants.SignType signType; |
||||
|
||||
@Resource |
||||
private NotifyService notifyService; |
||||
|
||||
@Resource |
||||
private PayRecordService payRecordService; |
||||
|
||||
@Resource |
||||
private WechatPayUtil wechatPayUtil; |
||||
|
||||
|
||||
@RequestMapping(value = "/notify", method = RequestMethod.POST) |
||||
@ApiOperation(value = "微信支付 -> 异步回调") |
||||
public void wechatNotify(HttpServletRequest request, HttpServletResponse response) { |
||||
try { |
||||
log.info("微信支付 -> 异步通知:处理开始"); |
||||
|
||||
String resXml = ""; // 反馈给微信服务器
|
||||
String notifyXml = null; // 微信支付系统发送的数据(<![CDATA[product_001]]>格式)
|
||||
notifyXml = IOUtil.inputStreamToString(request.getInputStream(), "UTF-8"); |
||||
|
||||
log.info("微信支付系统发送的数据:" + notifyXml); |
||||
SortedMap<String, String> map = XmlUtil.parseXmlToTreeMap(notifyXml, "UTF-8"); |
||||
|
||||
resXml = notifyService.wechatNotify(map); |
||||
|
||||
/* if (SignatureUtil.reCheckIsSignValidFromWeiXin(notifyXml, SysConst.getSysConfig().getWxApiKey(), "UTF-8")) { |
||||
log.info("微信支付系统发送的数据:" + notifyXml); |
||||
SortedMap<String, String> map = XmlUtil.parseXmlToTreeMap(notifyXml, "UTF-8"); |
||||
|
||||
resXml = notifyService.wechatNotify(map); |
||||
} else { |
||||
log.error("微信支付 -> 异步通知:验签失败"); |
||||
log.error("apiKey:" + SysConst.getSysConfig().getWxApiKey()); |
||||
log.error("返回信息:" + notifyXml); |
||||
resXml = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>" |
||||
+ "<return_msg><![CDATA[签名验证错误]]></return_msg>" + "</xml> "; |
||||
}*/ |
||||
|
||||
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); |
||||
out.write(resXml.getBytes()); |
||||
out.flush(); |
||||
out.close(); |
||||
log.info("微信支付 -> 异步通知:处理完成"); |
||||
} catch (Exception e) { |
||||
log.error("WechatPayController --> wechatNotify() error!", e); |
||||
} |
||||
} |
||||
} |
@ -1,72 +0,0 @@ |
||||
package com.hfkj.common.pay; |
||||
|
||||
import com.hfkj.common.pay.entity.WeChatPayReqInfo; |
||||
import com.hfkj.common.pay.entity.WechatCallBackInfo; |
||||
import com.hfkj.common.pay.util.HttpReqUtil; |
||||
import com.hfkj.common.pay.util.SignatureUtil; |
||||
import com.hfkj.common.pay.util.XmlUtil; |
||||
import com.hfkj.service.pay.PayRecordService; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Component; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.Map; |
||||
import java.util.SortedMap; |
||||
import java.util.TreeMap; |
||||
|
||||
@Component |
||||
public class WechatPayUtil { |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(WechatPayUtil.class); |
||||
@Resource |
||||
private PayRecordService payRecordService; |
||||
|
||||
/** |
||||
* @throws |
||||
* @Title: goAlipay |
||||
* @Description: 微信支付请求体 |
||||
* @author: 魏真峰 |
||||
* @param: [orderId] |
||||
* @return: java.lang.String |
||||
*/ |
||||
@RequestMapping("/goWechatPay") |
||||
@ResponseBody |
||||
public SortedMap<Object,Object> goWechatPay(WeChatPayReqInfo weChatPayReqInfo, Map<String,String> map) throws Exception{ |
||||
log.info("微信支付 -> 组装支付参数:开始"); |
||||
|
||||
String sign = SignatureUtil.createSign(weChatPayReqInfo, map.get("api_key"), "UTF-8"); |
||||
weChatPayReqInfo.setSign(sign); |
||||
String unifiedXmL = XmlUtil.toSplitXml(weChatPayReqInfo); |
||||
|
||||
String unifiedOrderResultXmL = HttpReqUtil.HttpsDefaultExecute("POST", map.get("unified_order_url"), null, unifiedXmL, null); |
||||
// 签名校验
|
||||
SortedMap<Object,Object> sortedMap = null; |
||||
if (SignatureUtil.checkIsSignValidFromWeiXin(unifiedOrderResultXmL, map.get("api_key"), "UTF-8")) { |
||||
// 组装支付参数
|
||||
WechatCallBackInfo wechatCallBackInfo = XmlUtil.getObjectFromXML(unifiedOrderResultXmL, WechatCallBackInfo.class); |
||||
Long timeStamp = System.currentTimeMillis()/1000; |
||||
sortedMap = new TreeMap<>(); |
||||
sortedMap.put("appId",map.get("app_id")); |
||||
// sortedMap.put("partnerid",SysConst.getSysConfig().getMch_id());
|
||||
// sortedMap.put("prepayid",wechatCallBackInfo.getPrepay_id());
|
||||
sortedMap.put("nonceStr",wechatCallBackInfo.getNonce_str()); |
||||
sortedMap.put("timeStamp",timeStamp.toString()); |
||||
sortedMap.put("signType","MD5"); |
||||
sortedMap.put("package", "prepay_id=" + wechatCallBackInfo.getPrepay_id()); |
||||
String secondSign = SignatureUtil.createSign(sortedMap, map.get("api_key"), "UTF-8"); |
||||
sortedMap.put("sign",secondSign); |
||||
|
||||
|
||||
log.info("微信支付 -> 组装支付参数:完成"); |
||||
} else { |
||||
log.error("微信支付 -> 组装支付参数:支付信息错误"); |
||||
log.error("错误信息:" + unifiedOrderResultXmL); |
||||
} |
||||
|
||||
return sortedMap; |
||||
} |
||||
|
||||
} |
@ -1,358 +1,97 @@ |
||||
package com.hfkj.common.pay.util; |
||||
|
||||
import com.hfkj.common.pay.entity.WechatPayReturnParam; |
||||
import com.hfkj.common.pay.entity.WechatReturn; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.dom4j.DocumentException; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.xml.sax.SAXException; |
||||
|
||||
import javax.xml.parsers.ParserConfigurationException; |
||||
import java.io.IOException; |
||||
import java.io.UnsupportedEncodingException; |
||||
import java.lang.reflect.Field; |
||||
import javax.xml.bind.annotation.adapters.HexBinaryAdapter; |
||||
import java.security.MessageDigest; |
||||
import java.security.NoSuchAlgorithmException; |
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.Map; |
||||
import java.util.SortedMap; |
||||
import java.util.Set; |
||||
|
||||
/** |
||||
* |
||||
* @Title: |
||||
* @Description: 微信支付签名工具类 |
||||
* @author: 魏真峰 |
||||
* @param: |
||||
* @return: |
||||
* @throws |
||||
* 签名工具类 |
||||
*/ |
||||
public class SignatureUtil { |
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(SignatureUtil.class); |
||||
|
||||
/** |
||||
* 将字节数组转换为十六进制字符串 |
||||
* @param byteArray |
||||
* @return |
||||
*/ |
||||
private static String byteToStr(byte[] byteArray) { |
||||
String strDigest = ""; |
||||
for (int i = 0; i < byteArray.length; i++) { |
||||
strDigest += byteToHexStr(byteArray[i]); |
||||
} |
||||
return strDigest; |
||||
} |
||||
|
||||
/** |
||||
* 将字节转换为十六进制字符串 |
||||
* |
||||
* @param mByte |
||||
* 参数签名 |
||||
* @param param 参数 |
||||
* @param key 秘钥 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
private static String byteToHexStr(byte mByte) { |
||||
char[] Digit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; |
||||
char[] tempArr = new char[2]; |
||||
tempArr[0] = Digit[(mByte >>> 4) & 0X0F]; |
||||
tempArr[1] = Digit[mByte & 0X0F]; |
||||
return new String(tempArr); |
||||
public static String createSign(Object param, String key) throws Exception { |
||||
Map map = JSONObject.parseObject(JSONObject.toJSONString(param), Map.class); |
||||
return md5Encode(paramSort(map, key).getBytes()); |
||||
} |
||||
|
||||
/** |
||||
* 获取签名 |
||||
* |
||||
* @param o |
||||
* 待加密的对象 该处仅限于Class |
||||
* 验证签名 |
||||
* @param checkSign 需验证的签名字符串 |
||||
* @param param 参数 |
||||
* @param key 秘钥 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static String createSign(Object o, String apiKey, String encoding) { |
||||
String result = notSignParams(o, apiKey); |
||||
result = MD5Util.MD5Encode(result, encoding).toUpperCase(); |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 签名算法 |
||||
* |
||||
* @param o |
||||
* 要参与签名的数据对象 |
||||
* @param apiKey |
||||
* API密匙 |
||||
* @return 签名 |
||||
* @throws IllegalAccessException |
||||
*/ |
||||
public static String notSignParams(Object o, String apiKey) { |
||||
ArrayList<String> list = new ArrayList<>(); |
||||
String result = ""; |
||||
try { |
||||
Class<?> cls = o.getClass(); |
||||
Field[] fields = cls.getDeclaredFields(); |
||||
list = getFieldList(fields, o); |
||||
Field[] superFields = cls.getSuperclass().getDeclaredFields(); // 获取父类的私有属性
|
||||
list.addAll(getFieldList(superFields, o)); |
||||
int size = list.size(); |
||||
String[] arrayToSort = list.toArray(new String[size]); |
||||
Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER); // 严格按字母表顺序排序
|
||||
StringBuilder sb = new StringBuilder(); |
||||
for (int i = 0; i < size; i++) { |
||||
sb.append(arrayToSort[i]); |
||||
} |
||||
result = sb.toString(); |
||||
if (apiKey != null && !"".equals(apiKey)) { |
||||
result += "key=" + apiKey; |
||||
} else { |
||||
result = result.substring(0, result.lastIndexOf("&")); |
||||
} |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
public static Boolean checkSign(String checkSign,Object param, String key) throws Exception { |
||||
Map map = JSONObject.parseObject(JSONObject.toJSONString(param), Map.class); |
||||
// 去除签名
|
||||
map.remove("sign"); |
||||
if (checkSign.equals(createSign(map, key))) { |
||||
return true; |
||||
} |
||||
return result; |
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* 将字段集合方法转换 |
||||
* |
||||
* @param array |
||||
* @param object |
||||
* 参数排序 |
||||
* @param param |
||||
* @return |
||||
* @throws IllegalArgumentException |
||||
* @throws IllegalAccessException |
||||
*/ |
||||
private static ArrayList<String> getFieldList(Field[] array, Object object) |
||||
throws IllegalArgumentException, IllegalAccessException { |
||||
ArrayList<String> list = new ArrayList<String>(); |
||||
for (Field f : array) { |
||||
f.setAccessible(true); |
||||
if (f.get(object) != null && f.get(object) != "" && !f.getName().equals("serialVersionUID") |
||||
&& !f.getName().equals("sign")) { |
||||
if (f.getName().equals("packageStr")) { |
||||
list.add("package" + "=" + f.get(object) + "&"); |
||||
} else { |
||||
list.add(f.getName() + "=" + f.get(object) + "&"); |
||||
} |
||||
public static String paramSort(final Map<String, Object> param, String key) { |
||||
Set<String> keySet = param.keySet(); |
||||
String[] keyArray = keySet.toArray(new String[keySet.size()]); |
||||
Arrays.sort(keyArray); |
||||
StringBuilder sb = new StringBuilder(); |
||||
for (String k : keyArray) { |
||||
if (StringUtils.isBlank(sb.toString())) { |
||||
sb.append(k).append("=").append(param.get(k)); |
||||
} else { |
||||
sb.append("&").append(k).append("=").append(param.get(k)); |
||||
} |
||||
} |
||||
return list; |
||||
} |
||||
|
||||
/** |
||||
* 通过Map<String,Object>中的所有元素参与签名 |
||||
* |
||||
* @param map |
||||
* 待参与签名的map集合 |
||||
* @params apikey apikey中 如果为空则不参与签名,如果不为空则参与签名 |
||||
* @return |
||||
*/ |
||||
public static String createSign(Map<Object, Object> map, String apiKey, String characterEncoding) { |
||||
String result = notSignParams(map, apiKey); |
||||
result = MD5Util.MD5Encode(result, characterEncoding).toUpperCase(); |
||||
logger.debug("sign result {}", result); |
||||
return result; |
||||
sb.append("&key=").append(key); |
||||
return sb.toString(); |
||||
} |
||||
|
||||
/** |
||||
* 通过Map<SortedMap,Object>中的所有元素参与签名 |
||||
* |
||||
* @param map |
||||
* 待参与签名的map集合 |
||||
* @params apikey apikey中 如果为空则不参与签名,如果不为空则参与签名 |
||||
* MD5加密 |
||||
* @param data |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static String createSign(SortedMap<Object, Object> map, String apiKey, String characterEncoding) { |
||||
String result = notSignParams(map, apiKey); |
||||
result = MD5Util.MD5Encode(result, characterEncoding).toUpperCase(); |
||||
logger.debug("sign result {}", result); |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 通过Map<SortedMap,Object>中的所有元素参与签名 |
||||
* |
||||
* @param map |
||||
* 待参与签名的map集合 |
||||
* @params apikey apikey中 如果为空则不参与签名,如果不为空则参与签名 |
||||
* @return |
||||
*/ |
||||
public static String createSha1Sign(SortedMap<Object, Object> map, String apiKey, String characterEncoding) { |
||||
String result = notSignParams(map, apiKey); |
||||
MessageDigest md = null; |
||||
try { |
||||
md = MessageDigest.getInstance("SHA-1"); |
||||
byte[] digest = md.digest(result.getBytes(characterEncoding)); |
||||
result = byteToStr(digest); |
||||
} catch (NoSuchAlgorithmException e) { |
||||
e.printStackTrace(); |
||||
} catch (UnsupportedEncodingException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 返回未加密的字符串 |
||||
* |
||||
* @param params |
||||
* @param apiKey |
||||
* @return 待加密的字符串 |
||||
*/ |
||||
private static String notSignParams(SortedMap<Object, Object> params, String apiKey) { |
||||
StringBuffer buffer = new StringBuffer(); |
||||
for (Map.Entry<Object, Object> entry : params.entrySet()) { |
||||
if (!org.springframework.util.StringUtils.isEmpty(entry.getValue())) { |
||||
buffer.append(entry.getKey() + "=" + entry.getValue() + "&"); |
||||
} |
||||
} |
||||
buffer.append("key=" + apiKey); |
||||
return buffer.toString(); |
||||
public static String md5Encode(byte[] data) throws Exception { |
||||
// 初始化MessageDigest
|
||||
MessageDigest md = MessageDigest.getInstance("MD5"); |
||||
// 执行摘要信息
|
||||
byte[] digest = md.digest(data); |
||||
// 将摘要信息转换为32位的十六进制字符串
|
||||
return new String(new HexBinaryAdapter().marshal(digest)); |
||||
} |
||||
|
||||
/** |
||||
* 返回未加密的字符串 |
||||
* |
||||
* @param params |
||||
* @param apiKey |
||||
* @return 待加密的字符串 |
||||
*/ |
||||
public static String notSignParams(Map<Object, Object> params, String apiKey) { |
||||
ArrayList<String> list = new ArrayList<>(); |
||||
for (Map.Entry<Object, Object> entry : params.entrySet()) { |
||||
if (entry.getValue() != "" && entry.getValue() != null) { |
||||
list.add(entry.getKey() + "=" + entry.getValue() + "&"); |
||||
} |
||||
} |
||||
int size = list.size(); |
||||
String[] arrayToSort = list.toArray(new String[size]); |
||||
Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER); |
||||
StringBuilder sb = new StringBuilder(); |
||||
for (int i = 0; i < size; i++) { |
||||
sb.append(arrayToSort[i]); |
||||
} |
||||
String result = sb.toString(); |
||||
if (apiKey != null && !"".equals(apiKey)) { |
||||
result += "key=" + apiKey; |
||||
} else { |
||||
result = result.substring(0, result.lastIndexOf("&")); |
||||
} |
||||
return result; |
||||
public static void main(String[] args) throws Exception { |
||||
String paramStr = "{\n" + |
||||
" \"merchantNo\": \"2023090816465844909\",\n" + |
||||
" \"outTradeNo\": \"ZF1130202305051459532538973458\",\n" + |
||||
" \"payMode\": \"WECHAT\",\n" + |
||||
" \"totalAmount\": 0.01,\n" + |
||||
" \"transType\": \"JSAPI\",\n" + |
||||
" \"profitSharing\": 0,\n" + |
||||
" \"specialField\": \"测试\"" + |
||||
"}"; |
||||
String sign = createSign(JSONObject.parseObject(paramStr), "ZatCMLMSZxnkc2rk7dtpTORMLcKetcKt"); |
||||
System.out.println(sign); |
||||
} |
||||
|
||||
/** |
||||
* 从API返回的XML数据里面重新计算一次签名 |
||||
* |
||||
* @param responseString |
||||
* API返回的XML数据 |
||||
* @param apiKey |
||||
* Key |
||||
* @return 新的签名 |
||||
* @throws ParserConfigurationException |
||||
* @throws IOException |
||||
* @throws SAXException |
||||
*/ |
||||
public static String reCreateSign(String responseString, String apiKey, String encoding) |
||||
throws IOException, SAXException, ParserConfigurationException { |
||||
Map<String, Object> map = XmlUtil.parseXmlToMap(responseString, encoding); |
||||
// 清掉返回数据对象里面的Sign数据(不能把这个数据也加进去进行签名),然后用签名算法进行签名
|
||||
map.replace("sign",""); |
||||
// 将API返回的数据根据用签名算法进行计算新的签名,用来跟API返回的签名进行比较
|
||||
return createSign(map, apiKey, encoding); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 检验API返回的数据里面的签名是否合法,规则是:按参数名称a-z排序,遇到空值的参数不参加签名 |
||||
* |
||||
* @param resultXml |
||||
* API返回的XML数据字符串 |
||||
* @param apiKey |
||||
* Key |
||||
* @return API签名是否合法 |
||||
* @throws ParserConfigurationException |
||||
* @throws IOException |
||||
* @throws SAXException |
||||
* @throws DocumentException |
||||
*/ |
||||
public static boolean checkIsSignValidFromWeiXin(String checktXml, String apiKey, String encoding) |
||||
throws ParserConfigurationException, IOException, SAXException, DocumentException { |
||||
SortedMap<String, String> map = XmlUtil.parseXmlToTreeMap(checktXml,encoding); |
||||
String signFromresultXml = (String) map.get("sign"); |
||||
WechatReturn wechatReturn = new WechatReturn(); |
||||
wechatReturn.setAppid((String) map.get("appid")); |
||||
wechatReturn.setMch_id((String) map.get("mch_id")); |
||||
wechatReturn.setNonce_str((String) map.get("nonce_str")); |
||||
wechatReturn.setPrepay_id((String) map.get("prepay_id")); |
||||
wechatReturn.setResult_code((String) map.get("result_code")); |
||||
wechatReturn.setReturn_code((String) map.get("return_code")); |
||||
wechatReturn.setReturn_msg((String) map.get("return_msg")); |
||||
wechatReturn.setTrade_type((String) map.get("trade_type")); |
||||
if (StringUtils.isEmpty(signFromresultXml)) { |
||||
logger.debug("API返回的数据签名数据不存在"); |
||||
return false; |
||||
} |
||||
if(!("SUCCESS".equals(map.get("return_code"))) || !("SUCCESS".equals(map.get("result_code")))){ |
||||
logger.debug("返回代码不成功!"); |
||||
return false; |
||||
} |
||||
logger.debug("服务器回包里面的签名{}", signFromresultXml); |
||||
// 清掉返回数据对象里面的Sign数据(不能把这个数据也加进去进行签名),然后用签名算法进行签名
|
||||
// 将API返回的数据根据用签名算法进行计算新的签名,用来跟API返回的签名进行比较
|
||||
// String signForAPIResponse = createSign(wechatReturn, apiKey, encoding);
|
||||
// if (!signForAPIResponse.equals(signFromresultXml)) {
|
||||
// // 签名验不过,表示这个API返回的数据有可能已经被篡改了
|
||||
// logger.debug("API返回的数据签名验证不通过");
|
||||
// return false;
|
||||
// }
|
||||
logger.debug("API返回的数据签名验证通过"); |
||||
return true; |
||||
} |
||||
/** |
||||
* |
||||
* @Title: reCheckIsSignValidFromWeiXin |
||||
* @Description: 微信支付异步回调,检验签名是否正确 |
||||
* @author: 魏真峰 |
||||
* @param: [checktXml, apiKey, encoding] |
||||
* @return: boolean |
||||
* @throws |
||||
*/ |
||||
public static boolean reCheckIsSignValidFromWeiXin(String checktXml, String apiKey, String encoding) |
||||
throws ParserConfigurationException, IOException, SAXException, DocumentException { |
||||
SortedMap<String, String> map = XmlUtil.parseXmlToTreeMap(checktXml,encoding); |
||||
String signFromresultXml = (String) map.get("sign"); |
||||
WechatPayReturnParam wechatPayReturnParam = new WechatPayReturnParam(); |
||||
wechatPayReturnParam.setAppid((String) map.get("appid")); |
||||
wechatPayReturnParam.setAttach((String) map.get("attach")); |
||||
wechatPayReturnParam.setBank_type((String) map.get("bank_type")); |
||||
wechatPayReturnParam.setCash_fee((String) map.get("cash_fee")); |
||||
wechatPayReturnParam.setFee_type((String) map.get("fee_type")); |
||||
wechatPayReturnParam.setIs_subscribe((String) map.get("is_subscribe")); |
||||
wechatPayReturnParam.setMch_id((String) map.get("mch_id")); |
||||
wechatPayReturnParam.setNonce_str((String) map.get("nonce_str")); |
||||
wechatPayReturnParam.setOpenid((String) map.get("openid")); |
||||
wechatPayReturnParam.setOut_trade_no((String) map.get("out_trade_no")); |
||||
wechatPayReturnParam.setResult_code((String) map.get("result_code")); |
||||
wechatPayReturnParam.setReturn_code((String) map.get("return_code")); |
||||
wechatPayReturnParam.setTime_end((String) map.get("time_end")); |
||||
wechatPayReturnParam.setTotal_fee((String) map.get("total_fee")); |
||||
wechatPayReturnParam.setTrade_type((String) map.get("trade_type")); |
||||
wechatPayReturnParam.setTransaction_id((String) map.get("transaction_id")); |
||||
if (StringUtils.isEmpty(signFromresultXml)) { |
||||
logger.debug("API返回的数据签名数据不存在"); |
||||
return false; |
||||
} |
||||
if(!("SUCCESS".equals(map.get("return_code"))) || !("SUCCESS".equals(map.get("result_code")))){ |
||||
logger.debug("返回代码不成功!"); |
||||
return false; |
||||
} |
||||
logger.debug("服务器回包里面的签名{}", signFromresultXml); |
||||
// 清掉返回数据对象里面的Sign数据(不能把这个数据也加进去进行签名),然后用签名算法进行签名
|
||||
// 将API返回的数据根据用签名算法进行计算新的签名,用来跟API返回的签名进行比较
|
||||
String signForAPIResponse = createSign(wechatPayReturnParam, apiKey, encoding); |
||||
if (!signForAPIResponse.equals(signFromresultXml)) { |
||||
// 签名验不过,表示这个API返回的数据有可能已经被篡改了
|
||||
logger.debug("API返回的数据签名验证不通过"); |
||||
return false; |
||||
} |
||||
logger.debug("API返回的数据签名验证通过"); |
||||
return true; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,245 @@ |
||||
package com.hfkj.config; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.security.VerifyCode; |
||||
import com.hfkj.common.security.VerifyCodeStorage; |
||||
import com.hfkj.common.utils.RedisUtil; |
||||
import com.hfkj.model.MtSmsMessageModel; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.net.ssl.*; |
||||
import java.io.*; |
||||
import java.net.URL; |
||||
import java.security.cert.CertificateException; |
||||
import java.security.cert.X509Certificate; |
||||
import java.util.*; |
||||
|
||||
/** |
||||
* @author Sum1Dream |
||||
* @version 1.0.0 |
||||
* @serviceName MessageConfig.java |
||||
* @Description // 短信接口
|
||||
* @createTime 15:28 2022/5/6 |
||||
**/ |
||||
@Component |
||||
public class MessageConfig { |
||||
|
||||
// 华为短信模版ID
|
||||
// 嗨森逛绑定工会卡
|
||||
public final static String HWMSG_ID1 = "SMS_22041400010"; |
||||
// 嗨森逛积分支付密码重置
|
||||
public final static String HWMSG_ID2 = "SMS_22041400009"; |
||||
// 嗨森逛注册
|
||||
public final static String HWMSG_ID3 = "SMS_22041400008"; |
||||
// 嗨森逛公司账户充值验证码
|
||||
public final static String HWMSG_ID4 = "SMS_22041400005"; |
||||
// 嗨森逛账号登录
|
||||
public final static String HWMSG_ID5 = "SMS_22050700002"; |
||||
|
||||
// 嗨森逛账号登录支付密码修改
|
||||
public final static String HWMSG_ID6 = "SMS_22072500001"; |
||||
|
||||
public final static String HWMSG_ID7 = "SMS_24051700003"; |
||||
|
||||
private static final String[] HEX_DIGITS = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"}; |
||||
|
||||
private static Logger log = LoggerFactory.getLogger(MessageConfig.class); |
||||
|
||||
/** |
||||
* 设置不验证主机 |
||||
*/ |
||||
private static final HostnameVerifier DO_NOT_VERIFY = (hostname, session) -> true; |
||||
|
||||
private static final String reqUrl = "https://139.9.32.119:18312/common/sms/sendTemplateMessage"; |
||||
private static final String account = "760887"; |
||||
private static final String password = "Z.o'&mO%7_?5M,Br"; |
||||
|
||||
@Resource |
||||
private RedisUtil redisUtil; |
||||
|
||||
public static void req(String phone,String smsCode, String HWMSG) throws Exception { |
||||
HttpsURLConnection connection; |
||||
InputStream is = null; |
||||
BufferedReader br = null; |
||||
try { |
||||
// ip:port根据实际情况填写
|
||||
Map<String, String> templateParas = new HashMap<>(); |
||||
templateParas.put("code", smsCode); |
||||
|
||||
trustAllHttpsCertificates(); |
||||
|
||||
URL realUrl = new URL(reqUrl); |
||||
connection = (HttpsURLConnection) realUrl.openConnection(); |
||||
connection.setHostnameVerifier(DO_NOT_VERIFY); |
||||
connection.setDoInput(true); // 设置可输入
|
||||
connection.setDoOutput(true); // 设置该连接是可以输出的
|
||||
connection.setRequestMethod("POST"); // 设置请求方式
|
||||
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); |
||||
|
||||
// 如果请求正文不包含签名名称,则设置签名为空
|
||||
Map<String, Object> body = buildRequestBody(phone, HWMSG, templateParas, account, password); |
||||
if (null == body || body.isEmpty()) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "参数校验失败"); |
||||
} |
||||
ObjectMapper objectMapper = new ObjectMapper(); |
||||
PrintWriter pw = new PrintWriter(new OutputStreamWriter(connection.getOutputStream(), "UTF-8")); |
||||
pw.write(objectMapper.writeValueAsString(body)); |
||||
pw.flush(); |
||||
pw.close(); |
||||
|
||||
int status = connection.getResponseCode(); |
||||
if (200 == status) { // 200
|
||||
is = connection.getInputStream(); |
||||
} else { // 400/401
|
||||
is = connection.getErrorStream(); |
||||
} |
||||
br = new BufferedReader(new InputStreamReader(is, "UTF-8")); |
||||
String line = null; |
||||
StringBuilder result = new StringBuilder(); |
||||
while ((line = br.readLine()) != null) { // 读取数据
|
||||
result.append(line + ""); |
||||
} |
||||
JSONObject resultObject = JSONObject.parseObject(result.toString()); |
||||
if (result == null |
||||
|| resultObject.getJSONArray("resultLists") == null |
||||
|| resultObject.getJSONArray("resultLists").size() == 0) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "短信发送失败,请稍后重试"); |
||||
} |
||||
System.out.println(result.toString()); |
||||
connection.disconnect(); |
||||
|
||||
} catch (Exception e) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "短信发送失败,请稍后重试"); |
||||
} finally { |
||||
is.close(); |
||||
br.close(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @Author Sum1Dream |
||||
* @name sendSmsCodeHw.java |
||||
* @Description // 普通华为短信验证码发送
|
||||
* @Date 16:31 2022/5/6 |
||||
* @Param [java.lang.String, java.lang.String] |
||||
* @return java.lang.String |
||||
*/ |
||||
public String sendSmsCodeHw(String phone, String HWMSG) throws Exception { |
||||
VerifyCode verifyCode = VerifyCodeStorage.getDate(phone); |
||||
String smsCode; |
||||
if (verifyCode != null) { |
||||
smsCode = verifyCode.getObject(); |
||||
} else { |
||||
// 生成随机6位验证码
|
||||
smsCode = String.valueOf(new Random().nextInt(899999) + 100000); |
||||
} |
||||
// ip:port根据实际情况填写
|
||||
String url = "https://139.9.32.119:18312/common/sms/sendTemplateMessage"; |
||||
Map<String, String> templateParas = new HashMap<>(); |
||||
templateParas.put("code", smsCode); |
||||
String account = "760887"; //实际账号
|
||||
String password = "Z.o'&mO%7_?5M,Br"; //实际密码
|
||||
|
||||
// 如果请求正文不包含签名名称,则设置签名为空
|
||||
Map<String, Object> body = buildRequestBody(phone, HWMSG, templateParas, account, password); |
||||
if (null == body || body.isEmpty()) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "参数校验失败"); |
||||
} |
||||
|
||||
HttpsURLConnection connection; |
||||
InputStream is = null; |
||||
BufferedReader br = null; |
||||
trustAllHttpsCertificates(); |
||||
|
||||
URL realUrl = new URL(url); |
||||
connection = (HttpsURLConnection) realUrl.openConnection(); |
||||
connection.setHostnameVerifier(DO_NOT_VERIFY); |
||||
connection.setDoInput(true); // 设置可输入
|
||||
connection.setDoOutput(true); // 设置该连接是可以输出的
|
||||
connection.setRequestMethod("POST"); // 设置请求方式
|
||||
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); |
||||
ObjectMapper objectMapper = new ObjectMapper(); |
||||
PrintWriter pw = new PrintWriter(new OutputStreamWriter(connection.getOutputStream(), "UTF-8")); |
||||
pw.write(objectMapper.writeValueAsString(body)); |
||||
pw.flush(); |
||||
pw.close(); |
||||
|
||||
int status = connection.getResponseCode(); |
||||
if (200 == status) { // 200
|
||||
is = connection.getInputStream(); |
||||
} else { // 400/401
|
||||
is = connection.getErrorStream(); |
||||
} |
||||
br = new BufferedReader(new InputStreamReader(is, "UTF-8")); |
||||
String line = null; |
||||
StringBuilder result = new StringBuilder(); |
||||
while ((line = br.readLine()) != null) { // 读取数据
|
||||
result.append(line + ""); |
||||
} |
||||
connection.disconnect(); |
||||
System.out.println(result.toString()); |
||||
|
||||
is.close(); |
||||
br.close(); |
||||
|
||||
redisUtil.set("SMS_" + phone, smsCode, 60 * 10); |
||||
|
||||
return "发送成功"; |
||||
} |
||||
|
||||
|
||||
// msisdn, smsTemplateId, paramValues, countryID
|
||||
public static Map<String, Object> buildRequestBody(String msisdn, String smsTemplateId, |
||||
Map<String, String> paramValues, String accout, String passward) { |
||||
if (null == msisdn || null == smsTemplateId || null == accout || null == passward) { |
||||
return null; |
||||
} |
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>(); |
||||
List<MtSmsMessageModel> requestLists = new ArrayList<MtSmsMessageModel>(); |
||||
MtSmsMessageModel mtSmsMessage = new MtSmsMessageModel(); |
||||
List<String> mobiles = new ArrayList<String>(); |
||||
mobiles.add(msisdn); |
||||
mtSmsMessage.setMobiles(mobiles); |
||||
mtSmsMessage.setTemplateId(smsTemplateId); |
||||
mtSmsMessage.setTemplateParas(paramValues); |
||||
mtSmsMessage.setSignature("【普惠GO】"); |
||||
requestLists.add(mtSmsMessage); |
||||
map.put("account", accout); |
||||
map.put("password", passward); |
||||
map.put("requestLists", requestLists); |
||||
return map; |
||||
} |
||||
|
||||
static void trustAllHttpsCertificates() throws Exception { |
||||
TrustManager[] trustAllCerts = new TrustManager[]{ |
||||
new X509TrustManager() { |
||||
@Override |
||||
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { |
||||
return; |
||||
} |
||||
|
||||
@Override |
||||
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { |
||||
return; |
||||
} |
||||
|
||||
@Override |
||||
public X509Certificate[] getAcceptedIssuers() { |
||||
return null; |
||||
} |
||||
} |
||||
}; |
||||
SSLContext sc = SSLContext.getInstance("SSL"); |
||||
sc.init(null, trustAllCerts, null); |
||||
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,153 @@ |
||||
package com.hfkj.dao; |
||||
|
||||
import com.hfkj.entity.BsUserLoginLog; |
||||
import com.hfkj.entity.BsUserLoginLogExample; |
||||
import java.util.List; |
||||
import org.apache.ibatis.annotations.Delete; |
||||
import org.apache.ibatis.annotations.DeleteProvider; |
||||
import org.apache.ibatis.annotations.Insert; |
||||
import org.apache.ibatis.annotations.InsertProvider; |
||||
import org.apache.ibatis.annotations.Options; |
||||
import org.apache.ibatis.annotations.Param; |
||||
import org.apache.ibatis.annotations.Result; |
||||
import org.apache.ibatis.annotations.Results; |
||||
import org.apache.ibatis.annotations.Select; |
||||
import org.apache.ibatis.annotations.SelectProvider; |
||||
import org.apache.ibatis.annotations.Update; |
||||
import org.apache.ibatis.annotations.UpdateProvider; |
||||
import org.apache.ibatis.type.JdbcType; |
||||
import org.springframework.stereotype.Repository; |
||||
|
||||
/** |
||||
* |
||||
* 代码由工具生成,请勿修改!!! |
||||
* 如果需要扩展请在其父类进行扩展 |
||||
* |
||||
**/ |
||||
@Repository |
||||
public interface BsUserLoginLogMapper extends BsUserLoginLogMapperExt { |
||||
@SelectProvider(type=BsUserLoginLogSqlProvider.class, method="countByExample") |
||||
long countByExample(BsUserLoginLogExample example); |
||||
|
||||
@DeleteProvider(type=BsUserLoginLogSqlProvider.class, method="deleteByExample") |
||||
int deleteByExample(BsUserLoginLogExample example); |
||||
|
||||
@Delete({ |
||||
"delete from bs_user_login_log", |
||||
"where id = #{id,jdbcType=BIGINT}" |
||||
}) |
||||
int deleteByPrimaryKey(Long id); |
||||
|
||||
@Insert({ |
||||
"insert into bs_user_login_log (user_id, platform_code, ", |
||||
"platform_name, login_type_code, ", |
||||
"login_type_name, ip, ", |
||||
"country, region_id, ", |
||||
"region_name, city_id, ", |
||||
"city_name, isp, `status`, ", |
||||
"remark, create_time, ", |
||||
"ext_1, ext_2, ext_3)", |
||||
"values (#{userId,jdbcType=BIGINT}, #{platformCode,jdbcType=VARCHAR}, ", |
||||
"#{platformName,jdbcType=VARCHAR}, #{loginTypeCode,jdbcType=VARCHAR}, ", |
||||
"#{loginTypeName,jdbcType=VARCHAR}, #{ip,jdbcType=VARCHAR}, ", |
||||
"#{country,jdbcType=VARCHAR}, #{regionId,jdbcType=VARCHAR}, ", |
||||
"#{regionName,jdbcType=VARCHAR}, #{cityId,jdbcType=VARCHAR}, ", |
||||
"#{cityName,jdbcType=VARCHAR}, #{isp,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, ", |
||||
"#{remark,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, ", |
||||
"#{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" |
||||
}) |
||||
@Options(useGeneratedKeys=true,keyProperty="id") |
||||
int insert(BsUserLoginLog record); |
||||
|
||||
@InsertProvider(type=BsUserLoginLogSqlProvider.class, method="insertSelective") |
||||
@Options(useGeneratedKeys=true,keyProperty="id") |
||||
int insertSelective(BsUserLoginLog record); |
||||
|
||||
@SelectProvider(type=BsUserLoginLogSqlProvider.class, method="selectByExample") |
||||
@Results({ |
||||
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), |
||||
@Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT), |
||||
@Result(column="platform_code", property="platformCode", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="platform_name", property="platformName", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="login_type_code", property="loginTypeCode", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="login_type_name", property="loginTypeName", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="ip", property="ip", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="country", property="country", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="region_id", property="regionId", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="region_name", property="regionName", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="city_id", property="cityId", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="city_name", property="cityName", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="isp", property="isp", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="status", property="status", jdbcType=JdbcType.INTEGER), |
||||
@Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), |
||||
@Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR) |
||||
}) |
||||
List<BsUserLoginLog> selectByExample(BsUserLoginLogExample example); |
||||
|
||||
@Select({ |
||||
"select", |
||||
"id, user_id, platform_code, platform_name, login_type_code, login_type_name, ", |
||||
"ip, country, region_id, region_name, city_id, city_name, isp, `status`, remark, ", |
||||
"create_time, ext_1, ext_2, ext_3", |
||||
"from bs_user_login_log", |
||||
"where id = #{id,jdbcType=BIGINT}" |
||||
}) |
||||
@Results({ |
||||
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), |
||||
@Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT), |
||||
@Result(column="platform_code", property="platformCode", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="platform_name", property="platformName", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="login_type_code", property="loginTypeCode", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="login_type_name", property="loginTypeName", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="ip", property="ip", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="country", property="country", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="region_id", property="regionId", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="region_name", property="regionName", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="city_id", property="cityId", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="city_name", property="cityName", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="isp", property="isp", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="status", property="status", jdbcType=JdbcType.INTEGER), |
||||
@Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), |
||||
@Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR) |
||||
}) |
||||
BsUserLoginLog selectByPrimaryKey(Long id); |
||||
|
||||
@UpdateProvider(type=BsUserLoginLogSqlProvider.class, method="updateByExampleSelective") |
||||
int updateByExampleSelective(@Param("record") BsUserLoginLog record, @Param("example") BsUserLoginLogExample example); |
||||
|
||||
@UpdateProvider(type=BsUserLoginLogSqlProvider.class, method="updateByExample") |
||||
int updateByExample(@Param("record") BsUserLoginLog record, @Param("example") BsUserLoginLogExample example); |
||||
|
||||
@UpdateProvider(type=BsUserLoginLogSqlProvider.class, method="updateByPrimaryKeySelective") |
||||
int updateByPrimaryKeySelective(BsUserLoginLog record); |
||||
|
||||
@Update({ |
||||
"update bs_user_login_log", |
||||
"set user_id = #{userId,jdbcType=BIGINT},", |
||||
"platform_code = #{platformCode,jdbcType=VARCHAR},", |
||||
"platform_name = #{platformName,jdbcType=VARCHAR},", |
||||
"login_type_code = #{loginTypeCode,jdbcType=VARCHAR},", |
||||
"login_type_name = #{loginTypeName,jdbcType=VARCHAR},", |
||||
"ip = #{ip,jdbcType=VARCHAR},", |
||||
"country = #{country,jdbcType=VARCHAR},", |
||||
"region_id = #{regionId,jdbcType=VARCHAR},", |
||||
"region_name = #{regionName,jdbcType=VARCHAR},", |
||||
"city_id = #{cityId,jdbcType=VARCHAR},", |
||||
"city_name = #{cityName,jdbcType=VARCHAR},", |
||||
"isp = #{isp,jdbcType=VARCHAR},", |
||||
"`status` = #{status,jdbcType=INTEGER},", |
||||
"remark = #{remark,jdbcType=VARCHAR},", |
||||
"create_time = #{createTime,jdbcType=TIMESTAMP},", |
||||
"ext_1 = #{ext1,jdbcType=VARCHAR},", |
||||
"ext_2 = #{ext2,jdbcType=VARCHAR},", |
||||
"ext_3 = #{ext3,jdbcType=VARCHAR}", |
||||
"where id = #{id,jdbcType=BIGINT}" |
||||
}) |
||||
int updateByPrimaryKey(BsUserLoginLog record); |
||||
} |
@ -0,0 +1,7 @@ |
||||
package com.hfkj.dao; |
||||
|
||||
/** |
||||
* mapper扩展类 |
||||
*/ |
||||
public interface BsUserLoginLogMapperExt { |
||||
} |
@ -0,0 +1,430 @@ |
||||
package com.hfkj.dao; |
||||
|
||||
import com.hfkj.entity.BsUserLoginLog; |
||||
import com.hfkj.entity.BsUserLoginLogExample.Criteria; |
||||
import com.hfkj.entity.BsUserLoginLogExample.Criterion; |
||||
import com.hfkj.entity.BsUserLoginLogExample; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import org.apache.ibatis.jdbc.SQL; |
||||
|
||||
public class BsUserLoginLogSqlProvider { |
||||
|
||||
public String countByExample(BsUserLoginLogExample example) { |
||||
SQL sql = new SQL(); |
||||
sql.SELECT("count(*)").FROM("bs_user_login_log"); |
||||
applyWhere(sql, example, false); |
||||
return sql.toString(); |
||||
} |
||||
|
||||
public String deleteByExample(BsUserLoginLogExample example) { |
||||
SQL sql = new SQL(); |
||||
sql.DELETE_FROM("bs_user_login_log"); |
||||
applyWhere(sql, example, false); |
||||
return sql.toString(); |
||||
} |
||||
|
||||
public String insertSelective(BsUserLoginLog record) { |
||||
SQL sql = new SQL(); |
||||
sql.INSERT_INTO("bs_user_login_log"); |
||||
|
||||
if (record.getUserId() != null) { |
||||
sql.VALUES("user_id", "#{userId,jdbcType=BIGINT}"); |
||||
} |
||||
|
||||
if (record.getPlatformCode() != null) { |
||||
sql.VALUES("platform_code", "#{platformCode,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getPlatformName() != null) { |
||||
sql.VALUES("platform_name", "#{platformName,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getLoginTypeCode() != null) { |
||||
sql.VALUES("login_type_code", "#{loginTypeCode,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getLoginTypeName() != null) { |
||||
sql.VALUES("login_type_name", "#{loginTypeName,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getIp() != null) { |
||||
sql.VALUES("ip", "#{ip,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getCountry() != null) { |
||||
sql.VALUES("country", "#{country,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getRegionId() != null) { |
||||
sql.VALUES("region_id", "#{regionId,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getRegionName() != null) { |
||||
sql.VALUES("region_name", "#{regionName,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getCityId() != null) { |
||||
sql.VALUES("city_id", "#{cityId,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getCityName() != null) { |
||||
sql.VALUES("city_name", "#{cityName,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getIsp() != null) { |
||||
sql.VALUES("isp", "#{isp,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getStatus() != null) { |
||||
sql.VALUES("`status`", "#{status,jdbcType=INTEGER}"); |
||||
} |
||||
|
||||
if (record.getRemark() != null) { |
||||
sql.VALUES("remark", "#{remark,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getCreateTime() != null) { |
||||
sql.VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}"); |
||||
} |
||||
|
||||
if (record.getExt1() != null) { |
||||
sql.VALUES("ext_1", "#{ext1,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getExt2() != null) { |
||||
sql.VALUES("ext_2", "#{ext2,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getExt3() != null) { |
||||
sql.VALUES("ext_3", "#{ext3,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
return sql.toString(); |
||||
} |
||||
|
||||
public String selectByExample(BsUserLoginLogExample example) { |
||||
SQL sql = new SQL(); |
||||
if (example != null && example.isDistinct()) { |
||||
sql.SELECT_DISTINCT("id"); |
||||
} else { |
||||
sql.SELECT("id"); |
||||
} |
||||
sql.SELECT("user_id"); |
||||
sql.SELECT("platform_code"); |
||||
sql.SELECT("platform_name"); |
||||
sql.SELECT("login_type_code"); |
||||
sql.SELECT("login_type_name"); |
||||
sql.SELECT("ip"); |
||||
sql.SELECT("country"); |
||||
sql.SELECT("region_id"); |
||||
sql.SELECT("region_name"); |
||||
sql.SELECT("city_id"); |
||||
sql.SELECT("city_name"); |
||||
sql.SELECT("isp"); |
||||
sql.SELECT("`status`"); |
||||
sql.SELECT("remark"); |
||||
sql.SELECT("create_time"); |
||||
sql.SELECT("ext_1"); |
||||
sql.SELECT("ext_2"); |
||||
sql.SELECT("ext_3"); |
||||
sql.FROM("bs_user_login_log"); |
||||
applyWhere(sql, example, false); |
||||
|
||||
if (example != null && example.getOrderByClause() != null) { |
||||
sql.ORDER_BY(example.getOrderByClause()); |
||||
} |
||||
|
||||
return sql.toString(); |
||||
} |
||||
|
||||
public String updateByExampleSelective(Map<String, Object> parameter) { |
||||
BsUserLoginLog record = (BsUserLoginLog) parameter.get("record"); |
||||
BsUserLoginLogExample example = (BsUserLoginLogExample) parameter.get("example"); |
||||
|
||||
SQL sql = new SQL(); |
||||
sql.UPDATE("bs_user_login_log"); |
||||
|
||||
if (record.getId() != null) { |
||||
sql.SET("id = #{record.id,jdbcType=BIGINT}"); |
||||
} |
||||
|
||||
if (record.getUserId() != null) { |
||||
sql.SET("user_id = #{record.userId,jdbcType=BIGINT}"); |
||||
} |
||||
|
||||
if (record.getPlatformCode() != null) { |
||||
sql.SET("platform_code = #{record.platformCode,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getPlatformName() != null) { |
||||
sql.SET("platform_name = #{record.platformName,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getLoginTypeCode() != null) { |
||||
sql.SET("login_type_code = #{record.loginTypeCode,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getLoginTypeName() != null) { |
||||
sql.SET("login_type_name = #{record.loginTypeName,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getIp() != null) { |
||||
sql.SET("ip = #{record.ip,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getCountry() != null) { |
||||
sql.SET("country = #{record.country,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getRegionId() != null) { |
||||
sql.SET("region_id = #{record.regionId,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getRegionName() != null) { |
||||
sql.SET("region_name = #{record.regionName,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getCityId() != null) { |
||||
sql.SET("city_id = #{record.cityId,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getCityName() != null) { |
||||
sql.SET("city_name = #{record.cityName,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getIsp() != null) { |
||||
sql.SET("isp = #{record.isp,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getStatus() != null) { |
||||
sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); |
||||
} |
||||
|
||||
if (record.getRemark() != null) { |
||||
sql.SET("remark = #{record.remark,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getCreateTime() != null) { |
||||
sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}"); |
||||
} |
||||
|
||||
if (record.getExt1() != null) { |
||||
sql.SET("ext_1 = #{record.ext1,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getExt2() != null) { |
||||
sql.SET("ext_2 = #{record.ext2,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getExt3() != null) { |
||||
sql.SET("ext_3 = #{record.ext3,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
applyWhere(sql, example, true); |
||||
return sql.toString(); |
||||
} |
||||
|
||||
public String updateByExample(Map<String, Object> parameter) { |
||||
SQL sql = new SQL(); |
||||
sql.UPDATE("bs_user_login_log"); |
||||
|
||||
sql.SET("id = #{record.id,jdbcType=BIGINT}"); |
||||
sql.SET("user_id = #{record.userId,jdbcType=BIGINT}"); |
||||
sql.SET("platform_code = #{record.platformCode,jdbcType=VARCHAR}"); |
||||
sql.SET("platform_name = #{record.platformName,jdbcType=VARCHAR}"); |
||||
sql.SET("login_type_code = #{record.loginTypeCode,jdbcType=VARCHAR}"); |
||||
sql.SET("login_type_name = #{record.loginTypeName,jdbcType=VARCHAR}"); |
||||
sql.SET("ip = #{record.ip,jdbcType=VARCHAR}"); |
||||
sql.SET("country = #{record.country,jdbcType=VARCHAR}"); |
||||
sql.SET("region_id = #{record.regionId,jdbcType=VARCHAR}"); |
||||
sql.SET("region_name = #{record.regionName,jdbcType=VARCHAR}"); |
||||
sql.SET("city_id = #{record.cityId,jdbcType=VARCHAR}"); |
||||
sql.SET("city_name = #{record.cityName,jdbcType=VARCHAR}"); |
||||
sql.SET("isp = #{record.isp,jdbcType=VARCHAR}"); |
||||
sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); |
||||
sql.SET("remark = #{record.remark,jdbcType=VARCHAR}"); |
||||
sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}"); |
||||
sql.SET("ext_1 = #{record.ext1,jdbcType=VARCHAR}"); |
||||
sql.SET("ext_2 = #{record.ext2,jdbcType=VARCHAR}"); |
||||
sql.SET("ext_3 = #{record.ext3,jdbcType=VARCHAR}"); |
||||
|
||||
BsUserLoginLogExample example = (BsUserLoginLogExample) parameter.get("example"); |
||||
applyWhere(sql, example, true); |
||||
return sql.toString(); |
||||
} |
||||
|
||||
public String updateByPrimaryKeySelective(BsUserLoginLog record) { |
||||
SQL sql = new SQL(); |
||||
sql.UPDATE("bs_user_login_log"); |
||||
|
||||
if (record.getUserId() != null) { |
||||
sql.SET("user_id = #{userId,jdbcType=BIGINT}"); |
||||
} |
||||
|
||||
if (record.getPlatformCode() != null) { |
||||
sql.SET("platform_code = #{platformCode,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getPlatformName() != null) { |
||||
sql.SET("platform_name = #{platformName,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getLoginTypeCode() != null) { |
||||
sql.SET("login_type_code = #{loginTypeCode,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getLoginTypeName() != null) { |
||||
sql.SET("login_type_name = #{loginTypeName,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getIp() != null) { |
||||
sql.SET("ip = #{ip,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getCountry() != null) { |
||||
sql.SET("country = #{country,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getRegionId() != null) { |
||||
sql.SET("region_id = #{regionId,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getRegionName() != null) { |
||||
sql.SET("region_name = #{regionName,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getCityId() != null) { |
||||
sql.SET("city_id = #{cityId,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getCityName() != null) { |
||||
sql.SET("city_name = #{cityName,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getIsp() != null) { |
||||
sql.SET("isp = #{isp,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getStatus() != null) { |
||||
sql.SET("`status` = #{status,jdbcType=INTEGER}"); |
||||
} |
||||
|
||||
if (record.getRemark() != null) { |
||||
sql.SET("remark = #{remark,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getCreateTime() != null) { |
||||
sql.SET("create_time = #{createTime,jdbcType=TIMESTAMP}"); |
||||
} |
||||
|
||||
if (record.getExt1() != null) { |
||||
sql.SET("ext_1 = #{ext1,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getExt2() != null) { |
||||
sql.SET("ext_2 = #{ext2,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getExt3() != null) { |
||||
sql.SET("ext_3 = #{ext3,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
sql.WHERE("id = #{id,jdbcType=BIGINT}"); |
||||
|
||||
return sql.toString(); |
||||
} |
||||
|
||||
protected void applyWhere(SQL sql, BsUserLoginLogExample example, boolean includeExamplePhrase) { |
||||
if (example == null) { |
||||
return; |
||||
} |
||||
|
||||
String parmPhrase1; |
||||
String parmPhrase1_th; |
||||
String parmPhrase2; |
||||
String parmPhrase2_th; |
||||
String parmPhrase3; |
||||
String parmPhrase3_th; |
||||
if (includeExamplePhrase) { |
||||
parmPhrase1 = "%s #{example.oredCriteria[%d].allCriteria[%d].value}"; |
||||
parmPhrase1_th = "%s #{example.oredCriteria[%d].allCriteria[%d].value,typeHandler=%s}"; |
||||
parmPhrase2 = "%s #{example.oredCriteria[%d].allCriteria[%d].value} and #{example.oredCriteria[%d].criteria[%d].secondValue}"; |
||||
parmPhrase2_th = "%s #{example.oredCriteria[%d].allCriteria[%d].value,typeHandler=%s} and #{example.oredCriteria[%d].criteria[%d].secondValue,typeHandler=%s}"; |
||||
parmPhrase3 = "#{example.oredCriteria[%d].allCriteria[%d].value[%d]}"; |
||||
parmPhrase3_th = "#{example.oredCriteria[%d].allCriteria[%d].value[%d],typeHandler=%s}"; |
||||
} else { |
||||
parmPhrase1 = "%s #{oredCriteria[%d].allCriteria[%d].value}"; |
||||
parmPhrase1_th = "%s #{oredCriteria[%d].allCriteria[%d].value,typeHandler=%s}"; |
||||
parmPhrase2 = "%s #{oredCriteria[%d].allCriteria[%d].value} and #{oredCriteria[%d].criteria[%d].secondValue}"; |
||||
parmPhrase2_th = "%s #{oredCriteria[%d].allCriteria[%d].value,typeHandler=%s} and #{oredCriteria[%d].criteria[%d].secondValue,typeHandler=%s}"; |
||||
parmPhrase3 = "#{oredCriteria[%d].allCriteria[%d].value[%d]}"; |
||||
parmPhrase3_th = "#{oredCriteria[%d].allCriteria[%d].value[%d],typeHandler=%s}"; |
||||
} |
||||
|
||||
StringBuilder sb = new StringBuilder(); |
||||
List<Criteria> oredCriteria = example.getOredCriteria(); |
||||
boolean firstCriteria = true; |
||||
for (int i = 0; i < oredCriteria.size(); i++) { |
||||
Criteria criteria = oredCriteria.get(i); |
||||
if (criteria.isValid()) { |
||||
if (firstCriteria) { |
||||
firstCriteria = false; |
||||
} else { |
||||
sb.append(" or "); |
||||
} |
||||
|
||||
sb.append('('); |
||||
List<Criterion> criterions = criteria.getAllCriteria(); |
||||
boolean firstCriterion = true; |
||||
for (int j = 0; j < criterions.size(); j++) { |
||||
Criterion criterion = criterions.get(j); |
||||
if (firstCriterion) { |
||||
firstCriterion = false; |
||||
} else { |
||||
sb.append(" and "); |
||||
} |
||||
|
||||
if (criterion.isNoValue()) { |
||||
sb.append(criterion.getCondition()); |
||||
} else if (criterion.isSingleValue()) { |
||||
if (criterion.getTypeHandler() == null) { |
||||
sb.append(String.format(parmPhrase1, criterion.getCondition(), i, j)); |
||||
} else { |
||||
sb.append(String.format(parmPhrase1_th, criterion.getCondition(), i, j,criterion.getTypeHandler())); |
||||
} |
||||
} else if (criterion.isBetweenValue()) { |
||||
if (criterion.getTypeHandler() == null) { |
||||
sb.append(String.format(parmPhrase2, criterion.getCondition(), i, j, i, j)); |
||||
} else { |
||||
sb.append(String.format(parmPhrase2_th, criterion.getCondition(), i, j, criterion.getTypeHandler(), i, j, criterion.getTypeHandler())); |
||||
} |
||||
} else if (criterion.isListValue()) { |
||||
sb.append(criterion.getCondition()); |
||||
sb.append(" ("); |
||||
List<?> listItems = (List<?>) criterion.getValue(); |
||||
boolean comma = false; |
||||
for (int k = 0; k < listItems.size(); k++) { |
||||
if (comma) { |
||||
sb.append(", "); |
||||
} else { |
||||
comma = true; |
||||
} |
||||
if (criterion.getTypeHandler() == null) { |
||||
sb.append(String.format(parmPhrase3, i, j, k)); |
||||
} else { |
||||
sb.append(String.format(parmPhrase3_th, i, j, k, criterion.getTypeHandler())); |
||||
} |
||||
} |
||||
sb.append(')'); |
||||
} |
||||
} |
||||
sb.append(')'); |
||||
} |
||||
} |
||||
|
||||
if (sb.length() > 0) { |
||||
sql.WHERE(sb.toString()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,128 @@ |
||||
package com.hfkj.dao; |
||||
|
||||
import com.hfkj.entity.BsUser; |
||||
import com.hfkj.entity.BsUserExample; |
||||
import java.util.List; |
||||
import org.apache.ibatis.annotations.Delete; |
||||
import org.apache.ibatis.annotations.DeleteProvider; |
||||
import org.apache.ibatis.annotations.Insert; |
||||
import org.apache.ibatis.annotations.InsertProvider; |
||||
import org.apache.ibatis.annotations.Options; |
||||
import org.apache.ibatis.annotations.Param; |
||||
import org.apache.ibatis.annotations.Result; |
||||
import org.apache.ibatis.annotations.Results; |
||||
import org.apache.ibatis.annotations.Select; |
||||
import org.apache.ibatis.annotations.SelectProvider; |
||||
import org.apache.ibatis.annotations.Update; |
||||
import org.apache.ibatis.annotations.UpdateProvider; |
||||
import org.apache.ibatis.type.JdbcType; |
||||
import org.springframework.stereotype.Repository; |
||||
|
||||
/** |
||||
* |
||||
* 代码由工具生成,请勿修改!!! |
||||
* 如果需要扩展请在其父类进行扩展 |
||||
* |
||||
**/ |
||||
@Repository |
||||
public interface BsUserMapper extends BsUserMapperExt { |
||||
@SelectProvider(type=BsUserSqlProvider.class, method="countByExample") |
||||
long countByExample(BsUserExample example); |
||||
|
||||
@DeleteProvider(type=BsUserSqlProvider.class, method="deleteByExample") |
||||
int deleteByExample(BsUserExample example); |
||||
|
||||
@Delete({ |
||||
"delete from bs_user", |
||||
"where id = #{id,jdbcType=BIGINT}" |
||||
}) |
||||
int deleteByPrimaryKey(Long id); |
||||
|
||||
@Insert({ |
||||
"insert into bs_user (header_img, user_name, ", |
||||
"phone, `status`, wx_mp_open_id, ", |
||||
"wx_ma_open_id, alipay_open_id, ", |
||||
"create_time, update_time, ", |
||||
"ext_1, ext_2, ext_3)", |
||||
"values (#{headerImg,jdbcType=VARCHAR}, #{userName,jdbcType=VARCHAR}, ", |
||||
"#{phone,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, #{wxMpOpenId,jdbcType=VARCHAR}, ", |
||||
"#{wxMaOpenId,jdbcType=VARCHAR}, #{alipayOpenId,jdbcType=VARCHAR}, ", |
||||
"#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, ", |
||||
"#{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" |
||||
}) |
||||
@Options(useGeneratedKeys=true,keyProperty="id") |
||||
int insert(BsUser record); |
||||
|
||||
@InsertProvider(type=BsUserSqlProvider.class, method="insertSelective") |
||||
@Options(useGeneratedKeys=true,keyProperty="id") |
||||
int insertSelective(BsUser record); |
||||
|
||||
@SelectProvider(type=BsUserSqlProvider.class, method="selectByExample") |
||||
@Results({ |
||||
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), |
||||
@Result(column="header_img", property="headerImg", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="user_name", property="userName", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="status", property="status", jdbcType=JdbcType.INTEGER), |
||||
@Result(column="wx_mp_open_id", property="wxMpOpenId", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="wx_ma_open_id", property="wxMaOpenId", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="alipay_open_id", property="alipayOpenId", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), |
||||
@Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP), |
||||
@Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR) |
||||
}) |
||||
List<BsUser> selectByExample(BsUserExample example); |
||||
|
||||
@Select({ |
||||
"select", |
||||
"id, header_img, user_name, phone, `status`, wx_mp_open_id, wx_ma_open_id, alipay_open_id, ", |
||||
"create_time, update_time, ext_1, ext_2, ext_3", |
||||
"from bs_user", |
||||
"where id = #{id,jdbcType=BIGINT}" |
||||
}) |
||||
@Results({ |
||||
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), |
||||
@Result(column="header_img", property="headerImg", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="user_name", property="userName", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="status", property="status", jdbcType=JdbcType.INTEGER), |
||||
@Result(column="wx_mp_open_id", property="wxMpOpenId", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="wx_ma_open_id", property="wxMaOpenId", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="alipay_open_id", property="alipayOpenId", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), |
||||
@Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP), |
||||
@Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR) |
||||
}) |
||||
BsUser selectByPrimaryKey(Long id); |
||||
|
||||
@UpdateProvider(type=BsUserSqlProvider.class, method="updateByExampleSelective") |
||||
int updateByExampleSelective(@Param("record") BsUser record, @Param("example") BsUserExample example); |
||||
|
||||
@UpdateProvider(type=BsUserSqlProvider.class, method="updateByExample") |
||||
int updateByExample(@Param("record") BsUser record, @Param("example") BsUserExample example); |
||||
|
||||
@UpdateProvider(type=BsUserSqlProvider.class, method="updateByPrimaryKeySelective") |
||||
int updateByPrimaryKeySelective(BsUser record); |
||||
|
||||
@Update({ |
||||
"update bs_user", |
||||
"set header_img = #{headerImg,jdbcType=VARCHAR},", |
||||
"user_name = #{userName,jdbcType=VARCHAR},", |
||||
"phone = #{phone,jdbcType=VARCHAR},", |
||||
"`status` = #{status,jdbcType=INTEGER},", |
||||
"wx_mp_open_id = #{wxMpOpenId,jdbcType=VARCHAR},", |
||||
"wx_ma_open_id = #{wxMaOpenId,jdbcType=VARCHAR},", |
||||
"alipay_open_id = #{alipayOpenId,jdbcType=VARCHAR},", |
||||
"create_time = #{createTime,jdbcType=TIMESTAMP},", |
||||
"update_time = #{updateTime,jdbcType=TIMESTAMP},", |
||||
"ext_1 = #{ext1,jdbcType=VARCHAR},", |
||||
"ext_2 = #{ext2,jdbcType=VARCHAR},", |
||||
"ext_3 = #{ext3,jdbcType=VARCHAR}", |
||||
"where id = #{id,jdbcType=BIGINT}" |
||||
}) |
||||
int updateByPrimaryKey(BsUser record); |
||||
} |
@ -0,0 +1,7 @@ |
||||
package com.hfkj.dao; |
||||
|
||||
/** |
||||
* mapper扩展类 |
||||
*/ |
||||
public interface BsUserMapperExt { |
||||
} |
@ -0,0 +1,346 @@ |
||||
package com.hfkj.dao; |
||||
|
||||
import com.hfkj.entity.BsUser; |
||||
import com.hfkj.entity.BsUserExample.Criteria; |
||||
import com.hfkj.entity.BsUserExample.Criterion; |
||||
import com.hfkj.entity.BsUserExample; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import org.apache.ibatis.jdbc.SQL; |
||||
|
||||
public class BsUserSqlProvider { |
||||
|
||||
public String countByExample(BsUserExample example) { |
||||
SQL sql = new SQL(); |
||||
sql.SELECT("count(*)").FROM("bs_user"); |
||||
applyWhere(sql, example, false); |
||||
return sql.toString(); |
||||
} |
||||
|
||||
public String deleteByExample(BsUserExample example) { |
||||
SQL sql = new SQL(); |
||||
sql.DELETE_FROM("bs_user"); |
||||
applyWhere(sql, example, false); |
||||
return sql.toString(); |
||||
} |
||||
|
||||
public String insertSelective(BsUser record) { |
||||
SQL sql = new SQL(); |
||||
sql.INSERT_INTO("bs_user"); |
||||
|
||||
if (record.getHeaderImg() != null) { |
||||
sql.VALUES("header_img", "#{headerImg,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getUserName() != null) { |
||||
sql.VALUES("user_name", "#{userName,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getPhone() != null) { |
||||
sql.VALUES("phone", "#{phone,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getStatus() != null) { |
||||
sql.VALUES("`status`", "#{status,jdbcType=INTEGER}"); |
||||
} |
||||
|
||||
if (record.getWxMpOpenId() != null) { |
||||
sql.VALUES("wx_mp_open_id", "#{wxMpOpenId,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getWxMaOpenId() != null) { |
||||
sql.VALUES("wx_ma_open_id", "#{wxMaOpenId,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getAlipayOpenId() != null) { |
||||
sql.VALUES("alipay_open_id", "#{alipayOpenId,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getCreateTime() != null) { |
||||
sql.VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}"); |
||||
} |
||||
|
||||
if (record.getUpdateTime() != null) { |
||||
sql.VALUES("update_time", "#{updateTime,jdbcType=TIMESTAMP}"); |
||||
} |
||||
|
||||
if (record.getExt1() != null) { |
||||
sql.VALUES("ext_1", "#{ext1,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getExt2() != null) { |
||||
sql.VALUES("ext_2", "#{ext2,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getExt3() != null) { |
||||
sql.VALUES("ext_3", "#{ext3,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
return sql.toString(); |
||||
} |
||||
|
||||
public String selectByExample(BsUserExample example) { |
||||
SQL sql = new SQL(); |
||||
if (example != null && example.isDistinct()) { |
||||
sql.SELECT_DISTINCT("id"); |
||||
} else { |
||||
sql.SELECT("id"); |
||||
} |
||||
sql.SELECT("header_img"); |
||||
sql.SELECT("user_name"); |
||||
sql.SELECT("phone"); |
||||
sql.SELECT("`status`"); |
||||
sql.SELECT("wx_mp_open_id"); |
||||
sql.SELECT("wx_ma_open_id"); |
||||
sql.SELECT("alipay_open_id"); |
||||
sql.SELECT("create_time"); |
||||
sql.SELECT("update_time"); |
||||
sql.SELECT("ext_1"); |
||||
sql.SELECT("ext_2"); |
||||
sql.SELECT("ext_3"); |
||||
sql.FROM("bs_user"); |
||||
applyWhere(sql, example, false); |
||||
|
||||
if (example != null && example.getOrderByClause() != null) { |
||||
sql.ORDER_BY(example.getOrderByClause()); |
||||
} |
||||
|
||||
return sql.toString(); |
||||
} |
||||
|
||||
public String updateByExampleSelective(Map<String, Object> parameter) { |
||||
BsUser record = (BsUser) parameter.get("record"); |
||||
BsUserExample example = (BsUserExample) parameter.get("example"); |
||||
|
||||
SQL sql = new SQL(); |
||||
sql.UPDATE("bs_user"); |
||||
|
||||
if (record.getId() != null) { |
||||
sql.SET("id = #{record.id,jdbcType=BIGINT}"); |
||||
} |
||||
|
||||
if (record.getHeaderImg() != null) { |
||||
sql.SET("header_img = #{record.headerImg,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getUserName() != null) { |
||||
sql.SET("user_name = #{record.userName,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getPhone() != null) { |
||||
sql.SET("phone = #{record.phone,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getStatus() != null) { |
||||
sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); |
||||
} |
||||
|
||||
if (record.getWxMpOpenId() != null) { |
||||
sql.SET("wx_mp_open_id = #{record.wxMpOpenId,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getWxMaOpenId() != null) { |
||||
sql.SET("wx_ma_open_id = #{record.wxMaOpenId,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getAlipayOpenId() != null) { |
||||
sql.SET("alipay_open_id = #{record.alipayOpenId,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getCreateTime() != null) { |
||||
sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}"); |
||||
} |
||||
|
||||
if (record.getUpdateTime() != null) { |
||||
sql.SET("update_time = #{record.updateTime,jdbcType=TIMESTAMP}"); |
||||
} |
||||
|
||||
if (record.getExt1() != null) { |
||||
sql.SET("ext_1 = #{record.ext1,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getExt2() != null) { |
||||
sql.SET("ext_2 = #{record.ext2,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getExt3() != null) { |
||||
sql.SET("ext_3 = #{record.ext3,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
applyWhere(sql, example, true); |
||||
return sql.toString(); |
||||
} |
||||
|
||||
public String updateByExample(Map<String, Object> parameter) { |
||||
SQL sql = new SQL(); |
||||
sql.UPDATE("bs_user"); |
||||
|
||||
sql.SET("id = #{record.id,jdbcType=BIGINT}"); |
||||
sql.SET("header_img = #{record.headerImg,jdbcType=VARCHAR}"); |
||||
sql.SET("user_name = #{record.userName,jdbcType=VARCHAR}"); |
||||
sql.SET("phone = #{record.phone,jdbcType=VARCHAR}"); |
||||
sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); |
||||
sql.SET("wx_mp_open_id = #{record.wxMpOpenId,jdbcType=VARCHAR}"); |
||||
sql.SET("wx_ma_open_id = #{record.wxMaOpenId,jdbcType=VARCHAR}"); |
||||
sql.SET("alipay_open_id = #{record.alipayOpenId,jdbcType=VARCHAR}"); |
||||
sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}"); |
||||
sql.SET("update_time = #{record.updateTime,jdbcType=TIMESTAMP}"); |
||||
sql.SET("ext_1 = #{record.ext1,jdbcType=VARCHAR}"); |
||||
sql.SET("ext_2 = #{record.ext2,jdbcType=VARCHAR}"); |
||||
sql.SET("ext_3 = #{record.ext3,jdbcType=VARCHAR}"); |
||||
|
||||
BsUserExample example = (BsUserExample) parameter.get("example"); |
||||
applyWhere(sql, example, true); |
||||
return sql.toString(); |
||||
} |
||||
|
||||
public String updateByPrimaryKeySelective(BsUser record) { |
||||
SQL sql = new SQL(); |
||||
sql.UPDATE("bs_user"); |
||||
|
||||
if (record.getHeaderImg() != null) { |
||||
sql.SET("header_img = #{headerImg,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getUserName() != null) { |
||||
sql.SET("user_name = #{userName,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getPhone() != null) { |
||||
sql.SET("phone = #{phone,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getStatus() != null) { |
||||
sql.SET("`status` = #{status,jdbcType=INTEGER}"); |
||||
} |
||||
|
||||
if (record.getWxMpOpenId() != null) { |
||||
sql.SET("wx_mp_open_id = #{wxMpOpenId,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getWxMaOpenId() != null) { |
||||
sql.SET("wx_ma_open_id = #{wxMaOpenId,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getAlipayOpenId() != null) { |
||||
sql.SET("alipay_open_id = #{alipayOpenId,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getCreateTime() != null) { |
||||
sql.SET("create_time = #{createTime,jdbcType=TIMESTAMP}"); |
||||
} |
||||
|
||||
if (record.getUpdateTime() != null) { |
||||
sql.SET("update_time = #{updateTime,jdbcType=TIMESTAMP}"); |
||||
} |
||||
|
||||
if (record.getExt1() != null) { |
||||
sql.SET("ext_1 = #{ext1,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getExt2() != null) { |
||||
sql.SET("ext_2 = #{ext2,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getExt3() != null) { |
||||
sql.SET("ext_3 = #{ext3,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
sql.WHERE("id = #{id,jdbcType=BIGINT}"); |
||||
|
||||
return sql.toString(); |
||||
} |
||||
|
||||
protected void applyWhere(SQL sql, BsUserExample example, boolean includeExamplePhrase) { |
||||
if (example == null) { |
||||
return; |
||||
} |
||||
|
||||
String parmPhrase1; |
||||
String parmPhrase1_th; |
||||
String parmPhrase2; |
||||
String parmPhrase2_th; |
||||
String parmPhrase3; |
||||
String parmPhrase3_th; |
||||
if (includeExamplePhrase) { |
||||
parmPhrase1 = "%s #{example.oredCriteria[%d].allCriteria[%d].value}"; |
||||
parmPhrase1_th = "%s #{example.oredCriteria[%d].allCriteria[%d].value,typeHandler=%s}"; |
||||
parmPhrase2 = "%s #{example.oredCriteria[%d].allCriteria[%d].value} and #{example.oredCriteria[%d].criteria[%d].secondValue}"; |
||||
parmPhrase2_th = "%s #{example.oredCriteria[%d].allCriteria[%d].value,typeHandler=%s} and #{example.oredCriteria[%d].criteria[%d].secondValue,typeHandler=%s}"; |
||||
parmPhrase3 = "#{example.oredCriteria[%d].allCriteria[%d].value[%d]}"; |
||||
parmPhrase3_th = "#{example.oredCriteria[%d].allCriteria[%d].value[%d],typeHandler=%s}"; |
||||
} else { |
||||
parmPhrase1 = "%s #{oredCriteria[%d].allCriteria[%d].value}"; |
||||
parmPhrase1_th = "%s #{oredCriteria[%d].allCriteria[%d].value,typeHandler=%s}"; |
||||
parmPhrase2 = "%s #{oredCriteria[%d].allCriteria[%d].value} and #{oredCriteria[%d].criteria[%d].secondValue}"; |
||||
parmPhrase2_th = "%s #{oredCriteria[%d].allCriteria[%d].value,typeHandler=%s} and #{oredCriteria[%d].criteria[%d].secondValue,typeHandler=%s}"; |
||||
parmPhrase3 = "#{oredCriteria[%d].allCriteria[%d].value[%d]}"; |
||||
parmPhrase3_th = "#{oredCriteria[%d].allCriteria[%d].value[%d],typeHandler=%s}"; |
||||
} |
||||
|
||||
StringBuilder sb = new StringBuilder(); |
||||
List<Criteria> oredCriteria = example.getOredCriteria(); |
||||
boolean firstCriteria = true; |
||||
for (int i = 0; i < oredCriteria.size(); i++) { |
||||
Criteria criteria = oredCriteria.get(i); |
||||
if (criteria.isValid()) { |
||||
if (firstCriteria) { |
||||
firstCriteria = false; |
||||
} else { |
||||
sb.append(" or "); |
||||
} |
||||
|
||||
sb.append('('); |
||||
List<Criterion> criterions = criteria.getAllCriteria(); |
||||
boolean firstCriterion = true; |
||||
for (int j = 0; j < criterions.size(); j++) { |
||||
Criterion criterion = criterions.get(j); |
||||
if (firstCriterion) { |
||||
firstCriterion = false; |
||||
} else { |
||||
sb.append(" and "); |
||||
} |
||||
|
||||
if (criterion.isNoValue()) { |
||||
sb.append(criterion.getCondition()); |
||||
} else if (criterion.isSingleValue()) { |
||||
if (criterion.getTypeHandler() == null) { |
||||
sb.append(String.format(parmPhrase1, criterion.getCondition(), i, j)); |
||||
} else { |
||||
sb.append(String.format(parmPhrase1_th, criterion.getCondition(), i, j,criterion.getTypeHandler())); |
||||
} |
||||
} else if (criterion.isBetweenValue()) { |
||||
if (criterion.getTypeHandler() == null) { |
||||
sb.append(String.format(parmPhrase2, criterion.getCondition(), i, j, i, j)); |
||||
} else { |
||||
sb.append(String.format(parmPhrase2_th, criterion.getCondition(), i, j, criterion.getTypeHandler(), i, j, criterion.getTypeHandler())); |
||||
} |
||||
} else if (criterion.isListValue()) { |
||||
sb.append(criterion.getCondition()); |
||||
sb.append(" ("); |
||||
List<?> listItems = (List<?>) criterion.getValue(); |
||||
boolean comma = false; |
||||
for (int k = 0; k < listItems.size(); k++) { |
||||
if (comma) { |
||||
sb.append(", "); |
||||
} else { |
||||
comma = true; |
||||
} |
||||
if (criterion.getTypeHandler() == null) { |
||||
sb.append(String.format(parmPhrase3, i, j, k)); |
||||
} else { |
||||
sb.append(String.format(parmPhrase3_th, i, j, k, criterion.getTypeHandler())); |
||||
} |
||||
} |
||||
sb.append(')'); |
||||
} |
||||
} |
||||
sb.append(')'); |
||||
} |
||||
} |
||||
|
||||
if (sb.length() > 0) { |
||||
sql.WHERE(sb.toString()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,248 @@ |
||||
package com.hfkj.entity; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* bs_user |
||||
* @author |
||||
*/ |
||||
/** |
||||
* |
||||
* 代码由工具生成 |
||||
* |
||||
**/ |
||||
public class BsUser implements Serializable { |
||||
/** |
||||
* 主键ID |
||||
*/ |
||||
private Long id; |
||||
|
||||
/** |
||||
* 用户头像 |
||||
*/ |
||||
private String headerImg; |
||||
|
||||
/** |
||||
* 用户名称 |
||||
*/ |
||||
private String userName; |
||||
|
||||
/** |
||||
* 手机号 |
||||
*/ |
||||
private String phone; |
||||
|
||||
/** |
||||
* 状态:0:不可用 1:正常 |
||||
*/ |
||||
private Integer status; |
||||
|
||||
/** |
||||
* 微信公众号openid |
||||
*/ |
||||
private String wxMpOpenId; |
||||
|
||||
/** |
||||
* 微信小程序openid |
||||
*/ |
||||
private String wxMaOpenId; |
||||
|
||||
/** |
||||
* 支付宝openid |
||||
*/ |
||||
private String alipayOpenId; |
||||
|
||||
/** |
||||
* 创建时间 |
||||
*/ |
||||
private Date createTime; |
||||
|
||||
/** |
||||
* 更新时间 |
||||
*/ |
||||
private Date updateTime; |
||||
|
||||
private String ext1; |
||||
|
||||
private String ext2; |
||||
|
||||
private String ext3; |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
public Long getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(Long id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public String getHeaderImg() { |
||||
return headerImg; |
||||
} |
||||
|
||||
public void setHeaderImg(String headerImg) { |
||||
this.headerImg = headerImg; |
||||
} |
||||
|
||||
public String getUserName() { |
||||
return userName; |
||||
} |
||||
|
||||
public void setUserName(String userName) { |
||||
this.userName = userName; |
||||
} |
||||
|
||||
public String getPhone() { |
||||
return phone; |
||||
} |
||||
|
||||
public void setPhone(String phone) { |
||||
this.phone = phone; |
||||
} |
||||
|
||||
public Integer getStatus() { |
||||
return status; |
||||
} |
||||
|
||||
public void setStatus(Integer status) { |
||||
this.status = status; |
||||
} |
||||
|
||||
public String getWxMpOpenId() { |
||||
return wxMpOpenId; |
||||
} |
||||
|
||||
public void setWxMpOpenId(String wxMpOpenId) { |
||||
this.wxMpOpenId = wxMpOpenId; |
||||
} |
||||
|
||||
public String getWxMaOpenId() { |
||||
return wxMaOpenId; |
||||
} |
||||
|
||||
public void setWxMaOpenId(String wxMaOpenId) { |
||||
this.wxMaOpenId = wxMaOpenId; |
||||
} |
||||
|
||||
public String getAlipayOpenId() { |
||||
return alipayOpenId; |
||||
} |
||||
|
||||
public void setAlipayOpenId(String alipayOpenId) { |
||||
this.alipayOpenId = alipayOpenId; |
||||
} |
||||
|
||||
public Date getCreateTime() { |
||||
return createTime; |
||||
} |
||||
|
||||
public void setCreateTime(Date createTime) { |
||||
this.createTime = createTime; |
||||
} |
||||
|
||||
public Date getUpdateTime() { |
||||
return updateTime; |
||||
} |
||||
|
||||
public void setUpdateTime(Date updateTime) { |
||||
this.updateTime = updateTime; |
||||
} |
||||
|
||||
public String getExt1() { |
||||
return ext1; |
||||
} |
||||
|
||||
public void setExt1(String ext1) { |
||||
this.ext1 = ext1; |
||||
} |
||||
|
||||
public String getExt2() { |
||||
return ext2; |
||||
} |
||||
|
||||
public void setExt2(String ext2) { |
||||
this.ext2 = ext2; |
||||
} |
||||
|
||||
public String getExt3() { |
||||
return ext3; |
||||
} |
||||
|
||||
public void setExt3(String ext3) { |
||||
this.ext3 = ext3; |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(Object that) { |
||||
if (this == that) { |
||||
return true; |
||||
} |
||||
if (that == null) { |
||||
return false; |
||||
} |
||||
if (getClass() != that.getClass()) { |
||||
return false; |
||||
} |
||||
BsUser other = (BsUser) that; |
||||
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) |
||||
&& (this.getHeaderImg() == null ? other.getHeaderImg() == null : this.getHeaderImg().equals(other.getHeaderImg())) |
||||
&& (this.getUserName() == null ? other.getUserName() == null : this.getUserName().equals(other.getUserName())) |
||||
&& (this.getPhone() == null ? other.getPhone() == null : this.getPhone().equals(other.getPhone())) |
||||
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus())) |
||||
&& (this.getWxMpOpenId() == null ? other.getWxMpOpenId() == null : this.getWxMpOpenId().equals(other.getWxMpOpenId())) |
||||
&& (this.getWxMaOpenId() == null ? other.getWxMaOpenId() == null : this.getWxMaOpenId().equals(other.getWxMaOpenId())) |
||||
&& (this.getAlipayOpenId() == null ? other.getAlipayOpenId() == null : this.getAlipayOpenId().equals(other.getAlipayOpenId())) |
||||
&& (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) |
||||
&& (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime())) |
||||
&& (this.getExt1() == null ? other.getExt1() == null : this.getExt1().equals(other.getExt1())) |
||||
&& (this.getExt2() == null ? other.getExt2() == null : this.getExt2().equals(other.getExt2())) |
||||
&& (this.getExt3() == null ? other.getExt3() == null : this.getExt3().equals(other.getExt3())); |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
final int prime = 31; |
||||
int result = 1; |
||||
result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); |
||||
result = prime * result + ((getHeaderImg() == null) ? 0 : getHeaderImg().hashCode()); |
||||
result = prime * result + ((getUserName() == null) ? 0 : getUserName().hashCode()); |
||||
result = prime * result + ((getPhone() == null) ? 0 : getPhone().hashCode()); |
||||
result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode()); |
||||
result = prime * result + ((getWxMpOpenId() == null) ? 0 : getWxMpOpenId().hashCode()); |
||||
result = prime * result + ((getWxMaOpenId() == null) ? 0 : getWxMaOpenId().hashCode()); |
||||
result = prime * result + ((getAlipayOpenId() == null) ? 0 : getAlipayOpenId().hashCode()); |
||||
result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); |
||||
result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode()); |
||||
result = prime * result + ((getExt1() == null) ? 0 : getExt1().hashCode()); |
||||
result = prime * result + ((getExt2() == null) ? 0 : getExt2().hashCode()); |
||||
result = prime * result + ((getExt3() == null) ? 0 : getExt3().hashCode()); |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
StringBuilder sb = new StringBuilder(); |
||||
sb.append(getClass().getSimpleName()); |
||||
sb.append(" ["); |
||||
sb.append("Hash = ").append(hashCode()); |
||||
sb.append(", id=").append(id); |
||||
sb.append(", headerImg=").append(headerImg); |
||||
sb.append(", userName=").append(userName); |
||||
sb.append(", phone=").append(phone); |
||||
sb.append(", status=").append(status); |
||||
sb.append(", wxMpOpenId=").append(wxMpOpenId); |
||||
sb.append(", wxMaOpenId=").append(wxMaOpenId); |
||||
sb.append(", alipayOpenId=").append(alipayOpenId); |
||||
sb.append(", createTime=").append(createTime); |
||||
sb.append(", updateTime=").append(updateTime); |
||||
sb.append(", ext1=").append(ext1); |
||||
sb.append(", ext2=").append(ext2); |
||||
sb.append(", ext3=").append(ext3); |
||||
sb.append(", serialVersionUID=").append(serialVersionUID); |
||||
sb.append("]"); |
||||
return sb.toString(); |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,344 @@ |
||||
package com.hfkj.entity; |
||||
|
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* bs_user_login_log |
||||
* @author |
||||
*/ |
||||
/** |
||||
* |
||||
* 代码由工具生成 |
||||
* |
||||
**/ |
||||
public class BsUserLoginLog implements Serializable { |
||||
/** |
||||
* 主键 |
||||
*/ |
||||
private Long id; |
||||
|
||||
/** |
||||
* 登录账户id |
||||
*/ |
||||
private Long userId; |
||||
|
||||
/** |
||||
* 登录平台code |
||||
*/ |
||||
private String platformCode; |
||||
|
||||
/** |
||||
* 登录平台名称 |
||||
*/ |
||||
private String platformName; |
||||
|
||||
/** |
||||
* 登录方式code |
||||
*/ |
||||
private String loginTypeCode; |
||||
|
||||
/** |
||||
* 登录方式名称 |
||||
*/ |
||||
private String loginTypeName; |
||||
|
||||
/** |
||||
* ip |
||||
*/ |
||||
private String ip; |
||||
|
||||
/** |
||||
* 国家 |
||||
*/ |
||||
private String country; |
||||
|
||||
/** |
||||
* 省份编号 |
||||
*/ |
||||
private String regionId; |
||||
|
||||
/** |
||||
* 省份名称 |
||||
*/ |
||||
private String regionName; |
||||
|
||||
/** |
||||
* 城市编号 |
||||
*/ |
||||
private String cityId; |
||||
|
||||
/** |
||||
* 城市名称 |
||||
*/ |
||||
private String cityName; |
||||
|
||||
/** |
||||
* 运营商 |
||||
*/ |
||||
private String isp; |
||||
|
||||
/** |
||||
* 状态 1:正常 2:风险 |
||||
*/ |
||||
private Integer status; |
||||
|
||||
/** |
||||
* 备注 |
||||
*/ |
||||
private String remark; |
||||
|
||||
/** |
||||
* 创建时间 |
||||
*/ |
||||
private Date createTime; |
||||
|
||||
private String ext1; |
||||
|
||||
private String ext2; |
||||
|
||||
private String ext3; |
||||
|
||||
private static final long serialVersionUID = 1L; |
||||
|
||||
public Long getId() { |
||||
return id; |
||||
} |
||||
|
||||
public void setId(Long id) { |
||||
this.id = id; |
||||
} |
||||
|
||||
public Long getUserId() { |
||||
return userId; |
||||
} |
||||
|
||||
public void setUserId(Long userId) { |
||||
this.userId = userId; |
||||
} |
||||
|
||||
public String getPlatformCode() { |
||||
return platformCode; |
||||
} |
||||
|
||||
public void setPlatformCode(String platformCode) { |
||||
this.platformCode = platformCode; |
||||
} |
||||
|
||||
public String getPlatformName() { |
||||
return platformName; |
||||
} |
||||
|
||||
public void setPlatformName(String platformName) { |
||||
this.platformName = platformName; |
||||
} |
||||
|
||||
public String getLoginTypeCode() { |
||||
return loginTypeCode; |
||||
} |
||||
|
||||
public void setLoginTypeCode(String loginTypeCode) { |
||||
this.loginTypeCode = loginTypeCode; |
||||
} |
||||
|
||||
public String getLoginTypeName() { |
||||
return loginTypeName; |
||||
} |
||||
|
||||
public void setLoginTypeName(String loginTypeName) { |
||||
this.loginTypeName = loginTypeName; |
||||
} |
||||
|
||||
public String getIp() { |
||||
return ip; |
||||
} |
||||
|
||||
public void setIp(String ip) { |
||||
this.ip = ip; |
||||
} |
||||
|
||||
public String getCountry() { |
||||
return country; |
||||
} |
||||
|
||||
public void setCountry(String country) { |
||||
this.country = country; |
||||
} |
||||
|
||||
public String getRegionId() { |
||||
return regionId; |
||||
} |
||||
|
||||
public void setRegionId(String regionId) { |
||||
this.regionId = regionId; |
||||
} |
||||
|
||||
public String getRegionName() { |
||||
return regionName; |
||||
} |
||||
|
||||
public void setRegionName(String regionName) { |
||||
this.regionName = regionName; |
||||
} |
||||
|
||||
public String getCityId() { |
||||
return cityId; |
||||
} |
||||
|
||||
public void setCityId(String cityId) { |
||||
this.cityId = cityId; |
||||
} |
||||
|
||||
public String getCityName() { |
||||
return cityName; |
||||
} |
||||
|
||||
public void setCityName(String cityName) { |
||||
this.cityName = cityName; |
||||
} |
||||
|
||||
public String getIsp() { |
||||
return isp; |
||||
} |
||||
|
||||
public void setIsp(String isp) { |
||||
this.isp = isp; |
||||
} |
||||
|
||||
public Integer getStatus() { |
||||
return status; |
||||
} |
||||
|
||||
public void setStatus(Integer status) { |
||||
this.status = status; |
||||
} |
||||
|
||||
public String getRemark() { |
||||
return remark; |
||||
} |
||||
|
||||
public void setRemark(String remark) { |
||||
this.remark = remark; |
||||
} |
||||
|
||||
public Date getCreateTime() { |
||||
return createTime; |
||||
} |
||||
|
||||
public void setCreateTime(Date createTime) { |
||||
this.createTime = createTime; |
||||
} |
||||
|
||||
public String getExt1() { |
||||
return ext1; |
||||
} |
||||
|
||||
public void setExt1(String ext1) { |
||||
this.ext1 = ext1; |
||||
} |
||||
|
||||
public String getExt2() { |
||||
return ext2; |
||||
} |
||||
|
||||
public void setExt2(String ext2) { |
||||
this.ext2 = ext2; |
||||
} |
||||
|
||||
public String getExt3() { |
||||
return ext3; |
||||
} |
||||
|
||||
public void setExt3(String ext3) { |
||||
this.ext3 = ext3; |
||||
} |
||||
|
||||
@Override |
||||
public boolean equals(Object that) { |
||||
if (this == that) { |
||||
return true; |
||||
} |
||||
if (that == null) { |
||||
return false; |
||||
} |
||||
if (getClass() != that.getClass()) { |
||||
return false; |
||||
} |
||||
BsUserLoginLog other = (BsUserLoginLog) that; |
||||
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) |
||||
&& (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId())) |
||||
&& (this.getPlatformCode() == null ? other.getPlatformCode() == null : this.getPlatformCode().equals(other.getPlatformCode())) |
||||
&& (this.getPlatformName() == null ? other.getPlatformName() == null : this.getPlatformName().equals(other.getPlatformName())) |
||||
&& (this.getLoginTypeCode() == null ? other.getLoginTypeCode() == null : this.getLoginTypeCode().equals(other.getLoginTypeCode())) |
||||
&& (this.getLoginTypeName() == null ? other.getLoginTypeName() == null : this.getLoginTypeName().equals(other.getLoginTypeName())) |
||||
&& (this.getIp() == null ? other.getIp() == null : this.getIp().equals(other.getIp())) |
||||
&& (this.getCountry() == null ? other.getCountry() == null : this.getCountry().equals(other.getCountry())) |
||||
&& (this.getRegionId() == null ? other.getRegionId() == null : this.getRegionId().equals(other.getRegionId())) |
||||
&& (this.getRegionName() == null ? other.getRegionName() == null : this.getRegionName().equals(other.getRegionName())) |
||||
&& (this.getCityId() == null ? other.getCityId() == null : this.getCityId().equals(other.getCityId())) |
||||
&& (this.getCityName() == null ? other.getCityName() == null : this.getCityName().equals(other.getCityName())) |
||||
&& (this.getIsp() == null ? other.getIsp() == null : this.getIsp().equals(other.getIsp())) |
||||
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus())) |
||||
&& (this.getRemark() == null ? other.getRemark() == null : this.getRemark().equals(other.getRemark())) |
||||
&& (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) |
||||
&& (this.getExt1() == null ? other.getExt1() == null : this.getExt1().equals(other.getExt1())) |
||||
&& (this.getExt2() == null ? other.getExt2() == null : this.getExt2().equals(other.getExt2())) |
||||
&& (this.getExt3() == null ? other.getExt3() == null : this.getExt3().equals(other.getExt3())); |
||||
} |
||||
|
||||
@Override |
||||
public int hashCode() { |
||||
final int prime = 31; |
||||
int result = 1; |
||||
result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); |
||||
result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode()); |
||||
result = prime * result + ((getPlatformCode() == null) ? 0 : getPlatformCode().hashCode()); |
||||
result = prime * result + ((getPlatformName() == null) ? 0 : getPlatformName().hashCode()); |
||||
result = prime * result + ((getLoginTypeCode() == null) ? 0 : getLoginTypeCode().hashCode()); |
||||
result = prime * result + ((getLoginTypeName() == null) ? 0 : getLoginTypeName().hashCode()); |
||||
result = prime * result + ((getIp() == null) ? 0 : getIp().hashCode()); |
||||
result = prime * result + ((getCountry() == null) ? 0 : getCountry().hashCode()); |
||||
result = prime * result + ((getRegionId() == null) ? 0 : getRegionId().hashCode()); |
||||
result = prime * result + ((getRegionName() == null) ? 0 : getRegionName().hashCode()); |
||||
result = prime * result + ((getCityId() == null) ? 0 : getCityId().hashCode()); |
||||
result = prime * result + ((getCityName() == null) ? 0 : getCityName().hashCode()); |
||||
result = prime * result + ((getIsp() == null) ? 0 : getIsp().hashCode()); |
||||
result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode()); |
||||
result = prime * result + ((getRemark() == null) ? 0 : getRemark().hashCode()); |
||||
result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); |
||||
result = prime * result + ((getExt1() == null) ? 0 : getExt1().hashCode()); |
||||
result = prime * result + ((getExt2() == null) ? 0 : getExt2().hashCode()); |
||||
result = prime * result + ((getExt3() == null) ? 0 : getExt3().hashCode()); |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
StringBuilder sb = new StringBuilder(); |
||||
sb.append(getClass().getSimpleName()); |
||||
sb.append(" ["); |
||||
sb.append("Hash = ").append(hashCode()); |
||||
sb.append(", id=").append(id); |
||||
sb.append(", userId=").append(userId); |
||||
sb.append(", platformCode=").append(platformCode); |
||||
sb.append(", platformName=").append(platformName); |
||||
sb.append(", loginTypeCode=").append(loginTypeCode); |
||||
sb.append(", loginTypeName=").append(loginTypeName); |
||||
sb.append(", ip=").append(ip); |
||||
sb.append(", country=").append(country); |
||||
sb.append(", regionId=").append(regionId); |
||||
sb.append(", regionName=").append(regionName); |
||||
sb.append(", cityId=").append(cityId); |
||||
sb.append(", cityName=").append(cityName); |
||||
sb.append(", isp=").append(isp); |
||||
sb.append(", status=").append(status); |
||||
sb.append(", remark=").append(remark); |
||||
sb.append(", createTime=").append(createTime); |
||||
sb.append(", ext1=").append(ext1); |
||||
sb.append(", ext2=").append(ext2); |
||||
sb.append(", ext3=").append(ext3); |
||||
sb.append(", serialVersionUID=").append(serialVersionUID); |
||||
sb.append("]"); |
||||
return sb.toString(); |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,71 @@ |
||||
package com.hfkj.model; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
public class MtSmsMessageModel { |
||||
List<String> mobiles; |
||||
|
||||
|
||||
String templateId; |
||||
|
||||
|
||||
Map<String, String> templateParas; |
||||
|
||||
|
||||
String signature; |
||||
|
||||
|
||||
String messageId; |
||||
|
||||
|
||||
String extCode; |
||||
|
||||
public List<String> getMobiles() { |
||||
return mobiles; |
||||
} |
||||
|
||||
public void setMobiles(List<String> mobiles) { |
||||
this.mobiles = mobiles; |
||||
} |
||||
|
||||
public String getTemplateId() { |
||||
return templateId; |
||||
} |
||||
|
||||
public void setTemplateId(String templateId) { |
||||
this.templateId = templateId; |
||||
} |
||||
|
||||
public Map<String, String> getTemplateParas() { |
||||
return templateParas; |
||||
} |
||||
|
||||
public void setTemplateParas(Map<String, String> templateParas) { |
||||
this.templateParas = templateParas; |
||||
} |
||||
|
||||
public String getSignature() { |
||||
return signature; |
||||
} |
||||
|
||||
public void setSignature(String signature) { |
||||
this.signature = signature; |
||||
} |
||||
|
||||
public String getMessageId() { |
||||
return messageId; |
||||
} |
||||
|
||||
public void setMessageId(String messageId) { |
||||
this.messageId = messageId; |
||||
} |
||||
|
||||
public String getExtCode() { |
||||
return extCode; |
||||
} |
||||
|
||||
public void setExtCode(String extCode) { |
||||
this.extCode = extCode; |
||||
} |
||||
} |
@ -0,0 +1,16 @@ |
||||
package com.hfkj.model; |
||||
|
||||
import com.hfkj.entity.BsUser; |
||||
import lombok.Data; |
||||
|
||||
/** |
||||
* 用户登录session对象 |
||||
*/ |
||||
@Data |
||||
public class UserSessionObject { |
||||
|
||||
/** |
||||
* 登录账户 |
||||
*/ |
||||
private BsUser user; |
||||
} |
@ -0,0 +1,119 @@ |
||||
package com.hfkj.pay; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.pay.util.SignatureUtil; |
||||
import com.hfkj.common.utils.HttpsUtils; |
||||
import com.hfkj.config.CommonSysConst; |
||||
import com.hfkj.model.order.OrderModel; |
||||
import com.hfkj.sysenum.order.OrderPayTypeEnum; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.SortedMap; |
||||
import java.util.TreeMap; |
||||
|
||||
/** |
||||
* @className: HuiPayService |
||||
* @author: HuRui |
||||
* @date: 2024/5/7 |
||||
**/ |
||||
public class HuiPayService { |
||||
static Logger log = LoggerFactory.getLogger(HuiPayService.class); |
||||
// 请求地址
|
||||
private final static String REQUEST_URL = "https://pay.dctpay.com/openApi/v1/"; |
||||
public final static String DEFAULT_MER_NO = "2023041916292112804"; |
||||
private final static String DEFAULT_MER_KEY = "2jLO2WjXcSRSzTCaca0Kmv0OFrfYBbrA"; |
||||
|
||||
/** |
||||
* JSAPI支付 |
||||
* @param openId |
||||
* @param order |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static Map<Object, Object> preorder(String merNo,String merKey,String openId,OrderModel order) throws Exception { |
||||
try { |
||||
log.info("=============== start 惠支付 start =================="); |
||||
Map<String, Object> param = new HashMap<>(); |
||||
param.put("merchantNo", merNo); |
||||
param.put("outTradeNo", order.getOrderNo()); |
||||
param.put("transType", "JSAPI"); |
||||
if (OrderPayTypeEnum.type1.getCode() == order.getPayType()) { |
||||
param.put("payMode", "WECHAT"); |
||||
} else if (OrderPayTypeEnum.type2.getCode() == order.getPayType()) { |
||||
param.put("payMode", "ALIPAY"); |
||||
} |
||||
param.put("totalAmount", order.getPayRealPrice()); |
||||
param.put("profitSharing", "0"); |
||||
param.put("subject", "购买产品"); |
||||
param.put("userId", openId); |
||||
param.put("notifyUrl", CommonSysConst.getSysConfig().getHuiPayPreorderNotifyUrl()); |
||||
param.put("sign", SignatureUtil.createSign(param, merKey)); |
||||
|
||||
log.info("请求地址:" + (REQUEST_URL + "trade/preorder")); |
||||
log.info("请求参数:" + JSONObject.toJSONString(param)); |
||||
|
||||
JSONObject response = HttpsUtils.doPost(REQUEST_URL + "trade/preorder", param, new HashMap<>()); |
||||
log.info("响应参数:" + response.toJSONString()); |
||||
|
||||
if (response != null && response.getString("return_code").equals("000000")) { |
||||
JSONObject payParam = response.getJSONObject("return_data").getJSONObject("payParam"); |
||||
SortedMap<Object, Object> sortedMap = new TreeMap<>(); |
||||
sortedMap.put("appId", payParam.get("app_id")); |
||||
sortedMap.put("nonceStr", payParam.get("nonce_str")); |
||||
sortedMap.put("timeStamp", payParam.get("time_stamp")); |
||||
sortedMap.put("signType", "MD5"); |
||||
sortedMap.put("package", payParam.get("package")); |
||||
sortedMap.put("prepay_id", payParam.get("prepay_id")); |
||||
sortedMap.put("sign", payParam.get("pay_sign")); |
||||
return sortedMap; |
||||
|
||||
} |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, response.getString("return_msg")); |
||||
|
||||
} catch (Exception e) { |
||||
log.info("出现异常:" + e.getMessage()); |
||||
throw e; |
||||
} finally { |
||||
log.info("=============== end 惠支付 end =================="); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 退款 |
||||
* @param merNo |
||||
* @param outTradeNo |
||||
* @param refundTradeNo |
||||
* @param refundAmount |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static JSONObject refund(String merNo,String merKey,String outTradeNo,String refundTradeNo, BigDecimal refundAmount) { |
||||
try { |
||||
log.info("=============== start 惠支付退款 start =================="); |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("merchantNo", merNo); |
||||
param.put("outTradeNo", outTradeNo); |
||||
param.put("refundTradeNo", refundTradeNo); |
||||
param.put("refundAmount", refundAmount); |
||||
param.put("sign" , SignatureUtil.createSign(param, merKey)); |
||||
log.info("请求地址:" + (REQUEST_URL + "trade/preorder")); |
||||
log.info("请求参数:" + JSONObject.toJSONString(param)); |
||||
|
||||
JSONObject response = HttpsUtils.doPost(REQUEST_URL + "trade/refund", param, new HashMap<>()); |
||||
log.info("响应参数:" + response.toJSONString()); |
||||
return response; |
||||
} catch (Exception e) { |
||||
log.info("出现异常"+ e.getMessage()); |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "退款异常"); |
||||
} finally { |
||||
log.info("=============== end 惠支付退款 end =================="); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,94 @@ |
||||
package com.hfkj.service.order; |
||||
|
||||
import com.hfkj.entity.BsGasOrder; |
||||
import com.hfkj.entity.BsMerchantUser; |
||||
import com.hfkj.entity.BsOrderChild; |
||||
import com.hfkj.model.order.OrderModel; |
||||
import com.hfkj.service.BsDeviceService; |
||||
import com.hfkj.service.BsMerchantUserService; |
||||
import com.hfkj.service.gas.BsGasOrderService; |
||||
import com.hfkj.sysenum.MerchantSourceTypeEnum; |
||||
import com.hfkj.sysenum.gas.OrderOilStatus; |
||||
import com.hfkj.sysenum.order.OrderChildProductTypeEnum; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import javax.annotation.Resource; |
||||
|
||||
/** |
||||
* @className: OrderPaySuccessService |
||||
* @author: HuRui |
||||
* @date: 2024/5/7 |
||||
**/ |
||||
@Component |
||||
public class OrderPaySuccessService { |
||||
Logger log = LoggerFactory.getLogger(OrderPaySuccessService.class); |
||||
@Resource |
||||
private BsOrderService orderService; |
||||
@Resource |
||||
private BsGasOrderService gasOrderService; |
||||
@Resource |
||||
private BsMerchantUserService merchantUserService; |
||||
@Resource |
||||
private BsDeviceService deviceService; |
||||
/** |
||||
* 订单业务处理 |
||||
* @param order |
||||
* @throws Exception |
||||
*/ |
||||
public void orderBusHandle(OrderModel order) { |
||||
for (BsOrderChild childOrder : order.getOrderChildList()) { |
||||
try { |
||||
if (childOrder.getProductType().equals(OrderChildProductTypeEnum.type1.getCode())) { |
||||
oilHandle(order); |
||||
} |
||||
} catch (Exception e) { |
||||
|
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 加油业务 |
||||
* @param order |
||||
*/ |
||||
public void oilHandle(OrderModel order) { |
||||
// 查询加油订单
|
||||
BsGasOrder gasOrder = gasOrderService.getDetailByOrderNo(order.getOrderNo()); |
||||
if (gasOrder != null) { |
||||
gasOrder.setTotalDeductionPrice(order.getDeduction().getTotalDeductionPrice()); |
||||
gasOrder.setDeductionCouponPrice(order.getDeduction().getCouponDiscountPrice()); |
||||
gasOrder.setPayIntegral(order.getDeduction().getIntegralDiscountPrice()); |
||||
gasOrder.setPayType(order.getPayType()); |
||||
gasOrder.setPayTime(order.getPayTime()); |
||||
gasOrder.setStatus(OrderOilStatus.STATUS2.getNumber()); |
||||
gasOrderService.updateGasOrder(gasOrder); |
||||
|
||||
if (StringUtils.isNotBlank(gasOrder.getUserPhone())) { |
||||
// 查询商户会员
|
||||
BsMerchantUser merchantUser = merchantUserService.getUser(gasOrder.getMerNo(), gasOrder.getUserPhone()); |
||||
if (merchantUser == null) { |
||||
// 注册商户会员
|
||||
merchantUser = new BsMerchantUser(); |
||||
merchantUser.setMerId(gasOrder.getMerId()); |
||||
merchantUser.setMerNo(gasOrder.getMerNo()); |
||||
merchantUser.setMerName(gasOrder.getMerName()); |
||||
merchantUser.setUserId(gasOrder.getUserId()); |
||||
merchantUser.setUserPhone(gasOrder.getUserPhone()); |
||||
merchantUser.setVipLevel(0); |
||||
merchantUser.setIntegral(0); |
||||
merchantUser.setStatus(1); |
||||
merchantUserService.editData(merchantUser); |
||||
} |
||||
// TODO 赠送积分
|
||||
} |
||||
|
||||
if (gasOrder.getChannelType().equals(MerchantSourceTypeEnum.type1.getNumber())) { |
||||
deviceService.printGasOrder(gasOrder.getMerId(), gasOrder, false ); |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,37 @@ |
||||
package com.hfkj.service.user; |
||||
|
||||
import com.hfkj.entity.BsUser; |
||||
import com.hfkj.entity.BsUserLoginLog; |
||||
import com.hfkj.sysenum.user.UserLoginPlatform; |
||||
import com.hfkj.sysenum.user.UserLoginType; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @className: BsUserLoginLogService |
||||
* @author: HuRui |
||||
* @date: 2024/5/6 |
||||
**/ |
||||
public interface BsUserLoginLogService { |
||||
|
||||
/** |
||||
* 创建 |
||||
* @param userLoginLog |
||||
*/ |
||||
void create(BsUserLoginLog userLoginLog); |
||||
|
||||
/** |
||||
* 异步创建登录日志 |
||||
* @param user |
||||
*/ |
||||
void asyncCreateLog(UserLoginPlatform loginPlatform, UserLoginType loginType, BsUser user, HttpServletRequest request); |
||||
|
||||
/** |
||||
* 查询日志列表 |
||||
* @param param |
||||
* @return |
||||
*/ |
||||
List<BsUserLoginLog> getLogList(Map<String, Object> param); |
||||
} |
@ -0,0 +1,66 @@ |
||||
package com.hfkj.service.user; |
||||
|
||||
import com.hfkj.common.security.SessionObject; |
||||
import com.hfkj.entity.BsUser; |
||||
import com.hfkj.sysenum.user.UserLoginPlatform; |
||||
import com.hfkj.sysenum.user.UserLoginType; |
||||
|
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @className: BsUserService |
||||
* @author: HuRui |
||||
* @date: 2024/6/11 |
||||
**/ |
||||
public interface BsUserService { |
||||
|
||||
/** |
||||
* 编辑数据 |
||||
* @param data |
||||
*/ |
||||
void editData(BsUser data); |
||||
|
||||
/** |
||||
* 获取用户 |
||||
* @param userId 用户id |
||||
* @return |
||||
*/ |
||||
BsUser getUser(Long userId); |
||||
|
||||
/** |
||||
* 获取用户 |
||||
* @param phone 手机号 |
||||
* @return |
||||
*/ |
||||
BsUser getUser(String phone); |
||||
|
||||
/** |
||||
* 查询用户 |
||||
* @param loginPlatform |
||||
* @param code |
||||
* @return |
||||
*/ |
||||
BsUser getUser(UserLoginPlatform loginPlatform, String code); |
||||
|
||||
/** |
||||
* 用户注册 |
||||
* @param phone 手机号 |
||||
* @param other 其他参数 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
BsUser register(String phone, Map<String, Object> other); |
||||
|
||||
/** |
||||
* 用户登录 |
||||
* @param platform 客户端 |
||||
* @param loginType 登录方式 |
||||
* @param phone 手机号 |
||||
* @param other 其他参数 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
SessionObject login(UserLoginPlatform platform, UserLoginType loginType, String phone, Map<String, Object> other) throws Exception; |
||||
|
||||
} |
||||
|
@ -0,0 +1,96 @@ |
||||
package com.hfkj.service.user.impl; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.common.utils.AliyunService; |
||||
import com.hfkj.common.utils.RequestUtils; |
||||
import com.hfkj.dao.BsUserLoginLogMapper; |
||||
import com.hfkj.entity.BsUser; |
||||
import com.hfkj.entity.BsUserLoginLog; |
||||
import com.hfkj.entity.BsUserLoginLogExample; |
||||
import com.hfkj.service.user.BsUserLoginLogService; |
||||
import com.hfkj.sysenum.SecUserLoginLogStatusEnum; |
||||
import com.hfkj.sysenum.user.UserLoginPlatform; |
||||
import com.hfkj.sysenum.user.UserLoginType; |
||||
import org.apache.commons.collections4.MapUtils; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.concurrent.ExecutorService; |
||||
import java.util.concurrent.Executors; |
||||
|
||||
/** |
||||
* @className: BsUserLoginLogServiceImpl |
||||
* @author: HuRui |
||||
* @date: 2024/5/6 |
||||
**/ |
||||
@Service("userLoginLogService") |
||||
public class BsUserLoginLogServiceImpl implements BsUserLoginLogService { |
||||
@Resource |
||||
private BsUserLoginLogMapper userLoginLogMapper; |
||||
|
||||
@Override |
||||
public void create(BsUserLoginLog userLoginLog) { |
||||
userLoginLog.setCreateTime(new Date()); |
||||
userLoginLogMapper.insert(userLoginLog); |
||||
} |
||||
|
||||
@Override |
||||
public void asyncCreateLog(UserLoginPlatform loginPlatform, UserLoginType loginType, BsUser user, HttpServletRequest request) { |
||||
// 创建一个单线程的线程池
|
||||
ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(); |
||||
// 异步记录登录信息
|
||||
singleThreadExecutor.submit(new Runnable() { |
||||
@Override |
||||
public void run() { |
||||
BsUserLoginLog loginLog = new BsUserLoginLog(); |
||||
loginLog.setPlatformCode(loginPlatform.getCode()); |
||||
loginLog.setPlatformName(loginPlatform.getName()); |
||||
loginLog.setLoginTypeCode(loginType.getCode()); |
||||
loginLog.setLoginTypeName(loginType.getName()); |
||||
loginLog.setUserId(user.getId()); |
||||
loginLog.setIp(RequestUtils.getIpAddress(request)); |
||||
// 查询ip归属地
|
||||
JSONObject ipAddress = AliyunService.queryAddress(loginLog.getIp()); |
||||
if (ipAddress != null) { |
||||
loginLog.setCountry(StringUtils.isNotBlank(ipAddress.getString("country"))?ipAddress.getString("country"):"未知"); |
||||
loginLog.setRegionId(StringUtils.isNotBlank(ipAddress.getString("region_id"))?ipAddress.getString("region_id"):null); |
||||
loginLog.setRegionName(StringUtils.isNotBlank(ipAddress.getString("region"))?ipAddress.getString("region"):"未知"); |
||||
loginLog.setCityId(StringUtils.isNotBlank(ipAddress.getString("city_id"))?ipAddress.getString("city_id"):null); |
||||
loginLog.setCityName(StringUtils.isNotBlank(ipAddress.getString("city"))?ipAddress.getString("city"):"未知"); |
||||
loginLog.setIsp(StringUtils.isNotBlank(ipAddress.getString("isp"))?ipAddress.getString("isp"):"未知"); |
||||
loginLog.setStatus(SecUserLoginLogStatusEnum.status1.getCode()); |
||||
} else { |
||||
loginLog.setCountry("未知"); |
||||
loginLog.setRegionName("未知"); |
||||
loginLog.setCityName("未知"); |
||||
loginLog.setIsp("未知"); |
||||
loginLog.setStatus(SecUserLoginLogStatusEnum.status2.getCode()); |
||||
} |
||||
create(loginLog); |
||||
} |
||||
}); |
||||
singleThreadExecutor.shutdown(); |
||||
} |
||||
|
||||
@Override |
||||
public List<BsUserLoginLog> getLogList(Map<String, Object> param) { |
||||
BsUserLoginLogExample example = new BsUserLoginLogExample(); |
||||
BsUserLoginLogExample.Criteria criteria = example.createCriteria(); |
||||
|
||||
if (MapUtils.getLong(param, "userId") != null) { |
||||
criteria.andUserIdEqualTo(MapUtils.getLong(param, "userId")); |
||||
} |
||||
|
||||
if (MapUtils.getInteger(param, "status") != null) { |
||||
criteria.andStatusEqualTo(MapUtils.getInteger(param, "status")); |
||||
} |
||||
|
||||
example.setOrderByClause("create_time desc"); |
||||
return userLoginLogMapper.selectByExample(example); |
||||
} |
||||
} |
@ -0,0 +1,139 @@ |
||||
package com.hfkj.service.user.impl; |
||||
|
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.security.AESEncodeUtil; |
||||
import com.hfkj.common.security.SessionObject; |
||||
import com.hfkj.common.security.UserCenter; |
||||
import com.hfkj.dao.BsUserMapper; |
||||
import com.hfkj.entity.BsUser; |
||||
import com.hfkj.entity.BsUserExample; |
||||
import com.hfkj.model.UserSessionObject; |
||||
import com.hfkj.service.user.BsUserLoginLogService; |
||||
import com.hfkj.service.user.BsUserService; |
||||
import com.hfkj.sysenum.user.UserLoginPlatform; |
||||
import com.hfkj.sysenum.user.UserLoginType; |
||||
import com.hfkj.sysenum.user.UserStatusEnum; |
||||
import org.apache.commons.collections4.MapUtils; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.web.context.request.RequestAttributes; |
||||
import org.springframework.web.context.request.RequestContextHolder; |
||||
|
||||
import javax.annotation.Resource; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @className: BsUserServiceImpl |
||||
* @author: HuRui |
||||
* @date: 2024/6/11 |
||||
**/ |
||||
@Service("bsUserService") |
||||
public class BsUserServiceImpl implements BsUserService { |
||||
@Resource |
||||
private BsUserMapper userMapper; |
||||
@Resource |
||||
private UserCenter userCenter; |
||||
@Resource |
||||
private BsUserLoginLogService userLoginLogService; |
||||
|
||||
@Override |
||||
public void editData(BsUser data) { |
||||
data.setUpdateTime(new Date()); |
||||
if (data.getId() == null) { |
||||
data.setCreateTime(new Date()); |
||||
userMapper.insert(data); |
||||
} else { |
||||
userMapper.updateByPrimaryKey(data); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public BsUser getUser(Long userId) { |
||||
return userMapper.selectByPrimaryKey(userId); |
||||
} |
||||
|
||||
@Override |
||||
public BsUser getUser(String phone) { |
||||
BsUserExample example = new BsUserExample(); |
||||
example.createCriteria() |
||||
.andPhoneEqualTo(phone) |
||||
.andStatusNotEqualTo(UserStatusEnum.status0.getCode()); |
||||
List<BsUser> list = userMapper.selectByExample(example); |
||||
if (!list.isEmpty()) { |
||||
return list.get(0); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public BsUser getUser(UserLoginPlatform loginPlatform, String code) { |
||||
BsUserExample example = new BsUserExample(); |
||||
BsUserExample.Criteria criteria = example.createCriteria().andStatusNotEqualTo(UserStatusEnum.status0.getCode()); |
||||
if (UserLoginPlatform.H5.getCode().equals(loginPlatform.getCode())) { |
||||
criteria.andWxMpOpenIdEqualTo(code); |
||||
} else if (UserLoginPlatform.WXAPPLETS.getCode().equals(loginPlatform.getCode())) { |
||||
criteria.andWxMaOpenIdEqualTo(code); |
||||
} else if (UserLoginPlatform.ALIPAY.getCode().equals(loginPlatform.getCode())) { |
||||
criteria.andAlipayOpenIdEqualTo(code); |
||||
} |
||||
List<BsUser> list = userMapper.selectByExample(example); |
||||
if (!list.isEmpty()) { |
||||
return list.get(0); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public BsUser register(String phone, Map<String, Object> other) { |
||||
// 查询手机号
|
||||
if (getUser(phone) != null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "用户手机号已存在,请更换"); |
||||
} |
||||
BsUser user = new BsUser(); |
||||
user.setPhone(phone); |
||||
user.setWxMaOpenId(MapUtils.getString(other, "wxMaOpenId")); |
||||
user.setWxMpOpenId(MapUtils.getString(other, "wxMpOpenId")); |
||||
user.setStatus(UserStatusEnum.status1.getCode()); |
||||
editData(user); |
||||
|
||||
user.setUserName("用户"+user.getId()); |
||||
editData(user); |
||||
return user; |
||||
} |
||||
|
||||
/** |
||||
* 生成token |
||||
* @param user 用户 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public String token(BsUser user) throws Exception { |
||||
// token 生成格式:账户id
|
||||
return AESEncodeUtil.aesEncrypt(user.getId().toString()); |
||||
} |
||||
|
||||
@Override |
||||
public SessionObject login(UserLoginPlatform platform, UserLoginType loginType, String phone, Map<String, Object> other) throws Exception { |
||||
// 查询用户
|
||||
BsUser user = getUser(phone); |
||||
if (user == null) { |
||||
user = register(phone, other); |
||||
} |
||||
|
||||
// 缓存
|
||||
UserSessionObject session = new UserSessionObject(); |
||||
session.setUser(user); |
||||
|
||||
SessionObject sessionObject = new SessionObject(token(user), session); |
||||
userCenter.save(sessionObject); |
||||
// 异步记录登录信息
|
||||
userLoginLogService.asyncCreateLog(platform, loginType, user, (HttpServletRequest) RequestContextHolder.getRequestAttributes().resolveReference(RequestAttributes.REFERENCE_REQUEST)); |
||||
return sessionObject; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,35 @@ |
||||
package com.hfkj.sysenum; |
||||
|
||||
import lombok.Getter; |
||||
|
||||
import java.util.Objects; |
||||
|
||||
/** |
||||
* @className: MerchantStatusEnum |
||||
* @author: HuRui |
||||
* @date: 2024/6/11 |
||||
**/ |
||||
@Getter |
||||
public enum MerchantSourceTypeEnum { |
||||
type1(1, "自建站"), |
||||
; |
||||
|
||||
private Integer number; |
||||
|
||||
private String name; |
||||
|
||||
MerchantSourceTypeEnum(int number, String name) { |
||||
this.number = number; |
||||
this.name = name; |
||||
} |
||||
|
||||
public static MerchantSourceTypeEnum getNameByType(Integer type) { |
||||
for (MerchantSourceTypeEnum ele : values()) { |
||||
if (Objects.equals(type,ele.getNumber())) { |
||||
return ele; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,53 @@ |
||||
package com.hfkj.sysenum.user; |
||||
|
||||
import java.util.Objects; |
||||
|
||||
/** |
||||
* 登录平台 |
||||
* @className: LoginType |
||||
* @author: HuRui |
||||
* @date: 2022/10/20 |
||||
**/ |
||||
public enum UserLoginPlatform { |
||||
H5("H5", "H5客户端"), |
||||
WXAPPLETS("WXAPPLETS", "微信小程序"), |
||||
ALIPAY("ALIPAY", "支付宝H5"), |
||||
; |
||||
|
||||
private String code; |
||||
|
||||
private String name; |
||||
|
||||
UserLoginPlatform(String code, String name) { |
||||
this.code = code; |
||||
this.name = name; |
||||
} |
||||
|
||||
/** |
||||
* 根据类型查询数据 |
||||
* @param code |
||||
* @return |
||||
*/ |
||||
public static UserLoginPlatform getDataByType(String code) { |
||||
for (UserLoginPlatform ele : values()) { |
||||
if(Objects.equals(code,ele.getCode())) return ele; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public String getCode() { |
||||
return code; |
||||
} |
||||
|
||||
public void setCode(String code) { |
||||
this.code = code; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
} |
@ -0,0 +1,54 @@ |
||||
package com.hfkj.sysenum.user; |
||||
|
||||
import java.util.Objects; |
||||
|
||||
/** |
||||
* 登录方式 |
||||
* @className: LoginType |
||||
* @author: HuRui |
||||
* @date: 2022/10/20 |
||||
**/ |
||||
public enum UserLoginType { |
||||
SMS("SMS", "短信登录"), |
||||
WECHAT_MA_PHONE("WECHAT_MA_PHONE", "微信小程序手机号"), |
||||
WECHAT_MA_OPENID("WECHAT_MA_OPENID", "微信小程序openId"), |
||||
WECHAT_MP_OPENID("WECHAT_MP_OPENID", "微信公众号openId"), |
||||
; |
||||
|
||||
private String code; |
||||
|
||||
private String name; |
||||
|
||||
UserLoginType(String code, String name) { |
||||
this.code = code; |
||||
this.name = name; |
||||
} |
||||
|
||||
/** |
||||
* 根据类型查询数据 |
||||
* @param code |
||||
* @return |
||||
*/ |
||||
public static UserLoginType getDataByType(String code) { |
||||
for (UserLoginType ele : values()) { |
||||
if(Objects.equals(code,ele.getCode())) return ele; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public String getCode() { |
||||
return code; |
||||
} |
||||
|
||||
public void setCode(String code) { |
||||
this.code = code; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
} |
@ -0,0 +1,50 @@ |
||||
package com.hfkj.sysenum.user; |
||||
|
||||
/** |
||||
* @className: UserStatusEnum |
||||
* @author: HuRui |
||||
* @date: 2024/5/6 |
||||
**/ |
||||
public enum UserStatusEnum { |
||||
/** |
||||
* 删除 |
||||
*/ |
||||
status0(0, "删除"), |
||||
|
||||
/** |
||||
* 正常 |
||||
*/ |
||||
status1(1, "正常"), |
||||
|
||||
/** |
||||
* 禁用 |
||||
*/ |
||||
status2(2, "禁用"), |
||||
; |
||||
|
||||
private int code; |
||||
|
||||
private String name; |
||||
|
||||
|
||||
UserStatusEnum(int code, String name) { |
||||
this.code = code; |
||||
this.name = name; |
||||
} |
||||
|
||||
public int getCode() { |
||||
return code; |
||||
} |
||||
|
||||
public void setCode(int code) { |
||||
this.code = code; |
||||
} |
||||
|
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
} |
@ -0,0 +1 @@ |
||||
huiPayPreorderNotifyUrl=https://test-oil.dctpay.com/crest/notify/huipay |
Loading…
Reference in new issue