package com.tofly.qualitycontrol.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.qualitycontrol.dto.CollectionNumberDetailDTO;
import com.tofly.qualitycontrol.entity.CollectionNumberDetail;
import com.tofly.qualitycontrol.service.ICollectionNumberDetailService;
import com.tofly.qualitycontrol.util.QualityControlUtil;
import com.tofly.qualitycontrol.vo.CollectionNumberDetailVO;
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.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;

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

/**
 * 归集管理详情控制器
 *
 * @author B
 */
@RestController
@RequestMapping("/collectionNumberDetail")
@Api(value = "归集管理详情接口", tags = "归集管理详情接口")
@RequiredArgsConstructor
public class CollectionNumberDetailController {

	private final ICollectionNumberDetailService collectionNumberDetailService;

	@ApiOperation(value = "添加归集详情,可批量", notes = "", httpMethod = "POST")
	@PostMapping("/addByBatch")
	public ResultRespone addToCollectionNumberByBatch(@Valid @RequestBody CollectionNumberDetailDTO collectionNumberDetailDTO,BindingResult bindingResult) {
		if (bindingResult.hasErrors()) {
			return ResultRespone.failed(QualityControlUtil.getErrorStrings(bindingResult),FAILED);
		}
		Boolean flag = collectionNumberDetailService.addToCollectionNumberByBatch(collectionNumberDetailDTO);
		return flag ? ResultRespone.success(flag,SUCCESS) : ResultRespone.failed(flag,FAILED);
	}

    @ApiImplicitParams({
            @ApiImplicitParam(name = "collectionNumber", value = "归集号", required = true, paramType = "query", dataType = "string", dataTypeClass = String.class),
            @ApiImplicitParam(name = "yhbhs", value = "用户编号，多个逗号隔开", required = true, paramType = "query", dataType = "string", dataTypeClass = String.class),
            @ApiImplicitParam(name = "isAll", value = "是否全部移除；1：是", required = true, paramType = "query", dataType = "string", dataTypeClass = String.class)
    })
	@ApiOperation(value = "删除归集详情,可批量", notes = "", httpMethod = "GET")
	@GetMapping("/deleteByBatch")
	public ResultRespone deleteCollectionNumber( String yhbhs , String collectionNumber , String isAll) {
        return ResultRespone.success(collectionNumberDetailService.deleteCollectionNumber(yhbhs , collectionNumber , isAll));
	}

//	@ApiImplicitParams({
//							   @ApiImplicitParam(value = "归集编号", name = "collectionNumber", required = true, paramType = "query", dataType = "string", dataTypeClass = String.class),
//							   @ApiImplicitParam(value = "客户编号", name = "clientNumber", required = false, paramType = "query", dataType = "string", dataTypeClass = String.class),
//					   })
//	@ApiOperation(value = "信息接口中的归集详情分页,查询", notes = "", httpMethod = "POST")
//	@PostMapping("/list")
//	public ResultRespone<IPage<CollectionNumberDetailVO>> list(@RequestParam String collectionNumber,@RequestParam(required = false) String clientNumber,@RequestBody Page<CollectionNumberDetail> page) {
//		return ResultRespone.success(collectionNumberDetailService.getList(collectionNumber,clientNumber,page),SUCCESS);
//	}

}
