package com.nantian.cloud.jly.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nantian.cloud.jly.entity.CheckBasisFile;
import com.nantian.cloud.jly.entity.CheckPlan;
import com.nantian.cloud.jly.entity.ConfigureDevice;
import com.nantian.cloud.jly.entity.ConfigureGaugeAssay;
import com.nantian.cloud.jly.service.CheckBasisFileService;
import com.nantian.cloud.jly.service.ConfigureGaugeAssayService;
import com.nantian.sc.cloud.common.core.util.R;
import com.nantian.sc.cloud.common.log.annotation.SysLog;
import com.nantian.sc.cloud.common.minio.service.MinioTemplate;
import com.nantian.sc.cloud.common.security.service.ScUser;
import com.nantian.sc.cloud.common.security.util.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.Date;
import java.util.List;
import java.util.UUID;


/**
 * 器具检定文件
 */
@RestController
@AllArgsConstructor
@RequestMapping("/ConfigureGaugeAssay")
@Api(value = "ConfigureGaugeAssay", tags = "器具检定文件")
public class ConfigureGaugeAssayController {

    private final ConfigureGaugeAssayService configureGaugeAssayService;


    /**
     * 保存/修改
     *
     * @param ConfigureGaugeAssay
     * @return R
     */
    @SysLog("器具检定文件-保存/修改")
    @PostMapping
    public R save(@RequestBody List<ConfigureGaugeAssay> ConfigureGaugeAssay) {
        ScUser u = SecurityUtils.getUser();
        ConfigureGaugeAssay.forEach(r -> {
            if (u.getId() != null) {
                r.setUserId(u.getId());
            }
            r.setDelFlag("1");
            r.setUpdateTime(new Date());
        });
        return R.ok(configureGaugeAssayService.saveOrUpdateBatch(ConfigureGaugeAssay));
    }

    @SysLog("器具检定文件-查询")
    @GetMapping("/getList")
    public R getList(Long id) {
        QueryWrapper<ConfigureGaugeAssay> queryWrapper = new QueryWrapper<ConfigureGaugeAssay>();
        queryWrapper.eq("gauges_id", id);
        List<ConfigureGaugeAssay> list = configureGaugeAssayService.list(queryWrapper);
        return R.ok(list);
    }

    @SysLog("器具检定文件-删除")
    @GetMapping("/delete")
    public R removeById(Long id) {
        return R.ok(configureGaugeAssayService.removeById(id));
    }

}
