package com.yuchen.saas.park.service.controller.device;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.api.entity.park.PmgBatEquipmentSite;
import com.yuchen.saas.park.service.service.EquipmentSiteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.nest.springwrap.core.mp.support.Condition;
import org.nest.springwrap.core.mp.support.Query;
import org.nest.springwrap.core.tool.api.R;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author 刘通
 * @date 2020/12/7 17:31
 */
@RestController
@AllArgsConstructor
@RequestMapping("/point")
@Api(value = "站点信息表", tags = "站点信息表接口")
public class EquipmentSiteController {

    @Autowired
    private EquipmentSiteService equipmentSiteService;

    /**
     * 详情
     */
    @GetMapping("/detail")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "详情", notes = "传入parkCompany")
    public R<PmgBatEquipmentSite> detail(PmgBatEquipmentSite pmgBatEquipmentSite) {
        PmgBatEquipmentSite detail = equipmentSiteService.getOne(Condition.getQueryWrapper(pmgBatEquipmentSite));
        return R.data(detail);
    }
    /**
     * 分页 站点信息表
     */
    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "分页", notes = "传入parkCompany")
    public R<IPage<PmgBatEquipmentSite>> list(PmgBatEquipmentSite pmgBatEquipmentSite, Query query) {
        System.out.println("*********:"+pmgBatEquipmentSite);
        IPage<PmgBatEquipmentSite> pages = equipmentSiteService.page(Condition.getPage(query),Condition.getQueryWrapper(pmgBatEquipmentSite));
        return  R.data(pages);
    }
    /**
     * 新增 站点信息
     */
    @PostMapping("/save")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "新增", notes = "传入parkCompany")
    public R save(@Valid @RequestBody PmgBatEquipmentSite pmgBatEquipmentSite) {
        return R.status(equipmentSiteService.save(pmgBatEquipmentSite));
    }
    /**
     * 批量新增 站点信息
     */
    @PostMapping("/saveList")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "新增", notes = "传入parkCompany")
    public R saveList(@Valid @RequestBody List<PmgBatEquipmentSite> pmgBatEquipmentSite) {
        return R.status(equipmentSiteService.saveOrUpdateBatch(pmgBatEquipmentSite));
    }
    /**
     * 修改
     */
    @PutMapping("/update")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "修改", notes = "传入parkCompany")
    public R update(@Valid @RequestBody PmgBatEquipmentSite pmgBatEquipmentSite) {
        return R.status(equipmentSiteService.updateById(pmgBatEquipmentSite));
    }

    /**
     * 删除 站点信息
     */
    @DeleteMapping("/remove")
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "逻辑删除", notes = "传入ids")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.status(equipmentSiteService.deleteLogic(Func.toLongList(ids)));
    }
}
