Merge branch 'dev/dev_xp' into dev/dev
# Conflicts: # src/main/java/com/ai/da/service/CollectionElementService.java # src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java
This commit is contained in:
@@ -494,6 +494,7 @@ public class RedisUtil {
|
||||
return maxLikeCount != null ? Integer.parseInt(maxLikeCount) : 0;
|
||||
}
|
||||
|
||||
public final static String IMAGE_SEGMENTATION = "ImageSegmentation:";
|
||||
|
||||
public final static String STRIPE_EXCEPTION_LOG = "StripeException:";
|
||||
|
||||
|
||||
@@ -7,9 +7,7 @@ import com.ai.da.common.response.Response;
|
||||
import com.ai.da.mapper.primary.DesignMapper;
|
||||
import com.ai.da.mapper.primary.entity.Account;
|
||||
import com.ai.da.mapper.primary.entity.TrialOrder;
|
||||
import com.ai.da.model.dto.AccountAddDTO;
|
||||
import com.ai.da.model.dto.QueryPaymentInfoDTO;
|
||||
import com.ai.da.model.dto.UserDesignStatisticDTO;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.PaymentInfoVO;
|
||||
import com.ai.da.model.vo.QuestionnaireFeedbackVO;
|
||||
import com.ai.da.model.vo.QuestionnaireVO;
|
||||
@@ -17,7 +15,6 @@ import com.ai.da.model.vo.QueryUserConditionsVO;
|
||||
import com.ai.da.service.AccountService;
|
||||
import com.ai.da.service.ConvenientInquiryService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
@@ -63,26 +60,7 @@ public class ConvenientInquiryController {
|
||||
@GetMapping("/getDesignStatistic")
|
||||
public Response<List<UserDesignStatisticDTO>> getDesignStatistic(@RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime,
|
||||
@RequestParam(required = false) List<Long> ids, @RequestParam(required = false) String email) {
|
||||
Long accountId = UserContext.getUserHolder().getId();
|
||||
String userEmail = accountService.getById(accountId).getUserEmail();
|
||||
if (accountId.equals(31L) || accountId.equals(87L) || accountId.equals(83L)
|
||||
|| accountId.equals(6L) || accountId.equals(4L) || accountId.equals(73L)
|
||||
|| userEmail.equals("joho8228@hotmail.com") || userEmail.equals("wanninghua160@gmail.com")
|
||||
) {
|
||||
if (StringUtil.isNullOrEmpty(startTime)) startTime = "2024-02-01 00:00:00";
|
||||
if (StringUtil.isNullOrEmpty(endTime)) {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
||||
Date date = new Date();
|
||||
endTime = simpleDateFormat.format(date);
|
||||
}
|
||||
if (!StringUtil.isNullOrEmpty(email)){
|
||||
email = email.trim();
|
||||
}
|
||||
List<UserDesignStatisticDTO> designStatistic = designMapper.getDesignStatistic(startTime, endTime, ids, email);
|
||||
return Response.success(designStatistic);
|
||||
} else {
|
||||
return Response.fail("Sorry, you don't have permission");
|
||||
}
|
||||
return Response.success(convenientInquiryService.getDesignStatistic(startTime, endTime, ids, email));
|
||||
}
|
||||
|
||||
|
||||
@@ -215,4 +193,10 @@ public class ConvenientInquiryController {
|
||||
public Response<String> exportTransactionRecords(@Valid @RequestBody QueryPaymentInfoDTO queryPaymentInfoDTO, HttpServletResponse response){
|
||||
return Response.success(convenientInquiryService.exportTransactionRecords(queryPaymentInfoDTO, response));
|
||||
}
|
||||
|
||||
@ApiOperation("获取生成功能使用频次")
|
||||
@PostMapping("/getGenerateFrequency")
|
||||
public Response<PageBaseResponse<AccountCreditsUsageDTO>> getGenerateFrequency(@Valid @RequestBody AccountCreditsUsageQueryDTO queryDTO){
|
||||
return Response.success(convenientInquiryService.getGenerateFrequency(queryDTO));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,10 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Api(tags = "collection模块")
|
||||
@@ -106,4 +109,25 @@ public class ElementController {
|
||||
return Response.success();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "图片分割")
|
||||
@PostMapping("/imageSegmentation")
|
||||
public Response<List<CollectionElementVO>> selectedImageSeg(
|
||||
@RequestPart(value = "files", required = false) MultipartFile[] files,
|
||||
@RequestParam(value = "type", required = false) @Pattern(regexp = "sketch|product", message = "类型必须是sketch或product") String type,
|
||||
@RequestParam(value = "id", required = false) Long id) {
|
||||
// 过滤空文件
|
||||
List<MultipartFile> nonEmptyFiles = Arrays.stream(files)
|
||||
.filter(file -> !file.isEmpty())
|
||||
.collect(Collectors.toList());
|
||||
// 参数校验
|
||||
if ((nonEmptyFiles.isEmpty()) && id == null) {
|
||||
throw new BusinessException("必须提供文件上传或ID");
|
||||
}
|
||||
if (!nonEmptyFiles.isEmpty() && id != null) {
|
||||
throw new BusinessException("不能同时提供文件上传和ID");
|
||||
}
|
||||
|
||||
return Response.success(collectionElementService.selectedImageSeg(nonEmptyFiles, id, type));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.ai.da.mapper.primary;
|
||||
|
||||
import com.ai.da.common.config.mybatis.plus.CommonMapper;
|
||||
import com.ai.da.mapper.primary.entity.Account;
|
||||
import com.ai.da.model.dto.AccountCreditsUsageDTO;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -32,4 +32,8 @@ public interface AccountMapper extends CommonMapper<Account> {
|
||||
|
||||
void toVisitor(Long id);
|
||||
|
||||
List<AccountCreditsUsageDTO> selectCreditUsage(boolean groupByEvent, String changeEvent, String role, String userEmail, Long id, String startTime, String endTime, Integer size, Integer offset);
|
||||
|
||||
int countCreditUsage(boolean groupByEvent, String changeEvent, String role, String userEmail, Long id, String startTime, String endTime);
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public interface DesignMapper extends CommonMapper<Design> {
|
||||
//返回插入数据后生成的主键
|
||||
Long insertDesign(Design design);
|
||||
|
||||
List<UserDesignStatisticDTO> getDesignStatistic(String startTime, String endTime, List<Long> ids, String email);
|
||||
List<UserDesignStatisticDTO> getDesignStatistic(String startTime, String endTime, List<Long> ids, String email, String role);
|
||||
|
||||
List<Design> selectDeleteList();
|
||||
}
|
||||
|
||||
@@ -69,6 +69,8 @@ public class Library implements Serializable {
|
||||
*/
|
||||
private Integer width;
|
||||
|
||||
private String segmentedData;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
|
||||
@@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@ApiModel("element-响应")
|
||||
public class CollectionElementVO {
|
||||
@@ -42,4 +44,6 @@ public class CollectionElementVO {
|
||||
|
||||
private String originalUrl;
|
||||
|
||||
private List<String> segmentedImages;
|
||||
|
||||
}
|
||||
|
||||
@@ -21,10 +21,7 @@ import com.ai.da.python.vo.*;
|
||||
import com.ai.da.service.DesignHistoryService;
|
||||
import com.ai.da.service.PythonTAllInfoService;
|
||||
import com.ai.da.service.SysFileService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONException;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.*;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -4199,4 +4196,58 @@ public class PythonService {
|
||||
//生成失败
|
||||
throw new BusinessException("brandDNAGenerate.interface.exception");
|
||||
}
|
||||
|
||||
public List<ImageSegmentation.ImageDate> imageSegmentation(ImageSegmentation imageSegmentation) {
|
||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
|
||||
.readTimeout(60, TimeUnit.SECONDS)//读取超时(单位:秒)
|
||||
.writeTimeout(60, TimeUnit.SECONDS)//写入超时(单位:秒)
|
||||
.build();
|
||||
|
||||
MediaType mediaType = MediaType.parse("application/json");
|
||||
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(imageSegmentation));
|
||||
|
||||
log.info("modifyModelProportion 请求地址: {},\n 参数:{}", accessPythonIp + ":" + accessPythonPort + "/api/clothing_seg", JSON.toJSONString(imageSegmentation));
|
||||
Request request = new Request.Builder()
|
||||
.url(accessPythonIp + ":" + accessPythonPort + "/api/clothing_seg")
|
||||
.method("POST", body)
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.build();
|
||||
Response response = null;
|
||||
try {
|
||||
response = client.newCall(request).execute();
|
||||
} catch (IOException ioException) {
|
||||
log.error("PythonService##imageSegmentation异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||
throw new BusinessException("generate.interface.error");
|
||||
}
|
||||
int responseCode = response.code();
|
||||
String bodyString;
|
||||
try {
|
||||
bodyString = response.body().string();
|
||||
if (responseCode != HttpURLConnection.HTTP_OK) {
|
||||
// 基本不会有除200以外的code
|
||||
log.info("imageSegmentation 失败。 Response code {}", responseCode);
|
||||
throw new BusinessException("imageSegmentation 失败。 Response code " + responseCode);
|
||||
}
|
||||
JSONObject jsonObject = JSON.parseObject(bodyString);
|
||||
if (response.isSuccessful() && jsonObject.get("msg").equals("OK!")) {
|
||||
log.info("imageSegmentation 结果 : {}", jsonObject.get("data").toString());
|
||||
List<ImageSegmentation.ImageDate> seg = JSONObject.parseObject(
|
||||
jsonObject.get("data").toString(),
|
||||
new TypeReference<List<ImageSegmentation.ImageDate>>() {}
|
||||
);
|
||||
return seg;
|
||||
}else {
|
||||
log.info("imageSegmentation 失败。 Response code {}", responseCode);
|
||||
throw new BusinessException("imageSegmentation 失败。 Response code " + responseCode);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("imageSegmentation 失败; error message => {}", e.getMessage());
|
||||
response.close();
|
||||
throw new BusinessException("generate.interface.error");
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
20
src/main/java/com/ai/da/python/vo/ImageSegmentation.java
Normal file
20
src/main/java/com/ai/da/python/vo/ImageSegmentation.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.ai.da.python.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ImageSegmentation {
|
||||
|
||||
private Long user_id;
|
||||
private List<ImageDate> image_data;
|
||||
|
||||
@Data
|
||||
public class ImageDate{
|
||||
public String image_url;
|
||||
public String image_type;
|
||||
// 作为入参时一起传入会怎样?
|
||||
public List<String> clothing_url;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.ai.da.mapper.primary.entity.LibraryModelPoint;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.*;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -137,4 +138,7 @@ public interface CollectionElementService extends IService<CollectionElement> {
|
||||
CollectionElement editLevel2Type(Long elementId, String level2Type, String designType);
|
||||
|
||||
List<CollectionElement> getByProjectId(Long projectId);
|
||||
|
||||
List<CollectionElementVO> selectedImageSeg(List<MultipartFile> files, Long id, String type);
|
||||
|
||||
}
|
||||
|
||||
@@ -4,8 +4,7 @@ import com.ai.da.common.response.PageBaseResponse;
|
||||
import com.ai.da.mapper.primary.entity.Account;
|
||||
import com.ai.da.mapper.primary.entity.Questionnaire;
|
||||
import com.ai.da.mapper.primary.entity.TrialOrder;
|
||||
import com.ai.da.model.dto.AccountAddDTO;
|
||||
import com.ai.da.model.dto.QueryPaymentInfoDTO;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.PaymentInfoVO;
|
||||
import com.ai.da.model.vo.QuestionnaireFeedbackVO;
|
||||
import com.ai.da.model.vo.QuestionnaireVO;
|
||||
@@ -21,6 +20,8 @@ public interface ConvenientInquiryService extends IService<Questionnaire> {
|
||||
|
||||
IPage<TrialOrder> getTrial(QueryUserConditionsVO queryUserConditionsVO);
|
||||
|
||||
List<UserDesignStatisticDTO> getDesignStatistic(String startTime, String endTime, List<Long> ids, String email);
|
||||
|
||||
QuestionnaireFeedbackVO getQuestionnaireInfo();
|
||||
|
||||
List<QuestionnaireVO> getAllQuestionnaire();
|
||||
@@ -53,4 +54,6 @@ public interface ConvenientInquiryService extends IService<Questionnaire> {
|
||||
Map<String, List<String>> getCities();
|
||||
|
||||
String exportTransactionRecords(QueryPaymentInfoDTO queryPaymentInfoDTO, HttpServletResponse response);
|
||||
|
||||
PageBaseResponse<AccountCreditsUsageDTO> getGenerateFrequency(AccountCreditsUsageQueryDTO queryDTO);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.ai.da.service.impl;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.ai.da.common.config.FileProperties;
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.common.constant.CommonConstant;
|
||||
import com.ai.da.common.context.UserContext;
|
||||
import com.ai.da.common.enums.*;
|
||||
import com.ai.da.common.response.ResultEnum;
|
||||
@@ -17,13 +18,16 @@ import com.ai.da.model.enums.StyleEnum;
|
||||
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.ImageSegmentation;
|
||||
import com.ai.da.service.*;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
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.collect.Lists;
|
||||
import com.google.gson.Gson;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -33,6 +37,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
@@ -78,6 +83,8 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
||||
private String collectionElement;
|
||||
@Value("${minio.bucketName.gradient}")
|
||||
private String gradientBucketName;
|
||||
@Value("${minio.bucketName.users}")
|
||||
private String userBucketName;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@@ -959,4 +966,95 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
||||
|
||||
return generateDetail;
|
||||
}
|
||||
|
||||
// 对于上传图片或者从library选择的图片进行图片分割
|
||||
public List<CollectionElementVO> selectedImageSeg(List<MultipartFile> files, Long id, String type) {
|
||||
Long accountId = UserContext.getUserHolder().getId();
|
||||
List<CollectionElementVO> resp = new ArrayList<>();
|
||||
List<ImageSegmentation.ImageDate> imageDates = new ArrayList<>();
|
||||
|
||||
boolean isUploadMode = !files.isEmpty();
|
||||
Library library = null;
|
||||
|
||||
// 判断是否是上传的图片
|
||||
if (isUploadMode) {
|
||||
String objectName = accountId + "/ImageSegment/input";
|
||||
for (MultipartFile file : files) {
|
||||
String md5 = MD5Utils.encryptFile(file);
|
||||
String segmentedResult = redisUtil.getFromString(RedisUtil.IMAGE_SEGMENTATION + md5);
|
||||
// 判断上传的图片是否有已分割的数据
|
||||
if (StringUtil.isNullOrEmpty(segmentedResult)) {
|
||||
String path = minioUtil.upload(userBucketName, objectName, file);
|
||||
ImageSegmentation.ImageDate imageDate = new ImageSegmentation().new ImageDate();
|
||||
imageDate.setImage_url(path);
|
||||
imageDate.setImage_type(type);
|
||||
imageDates.add(imageDate);
|
||||
} else {
|
||||
ImageSegmentation.ImageDate imageData = JSONObject.parseObject(segmentedResult, ImageSegmentation.ImageDate.class);
|
||||
resp.add(createCollectionElementVO(accountId, null, null, imageData.getImage_url(), imageData.getClothing_url()));
|
||||
}
|
||||
}
|
||||
} else if (Objects.nonNull(id)) {
|
||||
library = libraryService.getById(id);
|
||||
// 判断从library中选择的图片是否有分割数据
|
||||
if (StringUtil.isNullOrEmpty(library.getSegmentedData())) {
|
||||
ImageSegmentation.ImageDate imageDate = new ImageSegmentation().new ImageDate();
|
||||
imageDate.setImage_url(library.getUrl());
|
||||
imageDate.setImage_type(type);
|
||||
imageDates.add(imageDate);
|
||||
} else {
|
||||
List<String> restoredList = Arrays.asList(library.getSegmentedData().split(","));
|
||||
resp.add(createCollectionElementVO(accountId, id, library.getLevel1Type(), library.getUrl(), restoredList));
|
||||
}
|
||||
}
|
||||
|
||||
// 处理需要分割的图片
|
||||
if (!imageDates.isEmpty()) {
|
||||
// 准备图片分割的参数
|
||||
ImageSegmentation imageSegmentation = new ImageSegmentation();
|
||||
imageSegmentation.setUser_id(accountId);
|
||||
imageSegmentation.setImage_data(imageDates);
|
||||
// 图片分割
|
||||
List<ImageSegmentation.ImageDate> segmented = pythonService.imageSegmentation(imageSegmentation);
|
||||
// 处理图片分割结果
|
||||
for (ImageSegmentation.ImageDate imageData : segmented) {
|
||||
if (isUploadMode) {
|
||||
// 上传的图片需要添加到redis中存一天
|
||||
String key = RedisUtil.IMAGE_SEGMENTATION +
|
||||
MD5Utils.encryptFile
|
||||
(minioUtil.getPreSignedUrl
|
||||
(imageData.getImage_url(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME), false);
|
||||
redisUtil.addToString(key, new Gson().toJson(imageData), CommonConstant.GENERATE_RESULT_EXPIRE_TIME);
|
||||
resp.add(createCollectionElementVO(accountId, null, null, imageData.getImage_url(), imageData.getClothing_url()));
|
||||
} else {
|
||||
// 从library中选择的图片需要更新数据库中对应图片的分割数据
|
||||
String segmentedData = String.join(",", imageData.getClothing_url());
|
||||
library.setSegmentedData(segmentedData);
|
||||
library.setUpdateDate(new Date());
|
||||
libraryService.updateById(library);
|
||||
resp.add(createCollectionElementVO(accountId, id, library.getLevel1Type(), library.getUrl(), imageData.getClothing_url()));
|
||||
}
|
||||
}
|
||||
}
|
||||
return resp;
|
||||
}
|
||||
|
||||
// 准备返回数据
|
||||
private CollectionElementVO createCollectionElementVO(Long accountId, Long id, String level1Type,
|
||||
String imageUrl, List<String> clothingUrls) {
|
||||
CollectionElementVO vo = new CollectionElementVO();
|
||||
vo.setAccountId(accountId);
|
||||
vo.setId(id);
|
||||
vo.setLevel1Type(level1Type);
|
||||
vo.setUrl(minioUtil.getPreSignedUrl(imageUrl, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
vo.setMinIOPath(imageUrl);
|
||||
|
||||
List<String> segUrls = new ArrayList<>();
|
||||
for (String seg : clothingUrls) {
|
||||
segUrls.add(minioUtil.getPreSignedUrl(seg, CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
|
||||
}
|
||||
vo.setSegmentedImages(segUrls);
|
||||
return vo;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,14 +5,14 @@ import com.ai.da.common.constant.CommonConstant;
|
||||
import com.ai.da.common.context.UserContext;
|
||||
import com.ai.da.common.enums.CreditsEventsEnum;
|
||||
import com.ai.da.common.response.PageBaseResponse;
|
||||
import com.ai.da.common.response.ResultEnum;
|
||||
import com.ai.da.common.utils.CopyUtil;
|
||||
import com.ai.da.common.utils.DateUtil;
|
||||
import com.ai.da.mapper.primary.*;
|
||||
import com.ai.da.mapper.primary.entity.Account;
|
||||
import com.ai.da.mapper.primary.entity.Questionnaire;
|
||||
import com.ai.da.mapper.primary.entity.TrialOrder;
|
||||
import com.ai.da.model.dto.AccountAddDTO;
|
||||
import com.ai.da.model.dto.QueryPaymentInfoDTO;
|
||||
import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.enums.Language;
|
||||
import com.ai.da.model.vo.*;
|
||||
import com.ai.da.service.*;
|
||||
@@ -41,6 +41,7 @@ import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
@@ -68,10 +69,15 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
|
||||
private TrialOrderMapper trialOrderMapper;
|
||||
@Resource
|
||||
private PaymentInfoMapper paymentInfoMapper;
|
||||
@Resource
|
||||
private DesignMapper designMapper;
|
||||
|
||||
@Value("${minio.bucketName.users}")
|
||||
private String userBucket;
|
||||
|
||||
private static final List<Long> ADMIN_IDS = Arrays.asList(4L, 6L, 31L, 73L, 83L, 87L);
|
||||
private static final List<Long> ADMIN_IDS_READ_ONLY = Arrays.asList(12592L, 12201L);
|
||||
|
||||
public IPage<TrialOrder> getTrial(QueryUserConditionsVO queryUserConditionsVO) {
|
||||
log.info("getTrial parameter : {},page:{}, size:{}", queryUserConditionsVO, queryUserConditionsVO.getPage(), queryUserConditionsVO.getSize());
|
||||
/* 添加按条件查询试用用户 */
|
||||
@@ -122,6 +128,46 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
|
||||
// List<TrialOrder> trialOrders = trialOrderMapper.selectList(null);
|
||||
}
|
||||
|
||||
public List<UserDesignStatisticDTO> getDesignStatistic(String startTime, String endTime, List<Long> ids,
|
||||
String email) {
|
||||
Long accountId = UserContext.getUserHolder().getId();
|
||||
Account account = accountService.getById(accountId);
|
||||
// 允许查看数据的用户id
|
||||
if (Objects.nonNull(account.getSystemUser())
|
||||
&& (account.getSystemUser().equals(5)
|
||||
|| account.getSystemUser().equals(7)
|
||||
|| ADMIN_IDS.contains(account.getId())
|
||||
|| ADMIN_IDS_READ_ONLY.contains(account.getId())
|
||||
)) {
|
||||
if (StringUtil.isNullOrEmpty(startTime)) startTime = "2024-02-01 00:00:00";
|
||||
if (StringUtil.isNullOrEmpty(endTime)) {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
||||
Date date = new Date();
|
||||
endTime = simpleDateFormat.format(date);
|
||||
}
|
||||
if (!StringUtil.isNullOrEmpty(email)){
|
||||
email = email.trim();
|
||||
}
|
||||
String role;
|
||||
switch (account.getSystemUser()){
|
||||
case 5:
|
||||
role = "corp";
|
||||
break;
|
||||
case 7:
|
||||
role = "edu";
|
||||
break;
|
||||
case 1:
|
||||
role = "prsn";
|
||||
break;
|
||||
default:
|
||||
throw new BusinessException("Sorry, you don't have permission", ResultEnum.PROMPT.getCode());
|
||||
}
|
||||
return designMapper.getDesignStatistic(startTime, endTime, ids, email, role);
|
||||
} else {
|
||||
throw new BusinessException("Sorry, you don't have permission", ResultEnum.PROMPT.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public QuestionnaireFeedbackVO getQuestionnaireInfo() {
|
||||
String title = "AiDA_3.0 Feedback Survey--06/2024";
|
||||
@@ -802,4 +848,61 @@ public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMappe
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询generate使用频次
|
||||
* @param queryDTO
|
||||
* @return
|
||||
*/
|
||||
public PageBaseResponse<AccountCreditsUsageDTO> getGenerateFrequency(AccountCreditsUsageQueryDTO queryDTO){
|
||||
Long accountId = UserContext.getUserHolder().getId();
|
||||
Account account = accountService.getById(accountId);
|
||||
// 允许查看数据的用户id
|
||||
if (Objects.nonNull(account.getSystemUser())
|
||||
&& (account.getSystemUser().equals(5)
|
||||
|| account.getSystemUser().equals(7)
|
||||
|| ADMIN_IDS.contains(account.getId())
|
||||
|| ADMIN_IDS_READ_ONLY.contains(account.getId())
|
||||
)) {
|
||||
boolean groupByEvent = !StringUtil.isNullOrEmpty(queryDTO.getChangeEvent());
|
||||
String role;
|
||||
switch (account.getSystemUser()){
|
||||
case 5:
|
||||
role = "corp";
|
||||
break;
|
||||
case 7:
|
||||
role = "edu";
|
||||
break;
|
||||
case 1:
|
||||
role = "prsn";
|
||||
break;
|
||||
default:
|
||||
throw new BusinessException("Sorry, you don't have permission");
|
||||
}
|
||||
Integer size = queryDTO.getSize();
|
||||
int offset = (queryDTO.getPage() - 1) * size;
|
||||
List<AccountCreditsUsageDTO> creditsUsageDTOS = accountMapper.selectCreditUsage(
|
||||
groupByEvent, queryDTO.getChangeEvent(), role, queryDTO.getUserEmail(), queryDTO.getId(),
|
||||
queryDTO.getStartTime(), queryDTO.getEndTime(), size, offset);
|
||||
if (!creditsUsageDTOS.isEmpty()){
|
||||
int total = accountMapper.countCreditUsage(
|
||||
groupByEvent, queryDTO.getChangeEvent(), role, queryDTO.getUserEmail(), queryDTO.getId(),
|
||||
queryDTO.getStartTime(), queryDTO.getEndTime());
|
||||
// 总页数
|
||||
double totalPage = Math.ceil((double) total / size);
|
||||
// 组装返回参数
|
||||
PageBaseResponse<AccountCreditsUsageDTO> response = new PageBaseResponse<>();
|
||||
response.setContent(creditsUsageDTOS);
|
||||
response.setPage(queryDTO.getPage());
|
||||
response.setSize(size);
|
||||
response.setTotal(total);
|
||||
response.setPages((long) totalPage);
|
||||
return response;
|
||||
}else {
|
||||
return new PageBaseResponse<>();
|
||||
}
|
||||
}else {
|
||||
throw new BusinessException("Sorry, you don't have permission");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,5 +29,106 @@
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<!-- 查询用户积分使用情况,可灵活按事件类型查询或查询全部 -->
|
||||
<select id="selectCreditUsage" resultType="com.ai.da.model.dto.AccountCreditsUsageDTO">
|
||||
SELECT
|
||||
a.id id,
|
||||
a.user_email,
|
||||
a.credits currentCredits,
|
||||
<if test="groupByEvent">
|
||||
cd.change_event generateFunction,
|
||||
</if>
|
||||
cd.total_changed_credits consumedCredits,
|
||||
cd.count_account_id usageCount
|
||||
FROM
|
||||
t_account a
|
||||
LEFT JOIN
|
||||
(SELECT
|
||||
account_id,
|
||||
<if test="groupByEvent">
|
||||
change_event,
|
||||
</if>
|
||||
SUM(changed_credits) AS total_changed_credits,
|
||||
COUNT(account_id) AS count_account_id
|
||||
FROM
|
||||
t_credits_detail
|
||||
WHERE
|
||||
changed_credits <= 0
|
||||
<if test="changeEvent != null and changeEvent != ''">
|
||||
AND change_event = #{changeEvent}
|
||||
</if>
|
||||
<!-- 添加时间区间查询条件 -->
|
||||
<if test="startTime != null and startTime != ''">
|
||||
AND cd.create_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null and endTime != ''">
|
||||
AND cd.create_time <= #{endTime}
|
||||
</if>
|
||||
GROUP BY
|
||||
account_id
|
||||
<if test="groupByEvent">
|
||||
, change_event
|
||||
</if>
|
||||
) cd
|
||||
ON
|
||||
a.id = cd.account_id
|
||||
WHERE
|
||||
<choose>
|
||||
<when test="role == 'corp'">
|
||||
a.system_user IN (5, 6)
|
||||
</when>
|
||||
<when test="role == 'edu'">
|
||||
a.system_user IN (7, 8)
|
||||
</when>
|
||||
<when test="role == 'prsn'">
|
||||
a.system_user IN (0, 1, 2, 3, 4)
|
||||
</when>
|
||||
</choose>
|
||||
<if test="id != null">
|
||||
AND a.id = #{id}
|
||||
</if>
|
||||
<if test="userEmail != null and userEmail != ''">
|
||||
AND a.user_email = #{userEmail}
|
||||
</if>
|
||||
<!-- 添加分页查询 -->
|
||||
ORDER BY a.id
|
||||
<if test="size != null and offset != null">
|
||||
LIMIT #{size} OFFSET #{offset}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 查询总记录数 (优化版) -->
|
||||
<select id="countCreditUsage" resultType="int">
|
||||
SELECT COUNT(1)
|
||||
FROM t_account a
|
||||
<if test="changeEvent != null or startTime != null or endTime != null">
|
||||
LEFT JOIN t_credits_detail cd ON a.id = cd.account_id
|
||||
AND cd.changed_credits <= 0
|
||||
<if test="changeEvent != null and changeEvent != ''">
|
||||
AND cd.change_event = #{changeEvent}
|
||||
</if>
|
||||
<if test="startTime != null and startTime != ''">
|
||||
AND cd.create_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null and endTime != ''">
|
||||
AND cd.create_time <= #{endTime}
|
||||
</if>
|
||||
</if>
|
||||
WHERE
|
||||
<choose>
|
||||
<when test="role == 'corp'">
|
||||
a.system_user IN (5, 6)
|
||||
</when>
|
||||
<when test="role == 'edu'">
|
||||
a.system_user IN (7, 8)
|
||||
</when>
|
||||
<when test="role == 'prsn'">
|
||||
a.system_user IN (0, 1, 2, 3, 4)
|
||||
</when>
|
||||
</choose>
|
||||
<if test="userEmail != null and userEmail != ''">
|
||||
AND a.user_email = #{userEmail}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -34,8 +34,19 @@
|
||||
from t_account a
|
||||
left join t_design b on a.id = b.account_id
|
||||
<where>
|
||||
<choose>
|
||||
<when test="role == 'corp'">
|
||||
a.system_user IN (5, 6)
|
||||
</when>
|
||||
<when test="role == 'edu'">
|
||||
a.system_user IN (7, 8)
|
||||
</when>
|
||||
<when test="role == 'prsn'">
|
||||
a.system_user IN (0, 1, 2, 3, 4)
|
||||
</when>
|
||||
</choose>
|
||||
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
|
||||
b.create_date between #{startTime} and #{endTime}
|
||||
AND b.create_date between #{startTime} and #{endTime}
|
||||
</if>
|
||||
</where>
|
||||
and b.create_date not like '%:01'
|
||||
@@ -52,17 +63,6 @@
|
||||
GROUP BY b.account_id
|
||||
ORDER BY b.account_id asc) d
|
||||
left join trial_order c on d.user_email = c.email
|
||||
<!--select a.account_id,count(a.account_id) use_design_times,b.user_email,b.user_name,b.is_trial
|
||||
from `t_account` b
|
||||
left join t_design a
|
||||
on a.account_id = b.id
|
||||
<where>
|
||||
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
|
||||
a.create_date between #{startTime} and #{endTime}
|
||||
</if>
|
||||
</where>
|
||||
GROUP BY a.account_id
|
||||
ORDER BY a.account_id ASC;-->
|
||||
</select>
|
||||
|
||||
<select id="selectDeleteList" resultType="com.ai.da.mapper.primary.entity.Design">
|
||||
|
||||
Reference in New Issue
Block a user