package com.usky.iot.controller.web;


import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.common.log.annotation.Log;
import com.usky.common.log.enums.BusinessType;
import com.usky.iot.domain.BaseFacilityType;
import com.usky.iot.service.BaseFacilityTypeService;
import com.usky.iot.service.vo.BaseGgpFacilityTypeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 设施类型 前端控制器
 * </p>
 *
 * @author han
 * @since 2023-06-06
 */
@RestController
@RequestMapping("/baseFacilityType")
public class BaseFacilityTypeController {

    @Autowired
    private BaseFacilityTypeService baseFacilityTypeService;
    /**
     * 设施类型查看查询
     *
     * @return
     */
    @PostMapping("/typeInfo")
    public ApiResult<List<BaseGgpFacilityTypeVO>> typeInfo() {
        return ApiResult.success(baseFacilityTypeService.typeInfo());
    }
    /**
     * 设施类型分页
     * @param typeCode  类型编码
     * @param typeName  类型名称
     * @param current   当前页
     * @param size     每页条数
     * @return
     */
    @Log(title = "设施类型分页", businessType = BusinessType.OTHER)
    @GetMapping("/typePage")
    public ApiResult<CommonPage<BaseFacilityType>> typePage(@RequestParam(value = "typeCode", required = false) String typeCode,
                                                            @RequestParam(value = "typeName", required = false) String typeName,
                                                            @RequestParam(value = "current", required = false, defaultValue = "1") Integer current,
                                                            @RequestParam(value = "size", required = false, defaultValue = "10") Integer size)
    {
        return ApiResult.success(baseFacilityTypeService.typePage(typeCode, typeName, current, size));
    }

    /**
     * 设施类型根据ID查询
     *
     * @param id   主键ID
     * @return
     */
    @GetMapping("typeSelect")
    public ApiResult<List<BaseFacilityType>> typeSelect(@RequestParam(value = "id", required = false) Integer id) {
        return ApiResult.success(baseFacilityTypeService.typeSelect(id));
    }

    /**
     * 新增
     * @param baseFacilityType
     * @return
     */
    @PostMapping("/add")
    public ApiResult<Void> add(@RequestBody BaseFacilityType baseFacilityType){
        baseFacilityTypeService.add(baseFacilityType);
        return ApiResult.success();
    }

    /**
     * 修改
     * @param baseFacilityType
     * @return
     */
    @PutMapping("/edit")
    public ApiResult<Void> edit(@RequestBody BaseFacilityType baseFacilityType){
        baseFacilityTypeService.update(baseFacilityType);
        return ApiResult.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    public ApiResult<Void> remove(@PathVariable("id") Integer id)
    {
        baseFacilityTypeService.remove(id);
        return ApiResult.success();
    }
}

