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

import com.steerinfo.ems.Utils.MosaicUtils;
import com.steerinfo.ems.Utils.StrUtils;
import com.steerinfo.ems.emsscqklg.mapper.LgRealMapper;
import com.steerinfo.ems.emsscqklg.model.LgReal;
import com.steerinfo.ems.emsscqklg.service.EmsLgReportService;
import com.steerinfo.ems.emsscqklg.service.ILgRealService;
import org.apache.axis2.AxisFault;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("lgRealService")
public class LgRealImpl  implements ILgRealService {

    private static final Logger logger = LoggerFactory.getLogger(LgRealImpl.class);

    @Autowired
    private LgRealMapper lgRealMapper;

    @Autowired
    private EmsLgReportService emsLgReportService;

    @Override
    public List<LgReal> QueryLgReals1() throws AxisFault {
        List<LgReal> lgReals = emsLgReportService.queryReals1();
        if (lgReals.size() < 1) {
            logger.info("当前没有数据");
            return lgReals;
        }
        MosaicUtils mosaicUtils = new MosaicUtils();
        mosaicUtils.SetOpenConnSample();
        StringBuilder sql = new StringBuilder();
        lgReals.stream().forEach(s->{
            //sql = "update Param set ValueText='"+model.getEng().trim()+"' where Rid='"+model.getAltId()+"'";
            if (StrUtils.isNumeric(s.getEng())) {
                sql.append("update Ana set Eng='");
                sql.append(s.getEng());
                sql.append("' where AltId=");
                sql.append(s.getAltId());
                mosaicUtils.SetUpdateValue(sql.toString());
                sql.delete(0,sql.length());
                return;
            }
            sql.append("update Param set ValueText='");
            sql.append(s.getEng());
            sql.append("' where Rid=");
            sql.append(s.getAltId());
            mosaicUtils.SetUpdateValue(sql.toString());
            sql.delete(0,sql.length());
        });
        // Close
        mosaicUtils.SetCloseConnSample();
        return lgReals;
    }
    @Override
    public List<LgReal> QueryLgReals2() throws AxisFault {
        List<LgReal> lgReals = emsLgReportService.queryReals2();
        if (lgReals.size() < 1) {
            logger.info("当前没有数据");
            return lgReals;
        }
        MosaicUtils mosaicUtils = new MosaicUtils();
        mosaicUtils.SetOpenConnSample();
        StringBuilder sql = new StringBuilder();
        lgReals.stream().forEach(s->{
            //sql = "update Param set ValueText='"+model.getEng().trim()+"' where Rid='"+model.getAltId()+"'";
            if (StrUtils.isNumeric(s.getEng())) {
                sql.append("update Ana set Eng='");
                sql.append(s.getEng());
                sql.append("' where AltId=");
                sql.append(s.getAltId());
                mosaicUtils.SetUpdateValue(sql.toString());
                sql.delete(0,sql.length());
                return;
            }
            sql.append("update Param set ValueText='");
            sql.append(s.getEng());
            sql.append("' where Rid=");
            sql.append(s.getAltId());
            mosaicUtils.SetUpdateValue(sql.toString());
            sql.delete(0,sql.length());
        });
        // Close
        mosaicUtils.SetCloseConnSample();
        return lgReals;
    }
}
