/**
 * 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.operation.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.apache.commons.lang3.StringEscapeUtils;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.operation.pojo.entity.PlatformAnnouncementEntity;
import org.springblade.modules.operation.pojo.vo.PlatformAnnouncementVO;
import org.springblade.modules.operation.wrapper.PlatformAnnouncementWrapper;
import org.springblade.modules.operation.service.IPlatformAnnouncementService;
import org.springblade.core.boot.ctrl.BladeController;

import java.util.Date;
import java.util.Map;
import java.util.List;

/**
 * 平台通知公告表 控制器
 *
 * @author lzp
 * @since 2024-06-25
 */
@RestController
@AllArgsConstructor
@RequestMapping("sf/platformAnnouncement")
@Tag(name = "平台通知公告表", description = "平台通知公告表接口")
public class PlatformAnnouncementController extends BladeController {

	private final IPlatformAnnouncementService platformAnnouncementService;

	/**
	 * 平台通知公告表 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@Operation(summary = "详情", description  = "传入platformAnnouncement")
	public R<PlatformAnnouncementVO> detail(PlatformAnnouncementVO platformAnnouncement) {
		PlatformAnnouncementVO detail = platformAnnouncementService.findAnnouncementDetail(platformAnnouncement);
		return R.data(detail);
	}
	/**
	 * 平台通知公告表 分页
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@Operation(summary = "普通列表分页", description  = "传入platformAnnouncement")
	public R<List<PlatformAnnouncementVO>> list(PlatformAnnouncementVO platformAnnouncement, Query query,BladeUser bladeUser) {
		platformAnnouncement.setReadId(bladeUser.getUserId());
		List<PlatformAnnouncementVO> pages = platformAnnouncementService.findAnnouncementList(Condition.getPage(query), platformAnnouncement);
		return R.data(pages);
	}

	/**
	 * 平台通知公告表 自定义分页
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@Operation(summary = "管理员分页", description  = "传入platformAnnouncement")
	public R<IPage<PlatformAnnouncementVO>> page(PlatformAnnouncementVO platformAnnouncement, Query query) {
		IPage<PlatformAnnouncementVO> pages = platformAnnouncementService.selectPlatformAnnouncementPage(Condition.getPage(query), platformAnnouncement);
		return R.data(pages);
	}

	/**
	 * 平台通知公告表 新增
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@Operation(summary = "新增", description  = "传入platformAnnouncement")
	public R save(@Valid PlatformAnnouncementEntity platformAnnouncement,BladeUser bladeUser) {
		platformAnnouncement.setStatus("0");
		platformAnnouncement.setCreateTime(new Date());
		platformAnnouncement.setCreateBy(bladeUser.getUserId().toString());
		return R.status(platformAnnouncementService.save(platformAnnouncement));
	}

	/**
	 * 平台通知公告表 修改
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@Operation(summary = "修改", description  = "传入platformAnnouncement")
	public R update(@Valid PlatformAnnouncementEntity platformAnnouncement) {
		return R.status(platformAnnouncementService.updateById(platformAnnouncement));
	}

	/**
	 * 平台通知公告表 删除
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@Operation(summary = "逻辑删除", description  = "传入id")
	public R remove(@Parameter(name = "主键", required = true) @RequestParam String id ) {
		PlatformAnnouncementEntity platformAnnouncement  = platformAnnouncementService.getById(id);
		platformAnnouncement.setStatus("1");
		return R.status(platformAnnouncementService.updateById(platformAnnouncement));
	}



}
