/**
 * BladeX Commercial License Agreement
 * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
 * <p>
 * Use of this software is governed by the Commercial License Agreement
 * obtained after purchasing a license from BladeX.
 * <p>
 * 1. This software is for development use only under a valid license
 * from BladeX.
 * <p>
 * 2. Redistribution of this software's source code to any third party
 * without a commercial license is strictly prohibited.
 * <p>
 * 3. Licensees may copyright their own code but cannot use segments
 * from this software for such purposes. Copyright of this software
 * remains with BladeX.
 * <p>
 * Using this software signifies agreement to this License, and the software
 * must not be used for illegal purposes.
 * <p>
 * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
 * not liable for any claims arising from secondary or illegal development.
 * <p>
 * Author: Chill Zhuang (bladejava@qq.com)
 */
package org.springblade.modules.flowable.processForm.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import jakarta.validation.Valid;

import org.hibernate.validator.constraints.NotBlank;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.annotation.PreAuth;
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.springblade.modules.flowable.processForm.pojo.dto.ProcessDefDTO;
import org.springblade.modules.flowable.processForm.pojo.entity.ProcessFormEntity;
import org.springblade.modules.flowable.processForm.pojo.vo.AddProcessVo;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.flowable.processForm.pojo.entity.ProcessDefEntity;
import org.springblade.modules.flowable.processForm.pojo.vo.ProcessDefVO;
import org.springblade.modules.flowable.processForm.wrapper.ProcessDefWrapper;
import org.springblade.modules.flowable.processForm.service.IProcessDefService;
import org.springblade.core.boot.ctrl.BladeController;

import java.util.Map;

/**
 * 流程定义模板，flowable流程定义根据该模板动态部署一个流程定义。 控制器
 *
 * @author lzp
 * @since 2024-08-02
 */
@RestController
@AllArgsConstructor
@RequestMapping("blade-processDef/processDef")
@Tag(name = "流程定义模板，flowable流程定义根据该模板动态部署一个流程定义。", description = "流程定义模板，flowable流程定义根据该模板动态部署一个流程定义。接口")
public class ProcessDefController extends BladeController {

	private final IProcessDefService processDefService;

	/**
	 * 流程定义模板，flowable流程定义根据该模板动态部署一个流程定义。 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@Operation(summary = "详情", description  = "传入processDef")
	public R<ProcessDefDTO> detail(@Parameter(name = "id",description = "主键id",required = true) @RequestParam String id) {
		ProcessDefDTO detail = processDefService.getProcessForm(id);
		return R.data(detail);
	}


	/**
	 * 流程定义模板，flowable流程定义根据该模板动态部署一个流程定义。 自定义分页
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@Operation(summary = "分页", description  = "传入processDef")
	public R<IPage<ProcessDefVO>> page(ProcessDefVO processDef, Query query) {
		IPage<ProcessDefVO> pages = processDefService.selectProcessDefPage(Condition.getPage(query), processDef);
		return R.data(pages);
	}

	/**
	 * 流程定义模板，flowable流程定义根据该模板动态部署一个流程定义。 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@Operation(summary = "新增", description  = "传入processDef")
	public R save(@Valid @RequestBody AddProcessVo req) {
		return processDefService.saveProcessDef(req);
	}

	/**
	 * 流程定义模板，flowable流程定义根据该模板动态部署一个流程定义。 修改
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@Operation(summary = "修改", description  = "传入processDef")
	public R update(@Valid @RequestBody AddProcessVo processDef) {
		return processDefService.updateProcessDef(processDef);
	}

	/**
	 * 流程定义模板，flowable流程定义根据该模板动态部署一个流程定义。 新增或修改
	 */
	@GetMapping("/findFromDefList")
	@ApiOperationSupport(order = 6)
	@Operation(summary = "获取流程表单")
	public R findFromDefList() {
		return R.data(processDefService.findFromDefList());
	}

	/**
	 * 禁用/启用
	*/
	@GetMapping("/changeProcessStatus")
	@ApiOperationSupport(order = 6)
	@Operation(summary = "启用/禁用/删除 流程")
	public R changeProcessStatus(@Parameter(name = "processId",description = "流程id",required = true) @RequestParam String processId, @Parameter(name = "type",description = "type=1 禁用  type=0 启用  type=2 删除",required = true) @RequestParam String type){

		return R.status(processDefService.changeProcessStatus(processId,type));
	}

	/**
	 * 查询当前人员是否有新增流程权限
	*/
	@GetMapping("/findUserProcess")
	@ApiOperationSupport(order = 7)
	@Operation(summary = "查询当前人员是否有新增流程权限")
	public R findUserProcess(@Parameter(name = "formId",description = "流程表单id",required = true) @RequestParam String formId){
		return R.data(processDefService.findUserProcess(formId));
	}



}
