You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
package com.example.demo.serviceImpl;
import com.example.demo.Util.BaseDES; import com.example.demo.domain.entity.DetailY; import com.example.demo.domain.entity.Recharge; import com.example.demo.domain.entity.UserGold; import com.example.demo.domain.vo.ERP; import com.example.demo.mapper.db1.DetailYMapper; import com.example.demo.mapper.db1.OtherMapper; import com.example.demo.mapper.db1.RechargeMapper; import com.example.demo.mapper.db1.UserMapper; import com.example.demo.sevice.OtherService; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheConfig; import org.springframework.http.*; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.client.RestTemplate;
import org.slf4j.Logger; import org.slf4j.LoggerFactory;
import java.math.BigDecimal; import java.time.LocalDate; import java.time.Month; import java.util.HashMap; import java.util.Set; import java.util.HashSet; import java.util.Map;
@Service @Transactional @RequiredArgsConstructor @CacheConfig(cacheNames = "other") public class OtherServiceImpl implements OtherService {
private static final Logger log = LoggerFactory.getLogger(OtherServiceImpl.class); @Autowired private RestTemplate restTemplate;
private static final Set<String> typesToUpdateZero = new HashSet<>(); private static final Set<String> typesToUpdateOne = new HashSet<>(); private static final Set<String> typesToUpdateTwo = new HashSet<>(); private static final Set<String> typesToUpdateThree = new HashSet<>(); private static final Set<String> typesToUpdateFour = new HashSet<>(); private static final Set<String> typesToUpdateFive = new HashSet<>(); private final OtherMapper otherMapper; private final DetailYMapper detailYMapper; private final UserMapper userMapper; private final RechargeMapper rechargeMapper;
static { typesToUpdateZero.add("1"); typesToUpdateZero.add("2"); typesToUpdateZero.add("3"); typesToUpdateZero.add("4"); typesToUpdateZero.add("5"); typesToUpdateZero.add("6"); typesToUpdateZero.add("7"); typesToUpdateZero.add("8"); typesToUpdateZero.add("11"); typesToUpdateZero.add("12"); typesToUpdateZero.add("13"); typesToUpdateZero.add("14"); typesToUpdateZero.add("18"); typesToUpdateZero.add("19"); typesToUpdateZero.add("20"); typesToUpdateZero.add("21"); typesToUpdateZero.add("22"); typesToUpdateZero.add("23"); typesToUpdateZero.add("24"); typesToUpdateZero.add("26"); typesToUpdateZero.add("28"); typesToUpdateZero.add("29"); typesToUpdateZero.add("35"); typesToUpdateZero.add("36"); typesToUpdateZero.add("40"); typesToUpdateZero.add("45"); typesToUpdateZero.add("46"); typesToUpdateZero.add("47"); typesToUpdateZero.add("48"); typesToUpdateZero.add("49"); typesToUpdateZero.add("53"); typesToUpdateZero.add("54"); typesToUpdateZero.add("60"); // typesToUpdateZero.add("64");
// typesToUpdateZero.add("63");
typesToUpdateOne.add("9"); typesToUpdateOne.add("15"); typesToUpdateOne.add("17"); typesToUpdateOne.add("25"); typesToUpdateOne.add("27"); typesToUpdateOne.add("37"); typesToUpdateOne.add("41"); typesToUpdateOne.add("42"); typesToUpdateOne.add("43"); typesToUpdateOne.add("50"); typesToUpdateOne.add("51"); typesToUpdateOne.add("52"); typesToUpdateOne.add("62");
typesToUpdateTwo.add("55"); typesToUpdateTwo.add("56"); typesToUpdateTwo.add("57"); typesToUpdateTwo.add("58"); typesToUpdateTwo.add("59"); typesToUpdateTwo.add("61");
typesToUpdateThree.add("10"); typesToUpdateThree.add("16"); typesToUpdateThree.add("30"); typesToUpdateThree.add("31"); typesToUpdateThree.add("32"); typesToUpdateThree.add("33"); typesToUpdateThree.add("34"); typesToUpdateThree.add("39"); typesToUpdateThree.add("44");
typesToUpdateFour.add("65");
typesToUpdateFive.add("63"); typesToUpdateFive.add("64");
}
@Override public int addERP(ERP erp) throws Exception { DetailY detailY = new DetailY(); Recharge recharge = new Recharge();
String type = erp.getType(); String JwCode = erp.getJwcode(); BigDecimal taskJb = erp.getTaskJb(); BigDecimal freeJb = erp.getFreeJb(); BigDecimal rechargeJb = erp.getRechargeJb(); String uid = erp.getTable().getUid(); BigDecimal goldLast = erp.getTable().getGold_last(); String adminName = erp.getTable().getCz_user(); if(adminName==null||adminName.equals("")){ adminName = erp.getTable().getCz_bz(); } Integer platform = erp.getTable().getOperation_platform(); String productName = erp.getProductName(); String remark = erp.getReamrk(); String Way = otherMapper.selectWay(type); String country = null; String name = null; UserGold userGold = new UserGold(); userGold = userMapper.selectGold(JwCode); //新加判断位置
//判断usergold有没有查到数据
BaseDES des = new BaseDES();
String desjwcode= des.encrypt(JwCode); System.out.println("desjwcode:"+desjwcode);
// 创建 JSON 请求体
Map<String, String> requestBody = new HashMap<>(); requestBody.put("jwcode", desjwcode);
// 设置请求头
HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON);
// 创建 HttpEntity
HttpEntity<Map<String, String>> entity = new HttpEntity<>(requestBody, headers);
// 发送 POST 请求
try { ResponseEntity<Map> response = restTemplate.exchange( "http://hwapi.rzfwq.com/hwjnApp/hwhc-login/hwhclogin/hc/login/clent/info", HttpMethod.POST, entity, Map.class);
// 检查响应状态码
if (response.getStatusCode().is2xxSuccessful()) { Map<String, Object> responseBody = response.getBody(); if (responseBody != null) { // 获取data部分
Map<String, Object> data = (Map<String, Object>) responseBody.get("data"); if (data != null) { // 提取name和country
name = (String) data.get("name"); country = (String) data.get("country");
// 打印获取到的数据
System.out.println("Name: " + name); System.out.println("Country: " + country); } else { System.out.println("Data is null"); } } else { System.out.println("Response body is null"); } } else { System.out.println("Request failed with status code: " + response.getStatusCode()); } } catch (Exception e) { System.out.println("Error: " + e.getMessage()); // 设置默认的 country 值
country = "Unknown"; }
if(userGold==null){ userGold = new UserGold(); userGold.setBuyJb(BigDecimal.ZERO); userGold.setCoreJb(BigDecimal.ZERO); userGold.setFree6(BigDecimal.ZERO); userGold.setFree12(BigDecimal.ZERO); userGold.setJwcode(JwCode); userMapper.addUserGold(userGold); }
if (typesToUpdateFour.contains(type)) { log.info("类型为 金币系统操作,不写入数据"); return 0; // 返回默认值
}
if (typesToUpdateFive.contains(type)) { System.out.println("金币充值------------------------------------------------------"); detailY.setUpdateType(0);// 设置 updateType 为 0
detailY.setJwcode(JwCode); detailY.setRechargeCoin(rechargeJb); detailY.setFreeCoin(freeJb); detailY.setTaskCoin(taskJb); detailY.setRemark(remark); detailY.setName(adminName); detailY.setGtype(Integer.valueOf(type)); // detailY.setUsername(username);
// detailY.setArea(area);
detailY.setProductName(productName); detailY.setConsumePlatform(String.valueOf(platform)); detailY.setRechargeWay(Way); detailY.setArea(country); detailY.setCreateTime(erp.getCreateTime()); detailY.setGold_last(goldLast); detailY.setUid(uid);
detailY.setUsername(name);
BigDecimal buyJb = userGold.getBuyJb(); BigDecimal coreJb = userGold.getCoreJb(); buyJb = buyJb.add(rechargeJb); coreJb = coreJb.add(taskJb); // 设置更新后的Sumgold回到user对象
userGold.setBuyJb(buyJb); userGold.setCoreJb(coreJb); LocalDate now = LocalDate.now();
// 判断当前日期是在六月之前还是之后
Month currentMonth = now.getMonth(); boolean isBeforeJune = currentMonth.getValue() < Month.JUNE.getValue(); boolean isJune = currentMonth.getValue() == Month.JUNE.getValue(); boolean isAfterJune = currentMonth.getValue() > Month.JUNE.getValue();
// 根据月份更新 free6 或 free12
if (isBeforeJune || isJune) { // 如果是六月前,更新 free6
BigDecimal free6 = userGold.getFree6().add(freeJb); userGold.setFree6(free6); } else if (isAfterJune) { // 如果是六月后,更新 free12
BigDecimal free12 = userGold.getFree12().add(freeJb); userGold.setFree12(free12); } } if (typesToUpdateZero.contains(type)) { System.out.println("充值------------------------------------------------------"); detailY.setUpdateType(0);// 设置 updateType 为 0
detailY.setJwcode(JwCode); detailY.setRechargeCoin(rechargeJb); detailY.setFreeCoin(freeJb); detailY.setTaskCoin(taskJb); detailY.setRemark(remark); detailY.setName(adminName); detailY.setGtype(Integer.valueOf(type)); // detailY.setUsername(username);
// detailY.setArea(area);
detailY.setProductName(productName); detailY.setConsumePlatform(String.valueOf(platform)); detailY.setRechargeWay(Way); detailY.setArea(country); detailY.setCreateTime(erp.getCreateTime()); detailY.setGold_last(goldLast); detailY.setUid(uid);
detailY.setUsername(name);
BigDecimal buyJb =userGold.getBuyJb(); BigDecimal coreJb=userGold.getCoreJb(); buyJb = buyJb.add(rechargeJb); coreJb = coreJb.add(taskJb); // 设置更新后的Sumgold回到user对象
userGold.setBuyJb(buyJb); userGold.setCoreJb(coreJb); LocalDate now = LocalDate.now();
// 判断当前日期是在六月之前还是之后
Month currentMonth = now.getMonth(); boolean isBeforeJune = currentMonth.getValue() < Month.JUNE.getValue(); boolean isJune = currentMonth.getValue() == Month.JUNE.getValue(); boolean isAfterJune = currentMonth.getValue() > Month.JUNE.getValue();
// 根据月份更新 free6 或 free12
if (isBeforeJune||isJune) { // 如果是六月前,更新 free6
BigDecimal free6 = userGold.getFree6().add(freeJb); userGold.setFree6(free6); } else if (isAfterJune) { // 如果是六月后,更新 free12
BigDecimal free12 = userGold.getFree12().add(freeJb); userGold.setFree12(free12); } recharge.setJwcode(JwCode); recharge.setPaidGold(rechargeJb); recharge.setFreeGold(freeJb); recharge.setRechargeGold(rechargeJb); recharge.setRechargeWay(Way); recharge.setPayWay("ERP"); recharge.setRechargeTime(erp.getCreateTime()); recharge.setRemark(remark); recharge.setAdminName(adminName);
rechargeMapper.insert(recharge);
} else if (typesToUpdateOne.contains(type)) { System.out.println("消费------------------------------------------------------"); detailY.setUpdateType(1); // 设置 updateType 为 1
detailY.setJwcode(JwCode); detailY.setGtype(Integer.valueOf(type)); detailY.setRechargeCoin(rechargeJb); detailY.setFreeCoin(freeJb); detailY.setTaskCoin(taskJb); detailY.setRemark(remark); detailY.setName(adminName); detailY.setUsername(name); detailY.setArea(country); detailY.setProductName(productName); detailY.setConsumePlatform(String.valueOf(platform)); detailY.setConsumeType(Way); detailY.setGold_last(goldLast); detailY.setUid(uid);
detailY.setCreateTime(erp.getCreateTime());
BigDecimal buyJb =userGold.getBuyJb(); BigDecimal coreJb=userGold.getCoreJb(); buyJb = buyJb.add(rechargeJb); coreJb = coreJb.add(taskJb); // 设置更新后的Sumgold回到user对象
userGold.setBuyJb(buyJb); userGold.setCoreJb(coreJb); LocalDate now = LocalDate.now();
// 判断当前日期是在六月之前还是之后
Month currentMonth = now.getMonth(); boolean isBeforeJune = currentMonth.getValue() < Month.JUNE.getValue(); boolean isJune = currentMonth.getValue() == Month.JUNE.getValue(); boolean isAfterJune = currentMonth.getValue() > Month.JUNE.getValue();
// 根据月份更新 free6 或 free12
if (isBeforeJune||isJune) { // 如果是六月前,更新 free6
BigDecimal free6 = userGold.getFree6().add(freeJb); userGold.setFree6(free6); } else if (isAfterJune) { // 如果是六月后,更新 free12
BigDecimal free12 = userGold.getFree12().add(freeJb); userGold.setFree12(free12); } } else if (typesToUpdateTwo.contains(type)) { System.out.println("退款------------------------------------------------------"); detailY.setUpdateType(2); // 设置 updateType 为 2
detailY.setJwcode(JwCode); detailY.setGtype(Integer.valueOf(type)); detailY.setRechargeCoin(rechargeJb); detailY.setFreeCoin(freeJb); detailY.setTaskCoin(taskJb); detailY.setRemark(remark); detailY.setName(adminName); detailY.setUsername(name); detailY.setArea(country); detailY.setProductName(productName); detailY.setConsumePlatform(String.valueOf(platform)); detailY.setRefundType(Way);
detailY.setCreateTime(erp.getCreateTime()); detailY.setGold_last(goldLast); detailY.setUid(uid);
BigDecimal buyJb =userGold.getBuyJb(); BigDecimal coreJb=userGold.getCoreJb(); buyJb = buyJb.add(rechargeJb); coreJb = coreJb.add(taskJb); // 设置更新后的Sumgold回到user对象
userGold.setBuyJb(buyJb); userGold.setCoreJb(coreJb); LocalDate now = LocalDate.now();
// 判断当前日期是在六月之前还是之后
Month currentMonth = now.getMonth(); boolean isBeforeJune = currentMonth.getValue() < Month.JUNE.getValue(); boolean isJune = currentMonth.getValue() == Month.JUNE.getValue(); boolean isAfterJune = currentMonth.getValue() > Month.JUNE.getValue();
// 根据月份更新 free6 或 free12
if (isBeforeJune||isJune) { // 如果是六月前,更新 free6
BigDecimal free6 = userGold.getFree6().add(freeJb); userGold.setFree6(free6); } else if (isAfterJune) { // 如果是六月后,更新 free12
BigDecimal free12 = userGold.getFree12().add(freeJb); userGold.setFree12(free12); }
}else if (typesToUpdateThree.contains(type)) { System.out.println("其他------------------------------------------------------"); detailY.setUpdateType(3); // 设置 updateType 为 3
detailY.setJwcode(JwCode); detailY.setGtype(Integer.valueOf(type)); detailY.setRechargeCoin(rechargeJb); detailY.setFreeCoin(freeJb); detailY.setTaskCoin(taskJb); detailY.setRemark(remark); detailY.setName(adminName); detailY.setUsername(name); detailY.setArea(country); detailY.setProductName(productName); detailY.setConsumePlatform(String.valueOf(platform)); detailY.setReson(Way);
detailY.setCreateTime(erp.getCreateTime()); detailY.setGold_last(goldLast); detailY.setUid(uid);
BigDecimal buyJb =userGold.getBuyJb(); BigDecimal coreJb=userGold.getCoreJb(); buyJb = buyJb.add(rechargeJb); coreJb = coreJb.add(taskJb); // 设置更新后的Sumgold回到user对象
userGold.setBuyJb(buyJb); userGold.setCoreJb(coreJb); LocalDate now = LocalDate.now();
// 判断当前日期是在六月之前还是之后
Month currentMonth = now.getMonth(); boolean isBeforeJune = currentMonth.getValue() < Month.JUNE.getValue(); boolean isJune = currentMonth.getValue() == Month.JUNE.getValue(); boolean isAfterJune = currentMonth.getValue() > Month.JUNE.getValue();
// 根据月份更新 free6 或 free12
if (isBeforeJune||isJune) { // 如果是六月前,更新 free6
BigDecimal free6 = userGold.getFree6().add(freeJb); userGold.setFree6(free6); } else if (isAfterJune) { // 如果是六月后,更新 free12
BigDecimal free12 = userGold.getFree12().add(freeJb); userGold.setFree12(free12); } } // 添加其他业务逻辑
System.out.println(detailY+"-----测试能否传输------");
userMapper.updateGold(userGold); return detailYMapper.add(detailY); } }
|