package com.prolog.rdc.tms.controller.basicConfigure;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.rdc.tms.model.dto.basicConfigure.ApprovalNodeDTO;
import com.prolog.rdc.tms.model.dto.basicConfigure.ApprovalViewDTO;
import com.prolog.rdc.tms.model.vo.basicConfigure.ApprovalAddVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.ApprovalNodeDeleteVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.ApprovalNodeVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.ApprovalUpdateVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.ApprovalViewVO;
import com.prolog.rdc.tms.service.basicConfigure.ApprovalService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 审批配置控制层
 *
 * @author :lhb
 * @version :1.0.0
 * @className :ApprovalController
 * @creationTime :2022/04/29
 * @description :
 * @modifier :
 * @modifyTime :
 * @reviseRemarks:
 */
@RestController
@Api(tags = "基础配置-审批配置控制层")
@RequestMapping("/approval")
public class ApprovalController {
	@Autowired
	private ApprovalService approvalService;

	@UserLog("审批配置查询")
	@ApiOperation(httpMethod = "POST", value = "审批配置查询")
	@PostMapping(value = "/page")
	public RestMessage<Page<ApprovalViewDTO>> queryExecute(@RequestBody ApprovalViewVO approvalViewVO) {
		try {
			Page<ApprovalViewDTO> approvalViewDTOs = approvalService.query(approvalViewVO);
			return RestMessage.newInstance(true, "审批配置查询成功", approvalViewDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("审批配置新增")
	@ApiOperation(httpMethod = "POST", value = "审批配置新增")
	@PostMapping(value = "/add")
	public RestMessage<String> addExecute(@RequestBody ApprovalAddVO approvalAddVO) {
		try {
			approvalService.add(approvalAddVO);
			return RestMessage.newInstance(true, "审批配置新增成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("审批配置启用")
	@ApiOperation(httpMethod = "POST", value = "审批配置启用")
	@PostMapping(value = "/approval_enable")
	public RestMessage<String> approvalEnableExecute(@RequestBody List<Long> approvalIds) {
		try {
			approvalService.approvalEnable(approvalIds);
			return RestMessage.newInstance(true, "审批配置启用成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("审批配置停用")
	@ApiOperation(httpMethod = "POST", value = "审批配置停用")
	@PostMapping(value = "/approval_disable")
	public RestMessage<String> approvalDisableExecute(@RequestBody List<Long> approvalIds) {
		try {
			approvalService.approvalDisable(approvalIds);
			return RestMessage.newInstance(true, "审批配置停用成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("审批配置删除")
	@ApiOperation(httpMethod = "POST", value = "审批配置删除")
	@PostMapping(value = "/approval_delete")
	public RestMessage<String> approvalDeleteExecute(@RequestBody List<Long> approvalIds) {
		try {
			approvalService.approvalDelete(approvalIds);
			return RestMessage.newInstance(true, "审批配置删除成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("审批配置查看")
	@ApiOperation(httpMethod = "POST", value = "审批配置查看")
	@PostMapping(value = "/approval_view")
	public RestMessage<ApprovalViewDTO> approvalViewExecute(@RequestParam(value = "approvalId") String approvalId) {
		try {
			ApprovalViewDTO approvalViewDTO = approvalService.approvalView(approvalId);
			return RestMessage.newInstance(true, "审批配置查看成功", approvalViewDTO);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("审批配置修改")
	@ApiOperation(httpMethod = "POST", value = "审批配置修改")
	@PostMapping(value = "/approval_update")
	public RestMessage<String> approvalUpdateExecute(@RequestBody ApprovalUpdateVO approvalUpdateVO) {
		try {
			approvalService.approvalUpdate(approvalUpdateVO);
			return RestMessage.newInstance(true, "审批配置修改成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("审批流程节点配置")
	@ApiOperation(httpMethod = "POST", value = "审批流程节点配置")
	@PostMapping(value = "/approval_node_config")
	public RestMessage<String> approvalNodeConfigExecute(@RequestBody List<ApprovalNodeVO> approvalNodeVOs) {
		try {
			approvalService.approvalNodeConfig(approvalNodeVOs);
			return RestMessage.newInstance(true, "审批配置修改成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("审批流程节点删除")
	@ApiOperation(httpMethod = "POST", value = "审批流程节点删除")
	@PostMapping(value = "/approval_node_delete")
	public RestMessage<String> approvalNodeDeleteExecute(@RequestBody ApprovalNodeDeleteVO approvalNodeDeleteVO) {
		try {
			approvalService.approvalNodeDelete(approvalNodeDeleteVO);
			return RestMessage.newInstance(true, "审批配置修改成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("审批流程节点查询")
	@ApiOperation(httpMethod = "POST", value = "审批流程节点查询")
	@PostMapping(value = "/approval_node_query")
	public RestMessage<ApprovalNodeDTO> approvalNodeQueryExecute(@RequestParam("approvalId") String approvalId) {
		try {
			ApprovalNodeDTO dto = approvalService.approvalNodeQuery(approvalId);
			return RestMessage.newInstance(true, "审批流程节点查询成功", dto);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}
}
