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

import com.steerinfo.baseinfo.meterbasematterinfo.model.MeterBaseMatterInfo;
import com.steerinfo.baseinfo.meterbasematterinfodirect.model.MeterBaseMatterInfoDirect;
import com.steerinfo.framework.controller.RESTfulResult;
import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.baseinfo.meterbaseunitdirect.model.MeterBaseUnitDirect;
import com.steerinfo.baseinfo.meterbaseunitdirect.mapper.MeterBaseUnitDirectMapper;
import com.steerinfo.baseinfo.meterbaseunitdirect.service.IMeterBaseUnitDirectService;
import com.steerinfo.framework.user.UserPayload;
import com.steerinfo.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;

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

    @Resource
    private MeterBaseUnitDirectMapper meterBaseUnitDirectMapper;

    @Override
    protected IBaseMapper<MeterBaseUnitDirect, String> getMapper() {
        return meterBaseUnitDirectMapper;
    }

    @Override
    public String checkandadd(MeterBaseUnitDirect model) {
        if (StringUtils.isEmpty(model.getCarrierUnitName())) {
            return "承运单位名称不能为空";
        }
        if (StringUtils.isEmpty(model.getUnitType())){
            return "单位类型不能为空";
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String afl = sdf.format(new Date());
        String no = meterBaseUnitDirectMapper.GetNewID(afl);
        model.setCarrierUnitNo(afl + no);
        model.setCreateTime(new Date());
        model.setValidFlag("1");//有效
        meterBaseUnitDirectMapper.insert(model);
        return "";
    }

    @Override
    public String checkandupdate(String id, MeterBaseUnitDirect model) {
        if (model.getCarrierUnitName() == null || model.getCarrierUnitName().equals("")) {
            return "承运单位名称不能为空";
        }
        if (StringUtils.isEmpty(model.getUnitType())){
            return "单位类型不能为空";
        }
        model.setUpdateTime(new Date());
        meterBaseUnitDirectMapper.updateByPrimaryKey(model);
        return "";
    }
}
