package com.steerinfo.metermonitor.metermonitornote.service.impl;

import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.framework.service.pagehelper.PageHelper;
import com.steerinfo.framework.service.pagehelper.PageList;
import com.steerinfo.metermonitor.metermonitornote.mapper.MeterMonitorNoteMapper;
import com.steerinfo.metermonitor.metermonitornote.model.MeterMonitorNote;
import com.steerinfo.metermonitor.metermonitornote.service.IMeterMonitorNoteService;
import com.steerinfo.meterwork.except.MarkerMetException;
import com.steerinfo.meterwork.meterworkmonitor.model.MeterWorkMonitor;
import com.steerinfo.util.PublicMethod;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

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

    @Resource
    private MeterMonitorNoteMapper meterMonitorNoteMapper;

    @Override
    protected IBaseMapper<MeterMonitorNote, String> getMapper() {
        return meterMonitorNoteMapper;
    }


    @Override
    @Transactional(rollbackFor=Exception.class)
    public PageList<MeterMonitorNote> selectView(Map<String,Object> parmas, Integer pageNum, Integer pageSize)
    {
        PageHelper.startPage(pageNum, pageSize);
        List<MeterMonitorNote> rows = meterMonitorNoteMapper.selectView(parmas);
        PageList pageInfo = new PageList(rows);
        return pageInfo;
    }

    @Override
    public PageList<MeterMonitorNote> likeByDesc(Map<String, Object> parmas, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        if(parmas.get("baseSpotNoStr") != null) {
            String spotNoStr[] = parmas.get("baseSpotNoStr").toString().split(",");
            parmas.put("spotNoStr", spotNoStr);
        }
//        if(parmas.get("createManNoStr") != null) {
//            String manNoStr[] = parmas.get("createManNoStr").toString().split(",");
//            parmas.put("manNoStr", manNoStr);
//        }
        List<MeterMonitorNote> rows = meterMonitorNoteMapper.likeByDesc(parmas);
        PageList pageInfo = new PageList(rows);
        return pageInfo;
    }

    @Override
    @Transactional(rollbackFor=Exception.class)
    public PageList<MeterMonitorNote> selectByTime(String baseSpotNo, String operationTime, String carNo,Integer pageNum, Integer pageSize)
    {
        HashMap<String, Object> obj = new HashMap<>();
        obj.put("baseSpotNo", baseSpotNo);
        obj.put("operationTime", operationTime);
        obj.put("carNo", carNo);
        PageHelper.startPage(pageNum, pageSize);
        List<MeterMonitorNote> rows = meterMonitorNoteMapper.selectByTime(obj);
        PageList pageInfo = new PageList(rows);
        return pageInfo;
    }

    @Override
    @Transactional(rollbackFor=Exception.class)
    public  String doSaveWf(MeterMonitorNote model){
        try{
            SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
            String afl = formatter.format(new Date());
            String no = meterMonitorNoteMapper.getNewID(afl);
            model.setNoteNo(PublicMethod.IdCreate(3));
            meterMonitorNoteMapper.insertSelective(model);
            return model.getNoteNo();
        }catch (MarkerMetException e){
            throw  e;
        }
    }

    @Override
    @Transactional
    public PageList<MeterMonitorNote> selectByType(HashMap parmas, Integer pageNum, Integer pageSize){
        PageHelper.startPage(pageNum, pageSize);
        List<MeterMonitorNote> rows = meterMonitorNoteMapper.selectByType(parmas);
        PageList pageInfo = new PageList(rows);
        return pageInfo;
    }

    @Override
    public List<MeterMonitorNote> queryLikeNoPage(HashMap<String, Object> params) {
        List<MeterMonitorNote> monitors = meterMonitorNoteMapper.queryLikeNoPage(params);
        return monitors;
    }

    @Override
    public PageList<MeterMonitorNote> allStateView(HashMap parmas, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<MeterMonitorNote> rows = meterMonitorNoteMapper.allStateView(parmas);
        PageList pageInfo = new PageList(rows);
        return pageInfo;
    }

    @Override
    public PageList<MeterMonitorNote> resetCarView(HashMap parmas, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<MeterMonitorNote> rows = meterMonitorNoteMapper.resetCarView(parmas);
        PageList pageInfo = new PageList(rows);
        return pageInfo;
    }
}
