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


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.manage.system.api.param.CommonIdParam;
import com.yuchen.saas.park.api.entity.emergency.EmergencyDangerousGoods;
import com.yuchen.saas.park.service.service.emergency.IEmergencyDangerousGoodsService;
import io.swagger.annotations.ApiOperation;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * <p>
 * 应急预案-危险化学品信息表 前端控制器
 * </p>
 *
 * @author 洪铭铭
 * @since 2024-07-30
 */
@RestController
@RequestMapping("/emergencyPlan/emergencyDangerousGoods")
public class EmergencyDangerousGoodsController {

    @Autowired
    private IEmergencyDangerousGoodsService emergencyDangerousGoodsService;

    @PostMapping("/save")
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "新增", notes = "危险化学品信息新增")
    public R save(@Valid @RequestBody EmergencyDangerousGoods emergencyDangerousGoods) {
        return R.status(emergencyDangerousGoodsService.save(emergencyDangerousGoods));
    }

    @GetMapping("/list")
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "列表", notes = "危险化学品信息列表")
    public R<List<EmergencyDangerousGoods>> list(@RequestParam("planId") Long planId) {
        return R.data(emergencyDangerousGoodsService.list(new LambdaQueryWrapper<EmergencyDangerousGoods>()
                .eq(EmergencyDangerousGoods::getPlanId,
                        planId)));
    }

    @PostMapping("/update")
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "修改", notes = "危险化学品信息修改")
    public R update(@Valid @RequestBody EmergencyDangerousGoods emergencyDangerousGoods) {
        return R.status(emergencyDangerousGoodsService.saveOrUpdate(emergencyDangerousGoods));
    }

    @PostMapping("/delete")
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "删除", notes = "危险化学品信息删除")
    public R delete(@Valid @RequestBody CommonIdParam param) {
        return R.data(emergencyDangerousGoodsService.removeById(param.getId()));
    }

    @GetMapping("/detail")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "详情", notes = "危险化学品信息详情")
    public R<EmergencyDangerousGoods> detail(@RequestParam("id") Long id) {
        return R.data(emergencyDangerousGoodsService.getById(id));
    }

//    @PostMapping("/page")
//    @ApiOperationSupport(order = 6)
//    @ApiOperation(value = "分页列表", notes = "危险化学品信息分页列表")
//    public R<Page<EmergencyDangerousGoods>> page(@RequestBody EmergencyPlanQueryDto emergencyPlanQueryDto) {
//        return R.data(emergencyDangerousGoodsService.page(emergencyPlanQueryDto));
//    }



}
