IBZConfigService.java.ftl 3.4 KB
Newer Older
sq3536's avatar
sq3536 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
<#ibiztemplate>
TARGET=PSSYSTEM
</#ibiztemplate>
package ${pub.getPKGCodeName()}.util.service;

import ${pub.getPKGCodeName()}.util.domain.IBZConfig;
import ${pub.getPKGCodeName()}.util.errors.BadRequestAlertException;
import ${pub.getPKGCodeName()}.util.helper.DataObject;
import ${pub.getPKGCodeName()}.util.mapper.IBZConfigMapper;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Slf4j
@Service
public class IBZConfigService extends ServiceImpl<IBZConfigMapper, IBZConfig> implements IService<IBZConfig> {
25 26 27 28 29
<#if sys.getPSSystemSetting()?? && sys.getPSSystemSetting().getDataAccCtrlArch()?? && sys.getPSSystemSetting().getDataAccCtrlArch()==1>
    <#assign cachename="ibzrt_configs">
<#else >
    <#assign cachename=pub.getCodeName()?lower_case+"_configs">
</#if>
sq3536's avatar
sq3536 committed
30 31 32 33

    @Value("${r'${'}ibiz.systemid:${sys.getName()}}")
	private String systemId;

34 35 36
    @Value("${r'${'}ibiz.admin.userid:0100}")
    private String adminuserid;

37
    @Cacheable( value="${cachename}",key = "'cfgid:'+#p0+'||'+#p1+'||'+#p2")
sq3536's avatar
sq3536 committed
38 39 40 41 42
    public JSONObject getConfig(String cfgType,String targetType,String userId)
    {
        if(StringUtils.isEmpty(userId)||StringUtils.isEmpty(cfgType)||StringUtils.isEmpty(targetType))
            throw new BadRequestAlertException("获取配置失败,参数缺失","IBZConfig",cfgType);
        IBZConfig config=this.getOne(Wrappers.query(IBZConfig.builder().systemId(systemId).cfgType(cfgType).targetType(targetType).userId(userId).build()),false);
43 44 45 46 47 48 49
        if(config==null) {
            config=this.getOne(Wrappers.query(IBZConfig.builder().systemId(systemId).cfgType(cfgType).targetType(targetType).userId(adminuserid).build()),false);
            if(config==null) {
                return new JSONObject();
            }
        }
        return JSON.parseObject(config.getCfg());
sq3536's avatar
sq3536 committed
50 51
    }

52
    @CacheEvict( value="${cachename}",key = "'cfgid:'+#p0+'||'+#p1+'||'+#p2")
sq3536's avatar
sq3536 committed
53 54 55 56 57 58 59 60 61 62
    public boolean saveConfig(String cfgType,String targetType,String userId,JSONObject config)
    {
        if(StringUtils.isEmpty(userId)||StringUtils.isEmpty(cfgType)||StringUtils.isEmpty(targetType))
            throw new BadRequestAlertException("保存配置失败,参数缺失","IBZConfig",cfgType);
        String cfg="{}";
        if(config!=null)
            cfg=JSONObject.toJSONString(config);
        return this.saveOrUpdate(IBZConfig.builder().systemId(systemId).cfgType(cfgType).targetType(targetType).userId(userId).cfg(cfg).updateDate(DataObject.getNow()).build());
    }

63
    @CacheEvict( value="${cachename}",key = "'cfgid:'+#p0+'||'+#p1+'||'+#p2")
sq3536's avatar
sq3536 committed
64 65 66 67 68 69 70 71
    public void resetConfig(String cfgType,String targetType,String userId)
    {
        if(StringUtils.isEmpty(userId)||StringUtils.isEmpty(cfgType)||StringUtils.isEmpty(targetType))
            throw new BadRequestAlertException("重置配置失败,参数缺失","IBZConfig",cfgType);
        this.remove(Wrappers.query(IBZConfig.builder().systemId(systemId).cfgType(cfgType).targetType(targetType).userId(userId).build()));
    }

}