package com.duowenlvshi.duowenlszp.model.education.controller;

import com.duowenlvshi.duowenlszp.model.education.entity.Education;
import com.duowenlvshi.duowenlszp.model.education.server.EducationServer;
import com.duowenlvshi.duowenlszp.app.util.DeletEmoji;
import com.duowenlvshi.duowenlszp.app.util.SelectRedis;
import com.duowenlvshi.duowenlszp.app.util.TypeConversion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * @author yang fang yu
 * @since 2019/8/21 15:34
 */
@Transactional
@Component
public class EducationController {
    @Autowired
    EducationServer educationServer;
    @Autowired
    SelectRedis selectRedis;
    @Autowired
    DeletEmoji deletEmoji;

    public EducationController() {
    }

    public int insertEducation(Map<String, Object> map) {
        List<Map> list = (List)map.get("list");
        int i = 0;
        Education education;
        for(Iterator var4 = list.iterator(); var4.hasNext(); i = this.educationServer.save(education)) {
            Map map1 = (Map)var4.next();
            education = (Education)TypeConversion.mapToObject(map1, Education.class);
            education.setMajor(this.deletEmoji.filterEmoji(education.getMajor(), ""));
        }
        return i;
    }

    public int deletEducation(Map<String, Object> map) {
        String id = (String)map.get("id");
        int i = this.educationServer.delete(id);
        return i;
    }

    public List<Education> selectEducation(Map<String, Object> map) {
        String lawyerId = (String)map.get("lawyerId");
        List list = this.educationServer.selectByLawyerId(lawyerId);
        return list;
    }
}
