|
@@ -1,37 +1,196 @@
|
|
|
package com.tzld.piaoquan.api.service.contentplatform.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.tzld.piaoquan.api.common.enums.ExceptionEnum;
|
|
|
+import com.tzld.piaoquan.api.common.enums.contentplatform.AccountStatusEnum;
|
|
|
+import com.tzld.piaoquan.api.common.exception.CommonException;
|
|
|
+import com.tzld.piaoquan.api.config.JwtInterceptor;
|
|
|
+import com.tzld.piaoquan.api.dao.mapper.contentplatform.ContentPlatformAccountMapper;
|
|
|
+import com.tzld.piaoquan.api.dao.mapper.contentplatform.ContentPlatformVerifyCodeMapper;
|
|
|
+import com.tzld.piaoquan.api.dao.mapper.contentplatform.ext.ContentPlatformAccountMapperExt;
|
|
|
import com.tzld.piaoquan.api.model.param.contentplatform.*;
|
|
|
+import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformAccount;
|
|
|
+import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformAccountExample;
|
|
|
+import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformVerifyCode;
|
|
|
+import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformVerifyCodeExample;
|
|
|
import com.tzld.piaoquan.api.model.vo.contentplatform.AccountLoginVO;
|
|
|
import com.tzld.piaoquan.api.model.vo.contentplatform.AccountVO;
|
|
|
import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformAccountService;
|
|
|
+import com.tzld.piaoquan.growth.common.utils.Md5Util;
|
|
|
+import com.tzld.piaoquan.growth.common.utils.RedisUtils;
|
|
|
+import com.tzld.piaoquan.growth.common.utils.SendShortMessageUtil;
|
|
|
+import com.tzld.piaoquan.growth.common.utils.VerificationCodeGenerator;
|
|
|
+import com.tzld.piaoquan.growth.common.utils.page.Page;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
public class ContentPlatformAccountServiceImpl implements ContentPlatformAccountService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ContentPlatformAccountMapper accountMapper;
|
|
|
+ @Autowired
|
|
|
+ ContentPlatformAccountMapperExt accountMapperExt;
|
|
|
+ @Autowired
|
|
|
+ ContentPlatformVerifyCodeMapper verifyCodeMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisUtils redisUtils;
|
|
|
+
|
|
|
@Override
|
|
|
public AccountLoginVO login(AccountLoginParam param) {
|
|
|
- return null;
|
|
|
+ ContentPlatformAccount account = getAccountByTelNum(param.getTelNum());
|
|
|
+ if (Objects.isNull(account)) {
|
|
|
+ throw new CommonException(ExceptionEnum.ACCOUNT_NOT_EXISTS_WRONG);
|
|
|
+ }
|
|
|
+ Long now = System.currentTimeMillis();
|
|
|
+ if (StringUtils.hasText(param.getPassword())) {
|
|
|
+ String password = Arrays.toString(Base64.getDecoder().decode(param.getPassword()));
|
|
|
+ String md5Password = Md5Util.encoderByMd5(password);
|
|
|
+ if (!account.getPassword().equals(md5Password)) {
|
|
|
+ throw new CommonException(ExceptionEnum.LOGIN_PASSWORD_WRONG);
|
|
|
+ }
|
|
|
+ } else if (StringUtils.hasText(param.getVerifyCode())) {
|
|
|
+ ContentPlatformVerifyCodeExample example = new ContentPlatformVerifyCodeExample();
|
|
|
+ example.createCriteria().andTelNumEqualTo(param.getTelNum()).andCodeEqualTo(param.getVerifyCode());
|
|
|
+ example.setOrderByClause("id desc");
|
|
|
+ List<ContentPlatformVerifyCode> verifyCodeList = verifyCodeMapper.selectByExample(example);
|
|
|
+ if (CollectionUtils.isEmpty(verifyCodeList)) {
|
|
|
+ throw new CommonException(ExceptionEnum.EMAIL_VERIFY_CODE_NOT_EXIST);
|
|
|
+ }
|
|
|
+ ContentPlatformVerifyCode verifyCode = verifyCodeList.get(0);
|
|
|
+ if (verifyCode.getExprieTime() < now) {
|
|
|
+ throw new CommonException(ExceptionEnum.EMAIL_VERIFY_CODE_EXPIRED);
|
|
|
+ }
|
|
|
+ if (verifyCode.getStatus() == 1) {
|
|
|
+ throw new CommonException(ExceptionEnum.EMAIL_VERIFY_CODE_USED);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String token = UUID.randomUUID().toString().replace("-", "");
|
|
|
+
|
|
|
+ AccountLoginVO result = new AccountLoginVO();
|
|
|
+ BeanUtils.copyProperties(account, result);
|
|
|
+ result.setToken(token);
|
|
|
+
|
|
|
+ saveTokenToRedis(result, account.getToken(), token);
|
|
|
+ account.setToken(token);
|
|
|
+ account.setTokenExpireTimestamp(now + 7 * 24 * 60 * 60 * 1000L);
|
|
|
+ accountMapper.updateByPrimaryKey(account);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private ContentPlatformAccount getAccountByTelNum(String telNum) {
|
|
|
+ ContentPlatformAccountExample example = new ContentPlatformAccountExample();
|
|
|
+ example.createCriteria().andTelNumEqualTo(telNum);
|
|
|
+ List<ContentPlatformAccount> accountList = accountMapper.selectByExample(example);
|
|
|
+ if (CollectionUtils.isEmpty(accountList)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return accountList.get(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveTokenToRedis(AccountLoginVO loginInfo, String oldToken, String token) {
|
|
|
+ // 清除老token
|
|
|
+ String info = redisUtils.getString(JwtInterceptor.TOKEN_PREFIX.replace("{token}", oldToken));
|
|
|
+ if (StringUtils.hasText(info)) {
|
|
|
+ redisUtils.del(JwtInterceptor.TOKEN_PREFIX.replace("{token}", oldToken));
|
|
|
+ }
|
|
|
+ String redisKey = JwtInterceptor.TOKEN_PREFIX.replace("{token}", token);
|
|
|
+ redisUtils.setValueWithExpire(redisKey, JSON.toJSONString(loginInfo), 7 * 24 * 60 * 60L);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void sendMessageVerifyCode(AccountSendMessageParam param) {
|
|
|
-
|
|
|
+ String verifyCode = VerificationCodeGenerator.generateVerificationCode(6);
|
|
|
+// SendShortMessageUtil.sendVerifyCode(param.getTelNum(), verifyCode);
|
|
|
+ ContentPlatformVerifyCode verifyCodePO = new ContentPlatformVerifyCode();
|
|
|
+ verifyCodePO.setTelNum(param.getTelNum());
|
|
|
+ verifyCodePO.setCode(verifyCode);
|
|
|
+ verifyCodePO.setExprieTime(System.currentTimeMillis() + 10 * 60 * 1000L);
|
|
|
+ verifyCodeMapper.insertSelective(verifyCodePO);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<AccountVO> pageAccount(AccountListParam param) {
|
|
|
- return null;
|
|
|
+ public Page<AccountVO> pageAccount(AccountListParam param) {
|
|
|
+ Page<AccountVO> result = new Page<>(param.getPageNum(), param.getPageSize());
|
|
|
+ int offset = (param.getPageNum() - 1) * param.getPageSize();
|
|
|
+ int count = accountMapperExt.getAccountCount(param);
|
|
|
+ if (count == 0) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ List<ContentPlatformAccount> accountList = accountMapperExt.getAccountList(param, offset, param.getPageSize());
|
|
|
+ List<AccountVO> list = buildAccountVOList(accountList);
|
|
|
+ result.setTotalSize(count);
|
|
|
+ result.setObjs(list);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<AccountVO> buildAccountVOList(List<ContentPlatformAccount> accountList) {
|
|
|
+ if (CollectionUtils.isEmpty(accountList)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<AccountVO> result = new ArrayList<>();
|
|
|
+ for (ContentPlatformAccount account : accountList) {
|
|
|
+ AccountVO accountVO = new AccountVO();
|
|
|
+ accountVO.setId(account.getId());
|
|
|
+ accountVO.setName(account.getName());
|
|
|
+ accountVO.setIdentity(account.getIdentity());
|
|
|
+ accountVO.setChannel(account.getChannel());
|
|
|
+ accountVO.setContactName(account.getContactName());
|
|
|
+ accountVO.setTelNum(account.getTelNum());
|
|
|
+ accountVO.setCreateTimestamp(account.getCreateTimestamp());
|
|
|
+ result.add(accountVO);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void accountForbidden(AccountForbiddenParam param) {
|
|
|
-
|
|
|
+ ContentPlatformAccount account = accountMapper.selectByPrimaryKey(param.getId());
|
|
|
+ if (Objects.isNull(account)) {
|
|
|
+ throw new CommonException(ExceptionEnum.ACCOUNT_NOT_EXISTS_WRONG);
|
|
|
+ }
|
|
|
+ account.setStatus(AccountStatusEnum.FORBIDDEN.getVal());
|
|
|
+ account.setUpdateAccount(param.getOperator());
|
|
|
+ account.setUpdateTimestamp(System.currentTimeMillis());
|
|
|
+ accountMapper.updateByPrimaryKey(account);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void saveAccount(AccountSaveParam param) {
|
|
|
-
|
|
|
+ List<ContentPlatformAccount> telNumExistList = accountMapperExt.getTelNumExists(param.getId(), param.getTelNum());
|
|
|
+ if (CollectionUtils.isNotEmpty(telNumExistList)) {
|
|
|
+ throw new CommonException(ExceptionEnum.TEL_NUM_EXISTS_WRONG);
|
|
|
+ }
|
|
|
+ List<ContentPlatformAccount> channelExistsList = accountMapperExt.getChannelExists(param.getId(), param.getChannel());
|
|
|
+ if (CollectionUtils.isNotEmpty(channelExistsList)) {
|
|
|
+ throw new CommonException(ExceptionEnum.CHANNEL_EXISTS_WRONG);
|
|
|
+ }
|
|
|
+ Long now = System.currentTimeMillis();
|
|
|
+ ContentPlatformAccount account = new ContentPlatformAccount();
|
|
|
+ account.setName(param.getName());
|
|
|
+ account.setIdentity(param.getIdentity());
|
|
|
+ account.setChannel(param.getChannel());
|
|
|
+ account.setContactName(param.getContactName());
|
|
|
+ account.setTelNum(param.getTelNum());
|
|
|
+ if (StringUtils.hasText(param.getPassword())) {
|
|
|
+ String password = Arrays.toString(Base64.getDecoder().decode(param.getPassword()));
|
|
|
+ account.setPassword(Md5Util.encoderByMd5(password));
|
|
|
+ }
|
|
|
+ account.setUpdateAccount(param.getOperator());
|
|
|
+ account.setUpdateTimestamp(now);
|
|
|
+ if (Objects.isNull(param.getId())) {
|
|
|
+ account.setCreateAccount(param.getOperator());
|
|
|
+ account.setCreateTimestamp(now);
|
|
|
+ accountMapper.insertSelective(account);
|
|
|
+ } else {
|
|
|
+ account.setId(param.getId());
|
|
|
+ accountMapper.updateByPrimaryKey(account);
|
|
|
+ }
|
|
|
}
|
|
|
}
|