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

import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.meterwork.except.MarkerMetException;
import com.steerinfo.meterwork.meterworkstorageonline.mapper.MeterWorkStorageOnlineMapper;
import com.steerinfo.meterwork.meterworkstorageonline.model.MeterWorkStorageOnline;
import com.steerinfo.meterwork.meterworkstorageonline.service.IMeterWorkStorageOnlineService;
import com.steerinfo.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

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

    @Autowired
    private MeterWorkStorageOnlineMapper meterWorkStorageOnlineMapper;


    @Override
    protected IBaseMapper<MeterWorkStorageOnline, String> getMapper() {
        return meterWorkStorageOnlineMapper;
    }

    @Override
    @Transactional
    public String doSaveWf(MeterWorkStorageOnline model){
        if (model == null || StringUtils.isEmpty(model.getUserId())) {
            throw new MarkerMetException(500, "参数不正确！！");
        }
        MeterWorkStorageOnline meterWorkStorageOnline = meterWorkStorageOnlineMapper.selectByPrimaryKey(model.getUserId());
        if (meterWorkStorageOnline == null){
            MeterWorkStorageOnline mwso =  new MeterWorkStorageOnline();
            mwso.setUserId(model.getUserId());
            mwso.setLastTime(new Date());
            mwso.setWorkFlag("0");
        }else {
            model.setLastTime(new Date());
            meterWorkStorageOnlineMapper.updateByPrimaryKeySelective(model);
        }
        return model.getUserId();
    }

}
