Forráskód Böngészése

大学生快递站

zoujiajian 2 éve
szülő
commit
59ac718b7f

+ 2 - 0
netflix-dao/src/main/java/com/cyksj/mapper/GroupsMapper.java

@@ -41,4 +41,6 @@ public interface GroupsMapper extends BaseMapper<GroupsTrips> {
 	Integer countExpiredNum(Long accountId);
 
 	GroupsTrips selectTicketGroups(@Param("skuId") Long skuId, @Param("status") GroupsTrips.Status status, @Param("maxNum") Integer maxNum, @Param("ip") String ip);
+
+	GroupsTrips selectCollegeStudentUserGptTicket(Long skuId);
 }

+ 13 - 0
netflix-dao/src/main/java/com/cyksj/mapper/station/CollegeStudentStationClickRecordMapper.java

@@ -0,0 +1,13 @@
+package com.cyksj.mapper.station;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.CollegeStudentStationClickRecord;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: CollegeStudentStationClickRecordMapper
+ * 创建者: JavaZou
+ * 创建时间:2024/5/28 11:55
+ */
+public interface CollegeStudentStationClickRecordMapper extends BaseMapper<CollegeStudentStationClickRecord> {
+}

+ 13 - 0
netflix-dao/src/main/java/com/cyksj/mapper/station/CollegeStudentStationUserRelateMapper.java

@@ -0,0 +1,13 @@
+package com.cyksj.mapper.station;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.CollegeStudentStationUserRelate;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: CollegeStudentStationUserRelateMapper
+ * 创建者: JavaZou
+ * 创建时间:2024/5/28 11:57
+ */
+public interface CollegeStudentStationUserRelateMapper extends BaseMapper<CollegeStudentStationUserRelate> {
+}

+ 6 - 0
netflix-dao/src/main/java/com/cyksj/model/dto/AuthRedirect.java

@@ -77,4 +77,10 @@ public class AuthRedirect {
      * 跳转url
      */
     private String url;
+
+    /**
+     * 大学生快递站 进入类型
+     * 1.主动 2.被邀请用户
+     */
+    private Integer cst;
 }

+ 17 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/CollegeStudentStationClickRecord.java

@@ -0,0 +1,17 @@
+package com.cyksj.model.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: CollegeStudentStattionClickRecord
+ * 创建者: JavaZou
+ * 创建时间:2024/5/28 11:55
+ */
+@Getter
+@Setter
+public class CollegeStudentStationClickRecord extends BaseEntity{
+
+	private Long userId;
+}

+ 21 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/CollegeStudentStationUserRelate.java

@@ -0,0 +1,21 @@
+package com.cyksj.model.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: CollegeStudentStationUserRelate
+ * 创建者: JavaZou
+ * 创建时间:2024/5/28 11:56
+ */
+@Getter
+@Setter
+public class CollegeStudentStationUserRelate extends BaseEntity{
+	private Long userId;
+
+	/**
+	 * 1.主动 2.被邀请用户
+	 */
+	private Integer type;
+}

+ 9 - 0
netflix-dao/src/main/resources/mapper/GroupsMapper.xml

@@ -98,4 +98,13 @@
         order by available_num asc
         limit 1
     </select>
+
+    <select id="selectCollegeStudentUserGptTicket" resultType="com.cyksj.model.entity.GroupsTrips">
+        select gt.id
+        from `groups_trips` gt
+        where gt.sku_id = #{skuId}
+          and gt.status = 'validity'
+          and gt.available_num > 0
+        order by rand() limit 1
+    </select>
 </mapper>

+ 6 - 0
netflix-service/pom.xml

@@ -40,6 +40,12 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>com.github.rholder</groupId>
+            <artifactId>guava-retrying</artifactId>
+            <version>2.0.0</version>
+        </dependency>
     </dependencies>
 
 </project>

+ 2 - 0
netflix-service/src/main/java/com/cyksj/service/relation/GroupRelationFrontService.java

@@ -55,4 +55,6 @@ public interface GroupRelationFrontService {
 	List<RenewalView>  getHasPayGoods(long userId);
 
 	List<RenewalView> getExpiryRenewalNotify(Long userId);
+
+	void getCollegeStudentUserGptTicket(Long userId);
 }

+ 50 - 0
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupRelationFrontServiceImpl.java

@@ -39,6 +39,7 @@ import com.ejlchina.searcher.SearchResult;
 import com.ejlchina.searcher.param.Operator;
 import com.ejlchina.searcher.util.MapBuilder;
 import com.ejlchina.searcher.util.MapUtils;
+import com.github.rholder.retry.*;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
@@ -48,6 +49,8 @@ import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.util.*;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
@@ -730,4 +733,51 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 		}
 		return code.trim();
 	}
+
+
+	@Override
+	public void getCollegeStudentUserGptTicket(Long userId) {
+		Retryer<Boolean> build = RetryerBuilder.<Boolean>newBuilder()
+				.retryIfException()
+				//运行时异常重试
+				.retryIfRuntimeException()
+				//false重试
+				.retryIfResult(res -> Objects.equals(res, false))
+				//1s 间隔
+				.withWaitStrategy(WaitStrategies.fixedWait(1, TimeUnit.SECONDS))
+				//停止策略 : 尝试请求3次
+				.withStopStrategy(StopStrategies.stopAfterAttempt(3)).build();
+		try {
+			build.call(() -> {
+				Long gptMirrorSkuId = 429l;
+				GroupsTrips groups = groupsMapper.selectCollegeStudentUserGptTicket(gptMirrorSkuId);
+				GroupsRelation relation = null;
+				if (groups != null) {
+					relation = groupsRelationMapper.selectRandomOneRelationByGroupsId(groups.getId());
+				}
+				if (relation == null) {
+					//生成空车队
+					GoodsDonSku sku = goodsDonSkuMapper.selectById(gptMirrorSkuId);
+					relation = groupsFuncService.createNewGroupsTrips(sku);
+				}
+				DateTime startTime = DateTime.now();
+				DateTime expiryTime = DateUtil.offsetDay(startTime, 1);
+				int update = groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
+						.set(GroupsRelation::getUserId, userId)
+						.set(GroupsRelation::getStartTime, startTime)
+						.set(GroupsRelation::getExpiryTime, expiryTime)
+						.set(GroupsRelation::getStatus, GroupsRelation.Status.validity)
+						.eq(GroupsRelation::getId, relation.getId())
+						.ne(GroupsRelation::getUserId, 0));
+				if (update > 0) {
+					groupsMapper.decrAvailableNum(groups.getId());
+					return true;
+				}
+				log.error("发送用户:{} GPT镜像车票体验失败,进行重试", userId);
+				return false;
+			});
+		} catch (ExecutionException | RetryException e) {
+			log.error("发送用户GPT镜像体验失败:{}", StringUtil.getErrorText(e));
+		}
+	}
 }

+ 11 - 0
netflix-service/src/main/java/com/cyksj/service/station/CollegeStudentStationFService.java

@@ -0,0 +1,11 @@
+package com.cyksj.service.station;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: CollegeStudentStationFService
+ * 创建者: JavaZou
+ * 创建时间:2024/5/28 11:59
+ */
+public interface CollegeStudentStationFService {
+	void saveCollegeStudent(long userId);
+}

+ 26 - 0
netflix-service/src/main/java/com/cyksj/service/station/impl/CollegeStudentStationFServiceImpl.java

@@ -0,0 +1,26 @@
+package com.cyksj.service.station.impl;
+
+import com.cyksj.mapper.station.CollegeStudentStationClickRecordMapper;
+import com.cyksj.model.entity.CollegeStudentStationClickRecord;
+import com.cyksj.service.station.CollegeStudentStationFService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: CollegeStudentStationFServiceImpl
+ * 创建者: JavaZou
+ * 创建时间:2024/5/28 11:59
+ */
+@Service
+@RequiredArgsConstructor
+public class CollegeStudentStationFServiceImpl implements CollegeStudentStationFService {
+	private final CollegeStudentStationClickRecordMapper collegeStudentStationClickRecordMapper;
+
+	@Override
+	public void saveCollegeStudent(long userId) {
+		CollegeStudentStationClickRecord collegeStudentStationClickRecord = new CollegeStudentStationClickRecord();
+		collegeStudentStationClickRecord.setUserId(userId);
+		collegeStudentStationClickRecordMapper.insert(collegeStudentStationClickRecord);
+	}
+}

+ 2 - 1
netflix-service/src/main/java/com/cyksj/service/user/UserService.java

@@ -2,6 +2,7 @@ package com.cyksj.service.user;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.cyksj.dto.UserSharedDto;
+import com.cyksj.model.dto.AuthRedirect;
 import com.cyksj.model.dto.GzhOAuth2UserInfo;
 import com.cyksj.model.dto.UserWhoami;
 import com.cyksj.model.entity.User;
@@ -17,7 +18,7 @@ import java.util.List;
  */
 public interface UserService extends IService<User> {
 
-	User saveAuth(GzhOAuth2UserInfo userinfo, Long sharedId, Integer dsType, Long pid, User.RegisterEnv registerEnv, String dsCode, String callback, String callbackType, String customId) throws Exception;
+	User saveAuth(GzhOAuth2UserInfo userinfo, AuthRedirect re, User.RegisterEnv registerEnv) throws Exception;
 
     UserWhoami whoami(long userId);
 

+ 39 - 2
netflix-service/src/main/java/com/cyksj/service/user/impl/UserServiceImpl.java

@@ -23,6 +23,7 @@ import com.cyksj.mapper.corp.*;
 import com.cyksj.mapper.manage.cps.UserDistributePopularizeMapper;
 import com.cyksj.mapper.manage.distribute.UserDistributeSharedMapper;
 import com.cyksj.mapper.market.task.UserBindDetailMapper;
+import com.cyksj.mapper.station.CollegeStudentStationUserRelateMapper;
 import com.cyksj.model.dto.*;
 import com.cyksj.model.entity.*;
 import com.cyksj.model.request.LoginReq;
@@ -34,6 +35,7 @@ import com.cyksj.service.distribute.equipment.EquipmentDistributeService;
 import com.cyksj.service.exchange.ExchangeCodeService;
 import com.cyksj.service.mange.coupon.CouponCommonService;
 import com.cyksj.service.market.task.BindTaskService;
+import com.cyksj.service.relation.GroupRelationFrontService;
 import com.cyksj.service.shop.YhShopDistributeService;
 import com.cyksj.service.sys.SysConfigService;
 import com.cyksj.service.user.BadIntentionOpService;
@@ -120,10 +122,23 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
 	private final UserDistributeSharedMapper userDistributeSharedMapper;
 
 	private final BadIntentionOpService badIntentionOpService;
+
+	private final CollegeStudentStationUserRelateMapper collegeStudentStationUserRelateMapper;
+
+	private final GroupRelationFrontService groupRelationFrontService;
+
 	private static final GlobalThreadPoolTaskExecutor TASK_POOL = GlobalThreadPoolTaskExecutor.getInstance();
 
 	@Override
-	public User saveAuth(GzhOAuth2UserInfo info, Long sharedId, Integer dsType, Long pid, User.RegisterEnv registerEnv, String dsCode, String callback, String callbackType, String customId) throws Exception {
+	public User saveAuth(GzhOAuth2UserInfo info, AuthRedirect re, User.RegisterEnv registerEnv) throws Exception {
+		Long sharedId = re.getSharedId();
+		Integer dsType = re.getDsType();
+		Long pid = re.getPid();
+		String dsCode = re.getDsCode();
+		String callback = re.getCk();
+		String callbackType = re.getCt();
+		String customId = re.getCd();
+
 		final String unionid = info.getUnionid();
 		if (StrUtil.isEmpty(unionid)) {
 			throw BusinessRuntimeException.getInstance("授权操作异常,请刷新页面");
@@ -172,6 +187,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
 				}
 				//去关联对应企业微信用户
 				relateCorpUserAndSengWelfare(fUid, unionid);
+
+				//是否是大学生快递站进来的用户
+				Integer cst = re.getCst();
+				if (cst != null) {
+					handlerCollegeStudentUser(fUid, cst);
+				}
 			});
 		} else {
 			if (StrUtil.isEmpty(user.getRegisterEnv())) {
@@ -519,7 +540,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
 		String json = Codec.DoBase64.custom().setData(state).decodeAsText();
 		AuthRedirect re = Jsons.parseObject(json, AuthRedirect.class);
 		//保存用户信息
-		User user = saveAuth(userinfo, re.getSharedId(), re.getDsType(), re.getPid(), User.RegisterEnv.pc, re.getDsCode(), re.getCk(), re.getCt(), re.getCd());
+		User user = saveAuth(userinfo, re, User.RegisterEnv.pc);
 		if (user == null) {
 			throw BusinessRuntimeException.getInstance("系统错误,请重新授权");
 		}
@@ -765,4 +786,20 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
 		log.info("建立用户userId:{}与sharedId:{}绑定关系", userId, sharedId);
 		distributeService.saveDistributionInvitation(sharedId, user.getId(), dsPopularizeId);
 	}
+
+	/**
+	 * 处理大学生快递站用户
+	 */
+	public void handlerCollegeStudentUser(Long userId, Integer cst) {
+		try {
+			CollegeStudentStationUserRelate cstRelate = new CollegeStudentStationUserRelate();
+			cstRelate.setType(cst);
+			cstRelate.setUserId(userId);
+			collegeStudentStationUserRelateMapper.insert(cstRelate);
+
+			//赠送1天的GPT镜像车票
+			groupRelationFrontService.getCollegeStudentUserGptTicket(userId);
+		} catch (DuplicateKeyException e) {
+		}
+	}
 }

+ 4 - 3
netflix-web/src/main/java/com/cyksj/web/controller/user/AuthorizationController.java

@@ -93,7 +93,7 @@ public class AuthorizationController {
     private final TemplateCommonService templateCommonService;
 
     @GetMapping(value = "/weChat")
-    public void base(String url, String dsCode, Long sharedId, Integer dsType, Long popularizeId, String authType, String callbackType, String callback, String customId, HttpServletResponse response) throws Exception {
+    public void base(String url, String dsCode, Long sharedId, Integer dsType, Long popularizeId, String authType, String callbackType, String callback, String customId, Integer cst, HttpServletResponse response) throws Exception {
 
         log.info("微信授权转跳. url: {},authType:{}", url, authType);
 
@@ -109,7 +109,8 @@ public class AuthorizationController {
         AuthRedirect redirect = new AuthRedirect().setMappingId(mappingId).setSharedId(sharedId).setDsType(dsType).setPid(popularizeId).setDsCode(dsCode)
                 .setCd(customId)
                 .setCk(callback)
-                .setCt(callbackType);
+                .setCt(callbackType)
+                .setCst(cst);
         String state = Codec.DoBase64.custom().setData(Jsons.toJson(redirect)).encodeAsText();
 
         response.sendRedirect(authorizationService.createUrl(state, authType));
@@ -463,7 +464,7 @@ public class AuthorizationController {
         GzhOAuth2UserInfo userinfo = weChatService.getUserInfo(token.getAccessToken(), token.getOpenid());
 
         //保存用户信息
-        User user = userService.saveAuth(userinfo, re.getSharedId(), re.getDsType(), re.getPid(), registerEnv, re.getDsCode(), re.getCk(), re.getCt(), re.getCd());
+        User user = userService.saveAuth(userinfo, re, registerEnv);
         if (user == null) {
             throw BusinessRuntimeException.getInstance("系统错误,请重新授权");
         }

+ 36 - 0
netflix-web/src/main/java/com/cyksj/web/controller/user/CollegeStudentStationController.java

@@ -0,0 +1,36 @@
+package com.cyksj.web.controller.user;
+
+import com.cyksj.dto.Result;
+import com.cyksj.enums.GatewayResponse;
+import com.cyksj.service.station.CollegeStudentStationFService;
+import com.cyksj.web.util.StpUserUtil;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: CollegeStudentStationController
+ * 创建者: JavaZou
+ * 创建时间:2024/5/28 11:50
+ */
+@Slf4j
+@RestController
+@RequestMapping("/applet/college/student")
+@RequiredArgsConstructor
+public class CollegeStudentStationController {
+	private final CollegeStudentStationFService collegeStudentStationService;
+
+
+	/**
+	 * 大学生 扫码记录
+	 */
+	@PostMapping("/post")
+	public Result<String> saveCollegeStudent() {
+		long userId = StpUserUtil.getLoginIdAsLong();
+		collegeStudentStationService.saveCollegeStudent(userId);
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
+}