package org.security.trans.workHandOverUsers.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.security.desk.feign.IFaceClient;
import org.security.desk.vo.FaceVO;
import org.security.ht.workHandOverUsers.entity.WorkHandoverUsers;
import org.security.ht.workHandOverUsers.vo.WorkHandoverCheckVO;
import org.security.ht.workHandOverUsers.vo.WorkHandoverUsersVO;
import org.security.ht.workHandOverUsers.dto.WorkHandoverUsersDTO;
import org.security.trans.workHandOverUsers.service.IWorkHandoverUsers;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

/**
 * @author ：wzf
 * @apiNote ：工作交接用户信息
 * @since ：Created in 2022/9/2 16:40
 */
@AllArgsConstructor
@RestController
@RequestMapping("/work/handover")
public class WorkHandoverUsersController {
	private final IWorkHandoverUsers workHandoverUsersService;
	private final IFaceClient faceClient;

	/**
	 * 工作交接校验
	 *
	 * @return
	 */
	@PostMapping("/check")
	public R workHandoverCheck(@Valid @RequestBody WorkHandoverCheckVO workHandoverCheckVO) {
		return workHandoverUsersService.workHandoverCheck(workHandoverCheckVO);
	}

	@GetMapping("/detail/{idCard}")
	public R<WorkHandoverUsersVO> getByIdCard(@PathVariable String idCard) {
		return R.data(workHandoverUsersService.getByIdCard(idCard));
	}


	/**
	 * 工作交接人员信息录入
	 * @param workHandoverUsersDTO
	 * @return
	 */
	@PostMapping("/save")
	public R add(@Valid @RequestBody WorkHandoverUsersDTO workHandoverUsersDTO) {
		return R.status(workHandoverUsersService.saveData(workHandoverUsersDTO));
	}

	/**
	 * 工作交接人员信息录入(连同人脸录入)
	 */
	@PostMapping("/save-with-face")
	public R addWithFaceInfo(@RequestPart("faceVo") FaceVO faceVO, @RequestPart("file") MultipartFile file) {
		return workHandoverUsersService.saveWithFace(faceVO, file);
	}

	/**
	 * 工作交接人员人脸比对
	 */
	@PostMapping("/face-match")
	public R faceMatch(@RequestPart("file") MultipartFile file) {
		return faceClient.faceMatch(file);
	}

	/**
	 * 自定义分页 工作交接用户列表
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入workHandoverUsersDTO")
	public R<IPage<WorkHandoverUsersVO>> page(WorkHandoverUsersDTO workHandoverUsersDTO, Query query) {
		IPage<WorkHandoverUsersVO> pages = workHandoverUsersService.selectProjectPage(Condition.getPage(query), workHandoverUsersDTO);
		return R.data(pages);
	}

	/**
	 * 详情
	 */
	@GetMapping("/{id}")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入id")
	public R<WorkHandoverUsersVO> detail(@PathVariable String id) {
		WorkHandoverUsers workHandoverUsers = workHandoverUsersService.getById(id);
		return R.data(Func.copy(workHandoverUsers,WorkHandoverUsersVO.class));
	}
	/**
	 * 删除
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(workHandoverUsersService.removeByIds(Func.toLongList(ids)));
	}
}
