Przeglądaj źródła

Merge branch 'refs/heads/cooperation_info' into pre

zoujiajian 2 miesięcy temu
rodzic
commit
8340684eb7

+ 7 - 0
netflix-dao/src/main/java/com/cyksj/mapper/CooperationInfoMapper.java

@@ -0,0 +1,7 @@
+package com.cyksj.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.CooperationInfo;
+
+public interface CooperationInfoMapper extends BaseMapper<CooperationInfo> {
+}

+ 44 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/CooperationInfo.java

@@ -0,0 +1,44 @@
+package com.cyksj.model.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.hibernate.validator.constraints.Length;
+
+import javax.validation.constraints.NotNull;
+
+@Getter
+@Setter
+public class CooperationInfo extends BaseEntity {
+
+    /**
+     * 产品及规格
+     */
+    @NotNull
+    @Length(max = 1000)
+    private String productSpec;
+
+    /**
+     * 报价
+     */
+    @NotNull
+    @Length(max = 255)
+    private String quotation;
+
+    /**
+     * 联系方式
+     */
+    @NotNull
+    @Length(max = 255)
+    private String contactWay;
+
+    /**
+     * 状态 0-待处理 1-已联系 2-无效
+     */
+    private Integer status;
+
+    /**
+     * 备注
+     */
+    @Length(max = 2000)
+    private String remark;
+}

+ 19 - 0
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpUserServiceImpl.java

@@ -18,6 +18,7 @@ import com.cyksj.model.kf.CorpKfUserInfo;
 import com.cyksj.model.request.corp.CorpCommonReq;
 import com.cyksj.model.request.corp.CorpXmlMessage;
 import com.cyksj.model.views.YHLXUserDetailView;
+import com.cyksj.redis.RedisService;
 import com.cyksj.service.corp.CorpUserService;
 import com.cyksj.service.corp.WxCorpOps;
 import com.cyksj.service.corp.msg.CorpEventActionService;
@@ -77,6 +78,8 @@ public class CorpUserServiceImpl implements CorpUserService {
 
 	private final PhoneCodeMapper phoneCodeMapper;
 
+	private final RedisService redisService;
+
 	@Override
 	public YHLXUserDetailView getUserDetailView(String externalUserid, String corpId) throws Exception {
 		CorpUser corpUser = getExternalUserId(corpId, externalUserid);
@@ -149,6 +152,11 @@ public class CorpUserServiceImpl implements CorpUserService {
 		if (StrUtil.isEmpty(orderNo)) {
 			throw BusinessRuntimeException.getInstance("用户订单号不为空");
 		}
+		String bindLockValue = StrUtil.blankToDefault(orderNo, externalUserid);
+		String bindLockKey = RedisService.key.USER_BIND_ACCOUNT_INFO_KEY.getName() + bindLockValue;
+		if (!redisService.setNx(bindLockKey, bindLockValue, RedisService.key.USER_BIND_ACCOUNT_INFO_KEY.getTimeout())) {
+			throw BusinessRuntimeException.getInstance("account binding, please retry later");
+		}
 		CorpUser corpUser = getExternalUserId(corpId, externalUserid);
 		if (corpUser == null) {
 			throw BusinessRuntimeException.getInstance("添加用户不存在");
@@ -174,6 +182,17 @@ public class CorpUserServiceImpl implements CorpUserService {
 			throw BusinessRuntimeException.getInstance("该订单号对应的用户已绑定微信");
 		}
 		User user = userMapper.selectOne(Wrappers.lambdaQuery(User.class).eq(User::getUnionid, corpUser.getUnionid()).last("limit 1"));
+		if (user == null) {
+			if (!redisService.setNx(RedisService.key.REPEAT_USER_KEY.getNameFormat(corpUser.getUnionid()), corpUser.getUnionid(), RedisService.key.REPEAT_USER_KEY.getTimeout())) {
+				user = userMapper.selectOne(Wrappers.lambdaQuery(User.class).eq(User::getUnionid, corpUser.getUnionid()).last("limit 1"));
+				if (user == null) {
+					throw BusinessRuntimeException.getInstance("account binding, please retry later");
+				}
+			}
+		}
+		if (user == null) {
+			user = userMapper.selectOne(Wrappers.lambdaQuery(User.class).eq(User::getUnionid, corpUser.getUnionid()).last("limit 1"));
+		}
 		if (user == null) {
 			user = new User();
 			user.setNickname(corpUser.getName());

+ 39 - 0
netflix-service/src/main/java/com/cyksj/service/gzh/factory/EventMsgService.java

@@ -22,6 +22,7 @@ import com.cyksj.mapper.manage.coupon.CouponDistributePopularizeMapper;
 import com.cyksj.mapper.manage.coupon.CouponRecommendMapper;
 import com.cyksj.mapper.manage.cps.UserDistributePopularizeMapper;
 import com.cyksj.mapper.manage.distribute.UserDistributeMapper;
+import com.cyksj.mapper.market.task.UserBindDetailMapper;
 import com.cyksj.mapper.nano.NanoUserTrialReceiveRecordMapper;
 import com.cyksj.mapper.station.CollegeStudentStationUserRelateMapper;
 import com.cyksj.model.dto.*;
@@ -102,6 +103,8 @@ public class EventMsgService implements GzhMsgService {
 
 	private final GoodsDonSkuMapper goodsDonSkuMapper;
 
+    private final UserBindDetailMapper userBindDetailMapper;
+
 	private static final GlobalThreadPoolTaskExecutor TASK_POOL = GlobalThreadPoolTaskExecutor.getInstance();
 
 	@Override
@@ -170,6 +173,23 @@ public class EventMsgService implements GzhMsgService {
 			}
 		}
 		Boolean isNewUser = false;
+		if (gzhDto != null) {
+			String bindAccount = StrUtil.blankToDefault(gzhDto.getLoginPhone(), gzhDto.getLoginEmail());
+			if (StrUtil.isNotBlank(bindAccount)) {
+				UserBindDetail bindDetail = getWxBindDetail(gzhDto.getLoginPhone(), gzhDto.getLoginEmail());
+				if (bindDetail != null && bindDetail.getUserId() != null) {
+					user = userMapper.selectById(bindDetail.getUserId());
+				} else {
+					if (!redisService.setNx(RedisService.key.USER_BIND_ACCOUNT_INFO_KEY.getName() + bindAccount, bindAccount, RedisService.key.USER_BIND_ACCOUNT_INFO_KEY.getTimeout())) {
+						return false;
+					}
+					bindDetail = getWxBindDetail(gzhDto.getLoginPhone(), gzhDto.getLoginEmail());
+					if (bindDetail != null && bindDetail.getUserId() != null) {
+						user = userMapper.selectById(bindDetail.getUserId());
+					}
+				}
+			}
+		}
 		if (user == null) {
 			isNewUser = true;
 			user = new User();
@@ -347,6 +367,25 @@ public class EventMsgService implements GzhMsgService {
 		}
 	}
 
+	private UserBindDetail getWxBindDetail(String loginPhone, String loginEmail) {
+		if (StrUtil.isNotBlank(loginPhone)) {
+			UserBindDetail bindDetail = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
+					.eq(UserBindDetail::getPhone, loginPhone)
+					.isNotNull(UserBindDetail::getUserId)
+					.last("limit 1"));
+			if (bindDetail != null) {
+				return bindDetail;
+			}
+		}
+		if (StrUtil.isNotBlank(loginEmail)) {
+			return userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
+					.eq(UserBindDetail::getEmail, loginEmail)
+					.isNotNull(UserBindDetail::getUserId)
+					.last("limit 1"));
+		}
+		return null;
+	}
+
 	public UserSharedDto getUserShredDtoByDsCode(String dsCode) {
 		Long sharedId = 0l;
 		Long dsPopularizeId = 0l;

+ 35 - 3
netflix-service/src/main/java/com/cyksj/service/user/impl/UserServiceImpl.java

@@ -630,14 +630,27 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
 		// 转跳参数
 		String json = Codec.DoBase64.custom().setData(state).decodeAsText();
 		AuthRedirect re = Jsons.parseObject(json, AuthRedirect.class);
+		String loginPhone = re.getLp();
+		String loginEmail = re.getLe();
+		String bindAccount = StrUtil.blankToDefault(loginPhone, loginEmail);
+		if (StrUtil.isNotBlank(bindAccount)) {
+			UserBindDetail bindDetail = getWxBindDetail(loginPhone, loginEmail);
+			if (bindDetail != null && bindDetail.getUserId() != null) {
+				return redisService.getStr(re.getMappingId().toString());
+			}
+			if (!redisService.setNx(RedisService.key.USER_BIND_ACCOUNT_INFO_KEY.getName() + bindAccount, bindAccount, RedisService.key.USER_BIND_ACCOUNT_INFO_KEY.getTimeout())) {
+				throw BusinessRuntimeException.getInstance("account binding, please retry later");
+			}
+			bindDetail = getWxBindDetail(loginPhone, loginEmail);
+			if (bindDetail != null && bindDetail.getUserId() != null) {
+				return redisService.getStr(re.getMappingId().toString());
+			}
+		}
 		//保存用户信息
 		User user = saveAuth(userinfo, re, User.RegisterEnv.pc);
 		if (user == null) {
 			throw BusinessRuntimeException.getInstance("系统错误,请重新授权");
 		}
-		String loginPhone = re.getLp();
-		String loginEmail = re.getLe();
-
 		if (StrUtil.isNotBlank(loginPhone)) {
 			log.info("手机号phone:{}登录用户,微信扫描网页授权二维码进行用户信息绑定", loginPhone);
 			try {
@@ -658,6 +671,25 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
 		return redisService.getStr(re.getMappingId().toString());
 	}
 
+	private UserBindDetail getWxBindDetail(String loginPhone, String loginEmail) {
+		if (StrUtil.isNotBlank(loginPhone)) {
+			UserBindDetail bindDetail = userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
+					.eq(UserBindDetail::getPhone, loginPhone)
+					.isNotNull(UserBindDetail::getUserId)
+					.last("limit 1"));
+			if (bindDetail != null) {
+				return bindDetail;
+			}
+		}
+		if (StrUtil.isNotBlank(loginEmail)) {
+			return userBindDetailMapper.selectOne(Wrappers.lambdaQuery(UserBindDetail.class)
+					.eq(UserBindDetail::getEmail, loginEmail)
+					.isNotNull(UserBindDetail::getUserId)
+					.last("limit 1"));
+		}
+		return null;
+	}
+
 	@Override
 	@Transactional(rollbackFor = Throwable.class)
 	public void receiveGiftCardByRc(Long userId, String code, Long relationId) {

+ 34 - 0
netflix-web/src/main/java/com/cyksj/web/controller/cooperation/CooperationInfoFrontController.java

@@ -0,0 +1,34 @@
+package com.cyksj.web.controller.cooperation;
+
+import com.cyksj.dto.Result;
+import com.cyksj.enums.GatewayResponse;
+import com.cyksj.mapper.CooperationInfoMapper;
+import com.cyksj.model.entity.CooperationInfo;
+import lombok.RequiredArgsConstructor;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * server/合作信息
+ */
+@RestController
+@RequiredArgsConstructor
+@RequestMapping("/applets/cooperation")
+public class CooperationInfoFrontController {
+
+	private final CooperationInfoMapper cooperationInfoMapper;
+
+	/**
+	 * 提交合作信息
+	 */
+	@PostMapping("/info")
+	public Result<String> submit(@RequestBody @Validated CooperationInfo cooperationInfo) {
+		cooperationInfo.setStatus(0);
+		cooperationInfo.setRemark("");
+		cooperationInfoMapper.insert(cooperationInfo);
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
+}

+ 94 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/cooperation/CmsCooperationInfoController.java

@@ -0,0 +1,94 @@
+package com.cyksj.web.controller.manage.cooperation;
+
+import cn.hutool.core.lang.Assert;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.cyksj.dto.Result;
+import com.cyksj.enums.GatewayResponse;
+import com.cyksj.mapper.CooperationInfoMapper;
+import com.cyksj.model.entity.CooperationInfo;
+import com.ejlchina.searcher.BeanSearcher;
+import com.ejlchina.searcher.SearchResult;
+import com.ejlchina.searcher.util.MapUtils;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * admin/合作信息
+ */
+@RestController
+@RequiredArgsConstructor
+@RequestMapping("/manage/cooperation")
+public class CmsCooperationInfoController {
+
+	private final BeanSearcher beanSearcher;
+
+	private final HttpServletRequest request;
+
+	private final CooperationInfoMapper cooperationInfoMapper;
+
+	/**
+	 * 合作信息列表
+	 */
+	@GetMapping("/info/list")
+	public Result<SearchResult<CooperationInfo>> getInfoList() {
+		SearchResult<CooperationInfo> search = beanSearcher.search(CooperationInfo.class, MapUtils.flatBuilder(request.getParameterMap())
+				.orderBy(CooperationInfo::getId).desc()
+				.build());
+		return GatewayResponse.SUCCESS.newBuilder().toResult(search);
+	}
+
+	/**
+	 * 合作信息详情
+	 */
+	@GetMapping("/info/{id}")
+	public Result<CooperationInfo> getInfo(@PathVariable Long id) {
+		return GatewayResponse.SUCCESS.newBuilder().toResult(cooperationInfoMapper.selectById(id));
+	}
+
+	/**
+	 * 是否有待处理合作信息
+	 */
+	@GetMapping("/info/pending/exists")
+	public Result<Boolean> hasPending() {
+		Integer selectCount = cooperationInfoMapper.selectCount(Wrappers.lambdaQuery(CooperationInfo.class)
+				.eq(CooperationInfo::getStatus, 0));
+		return GatewayResponse.SUCCESS.newBuilder().toResult(selectCount > 0);
+	}
+
+	/**
+	 * 标记已联系
+	 */
+	@PutMapping("/info/mark/status/{id}")
+	public Result<String> markStatus(@PathVariable Long id) {
+		cooperationInfoMapper.update(null, Wrappers.lambdaUpdate(CooperationInfo.class)
+				.set(CooperationInfo::getStatus, 1)
+				.eq(CooperationInfo::getId, id)
+				.eq(CooperationInfo::getStatus, 0));
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
+
+	/**
+	 * 标记无效
+	 */
+	@PutMapping("/info/mark/invalid/{id}")
+	public Result<String> markInvalid(@PathVariable Long id) {
+		cooperationInfoMapper.update(null, Wrappers.lambdaUpdate(CooperationInfo.class)
+				.set(CooperationInfo::getStatus, 2)
+				.eq(CooperationInfo::getId, id));
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
+
+	/**
+	 * 修改备注
+	 */
+	@PutMapping("/info/remark")
+	public Result<String> updateRemark(@RequestBody CooperationInfo cooperationInfo) {
+		Assert.notNull(cooperationInfo.getId(), "记录不存在");
+		cooperationInfoMapper.update(null, Wrappers.lambdaUpdate(CooperationInfo.class)
+				.set(CooperationInfo::getRemark, cooperationInfo.getRemark() == null ? "" : cooperationInfo.getRemark())
+				.eq(CooperationInfo::getId, cooperationInfo.getId()));
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
+}