package com.hzs.system.config.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzs.common.core.annotation.Log;
import com.hzs.common.core.enums.*;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.domain.system.config.BdBonusItems;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.common.service.ITransactionCommonService;
import com.hzs.system.config.service.IBdBonusItemsService;
import com.hzs.system.config.vo.ApiBdBonusItemsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 奖项配置 前端控制器
 * </p>
 *
 * @author zhangjing
 * @since 2022-11-09
 */
@RestController
@RequestMapping("/api/bd-bonus-items")
public class ApiBdBonusItemsController extends BaseController {

    @Autowired
    private IBdBonusItemsService bonusItemsService;
    @Autowired
    private ITransactionCommonService iTransactionCommonService;

    /**
     * @description: 查询奖项配置列表(下拉选)
     * @author: zhang jing
     * @date: 2022/8/30 10:20
     * @param: [bonusItems]
     * @return: com.hzs.common.core.web.page.TableDataInfo
     **/
    @Log(module = EOperationModule.BONUS_CONFIG, business = EOperationBusiness.BONUS_ITEMS, method = EOperationMethod.SELECT)
    @GetMapping("/list")
    public TableDataInfo list(BdBonusItems bonusItems) {
        QueryWrapper<BdBonusItems> queryWrapper = new QueryWrapper();
        queryWrapper.eq("PK_COUNTRY", SecurityUtils.getPkCountry());
        queryWrapper.orderByAsc("PK_ID");
        List<BdBonusItems> list = bonusItemsService.list(queryWrapper);

        // 查询国际化
        Map<Integer, String> transactionMap = iTransactionCommonService.enumTransactionByDBFromPkId(list.stream().map(BdBonusItems::getPkTransaction).collect(Collectors.toList()));

        List<ApiBdBonusItemsVO> listVO = new ArrayList<>();
        for (BdBonusItems bdBonusItems : list) {
            listVO.add(ApiBdBonusItemsVO.builder()
                    .pkId(bdBonusItems.getPkId())
                    .bonusName(transactionMap.get(bdBonusItems.getPkTransaction()))
                    .build());
        }
        return getDataTable(listVO);
    }
}
