package com.example.demo.page.data;



import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.*;


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


@RestController
@CrossOrigin
@ResponseBody
public class ImportData {
    @Autowired
    JdbcTemplate jdbcTemplate = new JdbcTemplate();
    @PostMapping(value = "/permission")
    public List<Map<String, Object>> getData(@RequestBody Map<String,Object> postData){
        JSONArray Datas = JSONArray.parseArray(postData.get("postData").toString());
        for ( int i = 0; i< Datas.size(); i++){
            JSONObject data = Datas.getJSONObject(i);
            System.out.println(data);
            String sql = "insert into userscoreinfo (username,parentclass,childclass,subpoint,scoringelement," +
                    "awardtime,score) values (?,?,?,?,?,?,?)";
            jdbcTemplate.update(sql, data.get("username"), data.get("parentclass"), data.get("childclass"),
                    data.get("subpoint"), data.get("scoringelement"), data.get("awardtime"), data.get("score"));
        }

        return null;
    }

}
