package com.qmth.ops.biz.service; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.qmth.boot.core.ai.model.llm.LlmAppType; import com.qmth.ops.biz.dao.LlmOrgConfigDao; import com.qmth.ops.biz.domain.LlmOrgConfig; import com.qmth.ops.biz.domain.LlmPromptTemplate; import com.qmth.ops.biz.query.LlmOrgConfigQuery; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; @Service public class LlmOrgConfigService extends ServiceImpl { @Resource private LlmOrgConfigDao llmOrgConfigDao; public IPage query(LlmOrgConfigQuery query) { return llmOrgConfigDao.findByQuery(query); } public int countByPromptTemplate(LlmPromptTemplate template) { return llmOrgConfigDao .selectCount(new LambdaQueryWrapper().eq(LlmOrgConfig::getPromptId, template.getId())); } public LlmOrgConfig findByOrgAndAppType(Long orgId, LlmAppType appType) { return llmOrgConfigDao.selectOne(new LambdaQueryWrapper().eq(LlmOrgConfig::getOrgId, orgId) .eq(LlmOrgConfig::getAppType, appType)); } @Transactional public void updateModelAndPrompt(LlmOrgConfig llmOrgConfig) { llmOrgConfigDao.update(llmOrgConfig, new LambdaUpdateWrapper().set(LlmOrgConfig::getModelId, llmOrgConfig.getModelId()) .set(LlmOrgConfig::getPromptId, llmOrgConfig.getPromptId()) .eq(LlmOrgConfig::getOrgId, llmOrgConfig.getOrgId()) .eq(LlmOrgConfig::getAppType, llmOrgConfig.getAppType())); } @Transactional public void permit(LlmOrgConfig llmOrgConfig, int count) { llmOrgConfigDao.permit(llmOrgConfig.getOrgId(), llmOrgConfig.getAppType(), count); } @Transactional public void consume(LlmOrgConfig llmOrgConfig) { llmOrgConfigDao.consume(llmOrgConfig.getOrgId(), llmOrgConfig.getAppType()); } }