Commit 7dbb7e73 by 章家宝

feat: 新增需求"二手车收车偏好触发节点的变更"相关代码提交,主要改动:1 用户注册的时候就给新增用户偏好,2 新增用户偏好定时任务,系统中没有偏好设置的统一设置一下。

1 parent 88ae07bb
......@@ -7,9 +7,9 @@ import cn.binarywang.wx.miniapp.util.WxMaConfigHolder;
import cn.hutool.core.util.PhoneUtil;
import com.glsx.usedcar.module.account.domain.AccountInfo;
import com.glsx.usedcar.module.account.entity.Account;
import com.glsx.usedcar.module.account.service.AccountPreferenceService;
import com.glsx.usedcar.module.account.service.AccountService;
import com.glsx.usedcar.module.security.domain.MaLoginRequest;
import com.glsx.usedcar.util.NameUtil;
import com.glsx.usedcar.web.AccountJwtProvider;
import com.glsx.usedcar.web.dto.LoginRequest;
import jakarta.annotation.Resource;
......@@ -21,6 +21,7 @@ import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.WxSession;
import me.chanjar.weixin.common.session.WxSessionManager;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*;
import org.summerframework.core.exception.FieldException;
......@@ -55,6 +56,9 @@ public class LoginController extends LoginCommonController {
@Resource
private WxMaService wxMaService;
@Autowired
private AccountPreferenceService accountPreferenceService;
@PostMapping("login")
public Authenticity doLogin(@ModelAttribute LoginRequest loginRequest, HttpServletRequest request) {
Account account;
......@@ -142,6 +146,12 @@ public class LoginController extends LoginCommonController {
account.setCertifiedState(Account.CertifiedState.UNCERTIFIED);
account.setAccountType(Account.AccountType.COMMON);
account = accountService.addAccount(account, maLoginRequest.getRecommendCode());
try {
// 创建用户偏好
accountPreferenceService.addAccountPreferecneIfNot(account);
} catch (Exception e) {
log.error("创建用户偏好失败:{}", e.getMessage());
}
} else {
if (!account.isEnabled()) {
accountInfo.setStatus(403);
......
......@@ -3,6 +3,7 @@ package com.glsx.usedcar.module.account.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.glsx.usedcar.enums.common.DeleteFlag;
import com.glsx.usedcar.module.account.dao.AccountPreferenceDao;
import com.glsx.usedcar.module.account.dto.*;
import com.glsx.usedcar.module.account.entity.*;
......@@ -799,6 +800,26 @@ public class AccountPreferenceService {
});
}
public void addAccountPreferecneIfNot(Account account) {
log.info("添加用户偏好:{}", account.getAccountId());
AccountPreference preference = accountPreferenceDao.findByAccountIdAndDeletedFlag(account.getAccountId(), "N");
if (preference != null) {
return;
}
AccountPreference newPreference = new AccountPreference();
newPreference.setCityCn(" ");
newPreference.setCityName(" ");
newPreference.setCityCode(" ");
newPreference.setAccountId(account.getAccountId());
newPreference.setStatus((byte)0);
newPreference.setUpdatedBy("system");
newPreference.setUpdateTime(LocalDateTime.now());
newPreference.setCreatedBy("system");
newPreference.setCreateTime(LocalDateTime.now());
newPreference.setDeletedFlag(DeleteFlag.NOT_DELETED.getCode());
accountPreferenceDao.save(newPreference);
}
// 用于存储旧数据的容器类
private static class OldDataContainer {
Map<AccountPreferenceValue.PreferenceType, Set<String>> oldValueMap = new HashMap<>();
......
package com.glsx.usedcar.task;
import com.glsx.usedcar.module.account.dao.AccountDao;
import com.glsx.usedcar.module.account.entity.Account;
import com.glsx.usedcar.module.account.service.AccountPreferenceService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.List;
/**
*
*/
@Slf4j
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class FixedAccountPreferenceSchedule {
private final AccountDao accountDao;
private final AccountPreferenceService accountPreferenceService;
/**
* <pre>
* 只运行一次,将数据库中所有没有创建偏好的都给创建一次
* </pre>
*
*/
@Scheduled(initialDelay = 5000)
public void autoBidding() {
long start = System.currentTimeMillis();
try {
List<Account> all = accountDao.findAll();
for (Account account : all) {
accountPreferenceService.addAccountPreferecneIfNot(account);
}
} catch (Exception e) {
log.error("自动将所有的没有创建用户偏好的都给创建一下", e);
}
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!