|
|
@@ -1,19 +1,24 @@
|
|
|
package com.cyksj.web.controller.mirror;
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
import com.cyksj.mapper.GroupsRelationMapper;
|
|
|
+import com.cyksj.mapper.MidjourneyPaintingCollectRecordMapper;
|
|
|
import com.cyksj.mapper.MidjourneyPaintingPlazaMapper;
|
|
|
import com.cyksj.mapper.MidjourneyUserMapper;
|
|
|
import com.cyksj.model.dto.*;
|
|
|
-import com.cyksj.model.entity.GroupsRelation;
|
|
|
+import com.cyksj.model.entity.MidjourneyPaintingCollectRecord;
|
|
|
import com.cyksj.model.entity.MidjourneyPaintingPlaza;
|
|
|
import com.cyksj.model.entity.MidjourneyUser;
|
|
|
import com.cyksj.model.entity.MidjourneyUserConversation;
|
|
|
import com.cyksj.model.views.MidjourneyPaintingUserView;
|
|
|
+import com.cyksj.model.views.MidjourneyUserPaintingDayRecordView;
|
|
|
+import com.cyksj.model.views.MidjourneyUserPaintingRecordView;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.midjourney.MidjourneyService;
|
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
|
@@ -23,11 +28,13 @@ import com.ejlchina.searcher.util.MapBuilder;
|
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
/**
|
|
|
* @author zwhui
|
|
|
@@ -55,6 +62,8 @@ public class MidjourneyController {
|
|
|
|
|
|
private final MidjourneyPaintingPlazaMapper midjourneyPaintingPlazaMapper;
|
|
|
|
|
|
+ private final MidjourneyPaintingCollectRecordMapper midjourneyPaintingCollectRecordMapper;
|
|
|
+
|
|
|
public MidjourneyUser getUser(){
|
|
|
String userToken = request.getHeader("user-token");
|
|
|
MidjourneyUser midjourneyUser = (MidjourneyUser) redisService.get(RedisService.key.MIDJOURNEY_USER.getName() + userToken);
|
|
|
@@ -352,30 +361,49 @@ public class MidjourneyController {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* mj绘画广场 我的收藏
|
|
|
*/
|
|
|
@GetMapping("/get/painting")
|
|
|
- public Result<SearchResult<MidjourneyPaintingUserView>> getPaintingCollect(Boolean isCollect) {
|
|
|
- MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
|
|
|
- if (isCollect != null && isCollect) {
|
|
|
- MidjourneyUser user = getUser();
|
|
|
- GroupsRelation relation = groupsRelationMapper.selectById(user.getRelationId());
|
|
|
- if (relation == null) {
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ public Result<Page<MidjourneyPaintingUserView>> getPaintingCollect(@RequestParam(defaultValue = "1") Integer start, @RequestParam(defaultValue = "10") Integer limit, Boolean collect) {
|
|
|
+ if (limit > 20) {
|
|
|
+ limit = 20;
|
|
|
+ }
|
|
|
+ MidjourneyUser user = getUser();
|
|
|
+ Page<MidjourneyPaintingUserView> page = midjourneyPaintingPlazaMapper.getPaintingList(new Page<>(start, limit), collect, user.getId());
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改 mj绘画广场 收藏状态
|
|
|
+ */
|
|
|
+ @PutMapping("/collect/painting/{id}")
|
|
|
+ public Result<SearchResult<MidjourneyPaintingUserView>> collectPainting(@PathVariable Long id) {
|
|
|
+ MidjourneyUser user = getUser();
|
|
|
+ MidjourneyPaintingPlaza midjourneyPaintingPlaza = midjourneyPaintingPlazaMapper.selectById(id);
|
|
|
+ if (midjourneyPaintingPlaza == null || !midjourneyPaintingPlaza.getDeleted()) {
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+ MidjourneyPaintingCollectRecord record = Optional.ofNullable(midjourneyPaintingCollectRecordMapper.selectOne(Wrappers.lambdaQuery(MidjourneyPaintingCollectRecord.class)
|
|
|
+ .eq(MidjourneyPaintingCollectRecord::getPlazaId, id)
|
|
|
+ .eq(MidjourneyPaintingCollectRecord::getUserId, user.getId()).last("limit 1"))).orElse(new MidjourneyPaintingCollectRecord());
|
|
|
+ if (record.getId() == null) {
|
|
|
+ try {
|
|
|
+ record.setStatus(true);
|
|
|
+ record.setUserId(user.getId());
|
|
|
+ record.setPlazaId(id);
|
|
|
+ midjourneyPaintingCollectRecordMapper.insert(record);
|
|
|
+ } catch (DuplicateKeyException e) {
|
|
|
}
|
|
|
- Long userId = relation.getUserId();
|
|
|
- List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
- String pr = String.format(" inner join midjourney_painting_collect_record pr on pr.plaza_id = mpp.id and mpp.user_id in (%s)", userIdList.toString().replaceAll("]", "").replaceAll("\\[", ""));
|
|
|
- builder.put("pr", pr);
|
|
|
+ } else {
|
|
|
+ record.setStatus(!record.getStatus());
|
|
|
+ midjourneyPaintingCollectRecordMapper.updateById(record);
|
|
|
}
|
|
|
- SearchResult<MidjourneyPaintingUserView> search = beanSearcher.search(MidjourneyPaintingUserView.class, builder.build());
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 复制mj绘画
|
|
|
+ * 复制mj绘画广场 提示词
|
|
|
*/
|
|
|
@PostMapping("/painting/copy/{id}")
|
|
|
public Result<String> resetPaintingCopyNum(@PathVariable Long id) {
|
|
|
@@ -385,4 +413,32 @@ public class MidjourneyController {
|
|
|
}
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户绘画记录
|
|
|
+ */
|
|
|
+ @GetMapping("/get/painting/record")
|
|
|
+ public Result<SearchResult<MidjourneyUserPaintingDayRecordView>> getPaintingRecord(String prompt) {
|
|
|
+ MidjourneyUser user = getUser();
|
|
|
+ String condition = String.format(" and mc.user_id = %s", user.getId());
|
|
|
+ if (StrUtil.isNotBlank(prompt)) {
|
|
|
+ condition += String.format(" and mc.prompt = '%s'", prompt);
|
|
|
+ }
|
|
|
+ SearchResult<MidjourneyUserPaintingDayRecordView> search = beanSearcher.search(MidjourneyUserPaintingDayRecordView.class, MapUtils.flatBuilder(request.getParameterMap())
|
|
|
+ .put("condition", condition)
|
|
|
+ .orderBy(MidjourneyUserPaintingRecordView::getCreatedTime).desc()
|
|
|
+ .build());
|
|
|
+ String dateSql;
|
|
|
+ for (MidjourneyUserPaintingDayRecordView e : search.getDataList()) {
|
|
|
+ String date = e.getDate();
|
|
|
+ dateSql = String.format(" and DATE_FORMAT(mc.created_time,'%%Y-%%m-%%d') = '%s'", date);
|
|
|
+ List<MidjourneyUserPaintingRecordView> list = beanSearcher.searchAll(MidjourneyUserPaintingRecordView.class, MapUtils.builder()
|
|
|
+ .put("condition", condition)
|
|
|
+ .put("date", dateSql)
|
|
|
+ .orderBy(MidjourneyUserPaintingRecordView::getCreatedTime).desc()
|
|
|
+ .build());
|
|
|
+ e.setList(list);
|
|
|
+ }
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
+ }
|
|
|
}
|