package com.steerinfo.meterwork.meterworkmeasuringinstrument.service.impl;

import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.framework.user.UserPayload;
import com.steerinfo.meterwork.meterworkmeasuringinstrument.model.MeterWorkMeasuringInstrument;
import com.steerinfo.meterwork.meterworkmeasuringinstrument.mapper.MeterWorkMeasuringInstrumentMapper;
import com.steerinfo.meterwork.meterworkmeasuringinstrument.service.IMeterWorkMeasuringInstrumentService;
import com.steerinfo.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.math.BigDecimal;

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

    @Autowired
    private MeterWorkMeasuringInstrumentMapper meterWorkMeasuringInstrumentMapper;

    @Override
    protected IBaseMapper<MeterWorkMeasuringInstrument, String> getMapper() {
        return meterWorkMeasuringInstrumentMapper;
    }

    @Override
    public String checkandadd(MeterWorkMeasuringInstrument model) {
        if (StringUtils.isEmpty(model.getRailwayNo())) {
            return "车号不能为空";
        }
        if (StringUtils.isEmpty(model.getMatterName())){
            return "物资名称不能为空";
        }
        if(model.getNetWeight() == null){
            return "净重不能为空";
        }
        if(model.getGrossWeight() == null){
            return "毛重不能为空";
        }
        if(model.getTareWeight() == null){
            return "皮重不能为空";
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String afl = sdf.format(new Date());
        String actualFirstNo = sdf.format(new Date()) + meterWorkMeasuringInstrumentMapper.getNewID(afl);
        UserPayload payload = UserPayload.getCurrUser();
        String userName = payload.getUserName();
//            String userId = "admin";
//            String userName = "admins";
        model.setCreateManName(userName);
        model.setCreateTime(new Date());
        model.setActualNo(actualFirstNo);
        meterWorkMeasuringInstrumentMapper.insertSelective(model);
        return "";
    }
}
