package com.yonge.cooleshow.auth.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.util.Date;
import java.util.List;

import javax.validation.Valid;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.yonge.cooleshow.auth.api.dto.RealnameAuthReq;
import com.yonge.cooleshow.auth.api.dto.SysUserQueryInfo;
import com.yonge.cooleshow.auth.api.dto.UpdatePasswordDto;
import com.yonge.cooleshow.auth.api.dto.UserSetReq;
import com.yonge.cooleshow.auth.api.entity.SysRole;
import com.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.cooleshow.auth.api.vo.UserSetVo;
import com.yonge.cooleshow.auth.core.service.CustomTokenServices;
import com.yonge.cooleshow.auth.service.SysConfigService;
import com.yonge.cooleshow.auth.service.SysRoleService;
import com.yonge.cooleshow.auth.service.SysUserRoleService;
import com.yonge.cooleshow.auth.service.SysUserService;
import com.yonge.cooleshow.auth.web.controller.queryInfo.RoleQueryInfo;
import com.yonge.cooleshow.common.constant.CommonConstants;
import com.yonge.cooleshow.common.constant.SysConfigConstant;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.yonge.cooleshow.common.exception.BizException;
import com.yonge.cooleshow.common.security.AuthUser;
import com.yonge.cooleshow.common.security.SecurityConstants;
import com.yonge.cooleshow.common.security.SecurityUtils;
import com.yonge.cooleshow.common.service.IdGeneratorService;
import com.yonge.toolset.thirdparty.user.realname.RealnameAuthenticationPlugin;
import com.yonge.toolset.utils.date.DateUtil;
import com.yonge.toolset.utils.idcard.IdcardInfoExtractor;
import com.yonge.toolset.utils.idcard.IdcardValidator;
import com.yonge.toolset.utils.string.StringUtil;

@RestController()
@RequestMapping("user")
@Api(tags = "会员服务")
public class UserController extends BaseController {
    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private SysRoleService sysRoleService;
    @Autowired
    private SysUserRoleService sysUserRoleService;
    @Autowired
    private IdGeneratorService smsCodeService;

	@Autowired
	private CustomTokenServices tokenService;
	
    @Value("${message.debugMode}")
    private boolean debugMode;
    
    @Autowired
    private RealnameAuthenticationPlugin realnameAuthenticationPlugin;
    @Autowired
    private SysConfigService sysConfigService;

    @ApiOperation(value = "分页查询用户信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "userType", value = "用户类型", required = false, dataType = "String"),
            @ApiImplicitParam(name = "createStartDate", value = "开始注册时间", required = true, dataType = "String"),
            @ApiImplicitParam(name = "createEndDate", value = "结束注册时间", required = true, dataType = "String")})
    @GetMapping(value = "/queryPage")
    @PreAuthorize("@pcs.hasPermissions('user/queryPage')")
    public Object queryPage(SysUserQueryInfo queryInfo) {
        return succeed(sysUserService.queryPage(queryInfo));
    }


    @ApiOperation(value = "查询用户信息接口")
    @GetMapping("/query")
    @PreAuthorize("@pcs.hasPermissions('user/query')")
    public Object query() {
        AuthUser user = SecurityUtils.getUser();
        if (user != null) {
            return succeed(sysUserService.get(user.getUserId()));
        }
        return failed();
    }

    @ApiOperation(value = "根据用户编号获取用户基本信息")
    @GetMapping("/getBasic")
    public Object getBasic(Long userId) {
        if (userId == null) {
            return failed("参数校验异常");
        }
        return succeed(sysUserService.getBasic(userId));
    }

    @GetMapping(value = "/findByPhone")
    public Object findByPhone(String mobile) {
        return succeed(sysUserService.queryByPhone(mobile));
    }

    @GetMapping(value = "/queryUserByPhone")
    public SysUser queryUserByPhone(String mobile) {
        return sysUserService.queryByPhone(mobile);
    }

    @GetMapping(value = "/noAuth/queryUserByPhone")
    public Object noAuthQueryUserByPhone(String mobile) {
        SysUser sysUser = sysUserService.queryByPhone(mobile);
        if (sysUser == null) {
            return succeed(0);
        }
        return succeed(1);
    }

    @GetMapping(value = "/queryUserById/{userId}")
    public SysUser queryUserById(@PathVariable("userId") Long userId) {
        return sysUserService.get(userId);
    }

    @PostMapping(value = "/updateSysUser", consumes = MediaType.APPLICATION_JSON_VALUE)
    public HttpResponseResult<Boolean> updateSysUser(@RequestBody SysUser user) {
        user.setUpdateTime(new Date());
        sysUserService.update(user);
        return HttpResponseResult.succeed(true);
    }

    @ApiOperation(value = "新增用户")
    @PostMapping(value = "/add", consumes = MediaType.APPLICATION_JSON_VALUE)
    public HttpResponseResult<Long> add(@RequestBody SysUser sysUser) {
        return succeed(sysUserService.add(sysUser));
    }

    @ApiOperation(value = "设置用户密码")
    @PostMapping(value = "/setPassword", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({@ApiImplicitParam(name = "password", value = "密码", required = true, dataType = "String"),
            @ApiImplicitParam(name = "id", value = "用户id", required = true, dataType = "Long")})
    public Object setPassword(String password, Long id) {
        if (StringUtils.isEmpty(password) || null == id) {
            return failed("参数校验失败");
        }
        SysUser sysUser = sysUserService.get(id);
        if (sysUser == null) {
            return failed("用户不存在");
        }

        password = new BCryptPasswordEncoder().encode(password);
        sysUser.setPassword(password);
        sysUser.setUpdateTime(new Date());
        sysUserService.update(sysUser);
        return succeed();
    }

    @ApiOperation(value = "设置用户名密码")
    @PostMapping(value = "/setUsernameAndPassword", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({@ApiImplicitParam(name = "password", value = "密码", required = true, dataType = "String"),
            @ApiImplicitParam(name = "username", value = "用户名", dataType = "String")})
    public Object setPassword(String password, String username) {
        if (StringUtils.isEmpty(password)) {
            return failed("参数校验失败");
        }
        AuthUser authUser = SecurityUtils.getUser();
        if (authUser == null) {
            return failed("获取用户信息失败");
        }
        SysUser sysUser = sysUserService.get(authUser.getUserId());
        if (sysUser == null) {
            return failed("用户不存在");
        }
        if(!StringUtil.isEmpty(username)){
            if (sysUser.getUserType().contains("SYSTEM")) {
                sysUser.setRealName(username);
            }
            sysUser.setUsername(username);
        }
		/*if(StringUtils.isEmpty(sysUser.getImToken())){
			ImResult register = imFeignService.register(new ImUserModel(sysUser.getId().toString(), username, sysUser.getAvatar()));
			sysUser.setImToken(register.getToken());
		}else {
			imFeignService.update(new ImUserModel(sysUser.getId().toString(),username,sysUser.getAvatar()));
		}*/
        password = new BCryptPasswordEncoder().encode(password);
        sysUser.setPassword(password);
        sysUser.setUpdateTime(new Date());
        sysUserService.update(sysUser);
        return succeed();
    }

    @ApiOperation(value = "手机验证码修改密码")
    @PostMapping(value = "/updatePassword", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({@ApiImplicitParam(name = "mobile", value = "手机号", required = true, dataType = "String"),
            @ApiImplicitParam(name = "authCode", value = "验证码", required = true, dataType = "String"),
            @ApiImplicitParam(name = "newPassword", value = "新密码", required = true, dataType = "String")})
    public Object updatePassword(String mobile, String authCode, String newPassword) {
        if (StringUtils.isEmpty(mobile) || StringUtils.isEmpty(authCode) || StringUtils.isEmpty(newPassword)) {
            return failed("参数校验异常");
        }
        SysUser sysUser = sysUserService.queryByPhone(mobile);
        if (sysUser == null) {
            return failed("用户不存在");
        }
        if (smsCodeService.verifyValidCode(mobile, authCode)) {
            String password = new BCryptPasswordEncoder().encode(newPassword);
            sysUser.setPassword(password);
            sysUser.setUpdateTime(new Date());
            sysUserService.update(sysUser);
            return succeed();
        } else {
            return failed("验证码错误");
        }
    }

    @ApiOperation(value = "原密码修改密码")
    @PostMapping(value = "/updatePasswordByOldPassword")
    public Object updatePasswordByOldPassword(@RequestBody UpdatePasswordDto updatePasswordDto) {
        if (!updatePasswordDto.getNewPasswordFirst().equals(updatePasswordDto.getNewPasswordSecond())) {
            return failed("两次输入密码不一致");
        }
        AuthUser authUser = SecurityUtils.getUser();
        SysUser sysUser = sysUserService.get(authUser.getUserId());
        if (sysUser == null) {
            return failed("用户不存在");
        }
        if (!new BCryptPasswordEncoder().matches(updatePasswordDto.getOldPassword(), sysUser.getPassword())) {
            return failed("原密码错误");
        }
        sysUser.setPassword(new BCryptPasswordEncoder().encode(updatePasswordDto.getNewPasswordFirst()));
        sysUser.setUpdateTime(new Date());
        sysUserService.update(sysUser);
        return succeed();
    }

    @ApiOperation(value = "修改手机号")
    @PostMapping(value = "/updatePhone")
    public Object updatePhone(String oldPhone, String authCode, String newPhone) {
        if (StringUtils.isEmpty(oldPhone) || StringUtils.isEmpty(authCode) || StringUtils.isEmpty(newPhone)) {
            return failed("参数校验异常");
        }
        if (oldPhone.equals(newPhone)) {
            return failed("新旧手机号一致");
        }
        SysUser sysUser = sysUserService.queryByPhone(oldPhone);
        if (sysUser == null) {
            return failed("用户不存在");
        }
        SysUser newSysUser = sysUserService.queryByPhone(newPhone);
        if (newSysUser != null) {
            return failed("手机号被占用");
        }
        if (smsCodeService.verifyValidCode(newPhone, authCode)) {
            sysUser.setPhone(newPhone);
            sysUser.setUpdateTime(new Date());
            sysUserService.update(sysUser);
            return succeed();
        } else {
            return failed("验证码错误");
        }
    }

    @ApiOperation(value = "管理后台修改密码")
    @PostMapping(value = "/updatePassword2", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams({@ApiImplicitParam(name = "mobile", value = "手机号", required = true, dataType = "String"),
            @ApiImplicitParam(name = "userId", value = "用户编号", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "newPassword", value = "新密码", required = true, dataType = "String")})
    public Object updatePassword2(Long userId, String mobile, String newPassword) {
        if (StringUtils.isEmpty(mobile) || userId == null || StringUtils.isEmpty(newPassword)) {
            return failed("参数校验异常");
        }
        SysUser sysUser = sysUserService.queryByPhone(mobile);
        if (sysUser == null) {
            return failed("用户不存在");
        }
        if (sysUser.getId().intValue() != userId) {
            return failed("非法操作");
        }
        String password = new BCryptPasswordEncoder().encode(newPassword);
        sysUser.setPassword(password);
        sysUser.setUpdateTime(new Date());
        sysUserService.update(sysUser);
        return succeed();
    }

    /**
     * 启用/冻结
     */
    @GetMapping(value = "/changeLock/{userId}/{lockFlag}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "userId", paramType = "path", dataType = "long", required = true),
            @ApiImplicitParam(name = "lockFlag", value = "锁定状态 0-正常，9-锁定", paramType = "path", dataType = "int", required = true)
    })
    @ApiOperation(value = "启用/冻结", notes = "传入lockFlag")
    public HttpResponseResult<Boolean> changeLock(@PathVariable("userId") Long userId, @PathVariable("lockFlag") Integer lockFlag) {
        if (userId == null && lockFlag != 0 && lockFlag != 9) {
            return failed("参数校验异常");
        }
        SysUser sysUser = sysUserService.queryUserInfo(userId);
        if (sysUser == null) {
            return failed("用户不存在");
        }
        if (sysUser.getId() != userId.longValue()) {
            return failed("非法操作");
        }
        sysUser.setLockFlag(lockFlag);
        
        if(lockFlag == 1){
        	if(sysUser.getUserType().contains("STUDENT")){
        		tokenService.revokeToken("STUDENT", sysUser.getPhone());
        	}
        	if(sysUser.getUserType().contains("TEACHER")){
        		tokenService.revokeToken("TEACHER", sysUser.getPhone());
        	}
        	if(sysUser.getUserType().contains("SYSTEM")){
        		tokenService.revokeToken("SYSTEM", sysUser.getPhone());
        	}
        }
        sysUser.setUpdateTime(new Date());
        sysUserService.update(sysUser);
        return succeed();
    }

    /**
     * 重置密码
     */
    @GetMapping(value = "/resetPassword/{userId}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "userId", paramType = "path", dataType = "long", required = true),
    })
    @ApiOperation(value = "重置密码", notes = "传入userId")
    public HttpResponseResult<Boolean> resetPassword(@PathVariable("userId") Long userId) {
        if (userId == null) {
            return failed("参数校验异常");
        }
        SysUser sysUser = sysUserService.queryUserInfo(userId);
        if (sysUser == null) {
            return failed("用户不存在");
        }
        if (sysUser.getId() != userId.longValue()) {
            return failed("非法操作");
        }

        String password = new BCryptPasswordEncoder().encode(CommonConstants.DEFULT_PASSWORD);
        sysUser.setPassword(password);
        sysUser.setUpdateTime(new Date());
        sysUserService.update(sysUser);
        return succeed();
    }

    @ApiOperation(value = "修改用户")
    @PostMapping(value = "/update", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public Object update(SysUser sysUser) {
        AuthUser user = SecurityUtils.getUser();
        if (user != null) {
            Date date = new Date();
            sysUser.setId(user.getUserId());
            sysUser.setUpdateTime(date);
            if (sysUser.getBirthdate() != null && DateUtil.daysBetween(sysUser.getBirthdate(), date) <= 0) {
                throw new BizException("出生日期不可超过当前时间");
            }
            //手机号不能被占用
            if (!StringUtil.isEmpty(sysUser.getPhone())) {
                SysUser newSysUser = sysUserService.queryByPhone(sysUser.getPhone());
                if (newSysUser != null && !newSysUser.getId().equals(sysUser.getId())) {
                    return failed("手机号被占用");
                }
            }
            sysUser.setIsSuperAdmin(null);
            sysUserService.updateBaseInfo(sysUser);
            return succeed();
        }
        return failed();
    }

    @ApiOperation(value = "刷新token")
    @PostMapping(value = "/refreshImToken")
    public Object refreshImToken() {
        AuthUser user = SecurityUtils.getUser();
        if (user != null) {
            SysUser sysUser = sysUserService.get(user.getUserId());
            String username;
            if (sysUser.getUserType().contains("TEACHER") || sysUser.getUserType().contains("SYSTEM")) {
                username = sysUser.getRealName();
            } else {
                username = sysUser.getUsername();
            }
            if (StringUtils.isEmpty(username)) {
                return failed("获取Token失败: 用户名为空");
            } else {
				/*ImResult register = imFeignService.register(new ImUserModel(sysUser.getId().toString(), username, sysUser.getAvatar()));
				if(StringUtils.isEmpty(register.getToken())){
					return failed("获取Token失败: 请联系教务老师");
				}
				sysUser.setImToken(register.getToken());
				sysUserService.refreshImToken(sysUser);
				return succeed(register.getToken());*/
            }
        }
        return failed();
    }

    @ApiOperation(value = "校验用户手机号和密码")
    @GetMapping(value = "/checkUser")
    public Object checkUser(String phone, String password) {
        if (StringUtils.isEmpty(phone) || StringUtils.isEmpty(password)) {
            throw new BizException("请录入用户名和密码");
        }
        AuthUser user = SecurityUtils.getUser();
        if (user != null) {
            SysUser sysUser = sysUserService.get(user.getUserId());
            if (!sysUser.getPhone().equals(phone)) {
                return failed("手机号校验失败");
            }
            if (new BCryptPasswordEncoder().matches(password, sysUser.getPassword())) {
                return succeed();
            } else {
                return failed("密码校验失败");
            }
        }
        return failed();
    }

    @ApiOperation(value = "获取用户角色列表")
    @GetMapping("/getRole")
    @PreAuthorize("@pcs.hasPermissions('user/getRole')")
    public HttpResponseResult<List<SysRole>> getRole() {
        AuthUser user = SecurityUtils.getUser();
        if (user != null) {
            SysUser sysUser = sysUserService.get(user.getUserId());
            if (sysUser.getIsSuperAdmin()) {
            	RoleQueryInfo queryInfo = new RoleQueryInfo();
                queryInfo.setRows(9999);
                queryInfo.setIsEnable(true);
                return succeed(sysRoleService.queryPage(queryInfo).getRows());
            }
            return succeed(sysRoleService.findRoleByUserId(user.getUserId()));
        }
        return failed();
    }

    @ApiOperation(value = "用户角色新增")
    @ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户编号", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "roleIds", value = "角色id,逗号分隔", required = true, dataType = "String")})
    @PostMapping(value = "/addRole", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    @PreAuthorize("@pcs.hasPermissions('user/addRole')")
    public HttpResponseResult<Boolean> getRole(String userId, String roleIds) {
        if (StringUtils.isEmpty(userId) || StringUtils.isEmpty(roleIds)) {
            return failed(SecurityConstants.PARAM_VERIFY_EXCEPTION);
        }
        return status(sysUserRoleService.batchInsert(Long.parseLong(userId), roleIds));
    }

    @ApiOperation(value = "用户角色删除")
    @ApiImplicitParams({@ApiImplicitParam(name = "userId", value = "用户编号", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "roleIds", value = "角色id,逗号分隔", required = true, dataType = "String")})
    @PostMapping(value = "/delRole", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    @PreAuthorize("@pcs.hasPermissions('user/delRole')")
    public Object delRole(String userId, String roleIds) {
        if (StringUtils.isEmpty(userId) || StringUtils.isEmpty(roleIds)) {
            return failed(SecurityConstants.PARAM_VERIFY_EXCEPTION);
        }
        sysUserRoleService.batchDel(Long.parseLong(userId), roleIds);
        return succeed();
    }


    @PostMapping("/realNameAuth")
    @ApiOperation(value = "实名认证", notes = "传入realNameAuthDto")
    @ResponseBody
    public HttpResponseResult<IdcardInfoExtractor> realNameAuth(@Valid @RequestBody RealnameAuthReq realNameAuthDto) {
        AuthUser authUser = SecurityUtils.getUser();
        if (authUser == null) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        SysUser user = sysUserService.get(authUser.getUserId());
        if (user == null || null == user.getId()) {
            return failed("用户不存在");
        }
        IdcardValidator idcardValidator = new IdcardValidator();
        //验证身份证号合法性
        boolean validatedAllIdcard = idcardValidator.isValidatedAllIdcard(realNameAuthDto.getIdCardNo());
        if (!validatedAllIdcard) {
            return failed("身份证号不合法");
        }
        //通过身份证号获取身份信息
        IdcardInfoExtractor idcardInfoExtractor = new IdcardInfoExtractor(realNameAuthDto.getIdCardNo(), validatedAllIdcard);
        //todo 通过环境，不做实名判断
        try {
            boolean verify = realnameAuthenticationPlugin.verify(realNameAuthDto.getRealName(), realNameAuthDto.getIdCardNo());
            if (!verify) {
                return failed("未通过实名认证");
            }
        }catch (Exception e){
            e.printStackTrace();
            return failed("未通过实名认证");
        }

        if (realNameAuthDto.getSave()) {
            String defaultHeard = sysConfigService.findConfigValue(SysConfigConstant.DEFAULT_HEARD);
            if (StringUtil.isEmpty(user.getAvatar()) || user.getAvatar().equals(defaultHeard)) {
                user.setAvatar(
                        0 == idcardInfoExtractor.getGender() ? sysConfigService.findConfigValue(SysConfigConstant.DEFAULT_HEARD_GIRL) : sysConfigService.findConfigValue(SysConfigConstant.DEFAULT_HEARD_BOY));
            }
            realNameAuthDto.setUserId(user.getId());
            realNameAuthDto.setGender(idcardInfoExtractor.getGender());
            realNameAuthDto.setBirthday(idcardInfoExtractor.getBirthday());
            realNameAuthDto.setAvatar(user.getAvatar());
            //实名认证通过后立刻保存
            sysUserService.updateUserCard(realNameAuthDto);
        }
        return succeed(idcardInfoExtractor);
    }

    @GetMapping("/getSetDetail")
    @ApiOperation(value = "获取设置详情")
    public HttpResponseResult<UserSetVo> getSetDetail() {
        AuthUser authUser = SecurityUtils.getUser();
        if (authUser == null) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        SysUser user = sysUserService.get(authUser.getUserId());
        if (user == null || null == user.getId()) {
            return failed("用户不存在");
        }
        UserSetVo detail = sysUserService.getSetDetail(user.getId());
        return succeed(detail);
    }

    @PostMapping("/submitSetDetail")
    @ApiOperation(value = "修改设置信息", notes = "传入teacher")
    public HttpResponseResult<UserSetVo> submitSetDetail(@RequestBody UserSetReq setReq) {
        AuthUser authUser = SecurityUtils.getUser();
        if (authUser == null) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        SysUser user = sysUserService.get(authUser.getUserId());
        if (user == null || null == user.getId()) {
            return failed("用户不存在");
        }
        //设置
        sysUserService.submitSetDetail(setReq, user.getId());
        return succeed(sysUserService.getSetDetail(user.getId()));
    }

    @PostMapping(value = "/bindOpenId")
    public HttpResponseResult<Boolean> bindOpenId(@RequestBody SysUser param) {
        AuthUser authUser = SecurityUtils.getUser();
        if (authUser == null) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        SysUser user = sysUserService.get(authUser.getUserId());
        if (user == null || null == user.getId()) {
            return failed("用户不存在");
        }
        user.setWechatId(
                StringUtil.isEmpty(param.getWechatId()) ? user.getWxOpenid() : param.getWechatId()
        );
        user.setQqOpenid(
                StringUtil.isEmpty(param.getQqOpenid()) ? user.getQqOpenid() : param.getQqOpenid()
        );
        user.setUpdateTime(new Date());
        sysUserService.update(user);
        return HttpResponseResult.succeed(true);
    }

    @ApiOperation(value = "查询平台用户信息")
    @PostMapping(value = "/list")
    public HttpResponseResult<List<SysUser>> page(@RequestBody SysUserQueryInfo queryInfo) {
        return succeed(sysUserService.queryEmployeeList(queryInfo));
    }
}
