package com.ssm.manage.service.impl;

import com.github.pagehelper.PageInfo;
import com.ssm.core.service.impl.BaseServiceImpl;
import com.ssm.core.utils.SnowflakeUtil;
import com.ssm.manage.dao.SsmSysGlobalParaDao;
import com.ssm.manage.entity.SysGlobalParameters;
import com.ssm.manage.query.GlobalParaRequest;
import com.ssm.manage.service.SsmSysGlobalParaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Random;

@Service
public class SsmSysGlobalParaServiceImpl extends BaseServiceImpl<SysGlobalParameters> implements SsmSysGlobalParaService {
    @Autowired
    private SsmSysGlobalParaDao dao;

    @Override
    public SsmSysGlobalParaDao getDao() {
        return dao;
    }

    @Override
    public PageInfo<SysGlobalParameters> selectPage(GlobalParaRequest globalParaRequest) {
        return dao.selectPage(globalParaRequest);
    }

    @Override
    public int addGlobalPara(GlobalParaRequest globalParaRequest) {
        SysGlobalParameters globalParameters = new SysGlobalParameters();
        globalParameters.setId(new SnowflakeUtil(new Random().nextInt(1023)).nextId());
        globalParameters.setParametersName(globalParaRequest.getParametersName());
        globalParameters.setParametersValues(globalParaRequest.getParametersValues());
        return dao.saveNotNull(globalParameters);
    }

    @Override
    public int deleteGlobalPara(GlobalParaRequest globalParaRequest) {
        SysGlobalParameters globalParameters = new SysGlobalParameters();
        globalParameters.setId(globalParaRequest.getId());
        return dao.deleteByPrimaryKey(globalParameters);
    }


    @Override
    public int updateGlobalPara(GlobalParaRequest globalParaRequest) {
        SysGlobalParameters globalParameters = new SysGlobalParameters();
        globalParameters.setId(globalParaRequest.getId());
        globalParameters.setParametersValues(globalParaRequest.getParametersValues());
        return dao.updateByPrimaryKeySelective(globalParameters);
    }
}
