package com.jeequan.jeepay.agent.ctrl.store;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jeequan.jeepay.agent.ctrl.CommonCtrl;
import com.jeequan.jeepay.core.model.ApiRes;
import com.jeequan.jeepay.db.entity.DeviceProvideConfig;
import com.jeequan.jeepay.service.impl.DeviceProvideConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 设备厂商配置管理类
 *
 * @author zx
 * @date 2021-12-28 09:15
 */
@Slf4j
@RestController
@RequestMapping("api/device/provider")
public class DeviceProvideConfigController extends CommonCtrl {

	@Autowired private DeviceProvideConfigService deviceProvideConfigService;

	/**
	 * @author: zx
	 * @date: 2021-12-28 09:15
	 * @describe: 厂商配置列表
	 */
	@PreAuthorize("hasAnyAuthority('ENT_DEVICE_SPEAKER_LIST', 'ENT_DEVICE_PRINTER_LIST', 'ENT_DEVICE_SPEAKER_ADD'," +
			"'ENT_DEVICE_PRINTER_ADD', 'ENT_DEVICE_SPEAKER_EDIT', 'ENT_DEVICE_PRINTER_EDIT')")
	@GetMapping
	public ApiRes pages() {
		LambdaQueryWrapper<DeviceProvideConfig> gw = DeviceProvideConfig.gw();
		gw.select(DeviceProvideConfig::getConfigId, DeviceProvideConfig::getConfigDesc, DeviceProvideConfig::getProvider);

		gw.orderByDesc(DeviceProvideConfig::getCreatedAt);
		gw.eq(DeviceProvideConfig::getDeviceType, getValByteRequired("deviceType"));

        if (null != getValByte("state")) {
            gw.eq(DeviceProvideConfig::getState, getValByte("state"));
        }

		gw.select(DeviceProvideConfig::getConfigId, DeviceProvideConfig::getConfigDesc, DeviceProvideConfig::getDeviceType, DeviceProvideConfig::getProvider,
				DeviceProvideConfig::getCreatedAt, DeviceProvideConfig::getAppId, DeviceProvideConfig::getState);

		IPage<DeviceProvideConfig> page = deviceProvideConfigService.page(getIPage(true), gw);
		//返回数据
		return ApiRes.page(page);
	}

}
