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

import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.meterwork.meterworkonline.mapper.MeterWorkOnlineMapper;
import com.steerinfo.meterwork.meterworkonline.model.MeterWorkOnline;
import com.steerinfo.meterwork.meterworkonline.service.IMeterWorkOnlineService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;

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

    @Resource
    private MeterWorkOnlineMapper meterWorkOnlineMapper;

    @Override
    protected IBaseMapper<MeterWorkOnline, String> getMapper() {
        return meterWorkOnlineMapper;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int doSaveWf(MeterWorkOnline model){
        int num = 0;
        MeterWorkOnline mwo =  meterWorkOnlineMapper.selectByPrimaryKey(model.getUserId());
       if( mwo == null){
           //新增
           model.setLastTime(new Date());
           model.setWorkFlag("0");//未接管状态
           num = meterWorkOnlineMapper.insert(model);
        }else {
           //修改
           model.setLastTime(new Date());
           //meterWorkOnlineMapper.updateByPrimaryKeySelective(model);
           meterWorkOnlineMapper.batchUpdateForOnLine(model); //2021年2月25日 杨秀东修改为采用数据库时间更新
           num ++;
       }
       return num;
    }
}
