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.SsmSysBusinessParaDao;
import com.ssm.manage.dao.SsmSysGlobalParaDao;
import com.ssm.manage.entity.SysBusinessParameters;
import com.ssm.manage.entity.SysGlobalParameters;
import com.ssm.manage.query.BusinessParaRequest;
import com.ssm.manage.query.GlobalParaRequest;
import com.ssm.manage.service.SsmSysBusinessParaService;
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 SsmSysBusinessParaServiceImpl extends BaseServiceImpl<SysBusinessParameters> implements SsmSysBusinessParaService {
    @Autowired
    private SsmSysBusinessParaDao dao;

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

    @Override
    public PageInfo<SysBusinessParameters> selectPage(BusinessParaRequest businessParaRequest) {
        return dao.selectPage(businessParaRequest);
    }

    @Override
    public int addGlobalPara(BusinessParaRequest businessParaRequest) {
        SysBusinessParameters businessParameters = new SysBusinessParameters();
        businessParameters.setId(new SnowflakeUtil(new Random().nextInt(1023)).nextId());
        businessParameters.setParametersName(businessParaRequest.getParametersName());
        businessParameters.setParametersValues(businessParaRequest.getParametersValues());
        return dao.saveNotNull(businessParameters);
    }

    @Override
    public int deleteGlobalPara(BusinessParaRequest businessParaRequest) {
        SysBusinessParameters businessParameters = new SysBusinessParameters();
        businessParameters.setId(businessParaRequest.getId());
        return dao.deleteByPrimaryKey(businessParameters);
    }


    @Override
    public int updateGlobalPara(BusinessParaRequest businessParaRequest) {
        SysBusinessParameters businessParameters = new SysBusinessParameters();
        businessParameters.setId(businessParaRequest.getId());
        businessParameters.setParametersValues(businessParaRequest.getParametersValues());
        return dao.updateByPrimaryKeySelective(businessParameters);
    }
}
