BUGFIX:循环依赖导致项目无法启动

This commit is contained in:
2025-07-28 17:27:00 +08:00
parent b1d682a909
commit 39903f3da6
10 changed files with 428 additions and 283 deletions

View File

@@ -0,0 +1,11 @@
package com.ai.da.service;
import com.ai.da.mapper.primary.entity.APIGenerate;
import com.baomidou.mybatisplus.extension.service.IService;
public interface APIGenerateService extends IService<APIGenerate> {
void addAPIGenerateRecordAsync(String taskId, String function, String modelName, String status);
void updateAPIGenerateStatusAsync(String taskId, String status);
}

View File

@@ -0,0 +1,23 @@
package com.ai.da.service;
import com.ai.da.mapper.primary.entity.TrialOrder;
import com.ai.da.model.dto.AccountTrialDTO;
import com.ai.da.model.dto.TrialOrderDTO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
public interface TrialOrderService extends IService<TrialOrder> {
Boolean addTrialUser(AccountTrialDTO accountTrialDTO, HttpServletRequest request);
Boolean trialOrderApproval(List<Long> ids);
IPage<TrialOrder> trialOrderList(TrialOrderDTO trialOrderDTO);
Boolean trialOrderRefuse(List<Long> ids);
Boolean trialUserLogout();
}

View File

@@ -0,0 +1,68 @@
package com.ai.da.service.impl;
import com.ai.da.mapper.primary.APIGenerateMapper;
import com.ai.da.mapper.primary.entity.APIGenerate;
import com.ai.da.service.APIGenerateService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.Objects;
@Slf4j
@Service
public class APIGenerateServiceImpl extends ServiceImpl<APIGenerateMapper, APIGenerate> implements APIGenerateService {
@Async
public void addAPIGenerateRecordAsync(String taskId, String function, String modelName, String status){
log.info("异步执行添加");
if (!StringUtil.isNullOrEmpty(taskId) && !StringUtil.isNullOrEmpty(modelName)){
APIGenerate apiGenerate = new APIGenerate();
apiGenerate.setTaskId(taskId);
apiGenerate.setFunc(function);
apiGenerate.setModelName(modelName);
apiGenerate.setStatus(status);
apiGenerate.setRetry_count(0);
apiGenerate.setCreateTime(LocalDateTime.now());
addAPIGenerateRecord(apiGenerate); // 调用同步方法
}
}
@Transactional
public void addAPIGenerateRecord(APIGenerate apiGenerate) {
baseMapper.insert(apiGenerate);
}
@Async
public void updateAPIGenerateStatusAsync(String taskId, String status){
try {
log.info("异步执行修改");
QueryWrapper<APIGenerate> qw = new QueryWrapper<>();
qw.lambda().eq(APIGenerate::getTaskId, taskId);
APIGenerate apiGenerate = baseMapper.selectOne(qw);
if (Objects.nonNull(apiGenerate)){
if (apiGenerate.getStatus().equals("Ready") || apiGenerate.getStatus().equals("SUCCEEDED")) {
log.warn("当前任务 {} 状态已达Success, 不做修改", taskId);
} else {
apiGenerate.setStatus(status);
apiGenerate.setUpdateTime(LocalDateTime.now());
updateAPIGenerateRecord(apiGenerate);
}
} else {
log.error("任务 {} 在api_generate表中找不到", taskId);
}
} catch (Exception e) {
log.error("更新任务状态失败, taskId: {}, status: {}", taskId, status, e);
}
}
@Transactional
public void updateAPIGenerateRecord(APIGenerate apiGenerate){
baseMapper.updateById(apiGenerate);
}
}

View File

@@ -95,10 +95,10 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
private LibraryService libraryService;
@Resource
private UserLikeGroupService userLikeGroupService;
private TrialOrderMapper trialOrderMapper;
@Resource
private TrialOrderMapper trialOrderMapper;
private TrialOrderService trialOrderService;
@Resource
private QuestionnaireMapper questionnaireMapper;
@@ -646,14 +646,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
@Override
public Boolean trialUserLogout() {
AuthPrincipalVo userInfo = UserContext.getUserHolder();
Account account = accountMapper.selectById(userInfo.getId());
if (account.getIsTrial() != 1) {
throw new BusinessException("用户为正式用户");
}
libraryService.deleteTrialData(userInfo.getId());
userLikeGroupService.deleteTrialData(userInfo.getId());
return Boolean.TRUE;
return trialOrderService.trialUserLogout();
}
@Override
@@ -667,156 +660,17 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
@Override
public Boolean addTrialUser(AccountTrialDTO accountTrialDTO, HttpServletRequest request) {
// 获取用户申请试用IP
String ipAddress = RequestInfoUtil.getIpAddress(request);
boolean link = false;
if (StringUtils.isNotBlank(accountTrialDTO.getRef())) {
link = true;
}
// 先检测试用订单
QueryWrapper<TrialOrder> trialOrderQueryWrapper = new QueryWrapper<>();
trialOrderQueryWrapper.eq("BINARY email", accountTrialDTO.getEmail());
// trialOrderQueryWrapper.lambda().eq(TrialOrder::getIp, ipAddress);
// trialOrderQueryWrapper.lambda().and(wrapper ->
// wrapper.eq(TrialOrder::getEmail, accountTrialDTO.getEmail())
// .or() // OR
// .like(TrialOrder::getUserName, accountTrialDTO.getUserName()));
List<TrialOrder> trialOrders = trialOrderMapper.selectList(trialOrderQueryWrapper);
if (CollectionUtil.isNotEmpty(trialOrders)) {
TrialOrder trialOrder = trialOrders.get(0);
if (trialOrder.getStatus() == 1) {
throw new BusinessException("You have submitted a trial application, please wait for approval.");
}else {
throw new BusinessException("You have already been approved for a trial, please do not apply for the trial again");
}
}
// 先检测用户名和邮箱
QueryWrapper<Account> qw = new QueryWrapper<>();
qw.eq("BINARY user_email", accountTrialDTO.getEmail());
List<Account> accountList = accountMapper.selectList(qw);
if (CollectionUtil.isNotEmpty(accountList) && !accountList.get(0).getSystemUser().equals(0)) {
if (accountList.get(0).getIsTrial() == 1) {
throw new BusinessException("The email has already been registered", ResultEnum.PROMPT.getCode());
} else {
Account account = accountList.get(0);
if (null == account.getValidEndTime() || account.getValidEndTime() > System.currentTimeMillis()) {
throw new BusinessException("The email has already been registered", ResultEnum.PROMPT.getCode());
}
}
}
// 接收到数据后要形成一条使用订单信息
TrialOrder trialOrder = CopyUtil.copyObject(accountTrialDTO, TrialOrder.class);
trialOrder.setCreateTime(LocalDateTime.now());
trialOrder.setStatus(0);
trialOrder.setIp(ipAddress);
trialOrderMapper.insert(trialOrder);
// SendEmailUtil.sendCustomEmail("1023316923@qq.com", null, trialOrder,1);
// SendEmailUtil.sendCustomEmail("calvinwong@aidlab.hk", null, trialOrder,1);
// SendEmailUtil.sendCustomEmail("kaicpang.pang@connect.polyu.hk", null, trialOrder,1);
// 判断当前的试用订单是否自动批准
if (AutoApproved.getStatus()) {
// 改变试用订单状态,新增试用用户
trialOrder.setStatus(1);
trialOrder.setUpdateTime(LocalDateTime.now());
trialOrderMapper.updateById(trialOrder);
Account account = new Account();
if (CollectionUtil.isNotEmpty(accountList)) {
account = CopyUtil.copyObject(accountList.get(0), Account.class);
account.setIsTrial(1);
account.setIsBeginner(1);
account.setSystemUser(3);
account.setValidStartTime(System.currentTimeMillis());
account.setCountry(accountTrialDTO.getCountry());
if (link) {
account.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli()));
} else {
account.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli()));
}
account.setCredits(BigDecimal.valueOf(100));
accountMapper.updateById(account);
} else {
account.setUserName(trialOrder.getUserName());
account.setUserPassword("Third-000000");
account.setUserEmail(trialOrder.getEmail());
account.setLanguage(Language.ENGLISH.name());
account.setCountry(accountTrialDTO.getCountry());
account.setValidStartTime(System.currentTimeMillis());
if (link) {
account.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli()));
} else {
account.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli()));
}
account.setCreateDate(new Date());
account.setIsTrial(1);
account.setIsBeginner(1);
account.setSystemUser(3);
account.setCredits(BigDecimal.valueOf(100));
accountMapper.insert(account);
}
// 发送邮件提醒用户试用用户已创建
// SendEmailUtil.sendCustomEmail("1023316923@qq.com", null, trialOrder,2);
// SendEmailUtil.sendCustomEmail("calvinwong@aidlab.hk", null, trialOrder,2);
// SendEmailUtil.sendCustomEmail("kaicpang.pang@connect.polyu.hk", null, trialOrder,2);
if (trialOrder.getCountry().equals("China")) {
SendEmailUtil.sendCustomEmail(account.getUserEmail(), null, trialOrder, 3, trialOrder.getCountry(), link);
} else {
SendEmailUtil.sendCustomEmail(account.getUserEmail(), null, trialOrder, 3, trialOrder.getCountry(), link);
}
}
return Boolean.TRUE;
return trialOrderService.addTrialUser(accountTrialDTO, request);
}
@Override
public IPage<TrialOrder> trialOrderList(TrialOrderDTO trialOrderDTO) {
QueryWrapper<TrialOrder> qw = new QueryWrapper<>();
qw.lambda().eq(trialOrderDTO.getStatus() != null, TrialOrder::getStatus, trialOrderDTO.getStatus());
return trialOrderMapper.selectPage(new Page<>(trialOrderDTO.getPage(), trialOrderDTO.getSize()), qw);
return trialOrderService.trialOrderList(trialOrderDTO);
}
@Override
public Boolean trialOrderApproval(List<Long> ids) {
for (Long id : ids) {
TrialOrder trialOrder = trialOrderMapper.selectById(id);
trialOrder.setStatus(1);
trialOrder.setUpdateTime(LocalDateTime.now());
trialOrderMapper.updateById(trialOrder);
QueryWrapper<Account> qw = new QueryWrapper<>();
qw.eq("BINARY user_email", trialOrder.getEmail());
List<Account> accountList = accountMapper.selectList(qw);
Account account = new Account();
if (CollectionUtil.isNotEmpty(accountList)) {
account = CopyUtil.copyObject(accountList.get(0), Account.class);
account.setIsTrial(1);
account.setIsBeginner(1);
account.setValidStartTime(System.currentTimeMillis());
account.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli()));
accountMapper.updateById(account);
} else {
account.setUserName(trialOrder.getUserName());
account.setUserPassword("Third-000000");
account.setUserEmail(trialOrder.getEmail());
account.setLanguage(Language.ENGLISH.name());
account.setValidStartTime(System.currentTimeMillis());
account.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli()));
account.setCreateDate(new Date());
account.setIsTrial(1);
account.setIsBeginner(1);
account.setSystemUser(1);
accountMapper.insert(account);
}
// 发送邮件提醒用户试用用户已创建
// SendEmailUtil.sendCustomEmail("1023316923@qq.com", null, trialOrder,2, trialOrder.getCountry());
// SendEmailUtil.sendCustomEmail("calvinwong@aidlab.hk", null, trialOrder,2, trialOrder.getCountry());
// SendEmailUtil.sendCustomEmail("kaicpang.pang@connect.polyu.hk", null, trialOrder,2, trialOrder.getCountry());
if (trialOrder.getCountry().equals("China")) {
SendEmailUtil.sendCustomEmail(account.getUserEmail(), null, trialOrder, 3, trialOrder.getCountry(), false);
} else {
SendEmailUtil.sendCustomEmail(account.getUserEmail(), null, trialOrder, 3, trialOrder.getCountry(), false);
}
}
return Boolean.TRUE;
return trialOrderService.trialOrderApproval(ids);
}
@Override
@@ -832,13 +686,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
@Override
public Boolean trialOrderRefuse(List<Long> ids) {
for (Long id : ids) {
TrialOrder trialOrder = trialOrderMapper.selectById(id);
trialOrder.setStatus(2);
trialOrder.setUpdateTime(LocalDateTime.now());
trialOrderMapper.updateById(trialOrder);
}
return Boolean.TRUE;
return trialOrderService.trialOrderRefuse(ids);
}
@Override

View File

@@ -10,6 +10,7 @@ import com.ai.da.common.response.ResultEnum;
import com.ai.da.common.utils.*;
import com.ai.da.mapper.primary.CollectionElementMapper;
import com.ai.da.mapper.primary.GenerateDetailMapper;
import com.ai.da.mapper.primary.GenerateMapper;
import com.ai.da.mapper.primary.entity.*;
import com.ai.da.model.dto.*;
import com.ai.da.model.enums.ModelType;
@@ -68,7 +69,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
@Resource
private SysFileService sysFileService;
@Resource
private GenerateService generateService;
private GenerateMapper generateMapper;
@Resource
private GenerateDetailMapper generateDetailMapper;
@Resource
@@ -268,7 +269,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
// 保存合成信息到generate表
Generate generate = setGenerate(userId, generatePrintDTO.getTimeZone());
generateService.save(generate);
generateMapper.insert(generate);
// 保存合成后的信息到generateDetail
GenerateDetail generateDetail = setGenerateDetail(generate.getId(), generateUrl, generatePrintDTO.getTimeZone());
@@ -718,7 +719,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
private List<CollectionElement> covertGeneratesToCollections(List<GenerateDetail> generateDetailList, Map<Long, CollectionSketchDTO> idToMap) {
return CopyUtil.copyList(generateDetailList, CollectionElement.class, (o, d) -> {
Generate byId = generateService.getById(o.getGenerateId());
Generate byId = generateMapper.selectById(o.getGenerateId());
d.setAccountId(byId.getAccountId());
d.setLevel1Type(byId.getLevel1Type());
d.setCreateDate(Date.from(o.getCreateDate().atZone(ZoneId.systemDefault()).toInstant()));
@@ -741,7 +742,7 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
private List<CollectionElement> covertGeneratesToPrintCollections(List<GenerateDetail> generateDetailList, Map<Long, DesignCollectionPrintElementDTO> idToMap) {
return CopyUtil.copyList(generateDetailList, CollectionElement.class, (o, d) -> {
Generate byId = generateService.getById(o.getGenerateId());
Generate byId = generateMapper.selectById(o.getGenerateId());
d.setAccountId(byId.getAccountId());
d.setLevel1Type(byId.getLevel1Type());
if (!StringUtils.isEmpty(byId.getLevel2Type())) {

View File

@@ -109,6 +109,22 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
private CloudTaskService cloudTaskService;
@Resource
private APIGenerateMapper apiGenerateMapper;
@Resource
private CollectionSortMapper collectionSortMapper;
@Resource
private SysFileService sysFileService;
@Resource
private LibraryModelPointService libraryModelPointService;
@Resource
private PoseTransformationMapper poseTransformationMapper;
@Resource
private CloudTaskMapper cloudTaskMapper;
@Resource
private ToProductImageResultMapper toProductImageResultMapper;
@Resource
private AccountService accountService;
@Resource
private APIGenerateService apiGenerateService;
@Value("${redis.key.orderForGenerate}")
private String consumptionOrderKey;
@@ -144,9 +160,6 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
private String FREEPIK_API_KEY;
@Resource
private AccountService accountService;
// 创建 Random 对象
Random random = new Random();
@@ -318,9 +331,6 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
}
}
@Resource
private ToProductImageResultMapper toProductImageResultMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public void processToProductImageResult(String taskId, String url, String category) {
@@ -536,6 +546,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
generateDetailMapper.update(generateDetail, queryWrapper);
}
// 避免循环注入已移到libraryService中
public void updateLikeStatusBatch(List<Long> generateDetailIdList, Byte hasLike, Long libraryId, String timeZone) {
QueryWrapper<GenerateDetail> queryWrapper = new QueryWrapper<>();
queryWrapper.in("id", generateDetailIdList);
@@ -548,6 +559,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
generateDetailMapper.update(generateDetail, queryWrapper);
}
// 避免循环注入已移到libraryService中
public List<GenerateDetail> selectBatchByLibraryId(List<Long> libraryId) {
QueryWrapper<GenerateDetail> qw = new QueryWrapper<>();
qw.in("library_id", libraryId);
@@ -1112,11 +1124,8 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
return baseMapper.selectList(qw);
}
@Resource
private GenerateMapper generateMapper;
public List<Map<String, Object>> getCountByUserAndTime(String startTime, String endTime, List<Long> accountIdList) {
List<Map<String, Object>> byTypeAndTime = generateMapper.getByTypeAndTime(startTime, endTime, accountIdList);
List<Map<String, Object>> byTypeAndTime = baseMapper.getByTypeAndTime(startTime, endTime, accountIdList);
return byTypeAndTime;
}
@@ -1470,7 +1479,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
taskId = animateAnyone(poseTransformDTO, accountId);
if (!StringUtil.isNullOrEmpty(taskId)){
isRequestSuccess = true;
addAPIGenerateRecordAsync(taskId, Module.poseTransfer.getValue(), "wx", "Pending");
apiGenerateService.addAPIGenerateRecordAsync(taskId, Module.poseTransfer.getValue(), "wx", "Pending");
}
poseTransformation.setModelName("wx");
} else {
@@ -1535,13 +1544,6 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
return null;
}
@Resource
private PoseTransformationMapper poseTransformationMapper;
@Resource
private CloudTaskMapper cloudTaskMapper;
@Resource
private DesignService designService;
public void processPoseTransformResult(String taskId, String gifUrl, String videoUrl, String imageUrl) {
// 1、存储模型返回的数据
PoseTransformation poseTransformation;
@@ -1816,12 +1818,6 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
return collectionSort;
}
@Resource
private SysFileService sysFileService;
@Resource
private LibraryModelPointService libraryModelPointService;
public String modifyModelProportion(ModifyModelProportionDTO proportionDTO) {
log.info("modifyModelProportion params: {}", proportionDTO);
String name;
@@ -2048,8 +2044,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
}
}
@Resource
private CollectionSortMapper collectionSortMapper;
@Transactional(rollbackFor = Exception.class)
public void deleteGeneratedPose(Long projectId, Long id) {
@@ -2455,7 +2450,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
String videoUrl = output.getStr("video_url");
String status = output.getStr("task_status");
updateTaskStatusAsync(taskId, status);
apiGenerateService.updateAPIGenerateStatusAsync(taskId, status);
PoseTransformationVO poseTransformationVO = new PoseTransformationVO();
switch (status) {
@@ -2815,7 +2810,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
String key = RedisUtil.FLUX_POLLING_URL + taskId;
redisUtil.addToString(key, pollingUrl, CommonConstant.GENERATE_RESULT_EXPIRE_TIME);
// 添加到api_generate表中以便之后对结果查询做补偿
addAPIGenerateRecordAsync(taskId, func.getName(), "flux", "Pending");
apiGenerateService.addAPIGenerateRecordAsync(taskId, func.getName(), "flux", "Pending");
return taskId;
}
@@ -2843,7 +2838,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
String status = respObj.getStr("status");
// 异步更新状态
updateTaskStatusAsync(taskId, status);
apiGenerateService.updateAPIGenerateStatusAsync(taskId, status);
// 处理不同状态
switch (status) {
@@ -2899,15 +2894,6 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
}
}
@Async
public void updateTaskStatusAsync(String taskId, String status) {
try {
updateAPIGenerateStatusAsync(taskId, status);
} catch (Exception e) {
log.error("更新任务状态失败, taskId: {}, status: {}", taskId, status, e);
}
}
private GenerateResultVO getFluxResultAndSave(String taskId) {
Generate generate = selectByUniqueId(taskId);
if (Objects.nonNull(generate)) {
@@ -2967,43 +2953,5 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
}
}
@Async
@Transactional
public void addAPIGenerateRecordAsync(String taskId, String function, String modelName, String status){
try {
log.info("异步执行添加");
if (!StringUtil.isNullOrEmpty(taskId) && !StringUtil.isNullOrEmpty(modelName)){
APIGenerate apiGenerate = new APIGenerate();
apiGenerate.setTaskId(taskId);
apiGenerate.setFunc(function);
apiGenerate.setModelName(modelName);
apiGenerate.setStatus(status);
apiGenerate.setRetry_count(0);
apiGenerate.setCreateTime(LocalDateTime.now());
apiGenerateMapper.insert(apiGenerate);
}
} catch (Exception e){
log.error(e.getMessage());
}
}
@Async
@Transactional
public void updateAPIGenerateStatusAsync(String taskId, String status){
log.info("异步执行修改");
QueryWrapper<APIGenerate> qw = new QueryWrapper<>();
qw.lambda().eq(APIGenerate::getTaskId, taskId);
APIGenerate apiGenerate = apiGenerateMapper.selectOne(qw);
if (Objects.nonNull(apiGenerate)){
if (apiGenerate.getStatus().equals("Ready") || apiGenerate.getStatus().equals("SUCCEEDED")) {
log.warn("当前任务 {} 状态已达Success, 不做修改", taskId);
} else {
apiGenerate.setStatus(status);
apiGenerate.setUpdateTime(LocalDateTime.now());
apiGenerateMapper.updateById(apiGenerate);
}
} else {
log.error("任务 {} 在api_generate表中找不到", taskId);
}
}
}

View File

@@ -78,8 +78,6 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
@Resource
private ClassificationService classificationService;
@Resource
private GenerateService generateService;
@Resource
private MinioUtil minioUtil;
@Resource
private AccountMapper accountMapper;
@@ -87,6 +85,16 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
private EductionLibraryMapper eductionLibraryMapper;
@Resource
private EnterpriseLibraryMapper enterpriseLibraryMapper;
@Resource
private LibraryCopyMapper libraryCopyMapper;
@Resource
private LibraryModelPointCopyMapper libraryModelPointCopyMapper;
@Resource
private PythonTAllInfoService pythonTAllInfoService;
@Resource
private BrandRelLibraryMapper brandRelLibraryMapper;
@Resource
private GenerateDetailMapper generateDetailMapper;
@Value("${minio.bucketName.users}")
private String users;
@@ -101,12 +109,6 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
@Value("${access.python.address}")
private String fastApiPythonAddress;
@Resource
private PythonTAllInfoService pythonTAllInfoService;
@Resource
private BrandRelLibraryMapper brandRelLibraryMapper;
private static List<String> top = Arrays.asList(CollectionLevel2TypeEnum.DRESS.getRealName(),
CollectionLevel2TypeEnum.OUTWEAR.getRealName(), CollectionLevel2TypeEnum.BLOUSE.getRealName());
private static List<String> bottom = Arrays.asList(CollectionLevel2TypeEnum.SKIRT.getRealName(),
@@ -536,11 +538,11 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
libraryMapper.deleteBatchIds(deleteDTO.getLibraryIds());
// 1、确定该libraryId是否被generateDetail引用
List<GenerateDetail> generateDetails = generateService.selectBatchByLibraryId(deleteDTO.getLibraryIds());
List<GenerateDetail> generateDetails = selectBatchByLibraryId(deleteDTO.getLibraryIds());
// 2、有则更新generateDetail表的is_like字段和library_id字段
if (!generateDetails.isEmpty()){
generateService.updateLikeStatusBatch(
updateLikeStatusBatch(
generateDetails.stream().map(GenerateDetail::getId).collect(Collectors.toList()),
(byte)0,
0L,
@@ -556,6 +558,25 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
}
public List<GenerateDetail> selectBatchByLibraryId(List<Long> libraryId) {
QueryWrapper<GenerateDetail> qw = new QueryWrapper<>();
qw.in("library_id", libraryId);
return generateDetailMapper.selectList(qw);
}
public void updateLikeStatusBatch(List<Long> generateDetailIdList, Byte hasLike, Long libraryId, String timeZone) {
QueryWrapper<GenerateDetail> queryWrapper = new QueryWrapper<>();
queryWrapper.in("id", generateDetailIdList);
GenerateDetail generateDetail = new GenerateDetail();
generateDetail.setIsLike(hasLike);
generateDetail.setLibraryId(libraryId);
generateDetail.setUpdateDate(DateUtil.getByTimeZone(timeZone));
generateDetailMapper.update(generateDetail, queryWrapper);
}
@Override
public void deleteTrialData(Long userId) {
QueryWrapper<Library> qw = new QueryWrapper<>();
@@ -563,10 +584,6 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
libraryMapper.delete(qw);
}
@Resource
private LibraryCopyMapper libraryCopyMapper;
@Resource
private LibraryModelPointCopyMapper libraryModelPointCopyMapper;
@Override
public void moveLibraryDate() throws ParseException {
QueryWrapper<LibraryCopy> qw = new QueryWrapper<>();

View File

@@ -23,15 +23,12 @@ import java.util.stream.Collectors;
@Slf4j
@Service
public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> implements ProjectService {
@Resource
private ProjectMapper projectMapper;
@Override
public Set<Long> getChildProjectIdSet(Long projectId) {
QueryWrapper<Project> qw = new QueryWrapper<>();
// qw.lambda().eq(Project::getParentId, projectId);
List<Project> projectList = projectMapper.selectList(qw);
List<Project> projectList = baseMapper.selectList(qw);
if (CollectionUtil.isNotEmpty(projectList)) {
return projectList.stream().map(Project::getId).collect(Collectors.toSet());
}
@@ -42,7 +39,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
public List<Project> getByProjectNameLike(String projectName) {
QueryWrapper<Project> qw = new QueryWrapper<>();
qw.lambda().like(Project::getName, projectName);
return projectMapper.selectList(qw);
return baseMapper.selectList(qw);
}
@Resource

View File

@@ -0,0 +1,238 @@
package com.ai.da.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.ai.da.common.config.exception.BusinessException;
import com.ai.da.common.context.UserContext;
import com.ai.da.common.response.ResultEnum;
import com.ai.da.common.utils.CopyUtil;
import com.ai.da.common.utils.RequestInfoUtil;
import com.ai.da.common.utils.SendEmailUtil;
import com.ai.da.mapper.primary.AccountMapper;
import com.ai.da.mapper.primary.TrialOrderMapper;
import com.ai.da.mapper.primary.entity.Account;
import com.ai.da.mapper.primary.entity.TrialOrder;
import com.ai.da.model.dto.AccountTrialDTO;
import com.ai.da.model.dto.TrialOrderDTO;
import com.ai.da.model.enums.AutoApproved;
import com.ai.da.model.enums.Language;
import com.ai.da.model.vo.AuthPrincipalVo;
import com.ai.da.service.LibraryService;
import com.ai.da.service.TrialOrderService;
import com.ai.da.service.UserLikeGroupService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.time.*;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.List;
@Service
public class TrialOrderServiceImpl extends ServiceImpl<TrialOrderMapper, TrialOrder> implements TrialOrderService {
@Resource
private AccountMapper accountMapper;
@Resource
private LibraryService libraryService;
@Resource
private UserLikeGroupService userLikeGroupService;
@Override
public Boolean addTrialUser(AccountTrialDTO accountTrialDTO, HttpServletRequest request) {
// 获取用户申请试用IP
String ipAddress = RequestInfoUtil.getIpAddress(request);
boolean link = false;
if (StringUtils.isNotBlank(accountTrialDTO.getRef())) {
link = true;
}
// 先检测试用订单
QueryWrapper<TrialOrder> trialOrderQueryWrapper = new QueryWrapper<>();
trialOrderQueryWrapper.eq("BINARY email", accountTrialDTO.getEmail());
// trialOrderQueryWrapper.lambda().eq(TrialOrder::getIp, ipAddress);
// trialOrderQueryWrapper.lambda().and(wrapper ->
// wrapper.eq(TrialOrder::getEmail, accountTrialDTO.getEmail())
// .or() // OR
// .like(TrialOrder::getUserName, accountTrialDTO.getUserName()));
List<TrialOrder> trialOrders = baseMapper.selectList(trialOrderQueryWrapper);
if (CollectionUtil.isNotEmpty(trialOrders)) {
TrialOrder trialOrder = trialOrders.get(0);
if (trialOrder.getStatus() == 1) {
throw new BusinessException("You have submitted a trial application, please wait for approval.");
}else {
throw new BusinessException("You have already been approved for a trial, please do not apply for the trial again");
}
}
// 先检测用户名和邮箱
QueryWrapper<Account> qw = new QueryWrapper<>();
qw.eq("BINARY user_email", accountTrialDTO.getEmail());
List<Account> accountList = accountMapper.selectList(qw);
if (CollectionUtil.isNotEmpty(accountList) && !accountList.get(0).getSystemUser().equals(0)) {
if (accountList.get(0).getIsTrial() == 1) {
throw new BusinessException("The email has already been registered", ResultEnum.PROMPT.getCode());
} else {
Account account = accountList.get(0);
if (null == account.getValidEndTime() || account.getValidEndTime() > System.currentTimeMillis()) {
throw new BusinessException("The email has already been registered", ResultEnum.PROMPT.getCode());
}
}
}
// 接收到数据后要形成一条使用订单信息
TrialOrder trialOrder = CopyUtil.copyObject(accountTrialDTO, TrialOrder.class);
trialOrder.setCreateTime(LocalDateTime.now());
trialOrder.setStatus(0);
trialOrder.setIp(ipAddress);
baseMapper.insert(trialOrder);
// SendEmailUtil.sendCustomEmail("1023316923@qq.com", null, trialOrder,1);
// SendEmailUtil.sendCustomEmail("calvinwong@aidlab.hk", null, trialOrder,1);
// SendEmailUtil.sendCustomEmail("kaicpang.pang@connect.polyu.hk", null, trialOrder,1);
// 判断当前的试用订单是否自动批准
if (AutoApproved.getStatus()) {
// 改变试用订单状态,新增试用用户
trialOrder.setStatus(1);
trialOrder.setUpdateTime(LocalDateTime.now());
baseMapper.updateById(trialOrder);
Account account = new Account();
if (CollectionUtil.isNotEmpty(accountList)) {
account = CopyUtil.copyObject(accountList.get(0), Account.class);
account.setIsTrial(1);
account.setIsBeginner(1);
account.setSystemUser(3);
account.setValidStartTime(System.currentTimeMillis());
account.setCountry(accountTrialDTO.getCountry());
if (link) {
account.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli()));
} else {
account.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli()));
}
account.setCredits(BigDecimal.valueOf(100));
accountMapper.updateById(account);
} else {
account.setUserName(trialOrder.getUserName());
account.setUserPassword("Third-000000");
account.setUserEmail(trialOrder.getEmail());
account.setLanguage(Language.ENGLISH.name());
account.setCountry(accountTrialDTO.getCountry());
account.setValidStartTime(System.currentTimeMillis());
if (link) {
account.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli()));
} else {
account.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli()));
}
account.setCreateDate(new Date());
account.setIsTrial(1);
account.setIsBeginner(1);
account.setSystemUser(3);
account.setCredits(BigDecimal.valueOf(100));
accountMapper.insert(account);
}
// 发送邮件提醒用户试用用户已创建
// SendEmailUtil.sendCustomEmail("1023316923@qq.com", null, trialOrder,2);
// SendEmailUtil.sendCustomEmail("calvinwong@aidlab.hk", null, trialOrder,2);
// SendEmailUtil.sendCustomEmail("kaicpang.pang@connect.polyu.hk", null, trialOrder,2);
if (trialOrder.getCountry().equals("China")) {
SendEmailUtil.sendCustomEmail(account.getUserEmail(), null, trialOrder, 3, trialOrder.getCountry(), link);
} else {
SendEmailUtil.sendCustomEmail(account.getUserEmail(), null, trialOrder, 3, trialOrder.getCountry(), link);
}
}
return Boolean.TRUE;
}
// 将指定unix时间置为当天的235959
public long toDayEnd(long unixTimestampMillis){
// 将UNIX时间戳转换为LocalDateTime对象
LocalDateTime dateTime = Instant.ofEpochMilli(unixTimestampMillis)
.atZone(ZoneId.systemDefault())
.toLocalDateTime();
// 获取日期部分并设置时间为23:59:59
LocalDate date = dateTime.toLocalDate();
LocalDateTime endOfDay = date.atTime(LocalTime.of(23, 59, 59));
// 将LocalDateTime对象转换为UNIX时间戳以毫秒为单位 北京时间
return endOfDay.toInstant(ZoneOffset.ofHours(8)).toEpochMilli();
}
@Override
public IPage<TrialOrder> trialOrderList(TrialOrderDTO trialOrderDTO) {
QueryWrapper<TrialOrder> qw = new QueryWrapper<>();
qw.lambda().eq(trialOrderDTO.getStatus() != null, TrialOrder::getStatus, trialOrderDTO.getStatus());
return baseMapper.selectPage(new Page<>(trialOrderDTO.getPage(), trialOrderDTO.getSize()), qw);
}
@Override
public Boolean trialOrderApproval(List<Long> ids) {
for (Long id : ids) {
TrialOrder trialOrder = baseMapper.selectById(id);
trialOrder.setStatus(1);
trialOrder.setUpdateTime(LocalDateTime.now());
baseMapper.updateById(trialOrder);
QueryWrapper<Account> qw = new QueryWrapper<>();
qw.eq("BINARY user_email", trialOrder.getEmail());
List<Account> accountList = accountMapper.selectList(qw);
Account account = new Account();
if (CollectionUtil.isNotEmpty(accountList)) {
account = CopyUtil.copyObject(accountList.get(0), Account.class);
account.setIsTrial(1);
account.setIsBeginner(1);
account.setValidStartTime(System.currentTimeMillis());
account.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli()));
accountMapper.updateById(account);
} else {
account.setUserName(trialOrder.getUserName());
account.setUserPassword("Third-000000");
account.setUserEmail(trialOrder.getEmail());
account.setLanguage(Language.ENGLISH.name());
account.setValidStartTime(System.currentTimeMillis());
account.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli()));
account.setCreateDate(new Date());
account.setIsTrial(1);
account.setIsBeginner(1);
account.setSystemUser(1);
accountMapper.insert(account);
}
// 发送邮件提醒用户试用用户已创建
// SendEmailUtil.sendCustomEmail("1023316923@qq.com", null, trialOrder,2, trialOrder.getCountry());
// SendEmailUtil.sendCustomEmail("calvinwong@aidlab.hk", null, trialOrder,2, trialOrder.getCountry());
// SendEmailUtil.sendCustomEmail("kaicpang.pang@connect.polyu.hk", null, trialOrder,2, trialOrder.getCountry());
if (trialOrder.getCountry().equals("China")) {
SendEmailUtil.sendCustomEmail(account.getUserEmail(), null, trialOrder, 3, trialOrder.getCountry(), false);
} else {
SendEmailUtil.sendCustomEmail(account.getUserEmail(), null, trialOrder, 3, trialOrder.getCountry(), false);
}
}
return Boolean.TRUE;
}
@Override
public Boolean trialOrderRefuse(List<Long> ids) {
for (Long id : ids) {
TrialOrder trialOrder = baseMapper.selectById(id);
trialOrder.setStatus(2);
trialOrder.setUpdateTime(LocalDateTime.now());
baseMapper.updateById(trialOrder);
}
return Boolean.TRUE;
}
@Override
public Boolean trialUserLogout() {
AuthPrincipalVo userInfo = UserContext.getUserHolder();
Account account = accountMapper.selectById(userInfo.getId());
if (account.getIsTrial() != 1) {
throw new BusinessException("用户为正式用户");
}
libraryService.deleteTrialData(userInfo.getId());
userLikeGroupService.deleteTrialData(userInfo.getId());
return Boolean.TRUE;
}
}

View File

@@ -72,16 +72,12 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
private CollectionService collectionService;
@Resource
private UserLikeService userLikeService;
@Resource
private WorkspaceService workspaceService;
@Resource
private UserLikeMapper userLikeMapper;
@Resource
private MinioUtil minioUtil;
@Resource
private TDesignPythonOutfitMapper designPythonOutfitMapper;
@Resource
@@ -139,6 +135,24 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
private CollectionElementRelModelMapper collectionElementRelModelMapper;
@Resource
private CollectionSortService collectionSortService;
@Resource
private GenerateService generateService;
@Resource
private ToProductElementMapper toProductElementMapper;
@Resource
private ToProductImageRecordMapper toProductImageRecordMapper;
@Resource
private ToProductImageResultMapper toProductImageResultMapper;
@Resource
private CloudTaskMapper cloudTaskMapper;
@Resource
private PythonService pythonService;
@Resource
private CreditsService creditsService;
@Resource
private PoseTransformationMapper poseTransformationMapper;
@Resource
private ExportFileMapper exportFileMapper;
@Override
public void deleteUserGroup(Long userGroupId) {
@@ -337,9 +351,6 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
baseMapper.update(null,uw);
}
@Resource
private ExportFileMapper exportFileMapper;
@Override
public Boolean exportSave(MultipartFile file, Long projectId, String module) {
AuthPrincipalVo userHolder = UserContext.getUserHolder();
@@ -362,19 +373,6 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
return Boolean.TRUE;
}
@Resource
private ToProductImageRecordMapper toProductImageRecordMapper;
@Resource
private ToProductImageResultMapper toProductImageResultMapper;
@Resource
private CloudTaskMapper cloudTaskMapper;
@Resource
private PythonService pythonService;
@Resource
private CreditsService creditsService;
@Resource
private PoseTransformationMapper poseTransformationMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public List<ToProductImageResultVO> toProduct(ToProductImageDTO toProductImageDTO) {
@@ -645,9 +643,6 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
}
}
@Resource
private ToProductElementMapper toProductElementMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public ToProductElementVO toProductImageElementUpload(MultipartFile file, Long projectId) {
@@ -1779,8 +1774,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
return convert;
}
@Resource
private GenerateService generateService;
@Override
public ModuleChooseVO getModuleContent(ProjectDTO projectDTO) {
ModuleChooseVO moduleChooseVO = new ModuleChooseVO();