package thyyxxk.webserver.controller.lc.purchasePlan;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import thyyxxk.webserver.config.auth.PassToken;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.entity.lc.project.LcProject;
import thyyxxk.webserver.entity.lc.purchasePlan.LcPurchasePlan;
import thyyxxk.webserver.entity.lc.purchasePlan.LcPurchasePlanDetail;
import thyyxxk.webserver.entity.lc.purchasePlan.LcPurchasePlanParam;
import thyyxxk.webserver.service.lc.purchasePlan.LcPurchasePlanDetailService;
import thyyxxk.webserver.service.lc.purchasePlan.LcPurchasePlanService;
import thyyxxk.webserver.utils.ResultVoUtil;

import java.util.List;

/**
 * 科室采购计划Controller
 */
@RestController
@RequestMapping("/LcPurchasePlan")
public class LcPurchasePlanController {

    @Autowired
    private LcPurchasePlanService purchasePlanService;

    @Autowired
    private LcPurchasePlanDetailService lcPurchasePlanDetailService;

    /**
     * 新增或修改采购计划
     */
    @PostMapping("/save")
    public ResultVo<Boolean> save(@RequestBody LcPurchasePlan plan) {
        return ResultVoUtil.success(purchasePlanService.savePlanWithDetails(plan));
    }


    /**
     * 模糊查询采购计划列表（分页）
     */
    @PostMapping("/getLcPurchasePlanList")
    public ResultVo<Page<LcPurchasePlan>> getLcPurchasePlanList(@RequestBody LcPurchasePlanParam lcPurchasePlanParam) {
        Page<LcPurchasePlan> lcPurchasePlanList = purchasePlanService.getLcPurchasePlanList(lcPurchasePlanParam);
        return ResultVoUtil.success(lcPurchasePlanList);
    }

    /**
     * 删除采购明细
     */
    @PostMapping("/deleteLcPurchasePlanDetailList")
    public ResultVo<Boolean> deleteLcPurchasePlanDetailList(@RequestBody List<LcPurchasePlanDetail> lcPurchasePlanDetailList) {
        return ResultVoUtil.success(lcPurchasePlanDetailService.deleteLcPurchasePlanDetailList(lcPurchasePlanDetailList));
    }
}

