Bladeren bron

Claude session列表新增

zoujiajian 1 jaar geleden
bovenliggende
commit
0ad74a87cd

+ 5 - 3
netflix-dao/src/main/java/com/cyksj/model/entity/ClaudeSession.java

@@ -23,13 +23,15 @@ public class ClaudeSession extends BaseEntity {
 
     private String password;
 
-    private Boolean status;
+    private Integer status;
 
-    private Boolean isPlus;
+    @DbField("isPlus")
+    @TableField("isPlus")
+    private Integer isPlus;
 
     @DbField("carID")
     @TableField("carID")
-    private String carID;
+    private String carId;
 
     @DbField("officialSession")
     @TableField("officialSession")

+ 81 - 0
netflix-dao/src/main/java/com/cyksj/model/views/ClaudeCarSessionView.java

@@ -0,0 +1,81 @@
+package com.cyksj.model.views;
+
+import com.ejlchina.searcher.bean.DbField;
+import com.ejlchina.searcher.bean.SearchBean;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: ClaudeCarSessionView
+ * 创建者: JavaZou
+ * 创建时间:2025/3/20 11:03
+ */
+@Getter
+@Setter
+@SearchBean(tables = "claude_session cs")
+public class ClaudeCarSessionView {
+
+	@DbField("cs.id")
+	private Long id;
+
+	/**
+	 * 账号
+	 */
+	@DbField("cs.email")
+	private String email;
+
+	@DbField("cs.password")
+	private String password;
+
+	@DbField("cs.carID")
+	private String carId;
+
+
+	/**
+	 * 状态 1有效 1无效
+	 */
+	@DbField("cs.status")
+	private Integer status;
+
+	/**
+	 * 是否为plus会员
+	 */
+	@DbField("isPlus")
+	private Integer isPlus;
+
+	/**
+	 * 车名称
+	 */
+	@DbField("cs.car_name")
+	private String carName;
+
+	/**
+	 * 官方session
+	 */
+	@DbField("cs.officialSession")
+	private String officialSession;
+
+	/**
+	 * 分数
+	 */
+	@DbField("cs.score")
+	private Double score;
+
+	/**
+	 * 备注
+	 */
+	@DbField("cs.remark")
+	private String remark;
+
+	/**
+	 * 排序
+	 */
+	@DbField("cs.sort")
+	private Long sort;
+
+	@DbField("cs.created_time")
+	private Date createdTime;
+}

+ 0 - 10
netflix-service/src/main/java/com/cyksj/service/advertisement/impl/AdvertisementUserServiceImpl.java

@@ -3,29 +3,19 @@ package com.cyksj.service.advertisement.impl;
 import cn.hutool.core.bean.BeanUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.cyksj.common.exception.BusinessRuntimeException;
-import com.cyksj.common.util.StreamUtil;
-import com.cyksj.mapper.advertisement.AdvertisementProjectMapper;
 import com.cyksj.mapper.advertisement.AdvertisementUserMapper;
 import com.cyksj.model.dto.MiniProgramSession;
 import com.cyksj.model.dto.UserWhoami;
-import com.cyksj.model.entity.AdvertisementProject;
 import com.cyksj.model.entity.AdvertisementUser;
-import com.cyksj.model.entity.WxApp;
-import com.cyksj.service.advertisement.AdvertisementProjectService;
 import com.cyksj.service.advertisement.AdvertisementUserService;
 import com.cyksj.service.wechat.WeChatService;
 import lombok.RequiredArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
-import org.checkerframework.checker.units.qual.A;
 import org.springframework.stereotype.Service;
 import org.springframework.util.Assert;
 
-import java.math.BigDecimal;
-import java.util.List;
 import java.util.Optional;
 
 /**

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/claude/ClaudeSessionService.java

@@ -8,5 +8,5 @@ import com.cyksj.model.entity.ClaudeSession;
  * @date 2024/8/9 10:46
  */
 public interface ClaudeSessionService extends IService<ClaudeSession>  {
-    void getSession(String email, String password, String officialSession, Boolean isPlus);
+    Integer getSession(String email, String password, String officialSession, Integer isPlus);
 }

+ 12 - 10
netflix-service/src/main/java/com/cyksj/service/claude/impl/ClaudeSessionServiceImpl.java

@@ -24,16 +24,16 @@ import org.springframework.stereotype.Service;
 public class ClaudeSessionServiceImpl extends ServiceImpl<ClaudeSessionMapper, ClaudeSession> implements ClaudeSessionService {
 
 
-    private static final String MIRROR_CLAUDE_DOMAIN = "https://claudeplus.com.cn";
+    private static final String MIRROR_CLAUDE_DOMAIN = "https://kelaode.nf.video";
 
     @Override
-    public void getSession(String email, String password, String officialSession, Boolean isPlus) {
+    public Integer getSession(String email, String password, String officialSession, Integer isPlus) {
         ClaudeSession one = this.getOne(Wrappers.lambdaQuery(ClaudeSession.class).orderByDesc(ClaudeSession::getId).last(" limit 1"));
         if (isPlus == null) {
-            isPlus = true;
+            isPlus = 1;
         }
         try {
-            JSONObject loginResult = getLoginResult(email, password, officialSession, isPlus ? "Claude-PRO-" + one.getId() + 1 : "Claude-" + one.getId() + 1);
+            JSONObject loginResult = getLoginResult(email, password, officialSession, "Claude" + one.getId() + 1);
 
             //{
             //    "code": 1000,
@@ -46,6 +46,8 @@ public class ClaudeSessionServiceImpl extends ServiceImpl<ClaudeSessionMapper, C
             if (!loginResult.getInt("code").equals(1000)) {
                 log.error("新增claude 镜像账号异常,res:{}", loginResult);
             }
+            JSONObject data = loginResult.getJSONObject("data");
+            return data.getInt("id");
         } catch (Exception e) {
             throw BusinessRuntimeException.getInstance("登录获取token错误 error:" + e.getMessage());
         }
@@ -55,12 +57,12 @@ public class ClaudeSessionServiceImpl extends ServiceImpl<ClaudeSessionMapper, C
      * 获取登录结果
      */
     private JSONObject getLoginResult(String email, String password, String officialSession, String carId) throws Exception {
-        HttpRequest request = new HttpRequest(MIRROR_CLAUDE_DOMAIN + "/adminapi/chatgpt/session/add");
-        request.form("email", email);
-        request.form("password", password);
-        request.form("officialSession", officialSession);
-        request.form("carID", carId);
-        HttpResponse execute = request.method(Method.POST).execute();
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.putOpt("carID", carId);
+        jsonObject.putOpt("email", email);
+        jsonObject.putOpt("password", password);
+        jsonObject.putOpt("officialSession", officialSession);
+        HttpResponse execute = new HttpRequest(MIRROR_CLAUDE_DOMAIN + "/adminapi/chatgpt/session/add").method(Method.POST).header("apiauth", "chan").body(jsonObject.toString()).execute();
         return new JSONObject(execute.body());
     }
 

+ 21 - 10
netflix-web/src/main/java/com/cyksj/web/controller/manage/mirror/CmsClaudeController.java

@@ -7,7 +7,7 @@ import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.dto.Result;
 import com.cyksj.enums.GatewayResponse;
 import com.cyksj.model.entity.ClaudeSession;
-import com.cyksj.model.views.ChatgptCarSessionView;
+import com.cyksj.model.views.ClaudeCarSessionView;
 import com.cyksj.redis.RedisService;
 import com.cyksj.service.claude.ClaudeSessionService;
 import com.ejlchina.searcher.BeanSearcher;
@@ -42,9 +42,9 @@ public class CmsClaudeController {
      * 获取镜像车队账号列表
      */
     @GetMapping("/get")
-    public Result<SearchResult<ChatgptCarSessionView>> getMirrorCarSession() {
-        SearchResult<ChatgptCarSessionView> search = beanSearcher.search(ChatgptCarSessionView.class, MapUtils.flatBuilder(request.getParameterMap())
-                .orderBy(ChatgptCarSessionView::getId).desc()
+    public Result<SearchResult<ClaudeCarSessionView>> getMirrorCarSession() {
+        SearchResult<ClaudeCarSessionView> search = beanSearcher.search(ClaudeCarSessionView.class, MapUtils.flatBuilder(request.getParameterMap())
+                .orderBy(ClaudeCarSessionView::getId).desc()
                 .build());
         return GatewayResponse.SUCCESS.newBuilder().toResult(search);
     }
@@ -56,16 +56,24 @@ public class CmsClaudeController {
     public Result<String> updateMirrorCarSession(@RequestBody ClaudeSession claudeSession) {
         Long id = claudeSession.getId();
         ClaudeSession dbChatSession = claudeSessionService.getById(id);
+        Integer sessionId = null;
+        Boolean isUpdateSession = false;
         if (!ObjectUtil.equal(dbChatSession.getEmail(), claudeSession.getEmail()) || !ObjectUtil.equal(dbChatSession.getPassword(), claudeSession.getPassword())) {
-            claudeSessionService.getSession(dbChatSession.getEmail(), dbChatSession.getPassword(), claudeSession.getOfficialSession(), claudeSession.getIsPlus());
+            sessionId = claudeSessionService.getSession(dbChatSession.getEmail(), dbChatSession.getPassword(), claudeSession.getOfficialSession(), claudeSession.getIsPlus());
+            isUpdateSession = true;
         }
         Integer selectCount = claudeSessionService.getBaseMapper().selectCount(Wrappers.lambdaQuery(ClaudeSession.class)
                 .and(e -> e.eq(ClaudeSession::getEmail, claudeSession.getEmail())
-                        .or().eq(ClaudeSession::getCarID, claudeSession.getCarID()))
+                        .or().eq(ClaudeSession::getCarId, claudeSession.getCarId()))
                 .ne(ClaudeSession::getId, claudeSession.getId()));
         if (selectCount > 0) {
             throw BusinessRuntimeException.getInstance("请检验车队ID或账号是否已存在");
         }
+        if (isUpdateSession) {
+            if (sessionId != null) {
+                claudeSession.setStatus(1);
+            } else claudeSession.setStatus(0);
+        }
         claudeSessionService.updateById(claudeSession);
         return GatewayResponse.SUCCESS.newBuilder().toResult();
     }
@@ -77,7 +85,7 @@ public class CmsClaudeController {
     public Result<String> deleteMirrorCarSession(@PathVariable Long id) {
         Optional.ofNullable(claudeSessionService.getById(id))
                 .ifPresent(e -> {
-                    String carId = e.getCarID();
+                    String carId = e.getCarId();
                     if (StrUtil.isNotBlank(carId)) {
                         claudeSessionService.removeById(e.getId());
                         String highCarChatKey = RedisService.key.CLAUDE_CAR_CHAT.getName() + carId;
@@ -93,12 +101,15 @@ public class CmsClaudeController {
     @PostMapping("/post/mirror/car/session")
     public Result<String> postMirrorCarSession(@RequestBody ClaudeSession claudeSession) {
         Integer selectCount = claudeSessionService.getBaseMapper().selectCount(Wrappers.lambdaQuery(ClaudeSession.class)
-                .eq(ClaudeSession::getCarID, claudeSession.getCarID()).or().eq(ClaudeSession::getEmail, claudeSession.getEmail()));
+                .eq(ClaudeSession::getCarId, claudeSession.getCarId()).or().eq(ClaudeSession::getEmail, claudeSession.getEmail()));
         if (selectCount > 0) {
             throw BusinessRuntimeException.getInstance("请检验车队ID或账号是否已存在");
         }
-       claudeSessionService.getSession(claudeSession.getEmail(), claudeSession.getPassword(), claudeSession.getOfficialSession(),claudeSession.getIsPlus());
-
+        Integer sessionId = claudeSessionService.getSession(claudeSession.getEmail(), claudeSession.getPassword(), claudeSession.getOfficialSession(), claudeSession.getIsPlus());
+        if (sessionId != null) {
+            claudeSession.setStatus(1);
+        } else claudeSession.setStatus(0);
+        claudeSessionService.save(claudeSession);
         return GatewayResponse.SUCCESS.newBuilder().toResult();
     }