package com.steerinfo.ems.tmaintenance.service.impl;

import com.steerinfo.ems.tsubmitted.model.TSubmitted;
import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.ems.tmaintenance.model.TMaintenance;
import com.steerinfo.ems.tmaintenance.mapper.TMaintenanceMapper;
import com.steerinfo.ems.tmaintenance.service.ITMaintenanceService;
import com.steerinfo.framework.service.pagehelper.PageHelper;
import com.steerinfo.framework.service.pagehelper.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

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

    @Autowired
    private TMaintenanceMapper tMaintenanceMapper;

    @Override
    protected IBaseMapper<TMaintenance, String> getMapper() {
        return tMaintenanceMapper;
    }
    @Override
    public Integer MaxID(String mouth) {
        Integer maxId = tMaintenanceMapper.selectMaxId(mouth);
        if (maxId == null || maxId == 0) {
            maxId = 1;
        } else {
            maxId = maxId + 1;
        }
        return maxId;
    }

    @Override
    public List<TMaintenance> selectAll() {
        return tMaintenanceMapper.selectAll();
    }

    @Override
    public Integer deleMes(String ids, String id) {
        if ("".equals(ids) || ids == null) {
            return 0;
        } else {
            int count = tMaintenanceMapper.deleMes(ids, id);
            return count;
        }
    }

    @Override
    public Integer pusMes(TMaintenance params) {
        int count = 0;

        count = tMaintenanceMapper.pusMes(params);

        return count;
    }

    @Override
    public Integer pusMesAll(String declareid,String billstatus) {
        int count= tMaintenanceMapper.pusMesAll(declareid,billstatus);
        return count;
    }

    @Override
    public PageList<TMaintenance> listLikeapproval(Map<String, Object> parameters, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<TMaintenance> rows = tMaintenanceMapper.selectLike(parameters);
        PageList pageInfo = new PageList(rows);
        return pageInfo;
    }

    @Override
    public Integer pusMesAlla(String declareid,String billstatus,String approver,String datetime) {
        int count= tMaintenanceMapper.pusMesAlla(declareid,billstatus,approver,datetime);
        return count;
    }
    @Override
    public PageList<TMaintenance> listLikeapprovals(Map<String, Object> parameters, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<TMaintenance> rows = tMaintenanceMapper.selectLikes(parameters);
        List<TMaintenance> list = rows.stream().filter(tMaintenance -> !"编辑中".equals(tMaintenance.getBillstatus())).collect(Collectors.toList());
        PageList pageInfo = new PageList(list);
        return pageInfo;
    }
    @Override
    public PageList<TMaintenance> approval(Map<String, Object> parameters, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<TMaintenance> rows = tMaintenanceMapper.approval(parameters);
        List<TMaintenance> list = rows.stream().filter(tMaintenance -> "已通过".equals(tMaintenance.getBillstatus())||"已完成".equals(tMaintenance.getBillstatus())||"进行中".equals(tMaintenance.getBillstatus())).collect(Collectors.toList());
        PageList pageInfo = new PageList(list);
        return pageInfo;
    }
    @Override
    public Integer upstate(TMaintenance t) {
        int count = tMaintenanceMapper.updateByPrimaryKeySelective(t);
        return count;
    }

    @Override
    public String selectfilename(String filname) {
        String filenames=tMaintenanceMapper.selectfilename(filname);
        return filenames;
    }

    @Override
    public Integer updatecheck(String ids) {
        if ("".equals(ids) || ids == null) {
            return 0;
        } else {
            int count = tMaintenanceMapper.updatecheck(ids);
            return count;
        }
    }
}
