正在显示
15 个修改的文件
包含
205 行增加
和
34 行删除
| @@ -26,8 +26,6 @@ import com.zhonglai.luhui.openai.utils.OpenAiUtils; | @@ -26,8 +26,6 @@ import com.zhonglai.luhui.openai.utils.OpenAiUtils; | ||
| 26 | import com.zhonglai.luhui.openai.utils.SysConfigKeyType; | 26 | import com.zhonglai.luhui.openai.utils.SysConfigKeyType; |
| 27 | import io.swagger.annotations.Api; | 27 | import io.swagger.annotations.Api; |
| 28 | import io.swagger.annotations.ApiOperation; | 28 | import io.swagger.annotations.ApiOperation; |
| 29 | -import okhttp3.Request; | ||
| 30 | -import okhttp3.Response; | ||
| 31 | import org.apache.catalina.Session; | 29 | import org.apache.catalina.Session; |
| 32 | import org.apache.commons.io.input.ReaderInputStream; | 30 | import org.apache.commons.io.input.ReaderInputStream; |
| 33 | import org.springframework.beans.factory.annotation.Autowired; | 31 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -93,7 +91,7 @@ public class ChatGPTController extends BaseController { | @@ -93,7 +91,7 @@ public class ChatGPTController extends BaseController { | ||
| 93 | OpenAiLoginUser userInfo = (OpenAiLoginUser) getLoginUser(); | 91 | OpenAiLoginUser userInfo = (OpenAiLoginUser) getLoginUser(); |
| 94 | Integer user_id= userInfo.getUserId().intValue(); | 92 | Integer user_id= userInfo.getUserId().intValue(); |
| 95 | String room_id = String.valueOf(user_id); | 93 | String room_id = String.valueOf(user_id); |
| 96 | - List<Map<String,Object>> list = publicService.getObjectListBySQL("SELECT * FROM `lk_openai`.`gpt_message` WHERE room_id="+room_id+" AND user_id="+user_id+" order by create_time desc 5"); | 94 | + List<Map<String,Object>> list = publicService.getObjectListBySQL("SELECT * FROM `lk_openai`.`gpt_message` WHERE room_id="+room_id+" AND user_id="+user_id+" order by create_time desc limit 5"); |
| 97 | Collections.reverse(list); | 95 | Collections.reverse(list); |
| 98 | return AjaxResult.success(list); | 96 | return AjaxResult.success(list); |
| 99 | } | 97 | } |
| @@ -129,7 +127,7 @@ public class ChatGPTController extends BaseController { | @@ -129,7 +127,7 @@ public class ChatGPTController extends BaseController { | ||
| 129 | BigDecimal[] bs = vipService.getUnitprice(); | 127 | BigDecimal[] bs = vipService.getUnitprice(); |
| 130 | BigDecimal openaiUnitprice = bs[0]; | 128 | BigDecimal openaiUnitprice = bs[0]; |
| 131 | BigDecimal realityUnitprice = bs[1]; | 129 | BigDecimal realityUnitprice = bs[1]; |
| 132 | - if(openaiUnitprice.intValue()==0 || realityUnitprice.intValue()==0) | 130 | + if(openaiUnitprice.doubleValue()==0 || realityUnitprice.doubleValue()==0) |
| 133 | { | 131 | { |
| 134 | rlist.add(new CompletionChoiceMessage3_5("assistant","系统未配置流量单价,请联系管理员")); | 132 | rlist.add(new CompletionChoiceMessage3_5("assistant","系统未配置流量单价,请联系管理员")); |
| 135 | return AjaxResult.success(rlist); | 133 | return AjaxResult.success(rlist); |
| @@ -139,7 +137,7 @@ public class ChatGPTController extends BaseController { | @@ -139,7 +137,7 @@ public class ChatGPTController extends BaseController { | ||
| 139 | 137 | ||
| 140 | //上下文关联 | 138 | //上下文关联 |
| 141 | HttpSession session = httpServletRequest.getSession(); | 139 | HttpSession session = httpServletRequest.getSession(); |
| 142 | - List<ChatRoomMessages> messageList = Optional.ofNullable((List<Map<String, Object>>) session.getAttribute(sessionkey)).orElse(new ArrayList<>()).stream().map(item->mapToChatRoomMessages(item)).collect(Collectors.toList()); | 140 | + List<ChatRoomMessages> messageList = Optional.ofNullable((List<ChatRoomMessages>) session.getAttribute(sessionkey)).orElse(new ArrayList<>()); |
| 143 | ChatRoomMessages chatRoomMessages = new ChatRoomMessages(); | 141 | ChatRoomMessages chatRoomMessages = new ChatRoomMessages(); |
| 144 | chatRoomMessages.setRole("user"); | 142 | chatRoomMessages.setRole("user"); |
| 145 | chatRoomMessages.setContent(data); | 143 | chatRoomMessages.setContent(data); |
| @@ -150,9 +148,9 @@ public class ChatGPTController extends BaseController { | @@ -150,9 +148,9 @@ public class ChatGPTController extends BaseController { | ||
| 150 | CompletionResult3_5 completionResult3_5 = null; | 148 | CompletionResult3_5 completionResult3_5 = null; |
| 151 | if(vipService.isfree(openAiUserInfo.getVip_level())) | 149 | if(vipService.isfree(openAiUserInfo.getVip_level())) |
| 152 | { | 150 | { |
| 153 | - completionResult3_5 = sendGPTAi(messageList); | ||
| 154 | - }else{ | ||
| 155 | completionResult3_5 = sendFreeGPTAi(messageList); | 151 | completionResult3_5 = sendFreeGPTAi(messageList); |
| 152 | + }else{ | ||
| 153 | + completionResult3_5 = sendGPTAi(messageList); | ||
| 156 | } | 154 | } |
| 157 | 155 | ||
| 158 | Usage usage = completionResult3_5.getUsage(); | 156 | Usage usage = completionResult3_5.getUsage(); |
| @@ -206,7 +204,7 @@ public class ChatGPTController extends BaseController { | @@ -206,7 +204,7 @@ public class ChatGPTController extends BaseController { | ||
| 206 | publicService.insertAllToTable(insertGptMessages,"`lk_openai`.`gpt_message`"); | 204 | publicService.insertAllToTable(insertGptMessages,"`lk_openai`.`gpt_message`"); |
| 207 | } | 205 | } |
| 208 | 206 | ||
| 209 | - publicService.updateBySql("UPDATE `user_info` SET flow_packet_remain=flow_packet_remain-"+usage.getTotalTokens()+" WHERE id="+openAiUserInfo.getId()); | 207 | + publicService.updateBySql("UPDATE `lk_openai`.`user_info` SET flow_packet_remain=flow_packet_remain-"+usage.getTotalTokens()+" WHERE id="+openAiUserInfo.getId()); |
| 210 | 208 | ||
| 211 | UserFlowPacketRemainLog userFlowPacketRemainLog = new UserFlowPacketRemainLog(); | 209 | UserFlowPacketRemainLog userFlowPacketRemainLog = new UserFlowPacketRemainLog(); |
| 212 | userFlowPacketRemainLog.setCreate_time(DateUtils.getNowTimeMilly()); | 210 | userFlowPacketRemainLog.setCreate_time(DateUtils.getNowTimeMilly()); |
| @@ -214,22 +212,31 @@ public class ChatGPTController extends BaseController { | @@ -214,22 +212,31 @@ public class ChatGPTController extends BaseController { | ||
| 214 | userFlowPacketRemainLog.setType(2); //消费 | 212 | userFlowPacketRemainLog.setType(2); //消费 |
| 215 | 213 | ||
| 216 | StringBuffer stringBuffer = new StringBuffer(); | 214 | StringBuffer stringBuffer = new StringBuffer(); |
| 217 | - stringBuffer.append("房间号:"); | 215 | + stringBuffer.append("房间号:"); |
| 218 | stringBuffer.append(room_id); | 216 | stringBuffer.append(room_id); |
| 217 | + stringBuffer.append(";"); | ||
| 219 | stringBuffer.append("发送代币:"); | 218 | stringBuffer.append("发送代币:"); |
| 220 | stringBuffer.append(usage.getPromptTokens()); | 219 | stringBuffer.append(usage.getPromptTokens()); |
| 221 | - stringBuffer.append("返回代币:"); | 220 | + stringBuffer.append(";"); |
| 221 | + stringBuffer.append("返回代币:"); | ||
| 222 | stringBuffer.append(usage.getCompletionTokens()); | 222 | stringBuffer.append(usage.getCompletionTokens()); |
| 223 | + stringBuffer.append(";"); | ||
| 223 | userFlowPacketRemainLog.setDescribe(stringBuffer.toString()); | 224 | userFlowPacketRemainLog.setDescribe(stringBuffer.toString()); |
| 224 | userFlowPacketRemainLog.setTotal_tokens(usage.getTotalTokens()); | 225 | userFlowPacketRemainLog.setTotal_tokens(usage.getTotalTokens()); |
| 225 | 226 | ||
| 226 | - userFlowPacketRemainLog.setOpenai_money(openaiUnitprice.multiply(new BigDecimal(usage.getTotalTokens())).divide(new BigDecimal(1000),6)); | ||
| 227 | - userFlowPacketRemainLog.setReality_money(realityUnitprice.multiply(new BigDecimal(usage.getTotalTokens())).divide(new BigDecimal(1000),6)); | 227 | + userFlowPacketRemainLog.setOpenai_money((openaiUnitprice.multiply(new BigDecimal(usage.getTotalTokens()))).divide(new BigDecimal(1000),6,BigDecimal.ROUND_HALF_UP)); |
| 228 | + userFlowPacketRemainLog.setReality_money((realityUnitprice.multiply(new BigDecimal(usage.getTotalTokens()))).divide(new BigDecimal(1000),6,BigDecimal.ROUND_HALF_UP)); | ||
| 228 | publicService.insertToTable(userFlowPacketRemainLog,"`lk_openai`.`user_flow_packet_remain_log`"); | 229 | publicService.insertToTable(userFlowPacketRemainLog,"`lk_openai`.`user_flow_packet_remain_log`"); |
| 229 | } | 230 | } |
| 230 | return AjaxResult.success(rlist); | 231 | return AjaxResult.success(rlist); |
| 231 | } | 232 | } |
| 232 | 233 | ||
| 234 | + public static void main(String[] args) { | ||
| 235 | + BigDecimal openaiUnitprice = new BigDecimal(0.03); | ||
| 236 | + BigDecimal r = openaiUnitprice.multiply(new BigDecimal(61)).divide(new BigDecimal(1000),6); | ||
| 237 | + System.out.println(r.doubleValue()); | ||
| 238 | + } | ||
| 239 | + | ||
| 233 | 240 | ||
| 234 | /** | 241 | /** |
| 235 | * 付费接口 | 242 | * 付费接口 |
| @@ -242,6 +249,7 @@ public class ChatGPTController extends BaseController { | @@ -242,6 +249,7 @@ public class ChatGPTController extends BaseController { | ||
| 242 | jsonObject.put("model","gpt-3.5-turbo-0301"); | 249 | jsonObject.put("model","gpt-3.5-turbo-0301"); |
| 243 | jsonObject.put("messages",messageList); | 250 | jsonObject.put("messages",messageList); |
| 244 | String str = HttpUtil.post("https://chatgpt.njlaikun.com/v1/chat/completions",jsonObject.toString()); | 251 | String str = HttpUtil.post("https://chatgpt.njlaikun.com/v1/chat/completions",jsonObject.toString()); |
| 252 | + logger.info("返回的数据:{}",str); | ||
| 245 | CompletionResult3_5 completionResult = JSONObject.parseObject(str, CompletionResult3_5.class); | 253 | CompletionResult3_5 completionResult = JSONObject.parseObject(str, CompletionResult3_5.class); |
| 246 | return completionResult; | 254 | return completionResult; |
| 247 | } | 255 | } |
| 1 | package com.zhonglai.luhui.openai.controller; | 1 | package com.zhonglai.luhui.openai.controller; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.bean.BeanUtil; | ||
| 3 | import cn.hutool.http.HttpUtil; | 4 | import cn.hutool.http.HttpUtil; |
| 4 | import com.alibaba.fastjson.JSON; | 5 | import com.alibaba.fastjson.JSON; |
| 5 | import com.ruoyi.common.constant.Constants; | 6 | import com.ruoyi.common.constant.Constants; |
| @@ -10,6 +11,7 @@ import com.ruoyi.common.core.domain.Message; | @@ -10,6 +11,7 @@ import com.ruoyi.common.core.domain.Message; | ||
| 10 | import com.ruoyi.common.core.domain.MessageCode; | 11 | import com.ruoyi.common.core.domain.MessageCode; |
| 11 | import com.ruoyi.common.utils.DESUtil; | 12 | import com.ruoyi.common.utils.DESUtil; |
| 12 | import com.ruoyi.common.utils.DateUtils; | 13 | import com.ruoyi.common.utils.DateUtils; |
| 14 | +import com.ruoyi.common.utils.GsonConstructor; | ||
| 13 | import com.ruoyi.system.login.service.LoginService; | 15 | import com.ruoyi.system.login.service.LoginService; |
| 14 | import io.swagger.annotations.Api; | 16 | import io.swagger.annotations.Api; |
| 15 | import io.swagger.annotations.ApiImplicitParam; | 17 | import io.swagger.annotations.ApiImplicitParam; |
| @@ -35,22 +37,25 @@ public class OpenAiUserLoginController extends BaseController { | @@ -35,22 +37,25 @@ public class OpenAiUserLoginController extends BaseController { | ||
| 35 | private LoginService loginService; | 37 | private LoginService loginService; |
| 36 | @ApiOperation(value = "手机验证码登陆",notes = "返回token和longtoken,token是接口操作令牌失效时间端,长期本地缓存推荐存储longtoken,longtoken可以通过/openAiUserLogin/getTokenFromLongtoken接口换取token") | 38 | @ApiOperation(value = "手机验证码登陆",notes = "返回token和longtoken,token是接口操作令牌失效时间端,长期本地缓存推荐存储longtoken,longtoken可以通过/openAiUserLogin/getTokenFromLongtoken接口换取token") |
| 37 | @ApiImplicitParams({ | 39 | @ApiImplicitParams({ |
| 38 | - @ApiImplicitParam(value = "手机号",name = "phone"), | 40 | + @ApiImplicitParam(value = "/openAiUserLogin/sendPhoneCode返回的data数据",name = "key"), |
| 39 | @ApiImplicitParam(value = "验证码",name = "code"), | 41 | @ApiImplicitParam(value = "验证码",name = "code"), |
| 40 | }) | 42 | }) |
| 41 | @PostMapping("/userpassLogin") | 43 | @PostMapping("/userpassLogin") |
| 42 | - public AjaxResult userpassLogin(String phone, String code, String key) | 44 | + public AjaxResult userpassLogin(String code, String key) |
| 43 | { | 45 | { |
| 44 | //验证验证码 | 46 | //验证验证码 |
| 45 | - String str = HttpUtil.get("http://ly.userlogin.yu2le.com/userLogin/verificationCode?key="+key+"&code="+code); | ||
| 46 | - Message message = JSON.parseObject(str,Message.class); | 47 | + String str = HttpUtil.post("http://ly.userlogin.yu2le.com/userLogin/verificationCode?key="+key+"&code="+code,new HashMap<>()); |
| 48 | + | ||
| 49 | + Message message = GsonConstructor.get().fromJson(str,Message.class); | ||
| 47 | if(message.getCode()!=MessageCode.DEFAULT_SUCCESS_CODE.code) | 50 | if(message.getCode()!=MessageCode.DEFAULT_SUCCESS_CODE.code) |
| 48 | { | 51 | { |
| 49 | return AjaxResult.error(message.getMessage()); | 52 | return AjaxResult.error(message.getMessage()); |
| 50 | } | 53 | } |
| 54 | + String[] keys = DESUtil.decode(message.getData().toString(), ENCODE_KEY).split("_"); | ||
| 55 | + | ||
| 51 | //生成令牌 | 56 | //生成令牌 |
| 52 | - String token = loginService.openaiLoginByPass(phone,user_pass); | ||
| 53 | - String longtoken = DESUtil.encode(phone+"_"+ DateUtils.getNowTimeMilly(),ENCODE_KEY); | 57 | + String token = loginService.openaiLoginByPass(keys[0],user_pass); |
| 58 | + String longtoken = DESUtil.encode(keys[0]+"_"+ DateUtils.getNowTimeMilly(),ENCODE_KEY); | ||
| 54 | return AjaxResult.success().put(Constants.TOKEN, token).put("longtoken", longtoken); | 59 | return AjaxResult.success().put(Constants.TOKEN, token).put("longtoken", longtoken); |
| 55 | } | 60 | } |
| 56 | 61 | ||
| @@ -64,7 +69,7 @@ public class OpenAiUserLoginController extends BaseController { | @@ -64,7 +69,7 @@ public class OpenAiUserLoginController extends BaseController { | ||
| 64 | { | 69 | { |
| 65 | //生成令牌 | 70 | //生成令牌 |
| 66 | String str = HttpUtil.get("http://ly.userlogin.yu2le.com/userLogin/getPhoneCode/1/"+phone); | 71 | String str = HttpUtil.get("http://ly.userlogin.yu2le.com/userLogin/getPhoneCode/1/"+phone); |
| 67 | - Message message = JSON.parseObject(str,Message.class); | 72 | + Message message = GsonConstructor.get().fromJson(str,Message.class); |
| 68 | if(message.getCode()!=MessageCode.DEFAULT_SUCCESS_CODE.code) | 73 | if(message.getCode()!=MessageCode.DEFAULT_SUCCESS_CODE.code) |
| 69 | { | 74 | { |
| 70 | return AjaxResult.error(message.getMessage()); | 75 | return AjaxResult.error(message.getMessage()); |
| 1 | package com.zhonglai.luhui.openai.controller; | 1 | package com.zhonglai.luhui.openai.controller; |
| 2 | 2 | ||
| 3 | +import com.ruoyi.common.config.RuoYiConfig; | ||
| 3 | import com.ruoyi.common.core.controller.BaseController; | 4 | import com.ruoyi.common.core.controller.BaseController; |
| 4 | import com.ruoyi.common.core.domain.AjaxResult; | 5 | import com.ruoyi.common.core.domain.AjaxResult; |
| 5 | import com.ruoyi.common.core.page.TableDataInfo; | 6 | import com.ruoyi.common.core.page.TableDataInfo; |
| 7 | +import com.ruoyi.common.utils.StringUtils; | ||
| 8 | +import com.ruoyi.common.utils.file.FileUploadUtils; | ||
| 9 | +import com.ruoyi.common.utils.file.FileUtils; | ||
| 10 | +import com.ruoyi.framework.config.ServerConfig; | ||
| 6 | import com.ruoyi.system.service.PublicService; | 11 | import com.ruoyi.system.service.PublicService; |
| 7 | import io.swagger.annotations.Api; | 12 | import io.swagger.annotations.Api; |
| 13 | +import io.swagger.annotations.ApiImplicitParam; | ||
| 14 | +import io.swagger.annotations.ApiImplicitParams; | ||
| 8 | import io.swagger.annotations.ApiOperation; | 15 | import io.swagger.annotations.ApiOperation; |
| 9 | import org.springframework.beans.factory.annotation.Autowired; | 16 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | import org.springframework.web.bind.annotation.GetMapping; | 17 | import org.springframework.web.bind.annotation.GetMapping; |
| 11 | import org.springframework.web.bind.annotation.PostMapping; | 18 | import org.springframework.web.bind.annotation.PostMapping; |
| 12 | import org.springframework.web.bind.annotation.RequestMapping; | 19 | import org.springframework.web.bind.annotation.RequestMapping; |
| 13 | import org.springframework.web.bind.annotation.RestController; | 20 | import org.springframework.web.bind.annotation.RestController; |
| 21 | +import org.springframework.web.multipart.MultipartFile; | ||
| 14 | 22 | ||
| 23 | +import java.util.ArrayList; | ||
| 15 | import java.util.List; | 24 | import java.util.List; |
| 16 | import java.util.Map; | 25 | import java.util.Map; |
| 17 | 26 | ||
| @@ -20,6 +29,11 @@ import java.util.Map; | @@ -20,6 +29,11 @@ import java.util.Map; | ||
| 20 | @RequestMapping("/userInfo") | 29 | @RequestMapping("/userInfo") |
| 21 | public class UserInfoController extends BaseController { | 30 | public class UserInfoController extends BaseController { |
| 22 | @Autowired | 31 | @Autowired |
| 32 | + private ServerConfig serverConfig; | ||
| 33 | + | ||
| 34 | + private static final String FILE_DELIMETER = ","; | ||
| 35 | + | ||
| 36 | + @Autowired | ||
| 23 | private PublicService publicService; | 37 | private PublicService publicService; |
| 24 | @ApiOperation("获取用户信息") | 38 | @ApiOperation("获取用户信息") |
| 25 | @GetMapping("/getUserInfo") | 39 | @GetMapping("/getUserInfo") |
| @@ -49,7 +63,7 @@ public class UserInfoController extends BaseController { | @@ -49,7 +63,7 @@ public class UserInfoController extends BaseController { | ||
| 49 | public TableDataInfo useFlowPacketRemainLog() | 63 | public TableDataInfo useFlowPacketRemainLog() |
| 50 | { | 64 | { |
| 51 | startPage(); | 65 | startPage(); |
| 52 | - List<Map<String,Object>> list = publicService.getObjectListBySQL("SELECT * FROM `lk_openai`.`user_flow_packet_remain_log` WHERE `user_id=`"+getUserId().intValue()+" and `type`=2 order by create_time desc"); | 66 | + List<Map<String,Object>> list = publicService.getObjectListBySQL("SELECT * FROM `lk_openai`.`user_flow_packet_remain_log` WHERE `user_id`="+getUserId().intValue()+" and `type`=2 order by create_time desc"); |
| 53 | return getDataTable(list); | 67 | return getDataTable(list); |
| 54 | } | 68 | } |
| 55 | 69 | ||
| @@ -61,4 +75,45 @@ public class UserInfoController extends BaseController { | @@ -61,4 +75,45 @@ public class UserInfoController extends BaseController { | ||
| 61 | List<Map<String,Object>> list = publicService.getObjectListBySQL("SELECT * FROM `lk_openai`.`user_flow_packet_remain_log` WHERE `user_id`="+getUserId().intValue()+" and `type`=1 order by create_time desc"); | 75 | List<Map<String,Object>> list = publicService.getObjectListBySQL("SELECT * FROM `lk_openai`.`user_flow_packet_remain_log` WHERE `user_id`="+getUserId().intValue()+" and `type`=1 order by create_time desc"); |
| 62 | return getDataTable(list); | 76 | return getDataTable(list); |
| 63 | } | 77 | } |
| 78 | + | ||
| 79 | + /** | ||
| 80 | + * 通用上传请求(多个) | ||
| 81 | + */ | ||
| 82 | + @ApiOperation("通用上传请求(多个)") | ||
| 83 | + @ApiImplicitParams({ | ||
| 84 | + @ApiImplicitParam(name = "files", value = "文件集合", required = true, dataType = "List<MultipartFile>", dataTypeClass = List.class) | ||
| 85 | + }) | ||
| 86 | + @PostMapping("/uploads") | ||
| 87 | + public AjaxResult uploadFiles(List<MultipartFile> files) throws Exception | ||
| 88 | + { | ||
| 89 | + try | ||
| 90 | + { | ||
| 91 | + // 上传文件路径 | ||
| 92 | + String filePath = RuoYiConfig.getUploadPath(); | ||
| 93 | + List<String> urls = new ArrayList<String>(); | ||
| 94 | + List<String> fileNames = new ArrayList<String>(); | ||
| 95 | + List<String> newFileNames = new ArrayList<String>(); | ||
| 96 | + List<String> originalFilenames = new ArrayList<String>(); | ||
| 97 | + for (MultipartFile file : files) | ||
| 98 | + { | ||
| 99 | + // 上传并返回新文件名称 | ||
| 100 | + String fileName = FileUploadUtils.upload(filePath, file); | ||
| 101 | + String url = serverConfig.getUrl() + fileName; | ||
| 102 | + urls.add(url); | ||
| 103 | + fileNames.add(fileName); | ||
| 104 | + newFileNames.add(FileUtils.getName(fileName)); | ||
| 105 | + originalFilenames.add(file.getOriginalFilename()); | ||
| 106 | + } | ||
| 107 | + AjaxResult ajax = AjaxResult.success(); | ||
| 108 | + ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER)); | ||
| 109 | + ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER)); | ||
| 110 | + ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER)); | ||
| 111 | + ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER)); | ||
| 112 | + return ajax; | ||
| 113 | + } | ||
| 114 | + catch (Exception e) | ||
| 115 | + { | ||
| 116 | + return AjaxResult.error(e.getMessage()); | ||
| 117 | + } | ||
| 118 | + } | ||
| 64 | } | 119 | } |
| @@ -85,7 +85,7 @@ public class VipServiceImpl { | @@ -85,7 +85,7 @@ public class VipServiceImpl { | ||
| 85 | { | 85 | { |
| 86 | if("openai".equals(map.get("key"))) | 86 | if("openai".equals(map.get("key"))) |
| 87 | { | 87 | { |
| 88 | - openaiUnitprice = new BigDecimal(map.get("value").toString()); | 88 | + openaiUnitprice = new BigDecimal(map.get("value").toString()); |
| 89 | }else if("reality".equals(map.get("key"))) | 89 | }else if("reality".equals(map.get("key"))) |
| 90 | { | 90 | { |
| 91 | realityUnitprice = new BigDecimal(map.get("value").toString()); | 91 | realityUnitprice = new BigDecimal(map.get("value").toString()); |
| 1 | -# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2022 # 获取ip地址开关 addressEnabled: false # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8082 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn # Spring配置 spring: # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # redis 配置 redis: # 地址 host: 47.112.163.61 # 端口,默认为6379 port: 9527 # 数据库索引 database: 1 # 密码 password: Luhui586 # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 0 # 连接池中的最大空闲连接 max-idle: 8 # 连接池的最大数据库连接数 max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # token配置 token: # 令牌自定义标识 header: Authorization # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) expireTime: 1440 rediskey: lh-openai # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* mqtt: client: device_life: 180 # NameServer地址 rocketmq: name-server: 47.115.144.179:9876 # 默认的消息组 producer: group: deviceCommand send-message-timeout: 30000 send-topic: lh-chat-gpt send-tags: 1 sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: /login,/register,/captchaImage,/getCacheObject,/v2/api-docs chatgpt: token: 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 timeout: 5000 | ||
| 1 | +# 项目相关配置 jhlt: # 名称 name: zhonglai # 版本 version: 3.8.2 # 版权年份 copyrightYear: 2022 # 获取ip地址开关 addressEnabled: false # 开发环境配置 server: # 服务器的HTTP端口,默认为8080 port: 8082 servlet: # 应用的访问路径 context-path: / tomcat: # tomcat的URI编码 uri-encoding: UTF-8 # 连接数满后的排队数,默认为100 accept-count: 1000 threads: # tomcat最大线程数,默认为200 max: 800 # Tomcat启动初始化的线程数,默认值10 min-spare: 100 # 日志配置 logging: level: com.ruoyi: debug org.springframework: warn # Spring配置 spring: # 资源信息 messages: # 国际化资源文件路径 basename: i18n/messages profiles: active: druid # 文件上传 servlet: multipart: # 单个文件大小 max-file-size: 10MB # 设置总上传的文件大小 max-request-size: 20MB # 服务模块 devtools: restart: # 热部署开关 enabled: true # redis 配置 redis: # 地址 host: 47.112.163.61 # 端口,默认为6379 port: 9527 # 数据库索引 database: 1 # 密码 password: Luhui586 # 连接超时时间 timeout: 10s lettuce: pool: # 连接池中的最小空闲连接 min-idle: 0 # 连接池中的最大空闲连接 max-idle: 8 # 连接池的最大数据库连接数 max-active: 8 # #连接池最大阻塞等待时间(使用负值表示没有限制) max-wait: -1ms # token配置 token: # 令牌自定义标识 header: Authorization # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) expireTime: 1440 rediskey: lh-openai # MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.ruoyi.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # PageHelper分页插件 pagehelper: helperDialect: mysql supportMethodsArguments: true params: count=countSql # Swagger配置 swagger: # 是否开启swagger enabled: true # 请求前缀 pathMapping: /dev-api # 防止XSS攻击 xss: # 过滤开关 enabled: true # 排除链接(多个用逗号分隔) excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* mqtt: client: device_life: 180 # NameServer地址 rocketmq: name-server: 47.115.144.179:9876 # 默认的消息组 producer: group: deviceCommand send-message-timeout: 30000 send-topic: lh-chat-gpt send-tags: 1 sys: ## // 对于登录login 注册register 验证码captchaImage 允许匿名访问 antMatchers: /login,/register,/captchaImage,/getCacheObject,/v2/api-docs,/openAiUserLogin/* chatgpt: token: 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 timeout: 5000 |
| 1 | +#错误消息 | ||
| 2 | +not.null=* 必须填写 | ||
| 3 | +user.jcaptcha.error=验证码错误 | ||
| 4 | +user.jcaptcha.expire=验证码已失效 | ||
| 5 | +user.not.exists=用户不存在/密码错误 | ||
| 6 | +user.password.not.match=用户不存在/密码错误 | ||
| 7 | +user.password.retry.limit.count=密码输入错误{0}次 | ||
| 8 | +user.password.retry.limit.exceed=密码输入错误{0}次,帐户锁定10分钟 | ||
| 9 | +user.password.delete=对不起,您的账号已被删除 | ||
| 10 | +user.blocked=用户已封禁,请联系管理员 | ||
| 11 | +role.blocked=角色已封禁,请联系管理员 | ||
| 12 | +user.logout.success=退出成功 | ||
| 13 | + | ||
| 14 | +length.not.valid=长度必须在{min}到{max}个字符之间 | ||
| 15 | + | ||
| 16 | +user.username.not.valid=* 2到20个汉字、字母、数字或下划线组成,且必须以非数字开头 | ||
| 17 | +user.password.not.valid=* 5-50个字符 | ||
| 18 | + | ||
| 19 | +user.email.not.valid=邮箱格式错误 | ||
| 20 | +user.mobile.phone.number.not.valid=手机号格式错误 | ||
| 21 | +user.login.success=登录成功 | ||
| 22 | +user.register.success=注册成功 | ||
| 23 | +user.notfound=请重新登录 | ||
| 24 | +user.forcelogout=管理员强制退出,请重新登录 | ||
| 25 | +user.unknown.error=未知错误,请重新登录 | ||
| 26 | + | ||
| 27 | +##文件上传消息 | ||
| 28 | +upload.exceed.maxSize=上传的文件大小超出限制的文件大小!<br/>允许的文件最大大小是:{0}MB! | ||
| 29 | +upload.filename.exceed.length=上传的文件名最长{0}个字符 | ||
| 30 | + | ||
| 31 | +##权限 | ||
| 32 | +no.permission=您没有数据的权限,请联系管理员添加权限 [{0}] | ||
| 33 | +no.create.permission=您没有创建数据的权限,请联系管理员添加权限 [{0}] | ||
| 34 | +no.update.permission=您没有修改数据的权限,请联系管理员添加权限 [{0}] | ||
| 35 | +no.delete.permission=您没有删除数据的权限,请联系管理员添加权限 [{0}] | ||
| 36 | +no.export.permission=您没有导出数据的权限,请联系管理员添加权限 [{0}] | ||
| 37 | +no.view.permission=您没有查看数据的权限,请联系管理员添加权限 [{0}] |
| @@ -303,6 +303,12 @@ | @@ -303,6 +303,12 @@ | ||
| 303 | </dependency> | 303 | </dependency> |
| 304 | 304 | ||
| 305 | <dependency> | 305 | <dependency> |
| 306 | + <groupId>com.google.code.gson</groupId> | ||
| 307 | + <artifactId>gson</artifactId> | ||
| 308 | + <version>2.10.1</version> | ||
| 309 | + </dependency> | ||
| 310 | + | ||
| 311 | + <dependency> | ||
| 306 | <groupId>com.squareup.okhttp3</groupId> | 312 | <groupId>com.squareup.okhttp3</groupId> |
| 307 | <artifactId>okhttp</artifactId> | 313 | <artifactId>okhttp</artifactId> |
| 308 | <version>${okhttp.version}</version> | 314 | <version>${okhttp.version}</version> |
| @@ -179,5 +179,10 @@ | @@ -179,5 +179,10 @@ | ||
| 179 | <artifactId>jakarta.validation-api</artifactId> | 179 | <artifactId>jakarta.validation-api</artifactId> |
| 180 | <version>2.0.2</version> | 180 | <version>2.0.2</version> |
| 181 | </dependency> | 181 | </dependency> |
| 182 | + | ||
| 183 | + <dependency> | ||
| 184 | + <groupId>com.google.code.gson</groupId> | ||
| 185 | + <artifactId>gson</artifactId> | ||
| 186 | + </dependency> | ||
| 182 | </dependencies> | 187 | </dependencies> |
| 183 | </project> | 188 | </project> |
| 1 | +package com.ruoyi.common.utils; | ||
| 2 | + | ||
| 3 | +import com.google.gson.FieldNamingPolicy; | ||
| 4 | +import com.google.gson.Gson; | ||
| 5 | +import com.google.gson.GsonBuilder; | ||
| 6 | + | ||
| 7 | +public class GsonConstructor { | ||
| 8 | + private static final Gson gson; | ||
| 9 | + | ||
| 10 | + public GsonConstructor() { | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + public static final Gson get() { | ||
| 14 | + return gson; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + static { | ||
| 18 | + gson = (new GsonBuilder()).setVersion(1.0D).disableInnerClassSerialization().setFieldNamingPolicy(FieldNamingPolicy.IDENTITY).setDateFormat("yyyy-MM-dd").setPrettyPrinting().create(); | ||
| 19 | + } | ||
| 20 | +} |
| @@ -131,12 +131,16 @@ public class PublicSQL { | @@ -131,12 +131,16 @@ public class PublicSQL { | ||
| 131 | 131 | ||
| 132 | /** | 132 | /** |
| 133 | * 指定表名添加对象 | 133 | * 指定表名添加对象 |
| 134 | - * @param object | ||
| 135 | * @return | 134 | * @return |
| 136 | */ | 135 | */ |
| 137 | - public String insertToTable(Object object) | 136 | + public String insertToTable(Map map) |
| 138 | { | 137 | { |
| 138 | + Object object = map.get("object"); | ||
| 139 | String tableName = changTableNameFromObject(object); | 139 | String tableName = changTableNameFromObject(object); |
| 140 | + if(map.containsKey("tableName")) | ||
| 141 | + { | ||
| 142 | + tableName = map.get("tableName").toString(); | ||
| 143 | + } | ||
| 140 | StringBuffer sql = new StringBuffer(); | 144 | StringBuffer sql = new StringBuffer(); |
| 141 | sql.append("insert into "); | 145 | sql.append("insert into "); |
| 142 | sql.append(tableName + "("); | 146 | sql.append(tableName + "("); |
| 1 | package com.ruoyi.system.login.dto; | 1 | package com.ruoyi.system.login.dto; |
| 2 | 2 | ||
| 3 | import com.ruoyi.common.core.domain.BaseLoginUser; | 3 | import com.ruoyi.common.core.domain.BaseLoginUser; |
| 4 | +import com.ruoyi.common.utils.SecurityUtils; | ||
| 4 | import com.ruoyi.system.domain.tool.PublicSQLConfig; | 5 | import com.ruoyi.system.domain.tool.PublicSQLConfig; |
| 6 | +import com.ruoyi.system.domain.tool.SysLogininforType; | ||
| 5 | import org.springframework.security.core.GrantedAuthority; | 7 | import org.springframework.security.core.GrantedAuthority; |
| 6 | 8 | ||
| 7 | import java.util.Collection; | 9 | import java.util.Collection; |
| @@ -12,9 +14,26 @@ public class OpenAiLoginUser extends BaseLoginUser { | @@ -12,9 +14,26 @@ public class OpenAiLoginUser extends BaseLoginUser { | ||
| 12 | 14 | ||
| 13 | private OpenAiUserInfo openAiUserInfo; | 15 | private OpenAiUserInfo openAiUserInfo; |
| 14 | 16 | ||
| 17 | + public OpenAiLoginUser() { | ||
| 18 | + } | ||
| 19 | + | ||
| 15 | public OpenAiLoginUser(OpenAiUserInfo openAiUserInfo) { | 20 | public OpenAiLoginUser(OpenAiUserInfo openAiUserInfo) { |
| 16 | this.openAiUserInfo = openAiUserInfo; | 21 | this.openAiUserInfo = openAiUserInfo; |
| 17 | - setUserId(new Long(openAiUserInfo.getId())); | 22 | + super.setUserId(new Long(openAiUserInfo.getId())); |
| 23 | + } | ||
| 24 | + | ||
| 25 | + public OpenAiLoginUser(OpenAiUserInfo openAiUserInfo,Long userId, String token, Long loginTime, Long expireTime, String ipaddr, String loginLocation, String browser, String os, SysLogininforType sysLogininforType) { | ||
| 26 | + super.setUserId(userId); | ||
| 27 | + super.setToken(token); | ||
| 28 | + super.setLoginTime(loginTime); | ||
| 29 | + super.setExpireTime(expireTime); | ||
| 30 | + super.setIpaddr(ipaddr); | ||
| 31 | + super.setLoginLocation(loginLocation); | ||
| 32 | + super.setBrowser(browser); | ||
| 33 | + super.setOs(os); | ||
| 34 | + super.setSysLogininforType( sysLogininforType); | ||
| 35 | + super.setUserId(new Long(openAiUserInfo.getId())); | ||
| 36 | + this.openAiUserInfo = openAiUserInfo; | ||
| 18 | } | 37 | } |
| 19 | 38 | ||
| 20 | @Override | 39 | @Override |
| @@ -29,7 +48,7 @@ public class OpenAiLoginUser extends BaseLoginUser { | @@ -29,7 +48,7 @@ public class OpenAiLoginUser extends BaseLoginUser { | ||
| 29 | 48 | ||
| 30 | @Override | 49 | @Override |
| 31 | public String getPassword() { | 50 | public String getPassword() { |
| 32 | - return "123456"; | 51 | + return SecurityUtils.encryptPassword("123456"); |
| 33 | } | 52 | } |
| 34 | 53 | ||
| 35 | @Override | 54 | @Override |
| @@ -56,4 +75,12 @@ public class OpenAiLoginUser extends BaseLoginUser { | @@ -56,4 +75,12 @@ public class OpenAiLoginUser extends BaseLoginUser { | ||
| 56 | public boolean isEnabled() { | 75 | public boolean isEnabled() { |
| 57 | return openAiUserInfo.getState()!=0; | 76 | return openAiUserInfo.getState()!=0; |
| 58 | } | 77 | } |
| 78 | + | ||
| 79 | + public OpenAiUserInfo getOpenAiUserInfo() { | ||
| 80 | + return openAiUserInfo; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + public void setOpenAiUserInfo(OpenAiUserInfo openAiUserInfo) { | ||
| 84 | + this.openAiUserInfo = openAiUserInfo; | ||
| 85 | + } | ||
| 59 | } | 86 | } |
| @@ -16,7 +16,7 @@ public class OpenAiUserInfo implements Serializable { | @@ -16,7 +16,7 @@ public class OpenAiUserInfo implements Serializable { | ||
| 16 | private String nickname; // varchar(50) DEFAULT NULL COMMENT '昵称', | 16 | private String nickname; // varchar(50) DEFAULT NULL COMMENT '昵称', |
| 17 | private String img_url; // varchar(50) DEFAULT NULL COMMENT '头像地址', | 17 | private String img_url; // varchar(50) DEFAULT NULL COMMENT '头像地址', |
| 18 | private Integer vip_level; //vip等级(0试用用户,1vip1,2vip2,3vip3) | 18 | private Integer vip_level; //vip等级(0试用用户,1vip1,2vip2,3vip3) |
| 19 | - private Integer getVip_level_end_time; //vip到期时间 | 19 | + private Integer vip_level_end_time; //vip到期时间 |
| 20 | private Integer create_time; //创建时间 | 20 | private Integer create_time; //创建时间 |
| 21 | private Integer flow_packet_remain; //流量包余额 | 21 | private Integer flow_packet_remain; //流量包余额 |
| 22 | private Integer flow_packet_total; //流量包总额 | 22 | private Integer flow_packet_total; //流量包总额 |
| @@ -70,12 +70,12 @@ public class OpenAiUserInfo implements Serializable { | @@ -70,12 +70,12 @@ public class OpenAiUserInfo implements Serializable { | ||
| 70 | this.vip_level = vip_level; | 70 | this.vip_level = vip_level; |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | - public Integer getGetVip_level_end_time() { | ||
| 74 | - return getVip_level_end_time; | 73 | + public Integer getVip_level_end_time() { |
| 74 | + return vip_level_end_time; | ||
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | - public void setGetVip_level_end_time(Integer getVip_level_end_time) { | ||
| 78 | - this.getVip_level_end_time = getVip_level_end_time; | 77 | + public void setVip_level_end_time(Integer vip_level_end_time) { |
| 78 | + this.vip_level_end_time = vip_level_end_time; | ||
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | public Integer getCreate_time() { | 81 | public Integer getCreate_time() { |
| @@ -12,6 +12,8 @@ import eu.bitwalker.useragentutils.UserAgent; | @@ -12,6 +12,8 @@ import eu.bitwalker.useragentutils.UserAgent; | ||
| 12 | import io.jsonwebtoken.Claims; | 12 | import io.jsonwebtoken.Claims; |
| 13 | import io.jsonwebtoken.Jwts; | 13 | import io.jsonwebtoken.Jwts; |
| 14 | import io.jsonwebtoken.SignatureAlgorithm; | 14 | import io.jsonwebtoken.SignatureAlgorithm; |
| 15 | +import org.slf4j.Logger; | ||
| 16 | +import org.slf4j.LoggerFactory; | ||
| 15 | import org.springframework.beans.factory.annotation.Autowired; | 17 | import org.springframework.beans.factory.annotation.Autowired; |
| 16 | import org.springframework.beans.factory.annotation.Value; | 18 | import org.springframework.beans.factory.annotation.Value; |
| 17 | import org.springframework.stereotype.Component; | 19 | import org.springframework.stereotype.Component; |
| @@ -29,6 +31,8 @@ import java.util.concurrent.TimeUnit; | @@ -29,6 +31,8 @@ import java.util.concurrent.TimeUnit; | ||
| 29 | @Component | 31 | @Component |
| 30 | public class TokenService | 32 | public class TokenService |
| 31 | { | 33 | { |
| 34 | + protected final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 35 | + | ||
| 32 | // 令牌自定义标识 | 36 | // 令牌自定义标识 |
| 33 | @Value("${token.header}") | 37 | @Value("${token.header}") |
| 34 | private String header; | 38 | private String header; |
| @@ -75,7 +79,7 @@ public class TokenService | @@ -75,7 +79,7 @@ public class TokenService | ||
| 75 | } | 79 | } |
| 76 | catch (Exception e) | 80 | catch (Exception e) |
| 77 | { | 81 | { |
| 78 | - System.err.println(e); | 82 | + logger.error("令牌获取登录信息失败",e); |
| 79 | } | 83 | } |
| 80 | } | 84 | } |
| 81 | return null; | 85 | return null; |
| @@ -22,7 +22,7 @@ public interface PublicMapper { | @@ -22,7 +22,7 @@ public interface PublicMapper { | ||
| 22 | * 指定表名添加 | 22 | * 指定表名添加 |
| 23 | */ | 23 | */ |
| 24 | @InsertProvider(type = PublicSQL.class, method = "insertToTable") | 24 | @InsertProvider(type = PublicSQL.class, method = "insertToTable") |
| 25 | - int insertToTable(Object object,String tableName); | 25 | + int insertToTable(@Param("object") Object object,@Param("tableName") String tableName); |
| 26 | 26 | ||
| 27 | /** | 27 | /** |
| 28 | * 添加对象集合 | 28 | * 添加对象集合 |
-
请 注册 或 登录 后发表评论