Merge branch 'test/stable' into release/3.0

# Conflicts:
#	src/main/java/com/ai/da/service/impl/AccountServiceImpl.java
This commit is contained in:
2024-05-28 10:59:34 +08:00
86 changed files with 1874 additions and 363 deletions

View File

@@ -519,6 +519,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
account.setIsTrial(1);
account.setIsBeginner(1);
account.setValidStartTime(System.currentTimeMillis());
if (link) {
account.setValidEndTime(Instant.now().plus(14, ChronoUnit.DAYS).toEpochMilli());
}else {
@@ -904,15 +905,23 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
@Override
public void upgradeNotification() {
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
// queryWrapper.eq("id", 88L);
queryWrapper.and(wrapper ->
wrapper.gt("valid_end_time", 1709515797000L)
wrapper.gt("valid_end_time", 1715817600000L)
.or().isNull("valid_end_time"))
.isNotNull("user_email");
List<Account> accountList = accountMapper.selectList(queryWrapper);
System.out.println(accountList);
for (Account account : accountList) {
SendEmailUtil.sendUpgradeNotification(account, null);
// SendEmailUtil.sendUpgradeNotification(account, null, 0);
// SendEmailUtil.sendUpgradeNotification(account, null, 1);
if (account.getLanguage().equals(Language.CHINESE_SIMPLIFIED.name())) {
SendEmailUtil.sendUpgradeNotification(account, null, 0);
}else {
// 英文
SendEmailUtil.sendUpgradeNotification(account, null, 1);
}
}
}

View File

@@ -318,7 +318,7 @@ public class AliPayServiceImpl implements AliPayService {
CreditsEventsEnum.BUY_CREDITS.getValue(),
"positive");
// 更新积分
creditsService.buyCredits(orderByOrderNo.getAccountId(),orderByOrderNo.getTotalFee() / Integer.parseInt(CreditsEventsEnum.PRICE.getValue()));
creditsService.buyCredits(orderByOrderNo.getAccountId(),(int)(orderByOrderNo.getTotalFee() / Float.parseFloat(CreditsEventsEnum.PRICE.getValue())));
}
}
@@ -390,7 +390,8 @@ public class AliPayServiceImpl implements AliPayService {
AliPayTradeStateEnum.REFUND_SUCCESS.getType()); //退款成功
// 更新积分状态
OrderInfo orderByOrderNo = orderInfoService.getOrderByOrderNo(orderNo);
creditsService.creditsRefund(orderByOrderNo.getAccountId(), orderByOrderNo.getTotalFee() / Integer.parseInt(CreditsEventsEnum.PRICE.getValue()));
// creditsService.creditsRefund(orderByOrderNo.getAccountId(), orderByOrderNo.getTotalFee() / Integer.parseInt(CreditsEventsEnum.PRICE.getValue()));
creditsService.creditsRefund(orderByOrderNo.getAccountId(), (int)(orderByOrderNo.getTotalFee() / Float.parseFloat(CreditsEventsEnum.PRICE.getValue())));
} else {
log.info("调用失败,返回码 ===> " + response.getCode() + ", 返回描述 ===> " + response.getMsg());

View File

@@ -1,50 +1,113 @@
package com.ai.da.service.impl;
import com.ai.da.common.constant.AlipayHKConstant;
import com.ai.da.common.enums.CreditsEventsEnum;
import com.ai.da.service.AlipayHKService;
import com.ai.da.common.enums.OrderStatusEnum;
import com.ai.da.common.enums.PayTypeEnum;
import com.ai.da.common.utils.AlipayHKEncryptionUtil;
import com.ai.da.common.utils.AlipayHKRequestUtil;
import com.ai.da.mapper.primary.entity.OrderInfo;
import com.ai.da.model.dto.AlipayHKCallbackDTO;
import com.ai.da.model.dto.AlipayHKRequestDTO;
import com.ai.da.service.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.locks.ReentrantLock;
@Service
@Slf4j
public class AlipayHKServiceImpl implements AlipayHKService {
@Value("${alipay.hk.merchant-id}")
private static String merchantId;
@Value("${alipayHK.merchantId}")
private String merchantId;
@Value("${alipay.hk.segment-id}")
private static String segmentId;
@Value("${alipayHK.segmentId}")
private String segmentId;
@Value("${alipay.hk.AESKey}")
private static String aesKey;
@Value("${alipayHK.AESKey}")
private String aesKey;
@Value("${alipay.hk.rsaPrivateKey}")
private static String privateKeyPath;
@Value("${alipayHK.rsaPrivateKey}")
private String privateKeyPath;
@Value("${alipay.hk.rsaPublicKey}")
private static String publicKeyPath;
@Value("${alipayHK.rsaPublicKey}")
private String publicKeyPath;
@Resource
private OrderInfoService orderInfoService;
@Resource
private PaymentInfoService paymentInfoService;
@Resource
private CreditsService creditsService;
@Resource
private AlipayHKEncryptionUtil alipayHKEncryptionUtil;
@Resource
private AlipayHKRequestUtil alipayHKRequestUtil;
/**
* 创建订单
*/
public void createOrder(Integer amount){
@Override
public String createOrder(Integer amount, String wallet){
HashMap<String, Object> param = new HashMap<>();
String orderRef = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
param.put("order_ref", orderRef);
param.put("amount", Integer.parseInt(CreditsEventsEnum.PRICE.getValue()) * amount);
param.put("subject", "AiDA Credits Purchase");
param.put("wallet", "ALIPAYHK");
param.put("segment_id", segmentId);
param.put("payment_solution", "WAP");
try{
HashMap<String, Object> param = new HashMap<>();
String orderRef = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
param.put("order_ref", orderRef);
param.put("amount", Float.parseFloat(CreditsEventsEnum.PRICE.getValue()) * amount);
param.put("subject", "AiDA Credits Purchase");
// ALIPAYHK 或者 ALIPAYCN
param.put("wallet", wallet);
param.put("segment_id", segmentId);
param.put("payment_solution", "WAP");
log.info("alipay-hk 创建订单,参数信息: {}", param);
// 生成订单
log.info("创建订单");
OrderInfo orderInfo = orderInfoService.createOrderByProductId(amount, PayTypeEnum.ALIPAY_HK.getType());
// 加密
AlipayHKRequestDTO alipayHKRequestDTO = alipayHKEncryptionUtil.AESCBCWithRSA(param, AlipayHKConstant.CREATE_ORDER);
// 请求Alipay服务端
String response = alipayHKRequestUtil.createOrder(alipayHKRequestDTO);
// 获取response中的加密数据
JSONObject responseObj = JSONObject.parseObject(response);
JSONObject resultObj = JSONObject.parseObject(responseObj.get("result").toString());
String nonce = resultObj.get("nonce").toString();
String message = resultObj.get("message").toString();
// 解密
String s = alipayHKEncryptionUtil.decryptAES(message, nonce);
JSONObject jsonObject = JSONObject.parseObject(s);
String orderId = jsonObject.get("out_trade_no").toString();
orderInfoService.updateOrderNoById(orderInfo.getId(), orderId);
log.info("create_order 接口返回信息 {}", s);
return s;
}catch (Exception e){
log.error("订单创建失败 {}", e.getMessage());
// todo 或者抛异常
return null;
}
}
@@ -53,8 +116,122 @@ public class AlipayHKServiceImpl implements AlipayHKService {
* 异步回调
* @return
*/
public void callback(){
public String callback(Map<String, String> params){
log.info("支付通知正在执行");
log.info("通知参数 ===> {}", params);
String result = "failure";
String data = params.get("data");
String signature = params.get("signature");
try {
// 异步回调验签
Boolean verification = alipayHKEncryptionUtil.signatureVerification(data, signature);
if (!verification){
log.error("alipay-hk 验签失败");
return result;
}
AlipayHKCallbackDTO alipayHKCallbackDTO = JSONObject.parseObject(data, AlipayHKCallbackDTO.class);
//按照支付结果异步通知中的描述,对支付结果中的业务内容进行二次校验,
//1 商户需要验证该通知数据中的 out_trade_no 是否为商户系统中创建的订单号
String outTradeNo = alipayHKCallbackDTO.getOut_trade_no();
OrderInfo order = orderInfoService.getOrderByOrderNo(outTradeNo);
if(order == null){
log.error("订单不存在");
return result;
}
//2 判断 total_amount 是否确实为该订单的实际金额(即商户订单创建时的金额)
Long totalAmount = alipayHKCallbackDTO.getAmount();
Long totalFee = order.getTotalFee().longValue();
if(!Objects.equals(totalAmount, totalFee)){
log.error("金额校验失败");
return result;
}
//3 校验通知中的 seller_id或者 seller_email) 是否为 out_trade_no 这笔单据的对应的操作方
String sellerId = alipayHKCallbackDTO.getMerchant_id();
String sellerIdProperty = merchantId;
if(!sellerId.equals(sellerIdProperty)){
log.error("商家pid校验失败");
return result;
}
//4 验证 app_id 是否为该商户本身
String segId = alipayHKCallbackDTO.getSegment_id();
String segmentIdProperty = segmentId;
if(!segId.equals(segmentIdProperty)){
log.error("segmentId校验失败");
return result;
}
//在支付宝的业务通知中,只有交易通知状态为 TRADE_SUCCESS时
// 支付宝才会认定为买家付款成功。
String tradeStatus = alipayHKCallbackDTO.getStatus();
if(!AlipayHKConstant.STATUS_PAID.equals(tradeStatus)){
log.error("支付未成功");
return result;
}
processOrder(alipayHKCallbackDTO);
result = "success";
}catch (Exception e){
log.error(e.getMessage());
}
return result;
}
private final ReentrantLock lock = new ReentrantLock();
@Transactional(rollbackFor = Exception.class)
@Override
public void processOrder(AlipayHKCallbackDTO alipayHKCallbackDTO) {
log.info("处理订单");
//获取订单号
String orderNo = alipayHKCallbackDTO.getOut_trade_no();
String totalAmount = alipayHKCallbackDTO.getAmount().toString();
/*在对业务数据进行状态检查和处理之前,
要采用数据锁进行并发控制,
以避免函数重入造成的数据混乱*/
//尝试获取锁:
// 成功获取则立即返回true获取失败则立即返回false。不必一直等待锁的释放
if(lock.tryLock()) {
try {
//处理重复通知
//接口调用的幂等性:无论接口被调用多少次,以下业务执行一次
// String orderStatus = orderInfoService.getOrderStatus(orderNo);
OrderInfo orderByOrderNo = orderInfoService.getOrderByOrderNo(orderNo);
String orderStatus = orderByOrderNo.getOrderStatus();
// 当订单状态处于未支付或超时已关闭时,更新订单状态
if (!OrderStatusEnum.NOT_PAY.getType().equals(orderStatus) || !OrderStatusEnum.TIMEOUT_CLOSED.getType().equals(orderStatus)) {
return;
}
//更新订单状态
orderInfoService.updateStatusByOrderNo(orderNo, OrderStatusEnum.SUCCESS);
//记录支付日志
paymentInfoService.createPaymentInfoForAliPayHK(alipayHKCallbackDTO);
// 添加积分变更记录
creditsService.insertToCreditsDetail(orderByOrderNo.getAccountId(),
CreditsEventsEnum.BUY_CREDITS.getName() + "--AlipayHK",
CreditsEventsEnum.BUY_CREDITS.getValue(),
"positive");
// 更新积分
creditsService.buyCredits(orderByOrderNo.getAccountId(),Integer.parseInt(totalAmount) / Integer.parseInt(CreditsEventsEnum.PRICE.getValue()));
} finally {
//要主动释放锁
lock.unlock();
}
}
}
@@ -88,10 +265,28 @@ public class AlipayHKServiceImpl implements AlipayHKService {
public static void main(String[] args) throws Exception {
// test();
// AESCBCWithRSA();
// decrypt();
// public static void main(String[] args) throws Exception {
//// test();
//// AESCBCWithRSA();
//// decrypt();
// }
public static void main(String[] args) {
System.out.println("Supported TLS versions:");
String[] tlsVersions = getSupportedTLSVersions();
Arrays.stream(tlsVersions).forEach(System.out::println);
}
public static String[] getSupportedTLSVersions() {
try {
SSLContext context = SSLContext.getDefault();
SSLSocketFactory factory = context.getSocketFactory();
String[] supportedProtocols = factory.getDefaultCipherSuites();
return supportedProtocols;
} catch (Exception e) {
e.printStackTrace();
return new String[0];
}
}

View File

@@ -13,6 +13,8 @@ import com.ai.da.mapper.primary.ClassificationRelLibraryMapper;
import com.ai.da.mapper.primary.entity.Classification;
import com.ai.da.mapper.primary.entity.ClassificationRelLibrary;
import com.ai.da.model.dto.ClassificationDTO;
import com.ai.da.model.enums.DesignElementsEnum;
import com.ai.da.model.enums.Language;
import com.ai.da.model.vo.AuthPrincipalVo;
import com.ai.da.model.vo.ClassificationVO;
import com.ai.da.service.ClassificationService;
@@ -106,7 +108,19 @@ public class ClassificationServiceImpl implements ClassificationService {
List<Classification> classificationList = classificationMapper.selectList(qw);
if (CollectionUtil.isNotEmpty(classificationList)) {
// 获取结果集
return getClassificationVOList(classificationList);
List<ClassificationVO> classificationVOList = getClassificationVOList(classificationList);
if (classificationDTO.getType().equals("DesignElements")) {
for (ClassificationVO classificationVO : classificationVOList) {
String classificationName = classificationVO.getClassificationName();
DesignElementsEnum designElementsEnum = DesignElementsEnum.fromName(classificationName);
if (userHolder.getLanguage().equals(Language.ENGLISH.name())) {
classificationVO.setClassificationName(designElementsEnum.getEnglish());
}else {
classificationVO.setClassificationName(designElementsEnum.getChinese());
}
}
}
return classificationVOList;
}
return new ArrayList<>();
}

View File

@@ -35,6 +35,7 @@ import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@@ -76,6 +77,8 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
@Value("${minio.bucketName.collectionElement}")
private String collectionElement;
@Value("${minio.bucketName.gradient}")
private String gradientBucketName;
@Transactional
@Override
@@ -348,7 +351,20 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
@Override
public ValidateElementVO validateElement(DesignCollectionDTO designDTO) {
ValidateElementVO elementVO = CopyUtil.copyObject(designDTO, ValidateElementVO.class);
List<CollectionColorDTO> colorBoards = elementVO.getColorBoards();
for (CollectionColorDTO colorBoard : colorBoards) {
if (Objects.nonNull(colorBoard.getGradient())) {
String colorImg = colorBoard.getGradient().getColorImg();
String[] parts = colorImg.split(",");
String imageType = parts[0].split("/")[1].split(";")[0];
String base64Data = parts[1];
String gradientMinioUrl = minioUtil.uploadImageFromBase64(gradientBucketName, base64Data, imageType);
colorBoard.setGradientMinioUrl(gradientMinioUrl);
colorBoard.getGradient().setColorImg(null);
colorBoard.setGradientString(JSON.toJSONString(colorBoard.getGradient()));
}
}
elementVO.setColorBoards(colorBoards);
List<Long> usedElementIds = elementVO.getUsedElementIds();
List<CollectionElement> libraryCollectionElements = elementVO.getLibraryCollectionElements();
List<CollectionElement> generateCollectionElements = elementVO.getGenerateCollectionElements();
@@ -767,7 +783,10 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
element.setColorRgb(color.getRgbValue());
//按时区计算
element.setCreateDate(DateUtil.getByTimeZone(timeZone));
if (Objects.nonNull(color.getGradient())) {
color.getGradient().setColorImg(null);
}
element.setGradientString(JSON.toJSONString(color.getGradient()));
elements.add(element);
});
return elements;

View File

@@ -28,6 +28,7 @@ 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.apache.commons.lang3.SerializationUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -309,7 +310,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
}
private List<TDesignPythonOutfitDetail> saveDesignSingleItemDetailAndLayers(DesignPythonObjects pythonObjects
, Long designId, Long designItemId, AuthPrincipalVo userInfo
, Long designId, Long designItemId, Long userId
, JSONObject outfit, String timeZone, List<DesignSingleItemDTO> designSingleItemDTOList) {
DesignItem designItem = new DesignItem();
@@ -328,7 +329,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
return;
}
DesignItemDetail designItemDetail = CopyUtil.copyObject(detail, DesignItemDetail.class);
designItemDetail.setAccountId(userInfo.getId());
designItemDetail.setAccountId(userId);
designItemDetail.setDesignId(designId);
designItemDetail.setDesignItemId(designItemId);
designItemDetail.setCollectionElementId(detail.getElementId());
@@ -367,12 +368,9 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
// 7、将新生成的图层信息存入designPythonOutfitDetail表
JSONArray layers = outfit.getJSONArray("layers");
// 需要将request中的offset也存入数据库通过priority与image_category将sketch与layers关联
// Map<String, List<Long>> typeOffset = designSingleItemDTOList.stream()
// .collect(Collectors.toMap(d -> d.getType().toLowerCase(), DesignSingleItemDTO::getOffset));
Map<Integer, List<Long>> priorityOffset = designSingleItemDTOList.stream()
.collect(Collectors.toMap(DesignSingleItemDTO::getPriority, DesignSingleItemDTO::getOffset));
List<TDesignPythonOutfitDetail> list = setTDesignPythonOutfitDetailList(layers, designId, designPythonOutfit.getId(), userInfo.getId(), priorityOffset);
List<TDesignPythonOutfitDetail> list = setTDesignPythonOutfitDetailList(layers, designId, designPythonOutfit.getId(), userId, priorityOffset);
designPythonOutfitDetailService.saveBatch(list);
@@ -418,9 +416,17 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
@Override
@Transactional(rollbackFor = Exception.class)
public DesignSingleVO designSingleIncludeLayers(DesignSingleIncludeLayersDTO designSingleIncludeLayersDTO) {
log.info("designSingle request入参 ==> " + designSingleIncludeLayersDTO.toString());
// 记录入参 base64数据太长所以这里去掉
DesignSingleIncludeLayersDTO clone = SerializationUtils.clone(designSingleIncludeLayersDTO);
clone.getDesignSingleItemDTOList().forEach( i -> {
if (!Objects.isNull(i.getGradient()) && !StringUtil.isNullOrEmpty(i.getGradient().getColorImg())){
i.getGradient().setColorImg(null);
}
});
AuthPrincipalVo userInfo = UserContext.getUserHolder();
log.info("designSingle request入参 ==> " + JSONObject.toJSONString(clone));
Long userId = UserContext.getUserHolder().getId();
DesignItem designItem = selectById(designSingleIncludeLayersDTO.getDesignItemId());
if (Objects.isNull(designItem)) {
throw new BusinessException("designItem.not.found");
@@ -477,8 +483,6 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
}
JSONObject outfit = data.getJSONObject("0");
// 通过priority将offset关联到layers
// Map<String, List<Long>> typeOffset = designSingleIncludeLayersDTO.getDesignSingleItemDTOList().stream()
// .collect(Collectors.toMap(d -> d.getType().toLowerCase(), DesignSingleItemDTO::getOffset));
Map<Integer, List<Long>> priorityOffset = new HashMap<>();
try{
priorityOffset = designSingleIncludeLayersDTO.getDesignSingleItemDTOList().stream()
@@ -492,12 +496,12 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
if (!designSingleIncludeLayersDTO.getIsPreview()) {
// 更新及保存图层信息
tDesignPythonOutfitDetails = saveDesignSingleItemDetailAndLayers(objects, design.getId(), designSingleIncludeLayersDTO.getDesignItemId(),
userInfo, outfit, designSingleIncludeLayersDTO.getTimeZone(), designSingleIncludeLayersDTO.getDesignSingleItemDTOList());
userId, outfit, designSingleIncludeLayersDTO.getTimeZone(), designSingleIncludeLayersDTO.getDesignSingleItemDTOList());
saveCollectionElement(designSingleIncludeLayersDTO);
} else {
JSONArray layers = outfit.getJSONArray("layers");
tDesignPythonOutfitDetails = setTDesignPythonOutfitDetailList(layers, designItem.getDesignId(), null, userInfo.getId(), priorityOffset);
tDesignPythonOutfitDetails = setTDesignPythonOutfitDetailList(layers, designItem.getDesignId(), null, userId, priorityOffset);
}
List<DesignPythonOutfitVO> detailsVO = new ArrayList<>();
@@ -582,7 +586,8 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
designItemLayer.getLayers().forEach(layer -> {
ArrayList<Long> imageSize = new ArrayList<>();
for (int i = 0; i < layer.getImageSize().size(); i++) {
imageSize.add((long) (layer.getImageSize().get(i) * layer.getScale()));
// todo check这里的计算是否正确
imageSize.add((long) (layer.getImageSize().get(i) * layer.getScale()[i]));
}
layer.setImageSize(imageSize);
if (!StringUtil.isNullOrEmpty(layer.getImageUrl())) {
@@ -644,6 +649,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
layers -> (singleItem.getType().toLowerCase().equals(layers.getImageCategory().split("_")[0])
&& (flag ? Boolean.TRUE : singleItem.getPriority().equals(layers.getPriority())))
).collect(Collectors.toList()));
designItemClothesDetailVO.setGradient(singleItem.getGradient());
body.setLayersObject(layersObject.stream().filter(layers -> layers.getImageCategory().equals("body")).collect(Collectors.toList()));
clothes.add(designItemClothesDetailVO);

View File

@@ -350,7 +350,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
list.add(1L);
list.add(1L);
item.setOffset(list);
item.setResize_scale(1f);
item.setResize_scale(new Float[]{1.0f,1.0f});
String path = item.getPath();
if (StringUtils.isEmpty(path)) {
String bodyPath = item.getBody_path();
@@ -434,7 +434,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
list.add(1L);
list.add(1L);
item.setOffset(list);
item.setResize_scale(1f);
item.setResize_scale(new Float[]{1.0f,1.0f});
String path = item.getPath();
if (StringUtils.isEmpty(path)) {
String bodyPath = item.getBody_path();
@@ -631,7 +631,9 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
print.setPath(designItemDetail.getPrintPath());
print.setSingleOrOverall("overall");
print.setPosition("[0.0,0.0]");
print.setScale(1d);
// print.setScale(1d);
// todo mark 将print默认scale置为0.3
print.setScale(0.3d);
print.setAngle(0.0);
print.setPriority(1);
print.setCreateDate(LocalDateTime.now());
@@ -996,6 +998,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
d.setPath(minioUtil.getPresignedUrl(o.getPath(), 24 * 60));
d.setMinIOPath(o.getPath());
d.setLevel1Type(converTypeToLevel1(o.getType()));
d.setGradient(JSONObject.parseObject(o.getGradientString(), Gradient.class));
// 根据designItemDetailId获取印花
List<DesignItemDetailPrint> prints = designItemDetailPrintService.getByDesignItemDetailId(o.getId());
// 判断有无印花
@@ -1003,13 +1006,6 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
// 有印花
d.setPrintObject(convertToDesignSinglePrintDTO(prints));
}
// String printJson = o.getPrintJson();
// if (StringUtils.isEmpty(printJson)) {
// d.setPrintObject(new DesignPythonItemPrint(o.getPrintPath(),
// CollectionLevel1TypeEnum.PRINT_BOARD.getRealName(), 0.3f, Boolean.FALSE));
// } else {
// d.setPrintObject(JSON.parseObject(printJson, DesignPythonItemPrint.class));
// }
}));
//single 和 Models(模特)时候 系统元素为空
List<DesignItemDetail> filterDetail2 = designItemDetails.stream()

View File

@@ -259,7 +259,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
switch (level1Type) {
case "Moodboard":
text = translated + ",high quality";
generate.setText(text);
// generate.setText(text);
break;
case "Printboard":
if (userInput.contains("Painting Style")) {
@@ -270,11 +270,11 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
userInput = "Still life photography,hyper realism,3d,deepened projection,increased permutation value,increased concavity and convexity value," + translated;
}
text = userInput + ", fabric print, high quality";
generate.setText(text);
// generate.setText(text);
break;
case "Sketchboard":
text = "clear lines, simple outlines monochrome white vector image of " + translated + ", no background, sketch flat, front view display, best quality, ultra-high resolution 8k";
generate.setText(text);
// generate.setText(text);
default:
}
return text;

View File

@@ -130,10 +130,10 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
queryWrapper.eq("level2_type", query.getModelSex());
}
if (!StringUtils.isEmpty(query.getLevel2Type())) {
CollectionLevel2TypeEnum level2TypeEnum = CollectionLevel2TypeEnum.of(query.getLevel2Type());
if (Objects.isNull(level2TypeEnum)) {
throw new BusinessException("unknown.parameter.level2Type");
}
// CollectionLevel2TypeEnum level2TypeEnum = CollectionLevel2TypeEnum.of(query.getLevel2Type());
// if (Objects.isNull(level2TypeEnum)) {
// throw new BusinessException("unknown.parameter.level2Type");
// }
queryWrapper.eq("level2_type", query.getLevel2Type());
}
if (!StringUtils.isEmpty(query.getType())) {
@@ -228,13 +228,13 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
if (Objects.isNull(level1TypeEnum)) {
throw new BusinessException("unknown.parameter.level1Type");
}
if (!StringUtils.isEmpty(libraryUploadDTO.getLevel2Type())) {
CollectionLevel2TypeEnum level2TypeEnum = CollectionLevel2TypeEnum.of(libraryUploadDTO.getLevel2Type());
if (Objects.isNull(level2TypeEnum)) {
throw new BusinessException("unknown.parameter.level2Type");
}
}
if (level1TypeEnum.equals(LibraryLevel1TypeEnum.SKETCH_BOARD) && StringUtils.isEmpty(libraryUploadDTO.getLevel2Type())) {
// if (!StringUtils.isEmpty(libraryUploadDTO.getLevel2Type())) {
// CollectionLevel2TypeEnum level2TypeEnum = CollectionLevel2TypeEnum.of(libraryUploadDTO.getLevel2Type());
// if (Objects.isNull(level2TypeEnum)) {
// throw new BusinessException("unknown.parameter.level2Type");
// }
// }
if ((level1TypeEnum.equals(LibraryLevel1TypeEnum.SKETCH_BOARD) || level1TypeEnum.equals(LibraryLevel1TypeEnum.PRINT_BOARD) || level1TypeEnum.equals(LibraryLevel1TypeEnum.DESIGN_ELEMENTS)) && StringUtils.isEmpty(libraryUploadDTO.getLevel2Type())) {
throw new BusinessException("level2Type.cannot.be.empty");
}
String path = calculateFileUrl(level1TypeEnum, libraryUploadDTO.getLevel2Type(), libraryUploadDTO.getModelSex(), userInfo.getId());
@@ -244,6 +244,7 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
case MOOD_BOARD:
case PRINT_BOARD:
case SKETCH_BOARD:
case DESIGN_ELEMENTS:
bucketName = users;
break;
case MARKETING_SKETCH:

View File

@@ -54,7 +54,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
orderInfo.setTitle("积分购买 X" + amount );
orderInfo.setOrderNo(OrderNoUtils.getOrderNo()); //订单号 ??
// orderInfo.setProductId(amount);
orderInfo.setTotalFee(Integer.parseInt(CreditsEventsEnum.PRICE.getValue()) * amount); // 元 HKD
// orderInfo.setTotalFee(Integer.parseInt(CreditsEventsEnum.PRICE.getValue()) * amount); // 元 HKD
orderInfo.setTotalFee(Float.parseFloat(CreditsEventsEnum.PRICE.getValue()) * amount); // 元 HKD
orderInfo.setOrderStatus(OrderStatusEnum.NOT_PAY.getType()); //未支付
orderInfo.setPaymentType(paymentType);
baseMapper.insert(orderInfo);

View File

@@ -486,7 +486,8 @@ public class PayPalCheckoutServiceImpl implements PayPalCheckoutService {
// 更新积分状态
OrderInfo orderByOrderNo = orderInfoService.getOrderByOrderNo(orderId);
creditsService.creditsRefund(orderByOrderNo.getAccountId(), orderByOrderNo.getTotalFee() / Integer.parseInt(CreditsEventsEnum.PRICE.getValue()));
// creditsService.creditsRefund(orderByOrderNo.getAccountId(), orderByOrderNo.getTotalFee() / Integer.parseInt(CreditsEventsEnum.PRICE.getValue()));
creditsService.creditsRefund(orderByOrderNo.getAccountId(), (int)(orderByOrderNo.getTotalFee() / Float.parseFloat(CreditsEventsEnum.PRICE.getValue())));
log.info("退款成功");
result = Boolean.TRUE;
} else {
@@ -591,7 +592,7 @@ public class PayPalCheckoutServiceImpl implements PayPalCheckoutService {
CreditsEventsEnum.BUY_CREDITS.getValue(),
"positive");
// 更新积分
creditsService.buyCredits(orderInfo.getAccountId(), orderInfo.getTotalFee() / Integer.parseInt(CreditsEventsEnum.PRICE.getValue()));
creditsService.buyCredits(orderInfo.getAccountId(), (int)(orderInfo.getTotalFee() / Float.parseFloat(CreditsEventsEnum.PRICE.getValue())));
}
}
@@ -633,7 +634,8 @@ public class PayPalCheckoutServiceImpl implements PayPalCheckoutService {
CreditsEventsEnum.BUY_CREDITS.getValue(),
"positive");
// 更新积分
creditsService.buyCredits(orderByOrderNo.getAccountId(),orderByOrderNo.getTotalFee() / Integer.parseInt(CreditsEventsEnum.PRICE.getValue()));
// creditsService.buyCredits(orderByOrderNo.getAccountId(),orderByOrderNo.getTotalFee() / Integer.parseInt(CreditsEventsEnum.PRICE.getValue()));
creditsService.buyCredits(orderByOrderNo.getAccountId(),(int)(orderByOrderNo.getTotalFee() / Float.parseFloat(CreditsEventsEnum.PRICE.getValue())));
}
}

View File

@@ -3,6 +3,7 @@ package com.ai.da.service.impl;
import com.ai.da.common.enums.PayTypeEnum;
import com.ai.da.mapper.primary.PaymentInfoMapper;
import com.ai.da.mapper.primary.entity.PaymentInfo;
import com.ai.da.model.dto.AlipayHKCallbackDTO;
import com.ai.da.service.PaymentInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.gson.Gson;
@@ -48,7 +49,8 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
paymentInfo.setTransactionId(transactionId);
paymentInfo.setTradeType(tradeType);
paymentInfo.setTradeState(tradeState);
paymentInfo.setPayerTotal(payerTotal);
// 原来的单位是:分 Int 现改为:元 Long
paymentInfo.setPayerTotal(payerTotal / 100L);
paymentInfo.setContent(plainText);
baseMapper.insert(paymentInfo);
@@ -80,7 +82,8 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
paymentInfo.setTransactionId(transactionId);
paymentInfo.setTradeType("电脑网站支付");
paymentInfo.setTradeState(tradeStatus);
paymentInfo.setPayerTotal(totalAmountInt);
// 原来的单位是分 Int 现改为元 Long
paymentInfo.setPayerTotal(totalAmountInt / 100L);
Gson gson = new Gson();
String json = gson.toJson(params, HashMap.class);
@@ -95,7 +98,7 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
log.info("记录支付日志");
// int totalAmountInt = new BigDecimal(totalAmount).multiply(new BigDecimal("100")).intValue();
int totalAmountInt = new BigDecimal(order.purchaseUnits().get(0).payments().captures().get(0).amount().value()).intValue();
Long totalAmountInt = new BigDecimal(order.purchaseUnits().get(0).payments().captures().get(0).amount().value()).longValue();
PaymentInfo paymentInfo = new PaymentInfo();
paymentInfo.setOrderNo(order.id());
@@ -103,6 +106,7 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
paymentInfo.setTransactionId(order.id());
paymentInfo.setTradeType("电脑网站支付");
paymentInfo.setTradeState(order.status());
// todo 确认这里的数据单位是不是元
paymentInfo.setPayerTotal(totalAmountInt);
Gson gson = new Gson();
@@ -111,4 +115,35 @@ public class PaymentInfoServiceImpl extends ServiceImpl<PaymentInfoMapper, Payme
baseMapper.insert(paymentInfo);
}
@Override
public void createPaymentInfoForAliPayHK(AlipayHKCallbackDTO alipayHKCallbackDTO) {
log.info("记录支付日志");
//获取订单号
String orderNo = alipayHKCallbackDTO.getOut_trade_no();
//业务编号
String transactionId = alipayHKCallbackDTO.getTransaction_id();
//交易状态
String tradeStatus = alipayHKCallbackDTO.getStatus();
//交易金额
String totalAmount = alipayHKCallbackDTO.getAmount().toString();
// int totalAmountInt = new BigDecimal(totalAmount).multiply(new BigDecimal("100")).intValue();
Long totalAmountInt = new BigDecimal(totalAmount).longValue();
PaymentInfo paymentInfo = new PaymentInfo();
paymentInfo.setOrderNo(orderNo);
paymentInfo.setPaymentType(PayTypeEnum.ALIPAY_HK.getType());
paymentInfo.setTransactionId(transactionId);
paymentInfo.setTradeType("电脑网站支付");
paymentInfo.setTradeState(tradeStatus);
paymentInfo.setPayerTotal(totalAmountInt);
Gson gson = new Gson();
String json = gson.toJson(alipayHKCallbackDTO);
paymentInfo.setContent(json);
baseMapper.insert(paymentInfo);
}
}

View File

@@ -0,0 +1,474 @@
package com.ai.da.service.impl;
import com.ai.da.common.context.UserContext;
import com.ai.da.common.response.PageBaseResponse;
import com.ai.da.common.response.Response;
import com.ai.da.common.utils.CopyUtil;
import com.ai.da.common.utils.MinioUtil;
import com.ai.da.mapper.primary.*;
import com.ai.da.mapper.primary.entity.*;
import com.ai.da.model.dto.PortfolioDTO;
import com.ai.da.model.dto.QueryPortfolioPageDTO;
import com.ai.da.model.enums.Position;
import com.ai.da.model.enums.Sex;
import com.ai.da.model.vo.*;
import com.ai.da.service.*;
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 com.google.common.base.Function;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Service
public class PortfolioServiceImpl extends ServiceImpl<PortfolioMapper, Portfolio> implements PortfolioService {
@Resource
private UserLikeGroupMapper userLikeGroupMapper;
@Resource
private CollectionMapper collectionMapper;
@Resource
private CollectionElementService collectionElementService;
@Resource
private CollectionElementMapper collectionElementMapper;
@Resource
private TCollectionElementRelationMapper collectionElementRelationMapper;
@Resource
private PortfolioMapper portfolioMapper;
@Resource
private UserLikeService userLikeService;
@Resource
private UserLikeMapper userLikeMapper;
@Resource
private TDesignPythonOutfitMapper designPythonOutfitMapper;
@Resource
private TDesignPythonOutfitDetailMapper designPythonOutfitDetailMapper;
@Resource
private DesignItemMapper designItemMapper;
@Resource
private DesignItemDetailMapper designItemDetailMapper;
@Resource
private DesignItemDetailPrintMapper designItemDetailPrintMapper;
@Resource
private MinioUtil minioUtil;
@Resource
private WorkspaceService workspaceService;
@Resource
private DesignMapper designMapper;
@Resource
private UserLikeGroupService userLikeGroupService;
@Override
public Boolean publish(PortfolioDTO portfolioDTO) {
if (portfolioDTO.getPortfolioType().equals("History")) {
AuthPrincipalVo authPrincipalVo = UserContext.getUserHolder();
UserLikeGroup userLikeGroup = userLikeGroupMapper.selectById(portfolioDTO.getUserLikeGroupId());
UserLikeGroup userLikeGroupNew = userLikeGroup.setId(null);
userLikeGroupNew.setAccountId(-1L);
Long collectionIdOld = userLikeGroup.getCollectionId();
Collection collectionOld = collectionMapper.selectById(collectionIdOld);
List<CollectionElement> collectionElementListOld = collectionElementService.getByCollectionId(collectionIdOld);
collectionOld.setId(null);
collectionMapper.insert(collectionOld);
Long collectionIdNew = collectionOld.getId();
userLikeGroupNew.setCollectionId(collectionIdNew);
userLikeGroupMapper.insert(userLikeGroupNew);
// List<TCollectionElementRelation> collectionElementRelationListNew = new ArrayList<>();
for (CollectionElement element : collectionElementListOld) {
element.setCollectionId(collectionIdNew);
element.setId(null);
collectionElementMapper.insert(element);
TCollectionElementRelation collectionElementRelationNew = new TCollectionElementRelation();
collectionElementRelationNew.setCollectionId(collectionIdNew);
collectionElementRelationNew.setElementId(element.getId());
collectionElementRelationNew.setCreateDate(new Date());
collectionElementRelationMapper.insert(collectionElementRelationNew);
}
Portfolio portfolio = new Portfolio();
Long coverIdOld = portfolioDTO.getCoverId();
portfolio.setPortfolioName(portfolioDTO.getPortfolioName());
portfolio.setPortfolioType("History");
portfolio.setCollectionId(collectionIdNew);
portfolio.setAccountId(authPrincipalVo.getId());
portfolio.setCreateDate(LocalDateTime.now());
portfolio.setUpdateDate(LocalDateTime.now());
portfolio.setStatus(1);
portfolio.setIsDeleted(0);
portfolio.setUserLikeGroupSourceId(portfolioDTO.getUserLikeGroupId());
portfolioMapper.insert(portfolio);
List<UserLike> userLikeList = userLikeService.getUserLikeList(portfolioDTO.getUserLikeGroupId());
// List<Long> designPythonOutfitIdList = userLikeList.stream().map(UserLike::getDesignOutfitId).collect(Collectors.toList());
//
// QueryWrapper<TDesignPythonOutfit> qw = new QueryWrapper<>();
// qw.lambda().in(TDesignPythonOutfit::getId, designPythonOutfitIdList);
// List<TDesignPythonOutfit> designPythonOutfits = designPythonOutfitMapper.selectList(qw);
Long coverIdNew = null;
Boolean flag = false;
for (UserLike userLike : userLikeList) {
Long designOutfitIdOld = userLike.getDesignOutfitId();
TDesignPythonOutfit designPythonOutfit = designPythonOutfitMapper.selectById(designOutfitIdOld);
designPythonOutfit.setDesignId(-1L);
designPythonOutfit.setDesignItemId(-1L);
designPythonOutfit.setCollectionId(collectionIdNew);
if (designPythonOutfit.getId().equals(coverIdOld)) {
flag = true;
}
designPythonOutfit.setId(null);
designPythonOutfitMapper.insert(designPythonOutfit);
Long designOutfitIdNew = designPythonOutfit.getId();
userLike.setDesignOutfitId(designOutfitIdNew);
QueryWrapper<TDesignPythonOutfitDetail> qw = new QueryWrapper<>();
qw.lambda().eq(TDesignPythonOutfitDetail::getDesignPythonOutfitId, designOutfitIdOld);
List<TDesignPythonOutfitDetail> tDesignPythonOutfitDetails = designPythonOutfitDetailMapper.selectList(qw);
for (TDesignPythonOutfitDetail tDesignPythonOutfitDetail : tDesignPythonOutfitDetails) {
// Long designPythonOutfitDetailIdOld = tDesignPythonOutfitDetail.getId();
tDesignPythonOutfitDetail.setId(null);
tDesignPythonOutfitDetail.setDesignId(-1L);
tDesignPythonOutfitDetail.setDesignPythonOutfitId(designOutfitIdNew);
designPythonOutfitDetailMapper.insert(tDesignPythonOutfitDetail);
}
if (flag) {
coverIdNew = designOutfitIdNew;
portfolio.setCoverId(coverIdNew);
portfolioMapper.updateById(portfolio);
flag = false;
}
Long designItemIdOld = userLike.getDesignItemId();
DesignItem designItemOld = designItemMapper.selectById(designItemIdOld);
designItemOld.setId(null);
designItemOld.setAccountId(-1L);
designItemOld.setDesignId(-1L);
designItemOld.setCollectionId(collectionIdNew);
designItemMapper.insert(designItemOld);
Long designItemIdNew = designItemOld.getDesignId();
designPythonOutfit.setDesignItemId(designItemIdNew);
designPythonOutfitMapper.updateById(designPythonOutfit);
userLike.setDesignItemId(designItemIdNew);
userLike.setId(null);
userLike.setDesignId(-1L);
userLike.setUserLikeGroupId(userLikeGroupNew.getId());
userLikeMapper.insert(userLike);
QueryWrapper<DesignItemDetail> designItemDetailQueryWrapper = new QueryWrapper<>();
designItemDetailQueryWrapper.lambda().eq(DesignItemDetail::getDesignItemId, designItemOld);
List<DesignItemDetail> designItemDetailListOld = designItemDetailMapper.selectList(designItemDetailQueryWrapper);
for (DesignItemDetail designItemDetailOld : designItemDetailListOld) {
Long designItemDetailIdOld = designItemDetailOld.getId();
designItemDetailOld.setAccountId(-1L);
designItemDetailOld.setDesignId(-1L);
designItemDetailOld.setDesignItemId(designItemIdNew);
designItemDetailMapper.insert(designItemDetailOld);
Long designItemDetailIdNew = designItemDetailOld.getId();
QueryWrapper<DesignItemDetailPrint> designItemDetailPrintQueryWrapper = new QueryWrapper<>();
designItemDetailPrintQueryWrapper.lambda().eq(DesignItemDetailPrint::getDesignItemDetailId, designItemDetailIdOld);
DesignItemDetailPrint designItemDetailPrint = designItemDetailPrintMapper.selectOne(designItemDetailPrintQueryWrapper);
designItemDetailPrint.setDesignItemDetailId(designItemDetailIdNew);
designItemDetailPrintMapper.insert(designItemDetailPrint);
}
}
}else {
}
return Boolean.TRUE;
}
@Override
public PortfolioVO update(PortfolioDTO portfolioDTO) {
if (portfolioDTO.getPortfolioType().equals("History")) {
AuthPrincipalVo authPrincipalVo = UserContext.getUserHolder();
UserLikeGroup userLikeGroup = userLikeGroupMapper.selectById(portfolioDTO.getUserLikeGroupId());
UserLikeGroup userLikeGroupNew = userLikeGroup.setId(null);
userLikeGroupNew.setAccountId(-1L);
Long collectionIdOld = userLikeGroup.getCollectionId();
Collection collectionOld = collectionMapper.selectById(collectionIdOld);
List<CollectionElement> collectionElementListOld = collectionElementService.getByCollectionId(collectionIdOld);
collectionOld.setId(null);
collectionMapper.insert(collectionOld);
Long collectionIdNew = collectionOld.getId();
userLikeGroupNew.setCollectionId(collectionIdNew);
userLikeGroupMapper.insert(userLikeGroupNew);
// List<TCollectionElementRelation> collectionElementRelationListNew = new ArrayList<>();
for (CollectionElement element : collectionElementListOld) {
element.setCollectionId(collectionIdNew);
element.setId(null);
collectionElementMapper.insert(element);
TCollectionElementRelation collectionElementRelationNew = new TCollectionElementRelation();
collectionElementRelationNew.setCollectionId(collectionIdNew);
collectionElementRelationNew.setElementId(element.getId());
collectionElementRelationMapper.insert(collectionElementRelationNew);
}
Portfolio portfolio = getPortfolioByUserGroupIdSource(portfolioDTO.getUserLikeGroupId());
Long coverIdOld = portfolioDTO.getCoverId();
portfolio.setPortfolioName(portfolioDTO.getPortfolioName());
// portfolio.setPortfolioType("History");
portfolio.setCollectionId(collectionIdNew);
portfolio.setAccountId(authPrincipalVo.getId());
portfolio.setCreateDate(LocalDateTime.now());
portfolio.setUpdateDate(LocalDateTime.now());
portfolio.setStatus(1);
portfolio.setIsDeleted(0);
portfolioMapper.updateById(portfolio);
List<UserLike> userLikeList = userLikeService.getUserLikeList(portfolioDTO.getUserLikeGroupId());
Long coverIdNew = null;
Boolean flag = false;
for (UserLike userLike : userLikeList) {
Long designOutfitIdOld = userLike.getDesignOutfitId();
TDesignPythonOutfit designPythonOutfit = designPythonOutfitMapper.selectById(designOutfitIdOld);
designPythonOutfit.setDesignId(-1L);
designPythonOutfit.setDesignItemId(-1L);
designPythonOutfit.setCollectionId(collectionIdNew);
if (!flag && designPythonOutfit.getId() == coverIdOld) {
flag = true;
}
designPythonOutfit.setId(null);
designPythonOutfitMapper.insert(designPythonOutfit);
Long designOutfitIdNew = designPythonOutfit.getId();
userLike.setDesignOutfitId(designOutfitIdNew);
QueryWrapper<TDesignPythonOutfitDetail> qw = new QueryWrapper<>();
qw.lambda().eq(TDesignPythonOutfitDetail::getDesignPythonOutfitId, designOutfitIdOld);
List<TDesignPythonOutfitDetail> tDesignPythonOutfitDetails = designPythonOutfitDetailMapper.selectList(qw);
for (TDesignPythonOutfitDetail tDesignPythonOutfitDetail : tDesignPythonOutfitDetails) {
// Long designPythonOutfitDetailIdOld = tDesignPythonOutfitDetail.getId();
tDesignPythonOutfitDetail.setId(null);
tDesignPythonOutfitDetail.setDesignId(-1L);
tDesignPythonOutfitDetail.setDesignPythonOutfitId(designOutfitIdNew);
designPythonOutfitDetailMapper.insert(tDesignPythonOutfitDetail);
}
if (flag) {
coverIdNew = designPythonOutfit.getId();
portfolio.setCoverId(coverIdNew);
portfolioMapper.updateById(portfolio);
}
Long designItemIdOld = userLike.getDesignItemId();
DesignItem designItemOld = designItemMapper.selectById(designItemIdOld);
designItemOld.setId(null);
designItemOld.setAccountId(-1L);
designItemOld.setDesignId(-1L);
designItemOld.setCollectionId(collectionIdNew);
designItemMapper.insert(designItemOld);
Long designItemIdNew = designItemOld.getDesignId();
designPythonOutfit.setDesignItemId(designItemIdNew);
designPythonOutfitMapper.updateById(designPythonOutfit);
userLike.setDesignItemId(designItemIdNew);
userLike.setId(null);
userLike.setDesignId(-1L);
userLike.setUserLikeGroupId(userLikeGroupNew.getId());
userLikeMapper.insert(userLike);
QueryWrapper<DesignItemDetail> designItemDetailQueryWrapper = new QueryWrapper<>();
designItemDetailQueryWrapper.lambda().eq(DesignItemDetail::getDesignItemId, designItemOld);
List<DesignItemDetail> designItemDetailListOld = designItemDetailMapper.selectList(designItemDetailQueryWrapper);
for (DesignItemDetail designItemDetailOld : designItemDetailListOld) {
Long designItemDetailIdOld = designItemDetailOld.getId();
designItemDetailOld.setAccountId(-1L);
designItemDetailOld.setDesignId(-1L);
designItemDetailOld.setDesignItemId(designItemIdNew);
designItemDetailMapper.insert(designItemDetailOld);
Long designItemDetailIdNew = designItemDetailOld.getId();
QueryWrapper<DesignItemDetailPrint> designItemDetailPrintQueryWrapper = new QueryWrapper<>();
designItemDetailPrintQueryWrapper.lambda().eq(DesignItemDetailPrint::getDesignItemDetailId, designItemDetailIdOld);
DesignItemDetailPrint designItemDetailPrint = designItemDetailPrintMapper.selectOne(designItemDetailPrintQueryWrapper);
designItemDetailPrint.setDesignItemDetailId(designItemDetailIdNew);
designItemDetailPrintMapper.insert(designItemDetailPrint);
}
}
}
return null;
}
private Portfolio getPortfolioByUserGroupIdSource(Long userLikeGroupId) {
QueryWrapper<Portfolio> qw = new QueryWrapper<>();
qw.lambda().eq(Portfolio::getUserLikeGroupSourceId, userLikeGroupId);
return portfolioMapper.selectOne(qw);
}
@Override
public PageBaseResponse<PortfolioVO> page(QueryPortfolioPageDTO query) {
QueryWrapper<Portfolio> qw = new QueryWrapper<>();
qw.lambda().orderByDesc(Portfolio::getUpdateDate);
IPage<Portfolio> page = portfolioMapper.selectPage(new Page<>(query.getPage(), query.getSize()),qw);
IPage<PortfolioVO> convert = page.convert((Function<Portfolio, PortfolioVO>) portfolio -> {
if (portfolio != null) {
PortfolioVO vo = CopyUtil.copyObject(portfolio, PortfolioVO.class);
TDesignPythonOutfit designPythonOutfit = designPythonOutfitMapper.selectById(vo.getCoverId());
vo.setDesignPythonOutfitUrl(minioUtil.getPresignedUrl(designPythonOutfit.getDesignUrl(), 24 * 60));
return vo;
}
return null;
});
return PageBaseResponse.success(convert);
}
@Override
public PortfolioVO detail(PortfolioDTO portfolioDTO) {
Portfolio portfolio = portfolioMapper.selectById(portfolioDTO.getId());
PortfolioVO vo = CopyUtil.copyObject(portfolio, PortfolioVO.class);
Long collectionId = portfolio.getCollectionId();
List<CollectionElement> collectionElementList = collectionElementService.getByCollectionId(collectionId);
for (CollectionElement element : collectionElementList) {
if (StringUtils.isEmpty(element.getUrl())) {
continue;
}
element.setUrl(minioUtil.getPresignedUrl(element.getUrl(), 24 * 60));
}
vo.setCollectionElementList(collectionElementList);
QueryWrapper<TDesignPythonOutfit> qw = new QueryWrapper<>();
qw.lambda().eq(TDesignPythonOutfit::getCollectionId, portfolio.getCollectionId());
List<TDesignPythonOutfit> designPythonOutfitList = designPythonOutfitMapper.selectList(qw);
for (TDesignPythonOutfit tDesignPythonOutfit : designPythonOutfitList) {
tDesignPythonOutfit.setDesignUrl(minioUtil.getPresignedUrl(tDesignPythonOutfit.getDesignUrl(), 24 * 60));
}
vo.setDesignPythonOutfitList(designPythonOutfitList);
return vo;
}
@Override
public UserLikeChooseVO choose(PortfolioDTO portfolioDTO) {
AuthPrincipalVo authPrincipalVo = UserContext.getUserHolder();
UserLikeGroup userLikeGroup = userLikeGroupMapper.selectById(portfolioDTO.getUserLikeGroupId());
UserLikeGroup userLikeGroupNew = userLikeGroup.setId(null);
userLikeGroupNew.setAccountId(authPrincipalVo.getId());
Long collectionIdOld = userLikeGroup.getCollectionId();
Collection collectionOld = collectionMapper.selectById(collectionIdOld);
List<CollectionElement> collectionElementListOld = collectionElementService.getByCollectionId(collectionIdOld);
collectionOld.setId(null);
collectionMapper.insert(collectionOld);
Long collectionIdNew = collectionOld.getId();
Workspace workspace = workspaceService.getCurrentWorkspace();
Design design = new Design();
design.setCollectionId(collectionIdNew);
design.setAccountId(authPrincipalVo.getId());
if (workspace.getSex().equals(Sex.FEMALE.getValue())) {
design.setTemplateId(workspace.getMannequinFemaleId());
design.setModelType(workspace.getMannequinFemaleType());
}else {
design.setTemplateId(workspace.getMannequinMaleId());
design.setModelType(workspace.getMannequinMaleType());
}
design.setSystemScale(BigDecimal.valueOf(workspace.getSystemDesignerPercentage()));
if (workspace.getPosition().equals(Position.OVERALL.getValue())) {
design.setSingleOverall("overall");
design.setSwitchCategory("");
}else {
design.setSingleOverall("single");
design.setSwitchCategory(workspace.getPosition());
}
design.setCreateDate(new Date());
designMapper.insert(design);
userLikeGroupNew.setCollectionId(collectionIdNew);
userLikeGroupMapper.insert(userLikeGroupNew);
// List<TCollectionElementRelation> collectionElementRelationListNew = new ArrayList<>();
for (CollectionElement element : collectionElementListOld) {
element.setCollectionId(collectionIdNew);
element.setId(null);
collectionElementMapper.insert(element);
TCollectionElementRelation collectionElementRelationNew = new TCollectionElementRelation();
collectionElementRelationNew.setCollectionId(collectionIdNew);
collectionElementRelationNew.setElementId(element.getId());
collectionElementRelationNew.setCreateDate(new Date());
collectionElementRelationMapper.insert(collectionElementRelationNew);
}
List<UserLike> userLikeList = userLikeService.getUserLikeList(portfolioDTO.getUserLikeGroupId());
for (UserLike userLike : userLikeList) {
Long designOutfitIdOld = userLike.getDesignOutfitId();
TDesignPythonOutfit designPythonOutfit = designPythonOutfitMapper.selectById(designOutfitIdOld);
designPythonOutfit.setDesignId(design.getId());
designPythonOutfit.setDesignItemId(-1L);
designPythonOutfit.setCollectionId(collectionIdNew);
designPythonOutfit.setId(null);
designPythonOutfitMapper.insert(designPythonOutfit);
Long designOutfitIdNew = designPythonOutfit.getId();
userLike.setDesignOutfitId(designOutfitIdNew);
QueryWrapper<TDesignPythonOutfitDetail> qw = new QueryWrapper<>();
qw.lambda().eq(TDesignPythonOutfitDetail::getDesignPythonOutfitId, designOutfitIdOld);
List<TDesignPythonOutfitDetail> tDesignPythonOutfitDetails = designPythonOutfitDetailMapper.selectList(qw);
for (TDesignPythonOutfitDetail tDesignPythonOutfitDetail : tDesignPythonOutfitDetails) {
// Long designPythonOutfitDetailIdOld = tDesignPythonOutfitDetail.getId();
tDesignPythonOutfitDetail.setId(null);
tDesignPythonOutfitDetail.setDesignId(-1L);
tDesignPythonOutfitDetail.setDesignPythonOutfitId(designOutfitIdNew);
designPythonOutfitDetailMapper.insert(tDesignPythonOutfitDetail);
}
Long designItemIdOld = userLike.getDesignItemId();
DesignItem designItemOld = designItemMapper.selectById(designItemIdOld);
designItemOld.setId(null);
designItemOld.setAccountId(-1L);
designItemOld.setDesignId(-1L);
designItemOld.setCollectionId(collectionIdNew);
designItemMapper.insert(designItemOld);
Long designItemIdNew = designItemOld.getDesignId();
designPythonOutfit.setDesignItemId(designItemIdNew);
designPythonOutfitMapper.updateById(designPythonOutfit);
userLike.setDesignItemId(designItemIdNew);
userLike.setId(null);
userLike.setDesignId(design.getId());
userLike.setUserLikeGroupId(userLikeGroupNew.getId());
userLikeMapper.insert(userLike);
QueryWrapper<DesignItemDetail> designItemDetailQueryWrapper = new QueryWrapper<>();
designItemDetailQueryWrapper.lambda().eq(DesignItemDetail::getDesignItemId, designItemOld);
List<DesignItemDetail> designItemDetailListOld = designItemDetailMapper.selectList(designItemDetailQueryWrapper);
for (DesignItemDetail designItemDetailOld : designItemDetailListOld) {
Long designItemDetailIdOld = designItemDetailOld.getId();
designItemDetailOld.setAccountId(authPrincipalVo.getId());
designItemDetailOld.setDesignId(design.getId());
designItemDetailOld.setDesignItemId(designItemIdNew);
designItemDetailMapper.insert(designItemDetailOld);
Long designItemDetailIdNew = designItemDetailOld.getId();
QueryWrapper<DesignItemDetailPrint> designItemDetailPrintQueryWrapper = new QueryWrapper<>();
designItemDetailPrintQueryWrapper.lambda().eq(DesignItemDetailPrint::getDesignItemDetailId, designItemDetailIdOld);
DesignItemDetailPrint designItemDetailPrint = designItemDetailPrintMapper.selectOne(designItemDetailPrintQueryWrapper);
designItemDetailPrint.setDesignItemDetailId(designItemDetailIdNew);
designItemDetailPrintMapper.insert(designItemDetailPrint);
}
}
return userLikeGroupService.choose(userLikeGroupNew.getId());
}
}

View File

@@ -61,7 +61,8 @@ public class TDesignPythonOutfitDetailServiceImpl extends ServiceImpl<TDesignPyt
designPythonOutfitVO.setImageMinioUrl(StringUtil.isNullOrEmpty(detail.getImageUrl()) ? null : detail.getImageUrl());
designPythonOutfitVO.setMaskUrl(StringUtil.isNullOrEmpty(detail.getMaskUrl()) ? null : minIoUtil.getPresignedUrl(detail.getMaskUrl(), 24 * 60));
designPythonOutfitVO.setMaskMinioUrl(StringUtil.isNullOrEmpty(detail.getMaskUrl()) ? null : detail.getMaskUrl());
designPythonOutfitVO.setScale(Float.parseFloat(detail.getScale()));
// designPythonOutfitVO.setScale(Float.parseFloat(detail.getScale()));
designPythonOutfitVO.setScale(modifyScale(detail.getScale()));
designPythonOutfitVO.setOffset(StringUtil.isNullOrEmpty(detail.getOffset()) ? Arrays.asList(0L, 0L) : (List<Long>) JSON.parse(detail.getOffset()));
designPythonOutfitVO.setPriority(Math.abs(detail.getPriority()));
// designPythonOutfitVO.setOffset(CollectionUtil.isEmpty(offset) ? Arrays.asList(0L, 0L) : offset);
@@ -77,6 +78,33 @@ public class TDesignPythonOutfitDetailServiceImpl extends ServiceImpl<TDesignPyt
return designPythonOutfitVO;
}
private Float[] modifyScale(String scale){
Float[] scaleFloat = new Float[2];
if (!StringUtil.isNullOrEmpty(scale)){
if (scale.startsWith("[")){
// 去除中括号并去掉多余的空格
scale = scale.trim().replaceAll("^\\[|\\]$", "");
// 根据逗号和可选的空格拆分字符串
String[] parts = scale.split("\\s*,\\s*");
// Float[] floatArray = new Float[parts.length];
// 转换每个字符串为 Float 并添加到数组中
for (int i = 0; i < parts.length; i++) {
try {
scaleFloat[i] = Float.parseFloat(parts[i]);
} catch (NumberFormatException e) {
System.err.println("Invalid number format: " + parts[i]);
return new Float[0]; // 返回一个空数组或者其他错误处理逻辑
}
}
}else {
scaleFloat = new Float[]{Float.parseFloat(scale),Float.parseFloat(scale)};
}
}
return scaleFloat;
}
@Override
public void deleteByDesignPythonOutfitId(Long designPythonOutfitId) {
// QueryWrapper<TDesignPythonOutfitDetail> queryWrapper = new QueryWrapper<>();

View File

@@ -123,15 +123,6 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
}
List<UserLikeVO> userLikeVOS = userLikeService.getGroupDetail(userGroupId);
String sex = null;
// if (CollectionUtil.isNotEmpty(userLikeVOS)) {
// Long designId = userLikeVOS.get(0).getDesignId();
// Design design = designMapper.selectById(designId);
// if (design.getModelType().equals(ModelType.SYSTEM.getValue())) {
// sex = sysFileMapper.selectById(design.getTemplateId()).getLevel2Type();
// }else {
// sex = libraryMapper.selectById(design.getTemplateId()).getLevel2Type();
// }
// }
userLikeVOS.forEach(o -> {
TDesignPythonOutfit tDesignPythonOutfit1 = designPythonOutfitMapper.selectById(o.getDesignOutfitId());
o.setUrl(tDesignPythonOutfit1.getDesignUrl());

View File

@@ -81,4 +81,11 @@ public class UserLikeServiceImpl extends ServiceImpl<UserLikeMapper, UserLike> i
baseMapper.update(null,uw);
}
@Override
public List<UserLike> getUserLikeList(Long id) {
QueryWrapper<UserLike> qw = new QueryWrapper<>();
qw.lambda().eq(UserLike::getUserLikeGroupId, id);
return userLikeMapper.selectList(qw);
}
}

View File

@@ -9,18 +9,12 @@ import com.ai.da.common.utils.CopyUtil;
import com.ai.da.common.utils.FileUtil;
import com.ai.da.common.utils.MD5Utils;
import com.ai.da.common.utils.MinioUtil;
import com.ai.da.mapper.primary.LibraryMapper;
import com.ai.da.mapper.primary.SysFileMapper;
import com.ai.da.mapper.primary.WorkspaceMapper;
import com.ai.da.mapper.primary.entity.Library;
import com.ai.da.mapper.primary.entity.SysFile;
import com.ai.da.mapper.primary.entity.Workspace;
import com.ai.da.mapper.primary.*;
import com.ai.da.mapper.primary.entity.*;
import com.ai.da.model.dto.WorkspaceDTO;
import com.ai.da.model.dto.WorkspaceSaveDTO;
import com.ai.da.model.enums.*;
import com.ai.da.model.vo.AuthPrincipalVo;
import com.ai.da.model.vo.ModelVO;
import com.ai.da.model.vo.ModelsVO;
import com.ai.da.model.vo.WorkspaceVO;
import com.ai.da.model.vo.*;
import com.ai.da.service.WorkspaceService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -37,11 +31,13 @@ import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.annotation.Resource;
import javax.naming.Context;
import java.io.*;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@@ -57,6 +53,12 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
@Resource
private WorkspaceMapper workspaceMapper;
@Resource
private StyleMapper styleMapper;
@Resource
private WorkspaceRelStyleMapper workspaceRelStyleMapper;
@Resource
private LibraryMapper libraryMapper;
@@ -82,7 +84,8 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
private final static Integer SYSTEM_DESIGNER_PERCENTAGE = 30;
@Override
public boolean saveOrUpdate(Workspace workspace) {
public boolean saveOrUpdate(WorkspaceSaveDTO workspaceDTO) {
Workspace workspace = CopyUtil.copyObject(workspaceDTO, Workspace.class);
// 防止前端传值修改标识
workspace.setIsLastIndex(null);
AuthPrincipalVo userInfo = UserContext.getUserHolder();
@@ -113,12 +116,35 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
if (insert <= 0) {
throw new BusinessException("save.workspace.failed");
}
if (workspaceDTO.getStyleId() != null) {
WorkspaceRelStyle rel = new WorkspaceRelStyle();
rel.setWorkspaceId(workspace.getId());
rel.setStyleId(workspaceDTO.getStyleId());
workspaceRelStyleMapper.insert(rel);
}
return true;
} else {
int update = workspaceMapper.updateById(workspace);
if (update <= 0) {
throw new BusinessException("update.workspace.failed");
}
if (workspaceDTO.getStyleId() != null) {
QueryWrapper<WorkspaceRelStyle> qw = new QueryWrapper<>();
qw.lambda().eq(WorkspaceRelStyle::getWorkspaceId, workspace.getId());
List<WorkspaceRelStyle> workspaceRelStyles = workspaceRelStyleMapper.selectList(qw);
if (CollectionUtils.isEmpty(workspaceRelStyles)) {
WorkspaceRelStyle rel = new WorkspaceRelStyle();
rel.setWorkspaceId(workspace.getId());
rel.setStyleId(workspaceDTO.getStyleId());
workspaceRelStyleMapper.insert(rel);
}else {
WorkspaceRelStyle workspaceRelStyle = workspaceRelStyles.get(0);
if (!Objects.equals(workspaceRelStyle.getStyleId(), workspaceDTO.getStyleId())) {
workspaceRelStyle.setStyleId(workspaceRelStyle.getStyleId());
workspaceRelStyleMapper.updateById(workspaceRelStyle);
}
}
}
return true;
}
}
@@ -502,44 +528,36 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
return deleteIds;
}
// public static void main(String[] args) throws FileNotFoundException {
// String b = "C:\\workspace\\fileData\\aida_men_library\\top\\mens_test_9992.png";
// File pngFile = new File(b);
// SysFile sysFile = new SysFile();
// String fileName = pngFile.getName();
// sysFile.setName(fileName);
// sysFile.setLevel1Type("Images");
// sysFile.setLevel3Type("Male");
// StringBuilder sb = new StringBuilder();
// sb.append("aida-sys-image/images/male");
// String absolutePath = pngFile.getAbsolutePath();
// if (absolutePath.contains("bottom")) {
// sysFile.setLevel2Type("Bottoms");
// sb.append("/bottoms/");
// }else if(absolutePath.contains("top")) {
// sysFile.setLevel2Type("Tops");
// sb.append("/tops/");
// }else if(absolutePath.contains("outer")) {
// sysFile.setLevel2Type("Outwear");
// sb.append("/outwear/");
// }
// sb.append(fileName);
// String url = sb.toString();
// sysFile.setUrl(url);
// sysFile.setMd5(MD5Utils.encryptFile(new FileInputStream(pngFile)));
//// boolean b = minioUtil.doesObjectExist("aida-sys-image", uploadMinioPath);
//// if (!b) {
//// FileItem a = getMultipartFile(file, file.getName());
//// MultipartFile multipartFile = new CommonsMultipartFile(a);
//// minioUtil.upload(bucketName, uploadMinioPath, multipartFile, "");
//// }
// FileItem a = getMultipartFile(pngFile, fileName);
// MultipartFile multipartFile = new CommonsMultipartFile(a);
// System.out.println(url.substring(0,14));
// System.out.println(url.substring(15));
//// minioUtil.upload(url.substring(0,14), url.substring(15), multipartFile, "");
// sysFile.setCreateDate(new Date());
// }
@Override
public Workspace getCurrentWorkspace() {
AuthPrincipalVo authPrincipalVo = UserContext.getUserHolder();
QueryWrapper<Workspace> qw = new QueryWrapper<>();
qw.lambda().eq(Workspace::getAccountId, authPrincipalVo.getId());
qw.lambda().eq(Workspace::getIsLastIndex, 1);
// qw.lambda().eq(Workspace::getIsDeleted, 0);
List<Workspace> workspaces = workspaceMapper.selectList(qw);
if (CollectionUtils.isEmpty(workspaces)) {
throw new BusinessException("workspace not found.");
}
return workspaces.get(0);
}
@Override
public List<StyleVO> styleList() {
AuthPrincipalVo authPrincipalVo = UserContext.getUserHolder();
QueryWrapper<Style> qw = new QueryWrapper<>();
List<Style> styles = styleMapper.selectList(qw);
List<StyleVO> styleVOS = CopyUtil.copyList(styles, StyleVO.class);
for (StyleVO styleVO : styleVOS) {
StyleEnum styleEnum = StyleEnum.fromName(styleVO.getName());
if (authPrincipalVo.getLanguage().equals(Language.ENGLISH.name())) {
styleVO.setValue(styleEnum.getEnglish());
}else {
styleVO.setValue(styleEnum.getChinese());
}
}
return styleVOS;
}
public static List<File> getPNGFiles(String directoryPath) {
List<File> pngFiles = new ArrayList<>();