package top.lejings.db.http;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.lejings.db.mapper.selectById;
import top.lejings.db.mapper.selectByOther;
import top.lejings.db.people;

import java.util.List;

@RestController
@CrossOrigin(origins = "http://localhost:5173")
public class httpSelect {
    @Autowired
    private selectById selectById;
    @Autowired
    private selectByOther selectByOther;

    @RequestMapping("/selectAll")
    public List<people> selectAll()
    {
        return selectByOther.selectByOtherAll();
    }



    @RequestMapping("/select")
    public List<people> select(Integer id,String name,String password,String email)
    {
        System.out.println("----------------------------------");
        System.out.println(id+"     name:"+name+"   pw"+password+"      em"+email);
        System.out.println("----------------------------------");
        if(id!=null)
        {
            return selectById.selectById(id);

        }
        else//id为空
        {
            //单属性查询
            if(!name.isBlank()&&password.isBlank()&&email.isBlank())
            {
                return selectByOther.selectByName(name);
            }
            else if(name.isBlank()&&!password.isBlank()&&email.isBlank())
            {
                return selectByOther.selectByPassword(password);
            }
            else if(name.isBlank()&&password.isBlank()&&!email.isBlank())
            {
                return selectByOther.selectByEmail(email);
            }
            //双属性查询
            else if(!name.isBlank()&&!password.isBlank()&&email.isBlank())
            {
                return selectByOther.selectByNP(name,password);
            }
            else if(!name.isBlank()&&password.isBlank()&&!email.isBlank())
            {
                return selectByOther.selectByNE(name,email);
            }
            else if(name.isBlank()&&!password.isBlank()&&!email.isBlank())
            {
                return selectByOther.selectByPE(password, email);
            }
            //三属性查询
            else if(!name.isBlank()&&!password.isBlank()&&!email.isBlank())
            {
                return selectByOther.selectByOther3(name, password, email);
            }
            //即全空查询，输出所有值
            else
            {
                return selectByOther.selectByOtherAll();
            }








        }
    }


}
