Search in sources :

Example 21 with SysUser

use of com.ruoyi.common.core.domain.entity.SysUser in project wumei-smart by kerwincui.

the class DeviceServiceImpl method insertDeviceAuto.

/**
 * 设备认证后自动添加设备
 *
 * @return 结果
 */
@Override
public int insertDeviceAuto(String serialNumber, Long userId, Long productId) {
    Device device = new Device();
    int random = (int) (Math.random() * (9000)) + 1000;
    device.setDeviceName("设备" + random);
    device.setSerialNumber(serialNumber);
    SysUser user = userService.selectUserById(userId);
    device.setUserId(userId);
    device.setUserName(user.getUserName());
    Product product = productService.selectProductByProductId(productId);
    device.setProductId(productId);
    device.setProductName(product.getProductName());
    device.setTenantId(userId);
    device.setTenantName(user.getUserName());
    device.setFirmwareVersion(BigDecimal.valueOf(1.0));
    device.setStatus(3);
    device.setActiveTime(DateUtils.getNowDate());
    device.setIsShadow(0);
    device.setRssi(0);
    device.setIsCustomLocation(0);
    device.setCreateTime(DateUtils.getNowDate());
    device.setThingsModelValue(JSONObject.toJSONString(getThingsModelDefaultValue(device.getProductId())));
    return deviceMapper.insertDevice(device);
}
Also used : SysUser(com.ruoyi.common.core.domain.entity.SysUser) Device(com.ruoyi.iot.domain.Device) Product(com.ruoyi.iot.domain.Product)

Example 22 with SysUser

use of com.ruoyi.common.core.domain.entity.SysUser in project wumei-smart by kerwincui.

the class DeviceServiceImpl method insertDevice.

/**
 * 新增设备
 *
 * @param device 设备
 * @return 结果
 */
@Override
@Transactional(rollbackFor = Exception.class)
public Device insertDevice(Device device) {
    SysUser sysUser = getLoginUser().getUser();
    // 添加设备
    device.setCreateTime(DateUtils.getNowDate());
    device.setThingsModelValue(JSONObject.toJSONString(getThingsModelDefaultValue(device.getProductId())));
    device.setUserId(sysUser.getUserId());
    device.setUserName(sysUser.getUserName());
    device.setTenantId(sysUser.getUserId());
    device.setTenantName(sysUser.getUserName());
    device.setRssi(0);
    deviceMapper.insertDevice(device);
    // deviceUserMapper.insertDeviceUser(deviceUser);
    return device;
}
Also used : SysUser(com.ruoyi.common.core.domain.entity.SysUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with SysUser

use of com.ruoyi.common.core.domain.entity.SysUser in project wumei-smart by kerwincui.

the class DeviceUserServiceImpl method insertDeviceUser.

/**
 * 新增设备用户
 *
 * @param deviceUser 设备用户
 * @return 结果
 */
@Override
public int insertDeviceUser(DeviceUser deviceUser) {
    List<DeviceUser> deviceUsers = selectDeviceUserList(deviceUser);
    if (!deviceUsers.isEmpty())
        throw new RuntimeException("该用户已添加, 禁止重复添加");
    deviceUser.setCreateTime(DateUtils.getNowDate());
    deviceUser.setIsOwner(0);
    SysUser sysUser = getLoginUser().getUser();
    deviceUser.setTenantId(sysUser.getUserId());
    deviceUser.setTenantName(sysUser.getUserName());
    return deviceUserMapper.insertDeviceUser(deviceUser);
}
Also used : DeviceUser(com.ruoyi.iot.domain.DeviceUser) SysUser(com.ruoyi.common.core.domain.entity.SysUser)

Example 24 with SysUser

use of com.ruoyi.common.core.domain.entity.SysUser in project wumei-smart by kerwincui.

the class ProductAuthorizeServiceImpl method addProductAuthorizeByNum.

/**
 * 根据数量批量新增产品授权码
 * @param productAuthorizeVO
 * @return
 */
@Override
@Transactional
public int addProductAuthorizeByNum(ProductAuthorizeVO productAuthorizeVO) {
    Long productId = productAuthorizeVO.getProductId();
    int createNum = productAuthorizeVO.getCreateNum();
    List<ProductAuthorize> list = new ArrayList<>(createNum);
    SysUser user = getLoginUser().getUser();
    for (int i = 0; i < createNum; i++) {
        ProductAuthorize authorize = new ProductAuthorize();
        authorize.setProductId(productId);
        authorize.setCreateBy(user.getUserName());
        authorize.setCreateTime(DateUtils.getNowDate());
        authorize.setAuthorizeCode(IdUtils.fastSimpleUUID().toUpperCase());
        list.add(authorize);
    }
    return productAuthorizeMapper.insertBatchAuthorize(list);
}
Also used : SysUser(com.ruoyi.common.core.domain.entity.SysUser) ProductAuthorize(com.ruoyi.iot.domain.ProductAuthorize) ArrayList(java.util.ArrayList) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with SysUser

use of com.ruoyi.common.core.domain.entity.SysUser in project wumei-smart by kerwincui.

the class SocialLoginServiceImpl method callback.

@Override
public String callback(String source, AuthCallback authCallback, HttpServletRequest httpServletRequest) {
    AuthRequestWrap authRequestWrap = null;
    try {
        authRequestWrap = iAuthRequestFactory.getAuthRequest(source);
        checkSocialPlatform(authRequestWrap.getSocialPlatform());
        AuthResponse<AuthUser> authResponse = authRequestWrap.getAuthRequest().login(authCallback);
        String bindId = null;
        String loginId = null;
        if (authResponse.ok()) {
            SocialUser socialUser = findSocialUser(authResponse.getData().getUuid(), authResponse.getData().getSource());
            createOrUpdateSocialUser(socialUser, authResponse.getData());
            if (socialUser == null) {
                // 第一次登录
                bindId = genBindId(authResponse.getData());
            } else if (socialUser.getSysUserId() == null || socialUser.getSysUserId() <= 0) {
                // 初次绑定
                bindId = genBindId(authResponse.getData());
            } else {
                // 查看是否已经绑定
                SysUser sysUser = iSysUserService.selectUserById(socialUser.getSysUserId());
                if (sysUser == null) {
                    bindId = genBindId(authResponse.getData());
                } else {
                    // 直接登录跳转
                    loginId = genLoginId(sysUser);
                }
            }
            if (StringUtils.isNotEmpty(bindId)) {
                return authRequestWrap.getSocialPlatform().getBindUri() + bindId;
            } else {
                return authRequestWrap.getSocialPlatform().getRedirectLoginUri() + loginId;
            }
        } else {
            log.error("登录授权异常,code:{}, msg:{}", authResponse.getCode(), authResponse.getMsg());
            String errorId = genErrorId(authResponse.getMsg());
            return authRequestWrap.getSocialPlatform().getErrorMsgUri() + errorId;
        }
    } catch (AuthException authException) {
        // 返回错误信息
        log.error("", authException);
        if (authRequestWrap != null) {
            String errorId = genErrorId(authException.getMessage());
            return authRequestWrap.getSocialPlatform().getErrorMsgUri() + errorId;
        } else {
            return httpServletRequest.getServerName() + httpServletRequest.getServerPort();
        }
    } catch (Exception exception) {
        log.error("", exception);
        return HTTPS + httpServletRequest.getServerName();
    }
}
Also used : AuthRequestWrap(com.ruoyi.iot.model.login.AuthRequestWrap) SysUser(com.ruoyi.common.core.domain.entity.SysUser) SocialUser(com.ruoyi.iot.domain.SocialUser) AuthException(me.zhyd.oauth.exception.AuthException) AuthUser(me.zhyd.oauth.model.AuthUser) AuthException(me.zhyd.oauth.exception.AuthException)

Aggregations

SysUser (com.ruoyi.common.core.domain.entity.SysUser)78 Log (com.ruoyi.common.annotation.Log)16 SysRole (com.ruoyi.common.core.domain.entity.SysRole)13 LoginUser (com.ruoyi.common.core.domain.model.LoginUser)13 GetMapping (org.springframework.web.bind.annotation.GetMapping)11 AjaxResult (com.ruoyi.common.core.domain.AjaxResult)10 ServiceException (com.ruoyi.common.exception.ServiceException)10 SaCheckPermission (cn.dev33.satoken.annotation.SaCheckPermission)8 ExcelUtil (com.ruoyi.common.utils.poi.ExcelUtil)8 Transactional (org.springframework.transaction.annotation.Transactional)8 UserConstants (com.ruoyi.common.constant.UserConstants)7 BaseController (com.ruoyi.common.core.controller.BaseController)7 TableDataInfo (com.ruoyi.common.core.page.TableDataInfo)7 BusinessType (com.ruoyi.common.enums.BusinessType)7 StringUtils (com.ruoyi.common.utils.StringUtils)7 ISysPostService (com.ruoyi.system.service.ISysPostService)7 ISysRoleService (com.ruoyi.system.service.ISysRoleService)7 ISysUserService (com.ruoyi.system.service.ISysUserService)7 List (java.util.List)7 Collectors (java.util.stream.Collectors)7