parent
1b5a7cd753
commit
08dad6795a
@ -0,0 +1,113 @@ |
||||
package com.cweb.controller; |
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.common.security.UserCenter; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.common.utils.WxUtils; |
||||
import com.hfkj.entity.BsUserSpreadAccount; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.model.UserSessionObject; |
||||
import com.hfkj.service.gas.BsGasOrderSpreadService; |
||||
import com.hfkj.service.spread.BsUserSpreadAccountRecordService; |
||||
import com.hfkj.service.spread.BsUserSpreadAccountService; |
||||
import com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import org.apache.http.HttpEntity; |
||||
import org.apache.http.HttpHeaders; |
||||
import org.apache.http.client.methods.CloseableHttpResponse; |
||||
import org.apache.http.client.methods.HttpPost; |
||||
import org.apache.http.entity.StringEntity; |
||||
import org.apache.http.impl.client.CloseableHttpClient; |
||||
import org.apache.http.util.EntityUtils; |
||||
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.math.BigDecimal; |
||||
import java.util.HashMap; |
||||
import java.util.LinkedList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @className: BsUserSpreadAccountController |
||||
* @author: HuRui |
||||
* @date: 2025/3/31 |
||||
**/ |
||||
@Controller |
||||
@RequestMapping(value = "/test") |
||||
@Api(value = "个人推广账户业务") |
||||
public class TestController { |
||||
private static Logger log = LoggerFactory.getLogger(TestController.class); |
||||
@Resource |
||||
private UserCenter userCenter; |
||||
@Resource |
||||
private BsUserSpreadAccountService userSpreadAccountService; |
||||
@Resource |
||||
private BsGasOrderSpreadService gasOrderSpreadService; |
||||
|
||||
@RequestMapping(value = "/settleOrder", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "结算订单") |
||||
public ResponseData settleOrder() { |
||||
try { |
||||
gasOrderSpreadService.settleOrder(4L); |
||||
|
||||
return ResponseMsgUtil.success(""); |
||||
|
||||
} catch (Exception e) { |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
|
||||
@RequestMapping(value = "/transferBills", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "转账交易") |
||||
public ResponseData transferBills() { |
||||
try { |
||||
|
||||
JSONObject obj = WxUtils.transferBills("oUGn_4unIjp90MY-oEXluY4laDrQ",""+System.currentTimeMillis(), new BigDecimal("0.1"), "推广佣金提现"); |
||||
|
||||
System.out.println("响应内容:"+obj); |
||||
return ResponseMsgUtil.success(obj); |
||||
|
||||
} catch (Exception e) { |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/cancelTransferBills", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "取消转账") |
||||
public ResponseData cancelTransferBills(@RequestParam(value = "outBillNo", required = true) String outBillNo) { |
||||
try { |
||||
|
||||
return ResponseMsgUtil.success(WxUtils.cancelTransferBills(outBillNo)); |
||||
|
||||
} catch (Exception e) { |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping(value = "/queryTransferBills", method = RequestMethod.GET) |
||||
@ResponseBody |
||||
@ApiOperation(value = "查询转账详情") |
||||
public ResponseData queryTransferBills(@RequestParam(value = "outBillNo", required = true) String outBillNo) { |
||||
try { |
||||
|
||||
return ResponseMsgUtil.success(WxUtils.queryTransferBills(outBillNo)); |
||||
|
||||
} catch (Exception e) { |
||||
return ResponseMsgUtil.exception(e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,86 @@ |
||||
package com.cweb.controller; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.common.Base64Util; |
||||
import com.hfkj.common.utils.DateUtil; |
||||
import com.hfkj.common.utils.ResponseMsgUtil; |
||||
import com.hfkj.entity.BsUserSpreadAccountRecord; |
||||
import com.hfkj.model.ResponseData; |
||||
import com.hfkj.service.spread.BsUserSpreadAccountRecordService; |
||||
import com.hfkj.service.spread.BsUserSpreadAccountService; |
||||
import com.hfkj.sysenum.spread.UserSpreadAccountRecordSourceTypeEnum; |
||||
import com.wechat.pay.contrib.apache.httpclient.util.AesUtil; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
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.BufferedOutputStream; |
||||
import java.util.Date; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @className: WeiXinNotifyController |
||||
* @author: HuRui |
||||
* @date: 2025/4/10 |
||||
**/ |
||||
@Controller |
||||
@RequestMapping(value = "/wexinNotify") |
||||
@Api(value = "微信通知") |
||||
public class WeiXinNotifyController { |
||||
@Resource |
||||
private BsUserSpreadAccountRecordService userSpreadAccountRecordService; |
||||
@Resource |
||||
private BsUserSpreadAccountService userSpreadAccountService; |
||||
|
||||
@RequestMapping(value = "/withdraw", method = RequestMethod.POST) |
||||
@ResponseBody |
||||
@ApiOperation(value = "提现通知") |
||||
public void withdraw(@RequestBody JSONObject body, HttpServletResponse response) { |
||||
try { |
||||
System.out.println("提现通知:"+body.toJSONString()); |
||||
|
||||
JSONObject resource = body.getJSONObject("resource"); |
||||
// 解析后的数据
|
||||
String dataStr = new AesUtil("UXt3EGM5X6P71EXcNmszV1ONk7LX9IEj".getBytes()) |
||||
.decryptToString( |
||||
resource.getString("associated_data").getBytes(), |
||||
resource.getString("nonce").getBytes(), |
||||
resource.getString("ciphertext")); |
||||
|
||||
JSONObject data = JSONObject.parseObject(dataStr); |
||||
String outBillNo = data.getString("out_bill_no"); |
||||
|
||||
// 记录
|
||||
BsUserSpreadAccountRecord record = userSpreadAccountRecordService.getRecordByOrderNo(outBillNo); |
||||
if (record != null) { |
||||
String state = data.getString("state"); |
||||
if (state.equals("CANCELLED") || state.equals("FAIL")) { |
||||
// 充值余账户余额
|
||||
Map<String,Object> otherParam = new HashMap<>(); |
||||
otherParam.put("sourceContent", state.equals("CANCELLED")?"撤销提现":"转账失败"); |
||||
otherParam.put("sourceOrderNo", DateUtil.date2String(new Date(), DateUtil.YMDHMS)); |
||||
userSpreadAccountService.increase(record.getUserId(), record.getTransactionAmount(), UserSpreadAccountRecordSourceTypeEnum.type4, otherParam); |
||||
} |
||||
} |
||||
|
||||
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); |
||||
JSONObject result = new JSONObject(); |
||||
result.put("code", "SUCCESS"); |
||||
result.put("message", ""); |
||||
out.write(result.toJSONString().getBytes()); |
||||
out.flush(); |
||||
out.close(); |
||||
|
||||
} catch (Exception e) { |
||||
System.out.println("提现通知出现异常:"+e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,373 +1,163 @@ |
||||
package com.hfkj.common.utils; |
||||
|
||||
import com.google.common.collect.Maps; |
||||
import com.hfkj.common.pay.util.sdk.WXPayConstants; |
||||
import com.hfkj.common.pay.util.sdk.WXPayXmlUtil; |
||||
import com.thoughtworks.xstream.XStream; |
||||
import com.thoughtworks.xstream.io.naming.NoNameCoder; |
||||
import com.thoughtworks.xstream.io.xml.XppDriver; |
||||
import net.sf.cglib.beans.BeanMap; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
|
||||
import javax.crypto.Mac; |
||||
import javax.crypto.spec.SecretKeySpec; |
||||
import javax.xml.transform.OutputKeys; |
||||
import javax.xml.transform.Transformer; |
||||
import javax.xml.transform.TransformerFactory; |
||||
import javax.xml.transform.dom.DOMSource; |
||||
import javax.xml.transform.stream.StreamResult; |
||||
import java.io.StringWriter; |
||||
import java.security.MessageDigest; |
||||
import java.security.SecureRandom; |
||||
import java.util.*; |
||||
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.config.CommonSysConst; |
||||
import com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder; |
||||
import com.wechat.pay.contrib.apache.httpclient.auth.PrivateKeySigner; |
||||
import com.wechat.pay.contrib.apache.httpclient.auth.Verifier; |
||||
import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Credentials; |
||||
import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Validator; |
||||
import com.wechat.pay.contrib.apache.httpclient.cert.CertificatesManager; |
||||
import com.wechat.pay.contrib.apache.httpclient.exception.HttpCodeException; |
||||
import com.wechat.pay.contrib.apache.httpclient.exception.NotFoundException; |
||||
import com.wechat.pay.contrib.apache.httpclient.util.PemUtil; |
||||
import org.apache.http.HttpEntity; |
||||
import org.apache.http.HttpHeaders; |
||||
import org.apache.http.client.methods.CloseableHttpResponse; |
||||
import org.apache.http.client.methods.HttpGet; |
||||
import org.apache.http.client.methods.HttpPost; |
||||
import org.apache.http.entity.StringEntity; |
||||
import org.apache.http.impl.client.CloseableHttpClient; |
||||
import org.apache.http.util.EntityUtils; |
||||
|
||||
import java.io.FileInputStream; |
||||
import java.io.IOException; |
||||
import java.math.BigDecimal; |
||||
import java.nio.charset.StandardCharsets; |
||||
import java.security.GeneralSecurityException; |
||||
import java.security.PrivateKey; |
||||
import java.util.HashMap; |
||||
import java.util.LinkedList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
public class WxUtils { |
||||
|
||||
private static final Random RANDOM = new SecureRandom(); |
||||
|
||||
private static final String SYMBOLS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
||||
|
||||
// 微信请求地址
|
||||
private final static String REQ_URL = "https://api.mch.weixin.qq.com"; |
||||
// 商户号
|
||||
private final static String merchantId = "1614670195"; |
||||
// 商户证书编号
|
||||
private final static String merchantSerialNumber = "6E73923625A838DEA31C7BAA66938AD6281D698F"; |
||||
// APIv3密钥
|
||||
private final static String apiV3Key = "UXt3EGM5X6P71EXcNmszV1ONk7LX9IEj"; |
||||
|
||||
/** |
||||
* 生成签名 |
||||
* |
||||
* @param signMaps |
||||
* 获取请求 |
||||
* @return |
||||
* @throws Exception |
||||
* @throws GeneralSecurityException |
||||
* @throws IOException |
||||
* @throws HttpCodeException |
||||
* @throws NotFoundException |
||||
*/ |
||||
public static String generateSign(SortedMap<String, String> signMaps, String mchKey) { |
||||
StringBuffer sb = new StringBuffer(); |
||||
|
||||
// 字典序
|
||||
for (Map.Entry signMap : signMaps.entrySet()) { |
||||
String key = (String) signMap.getKey(); |
||||
String value = (String) signMap.getValue(); |
||||
|
||||
// 为空不参与签名、参数名区分大小写
|
||||
if (null != value && !"".equals(value) && !"sign".equals(key) && !"key".equals(key)) { |
||||
sb.append(key).append("=").append(value).append("&"); |
||||
} |
||||
} |
||||
|
||||
// 拼接key
|
||||
sb.append("key=").append(mchKey); |
||||
// MD5加密
|
||||
String sign = MD5Encode(sb.toString(), "UTF-8").toUpperCase(); |
||||
return sign; |
||||
} |
||||
|
||||
public static String generateSignSHA256(SortedMap<String, String> signMaps,String mchKey)throws Exception{ |
||||
StringBuffer sb = new StringBuffer(); |
||||
|
||||
// 字典序
|
||||
for (Map.Entry signMap : signMaps.entrySet()) { |
||||
String key = (String) signMap.getKey(); |
||||
String value = (String) signMap.getValue(); |
||||
|
||||
// 为空不参与签名、参数名区分大小写
|
||||
if (null != value && !"".equals(value) && !"sign".equals(key) && !"key".equals(key)) { |
||||
sb.append(key).append("=").append(value).append("&"); |
||||
} |
||||
} |
||||
|
||||
// 拼接key
|
||||
sb.append("key=").append(mchKey); |
||||
// HMACSHA256加密
|
||||
String sign = HMACSHA256(sb.toString(), mchKey).toUpperCase(); |
||||
return sign; |
||||
} |
||||
|
||||
private static String byteArrayToHexString(byte b[]) { |
||||
StringBuffer resultSb = new StringBuffer(); |
||||
for (int i = 0; i < b.length; i++) |
||||
resultSb.append(byteToHexString(b[i])); |
||||
|
||||
return resultSb.toString(); |
||||
} |
||||
|
||||
private static String byteToHexString(byte b) { |
||||
int n = b; |
||||
if (n < 0) |
||||
n += 256; |
||||
int d1 = n / 16; |
||||
int d2 = n % 16; |
||||
return hexDigits[d1] + hexDigits[d2]; |
||||
} |
||||
|
||||
public static String MD5Encode(String origin, String charsetname) { |
||||
String resultString = null; |
||||
try { |
||||
resultString = new String(origin); |
||||
MessageDigest md = MessageDigest.getInstance("MD5"); |
||||
if (charsetname == null || "".equals(charsetname)) |
||||
resultString = byteArrayToHexString(md.digest(resultString |
||||
.getBytes())); |
||||
else |
||||
resultString = byteArrayToHexString(md.digest(resultString |
||||
.getBytes(charsetname))); |
||||
} catch (Exception exception) { |
||||
} |
||||
return resultString; |
||||
} |
||||
|
||||
private static final String[] hexDigits = { "0", "1", "2", "3", "4", "5", |
||||
"6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; |
||||
|
||||
|
||||
|
||||
private static HashMap<String, String> sortAsc(Map<String, String> map) { |
||||
HashMap<String, String> tempMap = new LinkedHashMap<String, String>(); |
||||
List<Map.Entry<String, String>> infoIds = new ArrayList<Map.Entry<String, String>>(map.entrySet()); |
||||
//排序
|
||||
infoIds.sort(new Comparator<Map.Entry<String, String>>() { |
||||
@Override |
||||
public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> o2) { |
||||
return o1.getKey().compareTo(o2.getKey()); |
||||
} |
||||
}); |
||||
|
||||
for (int i = 0; i < infoIds.size(); i++) { |
||||
Map.Entry<String, String> item = infoIds.get(i); |
||||
tempMap.put(item.getKey(), item.getValue()); |
||||
} |
||||
return tempMap; |
||||
} |
||||
|
||||
|
||||
|
||||
/** |
||||
* 生成 HMACSHA256 |
||||
* @param data 待处理数据 |
||||
* @param key 密钥 |
||||
* @return 加密结果 |
||||
* @throws Exception |
||||
*/ |
||||
public static String HMACSHA256(String data, String key) throws Exception { |
||||
Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); |
||||
SecretKeySpec secret_key = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA256"); |
||||
sha256_HMAC.init(secret_key); |
||||
byte[] array = sha256_HMAC.doFinal(data.getBytes("UTF-8")); |
||||
StringBuilder sb = new StringBuilder(); |
||||
for (byte item : array) { |
||||
sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3)); |
||||
} |
||||
return sb.toString().toUpperCase(); |
||||
} |
||||
|
||||
/** |
||||
* 获取随机字符串 Nonce Str |
||||
* |
||||
* @return String 随机字符串 |
||||
*/ |
||||
public static String makeNonStr() { |
||||
char[] nonceChars = new char[32]; |
||||
for (int index = 0; index < nonceChars.length; ++index) { |
||||
nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length())); |
||||
} |
||||
return new String(nonceChars); |
||||
public static CloseableHttpClient getHttpClient() throws GeneralSecurityException, IOException, HttpCodeException, NotFoundException { |
||||
// 私钥文件路径
|
||||
PrivateKey merchantPrivateKey = PemUtil.loadPrivateKey(new FileInputStream("/home/project/oil/cert/wechat/1614670195/apiclient_key.pem")); |
||||
CertificatesManager certificatesManager = CertificatesManager.getInstance(); |
||||
certificatesManager.putMerchant(merchantId, new WechatPay2Credentials(merchantId, |
||||
new PrivateKeySigner(merchantSerialNumber, merchantPrivateKey)), |
||||
apiV3Key.getBytes(StandardCharsets.UTF_8)); |
||||
Verifier verifier = certificatesManager.getVerifier(merchantId); |
||||
WechatPayHttpClientBuilder builder = WechatPayHttpClientBuilder.create() |
||||
.withMerchant(merchantId, merchantSerialNumber, merchantPrivateKey) |
||||
.withValidator(new WechatPay2Validator(verifier)); |
||||
return builder.build(); |
||||
} |
||||
|
||||
/** |
||||
* 拼接签名数据 |
||||
* |
||||
*/ |
||||
public static String makeSign(BeanMap beanMap, String mchKey, String signType)throws Exception { |
||||
SortedMap<String, String> signMaps = Maps.newTreeMap(); |
||||
|
||||
for (Object key : beanMap.keySet()) { |
||||
Object value = beanMap.get(key); |
||||
|
||||
// 排除空数据
|
||||
if (value == null) { |
||||
continue; |
||||
} |
||||
signMaps.put(key + "", String.valueOf(value)); |
||||
} |
||||
if(signType.equals("MD5")) { |
||||
// 生成签名
|
||||
return generateSign(signMaps, mchKey); |
||||
}else if(signType.equals("SHA256")){ |
||||
return generateSignSHA256(signMaps, mchKey); |
||||
}else{ |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 数据转换为xml格式 |
||||
* |
||||
* @param object |
||||
* @param obj |
||||
* 商家转账 |
||||
* @param openId |
||||
* @param transferAmount |
||||
* @return |
||||
* @throws GeneralSecurityException |
||||
* @throws NotFoundException |
||||
* @throws IOException |
||||
* @throws HttpCodeException |
||||
*/ |
||||
public static String truncateDataToXML(Class<?> object, Object obj) { |
||||
XStream xStream = new XStream(new XppDriver(new NoNameCoder())); |
||||
xStream.alias("xml", object); |
||||
return xStream.toXML(obj); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 生成签名. 注意,若含有sign_type字段,必须和signType参数保持一致。 |
||||
* |
||||
* @param data 待签名数据 |
||||
* @param key API密钥 |
||||
* @param signType 签名方式 |
||||
* @return 签名 |
||||
*/ |
||||
public static String generateSignature(final Map<String, String> data, String key, WXPayConstants.SignType signType) throws Exception { |
||||
Set<String> keySet = data.keySet(); |
||||
String[] keyArray = keySet.toArray(new String[keySet.size()]); |
||||
Arrays.sort(keyArray); |
||||
StringBuilder sb = new StringBuilder(); |
||||
for (String k : keyArray) { |
||||
if (k.equals(WXPayConstants.FIELD_SIGN)) { |
||||
continue; |
||||
} |
||||
if (data.get(k).trim().length() > 0) // 参数值为空,则不参与签名
|
||||
sb.append(k).append("=").append(data.get(k).trim()).append("&"); |
||||
} |
||||
sb.append("key=").append(key); |
||||
if (WXPayConstants.SignType.MD5.equals(signType)) { |
||||
return MD5(sb.toString() , true); |
||||
} |
||||
else if (WXPayConstants.SignType.HMACSHA256.equals(signType)) { |
||||
return HMACSHA256(sb.toString(), key); |
||||
} |
||||
else { |
||||
throw new Exception(String.format("Invalid sign_type: %s", signType)); |
||||
} |
||||
} |
||||
|
||||
public static String generateSignature(final Map<String, Object> data) throws Exception { |
||||
Set<String> keySet = data.keySet(); |
||||
String[] keyArray = keySet.toArray(new String[keySet.size()]); |
||||
Arrays.sort(keyArray); |
||||
StringBuilder sb = new StringBuilder(); |
||||
for (String k : keyArray) { |
||||
if (k.equals(WXPayConstants.FIELD_SIGN)) { |
||||
continue; |
||||
} |
||||
if (StringUtils.isBlank(sb.toString())) { |
||||
sb.append(k).append("=").append(data.get(k)); |
||||
} else { |
||||
sb.append("&").append(k).append("=").append(data.get(k)); |
||||
} |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
|
||||
public static String generateSignature2(final Map<String, Object> data, String sign, String key) throws Exception { |
||||
Set<String> keySet = data.keySet(); |
||||
String[] keyArray = keySet.toArray(new String[keySet.size()]); |
||||
Arrays.sort(keyArray); |
||||
StringBuilder sb = new StringBuilder(); |
||||
for (String k : keyArray) { |
||||
if (k.equals(WXPayConstants.FIELD_SIGN)) { |
||||
continue; |
||||
} |
||||
if (data.get(k) != null) // 参数值为空,则不参与签名
|
||||
sb.append(k).append("=").append(data.get(k)).append("&"); |
||||
} |
||||
if (key != null) { |
||||
sb.append("app_secret=").append(key); |
||||
} |
||||
return sb.toString(); |
||||
public static JSONObject transferBills(String openId,String outBillNo, BigDecimal transferAmount, String transferRemark) throws GeneralSecurityException, NotFoundException, IOException, HttpCodeException { |
||||
JSONObject body = new JSONObject(); |
||||
body.put("appid", CommonSysConst.getSysConfig().getWxMaAppId()); |
||||
body.put("out_bill_no", outBillNo); |
||||
body.put("transfer_scene_id", "1000"); |
||||
body.put("openid", openId); |
||||
body.put("transfer_amount", transferAmount.multiply(new BigDecimal("100")).intValue()); |
||||
// body.put("openid", "oUGn_4unIjp90MY-oEXluY4laDrQ");
|
||||
// body.put("transfer_amount", 1);
|
||||
body.put("transfer_remark", transferRemark); |
||||
body.put("notify_url", CommonSysConst.getSysConfig().getDomainName()+"/crest/wexinNotify/withdraw"); |
||||
|
||||
List<Map<String,Object>> transferSceneReportInfosList = new LinkedList<>(); |
||||
Map<String,Object> transferSceneReportInfos = new HashMap<>(); |
||||
transferSceneReportInfos.put("info_type","活动名称"); |
||||
transferSceneReportInfos.put("info_content","推广有礼"); |
||||
transferSceneReportInfosList.add(transferSceneReportInfos); |
||||
Map<String,Object> transferSceneReportInfos2 = new HashMap<>(); |
||||
transferSceneReportInfos2.put("info_type","奖励说明"); |
||||
transferSceneReportInfos2.put("info_content","推广佣金"); |
||||
transferSceneReportInfosList.add(transferSceneReportInfos2); |
||||
body.put("transfer_scene_report_infos", transferSceneReportInfosList); |
||||
|
||||
HttpPost httpPost = new HttpPost(REQ_URL+"/v3/fund-app/mch-transfer/transfer-bills"); |
||||
httpPost.setEntity(new StringEntity(body.toJSONString(), "utf-8")); |
||||
httpPost.setHeader(HttpHeaders.ACCEPT, "application/json"); |
||||
httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "application/json"); |
||||
|
||||
CloseableHttpResponse httpResponse = WxUtils.getHttpClient().execute(httpPost); |
||||
HttpEntity entity = httpResponse.getEntity(); |
||||
JSONObject responseData = JSONObject.parseObject(EntityUtils.toString(entity)); |
||||
if (httpResponse.getStatusLine().getStatusCode() != 200) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseData.getString("message")); |
||||
} |
||||
return responseData; |
||||
} |
||||
|
||||
/** |
||||
* 生成 MD5 |
||||
* |
||||
* @param data 待处理数据 |
||||
* @return MD5结果 |
||||
* 撤销转账 |
||||
* @param outBillNo |
||||
* @return |
||||
* @throws GeneralSecurityException |
||||
* @throws NotFoundException |
||||
* @throws IOException |
||||
* @throws HttpCodeException |
||||
*/ |
||||
public static String MD5(String data , Boolean isUpperCase) throws Exception { |
||||
java.security.MessageDigest md = MessageDigest.getInstance("MD5"); |
||||
byte[] array = md.digest(data.getBytes("UTF-8")); |
||||
StringBuilder sb = new StringBuilder(); |
||||
for (byte item : array) { |
||||
sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3)); |
||||
} |
||||
if (isUpperCase) { |
||||
return sb.toString().toUpperCase(); |
||||
} else { |
||||
return sb.toString(); |
||||
} |
||||
} |
||||
|
||||
|
||||
public static JSONObject cancelTransferBills(String outBillNo) throws GeneralSecurityException, NotFoundException, IOException, HttpCodeException { |
||||
HttpPost httpPost = new HttpPost(REQ_URL+"/v3/fund-app/mch-transfer/transfer-bills/out-bill-no/"+outBillNo+"/cancel"); |
||||
httpPost.setHeader(HttpHeaders.ACCEPT, "application/json"); |
||||
httpPost.setHeader(HttpHeaders.CONTENT_TYPE, "application/json"); |
||||
|
||||
/** |
||||
* 将Map转换为XML格式的字符串 |
||||
* |
||||
* @param data Map类型数据 |
||||
* @return XML格式的字符串 |
||||
* @throws Exception |
||||
*/ |
||||
public static String mapToXml(Map<String, String> data) throws Exception { |
||||
org.w3c.dom.Document document = WXPayXmlUtil.newDocument(); |
||||
org.w3c.dom.Element root = document.createElement("xml"); |
||||
document.appendChild(root); |
||||
for (String key: data.keySet()) { |
||||
String value = data.get(key); |
||||
if (value == null) { |
||||
value = ""; |
||||
} |
||||
value = value.trim(); |
||||
org.w3c.dom.Element filed = document.createElement(key); |
||||
filed.appendChild(document.createTextNode(value)); |
||||
root.appendChild(filed); |
||||
} |
||||
TransformerFactory tf = TransformerFactory.newInstance(); |
||||
Transformer transformer = tf.newTransformer(); |
||||
DOMSource source = new DOMSource(document); |
||||
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); |
||||
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); |
||||
StringWriter writer = new StringWriter(); |
||||
StreamResult result = new StreamResult(writer); |
||||
transformer.transform(source, result); |
||||
String output = writer.getBuffer().toString(); //.replaceAll("\n|\r", "");
|
||||
try { |
||||
writer.close(); |
||||
httpPost.setEntity(new StringEntity("", "utf-8")); |
||||
CloseableHttpResponse httpResponse = WxUtils.getHttpClient().execute(httpPost); |
||||
HttpEntity entity = httpResponse.getEntity(); |
||||
JSONObject responseData = JSONObject.parseObject(EntityUtils.toString(entity)); |
||||
if (httpResponse.getStatusLine().getStatusCode() != 200) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseData.getString("message")); |
||||
} |
||||
catch (Exception ex) { |
||||
} |
||||
return output; |
||||
return responseData; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 千猪生成签名。 |
||||
* |
||||
* @param data 待签名数据 |
||||
* @param secret API密钥 |
||||
* @param signType 签名方式 |
||||
* @return 签名 |
||||
* 查询转账详情 |
||||
* @param outBillNo |
||||
* @return |
||||
* @throws GeneralSecurityException |
||||
* @throws NotFoundException |
||||
* @throws IOException |
||||
* @throws HttpCodeException |
||||
*/ |
||||
public static String generateSignaturePig(final Map<String, String> data, String secret, WXPayConstants.SignType signType) throws Exception { |
||||
Set<String> keySet = data.keySet(); |
||||
String[] keyArray = keySet.toArray(new String[keySet.size()]); |
||||
Arrays.sort(keyArray); |
||||
StringBuilder sb = new StringBuilder(); |
||||
for (String k : keyArray) { |
||||
if (k.equals(WXPayConstants.FIELD_SIGN)) { |
||||
continue; |
||||
} |
||||
if (data.get(k).trim().length() > 0) // 参数值为空,则不参与签名
|
||||
sb.append(k).append("=").append(data.get(k).trim()).append("&"); |
||||
} |
||||
String s = sb.substring(0, sb.length() - 1) + secret; |
||||
public static JSONObject queryTransferBills(String outBillNo) throws GeneralSecurityException, NotFoundException, IOException, HttpCodeException { |
||||
HttpGet httpGet = new HttpGet(REQ_URL+"/v3/fund-app/mch-transfer/transfer-bills/out-bill-no/"+outBillNo); |
||||
httpGet.setHeader(HttpHeaders.ACCEPT, "application/json"); |
||||
httpGet.setHeader(HttpHeaders.CONTENT_TYPE, "application/json"); |
||||
|
||||
if (WXPayConstants.SignType.MD5.equals(signType)) { |
||||
return MD5(sb.toString() , false); |
||||
} |
||||
else if (WXPayConstants.SignType.HMACSHA256.equals(signType)) { |
||||
return HMACSHA256(s, secret); |
||||
} |
||||
else { |
||||
throw new Exception(String.format("Invalid sign_type: %s", signType)); |
||||
CloseableHttpResponse httpResponse = WxUtils.getHttpClient().execute(httpGet); |
||||
HttpEntity entity = httpResponse.getEntity(); |
||||
JSONObject responseData = JSONObject.parseObject(EntityUtils.toString(entity)); |
||||
if (httpResponse.getStatusLine().getStatusCode() != 200) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, responseData.getString("message")); |
||||
} |
||||
return responseData; |
||||
} |
||||
|
||||
|
||||
} |
||||
|
@ -1,7 +1,13 @@ |
||||
package com.hfkj.dao; |
||||
|
||||
import org.apache.ibatis.annotations.Param; |
||||
import org.apache.ibatis.annotations.Select; |
||||
|
||||
/** |
||||
* mapper扩展类 |
||||
*/ |
||||
public interface BsUserSpreadAccountRecordMapperExt { |
||||
} |
||||
|
||||
@Select("select count(1) from bs_user_spread_account_record where user_id = #{userId} and DATE(create_time) = DATE(NOW()) and source_type = 2") |
||||
Integer withdrawChance(@Param("userId") Long userId); |
||||
} |
||||
|
@ -0,0 +1,130 @@ |
||||
package com.hfkj.dao; |
||||
|
||||
import com.hfkj.entity.BsUserSpreadAccountTransfer; |
||||
import com.hfkj.entity.BsUserSpreadAccountTransferExample; |
||||
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 BsUserSpreadAccountTransferMapper extends BsUserSpreadAccountTransferMapperExt { |
||||
@SelectProvider(type=BsUserSpreadAccountTransferSqlProvider.class, method="countByExample") |
||||
long countByExample(BsUserSpreadAccountTransferExample example); |
||||
|
||||
@DeleteProvider(type=BsUserSpreadAccountTransferSqlProvider.class, method="deleteByExample") |
||||
int deleteByExample(BsUserSpreadAccountTransferExample example); |
||||
|
||||
@Delete({ |
||||
"delete from bs_user_spread_account_transfer", |
||||
"where id = #{id,jdbcType=BIGINT}" |
||||
}) |
||||
int deleteByPrimaryKey(Long id); |
||||
|
||||
@Insert({ |
||||
"insert into bs_user_spread_account_transfer (user_spread_account_id, user_id, ", |
||||
"out_bill_no, transfer_bill_no, ", |
||||
"transfer_amount, `status`, ", |
||||
"fail_reason, create_time, ", |
||||
"update_time, ext_1, ", |
||||
"ext_2, ext_3)", |
||||
"values (#{userSpreadAccountId,jdbcType=BIGINT}, #{userId,jdbcType=BIGINT}, ", |
||||
"#{outBillNo,jdbcType=VARCHAR}, #{transferBillNo,jdbcType=VARCHAR}, ", |
||||
"#{transferAmount,jdbcType=DECIMAL}, #{status,jdbcType=INTEGER}, ", |
||||
"#{failReason,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, ", |
||||
"#{updateTime,jdbcType=TIMESTAMP}, #{ext1,jdbcType=VARCHAR}, ", |
||||
"#{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" |
||||
}) |
||||
@Options(useGeneratedKeys=true,keyProperty="id") |
||||
int insert(BsUserSpreadAccountTransfer record); |
||||
|
||||
@InsertProvider(type=BsUserSpreadAccountTransferSqlProvider.class, method="insertSelective") |
||||
@Options(useGeneratedKeys=true,keyProperty="id") |
||||
int insertSelective(BsUserSpreadAccountTransfer record); |
||||
|
||||
@SelectProvider(type=BsUserSpreadAccountTransferSqlProvider.class, method="selectByExample") |
||||
@Results({ |
||||
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), |
||||
@Result(column="user_spread_account_id", property="userSpreadAccountId", jdbcType=JdbcType.BIGINT), |
||||
@Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT), |
||||
@Result(column="out_bill_no", property="outBillNo", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="transfer_bill_no", property="transferBillNo", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="transfer_amount", property="transferAmount", jdbcType=JdbcType.DECIMAL), |
||||
@Result(column="status", property="status", jdbcType=JdbcType.INTEGER), |
||||
@Result(column="fail_reason", property="failReason", 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<BsUserSpreadAccountTransfer> selectByExample(BsUserSpreadAccountTransferExample example); |
||||
|
||||
@Select({ |
||||
"select", |
||||
"id, user_spread_account_id, user_id, out_bill_no, transfer_bill_no, transfer_amount, ", |
||||
"`status`, fail_reason, create_time, update_time, ext_1, ext_2, ext_3", |
||||
"from bs_user_spread_account_transfer", |
||||
"where id = #{id,jdbcType=BIGINT}" |
||||
}) |
||||
@Results({ |
||||
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), |
||||
@Result(column="user_spread_account_id", property="userSpreadAccountId", jdbcType=JdbcType.BIGINT), |
||||
@Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT), |
||||
@Result(column="out_bill_no", property="outBillNo", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="transfer_bill_no", property="transferBillNo", jdbcType=JdbcType.VARCHAR), |
||||
@Result(column="transfer_amount", property="transferAmount", jdbcType=JdbcType.DECIMAL), |
||||
@Result(column="status", property="status", jdbcType=JdbcType.INTEGER), |
||||
@Result(column="fail_reason", property="failReason", 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) |
||||
}) |
||||
BsUserSpreadAccountTransfer selectByPrimaryKey(Long id); |
||||
|
||||
@UpdateProvider(type=BsUserSpreadAccountTransferSqlProvider.class, method="updateByExampleSelective") |
||||
int updateByExampleSelective(@Param("record") BsUserSpreadAccountTransfer record, @Param("example") BsUserSpreadAccountTransferExample example); |
||||
|
||||
@UpdateProvider(type=BsUserSpreadAccountTransferSqlProvider.class, method="updateByExample") |
||||
int updateByExample(@Param("record") BsUserSpreadAccountTransfer record, @Param("example") BsUserSpreadAccountTransferExample example); |
||||
|
||||
@UpdateProvider(type=BsUserSpreadAccountTransferSqlProvider.class, method="updateByPrimaryKeySelective") |
||||
int updateByPrimaryKeySelective(BsUserSpreadAccountTransfer record); |
||||
|
||||
@Update({ |
||||
"update bs_user_spread_account_transfer", |
||||
"set user_spread_account_id = #{userSpreadAccountId,jdbcType=BIGINT},", |
||||
"user_id = #{userId,jdbcType=BIGINT},", |
||||
"out_bill_no = #{outBillNo,jdbcType=VARCHAR},", |
||||
"transfer_bill_no = #{transferBillNo,jdbcType=VARCHAR},", |
||||
"transfer_amount = #{transferAmount,jdbcType=DECIMAL},", |
||||
"`status` = #{status,jdbcType=INTEGER},", |
||||
"fail_reason = #{failReason,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(BsUserSpreadAccountTransfer record); |
||||
} |
@ -0,0 +1,7 @@ |
||||
package com.hfkj.dao; |
||||
|
||||
/** |
||||
* mapper扩展类 |
||||
*/ |
||||
public interface BsUserSpreadAccountTransferMapperExt { |
||||
} |
@ -0,0 +1,346 @@ |
||||
package com.hfkj.dao; |
||||
|
||||
import com.hfkj.entity.BsUserSpreadAccountTransfer; |
||||
import com.hfkj.entity.BsUserSpreadAccountTransferExample.Criteria; |
||||
import com.hfkj.entity.BsUserSpreadAccountTransferExample.Criterion; |
||||
import com.hfkj.entity.BsUserSpreadAccountTransferExample; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import org.apache.ibatis.jdbc.SQL; |
||||
|
||||
public class BsUserSpreadAccountTransferSqlProvider { |
||||
|
||||
public String countByExample(BsUserSpreadAccountTransferExample example) { |
||||
SQL sql = new SQL(); |
||||
sql.SELECT("count(*)").FROM("bs_user_spread_account_transfer"); |
||||
applyWhere(sql, example, false); |
||||
return sql.toString(); |
||||
} |
||||
|
||||
public String deleteByExample(BsUserSpreadAccountTransferExample example) { |
||||
SQL sql = new SQL(); |
||||
sql.DELETE_FROM("bs_user_spread_account_transfer"); |
||||
applyWhere(sql, example, false); |
||||
return sql.toString(); |
||||
} |
||||
|
||||
public String insertSelective(BsUserSpreadAccountTransfer record) { |
||||
SQL sql = new SQL(); |
||||
sql.INSERT_INTO("bs_user_spread_account_transfer"); |
||||
|
||||
if (record.getUserSpreadAccountId() != null) { |
||||
sql.VALUES("user_spread_account_id", "#{userSpreadAccountId,jdbcType=BIGINT}"); |
||||
} |
||||
|
||||
if (record.getUserId() != null) { |
||||
sql.VALUES("user_id", "#{userId,jdbcType=BIGINT}"); |
||||
} |
||||
|
||||
if (record.getOutBillNo() != null) { |
||||
sql.VALUES("out_bill_no", "#{outBillNo,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getTransferBillNo() != null) { |
||||
sql.VALUES("transfer_bill_no", "#{transferBillNo,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getTransferAmount() != null) { |
||||
sql.VALUES("transfer_amount", "#{transferAmount,jdbcType=DECIMAL}"); |
||||
} |
||||
|
||||
if (record.getStatus() != null) { |
||||
sql.VALUES("`status`", "#{status,jdbcType=INTEGER}"); |
||||
} |
||||
|
||||
if (record.getFailReason() != null) { |
||||
sql.VALUES("fail_reason", "#{failReason,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(BsUserSpreadAccountTransferExample example) { |
||||
SQL sql = new SQL(); |
||||
if (example != null && example.isDistinct()) { |
||||
sql.SELECT_DISTINCT("id"); |
||||
} else { |
||||
sql.SELECT("id"); |
||||
} |
||||
sql.SELECT("user_spread_account_id"); |
||||
sql.SELECT("user_id"); |
||||
sql.SELECT("out_bill_no"); |
||||
sql.SELECT("transfer_bill_no"); |
||||
sql.SELECT("transfer_amount"); |
||||
sql.SELECT("`status`"); |
||||
sql.SELECT("fail_reason"); |
||||
sql.SELECT("create_time"); |
||||
sql.SELECT("update_time"); |
||||
sql.SELECT("ext_1"); |
||||
sql.SELECT("ext_2"); |
||||
sql.SELECT("ext_3"); |
||||
sql.FROM("bs_user_spread_account_transfer"); |
||||
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) { |
||||
BsUserSpreadAccountTransfer record = (BsUserSpreadAccountTransfer) parameter.get("record"); |
||||
BsUserSpreadAccountTransferExample example = (BsUserSpreadAccountTransferExample) parameter.get("example"); |
||||
|
||||
SQL sql = new SQL(); |
||||
sql.UPDATE("bs_user_spread_account_transfer"); |
||||
|
||||
if (record.getId() != null) { |
||||
sql.SET("id = #{record.id,jdbcType=BIGINT}"); |
||||
} |
||||
|
||||
if (record.getUserSpreadAccountId() != null) { |
||||
sql.SET("user_spread_account_id = #{record.userSpreadAccountId,jdbcType=BIGINT}"); |
||||
} |
||||
|
||||
if (record.getUserId() != null) { |
||||
sql.SET("user_id = #{record.userId,jdbcType=BIGINT}"); |
||||
} |
||||
|
||||
if (record.getOutBillNo() != null) { |
||||
sql.SET("out_bill_no = #{record.outBillNo,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getTransferBillNo() != null) { |
||||
sql.SET("transfer_bill_no = #{record.transferBillNo,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getTransferAmount() != null) { |
||||
sql.SET("transfer_amount = #{record.transferAmount,jdbcType=DECIMAL}"); |
||||
} |
||||
|
||||
if (record.getStatus() != null) { |
||||
sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); |
||||
} |
||||
|
||||
if (record.getFailReason() != null) { |
||||
sql.SET("fail_reason = #{record.failReason,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_spread_account_transfer"); |
||||
|
||||
sql.SET("id = #{record.id,jdbcType=BIGINT}"); |
||||
sql.SET("user_spread_account_id = #{record.userSpreadAccountId,jdbcType=BIGINT}"); |
||||
sql.SET("user_id = #{record.userId,jdbcType=BIGINT}"); |
||||
sql.SET("out_bill_no = #{record.outBillNo,jdbcType=VARCHAR}"); |
||||
sql.SET("transfer_bill_no = #{record.transferBillNo,jdbcType=VARCHAR}"); |
||||
sql.SET("transfer_amount = #{record.transferAmount,jdbcType=DECIMAL}"); |
||||
sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); |
||||
sql.SET("fail_reason = #{record.failReason,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}"); |
||||
|
||||
BsUserSpreadAccountTransferExample example = (BsUserSpreadAccountTransferExample) parameter.get("example"); |
||||
applyWhere(sql, example, true); |
||||
return sql.toString(); |
||||
} |
||||
|
||||
public String updateByPrimaryKeySelective(BsUserSpreadAccountTransfer record) { |
||||
SQL sql = new SQL(); |
||||
sql.UPDATE("bs_user_spread_account_transfer"); |
||||
|
||||
if (record.getUserSpreadAccountId() != null) { |
||||
sql.SET("user_spread_account_id = #{userSpreadAccountId,jdbcType=BIGINT}"); |
||||
} |
||||
|
||||
if (record.getUserId() != null) { |
||||
sql.SET("user_id = #{userId,jdbcType=BIGINT}"); |
||||
} |
||||
|
||||
if (record.getOutBillNo() != null) { |
||||
sql.SET("out_bill_no = #{outBillNo,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getTransferBillNo() != null) { |
||||
sql.SET("transfer_bill_no = #{transferBillNo,jdbcType=VARCHAR}"); |
||||
} |
||||
|
||||
if (record.getTransferAmount() != null) { |
||||
sql.SET("transfer_amount = #{transferAmount,jdbcType=DECIMAL}"); |
||||
} |
||||
|
||||
if (record.getStatus() != null) { |
||||
sql.SET("`status` = #{status,jdbcType=INTEGER}"); |
||||
} |
||||
|
||||
if (record.getFailReason() != null) { |
||||
sql.SET("fail_reason = #{failReason,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, BsUserSpreadAccountTransferExample 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,249 @@ |
||||
package com.hfkj.entity; |
||||
|
||||
import java.io.Serializable; |
||||
import java.math.BigDecimal; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* bs_user_spread_account_transfer |
||||
* @author |
||||
*/ |
||||
/** |
||||
* |
||||
* 代码由工具生成 |
||||
* |
||||
**/ |
||||
public class BsUserSpreadAccountTransfer implements Serializable { |
||||
/** |
||||
* 主键 |
||||
*/ |
||||
private Long id; |
||||
|
||||
/** |
||||
* 推广账户id |
||||
*/ |
||||
private Long userSpreadAccountId; |
||||
|
||||
/** |
||||
* 用户id |
||||
*/ |
||||
private Long userId; |
||||
|
||||
/** |
||||
* 提现单号 |
||||
*/ |
||||
private String outBillNo; |
||||
|
||||
/** |
||||
* 微信转账单号 |
||||
*/ |
||||
private String transferBillNo; |
||||
|
||||
/** |
||||
* 转账金额 |
||||
*/ |
||||
private BigDecimal transferAmount; |
||||
|
||||
/** |
||||
* 状态 1:转账中 2:转账成功 3:转账失败 4:撤销转账 |
||||
*/ |
||||
private Integer status; |
||||
|
||||
/** |
||||
* 失败原因 |
||||
*/ |
||||
private String failReason; |
||||
|
||||
/** |
||||
* 创建时间 |
||||
*/ |
||||
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 Long getUserSpreadAccountId() { |
||||
return userSpreadAccountId; |
||||
} |
||||
|
||||
public void setUserSpreadAccountId(Long userSpreadAccountId) { |
||||
this.userSpreadAccountId = userSpreadAccountId; |
||||
} |
||||
|
||||
public Long getUserId() { |
||||
return userId; |
||||
} |
||||
|
||||
public void setUserId(Long userId) { |
||||
this.userId = userId; |
||||
} |
||||
|
||||
public String getOutBillNo() { |
||||
return outBillNo; |
||||
} |
||||
|
||||
public void setOutBillNo(String outBillNo) { |
||||
this.outBillNo = outBillNo; |
||||
} |
||||
|
||||
public String getTransferBillNo() { |
||||
return transferBillNo; |
||||
} |
||||
|
||||
public void setTransferBillNo(String transferBillNo) { |
||||
this.transferBillNo = transferBillNo; |
||||
} |
||||
|
||||
public BigDecimal getTransferAmount() { |
||||
return transferAmount; |
||||
} |
||||
|
||||
public void setTransferAmount(BigDecimal transferAmount) { |
||||
this.transferAmount = transferAmount; |
||||
} |
||||
|
||||
public Integer getStatus() { |
||||
return status; |
||||
} |
||||
|
||||
public void setStatus(Integer status) { |
||||
this.status = status; |
||||
} |
||||
|
||||
public String getFailReason() { |
||||
return failReason; |
||||
} |
||||
|
||||
public void setFailReason(String failReason) { |
||||
this.failReason = failReason; |
||||
} |
||||
|
||||
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; |
||||
} |
||||
BsUserSpreadAccountTransfer other = (BsUserSpreadAccountTransfer) that; |
||||
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) |
||||
&& (this.getUserSpreadAccountId() == null ? other.getUserSpreadAccountId() == null : this.getUserSpreadAccountId().equals(other.getUserSpreadAccountId())) |
||||
&& (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId())) |
||||
&& (this.getOutBillNo() == null ? other.getOutBillNo() == null : this.getOutBillNo().equals(other.getOutBillNo())) |
||||
&& (this.getTransferBillNo() == null ? other.getTransferBillNo() == null : this.getTransferBillNo().equals(other.getTransferBillNo())) |
||||
&& (this.getTransferAmount() == null ? other.getTransferAmount() == null : this.getTransferAmount().equals(other.getTransferAmount())) |
||||
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus())) |
||||
&& (this.getFailReason() == null ? other.getFailReason() == null : this.getFailReason().equals(other.getFailReason())) |
||||
&& (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 + ((getUserSpreadAccountId() == null) ? 0 : getUserSpreadAccountId().hashCode()); |
||||
result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode()); |
||||
result = prime * result + ((getOutBillNo() == null) ? 0 : getOutBillNo().hashCode()); |
||||
result = prime * result + ((getTransferBillNo() == null) ? 0 : getTransferBillNo().hashCode()); |
||||
result = prime * result + ((getTransferAmount() == null) ? 0 : getTransferAmount().hashCode()); |
||||
result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode()); |
||||
result = prime * result + ((getFailReason() == null) ? 0 : getFailReason().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(", userSpreadAccountId=").append(userSpreadAccountId); |
||||
sb.append(", userId=").append(userId); |
||||
sb.append(", outBillNo=").append(outBillNo); |
||||
sb.append(", transferBillNo=").append(transferBillNo); |
||||
sb.append(", transferAmount=").append(transferAmount); |
||||
sb.append(", status=").append(status); |
||||
sb.append(", failReason=").append(failReason); |
||||
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,31 @@ |
||||
package com.hfkj.service.spread; |
||||
|
||||
import com.hfkj.entity.BsUserSpreadAccountTransfer; |
||||
|
||||
/** |
||||
* @className: BsUserSpreadAccountTransferService |
||||
* @author: HuRui |
||||
* @date: 2025/4/10 |
||||
**/ |
||||
public interface BsUserSpreadAccountTransferService { |
||||
|
||||
/** |
||||
* 编辑数据 |
||||
* @param data |
||||
*/ |
||||
void editData(BsUserSpreadAccountTransfer data); |
||||
|
||||
/** |
||||
* 根据提现单号查询详情 |
||||
* @param outBillNo |
||||
* @return |
||||
*/ |
||||
BsUserSpreadAccountTransfer getDetailByOutBillNo(String outBillNo); |
||||
|
||||
/** |
||||
* 每日可提现次数 |
||||
* @param userId |
||||
* @return |
||||
*/ |
||||
int withdrawChance(Long userId); |
||||
} |
@ -0,0 +1,49 @@ |
||||
package com.hfkj.service.spread.impl; |
||||
|
||||
import com.hfkj.dao.BsUserSpreadAccountTransferMapper; |
||||
import com.hfkj.entity.BsUserSpreadAccountTransfer; |
||||
import com.hfkj.entity.BsUserSpreadAccountTransferExample; |
||||
import com.hfkj.service.spread.BsUserSpreadAccountTransferService; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @className: BsUserSpreadAccountTransferServiceImpl |
||||
* @author: HuRui |
||||
* @date: 2025/4/10 |
||||
**/ |
||||
@Service("userSpreadAccountTransferService") |
||||
public class BsUserSpreadAccountTransferServiceImpl implements BsUserSpreadAccountTransferService { |
||||
@Resource |
||||
private BsUserSpreadAccountTransferMapper userSpreadAccountTransferMapper; |
||||
|
||||
@Override |
||||
public void editData(BsUserSpreadAccountTransfer data) { |
||||
data.setUpdateTime(new Date()); |
||||
if (data.getId() == null) { |
||||
data.setCreateTime(new Date()); |
||||
userSpreadAccountTransferMapper.insert(data); |
||||
} else { |
||||
userSpreadAccountTransferMapper.updateByPrimaryKey(data); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public BsUserSpreadAccountTransfer getDetailByOutBillNo(String outBillNo) { |
||||
BsUserSpreadAccountTransferExample example = new BsUserSpreadAccountTransferExample(); |
||||
example.createCriteria().andOutBillNoEqualTo(outBillNo).andStatusNotEqualTo(0); |
||||
List<BsUserSpreadAccountTransfer> list = userSpreadAccountTransferMapper.selectByExample(example); |
||||
if (!list.isEmpty()) { |
||||
return list.get(0); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public int withdrawChance(Long userId) { |
||||
return 0; |
||||
} |
||||
} |
Loading…
Reference in new issue