package vip.xiaonuo.quality.controller;


import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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;
import vip.xiaonuo.common.exception.CommonException;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.quality.entity.QualityManufacturer;
import vip.xiaonuo.quality.entity.QualityReagent;
import vip.xiaonuo.quality.entity.QualityReagentOutStock;
import vip.xiaonuo.quality.param.QualityFenxibaogaoIdParam;
import vip.xiaonuo.quality.param.QualityManufacturerParam;
import vip.xiaonuo.quality.param.QualityReagentParam;
import vip.xiaonuo.quality.param.vo.ShiJiParam;
import vip.xiaonuo.quality.service.IQualityReagentService;
import vip.xiaonuo.risk.entity.RiskContract;
import vip.xiaonuo.risk.param.RiskContractParam;

import java.util.List;

/**
 * <p>
 * 质量试剂使用情况 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-12-11
 */
@RestController
@Api(tags = "质量试剂使用情况")
@ApiSupport(author = "wang", order = 1)
@Validated
public class QualityReagentController {

    @Autowired
    private IQualityReagentService reagentService;

    @ApiOperationSupport(order = 1)
    @ApiOperation("质量试剂使用情况分析")
    @PostMapping("/quality-reagent/getList")
    public CommonResult<List<QualityReagentOutStock>> getList(@RequestBody QualityReagentParam reagentParam) {
        return CommonResult.data(reagentService.getList(reagentParam));
    }

    @PostMapping("/quality-reagent/listPage")
    @ApiOperationSupport(order = 1)
    @ApiOperation("试剂使用情况列表")
    public CommonResult<Page<QualityReagent>> listPage(@RequestBody QualityManufacturerParam manufacturerParam) {
        return CommonResult.data(reagentService.listPage(manufacturerParam));
    }


    /**
     * 添加试剂使用情况
     *
     * @author 1
     * @date  2025/02/26 16:25
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation("添加试剂使用情况")
    @PostMapping("/biz/quality-reagent/add")
    public CommonResult<String> add(@RequestBody  QualityReagent qualityManufacturer) {
        String orgId = qualityManufacturer.getOrgId();
        if (StringUtils.isBlank(orgId)){
            throw new CommonException("请选择需要添加的公司");
        }
        reagentService.save(qualityManufacturer);
        return CommonResult.ok();
    }

    /**
     * 编辑试剂使用情况
     *
     * @author 1
     * @date  2025/02/26 16:25
     */
    @ApiOperation("编辑试剂使用情况")
    @PostMapping("/biz/quality-reagent/edit")
    public CommonResult<String> edit(@RequestBody QualityReagent qualityManufacturer) {
        reagentService.updateById(qualityManufacturer);
        return CommonResult.ok();
    }

    /**
     * 删除试剂使用情况
     *
     * @author 1
     * @date  2025/02/26 16:25
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation("删除试剂使用情况")
    @PostMapping("/biz/quality-reagent/delete")
    public CommonResult<String> delete(@RequestBody QualityFenxibaogaoIdParam qualityFenxibaogaoIdParamList) {
        reagentService.removeById(qualityFenxibaogaoIdParamList.getId());
        return CommonResult.ok();
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation("获取试剂列表")
    @PostMapping("/biz/quality-reagent/getShiJi")
    public CommonResult<List<QualityReagent> > getShiJi(@RequestBody ShiJiParam shiJiParam) {
        return CommonResult.data( reagentService.getShiJi(shiJiParam));
    }
}
