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

import com.steerinfo.ems.Utils.CompareUtil;
import com.steerinfo.ems.emsscqklg.mapper.EmsScqkLgMapper;
import com.steerinfo.ems.emsscqklg.model.EmsScqkLg;
import com.steerinfo.ems.emsscqklg.service.EmsLgReportService;
import com.steerinfo.ems.emsscqklg.service.IEmsScqkLgService;
import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * EmsScqkLg服务实现：
 * @author generator
 * @version 1.0-SNAPSHORT 2021-10-19 10:43
 * 类描述
 * 修订历史：
 * 日期：2021-10-19
 * 作者：generator
 * 参考：
 * 描述：EmsScqkLg服务实现
 * @see null
 * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
 */
@Service(value = "emsScqkLgService")
public class EmsScqkLgServiceImpl extends BaseServiceImpl<EmsScqkLg, Date> implements IEmsScqkLgService {

    @Autowired
    private EmsScqkLgMapper emsScqkLgMapper;

    @Autowired
    private EmsLgReportService emsLgReportService;

    @Override
    protected IBaseMapper<EmsScqkLg, Date> getMapper() {
        return emsScqkLgMapper;
    }

    @Override
    public int dateGenerate() {
       List<EmsScqkLg> emsScqkLgs =  emsLgReportService.queryReportByTime();
       EmsScqkLg model;
       Integer number=0;
       String[] ignoreArr = new String[] {"czsj","czr"};
       for(EmsScqkLg emsScqkLg :emsScqkLgs)
       {
           emsScqkLg.setCzr("炼钢MES");
           emsScqkLg.setCzsj(new Date());
           model = emsScqkLgMapper.selectByPrimaryKey(emsScqkLg.getId());
           if(model == null){
              number += emsScqkLgMapper.insert(emsScqkLg);
              return number ;
           }
          HashMap map = (HashMap) CompareUtil.compareFields(model,emsScqkLg,ignoreArr,0);
           if(map.size()>0){
               map.put("dates",model.getDates());
               emsScqkLgMapper.updateByMap(map);
           }
           //model.setGsrcl(emsScqkLg.getGsrcl());
           //number += emsScqkLgMapper.updateByPrimaryKeySelective(emsScqkLg);
       }
        return number;
    }
}
