package com.steerinfo.baseinfo.meterbasemetertypeconf.service.impl;

import com.steerinfo.baseinfo.meterbasespotinfo.model.MeterBaseSpotInfo;
import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.baseinfo.meterbasemetertypeconf.model.MeterBaseMetertypeConf;
import com.steerinfo.baseinfo.meterbasemetertypeconf.mapper.MeterBaseMetertypeConfMapper;
import com.steerinfo.baseinfo.meterbasemetertypeconf.service.IMeterBaseMetertypeConfService;
import com.steerinfo.framework.user.UserPayload;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.math.BigDecimal;

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

    @Autowired
    private MeterBaseMetertypeConfMapper meterBaseMetertypeConfMapper;

    @Override
    protected IBaseMapper<MeterBaseMetertypeConf, String> getMapper() {
        return meterBaseMetertypeConfMapper;
    }

    @Override
    public String checkandadd(MeterBaseMetertypeConf model) {
        if (model.getMeterTypeNo() == null || "".equals(model.getMeterTypeNo()) || model.getMeterTypeName() == null || "".equals(model.getMeterTypeName())) {
            return "业务类型名称及编码不能为空";
        }
        if (model.getSpotTypeNo() == null || "".equals(model.getSpotTypeNo()) || model.getSpotTypeName() == null || "".equals(model.getSpotTypeName())) {
            return "业务类型分类名称及编码不能为空";
        }
        if (model.getIsAllowOwnTare() == null || "".equals(model.getIsAllowOwnTare())) {
            return "是否允许使用自重不能为空";
        }
        if (model.getIsAllowTermTare() == null || "".equals(model.getIsAllowTermTare())) {
            return "是否允许使用期限皮重不能为空";
        }
        UserPayload payload = UserPayload.getCurrUser();
        String userId = payload.getUserCode();
        String userName = payload.getUserName();
        model.setCreateTime(new Date());
        model.setCreateManName(userName);
        model.setCreateManName(userId);
        // 校验当前业务类型是否已经配置
        MeterBaseMetertypeConf confquery = meterBaseMetertypeConfMapper.selectByPrimaryKey(model.getMeterTypeNo());
        if (confquery != null) {
            return "该业务类型已经新增了配置，请在原有配置信息上进行修改";
        }
        meterBaseMetertypeConfMapper.insert(model);
        return "";
    }
}
