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

import cn.hutool.core.lang.Assert;
import com.jisco.dynamicweight.dynamicbasebatchstation.model.DynamicBaseBatchStation;
import com.jisco.dynamicweight.dynamicbasescstation.mapper.DynamicBaseScStationMapper;
import com.jisco.dynamicweight.dynamicbasescstation.model.DynamicBaseScStation;
import com.jisco.dynamicweight.dynamicbasescstation.service.IDynamicBaseScStationService;
import com.jisco.dynamicweight.util.UserUtil;
import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * DynamicBaseScStation服务实现：
 * @author generator
 * @version 1.0-SNAPSHORT 2022-01-05 11:28
 * 类描述
 * 修订历史：
 * 日期：2022-01-05
 * 作者：generator
 * 参考：
 * 描述：DynamicBaseScStation服务实现
 * @see null
 * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
 */
@Service(value = "dynamicBaseScStationService")
public class DynamicBaseScStationServiceImpl extends BaseServiceImpl<DynamicBaseScStation, String> implements IDynamicBaseScStationService {

    @Autowired
    private DynamicBaseScStationMapper dynamicBaseScStationMapper;

    @Override
    protected IBaseMapper<DynamicBaseScStation, String> getMapper() {
        return dynamicBaseScStationMapper;
    }

    /**
     * 启用
     * @param id
     * @return
     */
    @Override
    public boolean enable(String id) {
        DynamicBaseScStation byId = this.getById(id);
        Assert.notNull(byId, "记录不存在");
        if (byId.getValidFlag().equals("1")) return false;
        DynamicBaseScStation config = new DynamicBaseScStation();
        config.setStationNo(id);
        setUpdateManInfo(config);
        return dynamicBaseScStationMapper.enable(config) == 1;
    }

    /**
     * 禁用
     * @param id
     * @return
     */
    @Override
    public boolean disable(String id) {
        DynamicBaseScStation byId = this.getById(id);
        if (byId.getValidFlag() == "0") return false;
        DynamicBaseScStation config = new DynamicBaseScStation();
        config.setStationNo(id);
        setUpdateManInfo(config);
        return dynamicBaseScStationMapper.disable(config) == 1;
    }

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