Browse Source

Merge branch 'milestone-20250702-金币重构一期' of http://39.101.133.168:8807/huangqizhen/gold-java into milestone-20250702-金币重构一期

lihuilin/hotfix-20250810160509-余额地区传参
lihuilin 1 month ago
parent
commit
eb46e64401
  1. 5
      pom.xml
  2. 4
      src/main/java/com/example/demo/DemoApplication.java
  3. 64
      src/main/java/com/example/demo/Mysql/MysqlController.java
  4. 2
      src/main/java/com/example/demo/Mysql/MysqlService.java
  5. 319
      src/main/java/com/example/demo/Mysql/MysqlServiceImpl.java
  6. 14
      src/main/java/com/example/demo/config/AppConfig.java
  7. 83
      src/main/java/com/example/demo/config/SqlServer1DataSourceConfig.java
  8. 11
      src/main/java/com/example/demo/controller/UserController.java
  9. 16
      src/main/java/com/example/demo/mapper/UserMapper.java
  10. 5
      src/main/java/com/example/demo/password/PasswordGenerator.java
  11. 8
      src/main/java/com/example/demo/service/UserService.java
  12. 6
      src/main/java/com/example/demo/serviceImpl/AuditServiceImpl.java
  13. 25
      src/main/java/com/example/demo/serviceImpl/UserServiceImpl.java
  14. 19
      src/main/resources/application.yml
  15. 3
      src/main/resources/mapper/AuditMapper.xml
  16. 46
      src/main/resources/mapper/UserMapper.xml

5
pom.xml

@ -47,6 +47,11 @@
<version>4.5.14</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>12.4.1.jre11</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.24</version>

4
src/main/java/com/example/demo/DemoApplication.java

@ -1,14 +1,18 @@
package com.example.demo;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableScheduling // 启用调度功能
@MapperScan(basePackages = "com.example.demo.mapper", sqlSessionTemplateRef = "mysql1SqlSessionTemplate")
public class DemoApplication {
public static void main(String[] args) {
System.setProperty("https.protocols", "TLSv1");
SpringApplication.run(DemoApplication.class, args);
}

64
src/main/java/com/example/demo/Mysql/MysqlController.java

@ -1,32 +1,32 @@
//package com.example.demo.Mysql;
//
//import com.example.demo.domain.vo.Result;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.CrossOrigin;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
///**
// * @program: GOLD
// * @ClassName MysqlController
// * @description:
// * @author: huangqizhen
// * @create: 202507-08 15:50
// * @Version 1.0
// **/
//@RestController
//@RequestMapping("/Mysql")
//@RequiredArgsConstructor
//@Slf4j
//@CrossOrigin
//public class MysqlController {
// @Autowired
// MysqlService mysqlService;
// @RequestMapping
// public Result Mysql () throws Exception {
// mysqlService.getSqlserverData();
// return Result.success();
// }
//}
package com.example.demo.Mysql;
import com.example.demo.domain.vo.Result;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @program: GOLD
* @ClassName MysqlController
* @description:
* @author: huangqizhen
* @create: 202507-08 15:50
* @Version 1.0
**/
@RestController
@RequestMapping("/Mysql")
@RequiredArgsConstructor
@Slf4j
@CrossOrigin
public class MysqlController {
@Autowired
MysqlService mysqlService;
@RequestMapping
public Result Mysql () throws Exception {
mysqlService.getSqlserverData();
return Result.success();
}
}

2
src/main/java/com/example/demo/Mysql/MysqlService.java

@ -6,4 +6,6 @@ package com.example.demo.Mysql;/**
@create: 202507-08 15:52
@Version 1.0
**/public interface MysqlService {
void getSqlserverData() throws Exception;
}

319
src/main/java/com/example/demo/Mysql/MysqlServiceImpl.java

@ -1,64 +1,255 @@
//package com.example.demo.Mysql;
//
//import com.example.demo.Mysql.MysqlService;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Service;
//
//import javax.sql.DataSource;
//import java.sql.*;
//import java.time.LocalDateTime;
//
//@Service
//public class MysqlServiceImpl implements MysqlService {
//
// private static final Logger logger = LoggerFactory.getLogger(MysqlServiceImpl.class);
//
// private final DataSource sqlServerDataSource;
// private final DataSource mysqlDataSource;
//
// public MysqlServiceImpl(@Qualifier("sqlServerDataSource") DataSource sqlServerDataSource,
// @Qualifier("mysqlDataSource") DataSource mysqlDataSource) {
// this.sqlServerDataSource = sqlServerDataSource;
// this.mysqlDataSource = mysqlDataSource;
// }
//
// @Override
// @Scheduled(cron = "0 0 * * * ?") // 每小时执行一次
// public void getSqlserverData() {
// logger.info("开始从 SQL Server 同步数据到 MySQL...");
// try (Connection sqlServerConn = sqlServerDataSource.getConnection();
// Connection mysqlConn = mysqlDataSource.getConnection()) {
//
// // SQL Server 查询数据
// String querySql = "SELECT gtype,jwcode, created_at FROM user_gold_records WHERE created_at > ?";
// try (PreparedStatement sqlServerStmt = sqlServerConn.prepareStatement(querySql)) {
// sqlServerStmt.setTimestamp(1, Timestamp.valueOf(LocalDateTime.now().minusHours(1))); // 获取最近一小时的数据
// ResultSet resultSet = sqlServerStmt.executeQuery();
//
// // 插入到 MySQL
// String insertSql = "INSERT INTO target_table (id, name, created_at) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE name = ?";
// try (PreparedStatement mysqlStmt = mysqlConn.prepareStatement(insertSql)) {
// while (resultSet.next()) {
// int id = resultSet.getInt("id");
// String name = resultSet.getString("name");
// Timestamp createdAt = resultSet.getTimestamp("created_at");
//
// mysqlStmt.setInt(1, id);
// mysqlStmt.setString(2, name);
// mysqlStmt.setTimestamp(3, createdAt);
// mysqlStmt.setString(4, name); // 更新时的值
// mysqlStmt.addBatch();
// }
// mysqlStmt.executeBatch(); // 批量插入
// }
// }
// logger.info("数据同步完成");
// } catch (SQLException e) {
// logger.error("数据同步失败", e);
// throw new RuntimeException("数据同步失败", e);
// }
// }
//}
package com.example.demo.Mysql;
import com.example.demo.Util.BaseDES;
import com.example.demo.domain.entity.User;
import com.example.demo.service.AdminService;
import com.example.demo.service.UserService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.http.*;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;
import javax.sql.DataSource;
import java.sql.*;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.format.DateTimeFormatter;
import java.util.*;
@Service
@Transactional
public class MysqlServiceImpl implements MysqlService {
@Autowired
private RestTemplate restTemplate;
Set<Integer> validZeroTypes = new HashSet<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 18, 19, 20, 21, 22, 23, 24, 26, 28, 29, 35, 36, 40, 45, 46, 47, 48, 49, 53, 54, 60));
Set<Integer> validOneTypes = new HashSet<>(Arrays.asList(9, 15, 17, 25, 27, 37, 41, 42, 43, 50, 51, 62));
Set<Integer> validTwoTypes = new HashSet<>(Arrays.asList(52, 55, 56, 57, 58, 59, 61));
Set<Integer> validThreeTypes = new HashSet<>(Arrays.asList(10, 16, 30, 31, 32, 33, 34, 39, 44));
LocalDateTime now = LocalDateTime.now();
Month currentMonth = now.getMonth();
@Autowired
private AdminService adminService;
@Autowired
private UserService userService;
@Autowired
@Qualifier("sqlserver1DataSource")
private DataSource sqlserver1DataSource;
@Autowired
@Qualifier("mysql1DataSource")
private DataSource mysql1DataSource;
private static final Logger logger = LoggerFactory.getLogger(MysqlServiceImpl.class);
@Override
@Scheduled(cron = "0 0 * * * ?") // 每小时执行一次
public void getSqlserverData() throws Exception {
logger.info("开始从 SQL Server 同步数据到 MySQL");
try (Connection sqlServerConn = sqlserver1DataSource.getConnection();
Connection mysqlConn = mysql1DataSource.getConnection()) {
logger.info("开始查询数据...");
// SQL Server 查询数据
String querySql = "SELECT gtype,jwcode,free,core_jb,buy_jb,cz_time,cz_user,cz_bz,operation_platform,goods_name " +
"FROM user_gold_records WHERE flag=1 and cz_time> ?";
try (PreparedStatement sqlServerStmt = sqlServerConn.prepareStatement(querySql)) {
sqlServerStmt.setTimestamp(1, Timestamp.valueOf(LocalDateTime.now().minusHours(1))); // 获取最近一小时的数据
ResultSet resultSet = sqlServerStmt.executeQuery();
logger.info("查询数据完毕!");
// 插入到 MySQL
//退款类型 61ERP退款退金币
String insertSql = "INSERT INTO user_gold_record (order_code,jwcode,sum_gold,permanent_gold,free_june,free_december," +
"task_gold,pay_platform,goods_name,refund_type,refund_model,remark,type,admin_id," +
"audit_status,create_time) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ";
try (PreparedStatement mysqlStmt = mysqlConn.prepareStatement(insertSql)) {
while (resultSet.next()) {
int gtype = resultSet.getInt("gtype");
Integer jwcode = resultSet.getInt("jwcode");
int free = resultSet.getInt("free");
int core_jb = resultSet.getInt("core_jb");
int buy_jb = resultSet.getInt("buy_jb");
Timestamp created_at = resultSet.getTimestamp("cz_time");
String name = resultSet.getString("cz_user");
String remark = resultSet.getString("cz_bz");
String operation_platform = resultSet.getString("operation_platform");
String goods_name = resultSet.getString("goods_name");
String timestampPart = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"));
if(StringUtils.isNumeric(name)){
Integer admin_id = Integer.valueOf(adminService.getId(name));
logger.info("用户传输完毕");
mysqlStmt.setInt(14, admin_id);
}else {
mysqlStmt.setInt(14, 99999);
}
Random random = new Random();
int randomNumber = random.nextInt(900) + 100;
// 判断gtype
if(validZeroTypes.contains(gtype)){
mysqlStmt.setInt(13, 0);
mysqlStmt.setString(1, "ERPCZ"+timestampPart+randomNumber);
}
if(validOneTypes.contains(gtype)){
mysqlStmt.setInt(13, 1);
mysqlStmt.setString(1, "ERPXF"+timestampPart+randomNumber);
}
if(validTwoTypes.contains(gtype)){
mysqlStmt.setInt(13, 2);
mysqlStmt.setString(1, "ERPTK"+timestampPart+randomNumber);
}
if(validThreeTypes.contains(gtype)){
mysqlStmt.setInt(13, 3);
mysqlStmt.setString(1, "ERPQT"+timestampPart+randomNumber);
}
mysqlStmt.setInt(2, jwcode);
mysqlStmt.setInt(3, free+core_jb+buy_jb);
mysqlStmt.setInt(4,buy_jb);
// 判断月份
if(currentMonth.getValue() >= 7){
mysqlStmt.setInt(5, free);
mysqlStmt.setInt(6, 0);
}
if(currentMonth.getValue() < 7){
mysqlStmt.setInt(5, 0);
mysqlStmt.setInt(6, free);
}
mysqlStmt.setInt(7, core_jb);
if (operation_platform.equals("1")){
mysqlStmt.setString(8, "ERP");
}
if (operation_platform.equals("2")){
mysqlStmt.setString(8, "HomilyLink");
}
if(operation_platform.equals("3")){
mysqlStmt.setString(8, "HomilyChart");
}
if(operation_platform.equals("4")){
continue;
}if(operation_platform.equals("0")){
mysqlStmt.setString(8, "初始化金币");
}
else {
mysqlStmt.setString(8, "其他");
}
mysqlStmt.setString(9, goods_name);
mysqlStmt.setString(10,"退款商品");
mysqlStmt.setInt(11, 0);
mysqlStmt.setString(12, remark);
mysqlStmt.setInt(15, 3);
mysqlStmt.setTimestamp(16, created_at);
// 更新时的值
mysqlStmt.addBatch();
logger.info("查询用户是否存在");
User user = userService.selectAllUser(String.valueOf(jwcode));
if(ObjectUtils.isEmpty(user)){
logger.info("用户不存在");
user = new User();
String country = null;
BaseDES des = new BaseDES();
String desjwcode= des.encrypt(String.valueOf(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";
}
user.setJwcode(jwcode);
user.setName( name);
user.setMarket(country);
logger.info("新添用户");
userService.addUser(user);
logger.info("用户添加成功");
user = userService.selectAllUser(String.valueOf(jwcode));
}
user.setSumPermanentGold(user.getSumPermanentGold()+buy_jb);
if(currentMonth.getValue() >= 7){
user.setSumFreeJune(user.getSumFreeJune()+free);
user.setCurrentFreeJune(user.getCurrentFreeJune()+free);
}
if(currentMonth.getValue() <7){
user.setSumFreeDecember(user.getSumFreeDecember()+free);
user.setCurrentFreeDecember(user.getCurrentFreeDecember()+free);
}
user.setSumTaskGold(user.getSumTaskGold()+core_jb);
user.setCurrentPermanentGold(user.getCurrentPermanentGold()+buy_jb);
user.setCurrentTaskGold(user.getCurrentTaskGold()+core_jb);
if(validZeroTypes.contains(gtype)) {
user.setRechargeNum(user.getRechargeNum() + 1);
}
if (validOneTypes.contains(gtype)){
user.setConsumeNum(user.getConsumeNum() + 1);
}
userService.updateAllGold(user);
}
mysqlStmt.executeBatch(); // 批量插入
}
}
logger.info("数据同步完成");
} catch (SQLException e) {
logger.error("数据连接失败", e.getMessage());
throw new RuntimeException("数据链接失败", e);
}
}
}

14
src/main/java/com/example/demo/config/AppConfig.java

@ -0,0 +1,14 @@
package com.example.demo.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
@Configuration
public class AppConfig {
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}

83
src/main/java/com/example/demo/config/SqlServer1DataSourceConfig.java

@ -1,33 +1,34 @@
//package com.example.demo.config;
//
//import com.zaxxer.hikari.HikariDataSource;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.SqlSessionTemplate;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.boot.jdbc.DataSourceBuilder;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//
//import javax.sql.DataSource;
//
//@Slf4j
//@Configuration
//public class SqlServer1DataSourceConfig {
//
// /**
// * 定义 SQL Server 数据源
// */
// @Bean(name = "sqlserver1DataSource")
// @ConfigurationProperties(prefix = "spring.datasource.sqlserver1")
// public DataSource sqlserver1DataSource() {
// log.info("Initializing SQL Server data source...");
// return DataSourceBuilder.create().type(HikariDataSource.class).build();
// }
//
package com.example.demo.config;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import javax.sql.DataSource;
@Slf4j
@Configuration
public class SqlServer1DataSourceConfig {
/**
* 定义 SQL Server 数据源
*/
@Bean(name = "sqlserver1DataSource")
@ConfigurationProperties(prefix = "spring.datasource.sqlserver1")
public DataSource sqlserver1DataSource() {
log.info("Initializing SQL Server data source...");
return DataSourceBuilder.create().type(HikariDataSource.class).build();
}
// /**
// * 定义 SQL Server SqlSessionFactory
// */
@ -50,14 +51,14 @@
// log.info("Initializing SQL Server SqlSessionTemplate...");
// return new SqlSessionTemplate(sqlSessionFactory);
// }
//
// /**
// * 定义全局 MyBatis 配置
// */
// @Bean
// @ConfigurationProperties(prefix = "mybatis.configuration.sqlserver1")
// public org.apache.ibatis.session.Configuration globalConfiguration() {
// log.info("Initializing SQL Server MyBatis global configuration...");
// return new org.apache.ibatis.session.Configuration();
// }
//}
/**
* 定义全局 MyBatis 配置
*/
@Bean
@ConfigurationProperties(prefix = "mybatis.configuration.sqlserver1")
public org.apache.ibatis.session.Configuration globalConfiguration() {
log.info("Initializing SQL Server MyBatis global configuration...");
return new org.apache.ibatis.session.Configuration();
}
}

11
src/main/java/com/example/demo/controller/UserController.java

@ -68,5 +68,14 @@ public class UserController {
return Result.error("请检查属性");
}
}
//检查并更新所有用户的首充时间若有变化
@PostMapping("/updateFirstRecharge")
public Result updateFirstRecharge() {
try {
userService.updateFirstRecharge();
return Result.success("更新成功");
} catch (Exception e) {
return Result.error("更新失败");
}
}
}

16
src/main/java/com/example/demo/mapper/UserMapper.java

@ -3,7 +3,12 @@ package com.example.demo.mapper;
import com.example.demo.domain.entity.User;
import com.example.demo.domain.vo.Gold;
import com.example.demo.domain.vo.GoldUser;
import lombok.Data;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
/**
* @program: gold-java
@ -24,11 +29,18 @@ public interface UserMapper {
void updateGold(User user);
User selectAllUser(String jwcode);
//查询充值次数
Integer selectRechargeNumByJwcode(Integer jwcode);
//获取用户表全部jwcode
List<Integer> getAllJwcode();
//获取某用户最早的充值订单
Date getEarliestRecharge(Integer jwcode);
//更新用户首充日期
void updateFirstRecharge(@Param("jwcode") Integer jwcode,
@Param("firstRecharge") Date firstRecharge);
void updateAllGold(User user);
void addUser(User user);
//根据精网号查询用户
User selectUserByJwcode(Integer jwcode);
}

5
src/main/java/com/example/demo/password/PasswordGenerator.java

@ -20,6 +20,11 @@ public class PasswordGenerator {
// 输出加密后的密码
System.out.println("加密后的密码: " + encodedPassword);
System.out.print("请输入原密码: ");
String qweq = scanner.nextLine();
boolean mat= passwordEncoder.matches(qweq,encodedPassword);
System.out.println("密码匹配结果:"+mat);
// 关闭 Scanner
scanner.close();
}

8
src/main/java/com/example/demo/service/UserService.java

@ -4,6 +4,8 @@ import com.example.demo.domain.entity.User;
import com.example.demo.domain.vo.Gold;
import com.example.demo.domain.vo.GoldUser;
import java.util.List;
/**
* @program: gold-java
* @ClassName UserService
@ -19,8 +21,10 @@ public interface UserService {
GoldUser selectgold(String jwcode);
User selectAllUser(String jwcode);
//更新用户的全部金币
void updateAllGold(User user);
//新增用户
void addUser(User user);
//更新用户的首充时间
void updateFirstRecharge();
}

6
src/main/java/com/example/demo/serviceImpl/AuditServiceImpl.java

@ -4,6 +4,7 @@ import com.example.demo.Util.GoldTistV2;
import com.example.demo.domain.entity.User;
import com.example.demo.domain.entity.UserGoldRecord;
import com.example.demo.domain.vo.Gold;
import com.example.demo.domain.vo.GoldUser;
import com.example.demo.domain.vo.RechargeAudit;
import com.example.demo.domain.vo.RefundAudit;
import com.example.demo.mapper.AuditMapper;
@ -72,7 +73,8 @@ public class AuditServiceImpl implements AuditService {
if (order.getType()==0){ //充值
//更新用户余额
User update = new User();
Integer rechargeNum = userMapper.selectRechargeNumByJwcode(order.getJwcode());
GoldUser gold = userMapper.selectGold(order.getJwcode().toString());
update.setJwcode(order.getJwcode()); //精网号
update.setSumPermanentGold(order.getPermanentGold()); //历史永久金币
update.setSumFreeJune(order.getFreeJune()); //历史六月免费金币
@ -82,7 +84,7 @@ public class AuditServiceImpl implements AuditService {
update.setCurrentFreeJune(order.getFreeJune()); //当前六月免费金币
update.setCurrentFreeDecember(order.getFreeDecember()); //当前十二月免费金币
update.setCurrentTaskGold(order.getTaskGold()); //当前任务金币
update.setRechargeNum(rechargeNum+1); //充值次数加一
update.setRechargeNum(gold.getRechargeNum()+1); //充值次数加一
auditMapper.updateUserGold(update);
//erp增加充值数据
// if(update.getJwcode().equals(94226013)){

25
src/main/java/com/example/demo/serviceImpl/UserServiceImpl.java

@ -7,8 +7,12 @@ import com.example.demo.mapper.ConsumeMapper;
import com.example.demo.mapper.UserMapper;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
* @program: gold-java
* @ClassName UserServiceImpl
@ -46,6 +50,27 @@ public class UserServiceImpl implements UserService {
public void addUser(User user) {
userMapper.addUser(user);
}
/*
每小时更新用户首充时间
*/
@Override
@Scheduled(cron = "0 0 0 * * ?")
public void updateFirstRecharge() {
List<Integer> jwcodeList = userMapper.getAllJwcode();
for(Integer jwcode : jwcodeList){
Date earliestPayTime = userMapper.getEarliestRecharge(jwcode);
if (earliestPayTime != null){
//获取用户的首充时间
Date currentFirstRecharge = userMapper.selectUserByJwcode(jwcode).getFirstRecharge();
//弱国首充时间为空或与最早支付时间不一致则更新
if (currentFirstRecharge == null || !currentFirstRecharge.after(earliestPayTime)){
userMapper.updateFirstRecharge(jwcode, earliestPayTime);
System.out.println("更新了用户" + jwcode + "的首充时间为"+earliestPayTime);
}
}
}
}
@Override
public GoldUser selectgold(String jwcode) {

19
src/main/resources/application.yml

@ -43,14 +43,11 @@ spring:
# hikari:
# pool-name: mysql2HikariCP
# maximum-pool-size: 10
# sqlserver1:
# jdbc-url: jdbc:sqlserver://52.76.43.43:1433/hwhcGold?serverTimezone=Asia/Shanghai
# username: hwhc_gold_query
# password: hwhc_gold_query4564jkj
# driver-class-name: com.mysql.cj.jdbc.Driver
# hikari:
# pool-name: mysql2HikariCP
# maximum-pool-size: 10
sqlserver1:
jdbc-url: jdbc:sqlserver://52.76.43.43:1433;databaseName=hwhcGold;encrypt=true;sslProtocol=TLSv1;trustServerCertificate=true;
username: hwhc_gold_query
password: hwhc_gold_query4564jkj
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
application:
name: demo
@ -85,9 +82,9 @@ mybatis:
mysql1:
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# sqlserver1:
# map-underscore-to-camel-case: true
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
sqlserver1:
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# mysql2:
# map-underscore-to-camel-case: true
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

3
src/main/resources/mapper/AuditMapper.xml

@ -22,7 +22,8 @@
current_permanent_gold = current_permanent_gold + COALESCE(#{currentPermanentGold},0),
current_free_june = current_free_june + COALESCE(#{currentFreeJune},0),
current_free_december = current_free_december + COALESCE(#{currentFreeDecember},0),
current_task_gold = current_task_gold + COALESCE(#{currentTaskGold},0)
current_task_gold = current_task_gold + COALESCE(#{currentTaskGold},0),
recharge_num = recharge_num + COALESCE(#{rechargeNum},0)
where jwcode = #{jwcode}
</update>

46
src/main/resources/mapper/UserMapper.xml

@ -46,13 +46,27 @@
current_free_june AS "NowFreeJune",
current_free_december AS "NowFreeDecember",
current_task_gold AS "NowTaskGold",
consume_num AS "consumeNum"
consume_num AS "consumeNum",
recharge_num AS "rechargeNum"
FROM user
WHERE jwcode = #{jwcode}
</select>
<select id="selectRechargeNumByJwcode" resultType="java.lang.Integer">
select recharge_num from user where jwcode = #{jwcode}
<select id="getAllJwcode" resultType="java.lang.Integer">
SELECT jwcode FROM user
</select>
<!--查用户最早的充值订单-->
<select id="getEarliestRecharge" resultType="java.util.Date">
select min(pay_time)
from user_gold_record
where jwcode = #{jwcode}
and type = 0 and audit_status in (1,3)
</select>
<select id="selectUserByJwcode" resultType="com.example.demo.domain.entity.User">
SELECT *
FROM user
WHERE jwcode = #{jwcode}
</select>
<!-- 根据精网号更新数据 -->
<update id="updateGold" parameterType="com.example.demo.domain.entity.User">
@ -70,17 +84,23 @@
<update id="updateAllGold" parameterType="com.example.demo.domain.entity.User">
UPDATE user
SET
<if test="sum_permanent_gold != null">sum_permanent_gold = #{sumPermanentGold},</if>
<if test="sum_free_june != null">sum_free_june = #{sumFreeJune},</if>
<if test="sum_free_december != null">sum_free_december = #{sumFreeDecember},</if>
<if test="sum_task_gold != null">sum_task_gold = #{sumTaskGold},</if>
<if test="current_permanent_gold != null">current_permanent_gold = #{currentPermanentGold},</if>
<if test="current_free_june != null">current_free_june = #{currentFreeJune},</if>
<if test="current_free_december != null">current_free_december = #{currentFreeDecember},</if>
<if test="current_task_gold != null">current_task_gold = #{currentTaskGold},</if>
<if test="consume_num != null">consume_num = #{consumeNum},</if>
<if test="recharge_num != null">recharge_num = #{rechargeNum}</if>
<if test="sumPermanentGold != null">sum_permanent_gold = #{sumPermanentGold},</if>
<if test="sumFreeJune != null">sum_free_june = #{sumFreeJune},</if>
<if test="sumFreeDecember != null">sum_free_december = #{sumFreeDecember},</if>
<if test="sumTaskGold != null">sum_task_gold = #{sumTaskGold},</if>
<if test="currentPermanentGold != null">current_permanent_gold = #{currentPermanentGold},</if>
<if test="currentFreeJune != null">current_free_june = #{currentFreeJune},</if>
<if test="currentFreeDecember != null">current_free_december = #{currentFreeDecember},</if>
<if test="currentTaskGold != null">current_task_gold = #{currentTaskGold},</if>
<if test="consumeNum != null">consume_num = #{consumeNum},</if>
<if test="rechargeNum != null">recharge_num = #{rechargeNum}</if>
where jwcode = #{jwcode}
</update>
<!--更新用户首充时间-->
<update id="updateFirstRecharge">
update user
set first_recharge = #{firstRecharge}
where jwcode = #{jwcode}
</update>
</mapper>
Loading…
Cancel
Save