package cn.com.ty.lift.ud.operation.controller;

import cn.com.ty.lift.ud.common.BaseController;
import cn.com.ty.lift.ud.operation.controller.query.OperationSetQuery;
import cn.com.ty.lift.ud.operation.mapper.entity.OperationSetEntity;
import cn.com.ty.lift.ud.operation.service.IOperationSetService;
import cn.com.xwy.boot.web.dto.RestResponse;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * 运营设置 API
 *
 * @author Xson
 * @date 2020-05-04
 */
@Api(tags = "运营设置 - 暂时没用上")
@RestController
@RequestMapping("/api/operationSets")
public class OperationSetController extends BaseController<OperationSetEntity, OperationSetQuery> {

    private final Logger log = LoggerFactory.getLogger(OperationSetController.class);

    private @Autowired
    IOperationSetService operationSetService;

    @Override
    protected IService<OperationSetEntity> getService() {
        return operationSetService;
    }

    /**
     * 查询重写
     *
     * @param request
     * @return
     */
    @PostMapping("/query-page")
    @ApiOperation(value = "查询")
    @Override
    public RestResponse getCondition(@RequestBody OperationSetQuery request) {
        request.setPageNum(1L);
        request.setPageSize(100L);
        IPage<OperationSetEntity> list = operationSetService.page(request.page(), request.condition());
        HashMap<String, String> map = new HashMap<>(2048);
        for (OperationSetEntity opEntity : list.getRecords()) {
            map.put(opEntity.getCode(), opEntity.getValue());
        }
        return RestResponse.success(map, "查询成功");
    }

}