|
|
@ -1,5 +1,6 @@ |
|
|
package com.example.demo.serviceImpl.bean; |
|
|
package com.example.demo.serviceImpl.bean; |
|
|
|
|
|
|
|
|
|
|
|
import com.example.demo.Util.BaseDES2; |
|
|
import com.example.demo.domain.vo.bean.*; |
|
|
import com.example.demo.domain.vo.bean.*; |
|
|
import com.example.demo.domain.vo.coin.Gold; |
|
|
import com.example.demo.domain.vo.coin.Gold; |
|
|
import com.example.demo.domain.vo.coin.GoldUser; |
|
|
import com.example.demo.domain.vo.coin.GoldUser; |
|
|
@ -15,16 +16,19 @@ import com.github.pagehelper.PageHelper; |
|
|
import com.github.pagehelper.PageInfo; |
|
|
import com.github.pagehelper.PageInfo; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
|
import org.springframework.http.HttpEntity; |
|
|
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
|
|
import org.springframework.http.MediaType; |
|
|
import org.springframework.http.ResponseEntity; |
|
|
import org.springframework.http.ResponseEntity; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
import org.springframework.web.client.RestClientException; |
|
|
import org.springframework.web.client.RestTemplate; |
|
|
import org.springframework.web.client.RestTemplate; |
|
|
import org.springframework.web.util.UriComponentsBuilder; |
|
|
import org.springframework.web.util.UriComponentsBuilder; |
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
import java.math.BigDecimal; |
|
|
import java.math.RoundingMode; |
|
|
import java.math.RoundingMode; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Objects; |
|
|
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -57,6 +61,9 @@ public class BeanRechargeServiceImpl implements BeanRechargeService { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private BeanUserMapper beanUserMapper; |
|
|
private BeanUserMapper beanUserMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Value("${bean.recharge.url}") |
|
|
|
|
|
String apiUrl; |
|
|
|
|
|
|
|
|
//新增金豆 |
|
|
//新增金豆 |
|
|
@Override |
|
|
@Override |
|
|
public Result add(BeanRecharge recharge) { |
|
|
public Result add(BeanRecharge recharge) { |
|
|
@ -121,6 +128,97 @@ public class BeanRechargeServiceImpl implements BeanRechargeService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public Result addBeanDC(BeanRecharge recharge) { |
|
|
|
|
|
try { |
|
|
|
|
|
// 验证精网号是否有效 |
|
|
|
|
|
recharge.setPermanentBean(0); |
|
|
|
|
|
if (recharge.getJwcode() == null || recharge.getJwcode().toString().isEmpty()) { |
|
|
|
|
|
return Result.error("精网号不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
if(recharge.getJwcode()<10000000||recharge.getJwcode()>99999999) |
|
|
|
|
|
{ |
|
|
|
|
|
return Result.error("精网号位数小于8位或大于8位"); |
|
|
|
|
|
} |
|
|
|
|
|
// 验证免费豆和永久豆是否为非负数 |
|
|
|
|
|
if (recharge.getFreeBean() < 0 || recharge.getPermanentBean() < 0) { |
|
|
|
|
|
return Result.error("免费豆和永久豆不能为负数"); |
|
|
|
|
|
} |
|
|
|
|
|
// 验证免费豆和永久豆是否为非负数 |
|
|
|
|
|
if (recharge.getFreeBean() > 999999 || recharge.getPermanentBean() > 999999) { |
|
|
|
|
|
return Result.error("免费豆和永久豆不能超过999999"); |
|
|
|
|
|
} |
|
|
|
|
|
// 验证免费豆和永久豆是否均为0 |
|
|
|
|
|
if (recharge.getFreeBean() == 0) { |
|
|
|
|
|
return Result.error("免费豆为0"); |
|
|
|
|
|
} |
|
|
|
|
|
BeanUserCard user = beanUserMapper.userCard(String.valueOf(recharge.getJwcode())); |
|
|
|
|
|
if(user==null){ |
|
|
|
|
|
return Result.error("用户查找不到"); |
|
|
|
|
|
} |
|
|
|
|
|
// 验证备注是否为空 |
|
|
|
|
|
if (recharge.getRemark() == null || recharge.getRemark().toString().isEmpty()) { |
|
|
|
|
|
return Result.error("备注不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
if(recharge.getAdminName() == null || recharge.getAdminName().toString().isEmpty()){ |
|
|
|
|
|
return Result.error("管理员名称不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
beanRechargeMapper1.add(recharge); |
|
|
|
|
|
String jwcode = recharge.getJwcode().toString(); |
|
|
|
|
|
// String jwcode = "2e35cadd48a15cc4cd834d35e38faa71"; |
|
|
|
|
|
try { |
|
|
|
|
|
BaseDES2 d = new BaseDES2(); |
|
|
|
|
|
jwcode = d.encrypt(jwcode); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
return Result.error("加密失败"); |
|
|
|
|
|
} |
|
|
|
|
|
String content = recharge.getRemark(); // 备注作为content参数 |
|
|
|
|
|
String orderNo = UUID.randomUUID().toString().replace("-", ""); // 生成唯一订单号(去除横线) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 1. 创建请求参数对象(使用Map或自定义实体类) |
|
|
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
|
|
params.put("jwcode", jwcode); |
|
|
|
|
|
params.put("gold_buy", recharge.getPermanentBean().toString()); |
|
|
|
|
|
params.put("gold_free", recharge.getFreeBean().toString()); |
|
|
|
|
|
params.put("content", content); |
|
|
|
|
|
params.put("order_no", orderNo); |
|
|
|
|
|
|
|
|
|
|
|
// 2. 构建请求头,指定Content-Type为JSON |
|
|
|
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON); // 关键:设置为JSON格式 |
|
|
|
|
|
|
|
|
|
|
|
// 3. 构建请求实体(参数+头信息) |
|
|
|
|
|
HttpEntity<Map<String, String>> requestEntity = new HttpEntity<>(params, headers); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
// 4. 发送POST请求 |
|
|
|
|
|
ResponseEntity<String> response = restTemplate.postForEntity( |
|
|
|
|
|
apiUrl, |
|
|
|
|
|
requestEntity, |
|
|
|
|
|
String.class |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
System.out.println("请求参数:" + params); |
|
|
|
|
|
System.out.println("响应状态码:" + response.getStatusCodeValue()); |
|
|
|
|
|
System.out.println("响应内容:" + response.getBody()); |
|
|
|
|
|
|
|
|
|
|
|
if (!response.getStatusCode().is2xxSuccessful()) { |
|
|
|
|
|
return Result.error("远程接口接口调用失败,状态码:" + response.getStatusCodeValue() + ",响应:" + response.getBody()); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (RestClientException e) { |
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
return Result.error("请求发送失败:" + e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
return Result.success("添加成功"); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
return Result.error("系统异常:" + e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//系统充值明细 |
|
|
//系统充值明细 |
|
|
@Override |
|
|
@Override |
|
|
public PageInfo<BeanSystemRechargeInfo> selectBySystem(Integer pageNum, Integer pageSize, BeanSystemRechargeInfo beanSystemRechargeInfo){ |
|
|
public PageInfo<BeanSystemRechargeInfo> selectBySystem(Integer pageNum, Integer pageSize, BeanSystemRechargeInfo beanSystemRechargeInfo){ |
|
|
|