SysConfigServiceImpl.java 2.34 KB
package com.diligrp.website.service.impl;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import com.diligrp.website.domain.SysConfig;
import com.diligrp.website.manager.SysConfigManager;
import com.diligrp.website.service.SysConfigService;
import com.diligrp.website.util.dao.BaseQuery;
import com.diligrp.website.util.domain.Result;
import com.diligrp.website.util.format.DateFormatUtils;
import com.diligrp.website.util.web.PageTemplate;

@Component("sysConfigService")
public class SysConfigServiceImpl implements SysConfigService {

    @Resource
    private SysConfigManager sysConfigManager;

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

    @Override
    public PageTemplate getSysConfigList(BaseQuery query) {
        return sysConfigManager.getSysConfigList(query);
    }

    @Override
    public Result addSysConfig(SysConfig cfg) {
        if (cfg == null) {
            return Result.create(false).setMsg("参数错误!");
        }
        if (StringUtils.isEmpty(cfg.getConfigCode())
                || StringUtils.isEmpty(cfg.getConfigName())
                || StringUtils.isEmpty(cfg.getValue())) {
            return Result.create(false).setMsg("必填参数为空");
        }
        cfg.setCreated(DateFormatUtils.currTimestamp());
        cfg.setModified(DateFormatUtils.currTimestamp());
        cfg.setYn(1);
        return sysConfigManager.addSysConfig(cfg);
    }

    @Override
    public Result getSysConfigById(Integer id) {
        SysConfig cfg = sysConfigManager.getSysConfigById(id);
        if (cfg == null) {
            return Result.create(false).setMsg("预制变量不存在");
        }
        return Result.create().addResult("cfg", cfg);
    }

    @Override
    public Result editSysConfig(SysConfig cfg) {
        if (cfg == null) {
            return Result.create(false).setMsg("参数错误!");
        }
        if (StringUtils.isEmpty(cfg.getConfigCode())
                || StringUtils.isEmpty(cfg.getConfigName())
                || StringUtils.isEmpty(cfg.getValue())) {
            return Result.create(false).setMsg("必填参数为空");
        }
        cfg.setModified(DateFormatUtils.currTimestamp());
        return sysConfigManager.editSysConfig(cfg);
    }

}