package com.ym.mec.student.controller;

import com.ym.mec.biz.dal.dao.SysAccountDao;
import com.ym.mec.biz.dal.entity.SysAccount;
import com.ym.mec.biz.service.SysAccountService;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;

@RequestMapping("studentOrder")
@Api(tags = "订单回调")
@RestController
public class StudentOrderController {
    private static final Logger log = LoggerFactory.getLogger(StudentOrderController.class);
    @Autowired
    private SysAccountDao sysAccountDao;


    @PostMapping("/notify")
    public String notify(HttpServletRequest request) {
       Map<String,String[]> msg = request.getParameterMap();
        ArrayList<SysAccount> sysAccounts = new ArrayList<>();
        for (Map.Entry<String, String[]> stringObjectEntry : msg.entrySet()) {
            SysAccount sysAccount = new SysAccount();
            String KeyVal = "Key:" + stringObjectEntry.getKey() + " val:" + stringObjectEntry.getValue().toString();
            log.warn(KeyVal);
            sysAccount.setMerNo(stringObjectEntry.getKey());
            sysAccount.setChannel(request.getParameter(stringObjectEntry.getKey()));
            sysAccounts.add(sysAccount);
        }
        sysAccountDao.batchInsert(sysAccounts);

        // "SUCCESS";
        // "FAILED";

        return "SUCCESS";
    }


    //
}
