/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.security.trans.projectBudgetManagement.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;

import javax.validation.Valid;

import org.security.trans.projectBudgetManagement.dto.ProjectDTO;
import org.security.trans.projectBudgetManagement.dto.ProjectOverReviewDTO;
import org.security.trans.projectBudgetManagement.dto.ProjectPayPlanDTO;
import org.security.trans.projectBudgetManagement.vo.ProjectContractVO;
import org.security.trans.projectBudgetManagement.vo.ProjectPayPlanVO;
import org.security.trans.projectBudgetManagement.vo.RemindDataVO;
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 com.baomidou.mybatisplus.core.metadata.IPage;
import org.security.trans.projectBudgetManagement.vo.ProjectVO;
import org.security.trans.projectBudgetManagement.service.IProjectService;
import org.springblade.core.boot.ctrl.BladeController;

import java.text.ParseException;
import java.util.List;

/**
 * 项目管理-项目管理信息主表 控制器
 *
 * @author BladeX
 * @since 2022-08-05
 */
@RestController
@AllArgsConstructor
@RequestMapping("/project")
@Api(value = "项目管理-项目管理信息主表", tags = "项目管理-项目管理信息主表接口")
public class ProjectController extends BladeController {

	private final IProjectService projectService;

	/**
	 * 详情
	 */
	@GetMapping("/{id}")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入id")
	public R<ProjectVO> detail(@PathVariable String id) {
		return R.data(projectService.getData(id));
	}

	/**
	 * 获取父级项目信息
	 */
	@GetMapping("/parent")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "获取父级项目信息")
	public R<List<ProjectVO>> getParentProject() {
		return R.data(projectService.getParentProject());
	}

	/**
	 * 自定义分页 项目管理-项目管理信息主表
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入project")
	public R<IPage<ProjectVO>> page(ProjectDTO projectDTO, Query query) {
		IPage<ProjectVO> pages = projectService.selectProjectPage(Condition.getPage(query), projectDTO);
		return R.data(pages);
	}

	/**
	 * 新增/修改 项目管理-项目管理信息主表
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增/修改", notes = "传入project")
	public R save(@Valid @RequestBody ProjectDTO projectDTO) {
		return R.status(projectService.saveData(projectDTO));
	}

	/**
	 * 删除 项目管理-项目管理信息主表
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(projectService.removeData(Func.toLongList(ids)));
	}

	/**
	 * 项目管理-项目结项
	 */
	@PostMapping("/over")
	@ApiOperationSupport(order = 9)
	@ApiOperation(value = "项目结项", notes = "传入id")
	public R projectOver(@ApiParam(value = "主键集合", required = true) @RequestParam String id) {
		return R.status(projectService.projectOver(id));
	}


	/**
	 * 结项项目审阅
	 */
	@PostMapping("/review")
	@ApiOperationSupport(order = 10)
	@ApiOperation(value = "结项项目审阅", notes = "传入id")
	public R projectOverReview(@RequestBody ProjectOverReviewDTO projectOverReviewDTO) {
		return R.status(projectService.projectOverReview(projectOverReviewDTO));
	}


	/**
	 * 首页-设备维保到期、项目付款计划时间到期、项目合同到期提醒
	 */
	@GetMapping("/remind/data")
	@ApiOperationSupport(order = 11)
	@ApiOperation(value = "首页到期提醒", notes = "")
	public R<List<RemindDataVO>> getRemindData() throws ParseException {
		return R.data(projectService.getRemindData());
	}

	/**
	 * 项目付款计划详情
	 */
	@GetMapping("/pay-plan/{id}")
	@ApiOperationSupport(order = 12)
	@ApiOperation(value = "项目付款计划详情", notes = "")
	public R<ProjectPayPlanVO> getProjectPayPlanData(@PathVariable String id) {
		return R.data(projectService.getProjectPayPlanData(id));
	}

	/**
	 * 合同详情
	 */
	@GetMapping("/contract/{id}")
	@ApiOperationSupport(order = 13)
	@ApiOperation(value = "项目合同详情", notes = "")
	public R<ProjectContractVO> getProjectContractData(@PathVariable String id) {
		return R.data(projectService.getProjectContractData(id));
	}
}
