/*
 *      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.springblade.business.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springblade.business.entity.ContractTreeDrawings;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;
import org.springblade.business.service.IContractTreeDrawingsService;
import org.springblade.core.boot.ctrl.BladeController;

import java.util.Date;

/**
 *  节点图纸控制器
 *
 * @author BladeX
 * @since 2022-06-14
 */
@RestController
@AllArgsConstructor
@RequestMapping("/contractTreeDrawings")
public class ContractTreeDrawingsController extends BladeController {

	private final IContractTreeDrawingsService contractTreeDrawingsService;

	/**
	 * 保存或修改节点上传的图纸记录
	 * @param primaryKeyId 节点primaryKeyId
	 * @param fileUrl 文件url
	 * @return 保存结果
	 */
	@PostMapping("/saveContractTreeDrawings")
	@ApiOperationSupport(order = 14)
	@ApiOperation(value = "保存或修改节点上传的图纸记录")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "primaryKeyId", value = "节点primaryKeyId", required = true),
			@ApiImplicitParam(name = "fileUrl", value = "文件url", required = true),
			@ApiImplicitParam(name = "id", value = "节点的drawingsId")
	})
	public R<Boolean> saveOrUpdateContractTreeDrawings(@RequestParam String primaryKeyId, @RequestParam String fileUrl, @RequestParam String id){
		//当前提交用户
		BladeUser user = AuthUtil.getUser();
		return StringUtils.isNotEmpty(id) ?
				R.data(this.contractTreeDrawingsService.update(Wrappers.<ContractTreeDrawings>lambdaUpdate()
						.set(ContractTreeDrawings::getFileUrl, fileUrl).set(ContractTreeDrawings::getUpdateUser, user.getUserId())
						.set(ContractTreeDrawings::getUpdateTime, new Date())
						.eq(ContractTreeDrawings::getId, id)))
				:
				R.data(this.contractTreeDrawingsService.save(new ContractTreeDrawings(primaryKeyId, fileUrl, user.getUserId(), user.getDeptId())));
	}
	
}
