package com.lightinit.hsdatashow.impl.admin;

import com.lightinit.hsdatashow.entity.GarbageCan;
import com.lightinit.hsdatashow.entity.StreetLamp;
import com.lightinit.hsdatashow.entity.StreetLampExample;
import com.lightinit.hsdatashow.mapper.StreetLampMapper;
import com.lightinit.hsdatashow.model.admin.GarbageCanModel;
import com.lightinit.hsdatashow.model.admin.StreetLampModel;
import com.lightinit.hsdatashow.service.admin.IStreetLampService;
import com.lightinit.hsdatashow.spring.DynamicDataContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class StreetLampServiceImpl implements IStreetLampService {
    @Autowired
    private StreetLampMapper streetLampMapper;
    @Override
    public StreetLampModel getStreetLamp(String type) {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        StreetLampExample example = new StreetLampExample();
        List<StreetLamp> list = streetLampMapper.selectList1(type);
        List<String> name = new ArrayList<>();
        List<Long> base = new ArrayList<>();
        List<Long> calyx = new ArrayList<>();
        StreetLampModel model = new StreetLampModel();
        for (StreetLamp streetLamp:list) {
                name.add(streetLamp.getStreet());
                base.add(streetLamp.getBase());
                calyx.add(streetLamp.getCalyx());
               // Collections.sort(base);
            model.setBase(base);
            model.setCalyx(calyx);
            model.setName(name);
        }
        return model;
    }

    @Override
    public List<GarbageCanModel>  getList() {
        DynamicDataContextHolder.setCustomerType(DynamicDataContextHolder.DEFAULT);
        StreetLampExample example = new StreetLampExample();

        List<GarbageCanModel> list = new ArrayList<>();
        List<StreetLamp> list1 = streetLampMapper.selectList();
        for (StreetLamp garbageCan:list1
                ) {
            GarbageCanModel model = new GarbageCanModel();
            model.setName(garbageCan.getStreetType());
            model.setValue(garbageCan.getBase());
            list.add(model);
        }
        return list;
    }
}
