/**
 * 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.order.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.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.modules.order.pojo.dto.OperationOrderSettleDTO;
import org.springblade.modules.order.pojo.form.OperationOrderConditionForm;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.order.pojo.entity.OperationOrderSettleEntity;
import org.springblade.modules.order.pojo.vo.OperationOrderSettleVO;
import org.springblade.modules.order.wrapper.OperationOrderSettleWrapper;
import org.springblade.modules.order.service.IOperationOrderSettleService;
import org.springblade.core.boot.ctrl.BladeController;
import java.util.Map;

/**
 * 工单结算表 控制器
 *
 * @author BladeX
 * @since 2024-06-26
 */
@RestController
@AllArgsConstructor
@RequestMapping("sf/operationOrderSettle")
@Tag(name = "工单结算表", description = "工单结算表接口")
public class OperationOrderSettleController extends BladeController {

	private final IOperationOrderSettleService operationOrderSettleService;

	/**
	 * 工单结算表 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@Operation(summary = "详情", description  = "传入operationOrderSettle")
	public R<OperationOrderSettleVO> detail(OperationOrderSettleEntity operationOrderSettle) {
		OperationOrderSettleEntity detail = operationOrderSettleService.getOne(Condition.getQueryWrapper(operationOrderSettle));
		return R.data(OperationOrderSettleWrapper.build().entityVO(detail));
	}
	/**
	 * 工单结算表 分页
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@Operation(summary = "分页", description  = "传入operationOrderSettle")
	public R<IPage<OperationOrderSettleVO>> list(@Parameter(hidden = true) @RequestParam Map<String, Object> operationOrderSettle, Query query) {
		IPage<OperationOrderSettleEntity> pages = operationOrderSettleService.page(Condition.getPage(query), Condition.getQueryWrapper(operationOrderSettle, OperationOrderSettleEntity.class));
		return R.data(OperationOrderSettleWrapper.build().pageVO(pages));
	}

	/**
	 * 工单结算表 自定义分页
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@Operation(summary = "分页", description  = "传入operationOrderSettle")
	public R<IPage<OperationOrderSettleVO>> page(OperationOrderConditionForm operationOrderSettle, Query query) {
		IPage<OperationOrderSettleVO> pages = operationOrderSettleService.selectOperationOrderSettlePage(Condition.getPage(query), operationOrderSettle);
		return R.data(pages);
	}

	/**
	 * 结算
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@Operation(summary = "结算", description  = "传入operationOrderSettle")
	public R save(@Valid @RequestBody OperationOrderSettleDTO orderSettleDTO) {
		return R.status(operationOrderSettleService.saveOrderSettle(orderSettleDTO));
	}

	/**
	 * 修改结算 是/否
	 */
	@GetMapping(value = "editIfSettle")
	@ApiOperationSupport(order = 5)
	@Operation(summary = "修改结算 是/否", description  = "传入")
	public R editIfSettle(@Parameter(name = "orderIds工单id,多个逗号拼接", required = true) @RequestParam String orderIds
		,@Parameter(name = "是否需要结算：1是 0否", required = true) @RequestParam String ifSettle){
		return R.status(operationOrderSettleService.ifSettle(orderIds,ifSettle));
	}

}
