package easydo.technology.system.rest;


import easydo.technology.annotation.WebLog;
import easydo.technology.system.domain.User;
import easydo.technology.system.domain.vo.UserDto;
import easydo.technology.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 系统用户 前端控制器
 * </p>
 *
 * @author wyn
 * @since 2020-09-30
 */
@RestController
@RequestMapping("/sysuser")
public class SysUserController {

    @Autowired
    private UserService sysUserService;

    @WebLog
    @RequestMapping(value = "/getList")
    public ResponseEntity<Object> getList(@RequestBody Map<Object,Object> paramMap){
        Map<String, Object> result = new HashMap<>();
        List<User> list = null;
        try {
            list = sysUserService.list();
            result.put("userList",list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

    @RequestMapping(value = "/getUserStrList")
    public ResponseEntity<Object> getUserStrList(@RequestBody Map<Object,Object> paramMap){
        Map<String, Object> result = new HashMap<>();
        List<UserDto> userList = new ArrayList<>();
        List<User> list = null;
        try {
            list = sysUserService.list();
            for(User user:list){
                UserDto vo = new UserDto();
                vo.setId(user.getId().toString());
                vo.setNickName(user.getNickName());
                userList.add(vo);
            }
            result.put("userList",userList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new ResponseEntity<>(result, HttpStatus.OK);
    }

}
