SysConfigManagerImpl.java 2.33 KB
package com.diligrp.website.manager.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.diligrp.website.dao.SysConfigDao;
import com.diligrp.website.domain.SysConfig;
import com.diligrp.website.manager.SysConfigManager;
import com.diligrp.website.manager.cache.SysConfigCache;
import com.diligrp.website.util.dao.BaseQuery;
import com.diligrp.website.util.domain.Result;
import com.diligrp.website.util.web.PageTemplate;

@Component("sysConfigManager")
public class SysConfigManagerImpl implements SysConfigManager {

    @Resource
    private SysConfigDao sysConfigDao;
    
    @Resource
    private SysConfigCache sysConfigCache;

    @Override
    public SysConfig getSysConfigByCode(String code) {
        return sysConfigCache.getSysConfig(code);
    }

    @Override
    public PageTemplate getSysConfigList(BaseQuery query) {
        Integer totalSize = sysConfigDao.getSysConfigListCount(query);
        List<SysConfig> list = sysConfigDao.getSysConfigList(query);
        return PageTemplate.create(query, totalSize, list);
    }

    @Override
    public Result addSysConfig(SysConfig cfg) {
        SysConfig dbCfg = sysConfigDao.getSysConfigByCode(cfg.getConfigCode());
        if (dbCfg != null) {
            return Result.create(false).setMsg("变量编码“" + cfg.getConfigCode() + "”已经存在了");
        }
        boolean flag = sysConfigDao.saveSysConfig(cfg);
        Result rst = Result.create(flag);
        if (!flag) {
            rst.setMsg("添加变量失败");
        }
        return rst;
    }

    @Override
    public SysConfig getSysConfigById(Integer id) {
        return sysConfigDao.getSysConfigById(id);
    }

    @Override
    @Transactional
    public Result editSysConfig(SysConfig cfg) {
        SysConfig dbCfg = sysConfigDao.getSysConfigByCode(cfg.getConfigCode());
        if (dbCfg == null) {
            return Result.create(false).setMsg("变量已经存在了");
        }
        cfg.setId(dbCfg.getId());
        cfg.setYn(dbCfg.getYn());
        sysConfigCache.clearSysConfig(cfg.getId());
        boolean flag = sysConfigDao.editSysConfig(cfg);
        Result rst = Result.create(flag);
        if (!flag) {
            rst.setMsg("修改失败");
        }
        return rst;
    }
}