package com.huimv.face.service.impl;

import com.alibaba.fastjson.JSON;
import com.huimv.face.domain.SaveDb;
import com.huimv.face.repo.SaveDbRepository;
import com.huimv.face.result.Result;
import com.huimv.face.service.SaveDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * @Project : huimv.shiwan
 * @Package : com.huimv.face.service.impl
 * @Description : TODO
 * @Author : yuxuexuan
 * @Create : 2020/12/29 0029 17:03
 **/
@Service
public class SaveDbServiceImpl implements SaveDbService {
    @Autowired
   private SaveDbRepository saveDbRepository;

    @Override
    public void save(SaveDb saveDb) {
        saveDbRepository.save(saveDb);
    }

    @Override
    public Result findDb(String str) {
        Integer id;

        switch (str){
            case "oneYear":
                id=1;
                break;
            case "oneWeek":
                id=2;
                break;
            case "oneDay":
                id=3;
                break;
            default:
                id=null;
        }
        if (id != null){
            SaveDb saveDb =  saveDbRepository.findById(id).get();
            List list = (List) JSON.parse(saveDb.getValue1());
            return new Result(10000,"查询成功",list);
        }else {
            return new Result(10001,"查询失败",null);
        }
    }
}
