Search in sources :

Example 1 with ProductAuthorize

use of com.ruoyi.iot.domain.ProductAuthorize 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 2 with ProductAuthorize

use of com.ruoyi.iot.domain.ProductAuthorize in project wumei-smart by kerwincui.

the class ProductAuthorizeServiceImpl method boundProductAuthorize.

/**
 * 根据产品id和设备序列号绑定授权码
 *
 * @param productAuthorize
 * @return
 */
@Override
@Transactional
public int boundProductAuthorize(ProductAuthorize productAuthorize) {
    ProductAuthorize authorize = null;
    if (StringUtils.isEmpty(productAuthorize.getAuthorizeCode())) {
        // TODO-kami: 2022/4/11 13:34 后期无需查询,硬件调用直接传入参数,可以删除
        authorize = productAuthorizeMapper.selectOneUnboundAuthorizeByProductId(productAuthorize);
        productAuthorize.setAuthorizeCode(authorize.getAuthorizeCode());
    } else {
        authorize = productAuthorizeMapper.selectOneUnboundAuthorizeByAuthorizeCode(productAuthorize);
    }
    if (authorize == null) {
        throw new ServiceException("授权码数据异常", HttpStatus.BAD_REQUEST);
    }
    productAuthorize.setAuthorizeId(authorize.getAuthorizeId());
    productAuthorize.setUpdateTime(DateUtils.getNowDate());
    return productAuthorizeMapper.updateProductAuthorize(productAuthorize);
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) ProductAuthorize(com.ruoyi.iot.domain.ProductAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ProductAuthorize (com.ruoyi.iot.domain.ProductAuthorize)2 Transactional (org.springframework.transaction.annotation.Transactional)2 SysUser (com.ruoyi.common.core.domain.entity.SysUser)1 ServiceException (com.ruoyi.common.exception.ServiceException)1 ArrayList (java.util.ArrayList)1