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

import cn.hutool.core.lang.Assert;
import com.jisco.dynamicweight.dynamicbasematerial.model.DynamicBaseMaterial;
import com.jisco.dynamicweight.util.UserUtil;
import com.steerinfo.baseinfo.meterbasecalibrarelation.model.MeterBaseCalibraRelation;
import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.jisco.dynamicweight.dynamicbasesender.model.DynamicBaseSender;
import com.jisco.dynamicweight.dynamicbasesender.mapper.DynamicBaseSenderMapper;
import com.jisco.dynamicweight.dynamicbasesender.service.IDynamicBaseSenderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;

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

    @Autowired
    private DynamicBaseSenderMapper dynamicBaseSenderMapper;

    @Override
    protected IBaseMapper<DynamicBaseSender, String> getMapper() {
        return dynamicBaseSenderMapper;
    }

    @Override
    public List<MeterBaseCalibraRelation> queryall(HashMap parmas) {
        return dynamicBaseSenderMapper.selectByParameters(parmas);
    }
    /**
     * 启用
     * @param id
     * @return
     */
    @Override
    public boolean enable(String id) {
        DynamicBaseSender byId = this.getById(id);
        Assert.notNull(byId, "记录不存在");
        if (byId.getValidFlag().equals("1")) return false;
        DynamicBaseSender config = new DynamicBaseSender();
        config.setSenderNo(id);
        setUpdateManInfo(config);
        return dynamicBaseSenderMapper.enable(config) == 1;
    }

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

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