package org.wcs.mapper.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.wcs.mapper.AppBaseGroupPermissionMapper;
import org.wcs.mapper.intf.AppBaseGroupPermissionService;
import org.wcs.model.po.app.AppBaseGroupPermission;
import org.wcs.utils.AppStringUtils;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class AppBaseGroupPermissionDao extends ServiceImpl<AppBaseGroupPermissionMapper, AppBaseGroupPermission> implements AppBaseGroupPermissionService {

    @Override
    public boolean deleteByUserGroupThrowException(String userGroup) {
        if(AppStringUtils.isEmpty(userGroup)) {
            throw new RuntimeException("删除用户组权限表异常，用户组不能为空");
        }
        LambdaQueryWrapper<AppBaseGroupPermission> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AppBaseGroupPermission::getUserGroup, userGroup);
        return super.remove(queryWrapper);
    }

    @Override
    public int insertThrowException(List<AppBaseGroupPermission> appBaseGroupPermissionList) {
        if(appBaseGroupPermissionList == null || appBaseGroupPermissionList.isEmpty()) {
            return 0;
        }
        LocalDateTime now = LocalDateTime.now();
        for(AppBaseGroupPermission appBaseGroupPermission : appBaseGroupPermissionList) {
            appBaseGroupPermission.setCreatTime(now);
        }
        return super.saveBatch(appBaseGroupPermissionList) ? appBaseGroupPermissionList.size() : 0;
    }
}
