package com.bonus.core.allocation.canteen.service;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonus.core.allocation.canteen.mapper.DzAllocCanteenAuthMapper;
import com.bonus.core.allocation.canteen.model.DzAllocCanteenAuth;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 食堂访问权限表 service
 *
 * @author shihao.li
 * @date 2024/8/22 16:02
 */
@Slf4j
@Service
public class DzAllocCanteenAuthService extends ServiceImpl<DzAllocCanteenAuthMapper, DzAllocCanteenAuth> {

//    /**
//     * 查询访问权限
//     */
//    public DzCanteenAuthModel queryAccessAuth() {
//        List<DzAllocCanteenAuth> canteenAuthList = this.list(Wrappers.lambdaQuery(DzAllocCanteenAuth.class)
//                .orderByAsc(DzAllocCanteenAuth::getId));
//        if (CollUtil.isEmpty(canteenAuthList)) {
//            return new DzCanteenAuthModel();
//        }
//        List<DzCanteenAuthDTO> canteenAuthDTOList = new ArrayList<>();
//        List<DzCanteenAuthDTO> marketAuthDTOList = new ArrayList<>();
//        for (DzAllocCanteenAuth allocCanteenAuth : canteenAuthList) {
//            if (AllocCanteenTypeEnum.CANTEEN.getKey().equals(allocCanteenAuth.getCanteenType())) {
//                canteenAuthDTOList.add(new DzCanteenAuthDTO(allocCanteenAuth));
//            } else {
//                marketAuthDTOList.add(new DzCanteenAuthDTO(allocCanteenAuth));
//            }
//        }
//        return new DzCanteenAuthModel(canteenAuthDTOList, marketAuthDTOList);
//    }
//
//    /**
//     * 保存访问权限
//     * 先清空数据库，再进行保存操作
//     */
//    @Transactional(rollbackFor = Exception.class)
//    public void saveAccessAuth(DzCanteenAuthModel canteenAuthModel) {
//        this.baseMapper.deleteAll();
//
//        List<DzCanteenAuthDTO> canteenAuthDTOList = canteenAuthModel.getCanteenAuthDTOList();
//        List<DzCanteenAuthDTO> marketAuthDTOList = canteenAuthModel.getMarketAuthDTOList();
//        if (CollUtil.isEmpty(canteenAuthDTOList) && CollUtil.isEmpty(marketAuthDTOList)) {
//            return;
//        }
//        List<DzAllocCanteenAuth> canteenAuthList = new ArrayList<>();
//        if (CollUtil.isNotEmpty(canteenAuthDTOList)) {
//            for (DzCanteenAuthDTO canteenAuthDTO : canteenAuthDTOList) {
//                canteenAuthList.add(new DzAllocCanteenAuth(canteenAuthDTO, AllocCanteenTypeEnum.CANTEEN.getKey()));
//            }
//        }
//        if (CollUtil.isNotEmpty(marketAuthDTOList)) {
//            for (DzCanteenAuthDTO marketAuthDTO : marketAuthDTOList) {
//                canteenAuthList.add(new DzAllocCanteenAuth(marketAuthDTO, AllocCanteenTypeEnum.SUPERMARKET.getKey()));
//            }
//        }
//        this.saveBatch(canteenAuthList);
//    }

}
