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

import com.github.pagehelper.util.StringUtil;
import com.steerinfo.ems.tcm0318.mapper.TCm0318Mapper;
import com.steerinfo.ems.tcm0318.model.TCm0318;
import com.steerinfo.ems.tcm0318.service.ITCm0318Service;
import com.steerinfo.ems.tcm0323.model.TCm0323;
import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.model.ICreatePO;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.framework.service.pagehelper.PageHelper;
import com.steerinfo.framework.service.pagehelper.PageList;
import com.steerinfo.framework.utils.misc.IdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * TCm0318服务实现：
 * @author 王金涛
 * @version 1.0-SNAPSHORT 2019-10-16 11:40
 * 类描述
 * 修订历史：
 * 日期：2019-10-16
 * 作者：王金涛
 * 参考：
 * 描述：TCm0318服务实现
 * @see null
 * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
 */
@Service(value = "tCm0318Service")
public class TCm0318ServiceImpl extends BaseServiceImpl<TCm0318, String> implements ITCm0318Service {
    @Autowired
    private TCm0318Mapper tCm0318Mapper;

    @Override
    protected IBaseMapper<TCm0318, String> getMapper() {
        return tCm0318Mapper;
    }

    @Override
    public TCm0318 add(TCm0318 t) {
        if (StringUtil.isEmpty(t.getRecordid())) {
            t.setId(this.genID());
            while(tCm0318Mapper.selectByPrimaryKey(t.getRecordid()) != null){
                t.setRecordid(String.valueOf(Long.parseLong(t.getRecordid()) + 1));
            }
        }
        if (t instanceof ICreatePO) {
            this.setCreate((ICreatePO)t);
        }
        this.getMapper().insert(t);
        return t;
    }

    public List<TCm0318> getByCode(Map<String, Object> parameters){
        return tCm0318Mapper.getByCode(parameters);
    }

    public PageList<TCm0318> dataQuery(Map<String, Object> parameters, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<TCm0318> rows = tCm0318Mapper.dataQuery(parameters);
        PageList<TCm0318> pageInfo = new PageList<TCm0318>(rows);
        return pageInfo;
    }

    public PageList<TCm0318> qualityassessment(Map<String, Object> parameters, Integer pageNum, Integer pageSize){
        PageHelper.startPage(pageNum, pageSize);
        List<TCm0318> rows = tCm0318Mapper.qualityassessment(parameters);
        PageList<TCm0318> pageInfo = new PageList<TCm0318>(rows);
        return pageInfo;
    }

    public List<Map<String, Object>> datacomparison(Map<String, Object> parameters){
        List<Map<String, Object>> rows = tCm0318Mapper.datacomparison(parameters);
        return rows;
    }

    //获取炼钢数据
    public void  getDataAsLg(String date) {
        List<TCm0318> dataAsLg = tCm0318Mapper.getDataAsLg(date);
        for (TCm0318 tCm0318 : dataAsLg) {
            TCm0318 tCm03181 = this.selectByparams(tCm0318);
            if(tCm03181 != null ){
                this.updateByparams(tCm0318);
            }else {
                tCm0318Mapper.insert(tCm0318);
            }
        }
    }

    @Override
    public void getDataAsYlc(String date) {
        List<TCm0318> dataAsLg = tCm0318Mapper.getDataAsYlc(date);
        for (TCm0318 tCm0318 : dataAsLg) {
            TCm0318 tCm03181 = this.selectByparams(tCm0318);
            if(tCm03181 != null ){
                this.updateByparams(tCm0318);
            }else {
                tCm0318Mapper.insert(tCm0318);
            }
        }
    }

    @Override
    public void getDataAsYgx(String date) {
        List<TCm0318> dataAsLg = tCm0318Mapper.getDataAsYgx(date);
        for (TCm0318 tCm0318 : dataAsLg) {
            TCm0318 tCm03181 = this.selectByparams(tCm0318);
            if (tCm03181 != null ) {
                this.updateByparams(tCm0318);
            }else {
                tCm0318Mapper.insert(tCm0318);
            }
        }
    }

    @Override
    public void getDataAsEgx(String date) {
        List<TCm0318> dataAsLg = tCm0318Mapper.getDataAsEgx(date);
        for (TCm0318 tCm0318 : dataAsLg) {
            TCm0318 tCm03181 = this.selectByparams(tCm0318);
            if (tCm03181 != null) {
                this.updateByparams(tCm0318);
            }else {
                tCm0318Mapper.insert(tCm0318);
            }
        }
    }

    @Override
    public void getDataAsFdc(String date) {
        List<TCm0318> dataAsLg = tCm0318Mapper.getDataAsFdc(date);
        for (TCm0318 tCm0318 : dataAsLg) {
            TCm0318 tCm03181 = this.selectByparams(tCm0318);
            if (tCm03181 != null ) {
                this.updateByparams(tCm0318);
            } else {
                tCm0318Mapper.insert(tCm0318);
            }
        }
    }

    @Override
    public void getDataAsJjc(String date) {
        List<TCm0318> dataAsLg = tCm0318Mapper.getDataAsJjc(date);
        for (TCm0318 tCm0318 : dataAsLg) {
            TCm0318 tCm03181 = this.selectByparams(tCm0318);
            if (tCm03181 != null ) {
                this.updateByparams(tCm0318);
            }else {
                tCm0318Mapper.insert(tCm0318);
            }
        }
    }


    @Override
    public void getDataAsWscj(String date) {
        List<TCm0318> dataAsLg = tCm0318Mapper.getDataAsWscj (date);
        for (TCm0318 tCm0318 : dataAsLg) {
            TCm0318 tCm03181 = this.selectByparams(tCm0318);
            if(tCm03181 != null ){
                this.updateByparams(tCm03181);
            } else {
                tCm0318Mapper.insert(tCm0318);
            }
        }
    }

    @Override
    public TCm0318 selectByparams(TCm0318 model) {
        return tCm0318Mapper.selectByparams(model);
    }

    @Override
    public int updateByparams(TCm0318 tCm0318) {
        return tCm0318Mapper.updateByparams(tCm0318);
    }

}
