promt优化+购买原图
This commit is contained in:
parent
bb8826c26e
commit
0c5ac83574
5
pom.xml
5
pom.xml
@ -26,6 +26,11 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.volcengine</groupId>
|
||||
<artifactId>volcengine-java-sdk-ark-runtime</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>eu.bitwalker</groupId>
|
||||
<artifactId>UserAgentUtils</artifactId>
|
||||
|
@ -0,0 +1,31 @@
|
||||
package com.pixelai.api.chat.controller;
|
||||
|
||||
import com.base.annotation.SysLog;
|
||||
import com.base.helper.Result;
|
||||
import com.pixelai.api.chat.service.VolcengineChatService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Api(tags = "火山方舟api调用")
|
||||
@RestController
|
||||
@RequestMapping("/VolcengineChat")
|
||||
public class VolcengineChatController {
|
||||
@Autowired
|
||||
private VolcengineChatService volcengineChatService;
|
||||
|
||||
@SysLog(action = "VolcengineChat:generatePromptWords", value = "火山方舟在线推理:提示词生成")
|
||||
@ApiOperation(value = "提示词生成", notes = "火山方舟在线推理")
|
||||
@RequestMapping(value = "generatePromptWords", method = {RequestMethod.POST})
|
||||
public Result<Object> generatePromptWords(@RequestParam("message") String message) throws Exception {
|
||||
Map response = volcengineChatService.generatePromptWords(message);
|
||||
Object data = response.get("body");
|
||||
return new Result<>(true, data);
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.pixelai.api.chat.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface VolcengineChatService {
|
||||
Map<String, Object> generatePromptWords(String message) throws Exception;
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.pixelai.api.chat.service.impl;
|
||||
|
||||
import com.pixelai.api.chat.service.VolcengineChatService;
|
||||
import com.pixelai.api.chat.utils.VolcengineChatUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class VolcengineChatServiceImpl implements VolcengineChatService {
|
||||
@Autowired
|
||||
VolcengineChatUtil volcengineChatUtil;
|
||||
@Override
|
||||
public Map<String, Object> generatePromptWords(String message) throws Exception {
|
||||
Map<String, Object> response=volcengineChatUtil.doRequest(message);
|
||||
return response;
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package com.pixelai.api.chat.utils;
|
||||
|
||||
import com.volcengine.ark.runtime.model.completion.chat.ChatCompletionRequest;
|
||||
import com.volcengine.ark.runtime.model.completion.chat.ChatMessage;
|
||||
import com.volcengine.ark.runtime.model.completion.chat.ChatMessageRole;
|
||||
import com.volcengine.ark.runtime.service.ArkService;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class VolcengineChatUtil {
|
||||
|
||||
@Value("${volcengine.ArkApiKey}")
|
||||
private String arkApiKey;
|
||||
@Value("${volcengine.Model}")
|
||||
private String model;
|
||||
|
||||
|
||||
public Map<String, Object> doRequest(String message) {
|
||||
// 创建ArkService实例
|
||||
ArkService arkService = ArkService.builder().apiKey(arkApiKey).build();
|
||||
|
||||
// 初始化消息列表
|
||||
List<ChatMessage> chatMessages = new ArrayList<>();
|
||||
ChatMessage userMessage;
|
||||
// 创建用户消息
|
||||
if(message.length()>0){
|
||||
userMessage = ChatMessage.builder()
|
||||
.role(ChatMessageRole.USER) // 设置消息角色为用户
|
||||
.content("请你丰富提示词,帮助用户更好的使用视觉大模型生成图片。文本要求两百字以内,格式要求不要换行,提示词如下:"+message) // 设置消息内容
|
||||
.build();
|
||||
}else {
|
||||
userMessage = ChatMessage.builder()
|
||||
.role(ChatMessageRole.USER) // 设置消息角色为用户
|
||||
.content("请你随机生成一张图片的提示词,帮助用户更方便的使用视觉大模型生成图片。文本要求两百字以内,格式要求不要换行。") // 设置消息内容
|
||||
.build();
|
||||
}
|
||||
|
||||
// 将用户消息添加到消息列表
|
||||
chatMessages.add(userMessage);
|
||||
|
||||
// 创建聊天完成请求
|
||||
ChatCompletionRequest chatCompletionRequest = ChatCompletionRequest.builder()
|
||||
.model(model)// 需要替换为您的推理接入点ID
|
||||
.messages(chatMessages) // 设置消息列表
|
||||
.build();
|
||||
Map response = new HashMap();
|
||||
// 发送聊天完成请求并打印响应
|
||||
try {
|
||||
// 获取响应并打印每个选择的消息内容
|
||||
// arkService.createChatCompletion(chatCompletionRequest)
|
||||
// .getChoices()
|
||||
// .forEach(choice -> System.out.println(choice.getMessage().getContent()));
|
||||
// 获取响应并存储每个选择的消息内容
|
||||
arkService.createChatCompletion(chatCompletionRequest)
|
||||
.getChoices()
|
||||
.forEach(choice -> response.put("body",choice.getMessage().getContent()));
|
||||
// response.put("body",arkService.createChatCompletion(chatCompletionRequest)
|
||||
// .getChoices());
|
||||
// System.out.println("\n\nbody:"+response.get("body"));
|
||||
} catch (Exception e) {
|
||||
response.put("body","请求失败: " + e.getMessage());
|
||||
System.out.println("请求失败: " + e.getMessage());
|
||||
} finally {
|
||||
// 关闭服务执行器
|
||||
arkService.shutdownExecutor();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
@ -1,134 +0,0 @@
|
||||
package com.pixelai.api.pa.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import com.base.annotation.SysLog;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.base.helper.BaseController;
|
||||
import com.base.helper.Result;
|
||||
import com.pixelai.api.pa.entity.MbConsumption;
|
||||
import com.pixelai.api.pa.service.MbConsumptionService;
|
||||
import io.swagger.annotations.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author gjj
|
||||
* @since 2024-12-23
|
||||
*/
|
||||
@Api(tags = "用户消费表")
|
||||
@RestController
|
||||
@RequestMapping("/mbConsumption")
|
||||
public class MbConsumptionController extends BaseController {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MbConsumptionController.class);
|
||||
@Autowired
|
||||
private MbConsumptionService entityService;
|
||||
|
||||
@SysLog(action = "findByPage", value = "分页查询用户消费")
|
||||
@ApiOperation(value = "分页查询用户消费", notes = "分页查询用户消费")
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ApiImplicitParams({@ApiImplicitParam(name = "size", value = "分页大小", paramType = "query"),
|
||||
@ApiImplicitParam(name = "current", value = "当前页面:从1开始", paramType = "query")})
|
||||
public Result<IPage<MbConsumption>> findByPage(final MbConsumption example, final Page page) {
|
||||
IPage<MbConsumption> records = entityService.page(example,page);
|
||||
return new Result(true, records);
|
||||
}
|
||||
|
||||
@SysLog(action = "delete", value = "删除用户消费")
|
||||
@ApiOperation(value = "删除用户消费")
|
||||
@RequestMapping(value = "{id}", method = {RequestMethod.DELETE})
|
||||
@ApiImplicitParam(name = "id", value = "用户消费ID", required = true, paramType = "path")
|
||||
public Result delete(@PathVariable final Integer id) {
|
||||
try {
|
||||
entityService.removeById(id);
|
||||
return new Result(true, "成功删除用户消费", null);
|
||||
} catch (DataIntegrityViolationException e) {
|
||||
LOG.error("删除用户消费失败", e);
|
||||
return new Result(false, "删除用户消费失败", "该用户消费不能删除,存在其他关联数据");
|
||||
} catch (Exception e) {
|
||||
LOG.error("删除用户消费失败", e);
|
||||
return new Result(false, "删除用户消费失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@SysLog(action = "one", value = "查询单个用户消费")
|
||||
@ApiOperation(value = "查询单个用户消费")
|
||||
@RequestMapping(value = "{id}", method = {RequestMethod.GET})
|
||||
@ApiImplicitParam(name = "id", value = "用户消费ID", required = true, paramType = "path")
|
||||
public Result one(@PathVariable final Integer id) {
|
||||
try {
|
||||
MbConsumption entity = entityService.getById(id);
|
||||
return new Result(true, entity);
|
||||
} catch (Exception e) {
|
||||
LOG.error("查询单个用户消费失败", e);
|
||||
return new Result(false, new MbConsumption());
|
||||
}
|
||||
}
|
||||
|
||||
@SysLog(action = "add", value = "添加用户消费")
|
||||
@ApiOperation(value = "添加用户消费")
|
||||
@RequestMapping(method = {RequestMethod.POST})
|
||||
public Result add(@Valid @RequestBody final MbConsumption entity, final BindingResult result) {
|
||||
try {
|
||||
if (result.hasErrors()) {
|
||||
Map<String, String> map = this.getErrors(result);
|
||||
String errorMsg = map.entrySet().iterator().next().getValue();
|
||||
return new Result(false, "保存用户消费失败", errorMsg, map);
|
||||
} else {
|
||||
entityService.save(entity);
|
||||
return new Result(true, "成功保存用户消费", null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("添加用户消费失败", e);
|
||||
return new Result(false, "保存用户消费失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@SysLog(action = "update", value = "修改用户消费")
|
||||
@ApiOperation(value = "修改用户消费")
|
||||
@RequestMapping(method = {RequestMethod.PUT})
|
||||
public Result update(@Valid @RequestBody final MbConsumption entity, final BindingResult result) {
|
||||
try {
|
||||
if (result.hasErrors()) {
|
||||
Map<String, String> map = this.getErrors(result);
|
||||
String errorMsg = map.entrySet().iterator().next().getValue();
|
||||
return new Result(false, "修改用户消费失败", errorMsg, map);
|
||||
} else {
|
||||
if (null == entity.getId()) {
|
||||
throw new RuntimeException("id不能为空");
|
||||
}
|
||||
entityService.updateById(entity);
|
||||
return new Result(true, "成功修改用户消费", null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("修改用户消费失败", e);
|
||||
return new Result(false, "修改用户消费失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation(value = "全部用户消费")
|
||||
@RequestMapping(value = "all", method = RequestMethod.GET)
|
||||
public Result<List<MbConsumption>> all(MbConsumption example) {
|
||||
List<MbConsumption> entitys = entityService.list(example);
|
||||
if (null != entitys) {
|
||||
return new Result<>(true, entitys);
|
||||
}
|
||||
return new Result<>(true, Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
package com.pixelai.api.pa.controller;
|
||||
|
||||
import com.base.annotation.Unsecured;
|
||||
import com.pixelai.api.component.entity.CpAttachment;
|
||||
import com.pixelai.api.component.entity.CpPhoto;
|
||||
import com.pixelai.api.pa.dao.PaPictureWallMapper;
|
||||
import com.pixelai.api.pa.service.PaVipCurrencyService;
|
||||
import com.pixelai.api.pa.vo.PaPictureWallVo;
|
||||
import com.pixelai.api.picture.vo.AiPictureVo;
|
||||
import com.pixelai.api.user.service.AcUserService;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import com.base.annotation.SysLog;
|
||||
@ -48,6 +51,8 @@ public class PaPictureWallController extends BaseController {
|
||||
private AcUserService acUserService;
|
||||
@Autowired
|
||||
private PaPictureWallMapper paPictureWallMapper;
|
||||
@Autowired
|
||||
private PaVipCurrencyService paVipCurrencyService;
|
||||
|
||||
@SysLog(action = "findByPage", value = "分页查询作品墙")
|
||||
@ApiOperation(value = "分页查询作品墙", notes = "分页查询作品墙")
|
||||
@ -151,4 +156,26 @@ public class PaPictureWallController extends BaseController {
|
||||
return new Result<>(true, Collections.emptyList());
|
||||
}
|
||||
|
||||
@SysLog(action = "PaPictureWall:geiOriginalPicture", value = "购买原图")
|
||||
@ApiOperation(value = "购买原图",notes = "购买原图")
|
||||
@RequestMapping(value="geiOriginalPicture",method = {RequestMethod.GET})
|
||||
public Result<PaPictureWallVo> geiOriginalPicture(Integer id) {
|
||||
Integer userId=acUserService.getUserId();
|
||||
if(userId==null){
|
||||
return new Result(false, "用户未登录");
|
||||
}
|
||||
PaPictureWall paPictureWall=entityService.lambdaQuery()
|
||||
.eq(PaPictureWall::getId,id)
|
||||
.eq(PaPictureWall::getState,"t").one();
|
||||
if (paPictureWall ==null){
|
||||
return new Result(false, "作品不存在");
|
||||
}
|
||||
//进行扣费
|
||||
Boolean state=paVipCurrencyService.consumeOriginalPicture(userId,paPictureWall);
|
||||
if (state==false){
|
||||
return new Result(false, "余额不足");
|
||||
}
|
||||
return new Result(true, paPictureWall);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
package com.pixelai.api.pa.dao;
|
||||
|
||||
import com.pixelai.api.pa.entity.MbConsumption;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author gjj
|
||||
* @since 2024-12-23
|
||||
*/
|
||||
public interface MbConsumptionMapper extends BaseMapper<MbConsumption> {
|
||||
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
package com.pixelai.api.pa.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author gjj
|
||||
* @since 2024-12-23
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@ApiModel(value="MbConsumption", description="")
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MbConsumption implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "用户id")
|
||||
private Integer userId;
|
||||
|
||||
@ApiModelProperty(value = "货币id")
|
||||
private Integer currencyId;
|
||||
|
||||
@ApiModelProperty(value = "变动类型,充值/消费/")
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty(value = "加减")
|
||||
private String addOrSub;
|
||||
|
||||
@ApiModelProperty(value = "数值")
|
||||
private Integer value;
|
||||
|
||||
@ApiModelProperty(value = "描述")
|
||||
private String description;
|
||||
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private Date createtime;
|
||||
|
||||
@ApiModelProperty(value = "状态")
|
||||
private String state;
|
||||
|
||||
public MbConsumption(Integer userId,String type,String addOrSub,Integer value,String description){
|
||||
this.userId=userId;
|
||||
this.type=type;
|
||||
this.addOrSub=addOrSub;
|
||||
this.value=value;
|
||||
this.description=description;
|
||||
this.createtime=new Date();
|
||||
this.state="t";
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@ import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author gjj
|
||||
@ -55,12 +55,26 @@ public class PaConsumption implements Serializable {
|
||||
@ApiModelProperty(value = "服务id")
|
||||
private Integer serviceId;
|
||||
|
||||
public PaConsumption(Integer userid,String addOrSub,Integer value,Integer serviceId){
|
||||
@ApiModelProperty(value = "描述")
|
||||
private String description;
|
||||
|
||||
public PaConsumption(Integer userid,String addOrSub,Integer value,Integer serviceId,String type,String description){
|
||||
this.userid=userid;
|
||||
this.addOrSub=addOrSub;
|
||||
this.value=value;
|
||||
this.serviceId=serviceId;
|
||||
this.type=type;
|
||||
this.createtime=new Date();
|
||||
this.description=description;
|
||||
}
|
||||
|
||||
public PaConsumption(Integer userid,String addOrSub,Integer value,String type,String description){
|
||||
this.userid=userid;
|
||||
this.addOrSub=addOrSub;
|
||||
this.value=value;
|
||||
this.type=type;
|
||||
this.createtime=new Date();
|
||||
this.description=description;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -62,5 +62,7 @@ public class PaPictureWall implements Serializable {
|
||||
@ApiModelProperty(value = "价格")
|
||||
private Integer price;
|
||||
|
||||
|
||||
public String consume(){
|
||||
return "您购买原图消费"+this.price+"钻石";
|
||||
}
|
||||
}
|
||||
|
@ -1,34 +1,34 @@
|
||||
package com.pixelai.api.pa.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.pixelai.api.pa.entity.MbConsumption;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author gjj
|
||||
* @since 2024-12-23
|
||||
*/
|
||||
public interface MbConsumptionService extends IService<MbConsumption> {
|
||||
|
||||
/**
|
||||
* 条件查询
|
||||
* @param example
|
||||
* @return
|
||||
*/
|
||||
List<MbConsumption> list(MbConsumption example);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param example
|
||||
* @param page
|
||||
* @return
|
||||
*/
|
||||
IPage<MbConsumption> page(MbConsumption example,IPage page);
|
||||
|
||||
}
|
||||
//package com.pixelai.api.pa.service;
|
||||
//
|
||||
//import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
//import com.pixelai.api.pa.entity.MbConsumption;
|
||||
//import com.baomidou.mybatisplus.extension.service.IService;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
///**
|
||||
// * <p>
|
||||
// * 服务类
|
||||
// * </p>
|
||||
// *
|
||||
// * @author gjj
|
||||
// * @since 2024-12-23
|
||||
// */
|
||||
//public interface MbConsumptionService extends IService<MbConsumption> {
|
||||
//
|
||||
// /**
|
||||
// * 条件查询
|
||||
// * @param example
|
||||
// * @return
|
||||
// */
|
||||
// List<MbConsumption> list(MbConsumption example);
|
||||
//
|
||||
// /**
|
||||
// * 分页查询
|
||||
// * @param example
|
||||
// * @param page
|
||||
// * @return
|
||||
// */
|
||||
// IPage<MbConsumption> page(MbConsumption example,IPage page);
|
||||
//
|
||||
//}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.pixelai.api.pa.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.pixelai.api.pa.entity.PaPictureWall;
|
||||
import com.pixelai.api.pa.entity.PaServices;
|
||||
import com.pixelai.api.pa.entity.PaVipCurrency;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
@ -17,10 +18,13 @@ import java.util.List;
|
||||
* @since 2024-12-04
|
||||
*/
|
||||
public interface PaVipCurrencyService extends IService<PaVipCurrency> {
|
||||
|
||||
/**
|
||||
* 为当前用户扣除钻石
|
||||
* @param money
|
||||
* 当前用户购买原图扣除钻石
|
||||
* @return
|
||||
*/
|
||||
Boolean consumeOriginalPicture(Integer userId, PaPictureWall paPictureWall);
|
||||
/**
|
||||
* 当前用户使用AI接口扣除钻石
|
||||
* @return
|
||||
*/
|
||||
Boolean consume(Integer userId, PaServices paServices);
|
||||
|
@ -1,55 +0,0 @@
|
||||
package com.pixelai.api.pa.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.pixelai.api.pa.entity.MbConsumption;
|
||||
import com.pixelai.api.pa.dao.MbConsumptionMapper;
|
||||
import com.pixelai.api.pa.service.MbConsumptionService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.pixelai.api.user.entity.AcUser;
|
||||
import com.pixelai.api.user.service.AcUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author gjj
|
||||
* @since 2024-12-23
|
||||
*/
|
||||
@Service
|
||||
public class MbConsumptionServiceImpl extends ServiceImpl<MbConsumptionMapper, MbConsumption> implements MbConsumptionService {
|
||||
@Autowired
|
||||
private AcUserService acUserService;
|
||||
@Override
|
||||
public List<MbConsumption> list(MbConsumption example) {
|
||||
return this.list(buildWrapper(example));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<MbConsumption> page(MbConsumption example, IPage page) {
|
||||
return this.page(page,buildWrapper(example));
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询
|
||||
*
|
||||
* @param example
|
||||
* @return
|
||||
*/
|
||||
private QueryWrapper<MbConsumption> buildWrapper(MbConsumption example) {
|
||||
QueryWrapper<MbConsumption> wrapper = new QueryWrapper<>();
|
||||
Integer userId=acUserService.getUserId();
|
||||
AcUser acuser=acUserService.getById(userId);
|
||||
if (acuser.getAcgroup()!=1){
|
||||
wrapper.lambda().eq(MbConsumption::getUserId,userId);
|
||||
}
|
||||
wrapper.lambda().eq(MbConsumption::getState,"t");
|
||||
wrapper.orderByDesc("createtime");
|
||||
return wrapper;
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.base.context.Context;
|
||||
import com.base.context.ContextHolder;
|
||||
import com.pixelai.api.pa.entity.PaConsumption;
|
||||
import com.pixelai.api.pa.entity.PaPictureWall;
|
||||
import com.pixelai.api.pa.entity.PaServices;
|
||||
import com.pixelai.api.pa.entity.PaVipCurrency;
|
||||
import com.pixelai.api.pa.dao.PaVipCurrencyMapper;
|
||||
@ -44,7 +45,23 @@ public class PaVipCurrencyServiceImpl extends ServiceImpl<PaVipCurrencyMapper, P
|
||||
//消费
|
||||
paVipCurrency.setNumerical(balance-paServices.getPrice());
|
||||
this.updateById(paVipCurrency);
|
||||
PaConsumption paConsumption=new PaConsumption(acUserService.getUserId(),"sub",paServices.getPrice(),paServices.getId());
|
||||
PaConsumption paConsumption=new PaConsumption(acUserService.getUserId(),"sub",paServices.getPrice(),paServices.getId(),"AI能力消费",paServices.consume());
|
||||
paConsumptionService.save(paConsumption);
|
||||
return true;
|
||||
}
|
||||
|
||||
public Boolean consumeOriginalPicture(Integer userId, PaPictureWall paPictureWall) {
|
||||
PaVipCurrency paVipCurrency=this.lambdaQuery().eq(PaVipCurrency::getUserid,userId)
|
||||
.eq(PaVipCurrency::getState,"t").one();
|
||||
//余额不足
|
||||
Integer balance=paVipCurrency.getNumerical();
|
||||
if ( balance< paPictureWall.getPrice()){
|
||||
return false;
|
||||
}
|
||||
//消费
|
||||
paVipCurrency.setNumerical(balance-paPictureWall.getPrice());
|
||||
this.updateById(paVipCurrency);
|
||||
PaConsumption paConsumption=new PaConsumption(acUserService.getUserId(),"sub",paPictureWall.getPrice(),"购买原图消费",paPictureWall.consume());
|
||||
paConsumptionService.save(paConsumption);
|
||||
return true;
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public class AiPictureController {
|
||||
@Autowired
|
||||
private CpPhotoService cpPhotoService;
|
||||
@Autowired
|
||||
private MbConsumptionService mbConsumptionService;
|
||||
private PaConsumptionService paConsumptionService;
|
||||
@Autowired
|
||||
private CpAttachmentService cpAttachmentService;
|
||||
|
||||
@ -83,10 +83,7 @@ public class AiPictureController {
|
||||
|
||||
//进行扣费并记录日志
|
||||
Boolean pay=paVipCurrencyService.consume(userId,paServices);
|
||||
if (pay){
|
||||
MbConsumption mbConsumption=new MbConsumption(userId,paServices.getName(),"sub",paServices.getPrice(),paServices.consume());
|
||||
mbConsumptionService.save(mbConsumption);
|
||||
}else{
|
||||
if (!pay){
|
||||
return new Result(false, "余额不足", "余额不足");
|
||||
}
|
||||
//预记录生成图片位置
|
||||
|
@ -165,10 +165,10 @@ public class AcUserServiceImpl extends ServiceImpl<AcUserMapper, AcUser> impleme
|
||||
paVipLevel.setExperience(0);
|
||||
paVipLevel.setState("t");
|
||||
paVipLevelService.save(paVipLevel);
|
||||
//默认分配1000钻石
|
||||
//默认分配0钻石
|
||||
PaVipCurrency paVipCurrency=new PaVipCurrency();
|
||||
paVipCurrency.setUserid(user.getId());
|
||||
paVipCurrency.setNumerical(1000);
|
||||
paVipCurrency.setNumerical(0);//默认分配0钻石
|
||||
paVipCurrency.setState("t");
|
||||
paVipCurrencyService.save(paVipCurrency);
|
||||
return new Result<>(true,"注册成功");
|
||||
|
@ -75,6 +75,8 @@ aliyun:
|
||||
|
||||
# 火山引擎配置
|
||||
volcengine:
|
||||
ArkApiKey: 036e5187-8625-41cd-87e6-3325296582f1
|
||||
Model: ep-20250121122940-tbf2p
|
||||
AccessKeyID: AKLTZWYwOWQ4Y2VlZmViNGU4MWI3YzY5NWQ3NTVkNzFjNWU
|
||||
SecretAccessKey: WVdJeU9XTXlZVE00TXpka05HUmhabUU1TXpjME16RTJPRGsyWkRjM1pUZw==
|
||||
|
||||
|
@ -85,6 +85,8 @@ aliyun:
|
||||
|
||||
# 火山引擎配置
|
||||
volcengine:
|
||||
ArkApiKey: 036e5187-8625-41cd-87e6-3325296582f1
|
||||
Model: ep-20250121122940-tbf2p
|
||||
AccessKeyID: AKLTZWYwOWQ4Y2VlZmViNGU4MWI3YzY5NWQ3NTVkNzFjNWU
|
||||
SecretAccessKey: WVdJeU9XTXlZVE00TXpka05HUmhabUU1TXpjME16RTJPRGsyWkRjM1pUZw==
|
||||
|
||||
|
@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.pixelai.api.pa.dao.MbConsumptionMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.pixelai.api.pa.entity.MbConsumption">
|
||||
<id column="id" property="id" />
|
||||
<result column="user_id" property="userId" />
|
||||
<result column="currency_id" property="currencyId" />
|
||||
<result column="type" property="type" />
|
||||
<result column="add_or_sub" property="addOrSub" />
|
||||
<result column="value" property="value" />
|
||||
<result column="description" property="description" />
|
||||
<result column="createtime" property="createtime" />
|
||||
<result column="state" property="state" />
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, user_id, currency_id, type, add_or_sub, value, description, createtime, state
|
||||
</sql>
|
||||
|
||||
</mapper>
|
@ -33,7 +33,9 @@
|
||||
upload_name,
|
||||
label_name,
|
||||
price,
|
||||
service_name
|
||||
service_name,
|
||||
serviceId,
|
||||
number
|
||||
from (select
|
||||
pa_picture_wall.id,
|
||||
pa_picture_wall.name,
|
||||
@ -42,10 +44,12 @@
|
||||
pa_picture_wall.size,
|
||||
pa_picture_wall.createtime,
|
||||
pa_picture_wall.state as state,
|
||||
pa_picture_wall.number as number,
|
||||
ac_user.realname as upload_name,
|
||||
cp_label.name as label_name,
|
||||
pa_picture_wall.price as price,
|
||||
pa_services.name as service_name
|
||||
pa_services.name as service_name,
|
||||
pa_services.id as serviceId
|
||||
from pa_picture_wall
|
||||
left join ac_user on pa_picture_wall.userid=ac_user.id
|
||||
left join cp_label on pa_picture_wall.cp_label_id =cp_label.id
|
||||
@ -59,7 +63,7 @@
|
||||
pa_picture_wall.id,
|
||||
pa_picture_wall.name,
|
||||
pa_picture_wall.watermark_path,
|
||||
pa_picture_wall.original_path,
|
||||
-- pa_picture_wall.original_path,
|
||||
pa_picture_wall.size,
|
||||
pa_picture_wall.createtime,
|
||||
pa_picture_wall.state as state,
|
||||
|
Loading…
Reference in New Issue
Block a user