package com.jisco.dynamicweight.dynamicbasebatchdbconfig.service.impl;

import cn.hutool.core.lang.Assert;
import com.jisco.dynamicweight.dynamicbasebatchdbconfig.mapper.DynamicBaseBatchdbConfigMapper;
import com.jisco.dynamicweight.dynamicbasebatchdbconfig.model.DynamicBaseBatchdbConfig;
import com.jisco.dynamicweight.util.UserUtil;
import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.jisco.dynamicweight.dynamicbasebatchdbconfig.service.IDynamicBaseBatchdbConfigService;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.math.BigDecimal;
import java.util.List;

/**
 * DynamicBaseBatchdbConfig服务实现：
 *
 * @author generator
 * @version 1.0-SNAPSHORT 2021-12-24 08:42
 * 类描述
 * 修订历史：
 * 日期：2021-12-24
 * 作者：generator
 * 参考：
 * 描述：DynamicBaseBatchdbConfig服务实现
 * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
 * @see null
 */
@Service(value = "dynamicBaseBatchdbConfigService")
public class DynamicBaseBatchdbConfigServiceImpl extends BaseServiceImpl<DynamicBaseBatchdbConfig, String> implements IDynamicBaseBatchdbConfigService {

    @Autowired
    private DynamicBaseBatchdbConfigMapper dynamicBaseBatchdbConfigMapper;

    @Override
    protected IBaseMapper<DynamicBaseBatchdbConfig, String> getMapper() {
        return dynamicBaseBatchdbConfigMapper;
    }

    @Override
    public boolean enable(String id) {
        DynamicBaseBatchdbConfig byId = this.getById(id);
        Assert.notNull(byId, "记录不存在");
        if (byId.getValidFlag().equals("1")) return false;
        DynamicBaseBatchdbConfig config = new DynamicBaseBatchdbConfig();
        config.setConfigNo(id);
        setUpdateManInfo(config);
        return dynamicBaseBatchdbConfigMapper.enable(config) == 1;
    }

    private void setUpdateManInfo(DynamicBaseBatchdbConfig config) {
        config.setUpdateManNo(UserUtil.getCurrentUserId());
        config.setUpdateManName(UserUtil.getCurrentUserName());
        config.setUpdateTime(new Date());
    }

    @Override
    public boolean disable(String id) {
        DynamicBaseBatchdbConfig byId = this.getById(id);
        if (byId.getValidFlag() == "0") return false;
        DynamicBaseBatchdbConfig config = new DynamicBaseBatchdbConfig();
        config.setConfigNo(id);
        setUpdateManInfo(config);
        return dynamicBaseBatchdbConfigMapper.disable(config) == 1;
    }
}
