package com.tofly.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tofly.base.entity.User;
import com.tofly.base.entity.UserMiddle;
import com.tofly.base.entity.UserRoles;
import com.tofly.base.mapper.UserMiddleMapper;
import com.tofly.base.service.UserMiddleService;
import com.tofly.base.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("userMiddleService")
public class UserMiddleServiceImpl extends ServiceImpl<UserMiddleMapper, UserMiddle> implements UserMiddleService {

    @Autowired
    private UserService userService;

    @Override
    public boolean synchronizeUser(String userName, String passWord, String realName, String flag) {
        return true;
    }

    @Override
    public boolean sendUserNewUpdate(UserRoles user) {
        // 判断当前用户是否存在
        User one = userService.getOne(new QueryWrapper<User>().lambda().eq(User::getUsername, user.getUsername()));
        // 获取当前用户新增/修改 绑定公司/部门/角色/中文名称
        if (null != one) {
            user.setId(one.getId());
            userService.updateByIdNew(null, user, null, user.getRoles(), user.getUserdeptList());
        } else {
            // 新增用户
            userService.saveNew(null, user, null);
        }
        return true;
    }

    @Override
    public boolean sendMarketingUser(String userName, String passWord, String realName, String flag) {
        return true;
    }


}
