package com.friday.custody.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.friday.custody.entity.TempAuthorizationInfoEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.annotations.Mapper;

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

/**
 * 
 * 
 * @author lyb
 * @email k0051582@gmail.com
 * @date 2023-06-01 11:09:50
 */
@Mapper
public interface TempAuthorizationInfoDao extends BaseMapper<TempAuthorizationInfoEntity> {

    default List<TempAuthorizationInfoEntity> queryListByTrustNo(String trustNo, String version){
        LambdaQueryWrapper<TempAuthorizationInfoEntity> queryWrapper = new LambdaQueryWrapper();
        if (StringUtils.isNotBlank(trustNo)) {
            queryWrapper.eq(TempAuthorizationInfoEntity::getTrustNo, trustNo);
        }
        queryWrapper.eq(TempAuthorizationInfoEntity::getVersion, version);
        List<TempAuthorizationInfoEntity> entityList = selectList(queryWrapper);
        return entityList;
    }

    default int updateOne(TempAuthorizationInfoEntity tempAuthorizationInfoEntity){
        LambdaUpdateWrapper<TempAuthorizationInfoEntity> updateWrapper = new LambdaUpdateWrapper();
        updateWrapper.eq(TempAuthorizationInfoEntity::getAppKey, tempAuthorizationInfoEntity.getAppKey());
        updateWrapper.eq(TempAuthorizationInfoEntity::getTrustNo, tempAuthorizationInfoEntity.getTrustNo());
        updateWrapper.eq(TempAuthorizationInfoEntity::getTenantName, tempAuthorizationInfoEntity.getTenantName());
        tempAuthorizationInfoEntity.setUpdateTime(new Date());
        int update = update(tempAuthorizationInfoEntity,updateWrapper);
        return update;
    }
}
