package com.tofly.qualitycontrol.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.qualitycontrol.entity.RejectedRecord;
import com.tofly.qualitycontrol.entity.ZlTransfer;
import com.tofly.qualitycontrol.service.IRejectedRecordService;
import com.tofly.qualitycontrol.service.IZlTransferService;
import com.tofly.qualitycontrol.vo.RejectedRecordVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import static com.tofly.qualitycontrol.common.QualityControlConstant.SUCCESS;

/**
 * 整改工单控制器
 *
 * @author B
 */
@RestController
@RequestMapping("/rejectedRecord")
@Api(value = "驳回、转派记录接口", tags = "驳回、转派记录接口")
@RequiredArgsConstructor
public class RejectedRecordController {

	private final IRejectedRecordService service;
	private final IZlTransferService IZlTransferService;

	@ApiImplicitParams({
							   @ApiImplicitParam(value = "认证编号", name = "certificationNumber", required = true, paramType = "query", dataType = "string", dataTypeClass = String.class)
					   })
	@ApiOperation(value = "指定工单的驳回记录,分页形式", notes = "", httpMethod = "POST")
	@PostMapping("/list")
	public ResultRespone<IPage<RejectedRecordVO>> list(@RequestParam String certificationNumber,@RequestBody Page<RejectedRecord> page) {
		return ResultRespone.success(service.getList(certificationNumber,page),SUCCESS);
	}

	/**
	 * 转派记录
	 * @param page
	 * @param zlTransfer
	 * @return
	 */
	@PostMapping("/zlTransfers")
	@ApiOperation(value = "获取转派信息")
	public ResultRespone zlTransferList(Page page,@RequestBody ZlTransfer zlTransfer){
		Page<ZlTransfer> zpage = IZlTransferService.page(page, Wrappers.query(zlTransfer).lambda().orderByDesc(ZlTransfer::getCreateTime));
		for (ZlTransfer vo:zpage.getRecords()) {
			vo.setLcjdName(service.getProcessName(vo.getLcjd()));
		}
		return ResultRespone.success(zpage);
	}

}
