package com.ssm.core.utils;

import com.ssm.manage.entity.AccountTradeRecord;
import com.ssm.manage.entity.StoreParament;
import com.ssm.manage.query.AccountTradeRecordRequest;
import com.ssm.manage.service.SsmAccountTradeRecordService;
import com.ssm.manage.service.SsmStoreParaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@Component
public class StoreParaUtils {
    private static StoreParaUtils storeParaUtils;

    @Autowired
    private  SsmStoreParaService ssmStoreParaService;

    @Autowired
    private SsmAccountTradeRecordService ssmAccountTradeRecordService;

    @PostConstruct
    public void init(){
        storeParaUtils = this;
    }

    public static StoreParament getStorePara(Long storeId, String key) {
        StoreParament storeParament = new StoreParament();
        storeParament.setStoreId(storeId);
        storeParament.setParamentName(key);
        storeParament = storeParaUtils.ssmStoreParaService.selectOne(storeParament);
        return storeParament;
    }

    public static List<StoreParament> getPara( String key) {
        StoreParament storeParament = new StoreParament();
        storeParament.setParamentName(key);
        List<StoreParament> list =storeParaUtils.ssmStoreParaService.select(storeParament);
        return list;
    }

    public static void main(String[] args) {
//        AccountTradeRecordRequest accountTradeRecordRequest = new AccountTradeRecordRequest();
//        accountTradeRecordRequest.setStoreId(69149684783009792L);
//        accountTradeRecordRequest.setInputDate(new Date());
//
//        List<AccountTradeRecord> list = storeParaUtils.ssmAccountTradeRecordService.selectList(accountTradeRecordRequest);
        List<AccountTradeRecord> list = new ArrayList<>();
        AccountTradeRecord accountTradeRecord = new AccountTradeRecord();
        accountTradeRecord.setId(87393419273355264L);
        accountTradeRecord.setAccountId(87368290908176384L);
        accountTradeRecord.setAccountName("面部拔筋");
        AccountTradeRecord accountTradeRecord1 = new AccountTradeRecord();
        accountTradeRecord1.setId(87393419632500736L);
        accountTradeRecord1.setAccountId(87290962355740672L);
        accountTradeRecord1.setAccountName("美容修眉");
        AccountTradeRecord accountTradeRecord2 = new AccountTradeRecord();
        accountTradeRecord2.setId(87393419932930048L);
        accountTradeRecord2.setAccountId(87368290908176384L);
        accountTradeRecord2.setAccountName("面部拔筋");
//        AccountTradeRecord accountTradeRecord3 = new AccountTradeRecord();
//        accountTradeRecord3.setId(87393420186947584L);
//        accountTradeRecord3.setAccountId(null);
//        accountTradeRecord3.setAccountName(null);
        list.add(accountTradeRecord);
        list.add(accountTradeRecord1);
        list.add(accountTradeRecord2);
//        list.add(accountTradeRecord3);
        Map<Long,List<AccountTradeRecord>> map = list.stream().collect(Collectors.groupingBy(AccountTradeRecord::getAccountId));
        Iterator<Map.Entry<Long,List<AccountTradeRecord>>> entryIterator = map.entrySet().iterator();
        while (entryIterator.hasNext()){
            Map.Entry<Long,List<AccountTradeRecord>> entry = entryIterator.next();
            List<AccountTradeRecord> list1 = entry.getValue();

        }
    }
}
