package edu.neusoft.project.controller;

import edu.neusoft.project.model.service.IndentService;
import edu.neusoft.project.model.service.PersonService;
import edu.neusoft.project.model.service.SongService;
import edu.neusoft.project.model.vo.Indent;
import edu.neusoft.project.model.vo.Person;
import edu.neusoft.project.model.vo.Song;
import edu.neusoft.project.util.MyMD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

//import java.util.ArrayList;


@Controller
public class PersonBasicAction {
    @Autowired
    private PersonService service;
    @Autowired
    private SongService songService;
    @Autowired
    private IndentService indentService;

    private MyMD5Util myMD5Util;

    private Person globalPerson = null;
//    HttpSession session;
    public String level = null;

    @ResponseBody
    @RequestMapping(value="selectUser.action", method=RequestMethod.POST,produces=MediaType.APPLICATION_JSON_VALUE)
    public boolean selectUser(String username,HttpServletRequest request){
        System.out.println("ajax yes");
//        boolean flag=service.selUser(username);
        return true;
    }
    @ResponseBody
    @RequestMapping("checkRegistUser.action")
    public int checkRegistUser(String username){
        String excl = String.valueOf(username.charAt(0));
        String ret=service.checkRegistUser(username);
        if ("!".equals(excl)){
            System.out.println("无权限");
            return 2;
        }else if ("yes".equals(ret)){
            System.out.println("无相同用户名，可以注册");
            return 1;
        }
        System.out.println("存在相同用户名:"+ret+"/"+username+"，不可以注册");
        return 0;

    }
    @RequestMapping("delThisIndent.action")
    @ResponseBody
    public int delThisIndent(String adminListPersonCode,String id){
        int ret = indentService.delThisIndent(adminListPersonCode,id);
        return ret;
    }
    @ResponseBody
    @RequestMapping("getTradingCount.action")
    public String getTradingCount(){
        String count="0";
        int intcount=service.getTradingCount();
        count=String.valueOf(intcount);
        return count;
    }
//    @ResponseBody
//    @RequestMapping("mjson.asp")
//    public void mjson(String username){
//
//
//    }


//    @RequestMapping("indentInfoAct.action")
//    @ResponseBody
//    public String indentInfo(String Id){
//        System.out.println(Id);
//        String data= indentService.indentInfo(Id);
//
//        System.out.println(data);
//        return  data;
//    }

}
