|
|
@@ -0,0 +1,142 @@
|
|
|
+package com.fdkankan.ucenter.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fdkankan.common.constant.ConstantUrl;
|
|
|
+import com.fdkankan.common.util.SecurityUtil;
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
|
+import com.fdkankan.ucenter.common.RedisKeyUtil;
|
|
|
+import com.fdkankan.ucenter.common.constants.ResultCode;
|
|
|
+import com.fdkankan.ucenter.entity.ContactUs;
|
|
|
+import com.fdkankan.ucenter.entity.ContactUsPoint;
|
|
|
+import com.fdkankan.ucenter.entity.MailTemplate;
|
|
|
+import com.fdkankan.ucenter.entity.User;
|
|
|
+import com.fdkankan.ucenter.exception.BusinessException;
|
|
|
+import com.fdkankan.ucenter.geo.IPUtils;
|
|
|
+import com.fdkankan.ucenter.mapper.IContactUsMapper;
|
|
|
+import com.fdkankan.ucenter.service.IContactUsPointService;
|
|
|
+import com.fdkankan.ucenter.service.IContactUsService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fdkankan.ucenter.service.IMailTemplateService;
|
|
|
+import com.fdkankan.ucenter.service.IUserService;
|
|
|
+import com.fdkankan.ucenter.util.DateUserUtil;
|
|
|
+import com.fdkankan.ucenter.vo.request.RegisterParam;
|
|
|
+import com.fdkankan.ucenter.vo.response.LoginVo;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2025-10-20
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class ContactUsServiceImpl extends ServiceImpl<IContactUsMapper, ContactUs> implements IContactUsService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RedisUtil redisUtil;
|
|
|
+ @Autowired
|
|
|
+ IMailTemplateService mailTemplateService;
|
|
|
+ @Autowired
|
|
|
+ IUserService userService;
|
|
|
+ @Autowired
|
|
|
+ LoginService loginService;
|
|
|
+ @Autowired
|
|
|
+ IContactUsPointService contactUsPointService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void submit(ContactUs contactUs) {
|
|
|
+ if(StringUtils.isBlank(contactUs.getName()) || StringUtils.isBlank(contactUs.getTel())
|
|
|
+ || StringUtils.isBlank(contactUs.getEmail()) || StringUtils.isBlank(contactUs.getCompany())){
|
|
|
+ throw new BusinessException(ResultCode.PARAM_MISS);
|
|
|
+ }
|
|
|
+ String redisKey = String.format(RedisKeyUtil.CONTACT_US_KEY,contactUs.getEmail());
|
|
|
+ if(redisUtil.hasKey(redisKey)){
|
|
|
+ throw new BusinessException(ResultCode.email_submit);
|
|
|
+ }
|
|
|
+ String uuid = UUID.randomUUID().toString().replace("-", "");
|
|
|
+ String redisKey2 = String.format(RedisKeyUtil.CONTACT_US_KEY,uuid);
|
|
|
+
|
|
|
+ User user = userService.getByUserName(contactUs.getEmail());
|
|
|
+ if(user !=null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Boolean b = mailTemplateService.sendMail(contactUs.getEmail(), new MailTemplate(), null);
|
|
|
+ if(!b){
|
|
|
+ throw new BusinessException(ResultCode.email_submit_error);
|
|
|
+ }
|
|
|
+
|
|
|
+ redisUtil.set(redisKey, uuid,15 * 60);
|
|
|
+ redisUtil.set(redisKey2, JSONObject.toJSONString(contactUs),15 * 60);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void callBack(String uuid, HttpServletResponse response) {
|
|
|
+
|
|
|
+ String rediskey = String.format(RedisKeyUtil.CONTACT_US_KEY,uuid);
|
|
|
+ String rediskey2 = null;
|
|
|
+ try {
|
|
|
+ if(redisUtil.hasKey(rediskey)){
|
|
|
+ ContactUs contactUs = JSONObject.parseObject(redisUtil.get(rediskey),ContactUs.class);
|
|
|
+ contactUs.setCountry(IPUtils.getCountry(contactUs.getIpAddress()));
|
|
|
+ this.save(contactUs);
|
|
|
+ rediskey2 = String.format(RedisKeyUtil.CONTACT_US_KEY,contactUs.getEmail());
|
|
|
+ User user = userService.getByUserName(contactUs.getEmail());
|
|
|
+ if(user !=null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ User userEntity = new User();
|
|
|
+ userEntity.setPassword(SecurityUtil.MD5("4Dage168."));
|
|
|
+ userEntity.setEmail(contactUs.getEmail());
|
|
|
+ userEntity.setUserName(contactUs.getEmail());
|
|
|
+ userEntity.setNickName(contactUs.getName());
|
|
|
+ userEntity.setHead(ConstantUrl.DEFAULT_USER_HEAD);
|
|
|
+ userEntity.setStatus(1);
|
|
|
+ userEntity.setIsNotice(1);
|
|
|
+ userEntity.setRecStatus("A");
|
|
|
+ userEntity.setCreateTime(DateUserUtil.getDate(new Date()));
|
|
|
+ userEntity.setUpdateTime(DateUserUtil.getDate(new Date()));
|
|
|
+ userEntity.setAgentKey("wherefor");
|
|
|
+ userService.save(userEntity);
|
|
|
+ LoginVo login = loginService.login(userEntity);
|
|
|
+ response.setHeader("token", login.getToken());
|
|
|
+ response.sendRedirect(contactUs.getRedirectUrl());
|
|
|
+ }
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("contact-us-callback-error:{}",e);
|
|
|
+ }finally {
|
|
|
+ redisUtil.del(rediskey);
|
|
|
+ if(rediskey2 != null){
|
|
|
+ redisUtil.del(rediskey2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void point(ContactUsPoint contactUsPoint) {
|
|
|
+ ContactUsPoint contactUsPoint2 = contactUsPointService.getBySessionId(contactUsPoint.getSessionId());
|
|
|
+ if(contactUsPoint2 == null){
|
|
|
+ contactUsPoint.setStopTime(1L);
|
|
|
+ contactUsPoint.setCountry(IPUtils.getCountry(contactUsPoint.getIpAddress()));
|
|
|
+ }
|
|
|
+ if(contactUsPoint2 != null){
|
|
|
+ contactUsPoint.setId(contactUsPoint2.getId());
|
|
|
+ contactUsPoint.setStopTime(contactUsPoint2.getStopTime() + 1);
|
|
|
+ }
|
|
|
+ contactUsPointService.saveOrUpdate(contactUsPoint);
|
|
|
+ }
|
|
|
+}
|