Ver código fonte

Merge branch 'dev/lh' of https://s-20coaj910c.zht2.com/lwh/seo into dev/lwh

lwh 1 semana atrás
pai
commit
a9b02287d8

+ 90 - 1
pig-marketing/pig-marketing-biz/src/main/java/com/pig4cloud/pig/marketing/service/impl/TcpDataServiceImpl.java

@@ -122,12 +122,101 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 				update.set("updateTime", LocalDateTime.now().format(DATE_TIME_FORMATTER));
 
 				mongoTemplate.updateFirst(query, update, Device.class);
+
+				syncNewUserData(existingDevice, reqDto.getDeviceInfo());
+				synUpdateUserData(existingDevice, reqDto.getDeviceInfo());
+
 				return existingDevice.getId();
 			}
 		}
 		return existingDevice.getId();
 	}
 
+	private void synUpdateUserData(Device device, String deviceInfo) {
+		if (device ==null) {
+			return;
+		}
+		String clientID = device.getClientID();
+
+		// 将deviceInfo从JSON字符串转换为JSON对象
+		JsonNode deviceInfoJson = null;
+		try {
+			if (deviceInfo != null && !deviceInfo.trim().isEmpty()) {
+				String subDeviceInfo = deviceInfo.trim().substring(deviceInfo.indexOf("{"));
+				deviceInfoJson = objectMapper.readTree(subDeviceInfo);
+			}
+		} catch (Exception e) {
+			log.error("syncActiveUserData fail = {}", e.getMessage());
+			return;
+		}
+
+		// 从JSON对象中提取需要的字段
+		String bundle = extractStringFromJson(deviceInfoJson, "bundle", "");
+		String appId = extractStringFromJson(deviceInfoJson, "appId", bundle);
+		String channel = extractStringFromJson(deviceInfoJson, "channel", "应用市场");
+		String version = extractStringFromJson(deviceInfoJson, "version", "0.0.0");
+
+		// 同步新增用户数据 -> mysql
+		// 构建mkt_stat_new_user对象
+		MktStatActiveUser activeUser = new MktStatActiveUser();
+		activeUser.setUserId(clientID);
+		activeUser.setAppId(appId);
+		activeUser.setChannel(channel);
+		activeUser.setVersion(version);
+		activeUser.setStatDate(LocalDateTime.now());
+
+		R<Boolean> result = remoteStatUserDataService.updateMktStatActiveUser(activeUser);
+		if (result.getData() == null || !result.getData()) {
+			log.error("update活跃用户记录失败:clientID = {}", clientID);
+		} else {
+			log.debug("update活跃用户记录成功:clientID = {}, appId = {}, channel = {}", clientID, appId, channel);
+		}
+	}
+
+	private void syncNewUserData(Device device, String deviceInfo) {
+		if (device ==null) {
+			return;
+		}
+
+		String clientID = device.getClientID();
+
+		// 将deviceInfo从JSON字符串转换为JSON对象
+		JsonNode deviceInfoJson = null;
+		try {
+			if (deviceInfo != null && !deviceInfo.trim().isEmpty()) {
+				String subDeviceInfo = deviceInfo.trim().substring(deviceInfo.indexOf("{"));
+				deviceInfoJson = objectMapper.readTree(subDeviceInfo);
+			}
+		} catch (Exception e) {
+			log.error("syncActiveUserData fail = {}", e.getMessage());
+			return;
+		}
+
+		// 从JSON对象中提取需要的字段
+		String bundle = extractStringFromJson(deviceInfoJson, "bundle", "");
+		String appId = extractStringFromJson(deviceInfoJson, "appId", bundle);
+		String channel = extractStringFromJson(deviceInfoJson, "channel", "应用市场");
+		String version = extractStringFromJson(deviceInfoJson, "version", "0.0.0");
+		String oldVersion = extractStringFromJson(deviceInfoJson, "oldVersion", "");
+
+		// 同步新增用户数据 -> mysql
+		// 构建mkt_stat_new_user对象
+		MktStatNewUser mktStatNewUser = new MktStatNewUser();
+		mktStatNewUser.setUserId(clientID);
+		mktStatNewUser.setAppId(appId);
+		mktStatNewUser.setChannel(channel);
+		mktStatNewUser.setVersion(version);
+		mktStatNewUser.setOldVersion(oldVersion);
+		mktStatNewUser.setStatDate(LocalDateTime.now());
+
+		R<Boolean> result = remoteStatUserDataService.updateMktStatNewUser(mktStatNewUser);
+		if (result.getData() == null || !result.getData()) {
+			log.error("update新增用户记录失败:clientID = {}", clientID);
+		} else {
+			log.debug("update新增用户记录成功:clientID = {}, appId = {}, channel = {}", clientID, appId, channel);
+		}
+	}
+
 	private void syncActiveUserData(Device device) {
 		if (device ==null) {
 			return;
@@ -194,7 +283,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 		String bundle = extractStringFromJson(deviceInfoJson, "bundle", "");
 		String appId = extractStringFromJson(deviceInfoJson, "appId", bundle);
 		String channel = extractStringFromJson(deviceInfoJson, "channel", "应用市场");
-		String version = extractStringFromJson(deviceInfoJson, "version", "1.0.0");
+		String version = extractStringFromJson(deviceInfoJson, "version", "0.0.0");
 		String oldVersion = extractStringFromJson(deviceInfoJson, "oldVersion", "");
 
 		// 同步新增用户数据 -> mysql

+ 8 - 0
pig-statistics/pig-statistics-api/src/main/java/com/pig4cloud/pig/statistics/api/feign/RemoteStatUserDataService.java

@@ -20,4 +20,12 @@ public interface RemoteStatUserDataService {
 	@PostMapping("/user/active/save")
 	R<Boolean> saveMktStatActiveUser(@RequestBody MktStatActiveUser data);
 
+	@NoToken
+	@PostMapping("/user/new/update")
+	R<Boolean> updateMktStatNewUser(@RequestBody MktStatNewUser data);
+
+	@NoToken
+	@PostMapping("/user/active/update")
+	R<Boolean> updateMktStatActiveUser(@RequestBody MktStatActiveUser data);
+
 }

+ 14 - 0
pig-statistics/pig-statistics-biz/src/main/java/com/pig4cloud/pig/statistics/controller/UserAnalyseController.java

@@ -56,6 +56,13 @@ public class UserAnalyseController {
 		return R.ok(userAnalyseService.saveMktStatNewUser(data));
 	}
 
+    @Inner
+	@PostMapping("/new/update")
+	@Operation(summary = "修改新增用户信息")
+	R<Boolean> updateMktStatNewUser(@RequestBody MktStatNewUser data){
+		return R.ok(userAnalyseService.updateMktStatNewUser(data));
+	}
+
 	@PostMapping("/new/trend")
 	@Operation(summary = "查询新增趋势")
 	public R<GetNewUserTrendVO> getNewUserTrend(@Valid @RequestBody UserAnalyseQueryBaseDTO reqDto) {
@@ -168,6 +175,13 @@ public class UserAnalyseController {
 		return R.ok(userAnalyseService.saveMktStatActiveUser(data));
 	}
 
+    @Inner
+	@PostMapping("/active/update")
+	@Operation(summary = "修改活跃用户信息")
+	R<Boolean> updateMktStatActiveUser(@RequestBody MktStatActiveUser data){
+		return R.ok(userAnalyseService.updateMktStatActiveUser(data));
+	}
+
 	@PostMapping("/active/trend")
 	@Operation(summary = "查询活跃趋势")
 	public R<GetNewUserTrendVO> getActiveTrend(@Valid @RequestBody UserAnalyseQueryBaseDTO reqDto) {

+ 15 - 1
pig-statistics/pig-statistics-biz/src/main/java/com/pig4cloud/pig/statistics/service/UserAnalyseService.java

@@ -161,9 +161,23 @@ public interface UserAnalyseService {
 	Boolean saveMktStatNewUser(MktStatNewUser data);
 
 	/**
-	 * 保存新增用戶数据
+	 * 保存活跃用戶数据
 	 * @param data
 	 * @return
 	 */
 	Boolean saveMktStatActiveUser(MktStatActiveUser data);
+
+	/**
+	 * 修改新增用户数据
+	 * @param data
+	 * @return
+	 */
+	Boolean updateMktStatNewUser(MktStatNewUser data);
+
+	/**
+	 * 修改活跃用户数据
+	 * @param data
+	 * @return
+	 */
+	Boolean updateMktStatActiveUser(MktStatActiveUser data);
 }

+ 23 - 0
pig-statistics/pig-statistics-biz/src/main/java/com/pig4cloud/pig/statistics/service/impl/UserAnalyseServiceImpl.java

@@ -3,6 +3,7 @@ package com.pig4cloud.pig.statistics.service.impl;
 
 import cn.hutool.core.collection.CollUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.pig4cloud.pig.common.core.exception.BusinessException;
@@ -1170,6 +1171,28 @@ public class UserAnalyseServiceImpl implements UserAnalyseService {
 		return activeUserMapper.insert(data) == 1;
 	}
 
+	@Override
+	public Boolean updateMktStatNewUser(MktStatNewUser data) {
+		LambdaUpdateWrapper<MktStatNewUser> updateWrapper = new LambdaUpdateWrapper<>();
+		updateWrapper.eq(MktStatNewUser::getUserId, data.getUserId());
+		updateWrapper.eq(MktStatNewUser::getVersion, "0.0.0");
+		updateWrapper.eq(MktStatNewUser::getChannel, "应用市场");
+		updateWrapper.set(MktStatNewUser::getAppId, data.getAppId());
+		int update = newUserMapper.update(null, updateWrapper);
+		return update == 1;
+	}
+
+	@Override
+	public Boolean updateMktStatActiveUser(MktStatActiveUser data) {
+		LambdaUpdateWrapper<MktStatActiveUser> updateWrapper = new LambdaUpdateWrapper<>();
+		updateWrapper.eq(MktStatActiveUser::getUserId, data.getUserId());
+		updateWrapper.eq(MktStatActiveUser::getVersion, "0.0.0");
+		updateWrapper.eq(MktStatActiveUser::getChannel, "应用市场");
+		updateWrapper.set(MktStatActiveUser::getAppId, data.getAppId());
+		int update = activeUserMapper.update(null, updateWrapper);
+		return update == 1;
+	}
+
 
 	/************************************** 公用方法 **************************************
 	 * 统计指定时间范围内的新增用户数