package com.huimv.admin.controller.primary;


import com.alibaba.fastjson.JSONObject;
import com.huimv.admin.domain.primary.SysUserEntity;
import com.huimv.admin.group.UserAndAccountGroup;
import com.huimv.admin.service.primary.IUserService;
import com.huimv.admin.utils.Result;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/user")
public class SysUserController {
    @Autowired
    private IUserService iUserService;

    @RequestMapping("/add")
    public Result addUser(SysUserEntity user){
        return  iUserService.addUser(user);
    }

    @RequestMapping("/edit")
    public Result updateUser(SysUserEntity user){
        return iUserService.updateUser(user);
    }

    @RequestMapping("/remove")
    public Result removeUser( @RequestParam("userIds") List<Integer> userIds) {

        return iUserService.removeUser(userIds);
    }

    @RequestMapping("/list_old")
    public List<UserAndAccountGroup> listUser_old(@RequestParam(name = "pageNum") int pageNum,
                                                  @RequestParam(name = "pageSize") int pageSize,
                                                  @RequestParam(name = "searchStr", required = false) String searchStr) {
        return iUserService.yxxList(searchStr,pageNum,pageNum);
    }

    @RequestMapping("/list")
    public JSONObject listUser(@RequestParam(name = "pageNum") int pageNum,
                               @RequestParam(name = "pageSize") int pageSize,
                               @RequestParam(name = "searchStr", required = false) String searchStr) {

        return iUserService.findUserAccount(searchStr,pageNum,pageSize);
    }

}
