金币系统后端
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.

481 lines
19 KiB

7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
  1. package com.example.demo.serviceImpl;
  2. import com.example.demo.Util.BaseDES;
  3. import com.example.demo.domain.entity.DetailY;
  4. import com.example.demo.domain.entity.Recharge;
  5. import com.example.demo.domain.entity.UserGold;
  6. import com.example.demo.domain.vo.ERP;
  7. import com.example.demo.mapper.db1.DetailYMapper;
  8. import com.example.demo.mapper.db1.OtherMapper;
  9. import com.example.demo.mapper.db1.RechargeMapper;
  10. import com.example.demo.mapper.db1.UserMapper;
  11. import com.example.demo.sevice.OtherService;
  12. import lombok.RequiredArgsConstructor;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.cache.annotation.CacheConfig;
  15. import org.springframework.http.*;
  16. import org.springframework.stereotype.Service;
  17. import org.springframework.transaction.annotation.Transactional;
  18. import org.springframework.web.client.RestTemplate;
  19. import org.slf4j.Logger;
  20. import org.slf4j.LoggerFactory;
  21. import java.math.BigDecimal;
  22. import java.time.LocalDate;
  23. import java.time.Month;
  24. import java.util.HashMap;
  25. import java.util.Set;
  26. import java.util.HashSet;
  27. import java.util.Map;
  28. @Service
  29. @Transactional
  30. @RequiredArgsConstructor
  31. @CacheConfig(cacheNames = "other")
  32. public class OtherServiceImpl implements OtherService {
  33. private static final Logger log = LoggerFactory.getLogger(OtherServiceImpl.class);
  34. @Autowired
  35. private RestTemplate restTemplate;
  36. private static final Set<String> typesToUpdateZero = new HashSet<>();
  37. private static final Set<String> typesToUpdateOne = new HashSet<>();
  38. private static final Set<String> typesToUpdateTwo = new HashSet<>();
  39. private static final Set<String> typesToUpdateThree = new HashSet<>();
  40. private static final Set<String> typesToUpdateFour = new HashSet<>();
  41. private static final Set<String> typesToUpdateFive = new HashSet<>();
  42. private final OtherMapper otherMapper;
  43. private final DetailYMapper detailYMapper;
  44. private final UserMapper userMapper;
  45. private final RechargeMapper rechargeMapper;
  46. static {
  47. typesToUpdateZero.add("1");
  48. typesToUpdateZero.add("2");
  49. typesToUpdateZero.add("3");
  50. typesToUpdateZero.add("4");
  51. typesToUpdateZero.add("5");
  52. typesToUpdateZero.add("6");
  53. typesToUpdateZero.add("7");
  54. typesToUpdateZero.add("8");
  55. typesToUpdateZero.add("11");
  56. typesToUpdateZero.add("12");
  57. typesToUpdateZero.add("13");
  58. typesToUpdateZero.add("14");
  59. typesToUpdateZero.add("18");
  60. typesToUpdateZero.add("19");
  61. typesToUpdateZero.add("20");
  62. typesToUpdateZero.add("21");
  63. typesToUpdateZero.add("22");
  64. typesToUpdateZero.add("23");
  65. typesToUpdateZero.add("24");
  66. typesToUpdateZero.add("26");
  67. typesToUpdateZero.add("28");
  68. typesToUpdateZero.add("29");
  69. typesToUpdateZero.add("35");
  70. typesToUpdateZero.add("36");
  71. typesToUpdateZero.add("40");
  72. typesToUpdateZero.add("45");
  73. typesToUpdateZero.add("46");
  74. typesToUpdateZero.add("47");
  75. typesToUpdateZero.add("48");
  76. typesToUpdateZero.add("49");
  77. typesToUpdateZero.add("53");
  78. typesToUpdateZero.add("54");
  79. typesToUpdateZero.add("60");
  80. // typesToUpdateZero.add("64");
  81. // typesToUpdateZero.add("63");
  82. typesToUpdateOne.add("9");
  83. typesToUpdateOne.add("15");
  84. typesToUpdateOne.add("17");
  85. typesToUpdateOne.add("25");
  86. typesToUpdateOne.add("27");
  87. typesToUpdateOne.add("37");
  88. typesToUpdateOne.add("41");
  89. typesToUpdateOne.add("42");
  90. typesToUpdateOne.add("43");
  91. typesToUpdateOne.add("50");
  92. typesToUpdateOne.add("51");
  93. typesToUpdateOne.add("52");
  94. typesToUpdateOne.add("62");
  95. typesToUpdateTwo.add("55");
  96. typesToUpdateTwo.add("56");
  97. typesToUpdateTwo.add("57");
  98. typesToUpdateTwo.add("58");
  99. typesToUpdateTwo.add("59");
  100. typesToUpdateTwo.add("61");
  101. typesToUpdateThree.add("10");
  102. typesToUpdateThree.add("16");
  103. typesToUpdateThree.add("30");
  104. typesToUpdateThree.add("31");
  105. typesToUpdateThree.add("32");
  106. typesToUpdateThree.add("33");
  107. typesToUpdateThree.add("34");
  108. typesToUpdateThree.add("39");
  109. typesToUpdateThree.add("44");
  110. typesToUpdateFour.add("65");
  111. typesToUpdateFive.add("63");
  112. typesToUpdateFive.add("64");
  113. }
  114. @Override
  115. public int addERP(ERP erp) throws Exception {
  116. DetailY detailY = new DetailY();
  117. Recharge recharge = new Recharge();
  118. String type = erp.getType();
  119. String JwCode = erp.getJwcode();
  120. BigDecimal taskJb = erp.getTaskJb();
  121. BigDecimal freeJb = erp.getFreeJb();
  122. BigDecimal rechargeJb = erp.getRechargeJb();
  123. String uid = erp.getTable().getUid();
  124. BigDecimal goldLast = erp.getTable().getGold_last();
  125. String adminName = erp.getTable().getCz_user();
  126. if(adminName==null||adminName.equals("")){
  127. adminName = erp.getTable().getCz_bz();
  128. }
  129. Integer platform = erp.getTable().getOperation_platform();
  130. String productName = erp.getProductName();
  131. String remark = erp.getReamrk();
  132. String Way = otherMapper.selectWay(type);
  133. String country = null;
  134. String name = null;
  135. UserGold userGold = new UserGold();
  136. userGold = userMapper.selectGold(JwCode);
  137. //新加判断位置
  138. //判断usergold有没有查到数据
  139. BaseDES des = new BaseDES();
  140. String desjwcode= des.encrypt(JwCode);
  141. System.out.println("desjwcode:"+desjwcode);
  142. // 创建 JSON 请求体
  143. Map<String, String> requestBody = new HashMap<>();
  144. requestBody.put("jwcode", desjwcode);
  145. // 设置请求头
  146. HttpHeaders headers = new HttpHeaders();
  147. headers.setContentType(MediaType.APPLICATION_JSON);
  148. // 创建 HttpEntity
  149. HttpEntity<Map<String, String>> entity = new HttpEntity<>(requestBody, headers);
  150. // 发送 POST 请求
  151. try {
  152. ResponseEntity<Map> response = restTemplate.exchange(
  153. "http://hwapi.rzfwq.com/hwjnApp/hwhc-login/hwhclogin/hc/login/clent/info",
  154. HttpMethod.POST, entity, Map.class);
  155. // 检查响应状态码
  156. if (response.getStatusCode().is2xxSuccessful()) {
  157. Map<String, Object> responseBody = response.getBody();
  158. if (responseBody != null) {
  159. // 获取data部分
  160. Map<String, Object> data = (Map<String, Object>) responseBody.get("data");
  161. if (data != null) {
  162. // 提取name和country
  163. name = (String) data.get("name");
  164. country = (String) data.get("country");
  165. // 打印获取到的数据
  166. System.out.println("Name: " + name);
  167. System.out.println("Country: " + country);
  168. } else {
  169. System.out.println("Data is null");
  170. }
  171. } else {
  172. System.out.println("Response body is null");
  173. }
  174. } else {
  175. System.out.println("Request failed with status code: " + response.getStatusCode());
  176. }
  177. } catch (Exception e) {
  178. System.out.println("Error: " + e.getMessage());
  179. // 设置默认的 country 值
  180. country = "Unknown";
  181. }
  182. if(userGold==null){
  183. userGold = new UserGold();
  184. userGold.setBuyJb(BigDecimal.ZERO);
  185. userGold.setCoreJb(BigDecimal.ZERO);
  186. userGold.setFree6(BigDecimal.ZERO);
  187. userGold.setFree12(BigDecimal.ZERO);
  188. userGold.setJwcode(JwCode);
  189. userMapper.addUserGold(userGold);
  190. }
  191. if (typesToUpdateFour.contains(type)) {
  192. log.info("类型为 金币系统操作,不写入数据");
  193. return 0; // 返回默认值
  194. }
  195. if (typesToUpdateFive.contains(type)) {
  196. System.out.println("金币充值------------------------------------------------------");
  197. detailY.setUpdateType(0);// 设置 updateType 为 0
  198. detailY.setJwcode(JwCode);
  199. detailY.setRechargeCoin(rechargeJb);
  200. detailY.setFreeCoin(freeJb);
  201. detailY.setTaskCoin(taskJb);
  202. detailY.setRemark(remark);
  203. detailY.setName(adminName);
  204. detailY.setGtype(Integer.valueOf(type));
  205. // detailY.setUsername(username);
  206. // detailY.setArea(area);
  207. detailY.setProductName(productName);
  208. detailY.setConsumePlatform(String.valueOf(platform));
  209. detailY.setRechargeWay(Way);
  210. detailY.setArea(country);
  211. detailY.setCreateTime(erp.getCreateTime());
  212. detailY.setGold_last(goldLast);
  213. detailY.setUid(uid);
  214. detailY.setUsername(name);
  215. BigDecimal buyJb = userGold.getBuyJb();
  216. BigDecimal coreJb = userGold.getCoreJb();
  217. buyJb = buyJb.add(rechargeJb);
  218. coreJb = coreJb.add(taskJb);
  219. // 设置更新后的Sumgold回到user对象
  220. userGold.setBuyJb(buyJb);
  221. userGold.setCoreJb(coreJb);
  222. LocalDate now = LocalDate.now();
  223. // 判断当前日期是在六月之前还是之后
  224. Month currentMonth = now.getMonth();
  225. boolean isBeforeJune = currentMonth.getValue() < Month.JUNE.getValue();
  226. boolean isJune = currentMonth.getValue() == Month.JUNE.getValue();
  227. boolean isAfterJune = currentMonth.getValue() > Month.JUNE.getValue();
  228. // 根据月份更新 free6 或 free12
  229. if (isBeforeJune || isJune) {
  230. // 如果是六月前,更新 free6
  231. BigDecimal free6 = userGold.getFree6().add(freeJb);
  232. userGold.setFree6(free6);
  233. } else if (isAfterJune) {
  234. // 如果是六月后,更新 free12
  235. BigDecimal free12 = userGold.getFree12().add(freeJb);
  236. userGold.setFree12(free12);
  237. }
  238. }
  239. if (typesToUpdateZero.contains(type)) {
  240. System.out.println("充值------------------------------------------------------");
  241. detailY.setUpdateType(0);// 设置 updateType 为 0
  242. detailY.setJwcode(JwCode);
  243. detailY.setRechargeCoin(rechargeJb);
  244. detailY.setFreeCoin(freeJb);
  245. detailY.setTaskCoin(taskJb);
  246. detailY.setRemark(remark);
  247. detailY.setName(adminName);
  248. detailY.setGtype(Integer.valueOf(type));
  249. // detailY.setUsername(username);
  250. // detailY.setArea(area);
  251. detailY.setProductName(productName);
  252. detailY.setConsumePlatform(String.valueOf(platform));
  253. detailY.setRechargeWay(Way);
  254. detailY.setArea(country);
  255. detailY.setCreateTime(erp.getCreateTime());
  256. detailY.setGold_last(goldLast);
  257. detailY.setUid(uid);
  258. detailY.setUsername(name);
  259. BigDecimal buyJb =userGold.getBuyJb();
  260. BigDecimal coreJb=userGold.getCoreJb();
  261. buyJb = buyJb.add(rechargeJb);
  262. coreJb = coreJb.add(taskJb);
  263. // 设置更新后的Sumgold回到user对象
  264. userGold.setBuyJb(buyJb);
  265. userGold.setCoreJb(coreJb);
  266. LocalDate now = LocalDate.now();
  267. // 判断当前日期是在六月之前还是之后
  268. Month currentMonth = now.getMonth();
  269. boolean isBeforeJune = currentMonth.getValue() < Month.JUNE.getValue();
  270. boolean isJune = currentMonth.getValue() == Month.JUNE.getValue();
  271. boolean isAfterJune = currentMonth.getValue() > Month.JUNE.getValue();
  272. // 根据月份更新 free6 或 free12
  273. if (isBeforeJune||isJune) {
  274. // 如果是六月前,更新 free6
  275. BigDecimal free6 = userGold.getFree6().add(freeJb);
  276. userGold.setFree6(free6);
  277. } else if (isAfterJune) {
  278. // 如果是六月后,更新 free12
  279. BigDecimal free12 = userGold.getFree12().add(freeJb);
  280. userGold.setFree12(free12);
  281. }
  282. recharge.setJwcode(JwCode);
  283. recharge.setPaidGold(rechargeJb);
  284. recharge.setFreeGold(freeJb);
  285. recharge.setRechargeGold(rechargeJb);
  286. recharge.setRechargeWay(Way);
  287. recharge.setPayWay("ERP");
  288. recharge.setRechargeTime(erp.getCreateTime());
  289. recharge.setRemark(remark);
  290. recharge.setAdminName(adminName);
  291. rechargeMapper.insert(recharge);
  292. } else if (typesToUpdateOne.contains(type)) {
  293. System.out.println("消费------------------------------------------------------");
  294. detailY.setUpdateType(1); // 设置 updateType 为 1
  295. detailY.setJwcode(JwCode);
  296. detailY.setGtype(Integer.valueOf(type));
  297. detailY.setRechargeCoin(rechargeJb);
  298. detailY.setFreeCoin(freeJb);
  299. detailY.setTaskCoin(taskJb);
  300. detailY.setRemark(remark);
  301. detailY.setName(adminName);
  302. detailY.setUsername(name);
  303. detailY.setArea(country);
  304. detailY.setProductName(productName);
  305. detailY.setConsumePlatform(String.valueOf(platform));
  306. detailY.setConsumeType(Way);
  307. detailY.setGold_last(goldLast);
  308. detailY.setUid(uid);
  309. detailY.setCreateTime(erp.getCreateTime());
  310. BigDecimal buyJb =userGold.getBuyJb();
  311. BigDecimal coreJb=userGold.getCoreJb();
  312. buyJb = buyJb.add(rechargeJb);
  313. coreJb = coreJb.add(taskJb);
  314. // 设置更新后的Sumgold回到user对象
  315. userGold.setBuyJb(buyJb);
  316. userGold.setCoreJb(coreJb);
  317. LocalDate now = LocalDate.now();
  318. // 判断当前日期是在六月之前还是之后
  319. Month currentMonth = now.getMonth();
  320. boolean isBeforeJune = currentMonth.getValue() < Month.JUNE.getValue();
  321. boolean isJune = currentMonth.getValue() == Month.JUNE.getValue();
  322. boolean isAfterJune = currentMonth.getValue() > Month.JUNE.getValue();
  323. // 根据月份更新 free6 或 free12
  324. if (isBeforeJune||isJune) {
  325. // 如果是六月前,更新 free6
  326. BigDecimal free6 = userGold.getFree6().add(freeJb);
  327. userGold.setFree6(free6);
  328. } else if (isAfterJune) {
  329. // 如果是六月后,更新 free12
  330. BigDecimal free12 = userGold.getFree12().add(freeJb);
  331. userGold.setFree12(free12);
  332. }
  333. } else if (typesToUpdateTwo.contains(type)) {
  334. System.out.println("退款------------------------------------------------------");
  335. detailY.setUpdateType(2); // 设置 updateType 为 2
  336. detailY.setJwcode(JwCode);
  337. detailY.setGtype(Integer.valueOf(type));
  338. detailY.setRechargeCoin(rechargeJb);
  339. detailY.setFreeCoin(freeJb);
  340. detailY.setTaskCoin(taskJb);
  341. detailY.setRemark(remark);
  342. detailY.setName(adminName);
  343. detailY.setUsername(name);
  344. detailY.setArea(country);
  345. detailY.setProductName(productName);
  346. detailY.setConsumePlatform(String.valueOf(platform));
  347. detailY.setRefundType(Way);
  348. detailY.setCreateTime(erp.getCreateTime());
  349. detailY.setGold_last(goldLast);
  350. detailY.setUid(uid);
  351. BigDecimal buyJb =userGold.getBuyJb();
  352. BigDecimal coreJb=userGold.getCoreJb();
  353. buyJb = buyJb.add(rechargeJb);
  354. coreJb = coreJb.add(taskJb);
  355. // 设置更新后的Sumgold回到user对象
  356. userGold.setBuyJb(buyJb);
  357. userGold.setCoreJb(coreJb);
  358. LocalDate now = LocalDate.now();
  359. // 判断当前日期是在六月之前还是之后
  360. Month currentMonth = now.getMonth();
  361. boolean isBeforeJune = currentMonth.getValue() < Month.JUNE.getValue();
  362. boolean isJune = currentMonth.getValue() == Month.JUNE.getValue();
  363. boolean isAfterJune = currentMonth.getValue() > Month.JUNE.getValue();
  364. // 根据月份更新 free6 或 free12
  365. if (isBeforeJune||isJune) {
  366. // 如果是六月前,更新 free6
  367. BigDecimal free6 = userGold.getFree6().add(freeJb);
  368. userGold.setFree6(free6);
  369. } else if (isAfterJune) {
  370. // 如果是六月后,更新 free12
  371. BigDecimal free12 = userGold.getFree12().add(freeJb);
  372. userGold.setFree12(free12);
  373. }
  374. }else if (typesToUpdateThree.contains(type)) {
  375. System.out.println("其他------------------------------------------------------");
  376. detailY.setUpdateType(3); // 设置 updateType 为 3
  377. detailY.setJwcode(JwCode);
  378. detailY.setGtype(Integer.valueOf(type));
  379. detailY.setRechargeCoin(rechargeJb);
  380. detailY.setFreeCoin(freeJb);
  381. detailY.setTaskCoin(taskJb);
  382. detailY.setRemark(remark);
  383. detailY.setName(adminName);
  384. detailY.setUsername(name);
  385. detailY.setArea(country);
  386. detailY.setProductName(productName);
  387. detailY.setConsumePlatform(String.valueOf(platform));
  388. detailY.setReson(Way);
  389. detailY.setCreateTime(erp.getCreateTime());
  390. detailY.setGold_last(goldLast);
  391. detailY.setUid(uid);
  392. BigDecimal buyJb =userGold.getBuyJb();
  393. BigDecimal coreJb=userGold.getCoreJb();
  394. buyJb = buyJb.add(rechargeJb);
  395. coreJb = coreJb.add(taskJb);
  396. // 设置更新后的Sumgold回到user对象
  397. userGold.setBuyJb(buyJb);
  398. userGold.setCoreJb(coreJb);
  399. LocalDate now = LocalDate.now();
  400. // 判断当前日期是在六月之前还是之后
  401. Month currentMonth = now.getMonth();
  402. boolean isBeforeJune = currentMonth.getValue() < Month.JUNE.getValue();
  403. boolean isJune = currentMonth.getValue() == Month.JUNE.getValue();
  404. boolean isAfterJune = currentMonth.getValue() > Month.JUNE.getValue();
  405. // 根据月份更新 free6 或 free12
  406. if (isBeforeJune||isJune) {
  407. // 如果是六月前,更新 free6
  408. BigDecimal free6 = userGold.getFree6().add(freeJb);
  409. userGold.setFree6(free6);
  410. } else if (isAfterJune) {
  411. // 如果是六月后,更新 free12
  412. BigDecimal free12 = userGold.getFree12().add(freeJb);
  413. userGold.setFree12(free12);
  414. }
  415. }
  416. // 添加其他业务逻辑
  417. System.out.println(detailY+"-----测试能否传输------");
  418. userMapper.updateGold(userGold);
  419. return detailYMapper.add(detailY);
  420. }
  421. }