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.CheckAbnormalReport;
import com.nantian.cloud.jly.entity.CheckBasis;
import com.nantian.cloud.jly.entity.CheckNoD12;
import com.nantian.cloud.jly.service.CheckAbnormalReportService;
import com.nantian.cloud.jly.service.CheckNoD12Service;
import com.nantian.sc.cloud.common.core.util.R;
import com.nantian.sc.cloud.common.log.annotation.SysLog;
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.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.util.Date;
import java.util.List;


/**
 *不符合报告记录
 *
 * @author
 * @date 2021-09-3
 */
@RestController
@AllArgsConstructor
@Api(value = "CheckNoD12",tags = "不符合")
@RequestMapping("/checkNoD12")
public class CheckNoD12Controller {

	private final CheckNoD12Service checkNoD12Service;


	/**
	 * 查询
	 *
	 * @return
	 */
	@SysLog("D12不符合项-查询")
	@GetMapping("/getD12")
	public R getBycheckPlanId(BigInteger checkPlanId, String epc) {
		QueryWrapper<CheckNoD12> queryWrapper = new QueryWrapper<CheckNoD12>();
		queryWrapper.eq("check_plan_id",checkPlanId);
		queryWrapper.eq("epc",epc);
		List<CheckNoD12> list = checkNoD12Service.list(queryWrapper);
		return R.ok(list);
	}



	/**
	 * 保存/修改
	 *
	 */
	@SysLog("D12不符合项-保存/修改")
	@PostMapping
	public R save(@RequestBody List<CheckNoD12> checkNoD12) {
		ScUser u= SecurityUtils.getUser();
		for (CheckNoD12 D12: checkNoD12) {
			if (u.getId() != null) {
				D12.setUserid(u.getId());
			}
			if (u.getDeptId() != null) {
				D12.setDeptId(u.getDeptId());
			}
			D12.setDelFlag("1");
			D12.setUpdateTime(new Date());
		}
		return R.ok(checkNoD12Service.saveOrUpdateBatch(checkNoD12));
	}

}
