Merge remote-tracking branch 'origin/develop' into dev_shb

# Conflicts:
#	src/main/java/com/ai/da/service/impl/DesignServiceImpl.java
This commit is contained in:
shahaibo
2023-09-13 10:34:09 +08:00
101 changed files with 1597 additions and 346 deletions

View File

@@ -0,0 +1,18 @@
package com.ai.da.service;
import com.ai.da.model.dto.ChatFlushDTO;
import com.ai.da.model.dto.ChatSendDTO;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
/**
* @author aida
* @version 1.0
* @project aida_back
* @description 对话机器人服务接口
* @date 2023/7/25 16:42:18
*/
public interface ChatRobotService {
SseEmitter sendMessageToChatRobot(ChatSendDTO chatSendDTO);
String chatBufferFlush(ChatFlushDTO chatFlushDTO);
}

View File

@@ -115,4 +115,12 @@ public interface CollectionElementService extends IService<CollectionElement> {
*/
void refreshHistoryData() ;
/**
* 当level2Type发生改变时修改levelType
* @param elementId
* @param level2Type
* @return
*/
CollectionElement editLevel2Type(Long elementId,String level2Type);
}

View File

@@ -75,5 +75,5 @@ public interface DesignService extends IService<Design> {
* @param designItemId
* @return
*/
DesignItemDetailVO detail(Long designItemId);
DesignItemDetailVO detail(Long designPythonOutfitId,Long designItemId);
}

View File

@@ -0,0 +1,16 @@
package com.ai.da.service;
import com.ai.da.model.dto.GenerateLikeDTO;
import com.ai.da.model.dto.GenerateThroughImageTextDTO;
import com.ai.da.model.vo.GenerateCaptionVO;
import com.ai.da.model.vo.GenerateCollectionVO;
import com.ai.da.model.vo.GenerateLikeVO;
public interface GenerateService {
GenerateCaptionVO generateCaption(Long sketchElementId);
GenerateCollectionVO generateThroughImageText(GenerateThroughImageTextDTO generateThroughImageTextDTO);
GenerateLikeVO generateLike(GenerateLikeDTO generateLikeDTO);
}

View File

@@ -2,10 +2,13 @@ package com.ai.da.service;
import com.ai.da.mapper.entity.TDesignPythonOutfitDetail;
import com.ai.da.model.vo.DesignPythonOutfitVO;
import com.ai.da.model.vo.TDesignPythonOutfitDetailVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* design item详情表 服务类
*
@@ -23,4 +26,12 @@ public interface ITDesignPythonOutfitDetailService extends IService<TDesignPytho
*/
IPage<TDesignPythonOutfitDetailVO> selectTDesignPythonOutfitDetailPage(IPage<TDesignPythonOutfitDetailVO> page, TDesignPythonOutfitDetailVO tDesignPythonOutfitDetail);
/**
* 通过DesignPythonOutfitId获取designPythonOutfitDetail
* @param designPythonOutfitId
* @return
*/
List<TDesignPythonOutfitDetail> getDetailByDesignPythonOutfitId(Long designPythonOutfitId);
DesignPythonOutfitVO convertToDesignPythonOutfitVO(TDesignPythonOutfitDetail detail);
}

View File

@@ -6,6 +6,7 @@ import com.ai.da.model.vo.PantoneVO;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
import java.util.Map;
/**
* 服务类
@@ -41,6 +42,10 @@ public interface PanToneService extends IService<PanTone> {
*/
PantoneVO getByRGB(Integer r,Integer g,Integer b);
Map<String,PantoneVO> getPantoneByRgbBatch(List<String> colors);
PantoneVO getPantoneByRgb(String color);
/**
* 根据hsv批量查询
* @param rgbByHsvBatch

View File

@@ -1,12 +1,9 @@
package com.ai.da.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ai.da.common.config.exception.BusinessException;
import com.ai.da.common.constant.TokenConstant;
import com.ai.da.common.enums.LoginTypeEnum;
import com.ai.da.common.enums.OperationTypeEnum;
import com.ai.da.common.httpdata.token.TokenQuery;
import com.ai.da.common.security.jwt.JWTTokenHelper;
import com.ai.da.common.utils.*;
import com.ai.da.mapper.AccountMapper;
@@ -19,25 +16,18 @@ import com.ai.da.model.vo.AuthPrincipalVo;
import com.ai.da.service.AccountLoginLogService;
import com.ai.da.service.AccountService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.util.RequestUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
@@ -64,15 +54,49 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
public AccountPreLoginVO preLogin(AccountPreLoginDTO accountDTO) {
log.info("aida预先登入accountDTO###{}", JSON.toJSONString(accountDTO));
Account account = getOneByUserName(accountDTO.getUserName());
Assert.isTrue(Objects.nonNull(account),"User does not exist!");
Assert.isTrue(Objects.nonNull(account), "User does not exist!");
//用户有效期校验
validateUserValidaExpire(account);
if("Third-000000".equals(account.getUserPassword())){
if ("Third-000000".equals(account.getUserPassword())) {
account.setUserPassword(accountDTO.getPassword());
accountMapper.updateById(account);
}else{
Assert.isTrue(account.getUserPassword().equals(accountDTO.getPassword()),"Password error !");
} else {
Assert.isTrue(account.getUserPassword().equals(accountDTO.getPassword()), "Password error !");
}
/*发送邮件*/
OperationTypeEnum operationTypeEnum = OperationTypeEnum.of(accountDTO.getOperationType());
log.info(account.getUserEmail());
log.info(accountDTO.getEmail());
Assert.isTrue(account.getUserEmail().equals(accountDTO.getEmail()), "Email error !");
Assert.notNull(operationTypeEnum, "Unknown operation type!");
String randomVerifyCode = RandomsUtil.generateVerifyCode(100000L, 999999L);
LocalCacheUtils.setVerifyCodeCache(
accountDTO.getOperationType() + "_" + accountDTO.getEmail(), randomVerifyCode);
Boolean result = Boolean.FALSE;
switch (operationTypeEnum) {
case LOGIN:
Assert.notNull(accountDTO, "Email not registered!");
result = SendEmailUtil.send(accountDTO.getEmail(), null,
SendEmailUtil.LOGIN_TEMPLATE_ID, randomVerifyCode);
break;
case FORGET_PWD:
Assert.notNull(accountDTO, "Email not registered!");
result = SendEmailUtil.send(accountDTO.getEmail(), null,
SendEmailUtil.UPDATE_PWD_TEMPLATE_ID, randomVerifyCode);
break;
case EXCEPTION_IP:
Assert.notNull(accountDTO, "Email not registered!");
result = SendEmailUtil.send(accountDTO.getEmail(), accountDTO.getIp(),
SendEmailUtil.EXCEPTION_ID_TEMPLATE_ID, randomVerifyCode);
break;
case BIND_MAILBOX:
result = SendEmailUtil.send(accountDTO.getEmail(), null,
SendEmailUtil.BIND_MAILBOX_TEMPLATE_ID, randomVerifyCode);
break;
default:
Assert.notNull(operationTypeEnum, "Unknown operation type!");
}
Assert.isTrue(result, "Failed to send mail");
return new AccountPreLoginVO(account.getId());
}
@@ -81,10 +105,10 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
public AccountLoginVO login(AccountLoginDTO accountLoginDTO, HttpServletRequest request) {
log.info("aida确认登入###accountLoginDTO###{}", JSON.toJSONString(accountLoginDTO));
Account accountExist = getOneByEmail(accountLoginDTO.getEmail().trim());
Assert.notNull(accountExist,"User does not exist!");
Assert.notNull(accountExist, "User does not exist!");
LoginTypeEnum accountType = LoginTypeEnum.of(accountLoginDTO.getLoginType());
if (Objects.isNull(accountType)|| accountType.equals(LoginTypeEnum.PASSWORD)) {
if (Objects.isNull(accountType) || accountType.equals(LoginTypeEnum.PASSWORD)) {
throw new BusinessException("Unknown login type!");
}
//用户有效期校验
@@ -95,8 +119,8 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
case PASSWORD:
Assert.isTrue(StringUtils.isNotBlank(accountLoginDTO.getPassword()), "Please input a password !");
account = getOneByUserName(accountLoginDTO.getUserName());
Assert.isTrue(Objects.nonNull(account),"User does not exist!");
Assert.isTrue(account.getUserPassword().equals(accountLoginDTO.getPassword()),"Password error !");
Assert.isTrue(Objects.nonNull(account), "User does not exist!");
Assert.isTrue(account.getUserPassword().equals(accountLoginDTO.getPassword()), "Password error !");
// Assert.isTrue(StringUtils.isBlank(
// LocalCacheUtils.getTokenCache(String.valueOf(account.getId()))),"该用户已登入");
break;
@@ -108,9 +132,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
throw new BusinessException("Email not registered!");
}
//校验邮箱验证码
String verifyCode = LocalCacheUtils.getVerifyCodeCache( OperationTypeEnum.LOGIN.name() + "_" +accountLoginDTO.getEmail());
String verifyCode = LocalCacheUtils.getVerifyCodeCache(OperationTypeEnum.LOGIN.name() + "_" + accountLoginDTO.getEmail());
Assert.isTrue(StringUtils.isNotBlank(verifyCode), "The verification code has expired!");
if(!"921314".equals(accountLoginDTO.getEmailVerifyCode())){
if (!"921314".equals(accountLoginDTO.getEmailVerifyCode())) {
Assert.isTrue(verifyCode.equals(accountLoginDTO.getEmailVerifyCode()), "Verification code error!");
}
break;
@@ -118,34 +142,36 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
}
AccountLoginVO response = CopyUtil.copyObject(account, AccountLoginVO.class);
response.setEmail(account.getUserEmail());
String token =LocalCacheUtils.getTokenCache(String.valueOf(account.getId()));
if(StringUtils.isNotBlank(token)){
String token = LocalCacheUtils.getTokenCache(String.valueOf(account.getId()));
if (StringUtils.isNotBlank(token)) {
//用户已登入
response.setToken(token);
}else{
response.setToken(createAccountToken(account.getId(),account.getUserName()));
} else {
response.setToken(createAccountToken(account.getId(), account.getUserName()));
}
response.setUserId(account.getId());
//判断是否常用ip 不是则发邮件提示
calculateExceptionIp(RequestInfoUtil.getIpAddress(request),account);
calculateExceptionIp(RequestInfoUtil.getIpAddress(request), account);
return response;
}
private void validateUserValidaExpire(Account account){
private void validateUserValidaExpire(Account account) {
Long currentTime = new Date().getTime();
if(Objects.nonNull(account.getValidStartTime())){
Assert.isTrue(currentTime >= account.getValidStartTime(),"User expired !" );
if (Objects.nonNull(account.getValidStartTime())) {
Assert.isTrue(currentTime >= account.getValidStartTime(), "User expired !");
}
if(Objects.nonNull(account.getValidEndTime())){
Assert.isTrue(currentTime <= account.getValidEndTime(),"User expired !" );
if (Objects.nonNull(account.getValidEndTime())) {
Assert.isTrue(currentTime <= account.getValidEndTime(), "User expired !");
}
}
private void calculateExceptionIp(String ip ,Account account ){
private void calculateExceptionIp(String ip, Account account) {
//必须先绑定邮箱才可以发有异常ip邮件提醒
if(StringUtils.isNotBlank(account.getUserEmail())){
if (StringUtils.isNotBlank(account.getUserEmail())) {
List<AccountLoginLog> accountLoginLogs = accountLoginLogService.getByUserId(account.getId());
if(CollectionUtil.isNotEmpty(accountLoginLogs)){
if (CollectionUtil.isNotEmpty(accountLoginLogs)) {
List<String> existIps = accountLoginLogs.stream().map(AccountLoginLog::getIp).collect(Collectors.toList());
if(!existIps.contains(ip)){
if (!existIps.contains(ip)) {
//非常用ip,没有出现过
EmailSendDTO emailSendDTO = new EmailSendDTO();
emailSendDTO.setEmail(account.getUserEmail());
@@ -156,11 +182,12 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
}
}
//保存登入日志
accountLoginLogService.saveLoginLog(ip,account.getId());
accountLoginLogService.saveLoginLog(ip, account.getId());
}
private String createAccountToken(Long userId,String userName){
private String createAccountToken(Long userId, String userName) {
String token = LocalCacheUtils.getTokenCache(String.valueOf(userId));
if(StringUtils.isNotBlank(token)){
if (StringUtils.isNotBlank(token)) {
return token;
}
AuthPrincipalVo principal = new AuthPrincipalVo();
@@ -174,14 +201,14 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
@Override
public Boolean bindEmail(AccountBindEmailDTO accountBindEmailDTO) {
Account account = getOneByUserId(accountBindEmailDTO.getUserId());
Assert.notNull(account,"User does not exist !");
Assert.isTrue(StringUtils.isBlank(account.getUserEmail()),"User has bound mailbox !");
Assert.notNull(account, "User does not exist !");
Assert.isTrue(StringUtils.isBlank(account.getUserEmail()), "User has bound mailbox !");
//校验邮箱验证码
String verifyCode = LocalCacheUtils.getVerifyCodeCache(OperationTypeEnum.BIND_MAILBOX.name() + "_" + accountBindEmailDTO.getUserEmail());
Assert.isTrue(StringUtils.isNotBlank(verifyCode), "The verification code has expired !");
Assert.isTrue(verifyCode.equals(accountBindEmailDTO.getEmailVerifyCode()), "Verification code error !");
//绑定
updatePwdByUserId(accountBindEmailDTO.getUserEmail(),accountBindEmailDTO.getUserId());
updatePwdByUserId(accountBindEmailDTO.getUserEmail(), accountBindEmailDTO.getUserId());
return Boolean.TRUE;
}
@@ -206,6 +233,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
accountNew.setUserPassword(pwd);
accountMapper.update(accountNew, queryWrapper);
}
private void updatePwdByUserId(String email, Long userId) {
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("id", userId);
@@ -227,6 +255,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
queryWrapper.eq("user_name", userName);
return accountMapper.selectOne(queryWrapper);
}
private Account getOneByUserId(Long userId) {
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("id", userId);
@@ -240,9 +269,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
Assert.notNull(operationTypeEnum, "Unknown operation type!");
Account emailAccount = getOneByEmail(emailSendDTO.getEmail());
String randomVerifyCode =RandomsUtil.generateVerifyCode(100000L,999999L);
String randomVerifyCode = RandomsUtil.generateVerifyCode(100000L, 999999L);
LocalCacheUtils.setVerifyCodeCache(
emailSendDTO.getOperationType() + "_" + emailSendDTO.getEmail(),randomVerifyCode);
emailSendDTO.getOperationType() + "_" + emailSendDTO.getEmail(), randomVerifyCode);
Boolean result = Boolean.FALSE;
switch (operationTypeEnum) {
case LOGIN:
@@ -275,7 +304,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
public Boolean logout(AccountLogoutDTO accountLogoutDTO) {
//jwt本身失效比较难做 统一用缓存实现 删除缓存就失效
String token = LocalCacheUtils.getTokenCache(String.valueOf(accountLogoutDTO.getUserId()));
if(StringUtils.isNotBlank(token)){
if (StringUtils.isNotBlank(token)) {
LocalCacheUtils.delTokenCache(String.valueOf(accountLogoutDTO.getUserId()));
}
return Boolean.TRUE;
@@ -284,7 +313,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
@Override
public Boolean isLogin(AccountLogoutDTO accountLogoutDTO) {
String token = LocalCacheUtils.getTokenCache(String.valueOf(accountLogoutDTO.getUserId()));
if(StringUtils.isNotBlank(token)){
if (StringUtils.isNotBlank(token)) {
return Boolean.TRUE;
}
return Boolean.FALSE;
@@ -299,52 +328,52 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
account.setValidStartTime(Long.valueOf(accountAddDTO.getValidStartTime()));
account.setValidEndTime(Long.valueOf(accountAddDTO.getValidEndTime()));
account.setCreateDate(new Date());
return accountMapper.insert(account)>0;
return accountMapper.insert(account) > 0;
}
@Override
public Boolean editUser(AccountEditDTO accountEditDTO) {
if(Objects.isNull(accountEditDTO)|| ObjectUtils.isAllFieldNull(accountEditDTO)){
if (Objects.isNull(accountEditDTO) || ObjectUtils.isAllFieldNull(accountEditDTO)) {
throw new BusinessException("The edited account information cannot be blank!");
}
QueryWrapper<Account> queryTotal = new QueryWrapper<>();
Account account = new Account();
//校验
if(StringUtils.isNotBlank(accountEditDTO.getNewEmail())){
Assert.isTrue(StringUtils.isNotBlank(accountEditDTO.getOldEmail()),"oldEmail cannot be empty!");
queryTotal.eq("user_email",accountEditDTO.getOldEmail());
if (StringUtils.isNotBlank(accountEditDTO.getNewEmail())) {
Assert.isTrue(StringUtils.isNotBlank(accountEditDTO.getOldEmail()), "oldEmail cannot be empty!");
queryTotal.eq("user_email", accountEditDTO.getOldEmail());
Account accountSelect = accountMapper.selectOne(queryTotal);
Assert.notNull(accountSelect,"oldEmail does not exist!");
Assert.notNull(accountSelect, "oldEmail does not exist!");
account.setUserEmail(accountEditDTO.getNewEmail());
}
if(StringUtils.isNotBlank(accountEditDTO.getNewUserName())){
Assert.isTrue(StringUtils.isNotBlank(accountEditDTO.getOldUserName()),"oldUserName cannot be empty!");
queryTotal.eq("user_name",accountEditDTO.getOldUserName());
if (StringUtils.isNotBlank(accountEditDTO.getNewUserName())) {
Assert.isTrue(StringUtils.isNotBlank(accountEditDTO.getOldUserName()), "oldUserName cannot be empty!");
queryTotal.eq("user_name", accountEditDTO.getOldUserName());
Account accountSelect = accountMapper.selectOne(queryTotal);
Assert.notNull(accountSelect,"oldUserName does not exist!");
Assert.notNull(accountSelect, "oldUserName does not exist!");
account.setUserName(accountEditDTO.getNewUserName());
}
if(StringUtils.isNotBlank(accountEditDTO.getNewValidStartTime())){
Assert.isTrue(StringUtils.isNotBlank(accountEditDTO.getOldUserName()),"oldUserName cannot be empty!");
queryTotal.eq("user_name",accountEditDTO.getOldUserName());
if (StringUtils.isNotBlank(accountEditDTO.getNewValidStartTime())) {
Assert.isTrue(StringUtils.isNotBlank(accountEditDTO.getOldUserName()), "oldUserName cannot be empty!");
queryTotal.eq("user_name", accountEditDTO.getOldUserName());
Account accountSelect = accountMapper.selectOne(queryTotal);
Assert.notNull(accountSelect,"oldUserName does not exist!");
Assert.notNull(accountSelect, "oldUserName does not exist!");
account.setValidStartTime(Long.valueOf(accountEditDTO.getNewValidStartTime()));
}
if(StringUtils.isNotBlank(accountEditDTO.getNewValidEndTime())){
Assert.isTrue(StringUtils.isNotBlank(accountEditDTO.getOldUserName()),"oldUserName cannot be empty!");
queryTotal.eq("user_name",accountEditDTO.getOldUserName());
if (StringUtils.isNotBlank(accountEditDTO.getNewValidEndTime())) {
Assert.isTrue(StringUtils.isNotBlank(accountEditDTO.getOldUserName()), "oldUserName cannot be empty!");
queryTotal.eq("user_name", accountEditDTO.getOldUserName());
Account accountSelect = accountMapper.selectOne(queryTotal);
Assert.notNull(accountSelect,"oldUserName does not exist!");
Assert.notNull(accountSelect, "oldUserName does not exist!");
account.setValidEndTime(Long.valueOf(accountEditDTO.getNewValidEndTime()));
}
Account accountSelect = accountMapper.selectOne(queryTotal);
Assert.notNull(accountSelect,"oldAccount does not exist!");
accountMapper.update(account,queryTotal);
Assert.notNull(accountSelect, "oldAccount does not exist!");
accountMapper.update(account, queryTotal);
return null;
}
}

View File

@@ -0,0 +1,99 @@
package com.ai.da.service.impl;
import com.ai.da.model.dto.ChatFlushDTO;
import com.ai.da.model.dto.ChatSendDTO;
import com.ai.da.service.ChatRobotService;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* @author aida
* @version 1.0
* @project ChatRobot
* @description 请求python Chat Stream 接口服务实现类
* @date 2023/7/10 10:41:45
*/
@Slf4j
@Service
public class ChatRobotServiceImpl implements ChatRobotService {
// @Value("")
String chatStreamUrl = "http://18.167.251.121:6789/api/chat_stream";
String chatBufferFlushUrl = "http://18.167.251.121:6789/api/chat_flush";
RestTemplate restTemplate = new RestTemplate();
Gson gson = new GsonBuilder().create();
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
Integer timeout = 99999999;
@Override
public SseEmitter sendMessageToChatRobot(ChatSendDTO chatSendDTO) {
SseEmitter emitter = new SseEmitter();
String requestBody = gson.toJson(chatSendDTO);
executorService.execute(() -> {
try {
// 这里根据你的业务逻辑,从服务获取数据
// 示例:从服务获取数据并逐条发送给客户端
URL urlObj = new URL(chatStreamUrl);
HttpURLConnection connection = (HttpURLConnection) urlObj.openConnection();
connection.setConnectTimeout(timeout);
connection.setReadTimeout(timeout);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
connection.setDoOutput(true);
OutputStream outputStream = connection.getOutputStream();
outputStream.write(requestBody.getBytes());
outputStream.flush();
outputStream.close();
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
log.info(line);
emitter.send(line);
// Thread.sleep(1000);
}
reader.close();
} else {
System.out.println("Request failed with status code: " + responseCode);
}
connection.disconnect();
emitter.complete();
} catch (Exception e) {
emitter.completeWithError(e);
}
});
return emitter;
}
@Override
public String chatBufferFlush(ChatFlushDTO chatFlushDTO) {
log.info(chatBufferFlushUrl);
return String.valueOf(restTemplate.postForEntity(chatBufferFlushUrl, chatFlushDTO, String.class));
}
}

View File

@@ -24,6 +24,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import io.netty.util.internal.StringUtil;
import javafx.scene.chart.ValueAxis;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.LICENSE;
@@ -570,4 +571,17 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
}
return Boolean.TRUE;
}
@Override
public CollectionElement editLevel2Type(Long elementId, String level2Type){
CollectionElement collectionElement = null;
if(!Objects.isNull(elementId)){
collectionElement = collectionElementMapper.selectById(elementId);
if (StringUtil.isNullOrEmpty(collectionElement.getLevel2Type()) || !(collectionElement.getLevel2Type()).equals(level2Type)){
collectionElement.setLevel2Type(level2Type);
updateById(collectionElement);
}
}
return collectionElement;
}
}

View File

@@ -157,6 +157,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
LibraryModelPoint modelPoint = libraryModelPointService.getById(design.getTemplateId());
Assert.notNull(modelPoint,"template does not exists!");
Library library = libraryService.getById(modelPoint.getLibraryId());
// ??和上面重复
Assert.notNull(modelPoint,"template does not exists!");
designLibraryModelPointVO = collectionElementService.calculateTemplatePoint(modelPoint,library.getHigh(),library.getWidth(),library.getUrl());
}
@@ -170,6 +171,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
//designSingle
DesignCollectionItemVO response = saveSingleDesignItemAndDetail(objects,design.getId(),designSingleDTO.getDesignItemId(),
design.getCollectionId(),userInfo,designSingleDTO.getTimeZone());
// ??
designItem.setDesignUrl(response.getDesignItemUrl());
return response;
}

View File

@@ -16,7 +16,6 @@ import com.ai.da.mapper.entity.Collection;
import com.ai.da.model.dto.*;
import com.ai.da.model.vo.*;
import com.ai.da.python.PythonService;
import com.ai.da.python.vo.DesignPythonItem;
import com.ai.da.python.vo.DesignPythonItemPrint;
import com.ai.da.python.vo.DesignPythonObject;
import com.ai.da.python.vo.DesignPythonObjects;
@@ -27,6 +26,7 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@@ -81,6 +81,8 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
@Resource
private ITDesignPythonOutfitDetailService designPythonOutfitDetailService;
@Resource
private PanToneService panToneService;
@Resource
private PythonTAllInfoService pythonTAllInfoService;
@Value("${minio.endpoint}")
private String endpoint;
@@ -679,18 +681,27 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
}
@Override
public DesignItemDetailVO detail(Long designItemId) {
public DesignItemDetailVO detail(Long designPythonOutfitId,Long designItemId) {
DesignItem designItem = designItemService.getById(designItemId);
Assert.notNull(designItem,"design item does not exist!");
Design design = getById(designItem.getDesignId());
Assert.notNull(design,"design does not exist!");
List<DesignItemDetail> designItemDetails = designItemDetailService.selectByDesignItemId(designItemId);
Assert.notEmpty(designItemDetails,"designItemDetails does not exist!");
// 添加判断designPythonOutfitId是否存在
TDesignPythonOutfit designPythonOutfit = new TDesignPythonOutfit();
Boolean flag = Boolean.FALSE;
if (Objects.nonNull(designPythonOutfitId)){
designPythonOutfit = designPythonOutfitService.getById(designPythonOutfitId);
Assert.notNull(designPythonOutfit,"designPythonOutfit does not exist!");
flag = Boolean.TRUE;
}
DesignItemDetailVO response = new DesignItemDetailVO();
response.setSingleOverall(design.getSingleOverall());
response.setSwitchCategory(design.getSwitchCategory());
response.setDesignItemId(designItemId);
response.setDesignItemUrl(designItem.getDesignUrl());
// response.setDesignItemUrl(designItem.getDesignUrl());
response.setHighDesignUrl(designItem.getHighDesignUrl());
List<DesignItemDetail> filterDetail = designItemDetails.stream()
.filter(f -> OUTWEAR_DRESS_BLOUSE.contains(f.getType()) || SKIRT_TROUSERS.contains(f.getType()))
@@ -708,13 +719,14 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
}));
//single 和 Models(模特)时候 系统元素为空
List<DesignItemDetail> filterDetail2 =designItemDetails.stream()
.filter(f -> SYS_HAIRSTYLE_SHOES.contains(f.getType()) )
// .filter(f -> SYS_HAIRSTYLE_SHOES.contains(f.getType()) )
.filter(f -> SYS_HAIRSTYLE_SHOES_BODY.contains(f.getType()) )
.collect(Collectors.toList());
response.setOthers(CopyUtil.copyList(filterDetail2,DesignItemOthersDetailVO.class,(o,d)->{
d.setId(o.getBusinessId());
d.setPrintObject(new DesignPythonItemPrint());
}));
return response;
return editDesignItemLayer(flag,designPythonOutfit,designItem.getDesignUrl(),editResponseColor(designItemDetails,response));
}
private String converTypeToLevel1(String type){
if(StringUtils.isEmpty(type)){
@@ -754,5 +766,84 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
return design.getId();
}
private DesignItemDetailVO editResponseColor(List<DesignItemDetail> designItemDetails,DesignItemDetailVO designItemDetailVO){
/*designItemDetails.forEach(d -> {
if (!StringUtil.isNullOrEmpty(d.getColor())){
PantoneVO pantoneByRgb = panToneService.getPantoneByRgb(d.getColor());
DesignItemClothesDetailVO clothesDetailVO = designItemDetailVO.getClothes().stream()
.filter(v -> v.getId().equals(d.getBusinessId()))
.findFirst().orElse(null);
if (Objects.nonNull(clothesDetailVO)){
clothesDetailVO.setColor(pantoneByRgb);
} else {
DesignItemOthersDetailVO othersDetailVO = designItemDetailVO.getOthers().stream()
.filter(v -> v.getId().equals(d.getBusinessId()))
.findFirst().orElse(null);
if (Objects.nonNull(othersDetailVO)) {
othersDetailVO.setColor(pantoneByRgb);
}
}
}
});*/
HashMap<Long, String> businessIdColor = new HashMap<>();
designItemDetails.forEach(designItemDetail -> {
if (!StringUtil.isNullOrEmpty(designItemDetail.getColor())){
businessIdColor.put(designItemDetail.getBusinessId(),designItemDetail.getColor());
}
});
Map<String, PantoneVO> pantoneByRgbBatch = panToneService.getPantoneByRgbBatch(new ArrayList<>(businessIdColor.values()));
designItemDetailVO.getClothes().forEach(c -> {
PantoneVO pantoneVO = pantoneByRgbBatch.get(businessIdColor.get(c.getId()));
c.setColor(pantoneVO);
});
designItemDetailVO.getOthers().forEach(o -> {
PantoneVO pantoneVO = pantoneByRgbBatch.get(businessIdColor.get(o.getId()));
o.setColor(pantoneVO);
});
return designItemDetailVO;
}
private DesignItemDetailVO editDesignItemLayer(Boolean flag,TDesignPythonOutfit designPythonOutfit,String designItemUrl,DesignItemDetailVO designItemDetailVO){
ArrayList<DesignPythonOutfitVO> detailsVO = new ArrayList<>();
if (flag){
// 1、判断designPythonOutfitId查出的图层信息是否为空不允许为空系统内部错误
List<TDesignPythonOutfitDetail> details = designPythonOutfitDetailService.getDetailByDesignPythonOutfitId(designPythonOutfit.getId());
Assert.notEmpty(details,"Some errors occurred, please restart the design");
details.forEach(detail -> {
detailsVO.add(designPythonOutfitDetailService.convertToDesignPythonOutfitVO(detail));
});
// 2、将查询出的图层信息填充到designItemDetailVO中
designItemDetailVO.setDesignItemUrl(designPythonOutfit.getDesignUrl());
// 2.1 填充clothes
designItemDetailVO.getClothes().forEach(c -> {
String type = c.getType().toLowerCase();
List<DesignPythonOutfitVO> outfitVOS = detailsVO.stream().filter(detail -> detail.getImageCategory().equals(type + "_back") ||
detail.getImageCategory().equals(type + "_front")).collect(Collectors.toList());
c.setLayersObject(outfitVOS);
});
// 2.2 填充others
designItemDetailVO.getOthers().forEach(o -> {
String type = o.getType().toLowerCase();
List<DesignPythonOutfitVO> outfitVOS = detailsVO.stream().filter(detail -> detail.getImageCategory().equals(type + "_back") ||
detail.getImageCategory().equals(type + "_front") ||
detail.getImageCategory().equals("body")).collect(Collectors.toList());
o.setLayersObject(outfitVOS);
});
}else{
designItemDetailVO.setDesignItemUrl(designItemUrl);
}
return designItemDetailVO;
}
}

View File

@@ -0,0 +1,177 @@
package com.ai.da.service.impl;
import cn.hutool.core.lang.Assert;
import com.ai.da.common.context.UserContext;
import com.ai.da.common.enums.CollectionLevel1TypeEnum;
import com.ai.da.common.enums.GenerateTypeEnum;
import com.ai.da.common.enums.ModelNameEnum;
import com.ai.da.common.utils.DateUtil;
import com.ai.da.common.utils.MD5Utils;
import com.ai.da.mapper.CollectionElementMapper;
import com.ai.da.mapper.GenerateDetailMapper;
import com.ai.da.mapper.GenerateMapper;
import com.ai.da.mapper.entity.*;
import com.ai.da.model.dto.GenerateLikeDTO;
import com.ai.da.model.dto.GenerateThroughImageTextDTO;
import com.ai.da.model.vo.*;
import com.ai.da.python.PythonService;
import com.ai.da.service.CollectionElementService;
import com.ai.da.service.GenerateService;
import com.ai.da.service.LibraryService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.netty.util.internal.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.*;
@Service
public class GenerateServiceImpl extends ServiceImpl<GenerateMapper,Generate> implements GenerateService {
@Resource
private CollectionElementMapper collectionElementMapper;
@Resource
private GenerateDetailMapper generateDetailMapper;
@Resource
private LibraryService libraryService;
@Resource
private PythonService pythonService;
@Resource
private CollectionElementService collectionElementService;
@Override
public GenerateCaptionVO generateCaption(Long sketchElementId) {
CollectionElement collectionElement = collectionElementMapper.selectById(sketchElementId);
Assert.notNull(collectionElement,"System error!Please reselect the sketch");
Assert.isTrue("Sketchboard".equals(collectionElement.getLevel1Type()) && !StringUtil.isNullOrEmpty(collectionElement.getUrl())
,"System error!Please reselect the sketch");
String url = collectionElement.getUrl();
// String caption = pythonService.generateSketchCaption(url);
GenerateCaptionVO recognized_caption = new GenerateCaptionVO("recognized caption");
return recognized_caption;
}
@Override
public GenerateCollectionVO generateThroughImageText(GenerateThroughImageTextDTO generateThroughImageTextDTO) {
// 1、获取用户信息
AuthPrincipalVo userHolder = UserContext.getUserHolder();
Long accountId = userHolder.getId();
// 2、判断必须入参是否为非空
Generate generate = new Generate();
generate.setAccountId(accountId);
generate.setGenerateType(generateThroughImageTextDTO.getGenerateType());
generate.setModelName(StringUtil.isNullOrEmpty(generateThroughImageTextDTO.getVersion()) ? ModelNameEnum.MODEL_0.getCode() : generateThroughImageTextDTO.getVersion());
generate.setCreateDate(DateUtil.getByTimeZone(generateThroughImageTextDTO.getTimeZone()));
generate.setLevel1Type(generateThroughImageTextDTO.getLevel1Type());
String text = generateThroughImageTextDTO.getText();
Long elementId = generateThroughImageTextDTO.getCollectionElementId();
validateGeneraType(generate,text,elementId);
// 3、将请求信息落库
// 3.1 sketch或print在t_collection_element表中的信息是否需要更新 如 level2Type
CollectionElement collectionElement = collectionElementService.editLevel2Type(elementId, generateThroughImageTextDTO.getLevel2Type());
// 3.2 将本次generate的请求信息添加到t_generate表中
save(generate);
// 4、向模型发起请求
int mode = GenerateTypeEnum.TEXT.getValue().equals(generate.getGenerateType()) ? GenerateTypeEnum.TEXT.getCode() : GenerateTypeEnum.TEXT_IMAGE.getCode();
// String generatedSketchUrl = pythonService.generateSketchOrPrint(collectionElement.getUrl(),text,mode,generateThroughImageTextDTO.getVersion());
List<String> generatedSketchUrl = Arrays.asList("testUrl1","testUrl2","testUrl3","testUrl4");
// 5、处理模型返回的数据
// 5.1 将相应的url保存到数据库
List<GenerateCollectionItemVO> generatedCollectionItems = new ArrayList<>();
generatedSketchUrl.forEach(item -> {
GenerateDetail generateDetail = new GenerateDetail();
generateDetail.setUrl(item);
generateDetail.setGenerateId(generate.getId());
generateDetail.setCreateDate(DateUtil.getByTimeZone(generateThroughImageTextDTO.getTimeZone()));
generateDetailMapper.insert(generateDetail);
GenerateCollectionItemVO generateCollectionItemVO = new GenerateCollectionItemVO();
generateCollectionItemVO.setGenerateItemId(generateDetail.getId());
generateCollectionItemVO.setGenerateItemUrl(item);
generatedCollectionItems.add(generateCollectionItemVO);
});
// 6、将模型返回的图片地址返回给前端
Long collectionId = Objects.isNull(collectionElement) ? null : collectionElement.getCollectionId();
return new GenerateCollectionVO(generate.getId(),collectionId,generatedCollectionItems);
}
private void validateGeneraType(Generate generate,String text,Long elementId){
switch(generate.getGenerateType()){
case "text":
Assert.notNull(text,"Please input the caption");
generate.setText(text);
break;
case "image":
Assert.notNull(elementId,"Please choose a image");
generate.setCollectionElementId(elementId);
break;
case "text-image":
Assert.isTrue(!StringUtil.isNullOrEmpty(text) && Objects.nonNull(elementId),
"Please input the caption and choose a image");
generate.setText(text);
generate.setCollectionElementId(elementId);
default:
}
}
@Override
public GenerateLikeVO generateLike(GenerateLikeDTO generateLikeDTO) {
// 1、判断参数是否正确
// 1.1 必须参数是否非空
if(CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName().equals(generateLikeDTO.getLevel1Type()) ){
Assert.isTrue(!StringUtil.isNullOrEmpty(generateLikeDTO.getLevel2Type()),"level2Type cannot be empty");
}
// 1.2 判断参数是否真实有效
Long generateDetailId = generateLikeDTO.getGenerateDetailId();
GenerateDetail generateDetail = generateDetailMapper.selectById(generateDetailId);
Assert.notNull(generateDetail,"generateItem does not exist");
Generate generate = getById(generateDetail.getGenerateId());
Assert.isTrue(generateLikeDTO.getLevel1Type().equals(generate.getLevel1Type()),"level1Type does not match");
// 2、将like的图片信息存入library
AuthPrincipalVo userInfo = UserContext.getUserHolder();
Long accountId = userInfo.getId();
Library library = setLibrary(accountId, generateLikeDTO, generateDetail.getUrl());
libraryService.save(library);
// 3、更新generateDetail表的isLike列
updateLikeStatus(generateLikeDTO.getGenerateDetailId(),(byte)1);
return new GenerateLikeVO(library.getId());
}
public Library setLibrary(Long accountId,GenerateLikeDTO generateLikeDTO,String imageUrl){
Library library = new Library();
library.setAccountId(accountId);
library.setLevel1Type(generateLikeDTO.getLevel1Type());
library.setLevel2Type(StringUtil.isNullOrEmpty(generateLikeDTO.getLevel2Type()) ? null : generateLikeDTO.getLevel2Type());
library.setName(DateUtil.dateToStr(new Date(),DateUtil.YYYY_MM_DD));
library.setUrl(imageUrl);
library.setMd5(MD5Utils.encryptFile(imageUrl,Boolean.FALSE));
library.setCreateDate(DateUtil.getByTimeZone(generateLikeDTO.getTimeZone()));
return library;
}
public void updateLikeStatus(Long generateDetailId,Byte hasLike){
QueryWrapper<GenerateDetail> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("id", generateDetailId);
GenerateDetail generateDetail = new GenerateDetail();
generateDetail.setIsLike(hasLike);
generateDetailMapper.update(generateDetail,queryWrapper);
}
}

View File

@@ -3,7 +3,7 @@ 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.utils.CopyUtil;
import com.ai.da.mapper.entity.Collection;
import com.ai.da.common.utils.PantoneUtils;
import com.ai.da.mapper.entity.ColorLookupTable;
import com.ai.da.mapper.entity.PanTone;
import com.ai.da.mapper.PanToneMapper;
@@ -15,17 +15,12 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import io.netty.util.internal.StringUtil;
import org.checkerframework.checker.units.qual.A;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -35,6 +30,8 @@ public class PanToneServiceImpl extends ServiceImpl<PanToneMapper, PanTone> impl
@Resource
private PanToneMapper panToneMapper;
@Resource
private PanToneService panToneService;
@Resource
private ColorLoopUpTableService colorLoopUpTableService;
@Override
@@ -74,6 +71,55 @@ public class PanToneServiceImpl extends ServiceImpl<PanToneMapper, PanTone> impl
return coverPanToneToVo(panTones);
}
@Override
public Map<String,PantoneVO> getPantoneByRgbBatch(List<String> colors){
HashMap<Integer,String> colorValueRgb = new HashMap<>();
HashMap<Integer,String> colorIndexRgb = new HashMap<>();
ArrayList<Integer> values = new ArrayList<>();
colors.forEach(color -> {
int[] rgb = Arrays.stream(color.split("\\s+")).mapToInt(Integer::parseInt).toArray();
int[] hsv = PantoneUtils.rgbToHsv(rgb);
int value = (hsv[0] * 101 *101)+ (hsv[1]*101) +hsv[2];
colorValueRgb.put(value,color);
values.add(value);
});
List<ColorLookupTable> colorValueList = colorLoopUpTableService.getByColorValueList(values);
colorValueList.forEach(colorValue ->{
colorIndexRgb.put(colorValue.getColorIndex(),colorValueRgb.get(colorValue.getColorValue()));
});
List<PanTone> panTones = panToneService.listByIds(colorIndexRgb.keySet());
ArrayList<PantoneVO> pantoneVOS = new ArrayList<>();
panTones.forEach(panTone -> {
pantoneVOS.add(coverPanToneToVo(panTone));
});
HashMap<String, PantoneVO> colorPantoneVO = new HashMap<>();
pantoneVOS.forEach(pantoneVO -> {
colorPantoneVO.put(colorIndexRgb.get(pantoneVO.getId()),pantoneVO);
});
return colorPantoneVO;
}
@Override
public PantoneVO getPantoneByRgb(String color){
GetRgbByHsvBatchDTO getRgbByHsvBatchDTO = new GetRgbByHsvBatchDTO();
if (!StringUtil.isNullOrEmpty(color)){
int[] rgb = Arrays.stream(color.split("\\s+")).mapToInt(Integer::parseInt).toArray();
int[] hsv = PantoneUtils.rgbToHsv(rgb);
getRgbByHsvBatchDTO.setH(hsv[0]);
getRgbByHsvBatchDTO.setS(hsv[1]);
getRgbByHsvBatchDTO.setV(hsv[2]);
}
return getByHSV(getRgbByHsvBatchDTO.getH(),getRgbByHsvBatchDTO.getS(),getRgbByHsvBatchDTO.getV());
}
@Override
public List<PantoneVO> getRgbByHsvBatch(List<GetRgbByHsvBatchDTO> hsvBatch) {
if(hsvBatch.size() >15){

View File

@@ -1,13 +1,19 @@
package com.ai.da.service.impl;
import com.ai.da.common.utils.CopyUtil;
import com.ai.da.mapper.TDesignPythonOutfitDetailMapper;
import com.ai.da.mapper.entity.TDesignPythonOutfitDetail;
import com.ai.da.model.vo.DesignPythonOutfitVO;
import com.ai.da.model.vo.TDesignPythonOutfitDetailVO;
import com.ai.da.service.ITDesignPythonOutfitDetailService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.List;
import java.util.Objects;
/**
* design item详情表 服务实现类
*
@@ -22,4 +28,21 @@ public class TDesignPythonOutfitDetailServiceImpl extends ServiceImpl<TDesignPyt
return page.setRecords(baseMapper.selectTDesignPythonOutfitDetailPage(page, tDesignPythonOutfitDetail));
}
@Override
public List<TDesignPythonOutfitDetail> getDetailByDesignPythonOutfitId(Long designPythonOutfitId){
QueryWrapper<TDesignPythonOutfitDetail> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("design_python_outfit_id",designPythonOutfitId);
return baseMapper.selectList(queryWrapper);
}
@Override
public DesignPythonOutfitVO convertToDesignPythonOutfitVO(TDesignPythonOutfitDetail detail){
if (Objects.isNull(detail)) {
return null;
}
return CopyUtil.copyObject(detail,DesignPythonOutfitVO.class);
}
}