|
|
@@ -1,29 +1,42 @@
|
|
|
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.model.dto.*;
|
|
|
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.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;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.SearchResult;
|
|
|
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;
|
|
|
|
|
|
-/**
|
|
|
+/** server/镜像服务/mj绘画
|
|
|
* @author zwhui
|
|
|
* @date 2024/4/23 10:31
|
|
|
*/
|
|
|
@@ -43,6 +56,14 @@ public class MidjourneyController {
|
|
|
|
|
|
private final RedisService redisService;
|
|
|
|
|
|
+ private final GroupsRelationMapper groupsRelationMapper;
|
|
|
+
|
|
|
+ private final UserBindRelationService userBindRelationService;
|
|
|
+
|
|
|
+ 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);
|
|
|
@@ -338,4 +359,86 @@ public class MidjourneyController {
|
|
|
redisService.del(RedisService.key.MIDJOURNEY_USER.getName() + midjourneyUser.getUserToken());
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * mj绘画广场 我的收藏
|
|
|
+ */
|
|
|
+ @GetMapping("/get/painting")
|
|
|
+ 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) {
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ record.setStatus(!record.getStatus());
|
|
|
+ midjourneyPaintingCollectRecordMapper.updateById(record);
|
|
|
+ }
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 复制mj绘画广场 提示词
|
|
|
+ */
|
|
|
+ @PostMapping("/painting/copy/{id}")
|
|
|
+ public Result<String> resetPaintingCopyNum(@PathVariable Long id) {
|
|
|
+ MidjourneyPaintingPlaza midjourneyPaintingPlaza = midjourneyPaintingPlazaMapper.selectById(id);
|
|
|
+ if (midjourneyPaintingPlaza != null) {
|
|
|
+ midjourneyPaintingPlazaMapper.updatePaintingCopyNum(id);
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
}
|