package org.springblade.swzdr.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.swzdr.pojo.entity.RyLhspEntity;
import org.springblade.swzdr.pojo.vo.RyLhspVO;
import org.springblade.swzdr.service.IRyInfoService;
import org.springblade.swzdr.service.IRyLhspService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 人员_列化审批 控制器
 *
 * @author BladeX
 * @since 2024-09-24
 */
@RestController
@AllArgsConstructor
@RequestMapping("blade-ryLhsp/ryLhsp")
@Tag(name = "人员_列化审批", description = "人员_列化审批接口")
public class RyLhspController extends BladeController {

	private final IRyLhspService ryLhspService;

	private final IRyInfoService ryInfoService;

	/**
	 * 人员_列化审批 详情
	 */
//	@GetMapping("/detail")
//	@ApiOperationSupport(order = 1)
//	@Operation(summary = "详情", description  = "传入ryLhsp")
//	public R<RyLhspVO> detail(RyLhspEntity ryLhsp) {
//		RyLhspEntity detail = ryLhspService.getOne(Condition.getQueryWrapper(ryLhsp));
//		return R.data(RyLhspWrapper.build().entityVO(detail));
//	}

	/**
	 * 人员_列化审批 分页
	 */
//	@GetMapping("/list")
//	@ApiOperationSupport(order = 2)
//	@Operation(summary = "分页", description  = "传入ryLhsp")
//	public R<IPage<RyLhspVO>> list(@Parameter(hidden = true) @RequestParam Map<String, Object> ryLhsp, Query query) {
//		IPage<RyLhspEntity> pages = ryLhspService.page(Condition.getPage(query), Condition.getQueryWrapper(ryLhsp, RyLhspEntity.class));
//		return R.data(RyLhspWrapper.build().pageVO(pages));
//	}

	/**
	 * 人员_列化审批 自定义分页
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@Operation(summary = "分页", description  = "传入ryLhsp")
	public R<IPage<RyLhspVO>> page(@RequestParam Map<String, String> params, Query query) {
		params.put("deptId", AuthUtil.getDeptId().split(",")[0]);
		params.put("userId", AuthUtil.getUserId().toString());
		IPage<RyLhspVO> pages = ryLhspService.selectRyLhspPage(Condition.getPage(query), params);
		return R.data(pages);
	}

	/**
	 * 人员_列化审批 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@Operation(summary = "新增", description  = "传入ryLhsp")
	public R save(@Valid @RequestBody RyLhspEntity ryLhsp) {
		return R.status(ryLhspService.save(ryLhsp));
	}

	/**
	 * 人员_列化审批 修改
	 */
	@Transactional
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@Operation(summary = "修改", description  = "传入ryLhsp")
	public R update(@Valid @RequestBody RyLhspEntity ryLhsp) {
		ryLhspService.updateById(ryLhsp);
		if (ryLhsp.getSpjg() == 2) {
			// 撤管审批通过，将ry_info表数据删除
			ryInfoService.removeById(ryLhsp.getUserId());
		}
		return R.status(true);
	}

	/**
	 * 人员_列化审批 新增或修改
	 */
//	@PostMapping("/submit")
//	@ApiOperationSupport(order = 6)
//	@Operation(summary = "新增或修改", description  = "传入ryLhsp")
//	public R submit(@Valid @RequestBody RyLhspEntity ryLhsp) {
//		return R.status(ryLhspService.saveOrUpdate(ryLhsp));
//	}

	/**
	 * 人员_列化审批 删除
	 */
//	@PostMapping("/remove")
//	@ApiOperationSupport(order = 7)
//	@Operation(summary = "逻辑删除", description  = "传入ids")
//	public R remove(@Parameter(name = "主键集合", required = true) @RequestParam String ids) {
//		return R.status(ryLhspService.deleteLogic(Func.toLongList(ids)));
//	}

	/**
	 * 导出数据
	 */
//	@PreAuth(RoleConstant.HAS_ROLE_ADMIN)
//	@GetMapping("/export-ryLhsp")
//	@ApiOperationSupport(order = 9)
//	@Operation(summary = "导出数据", description  = "传入ryLhsp")
//	public void exportRyLhsp(@Parameter(hidden = true) @RequestParam Map<String, Object> ryLhsp, BladeUser bladeUser, HttpServletResponse response) {
//		QueryWrapper<RyLhspEntity> queryWrapper = Condition.getQueryWrapper(ryLhsp, RyLhspEntity.class);
//		//if (!AuthUtil.isAdministrator()) {
//		//	queryWrapper.lambda().eq(RyLhsp::getTenantId, bladeUser.getTenantId());
//		//}
//		queryWrapper.lambda().eq(RyLhspEntity::getIsDeleted, BladeConstant.DB_NOT_DELETED);
//		List<RyLhspExcel> list = ryLhspService.exportRyLhsp(queryWrapper);
//		ExcelUtil.export(response, "人员_列化审批数据" + DateUtil.time(), "人员_列化审批数据表", list, RyLhspExcel.class);
//	}

}
