package com.yeejoin.amos.boot.module.cas.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.cas.api.dto.IdxBizXnzsDto;
import com.yeejoin.amos.boot.module.cas.api.dto.ResultDto;
import com.yeejoin.amos.boot.module.cas.api.entity.IdxBizXnzs;
import com.yeejoin.amos.boot.module.cas.api.mapper.IdxBizXnzsMapper;
import com.yeejoin.amos.boot.module.cas.api.service.IIdxBizXnzsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import springfox.documentation.spring.web.json.Json;

import java.util.*;

/**
 *  服务实现类
 *
 * @author wanglong
 * @date 2022-09-14
 */
@Service
public class IdxBizXnzsServiceImpl extends BaseService<IdxBizXnzsDto, IdxBizXnzs,IdxBizXnzsMapper> implements IIdxBizXnzsService {
    @Autowired
    private IdxBizXnzsMapper idxBizXnzsMapper;

    @Override
    public ResultDto select() {
        List<IdxBizXnzsDto> xnzsDtoList = idxBizXnzsMapper.select();

        List<String> axisData = new ArrayList<>();
        List<List<Double>> seriesDataList=new ArrayList<>();

        for(IdxBizXnzsDto bizXnzsDto : xnzsDtoList){
            List<Double> list=new ArrayList<>();
            axisData.add(bizXnzsDto.getAxisData());

            Double one = bizXnzsDto.getOne();
            Double two = bizXnzsDto.getTwo();
            Double three = bizXnzsDto.getThree();
            Double four = bizXnzsDto.getFour();

            Double min;

            Double[] doubles = {one,two,three,four};

            Arrays.sort(doubles);

            list.add(doubles[0]);
            list.add((doubles[0]+doubles[1])/2);
            list.add((doubles[1]+doubles[2])/2);
            list.add((doubles[2]+doubles[3])/2);
            list.add(doubles[3]);
            seriesDataList.add(list);
        }

        System.out.println(seriesDataList);

        ResultDto resultDto = new ResultDto();
        resultDto.setAxisData(axisData);
        resultDto.setSeriesData(seriesDataList);


        return resultDto;
    }
}
