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

import com.steerinfo.framework.controller.RESTfulResult;
import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.meterwork.meterworkrailwayreceived.model.MeterWorkRailwayReceived;
import com.steerinfo.meterwork.meterworkrailwayreceived.mapper.MeterWorkRailwayReceivedMapper;
import com.steerinfo.meterwork.meterworkrailwayreceived.service.IMeterWorkRailwayReceivedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

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

    @Autowired
    private MeterWorkRailwayReceivedMapper meterWorkRailwayReceivedMapper;

    @Override
    protected IBaseMapper<MeterWorkRailwayReceived, String> getMapper() {
        return meterWorkRailwayReceivedMapper;
    }

    @Override
    public RESTfulResult checkandadd(MeterWorkRailwayReceived model) throws Exception {
        try{
            RESTfulResult rm = new RESTfulResult();
            rm.setCode("200");
            rm.setData(model.getActualFirstNo());
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            String afl = sdf.format(new Date());
            String no = meterWorkRailwayReceivedMapper.getNewID(afl);
            model.setActualFirstNo(sdf.format(new Date()) + no);
            meterWorkRailwayReceivedMapper.insertSelective(model);
            rm.setMessage("成功");
            return rm;
        }
        catch (Exception e){
            throw e;
        }
    }
}
