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

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