package com.aegis.web.controller.emergency.plan;

import com.aegis.common.annotation.Log;
import com.aegis.common.core.controller.BaseController;
import com.aegis.common.core.domain.AjaxResult;
import com.aegis.common.enums.BusinessType;
import com.aegis.emergency.plan.domain.PlanUsage;
import com.aegis.emergency.plan.service.IPlanUsageService;
import java.util.List;
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.PathVariable;
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;

/**
 * 预案使用记录 Controller
 */
@RestController
@RequestMapping("/api/plans/{planId}/usage")
public class PlanUsageController extends BaseController {

    @Autowired
    private IPlanUsageService usageService;

    @PreAuthorize("@ss.hasPermi('emergency:plan:usage:list')")
    @GetMapping
    public AjaxResult list(@PathVariable Long planId) {
        List<PlanUsage> usages = usageService.listByPlanId(planId);
        return success(usages);
    }

    @PreAuthorize("@ss.hasPermi('emergency:plan:usage:add')")
    @Log(title = "预案使用记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@PathVariable Long planId, @RequestBody PlanUsage usage) {
        usage.setPlanId(planId);
        usage.setDelFlag("0");
        return toAjax(usageService.save(usage));
    }
}