package com.unis.detectionnum.server.domain;

import java.util.*;

import com.google.common.collect.Lists;
import com.unis.detectionnum.common.vo.GetXYVO;
import com.unis.detectionnum.server.entity.GetXYDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.unis.common.utils.LsBeanUtils;
import com.unis.detectionnum.common.vo.ScanPointsQueryVO;
import com.unis.detectionnum.common.vo.ScanPointsVO;
import com.unis.detectionnum.server.dao.ScanPointsDao;
import com.unis.detectionnum.server.entity.ScanPointsDO;

@Component
public class ScanPointsDomain extends BaseDomain {

    @Autowired
    private ScanPointsDao scanPointsDao;

    public List<ScanPointsVO> getPointListByQuery(ScanPointsQueryVO pointsQueryVO) {
        List<ScanPointsVO> scanPointsVOs = new ArrayList<>();
        List<ScanPointsDO> scanPointsDOs = scanPointsDao.selectByParams(pointsQueryVO);
        for (ScanPointsDO sPointsDO : scanPointsDOs) {
            ScanPointsVO sPointsVO = new ScanPointsVO();
            LsBeanUtils.copyAllProperties(sPointsDO, sPointsVO);
            scanPointsVOs.add(sPointsVO);
        }
        return scanPointsVOs;
    }

    public void insertPointsList(List<ScanPointsVO> sScanPointsList) {

        List<ScanPointsDO> scanPointsDOs = new ArrayList<>();
        for (ScanPointsVO sPointsVO : sScanPointsList) {
            ScanPointsDO sPointsDO = new ScanPointsDO();
            LsBeanUtils.copyAllProperties(sPointsVO, sPointsDO);
            scanPointsDOs.add(sPointsDO);
        }

        scanPointsDao.insertPointsList(scanPointsDOs);

    }

    /**
     * @param operateId
     * @return Double [] []
     * @throws
     * @Title: getPointDataInfo
     * @Description: 根据扫描纪录id获取点数数据
     */
    public ArrayList<ArrayList<Double>> getPointDataInfo(Map<String, Object> map) {

        List<ScanPointsDO> pointsDOs = scanPointsDao.selectByOperateId(map);
        List<ScanPointsDO> pointsDOCopys = scanPointsDao.selectByOperateIdCopy(map);
        ArrayList<ArrayList<Double>> test1 = Lists.newArrayList();
        if (pointsDOs != null && pointsDOs.size() > 0) {
//            Double[][] pointsData = new Double[15][84];
            for (int index = 0; index < pointsDOs.size(); index++) {
                ArrayList<Double> test2 = Lists.newArrayList();
                ScanPointsDO s = pointsDOs.get(index);
                double result_1 = s.getResult_1();
                double result_2 = s.getResult_2();
                Double pointZ = s.getPointZ();
                test2.add(result_1);
                test2.add(result_2);
                test2.add(pointZ);
                test1.add(test2);
            }
        }
        if (pointsDOCopys != null && pointsDOCopys.size() > 0) {
//            Double[][] pointsData = new Double[15][84];
            for (int index = 0; index < pointsDOCopys.size(); index++) {
                ArrayList<Double> test2 = Lists.newArrayList();
                ScanPointsDO s = pointsDOCopys.get(index);
                double result_1 = s.getResult_1();
                double result_2 = s.getResult_2();
                Double pointZ = s.getPointZ();
                test2.add(result_1);
                test2.add(result_2);
                test2.add(pointZ);
                test1.add(test2);
            }
        }
        return test1;
    }

    //插入 x y 的数据
    public void insertPointsXOrY(List<GetXYVO> getScanPoints) {

     /*   List<GetXYDO> scanPointsDOs = new ArrayList<>();
        for (GetXYVO sPointsVO : getScanPoints) {
            GetXYDO sPointsDO = new GetXYDO();
            LsBeanUtils.copyAllProperties(sPointsVO, sPointsDO);
            scanPointsDOs.add(sPointsDO);
        }*/
     if (getScanPoints.size()>0){
         scanPointsDao.insertPointsXOrY(getScanPoints);
     }
    }

    public void updateZ(GetXYVO getXYVO) {
        /*GetXYDO sPointsDO = new GetXYDO();
        LsBeanUtils.copyAllProperties(getXYVO, sPointsDO);*/
        scanPointsDao.updateZ(getXYVO);
    }
    public void updateZ2(GetXYVO getXYVO) {
        GetXYDO sPointsDO = new GetXYDO();
        LsBeanUtils.copyAllProperties(getXYVO, sPointsDO);
        scanPointsDao.updateZ2(getXYVO);
    }

    public List<GetXYVO> getXYListByZ(String operateId) {
        List<GetXYVO> scanPointsVOs = new ArrayList<>();
        List<GetXYDO> scanPointsDOs = scanPointsDao.getXYListByZ(operateId);
        for (GetXYDO sPointsDO : scanPointsDOs) {
            GetXYVO sPointsVO = new GetXYVO();
            LsBeanUtils.copyAllProperties(sPointsDO, sPointsVO);
            scanPointsVOs.add(sPointsVO);
        }
        return scanPointsVOs;
    }

    //得到 operateId
    public String getOperateId(String sbCode) {
        return scanPointsDao.getOperateId(sbCode);
    }

    // 根据operateId 和 points_z 为空查到列表
    public List<GetXYVO> getNoZList(String operateId) {
        List<GetXYVO> scanPointsVOs = new ArrayList<>();
        List<GetXYDO> scanPointsDOs = scanPointsDao.getNoZList(operateId);
        for (GetXYDO sPointsDO : scanPointsDOs) {
            GetXYVO sPointsVO = new GetXYVO();
            LsBeanUtils.copyAllProperties(sPointsDO, sPointsVO);
            scanPointsVOs.add(sPointsVO);
        }
        return scanPointsVOs;
    }

    // 根据operateId 和 points_z 为空查到列表
    public List<GetXYVO> getNoZList2(String operateId) {
        List<GetXYVO> scanPointsVOs = new ArrayList<>();
        List<GetXYDO> scanPointsDOs = scanPointsDao.getNoZList2(operateId);
        for (GetXYDO sPointsDO : scanPointsDOs) {
            GetXYVO sPointsVO = new GetXYVO();
            LsBeanUtils.copyAllProperties(sPointsDO, sPointsVO);
            scanPointsVOs.add(sPointsVO);
        }
        return scanPointsVOs;
    }

    public String getSbCodeByBh(String cfbh) {
        return scanPointsDao.getSbCodeByBh(cfbh);
    }

    public List<GetXYVO> getNotZList() {
        return scanPointsDao.getNotZList();
    }


    public double getFinalAvgZ(HashMap<String, Object> map) {
        return scanPointsDao.getFinalAvgZ(map);
    }

    public double getFinalAvgZCopy(HashMap<String, Object> map) {
        return scanPointsDao.getFinalAvgZCopy(map);
    }

    public double  getPenultAvgZ (HashMap<String, Object> map) {
        return scanPointsDao.getPenultAvgZ(map);
    }

    public double  getPenultAvgZCopy (HashMap<String, Object> map) {
        return scanPointsDao.getPenultAvgZCopy(map);
    }


    public double getDensity(String sbCode) {
        return scanPointsDao.getDensity(sbCode);
    }

    public double getCfExtent(String sbCode) {
        return scanPointsDao.getCfExtent(sbCode);
    }

    public double getCfWide(String sbCode) {
        return scanPointsDao.getCfWide(sbCode);
    }

    public double getCfGd(String sbCode) {
        return scanPointsDao.getCfGd(sbCode);
    }

    public GetXYDO getRadian(GetXYVO getXYVO) {
        GetXYDO getXYDO = new GetXYDO();
        LsBeanUtils.copyAllProperties(getXYVO, getXYDO);
        return scanPointsDao.getRadian(getXYVO);
    }

    public double getPointsMaxZ(String operateId) {
        return scanPointsDao.getPointsMaxZ(operateId);
    }

    public Map<String, Object> getCfdata(String sbCode) {
        Map<String, Object> cfdata = scanPointsDao.getCfdata(sbCode).get(0);
        return cfdata;
    }

    //插入 x y 的数据
    public void insertPointsXOrYone(GetXYVO getXYVO) {
       scanPointsDao.insertPointsXOrYone(getXYVO);
    }

    public void deleteByXYP(String id) {
        scanPointsDao.deleteByXYP(id);
    }

    public void deleteByXYP2(String id) {
        scanPointsDao.deleteByXYP2(id);
    }

    public void deleteByoperateId(String operateId) {
        scanPointsDao.deleteByoperateId(operateId);
    }

    //插入 x y 的数据
    public void insertPointsXOrY2(List<GetXYVO> getScanPoints) {
        if (getScanPoints.size()>0){
            scanPointsDao.insertPointsXOrY2(getScanPoints);
        }
    }

    public double getFinalAvgZz(HashMap<String, Object> map) {
        return scanPointsDao.getFinalAvgZz(map);
    }

    public double selectByoperateIdMax(String operateId) {
        return scanPointsDao.selectByoperateIdMax(operateId);
    }

    public int getByOperateIdCOUNT(HashMap<String, Object> map) {
        return scanPointsDao.getByOperateIdCOUNT(map);
    }

    public int getByOperateIdCOUNTCopy(HashMap<String, Object> map) {
        return scanPointsDao.getByOperateIdCOUNTCopy(map);
    }
}