LlmOrgConfigService.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package com.qmth.ops.biz.service;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  4. import com.baomidou.mybatisplus.core.metadata.IPage;
  5. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  6. import com.qmth.boot.core.ai.model.llm.LlmAppType;
  7. import com.qmth.ops.biz.dao.LlmOrgConfigDao;
  8. import com.qmth.ops.biz.domain.LlmOrgConfig;
  9. import com.qmth.ops.biz.domain.LlmPromptTemplate;
  10. import com.qmth.ops.biz.query.LlmOrgConfigQuery;
  11. import org.springframework.stereotype.Service;
  12. import org.springframework.transaction.annotation.Transactional;
  13. import javax.annotation.Resource;
  14. @Service
  15. public class LlmOrgConfigService extends ServiceImpl<LlmOrgConfigDao, LlmOrgConfig> {
  16. @Resource
  17. private LlmOrgConfigDao llmOrgConfigDao;
  18. public IPage<LlmOrgConfig> query(LlmOrgConfigQuery query) {
  19. return llmOrgConfigDao.findByQuery(query);
  20. }
  21. public int countByPromptTemplate(LlmPromptTemplate template) {
  22. return llmOrgConfigDao
  23. .selectCount(new LambdaQueryWrapper<LlmOrgConfig>().eq(LlmOrgConfig::getPromptId, template.getId()));
  24. }
  25. public LlmOrgConfig findByOrgAndAppType(Long orgId, LlmAppType appType) {
  26. return llmOrgConfigDao.selectOne(new LambdaQueryWrapper<LlmOrgConfig>().eq(LlmOrgConfig::getOrgId, orgId)
  27. .eq(LlmOrgConfig::getAppType, appType));
  28. }
  29. @Transactional
  30. public void updateModelAndPrompt(LlmOrgConfig llmOrgConfig) {
  31. llmOrgConfigDao.update(llmOrgConfig,
  32. new LambdaUpdateWrapper<LlmOrgConfig>().set(LlmOrgConfig::getModelId, llmOrgConfig.getModelId())
  33. .set(LlmOrgConfig::getPromptId, llmOrgConfig.getPromptId())
  34. .eq(LlmOrgConfig::getOrgId, llmOrgConfig.getOrgId())
  35. .eq(LlmOrgConfig::getAppType, llmOrgConfig.getAppType()));
  36. }
  37. @Transactional
  38. public void permit(LlmOrgConfig llmOrgConfig, int count) {
  39. llmOrgConfigDao.permit(llmOrgConfig.getOrgId(), llmOrgConfig.getAppType(), count);
  40. }
  41. @Transactional
  42. public void consume(LlmOrgConfig llmOrgConfig) {
  43. llmOrgConfigDao.consume(llmOrgConfig.getOrgId(), llmOrgConfig.getAppType());
  44. }
  45. }