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

import cn.hutool.core.lang.Assert;
import com.steerinfo.framework.controller.RESTfulResult;
import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.meterwork.meterworkcaractfirstbak.mapper.MeterWorkCarActFirstBakMapper;
import com.steerinfo.meterwork.meterworkcaractfirstbak.model.MeterWorkCarActFirstBak;
import com.steerinfo.meterwork.meterworkcaractfirstbak.service.IMeterWorkCarActFirstBakService;
import com.steerinfo.util.PublicMethod;
import net.sf.ehcache.transaction.xa.EhcacheXAException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

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

    @Resource
    private MeterWorkCarActFirstBakMapper meterWorkCarActFirstBakMapper;

    @Override
    protected IBaseMapper<MeterWorkCarActFirstBak, String> getMapper() {
        return meterWorkCarActFirstBakMapper;
    }

    @Override
    public RESTfulResult batchCheckAdd(List<MeterWorkCarActFirstBak> models) {
        RESTfulResult rm = new RESTfulResult();
        rm.setFailed();
        try {
            Assert.isTrue(models.size() > 0, "数据为空，不能进行批量保存");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            for (MeterWorkCarActFirstBak model: models) {
                String no = PublicMethod.IdCreate(3);
                model.setActualFirstNo(no + "bak");
                meterWorkCarActFirstBakMapper.insertSelective(model);
            }
            rm.setSucceed();
            rm.setData(models);
            rm.setCode("200");
            rm.setMessage("操作成功");
        }catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常>>>" + e.getMessage());
        }
        return rm;
    }
}
