/**
 * 文件：UserController.java
 * 版本：1.0.0
 * 日期：
 * Copyright &reg;
 * All right reserved.
 */
package com.mortals.xhx.base.system.user.web;


import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.IBaseEnum;
import com.mortals.framework.common.Rest;
import com.mortals.framework.common.code.UserType;
import com.mortals.framework.model.Context;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.role.model.RoleEntity;
import com.mortals.xhx.base.system.role.service.RoleService;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.code.UserStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>Title: 用户信息</p>
 * <p>Description: UserController  </p>
 * <p>Copyright: Copyright &reg;  </p>
 * <p>Company: </p>
 * @author
 * @version 1.0.0
 */
@RestController
@RequestMapping("user")
public class UserController extends BaseCRUDJsonBodyMappingController<UserService, UserEntity, Long> {

    @Autowired
    private RoleService roleService;

    public UserController() {
        super.setModuleDesc("用户信息");
    }

    @Override
    protected void init(Map<String, Object> model, Context context) {

        this.addDict(model,"userType", IBaseEnum.getEnumMap(UserType.class));
        this.addDict(model,"status", UserStatus.getEnumMap());
        List<RoleEntity> roleList = roleService.find(new RoleEntity());
        this.addDict(model,"roleId", roleList.stream().collect(Collectors.toMap(e->e.getId().toString(), e->e.getName())));
        super.init(model, context);
    }


    @PostMapping({"refreshUser"})
    @UnAuth
    public Rest<Object> refreshUser() {
        log.info("刷新用户");
        this.service.refreshUser();
        return Rest.ok("用户同步刷新操作成功");
    }

}